From 1e78675aae0291a99b2c2574f31107a43f4753f0 Mon Sep 17 00:00:00 2001 From: HHHEEEWWW <288059553+HHHEEEWWW@users.noreply.github.com> Date: Sat, 15 Aug 2026 23:20:29 +0800 Subject: [PATCH] Raise metadata registration sanity limit for Unity 6 games Unity 6 (6000.x) games can have metadata registration count fields above the old 0xC0000 sanity limit (e.g. Pax Autocratica after its 2026-08 update had ~0xD04C4). Candidates were rejected, so LibCpp2IL failed with 'Failed to find code registration or metadata registration!' and BepInEx could not generate interop assemblies. Subsequent validation (typeDefinitionsSizesCount / numTypes vs the metadata file) still checks candidates, so the limit only acts as a coarse filter. Raise it to 0x400000 to cover larger games. --- LibCpp2IL/BinarySearcher.cs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/LibCpp2IL/BinarySearcher.cs b/LibCpp2IL/BinarySearcher.cs index 3cd152b6..2fe2dc52 100644 --- a/LibCpp2IL/BinarySearcher.cs +++ b/LibCpp2IL/BinarySearcher.cs @@ -349,10 +349,18 @@ public ulong FindMetadataRegistrationPost24_5() if (i % 2 == 0) { //Count - ok = mrWords[i] < 0xC_0000; + // Sanity limit for metadata registration count fields. + // Unity 6 (6000.x) games can legitimately exceed 0xC0000 + // (e.g. Pax Autocratica on 2026-08 update had ~0xD04C4), + // which made real registrations get rejected and interop + // generation fail with "Failed to find code registration + // or metadata registration!". Subsequent checks + // (typeDefinitionsSizesCount / numTypes vs metadata) + // still validate candidates, so this is only a coarse filter. + ok = mrWords[i] < 0x4_00000; if (!ok) - LibLogger.VerboseNewline($"\t\t\tRejected Metadata registration at 0x{va:X}, because it has a count field 0x{mrWords[i]:X} at offset {i} which is above sanity limit of 0xC0000. If metadata registration detection fails, may need to bump up the limit."); + LibLogger.VerboseNewline($"\t\t\tRejected Metadata registration at 0x{va:X}, because it has a count field 0x{mrWords[i]:X} at offset {i} which is above sanity limit of 0x400000. If metadata registration detection fails, may need to bump up the limit."); } else {