Skip to content

Commit

Permalink
Fix issues with version >= 0x29
Browse files Browse the repository at this point in the history
  • Loading branch information
wannkunstbeikor committed Aug 28, 2024
1 parent 89635ce commit 6bd8137
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions Galanthus/SdfToc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -561,7 +561,8 @@ private static void ParseEntry(DataStream inStream, bool isSigned, string name,
{
byte sizesAndFlags = inStream.ReadByte();
bool isCompressed = (sizesAndFlags >> 5 & 1) != 0;
bool isEncrypted = ((sizesAndFlags >> 6) & 1) != 0;
bool isEncrypted = (sizesAndFlags >> (inVersion >= 0x29 ? 7 : 6) & 1) != 0;
bool noPageSize = inVersion >= 0x29 && (sizesAndFlags >> 6 & 1) != 0;

long decompressedSize = inStream.ReadSizedInt((sizesAndFlags & 3) + 1);
byte unk1 = 0;
Expand Down Expand Up @@ -590,12 +591,20 @@ private static void ParseEntry(DataStream inStream, bool isSigned, string name,
{
long pageCount = (decompressedSize + 0xffff) >> 16;
pageSizes = new List<int>((int)pageCount);
if (pageCount > 1 && (inVersion < 0x29 || !isEncrypted))
if (pageCount > 1 && !noPageSize)
{
int sum = 0;
for (int page = 0; page < pageCount; page++)
{
pageSizes.Add(inStream.ReadUInt16());
int size = inStream.ReadUInt16();
pageSizes.Add(size);
if (size == 0)
{
size = 0x10000;
}
sum += size;
}
Debug.Assert(sum == compressedSize, "Invalid page sizes");
}
else
{
Expand All @@ -609,12 +618,12 @@ private static void ParseEntry(DataStream inStream, bool isSigned, string name,
sign = inStream.ReadInt32();
}

asset.DataSlices.Add(new DataSlice()
asset.DataSlices.Add(new DataSlice
{
DecompressedSize = decompressedSize,
CompressedSize = compressedSize,
IsCompressed = isCompressed,
IsOodle = (sizesAndFlags >> 7 & 1) != 0,
IsOodle = inVersion >= 0x29 || (sizesAndFlags >> 7 & 1) != 0,
IsEncrypted = isEncrypted,
Offset = offset,
Index = index,
Expand Down

0 comments on commit 6bd8137

Please sign in to comment.