Skip to content

Commit

Permalink
Update to use SerdesNet 3.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
csinkers committed Nov 16, 2024
1 parent 43bc476 commit 49cdd6a
Show file tree
Hide file tree
Showing 265 changed files with 706 additions and 789 deletions.
4 changes: 2 additions & 2 deletions src/Config/AssetId.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static AssetId FromDisk(AssetType type, int disk, AssetMapping mapping)
return AssetMapping.Global.EnumToId(enumType, enumValue);
}

public static AssetId SerdesU8(string name, AssetId id, AssetType type, AssetMapping mapping, ISerializer s)
public static AssetId SerdesU8(string name, AssetId id, AssetType type, AssetMapping mapping, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);

Expand All @@ -46,7 +46,7 @@ public static AssetId SerdesU8(string name, AssetId id, AssetType type, AssetMap
return FromDisk(type, diskValue, mapping);
}

public static AssetId SerdesU16(string name, AssetId id, AssetType type, AssetMapping mapping, ISerializer s)
public static AssetId SerdesU16(string name, AssetId id, AssetType type, AssetMapping mapping, ISerdes s)
{
ArgumentNullException.ThrowIfNull(mapping);
ArgumentNullException.ThrowIfNull(s);
Expand Down
2 changes: 1 addition & 1 deletion src/Config/IAssetContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public interface IAssetContainer
/// <param name="path">The path to the container file/directory</param>
/// <param name="context">The loader context, containing the JSON serialiser, file system access object etc</param>
/// <returns></returns>
ISerializer Read(string path, AssetLoadContext context);
ISerdes Read(string path, AssetLoadContext context);

/// <summary>
/// Write all assets inside a container
Expand Down
4 changes: 2 additions & 2 deletions src/Config/IAssetLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ namespace UAlbion.Config;

public interface IAssetLoader
{
object Serdes(object existing, ISerializer s, AssetLoadContext context);
object Serdes(object existing, ISerdes s, AssetLoadContext context);
}

public interface IAssetLoader<T> : IAssetLoader where T : class
{
T Serdes(T existing, ISerializer s, AssetLoadContext context); // SerDes = Serialise / Deserialise.
T Serdes(T existing, ISerdes s, AssetLoadContext context); // SerDes = Serialise / Deserialise.
}
4 changes: 2 additions & 2 deletions src/Config/UAlbion.Config.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,10 @@
</ItemGroup>

<ItemGroup Condition="!Exists('..\..\deps\SerdesNet')">
<PackageReference Include="SerdesNet" Version="2.0.1" />
<PackageReference Include="SerdesNet" Version="3.0.1" />
</ItemGroup>
<ItemGroup Condition="Exists('..\..\deps\SerdesNet')">
<ProjectReference Include="..\..\deps\SerdesNet\src\SerdesNet.csproj" />
<ProjectReference Include="..\..\deps\SerdesNet\src\SerdesNet\SerdesNet.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/Core/UAlbion.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
</PropertyGroup>

<ItemGroup Condition="!Exists('..\..\deps\SerdesNet')">
<PackageReference Include="SerdesNet" Version="2.0.1" />
<PackageReference Include="SerdesNet" Version="3.0.1" />
</ItemGroup>
<ItemGroup Condition="Exists('..\..\deps\SerdesNet')">
<ProjectReference Include="..\..\deps\SerdesNet\src\SerdesNet.csproj" />
<ProjectReference Include="..\..\deps\SerdesNet\src\SerdesNet\SerdesNet.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Microsoft.CodeAnalysis.NetAnalyzers" Version="8.0.0">
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/AlbionReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace UAlbion.Formats;

public class AlbionReader : GenericBinaryReader
public class AlbionReader : ReaderSerdes
{
readonly BinaryReader _br;

Expand Down
2 changes: 1 addition & 1 deletion src/Formats/AlbionWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace UAlbion.Formats;

public class AlbionWriter : GenericBinaryWriter
public class AlbionWriter : WriterSerdes
{
public AlbionWriter(BinaryWriter bw)
: base(bw, FormatUtil.BytesFrom850String, ApiUtil.Assert)
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/AlbionPalette.cs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public uint[] GetUnambiguousPalette()
public ReadOnlySpan<uint> GetPaletteAtTime(int i) => _texture.GetLayerBuffer(0).GetRow(i % _texture.Height);
public override string ToString() { return string.IsNullOrEmpty(Name) ? $"Palette {Id}" : $"{Name} ({Id})"; }

public static AlbionPalette Serdes(AlbionPalette p, AssetLoadContext context, ISerializer s)
public static AlbionPalette Serdes(AlbionPalette p, AssetLoadContext context, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
ArgumentNullException.ThrowIfNull(context);
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Automap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public Automap(int width, int height)
_discovered = new BitArray(width * height);
}

public static Automap Serdes(Automap map, ISerializer s)
public static Automap Serdes(Automap map, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
int length;
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/AutomapInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class AutomapInfo // Total size 0x13 = 19 bytes
/// </summary>
public string Name { get; set; } // name length = 15

public static AutomapInfo Serdes(int _, AutomapInfo existing, ISerializer s)
public static AutomapInfo Serdes(int _, AutomapInfo existing, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
var info = existing ?? new AutomapInfo();
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Bitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public Bitmap8Bit(uint width, uint[] palette, byte[] pixels)
public IList<uint> Palette { get; private set; }
public byte[] Pixels { get; private set; }

public static Bitmap8Bit Serdes(Bitmap8Bit b, ISerializer s)
public static Bitmap8Bit Serdes(Bitmap8Bit b, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);

Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Block.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public byte[] RawLayout
set => _tiles = MapTile.FromPacked(value, Width, 0, 0);
}

public static Block Serdes(int _, Block b, ISerializer s)
public static Block Serdes(int _, Block b, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
b ??= new Block();
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/BlockList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ namespace UAlbion.Formats.Assets;
public class BlockList : List<Block>
{
public const int MaxCount = 4095;
public static BlockList Serdes(int blockNumber, BlockList blockList, ISerializer s)
public static BlockList Serdes(int blockNumber, BlockList blockList, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
blockList ??= [];
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/ColorRange.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class ColorRange
/// <summary>
/// Reads range from IFF stream.
/// </summary>
public static ColorRange Serdes(int _, ColorRange c, ISerializer s)
public static ColorRange Serdes(int _, ColorRange c, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
c ??= new ColorRange();
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/EventSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public EventSet(EventSetId id, IEnumerable<EventNode> nodes, IEnumerable<ushort>
}
}

public static EventSet Serdes(EventSetId id, EventSet set, AssetMapping mapping, ISerializer s)
public static EventSet Serdes(EventSetId id, EventSet set, AssetMapping mapping, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
set ??= new EventSet { Id = id };
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/CopyChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class CopyChunk : FlicChunk
{
public byte[] PixelData { get; private set; }
public override FlicChunkType Type => FlicChunkType.FullUncompressed;
protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
PixelData = s.Bytes(null, null, (int)length);
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/DeltaFlcChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class DeltaFlcChunk : FlicChunk
DeltaFlcLine[] _lines;
public override FlicChunkType Type => FlicChunkType.DeltaWordOrientedRle;

protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
var start = s.Offset;
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/DeltaFlcLine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override string ToString() =>
public byte? LastPixel { get; }
public IList<DeltaFlcLineToken> Tokens { get; } = [];

public DeltaFlcLine(ISerializer s)
public DeltaFlcLine(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
int remaining = 1;
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/DeltaFlcLineToken.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public override string ToString()
public sbyte SignedCount { get; }
public ushort[] PixelData { get; }

public DeltaFlcLineToken(ISerializer s)
public DeltaFlcLineToken(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
ColumnSkipCount = s.UInt8(null, 0);
Expand Down
6 changes: 3 additions & 3 deletions src/Formats/Assets/Flic/FlicChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public abstract class FlicChunk
{
const uint ChunkHeaderSize = 6;
public abstract FlicChunkType Type { get; }
protected abstract uint LoadChunk(uint length, ISerializer s);
protected abstract uint LoadChunk(uint length, ISerdes s);

public static FlicChunk Load(ISerializer s, int width, int height)
public static FlicChunk Load(ISerdes s, int width, int height)
{
ArgumentNullException.ThrowIfNull(s);

Expand Down Expand Up @@ -57,4 +57,4 @@ public static FlicChunk Load(ISerializer s, int width, int height)
ApiUtil.Assert(actualChunkSize == chunkSize);
return c;
}
}
}
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/FlicFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ namespace UAlbion.Formats.Assets.Flic;

public class FlicFile
{
public FlicFile(ISerializer s)
public FlicFile(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
if (s.IsWriting())
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/FlicFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public FlicFrame(int width, int height)
public ushort Width { get; private set; } // Overrides, usually 0.
public ushort Height { get; private set; }

protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
var initialOffset = s.Offset;
Expand Down
4 changes: 2 additions & 2 deletions src/Formats/Assets/Flic/FullByteOrientedRleChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public FullByteOrientedRleChunk(int width, int height)

public override FlicChunkType Type => FlicChunkType.FullByteOrientedRle;

public IEnumerable<byte> ReadLinePixels(ISerializer s)
public IEnumerable<byte> ReadLinePixels(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);

Expand Down Expand Up @@ -53,7 +53,7 @@ public IEnumerable<byte> ReadLinePixels(ISerializer s)
}
}

protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
int i = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/Formats/Assets/Flic/Palette8Chunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ sealed class PalettePacket
public byte Skip { get; }
public byte[] Triplets { get; }

public PalettePacket(ISerializer s)
public PalettePacket(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
Skip = s.UInt8(null, 0);
Expand All @@ -30,7 +30,7 @@ public PalettePacket(ISerializer s)
}

public override FlicChunkType Type => FlicChunkType.Palette8Bit;
protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
ushort packetCount = s.UInt16(null, 0);
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Flic/UnknownChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class UnknownChunk : FlicChunk
public override FlicChunkType Type { get; }
public UnknownChunk(FlicChunkType type) => Type = type;
public override string ToString() => $"Unknown:{Type} ({Bytes.Length} bytes)";
protected override uint LoadChunk(uint length, ISerializer s)
protected override uint LoadChunk(uint length, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
Bytes = s.Bytes(null, null, (int)length);
Expand Down
4 changes: 2 additions & 2 deletions src/Formats/Assets/IFFChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public IffChunk(string typeId, int length)
Length = length;
}

public void WriteLength(ISerializer s)
public void WriteLength(ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
var offset = s.Offset;
Expand All @@ -25,7 +25,7 @@ public void WriteLength(ISerializer s)
s.Seek(offset);
}

public static IffChunk Serdes(int _, IffChunk c, ISerializer s)
public static IffChunk Serdes(int _, IffChunk c, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
c ??= new IffChunk();
Expand Down
18 changes: 9 additions & 9 deletions src/Formats/Assets/InterlacedBitmap.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public sealed class InterlacedBitmap
public byte[] Thumbnail { get; set; }
public byte[] ImageData { get; set; }

public static InterlacedBitmap Serdes(InterlacedBitmap img, ISerializer s)
public static InterlacedBitmap Serdes(InterlacedBitmap img, ISerdes s)
{
ArgumentNullException.ThrowIfNull(s);
img ??= new InterlacedBitmap();
Expand Down Expand Up @@ -82,14 +82,14 @@ public static InterlacedBitmap Serdes(InterlacedBitmap img, ISerializer s)
return img;
}

static void WriteChunk(ISerializer s, string chunkType, Action<ISerializer, int> serdes)
static void WriteChunk(ISerdes s, string chunkType, Action<ISerdes, int> serdes)
{
var chunk = IffChunk.Serdes(0, new IffChunk(chunkType, 0), s);
serdes(s, chunk.Length);
chunk.WriteLength(s);
}

void SerdesHeader(ISerializer s, int length)
void SerdesHeader(ISerdes s, int length)
{
if (length < 20)
throw new FormatException($"ILBM header chunk was {length} bytes, expected at least 20");
Expand All @@ -111,7 +111,7 @@ void SerdesHeader(ISerializer s, int length)
s.Bytes("UnexpectedHeaderData", null, length - 20);
}

void SerdesPalette(ISerializer s, int length)
void SerdesPalette(ISerdes s, int length)
{
uint[] pal = Palette ?? new uint[length / 3];
for (int i = 0; i < pal.Length; i++)
Expand All @@ -126,13 +126,13 @@ void SerdesPalette(ISerializer s, int length)
Palette = pal;
}

void SerdesHotspot(ISerializer s, int _)
void SerdesHotspot(ISerdes s, int _)
{
HotspotX = s.Int16(nameof(HotspotX), HotspotX);
HotspotY = s.Int16(nameof(HotspotY), HotspotY);
}

void SerdesThumbnail(ISerializer s, int length)
void SerdesThumbnail(ISerdes s, int length)
{
ThumbnailWidth = s.UInt16BE(nameof(ThumbnailWidth), ThumbnailWidth);
ThumbnailHeight = s.UInt16BE(nameof(ThumbnailHeight), ThumbnailHeight);
Expand All @@ -142,18 +142,18 @@ void SerdesThumbnail(ISerializer s, int length)
: s.Bytes("Pixels", null, length - 4);
}

void SerdesPixels(ISerializer s, int length)
void SerdesPixels(ISerdes s, int length)
{
ImageData = Compression == 1
? s.IsReading() ? Unpack(s, length) : Pack(ImageData, s)
: s.Bytes("Pixels", ImageData, length);
}

// ReSharper disable UnusedParameter.Local
static byte[] Pack(byte[] data, ISerializer s) => throw new NotImplementedException();
static byte[] Pack(byte[] data, ISerdes s) => throw new NotImplementedException();
// ReSharper restore UnusedParameter.Local

static byte[] Unpack(ISerializer s, int size)
static byte[] Unpack(ISerdes s, int size)
{
using MemoryStream ms = new MemoryStream();
var finalOffset = s.Offset + size;
Expand Down
10 changes: 5 additions & 5 deletions src/Formats/Assets/Inv/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,13 @@ public Inventory(InventoryId id)
[JsonIgnore, DiagEdit(Style = DiagEditStyle.InvSlot)] public ItemSlot Feet => TrySlot(ItemSlotId.Feet);
[JsonIgnore, DiagEdit(Style = DiagEditStyle.InvSlot)] public ItemSlot RightFinger => TrySlot(ItemSlotId.RightFinger);

public static Inventory SerdesChest(int n, Inventory inv, AssetMapping mapping, ISerializer s) => Serdes(n, inv, mapping, s, InventoryType.Chest);
public static Inventory SerdesMerchant(int n, Inventory inv, AssetMapping mapping, ISerializer s) => Serdes(n, inv, mapping, s, InventoryType.Merchant);
public static Inventory SerdesCharacter(int n, Inventory inv, AssetMapping mapping, ISerializer s) => Serdes(n, inv, mapping, s, InventoryType.Player);
public static Inventory SerdesMonster(int n, Inventory inv, AssetMapping mapping, ISerializer s) => Serdes(n, inv, mapping, s, InventoryType.Monster);
public static Inventory SerdesChest(int n, Inventory inv, AssetMapping mapping, ISerdes s) => Serdes(n, inv, mapping, s, InventoryType.Chest);
public static Inventory SerdesMerchant(int n, Inventory inv, AssetMapping mapping, ISerdes s) => Serdes(n, inv, mapping, s, InventoryType.Merchant);
public static Inventory SerdesCharacter(int n, Inventory inv, AssetMapping mapping, ISerdes s) => Serdes(n, inv, mapping, s, InventoryType.Player);
public static Inventory SerdesMonster(int n, Inventory inv, AssetMapping mapping, ISerdes s) => Serdes(n, inv, mapping, s, InventoryType.Monster);
public IEnumerable<ItemSlot> EnumerateAll() => Slots.Where(x => x != null);

static Inventory Serdes(int n, Inventory inv, AssetMapping mapping, ISerializer s, InventoryType type)
static Inventory Serdes(int n, Inventory inv, AssetMapping mapping, ISerdes s, InventoryType type)
{
ArgumentNullException.ThrowIfNull(s);
var invId = new InventoryId(type, (ushort)n);
Expand Down
2 changes: 1 addition & 1 deletion src/Formats/Assets/Inv/ItemData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public override string ToString()
return sb.ToString();
}

public static ItemData Serdes(AssetId id, ItemData item, ISerializer s, ISpellManager spellManager)
public static ItemData Serdes(AssetId id, ItemData item, ISerdes s, ISpellManager spellManager)
{
ArgumentNullException.ThrowIfNull(s);
ArgumentNullException.ThrowIfNull(spellManager);
Expand Down
Loading

0 comments on commit 49cdd6a

Please sign in to comment.