From 76e5a20e1d068b92a27bea4225ba404906256185 Mon Sep 17 00:00:00 2001 From: Alex Barney Date: Sat, 10 Jul 2021 16:58:55 -0700 Subject: [PATCH] Handle old, pre-release cnmt files --- src/LibHac/Cnmt.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/LibHac/Cnmt.cs b/src/LibHac/Cnmt.cs index b5616af3..a307762f 100644 --- a/src/LibHac/Cnmt.cs +++ b/src/LibHac/Cnmt.cs @@ -42,7 +42,13 @@ namespace LibHac TableOffset = reader.ReadUInt16(); ContentEntryCount = 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) { @@ -61,7 +67,8 @@ namespace LibHac break; } - file.Position = 0x20 + TableOffset; + int baseOffset = isOldCnmtFormat ? 0x18 : 0x20; + file.Position = baseOffset + TableOffset; ContentEntries = new CnmtContentEntry[ContentEntryCount]; MetaEntries = new CnmtContentMetaEntry[MetaEntryCount];