From ce2ec384bdf7a57b855dad7511e5c6a0b95dd001 Mon Sep 17 00:00:00 2001 From: aldotms89 <119340049+aldotms89@users.noreply.github.com> Date: Tue, 24 Nov 2026 22:30:02 -0600 Subject: [PATCH] Shader split: read both MT Framework ARC v7 entry sizes Resident Evil 6 archives use 64-byte path fields. Validate both table layouts and yield SPK records directly to the collector to avoid holding a second copy of the package. --- dm/gfx/tools/shader_split.py | 50 ++++++++++++++++++++------- dm/tools/tests/test_split_targeted.py | 45 ++++++++++++++++++++++++ docs/agents/symptoms.md | 1 + docs/reference/shaders.md | 8 +++++ peanuts/UPSTREAM-EDITS.md | 2 ++ 5 files changed, 94 insertions(+), 12 deletions(-) diff --git a/dm/gfx/tools/shader_split.py b/dm/gfx/tools/shader_split.py index ba2f3b58..03718224 100644 --- a/dm/gfx/tools/shader_split.py +++ b/dm/gfx/tools/shader_split.py @@ -1541,18 +1541,40 @@ def pg_sized_shader(d, label): return [(f'{label}#PGSO', st, ctl, code)] MTARC, MTSPK = b'ARC\0', b'SPK\0' +# PEANUTS(upstream-candidate) begin: detect both ARC v7 entry widths and stream SPK records. def mtarc_members(d, label): - """Capcom's MT Framework archive (The Great Ace Attorney Chronicles: 447 '.arc' files under nativeNXx64): 'ARC\\0', u16 version 7, u16 entry count, then one 0x90-byte entry per file - {char path[128] ('\\\\'-separated, no extension), u32 type hash, u32 stored length, u32 length in the low 29 bits (flags above), u32 offset}; the data is a zlib stream, or stored when the - stored length equals the length. → (path, data) of each entry""" + """Capcom MT Framework ARC v7: magic, u16 version, u16 count, then a table. + Entries are 0x90 bytes in The Great Ace Attorney Chronicles (128-byte path) + and 0x50 bytes in Resident Evil 6 (64-byte path). Four little-endian u32s + follow the path: type hash, stored size, size (low 29 bits) with flags, offset. + A member is stored if its sizes match, and zlib-compressed otherwise. + """ import zlib + if len(d) < 8: red(f'{label}: truncated ARC header') ver, n = struct.unpack_from(' len(d): return None + rows = [] + for i in range(n): + o = 8 + stride * i + path = d[o:o + path_size].split(b'\0', 1)[0].decode('latin-1') + csz, usz, off = struct.unpack_from('<3I', d, o + path_size + 4) + if not path or not path.isprintable() or off < end or off + csz > len(d): + return None + rows.append((path, csz, usz & 0x1fffffff, off)) + end = off + csz + return rows + + # Prefer the original wide layout if both tables are consistent. + rows = entries(128) or entries(64) + if rows is None: red(f'{label}: no consistent ARC v7 entry layout (0x90 or 0x50)') + for path, csz, usz, off in rows: + data = d[off:off + csz] if csz == usz else zlib.decompress(memoryview(d)[off:off + csz]) if len(data) != usz: red(f'{label}#{path}: {len(data):#x} bytes, the entry says {usz:#x}') yield path.replace('\\', '/'), data @@ -1560,8 +1582,12 @@ def mtspk_shaders(d, label): """MT Framework's shader package ('SPK\\0'; The Great Ace Attorney Chronicles keeps its only one, sc\\NX_64\\root, in sa/NX_64/root.arc): after the package's tables every shader is a code area followed directly by its control section, back to back to the end of the file (230 vertex shaders, then 230 pixel shaders). Each control section names its code length (+0x704), so the code area is the bytes right before it, and every block must start where the previous one ended. The tables that say which vertex and pixel shaders the engine combines are not - read, so the shaders are paired as single-stage programs (separable_pairs)""" - out, end, c = [], None, d.find(CTL_MAGIC) + read, so the shaders are paired as single-stage programs (separable_pairs). + Resident Evil 6 (SDK 6.5.0) uses the same control and code layout in its four + packages. Yield records one at a time so the caller can deduplicate them + without keeping a second copy of the entire package (GameStage is 424 MB). + """ + end, c = None, d.find(CTL_MAGIC) while c >= 0: nctl, ncode = struct.unpack_from(' +### ARC v7 archives with short paths + +- **Symptom:** Shader extraction fails on ARC v7 archives with 64-byte path fields. +- **Cause:** The reader assumed the 128-byte path field and read the length and offset fields at the wrong positions. +- **Fix:** Validate the member table for both entry widths and read shader records from SPK packages one at a time. +- **Found on:** Resident Evil 6 2.0.0 (v131072). + ### PKZ version 1 archives - **Symptom:** `[RED] ... PKZ version 0x10000: only 0x20000 is known` stops the shader split. diff --git a/peanuts/UPSTREAM-EDITS.md b/peanuts/UPSTREAM-EDITS.md index 08b4e8c4..b5f95904 100644 --- a/peanuts/UPSTREAM-EDITS.md +++ b/peanuts/UPSTREAM-EDITS.md @@ -188,6 +188,8 @@ Also gated, but not `#ifdef`-paired with upstream code (new Peanuts-owned files/ ## Summary of good upstream-contribution candidates (general fixes, not Peanuts-specific) +- MT Framework ARC v7 short-path layout and streamed SPK records ([shader reader](../docs/reference/shaders.md#arc-v7-archives-with-short-paths)). + 1. `dm/host/plat/plat_android.c` — stack guard-page exclusion (IL2CPP GC crash fix) 2. `dm/host/crash.c` — stripped-library lib+offset in crash output 3. `dm/host/loader.c` — module arena (fixes an Android-only OOB read vs the console's layout)