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
10 changes: 9 additions & 1 deletion Source/SharpNeedle/Framework/Ninja/Csd/Cast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ public void Read(BinaryObjectReader reader, Family family)
Info = reader.ReadObjectOffset<CastInfo>();
InheritanceFlags = reader.Read<BitSet<uint>>();
MaterialFlags = reader.Read<BitSet<uint>>();
SpriteIndices = reader.ReadArrayOffset<int>(reader.Read<int>());

if (reader.OffsetBinaryFormat == OffsetBinaryFormat.U64)
{
SpriteIndices = reader.ReadArrayOffset<int>((int)reader.Read<ulong>());
}
else
{
SpriteIndices = reader.ReadArrayOffset<int>(reader.Read<int>());
}

Text = reader.ReadStringOffset();
FontName = reader.ReadStringOffset();
Expand Down
5 changes: 3 additions & 2 deletions Source/SharpNeedle/Framework/Ninja/Csd/CastInfoTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ public class CastInfoTable : List<(string? Name, int FamilyIdx, int CastIdx)>, I
{
public void Read(BinaryObjectReader reader)
{
int count = reader.Read<int>();
// FYI: this is not an offset, this is just to read it as a long or int based on the format
long count = reader.ReadOffsetValue();
if (count == 0)
{
reader.Skip(reader.GetOffsetSize());
Expand Down Expand Up @@ -35,7 +36,7 @@ public void Write(BinaryObjectWriter writer)
{
foreach ((string? Name, int FamilyIdx, int CastIdx) in this)
{
writer.WriteOffset(() =>
writer.WriteOffset(() =>
{
writer.WriteString(StringBinaryFormat.NullTerminated, Name);
writer.Write<byte>(0);
Expand Down
12 changes: 7 additions & 5 deletions Source/SharpNeedle/Framework/Ninja/Csd/CsdDictionary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,16 @@ public bool Remove(KeyValuePair<string?, T> item)

public void Read(BinaryObjectReader reader)
{
int count = reader.Read<int>();
// FYI: this is not an offset, this is just to read it as a long or int based on the format
long count = reader.ReadOffsetValue();
if (count == 0)
{
reader.Skip(reader.GetOffsetSize() * 2);
return;
}

Items.AddRange(reader.ReadObjectArrayOffset<T>(count));
NameTable.AddRange(reader.ReadObjectArrayOffset<NameIndexPair>(count));
Items.AddRange(reader.ReadObjectArrayOffset<T>((int)count));
NameTable.AddRange(reader.ReadObjectArrayOffset<NameIndexPair>((int)count));
}

public void Write(BinaryObjectWriter writer)
Expand Down Expand Up @@ -232,14 +233,15 @@ public NameIndexPair(string? name, int idx)
public void Read(BinaryObjectReader reader)
{
Name = reader.ReadStringOffset();
Index = reader.Read<int>();
// FYI: this is not an offset, this is just to read it as a long or int based on the format
Index = (int)reader.ReadOffsetValue();
}

public void Write(BinaryObjectWriter writer)
{
string? name = Name;

writer.WriteOffset(() =>
writer.WriteOffset(() =>
{
writer.WriteString(StringBinaryFormat.NullTerminated, name);
writer.Write<byte>(0);
Expand Down
1 change: 1 addition & 0 deletions Source/SharpNeedle/Framework/Ninja/Csd/CsdProject.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public void Read(BinaryObjectReader reader)
continue;
Stream stream = Package.GetStream(i);
using BinaryObjectReader infoReader = new(stream, StreamOwnership.Transfer, Package.Endianness);
infoReader.OffsetBinaryFormat = reader.OffsetBinaryFormat;
try
{
InfoChunk info = infoReader.ReadObject<InfoChunk, ChunkBinaryOptions>(options);
Expand Down
7 changes: 5 additions & 2 deletions Source/SharpNeedle/Framework/Ninja/Csd/Family.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ public void AttachMotion(FamilyMotion motion)
public void Read(BinaryObjectReader reader, Scene context)
{
Scene = context;
int castCount = reader.Read<int>();
// FYI: this is not an offset
int castCount = (int)reader.ReadOffsetValue();

CastBuffer = new List<Cast>(castCount);
reader.ReadOffset(() =>
{
Expand All @@ -31,7 +33,8 @@ public void Read(BinaryObjectReader reader, Scene context)
}
});

int root = reader.Read<int>();
// FYI: this is not an offset
int root = (int)reader.ReadOffsetValue();
TreeDescriptorNode[] tree = reader.ReadArrayOffset<TreeDescriptorNode>(CastBuffer.Count);
if (CastBuffer.Count != 0)
{
Expand Down
10 changes: 9 additions & 1 deletion Source/SharpNeedle/Framework/Ninja/Csd/Motions/CastMotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,15 @@ public CastMotion(Cast cast)
public void Read(BinaryObjectReader reader)
{
Clear();
Flags = reader.Read<BitSet<uint>>();
if (reader.OffsetBinaryFormat == OffsetBinaryFormat.U64)
{
Flags = (BitSet<uint>)reader.Read<BitSet<long>>().Value;
}
else
{
Flags = reader.Read<BitSet<uint>>();
}

int count = Flags.PopCount();

if (count == 0)
Expand Down
15 changes: 13 additions & 2 deletions Source/SharpNeedle/Framework/Ninja/Csd/Motions/KeyFrame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,15 @@ public void Read(BinaryObjectReader reader)
{
Frame = reader.Read<int>();
Value = reader.Read<uint>();
Interpolation = reader.Read<InterpolationType>();
if (reader.OffsetBinaryFormat == OffsetBinaryFormat.U64)
{
Interpolation = (InterpolationType)reader.Read<uint>();
}
else
{
Interpolation = reader.Read<InterpolationType>();
}

InTangent = reader.Read<float>();
OutTangent = reader.Read<float>();
Field14 = reader.Read<uint>();
Expand All @@ -26,7 +34,10 @@ public void Write(BinaryObjectWriter writer)
{
writer.Write(Frame);
writer.Write(Value.Uint);
writer.Write(Interpolation);
if(writer.OffsetBinaryFormat == OffsetBinaryFormat.U64)
writer.Write((uint)Interpolation);
else
writer.Write(Interpolation);
writer.Write(InTangent);
writer.Write(OutTangent);
writer.Write(Field14);
Expand Down
12 changes: 10 additions & 2 deletions Source/SharpNeedle/Framework/Ninja/Csd/Scene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ public void Read(BinaryObjectReader reader)
float motionBegin = reader.Read<float>();
float motionEnd = reader.Read<float>();
Textures = new List<Vector2>(reader.ReadArrayOffset<Vector2>(reader.Read<int>()));
Sprites = new List<Sprite>(reader.ReadArrayOffset<Sprite>(reader.Read<int>()));
// The ReadOffsetValue call is not for an offset
Sprites = new List<Sprite>(reader.ReadArrayOffset<Sprite>((int)reader.ReadOffsetValue()));

int familyCount = reader.Read<int>();
// FYI: this is not an offset
int familyCount = (int)reader.ReadOffsetValue();
Families = new List<Family>(familyCount);
reader.ReadOffset(() =>
{
Expand All @@ -51,6 +53,12 @@ public void Read(BinaryObjectReader reader)
if (Version >= 1)
{
AspectRatio = reader.Read<float>();

//This is the only "new" field in x64 CSD files, is this alignment/padding, or is this a new field?
if (reader.OffsetBinaryFormat == OffsetBinaryFormat.U64)
{
reader.Read<uint>();
}
}

if (Version >= 2)
Expand Down
3 changes: 2 additions & 1 deletion Source/SharpNeedle/Framework/Ninja/Csd/TextureMirage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ public TextureMirage(string name)
public void Read(BinaryObjectReader reader)
{
Name = reader.ReadStringOffset();
MemoryDataIndex = reader.Read<int>();
// FYI: this is not an offset
MemoryDataIndex = (int)reader.ReadOffsetValue();
}

public void Write(BinaryObjectWriter writer)
Expand Down
5 changes: 3 additions & 2 deletions Source/SharpNeedle/Framework/Ninja/InfoChunk.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ public void Read(BinaryObjectReader reader, ChunkBinaryOptions options)

Chunks.Clear();
Chunks.Capacity = chunkCount;
reader.ReadOffset(() =>
uint offset = reader.ReadUInt32();
reader.ReadAtOffset(offset, () =>
{
reader.PushOffsetOrigin();
for (int i = 0; i < chunkCount; i++)
Expand Down Expand Up @@ -56,7 +57,7 @@ public void Read(BinaryObjectReader reader, ChunkBinaryOptions options)
});

reader.Skip(4); // size of all chunks
Offsets = reader.ReadObjectOffset<OffsetChunk>();
Offsets = reader.ReadObjectAtOffset<OffsetChunk>(reader.ReadUInt32());
reader.Skip(4); // Offsets.BinarySize

Field1C = reader.Read<uint>();
Expand Down