Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions Source/SharpNeedle/Framework/BINA/BinaryResource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public override void Read(IFile file)

reader.Endianness = Version.Endianness;

Size = reader.Read<uint>();
ushort chunkCount = reader.Read<ushort>();
Size = reader.ReadUInt32();
ushort chunkCount = reader.ReadUInt16();
reader.Skip(2);

ChunkParseOptions options = new()
Expand Down Expand Up @@ -113,13 +113,13 @@ private void WriteV1(BinaryObjectWriter writer)
{
long begin = writer.Position;
SeekToken sizeToken = writer.At();
writer.Write(0);
writer.Write(0L); // Offset table
writer.Write(0L); // what
writer.WriteInt32(0);
writer.WriteInt64(0); // Offset table
writer.WriteInt64(0); // what

writer.WriteObject(Version);
writer.Write(Signature);
writer.Write(0);
writer.WriteUInt32(Signature);
writer.WriteInt32(0);
writer.PushOffsetOrigin();

ChunkParseOptions options = new()
Expand All @@ -146,14 +146,14 @@ private void WriteV1(BinaryObjectWriter writer)
byte[] offTableEncoded = offTable.Encode();
writer.Skip(4); // Skip size for now
writer.WriteArrayOffset(offTableEncoded);
writer.Write(offTableEncoded.Length);
writer.WriteInt32(offTableEncoded.Length);

endToken.Dispose();
writer.Flush();
endToken = writer.At(writer.Length, SeekOrigin.End);

sizeToken.Dispose();
writer.Write((int)((long)endToken - begin));
writer.WriteInt32((int)((long)endToken - begin));
writer.PopOffsetOrigin();
endToken.Dispose();
}
Expand All @@ -165,8 +165,8 @@ private void WriteV2(BinaryObjectWriter writer)
writer.WriteObject(Version);

SeekToken sizeToken = writer.At();
writer.Write(0);
writer.Write((short)Chunks.Count);
writer.WriteInt32(0);
writer.WriteInt16((short)Chunks.Count);
writer.Align(4);

ChunkParseOptions options = new()
Expand All @@ -181,7 +181,7 @@ private void WriteV2(BinaryObjectWriter writer)
using SeekToken end = writer.At(writer.Length, SeekOrigin.Begin);
sizeToken.Dispose();

writer.Write((int)((long)end - begin));
writer.WriteInt32((int)((long)end - begin));
}

public abstract void Read(BinaryObjectReader reader);
Expand Down
4 changes: 2 additions & 2 deletions Source/SharpNeedle/Framework/BINA/ChunkHeader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ public struct ChunkHeader : IBinarySerializable
public void Read(BinaryObjectReader reader)
{
Signature = reader.ReadNative<uint>();
reader.Read(out Size);
Size = reader.ReadUInt32();
}

public void Write(BinaryObjectWriter writer)
{
writer.WriteNative(Signature);
writer.Write(ref Size);
writer.WriteUInt32(Size);
}
}
22 changes: 11 additions & 11 deletions Source/SharpNeedle/Framework/BINA/DataChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ public void Read(BinaryObjectReader reader, ChunkParseOptions options)
Signature = options.Header.Value.Signature;
BinaryHelper.EnsureSignature(Signature, true, BinSignature, AltBinSignature);

uint strTableOffset = reader.Read<uint>();
uint strTableSize = reader.Read<uint>();
int offTableSize = reader.Read<int>();
uint strTableOffset = reader.ReadUInt32();
uint strTableSize = reader.ReadUInt32();
int offTableSize = reader.ReadInt32();

ushort dataOffset = reader.Read<ushort>();
ushort dataOffset = reader.ReadUInt16();
reader.Skip(2);

reader.Skip(dataOffset);
Expand Down Expand Up @@ -65,16 +65,16 @@ public void Write(BinaryObjectWriter writer, ChunkParseOptions options)

writer.WriteNative(Signature);

writer.Write((int)(baseSize + table.Length + 0x34)); // Size
writer.Write((int)baseSize); // String Table
writer.Write(0); // String Table Size
writer.Write(table.Length); // Offset Table Size
writer.WriteInt32((int)(baseSize + table.Length + 0x34)); // Size
writer.WriteInt32((int)baseSize); // String Table
writer.WriteInt32(0); // String Table Size
writer.WriteInt32(table.Length); // Offset Table Size

writer.Write((short)0x18);
writer.Write((short)0x00);
writer.WriteInt16(0x18);
writer.WriteInt16(0x00);

// Reserved
writer.WriteCollection(Enumerable.Repeat<long>(0, 3));
writer.Skip(24);

// Slice the buffer because the capacity can be bigger
writer.WriteArray(dataStream.GetBuffer().AsSpan()[..(int)dataStream.Length]);
Expand Down
14 changes: 7 additions & 7 deletions Source/SharpNeedle/Framework/BINA/OffsetTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,19 @@ public static void Encode(IEnumerable<long> offsets, BinaryValueWriter writer)
long d = (offset - lastOffset) >> 2;
if (d > 0x3FFF)
{
writer.WriteBig((byte)(0xC0 | (d >> 24)));
writer.WriteBig((byte)(d >> 16));
writer.WriteBig((byte)(d >> 8));
writer.WriteBig((byte)(d & 0xFF));
writer.WriteByte((byte)(0xC0 | (d >> 24)));
writer.WriteByte((byte)(d >> 16));
writer.WriteByte((byte)(d >> 8));
writer.WriteByte((byte)(d & 0xFF));
}
else if (d > 0x3F)
{
writer.WriteBig((byte)(0x80 | (d >> 8)));
writer.WriteBig((byte)d);
writer.WriteByte((byte)(0x80 | (d >> 8)));
writer.WriteByte((byte)d);
}
else
{
writer.Write((byte)(0x40 | d));
writer.WriteByte((byte)(0x40 | d));
}

lastOffset = offset;
Expand Down
4 changes: 2 additions & 2 deletions Source/SharpNeedle/Framework/BINA/RawChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public void Write(BinaryObjectWriter writer, ChunkParseOptions options)
throw new InvalidDataException("RawChunk has no data");
}

writer.Write(Signature);
writer.Write(Data.Length + ChunkHeader.BinarySize);
writer.WriteUInt32(Signature);
writer.WriteInt32(Data.Length + ChunkHeader.BinarySize);
writer.WriteArray(Data);
}

Expand Down
24 changes: 12 additions & 12 deletions Source/SharpNeedle/Framework/BINA/Version.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,15 @@ public Version(byte major, byte minor, byte revision, Endianness endianness)

public void Read(BinaryObjectReader reader)
{
byte ma = reader.Read<byte>();
byte mi = reader.Read<byte>();
byte r = reader.Read<byte>();
byte ma = reader.ReadByte();
byte mi = reader.ReadByte();
byte r = reader.ReadByte();

Major = ma < 0x30 ? ma : (byte)(ma - 0x30);
Minor = mi < 0x30 ? mi : (byte)(mi - 0x30);
Revision = r < 0x30 ? r : (byte)(r - 0x30);

byte e = reader.Read<byte>();
byte e = reader.ReadByte();
switch (e)
{
case 0x4C:
Expand All @@ -45,25 +45,25 @@ public readonly void Write(BinaryObjectWriter writer)
{
if (Major == 0)
{
writer.Write(Major);
writer.Write(Minor);
writer.Write((byte)(Revision + 0x30));
writer.WriteByte(Major);
writer.WriteByte(Minor);
writer.WriteByte((byte)(Revision + 0x30));
}
else
{
writer.Write((byte)(Major + 0x30));
writer.Write((byte)(Minor + 0x30));
writer.Write((byte)(Revision + 0x30));
writer.WriteByte((byte)(Major + 0x30));
writer.WriteByte((byte)(Minor + 0x30));
writer.WriteByte((byte)(Revision + 0x30));
}

switch (Endianness)
{
case Endianness.Little:
writer.Write((byte)0x4C);
writer.WriteByte(0x4C);
break;

case Endianness.Big:
writer.Write((byte)0x42);
writer.WriteByte(0x42);
break;
}
}
Expand Down
12 changes: 6 additions & 6 deletions Source/SharpNeedle/Framework/Glitter/AnimationParameter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class AnimationParameter : IBinarySerializable
public void Read(BinaryObjectReader reader)
{
long keyframeOffset = reader.ReadOffsetValue();
int keyframeCount = reader.Read<int>();
int keyframeCount = reader.ReadInt32();

reader.ReadAtOffset(keyframeOffset, () =>
{
Expand All @@ -19,8 +19,8 @@ public void Read(BinaryObjectReader reader)
}
});

Field08 = reader.Read<int>();
Field0C = reader.Read<int>();
Field08 = reader.ReadInt32();
Field0C = reader.ReadInt32();
}

public void Write(BinaryObjectWriter writer)
Expand All @@ -33,9 +33,9 @@ public void Write(BinaryObjectWriter writer)
}
});

writer.Write(Keyframes.Count);
writer.WriteInt32(Keyframes.Count);

writer.Write(Field08);
writer.Write(Field0C);
writer.WriteInt32(Field08);
writer.WriteInt32(Field0C);
}
}
8 changes: 4 additions & 4 deletions Source/SharpNeedle/Framework/Glitter/Effect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public override void Read(BinaryObjectReader reader)
{
reader.EnsureSignature(Signature);

Version = reader.Read<uint>();
Version = reader.ReadUInt32();
if (Version != 0x01060000)
{
throw new NotSupportedException();
Expand All @@ -31,10 +31,10 @@ public override void Write(BinaryObjectWriter writer)
throw new NotSupportedException();
}

writer.Write(Signature);
writer.Write(Version);
writer.WriteUInt32(Signature);
writer.WriteUInt32(Version);

writer.Write(0); // Always 0?
writer.WriteInt32(0); // Always 0?

if (Parameters.First != null)
{
Expand Down
66 changes: 34 additions & 32 deletions Source/SharpNeedle/Framework/Glitter/EffectParameter.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
namespace SharpNeedle.Framework.Glitter;

using System.Net;

public class EffectParameter : IBinarySerializable<Effect>
{
public string? Name { get; set; }
Expand All @@ -26,32 +28,32 @@ public void Read(BinaryObjectReader reader, Effect parent)
{
Name = reader.ReadStringOffset();

StartTime = reader.Read<float>();
LifeTime = reader.Read<float>();
StartTime = reader.ReadSingle();
LifeTime = reader.ReadSingle();

PreprocessFrame = reader.Read<int>();
PreprocessFrame = reader.ReadInt32();

EffectScale = reader.Read<float>();
EmittingScale = reader.Read<float>();
Opacity = reader.Read<float>();
EffectScale = reader.ReadSingle();
EmittingScale = reader.ReadSingle();
Opacity = reader.ReadSingle();

Field1C = reader.Read<float>();
Field1C = reader.ReadSingle();

reader.Align(16);
Position = reader.Read<Vector3>();
Position = reader.ReadVector3();
reader.Align(16);
Rotation = reader.Read<Vector3>().ToDegrees();
Rotation = reader.ReadVector3().ToDegrees();
reader.Align(16);
Scale = reader.Read<Vector3>();
Scale = reader.ReadVector3();
reader.Align(16);

Field50 = reader.Read<int>();
Field54 = reader.Read<int>();
Field58 = reader.Read<int>();
Field5C = reader.Read<int>();
Field60 = reader.Read<int>();
Field50 = reader.ReadInt32();
Field54 = reader.ReadInt32();
Field58 = reader.ReadInt32();
Field5C = reader.ReadInt32();
Field60 = reader.ReadInt32();

Loop = Convert.ToBoolean(reader.Read<int>());
Loop = Convert.ToBoolean(reader.ReadInt32());

for (int i = 0; i < Animations.Capacity; i++)
{
Expand Down Expand Up @@ -81,31 +83,31 @@ public void Write(BinaryObjectWriter writer, Effect parent)
{
writer.WriteStringOffset(StringBinaryFormat.NullTerminated, Name);

writer.Write(StartTime);
writer.Write(LifeTime);
writer.WriteSingle(StartTime);
writer.WriteSingle(LifeTime);

writer.Write(PreprocessFrame);
writer.WriteInt32(PreprocessFrame);

writer.Write(EffectScale);
writer.Write(EmittingScale);
writer.Write(Opacity);
writer.Write(Field1C);
writer.WriteSingle(EffectScale);
writer.WriteSingle(EmittingScale);
writer.WriteSingle(Opacity);
writer.WriteSingle(Field1C);

writer.Align(16);
writer.Write(Position);
writer.WriteVector3(Position);
writer.Align(16);
writer.Write(Rotation.ToRadians());
writer.WriteVector3(Rotation.ToRadians());
writer.Align(16);
writer.Write(Scale);
writer.WriteVector3(Scale);
writer.Align(16);

writer.Write(Field50);
writer.Write(Field54);
writer.Write(Field58);
writer.Write(Field5C);
writer.Write(Field60);
writer.WriteInt32(Field50);
writer.WriteInt32(Field54);
writer.WriteInt32(Field58);
writer.WriteInt32(Field5C);
writer.WriteInt32(Field60);

writer.Write(Convert.ToInt32(Loop));
writer.WriteInt32(Convert.ToInt32(Loop));

foreach (AnimationParameter animation in Animations)
{
Expand Down
Loading