Add support for loading and saving Scheme files.

This commit is contained in:
Ray Koopa 2017-04-21 15:35:28 +02:00
parent ddcd41df6f
commit 12f1c4925a
7 changed files with 3021 additions and 34 deletions

View File

@ -21,7 +21,6 @@ Formats of the second generation 2D games are mostly focused right now.
| Description | Extension | Games | Load | Save |
|-------------------|:---------:|:-----------:|:----:|:----:|
| Archive | DIR | W2, WA, WWP | Yes | Yes |
| Game Scheme | WSC | WA, WWP | No | No |
| Image | IMG | W2, WA, WWP | Yes | No |
| Mission | DAT | W2 | No | No |
| Mission | WAM | WA, WWP | No | No |
@ -32,6 +31,7 @@ Formats of the second generation 2D games are mostly focused right now.
| Project X Library | PXL | WA+PX | No | No |
| Project X Scheme | PXS | WA+PX | No | No |
| Replay | WAGAME | WA | No | No |
| Scheme | WSC | WA, WWP | Yes | Yes |
| Team Container | ST1 | W2 | No | No |
| Team Container | WGT | WA, WWP | No | No |
| Weapon Scheme | WEP | W2 | No | No |

View File

@ -1,7 +1,8 @@
using System;
using System.IO;
using Syroot.Worms.Gen2;
using System.Collections.Generic;
using Syroot.Worms.Gen2.Armageddon;
using Syroot.Worms.Core;
namespace Syroot.Worms.Test
{
@ -33,16 +34,8 @@ namespace Syroot.Worms.Test
// Console.WriteLine("Loading {imgFile}...");
// Image image = new Image(imgFile);
//}
Palette pal = new Palette(@"C:\Games\Worms Armageddon 3.7.2.1\graphics\ServerLobby\flagsandwormnet.pal");
pal.Save(@"D:\Pictures\test.pal");
foreach (string palFile in GetFiles(" *.pal"))
{
Console.WriteLine($"Loading {palFile}...");
Palette palette = new Palette(palFile);
palette.Save(@"D:\Pictures\test.pal");
}
Scheme scheme = new Scheme(@"D:\Pictures\Test.wsc");
scheme.Save(@"D:\Pictures\Test2.wsc");
Console.ReadLine();
}

View File

@ -1,7 +1,7 @@
namespace Syroot.Worms.Core
{
/// <summary>
/// Represents extension methods for byte array instances.
/// Represents extension methods for <see cref="Byte"/> array instances.
/// </summary>
internal static class ByteArrayExtensions
{

View File

@ -0,0 +1,226 @@
namespace Syroot.Worms.Core
{
/// <summary>
/// Represents extension methods for <see cref="Byte"/> instances.
/// </summary>
internal static class ByteExtensions
{
// ---- METHODS (INTERNAL) -------------------------------------------------------------------------------------
/// <summary>
/// Returns the current byte with the bit at the <paramref name="index"/> set (being 1).
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="index">The 0-based index of the bit to enable.</param>
/// <returns>The current byte with the bit enabled.</returns>
internal static byte EnableBit(this byte self, int index)
{
return (byte)(self | (1 << index));
}
/// <summary>
/// Returns the current byte with the bit at the <paramref name="index"/> cleared (being 0).
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="index">The 0-based index of the bit to disable.</param>
/// <returns>The current byte with the bit disabled.</returns>
internal static byte DisableBit(this byte self, int index)
{
return (byte)(self & ~(1 << index));
}
/// <summary>
/// Returns a value indicating whether the bit at the <paramref name="index"/> in the current byte is enabled
/// or disabled.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="index">The 0-based index of the bit to check.</param>
/// <returns><c>true</c> when the bit is set; otherwise <c>false</c>.</returns>
internal static bool GetBit(this byte self, int index)
{
return (self & (1 << index)) != 0;
}
/// <summary>
/// Returns the current byte with all bits rotated in the given <paramref name="direction"/>, where positive
/// directions rotate left and negative directions rotate right.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="direction">The direction in which to rotate, where positive directions rotate left.</param>
/// <returns>The current byte with the bits rotated.</returns>
internal static byte RotateBits(this byte self, int direction)
{
int bits = sizeof(byte) * 8;
if (direction > 0)
{
return (byte)((self << direction) | (self >> (bits - direction)));
}
else if (direction < 0)
{
direction = -direction;
return (byte)((self >> direction) | (self << (bits - direction)));
}
return self;
}
/// <summary>
/// Returns the current byte with the bit at the <paramref name="index"/> enabled or disabled, according to
/// <paramref name="enable"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="index">The 0-based index of the bit to enable or disable.</param>
/// <param name="enable"><c>true</c> to enable the bit; otherwise <c>false</c>.</param>
/// <returns>The current byte with the bit enabled or disabled.</returns>
internal static byte SetBit(this byte self, int index, bool enable)
{
if (enable)
{
return EnableBit(self, index);
}
else
{
return DisableBit(self, index);
}
}
/// <summary>
/// Returns the current byte with the bit at the <paramref name="index"/> enabled when it is disabled or
/// disabled when it is enabled.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="index">The 0-based index of the bit to toggle.</param>
/// <returns>The current byte with the bit toggled.</returns>
internal static byte ToggleBit(this byte self, int index)
{
if (GetBit(self, index))
{
return DisableBit(self, index);
}
else
{
return EnableBit(self, index);
}
}
/// <summary>
/// Returns an <see cref="Byte"/> instance represented by the given number of <paramref name="bits"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of least significant bits which are used to store the <see cref="Byte"/>
/// value.</param>
/// <returns>The decoded <see cref="Byte"/>.</returns>
internal static byte DecodeByte(this byte self, int bits)
{
return DecodeByte(self, bits, 0);
}
/// <summary>
/// Returns an <see cref="Byte"/> instance represented by the given number of <paramref name="bits"/>, starting
/// at the <paramref name="firstBit"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of least significant bits which are used to store the <see cref="Byte"/>
/// value.</param>
/// <paramref name="firstBit"/>The first bit of the encoded value.</param>
/// <returns>The decoded <see cref="Byte"/>.</returns>
internal static byte DecodeByte(this byte self, int bits, int firstBit)
{
// Shift to the first bit and keep only the required bits.
return (byte)((self >> firstBit) & ((1 << bits) - 1));
}
/// <summary>
/// Returns an <see cref="SByte"/> instance represented by the given number of <paramref name="bits"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of least significant bits which are used to store the <see cref="SByte"/>
/// value.</param>
/// <returns>The decoded <see cref="SByte"/>.</returns>
internal static sbyte DecodeSByte(this byte self, int bits)
{
return DecodeSByte(self, bits, 0);
}
/// <summary>
/// Returns an <see cref="SByte"/> instance represented by the given number of <paramref name="bits"/>, starting
/// at the <paramref name="firstBit"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of least significant bits which are used to store the <see cref="SByte"/>
/// value.</param>
/// <paramref name="firstBit"/>The first bit of the encoded value.</param>
/// <returns>The decoded <see cref="SByte"/>.</returns>
internal static sbyte DecodeSByte(this byte self, int bits, int firstBit)
{
self >>= firstBit;
int absMask = 1 << bits;
byte abs = (byte)(self & (absMask - 1));
if (abs.GetBit(bits - 1))
{
return (sbyte)(abs - absMask);
}
else
{
return (sbyte)abs;
}
}
/// <summary>
/// Returns the current byte with the given <paramref name="value"/> set into the given number of
/// <paramref name="bits"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of bits which are used to store the <see cref="Byte"/> value.</param>
/// <returns>The current byte with the value encoded into it.</returns>
internal static byte Encode(this byte self, byte value, int bits)
{
return Encode(self, value, bits, 0);
}
/// <summary>
/// Returns the current byte with the given <paramref name="value"/> set into the given number of
/// <paramref name="bits"/> starting at <paramref name="firstBit"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of bits which are used to store the <see cref="Byte"/> value.</param>
/// <param name="firstBit"/>The first bit used for the encoded value.</param>
/// <returns>The current byte with the value encoded into it.</returns>
internal static byte Encode(this byte self, byte value, int bits, int firstBit)
{
// Clear the bits required for the value and fit it into them by truncating.
int mask = ((1 << bits) - 1) << firstBit;
self &= (byte)~mask;
value = (byte)((value << firstBit) & mask);
// Set the value.
return (byte)(self | value);
}
/// <summary>
/// Returns the current byte with the given <paramref name="value"/> set into the given number of
/// <paramref name="bits"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of bits which are used to store the <see cref="SByte"/> value.</param>
/// <returns>The current byte with the value encoded into it.</returns>
internal static byte Encode(this byte self, sbyte value, int bits)
{
return Encode(self, value, bits, 0);
}
/// <summary>
/// Returns the current byte with the given <paramref name="value"/> set into the given number of
/// <paramref name="bits"/> starting at <paramref name="firstBit"/>.
/// </summary>
/// <param name="self">The extended <see cref="Byte"/> instance.</param>
/// <param name="bits">The number of bits which are used to store the <see cref="SByte"/> value.</param>
/// <param name="firstBit"/>The first bit used for the encoded value.</param>
/// <returns>The current byte with the value encoded into it.</returns>
internal static byte Encode(this byte self, sbyte value, int bits, int firstBit)
{
// Set the value as a normal byte, but then fix the sign.
self = Encode(self, (byte)value, bits, firstBit);
return self.SetBit(bits + firstBit - 1, value < 0);
}
}
}

View File

@ -1,10 +0,0 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Syroot.Worms.Gen2.Armageddon
{
class GameScheme
{
}
}

File diff suppressed because it is too large Load Diff

View File

@ -2,7 +2,7 @@
<PropertyGroup>
<Description>.NET library to load and modify file formats of Team17 Worms games.</Description>
<Copyright>MIT</Copyright>
<Copyright>(c) Syroot, licensed under MIT</Copyright>
<AssemblyName>Syroot.Worms</AssemblyName>
<AssemblyTitle>Worms</AssemblyTitle>
<Authors>Syroot</Authors>
@ -17,19 +17,25 @@
<RepositoryType>git</RepositoryType>
<RepositoryUrl>https://github.com/Syroot/Worms</RepositoryUrl>
<TargetFrameworks>netstandard1.6</TargetFrameworks>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
<TargetFrameworks>net45;netstandard1.6</TargetFrameworks>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Syroot.IO.BinaryData" Version="1.1.0" />
<PackageReference Include="Syroot.Maths" Version="1.2.0" />
</ItemGroup>
<ItemGroup>
<Folder Include="Gen1\" />
<Folder Include="Gen2\Armageddon\ProjectX\" />
<Folder Include="Gen3\" />
<PackageReference Include="Syroot.IO.BinaryData" Version="1.2.0" />
<PackageReference Include="Syroot.Maths" Version="1.3.0" />
</ItemGroup>
<ItemGroup Condition="'$(TargetFramework)' == 'net45'">
<Reference Include="System" />
</ItemGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Debug'">
<DebugType>portable</DebugType>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)' == 'Release'">
<DebugType>none</DebugType>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>
</Project>