# Packing ## Game packages ### A whole Switch 2 update in a Switch 1 dump - **Symptom:** packing a dump with a complete Switch 2 update fails with `program ID 0400…, the base is 0100…`. - **Cause:** the packer used the base program's identity for the update. The complete update declares its Switch 2 counterpart in its own `main.npdm`, while the add-on content belongs to the base application. - **Fix:** `scan_dump` and `pack_dump.py` select the program declared by the requested version. A whole update may change the leading platform byte from `01` to `04` with the rest of the ID equal. Profile selection and shader inputs follow that program, and the DLC indices still use the base application's add-on content ID. Selecting `-p v0` keeps the base program. - **Found on:** [Red Dead Redemption: Nintendo Switch 2 Edition](../../dm/games/040000B0196AA000/README.md). The dump built with the complete update and one DLC image. `test_nsp_dump.py` covers both version selections, DLC ownership and rejection of an unrelated program ID. ### An iOS build stops when the profile has no prewarm seed list - **Symptom:** after the shader build, `build_ipa.sh` stops at `copy shader tables` because `pso_manifest.tsv` does not exist. This also stops the shell's game-framework build. - **Cause:** a profile may have no recorded pipeline prewarm seeds yet. The host supports that state and still reads the device's own list, but the iOS packager required the optional seed file alongside the required shader tables. - **Fix:** copy a recorded seed list when present and report its absence otherwise. Required shader tables and a failed copy of an existing seed list still stop the build. No seed records are invented, and shader cache inputs are unchanged. This does not change shader rebuild or resume decisions. - **Found on:** [Pokémon Pokopia](../../dm/games/0400A3A01EE4C000/README.md), [NX2Apple issue #922](https://github.com/LNPANDY/NX2Apple/issues/922). The separate report of repeated shader compilation remains open. ### PFS0 files extend beyond a truncated package - **Symptom:** `nx_extract --aoc` aborts with an unhandled `ResultFsOutOfRange (2002-3005)` when a package's file table declares bytes that are not present. - **Cause:** the PFS0 header and name table were checked, but each payload-relative file offset and size was trusted. LibHac later tried to read the missing bytes, before the extractor could issue its normal damaged-package diagnostic. - **Fix:** `PackageStorage` validates every file range against the original payload before mounting or adding a virtual final name terminator. The size check uses subtraction to avoid 64-bit overflow, and accepts an empty file at EOF. `OpenNsp` probes the XCI header only when enough bytes exist, then routes malformed PFS0 headers and payload ranges to a named `[RED] the NSP is damaged` message and exit code 3. `--allow-damaged` cannot supply missing container bytes, so it does not bypass this check. The source is never changed. - **Found on:** [Diablo II: Resurrected](../../dm/games/0100726014352000/README.md), whose separate licence-only DLC package was truncated ([issue #2013](https://github.com/seedds/nxnative/issues/2013)). Main now has the shared [CASC/SHAD reader](shaders.md#blizzards-casc-storage-and-shad-containers); that separate shader-discovery fix does not repair missing package bytes. The reported base game alone (v0) remains unchecked, as the game note records. - **Check:** `dm/tools/tests/test_pfs0_storage.py` exercises synthetic payload truncation, out-of-range and overflowing spans, an empty file at EOF, and the CLI's damaged-input exit with and without `--allow-damaged`, with both normal and missing-final-NUL name tables. ### DLC extraction rejects an archived filename - **Symptom:** `nx_extract --aoc --romfs-image` stops with `ResultFsInvalidCharacter (2002-6004)` after selecting the add-on's data NCA. - **Cause:** LibHac 0.19 enumerates a RomFS directory named `D:`, then rejects the colon when the string-based file-open overload validates the full path. - **Fix:** for this result on a LibHac RomFS, the image writer uses the path it got from archive enumeration with LibHac's typed file-open overload. Reads still go through the NCA's integrity-checked storage. The image preserves the original bytes and name. - **Found on:** [CAPTAIN TSUBASA 2: WORLD FIGHTERS](../../dm/games/01009720213B0000/README.md), all five supplied DLCs. `test_romfs_read.py` also exercises a synthetic archive with a literal `D:` directory. ### PFS0 file-name table missing its final NUL - **Symptom:** package identification stops with `ValueError: subsection not found` in `pfs0_names`, or LibHac reports `ResultFsPathNotFound` opening the last file of an NSP. - **Cause:** older NSZ writers omitted the final NUL in the PFS0 string table. The final name is bounded by the table length, but the Python scanner required a terminator and LibHac reads names as NUL-terminated strings. - **Fix:** `nx_extract` supplies LibHac with a virtual header containing the missing NUL followed by the original payload storage. File offsets remain relative to that payload, and the source package and encrypted NCA bytes are unchanged. Truncated tables and out-of-table name offsets still fail. Synthetic package tests cover the reader and payload preservation (`test_pfs0_storage.py`). The Python scanner's own table reader (`pfs0_names`), which accepted the table boundary as the end of the final name, is gone: the scan reads every package through `nx_extract` ([An update is taken for the version in its file name](#an-update-is-taken-for-the-version-in-its-file-name)). - **Found on:** Moving Out 2 (`010065D018172000`), base 1.1.254 NSP and update 1.3.315 NSZ. Package reading was checked, not gameplay. ### A NUP with complete standalone updates stops at "no base game" - **Symptom:** `no base game, only update packages: pack the base game and its update into one NUP`, even when the update carries the complete game's files ([issue #1195](https://github.com/seedds/nxnative/issues/1195)). - **Cause:** `pack_nup.scan` required a `base` record. NUP v1 permits a container without one when every update has the `standalone_update` flag (package flags bit 0, [SPEC §3.1.2](https://github.com/a55uka/nup/blob/meow/SPEC.md#312-package-kinds)). The reference packer writes one for a dump with no `base/` folder and, since its commit `92089de3`, for an empty `base/` too; before that an empty `base/` gave an empty base record, which got through the check. The issue was filed before that commit, so its NUP came from a dump with no `base/` folder or from another packer; the file itself was not seen. - **Fix:** no base record and a base record with no files are one case: `scan` gives `None` for the base, and only the update versions present are offered. Both packing entry points select the newest update by default; requesting version 0 fails. The selected update must have `exefs/main`, `exefs/main.npdm` and its own RomFS; it cannot borrow another update's RomFS. Control data the update lacks comes from the record that holds application metadata: the empty base record, else the first package ([SPEC §5.1](https://github.com/a55uka/nup/blob/meow/SPEC.md#51-localized-records-types-0x0009--0x000a)). A base with files still supplies the RomFS for an update without one. Program-ID, DLC, content-size and SHA-256 checks apply as before. A version that cannot be packed stops at a `[RED]` line: the disk check reads its RomFS folder before extraction, so `cli()` catches `pack_nup.Error`. - **Not known from the file:** whether the update is the whole game. The flag does not promise it (the spec says such an update needs a matching base elsewhere), and an update holding only changed files would pack and then fail at boot, after a full shader build. The scripts print that the update is taken as the whole game. Measured: both NUPs at hand have an update RomFS that holds every path of its base (Age of Imprisonment: 2,065 base files, 2,153 in the update, none missing; Yoshi and the Mysterious Book: 147 and 147, none missing). - **Found on:** [Mario Kart World](../../dm/games/0400C3F00006E000/README.md). Reproduced with its base dump repackaged by the reference tool as a standalone-update fixture; this checks packaging, not the reported 1.8.0's contents or gameplay. Synthetic tests cover both entry points, both forms of no base, multiple versions, control data, DLC and incomplete updates. ### A completed build still needs its original package or NUP - **Symptom:** after a successful build, removing the original NSPs or NUP saves tens of gigabytes, but the next `build_ipa_from_nsp.py` run asks for `prod.keys` or reports no package. The build already holds the complete `extract/v*/ExeFS` and `RomFS.img` that the game runs from. - **Cause:** the script recognized only packages, NUP containers and loose dump trees as inputs. Its extracted image was a cache owned by one of those sources, never a source itself, even though every later stage reads that image and the rewritten modules, shaders, host and saves already share its build folder. - **Fix:** an existing build folder (with `extract/v*` and no package, NUP or dump beside it) is an input. Every `extract/v*` entry must have `ExeFS/main`, `ExeFS/main.npdm`, a valid `RomFS.img` (and valid `romfs_programs/*.img` if present), and one shared program ID; `-p` selects among its versions. Existing `aoc/*.img` files (ignoring `._*` sidecars) are validated and reused in place, and no package, NUP, key or extraction step is involved. Profile lookup stays normal: repository profiles (and regional `same_build` matches) take precedence over build-local `profile/` outputs so repo updates and derived builds work, while an unregistered game reuses its local provisional profile or surveys from `extract/v*`. The input is also the work folder: another `--work-dir` is refused, `--no-keep-extracted` keeps `extract/` untouched, and missing-icon/name notices never advise deleting `extract/`. - **Found on:** [Hyrule Warriors: Age of Imprisonment](../../dm/games/04003F40232DE000/README.md), whose 43 GB extracted image rebuilt from its build folder after the 44 GB NUP was no longer used (PR #3530). `test_nsp_existing_build.py` covers detection, numeric version ordering, validation, package precedence, repo-vs-local profile precedence, derivation, provisional reuse, `same_build`, `survey_extracted`, `--no-keep-extracted`, missing-icon notices, and `aoc/` reuse. ### A registered update with its own shader tables is reported red or packed with another version's shaders - **Symptom:** packing a registered build from a derived profile on a multi-build game prints `[RED] this Mac app uses (), which game profile was not brought up on (...): its settings, with this version's own shaders; every module is a registered build`, naming `` among the registered builds. Or, when a profile registers an update whose shaders are not in `shader_versions` and both the base and update are present, the build stays non-derived and packs `shader_versions`' shader libraries into the update instead of the update's own shaders. - **Cause:** two separate assumptions in `scripts/build_ipa_from_nsp.py`. First, `report_profile_status` compared `g.builds() == reg.builds()` (the whole build table, including other versions and the `display` string), whereas `derive_profile` keeps only the packed version's row, so a multi-build profile never matched. Second, `main` assumed `shader_versions` covers every registered `build` row whenever `all(v in have for v in need)` held, even when `pkg_ver` was not in `shader_versions`. - **Fix:** `profile_derivation_reason` treats committed shader tables as covering `shader_versions` plus any additional registered builds explicitly verified in `shader_covers` (Hades II `v655360`, FIFA 23 `v196608`); any other registered build derives its own shader tables even when `shader_versions` is present (and avoids extracting `shader_versions` unnecessarily). `report_profile_status` compares `pkg_ver`'s module build IDs (ignoring `display`) against `reg.builds().get(pkg_ver)` and reports registered builds without `[RED]`, while mismatched, mixed, or unregistered modules stay red. `dm/tools/tests/test_nsp_registered_update.py` covers all cases. - **Found on:** [Mario Kart World](../../dm/games/0400C3F00006E000/README.md) 1.8.0 (`v917504`, 11,601 shaders vs `v0`'s 11,558; PR #2621) and existing multi-build profiles such as [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) when packed without all `shader_versions`. ### An update's prewarm capture reports missing shaders - **Symptom:** `merge_prewarm_seeds.py` reports `profile package v0` and `missing shader` for rows captured on an update. A capture with only duplicates and missing shaders can disappear from the local inbox. - **Cause:** the importer checked every capture against the repository profile's shader map. Its cleanup treated a key absent from that map as missing from the capture's version. Separately, once `shader_map.tsv` was no longer committed in `dm/games/`, falling back to format-only validation when no shader map was found allowed cross-game `pso_user.tsv` uploads (e.g., from shared-directory launchers) to pollute `pso_manifest.tsv.gz`. - **Fix:** resolve the capture's version against shader coverage in local build profiles (`--games-dir`, `REGRESS_GAMES`, `DM_GAMES_DIR`). Reject unfiltered captures (require `# prewarm-filtered-v1` produced by `PrewarmUpload.swift` against the app's bundled `dm/shader_map.tsv`); validate against available local shader maps when present, and when no local map is available allow `# prewarm-filtered-v1` captures with pipeline format validation and Switch 1 `M`-row rejection. Keep the capture if any rows remain unresolved. `--prune` cleans existing manifests against local shader maps. [Prewarm import usage](../development.md#prewarm-lists) - **Found on:** [Mario Kart World](../../dm/games/0400C3F00006E000/README.md#180) (update map mismatch) and [The Legend of Zelda: Breath of the Wild](../../dm/games/01007EF00011E000/README.md) (cross-game manifest contamination). ### A NUP or a dump of a game with no profile stops before the survey - **Symptom:** `[RED] a NUP packs only a game with a profile, and has none: the survey that makes a provisional profile reads NSPs`, or the same line for a dump folder ([issue #1265](https://github.com/seedds/nxnative/issues/1265)). A folder holding `exefs/` and `romfs/` directly, or only `updates/<version>/`, was not taken for a dump at all: the script asks for `prod.keys`, then stops with `no NSP with a readable title ID`. - **Cause:** the survey and the build ID lookup (`same_build`) ran `nx_extract --manifest`, which reads NSPs. `pack_dump.is_dump` asked for `base/exefs/main.npdm`. - **Fix:** each source leaves the same files for the survey: `survey_nup` reads the newest version from the container (its ExeFS, a RomFS manifest in `nx_extract`'s format: path, size, first 32 bytes, `Nup.head` inflating only those; the NROs whole and the control data), and `survey_dump` from the folder, whose name names the game, as a dump has no control data. `same_build` reads main from the container or the folder. A dump may have no `base/` when an update's folder holds code and a RomFS, and `exefs/` and `romfs/` directly in the folder, as `nup extract` writes them, count as `base/`: version 0, so a profile that registers another version packs them from a derived profile. - **Found on:** Star Fox (`0400E88025B1A000`, update v131072; no profile in the repository then), The Legend of Zelda: Ocarina of Time (`0400486024DEC000`, issue #1265) and [Fire Emblem Fortune's Weave](../../dm/games/04007EF01F8AE000/README.md), whose dump holds `updates/131072/` alone. ### A damaged file in a NUP or a dump has no hash to fail - **Symptom:** the game reloads one asset for ever: a background loader takes about a core and the process several (Ocarina of Time: 412% CPU on the Mac, `OptimizeChangeBanc` and `ParallelDecompThread` busy all session, one model and its texture opened about 22 times a second). Or, from the NSP script: `vN: K file(s) whose bytes do not start as their names promise (a .zs file that is not a zstd stream), so the game files are damaged`, then the files. - **Cause:** the game files themselves. An NSP's files are checked against the NCA's hashes at extraction, so a damaged one stops the build ([`--allow-damaged`](../development.md#the-packing-script-in-detail)). A NUP or a dump folder carries no such hashes: whatever bytes it holds are packed. On one NUP of Ocarina of Time three `.zs` textures began with 12,288 zero bytes, so no zstd frame: the game could not decompress them, and its loader asked for them again on every pass ([PR #1530](https://github.com/seedds/nxnative/pull/1530)). The container's own SHA-256 of each file matched, so the bytes were like this when the NUP was packed. Another NUP of the same version holds all three as zstd streams, and none of its 102,185 `.zs` files fails the check. - **Fix:** the NSP script reads the first bytes of every file whose name promises a format (`romfs_image.FORMAT_HEADS`: `.zs` starts with a zstd frame or a skippable frame) once per extracted image (`check_formats`, after extraction; the result is kept in `RomFS.img.formats` beside the image until the image changes: Ocarina of Time 16 s from a USB SSD) and stops naming the damaged files: pack again from a good copy of the game. `--allow-damaged` lists them and packs them as they are. The host serves a game's files as they are: substituting other files for damaged ones would hide the damage and change what the game draws. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md), a contributor's NUP of v131072. ### A NUP whose folder contains itself - **Symptom:** `pack_nup.py`, or the NSP script on a NUP, ends in a Python traceback (`RecursionError` in `tree_bytes`) instead of a `[RED]` line. - **Cause:** `Nup` checked each folder's child range and each child index against the table sizes, but not that the folders form a tree. A table of contents whose hash matches can still name a folder, or one of its ancestors, as its own child; `scan` sums the base package's size by recursion and never ends, and `entries` (the RomFS image's walk) would loop. - **Fix:** `Nup` walks the folder graph once, depth first without recursion, and refuses a folder that contains itself, naming it (`contains itself (damaged file)`), before any other walk sees the container. - **Check:** `test_nsp_nup` Read.test_folder_cycle_refused: a folder made its own parent, then a cycle of two folders, each with the TOC hash fixed up, are refused, and the script exits 1 with no traceback. Without the check the container opens. - **Found on:** a code audit; no damaged NUP of this kind is known. ### A NUP icon is written as control data - **Symptom:** the JPEG icon in a NUP is written as `control.nacp` and the display version is written as `icon.jpg`. A wrong-size NACP can also supply incorrect application and DLC IDs during scanning. - **Cause:** [nup PR #20](https://github.com/a55uka/nup/pull/20) replaced explicit TLV values with an enum that starts at 0. SPEC §5 starts at 1, so each type in a block produced by that writer is one too low. The upstream writer fix in [nup PR #22](https://github.com/a55uka/nup/pull/22) starts the enum at 1. In nxnative, scanning used the offsets of the ID fields as its only NACP size check. - **Fix:** `Package.meta()` normalizes a shifted block at read time. NACP and icon payloads determine the numbering when they can, with type 0 or a non-32-byte type 7 as fallback markers ([nup PR #32](https://github.com/a55uka/nup/pull/32)). The same reader omits NACP records whose size differs from `0x4000` before scanning or extraction uses them. Extraction reports these decisions once per package. - **Found on:** a sample written with upstream `nup` at `a4840f06` reproduced the swapped files. A Resident Evil 4 archive confirmed shifted numbering. A Super Mario Bros. Wonder archive contained a valid NACP at type 2 alongside shifted records. ### A Switch 2 Edition NUP stops at "2 base packages" or "is not a base title ID" - **Symptom:** `[RED] <file>.nup: 2 base packages`, `base program ID 040015100B514001 is not a base title ID`, or `010015100B515001 is not a DLC of 040015100B514001`, from a NUP of a Switch 1 game's Nintendo Switch 2 Edition ([PR #2692](https://github.com/seedds/nxnative/pull/2692)). Packed by hand on its own RomFS, the Switch 2 program crashed within a second of `nnMain` on a null `this` in a constructor: with no heap sizes the engine's heaps were never made. With an add-on older than the program: `[RED] game asks to show an error: its upgrade add-on content is older than this program needs`, then `CRASH sig=4` at the game's own trap (before the hook, a crash in `sdk` under `nn::applet::StartLibraryAppletImmediately`). - **Cause:** a Switch 2 Edition is one application of two programs, and `scan` took one base package and derived the application and its DLC from that program's ID. The Switch 1 program (`010015100B514000`, index 0) holds the game data; the Switch 2 program (`040015100B514001`, index 1) has a RomFS of a few files of its own, and its ID differs from the application's above the low 12 bits. The game data is not laid over the Switch 2 program by the system: Super Mario Bros. Wonder's Switch 2 code mounts its own RomFS as `content:`, and when that has no `System/AddressTable` it mounts program 0's RomFS with `nn::fs::MountRom(name, 0, …)` as `conorig:` and the upgrade add-on with `nn::fs::MountAddOnContent` as `aocup:`, and looks up each file in `aocup:`, then `conorig:`. Before that it reads `aocup:/System/AocUpgradeVersion.txt` and stops below 3 (`main+0x132b9b4`, 1.2.1) with `nn::err::ShowUnacceptableAddOnContentForUpgradeVersionError`, which the host did not answer. The host ignored that program index and served the program its own RomFS ([`fs::MountRom` with a program index](services.md#older-sdk-names-for-the-same-calls)). NUPs come in other layouts too: on S790, Wonder's and Xenoblade Chronicles X's Switch 2 Editions each hold one base package, the Switch 2 program's, whose packer had already merged the game data into its RomFS. - **Fix:** `scan` groups base and update packages by their NPDM's program ID; the low 12 bits are the program index, and the programs must belong to one application, which the NACP names (`SaveDataOwnerId`, else the program ID above those bits). It packs one program (`--program N`, default the highest index, the Switch 2 program), with its own updates. Each other program's RomFS, at that program's newest update no higher than the packed version, goes beside its own as `romfs_programs/<index>.img`. The host's `MountRom(name, index, …)` mounts that image (`DM_ROMFS_PROGRAMS`, default `romfs_programs` beside `DM_ROMFS`), and its own RomFS when there is none. The Mac app (a `GameDataPrograms` data bundle), the IPA and the Xcode project carry the folder beside the RomFS, and the iOS app names it when its RomFS is in Documents. A DLC's index is its title ID minus the NACP's `AddOnContentBaseId` (else the application's ID + 0x1000, or the Switch 1 counterpart's ID + 0x1000 when a NACP-less Switch 2 container's add-ons all fall in its range). The add-on is packed as DLC only, laid over no RomFS: the game checks its version and layers it itself, where a merge into the program's RomFS skipped both. The survey lists the other programs' files after the program's own, and the format check reads their images. The host answers the upgrade-version error applet with the red line above. - **Check:** `test_nsp_nup` Programs (the default and `--program`, both programs with updates, the one-program layout, the refusals, the script's survey, disk estimate and format check), `test_nsp_mac_app` `test_other_programs_romfs_beside_the_romfs`, `test_xcode_workflow` (staging), `t_fs` (an index with an image, one without, `DM_ROMFS_PROGRAMS`). On the Mac (M-series, 1.2.1, provisional profile): the S790 NUP packed as it is (one base, merged RomFS, which has `System/AddressTable`, so the game mounts no other RomFS) reaches the title, the menus and the character choice. Laid out as PR #2692's NUP, the program's own 144-byte RomFS (`System/RegionLangMask.txt`) with a program 0 image beside it: the game mounts `conorig:` from `romfs_programs/0.img` and `aocup:` from `aoc/1.img`. With the Switch 1 1.2.1 RomFS and the S790 add-on (`AocUpgradeVersion.txt` 1) it stops at the version check, as the console would; with that file made 3 it reads its Switch 2 heap sizes from `aocup:` and needs one file neither holds (`RSDB/DVModelBakeInfo.Product.110.rstbl.byml.zs`, only in the S790 NUP's merged tree), and with that tree as program 0's image it reaches the opening in the Flower Kingdom. A consistent two-program NUP of 1.2.1 was not at hand. - **Found on:** [Super Mario Bros. Wonder – Nintendo Switch 2 Edition + Meetup in Bellabel Park](../../dm/games/040015100B514001/README.md) (`040015100B514001`, 1.2.1), first packed by a contributor in [PR #2692](https://github.com/seedds/nxnative/pull/2692), whose RomFS merge this replaces; [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) is its Switch 1 program. ### A provisional profile of a Switch 2 game shows no SDK and a Switch 1 memory pool - **Symptom:** the survey of a Switch 2 game says `SDK: ?` and `no SDK version string found`, and its provisional profile has `app_pool 0xCD500000`. - **Cause:** the SDK version pattern did not take the variant the Switch 2's SDKs name (`NintendoSdk_nnSdk-Generic_21_4_4`), and `guess` had one pool, a 4 GB Switch's. - **Fix:** the pattern takes the variant, and an `sdk` built for the Switch 2 (`spec: Ounce`, as `dm_sdk_ounce` reads it) gets the 9 GB pool every Switch 2 profile has. Open: only the pool changes; a game with system resource keeps the 5 GB block (Star Fox's profile has 21 GB with a 16 GB alias region), so a provisional profile may still not fit and needs the bring-up. - **Found on:** Star Fox and Kirby Air Riders (`040077201BE50000`; no profile), read from their NUP and extraction; first reported with [Fire Emblem Fortune's Weave](../../dm/games/04007EF01F8AE000/README.md). ### Extracted Control NCA metadata for dump folders - **Symptom:** a game built from a dump folder is labelled after the folder (such as `dump`), has display version `?`, no supported language list and no app icon, even when the dump holds an extracted Control NCA (`control/control.nacp`, `control/icon_<Language>.dat`), or an Ounce (`0400`) program picks the Switch 1 `control/` identity instead of its `control/Acd_1/` Switch 2 Edition identity. - **Cause:** `pack_dump.py` and `survey_dump` ignored extracted Control NCA directories and never mapped them to `control.nacp` and `icon.jpg` beside `ExeFS` and `RomFS.img` as `nx_extract` does for NSPs, and `build_ipa_from_nsp.py` read `app_name` only from `base / 'control.nacp'`. - **Fix:** `pack_dump.copy_control` maps the selected version folder's `control/control.nacp` and localized `control/icon_<Language>.dat` (in `nacp.LANGUAGES` order—American English, British English, Japanese, …—matching `nx_extract`, with sorted `icon_*.dat` as catch-all) into `out/control.nacp` and `out/icon.jpg`, falling back to loose `control.nacp` / `icon.jpg` in that same version folder. When the version's `exefs/main.npdm` is an Ounce (`0400`) program and `control/Acd_1/` is present, `control/Acd_1/` is preferred over `control/`. Missing or moved sources remove stale outputs; nothing walks above the chosen version directory. Both `pack_version` and `survey_dump` call `copy_control`, and `build_ipa_from_nsp.py` prefers `game / 'control.nacp'` over `base / 'control.nacp'` for `app_name`. Note: `pack_dump.scan` still requires program index 0 (`app & 0xFFF == 0`), so multi-program / Program 1 folder dumps remain separate work. - **Check:** `dm/tools/tests/test_nsp_dump.py` covers Switch 1 vs Ounce `Acd_1` selection, `nacp.LANGUAGES` icon priority (`BritishEnglish` over `BrazilianPortuguese`), partial `Acd_1` fallback, loose fallback, stale removal without parent-folder fallback, read-only overwrite, real `0x4000`-byte NACP parsing through `pack_version`/`survey_dump`, and update-over-base `app_name` selection. - **Found on:** [Super Mario Bros. Wonder – Nintendo Switch 2 Edition + Meetup in Bellabel Park](../../dm/games/040015100B514001/README.md) (`040015100B514001`, v327680; [PR #1562](https://github.com/seedds/nxnative/pull/1562)), where `control/` held the Switch 1 title and `control/Acd_1/` held the Switch 2 Edition title and icon. ## Build tools ### Stopping a build left its tools running - **Symptom:** after the NSP script was stopped in Spyder (its interrupt), or by a front end's SIGTERM, the tool it was running went on: a shader build or `build_ipa.sh`'s `xcodebuild` kept the CPU busy and wrote into the build folder that the next build reads, and the script could wait for it with no end. A regression run (`regress.py`) stopped during a shader build whose direct child ignored SIGTERM for 10 s left the build's workers running. A tool's child still writing after the tool's own exit was taken for a finished step. - **Cause:** `run` (the NSP script) started each tool in the script's own process group and on an interrupt stopped only that tool (`terminate`, then a wait without a limit); a terminal's Ctrl-C reaches the whole foreground group, but Spyder's interrupt reaches only its kernel, and nothing handled SIGTERM, so the tool's descendants were never told. `run_heavy` (`regress.py`) did start a group of its own, but its fallback after 10 s killed only the direct child, without reaping it, and a child left running after the job's own exit went unnoticed. `run` also read the tool's output until its end, so a descendant holding the output kept it waiting after the tool had exited. - **Fix:** both run their tool through `dm/tools/proc_group.py`: the tool leads a session and process group of its own, and on an interrupt, a SIGTERM or an error (a log that cannot be written) the whole group gets the signal that stopped the caller (SIGINT for an interrupt, SIGTERM otherwise), resumed first when a pause (`run_heavy`'s measuring lock) left it stopped; what is left after 5 s is killed and the tool reaped. A process of the group still running 5 s after the tool's normal exit, holding its output or not, is stopped and fails the step as an exit code would (what it writes may be incomplete); the message names it. The tool's exit is seen while its output is read, so a holder of the output no longer stalls the step. The NSP script's `cli` turns SIGTERM into an exit with code 143 (the [front end's contract](../frontends.md)), with the handler set only while it runs (Spyder's kernel gets its own back). A process that leaves the group itself (`setsid`) is out of reach of group supervision: it is neither signalled nor waited for (one still holding `run`'s output fails the step, unnamed). `patch_nso.py`'s pool of forked workers is outside this change: they stay in the rewrite's group, and the rewrite's SIGTERM handler (`sys.exit(143)`) ends the pool, which stops and reaps them. `boot_mac`, the rewrite pool and regress.py's game runs still stop their direct child only: moving them to `proc_group` is a separate change (`bench.py`'s stop: [Stopping a benchmark left its host running](#stopping-a-benchmark-left-its-host-running)). `dm/tools/tests/test_proc_group.py` runs real process trees (`fixtures/proc_tree.py`) through `run`, `run_heavy` and `cli`. - **Found on:** no game; found in a review of the build scripts, with a repro (an interrupt raised in `run`'s progress callback, after which the tool's child kept writing). ### Closing the terminal left a build's tools running - **Symptom:** after the terminal running the NSP script or `regress.py` was closed, the tool the script was running (a shader build, `xcodebuild`, a game under the harness) went on running with no parent, writing into the build folder; the script itself had gone without its cleanup. - **Cause:** since [Stopping a build left its tools running](#stopping-a-build-left-its-tools-running), each tool leads a session and process group of its own, so the shell's SIGHUP on a closing terminal, sent to its job, reaches the script alone. Neither script handled SIGHUP, and its default action ended the script before the tool's group was stopped; before that change the tool was in the script's group and got the SIGHUP too. Reproduced with a script running `sleep 30` through `proc_group.Group`: a SIGHUP to the script's group ended the script and left the sleep running, where a plain child in the script's group went with it. - **Fix:** the NSP script's `cli` turns SIGHUP into `Stopped` as it does SIGTERM (the running tool's group stopped, the stage line ended, exit code 129; both handlers set only while `cli` runs and given back after), and `regress.py`'s main exits with 129 on SIGHUP as with 143 on SIGTERM, so the finally blocks stop the game or build's group. `test_proc_group` (`Cli.test_sighup_during_a_tool`) sends a real SIGHUP to the script while a tool's group runs and checks the group is gone and the tool got its SIGTERM. - **Found on:** no game; found in the audit of the review's process-group change. ### Stopping a benchmark left its host running - **Symptom:** after `bench.py` was stopped with SIGTERM (`kill <pid>`, a front end's or a wrapper's stop), the game host it had started went on running the route headless or in its window, and `--lock` stayed. The next measuring run on that Mac (another `bench.py --lock`, `regress.py --lock`) then waits: its stale check (`lock_holder`) takes a lock whose process is gone for held while a `dmhost` runs, and the leftover host is one (read in the code, not run). - **Cause:** `bench.py` set no SIGTERM handler, so Python's default ended it at once and `run_one`'s `finally`, which stops the host (SIGTERM, a SIGKILL 5 s later) and removes the lock, never ran. An interrupt did run it, but ended with a traceback and Python's own exit by SIGINT. A second interrupt during the host's 5 s grace period skipped the kill and the lock's removal, and a synchronous signal raised during `subprocess.Popen` (after `_fork_exec` started the child, before `p` was bound) or `wait_lock` (between `os.open` and returning) could still orphan the host or leak an empty lock file (read in the code). - **Fix:** `main` turns SIGTERM into `Stopped` (a `BaseException`, as the NSP script's `cli` does) and handles SIGINT through the same handler while it runs, restoring the caller's handlers in its `finally`; exit code 143 (`stopped (SIGTERM)` on stderr) or 130 (`interrupted`). A Python-level deferral (`_defer_stops`) holds SIGTERM and SIGINT across the brief `subprocess.Popen` launch and atomic lock creation so `p` and lock ownership (`hold_lock`) are bound before unwinding, while keeping the child's signal mask unblocked and `SIG_DFL` across `execve`. `stop_host` escalates a second SIGTERM or interrupt during the 5 s grace period to an immediate SIGKILL, retries `p.kill(); p.wait()` if another signal arrives during kill/reap, and re-raises it once the host is gone; `hold_lock` always removes a lock it acquired without touching another live holder's lock. The host stays a direct child in `bench.py`'s process group (not `proc_group`): during a run it starts only the watchdog's synchronous `/usr/bin/sample` (`crash.c`), and a terminal's Ctrl-C and SIGHUP still reach it directly. `dm/tools/tests/test_bench.py` (`Stop`) covers SIGTERM, SIGINT, a SIGTERM-ignoring host, an escalating second SIGTERM, handler restoration, SIGTERM/SIGINT during `Popen` before assignment, repeated signals during `kill`/`wait`, and SIGTERM while waiting on another process's lock. - **Found on:** no game; found in a review of the benchmark script, with a repro (a fake build folder and host: after SIGTERM to `bench.py` the host was still running and the lock still there). ### Stopping a build while it replaced an output left that output half deleted - **Symptom:** none seen on a game. An interrupt, a SIGTERM or a failed delete while the NSP script replaced one of its outputs (an extraction, the rewritten modules, the NROs, a DLC folder, a shader capture, the shader package) could leave that output half deleted at its real path, and a reuse check that looks for a few files (`extract`'s: `ExeFS/main`, `RomFS.img`, the RomFS marker) could take it for a finished output on the next run. - **Cause:** `swap_in` deleted the old output in place (`rmtree(dst)`) and only then renamed the staged one (`<dst>.partial`) in; its comment said the old one was untouched on failure. Its callers already write their completion stamps only after the swap, so the old output was stale whenever it was replaced: the loss was the half-deleted folder, not the old contents. - **Fix:** `swap_in` renames the old output aside (`<dst>.old.partial`, a name the build ignores as it does every `.partial` folder), renames the new one in, and only then deletes the old one; a failure or an interrupt before the new one is in renames the old one back. The output is always the whole old one, the whole new one, or absent. This is recoverable, not atomic: a SIGKILL between the two renames leaves no output (the old one aside), which the next run rebuilds, and a delete stopped after the new one is in leaves the aside folder's remains until that output is replaced again (disk space only). A failed delete of the old output still fails the step, after the new one is in. `dm/tools/tests/test_nsp_swap_in.py` runs each case in a process of its own (`fixtures/swap_in_run.py`): failed and interrupted renames, interrupted and failed deletes, an earlier run's aside folder, a SIGKILL between the renames, each followed by a rerun. - **Found on:** no game; found in a review of the build scripts. The half-deleted output was reproduced with the old `swap_in` (an interrupt during its delete); that `extract` would have reused one is inferred, not reproduced. - **Since:** the step 15 audit found three gaps, each reproduced against the script before it: a rerun after a SIGKILL between the two renames deleted the aside copy, the old output, before publishing again, so a rerun that then failed left no output; an interrupt between the rename aside and the second rename (outside the `try`) put nothing back; and a failure to rename the old one back raised that rename's own `OSError`, hiding the first failure and where the old output was. Now the rollback is judged by what is on the disk (the old output aside and nothing in place: it goes back), a failed putting back raises `BuildError` naming `<dst>.old.partial`, and an aside folder a run finds is put back when nothing is in place and deleted only when the new output went in. The NSZ decompression publishes through `swap_in` too instead of deleting its stale output first. `test_nsp_swap_in`: a kill between the renames then a rerun that fails (the old output back in place), an interrupt right after the rename aside, and a putting back that fails (`BuildError`, nothing deleted, the next run publishes); all three fail on the script before. ### `regress.py list` printed nothing for a mistyped games folder - **Symptom:** `regress.py --games-dir <folder> list` printed nothing and exited 0 when the folder did not exist or held no game with a Mac build, which reads as "no games here, all fine"; `check`, `chain`, `usage` and the other game commands stop on the same folder with `[RED] regress.py: no game with a Mac build under <folder>` and exit 2. - **Cause:** the game commands find their games through `select`, which raises that error on an empty list; `cmd_list` called `find_games` directly, which returns an empty list for a missing folder, and returned 0 whatever it found. - **Fix:** `local_games` (the games, or that error) serves `select` and `cmd_list`, so `list` stops with the same line and exit code. It still runs before the harness root is made and before Metal's cache is cleaned, so nothing is written. - **Found on:** no game; a missing and an empty `--games-dir` in `dm/tools/tests/test_regress.py` `test_list_stops_without_games` (exit 0 and no output before, the `[RED]` line and exit 2 after). ### Building needed .NET, and finding its runtime kept failing - **Symptom:** before running the NSP script, a player had to install the .NET SDK 10, and builds then failed in ways that were about .NET, not the game: a translator that finds no runtime of its architecture ([GitHub issue #54](https://github.com/seedds/nxnative/issues/54), [#248](https://github.com/seedds/nxnative/issues/248)), a Homebrew runtime the apphosts cannot find, a dll tied to one architecture ([#803](https://github.com/seedds/nxnative/issues/803)), the entries below. [GitHub issue #1853](https://github.com/seedds/nxnative/issues/1853) asked for the tools to be rewritten in Python or Objective-C. - **Cause:** both C# tools were framework-dependent: the shader translator a committed apphost with its dlls, which needs a .NET 10 runtime of the architecture it starts as, and `nx_extract` built with `dotnet build` on the player's Mac at each run. Neither needs .NET itself: Ryujinx's shader library and LibHac compile ahead of time. A rewrite would have replaced about 49,000 lines of Ryujinx's translator and LibHac's NCA, patch and container layers with new code, changing every game's shaders or extraction on any difference. - **Fix:** both are committed as native universal executables (NativeAOT, arm64 and x86_64), `dm/gfx/tools/dmsh_xlate_bin/dmsh_xlate` and `dm/tools/nx_extract_bin/nx_extract`, which `dm/tools/native_tools.sh` builds (the .NET SDK is needed only there). Each embeds its sources and prints their digest with `--source-sha`: `tool_lock.py` refuses a translator, and the NSP script (`find_nx_extract`) an `nx_extract`, not built from the sources in the repository, and the lock records the translator's own fingerprint in place of its dlls'. The NSP script no longer asks for `dotnet`, sets `DOTNET_ROOT` or builds `nx_extract`. `dm/tools/tests/test_native_tools.py` checks that both are universal, alone in their folders, built from their sources and, for the translator, the lock's. Measured before landing: the native translator wrote the same SPIR-V, reflection files and messages as the framework-dependent one for 2,058 shaders of Octopath Traveler II (Maxwell) and 672 of Splatoon Raiders (Ampere), byte for byte, and the native `nx_extract` the same ExeFS and merged RomFS image (651 MB) of Big Brain Academy: Brain vs. Brain with its update, and the same `--contents` and `--keys` output. The cost: each translator rebuild adds about 1.4 MB to the repository's history (the dlls about 0.3 MB), since the executable holds the runtime; the build is not byte-reproducible, so a rebuild only follows a source change. - **Found on:** every game's build; reported in [GitHub issue #1853](https://github.com/seedds/nxnative/issues/1853). ### The committed translator crashes at address 0 on macOS 26 - **Symptom:** on macOS 26 the NSP script stops before extracting anything with `[RED] the shader translator does not run (exit code -11)`, and `dmsh_xlate --source-sha` exits 139: `EXC_BAD_ACCESS` at address 0 with pc 0, called from `dmsh_xlate +0x5adc`. On macOS 27, and under `arch -x86_64`, it runs. - **Cause:** the arm64 slice committed with the [native tools](#building-needed-net-and-finding-its-runtime-kept-failing) imported `pipe2` weakly: its minimum macOS is 12.0, and `pipe2` is declared from the macOS 27 SDK on. The .NET runtime's `SystemNative_Pipe`, which opens the signal pipe at start, was compiled to call it without a check, so on a Mac without it the import binds to 0 and the call jumps there. Microsoft's NativeAOT runtime pack (10.0.14, built against the macOS 15.5 SDK) has no such call: a build with it on the same sources has no `pipe2` import. So that slice was linked with another `libSystem.Native.a`, one configured against the 27.2 SDK; which .NET gave it is open (a source-built one, such as Homebrew's formula, builds its host architecture's pack against the installed SDK, which would also explain the clean x86_64 slice). - **Fix:** the translator is rebuilt with Microsoft's .NET SDK. `native_tools.sh` refuses a slice with a weak import before it joins the slices, and `test_native_tools.py` (`test_no_weak_imports`) reads the symbol tables of both committed tools, so a function newer than the minimum macOS cannot be committed again from any Mac. `nx_extract` had none. Measured: over the translator jobs of a full Cuphead shader build, the new arm64 slice wrote the same files as the old one, byte for byte. Not run on macOS 26 here. - **Found on:** every game's build on macOS 26 ([GitHub issue #2190](https://github.com/seedds/nxnative/issues/2190), [#2239](https://github.com/seedds/nxnative/issues/2239), [#2227](https://github.com/seedds/nxnative/issues/2227)). ### Homebrew .NET is on PATH but apphosts cannot find the runtime - **Symptom:** the first extraction stops with `nx_extract exit code 131` and `.NET location: Not found`, even though `dotnet` is on `PATH`. The shader translator can fail the same way. - **Cause:** standalone .NET apphosts search runtime roots and registered installations, not `PATH` ([.NET runtime discovery](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-environment-variables#dotnet_root-dotnet_rootx86-dotnet_root_x86-dotnet_root_x64)). Homebrew's formula installs the runtime under `libexec` and its `bin/dotnet` can be a wrapper that sets `DOTNET_ROOT` only for its own child ([Homebrew caveat](https://formulae.brew.sh/formula/dotnet)). Resolving that wrapper's symlink gives `bin`, not the runtime root. - **Fix:** resolved for good by [native tools](#building-needed-net-and-finding-its-runtime-kept-failing), which need no runtime; `configure_dotnet` is gone. Before that, `scripts/build_ipa_from_nsp.py` `configure_dotnet` derived the root from the `Microsoft.NETCore.App` entry in `dotnet --list-runtimes`, using the build's environment, before any extraction or survey. It exports `DOTNET_ROOT` both to that environment and to `os.environ`, for tools launched with an explicit environment and those that inherit it. Caller-supplied roots, including architecture-specific overrides, retain precedence. A failed or malformed probe leaves the environment unchanged rather than guessing the wrapper's directory. - **Found on:** [Balatro](../../dm/games/0100CD801CE5E000/README.md), first extraction with Homebrew .NET ([PR #284](https://github.com/seedds/nxnative/pull/284)). Applies to every game's build on that installation setup. ### The shader step stops with an empty `xlate_source` - **Symptom:** the extraction and captures succeed, then the shader step stops with `translation chain tools do not match the lock file: xlate_source: lock … / actual` and nothing after `actual`, which reads like a stale translator. - **Cause:** the translator (`dmsh_xlate_bin/dmsh_xlate`) is a universal framework-dependent apphost. When it finds no .NET 10 runtime for the slice it starts as, it exits 131 with an empty stdout. A Python under Rosetta (an Intel Homebrew's) starts it as x86_64, and it finds only the arm64 .NET; extraction is not affected, because `nx_extract` is built for the SDK's own architecture only. An Intel .NET on Apple silicon, or a `DOTNET_ROOT` that names one, fails the same way. `tools_now` (then in `dmsh_chain.py`) kept only the stdout of `dmsh_xlate --source-sha`, without its exit code or stderr, so the apphost's own message was lost. - **Fix:** the translator is now native and needs no runtime ([native tools](#building-needed-net-and-finding-its-runtime-kept-failing)); the checks below stay, for a translator that does not start. The NSP script checks the environment before extracting anything: `check_native_python` stops under Rosetta (`sysctl.proc_translated`), and `check_prereqs` starts the translator once with `--source-sha` and stops with its first message line (`check_translator`). It also checks glslang and, for an iPhone build, the iOS SDK (`check_ios_sdk`, before the Metal check, whose message would blame the Metal toolchain). `own_compilers.py` no longer asks a Mac-only shader build (`DMSH_TARGETS=mac`) for the iOS Metal compiler. `tool_lock.py` records `--source-sha`'s failure instead of its empty stdout (`xlate_embedded`: `does not run (<first message line>)`), so `dmsh_build.py` run directly and `--update-lock` stop with the same message as the NSP script, without the lock and rebuild lines. The tool checks used to be in `dmsh_chain.py`, which is part of the chain version and of every shader's cache key, so that fix rebuilt every library; they now live in `tool_lock.py`, outside both, and a change to them rebuilds nothing. - **Found on:** NX2Apple builds ([LNPANDY/NX2Apple#31](https://github.com/LNPANDY/NX2Apple/issues/31), item 3; [PR #477](https://github.com/seedds/nxnative/pull/477), [PR #487](https://github.com/seedds/nxnative/pull/487)); reproduced with `arch -x86_64`. Applies to every game. ### An Intel Mac cannot load the bundled translator's dll - **Symptom:** on an Intel Mac, the NSP script stops at its translator check with `[RED] the shader translator does not run (Unhandled exception. System.IO.FileLoadException: Could not load file or assembly '…/dmsh_xlate.dll'. The assembly architecture is not compatible with the current process architecture.)`, although the .NET 10 runtime for x86_64 is installed. - **Cause:** the launcher `dmsh_xlate` is universal, but `dmsh_xlate.dll` beside it was arm64-only (`PE32+`, machine `0xAA64`). A .NET build for a runtime ID (`-r osx-arm64`) sets an executable's `PlatformTarget` to that architecture unless the project names one, and the repository had no single command for rebuilding the translator, so the bundled dll flipped between AnyCPU and arm64 from one rebuild to the next. The Ryujinx libraries stayed AnyCPU, because a library does not take its architecture from the runtime ID. - **Fix:** resolved for good by [native tools](#building-needed-net-and-finding-its-runtime-kept-failing): the translator has no dll, and `test_native_tools.py` checks its two architectures. Before that, `dmsh_xlate.csproj` pinned `<PlatformTarget>AnyCPU</PlatformTarget>`, so a build with any `-r`, or none, gives an AnyCPU dll (`PE32`, machine `0x14C`, IL only). `dm/tools/tests/test_xlate_anycpu.py` reads the PE/CLI headers of every dll in `dmsh_xlate_bin` and the launcher's Mach-O header, and fails when a dll is tied to an architecture or the launcher lacks x86_64 or arm64; it needs no .NET. The rebuilt translator writes the same SPIR-V and reflection files as the arm64-only one (9,556 shaders compared byte for byte). - **Found on:** an Intel MacBook Pro building any game ([GitHub issue #803](https://github.com/seedds/nxnative/issues/803), which bisected the flips). Applies to every game. ### The Vulkan shader step fails with `Argument list too long: 'xcrun'` - **Symptom:** `vk_shaders.py` stops with `OSError: [Errno 7] Argument list too long: 'xcrun'` after the Metal compiles, in the `metallib` link. - **Cause:** `metallib()` passed every `.air` file as an absolute path in one command. The NSP script runs it with `TMPDIR` set to the work folder, so each path holds that folder's name; a game with thousands of generated modules (Super Mario Galaxy: 3,083 captured shaders, more with the dual-source variants) under a long NSP folder name exceeds macOS's 1 MB `ARG_MAX`. - **Fix:** `metallib()` runs from the files' common folder with relative paths and an absolute output path, so the command length no longer depends on the work folder's name. - **Found on:** [Super Mario Galaxy](../../dm/games/010099C022B96000/README.md), with its dump in a folder named after both games of the cartridge. Applies to every Vulkan game's shader step. ### The shader step stands at 99% after the last shader - **Symptom:** a shader build's progress line stops just short of its total (`42,811 of 42,848` for Ocarina of Time, every shader from the cache) and stays frozen through the late mesh, library-image and table steps before the stage ends, which looks like a hang. - **Cause:** `dmsh_build.py` wrote `DMSH_PROGRESS` at most every half second during `cache check` and `compiling` without flushing the final count, emitted no progress for mesh libraries, `publish_library` (40–49 s for Ocarina of Time's 10.7 GB Mac image on an M3 Max; two images on iOS), or `c1_guard.py` and `cb_extent.py` (6.5–19 s with a warm memo, ~100–106 s cold), and unlinked the progress file before running the table tools. `ShaderWatch` also mapped every step other than `cache check` back to `compiling`, hiding `compiling RT library`. - **Fix:** `dmsh_build.py` now flushes the final count of `cache check` and `compiling`, flushes immediately on every step change, reports `compiling mesh libraries` across `_mesh`, passes an `on_progress` callback through `publish_library` to `shader_lib.write` for `writing the library image` (or `writing the Mac library image` and `writing the iOS library image` on dual-image builds, with file counts and bytes written), and reports `c1 guard` and `uniform read extents` before unlinking `DMSH_PROGRESS` at exit. `ShaderWatch` reads `step`, counts, unit and formatted bytes directly from `DMSH_PROGRESS`. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game) v131072 on an M3 Max ([PR #2684](https://github.com/seedds/nxnative/pull/2684)). Checked in `dm/tools/tests/test_shader_lib.py` (`test_write_reports_progress`), `dm/tools/tests/test_nsp_mac.py` (`test_shader_watch_follows_all_phases`) and `dm/tools/tests/test_shader_toolchain_cache.py` (`BuildProgress`). ### A comma in the build path stops the shader split - **Symptom:** `shader_split.py` stops with `FileNotFoundError` naming only the part of the NSP folder before a comma. - **Cause:** the NSP script joined the RomFS, ExeFS and DLC paths with commas, and the splitter used the same character to separate the paths for each game version. - **Fix:** the NSP script sends each path list as a JSON array. The direct splitter CLI still accepts its original comma-separated arguments. A synthetic base, update and DLC under a path with a comma verify that all three shader sources reach the split. - **Found on:** [Pokémon: Let's Go, Pikachu!](../../dm/games/010003F003A34000/README.md#found-on-this-game) 1.0.2 (`010003F003A34000`). ### The split shader tables differ from a game profile's - **Symptom:** the shader split stops with `the split shader tables differ from game profile <id>'s`, on the game version the profile registers. - **Cause:** the check compares the split's data rows with the profile's byte for byte, so it stops for either of two reasons: other game files, or a change to `shader_split.py` that reads the same files differently. A profile's tables can only be split again where its game files are, so continuous integration cannot catch the second reason. - **Fix:** the error shows each differing table's row counts and its first row on each side. For a splitter change, check that the new rows are right, then copy the tables from `shader/pkg.partial/tables` in the build folder into the profile. A change to the splitter's output also needs the other profiles it reaches split again. - **Duplicate selection (first four profiles refreshed, 2026-11-17, issues [#2916](https://github.com/seedds/nxnative/issues/2916) and [#2921](https://github.com/seedds/nxnative/issues/2921)):** `8d62601f` made `main` use the same checked first-copy selection as RomFS, replacing unchecked last-copy selection. The registered executables of [Splatoon Raiders](../../dm/games/0400380020056000/README.md), [Pokémon Scarlet](../../dm/games/0100A3D008C5C000/README.md), [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md) and [Donkey Kong Bananza](../../dm/games/040074A01BF12000/README.md) each regenerate 40 `main` rows: 22 source labels change and 14 more rows change only their package index. Their maps were refreshed with those 36 differing rows and the current source-column header; every registered key, stage and package and every non-`main` row is preserved. The strict table comparison and duplicate-content checks stay unchanged. Bananza's additional DLC shaders still use the existing DLC-only derived profile; they do not belong in its registered base/update map. - **Registered representatives:** Source labels determine package ordering and indices. When packing a registered build, the splitter prefers the map's occurrence when the same source, key and stage are found, both among shaders collected with `main` and when merging scanned files. It checks duplicate shader payloads before selecting the registered occurrence. The game's copy still takes precedence over a DLC copy, and play captures supply only new shader keys. A missing occurrence falls back to first-copy selection, and the packer checks the generated tables row for row. Standalone splits and new profiles use checked first-copy selection. `test_split_representatives` covers package order, payloads, missing registered sources and the packing gate. - **Further rollout (2026-11-17 to 2026-11-19, issues [#2924](https://github.com/seedds/nxnative/issues/2924), [#2927](https://github.com/seedds/nxnative/issues/2927), [#2946](https://github.com/seedds/nxnative/issues/2946), [#2964](https://github.com/seedds/nxnative/issues/2964) and [#2950](https://github.com/seedds/nxnative/issues/2950)):** [Odyssey](../../dm/games/0100000000010000/README.md#files-and-shaders), [Breath of the Wild](../../dm/games/01007EF00011E000/README.md#files-and-shaders), [Wonder](../../dm/games/010015100B514000/README.md#shaders), [Mario Tennis Fever](../../dm/games/0400D4201C6EA000/README.md#shaders), [Orbitals](../../dm/games/040032B023CA4000/README.md#shaders), [Fire Emblem Fortune's Weave](../../dm/games/04007EF01F8AE000/README.md#shaders), [Pokémon Legends: Z-A](../../dm/games/0100F43008C44000/README.md#files-and-shaders), [Super Smash Bros. Ultimate](../../dm/games/01006A800016E000/README.md#files-and-shaders), [Mario Kart World](../../dm/games/0400C3F00006E000/README.md#shaders) and [Final Fantasy XII The Zodiac Age](../../dm/games/0100EB100AB42000/README.md#files-and-shaders) have verified representative refreshes. Their notes record the checks and limits. - **Found on:** Duplicate source labels occurred in the executable scan for [Echoes of Wisdom](../../dm/games/01008CF01BAAC000/README.md#found-on-this-game) and across RomFS files for [Fast Fusion](../../dm/games/040041E0212AE000/README.md#found-on-this-game). In [Splatoon Raiders](../../dm/games/0400380020056000/README.md) ([issue #1263](https://github.com/seedds/nxnative/issues/1263)), [NVN2 task and mesh shaders](shaders.md#nvn2-task-and-mesh-shaders) moved one row from vertex to mesh. Donkey Kong Bananza, Pokemon Pokopia and Hyrule Warriors: Age of Imprisonment were checked and hold no such shader; Fire Emblem Fortune's Weave was not checked, as no dump was at hand. ### TT Games shaders are missing from the executable and DAT archives - **Symptom:** a provisional build of LEGO Star Wars: The Skywalker Saga reports loose control sections with no code area and misses the shaders in its `.nnx_shaders` members. - **Cause:** some control sections have neither a relocated code pointer nor a nearby instruction constructing one. Headerless compute code also makes both adjacent ranges look plausible by length alone. The remaining shaders live in TT Games' CC4 v2 DAT indices, which the splitter did not read. - **Fix:** keep reference-based matches first, then take a unique adjacent code area. When multiple ranges fit a headerless compute shader, use Maxwell scheduling words and an `EXIT` in an instruction slot to distinguish them. For embedded vertex and fragment assembly, the splitter also recognizes a nearby copy of headed code when the stage and byte count passed to the call agree and the control reference is in the same straight-line sequence. Ambiguous candidates stay unselected. `ttdat.py` reads the bounded index, maps full paths to file records with their FNV-1a hashes, and reads only `.nnx_shaders` members. Older serialized programs keep reflection data between their control section and headed code, searched only up to the next program. OODL members enable the existing Mac host decoder. The splitter reports malformed indices and members through its unreadable-file diagnostics. - **Found on:** LEGO Star Wars: The Skywalker Saga (`010042D00D900000`, 1.10.0, main `ec593a5f9552100a9fe95c4ca9e34873`), [issue #1597](https://github.com/seedds/nxnative/issues/1597). The [original PR](https://github.com/seedds/nxnative/pull/2785) reports 667 executable shaders and 97,648 RomFS shaders from a fresh split with a provisional profile. The rebase was checked on [Advance Wars 1+2: Re-Boot Camp](../../dm/games/0100300012F2A000/README.md#files-and-shaders): all 43 executable shaders, including 32 loose Bink programs, match the previous splitter byte for byte. ### DFLT shader members in TT Games DLC - **Symptom:** the shader split reports `unsupported TT Games compression b'DFLT'` and leaves out the affected add-on shaders. - **Cause:** the CC4 reader handled stored members and OODL chunks. DFLT uses the same 12-byte chunk header with little-endian stored and decoded lengths. Each compressed chunk in the tested DLC holds one final DEFLATE block. The type bits are 0 for dynamic Huffman and 1 for fixed Huffman. Standard DEFLATE expects 2 for dynamic Huffman. - **Fix:** interpret the DFLT block type before decoding with zlib. Require the decoder to consume the whole chunk and produce exactly its declared length within the indexed member size. - **Found on:** [LEGO Star Wars: The Skywalker Saga](../../dm/games/010042D00D900000/README.md) 1.10.0. All 551 compressed chunks from 83 shader members in 15 DLC archives decode. The full split adds 984 shader keys to the 98,315 from the updated game and reports no unreadable files. ### TT Games CC4 layout -11 shader archives are unreadable - **Symptom:** the shader split reports `unsupported CC4 version 2, layout -11` and leaves out the shaders in those DAT archives. - **Cause:** the reader only understood layout -13. Layout -11 uses a 32-bit path hash with multiplier `0x199933` and a full 64-bit member offset. Its compressed shader members use headerless RFPK streams inside the same 12-byte chunk framing as OODL and DFLT. - **Fix:** select the hash width, hash algorithm, and offset decoding from the index layout. Read the RFPK commands within the enclosing chunk's input and output lengths, including overlapping backreferences. The reader still decodes only named `.nnx_shaders` members. - **Found on:** [LEGO CITY UNDERCOVER](../../dm/games/01003A30012C0000/README.md) 1.0.2. [Wanneshey reported the format and diagnosed the missing shaders](https://github.com/seedds/nxnative/issues/3595). The Mac development build reproduced the increase from 331 to 24,063 unique stages, with all five DAT archives readable. ### TT Games / Double Eleven .DATNX gameplay shaders are missing - **Symptom:** a provisional build of LEGO Harry Potter Collection renders the launcher and UI/HUD, but 3D characters and environments are invisible in gameplay with hundreds of `[RED] shader <key> is not in the shader map` lines (only 385 shaders extracted from the NROs and `launcher.pkdswitch`). - **Cause:** both games store their gameplay shaders inside hash-indexed `.DATNX` archives (`harry1_dll/HARRY1.DATNX`, `HARRY1B.DATNX`, `harry2_dll/HARRY2.DATNX`, `HARRY2B.DATNX`), which `shader_split.py` did not read. A `.DATNX` archive has a 16-byte `<QQ` header (`index_offset`, `index_size`), an `<iI` index header (`version == -1`, `resource_count`), `resource_count × 24 B` records (`<QIIII`: `offset`, `marker == 0x12345678`, `stored_size`, `decoded_size`, `flags`), and `resource_count × 4 B` trailing hashes. Flags are `0x00000000` (uncompressed, `stored_size == decoded_size`) or `0x04040404` (zlib-wrapped LZHAM stream with `dict_size_log2 = 15`, Adler-32 verified, default table update rate; includes valid 7-byte streams with `decoded_size == 0`). Because the index carries hashes rather than file names, every member must be decoded and probed without mistaking accidental `CTL_MAGIC` bytes in ordinary assets for malformed shader records. - **Fix:** `dm/gfx/tools/datnx.py` validates and reads `.DATNX` indices and members; `dm/gfx/tools/lzham.py` compiles a cached shared library on demand from the vendored Public Domain `lzhamdecomp` sources (`dm/third_party/lzham/` and `dm/gfx/tools/lzham_api.cpp`) so no external `pylzham` install is needed. `shader_split.py` batches `.DATNX` members across workers (`datnx_jobs`, `datnx_shaders`) and scans each decoded resource with `ttdat_programs(..., strict=False)` (requiring a valid Maxwell `EXIT` scheduling stream for headerless compute candidates while keeping strict validation for CC4 `.nnx_shaders` files). `dm/tools/tool_inputs.py` tracks the LZHAM C++ sources in `shader_split_files`. `dm/tools/tests/test_split_datnx.py` covers upstream LZHAM streams (empty, shader, multi-window), error cases, `.DATNX` layout validation, probe mode, and splitter integration. - **Found on:** [LEGO Harry Potter Collection](../../dm/games/010052A00B5D2000/README.md) (v1.0.2 / `v131072`, [issue #3382](https://github.com/seedds/nxnative/issues/3382)). The reporter's metadata inspection and local test extracted 7,294 shaders (1,469 unique from `harry1_dll`, 5,440 from `harry2_dll`, recovering all 213 captured missing gameplay keys with `shaders 7294: ok 7294`) and reached visible, playable opening gameplay in both Years 1–4 and Years 5–7 on an M3 Pro. The registered 1.0.1 build's shader split recovers the same shader counts with the self-contained reader. ### An OpenGL capture finds no shaders in a game that boots with NVN - **Symptom:** The packer selects OpenGL and stops at `captured only 0 run-time shaders`. A diagnostic boot initializes an NVN device and reports missing NVN shaders. - **Cause:** The executable links EGL and names `glShaderSource` alongside its NVN loader. The packer used the OpenGL names as renderer evidence without looking for the compiled NVN programs in the extracted RomFS. - **Fix:** When both loaders are present and there are no recognized OpenGL sources, GLSLC file headers in the RomFS or in ZIP members select the existing NVN shader build. The survey sees the outer archive headers, so the packer resolves this ambiguity after extraction. - **Found on:** [DOOM + DOOM II](../../dm/games/01008CB01E52E000/README.md) 1.0.6. The Mac boot uses NVN 55.15. The existing ZIP splitter reads 101 GLSLC outputs from `switch.kpf` and builds all 63 distinct shaders. ### The shader package and the shader map come from different splits - **Symptom:** `dmsh_build.py` stops with `[RED] <package> holds no record of shader <key>, which the shader map names: the package and the map come from different shader_split.py runs`, with `(its records carry no keys: it was split before they did)` for a package from before chain `3df44a5a4e0c`. Before that chain: wrong shaders wherever the game drew, such as a black screen with sound. - **Cause:** `dmsh_build.py` `rec_of` read a shader's record by its row's index in the map alone. With a package (`shader/pkg/*.bin`) from one split and a map from a later one that dropped or added a row, every later row of that package was translated from another shader's bytes. The NSP script's own split never mixes them: its reuse key covers `shader_split.py` and the profile's tables. A build whose split came from elsewhere could: NX2Apple's patches hand the split to another tool under the same key. - **Fix:** general, in the package format. `shader_split.py` writes each record's key (its 8 bytes) at record +0x08, in header bytes that were zero; `dmsh_build.py` `record_index` indexes a package by those keys and `rec_of` finds a row's record by its key, so a row's index no longer matters and a package that does not hold a row's shader stops the build before the first job. The control section is searched from +0x38, after the header. The map keeps its index column, so the profiles' tables did not change. A package from before the change carries no keys: the NSP script splits again by itself (its key covers `shader_split.py`), while a tool that hands `dmsh_build.py` an older package, such as `regress.py`'s use of a game's `<id>_build/shader/pkg`, needs that build run again first. `test_shader_package_keys` covers both sides. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) ([issue #1841](https://github.com/seedds/nxnative/issues/1841), diagnosed by its reporter). A build through NX2Apple 1.3.0 kept `ps_lib.bin` from an older split (4,711 records) beside a map from a split after 04df08d4 (4,707 rows), so the present pass's pixel shader `29e3c9dd92b8a571` was translated from a terrain shader's record and drew black. ### A provisional profile loses its tables to its own derived copy - **Symptom:** a shader stage stops with `FileNotFoundError: [Errno 2] No such file or directory: …/profile/<id>/bf_want.tsv` right after `the reader decoded additional compute kernels from this registered build`, and the profile folder is left with `game.tsv` alone: its shader tables, prewarm list and conflict rulings are gone. - **Cause:** the build took its own provisional profile for a registered one. `DM_GAMES_DIR` reached the build folder's `profile/` (the bring-up recipe the script prints sets it), so `game.py` `by_title` found the provisional profile there and `main` packed it as registered. Steps meant for a registered profile then ran on it: the split's compute-kernel check derived it (`derive_profile`) into the folder where derived and provisional profiles go, `<build folder>/profile/<id>`, which was the profile's own folder. `derive_profile` deletes that folder's files and then copies the profile's into it, so the copy read files the delete had removed. The heap check, which runs only for a provisional profile, was skipped as well. - **Fix:** general, in the profile lookup. `own_profile_folders` names every folder the script writes a game's provisional and derived profiles to (`<NSP folder>/<id>_build/profile`, `<work dir>/profile`, `--profile-out`), and `main` leaves them out of `by_title` and of `same_build`'s `by_build` (their `skip`). A provisional profile there is packed as provisional again, with its heap check, and a derived one is derived again from its registered profile. `derive_profile` stops with a `BuildError` rather than derive a profile onto its own folder. This also covers a multi-program game's provisional profiles that the first program's build put on `DM_GAMES_DIR` ([PR #2503](https://github.com/seedds/nxnative/pull/2503)). Tests: `test_the_builds_own_profile_is_not_taken_as_registered` (`test_nsp_work_dir.py`) and `test_a_profile_is_never_derived_onto_its_own_folder` (`test_nsp_incremental.py`). - **Found on:** [Chained Echoes](../../dm/games/0100C510166F0000/README.md) ([PR #2564](https://github.com/seedds/nxnative/pull/2564)), whose provisional profile had additional compute kernels to add. The tables came back from `shader/pkg.partial/tables`, and the prewarm list and the conflict rulings from their empty defaults. ### A reuse build spends a minute and a half on the c1 and uniform extent tables - **Symptom:** a build that restores every shader from the compile cache still spends about a minute and a half after the last shader, with the progress line at 99%, before `dmsh_build.py` prints `c1_full.tsv: …` and `cb_extent.tsv: …`: 95 s for Ocarina of Time's 42,848 shaders on an M3 Max. - **Cause:** `c1_guard.py` and `cb_extent.py` analysed every shader's MSL and reflection again after each full build (`dmsh_build.py` runs them, and `chain_tables` when a table names another library), though a shader restored from the cache has the same files, so the same answer. - **Fix:** with `DMSH_TABLE_MEMO` set to a folder, each tool keeps a line per shader there (`c1_guard.memo`, `cb_extent.memo`): the SHA-256 of the files it read, then its answer. The next run takes the answer of every shader whose files hash the same and analyses the rest. The NSP script sets it to its shader cache folder for the build and for `chain_tables`. The memo's first line is a fingerprint of `c1_guard.py`, `cb_extent.py`, `dmsh_abi.py` and the header it reads (`dm/gfx/nvn/dmsh_abi.h`: the binding kinds `cb_extent.py` filters on), so an edit to any of them starts it empty. It holds the last run's answers only (6.5 MB for Ocarina of Time). Without the variable nothing is hashed. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game) v131072 on an M3 Max: both tables in 95.1 s without the memo, 96.8 s with an empty one and 6.5 s from a full one, byte-identical after the header in all three runs. `dm/tools/tests/test_nsp_chain.py` (`TableTools`: the same tables from the memo, its answer used, changed bytes analysed again, another version's memo not taken). ### A cold build spends half a minute on the c1 and uniform extent tables - **Symptom:** after the last shader of a cold full build, `dmsh_build.py` keeps every core busy for about another half minute before it prints `c1_full.tsv: …` and `cb_extent.tsv: …`: Tears of the Kingdom's 28,669 shaders on an M5 Pro, 33 s of a 507 s build when the build runs them. The tools alone on a finished library: 27 s, and 14 s for Breath of the Wild. - **Cause:** `c1_guard.py` and `cb_extent.py` spent their time in patterns over each shader's whole MSL. The interval arithmetic was 1% of it. - `definitions_of` scanned every shader with a c1 read or a bounded uniform read for its temporaries: the declarations twice, the assignments once. It was 85% of `c1_guard.py` and 52% of `cb_extent.py`. Most indices are literals and ask for no definition: of 484 sampled shaders with a c1 read, 11 have a temporary in an index. - `ASSIGNMENT` starts with a lookbehind or an alternation, and `cb_extent.py` ran two patterns that start with `\b` for each binding of each shader (45% of its time). `re` tries such a pattern at every character ([Rewrites that try every character of a large source](shaders.md#rewrites-that-try-every-character-of-a-large-source)). - **Fix:** the same answers from less scanning, in the two tools. - `Definitions` makes `definitions_of` when `Interval` first looks a temporary up. - `definitions_of` counts the declarations in the scan that collects them. It finds the assignments with `ASSIGNED`, `ASSIGNMENT`'s first form with its literal first, when the text has no `++` and no `--`: the other two forms need one. A text with one takes `ASSIGNMENT` as before. - `cb_extent.py` `uses_of` counts a binding's uses and its declaration with `str.find` and the characters on both sides. - The memo's fingerprint covers both tools, so the first build after this fills the memo again. - **Measurement:** M5 Pro (18 cores), Python 3.13, the Mac library image, no memo, the two tools one after the other as the build runs them, best of three. | Both tools, wall (CPU) | Before | After | |---|---|---| | Tears of the Kingdom, 28,669 shaders | 26.7 s (458 s) | 5.0 s (79 s) | | Breath of the Wild, 19,592 | 14.3 s (241 s) | 3.0 s (45 s) | | Pokémon Scarlet, 30,142 | 24.2 s (417 s) | 4.8 s (76 s) | A whole cold Mac build of Tears of the Kingdom, one run each: 507.1 to 490.9 s. The two tools inside it: 33.3 s (543 s of CPU) to 10.5 s (109 s). The rest of the build, the same work in both, took 473.8 and 480.4 s. Both tables of the three games are the same line for line after the header, which holds the time of the run, and so are the two whole builds' tables. - **Open:** - Reading a vertex shader's body once was measured and not taken. Its MSL holds `main0`'s body in `main0`, `main0_z` and `main0_gs`, and the copies are 55% of a library's text. Dropping them halves the unchanged tools (26.7 to 13.3 s) and saves 1.4 s after this change (5.0 to 3.6 s), for a check of the three entry points' forms. - The memo ([A reuse build spends a minute and a half on the c1 and uniform extent tables](#a-reuse-build-spends-a-minute-and-a-half-on-the-c1-and-uniform-extent-tables)) no longer gains on these games: a run from a full memo is 4.9 s for Tears of the Kingdom, since every file is still read and hashed. Not measured on Ocarina of Time, which the memo was written for. - `ACCESS` also starts with `\b` and is most of what `c1_guard.py` still costs. - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#found-on-this-game), in a profile of its cold Mac build. - **Check:** `dm/gfx/tests/test_table_scans.py`: the assignment scan against the plain one, definitions made only for a temporary, `uses_of` against the two patterns. ### Every second build signs the whole Mac app again - **Symptom:** a build's last stage shows `Mac app · game files` without `(reused, signed)` and signs for three minutes, though the game files did not change and the build before it showed `game files (reused, signed)`; a build that changed nothing still shows `Mac app · pipeline archive` and signs for half a minute. Ocarina of Time (a 36 GB app) on an M3 Max: `Mac app` took 3:33 in the build after one where it took 1:11, and four packs that each changed one small file took 8 s, 220 s, 8 s and 220 s. - **Cause:** three things kept `pack_app.py` from finding a data bundle as its last pack left it. A bundle cloned from the app being replaced has the change time of its files moved by macOS a second to a minute after the pack (seen on macOS 27.2 on APFS, as Spotlight takes in the new app; not in a `.noindex` folder, and not for the files that are clones of the build folder's), so the record a pack wrote after reusing a bundle never matched at the next pack, and reuse alternated. It moves the change times of the build folder's large files as well (the 10.7 GB library image, 6 and 19 minutes after its build), which the packer keys those inputs by, so a build that changed nothing made the shader libraries' bundle again. The prewarm pipelines in `pso/mac` were taken away by each `pso_offline.py` run (as archives of an architecture not asked for) and linked again by the NSP script, and `pso_offline.py` wrote `prebuilt.tsv` and `archive.tsv` again with the same text: new times for files the packer keys by their times, so the pipeline archive bundle was made and signed by every build. And a pack that stopped (while it signed, the long step) had already deleted `<app>.key`, so the next pack signed every bundle though the app in place was unchanged. - **Fix:** `<app>.key` also records a SHA-256 for each file of the data bundles (`seals`): the digest its bundle's signature holds (`CodeResources`, `files2`), which codesign wrote from the bytes it read, and for the few small files the signature does not name (the bundle's `Info.plist`, the signature's own) their own. A file whose change time alone differs from the record is read and compared with it (`as_recorded`): the same bytes are reused (and the app's record is written again with the new times), other bytes or a file with no recorded digest make the bundle anew as before. The large inputs are taken the same way (`as_packed`, the record's `sources`: the app's copy's digest for the RomFS image and the archive's files, which are clones, and the library image's own, read while its bundle is filled). The NSP script leaves a prewarm file in `pso/mac` that is already this build's (the same link, or a copy of the same bytes), `pso_offline.py` leaves an asked architecture's prewarm files and a list whose text is unchanged, and a pack that fails sets its record aside as `<app>.key.replaced`, from which the next pack takes only the data bundles. The new data bundles are signed at once, each by its own codesign. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game) v131072 on an M3 Max: the four packs took 8 to 9 s each; the `Mac app` stage of a build that changed nothing went from 0:39 to 0:01, and of a build after a chain change from 3:33 (4:02 the same day) to 1:00, the shader libraries and the pipeline archive signed together in 34 s (70 s one after the other, 38 s at once, the same signatures); with the change times of the RomFS image, the library image and the archive moved, the app is `reused (inputs unchanged)` after 22 s of reading them, where all three bundles were made again before; the app verifies (`codesign --verify --strict`), and its files are those of the app built before, but for the chain label, the host and the prewarm pipelines. `dm/tools/tests/test_nsp_mac_app.py` (`PackReuse`: a moved change time with the packed bytes and with other bytes, a stopped pack; `Sign`; `App`: codesign's own record of a large file; `Script`: the prewarm files left in place), `dm/tools/tests/test_pso_offline.py`. ### A build that changes nothing takes a minute and three quarters - **Symptom:** a build whose every stage says `reused (inputs unchanged)` still takes 1:45 (Ocarina of Time on an M3 Max): 22 s between `unpack` and `rewrite`, 12 s in `Mac shaders · checking the inputs`, 26 s in `Pipeline archive`, 39 s in `Mac app`. - **Cause:** each of them read the game or its libraries again to find them unchanged. `profile_guess.py build_sources` reads the head of every file of the RomFS, several times over, to say how the shaders are got (19 s for 186,583 files). The shader step's reuse path prunes the compile cache, and `prune_shaders` read every per-shader entry's size along with its name, which walks the blob table of an 11.5 GB file (13 s) though nothing was to go. `pso_offline.py` read every reflection and hashed every library its bases name (33,365 bases) before its key could say the archive was reused. The app was packed again for the reasons of [Every second build signs the whole Mac app again](#every-second-build-signs-the-whole-mac-app-again). - **Fix:** the NSP script keeps `build_sources`' answer beside the image (`RomFS.img.sources`) while the image's size and time, the code modules, the module list and the readers are the same, as `check_formats` keeps its own. `prune_shaders` reads names and times from the entry table and sizes only for what it removes. `pso_offline.py` keeps a key of what a run reads by name and time (`run.key` in its work folder: the library image's place, inode, size, modification and change times, the lists, the compiler, the options and the tools' code) with the state of its outputs, and a run with the same key and outputs returns before it reads a library; a library in a folder, or any difference, goes through `archive_key` as before. The inode and change time also catch [changed shader bytes whose modification time was preserved](#a-changed-shader-library-reuses-an-old-pipeline-archive). - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game) v131072 on an M3 Max: 1:45 to 0:10, three builds in a row, the app `reused (inputs unchanged)`; the first build with the new tools took 1:10. ### After a chain change the steps behind the last shader take three minutes - **Symptom:** a build after a chain change that left the MSL as it was (`Metal cache: mac 55482 reused, 0 compiled`) spends about a minute in `writing the library image` and a minute and a half in the c1 and uniform extent tables, and its app step half a minute in `shader libraries` (Ocarina of Time, 42,848 shaders: 0:56, 1:26 and 0:25 on an M3 Max). - **Cause:** the tables' memo ([A reuse build spends a minute and a half on the c1 and uniform extent tables](#a-reuse-build-spends-a-minute-and-a-half-on-the-c1-and-uniform-extent-tables)) is keyed by each shader's files, and a reflection names its chain version, which neither tool reads: after a chain change every key missed. `dmsh_build.py` writes the image from its 300,000 staged outputs, read out of the compile cache one after the other on one SQLite connection, which gives a library's chain of pages at about 190 MB/s; the app's copy of the library (`shader_lib.subset`) read its 130,000 files one by one too. - **Fix:** the memo's key takes a reflection without its chain version (`memo_reflection`). `shader_lib.write` calls the sources it is given as functions on eight threads, a few entries ahead of the writer, which takes them in order, and `shader_cache.Store.get` reads on a read-only connection of the calling thread's own when that thread is not the one that opened the store and is not inside a batch (it takes the store's lock to ask, so a batch under way in another thread is over first, as before); `subset` reads its files the same way, and `pso_offline.py` hashes the libraries on eight threads. The connections have a [reader-lifetime guard during recovery and close](#cache-recovery-races-a-parallel-shader-reader). - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game) v131072 on an M3 Max: both tables in 106 s with an empty memo, 6.6 s from a full one and 13 to 19 s in the builds after a chain change (86 to 104 s before), their rows the same; the image in 40 to 49 s (56 to 70 s before; 7.4 GB from the cache in 22.3 s against 48.8 s alone), the app's copy in 15 s against 23 s, the same bytes each time; every file of the library is the one the unchanged tools built, but for the chain label. `dm/tools/tests/test_nsp_chain.py` (`test_memo_holds_across_a_chain_change`), `dm/tools/tests/test_shader_lib.py` (`Write`), `dm/tools/tests/test_shader_cache.py`. ### Cache recovery races a parallel shader reader - **Symptom:** a shader build stops with an uncaught `KeyError` in `Store._reader` while the damaged compile cache is being recreated. - **Cause:** the parallel reader checked and returned its registry entry outside the store lock, so recovery could clear that entry before the lookup. Connection creation also ran outside the lock, allowing a reader of the old file to be registered after recovery replaced it, and recovery could close a connection during an active `fetchall`. - **Fix:** `shader_cache.Store._reader` creates, registers and reserves a connection under the store lock, then keeps its own query lock until `fetchall` finishes. Recovery and close retire readers under the same registry lock and wait for active queries before closing their connections. A failed query releases its reservation before returning to the primary connection, preserving the lock order; independent readers still execute in parallel. - **Found on:** no game; reproduced with synthetic caches during the review of PR #2820. `test_shader_cache.Entries` pauses opening, fetching and a failed query during recovery, checks the recreated cache remains readable, and requires two independent queries to enter SQLite together. ### A changed shader library reuses an old pipeline archive - **Symptom:** replacing a shader-library image with different bytes of the same size while preserving its modification time leaves the old pipeline archive reused without reading the changed libraries. - **Cause:** `pso_offline.run_key` recorded only the image's path, size and modification time. That identity could remain unchanged after a timestamp-preserving write or replacement, bypassing the content-based `archive_key`. - **Fix:** the fast key also records the inode and change time, as the image reader does (`romfs._resolve`), and its format is version 2. A changed identity goes through `archive_key`, which hashes the libraries' bytes; an unchanged image still takes the fast path. - **Found on:** no game; reproduced with synthetic libraries during the review of PR #2820. `test_pso_offline.Build.test_a_changed_image_with_preserved_size_and_mtime_is_read_again` changes used metallib bytes inside a valid image, restores its modification time, and checks that the compiler is called again before subsequent unchanged runs are reused. ### A missing shader's key was lost after two more starts - **Symptom:** a `--seen-shaders` build does not add a shader the game reported missing (`[RED] shader <key> (<stage>) failed to load`, or `failed to load shader <key>_b`) in a session before the last two starts of the app: the area still draws without it after the rebuild. - **Cause:** the only record of the key was the log. `dm/mac/launcher.c` renames `<title ID>.log` to `.prev.log` at every start, also one that only opens the settings window and quits, and `seen_logs` reads those two files, so the third start from the session onward dropped its keys. The `--platform mac` run command's `tee` starts `run/host.log` again on each run, which keeps one session. - **Fix:** general, for every NVN game on the Mac. The host writes the key when it misses the shader: `shader_missing_note` (`nvn_mtl.m`), at the two red lines, appends it to the file `DM_NVN_MISSING_KEYS` names. The launcher sets that to `shader_missing.txt` beside the save; the partial run command to `run/shader_missing.txt`, after its pipeline prebuild, whose loads are not what the game asked for. `seen_lists` / `seen_keys` read both files and never write them. A launch does no work: no log is searched. Each key is written once across runs, so the file stops at 17 bytes per distinct key the game ever missed (2.2 MB for the 131,426 keys of the largest map listed in [Building selected Mac shaders](../development.md#building-selected-mac-shaders)). A key that later loads stays in the file and is only built again, as `partial-keys.txt` already does; a key of another game version is dropped by the shader map filter and stays for that version's build folder; a chain change keeps them, as a key names the guest shader. A line a stopped host left half written is not read as a key, and the next key starts on a new line. Only `<key>` and `<key>_b`: the geometry routes' libraries (`_bg<n>`, `_bgv`, `_bl<n>`) and `rt_library_b` are not keys of the map. - **Check:** `dm/gfx/tests/t_missing_keys.m` (the real `shader_load` and `prog_get` on an empty library: both red lines, once per key across runs and four threads, the routes, a half line, unset); `dm/tools/tests/test_nsp_mac_app.py` `test_missing_shader_outlives_the_logs` (the packed launcher over three starts, with a stand-in host), `test_keys_from_the_hosts_lists`, `test_prebuild_keeps_no_missing_keys`. - **Found on:** reported in [GitHub issue #1519](https://github.com/seedds/nxnative/issues/1519), from two `--seen-shaders` sessions that asked for 2,614 keys their partial library lacked. Shown with the packed launcher, the host's loader and synthetic tests; not run on a game. ### The free-space check stops a build on a Mac that has the space - **Symptom:** the NSP script stops with `[RED] less than N GB free on the volume of <build folder>` before extraction (or `less than 5 GB free` before the IPA), while Finder and the Storage settings show far more available. The Mac app step can stop with `the app needs … GB on the volume of …`, and `pso_offline.py` with `GB free on the volume of …, metal-tt needs about …` or `GB free before merging`. - **Cause:** every check read `shutil.disk_usage` (`statvfs`), which counts only unallocated blocks. On APFS, space held by purgeable data (local Time Machine snapshots, caches the system deletes on demand) is not in it, though macOS frees that space while a write needs it. - **Fix:** `dm/tools/vol_space.py` `free_bytes` returns macOS's `kCFURLVolumeAvailableCapacityForImportantUsageKey` for the path's volume (the capacity for writes a user asked for, queried through CoreFoundation), never less than `statvfs`'s figure, and `statvfs` alone where macOS gives none. It asks the nearest existing folder of a path not made yet. The NSP script's `free_gb`, `pack_app.py`'s copy check and `pso_offline.py`'s checks before `metal-tt` and before the merge use it. Two reads keep `statvfs`: `tree_tar.pack_quiet`, housekeeping nobody asked for, which should make macOS purge nothing, and `pso_offline.py`'s diagnosis of a failed `metal-tt`, which reports what was really left. Tests: `dm/tools/tests/test_vol_space.py`. - **Found on:** a user's APFS volume with a local Time Machine snapshot holding over 50 GB of deleted files ([PR #2257](https://github.com/seedds/nxnative/pull/2257)): `statvfs` showed 18.84 GiB free and the capacity for important usage 68.02 GiB. With the capacity, an [Ocarina of Time](../../dm/games/0400486024DEC000/README.md) v131072 `--platform mac-app` build wrote 57 GB of work and a 35.2 GB app there, with 24 GiB still unallocated at the end. Applies to every game built on a Mac. ### The shader split takes a minute on a RomFS of 300,000 files - **Symptom:** the NSP script's `shader split` step takes 60 to 77 s for Tears of the Kingdom on an M5 Pro. `shader_split.py` prints nothing for its first 26 s, then its `progress: n/304243` count slows after the first half. - **Cause:** only 1,683 of the 304,243 files hold a shader container, and parsing and de-duplicating shaders took under 1% of worker time. The CRA, zip, PDAT and RPF6 finders made 1.2 million opens in the parent process (22.9 of the 26.4 s before the scan). `unzs` also started `zstd` for each of 32,176 files without a dictionary, 39% of worker time. Image opens themselves added contention ([Processes that scan one RomFS image in parallel wait on its opens](#processes-that-scan-one-romfs-image-in-parallel-wait-on-its-opens)). - **Fix:** the pool reads the first eight bytes of each file in batches. The CRA, zip, PDAT and RPF6 finders validate the candidates selected by their first four bytes. The EA finder uses the same read and matches its four- and eight-byte signatures. `unzs` decodes all zstd frames in process, using the existing dictionary lookup when a dictionary is named. The separate Next Level Games decoder still uses the command. - **Measurement:** the [original PR](https://github.com/seedds/nxnative/pull/3002) measured a cold split on an 18-core M5 Pro, Python 3.13, with `J=18`. Tears of the Kingdom 1.4.3 went from 60.0 s (528 s CPU) to 17.5 s (215 s CPU) with both optimizations. Its split inside a cold pack went from 70.6 to 21.9 s. Breath of the Wild went from 70.1 to 67.1 s and Pokémon Scarlet stayed at 10.4 s. The package files and all four tables were byte-identical in all three comparisons on the PR base. - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#found-on-this-game), while profiling the shader split. - **Check:** `test_split_magics.py` splits an image with a renamed zip, an eight-byte EA signature and concatenated zstd frames with an empty `PATH`. `test_easf.py` covers EA's version keys and DLC routing. ### The shader split takes over a minute on a RomFS of Yaz0 files - **Symptom:** the NSP script's `shader split` step takes 76 to 79 s for Breath of the Wild on an M5 Pro, every core busy (about 980 s of CPU). - **Cause:** 31,304 of the RomFS's 41,062 files are Yaz0 (8.0 GB stored, 15.7 GB decoded), and `yaz0()` decoded them one item at a time in Python, about 34 MB/s a core: 911 of the workers' 1,051 CPU seconds. Four in five items are literals, so the time went to interpreter steps, not to copies. - **Fix:** where a C compiler is available (Xcode's `clang` on a Mac, `cc` on Linux) and `DM_YAZ0_NATIVE` is not `0`, `yaz0()` hands valid-sized streams to `dm/gfx/tools/yaz0.c` through ctypes: `dm/tools/native_c.py` builds it once into `$TMPDIR/dm-native-<uid>/` (warmed once in `shader_split.main()` before spawning the worker pool so a cold cache never runs `J` parallel builds or repeats failure warnings, and never writing into the repository or the home folder). The C decoder runs only when the header's size is at most 91 bytes per stream byte (the most a 3-byte back-reference copies), checks every read against the stream and every write against that size, and returns a code on any failure; the Python decoder then runs on the stream to emit the same `[RED]` message. Wherever the library is disabled (`DM_YAZ0_NATIVE=0`, including `fuzz_shader_split.py`) or does not build or load, the Python decoder runs instead: once 0x1000 bytes are out, whole groups go in batches, as many as can neither read past the stream nor pass the size in its header, with 256-entry lookup tables for literal runs and back-reference lengths/distances, while the start, end and damaged streams stay item by item. `dm/tools/tool_inputs.py` tracks `yaz0.c` alongside `shader_split.py`'s other native inputs. - **Measurement:** the [original PR](https://github.com/seedds/nxnative/pull/3295) measured against `002724b8` on an 18-core M5 Pro, Python 3.13, `J=18`, three cold scratch splits each: 75.7 to 78.8 s (961 to 987 s CPU) became 12.2 to 13.9 s (126 to 132 s CPU) with the C decoder (the first run building the library), and 41.2 to 44.0 s (521 to 527 s CPU) with the Python decoder alone. On one core, 330 of the game's Yaz0 files (304 MB decoded) went from 34.5 to 1,115 MB/s (71.4 MB/s in Python). The package and all six tables were byte-identical in every run. - **Found on:** [Breath of the Wild](../../dm/games/01007EF00011E000/README.md#found-on-this-game), while profiling the shader split. - **Check:** `test_split_yaz0.py` keeps the old decoder as the reference and compares it on 7,257 generated streams (random, every length at short distances, sizes ending inside a group or a copy, every truncation, back-references before the start) with the C decoder alone (nothing written past the size), with `yaz0()` as bytes, bytearray and memoryview, and with the Python decoder alone, plus `DM_YAZ0_NATIVE=0`, `_pool_init`, `tool_inputs.shader_split_files` and Python-only fuzzing checks. `test_native_c.py` covers compilation, caching, build failures, unsafe temp folders, other platforms and Macs without Xcode. `dm/gfx/tests/t_yaz0.c` tests `yaz0.c` with exact-size heap buffers under ASan and UBSan (`make -C dm/gfx/tests yaz0-asan`) and brings `yaz0.c` into `lint_c.py`. ## Diagnostic reports ### A large log can retain key material after redaction - **Symptom:** `scripts/bug_report.py` can include key material from a log larger than 4 MB in the report zip, despite removing the same key line from a smaller log. - **Cause:** `read_text` kept fixed byte windows before `redact` matched key lines. The first window could end partway through a value, below the matcher’s 32-hex-digit threshold; the last could start after the key name. Neither fragment was recognized as a key line. Whitespace before a detached value can also keep it inside the bundle’s final byte cap. - **Fix:** keep only complete lines at the two read boundaries before redaction, using the byte before the tail to distinguish a complete first line from a fragment. The omitted-byte count includes the discarded fragments; reading stays bounded. Files within the limit and a complete final line without a newline are unchanged. - **Found on:** synthetic logs in `dm/tools/tests/test_bug_report.py`, including a key value surviving in the final zip on the old code. No game files or real keys are needed; this is a diagnostic collector finding, not a game-runtime failure. ### A bug report for an NSP folder left out the Mac app packed there - **Symptom:** `scripts/bug_report.py <NSP folder>` (or its `<title ID>_build`, or `<title ID>`) writes `unknown (not recorded by the build)` (or `target`) under both "nxnative commit" and "Shader chain version" in `report.md`, although the run log records `[dm] build: commit …, shader chain …` or the Mac app the NSP script packed into that folder records both (`DMCommit`, `DMChain`); given the `.app` itself, the script names them, while data-bundle Mac apps also omitted `Contents/Resources/msl/b-<chain>.img` from the shader folder list. - **Cause:** `collect` read `DMCommit`/`DMChain` only from an explicit `.app` target's `Info.plist`: it neither parsed the host's startup `build:` line from the collected run log (`dm/host/main.c`) nor checked the `<game name>.app` that `build_ipa_from_nsp.py --platform mac-app` writes directly into the NSP folder. Separately, `shader_dirs` skipped every symlink, which excluded data-bundle Mac apps' `Contents/Resources/msl` link into `Contents/PlugIns/ShaderLibraries.bundle`. - **Fix:** for non-`.app` targets, `collect` first reads `[dm] build: commit …, shader chain …` from the collected run log (`--ios-log` when given, never mixing Mac logs or a sibling Mac app into an iPhone report; otherwise the Mac app log, falling back to `.prev.log` only when `.log` is absent). When no run log has a `build:` line for an NSP folder (and `--ios-log` is not given), `resolve` lists the apps directly in the NSP folder whose `DMTitleID` matches the build's title ID, and with exactly one, `collect` takes its `DMCommit` and `DMChain` (or its sole `b-<chain>` library, stripping `.img`), names the app beside each value, lists its library before the build's shader folders, and keeps the build's logs. With none or several, both stay unknown and the report's file list says why: a folder never guesses which app ran. Only the stamps are taken: the name, version, settings and `env.txt` of a sibling app stay out, and "How it was built and run" is left to fill in. `shader_dirs` follows a `Contents/Resources/msl` symlink only when it resolves inside the `.app` bundle. - **Found on:** the NSP folder of [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md): commit and chain unknown before; after, `786715256f37` and `ded41f8d62ed` from its app, the values the same script reports for the app, with the same 18 files in the zip. `dm/tools/tests/test_bug_report.py` covers one app, two apps, an app of another title, runtime Mac and iPhone startup logs, and data-bundle `msl` symlinks. ## IPA archives ### Code variants in iOS builds - **Symptom:** a fixed-rate game patch can run at the wrong speed if it starts with the stock RomFS files or a different present rate. - **Cause:** iOS embeds rewritten executable pages in the app. The timing data and frame pacing must agree with those pages even when the base RomFS is supplied separately. - **Fix:** pass the variant's own `patched/` as `PATCHED` and its directory as `DM_IOS_VARIANT`. The iOS packer carries `env.txt` and `romfs/` in `dm/variant/`. Startup applies those environment values before diagnostics and launcher choices, and places the bundled overlay first in `DM_ROMFS_OVERLAY`. A variant missing its settings or overlay stops at startup. Both bundled and separate base RomFS use the same overlay. - **Found on:** [Animal Crossing: New Horizons](../../dm/games/01006F8002326000/README.md#ios). ### iOS embedding rejects an alias cut in the fixups table - **Symptom:** the IPA's `gen_embed` step stops with `ValueError: dictionary update sequence element ... has length 4; 2 is required`. - **Cause:** the embed generator split every rewrite record into separate words and expected exactly a key and a value. `ALIAS_CUT` carries an offset, original bytes and replacement bytes after its key. - **Fix:** `gen_embed.py` splits each header record at its first whitespace and parses the scalar layout fields it uses. The native loader still gets the full fixups table, including every alias cut. - **Check:** the iOS compile and link fixture (`dm/ios/tools/build_smoke.py`) includes an `ALIAS_CUT` row alongside the layout fields. - **Found on:** [Trails in the Sky 1st Chapter](../../dm/games/01002C9022770000/README.md#found-on-this-game), update 1.0.6. ### AltServer cannot install a file of 2 GiB or more - **Symptom:** AltServer stops installing an IPA with "The file “b-<chain>.img” couldn’t be saved in the folder “msl”", although the RomFS stays out of it (`--romfs separate`). Other install tools install the same IPA. - **Cause:** in AltServer, not here. Its `writeFile` (`AltServer/Devices/ALTDeviceManager.mm`) reads a file whole and hands it to one `afc_file_write`, which libimobiledevice sends with one `send()` and returns its result as an `int`, so a file of 2^31 bytes or more fails, and AltServer reports the short write as a file it could not save. A shader library is one file, `msl/b-<chain>.img` ([Shader libraries take a file per shader variant](#shader-libraries-take-a-file-per-shader-variant)); a bundled RomFS image or a DLC image that large fails the same way. - **Fix:** a workaround, as the limit is the install tool's, and opt-in: `SHADER_FILES = True` or `--shader-files` in the NSP script (`DM_SHADER_FILES=1` for `build_ipa.sh`, `pack_ipa.py --shader-files`) packs the shader library as its separate files, `msl/b-<chain>/`, whatever its size. What the app carries of the image (after the build's exclusions) is written into a folder beside the IPA for the length of the pack, and the host reads a library folder before an image (`nvn_mtl.m`, `msl_data`). The game files still need `--romfs separate` when their image is that large. It is off by default: other install tools take large files, and one file installs faster than tens of thousands. The folder is written and deflated again at every pack, as its files are new each time. - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#found-on-this-game) 1.4.3, whose library is 2.10 GiB ([issue #1688](https://github.com/seedds/nxnative/issues/1688), [PR #1697](https://github.com/seedds/nxnative/pull/1697)). The cause is read from AltServer's and libimobiledevice's source; an install through AltServer with `--shader-files` has not been run. ### A streamed file changes size and the IPA fails its CRC check - **Symptom:** packing succeeds, but `unzip -t` or Python's `ZipFile.testzip()` reports a bad CRC for a large deflated file. - **Cause:** `pack_ipa.py` wrote the uncompressed size collected before reading. Its streaming check compared the output size only for stored files, so a compressible file that grew or shrank still published an archive with the old size. - **Fix:** count uncompressed bytes as they are read and compare them with the listed size before completing either streamed method. A mismatch stops the pack and removes the partial archive, preserving the previous IPA and its reuse index. Regression tests cover growth and shrinkage with both deflate and store. - **Found on:** synthetic IPA inputs while reviewing [PR #279](https://github.com/seedds/nxnative/pull/279); no game files required. ### An empty icon file gives the app a blank icon and the log names it as the icon - **Symptom:** the build logs `app icon: <file>` and succeeds, but the app's home-screen icon is blank. - **Cause:** `build_ipa.sh` scales the icon (`DM_ICON`, `--icon` / `--fallback-icon` in the NSP script, or the extracted `icon.jpg`) to the asset catalog's `icon.png` with `sips`. `sips` skips an empty file with `Warning: … not a valid file - skipping`, exits 0 and writes nothing, so the catalog named a PNG that does not exist and `DM_APPICON` was set. `actool` then compiles that catalog with exit 0 and no message, and its partial Info.plist has no icon keys. A text file named `.jpg` or `.png` and an unreadable file already stopped the build (`sips` exits 13), naming the file. - **Fix:** `build_ipa.sh` also checks that the PNG was written and is not empty, and in every case stops with `the icon <file> is not an image sips can read (empty, unreadable or not an image): give a JPEG or PNG`. `dm/ios/tests/test_app_icon.py` runs the icon step alone: an image becomes a 1024x1024 icon, no file leaves the icon blank, an empty file or a text file named `.jpg` / `.png` stops naming the file. - **Found on:** reading the icon step; reproduced with a zero-byte `DM_ICON` (and `actool` run on the resulting catalog), no game files required. Applies to every game's iPhone build. ## RomFS images ### RomFS image paths and shader groups fail on Windows - **Symptom:** a Windows build cannot read a resource inside `RomFS.img`, or its shader sources have backslash-separated labels that do not match the profile's slash-separated groups. - **Cause:** the image reader splits host paths only on `/`, assumes `os.pread` exists, and opens descriptors without `os.O_BINARY`; Windows uses `\` and does not provide `os.pread`, and text-mode descriptors can alter binary bytes. Reusing a shared backing descriptor via `os.dup` would also share the OS file cursor across concurrent readers under a seek/read fallback. Shader source labels inherited the host's separator. - **Fix:** normalize host paths when finding the image while preserving native separators for host lookups, open image descriptors with `os.O_BINARY` when present, bypass shared backing descriptors when `os.pread` is absent so each reader keeps an independent cursor, and route both `read()` and `readinto()` through a single offset-read helper that falls back to `lseek` + `read`. Normalize `shader_split.py` source labels (base, updates, DLC, and sibling UE3 shader caches) to `/`. Synthetic tests cover binary bytes, no-`pread` cursor independence across both read APIs, Windows path resolution, and portable labels (`dm/tools/tests/test_romfs_read.py`). - **Found on:** a Windows-built [Rhythm Heaven Groove](../../dm/games/0100D9F01D474000/README.md) 1.0.0 IPA ([PR #591](https://github.com/seedds/nxnative/pull/591)), reported to run on an iPhone with separate Windows front-end fixes; the reworked integration was verified with simulated no-`pread` and Windows-separator tests on macOS (no Windows host was available locally). ### RomFS folder transfers fail or leave stale game files - **Symptom:** `devicectl` copying a large RomFS folder fails with POSIX error 24 (`EMFILE`) or spends most of its time on small files; deleting an old folder during iOS startup hits the launch watchdog. A push after changing extracted files can also keep sending old assets if an image is reused solely because it exists. - **Cause:** a folder transfer performs hundreds of thousands of file operations. The image cache must track its source tree, and magic plus total length cannot establish that an image's index is valid. Accepting that weak check before deleting the working folder loses the fallback when mounting later rejects the index. - **Fix:** `dm/tools/romfs_image.py` packs one `DMROMFS1` file: a 32-byte header, file bytes, then the index and name pool. Each directory has a sorted, contiguous run of child entries; the host binary-searches each path component and reads file ranges with `pread` through one descriptor per mount. Overlay folders keep precedence and directory listings merge both sources. The shared `dm/host/romfs_image.h` loader checks the full index before either mounting or iOS folder cleanup: length, entry and name bounds, file ranges, a rooted breadth-first directory tree, and sorted, unique child names. It supports an empty root too. Invalid images fall back to the folders on iOS; an explicit invalid `DM_ROMFS` image is refused with a `[RED]` line. The index check detects interrupted sequential transfers and structural damage, not same-length corruption inside file contents. The packer publishes by rename only after the source stays stable. Its reuse stamp tracks source names and file metadata including ctime, the packer and image identity; the push helper always checks it, and `--repack` forces a rebuild. Usage: [Quick reinstalls](../development.md#quick-reinstalls). - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#files-and-shaders), whose 304,000-file transfer and startup deletion failures are reported in [PR #369](https://github.com/seedds/nxnative/pull/369). [ANIMAL WELL](../../dm/games/010020D01AD24000/README.md#files) provides the empty-image boot case. Synthetic packer/host tests cover actual file reads, case aliases, overlay merging, corrupt indexes and changed sources; the macOS Foundation test executes iOS's locator to check that rejected images preserve its folder. ### `devicectl` copies a large RomFS image through the Mac's memory - **Symptom:** `scripts/push_romfs.sh` stops after a few seconds to two minutes with `The connection was interrupted` (`com.apple.dt.CoreDeviceError error 3`, `com.apple.Mercury.error error 1000`) and leaves a 0 KB `Documents/romfs.img`; retries fail the same way. Meanwhile macOS says the system has run out of application memory although little RAM is in use: `sysctl vm.swapusage` shows the swap nearly full, and `top -o mem` shows `CoreDeviceService` holding tens of GB, nearly all of it compressed. Neither the device's lock state nor its free space is the cause. - **Cause:** `xcrun devicectl device copy to` has the Mac's `CoreDeviceService` read the whole source file into its own memory. A 26 GB image grew the service to 25–27 GB within about 30 s; on a 16 GB Mac whose nearly full internal disk could not grow the swap past 27.6 GB, the system killed the service (it started again the second the copy failed, with no crash report), and `devicectl` lost its connection. The memory stays held while the service lives: killing it (launchd starts it again on demand) let the swap fall from 27 to 4 GB. App installs (`devicectl device install app`) take another path and stream: an app holding one 8 GB shader image installed with no such growth. - **Fix:** `push_romfs.sh` sends the image over AFC (house_arrest, the channel of Finder's file sharing; the app sets `UIFileSharingEnabled`) with libimobiledevice's `afcclient --container <bundle ID>`, to `Documents/romfs.img.part`, which `main.m` never takes, and renames it to `romfs.img` once the device holds all of it. `afcclient` exits 0 even when a command fails, so the script compares the size on the device (`afcclient info`) with the image's: a cut-off copy stops it with a `[RED]` line and leaves the old `romfs.img` as it was. Before copying, the script checks that `afcclient` opens the app's `Documents`: it finds a device only by its UDID over USB, where `devicectl` also takes its own identifier, the device's name and Wi-Fi, so a wrong ID or a Wi-Fi-only device gets a `[RED]` line saying so. `afcclient` stayed at 12 MB while sending, about 33 MB/s to an M1 iPad over USB-C. Without `afcclient` (`brew install libimobiledevice`) the script copies through `devicectl` only an image smaller than half the Mac's memory, and says how to install it; `ROMFS_PUSH_VIA=afc` / `devicectl` chooses either. `dm/tools/tests/test_romfs_image.py` (`AfcTransfers`) runs the script against a fake `afcclient`. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) (a 26.2 GB image, an iPad Pro 11-inch 3rd generation, a 16 GB M4 MacBook Air, macOS 27.2, CoreDevice 651.32; 2026-11-08): six `devicectl` pushes failed. Every game whose image is larger than the Mac's free memory and swap is affected. ### `devicectl`'s `--remove-existing-content` empties the app's whole container - **Symptom:** after `scripts/push_romfs.sh <device> <bundle ID> <resources.env>` the game files are gone from the device, and so are the saves: `Documents` is empty, and `Documents`, `Library`, `SystemData` and `tmp` all carry the time of the push. The script stopped with `ERROR: Failed to retrieve the file node for Documents/aoc (com.apple.dt.CoreDeviceError error 7000)` after the image had been copied. - **Cause:** the script replaced the DLC folder with `xcrun devicectl device copy to … --destination Documents/aoc --remove-existing-content true`, from an empty folder when the build has no DLC. On CoreDevice 651.32 (macOS 27.2, an iPad on iPadOS 27.0.1) that empties the app's whole data container, whether `Documents/aoc` exists or not, and then fails with the error above: a test file in `Documents` and a folder in `Library` were gone afterwards, and every folder of the container had been made again. Every push from a `resources.env` ran it, for every game. - **Fix:** the script replaces `Documents/aoc` over AFC only (`afcclient … rm -rf /Documents/aoc`, `mkdir`, then a `put -r -f` of each DLC item, each checked with `afcclient info`, as `afcclient` exits 0 when a command fails) and never passes `--remove-existing-content`. Without `afcclient` it leaves `Documents/aoc` as it is when the build has no DLC, and stops with a `[RED]` line, after the image, when it has some. `dm/tools/tests/test_romfs_image.py` (`DlcTransfers`) checks that a save and the app's preferences survive both a DLC set and an empty one, and that `devicectl` is never given the flag. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) (2026-11-08): the first complete AFC copy of its 26.2 GB image was deleted by the DLC step that followed it; reproduced twice with test files (with `Documents/aoc` missing and present). The app held no save yet. ### A reboot packs a RomFS image again - **Symptom:** the first build after restarting the Mac spends minutes in `unpack` (`[1/5] unpack v131072: 5%, 1.2/~24.4 GB`) although the game, the packer and the image are as they were: 8 minutes for a 24.4 GB image from a NUP on a network share. - **Cause:** the stamp beside an image (`RomFS.img.inputs.json`) held `st_dev` in the image's identity, and macOS numbers a volume when it mounts it. Across one reboot the Data volume went from 16777234 to 16777232 while inode, size and both times stayed, so `reusable()` refused every game's image at once. - **Fix:** `file_identity` leaves `st_dev` out, as the IPA and app packers' stamps already did. Inode, size, modification and change times still catch an image replaced or written over. An old stamp still misses the fast check, so the [NUP packer verifies the existing image](#an-old-nup-cache-stamp-makes-the-build-unpack-again) before repacking. - **Found on:** Ocarina of Time (Switch 2, `0400486024DEC000`, packed from a NUP; PR #1299); the stamps of Star Fox and Mario Kart World show the same two numbers. `dm/tools/tests/test_romfs_image.py` remounts an image under another device number. ### An old NUP cache stamp makes the build unpack again - **Symptom:** the next build spends minutes unpacking a NUP after a packer update even though its complete `RomFS.img` is still present. - **Cause:** the stamp's digest holds the packers' source (`romfs_image.py` and `pack_nup.py`), and its identity has the fields `file_identity` gives; a change to either misses the fast check for every image, though neither says the image's bytes changed. - **Fix:** on a stamp miss, `pack_nup.verified` compares the existing image with what the packer would write now: its size, its header and index as `romfs_image.layout` makes them (the bytes `write` writes, so a change of format still packs again), and each file's bytes against the SHA-256 in the NUP's table of contents. Only the image is read, not the NUP's file data. If the image is the same before and after the check, its stamp is renewed and later builds take the fast check; otherwise it is packed again. The build's unpack line ends in `reused (image checked)`. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md) v131072 (PR #1630): the 26.25 GB image took 21.6 s to check on an Apple M1 and 0.1 s to reuse on the next build, against minutes to unpack. `dm/tools/tests/test_nsp_nup.py` (`ImageReuse`) covers an old stamp, a damaged file, a wrong index, a cut-off image, an image changed during the check and an older layout. ### A commit switched and back, or another worktree, rebuilds every shader - **Symptom:** a build after `git checkout` to another commit and back, or from another worktree of the same repository, with the translator's bytes as they were, translates every shader again: `building the whole shader map, 42,848 shaders` and 46 minutes for Ocarina of Time's Mac shaders, all from the compile cache, where `reused (inputs unchanged)` was expected. - **Cause:** the shader step's reuse key (`build_shaders`) took the translator by where it was and when it was written: its folder `dm/gfx/tools/dmsh_xlate_bin` as path, size and modification time (`('stat', ...)` in `fingerprint`), from when the translator was a folder of .NET binaries, and its path (`str(xlate)`). Git writes a file again whenever a checkout moves between commits where it differs, and the translator differs between most chain versions, so going and coming back gave the same bytes a new time; another worktree has another path. Either missed the key, and the step removes its key and builds again. - **Fix:** `scripts/build_ipa_from_nsp.py`: the key takes the translator by its bytes alone (`translator_key`: `('files', [xlate])`), as it takes the chain's other tools. It is one native executable that links only system libraries, 7.9 MB: 3 to 5 ms to hash. The other `('stat', ...)` inputs are extracted or provisional game files, too large to read for a key, and stay as they are. The key's form changed, so each game's first shader step after the fix translates again once. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game), its Mac app build after the checkout went to a newer `main` and back while the build ran ([PR #2496](https://github.com/seedds/nxnative/pull/2496)). `dm/tools/tests/test_nsp_chain.py` (`TranslatorKey`) takes `build_shaders`' key with the translator rewritten with the same bytes and a new time, at another checkout's path (key kept) and with other bytes (key changed). ### A stale `DM_ROMFS` path crashes the game soon after `nnMain` - **Symptom:** a direct `dmhost` run logs `fs mount rom: → <path> (read-only)` for a path that does not exist, then crashes in the game's code a fraction of a second after `nnMain` (Echoes of Wisdom: `CRASH sig=11 addr=0x88` 0.3 s in). The host now stops at the mount instead with `FATAL the game files <path> (rom:) are missing: neither a folder nor a RomFS image`. - **Cause:** an old run command still named the extraction's `RomFS` folder after a rebuild replaced it with `RomFS.img` ([RomFS folder transfers](#romfs-folder-transfers-fail-or-leave-stale-game-files)). The read-only mount accepted any path, so every read failed and the game used the missing data. The iOS app and the Mac app launcher check their game files before they start the host; direct runs had no such check. - **Fix:** `mount_ex` (`dm/host/hle_fs.c`) stops on a read-only, non-save mount whose path is neither a folder nor a regular file, with the same `stat` that tells an image from a folder. Add-on content and system data check their paths before mounting, so only the rom mount (`DM_ROMFS`, or `$DM_ROOT/romfs` when it is unset) reaches it. `dm/host/tests/t_fs.c` checks a missing path and a fifo in a forked child. - **Found on:** [Echoes of Wisdom](../../dm/games/01008CF01BAAC000/README.md#found-on-this-game) 1.1.0 on the Mac ([issue #615](https://github.com/seedds/nxnative/issues/615), [PR #616](https://github.com/seedds/nxnative/pull/616)). ### Separate RomFS deployment loses its image or folder fallback - **Symptom:** a successful `--romfs separate --no-keep-extracted` build prints a push command pointing at deleted game files. On iOS, a complete image for another build can also prevent startup despite a valid `Documents/romfs` folder. - **Cause:** separate mode omitted the extraction-retention check, so normal post-build cleanup deleted the image needed for transfer. The startup identity rejection returned before the existing folder lookup. - **Fix:** reject separate mode without `--keep-extracted` before extraction or building. Reject a mismatching image while continuing to the validated folder fallback; move a folder aside for deletion only after accepting the image. Matching images and the default bundled route retain their behavior. The identity covers image size, header and index, not same-length file-content changes. - **Found on:** synthetic CLI and Foundation startup tests while integrating [PR #493](https://github.com/seedds/nxnative/pull/493), after [PR #478](https://github.com/seedds/nxnative/pull/478); no game or device is needed to reproduce either failure. ### A hand-copied RomFS.img is not found on iOS - **Symptom:** a `--romfs separate` app whose image was copied into its Documents folder by hand (Finder, the Files app, a LiveContainer guest) logs `boot: game files not found (Documents/romfs.img, Documents/romfs or <App>/romfs)`, and a build with `romfs.id` shows "There is no game file image on this device.", though the complete image is there. Renaming it to `romfs.img` makes the game start. - **Cause:** the NSP script writes the image as `extract/<version>/RomFS.img`, and `push_romfs.sh` copies it to `Documents/romfs.img`. A hand copy keeps the source's name. The Mac's file system ignores letter case, so the mismatch never shows there, but iOS's does not, and `main.m` looked up only the exact `romfs.img`. - **Fix:** `main.m` (`romfs_document_images`) lists Documents for `romfs.img` in any letter case, `romfs.img` itself first, and takes the first that is complete and passes the `romfs.id` check; a rejected or incomplete one falls through to the next spelling, then to the folders. The identity report, the backup exclusion and the log lines use the names found. Folder names (`Documents/romfs`) are still matched exactly. - **Found on:** [South Park: The Fractured But Whole](../../dm/games/01008F2005154000/README.md) 1.05 on an iPhone 15 Pro Max. The Foundation startup test runs the locator on a case-sensitive APFS disk image. [Issue #582](https://github.com/seedds/nxnative/issues/582). ### Building creates a full RomFS tree before packing its image - **Symptom:** reducing the iPhone transfer to one image still creates thousands of resource files on the Mac, and build scanners require the expanded folder. - **Cause:** folder extraction followed by a separate image pack duplicates the work; ordinary filesystem APIs cannot address files inside an image. - **Fix:** the NSP pipeline passes `--romfs-image` to `nx_extract`. LibHac layers the update over the base and checks its integrity while the writer streams file bytes into a temporary `DMROMFS1` image, appends the sorted directory index and publishes by rename. ExeFS remains expanded; RomFS and each DLC remain one physical file. `dm/tools/romfs.py` gives the scanners read-only virtual paths, bounded seeks and archive mappings (Python 3.12+), without changing the process's standard filesystem APIs. The IPA packer maps the physical image to `Payload/DmIOS.app/romfs.img`; iOS and the Mac launcher validate and mount it in place. Neither installation nor startup expands the resource files. Documents overrides and legacy folder inputs remain supported. A source image is uncompressed; the IPA can deflate it, so file-count reduction does not imply a smaller installed byte count. Full images for separate game versions cannot share unchanged individual files through APFS clones as legacy folder extraction did. - **Found on:** [ANIMAL WELL](../../dm/games/010020D01AD24000/README.md#files), whose direct image is an empty root (56 bytes); the local Baba Is You provisional build exercises 6,374 files in a 103,473,292-byte image, 131 shaders and an unsigned IPA containing only the single image entry. [Raging Loop](../../dm/games/010020400E1C2000/README.md#files-and-shaders) supplies Unity resources: all 1,473 source manifest entries match the image, and every registered shader remains in the scan. Synthetic integration tests call the actual LibHac writer, read unaligned archive ranges, and exercise IPA mapping, Xcode staging and bundled-image startup. ### A build folder holds hundreds of thousands of small files - **Symptom:** a game's `<id>_build` folder is slow to count, copy or delete: Metroid Dread's held 160,331 files in 48,782 folders, 84,541 of them in the compile cache. - **Cause:** the compile cache (`shader/cache/cas`) keeps a few files per shader, and Xcode's derived data (`ipa/build/ios/pkg/dd`) over a thousand. Both are needed to make the next build fast, and only while a build runs. The cache has since become [one file read in place](#the-compile-cache-was-unpacked-for-each-build), and the tar remains for the derived data. - **Fix:** `dm/tools/tree_tar.py` keeps each as one uncompressed tar beside where the folder was. `build_shaders` unpacks the cache only when `dmsh_build.py` will run, and packs it after pruning; the NSP script does the same for the derived data around `build_ipa.sh`. Keeping real folders during the build leaves `dmsh_build.py`, its chain version and Xcode unchanged. A build folder from before this converts by itself. Restored files keep their times, and Xcode's incremental build holds across the round trip (1 file compiled, against 262 for a full build). A build that stops leaves the folder, and a damaged tar costs only the cache it held. `regress.py`'s chain builds share the cache under the same lock. The cost is time on each build that runs the step, and a cache that no longer shares its libraries' blocks through APFS clones. The shader libraries (`b-<chain>`) stay folders: the host reads them one by one. - **Found on:** [ANIMAL WELL](../../dm/games/010020D01AD24000/README.md#found-on-this-game) (the round trip) and [Metroid Dread](../../dm/games/010093801237C000/README.md#found-on-this-game) (84,541 cache files: 51 s to pack, 22 s to restore on a T7). ### The compile cache was unpacked for each build - **Symptom:** a build that runs the shader step writes the compile cache's files back and removes them again, on Skyward Sword HD 24,131 files and 10,150 folders each time, Tears of the Kingdom over 900,000 entries. Removing old entries took up to half an hour on an external drive. - **Cause:** the cache was a folder of a few files per shader, read and written by path, so a tar could only hold it between builds. - **Fix:** `dm/tools/shader_cache.py` keeps it as one SQLite file, `cas.db`, whose entries go in and out by name, with nothing unpacked. Bytes are stored by their hash, since a library under its MSL's digest and its shader's digest was one APFS clone. `dmsh_build.py` and `dmsh_mtlcache.py` use it directly; a shader's entry is written in one transaction, so a stop leaves all of it or none. Several writers wait for each other: `dmsh_build.py`'s threads share a connection, and `regress.py`'s chain builds share their own per-game file, with [read-only reuse of the normal cache](#regression-shader-compilations-grow-the-normal-build-cache). Pruning is a query that gives its pages back. A `cas/` or `cas.tar` from before this moves in by itself at the next shader step, without unpacking a tar: the Metal compile results come along. The per-shader entries do not, as the change of chain they came with means they cannot hit, and neither do the fetch variants, whose older entries hold their source's file name, so that a fresh compile's bytes differ (`regress.py` reports these as changed variants with no change of MSL). A damaged file costs the work it held and is made anew, and a full drive is one `[RED]` line. A revision from before this keeps its own folder, `regress/cas`. - **Measured** on Skyward Sword HD: a 281 MB `cas.tar` became a 226 MB `cas.db`, restoring all 2,470 shaders from the cache took 6 s (9 to 13 s with the tar), and the build folder's `shader/` holds 8 files. It also ran on an exFAT volume, with three processes writing at once. - **Found on:** [Skyward Sword HD](../../dm/games/01002DA013484000/README.md#found-on-this-game). ### A GL regression run reports a hang while frames continue - **Symptom:** `regress.py check` reports `hang (no frame after 72.0 s)` and stops before the last scheduled screenshot, although the captured log has later `[gl] frame` lines and the thread sample shows the game drawing and swapping normally. - **Cause:** the watchdog read only the display link's periodic `presents N` messages for GL games. Those messages stop while the present path falls back to timed presents; the game's GL frame counter keeps advancing. - **Fix:** `run_watched` accepts `[gl] frame N:` as progress too, preserving the present messages for older hosts and other graphics layers. The timeout still catches a game whose frame counter actually stops. - **Check:** `test_regress.py` drives the real watchdog with a controlled clock and child-process log: one present message, then continuing GL frames, must finish without a hang. - **Found on:** Fate/hollow ataraxia REMASTERED (`010070E022546000`, provisional profile), during the [GL argument-buffer regression check](rendering.md#gl-resources-exceed-the-direct-metal-sampler-table): the watchdog stopped at its last display-link record, frame 4200, while the log had reached GL frame 6000. ### Regression shader compilations grow the normal build cache - **Symptom:** Ocarina of Time's `shader/cache/cas.db` occupies 40.8 GB: 30.4 GB of unique Mac and iOS Metal compilations, two complete generations of 42,848 per-shader records, variants and old staged outputs. Some results are useful for regression tests, but pruning old regression chain libraries does not reclaim their cache entries. - **Cause:** `regress.py` directed baseline and candidate builders into the normal build's cache. Metal compilations and variants have no retention limit there; per-shader pruning also preserves entries written after the normal library's stamp. - **Fix:** each game's regression runs share `<id>-work/regress/cas.db`. `shader_cache.py` reads matching immutable shader, variant and Metal entries from the normal cache through SQLite `mode=ro`, including committed WAL writes; local entries take precedence, and new outputs, staging and mutable bookkeeping go only into the regression cache. Missing or damaged fallback databases are ignored, never created or repaired. The harness supplies this cache reader to historical SQLite-based builders without changing their shader chain. Its default physical size budget is the larger of 8 GiB and four times the largest shader-library image in the normal build or retained regression chains; `--shader-cache-gb` sets a fixed per-game budget in GiB. Before and after a build, including a failed or reused build, cleanup removes oldest-written groups until the database fits and returns free pages without copying the database. Shader outputs, variants and split libraries leave as whole groups, identical blobs remain shared, and leftover staging is removed first. Builders hold a shared per-game lock; cleanup requires its exclusive lock, so active builds can temporarily exceed the budget. Folder-based historical builders remain serialized and their legacy archive is removed if it exceeds the budget; the next SQLite-based run adopts it into the regression database. Existing results already mixed into the normal cache stay there: this change does not identify or delete them. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game). - **Check:** `test_shader_cache.py` (read-only fallback, live WAL, forked workers, physical size, grouped eviction, failed builds, concurrent users and a writer without a live harness), `test_regress.py` (historical builder wiring, shared results across runs, automatic and explicit budgets, reused builds). ### Unused files had no one place in the build folder - **Symptom:** Ocarina of Time's `run/pso_archive` held 13.9 GB in 99 files: 64 indexed by library file names (5.3 GB, about 33,700 pipelines, against a prewarm of under 10,000) and 35 with no index (8.4 GB) from the first week. What a build or a run no longer used was deleted in place by some steps, kept by others, and could be told apart from what was in use only by a tool. - **Cause:** a pipeline's archive key covers its libraries' bytes (`arch_key`), so a chain change, a profile edit or an OS update leaves old pipelines no lookup reaches, and only compaction, which takes small files by tier, ever dropped any. The build's own retirements (old libraries, keys, compile caches) were deletions scattered over the build folder. - **Fix:** one folder, `<id>_build/obsolete/`. The NSP script moves what it retires there (`retire`: old chains' libraries and keys from `prune_stale_chains`, other chains' compile caches from `shader_cache.drop_generations`) into `<date time> build/` at their places in the build folder, a rename each. The host counts the pipelines taken from each archive file (`arch_lookup`, `ArchUse`), and once a start has asked for the prewarm lists' pipelines and every shader pair's pulling base (the prebuild's walk, after a chain change; or no pairs), moves the files none was taken from into `$DM_OBSOLETE/<date time> <archive folder>/` (`arch_sweep`, `arch_retire`; the Mac run command sets `DM_OBSOLETE`; the app, without it, removes them), as it already did with files indexed by library file names and files the system cannot open. Both walks are needed for every file, since a run file can hold pulling bases beside bases with a vertex layout. Not in the prebuild's bundle form, nor for files a compaction takes. A file with some live pipelines stays whole: dropping the rest means compacting it, which compiles every pipeline it keeps again (about 85 ms each on Ocarina of Time, 713-762 s for its 8,500 bases), so the sweep only counts them (`… indexed files kept, M of their K pipelines taken; F of them under a quarter used (X MB)`). Measured on Pokémon Legends: Arceus, its archive from chain 66eab9c9a6b4 under chain 19d183a2b462 (copied run folder, the prebuild tool on an M4 Pro): all 19,449 Metal compiles were byte-identical, so the prebuild took all 9,318 pair bases from the archive in 3.4 s and the line read `8 indexed files kept, 9172 of their 9339 pipelines taken; 0 of them under a quarter used (0.0 MB)`. A chain change mostly leaves the libraries' bytes as they were, so a file's pipelines live or die together, and usage-driven compaction would have freed nothing there: not built. A successful build empties the folder's entries of earlier builds and runs (`empty_obsolete`), keeps its own until the next one, and logs how much is left. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game). - **Check:** `test_pso_archive.py` (`test_unused_file_moved_to_obsolete`: two files, a start that takes from one, the other moved with its index once both walks ran), `test_nsp_mac.py` (`test_prune_stale_chains_after_success`, `test_older_compile_caches_go_with_a_build`, `test_obsolete_emptied_by_the_next_successful_build`). On Ōkami HD's copied run folder, the prebuild tool with a current-chain library moved its archive file from an older chain (0.9 MB) to the obsolete folder and built 41 bases; the next run took all 41 from the archive and moved nothing. ### Old chains' compiles stayed in the one compile cache file - **Symptom:** Ocarina of Time's `shader/cache/cas.db` grew to 52 GB, of which its current Mac library used 10.3 GB: about seven generations of Mac Metal compiles (31.4 GB), one of iOS (5.3 GB), three sets of 42,848 per-shader entries (one of them in use), the variants nothing reads since c8bfa161 (2.1 GB) and stopped builds' staging (1.0 GB). What a development build of another chain left could not be told apart or removed without a tool. - **Cause:** every chain wrote into one file. The Metal compiles (`metallib/`) are keyed by the MSL, the convention and the compiler, not by the chain, so no prune could tell which were still wanted, and the NSP script left them all; `shader/` entries newer than the library's list stayed as well. - **Fix:** one file per chain version, `shader/cache/cas-<chain>.db` (`shader_cache.for_chain`). A build writes only its own file; another chain's per-shader entries never hit (their digests cover the chain), and a Metal compile it reads from an older file is copied into its own first. After a successful or reused build the NSP script moves the other files whole into `obsolete/` (`shader_cache.drop_generations`, from `prune_shader_cache`; [Unused files had no one place in the build folder](#unused-files-had-no-one-place-in-the-build-folder)): older chains', and `cas.db`, the one file of every chain from before, which is the oldest generation. A target the build compiled nothing for (iOS after a Mac-only build, the Mac after an iPhone-only one) first takes the newest other file's compiles of it, and nothing goes while the chain has no file of its own or when copying fails. `regress.py` reads the player's generations through `--readonly <shader/cache>`. A chain change copies the compiles it reuses instead of sharing them, a few GB for a large game, once. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game). - **Check:** `test_shader_cache.py` (`Generations`: copying on read, newest generation first, other chains' shaders never hit, dropping older files with the other target kept, a folder as the read-only cache), `test_nsp_mac.py` (`test_older_compile_caches_go_with_a_build`). ### The compile cache stored shader artifacts uncompressed - **Symptom:** even after per-chain generations retire older chains, an active `shader/cache/cas-<chain>.db` still takes tens of gigabytes for large games (e.g. ~2.2 GB for Super Mario Bros. Wonder's Mac chain, ~10–15 GB per Ocarina of Time chain, and ~49–58 GB for a full Pokémon Pokopia build: [issue #1174](https://github.com/seedds/nxnative/issues/1174), [PR #2390](https://github.com/seedds/nxnative/pull/2390)). - **Cause:** `shader_cache.py` deduplicated blobs by content hash but stored every `.metal` source, `.json` reflection file, and `.metallib` Metal bitcode as raw SQLite BLOB bytes. - **Fix:** `dm/tools/shader_cache.py` stores new compile caches in a v2 table schema, `blob(id, hash, codec, payload)`, encoding blobs of 64 bytes or more inline with standard Zstandard level 1 frames (`compression.zstd` on Python 3.14+, `backports.zstd` earlier; incompressible payloads and environments without Zstd store raw with `codec=0`). Naming the column `payload` instead of v1's `data` ensures older checkouts fail closed with `no such column: b.data` instead of misreading compressed frames as raw libraries. Existing v1 raw caches remain readable and writable in place, and migrate automatically to compressed v2 on the next chain change (older-generation `metallib/` reads and `take()` compress v1 blobs once and copy v2 blobs without re-encoding). In forked builds (`Served`/`Remote`), workers hash, link existing blobs by digest without transferring payload bytes, and run Zstd encode/decode in the worker processes. `prune_shaders()` and `trim()` use stored `length(payload)` without decompressing. Corrupt Zstd frames trigger normal damage recovery in `Store` and are ignored in `_ReadOnly`; a missing Zstd module or unknown codec raises `RuntimeError` without deleting the cache. Library images (`b-<chain>.img`) and `DMSH_CHAIN` are unchanged. - **Measured** on an Apple M4 Pro (14 cores, external T7 SSD, controlled A/B against `origin/main` raw v1): - [Cuphead](../../dm/games/0100A5C00D162000/README.md) (3,118 shaders, 157.0 MB `b-<chain>.img`): `cas-<chain>.db` 180.5 → 106.1–107.9 MB (−40.2% to −41.2%); cold 39.15 → 34.43 s (−12.1%), warm 11.81 / 9.78 → 11.65 / 9.59 s, chain-change 21.25 → 21.95 s. - [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) (76,889 unique blobs, 2.06 GB `b-<chain>.img`): `cas-<chain>.db` 2,239.3 → 859.5 MB (2.61×, −61.6%); chain-change 176.65 → 165.69 s (−6.2%), interleaved warm builds 80.64 / 69.44 → 60.18 / 67.52 s (−25.4% / −2.8%), 8-thread `Store.get` over 35,000 entries (1,050.7 MB raw) 7.57 → 2.20 s (3.44× faster). Both games produced byte-for-byte identical `b-<chain>.img` contents across every phase. - **Found on:** [Pokémon Pokopia](../../dm/games/0400A3A01EE4C000/README.md) and [Ocarina of Time](../../dm/games/0400486024DEC000/README.md) ([issue #1174](https://github.com/seedds/nxnative/issues/1174), [PR #2390](https://github.com/seedds/nxnative/pull/2390)); benchmarked on Cuphead and Super Mario Bros. Wonder. - **Check:** `test_shader_cache.py` (`Compression`: inline Zstd and incompressible fallback, fail-closed v2 column check, v1 read/write/migration and zero-reencode v2→v2 copy/take, corrupt Zstd recovery and read-only ignore, missing/unknown codec preservation, forked worker corrupt-Zstd recovery). ### A partial Mac build creates a database at the cache directory path - **Symptom:** a fresh `--seen-shaders` build succeeds. A later full build stops with `NotADirectoryError` while removing `shader/cache/b-<chain>.img`. - **Cause:** the packer passes `shader/cache` as `DMSH_CAS` on partial builds. When that path is absent, `dmsh_build.py` interprets it as the name of a SQLite file. - **Fix:** `build_shaders` creates the cache directory before calling the compiler. For an existing misplaced database, it folds in the SQLite write-ahead log and moves the file to `shader/cache/cas.db`, where the compiler can reuse its Metal compilations. - **Found on:** [Mortal Kombat 11](../../dm/games/0100F2200C984000/README.md), switching from its first partial Mac build to a full one. The bug can affect any fresh NVN partial build. - **Check:** `test_nsp_mac_app.py` (`SeenShaders`) checks the directory before a partial compile and retrieves a saved Metal compile after the full build recovers a misplaced database. ### A new compile cache on an exFAT drive is "a readonly database" - **Symptom:** the first build of a game whose build folder is on an exFAT drive stops at its shader step, before any shader is compiled: `dmsh_build.py` fails opening `shader/cache/cas.db` with `sqlite3.OperationalError: attempt to write a readonly database` at `PRAGMA journal_mode=WAL` in `shader_cache.Store._open`, and the step ends with `[RED] own_compilers.py exit code 1`. Running the build again goes past it, as the failed run has left the file 16 KB long. - **Cause:** SQLite notes a database file's inode when it opens it and refuses a write once its path names another inode (`SQLITE_READONLY_DBMOVED`, extended code 1032, which Python reports as a read-only database); it skips that check while the file is empty. macOS's exFAT driver (FSKit: `mount` shows `exfat, …, fskit`) gives an empty file a placeholder inode (18446744073709551598 on a disk image) and, once it has data, a lasting one. SQLite has guarded against this on Apple systems since 2017: on a volume whose type is `msdos` or `exfat`, it writes one byte (`S`) into an empty file when it opens it, before it notes the inode. On the reporter's external exFAT drive (macOS 26.6.2) the inode still changed at the first write after the open, `PRAGMA auto_vacuum` here, so the WAL pragma after it failed; plain SQLite showed it there too (on a new file, `CREATE TABLE` then `INSERT` failed at the `INSERT`). **Open:** why SQLite's guard missed there (its SQLite build, the drive, or macOS 26's driver). On an exFAT disk image under macOS 27.2, with Apple's SQLite 3.54.0 and 3.54.1 from Homebrew and the tool venv, the guard holds: a new file is 1 byte after the open and keeps its inode, and the cache passes with 400 writes, then 1,200 more from three processes at once. - **Fix:** `dm/tools/shader_cache.py`: when `Store._open` gets `SQLITE_READONLY_DBMOVED` while it sets the file up, it opens the file again once and finishes, so that SQLite notes the inode the file now keeps. It costs nothing where the error does not come. A file that moves again fails as before. The page size, incremental vacuum and WAL stay as they were. The error's code needs Python 3.11 or newer; an older one fails as before. - **Checked:** `test_shader_cache.py` (`Renumbered`) gets SQLite's real error by putting a copy of the file in its place after its first write: the store opens the file twice and keeps its settings through 200 writes, and fails as before when the file moves again; with `DM_EXFAT_DIR` naming a folder on an exFAT volume, the tests also run there. On the reporter's drive, an earlier form of the fix (a new file always opened again after its header) held 500 entries, then 1,200 more from three processes at once ([PR #2435](https://github.com/seedds/nxnative/pull/2435)). - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game), its first Mac app build from a NUP onto an exFAT drive ([GitHub issue #2434](https://github.com/seedds/nxnative/issues/2434)). Applies to every game. ### Shader libraries take a file per shader variant - **Symptom:** a game's shader libraries are slow to copy or delete: Skyward Sword HD's `b-<chain>/` held 12,064 files for 2,470 shaders, a third of its build folder's files, and each `regress.py` chain build held another set. A tar would not do: the host reads these files at every run. - **Cause:** `dmsh_build.py` writes each shader's library, reflection, source and side libraries as separate files, and the host opened them by path. - **Fix:** `dm/tools/shader_lib.py` packs the folder into one file beside its name, `b-<chain>.img`, in the [RomFS image](#romfs-folder-transfers-fail-or-leave-stale-game-files)'s format, flat, each file's data on 16 bytes. Nothing unpacks it: the host (`dm/gfx/nvn/msl_image.h`) keeps one descriptor and maps only a shader's pages, and the tools read it through `romfs.py`. `dmsh_build.py` still writes a folder, so the chain version does not change. The NSP script packs at the end of the shader step, also on a reused step, so a folder from before this converts without a rebuild, and removes the old image only just before a build that replaces it. `regress.py` packs each chain build once it has read it; a revision from before this keeps a folder, and has a chain key of its own. The Mac app and the IPA carry the one file, without the Mac's sources, as `msl/b-<chain>.img`. An iPhone build keeps the pulling vertex libraries, which the launcher's Metal 4 pipelines and prebuild read on the device ([Pulling vertex inputs](rendering.md#pulling-vertex-inputs)). An explicit `IOS_PULL=0`, without an offline archive or Xcode project, neither compiles nor keeps them (`DMSH_IOS_PULL=0` for `dmsh_build.py`), so `pack_ipa.py` reuses that smaller image between packs. A build that wants them again compiles them, and `pack_ipa.py` refuses an image without them for an app that reads them. Each file comes from a folder beside the image first, so a partial `dmsh_build.py` run (given keys) goes over a packed library, and the next pack takes it in; a host running from a folder goes on when it is packed. Real files remain where a tool needs them: a compile's temporary files, and the libraries `metal-tt` reads, for the length of its run. `shader_lib.py expand` gives an old kept host its folder back. - **Measured** on Skyward Sword HD, on an external drive, warm cache: 10,017 files to one: copy 3.72 s to 0.18 s, delete 0.40 s to 0.02 s, 150 MB to 131 MB on disk. Reading all 2,470 shaders' reflection and libraries 100 ms to 28 ms. The map must be `MAP_SHARED`: on a file this size a private mapping costs about 80 µs, against 0.9 µs. A cold read has not been measured, as the cache cannot be emptied without an administrator. - **Found on:** [Skyward Sword HD](../../dm/games/01002DA013484000/README.md#found-on-this-game). ### A Mac app packed with the library's image names it `b-<chain>.img.img` - **Symptom:** the Mac app logs `[RED] shader library …/Contents/Resources/msl/b-<chain> (a folder or a .img file) does not exist` and then `failed to load shader`. Its `msl/` holds `b-<chain>.img.img`, and its `Info.plist` records `DMChain` as `<chain>.img`. - **Cause:** `pack_app.py` accepts the library's folder path or image path. It used the input filename as the output stem and appended `.img` when it wrote the image. The NSP script passes the folder path. - **Fix:** use `shader_lib.name_of` for the output stem in the signed `ShaderLibraries` bundle and in its reuse key, for both the primary program and `--program` entries. The primary stem still takes the explicit `--msl-name` override and supplies `DMChain`. `test_nsp_mac_app.py` checks the signed layout and reuse across both input spellings. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game), a Mac app packed by hand from the build's `shader/cache/b-<chain>.img` ([PR #1790](https://github.com/seedds/nxnative/pull/1790)). ### Identical shader files repeated inside library images - **Symptom:** a built shader library image `b-<chain>.img` stores a separate full copy for every shader filename even when `cas-<chain>.db` already holds identical compiled payloads once. - **Cause:** `dmsh_build.py` queried `STORE.names(prefix)` without each entry's `blob` ID, and `shader_lib.write` assigned a fresh data range to every filename; `shader_lib.subset` and `shader_lib.pack` also copied each entry individually from existing images. Both `romfs.py` and the native reader (`dm/host/romfs_image.h`, `dm/gfx/nvn/msl_image.h`) already allow several filenames to point at one range. - **Fix:** `shader_cache.Store.blob_ids` exposes local staged `blob` IDs, `shader_lib.write` takes an optional `share` map so aliased entries reuse the first entry's `(offset, size)` range without invoking loaders or writing duplicate bytes, and `dmsh_build.publish_library`, `shader_lib.subset`, and `shader_lib.pack` pass those `blob` IDs and existing image ranges. The image format, readers, and shader contents are unchanged, with zero extra hashing and fewer SQLite reads and disk writes; legacy loose-folder packs without a prior image stay unshared. - **Measured** on [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game)'s real library image `b-13b3bdb97e7e.img` (`9.250 GiB`, `173,316` files): `3.86%` duplicate bytes overall (`0.357 GiB`, `5,825` duplicate entries) and `4.20%` in the app subset (`0.199 GiB` of `4.732 GiB`), matching the `cas.db` vs library size gap; investigated following Pokémon Pokopia `#1174` / [PR #2140](https://github.com/seedds/nxnative/pull/2140). - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game). ### A shader build leaves a file per shader output while it runs or after a stop - **Symptom:** a game's build folder holds tens of thousands of small files while its shaders build, and keeps them when the build stops: Octopath Traveler 0's `_build`, stopped in its compile, held 68,230 files (38,376 in `tmp/dmsh_*`, 29,757 in `shader/cache/b-<chain>/`), against 105 once a build finished. Every later build made another `tmp/dmsh_*` beside the old one. - **Cause:** `dmsh_build.py` wrote each shader's outputs into `b-<chain>/` and packed them into the image only at the end ([the entry above](#shader-libraries-take-a-file-per-shader-variant)); its cache check restored every cache hit into that folder before anything was translated; the translator wrote every missed shader's working files (`.bin`, `.spv`, `.res.json`, `.metal`) into one temporary folder before any was finished; and that folder went only when the build ended normally. - **Fix:** `dm/gfx/tools/dmsh_build.py`. A finished shader's files go into the compile cache (`cas-<chain>.db`, under `stage/<output folder>/`) and leave the disk (`commit`); reads of another shader's outputs (a vertex shader's paired pixel MSL for `vs_pad`, the mesh step) take them from there (`output`). At the end the image is written from the staged outputs (`publish_library`, through `shader_lib.write`), with a partial build's image under it less the keys it built, and the folder and the staged entries go; when the image cannot be written, the staged outputs go back into the folder. Cache hits are restored when their shader is finished, not at the look. The shaders are translated and finished in batches of 4 × `J` (the next batch is translated while this one is finished), each in a folder of its own, and a shader's working files go as soon as it is finished. Each build's working folder holds its process ID; a later build removes a `dmsh_*` folder whose process is gone (one without the ID after a day). The NSP script's progress comes from a small file the build rewrites (`DMSH_PROGRESS`), no longer from counting its files. The outputs are the same: chain `cfcc3a82c78b` against the new one, Minecraft Dungeons II's 61,655 library files and Octopath Traveler 0's 41,880 are byte for byte the same (reflection without its `chain` field), apart from `_b_cas.txt`, which lists the new chain's cache digests. - **Measured** on an M4 Pro, every shader translated again (the chain changed), the Metal libraries from the cache: Octopath Traveler 0, 10,324 shaders, at most 405 files under `shader/` and `tmp/` (12 outside a build), 2:48 for the step (2:55 with batches of 4 × 128); Minecraft Dungeons II, 15,826 shaders, at most 3,279 with batches of 256 removed whole. Stopped with SIGKILL near the end of a compile: 40 files in `b-<chain>/` and 7 in `tmp/dmsh_*`; the next run cleared them and wrote the same library from the cache in 59 s. A partial build of 42 shaders for the Mac and the iPhone leaves one image each, also when run again over them. - **Found on:** [Minecraft Dungeons II](../../dm/games/0100A7C01B792000/README.md#found-on-this-game) and [Octopath Traveler 0](../../dm/games/01005270232F2000/README.md#found-on-this-game) builds, reported by the user. ### A full drive during a shader build drops finished outputs from the library - **Symptom:** after a shader build on a nearly full drive (one `[RED] the shader compile cache … cannot be written` line), the library image lacks some outputs of a shader that built: the host finds no reflection or library for it. - **Cause:** `commit` in `dmsh_build.py` removed each file from the disk as soon as its write into the stage had been made, inside the batch that held the shader's other files. SQLite answers a write that does not fit with `SQLITE_FULL` and may roll the whole transaction back, the writes before it too; `Store.put` turned the error into its `full` flag, and the files of those earlier writes were neither on disk nor staged, so `publish_library` left them out. A later write in the same batch ran outside any transaction and stayed, and a failed commit raised after every file was gone. - **Fix:** `dm/tools/shader_cache.py`: a write or a commit that fails fails its whole batch, which is rolled back with `full` set, and no write is tried after that (one inside the ended transaction would land on its own). The outermost batch is tracked by the store, not by SQLite's transaction flag, which the failed write cleared. `commit` removes its files only once the batch has committed and `full` is still clear; otherwise every file stays on disk, where `publish_library` takes it. A forked worker's store (`Remote`) has `full` from the end of its batch. `dm/tools/tests/test_shader_cache.py` fills a store with a page limit inside a batch and fails a commit; `test_shader_toolchain_cache.py` stages a shader into a full store and publishes it. - **Found on:** a code audit's reproduction with a page-limited SQLite file (2026-11-13); no build has been seen to lose an output. ### A work folder holds millions of small files - **Symptom:** a game's `<id>-work` folder is too slow to count: Tears of the Kingdom's held 8,893,028 files and 509 GB, and its count ran past ten minutes. - **Cause:** `regress.py` kept one whole shader build per chain version in `regress/chain` (45 there; Breath of the Wild held 57), and agents' investigations leave folders nothing reads again (`build` alone over 351,000 files). - **Fix:** `prune_chains` in `scripts/regress.py` removes chain builds after each chain step, beyond the 3 used last, any used within 24 hours and those of the 3 newest stored baselines; a check that needs one builds it again. `tree_tar.pack_quiet` packs each other top-level folder untouched for 14 days, with 100 files or more, into `<name>.tar` at the end of an NSP script or `regress.py` run. These tars keep extended attributes, so a RomFS folder's case-collision names survive, and `tar --xattrs -xf` restores them (plain `tar -xf` does not). A Python virtual environment stays a folder, as scripts run it by its path and nothing writes to it, which made it look untouched. It frees no space beyond the chain builds: a folder of APFS clones can take more as a tar, so each tar must fit with 20 GB to spare. A player's NSP folder has no work folder. - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#found-on-this-game). ### The zstd command given a path inside the image - **Symptom:** the NSP script stops at the shader split of a registered profile with `[RED] 13744 file(s) could not be read, their shaders are left out (first: AI/FileEntry/FileEntry.Product.100.byml.zs: CalledProcessError: Command ['zstd', '-d', '-c', '-q', '…/extract/v0/RomFS.img/AI/…'] returned non-zero exit status 1.)`. - **Cause:** `shader_split.py`'s `unzs` read a `.zs` file through `romfs.open`, which reads inside the image, but then handed its path to the `zstd` command, which can only open real files (`Not a directory`). - **Fix:** `unzs` initially fed the command the bytes it read and now [decodes zstd in process](#the-shader-split-takes-a-minute-on-a-romfs-of-300000-files). `test_romfs_read.py` checks a zstd file inside an image. - **Found on:** [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md#shaders): every file of its RomFS is zstd-compressed, 13,744 left out in both versions; the first image-backed build after the folder extraction. ### Under `--work-dir` the programs of one game overwrote each other's RomFS - **Symptom:** an iPhone build of Super Mario 3D All-Stars with `--work-dir` (as NX2Apple runs the script) builds every program, then stops at the app build with `[RED] missing RomFS marker 'MovieData/BgMovieGalaxy.mp4' in <work dir>/extract/v393216/RomFS.img` and `FAIL: no RomFS at …`. - **Cause:** the first program's build packs each of the others from its own profile ([`oe::ExecuteProgram`](services.md#multi-program-applications-oeexecuteprogram)), each in its own build folder, `<NSP folder>/<id>_build`. `--work-dir` named one folder for all of them, so each program's `extract/<version>/RomFS.img` replaced the one before, and the package found Sunshine's image where the launcher's should be. Without `--work-dir` the folders were already apart. - **Fix:** `build_folder` in `scripts/build_ipa_from_nsp.py` gives a program packed with the first `<work dir>/programs/<id>_build` under `--work-dir`; the first program, a game of one program and `--program N` alone keep the folder as named. Test: `test_nsp_build_folder.py`. - **Found on:** [Super Mario 3D All-Stars](../../dm/games/010049900F546000/README.md#found-on-this-game), 1.1.4, built by NX2Apple 1.2.1 as one IPA. ### A shader capture cannot mount the launcher's RomFS - **Symptom:** A shader capture stops with `[RED] fs::MountRom(rom0, program index 0): no RomFS of program 0`, followed by a crash before the first frame. - **Cause:** The capture boots a child program before the packer writes the final `programs.tsv`. The child loads shared files from the launcher's RomFS. With no table, the host mounts the child's own RomFS at `rom0:` and the files are missing. - **Fix:** `build_ipa_from_nsp.py` gives a child program's build-time boots a temporary `DM_PROGRAMS` table with the path to program 0's packed RomFS. The same host lookup serves the capture and the final collection. `test_nsp_multi_program.py` verifies the capture sees the launcher path. - **Found on:** [Kingdom Hearts HD 1.5 + 2.5 ReMIX](../../dm/games/010090C022978000/README.md#found-on-this-game), 1.0.0. ### A dump tool's `.listing` files in the game's folders - **Symptom:** a game built from a dump folder crashes in its own code while it loads, where builds from other dumps of the same version play: Nintendo Switch Sports Resort at `main+0x9d7c60`, listing its `Parameter` folders. - **Cause:** an FTP dump keeps the server's directory listing as `.listing` in every folder, which the NUP spec (§6.3) allows a producer to keep. The RomFS image packed it as a game file, so a game that lists a folder saw one more entry. Switch Sports Resort cuts each name at its first `.`, got an empty name, loaded `Parameter/<folder>/` and found no resource. - **Fix:** `ARTIFACTS` in `dm/tools/romfs_image.py`, the dump-tool files that are not game files (`.listing`), is left out of the image, out of a NUP's RomFS (`scripts/pack_nup.py`) and out of the survey's file list (`dm/games/profile_guess.py`). Other dot files stay game files. Test: `test_romfs_image.py` (`test_dump_tool_listings_are_left_out`). - **Found on:** [Nintendo Switch Sports Resort](../../dm/games/04008E001F098000/README.md#found-on-this-game) (v65536, from a dump folder). ### Processes that scan one RomFS image in parallel wait on its opens - **Symptom:** a tool that scans the files of one RomFS image spends much of its time opening them. In Tears of the Kingdom’s shader split, an open took 133 µs with 18 workers, against 28 µs with one. - **Cause:** every virtual file read opened the same backing image by path. Workers shared the kernel cost of repeated path resolution and opens of that image. - **Fix:** `romfs.reuse_descriptors` keeps a backing descriptor per image for the parent’s archive planning and for the lifetime of each scan worker. The virtual file gets a duplicate for its bounded `pread` or `mmap`. It reuses a descriptor only when the image identity still matches. The scan closes the backing descriptors on exit, and the metadata cache owns none. - **Measurement:** the [original PR](https://github.com/seedds/nxnative/pull/3002) isolated descriptor reuse on Tears of the Kingdom, with 60.0 → 47.7 s wall time and 528 → 471 s CPU time on an M5 Pro. - **Found on:** [Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md#found-on-this-game), while profiling the shader split. - **Check:** `test_romfs_read.py` verifies distinct virtual file descriptors, cleanup after an exception and correct reads after an image is replaced. ## Add-on content ### Separate DLC for a NUP - **Symptom:** a build from a NUP with no embedded DLC omits add-ons the player has as separate RomFS images. The host logs `aoc: reporting 0 add-on contents {} (no DM_AOC_DIR)`. - **Cause:** the packing script selected DLC solely from the container. A separately extracted image never reached the shader scan or the app packer. - **Fix:** `--aoc-dir <folder>` selects a directory of numbered RomFS images for a NUP with no embedded DLC. The script validates the images and stages the complete set separately from the package extraction cache. Each rebuild uses the current selection, including after a front end clears its build folder. An empty folder selects no DLC. A NUP that already lists DLC rejects the option. A prepared Xcode project compares these images by checksum on incremental builds because a replacement can have the same size and whole-second modification time. - **Found on:** [Pokémon Pokopia](../../dm/games/0400A3A01EE4C000/README.md), v655360, whose marker add-on unlocks data in the update. [PR #2905](https://github.com/seedds/nxnative/pull/2905) reports the result on a MacBook Air. - **Check:** `test_nsp_nup.py` checks that the selected images reach the build, stale package images stay out, and rebuilds handle replacement, removal and cleanup. `test_xcode_workflow.py` checks that the staged app also replaces images with matching sizes and times and removes retired images. ### DLC in Documents is ignored or removed DLC remains installed - **Symptom:** a game's DLC works only when packed inside its IPA, although its base RomFS can be deployed separately. After pushing a smaller DLC set, removed indices can remain reported as owned and mounted. - **Cause:** the iOS launcher originally checked only `<App>/aoc`. Merely adding `Documents/aoc` discovery is insufficient: `devicectl device copy to` merges directories by default, retaining removed indices, and skipping a build with no DLC leaves the entire previous set behind. The host counts and mounts the numeric entries under `DM_AOC_DIR`, so those leftovers remain active. - **Fix:** `aoc_locate` in `dm/ios/Sources/main.m` preserves an explicit `DM_AOC_DIR` from the launch environment or `env.txt`; otherwise it selects the first directory at `Documents/aoc`, then `<App>/aoc`, and logs `boot: DLC from <path>`. `Documents/aoc` is excluded from backups. Given `resources.env`, `scripts/push_romfs.sh` transfers the complete `DM_RESOURCE_AOC` directory with `--remove-existing-content true`, replacing old `<index>.img` files and legacy `<index>/` trees. An empty or omitted value sends an empty directory, clearing previous content and explicitly selecting no external DLC rather than falling back to bundled content. A nonempty path that is unavailable stops before any transfer. A direct RomFS-image push has no DLC metadata and leaves DLC unchanged. Transfers are not atomic: rerun a failed push before launching the game. Usage: [Quick reinstalls](../development.md#quick-reinstalls). - **Found on:** synthetic startup and transfer fixtures while reviewing [PR #486](https://github.com/seedds/nxnative/pull/486), part of [issue #388](https://github.com/seedds/nxnative/issues/388). The Foundation fixture runs the actual iOS locator; the push-helper fixture models devicectl's documented merge and replacement behavior, including smaller and empty DLC sets and transfer failure. Applies to every game; no device gameplay validation was performed. ### A registered build without the profile's DLC stops at the shader split - **Symptom:** a game version the profile registers, packed with fewer DLC (or none, or other ones) than the profile was split with, stops at the shader split with `the split shader tables differ from game profile <id>'s`, though the NSP script should derive a DLC-only profile for it (`the installed DLC shader content differs from the registered tables: using a shader-only derived profile`). - **Cause:** `shader_split.py` writes one row per shader key, where the key was first found, and it scans in path order: `aoc/<index>/…` sorts before most game paths. A DLC that ships a copy of one of the game's shaders gave that shader a DLC row whenever the DLC was installed, and a game row when it was not. `dlc_only_shader_change` requires the game's rows (the rows outside `/aoc/`) to be the same on both sides, so a profile split with such a DLC built only with that DLC, and one split without it would not have built with it. - **Fix:** general, in the split (`merge_keys`): a key found in both the game and a DLC is the game's row, whatever the scan order; otherwise the first copy is kept, and two different copies of one key are still red. The game's rows are then the same with or without any DLC, and the derivation rule stays strict in both directions. The profiles with DLC rows were split again with their DLC: PRAGMATA's 45 shared shaders moved to the game's rows (no other change); Mario + Rabbids Sparks of Hope (7 DLC) and FINAL FANTASY X/X-2 HD Remaster (2) came out the same; Xenoblade Chronicles 2, split here with more DLC than its profile, derived a DLC-only profile with no game row changed. `test_split_dlc_shared` (the merge: the game's copy in either order; fails without the change) and `test_nsp_incremental` `DlcOnlyShaders` (both directions with a shared shader; a profile under the old crediting is refused). - **Found on:** [PRAGMATA](../../dm/games/0400C76024710000/README.md) v196608 from a NUP with no DLC, against a profile split with `re_dlc_000.pak`, which holds 45 of the game's shaders ([issue #2439](https://github.com/seedds/nxnative/issues/2439), diagnosed by its reporter and a commenter, both splits checked on their data). ### A generated profile omits the OpenGL library from the app - **Symptom:** the Mac or iOS build reports that it translated the OpenGL shaders for an NVN game, but the installed app has no supplemental GL library and its OpenGL draws are missing. - **Cause:** the packer generates a working profile when the registered profile has no committed NVN shader map. That derivation copied the build and settings but dropped `gl_capture.tsv`. Both packers use the list to decide whether the game needs the GL library alongside its NVN shaders. - **Fix:** a shader-only derivation keeps the registered GL capture list. A derivation for another build still starts without it. Refreshing copied files updates or removes the list without discarding the generated NVN shader tables. - **Check:** `test_nsp_incremental` covers copying, updating, removing and excluding the list for another build. - **Found on:** [NARUTO SHIPPUDEN: ULTIMATE NINJA STORM 4 ROAD TO BORUTO 1.1.0](../../dm/games/01003F800CF5C000/README.md), during app packaging. ### A program of a multi-program game mounts the wrong DLC - **Symptom:** a program packed alone (`--program N`) or packed with its launcher (the launcher's profile names it in `programs`) mounts another DLC than the one it asks for, or none: the build prints `DLC index 0:` for the application's first DLC, the run reports one index fewer than the build extracted (`aoc: reporting 1 add-on contents {1}` for two DLC), `fs mount dlc:` names the wrong image, and the program can end at start (`nnMain returned`). - **Cause:** a program's build runs with its own title ID, the application's plus N, and `extract_aoc` numbered each DLC from that title ID (`index = title ID − title ID of the build − 0x1000`). A DLC belongs to the application and the game asks for it by its index from the application, so every image of program N was N below its index: the application's DLC 1 became `0.img`, which no game asks for, and the game's DLC 1 was the application's DLC 2. - **Fix:** `extract_aoc` numbers from the application's title ID (the build's with its low three hex digits cleared, as a base game's ends in `000`), and a program's DLC extraction key carries that change, so an `aoc/` numbered the old way is extracted again. `test_a_programs_dlc_are_the_applications` in `test_nsp_scan.py` checks the names. - **Found on:** METAL GEAR SOLID: Peace Walker - Master Collection Version (`0100C6F01C4F8000`, 1.3.1), whose launcher starts the game in program 1 (`0100C6F01C4F8001`): with the Multilingual Pack (`…9001`) and the Pre-Order Bonus (`…9002`), program 1 mounted the Pre-Order Bonus where it asked for the Multilingual Pack and ended at start; numbered from the application, it mounts `1.img` with the pack's 273 entries and gets past its start. ### Decoder-backed archives stored only in DLC are skipped at the shader split - **Symptom:** the shader split prints `[RED] N file(s) could not be read, their shaders are left out` with `Oodle- or LZ5-compressed game files: set DM_OODLE_HOST ...` in `shader_split.log`, and splits only shaders embedded in `main` (e.g., 189 / 193 instead of ~58,700) when the program's own RomFS holds no decoder-backed archives and its `.forge` or other Oodle/LZ5 archives live in DLC. - **Cause:** `build_ipa_from_nsp.py` computed `src = build_sources(...)` from the packed program's own RomFS only and set `DM_OODLE_HOST` / `DM_OODLE_MODULES` only from `src['oodle_packs'][0] or src['ue_legacy'][0]`, even though `split_shaders` passes `dlc_roms` to `shader_split.py`, which dispatches every Oodle/LZ5 archive reader over DLC roots too. - **Fix:** `profile_guess.py` factors its RomFS decoder-archive scanner into `decoder_archives` / `decoder_sources` (using `romfs.os.walk` and `romfs.open`, so both `.img`- and directory-backed roots are scanned for all Oodle/LZ5 archive formats, excluding LZO1X Scimitar v27 `.forge`). When an NVN program's own RomFS does not already trigger the Oodle host and `dlc_roms` is non-empty, `build_ipa_from_nsp.py` runs `dlc_decoder_sources` (cached in `work/aoc.sources` for image-only DLC) and enables `DM_OODLE_HOST` / `DM_OODLE_MODULES` if any DLC root needs it. - **Found on:** Assassin's Creed: The Ezio Collection (`0100670014482000`, update 1.3, M4 Pro; [PR #1403](https://github.com/seedds/nxnative/pull/1403)): Brotherhood and Revelations keep all 105 `.forge` archives in DLC while their own RomFS holds only a placeholder, splitting 189 / 193 shaders before vs ~58,700 each after. Synthetic tests in `test_profile_guess.py` and `test_nsp_incremental.py` cover image- and directory-backed DLC, Oodle vs LZO1X `.forge`, other Oodle formats, caching, and the `main()` Oodle-host predicate. ## Launcher metadata ### A game packed from a NUP or a dump shows "Ver. ?" for a build its profile registers - **Symptom:** the game shows `?` where it shows its version (Super Mario Bros. Wonder's title screen: `Ver. ?`), and the build's lines name the version as `v327680 (?)`. - **Cause:** a package with no control data (a NUP update, a dump) packed from a derived profile, here because the folder had no base game for the shader tables. `derive_profile` took the display version of the build row it writes from the package's `control.nacp` alone and wrote `?` without one, and the host answers `nn::oe::GetDisplayVersion` from that row by `main`'s build ID (`hle_sdk16.c`). The profile it derives from registered that very build, with its display version. - **Fix:** `derive_profile` takes the package's control data first, then the display version the profile registers for this `main` build. The selected package's numeric label can supply the version when those sources have no answer. - **Found on:** [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) (1.2.1, v327680, an update-only NUP; `main` ff773e90…, the registered build): `Ver. ?` before, `Ver. 1.2.1` after, one Mac boot each to the title screen. - **Check:** `dm/tools/tests/test_nsp_alias.py` `test_derived_profile_keeps_the_display_version_the_profile_registers_for_the_build`. ### An unregistered NUP build loses its numeric version label - **Symptom:** the title menu of a game packed from a NUP with a version label shows `version: ?`. - **Cause:** the NUP has no NACP and the profile has no matching build. The packer discarded the NUP label and wrote `?` into the derived build row that `nn::oe::GetDisplayVersion` reads. - **Fix:** the survey, derived profile and app read the selected package's version label from the NUP. The label accepts one to three ASCII numeric components, an optional `v` and up to 15 version bytes. A label equal to the package's `v<number>` tag is ignored. The label stays with its package and is read again on each build. - **Found on:** [Mario Kart World](../../dm/games/0400C3F00006E000/README.md) 1.8.0. The reporter rebuilt the game and verified the title menu. Reading the local NUP and deriving its profile also gave `1.8.0` for both the build row and bundle metadata. [Issue #2902](https://github.com/seedds/nxnative/issues/2902) ### An app packed without control data says version 1.0 - **Symptom:** Finder shows `Version 1.0` for a Mac app whose game is at another version. - **Cause:** the app packer got its version from the game's NACP. A dump or NUP can have no NACP, leaving the bundle packer to write its default even when another source identifies the version. - **Fix:** Mac apps and IPAs take the packed version's NACP first, then the numeric version from the packed build's profile row, then the base game's NACP, then the selected NUP package's version label. The build can read the base NACP from the NUP even when it only extracts the update. With no usable value the app defaults to `1.0`. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md). The author rebuilt the Mac app from a NUP whose selected update was labelled `1.1.1` and checked both version fields in `Info.plist`. The local NUP has neither a NACP nor a display label. The profile registers `1.1.1` for its verified v131072 build ID, which gives the local build the same app version. [PR #2822](https://github.com/seedds/nxnative/pull/2822) - **Check:** `dm/tools/tests/test_nsp_nup.py` exercises the app fallback through the packing entry point with a synthetic NUP and the registered Ocarina of Time build IDs. ### No Game language row in an app packed from a NUP or a dump - **Symptom:** the settings of a Mac app or IPA packed from a NUP or a dump folder have no Game language row, while `DM_LANG` in the environment changes the language. Reported on [Donkey Kong Bananza](../../dm/games/040074A01BF12000/README.md) ([NX2Apple#619](https://github.com/LNPANDY/NX2Apple/issues/619), [#659](https://github.com/LNPANDY/NX2Apple/issues/659); the reporters' packed files were not available). - **Cause:** `settings.py` shows the row when the game's `control.nacp` lists more than one language, and two cases gave it none. A NUP update may carry no control data: the NSP script's language check fell back to the base game's file, but the Mac settings got only the update's path, and `build_ipa.sh`'s fallback (`$W/data/v0`) is a folder the NSP script does not make. And there may be no NACP at all: the Yoshi and the Mysterious Book and [Age of Imprisonment](../../dm/games/04003F40232DE000/README.md) NUPs carry none in any package, and an FTP dump such as Bananza's has no control data. - **Fix:** `languages_control` in `build_ipa_from_nsp.py` picks the file once (the packed version's, else the base game's), for the check, `mac_app` and `build_ipa.sh` (`CONTROL`). With no list, `settings.py` offers every language with a note, as `game_language` and `DM_LANG` already accept any. Age of Imprisonment shows a language it lacks as English (Russian, Portuguese) and has more text languages than its voice folders suggest (Dutch, Simplified Chinese), so a game's list cannot be read from its folders. - **Found on:** code reading and the NUP records of the two games above, with [PR #1182](https://github.com/seedds/nxnative/pull/1182); boots of [Age of Imprisonment](../../dm/games/04003F40232DE000/README.md) to its first settings screen. Not confirmed on Bananza by the reporters. ### An app packed from a NUP's update has no icon - **Symptom:** the Mac app has the system's blank application icon (no `AppIcon.icns` in its `Contents/Resources`), though the NUP carries the game's icon. - **Cause:** the NUP has the icon on its base game's record and none on the update's. `pack_version` saved the packed package's own records only, and the NSP script looks for `icon.jpg` in the packed version's folder, then in the folder the base game is extracted to alone. A profile that builds from the update only makes no such folder, so the base game's icon was never written. - **Fix:** `pack_nup.control` gives an update without an icon its base game's (the icon record, else its localized icons, as for its own). The NACP stays the package's own, since its display version and languages are that version's. - **Found on:** [The Legend of Zelda: Ocarina of Time](../../dm/games/0400486024DEC000/README.md) (v131072). The profile builds from the update alone, and its Mac app had no icon because the NUP's 256×256 JPEG was on the base record. The [PR #2823](https://github.com/seedds/nxnative/pull/2823) author applied the fix to an older main revision and repacked the Mac app. The update's extraction contained the base game's `icon.jpg`, the app contained `AppIcon.icns` with the game's artwork, and the signature verified. - **Check:** `dm/tools/tests/test_nsp_nup.py` `test_update_without_an_icon_takes_its_base_games`. ### A Mac front end's default settings change Metal execution paths - **Symptom:** starting a Mac app through a front end with unchanged settings enables the encode thread, and can disable Metal 4 pipelines and the pipeline archive; starting the same app from Finder keeps the host's defaults. - **Cause:** Mac `launcher.json` reused iOS defaults from `settings.tsv`. `rec_on` in `nvn_rec.h` defaults off on Mac and on on iOS; `pso4_on` in `nvn_mtl.m` defaults on on Mac and follows the profile on iOS. The exported defaults instead enabled the encode thread everywhere and followed the profile for Metal 4 everywhere. A front end applying those values changed the Mac host's behavior without a player override. - **Fix:** a setting's default may be `<ios>|<mac>`, selected before resolving a profile macro or build variable. Metal 4 uses `DM_GAME_PSO_MTL4|1`, the encode thread `1|0`. The generator validates the platform and the pair. Tests cover a profile with Metal 4 on and one with it off, and both platforms; the host and shader chain are unchanged. - **Found on:** synthetic metadata generation for [Super Mario Bros. Wonder](../../dm/games/010015100B514000/README.md) while reviewing [PR #352](https://github.com/seedds/nxnative/pull/352); checked against the native defaults, without a gameplay run. ### The Mac settings window stays on screen after Play - **Symptom:** in a Mac app, the settings window stays on screen after **Play**, not responding (a spinning cursor over it), until the game ends. - **Cause:** the window runs in the launcher's process (`dm/mac/Launcher.swift`). `finish` ordered the window out and stopped `NSApp.run`; then `launcher.c` started the host and blocked in `waitpid`, so the main thread never ran another run-loop pass. A window's order-out is committed only at the end of such a pass, and its default fade-out runs over several passes, so the window never left the screen. With the run loop kept running, the same order-out took effect at once. - **Fix:** `finish` sets the window's `animationBehavior` to `.none` before the order-out, and `dm_mac_launcher` calls `CATransaction.flush()` after `run()` returns, before it hands back to `launcher.c`. Neither alone was enough. Check: a copy of the window with a timed Play and a `CGWindowListCopyWindowInfo` probe while the thread then blocks; the window was still listed 2 and 4 s after Play before the fix, and gone 3 times in 3 after it. `test_launcher_storage.py` and `test_nsp_mac_app.py` pass. - **Found on:** the Mac app of [Breath of the Wild](../../dm/games/01007EF00011E000/README.md); applies to every Mac app. ### A reused Mac app reports an earlier source commit - **Symptom:** packing after a checkout-only change reports `reused (inputs unchanged)`, but `Info.plist` still names the earlier `DMCommit`; build-provenance checks reject the app. - **Cause:** `pack_app.py` included selected runtime files, options and tools in its reuse key, but not the checkout identity it writes into the bundle. Identical runtime files can belong to different commits, or to clean, dirty and non-Git source states. - **Fix:** read source identity once, include it in the reuse key and use that same snapshot for `DMCommit`. An unchanged identity still reuses the complete app. A changed identity repacks and signs the outer bundle through the existing atomic replacement path while reusing unchanged signed data bundles. This does not prove that the source tree stayed unchanged throughout packaging. - **Check:** `PackReuse.test_source_identity_invalidates_reuse_and_matches_metadata` calls the real pack entry point with synthetic files and fake external compiler/signing tools. Changed commit, dirty state and missing Git provenance must repack with matching metadata (reusing the signed data bundles); each unchanged state must reuse without compiling or signing. The old key fails this regression. - **Found on:** local [Ocarina of Time](../../dm/games/0400486024DEC000/README.md) candidate packaging after a documentation-only commit ([PR #2232](https://github.com/seedds/nxnative/pull/2232)). No game-data or rendering change is needed to reproduce it. ## External drives ### A game folder on an exFAT drive reads one update as two, or fails to remove a folder - **Symptom:** with the NSP folder on an exFAT or FAT drive, the build leaves out an update whose name has no `[v…]` tag (the folder seems to hold two), or a stage stops with `FileNotFoundError` on a `._<name>` path inside `<id>_build/` and the next run fails on the half-deleted folder. - **Cause:** these file systems have no extended attributes, so macOS keeps a file's attributes (a download's quarantine flag) in an AppleDouble file `._<name>` beside it, and deletes it with the file. `scan_nsps` took `._Update [<title ID>800].nsp`, 4 KB of metadata, for an update: its name carries the title ID. Deleting `x` takes `._x` with it, so `shutil.rmtree`'s later unlink of the listed `._x` found it gone; before Python 3.13 that error ended the removal. - **Fix:** `scripts/build_ipa_from_nsp.py` `scan_nsps` takes a file only when its header is one nx_extract opens (`is_package`: `PFS0` at 0, or an XCI's `HEAD` at 0x100), and says which files it skips. The name tag alone no longer counts, so the same check also rejects any other tagged file that is not a package. Names that start with `._` are skipped without a line. The script's `rmtree` passes ENOENT from `shutil.rmtree` (the entry is gone, which is the goal) and raises every other error. `dm/tools/tests/test_nsp_external_drive.py` and `test_nsp_scan.py` cover both without game files. - **Found on:** the NX2Apple fork's users, who keep games on external drives ([PR #476](https://github.com/seedds/nxnative/pull/476), part of [issue #388](https://github.com/seedds/nxnative/issues/388)); reproduced on an exFAT disk image made with `hdiutil create -fs ExFAT`. Applies to every game. ### The c1 guard stops on an AppleDouble file after the shader build - **Symptom:** with the build folder on an exFAT or FAT drive, the shader step compiles every library and then stops in `c1_guard.py` with `UnicodeDecodeError: 'utf-8' codec can't decode byte …` (dmsh_build.py: `[RED] c1_guard.py failed`), reading a `._<key>_b.metal`. - **Cause:** the same AppleDouble files as above, beside the shader build's outputs. `c1_guard.py` took every name ending in `.metal` for a shader's MSL and read the binary `._` file as text. `cb_extent.py` (every `_b.json`) skipped it only because it ignores what it cannot parse, and `dmsh_mtlcache.py` (every `_b.metal`) took `._<key>_b` for a shader, found no readable reflection for it and so filled the Metal cache from none of that folder's libraries. - **Fix:** the three take only the names the shader build writes, `<16 hex key>_b….metal` / `.json` as `dmsh_build.py` (`OUT_KEY`) and `regress.py` already did: `c1_guard.py` `outputs` (which `cb_extent.py` uses too) and `dmsh_mtlcache.py` `OUTPUT`. None of them is part of the chain version. `dm/tools/tests/test_nsp_chain.py` runs both table tools on a folder with `._` files; the old `c1_guard.py` stops on it. On 13 Sentinels' 751 shaders both tables are unchanged. - **Found on:** a user's iOS shader build on an external drive ([PR #555](https://github.com/seedds/nxnative/pull/555)). Applies to every NVN game. ### The Mac app step stops on AppleDouble files in its inputs, its copies and its signature - **Symptom:** with the build folder or the app on an exFAT or FAT drive, the Mac app step stops in `pack_app.py`. The first form it takes is `no input file at <build>/shader/cache/<chain>/._<key>_b.metallib`, or `no rewriter fixups for <build>/<version>/._main.patched.bin` when the modules come first. When the inputs get past it, the copies stop with `chflags` or `Permission denied`, and the signing step stops with `codesign failed (1): code object is not signed at all` and `In subcomponent: …/Contents/MacOS/._nxnative`, which reads like a broken launcher build. - **Cause:** the same AppleDouble files as above. The module, shader, pipeline and font globs of `selected_inputs` took `._<name>` for a module or a library, and a `._x.patched.bin` has no `x.fixups.tsv` beside it. `shutil.copy2` of the host tried to set the copy's flags on a file system without extended attributes (`chflags: Operation not permitted`), and `cp -R` carried a folder's sidecars into the bundle, where `DMModuleFiles` listed them. `codesign` then read the `._nxnative` beside the launcher as a nested code object that is not signed and refused the whole bundle. Signing also sets an attribute on what it signs, so the sidecar comes back after a successful signature. - **Fix:** `dm/mac/pack_app.py` `detritus()` drops those names from `selected_inputs`, so neither the pack nor `DMModuleFiles` sees them. `copy()` passes `-X` where it copies and not where it clones (`cp` refuses the two together), and the host goes through `shutil.copy` instead of `copy2`, so a copy creates none of them. `strip_detritus()` runs before `codesign` reads the staged bundle, runs again after `xattr -cr` when `codesign` still refuses one, and runs once more after signing. On APFS nothing changes: no sidecar exists there, and the two passes are a stat walk. `dm/tools/tests/test_nsp_mac_app.py` puts a `._` file in every input folder and checks that it is not selected, does not reach the bundle, and is not in `DMModuleFiles`. - **Found on:** the NX2Apple fork's users, packing Mac apps on an external drive ([LNPANDY/NX2Apple#486](https://github.com/LNPANDY/NX2Apple/issues/486)); reproduced on an exFAT disk image made with `hdiutil create -fs ExFAT`, where the same inputs pack, sign and pass `codesign --verify --strict` with the change and stop three ways without it. Applies to every game's Mac app. ### A second Mac app build stops with `[Errno 45]` when it replaces the old app - **Symptom:** with the app on a Mac OS Extended, exFAT or FAT drive, the first build into a folder works and the next one that changes anything stops in `pack_app.py` `replace_app` with `OSError: [Errno 45] Operation not supported: '<app>'`. The old app stays in place. - **Cause:** `replace_app` exchanges the new and the old app with `renamex_np(RENAME_SWAP)`, which only APFS offers: the others return `ENOTSUP`. A first build has no old app to exchange, so it takes a plain rename. - **Fix:** on `ENOTSUP` or `EOPNOTSUPP`, `swap_by_moves` makes the state the swap leaves with three renames (the old app to `<app>.old`, the new one to `<app>`, the old one to `<app>.partial`), so the key write and its rollback do not change. A rename that fails undoes the ones before it. These volumes cannot make it atomic: a process killed between the first two renames leaves no app at `<app>`, with the old one at `<app>.old` until the next replacement clears it. APFS still swaps. Tests: `dm/tools/tests/test_nsp_mac_app.py` `test_volume_without_atomic_swap_replaces_by_moves`, `test_fallback_restores_the_old_app_when_a_move_fails` and `test_fallback_clears_an_old_app_a_killed_build_left_aside`. - **Found on:** a user's rebuild onto an external Mac OS Extended (Journaled) drive ([LNPANDY/NX2Apple#595](https://github.com/LNPANDY/NX2Apple/issues/595), [PR #1190](https://github.com/seedds/nxnative/pull/1190)); reproduced on HFS+ and exFAT disk images made with `hdiutil create`, where the `PackReuse` tests stop with the real errno without the change and reach the fallback with it. Applies to every game's Mac app. ### External shader directories contain AppleDouble metadata - **Symptom:** on an exFAT or FAT drive, shader splitting stops with `ValueError: not a version 2 shader code archive` or `[RED] /glslc_capture/._…: no GLSLC output`. - **Cause:** `shader_split.py` selected captured `.glslc` programs and decoded `.ushaderbytecode` archives by extension alone. macOS AppleDouble sidecars retain that extension, but their `._<name>` files contain metadata rather than shader bytes. - **Fix:** exclude `._` names when listing both external shader directories, including `DM_GLSLC_CAPTURE` and `DM_UE_SHADERS` overrides. Other dot-prefixed names remain valid inputs, and malformed real inputs still fail their normal validation. - **Found on:** an external-drive build reported in [issue #229's follow-up](https://github.com/seedds/nxnative/issues/229#issuecomment-6563450365). That commenter used a different, unnamed game; this fixes the sidecar failure, not the original Metroid Prime 4 port. ## Compressed inputs ### NSZ decompression rejects `--keys` - **Symptom:** `decompress NSZ` stops immediately with `nsz: error: unrecognized arguments: --keys …`. - **Cause:** `nsz` 4.6.1 has no `--keys` argument. It loads `keys.txt` beside `sys.argv[0]`, or falls back to `~/.switch/prod.keys`, while importing its modules, before parsing arguments ([4.6.1 key loader](https://github.com/nicoboss/nsz/blob/4.6.1/nsz/nut/Keys.py)). Version 5.0 supports `--keys` ([argument parser](https://github.com/nicoboss/nsz/blob/5.0.0/nsz/ParseArguments.py)); staging `keys.txt` also supports 4.6.1. - **Fix:** `scripts/build_ipa_from_nsp.py` `decompress_nsz` prefers the current Python's module: it links the file selected by `-k` as `keys.txt` in the conversion's temporary folder and runs `nsz -D` there, with `sys.argv[0]` set to `nsz` before import. Without the module, `nsz_command` probes `nsz` and `nsz-cli-macos-arm64` on the build's PATH and passes `--keys` to the first whose successful help lists that option. An unsupported or failed candidate does not hide the next one; when none works, the error lists the reasons and installation options. Executable, input and output paths are absolute because conversion changes directories. The temporary folder and link are removed on success or failure; the user's default keys are untouched. - **Found on:** [Super Mario Odyssey](../../dm/games/0100000000010000/README.md), converting its v0 NSZ. Applies to NSZ and XCZ inputs for every game. Synthetic tests during [PR #327](https://github.com/seedds/nxnative/pull/327) also reproduce an older console script hiding the release binary, a failed help probe containing `--keys`, and a relative PATH executable failing after the directory change; no game files are needed for those cases. ### ZBIC-compressed NSO segments - **Symptom:** the NSP script or any module tool stops on `main`: `compressed with zstd (NSO flag bit 7), which this loader does not decode yet`; with the decoder but without its package, `ZBIC (zstd) segments need the zbic package (python3 -m pip install zbic)`. - **Cause:** from system 22.0.0, an NSO may store its segments as **ZBIC**, NSO flag bit 7 for the whole module (the per-segment compression and check-hash bits keep their meaning). ZBIC is Nintendo's variant of zstd, not a container around standard frames: its frames start with the magic `ZBIC` and its FSE tables are written with binary interpolative coding, so neither `compression.zstd` nor the `zstd` command can read them. - **Fix:** `dm/tools/nso.py` decodes such segments with the [`zbic`](https://pypi.org/project/zbic/) package (Kinnay's, zstd with Atmosphère's ZBIC changes), imported only for a flag-bit-7 module; every segment is still held to the header's size and SHA-256. zstd has no fixed ratio bound, so a ZBIC segment is held only to its own size, where an LZ4 one is also held to 255 bytes per stored byte. Install it with the other tools (README, step 1). The NSP script checks for it before it extracts anything, as it does for its other modules, because it first reads a module at the rewrite, after the whole RomFS is unpacked. - **Check:** Well Dweller's `main` decodes to 85,370,056 bytes with segments `0x39680d0 / 0x9f7e74 / 0x9b1930`, every SHA-256 matching; `dm/tools/tests/test_nso.py` checks that a flag-bit-7 module whose segments are not ZBIC is an Error naming ZBIC. - **Found on:** [Well Dweller](../../dm/games/0100217023F6C000/README.md) (SDK 22.2.0). ## Versions with different modules ### A version without one of the profile's modules stops the host at boot - **Symptom:** `FATAL open <folder>/subsdk1.fixups.tsv` right after the host starts, or `build_ipa.sh` stops with `no rewritten module …/subsdk1`, for a version that has no such module. - **Cause:** a game's versions can differ in modules: Mario Kart World's base game has `main`, `subsdk0` (a Mono runtime) and `sdk`, its update 1.8.0 `main`, `subsdk0` (the movie player), `subsdk1` (a C library) and `sdk`. The host, the rewrite, the IPA and the shader split all took the one `modules` list of the profile. - **Fix:** `modules` lists all of them in load order, and each `build` row names its own (`game.py` `build_modules`; a row naming one `modules` lacks is an error). The host loads the modules of the row of `main`'s build, read from the rewriter's `main.fixups.tsv` (`main.c` `profile_modules`, from `DM_GAME_BUILD_MODULES`), and all of `modules` for a build with no row. `build_ipa.sh` takes the same list (`game.py modules <id> <folder>`). The NSP script rewrites, sizes `mem_used` from and splits the modules the packed version's ExeFS holds (`Game.modules_in`), and a derived profile's row names those (`derive_profile`). - **Found on:** [Mario Kart World](../../dm/games/0400C3F00006E000/README.md): the base game boots with its three modules from a profile that lists four. Applies to every game. `test_game_profile.py` checks the rows and the list. ### An update that changes only code stops the extraction with exit code -6 - **Symptom:** the NSP script stops at `extract v<version>` with `[RED] nx_extract exit code -6`; `logs/extract_v<version>.log` lists the ExeFS and its build IDs, then ends in `Unhandled exception. LibHac.Common.HorizonResultException: ResultFsInvalidArgument (2002-6001)` at `Aes128CtrExStorage..ctor`, under `Nca.OpenRawStorageWithPatch` and the RomFS read. - **Cause:** the update changes the code modules and no data. Its Program NCA's data section is still a patch (`IsPatchSection`), but its relocation table has one entry and its AES-CTR-Ex table none (an empty `BKTR` header, size 0), and the section holds no data of its own. LibHac 0.19 refuses an AES-CTR-Ex table of no entries (`BucketTree.Initialize` returns `ResultFsInvalidArgument` for `entryCount <= 0`, while `LibHac.FsSystem.AesCtrCounterExtendedStorage` handles zero entries with an empty tree), so layering the update over the base throws. The section's IVFC hash data (levels, salt, master hash) is the base data section's, so the patched RomFS is the base RomFS byte for byte. - **Fix:** `dm/tools/nx_extract/Program.cs` (`PatchKeepsData`) verifies both NCAs' data FS headers (`GetFsHeader`): when both are non-sparse, non-compressed RomFS IVFC sections, the update is an `AesCtrEx` patch whose `BKTR` AES-CTR-Ex header has zero entries, and both sections share the same 0xF8-byte IVFC hash data, `nx_extract` reads the base game's RomFS (with full IVFC verification) and logs `the update's data section is a patch that changes nothing (empty AES-CTR-Ex table, the base's IVFC hash): the base game's RomFS is read`. Any other patch is layered as before. - **Found on:** [Pokémon Legends: Z-A](../../dm/games/0100F43008C44000/README.md) base v0 with update v65536 (1.0.1, key generation 18; its `main` is 1.0.0's, `7222e13e…`): the merged RomFS (22 files, 4.08 GB) now writes as an image with every hash check on, and lists the same 22 files as the base game alone. Synthetic NCA3 tests in `dm/tools/tests/test_pfs0_storage.py` (`Pfs0StorageTests.cs`) reproduce LibHac's `2002-6001` error on an empty AES-CTR-Ex table and check the guard's accept and reject cases. Not checked: Z-A 1.0.1 packed and played. ## Package identification ### An update is taken for the version in its file name - **Symptom:** `[RED] leaving out update NSPs without a version tag ([v<N>]) in their name`, for every untagged update when the folder holds any other update (`….v720896.UPD.nsp`, [PR #393](https://github.com/seedds/nxnative/pull/393)). A single untagged update is packed as the newest version the profile registers, whatever it is. A wrongly tagged update is packed as the tagged version, and after the whole extraction the build IDs disagree with the profile's row and the build goes on from a derived profile, without that build's fixes. A base game served at a later version is packed as `v0`, which the profile may not register: Castlevania: Belmont's Curse's base is 1.1.0 (v65536) and its profile registers only `v65536`. - **Cause:** `scan_nsps` took each package's version from the `[v<N>]` tag in its file name and its title ID from its ticket or tag; it read a package's content metas only when it held several. A base game was always `v0`. Tags drift in real collections: a Castlevania base NSZ was tagged `[v0]`, while its content meta and `cnmt.xml` say v65536. - **Fix:** `scan_nsps` reads every package's content metas in one run, `nx_extract <prod.keys> --contents <package>...` (`package <index> <file name>`, then one `content <type> <title ID> <version>` line per content meta; only headers and the meta NCAs are read, about 0.05 s for a folder). Each package's title ID and version are its content metas', for the base game, every update and every DLC, so a file's name no longer matters to the build. `nsp_versions` names the base game by its own version (`v0` for most games; `v65536` for that Castlevania base, its profile's registered row). A `[v<N>]` tag that disagrees is said in one line and ignored. Keys that cannot open the meta NCAs stop the scan with `nx_extract`'s line ([Keys older than the game](#keys-older-than-the-game-stop-the-extraction-with-an-unhandled-missingkeyexception)). A package that cannot be read, or that holds no base game, update or DLC (a delta update), is skipped with a `[RED]` line, since it could not be extracted either. The ticket and tag readers (`title_of`, `nx_extract --title`, `is_merged`) and the untagged-update guess are gone. DLC extraction always names the DLC's title ID (`--aoc … <DLC title ID>`). - **Found on:** [Castlevania: Belmont's Curse](../../dm/games/0100BA4026E94000/README.md)'s base game ([issue #1629](https://github.com/seedds/nxnative/issues/1629)). Checked with the real tool on renamed links: Balatro with an untagged update (base v0, update v851968); Mario Kart 8 Deluxe with its update tagged `[v65536]` (taken as v1441792, said), an untagged DLC (v65536) and a truncated package (skipped: `ResultFsOutOfRange`); NieR:Automata's XCI; keys holding only `header_key` stop with `prod.keys has no key_area_key_application_0c`. Applies to every game. ### An NSP without a ticket or a title ID in its name stops with "no NSP with a readable title ID" - **Symptom:** `[RED] no NSP with a readable title ID in <folder>`, although the keys open the package (the launcher's key check passes). Renaming the file to `Game [0100XXXXXXXXXXXX].nsp` makes the build go on. - **Cause:** `title_of` took the title ID only from the ticket's file name (`<rights ID>.tik`) or from a `[title ID]` tag in the package's file name. Many NSPs carry no ticket (standard-crypto dumps, repacks), and a download's file name often has no tag. - **Fix:** with neither, `title_of` asked the package (`nx_extract <prod.keys> --title <package>`: the lowest title ID of its meta NCAs' headers). Since [issue #1629](https://github.com/seedds/nxnative/issues/1629) every package's title ID comes from its content metas, ticket or not, tag or not ([An update is taken for the version in its file name](#an-update-is-taken-for-the-version-in-its-file-name)); `title_of` and `--title` are gone. It works for NSP, NSZ (the meta NCAs are not compressed), XCI and XCZ. `nx_extract` is built into a temporary folder for it, since the build folder is named after the title ID. Key values are never printed. - **Found on:** NX2Apple, [LNPANDY/NX2Apple#177](https://github.com/LNPANDY/NX2Apple/issues/177) ([Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md), whose base NSP has no ticket). Applies to every game. ### A game file whose extension is in capitals is not found - **Symptom:** `[RED] no NSP with a readable title ID in <folder>` for a folder holding `Game [0100XXXXXXXXXXXX].NSP`, on any Mac volume; renaming it to `.nsp` makes the build go on. A dump folder beside `Game.NSP` is packed instead of the package, and `Game.NUP` is not found. A `Game.NSZ` stops with `nsz made no Game.nsp`. - **Cause:** the script listed the folder with `Path.glob('*.nsp')`, which compares case-sensitively on every POSIX system, a case-insensitive Mac volume included. nsz has the same limit of its own: `PathTools.isCompressedGame` takes only a lowercase extension, and nsz skips anything else and exits 0 with no output. It resolves a symlink before it looks. - **Fix:** `files_with_suffix` lists a folder's files by their lowercased extension, for every scan of the inputs, and a package beside a compressed one is found in that listing. A compressed file in capitals goes to nsz as a hard link with a lowercase extension in its temporary folder, or as a copy where there can be none (another volume, exFAT), so the player's file stays as it is. - **Found on:** NX2Apple, [LNPANDY/NX2Apple#554](https://github.com/LNPANDY/NX2Apple/issues/554) ([Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md)). Applies to every game. ### A merged NSP (base game, update and DLC in one file) packs as one title - **Symptom:** a game folder holding one merged package (`[Base + Update + DLC].nsp`, or a 1G+1U cartridge dump with no update NSP beside it) stops with `no base game NSP found`, or packs the base game alone (v0) without its update and DLC; when the base game's own build cannot be packed (Mario Kart 8 Deluxe 1.0.0's `main` is 32-bit), the build stops there. - **Cause:** `scan_nsps` gave each file one title ID: its first ticket's, else its name's tag. A merged package holds a ticket per title in any order, so it counted as the base game or as the update, never as both, and its DLC was never seen. `nx_extract` then read the update from a separate update NSP only. - **Fix:** a package is asked for its content metas (`nx_extract <prod.keys> --contents`; first only a package whose file table held more than one `*.cnmt.nca`, since [issue #1629](https://github.com/seedds/nxnative/issues/1629) every package: [An update is taken for the version in its file name](#an-update-is-taken-for-the-version-in-its-file-name)), and counts as each Application, Patch and AddOnContent it lists, with the versions from the metas. The one file is then given to `nx_extract` as both the base game and the update: `OpenNsp` keeps the NCAs that the Application content meta lists for the base and the Patch content meta's for the update, both of the application being packed (`--app`), and `--aoc <package> <out> <DLC title ID>` takes one DLC's data NCA by its title ID. The extraction estimate, the progress total and the NSZ conversion count the file once. A DLC NSP that bundles several DLC is read the same way. - **Found on:** Mario Kart 8 Deluxe (0100152000022000, no profile here) from one merged NSP, in NX2Apple ([PR #842](https://github.com/seedds/nxnative/pull/842), [LNPANDY/NX2Apple#376](https://github.com/LNPANDY/NX2Apple/issues/376)). Checked with Balatro's update NSP and base NSP merged into one PFS0: it scans as base v0 and update v851968, and `nx_extract` given it as base and update writes the same ExeFS, control data and RomFS manifest as the two separate NSPs. Applies to every game. ### A derived profile leaves out a module that moved to another slot - **Symptom:** a version a profile was not brought up on crashes at its first movie: `UNIMPL _ZN5movie9ExtractorC1ENS_13ContainerTypeE`, then `CRASH sig=11` ([issue #1211](https://github.com/seedds/nxnative/issues/1211)). The derived profile's `modules` has only `main sdk`. - **Cause:** `derive_profile` could only take modules out of the profile's list, but a module's slot belongs to a build, not to a game: Absolum's movie module is `subsdk2` in 1.1.2, where `subsdk0` is NVIDIA's Vulkan driver, and `subsdk0` in 1.2.1. - **Fix:** `derive_profile` adds what `profile_guess.main_modules` finds: a module the list leaves out that exports something `main` imports, which no listed module and no host hook supplies, and never a GPU driver. It shares this with `nro_modules` (`modules_supplying`). The added module goes in the version's `build` row too, since the host loads what the row names. Checked on 9 games' real modules with their registered lists: nothing is added (Super Mario Galaxy 2's GLSLC and `nn::pcm`, which the host supplies, stay out), and each of the 7 subsdks taken out of a list comes back. A registered build keeps its row: the rule runs only when a profile is derived. - **Found on:** [Absolum](../../dm/games/0100A83022A22000/README.md) 1.2.1, from the reporter's logs: with the module added by hand the game reached gameplay at 60 fps. No 1.2.1 files on this Mac: not run here. ### A derived profile loads only the modules its version ships - **Symptom:** the NSP script stops at its rewrite stage with `FileNotFoundError: … extract/v0/ExeFS/subsdk1` while packing a version the profile was not brought up on; the extraction has every other module. - **Cause:** `derive_profile` in `scripts/build_ipa_from_nsp.py` gives the derived profile this version's `build` row, made only from the modules its ExeFS holds, but copied `modules` unchanged. A version that ships fewer modules than the registered one (an older base game before an update added a module) then names a module the rewrite and the host try to load. - **Fix:** `derive_profile` keeps in `modules` only those the version's ExeFS holds, with a comment naming the ones left out; a version that ships them all keeps the line as it is, and `shader_only` derivations are unchanged. The host is built from the derived profile, so it loads the same list. - **Found on:** Mario Kart World 1.0.0 (`0400C3F00006E000`, a base-game dump: `main`, `subsdk0` and `sdk`), packed from a profile for 1.8.0, whose `subsdk1` is the C library module the update added ([PR #1081](https://github.com/seedds/nxnative/pull/1081)). With it the rewrite, the shader split (11,561 shaders) and the Mac host built, and the game drew its first course on the Mac. - **Check:** `test_nsp_incremental` (`test_a_module_the_version_does_not_ship_is_left_out`: the module left out with its comment and its build row, then kept once the version ships it). ### Another edition's files lack the profile's RomFS marker - **Symptom:** a game packed under another title ID than its profile's (another region's edition of the same `main` build) builds its shaders, then stops at the app step with `no RomFS at …/RomFS.img (missing CPK/ALL_USEU.CPK)` (on iOS also `[RED] missing RomFS marker`). Every build of it extracts the whole package again, though nothing changed. - **Cause:** `romfs_marker` names a file of the edition the profile was brought up on, and another edition may name its files differently: Persona 5 Royal's Asian title has `CPK/ALL_ASIA.CPK` where the registered one has `CPK/ALL_USEU.CPK`. `derive_profile` copied the marker unchanged, so the app step checked the RomFS for a file it never holds. `extract` also took the image for reuse only when it held the marker, read from the registered profile before any derivation, so it never reused this edition's image. - **Fix:** general, in `scripts/build_ipa_from_nsp.py`. `derive_profile`, for a profile derived under another title ID, keeps a marker the version's RomFS holds and otherwise takes the largest file it holds, as a provisional profile does; the choice is in the derived key. A profile derived under its own title keeps a missing marker, so the app step still stops on a damaged or mixed-up RomFS, as does an empty one. `extract` reuses an image by its [extraction key](#extractions-kept-from-an-older-nx_extract-or-another-copy-of-the-game) and a valid index (`romfs` reads it as a directory), not by the marker: the key names the packages, the options and the `nx_extract` that made it, and `swap_in` never leaves a half-replaced image in place ([Stopping a build while it replaced an output](#stopping-a-build-while-it-replaced-an-output-left-that-output-half-deleted)). - **Found on:** [Persona 5 Royal](../../dm/games/01005CA01580E000/README.md)'s Asian title `01004B10157F2000` v65536 ([PR #1882](https://github.com/seedds/nxnative/pull/1882)): on the reporter's RomFS the rule takes `CPK/ALL_ASIA.CPK`, and the Mac app packed and passed its codesign check with that marker. Its gameplay and iOS are not tested. The extraction reuse is inferred from the code and checked by the tests, not timed on the game. - **Check:** `test_nsp_incremental` (`test_cross_title_marker_uses_actual_regional_resources`: folder and image, with and without the inherited marker, then reuse; the same title, an empty RomFS and a shader-only derivation keep the marker) and `test_nsp_extraction_key` `Program` (an image without the registered profile's files is reused under its key; one with a cut index is extracted again). ## Keys ### Keys older than the game stop the extraction with an unhandled MissingKeyException - **Symptom:** `nx_extract` stops with exit code 134 and `Unhandled exception. LibHac.Common.Keys.MissingKeyException: Unable to decrypt NCA section.` with `Key Name: key_area_key_application_<NN>` (or `titlekek_<NN>`), after any NSZ conversion, the build ID lookup or the survey. An NSZ converted with such keys is written anyway: `nsz -D` warns `master_key_<NN> missing … This will lead to corrupted output.` and exits 0. - **Cause:** each NCA's header names the key generation its content needs; a prod.keys dumped from a console on older firmware than the game lacks that master key and every key derived from it. Nothing checked the keys against the packages before the first step that decrypts them, and LibHac's exception reached the log as a crash. - **Fix:** `nx_extract <prod.keys> --keys <package>...` opens every NCA of the packages (an NSZ's or XCZ's compressed ones by their header, which nsz keeps as it was) and applies LibHac's own test (`CanOpenSection`). On the newest key missing it prints `[RED] <file>: prod.keys has no <key> (master key <NN>, which came with firmware <version>) …` and exits with code 6; a rights-ID NCA with no common ticket is named the same way. The NSP script runs it once after scanning the folder (`check_keys` in `package_reader`), before `nsz -D`, the survey and the extraction, and stops with that line; any other failure of the check is left to those steps. Extraction, `--aoc` and `--contents` run the same check before they decrypt anything (the content metas first), so `nx_extract` alone also stops with exit code 6 instead of a crash. The firmware table runs to 21.0.0 (master key 0x14); a newer key is named as "a firmware after 21.0.0". The check reads only headers: the NSP script stops on Balatro's two NSPs in about 1.5 s. - **Found on:** NX Library ([Bium23/NxLibrary](https://github.com/Bium23/NxLibrary)), a Mac front end that checks the keys before starting a build, an idea from NX2Apple. Checked with Balatro's NSPs and an NSZ of its base game, with a copy of prod.keys without the keys of master key 0x10 and later (and one without 0x0a and later): every path names `key_area_key_application_10` and firmware 17.0.0, and the complete keys pass and extract as before. Applies to every game. ## Cartridge dumps ### A cartridge dump with its update on it extracts the update as the base game - **Symptom:** the extraction of a game whose base is an XCI that also carries its update (a "1G+1U" dump) stops with `[RED] nx_extract exit code -6`. `extract_v<version>.log` lists the update's build IDs even for the base game alone, then ends in an unhandled exception from the RomFS (`ResultFsNonRealDataVerificationFailed (2002-4604): Hash error!` from `RomFsFileSystem..ctor`, or `ArgumentException` / `InvalidOperationException` from the patch layers). - **Cause:** the XCI's secure partition holds the update's NCAs beside the base game's, and the update's Program NCA has the program's title ID too. `nx_extract` took the first Program NCA of the lowest title ID as the base, which is the update's when the dump lists it first. Its data section is a patch (BKTR) over the base RomFS, so it cannot be read alone or under another patch. The ExeFS still opens, with the update's build IDs, because an update's code section is complete. The Control NCA (display version, icon) was also whichever of the two came last. - **Fix:** `dm/tools/nx_extract/Program.cs` `OpenNsp` reads the base package's content metas (`*.cnmt` in its Meta NCAs) and keeps only the NCAs that its Application content meta lists, and prints how many it left out. When none of them is a Program NCA (NCA files renamed, so their names are not content IDs), it prints a `[RED]` line and reads every NCA as before. An NSP or a base-only XCI keeps every NCA but its meta NCA, so it extracts as before (Balatro's NSPs and Monster Hunter Rise's XCI give identical manifests). The update on the cartridge is packed too since [a merged package counts as each title it holds](#a-merged-nsp-base-game-update-and-dlc-in-one-file-packs-as-one-title). - **Found on:** [The Legend of Zelda: Tears of the Kingdom](../../dm/games/0100F2C0115B6000/README.md), a 1G+1U XCI (base v0 with update 1.4.3, whose 524 MB Program NCA is listed before the base's 17.1 GB one) beside the 1.4.3 update NSP ([PR #311](https://github.com/seedds/nxnative/pull/311)). Reproduced with a package of Balatro's update NSP followed by its base NSP: the base alone and the base with the update now give the same manifests and control data as the separate NSPs. Applies to any game's XCI that carries its update. ### A cartridge dump that holds two games packs only the first - **Symptom:** an XCI with two applications (Super Mario Galaxy + Super Mario Galaxy 2 on one cartridge dump) always packs the first game; `build_ipa_from_nsp.py` never reaches the second. - **Cause:** the scan took one title ID per file (the file name tags both games, and the first tag won), and `nx_extract` kept the NCAs of every Application content meta and took the Program NCA of the lowest title ID. Nothing could name the other application. - **Fix:** the XCI's content metas make it [count as each title it holds](#a-merged-nsp-base-game-update-and-dlc-in-one-file-packs-as-one-title), so the scan finds two games and stops with `more than one game in the folder`, naming both. `--title-id <title ID>` (`TITLE_ID` in Spyder) picks the game to pack from them; the script passes its title ID to every base extraction (`nx_extract … --app <title ID>`), and `OpenNsp` keeps only that title's Application and Patch content metas' NCAs (an `--app` the package has no content meta of stops with the ones it has). Each game gets its own `<title ID>_build/` folder and app. - **Found on:** [Super Mario Galaxy 2](../../dm/games/0100FD8022DAA000/README.md), on the same XCI as [Super Mario Galaxy](../../dm/games/010099C022B96000/README.md) ([PR #701](https://github.com/seedds/nxnative/pull/701), which packed both from the XCI with an earlier form of the option). This form is checked with a test XCI's file table and with Balatro's packages (`--app` of a title the package does not hold stops, naming the one it has); no two-game XCI is on hand. ## Damaged packages ### Extraction of a damaged NSP ends in "The LinkedList is empty" - **Symptom:** `nx_extract` stops with exit code 134 and `Unhandled exception. System.InvalidOperationException: The LinkedList is empty.` from `LibHac.Tools.FsSystem.CachedStorage.GetBlock`, with no `[RED] hash check failed` list, with or without `--allow-damaged`. - **Cause:** a damaged NSP with more than a few damaged files used up LibHac 0.19's hash cache. `CachedStorage.GetBlock` takes a block off its list before reading into it and does not put it back when the read fails, so the 4 blocks of a filesystem last for 4 failed reads and the next read that misses the cache throws. That exception is no hash error, so `nx_extract` did not catch it. A copy of SteamWorld Dig with 2 flipped bytes listed its 2 files; with 40 it crashed. - **Fix:** each hash error gets a new checked filesystem (`Failed` in `dm/tools/nx_extract/Program.cs`, on the image, folder and manifest paths), so a damaged NSP lists every damaged file and stops with exit code 3, or goes on with `--allow-damaged`. The same copy with 40 flipped bytes lists all 36 files. `test_every_damaged_file_is_listed_past_the_hash_cache` in `dm/tools/tests/test_romfs_read.py` puts a real RomFS behind a real `CachedStorage` on all three paths, with no NSP or keys. - **Found on:** [Breath of the Wild](../../dm/games/01007EF00011E000/README.md#found-on-this-game) ([issue #810](https://github.com/seedds/nxnative/issues/810), whose reporter diagnosed the lost cache blocks and carried a local patch that reopens the filesystem). Applies to any game. ### A damaged RomFS's own tables - **Symptom:** `[RED] the NSP is damaged: a filesystem's own tables fail the NCA's hash check`, exit code 3, right after the build IDs; before 2026-11-04, `[RED] nx_extract exit code -6` with an unhandled `ResultFsNonRealDataVerificationFailed (2002-4604)` under `RomfsHeader`. The ExeFS reads, and the build IDs and name are printed, since only the RomFS is hit. - **Cause:** the damage lies in what the RomFS opens from (its header, or the hash levels above it), so no file can be listed, and `--allow-damaged` has no file to write as read. Hashing each NCA tells which one it is: its file name is the first 16 bytes of its SHA-256. - **Fix:** `nx_extract` says so and exits with 3, as for damaged files. A good copy of the NSP is the only cure. A base game that is intact packs alone with `--package <its version>`, once it has a profile. - **Found on:** [Mario & Luigi: Brothership](../../dm/games/01006D0017F7A000/README.md#versions): update 1.0.1's Program NCA `074db5a4…` (its NSP is also a repack: it holds a `.cnmt.xml`). ### A crash from a damaged NSP's file looks like a host bug - **Symptom:** a build packed with `--allow-damaged` crashes or draws wrongly in game code, the same way on each run, at a place unrelated to the host's last work. The log gave no sign of damage; the build log's list (`logs/extract_<version>.log`) is the only record, and it is not part of a bug report's run log. - **Cause:** `--allow-damaged` writes files that failed the NCA's hash check as they were read, and nothing told the running host. A wrong byte in a compressed pack decodes to wrong data far from where the game then fails. A hash block also spans neighbouring small files, so a listed file's bytes may still be right. - **Fix:** the entry's last byte in a `DMROMFS1` index ([format](../../dm/tools/romfs_image.py)) is 1 on a file that failed the check (`img_ent.flags`, `romfs_image.h`; `nx_extract` sets it, and every reader refuses another value, or a flag on a directory). The mark stays with the image in an IPA, a Mac app or a hand-copied `romfs.img`. The host logs `[RED] fs RomFS image <path>: damaged files <N>: ...` at the mount and `[RED] fs rom:/<file> failed the NCA's hash check ...` at each damaged file's first open. A clean image is byte-identical to one from before this mark (checked on SteamWorld Dig), so its identity does not change. Not marked: an image extracted before this change, and folder extraction, which has no index (the NSP script writes images). Search a crash's log for `hash check` before looking for a cause in the host. - **Found on:** [Breath of the Wild](../../dm/games/01007EF00011E000/README.md#found-on-this-game) ([issue #810](https://github.com/seedds/nxnative/issues/810)). `dm/host/tests/t_fs.c` checks the count, the single report at first open and the refused flags; a boot of SteamWorld Dig on a deliberately damaged image logged the count and the files it opened. ### A build that allows damaged files splits and restores every shader again - **Symptom:** every build with `--allow-damaged` runs the shader split and restores every shader from the compile cache, though nothing changed: about 56 s of split and 9½ minutes of shaders (42,848, about 75 a second) for Ocarina of Time on an M3 Max, each build. - **Cause:** `split_shaders` gave a damaged copy no key (`key = None if ALLOW_DAMAGED`): a good copy that replaces a damaged one keeps every file's path and size, all that the RomFS input (`('tree', …)`) sees, so that key would have kept the damaged split. The shader step takes the package's key as its input, so it never reused its libraries either; the Vulkan and OpenGL shader steps were told not to reuse (`reuse=not ALLOW_DAMAGED`). - **Fix:** a damaged copy is keyed as the same extraction: its RomFS by its files' times (`('stat', …)`, which an extraction writes again; inside `RomFS.img`, the image's) and by `check_formats`' list of damaged files (`RomFS.img.formats`). A build of the same extraction reuses the split and the shaders; a new extraction (a repaired copy, other options: `extraction_key`) or another damage list splits again. The Vulkan and OpenGL steps key a damaged copy by times as well (their `provisional` keying). An undamaged build's key is as before, and damaged and undamaged builds never take each other's split. - **Found on:** [Ocarina of Time](../../dm/games/0400486024DEC000/README.md#found-on-this-game), v131072 built with `--allow-damaged`, which a contributor kept on after replacing a NUP with three damaged textures ([A damaged file in a NUP or a dump has no hash to fail](#a-damaged-file-in-a-nup-or-a-dump-has-no-hash-to-fail)): the option alone, with no file damaged, took this path. `dm/tools/tests/test_nsp_incremental.py` (`SplitShaders.test_damaged_reuses_only_the_same_extraction`). ### Build anyway stops on an unreadable archive despite matching shader tables - **Symptom:** a registered game's extraction succeeds with `--allow-damaged`, but shader splitting stops with `file(s) could not be read; the profile's tables hold every file's shaders`, even when every generated shader table matches its registered table. - **Cause:** the shader step rejected unreadable archive data before comparing the tables, independently of the explicit extraction override. A corrupt non-shader resource can produce that warning without losing any required shader. - **Fix:** allow the explicit override past the unreadable-file guard, retaining the warning and all registered shader-table comparisons. Missing or changed shaders still stop the build, and a normal build still rejects unreadable files. This does not repair corrupted game assets. - **Found on:** [Xenoblade Chronicles 3](../../dm/games/010074F013262000/README.md), 2.2.1: `bf3.ard` failed its NCA integrity check and one zlib stream failed decompression, while all 27,055 shader keys and all generated profile tables matched. - **Check:** `test_nsp_incremental.py` covers matching tables, reuse, a mismatched table under the override and refusal without the override. ### An update's offline HTML pages reported as a damaged NSP - **Symptom:** the NSP script stops at the offline HTML pages (`logs/extract_html_<version>.log`) with `[RED] the NSP is damaged: <n> files fail the NCA's hash check` and a list under `/html-document/`, although the program extracted cleanly and the NSZ tool verified every NCA of the update. - **Cause:** an update's HtmlDocument NCA can be a patch of the base game's. `nx_extract --html` guessed: it read the update's NCA alone first and over each base NCA second, keeping the first read that did not throw. A read that fails the hash check does not throw, though: `Copy` lists each file as damaged and goes on. So the read alone was kept, the patched one was never tried, and the files it listed stopped the build. - **Fix:** `nx_extract --html` (`dm/tools/nx_extract/Program.cs`) reads the NCA's header: a data section with a relocation table (`IsPatchSection`) is a patch, read over the base game's Manual NCAs, and any other is read alone, once, so damage in it is reported as damage. The header does not say which base NCA a patch is over (HtmlDocument and LegalInformation are both Manual), so `Try` reads over each in turn and undoes a read that adds files that fail the hash check (it deletes the folder and takes the entries off the list). A patch that reads over none is reported with `[RED] an HtmlDocument NCA of the update patches none of the base game's`, and the log names each patched read (`html<n>: a patch of the base game's NCA`). - **Found on:** [Super Smash Bros. Ultimate](../../dm/games/01006A800016E000/README.md#found-on-this-game) update 13.0.5 (`v2031616`) ([PR #1215](https://github.com/seedds/nxnative/pull/1215)): 1,641 of the NCA's files failed alone; read through the base, 2,798 files (122.2 MB) and none damaged, and the game packed and played a battle on the Mac at 60 fps. Balatro's update has a full Manual NCA: it is read alone, as before. `IsPatchSection` checked on Balatro's update: true on the Program NCA's RomFS, false on its ExeFS, its Manual NCA and every base section. ### Extractions kept from an older nx_extract or another copy of the game - **Symptom:** an offline page of the game shows white and takes no button: `[RED] web: the page asked for dmweb://doc/contents.htdocs/howto/img/bg_melee.webp, which its document does not have` (five such lines: two images, two scripts, a font), then `web: page error: ReferenceError: Can't find variable: controller_setting`. Super Smash Bros. Ultimate opens its How to Play page before the first battle, so the game could not be played past it. The same cause kept a version's program: an image packed with `--allow-damaged` stayed in a later build without the option, or after a good copy of the same file replaced the damaged one. - **Cause:** both outputs of `nx_extract` for a version were reused for as long as they existed: `extract_html` took `extract/<version>/html` when the folder was there, and `extract` took `ExeFS/` and `RomFS.img` when they were there with the profile's RomFS marker. The app was built with an nx_extract from before [the patch read](#an-updates-offline-html-pages-reported-as-a-damaged-nsp) and with damaged files allowed: 1,641 of the 2,798 files of the update's pages failed the hash check and were left out. A later build with the fixed nx_extract over the same build folder kept that folder, so the fix never reached the pages. Neither stage looked at what made its output: which nx_extract, which package files, which options. - **Fix:** one key for every output of nx_extract (`extraction_key` in `scripts/build_ipa_from_nsp.py`): nx_extract's source sha (the one `find_nx_extract` checks the executable carries), each package's name, size and time (a good copy has the same name and size), and the options (`extract_flags`: the application, the program, `--allow-damaged`). It is written beside the output after the output is in place (`extract/<version>/extract.key`, `html.key`, `aoc.key`), and the output is reused only while it matches; a folder with no key, from a build before it, is extracted again once. A new program extraction replaces the version's folder whole, so its pages are read again with it. A NUP or a dump folder's packer removes `extract.key`, since what it writes is not nx_extract's. Cost: each change to nx_extract's source extracts every version again on the next build (minutes for a large game; the shader split of a profiled game keys on the RomFS's names and sizes, so its shaders are kept), the pages 4.5 s for Smash. `pack_app.py` already takes the pages as an input of the app, so a Mac app follows. - **Found on:** [Super Smash Bros. Ultimate](../../dm/games/01006A800016E000/README.md#found-on-this-game) 13.0.5 (`v2031616`), a Mac app built at 7249ee9f ([PR #1545](https://github.com/seedds/nxnative/pull/1545)): its `html0` held 1,157 of 2,798 files. Read again with the current nx_extract: 2,798 files, none damaged, the 1,157 the app had byte-identical. With the 1,641 added to the app, the page loads with no red line, takes buttons and ends (`web: the page ended: exit reason 3`), and the game goes on to its stage selection. - **Check:** `dm/tools/tests/test_nsp_extraction_key.py`. ## Build ID lookup ### An unreadable unused base stops discovery after a readable update - **Symptom:** for a title ID with no profile, the newest update extracts successfully during `build ID lookup`, but the subsequent base-only probe fails its ExeFS hash check and stops the survey, even though the update supplies the code. - **Cause:** `same_build` tries the newest update's main build ID, then the base game's as a second guess. Both used the same fatal extraction call, making the optional base-only probe a required input. This lookup error is independent of why that base cannot be read; the reported base hash failure has not been diagnosed as damage or a sparse NCA. - **Fix:** `scripts/build_ipa_from_nsp.py` `same_build` catches `BuildError` only on the base-only probe after the newest update's extraction succeeded. It logs `[RED] the base game alone could not be read for the build ID lookup; the update supplies the code, so the survey goes on`, deletes the partial output and continues without an alias match. A failed update extraction, unexpected errors from the base probe when there is no update, and other exceptions still propagate. Exit code 4 is accepted only for a base-only probe with no readable main. The survey and build's actual extractions remain strict. See also [recognizing a sparse base](#the-surveys-build-id-lookup-stops-on-the-base-game-alone-with-a-hash-error). - **Found on:** [Pokémon Violet](../../dm/games/01008F6008C5E000/README.md#files-and-shaders) ([PR #2701](https://github.com/seedds/nxnative/pull/2701)). - **Check:** `dm/tools/tests/test_nsp_alias.py` covers continuation after an unreadable optional base and preservation of the required base-only failure. ### A program introduced by an NSP update has no base NCA - **Symptom:** selecting the new program with `--program` stops at `no Program NCA … in the base NSP`. Reading its update Program NCA directly opens the ExeFS but fails on the RomFS. - **Cause:** the program ships only in the update. Its RomFS uses BKTR, and all 6,237 relocations select the update's own storage. LibHac applies the relocation map through its patch-overlay API. - **Fix:** `nx_extract` accepts an explicitly selected program supplied by the update. For a BKTR section it checks every relocation before using the update as both inputs to LibHac's overlay. A relocation into base storage still requires the matching base NCA. ExeFS and RomFS extraction keep their integrity checks. - **Found on:** [XCOM 2 Collection](../../dm/games/0100D0B00FB74000/README.md) `v131072`, whose War of the Chosen program extracted all 5,317 RomFS files with strict integrity checks. ## Sparse base games ### The survey's build ID lookup stops on the base game alone with a hash error - **Symptom:** for a game with no profile, the NSP script stops at `build ID lookup · main of the base game` with `[RED] nx_extract exit code -6`; `<title ID>_survey/logs/exefs.log` ends in `ResultFsNonRealDataVerificationFailed (2002-4604): Hash error!` from `PartitionFileSystemMetaCore.QueryMetaDataSize` under `Nca.OpenFileSystem`, although every NCA in both NSPs matches its content ID (the SHA-256 that names it) and the base game with its update extracts cleanly. - **Cause:** the base game's Program NCA is sparse: its code and data sections carry a sparse layer and leave out data that the update supplies, so the base is smaller than its update (1.6 GB against 2.9 GB). Horizon mounts such an NCA only through its patch; read alone, the left-out ranges fail the hash check from the first block of the ExeFS. The lookup (`same_build`) tries main's build ID of the newest update first, then of the base game alone, and `run` stopped the build on the second attempt's failure. - **Fix:** `dm/tools/nx_extract/Program.cs` stops with exit code 4 and `[RED] the base game's program is sparse: it can be read only with its update NSP` when it is given a sparse base without an update (any enabled section of the Program NCA with a sparse layer). `scripts/build_ipa_from_nsp.py` `run` takes the exit codes a caller accepts (`ok`), and `same_build` accepts 4: the base game alone then has no main of its own and the lookup goes on. The base game with its update reads as before (LibHac layers the update over the sparse base; the whole 4.2 GB merged RomFS of the game below reads with every hash check on). - **Found on:** [Minecraft Dungeons II](../../dm/games/0100A7C01B792000/README.md), base v0 (SDK 22.2.0) with update v131072 (1.1.3.0). Applies to any game whose base Program NCA is sparse. ### The offline pages of a sparse base game stop the build as a damaged NSP - **Symptom:** the NSP script stops right after `extract v<version>` with `[RED] the NSP is damaged: a filesystem's own tables fail the NCA's hash check` and `nx_extract exit code 3` from `logs/extract_html_<version>.log`, although every NCA's SHA-256 matches its name. - **Cause:** the base game's HtmlDocument NCA can be sparse too (16 KB, beside the sparse Program NCA). `--html` reads the update's HtmlDocument NCAs, each over a base one when it is a patch, and then every base HtmlDocument NCA on its own; a sparse one read alone fails the hash check while its tables open. - **Fix:** `dm/tools/nx_extract/Program.cs` reads no sparse base HtmlDocument NCA on its own (`a sparse HtmlDocument NCA of the base game (… bytes): read only through the update's patch, not alone`), as Horizon mounts it only through its patch. - **Found on:** [Minecraft Dungeons II](../../dm/games/0100A7C01B792000/README.md), base v0 with update v131072: the update's patch (`accessible-urls`) and its full legal information NCA are read, the base's legal information NCA too. ### Offline pages of a sparse base game are incomplete without its update patch - **Symptom:** `nx_extract --html` on a base NSP with no update (or an update that does not patch its sparse Manual NCA) prints `a sparse HtmlDocument NCA of the base game (16384 bytes): read only through the update's patch, not alone`, writes only the non-sparse Manual NCAs (`1 HtmlDocument NCAs`) and exits 0, although the sparse HtmlDocument pages are missing. - **Cause:** the sparse-base skip above skipped every sparse base Manual NCA unconditionally without checking whether an update patch actually read through that base NCA. Without an update, or when the update only ships an unrelated full Manual NCA (such as LegalInformation) or patches a different base NCA, nothing supplied the sparse NCA's pages. - **Fix:** `dm/tools/nx_extract/Program.cs` (`ExtractHtml`) records the exact base Manual NCAs that an update patch successfully read through (`patched`). A sparse base Manual NCA is skipped only when it is in `patched`; otherwise `--html` removes any partial `html<n>` folders it created, prints `[RED] a sparse HtmlDocument NCA of the base game (… bytes) has no update patch to read it through: its pages are missing; pack the base game with its update NSP`, and stops with exit code 4 (the code a sparse base Program NCA without its update already returns). Non-sparse bases and updates whose patch matches the sparse base read identically to before. - **Check:** `dm/tools/tests/test_pfs0_storage.py` (`CheckSparseHtmlExtraction` in `Pfs0StorageTests.cs`) covers base-only sparse extraction (including end-to-end `--html` CLI on a synthetic NSP), an unrelated full update Manual NCA, a patch matching a different base NCA, a failed patch alongside a full update NCA, a second unpatched sparse base, a matching patch (3 directories, exit 0), and a non-sparse base alone. - **Found on:** [Minecraft Dungeons II](../../dm/games/0100A7C01B792000/README.md), base v0 without its update ([PR #1769](https://github.com/seedds/nxnative/pull/1769)): base-only extraction previously wrote 14 files in one directory and exited 0, against 29 files in three directories with update v131072. ### An update's manual patch read over the wrong base NCA stops the build - **Symptom:** with the base game and its update in the folder, the NSP script stops after `extract v<version>` with `[RED] a sparse HtmlDocument NCA of the base game (16384 bytes) has no update patch to read it through` and `nx_extract exit code 4`; `logs/extract_html_v<version>.log` shows `html0: 1 files … a patch of the base game's NCA` before it. - **Cause:** the base game has two Manual NCAs, its HtmlDocument (sparse, 16 KB) and its LegalInformation (complete), and the NCA header calls both `Manual`. `--html` read each update patch over the base Manual NCAs by trial, in the package's order, and took the first that read without a hash failure. A patch whose pages all come from the update reads cleanly over either base, so when the package lists the LegalInformation NCA first, the HtmlDocument patch was taken as its patch and the sparse HtmlDocument NCA was left unpatched. Whether a build passed depended on the order of the files in the NSP. - **Fix:** `dm/tools/nx_extract/Program.cs` keeps each NCA's content type from its package's content meta (`g_metaType`, filled by `OpenNsp`), and `ExtractHtml` reads a patch only over the base NCAs of its own type (HtmlDocument over HtmlDocument, LegalInformation over LegalInformation), as Horizon mounts a patch over the base content of its type. An NCA the content meta does not list (renamed NCA files) is tried as before. - **Check:** `dm/tools/tests/test_pfs0_storage.py` (`CheckSparseHtmlExtraction`): a patch that reads over every base is read over the base of its type with the LegalInformation NCA listed first (case 7b), and a typed patch with no base of its type is read over none (7c). - **Found on:** [Minecraft Dungeons II](../../dm/games/0100A7C01B792000/README.md), base v65536 (file name `[v0]`) with update v131072 (1.1.3.0), from a package listing the LegalInformation NCA before the sparse HtmlDocument one: 1 file in 2 folders and exit 4 before, 29 files in 3 folders after, as with the package the profile was brought up on. ### Unreal 4.27 shaders with 8-byte hashes, an untagged record or a version 12 pak - **Symptom:** the shader split for an Unreal 4.27 game finds no shaders or stops on the shader library: `shader library chunk … does not parse`, `pak version 12, only … are read`, or `not an LSLG record`. - **Cause:** Godzilla: Destroy All Monsters Melee Remastered uses 8-byte xxHash64 values in its IoStore shader library. The reader supported 20-byte SHA-1 values, as used by FINAL FANTASY RESONANCE. Godzilla's Switch shader records omit the `LSLG` and stage tag, and its pak footer is version 12. - **Fix:** `uepak.py` tries 20-byte hashes first and switches to 8 only if the tables fail to parse with matching counts and consume the whole chunk. The version 2 archive stores each 8-byte hash with 12 zero bytes appended. Version 12 follows version 11's footer rules. For untagged Switch records, `raw_record` looks for a unique control section with matching code lengths and a `0x880`-byte control length. `shader_split.ue_shaders` takes the stage from the archive's frequency for those records. - **Check:** `test_uepak_iostore.py` covers both hash widths, a wrong-width parse that reaches the chunk's end, valid and legacy-position version 12 footers, and untagged records with code or control length mismatches or a copy of the control magic inside shader code. The [PR author](https://github.com/seedds/nxnative/pull/3022) built 6,878 Mac shaders for update 131072. - **Found on:** Godzilla: Destroy All Monsters Melee Remastered (`0100A00026D70000`).