mirror of
https://gitlab.com/Syroot/Worms.git
synced 2025-01-26 13:47:58 +03:00
Update to BinaryData 5.
This commit is contained in:
parent
3877a8dc27
commit
55fdd54027
@ -1,10 +1,7 @@
|
||||
using Syroot.Worms.Gen2.Armageddon.ProjectX;
|
||||
|
||||
namespace Syroot.Worms.Test
|
||||
namespace Syroot.Worms.Scratchpad
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents the main class of the application containing the program entry point.
|
||||
/// </summary>
|
||||
internal class Program
|
||||
{
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
@ -0,0 +1,9 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
</ItemGroup>
|
||||
</Project>
|
@ -5,7 +5,7 @@ using System.IO;
|
||||
using System.Linq;
|
||||
using Syroot.Worms.Core;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Common
|
||||
namespace Syroot.Worms.Test.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of methods helping in executing tests.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2
|
||||
namespace Syroot.Worms.Test.Gen2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="Archive"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="GeneratedMap"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="LandData"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon.ProjectX;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon.ProjectX
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="Library"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon.ProjectX;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon.ProjectX
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="Scheme"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="Scheme"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Armageddon;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Armageddon
|
||||
namespace Syroot.Worms.Test.Gen2.Armageddon
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="TeamContainer"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2
|
||||
namespace Syroot.Worms.Test.Gen2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="ImageData"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2
|
||||
namespace Syroot.Worms.Test.Gen2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="Palette"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.WorldParty;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.WorldParty
|
||||
namespace Syroot.Worms.Test.Gen2.WorldParty
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="LandData"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.WorldParty;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.WorldParty
|
||||
namespace Syroot.Worms.Test.Gen2.WorldParty
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="TeamContainer"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Worms2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Worms2
|
||||
namespace Syroot.Worms.Test.Gen2.Worms2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="LandData"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Worms2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Worms2
|
||||
namespace Syroot.Worms.Test.Gen2.Worms2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="SchemeOptions"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Worms2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Worms2
|
||||
namespace Syroot.Worms.Test.Gen2.Worms2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="SchemeWeapons"/> class.
|
@ -1,8 +1,8 @@
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using Syroot.Worms.Gen2.Worms2;
|
||||
using Syroot.Worms.UnitTest.Common;
|
||||
using Syroot.Worms.Test.Common;
|
||||
|
||||
namespace Syroot.Worms.UnitTest.Gen2.Worms2
|
||||
namespace Syroot.Worms.Test.Gen2.Worms2
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents a collection of tests for the <see cref="TeamContainer"/> class.
|
@ -1,12 +1,12 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp2</TargetFramework>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
|
||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
</Project>
|
||||
|
@ -1,21 +0,0 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>netcoreapp1.1</TargetFramework>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="15.0.0" />
|
||||
<PackageReference Include="MSTest.TestAdapter" Version="1.1.11" />
|
||||
<PackageReference Include="MSTest.TestFramework" Version="1.1.11" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Syroot.Worms\Syroot.Worms.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Service Include="{82a7f48d-3b50-4b1e-b82e-3ada8210c358}" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
@ -3,11 +3,11 @@ Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio 15
|
||||
VisualStudioVersion = 15.0.26403.7
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Syroot.Worms", "Syroot.Worms\Syroot.Worms.csproj", "{DD76B6AA-5A5A-4FCD-95AA-9552977525A1}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms", "Syroot.Worms\Syroot.Worms.csproj", "{DD76B6AA-5A5A-4FCD-95AA-9552977525A1}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Syroot.Worms.UnitTest", "Syroot.Worms.UnitTest\Syroot.Worms.UnitTest.csproj", "{493816DB-A1A1-4981-9F5F-8044499937B6}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Test", "Syroot.Worms.Test\Syroot.Worms.Test.csproj", "{20ACA971-A9D0-4424-9958-9CEE24F43C9C}"
|
||||
EndProject
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Test", "Syroot.Worms.Test\Syroot.Worms.Test.csproj", "{2D796945-A523-4A22-BDEE-702D6BA36F69}"
|
||||
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Syroot.Worms.Scratchpad", "Syroot.Worms.Scratchpad\Syroot.Worms.Scratchpad.csproj", "{0D7F9DC3-7268-494E-BA1E-6C01525EB9AB}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
@ -19,16 +19,19 @@ Global
|
||||
{DD76B6AA-5A5A-4FCD-95AA-9552977525A1}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{DD76B6AA-5A5A-4FCD-95AA-9552977525A1}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{DD76B6AA-5A5A-4FCD-95AA-9552977525A1}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{493816DB-A1A1-4981-9F5F-8044499937B6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{493816DB-A1A1-4981-9F5F-8044499937B6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{493816DB-A1A1-4981-9F5F-8044499937B6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{493816DB-A1A1-4981-9F5F-8044499937B6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{2D796945-A523-4A22-BDEE-702D6BA36F69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{2D796945-A523-4A22-BDEE-702D6BA36F69}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{2D796945-A523-4A22-BDEE-702D6BA36F69}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{2D796945-A523-4A22-BDEE-702D6BA36F69}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{20ACA971-A9D0-4424-9958-9CEE24F43C9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{20ACA971-A9D0-4424-9958-9CEE24F43C9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{20ACA971-A9D0-4424-9958-9CEE24F43C9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{20ACA971-A9D0-4424-9958-9CEE24F43C9C}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0D7F9DC3-7268-494E-BA1E-6C01525EB9AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0D7F9DC3-7268-494E-BA1E-6C01525EB9AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0D7F9DC3-7268-494E-BA1E-6C01525EB9AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0D7F9DC3-7268-494E-BA1E-6C01525EB9AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {1CD4EDE2-A5FB-4A58-A850-3506AB7E7B69}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
@ -1,114 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Runtime.InteropServices;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents extension methods for <see cref="BinaryReader"/> instances.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static class BinaryReaderExtensions
|
||||
{
|
||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Reads an <see cref="ILoadable"/> instance from the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ILoadable"/> class to instantiate.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
|
||||
/// <returns>The <see cref="ILoadable"/> instance.</returns>
|
||||
internal static T Load<T>(this BinaryDataReader self) where T : ILoadable, new()
|
||||
{
|
||||
T instance = new T();
|
||||
instance.Load(self.BaseStream);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads <see cref="ILoadable"/> instances from the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ILoadable"/> class to instantiate.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
|
||||
/// <param name="count">The number of instances to read.</param>
|
||||
/// <returns>The <see cref="ILoadable"/> instances.</returns>
|
||||
internal static T[] Load<T>(this BinaryDataReader self, int count) where T : ILoadable, new()
|
||||
{
|
||||
T[] instances = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
instances[i] = Load<T>(self);
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 0-terminated string which is stored in a fixed-size block of <paramref name="length"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size blocks takes.</param>
|
||||
/// <returns>The read string.</returns>
|
||||
internal static string ReadFixedString(this BinaryDataReader self, int length)
|
||||
{
|
||||
string str = self.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
self.Seek(length - str.Length - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads <paramref name="count"/> 0-terminated strings which are stored in a fixed-size block of
|
||||
/// <paramref name="length"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryDataReader"/>.</param>
|
||||
/// <param name="count">The number of values to read.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size blocks takes.</param>
|
||||
/// <returns>The read string.</returns>
|
||||
internal static string[] ReadFixedStrings(this BinaryDataReader self, int count, int length)
|
||||
{
|
||||
string[] strings = new string[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
strings[i] = ReadFixedString(self, length);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a raw byte structure from the current stream and returns it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryReader"/> instance.</param>
|
||||
/// <returns>The structure of type <typeparamref name="T"/>.</returns>
|
||||
internal static T ReadStruct<T>(this BinaryReader self) where T : struct
|
||||
{
|
||||
// Read the raw bytes of the structure.
|
||||
byte[] bytes = self.ReadBytes(Marshal.SizeOf<T>());
|
||||
|
||||
// Convert them to a structure instance and return it.
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
T instance = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
||||
handle.Free();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads raw byte structures from the current stream and returns them.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryReader"/> instance.</param>
|
||||
/// <param name="count">The number of values to read.</param>
|
||||
/// <returns>The structures of type <typeparamref name="T"/>.</returns>
|
||||
internal static T[] ReadStructs<T>(this BinaryReader self, int count) where T : struct
|
||||
{
|
||||
T[] values = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = ReadStruct<T>(self);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
}
|
||||
}
|
221
src/Syroot.Worms/Core/BinaryStreamExtensions.cs
Normal file
221
src/Syroot.Worms/Core/BinaryStreamExtensions.cs
Normal file
@ -0,0 +1,221 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents extension methods for <see cref="BinaryStream"/> instances.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static partial class BinaryStreamExtensions
|
||||
{
|
||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
||||
|
||||
// ---- Reading ----
|
||||
|
||||
/// <summary>
|
||||
/// Reads an <see cref="ILoadable"/> instance from the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ILoadable"/> class to instantiate.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <returns>The <see cref="ILoadable"/> instance.</returns>
|
||||
internal static T Load<T>(this BinaryStream self) where T : ILoadable, new()
|
||||
{
|
||||
T instance = new T();
|
||||
instance.Load(self.BaseStream);
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads <see cref="ILoadable"/> instances from the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ILoadable"/> class to instantiate.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <param name="count">The number of instances to read.</param>
|
||||
/// <returns>The <see cref="ILoadable"/> instances.</returns>
|
||||
internal static T[] Load<T>(this BinaryStream self, int count) where T : ILoadable, new()
|
||||
{
|
||||
T[] instances = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
instances[i] = Load<T>(self);
|
||||
}
|
||||
return instances;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a 0-terminated string which is stored in a fixed-size block of <paramref name="length"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size blocks takes.</param>
|
||||
/// <returns>The read string.</returns>
|
||||
internal static string ReadFixedString(this BinaryStream self, int length)
|
||||
{
|
||||
string str = self.ReadString(StringCoding.ZeroTerminated);
|
||||
self.Seek(length - str.Length - 1);
|
||||
return str;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads <paramref name="count"/> 0-terminated strings which are stored in a fixed-size block of
|
||||
/// <paramref name="length"/> bytes.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <param name="count">The number of values to read.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size blocks takes.</param>
|
||||
/// <returns>The read string.</returns>
|
||||
internal static string[] ReadFixedStrings(this BinaryStream self, int count, int length)
|
||||
{
|
||||
string[] strings = new string[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
strings[i] = ReadFixedString(self, length);
|
||||
}
|
||||
return strings;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads a raw byte structure from the current stream and returns it.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <returns>The structure of type <typeparamref name="T"/>.</returns>
|
||||
internal static T ReadStruct<T>(this BinaryStream self) where T : struct
|
||||
{
|
||||
// Read the raw bytes of the structure.
|
||||
byte[] bytes = self.ReadBytes(Marshal.SizeOf<T>());
|
||||
|
||||
// Convert them to a structure instance and return it.
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
T instance = Marshal.PtrToStructure<T>(handle.AddrOfPinnedObject());
|
||||
handle.Free();
|
||||
|
||||
return instance;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Reads raw byte structures from the current stream and returns them.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <param name="count">The number of values to read.</param>
|
||||
/// <returns>The structures of type <typeparamref name="T"/>.</returns>
|
||||
internal static T[] ReadStructs<T>(this BinaryStream self, int count) where T : struct
|
||||
{
|
||||
T[] values = new T[count];
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
values[i] = ReadStruct<T>(self);
|
||||
}
|
||||
return values;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current address of the stream to which a 4-byte placeholder has been written which can be filled
|
||||
/// later.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <returns>The address at which a 4-byte placeholder has been written to.</returns>
|
||||
internal static uint ReserveOffset(this BinaryStream self)
|
||||
{
|
||||
uint offset = (uint)self.Position;
|
||||
self.WriteUInt32(0);
|
||||
return offset;
|
||||
}
|
||||
|
||||
// ---- Writing ----
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given <see cref="ISaveable"/> instance into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ISaveable"/> class to write.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <param name="value">The instance to write into the current stream.</param>
|
||||
internal static void Save<T>(this BinaryStream self, T value) where T : ISaveable
|
||||
{
|
||||
value.Save(self.BaseStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given <see cref="ISaveable"/> instances into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ISaveable"/> class to write.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/>.</param>
|
||||
/// <param name="values">The instances to write into the current stream.</param>
|
||||
internal static void Save<T>(this BinaryStream self, T[] values) where T : ISaveable
|
||||
{
|
||||
foreach (T value in values)
|
||||
{
|
||||
Save(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
internal static void SatisfyOffset(this BinaryStream self, uint offset, int value)
|
||||
{
|
||||
using (self.TemporarySeek(offset, SeekOrigin.Begin))
|
||||
self.WriteInt32(value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given string into a fixed-size block of <paramref name="length"/> bytes and 0-terminates it.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <param name="value">The string to write.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size block takes.</param>
|
||||
internal static void Write(this BinaryStream self, string value, int length)
|
||||
{
|
||||
byte[] bytes = self.Encoding.GetBytes(value);
|
||||
self.Write(bytes);
|
||||
self.Write(new byte[length - bytes.Length]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given strings into fixed-size blocks of <paramref name="length"/> bytes and 0-terminates them.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <param name="values">The strings to write.</param>
|
||||
/// <param name="length">The number of bytes a fixed-size block takes.</param>
|
||||
internal static void Write(this BinaryStream self, string[] values, int length)
|
||||
{
|
||||
foreach (string value in values)
|
||||
{
|
||||
Write(self, value, length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the bytes of a structure into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <param name="value">The structure to write.</param>
|
||||
internal static void Write<T>(this BinaryStream self, T value) where T : struct
|
||||
{
|
||||
// Get the raw bytes of the structure instance.
|
||||
byte[] bytes = new byte[Marshal.SizeOf<T>()];
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false);
|
||||
handle.Free();
|
||||
|
||||
// Write the bytes to the stream.
|
||||
self.Write(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the bytes of structures into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryStream"/> instance.</param>
|
||||
/// <param name="values">The structures to write.</param>
|
||||
internal static void Write<T>(this BinaryStream self, T[] values) where T : struct
|
||||
{
|
||||
foreach (T value in values)
|
||||
{
|
||||
Write(self, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,101 +0,0 @@
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Core
|
||||
{
|
||||
/// <summary>
|
||||
/// Represents extension methods for <see cref="BinaryWriter"/> instances.
|
||||
/// </summary>
|
||||
[DebuggerStepThrough]
|
||||
internal static class BinaryWriterExtensions
|
||||
{
|
||||
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given <see cref="ISaveable"/> instance into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ISaveable"/> class to write.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param>
|
||||
/// <param name="value">The instance to write into the current stream.</param>
|
||||
internal static void Save<T>(this BinaryDataWriter self, T value) where T : ISaveable
|
||||
{
|
||||
value.Save(self.BaseStream);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given <see cref="ISaveable"/> instances into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the <see cref="ISaveable"/> class to write.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryDataWriter"/>.</param>
|
||||
/// <param name="values">The instances to write into the current stream.</param>
|
||||
internal static void Save<T>(this BinaryDataWriter self, T[] values) where T : ISaveable
|
||||
{
|
||||
foreach (T value in values)
|
||||
{
|
||||
Save(self, value);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given string into a fixed-size block of <paramref name="length"/> bytes and 0-terminates it.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryDataWriter"/> instance.</param>
|
||||
/// <param name="value">The string to write.</param>
|
||||
/// <param name="length">The number of bytes the fixed-size block takes.</param>
|
||||
internal static void Write(this BinaryDataWriter self, string value, int length)
|
||||
{
|
||||
byte[] bytes = self.Encoding.GetBytes(value);
|
||||
self.Write(bytes);
|
||||
self.Write(new byte[length - bytes.Length]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the given strings into fixed-size blocks of <paramref name="length"/> bytes and 0-terminates them.
|
||||
/// </summary>
|
||||
/// <param name="self">The extended <see cref="BinaryDataWriter"/> instance.</param>
|
||||
/// <param name="values">The strings to write.</param>
|
||||
/// <param name="length">The number of bytes a fixed-size block takes.</param>
|
||||
internal static void Write(this BinaryDataWriter self, string[] values, int length)
|
||||
{
|
||||
foreach (string value in values)
|
||||
{
|
||||
Write(self, value, length);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the bytes of a structure into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryWriter"/> instance.</param>
|
||||
/// <param name="value">The structure to write.</param>
|
||||
internal static void Write<T>(this BinaryWriter self, T value) where T : struct
|
||||
{
|
||||
// Get the raw bytes of the structure instance.
|
||||
byte[] bytes = new byte[Marshal.SizeOf<T>()];
|
||||
|
||||
GCHandle handle = GCHandle.Alloc(bytes, GCHandleType.Pinned);
|
||||
Marshal.StructureToPtr(value, handle.AddrOfPinnedObject(), false);
|
||||
handle.Free();
|
||||
|
||||
// Write the bytes to the stream.
|
||||
self.Write(bytes);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Writes the bytes of structures into the current stream.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The type of the structure to read.</typeparam>
|
||||
/// <param name="self">The extended <see cref="BinaryWriter"/> instance.</param>
|
||||
/// <param name="values">The structures to write.</param>
|
||||
internal static void Write<T>(this BinaryWriter self, T[] values) where T : struct
|
||||
{
|
||||
foreach (T value in values)
|
||||
{
|
||||
Write(self, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -40,7 +40,7 @@ namespace Syroot.Worms.Core
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the RIFF data from.</param>
|
||||
protected void LoadRiff(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the file header.
|
||||
if (reader.ReadString(_signature.Length) != _signature)
|
||||
@ -78,25 +78,25 @@ namespace Syroot.Worms.Core
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the RIFF data in.</param>
|
||||
protected void SaveRiff(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.NoPrefixOrTermination);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
writer.Write(_typeData.FileIdentifier, BinaryStringFormat.NoPrefixOrTermination);
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
writer.Write(_typeData.FileIdentifier, StringCoding.Raw);
|
||||
|
||||
// Write the chunks.
|
||||
foreach (KeyValuePair<string, MethodInfo> chunkSaver in _typeData.ChunkSavers)
|
||||
{
|
||||
writer.Write(chunkSaver.Key, BinaryStringFormat.NoPrefixOrTermination);
|
||||
Offset chunkSizeOffset = writer.ReserveOffset();
|
||||
writer.Write(chunkSaver.Key, StringCoding.Raw);
|
||||
uint chunkSizeOffset = writer.ReserveOffset();
|
||||
|
||||
chunkSaver.Value.Invoke(this, new object[] { writer });
|
||||
|
||||
chunkSizeOffset.Satisfy((int)(writer.Position - chunkSizeOffset.Position - 4));
|
||||
writer.SatisfyOffset(chunkSizeOffset, (int)(writer.Position - chunkSizeOffset - 4));
|
||||
}
|
||||
|
||||
fileSizeOffset.Satisfy((int)writer.Position - 8);
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)(writer.Position - 8));
|
||||
}
|
||||
}
|
||||
|
||||
@ -123,7 +123,7 @@ namespace Syroot.Worms.Core
|
||||
{
|
||||
ParameterInfo[] parameters = method.GetParameters();
|
||||
if (parameters.Length == 2
|
||||
&& parameters[0].ParameterType == typeof(BinaryDataReader)
|
||||
&& parameters[0].ParameterType == typeof(BinaryStream)
|
||||
&& parameters[1].ParameterType == typeof(int))
|
||||
{
|
||||
typeData.ChunkLoaders.Add(loadAttribute.Identifier, method);
|
||||
@ -135,7 +135,7 @@ namespace Syroot.Worms.Core
|
||||
{
|
||||
ParameterInfo[] parameters = method.GetParameters();
|
||||
if (parameters.Length == 1
|
||||
&& parameters[0].ParameterType == typeof(BinaryDataWriter))
|
||||
&& parameters[0].ParameterType == typeof(BinaryStream))
|
||||
{
|
||||
typeData.ChunkSavers.Add(saveAttribute.Identifier, method);
|
||||
}
|
||||
|
@ -65,7 +65,7 @@ namespace Syroot.Worms.Gen2
|
||||
}
|
||||
|
||||
Clear();
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
@ -96,7 +96,7 @@ namespace Syroot.Worms.Gen2
|
||||
nextEntryOffset = reader.ReadInt32();
|
||||
int offset = reader.ReadInt32();
|
||||
int length = reader.ReadInt32();
|
||||
string name = reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
string name = reader.ReadString(StringCoding.ZeroTerminated);
|
||||
using (reader.TemporarySeek(offset, SeekOrigin.Begin))
|
||||
{
|
||||
Add(name, reader.ReadBytes(length));
|
||||
@ -125,12 +125,12 @@ namespace Syroot.Worms.Gen2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data in.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream))
|
||||
using (BinaryStream writer = new BinaryStream(stream))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
Offset tocOffset = writer.ReserveOffset();
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
uint tocOffset = writer.ReserveOffset();
|
||||
|
||||
// Write the data and build the hash table and file entries.
|
||||
List<HashTableEntry>[] hashTable = new List<HashTableEntry>[_hashSize];
|
||||
@ -155,7 +155,7 @@ namespace Syroot.Worms.Gen2
|
||||
// Write the hash table and file entries.
|
||||
int tocStart = (int)writer.Position;
|
||||
int fileEntryOffset = sizeof(int) + _hashSize * sizeof(int);
|
||||
tocOffset.Satisfy(tocStart);
|
||||
writer.SatisfyOffset(tocOffset, tocStart);
|
||||
writer.Write(_tocSignature);
|
||||
for (int i = 0; i < _hashSize; i++)
|
||||
{
|
||||
@ -173,14 +173,14 @@ namespace Syroot.Worms.Gen2
|
||||
for (int j = 0; j < entries.Count; j++)
|
||||
{
|
||||
HashTableEntry entry = entries[j];
|
||||
Offset nextEntryOffset = writer.ReserveOffset();
|
||||
uint nextEntryOffset = writer.ReserveOffset();
|
||||
writer.Write(entry.Offset);
|
||||
writer.Write(entry.Length);
|
||||
writer.Write(entry.Name, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(entry.Name, StringCoding.ZeroTerminated);
|
||||
writer.Align(4);
|
||||
if (j < entries.Count - 1)
|
||||
{
|
||||
nextEntryOffset.Satisfy((int)writer.Position - tocStart);
|
||||
writer.SatisfyOffset(nextEntryOffset, (int)writer.Position - tocStart);
|
||||
}
|
||||
}
|
||||
fileEntryOffset = (int)writer.Position - tocStart;
|
||||
@ -188,7 +188,7 @@ namespace Syroot.Worms.Gen2
|
||||
}
|
||||
}
|
||||
|
||||
fileSizeOffset.Satisfy(tocStart + fileEntryOffset - 1);
|
||||
writer.SatisfyOffset(fileSizeOffset, tocStart + fileEntryOffset - 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -54,7 +54,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
Settings = reader.ReadStruct<MapGeneratorSettings>();
|
||||
}
|
||||
@ -78,7 +78,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
writer.Write(Settings);
|
||||
}
|
||||
|
@ -104,7 +104,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
@ -115,7 +115,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
|
||||
// Read the data.
|
||||
Size = reader.ReadStruct<Vector2>();
|
||||
TopBorder = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
TopBorder = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WaterHeight = reader.ReadInt32();
|
||||
Unknown = reader.ReadInt32();
|
||||
|
||||
@ -128,8 +128,8 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
Background = reader.Load<ImageData>();
|
||||
|
||||
// Read the file paths.
|
||||
LandTexturePath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
WaterDirPath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,15 +151,15 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
|
||||
// Write the data.
|
||||
writer.Write(Size);
|
||||
writer.Write(TopBorder, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(TopBorder, BooleanCoding.Dword);
|
||||
writer.Write(WaterHeight);
|
||||
writer.Write(Unknown);
|
||||
|
||||
@ -173,10 +173,10 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
Background.Save(writer.BaseStream);
|
||||
|
||||
// Write the file paths.
|
||||
writer.Write(LandTexturePath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(WaterDirPath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(LandTexturePath, StringCoding.ByteCharCount);
|
||||
writer.Write(WaterDirPath, StringCoding.ByteCharCount);
|
||||
|
||||
fileSizeOffset.Satisfy();
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
@ -7,7 +8,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
|
||||
|
||||
public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute)
|
||||
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
ExplosionAction explosionAction;
|
||||
switch (instance)
|
||||
@ -25,20 +27,21 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
switch (explosionAction)
|
||||
{
|
||||
case ExplosionAction.Bounce:
|
||||
return reader.ReadObject<BounceAction>();
|
||||
return stream.ReadObject<BounceAction>();
|
||||
case ExplosionAction.Dig:
|
||||
return reader.ReadObject<DigAction>();
|
||||
return stream.ReadObject<DigAction>();
|
||||
case ExplosionAction.Home:
|
||||
return reader.ReadObject<HomeAction>();
|
||||
return stream.ReadObject<HomeAction>();
|
||||
case ExplosionAction.Roam:
|
||||
return reader.ReadObject<RoamAction>();
|
||||
return stream.ReadObject<RoamAction>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value)
|
||||
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
writer.WriteObject(value);
|
||||
stream.WriteObject(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,7 +28,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public int TerrainOffset { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool Fart { get; set; }
|
||||
|
||||
public int DiseasePower { get; set; }
|
||||
|
@ -75,14 +75,14 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
{
|
||||
throw new InvalidDataException("Invalid PXL file signature.");
|
||||
}
|
||||
Version = reader.ReadByte();
|
||||
Version = reader.Read1Byte();
|
||||
|
||||
// Read the items.
|
||||
Clear();
|
||||
@ -90,14 +90,14 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
for (int i = 0; i < itemCount; i++)
|
||||
{
|
||||
LibraryItemType type = reader.ReadEnum<LibraryItemType>(true);
|
||||
string name = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
string name = reader.ReadString(StringCoding.Int32CharCount);
|
||||
switch (type)
|
||||
{
|
||||
case LibraryItemType.File:
|
||||
Add(new LibraryItem(name, reader.ReadBytes(reader.ReadInt32())));
|
||||
break;
|
||||
case LibraryItemType.Script:
|
||||
Add(new LibraryItem(name, reader.ReadString(BinaryStringFormat.DwordLengthPrefix)));
|
||||
Add(new LibraryItem(name, reader.ReadString(StringCoding.Int32CharCount)));
|
||||
break;
|
||||
case LibraryItemType.Weapon:
|
||||
Add(new LibraryItem(name, reader.Load<Weapon>()));
|
||||
@ -125,7 +125,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
@ -135,8 +135,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
writer.Write(Count);
|
||||
foreach (LibraryItem item in this)
|
||||
{
|
||||
writer.Write(item.Type, true);
|
||||
writer.Write(item.Key, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.WriteEnum(item.Type, true);
|
||||
writer.Write(item.Key, StringCoding.Int32CharCount);
|
||||
switch (item.Type)
|
||||
{
|
||||
case LibraryItemType.File:
|
||||
@ -145,7 +145,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
writer.Write(value);
|
||||
break;
|
||||
case LibraryItemType.Script:
|
||||
writer.Write((string)item.Value, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write((string)item.Value, StringCoding.Int32CharCount);
|
||||
break;
|
||||
case LibraryItemType.Weapon:
|
||||
writer.Save((Weapon)item.Value);
|
||||
|
@ -72,7 +72,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadString(_signature.Length) != _signature)
|
||||
@ -100,7 +100,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
Files = new Dictionary<string, byte[]>(filesCount);
|
||||
for (int i = 0; i < filesCount; i++)
|
||||
{
|
||||
string name = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
string name = reader.ReadString(StringCoding.Int32CharCount);
|
||||
int length = reader.ReadInt32();
|
||||
Files.Add(name, reader.ReadBytes(length));
|
||||
}
|
||||
@ -110,20 +110,20 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
Scripts = new Dictionary<string, string>(scriptsCount);
|
||||
for (int i = 0; i < scriptsCount; i++)
|
||||
{
|
||||
Scripts.Add(reader.ReadString(BinaryStringFormat.DwordLengthPrefix),
|
||||
reader.ReadString(BinaryStringFormat.DwordLengthPrefix));
|
||||
Scripts.Add(reader.ReadString(StringCoding.Int32CharCount),
|
||||
reader.ReadString(StringCoding.Int32CharCount));
|
||||
}
|
||||
|
||||
// Read required libraries.
|
||||
int librariesCount = reader.ReadInt32();
|
||||
Libraries = new List<string>(reader.ReadStrings(librariesCount, BinaryStringFormat.DwordLengthPrefix));
|
||||
Libraries = new List<string>(reader.ReadStrings(librariesCount, StringCoding.Int32CharCount));
|
||||
|
||||
// Read a possibly attached scheme file.
|
||||
if (reader.ReadBoolean())
|
||||
{
|
||||
reader.Seek(sizeof(int)); // Scheme length not required due to intelligent loading.
|
||||
GameScheme = reader.Load<Armageddon.Scheme>();
|
||||
GameSchemeName = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
GameSchemeName = reader.ReadString(StringCoding.Int32CharCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -146,10 +146,10 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.NoPrefixOrTermination);
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
writer.Write(Version);
|
||||
|
||||
// Write the scheme flags.
|
||||
@ -169,7 +169,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
writer.Write(Files.Count);
|
||||
foreach (KeyValuePair<string, byte[]> file in Files)
|
||||
{
|
||||
writer.Write(file.Key, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(file.Key, StringCoding.Int32CharCount);
|
||||
writer.Write(file.Value.Length);
|
||||
writer.Write(file.Value);
|
||||
}
|
||||
@ -178,8 +178,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
writer.Write(Scripts.Count);
|
||||
foreach (KeyValuePair<string, string> script in Scripts)
|
||||
{
|
||||
writer.Write(script.Key, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(script.Value, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(script.Key, StringCoding.Int32CharCount);
|
||||
writer.Write(script.Value, StringCoding.Int32CharCount);
|
||||
}
|
||||
|
||||
// Write required libraries.
|
||||
@ -196,7 +196,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
schemeBytes = schemeStream.ToArray();
|
||||
}
|
||||
writer.Write(schemeBytes.Length);
|
||||
writer.Write(GameSchemeName, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(GameSchemeName, StringCoding.Int32CharCount);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -6,10 +6,10 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
public short SoundIndex;
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroWord)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Word)]
|
||||
public bool RepeatSound;
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool UseExplosionSound;
|
||||
|
||||
public int SoundBeforeExplosion;
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
@ -7,7 +8,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
|
||||
|
||||
public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute)
|
||||
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
WeaponAirstrikeSubstyle airstrikeSubstyle;
|
||||
switch (instance)
|
||||
@ -22,16 +24,17 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
switch (airstrikeSubstyle)
|
||||
{
|
||||
case WeaponAirstrikeSubstyle.Launcher:
|
||||
return reader.ReadObject<LauncherStyle>();
|
||||
return stream.ReadObject<LauncherStyle>();
|
||||
case WeaponAirstrikeSubstyle.Mines:
|
||||
return reader.ReadObject<MineStyle>();
|
||||
return stream.ReadObject<MineStyle>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value)
|
||||
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
writer.WriteObject(value);
|
||||
stream.WriteObject(value);
|
||||
}
|
||||
}
|
||||
}
|
@ -14,7 +14,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public int FireBurnTime { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool RemainOnTerrain { get; set; }
|
||||
}
|
||||
}
|
@ -10,7 +10,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public int FixedSpeed { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool RunAway { get; set; }
|
||||
|
||||
public CollisionFlags Collisions { get; set; }
|
||||
@ -41,7 +41,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public Sound Sound { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool ExplodeOnSpace { get; set; }
|
||||
|
||||
public ExplosionAction ExplosionAction { get; set; }
|
||||
|
@ -44,7 +44,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public Sound Sound { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool ExplodeOnSpace { get; set; }
|
||||
|
||||
public ExplosionAction ExplosionAction { get; set; }
|
||||
|
@ -12,7 +12,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
public int Time { get; set; }
|
||||
|
||||
[BinaryMember(BooleanFormat = BinaryBooleanFormat.NonZeroDword)]
|
||||
[BinaryMember(BooleanCoding = BooleanCoding.Dword)]
|
||||
public bool StayBetweenTurns { get; set; }
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using Syroot.BinaryData;
|
||||
|
||||
namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
@ -7,7 +8,8 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
{
|
||||
// ---- METHODS (PUBLIC) ---------------------------------------------------------------------------------------
|
||||
|
||||
public object Read(BinaryDataReader reader, object instance, BinaryMemberAttribute memberAttribute)
|
||||
public object Read(Stream stream, object instance, BinaryMemberAttribute memberAttribute,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
ExplosionTarget explosionTarget;
|
||||
switch (instance)
|
||||
@ -22,16 +24,17 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
switch (explosionTarget)
|
||||
{
|
||||
case ExplosionTarget.Clusters:
|
||||
return reader.ReadObject<ClusterTarget>();
|
||||
return stream.ReadObject<ClusterTarget>();
|
||||
case ExplosionTarget.Fire:
|
||||
return reader.ReadObject<FireTarget>();
|
||||
return stream.ReadObject<FireTarget>();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void Write(BinaryDataWriter writer, object instance, BinaryMemberAttribute memberAttribute, object value)
|
||||
public void Write(Stream stream, object instance, BinaryMemberAttribute memberAttribute, object value,
|
||||
ByteConverter byteConverter)
|
||||
{
|
||||
writer.WriteObject(value);
|
||||
stream.WriteObject(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -113,7 +113,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
long offset = reader.Position;
|
||||
@ -122,10 +122,10 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
// Read general settings.
|
||||
TableRow = reader.ReadInt32();
|
||||
Remembered = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
UsableInCavern = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
Remembered = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
UsableInCavern = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
Shots = reader.ReadInt32();
|
||||
ShotEndsTurn = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
ShotEndsTurn = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
RetreatTime = reader.ReadInt32();
|
||||
Unknown1 = reader.ReadInt32();
|
||||
CrateChance = reader.ReadInt32();
|
||||
@ -239,34 +239,34 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
// Read additional settings.
|
||||
reader.Position = offset + 468;
|
||||
AmmunitionOverride = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
AmmunitionOverride = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
Ammunition = reader.ReadInt32();
|
||||
Unknown3 = reader.ReadInt32();
|
||||
WeaponSprite = reader.ReadInt32();
|
||||
NameLong = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
Name = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
GridImageFile = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
GfxDirectoryFile = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
SpriteNames = reader.ReadStrings(5, BinaryStringFormat.DwordLengthPrefix);
|
||||
DelayOverride = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
NameLong = reader.ReadString(StringCoding.Int32CharCount);
|
||||
Name = reader.ReadString(StringCoding.Int32CharCount);
|
||||
GridImageFile = reader.ReadString(StringCoding.Int32CharCount);
|
||||
GfxDirectoryFile = reader.ReadString(StringCoding.Int32CharCount);
|
||||
SpriteNames = reader.ReadStrings(5, StringCoding.Int32CharCount);
|
||||
DelayOverride = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
Delay = reader.ReadInt32();
|
||||
|
||||
UseLibrary = reader.ReadBoolean();
|
||||
if (UseLibrary)
|
||||
{
|
||||
LibraryName = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
LibraryWeaponName = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
LibraryName = reader.ReadString(StringCoding.Int32CharCount);
|
||||
LibraryWeaponName = reader.ReadString(StringCoding.Int32CharCount);
|
||||
}
|
||||
|
||||
AimSpriteEven = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
AimSpriteUphill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
AimSpriteDownhill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
PickSpriteEven = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
PickSpriteUphill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
PickSpriteDownhill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
FireSpriteEven = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
FireSpriteUphill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
FireSpriteDownhill = reader.ReadString(BinaryStringFormat.DwordLengthPrefix);
|
||||
AimSpriteEven = reader.ReadString(StringCoding.Int32CharCount);
|
||||
AimSpriteUphill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
AimSpriteDownhill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
PickSpriteEven = reader.ReadString(StringCoding.Int32CharCount);
|
||||
PickSpriteUphill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
PickSpriteDownhill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
FireSpriteEven = reader.ReadString(StringCoding.Int32CharCount);
|
||||
FireSpriteUphill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
FireSpriteDownhill = reader.ReadString(StringCoding.Int32CharCount);
|
||||
AimSpriteOverride = reader.ReadBoolean();
|
||||
PickSpriteOverride = reader.ReadBoolean();
|
||||
FireSpriteOverride = reader.ReadBoolean();
|
||||
@ -283,19 +283,19 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Write the header.
|
||||
long offset = writer.Position;
|
||||
writer.Write(Version, true);
|
||||
writer.WriteEnum(Version, true);
|
||||
writer.Write(Checksum);
|
||||
|
||||
// Write the general settings.
|
||||
writer.Write(TableRow);
|
||||
writer.Write(Remembered, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(UsableInCavern, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(Remembered, BooleanCoding.Dword);
|
||||
writer.Write(UsableInCavern, BooleanCoding.Dword);
|
||||
writer.Write(Shots);
|
||||
writer.Write(ShotEndsTurn, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(ShotEndsTurn, BooleanCoding.Dword);
|
||||
writer.Write(RetreatTime);
|
||||
writer.Write(Unknown1);
|
||||
writer.Write(CrateChance);
|
||||
@ -303,7 +303,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
writer.Write(Unknown2);
|
||||
|
||||
// Write the activation and the corresponding weapon settings.
|
||||
writer.Write(Activation, true);
|
||||
writer.WriteEnum(Activation, true);
|
||||
switch (Activation)
|
||||
{
|
||||
case WeaponActivation.Airstrike:
|
||||
@ -312,14 +312,14 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
break;
|
||||
case WeaponActivation.Crosshair:
|
||||
writer.Write(NotUsed);
|
||||
writer.Write(CrosshairAction, true);
|
||||
writer.WriteEnum(CrosshairAction, true);
|
||||
if (CrosshairAction != WeaponCrosshairAction.None)
|
||||
{
|
||||
writer.WriteObject(Style);
|
||||
}
|
||||
break;
|
||||
case WeaponActivation.Spacebar:
|
||||
writer.Write(SpacebarAction, true);
|
||||
writer.WriteEnum(SpacebarAction, true);
|
||||
switch (SpacebarAction)
|
||||
{
|
||||
case WeaponSpacebarAction.Armageddon:
|
||||
@ -342,7 +342,7 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
break;
|
||||
case WeaponActivation.Throw:
|
||||
writer.Write(ThrowHerdCount);
|
||||
writer.Write(ThrowAction, true);
|
||||
writer.WriteEnum(ThrowAction, true);
|
||||
if (ThrowAction != WeaponThrowAction.None)
|
||||
{
|
||||
writer.WriteObject(Style);
|
||||
@ -352,34 +352,34 @@ namespace Syroot.Worms.Gen2.Armageddon.ProjectX
|
||||
|
||||
// Write additional settings.
|
||||
writer.Position = offset + 468;
|
||||
writer.Write(AmmunitionOverride, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(AmmunitionOverride, BooleanCoding.Dword);
|
||||
writer.Write(Ammunition);
|
||||
writer.Write(Unknown3);
|
||||
writer.Write(WeaponSprite);
|
||||
writer.Write(NameLong, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(Name, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(GridImageFile, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(GfxDirectoryFile, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(SpriteNames, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(DelayOverride, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(NameLong, StringCoding.Int32CharCount);
|
||||
writer.Write(Name, StringCoding.Int32CharCount);
|
||||
writer.Write(GridImageFile, StringCoding.Int32CharCount);
|
||||
writer.Write(GfxDirectoryFile, StringCoding.Int32CharCount);
|
||||
writer.Write(SpriteNames, StringCoding.Int32CharCount);
|
||||
writer.Write(DelayOverride, BooleanCoding.Dword);
|
||||
writer.Write(Delay);
|
||||
|
||||
writer.Write(UseLibrary);
|
||||
if (UseLibrary)
|
||||
{
|
||||
writer.Write(LibraryName, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(LibraryWeaponName, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(LibraryName, StringCoding.Int32CharCount);
|
||||
writer.Write(LibraryWeaponName, StringCoding.Int32CharCount);
|
||||
}
|
||||
|
||||
writer.Write(AimSpriteEven, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(AimSpriteUphill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(AimSpriteDownhill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(PickSpriteEven, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(PickSpriteUphill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(PickSpriteDownhill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(FireSpriteEven, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(FireSpriteUphill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(FireSpriteDownhill, BinaryStringFormat.DwordLengthPrefix);
|
||||
writer.Write(AimSpriteEven, StringCoding.Int32CharCount);
|
||||
writer.Write(AimSpriteUphill, StringCoding.Int32CharCount);
|
||||
writer.Write(AimSpriteDownhill, StringCoding.Int32CharCount);
|
||||
writer.Write(PickSpriteEven, StringCoding.Int32CharCount);
|
||||
writer.Write(PickSpriteUphill, StringCoding.Int32CharCount);
|
||||
writer.Write(PickSpriteDownhill, StringCoding.Int32CharCount);
|
||||
writer.Write(FireSpriteEven, StringCoding.Int32CharCount);
|
||||
writer.Write(FireSpriteUphill, StringCoding.Int32CharCount);
|
||||
writer.Write(FireSpriteDownhill, StringCoding.Int32CharCount);
|
||||
writer.Write(AimSpriteOverride);
|
||||
writer.Write(PickSpriteOverride);
|
||||
writer.Write(FireSpriteOverride);
|
||||
|
@ -608,7 +608,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadString(_signature.Length) != _signature)
|
||||
@ -618,9 +618,9 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
Version = reader.ReadEnum<SchemeVersion>(true);
|
||||
|
||||
// Read the options.
|
||||
HotSeatDelay = reader.ReadByte();
|
||||
RetreatTime = reader.ReadByte();
|
||||
RetreatTimeRope = reader.ReadByte();
|
||||
HotSeatDelay = reader.Read1Byte();
|
||||
RetreatTime = reader.Read1Byte();
|
||||
RetreatTimeRope = reader.Read1Byte();
|
||||
ShowRoundTime = reader.ReadBoolean();
|
||||
AutomaticReplays = reader.ReadBoolean();
|
||||
FallDamage = (SchemeFallDamage)(reader.ReadByte() * 50 % 0x100 * 2);
|
||||
@ -633,13 +633,13 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
WeaponCrateProbability = reader.ReadSByte();
|
||||
DonorCards = reader.ReadBoolean();
|
||||
HealthCrateProbability = reader.ReadSByte();
|
||||
HealthCrateEnergy = reader.ReadByte();
|
||||
HealthCrateEnergy = reader.Read1Byte();
|
||||
UtilityCrateProbability = reader.ReadSByte();
|
||||
LoadObjectTypesAndCount(reader);
|
||||
LoadMineDelayConfig(reader);
|
||||
DudMines = reader.ReadBoolean();
|
||||
ManualWormPlacement = reader.ReadBoolean();
|
||||
WormEnergy = reader.ReadByte();
|
||||
WormEnergy = reader.Read1Byte();
|
||||
LoadTurnTimeConfig(reader);
|
||||
LoadRoundTimeConfig(reader);
|
||||
NumberOfWins = (byte)Math.Max(1, (int)reader.ReadByte());
|
||||
@ -698,10 +698,10 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="format">The <see cref="SchemeSaveFormat"/> to respect when storing the settings.</param>
|
||||
public void Save(Stream stream, SchemeSaveFormat format)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.NoPrefixOrTermination);
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
writer.Write((byte)Version);
|
||||
|
||||
// Write the options.
|
||||
@ -712,10 +712,10 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
writer.Write(AutomaticReplays);
|
||||
writer.Write((byte)((int)FallDamage / 4 * 41 % 0x80));
|
||||
writer.Write(ArtilleryMode);
|
||||
writer.Write(SchemeEditor, false);
|
||||
writer.Write(StockpilingMode, true);
|
||||
writer.Write(WormSelectMode, true);
|
||||
writer.Write(SuddenDeathEvent, true);
|
||||
writer.WriteEnum(SchemeEditor, false);
|
||||
writer.WriteEnum(StockpilingMode, true);
|
||||
writer.WriteEnum(WormSelectMode, true);
|
||||
writer.WriteEnum(SuddenDeathEvent, true);
|
||||
writer.Write(_mapWaterRiseToRaw[(byte)WaterRiseRate]);
|
||||
writer.Write(WeaponCrateProbability);
|
||||
writer.Write(DonorCards);
|
||||
@ -780,13 +780,13 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
private void LoadObjectTypesAndCount(BinaryDataReader reader)
|
||||
private void LoadObjectTypesAndCount(BinaryStream reader)
|
||||
{
|
||||
// Invalid values default to 8 mines.
|
||||
ObjectTypes = SchemeObjectType.Mines;
|
||||
ObjectCount = SchemeObjectCount.Count8;
|
||||
|
||||
byte raw = reader.ReadByte();
|
||||
byte raw = reader.Read1Byte();
|
||||
if (raw < 12)
|
||||
{
|
||||
// WA before 3.6.28.0 and WWP only store object type.
|
||||
@ -823,9 +823,9 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadMineDelayConfig(BinaryDataReader reader)
|
||||
private void LoadMineDelayConfig(BinaryStream reader)
|
||||
{
|
||||
byte raw = reader.ReadByte();
|
||||
byte raw = reader.Read1Byte();
|
||||
if (raw == 4 || raw > 0x7F)
|
||||
{
|
||||
MineDelay = 0;
|
||||
@ -838,9 +838,9 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadTurnTimeConfig(BinaryDataReader reader)
|
||||
private void LoadTurnTimeConfig(BinaryStream reader)
|
||||
{
|
||||
byte raw = reader.ReadByte();
|
||||
byte raw = reader.Read1Byte();
|
||||
if (raw > 0x7F)
|
||||
{
|
||||
TurnTime = 0;
|
||||
@ -853,9 +853,9 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadRoundTimeConfig(BinaryDataReader reader)
|
||||
private void LoadRoundTimeConfig(BinaryStream reader)
|
||||
{
|
||||
byte raw = reader.ReadByte();
|
||||
byte raw = reader.Read1Byte();
|
||||
if (raw > 0x7F)
|
||||
{
|
||||
RoundTimeMinutes = 0;
|
||||
@ -933,7 +933,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
return Version == SchemeVersion.Extended ? 64 : 45;
|
||||
}
|
||||
|
||||
private void SaveObjectTypesAndCount(BinaryDataWriter writer, SchemeSaveFormat format)
|
||||
private void SaveObjectTypesAndCount(BinaryStream writer, SchemeSaveFormat format)
|
||||
{
|
||||
byte raw = 0;
|
||||
if (format == SchemeSaveFormat.ExtendedWithObjectCount)
|
||||
@ -953,7 +953,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
// Get the index of the object count and compute the raw value from that.
|
||||
int index = Array.IndexOf(_objectCounts, (byte)ObjectCount);
|
||||
raw = (byte)(index * 4 + (8 + raw));
|
||||
raw = (byte)(index * 4 + 8 + raw);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -974,7 +974,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
writer.Write(raw);
|
||||
}
|
||||
|
||||
private void SaveMineDelayConfig(BinaryDataWriter writer)
|
||||
private void SaveMineDelayConfig(BinaryStream writer)
|
||||
{
|
||||
if (MineDelayRandom)
|
||||
{
|
||||
@ -986,7 +986,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveTurnTimeConfig(BinaryDataWriter writer)
|
||||
private void SaveTurnTimeConfig(BinaryStream writer)
|
||||
{
|
||||
if (TurnTimeInfinite)
|
||||
{
|
||||
@ -998,7 +998,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
}
|
||||
}
|
||||
|
||||
private void SaveRoundTimeConfig(BinaryDataWriter writer)
|
||||
private void SaveRoundTimeConfig(BinaryStream writer)
|
||||
{
|
||||
if (RoundTimeSeconds > 0)
|
||||
{
|
||||
|
@ -196,15 +196,15 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
Name = reader.ReadFixedString(17);
|
||||
WormNames = reader.ReadFixedStrings(8, 17);
|
||||
CpuLevel = reader.ReadByte();
|
||||
CpuLevel = reader.Read1Byte();
|
||||
SoundBankName = reader.ReadFixedString(0x20);
|
||||
SoundBankLocation = reader.ReadByte();
|
||||
SoundBankLocation = reader.Read1Byte();
|
||||
FanfareName = reader.ReadFixedString(0x20);
|
||||
UseCustomFanfare = reader.ReadByte();
|
||||
UseCustomFanfare = reader.Read1Byte();
|
||||
|
||||
GraveSprite = reader.ReadSByte();
|
||||
if (GraveSprite < 0)
|
||||
@ -241,13 +241,13 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
Data = reader.ReadBytes(20 * 17)
|
||||
};
|
||||
|
||||
DeathmatchRank = reader.ReadByte();
|
||||
DeathmatchRank = reader.Read1Byte();
|
||||
TrainingMissionTimes = reader.ReadInt32s(_trainingMissionCount);
|
||||
Unknown1 = reader.ReadInt32s(10);
|
||||
TrainingMissionMedals = reader.ReadBytes(_trainingMissionCount);
|
||||
Unknown2 = reader.ReadBytes(10);
|
||||
Unknown3 = reader.ReadInt32s(7);
|
||||
Unknown4 = reader.ReadByte();
|
||||
Unknown4 = reader.Read1Byte();
|
||||
}
|
||||
}
|
||||
|
||||
@ -257,7 +257,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
writer.Write(Name, 17);
|
||||
writer.Write(WormNames, 17);
|
||||
@ -275,7 +275,7 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
writer.Write(Grave.Data);
|
||||
}
|
||||
|
||||
writer.Write(TeamWeapon, true);
|
||||
writer.WriteEnum(TeamWeapon, true);
|
||||
writer.Write(GamesLost);
|
||||
writer.Write(DeathmatchesLost);
|
||||
writer.Write(GamesWon);
|
||||
|
@ -76,19 +76,19 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadString(BinaryStringFormat.ZeroTerminated) != _signature)
|
||||
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
|
||||
{
|
||||
throw new InvalidDataException("Invalid WGT file signature.");
|
||||
}
|
||||
Version = reader.ReadByte(); // Really version?
|
||||
Version = reader.Read1Byte(); // Really version?
|
||||
|
||||
// Read global settings.
|
||||
byte teamCount = reader.ReadByte();
|
||||
byte teamCount = reader.Read1Byte();
|
||||
UnlockedFeatures = reader.ReadEnum<UnlockedFeatures>(false);
|
||||
Unknown = reader.ReadByte();
|
||||
Unknown = reader.Read1Byte();
|
||||
|
||||
// Read the teams.
|
||||
Teams = new List<Team>(reader.Load<Team>(teamCount));
|
||||
@ -113,15 +113,15 @@ namespace Syroot.Worms.Gen2.Armageddon
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(_signature, StringCoding.ZeroTerminated);
|
||||
writer.Write(Version);
|
||||
|
||||
// Write global settings.
|
||||
writer.Write((byte)Teams.Count);
|
||||
writer.Write(UnlockedFeatures, false);
|
||||
writer.WriteEnum(UnlockedFeatures, false);
|
||||
writer.Write(Unknown);
|
||||
|
||||
// Write the teams.
|
||||
|
@ -133,7 +133,7 @@ namespace Syroot.Worms.Gen2
|
||||
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
|
||||
internal void Load(Stream stream, bool alignData)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
@ -143,16 +143,16 @@ namespace Syroot.Worms.Gen2
|
||||
int fileSize = reader.ReadInt32();
|
||||
|
||||
// Read an optional string describing the image contents and the bits per pixel.
|
||||
BitsPerPixel = reader.ReadByte();
|
||||
BitsPerPixel = reader.Read1Byte();
|
||||
if (BitsPerPixel == 0)
|
||||
{
|
||||
Description = String.Empty;
|
||||
BitsPerPixel = reader.ReadByte();
|
||||
BitsPerPixel = reader.Read1Byte();
|
||||
}
|
||||
else if (BitsPerPixel > 32)
|
||||
{
|
||||
Description = (char)BitsPerPixel + reader.ReadString(BinaryStringFormat.ZeroTerminated);
|
||||
BitsPerPixel = reader.ReadByte();
|
||||
Description = (char)BitsPerPixel + reader.ReadString(StringCoding.ZeroTerminated);
|
||||
BitsPerPixel = reader.Read1Byte();
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -170,7 +170,7 @@ namespace Syroot.Worms.Gen2
|
||||
Palette[0] = Color.Black;
|
||||
for (int i = 1; i <= colorCount; i++)
|
||||
{
|
||||
Palette[i] = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
|
||||
Palette[i] = new Color(reader.Read1Byte(), reader.Read1Byte(), reader.Read1Byte());
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -222,16 +222,16 @@ namespace Syroot.Worms.Gen2
|
||||
/// <param name="alignData"><c>true</c> to align the data array by 4 bytes.</param>
|
||||
internal void Save(Stream stream, bool compress, bool alignData)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
|
||||
// Write an optional string describing the image contents and the bits per pixel.
|
||||
if (Description != null)
|
||||
{
|
||||
writer.Write(Description, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(Description, StringCoding.ZeroTerminated);
|
||||
}
|
||||
writer.Write(BitsPerPixel);
|
||||
|
||||
@ -245,7 +245,7 @@ namespace Syroot.Worms.Gen2
|
||||
{
|
||||
flags |= Flags.Compressed;
|
||||
}
|
||||
writer.Write(flags, true);
|
||||
writer.WriteEnum(flags, true);
|
||||
|
||||
// Write the image palette if available. The first color of the palette is implicitly black.
|
||||
if (Palette != null)
|
||||
@ -276,7 +276,7 @@ namespace Syroot.Worms.Gen2
|
||||
}
|
||||
writer.Write(data);
|
||||
|
||||
fileSizeOffset.Satisfy();
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -119,7 +119,7 @@ namespace Syroot.Worms.Gen2
|
||||
// ---- METHODS (PRIVATE) --------------------------------------------------------------------------------------
|
||||
|
||||
[RiffChunkLoad("data")]
|
||||
private void LoadDataChunk(BinaryDataReader reader, int length)
|
||||
private void LoadDataChunk(BinaryStream reader, int length)
|
||||
{
|
||||
// Read the PAL version.
|
||||
Version = reader.ReadInt16();
|
||||
@ -132,31 +132,31 @@ namespace Syroot.Worms.Gen2
|
||||
Colors = new Color[reader.ReadInt16()];
|
||||
for (int i = 0; i < Colors.Length; i++)
|
||||
{
|
||||
Colors[i] = new Color(reader.ReadByte(), reader.ReadByte(), reader.ReadByte());
|
||||
Colors[i] = new Color(reader.Read1Byte(), reader.Read1Byte(), reader.Read1Byte());
|
||||
int alpha = reader.ReadByte(); // Dismiss alpha, as it is not used in WA.
|
||||
}
|
||||
}
|
||||
|
||||
[RiffChunkLoad("offl")]
|
||||
private void LoadOfflChunk(BinaryDataReader reader, int length)
|
||||
private void LoadOfflChunk(BinaryStream reader, int length)
|
||||
{
|
||||
OfflData = reader.ReadBytes(length);
|
||||
}
|
||||
|
||||
[RiffChunkLoad("tran")]
|
||||
private void LoadTranChunk(BinaryDataReader reader, int length)
|
||||
private void LoadTranChunk(BinaryStream reader, int length)
|
||||
{
|
||||
TranData = reader.ReadBytes(length);
|
||||
}
|
||||
|
||||
[RiffChunkLoad("unde")]
|
||||
private void LoadUndeChunk(BinaryDataReader reader, int length)
|
||||
private void LoadUndeChunk(BinaryStream reader, int length)
|
||||
{
|
||||
UndeData = reader.ReadBytes(length);
|
||||
}
|
||||
|
||||
[RiffChunkSave("data")]
|
||||
private void SaveDataChunk(BinaryDataWriter writer)
|
||||
private void SaveDataChunk(BinaryStream writer)
|
||||
{
|
||||
// Write the PAL version.
|
||||
writer.Write(_version);
|
||||
@ -174,19 +174,19 @@ namespace Syroot.Worms.Gen2
|
||||
}
|
||||
|
||||
[RiffChunkSave("offl")]
|
||||
private void SaveOfflChunk(BinaryDataWriter writer)
|
||||
private void SaveOfflChunk(BinaryStream writer)
|
||||
{
|
||||
writer.Write(OfflData);
|
||||
}
|
||||
|
||||
[RiffChunkSave("tran")]
|
||||
private void SaveTranChunk(BinaryDataWriter writer)
|
||||
private void SaveTranChunk(BinaryStream writer)
|
||||
{
|
||||
writer.Write(TranData);
|
||||
}
|
||||
|
||||
[RiffChunkSave("unde")]
|
||||
private void SaveUndeChunk(BinaryDataWriter writer)
|
||||
private void SaveUndeChunk(BinaryStream writer)
|
||||
{
|
||||
writer.Write(UndeData);
|
||||
}
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Syroot.BinaryData;
|
||||
@ -100,7 +99,7 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
@ -111,7 +110,7 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
|
||||
// Read the data.
|
||||
Size = reader.ReadStruct<Vector2>();
|
||||
TopBorder = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
TopBorder = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WaterHeight = reader.ReadInt32();
|
||||
|
||||
// Read the possible object coordinate array.
|
||||
@ -123,8 +122,8 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
Background = new ImageData(stream, true);
|
||||
|
||||
// Read the file paths.
|
||||
LandTexturePath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
WaterDirPath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -146,15 +145,15 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
|
||||
// Write the data.
|
||||
writer.Write(Size);
|
||||
writer.Write(TopBorder, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(TopBorder, BooleanCoding.Dword);
|
||||
writer.Write(WaterHeight);
|
||||
|
||||
// Write the possible object coordinate array.
|
||||
@ -167,10 +166,10 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
Background.Save(writer.BaseStream, false, true);
|
||||
|
||||
// Write the file paths.
|
||||
writer.Write(LandTexturePath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(WaterDirPath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(LandTexturePath, StringCoding.ByteCharCount);
|
||||
writer.Write(WaterDirPath, StringCoding.ByteCharCount);
|
||||
|
||||
fileSizeOffset.Satisfy();
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -195,15 +195,15 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
Name = reader.ReadFixedString(17);
|
||||
WormNames = reader.ReadFixedStrings(8, 17);
|
||||
CpuLevel = reader.ReadByte();
|
||||
CpuLevel = reader.Read1Byte();
|
||||
SoundBankName = reader.ReadFixedString(0x20);
|
||||
SoundBankLocation = reader.ReadByte();
|
||||
SoundBankLocation = reader.Read1Byte();
|
||||
FanfareName = reader.ReadFixedString(0x20);
|
||||
UseCustomFanfare = reader.ReadByte();
|
||||
UseCustomFanfare = reader.Read1Byte();
|
||||
|
||||
GraveSprite = reader.ReadSByte();
|
||||
if (GraveSprite < 0)
|
||||
@ -240,11 +240,11 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
Data = reader.ReadBytes(20 * 17)
|
||||
};
|
||||
|
||||
Unknown1 = reader.ReadByte();
|
||||
DeathmatchRank = reader.ReadByte();
|
||||
Unknown1 = reader.Read1Byte();
|
||||
DeathmatchRank = reader.Read1Byte();
|
||||
TrainingMissionTimes = reader.ReadInt32s(_trainingMissionCount);
|
||||
WeaponPoints = reader.ReadBytes(46);
|
||||
Fort = reader.ReadByte();
|
||||
Fort = reader.Read1Byte();
|
||||
Unknown2 = reader.ReadInt32s(7);
|
||||
}
|
||||
}
|
||||
@ -255,7 +255,7 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
writer.Write(Name, 17);
|
||||
writer.Write(WormNames, 17);
|
||||
@ -273,7 +273,7 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
writer.Write(Grave.Data);
|
||||
}
|
||||
|
||||
writer.Write(TeamWeapon, true);
|
||||
writer.WriteEnum(TeamWeapon, true);
|
||||
writer.Write(GamesLost);
|
||||
writer.Write(DeathmatchesLost);
|
||||
writer.Write(GamesWon);
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
@ -81,19 +80,19 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadString(BinaryStringFormat.ZeroTerminated) != _signature)
|
||||
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
|
||||
{
|
||||
throw new InvalidDataException("Invalid WWP file signature.");
|
||||
}
|
||||
Version = reader.ReadByte(); // Really version?
|
||||
Version = reader.Read1Byte(); // Really version?
|
||||
|
||||
// Read global settings.
|
||||
byte teamCount = reader.ReadByte();
|
||||
Unknown1 = reader.ReadByte();
|
||||
Unknown2 = reader.ReadByte();
|
||||
byte teamCount = reader.Read1Byte();
|
||||
Unknown1 = reader.Read1Byte();
|
||||
Unknown2 = reader.Read1Byte();
|
||||
Unknown3 = reader.ReadBytes(840);
|
||||
|
||||
// Read the teams.
|
||||
@ -119,10 +118,10 @@ namespace Syroot.Worms.Gen2.WorldParty
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(_signature, StringCoding.ZeroTerminated);
|
||||
writer.Write(Version);
|
||||
|
||||
// Write global settings.
|
||||
|
@ -104,7 +104,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadInt32() != _signature)
|
||||
@ -115,7 +115,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
|
||||
// Read the data.
|
||||
Size = reader.ReadStruct<Vector2>();
|
||||
TopBorder = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
TopBorder = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
|
||||
// Read the possible object coordinate array.
|
||||
ObjectLocations = reader.ReadStructs<Vector2>(reader.ReadInt32());
|
||||
@ -128,8 +128,8 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
UnknownImage = reader.Load<ImageData>();
|
||||
|
||||
// Read the file paths.
|
||||
LandTexturePath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
WaterDirPath = reader.ReadString(BinaryStringFormat.ByteLengthPrefix);
|
||||
LandTexturePath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
WaterDirPath = reader.ReadString(StringCoding.ByteCharCount);
|
||||
}
|
||||
}
|
||||
|
||||
@ -151,15 +151,15 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature);
|
||||
Offset fileSizeOffset = writer.ReserveOffset();
|
||||
uint fileSizeOffset = writer.ReserveOffset();
|
||||
|
||||
// Write the data.
|
||||
writer.Write(Size);
|
||||
writer.Write(TopBorder, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(TopBorder, BooleanCoding.Dword);
|
||||
|
||||
// Write the possible object coordinate array.
|
||||
writer.Write(ObjectLocations.Length);
|
||||
@ -173,10 +173,10 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
UnknownImage.Save(writer.BaseStream);
|
||||
|
||||
// Write the file paths.
|
||||
writer.Write(LandTexturePath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(WaterDirPath, BinaryStringFormat.ByteLengthPrefix);
|
||||
writer.Write(LandTexturePath, StringCoding.ByteCharCount);
|
||||
writer.Write(WaterDirPath, StringCoding.ByteCharCount);
|
||||
|
||||
fileSizeOffset.Satisfy();
|
||||
writer.SatisfyOffset(fileSizeOffset, (int)writer.Position);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -221,7 +221,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
if (reader.ReadString(_signature.Length) != _signature)
|
||||
@ -236,35 +236,35 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
RetreatTimeRope = reader.ReadInt32();
|
||||
ObjectCount = reader.ReadInt32();
|
||||
MineDelay = reader.ReadInt32();
|
||||
DudMines = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
DudMines = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WindPower = reader.ReadInt32();
|
||||
Friction = reader.ReadInt32();
|
||||
ReplayRequiredKills = reader.ReadInt32();
|
||||
ReplayRequiredDamage = reader.ReadInt32();
|
||||
AutomaticReplays = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
AutomaticReplays = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
FallDamage = reader.ReadInt32();
|
||||
RopeSwings = reader.ReadInt32();
|
||||
ShowRoundTime = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
ShowRoundTime = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WaterRiseRate = reader.ReadInt32();
|
||||
SuddenDeathHealthDrop = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
IndestructibleBorder = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
RestrictGirders = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
SuddenDeathHealthDrop = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
IndestructibleBorder = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
RestrictGirders = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WormSelectMode = reader.ReadEnum<SchemeWormSelect>(true);
|
||||
ExtendedChatControls = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
ExtendedChatControls = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
HotSeatDelay = reader.ReadInt32();
|
||||
EnableStockpiling = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
EnableStockpiling = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
CrateProbability = reader.ReadInt32();
|
||||
CrateIntelligence = reader.ReadInt32();
|
||||
HealthCrateEnergy = reader.ReadInt32();
|
||||
BoobyTraps = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
EnableSuperWeapons = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
BoobyTraps = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
EnableSuperWeapons = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
WormEnergy = reader.ReadInt32();
|
||||
ArtilleryMode = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
SuddenDeathDisableWormSelect = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
ArtilleryMode = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
SuddenDeathDisableWormSelect = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
// The following option does not exist in all schemes.
|
||||
if (!reader.EndOfStream)
|
||||
{
|
||||
UseOilDrums = reader.ReadBoolean(BinaryBooleanFormat.NonZeroDword);
|
||||
UseOilDrums = reader.ReadBoolean(BooleanCoding.Dword);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -287,10 +287,10 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(_signature, BinaryStringFormat.NoPrefixOrTermination);
|
||||
writer.Write(_signature, StringCoding.Raw);
|
||||
|
||||
// Write the options.
|
||||
writer.Write(RoundTime);
|
||||
@ -299,32 +299,32 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
writer.Write(RetreatTimeRope);
|
||||
writer.Write(ObjectCount);
|
||||
writer.Write(MineDelay);
|
||||
writer.Write(DudMines, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(DudMines, BooleanCoding.Dword);
|
||||
writer.Write(WindPower);
|
||||
writer.Write(Friction);
|
||||
writer.Write(ReplayRequiredKills);
|
||||
writer.Write(ReplayRequiredDamage);
|
||||
writer.Write(AutomaticReplays, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(AutomaticReplays, BooleanCoding.Dword);
|
||||
writer.Write(FallDamage);
|
||||
writer.Write(RopeSwings);
|
||||
writer.Write(ShowRoundTime, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(ShowRoundTime, BooleanCoding.Dword);
|
||||
writer.Write(WaterRiseRate);
|
||||
writer.Write(SuddenDeathHealthDrop, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(IndestructibleBorder, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(RestrictGirders, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(WormSelectMode, true);
|
||||
writer.Write(ExtendedChatControls, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(SuddenDeathHealthDrop, BooleanCoding.Dword);
|
||||
writer.Write(IndestructibleBorder, BooleanCoding.Dword);
|
||||
writer.Write(RestrictGirders, BooleanCoding.Dword);
|
||||
writer.WriteEnum(WormSelectMode, true);
|
||||
writer.Write(ExtendedChatControls, BooleanCoding.Dword);
|
||||
writer.Write(HotSeatDelay);
|
||||
writer.Write(EnableStockpiling, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(EnableStockpiling, BooleanCoding.Dword);
|
||||
writer.Write(CrateProbability);
|
||||
writer.Write(CrateIntelligence);
|
||||
writer.Write(HealthCrateEnergy);
|
||||
writer.Write(BoobyTraps, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(EnableSuperWeapons, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(BoobyTraps, BooleanCoding.Dword);
|
||||
writer.Write(EnableSuperWeapons, BooleanCoding.Dword);
|
||||
writer.Write(WormEnergy);
|
||||
writer.Write(ArtilleryMode, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(SuddenDeathDisableWormSelect, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(UseOilDrums, BinaryBooleanFormat.NonZeroDword);
|
||||
writer.Write(ArtilleryMode, BooleanCoding.Dword);
|
||||
writer.Write(SuddenDeathDisableWormSelect, BooleanCoding.Dword);
|
||||
writer.Write(UseOilDrums, BooleanCoding.Dword);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -62,11 +62,11 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
// Read the header.
|
||||
reader.Seek(_trashLength);
|
||||
if (reader.ReadString(BinaryStringFormat.ZeroTerminated) != _signature)
|
||||
if (reader.ReadString(StringCoding.ZeroTerminated) != _signature)
|
||||
{
|
||||
throw new InvalidDataException("Invalid WEP file signature.");
|
||||
}
|
||||
@ -98,11 +98,11 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
// Write the header.
|
||||
writer.Write(new byte[_trashLength]);
|
||||
writer.Write(_signature, BinaryStringFormat.ZeroTerminated);
|
||||
writer.Write(_signature, StringCoding.ZeroTerminated);
|
||||
|
||||
// Write the weapon settings.
|
||||
foreach (SchemeWeaponSetting weapon in Weapons)
|
||||
|
@ -1,4 +1,3 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using Syroot.BinaryData;
|
||||
@ -110,7 +109,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
Unknown1 = reader.ReadInt16();
|
||||
Name = reader.ReadFixedString(66);
|
||||
@ -162,7 +161,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
writer.Write(Unknown1);
|
||||
writer.Write(Name, 66);
|
||||
|
@ -56,7 +56,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to load the data from.</param>
|
||||
public void Load(Stream stream)
|
||||
{
|
||||
using (BinaryDataReader reader = new BinaryDataReader(stream, Encoding.ASCII, true))
|
||||
using (BinaryStream reader = new BinaryStream(stream, encoding: Encoding.ASCII, leaveOpen: true))
|
||||
{
|
||||
Teams = new List<Team>();
|
||||
while (!reader.EndOfStream)
|
||||
@ -84,7 +84,7 @@ namespace Syroot.Worms.Gen2.Worms2
|
||||
/// <param name="stream">The <see cref="Stream"/> to save the data to.</param>
|
||||
public void Save(Stream stream)
|
||||
{
|
||||
using (BinaryDataWriter writer = new BinaryDataWriter(stream, Encoding.ASCII))
|
||||
using (BinaryStream writer = new BinaryStream(stream, encoding: Encoding.ASCII))
|
||||
{
|
||||
foreach (Team team in Teams)
|
||||
{
|
||||
|
@ -1,41 +1,24 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<Description>.NET library to load and modify file formats of Team17 Worms games.</Description>
|
||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||
<AssemblyName>Syroot.Worms</AssemblyName>
|
||||
<AssemblyTitle>Worms</AssemblyTitle>
|
||||
<Authors>Syroot</Authors>
|
||||
<VersionPrefix>1.0.0-alpha3</VersionPrefix>
|
||||
|
||||
<PackageId>Syroot.Worms</PackageId>
|
||||
<PackageTags>worms;team17</PackageTags>
|
||||
<PackageReleaseNotes>Initial release.</PackageReleaseNotes>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/Syroot/Worms/master/res/Logo.png</PackageIconUrl>
|
||||
<PackageProjectUrl>https://github.com/Syroot/Worms</PackageProjectUrl>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/Syroot/Worms/master/LICENSE</PackageLicenseUrl>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/Syroot/Worms</RepositoryUrl>
|
||||
|
||||
<TargetFrameworks>net46;netstandard1.6</TargetFrameworks>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Syroot.IO.BinaryData" Version="2.0.0-rc1" />
|
||||
<PackageReference Include="Syroot.Maths" Version="1.3.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup Condition="'$(TargetFramework)' == 'net46'">
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
|
||||
<DebugType>portable</DebugType>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
|
||||
<DebugType>none</DebugType>
|
||||
<GenerateDocumentationFile>true</GenerateDocumentationFile>
|
||||
</PropertyGroup>
|
||||
|
||||
<PropertyGroup>
|
||||
<AssemblyName>Syroot.Worms</AssemblyName>
|
||||
<AssemblyTitle>Worms</AssemblyTitle>
|
||||
<Authors>Syroot</Authors>
|
||||
<Copyright>(c) Syroot, licensed under MIT</Copyright>
|
||||
<Description>.NET library to load and modify file formats of Team17 Worms games.</Description>
|
||||
<PackageIconUrl>https://raw.githubusercontent.com/Syroot/Worms/master/res/Logo.png</PackageIconUrl>
|
||||
<PackageId>Syroot.Worms</PackageId>
|
||||
<PackageLicenseUrl>https://raw.githubusercontent.com/Syroot/Worms/master/LICENSE</PackageLicenseUrl>
|
||||
<PackageProjectUrl>https://github.com/Syroot/Worms</PackageProjectUrl>
|
||||
<PackageReleaseNotes>Initial release.</PackageReleaseNotes>
|
||||
<PackageTags>worms;team17</PackageTags>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<RepositoryUrl>https://github.com/Syroot/Worms</RepositoryUrl>
|
||||
<TargetFrameworks>net461;netstandard2</TargetFrameworks>
|
||||
<VersionPrefix>1.0.0</VersionPrefix>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Syroot.BinaryData.Serialization" Version="5.0.0" />
|
||||
<PackageReference Include="Syroot.Maths" Version="1.5.1" />
|
||||
<PackageReference Include="Syroot.BinaryData" Version="5.0.0" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
x
Reference in New Issue
Block a user