Skip to content

Commit

Permalink
Be explicit about endianness
Browse files Browse the repository at this point in the history
  • Loading branch information
mnadareski committed Dec 17, 2024
1 parent 2239b82 commit fa9e9a0
Show file tree
Hide file tree
Showing 31 changed files with 4,455 additions and 2,450 deletions.
432 changes: 216 additions & 216 deletions SabreTools.Serialization/Deserializers/AACS.cs

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions SabreTools.Serialization/Deserializers/BDPlus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public class BDPlus : BaseBinaryDeserializer<SVM>
if (svm.Day < 1 || svm.Day > 31)
return null;

svm.Unknown2 = data.ReadUInt32();
svm.Length = data.ReadUInt32();
svm.Unknown2 = data.ReadUInt32LittleEndian();
svm.Length = data.ReadUInt32LittleEndian();
if (svm.Length > 0)
svm.Data = data.ReadBytes((int)svm.Length);

Expand Down
35 changes: 26 additions & 9 deletions SabreTools.Serialization/Deserializers/BFPK.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public class BFPK : BaseBinaryDeserializer<Archive>
#region Header

// Try to parse the header
var header = data.ReadType<Header>();
if (header?.Magic != SignatureString)
var header = ParseHeader(data);
if (header.Magic != SignatureString)
return null;

// Set the archive header
Expand Down Expand Up @@ -58,32 +58,49 @@ public class BFPK : BaseBinaryDeserializer<Archive>
}

/// <summary>
/// Parse a Stream into a file entry
/// Parse a Stream into a FileEntry
/// </summary>
/// <param name="data">Stream to parse</param>
/// <returns>Filled file entry on success, null on error</returns>
private static FileEntry ParseFileEntry(Stream data)
/// <returns>Filled FileEntry on success, null on error</returns>
public static FileEntry ParseFileEntry(Stream data)
{
var fileEntry = new FileEntry();

fileEntry.NameSize = data.ReadInt32();
fileEntry.NameSize = data.ReadInt32LittleEndian();
if (fileEntry.NameSize > 0)
{
byte[] name = data.ReadBytes(fileEntry.NameSize);
fileEntry.Name = Encoding.ASCII.GetString(name);
}

fileEntry.UncompressedSize = data.ReadInt32();
fileEntry.Offset = data.ReadInt32();
fileEntry.UncompressedSize = data.ReadInt32LittleEndian();
fileEntry.Offset = data.ReadInt32LittleEndian();
if (fileEntry.Offset > 0)
{
long currentOffset = data.Position;
data.Seek(fileEntry.Offset, SeekOrigin.Begin);
fileEntry.CompressedSize = data.ReadInt32();
fileEntry.CompressedSize = data.ReadInt32LittleEndian();
data.Seek(currentOffset, SeekOrigin.Begin);
}

return fileEntry;
}

/// <summary>
/// Parse a Stream into a Header
/// </summary>
/// <param name="data">Stream to parse</param>
/// <returns>Filled Header on success, null on error</returns>
public static Header ParseHeader(Stream data)
{
var obj = new Header();

byte[] magic = data.ReadBytes(4);
obj.Magic = Encoding.ASCII.GetString(magic);
obj.Version = data.ReadInt32LittleEndian();
obj.Files = data.ReadInt32LittleEndian();

return obj;
}
}
}
Loading

0 comments on commit fa9e9a0

Please sign in to comment.