Raise metadata registration sanity limit for Unity 6 games - #604
Raise metadata registration sanity limit for Unity 6 games#604HHHEEEWWW wants to merge 1 commit into
Conversation
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.
|
Hi, a friendly nudge on this one. Since opening the PR, Pax Autocratica (Unity 6000.0.37f1) still fails interop generation on any unpatched Cpp2IL with The change is a one-line constant bump with existing downstream validation (typeDefinitionsSizesCount / numTypes vs the metadata file) still guarding correctness, and the branch is up to date with development and mergeable. Happy to add a regression test (e.g. parsing Pax Autocratica's Global-metadata.dat) or adjust anything else if that would help get this merged. Thanks! |
|
It has been less than 24 hours and I haven't had time to look into it myself to confirm the diagnosis. It will be merged once I have and not before. Bumping these constants directly increases the chances of other games getting false positives so I do not do it lightly. |
Problem
Unity 6 (6000.x) games can have metadata registration count fields above the hardcoded sanity limit of
0xC0000(786,432). When that happens, real registrations get rejected and LibCpp2IL fails with:LibCpp2ILInitializationException: Fatal Exception initializing LibCpp2IL! ---> System.Exception: Failed to find code registration or metadata registration!Repro: Pax Autocratica after its 2026-08-15 update (Unity 6000.0.37f1). Cpp2IL verbose output:
Found 2 potential metadata registrations: [18E905CA0, 18E905CB0] Rejected Metadata registration at 0x18E905CA0, because it has a count field 0xCFE2E at offset 0 which is above sanity limit of 0xC0000. Rejected Metadata registration at 0x18E905CB0, because it has a count field 0xD04C4 at offset 8 which is above sanity limit of 0xC0000.This breaks BepInEx interop generation for affected games (
Failed to generate Il2Cpp interop assemblies).Fix
Raise the sanity limit to
0x400000(4,194,304). Subsequent validation still applies: candidates are checked against the metadata file viatypeDefinitionsSizesCountandnumTypes, so this value only acts as a coarse pre-filter — it cannot accept a bogus registration.This mirrors the 2022 precedent (commit history: limit was previously raised to
0x70000for Zenith) and keeps the safety check while accommodating larger modern games.