Skip to content

Commit

Permalink
Fix alignment and byte order writing
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchLeaders committed Jan 16, 2024
1 parent 9e198b6 commit 33daccb
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/SarcLibrary/Sarc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,16 +84,15 @@ public unsafe void Write(Stream stream, Endianness? endianness = null, bool lega
}

int dataOffset = (int)writer.Position;
for (int i = 0; i < sorted.Length; i++) {
SarcNodeData entry = sorted[i];
writer.Write(entry.Value.Data);
writer.Align(entry.Value.Alignment);
foreach ((var _, var value) in sorted) {
writer.Move(value.Data.Length.AlignUp(value.Alignment));
writer.Write(value.Data);
}

SarcHeader header = new() {
Magic = SARC_MAGIC,
HeaderSize = 0x14,
ByteOrderMark = endianness.Value,
ByteOrderMark = Endianness.Big,
FileSize = (int)writer.Position,
DataOffset = dataOffset,
Version = (ushort)Version
Expand Down
7 changes: 4 additions & 3 deletions src/SarcLibrary/Writers/SfatWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,12 @@ public static void Write(RevrsWriter writer, SarcNodeData[] entries, bool isHash
SfatNode node = new() {
FileNameHash = entry.Value.FileNameHash,
FileAttributes = isHashOnly ? 0x0 : 0x01000000 | (nameOffset / 4),
DataStartOffset = dataOffset,
DataEndOffset = dataOffset += entry.Value.Data.Length.Align(entry.Value.Alignment)
DataStartOffset = dataOffset += entry.Value.Data.Length.AlignUp(entry.Value.Alignment),
DataEndOffset = dataOffset += entry.Value.Data.Length
};

nameOffset += (entry.Name.Length + 1).Align(0x4);
nameOffset += entry.Name.Length + 1;
nameOffset += nameOffset.AlignUp(0x4);
writer.Write<SfatNode, SfatNode.Reverser>(node);
}
}
Expand Down

0 comments on commit 33daccb

Please sign in to comment.