Handle old, pre-release cnmt files

This commit is contained in:
Alex Barney 2021-07-10 16:58:55 -07:00
parent 7cbbf023ff
commit 76e5a20e1d

View file

@ -42,7 +42,13 @@ namespace LibHac
TableOffset = reader.ReadUInt16(); TableOffset = reader.ReadUInt16();
ContentEntryCount = reader.ReadUInt16(); ContentEntryCount = reader.ReadUInt16();
MetaEntryCount = reader.ReadUInt16(); MetaEntryCount = reader.ReadUInt16();
file.Position += 12;
// Old, pre-release cnmt files don't have the "required system version" field.
// Try to detect this by reading the padding after that field.
// The old format usually contains hashes there.
file.Position += 8;
int padding = reader.ReadInt32();
bool isOldCnmtFormat = padding != 0;
switch (Type) switch (Type)
{ {
@ -61,7 +67,8 @@ namespace LibHac
break; break;
} }
file.Position = 0x20 + TableOffset; int baseOffset = isOldCnmtFormat ? 0x18 : 0x20;
file.Position = baseOffset + TableOffset;
ContentEntries = new CnmtContentEntry[ContentEntryCount]; ContentEntries = new CnmtContentEntry[ContentEntryCount];
MetaEntries = new CnmtContentMetaEntry[MetaEntryCount]; MetaEntries = new CnmtContentMetaEntry[MetaEntryCount];