Skip to content

RomFS trailing slash, DM_GAME_ID build break, Rosetta Python, and install on a device from NS Port Builder - #31

Closed
ufooer wants to merge 2 commits into
LNPANDY:mainfrom
ufooer:ios-install-and-fixes
Closed

ufooer wants to merge 2 commits into
LNPANDY:mainfrom
ufooer:ios-install-and-fixes

Conversation

@ufooer

@ufooer ufooer commented Oct 27, 2026

Copy link
Copy Markdown

Four things found while taking Bayonetta 3 and Super Mario Bros. Wonder from NSPs to an iPad mini (A17 Pro) with NS Port Builder on an Apple silicon Mac. One commit each.

1. RomFS archive: a trailing slash names the same directory

Bayonetta 3 never started its opening movie on iOS (both update 1.1.0 and 1.2.0): the game sat on the swirling scene at 60 fps and no movie decoder was ever created. DM_FS=1 showed why, once at boot:

fs opendir not found: @romfsarc:/movie/

The game opens movie/ with a trailing slash. opendir(3) on a plain tree ignores it, so the Mac never saw this; the archive's find_dir compared byte for byte and said the folder did not exist. find_dir now drops trailing slashes (covers romfsarc_is_dir / _list / _count), and t_romfs_arc checks every directory again with a slash appended — the old code fails it for movie/, movie/skilltree/, movie/tutorial/. With the fix the movie plays on the device.

2. iOS app: main.m takes the game ID from the runtime profile

73a89fb moved main.m from game_profile.h to hle_profile.h but left two uses of DM_GAME_ID, so every IPA build currently stops in xcodebuild (use of undeclared identifier 'DM_GAME_ID', main.m:46 and :95). Both read dm_profile()->id now, like the RomFS marker beside them.

3. Build script: stop early under Rosetta

On a Mac with an Intel Homebrew in /usr/local, the first python3 is x86_64. Its children prefer the x86_64 slice, so the shader translator's universal apphost looks for an x86_64 .NET, finds only the arm64 one, prints nothing, and the build stops at the iOS shader step with xlate_source: lock … / actual (empty) — which reads like a stale translator. sysctl.proc_translated is checked up front and the message says what to do.

4. NS Port Builder: native Python, one game per folder, install on a device

  • Native Python. The venv was made from that same x86_64 interpreter. Non-native interpreters are skipped now; a venv made from one is made again from a native one, and the dependency row says why.
  • A ROMs folder with several games. Picking only the base game passed its whole folder, and the script refuses more than one game per folder. The picked files are staged whenever the folder holds other games, together with that game's own update / add-on content found by title ID. ipaPath is now read from the script's output IPA: line, as its comment already said (it stayed empty without an output folder).
  • Install on a connected iPhone / iPad (new scripts/install_ios.py, also usable from a terminal). It signs the IPA with the Mac's own Apple Development certificate — the profile comes from Xcode's automatic signing through a throwaway project, with increased-memory-limit when the team can have it — installs with devicectl, and copies the romfs/ archive into Documents/romfs: only files whose SHA-1 changed, the index last, sizes checked. The save, pso_user.tsv and the launcher's settings are copied to the Mac first and put back if the install emptied the app's data; if the app's data cannot be listed (it happens over Wi-Fi) it stops instead of installing without a backup. App IDs are global, so when org.nxnative.<title ID> already belongs to another team (it did for Mario Wonder), the app is signed as a stable team-specific variant. Nothing about the account is stored but the team picked in the window. The window gets a device / team picker, "after the build, sign and install on …" and Install now.

Tested

  • t_romfs_arc on both games' archives (551 and 19,012 files).
  • iPad mini (A17 Pro), iPadOS 27: Bayonetta 3 1.2.0 — opening movie plays; install script end to end, a re-install that sends nothing, one deliberately mismatched shard resent alone. Super Mario Bros. Wonder v0 from the app: build → automatic install (App ID taken → team variant) → 3.5 GB of game files → boots to the title at 60 fps.
  • swift build -c release for the front end; the iOS app builds with item 2.

🤖 Generated with Claude Code

LNPANDY added a commit that referenced this pull request Oct 27, 2026
…sync-patcher alignment)

- **A trailing slash names the same directory in the RomFS archive** (romfs_arc.c find_dir): Bayonetta 3 opens "movie/" at boot, and the archive's byte-for-byte directory lookup said the folder did not exist — the game sat at the swirling scene and never started its opening movie, iOS only (opendir on a plain tree ignores the slash, which is why the Mac never saw it). find_dir trims trailing slashes; t_romfs_arc now checks every directory again with one appended (the old code fails for movie/, movie/skilltree/, movie/tutorial/). Verified on a fixture archive: all checks passed.
- **The iOS build was broken for every game** (issue #32, PR #31 item 2): 73a89fb moved main.m to hle_profile.h but left two uses of DM_GAME_ID — a macro defined in game_profile.h, which main.m no longer includes. Both read dm_profile()->id now, like the marker beside them.
- **sync_upstream.py's main.m patcher text aligned** with those two uses (the replacement emitted DM_GAME_ID; without this the next sync would have restored the broken build — the same patcher-text drift class as last night's three).

From ufooer's PR #31, items 1 and 2, applied by hand so they could ship now (the PR as a whole conflicts with the launcher merge in ContentView.swift and needs a rebase for its frontend half). The host builds, the archive test passes with the trailing-slash checks, and the patcher consistency holds.
@LNPANDY

LNPANDY commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Excellent report — four real fixes, one commit each, and the install script is a feature I had on the list. Items 1 and 2 are applied now (dec3c372), ahead of your rebase, because item 2 breaks every iOS build that exists today (issue #32 was the same bug, filed independently).

What I verified:

  • The trailing slash (find_dir): confirmed the old code fails movie/ (byte-for-byte directory lookup) and your fix plus the per-directory test pass — I packed a small archive and ran t_romfs_arc: all checks passed with the new trailing-slash assertions.
  • DM_GAME_ID: confirmed both uses in main.m are on the hle_profile.h include path, built the host, and — this one is important to me after last night — aligned sync_upstream.py's main.m patcher text with your change (the replacement emitted the macro; without aligning it, the next daily sync would have restored the broken build). Your issue error: use of undeclared identifier 'DM_GAME_ID' #32 was this exact failure, and your report arrived before anyone else connected it to the runtime-profile merge.

Why I did not take the whole PR as it stands: since your base, the launcher library (#27) landed in ContentView.swift, so the frontend half (item 4) and its Localization.swift rows conflict now — GitHub shows CONFLICTING. Items 1–3 were clean files, so they went in above.

What I would like: a rebase of your branch onto current main (or push the item-4 half separately from the Rosetta check in item 3, which is in build_ipa_from_nsp.py and was also clean). The install script itself I want in as-is: signing with the Mac's own certificate through a throwaway project, SHA-1-diffed archive copies with the index last, the save-backup-before-reinstall behaviour, and the team-variant App ID for org.nxnative.<title ID> collisions — that last one is the kind of detail you only learn from a real device, and the Mario Wonder note says you did. The 🤖 Generated with Claude Code attribution is fine, and I would rather have the tested feature than a hand-typed equivalent.

One thing I will ask when the frontend half comes back: the staging logic that brings the folder's other NSPs along ("a ROMs folder with several games") stages by title ID arithmetic (base + 0x800 the update, base + 0x1000+n add-on content). That matches how dumps name updates, but DLC numbering is not always contiguous — does it hold on your dumps across games, or should it be a prefix match (<base tid> in the name) instead?

An Intel Python (an Intel Homebrew in /usr/local on an Apple silicon Mac)
runs under Rosetta, and its children prefer the x86_64 slice: the shader
translator's universal apphost then wants an x86_64 .NET, finds the arm64
one, prints nothing, and the build stops at the iOS shader step with
"xlate_source: lock … / actual" (empty) and advice to rebuild dmsh_xlate,
which is not the problem. sysctl.proc_translated says so up front now.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Three things a first build on an Apple silicon Mac ran into:

- Python under Rosetta. The venv was made from the first python3 with a
  usable version, which on a Mac with an Intel Homebrew is /usr/local's
  x86_64 one; the shader step then failed (see the build script commit).
  Interpreters that do not run natively are skipped now, and a venv made
  from one is made again from a native one (the row says why).
- A ROMs folder with several games. Picking only the base game passed its
  whole folder to the script, which refuses more than one game per folder.
  The picked files are staged whenever the folder holds other games,
  together with that game's own update / add-on content found by title ID.
  The output IPA's path is read from the script's "output IPA:" line as the
  comment beside ipaPath already said (it stayed empty without an output folder).
- Installing. scripts/install_ios.py signs the IPA with the Mac's Apple
  Development certificate (profile from Xcode's automatic signing through a
  throwaway project, with increased-memory-limit when the team can have it),
  installs it with devicectl and copies the romfs/ archive into
  Documents/romfs, only the files whose SHA-1 changed and the index last.
  The save, the learned pipelines and the launcher's settings are copied to
  the Mac first and put back if the install emptied the app's data; a
  listing that cannot be read stops the install rather than risk the save.
  When org.nxnative.<title ID> already belongs to another team (App IDs are
  global, first come first served), the app is signed as a team-specific
  variant of it. The window gets a device / team picker, "after the build,
  sign and install on …" and Install now.

Tested on an iPad mini (A17 Pro): Bayonetta 3 (install, re-install that sent
nothing, one changed shard resent alone) and Super Mario Bros. Wonder from
the app (build, App ID taken → team variant, 3.5 GB of game files, boots to
the title at 60 fps).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ufooer
ufooer force-pushed the ios-install-and-fixes branch from e2f650c to e2d929b Compare October 27, 2026 08:33
@ufooer

ufooer commented Oct 27, 2026

Copy link
Copy Markdown
Author

Thanks for applying 1 and 2 ahead, and for catching the sync patcher text — I would have missed that one.

Rebased onto current main (ios-install-and-fixes force-pushed): the branch is now items 3 and 4 only, two commits on top of dec3c37.

  • The launcher redesign (nxnative for Mac: a game library around the build #27) replaced the views item 4 hooked into, so the install controls now live on the new Build page as their own group, Install on a device (shown for iPhone / iPad only), in the launcher's group / row / LauncherSwitchStyle look: the auto-install switch, the device picker with Refresh, and a team picker when the Mac has certificates of more than one team. The iPhone outcome group gets an Install now row.
  • Your output IPA: parsing and the chain-change notice are kept as they are; the conflicting line of mine was a duplicate and is gone.
  • The archive step's new cancel handling is kept; the automatic install runs only when the archive succeeded and the build was not stopped. The install process runs in its own group like the build (inOwnGroup / track), so Stop ends devicectl / xcodebuild with it.
  • frontend/README.md: your version, with "This app does not install anything on an iPhone" replaced by a short Install on a device section.

Built with swift build -c release and checked in the running app (the group renders on the Build page, remembers the device and team, hides for This Mac). The install script itself is unchanged from what was tested on the device.

On the DLC staging question: it is a range check, not a walk, so gaps in DLC numbering do not matter. An add-on's title ID is the application's ID + 0x1000 with the add-on index in the low 12 bits, so every add-on of a game lands in [base + 0x1000, base + 0x2000) whatever its index, and the update is base + 0x800. A prefix match on the base ID would miss them: they differ from the base in the fourth hex digit from the end (…B514000 → …B515001), and a looser prefix that does catch them (the first 12 digits) also catches the neighbouring application, since bases are 0x2000 apart. The folder scan in scan(folder:) uses the same rule (tid & 0xFFF). To be precise about what I tested: base + update (Bayonetta 3) and base only (Mario Wonder); I had no add-on content dump to check against, and files without a [title ID] in the name are not brought along.

LNPANDY added a commit that referenced this pull request Oct 27, 2026
An Intel Python (an Intel Homebrew in /usr/local) runs under Rosetta on an Apple silicon Mac,
and its children prefer the x86_64 slice: the shader translator's universal apphost asks for an
x86_64 .NET, finds only the arm64 one, prints nothing, and the build stops at the iOS shader
step with an empty "xlate_source: lock … / actual" — advice that points at the translator when
the problem is the interpreter. One sysctl call turns a mystery into a one-line fix.

ufooer found this on an iPad bring-up (PR #31, item 3). The check is a carrier entry in
sync_upstream.py, because build_ipa_from_nsp.py is a vendored file: added by hand without the
patcher entry, it would have been silently reverted by the next sync, which is exactly how the
NRO header skip was lost earlier today.
@LNPANDY

LNPANDY commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Closing this in favour of #28, which merged as 7c4a1e06 — but not because your work was wrong. Three of your four items are in or recorded, and I want to be specific about each, because the report and the bring-up behind it were good.

What is on main from your PR:

  • Item 1, the RomFS trailing slash — applied by hand in dec3c372 days ago, with t_romfs_arc extended to check every directory with a slash appended. That fix is why Bayonetta 3's opening movie plays.
  • Item 2, the the GAME_ID macro macro (a macro, not an env switch) — same commit. That was breaking every iOS build (main.m:46, :95), and issue error: use of undeclared identifier 'DM_GAME_ID' #32 was the same bug reported independently. Both uses read dm_profile()->id now.
  • Item 3, the Rosetta check — merged today as 75f69c04, taken straight from your commit. I added it as a carrier entry in sync_upstream.py at the same time, because build_ipa_from_nsp.py is vendored and a hand-applied change there gets silently reverted by the next sync. That is not hypothetical: the NRO header skip was lost exactly that way earlier today. Your five lines are unchanged.

What I did not take, and why:

  • The install script (install_ios.py). The maintainer's call, and I agree with it: if a user can build an iOS app at all they have Xcode, and a route that lets xcodebuild do the signing and provisioning is less code to maintain and less to go wrong than a 390-line hand-rolled signing flow with its own App-ID-collision, backup and restore logic. It is a good piece of work — the "copy to the Mac first, put it back if the install emptied the app's data" guard is more careful than most — it is simply the second implementation of a thing that now has a first one.
  • The multi-game folder staging. That is a real gap and still open: I filed The Mac app cannot build from a folder that holds more than one game, and does not say why #58 for it, with your approach written down (stage the picked files by title ID, match update and DLC by ID prefix, say it in the log). It could not come across as-is because it sat in the same commit as the install script, but the idea is not lost. If you want to send it as its own PR against current main, The Mac app cannot build from a folder that holds more than one game, and does not say why #58 is the place to say so and I will review it quickly.
  • Native Python / venv. Same commit. The Rosetta guard now stops the build at the script with a message naming the interpreter, which is the part that mattered; the venv-rebuild half is worth having, and belongs with The Mac app cannot build from a folder that holds more than one game, and does not say why #58 rather than with the installer.

So: one item in already, one merged today, one tracked as #58, one superseded by design. If you have more from that iPad bring-up — and a Mario Wonder build that boots to the title at 60 fps suggests you do — they will be read on their own merits, as this one was.

@LNPANDY LNPANDY closed this Oct 27, 2026
LNPANDY added a commit that referenced this pull request Oct 27, 2026
…ssue #58)

The launcher passed the picked game's whole folder to the script, and the script refuses a
folder with more than one title family ("more than one game in the folder, keep one game per
folder") — so a `~/ROMs` with five games could not build any of them, and nothing said why.

The staging that already existed for "base game and update in different folders" now also
covers "this folder holds other games": the picked files are symlinked into a temporary folder,
and that game's own update and add-on content come along. Siblings are classified exactly as
build_ipa_from_nsp.py:445 does — low 12 bits 0x000 base, 0x800 update, anything else add-on
below the base — so the two cannot disagree about what belongs to which game. The log says when
this happens, so it is not silent magic.

ufooer wrote this in PR #31 and I could not take that commit as-is (it carried the install
script this fork now does through Xcode, and a Rosetta guard that is already on main); the
staging half is applied here, with the classification matching the script's rather than the
approximation in the original.

**Also fixes a test that never ran.** `testLastMeaningfulLineSkipsProgressEventsAndBlankLines`
(issue #52's test, `dc65dbab`) was added *after* LibraryTests' closing brace, so it sat at file
scope and XCTest never collected it: `swift test` reported 32 tests both before and after it
existed, and I read that as "it passed". It is inside the class now, and the count went 32 → 35
with the two new ones. Nothing was wrong with the code it covers, only with my evidence for it.

Swift 35 tests, 0 failures.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants