Skip to content

NRO loading (nn::ro) for every game, refusing online SDKs such as Epic Online Services - #91

Closed
v0lumehi wants to merge 3 commits into
seedds:mainfrom
v0lumehi:nro-loading
Closed

v0lumehi wants to merge 3 commits into
seedds:mainfrom
v0lumehi:nro-loading

Conversation

@v0lumehi

Copy link
Copy Markdown
Contributor

This came up while bringing up Super Smash Bros. Ultimate (#65): its fighter code lives in 98 NROs inside data.arc. The feature itself works for every game.

What it does

  • Pack time: dm/tools/nro_collect.py collects the NROs a game's NRR files register, by SHA-256.
    • It takes loose files, or the current file of each path in an indexed archive. For Smash that is data.arc, read through the new dm/gfx/tools/smash_arc.py.
    • The older releases' NRRs also register 666 superseded copies that are still in the archive. Those are left out.
    • patch_nso.py now reads NROs. The NSP script's rewrite step collects them and rewrites them together with the profile's modules, in parallel, and writes nro.tsv beside them. For Smash that is 101 modules in 1:45, reused on later runs.
  • Host (nn::ro):
    • The NROs in nro.tsv are mapped at start but stay out of symbol lookups and the startup init.
    • LoadModule finds a module by its SHA-256, relocates it against the modules loaded before it, binds the earlier modules' imports it defines, fills nn::ro::Module as the SDK does and calls DT_INIT.
    • UnloadModule calls DT_FINI and points those imports back at their stubs.
    • GetBufferSize, RegisterModuleInfo and LookupModuleSymbol behave as in the SDK.
    • Only data is written at load time, so the same scheme can work once the NROs are embedded in the iOS executable. gen_embed.py does not embed them yet; that is the next step for Smash.
  • DM_NRO=0 turns NRO loading off.

Online SDKs are refused

Hades and Hades II ship Epic Online Services as an NRO (rom:/nro/EOSSDK-Switch-Shipping.nro). Hades' main imports only EOS Auth, Connect and PlayerDataStorage, which is Epic-account cross-save. The host can't serve that. Running the real SDK would at best fail its login, and at worst wait on time-outs or contact Epic's servers with a console identity the host makes up. We don't know whether that could get an account banned.

So an NRO that exports EOS_Platform_Create is never packed or loaded, and an NRR that registers only such modules fails RegisterModuleInfo, as every registration did before. Hades then behaves exactly as before: offline, with local saves. The check goes by what the module contains, not by title ID.

Question for you: how would you like NRO loading and online SDKs handled? Options:

  • always load everything;
  • refuse online SDKs, as this PR does;
  • decide per profile.

Checked

  • Smash 13.0.5 on the Mac:
    • It registers its NRR (98 hashes) and loads NROs as it needs them. Each one is relocated, bound and initialised, and no stub is called.
    • With the rest of the bring-up it reaches the title, the menus and a match.
    • The Smash profile itself comes in a later PR.
  • Hades 1.0.38233: the EOS registration is refused with one log line, the game never asks for the module, and it renders past frame 1,500 as before, with one red line fewer.
  • This branch: dm/tools/tests pass, and the Mac host builds.

…ghter code is 98 NROs inside data.arc, whose exports main imports (1,045 lua2cpp::create_agent_* functions, global, bound to stubs at start), and the host loaded none. The SDK's own LoadModule (SDK 8.2.1 LoadModuleInternal, sdk+0x347460) uses ldr:ro only to map the image and then relocates through rtld's module lists, which the host replaces, so the host takes over the whole call. Pack time: dm/tools/nro_collect.py collects the NROs a game's NRR files register by SHA-256 (loose files; the current files of an indexed archive, Smash's data.arc through the new dm/gfx/tools/smash_arc.py, which reads its file-system table: 98 NROs in 7 s, while the older releases' NRRs also register 666 superseded copies the archive still holds, left out; else a scan for stored and zstd-framed NROs, all 764 in 7 min); patch_nso.py now reads NROs (the flat image, segments at +0x20, build ID at +0x40); the NSP script's rewrite step collects them (its own reuse key) and rewrites them with the profile's modules, as many at once as the Mac has cores, with nro.tsv beside them (Smash: 101 modules in 1:45, reused on the second run). Host: MAX_MOD 128; the NROs of nro.tsv are mapped at start (code read-only + execute) and stay out of symbol lookups and the startup init pass; LoadModule finds one by the image's SHA-256, restores its data and bss after the first load, relocates it against the modules loaded then in load order, binds the earlier modules' symbol relocations it defines (bind_sym, the binding step of relocate factored out), fills nn::ro::Module as the SDK does and calls its DT_INIT; UnloadModule calls DT_FINI and binds every relocation that pointed into it again; GetBufferSize returns the header's bss size as the SDK does; RegisterModuleInfo accepts the NRR; LookupModuleSymbol searches the one module; an NRO does not count as used memory. Only data is written at a load, so the same works once the NROs are embedded in the iOS executable (gen_embed.py takes only the profile's modules so far). DM_NRO=0 turns loading off: Hades and Hades II load their EOS SDK NRO, which the host refused so far (they play offline); a repack that finds it through NRRs now runs it, not checked without their files. Smash 13.0.5 on the Mac: the game registers its NRR (98 hashes) and loads six NROs in its first 30 s, each relocated, bound into the modules loaded before it (2, 1, then 11 imports each) and initialised, with no stub called and the frame loop at 60 fps. docs/agents/03-bringup.md has the NRO case. dm/tools/tests pass
… Services, known by its export EOS_Platform_Create. Hades and Hades II load rom:/nro/EOSSDK-Switch-Shipping.nro; Hades' main imports only EOS Auth, Connect and PlayerDataStorage (Epic-account cross-save), which the host cannot serve, and the real SDK would at best fail its login and at worst wait on time-outs or contact Epic's servers with a console identity the host makes up (whether that could get an account banned is unknown). Before the host loaded NROs both games played offline with local saves, and they do again. dm/tools/nro_collect.py (ONLINE_SDKS) does not write such an NRO and lists it in nro.tsv as a "refused" row, so the pack carries no code for it; the NSP script rewrites only the other rows; the host reads the refused hashes (nro_refused) and ro::LoadModule refuses them with one log line ("refused …: an online SDK (Epic Online Services), not loaded; the game plays offline"), and refuses by the export too when an older nro.tsv lists the module. DM_NRO=0 still turns all NRO loading off. Checked on Smash's NROs: none is refused, and a module with a listed export is. Not checked on Hades or Hades II (no game files here). docs/agents/03-bringup.md notes it; the PR asks the maintainer: always load, refuse online SDKs (as now) or decide per profile
…fails RegisterModuleInfo, as every registration did before the host loaded NROs, so the game takes the path it took then. Hades 1.0.38233 (game.nrr with the one EOS SDK hash; the NSP script's rewrite step now collects it as a refused row): the registration is refused with one log line, the game never asks for the module, and it renders on past frame 1,500 as before, one red line fewer (the old RegisterModuleInfo one). Checked with a test rewrite, host and empty save in a folder of its build folder, removed afterwards; its patched modules, IPA, saves and shader caches untouched
seedds added a commit that referenced this pull request Oct 24, 2026
Integrate PRs #75, #90 and #91 with focused correctness fixes:
- Prioritize demanded render pipelines and bound speculative compilation.
- Follow copied jump-table bases and reject W/X register clobbers.
- Collect and rewrite registered NROs, load them on the Mac, and preserve
  runtime activation order through unload/reload and symbol rebinding.
- Preserve refused-only manifests and invalidate collection caches when
  archive readers or symbol parsing change.

Add pipeline scheduling, register tracing, NRO packaging and loader
lifecycle regression coverage. Document that executable NRO embedding
on iOS remains outside this integration.

Validation: 41 Python tests; 48 pipeline scheduling, 102 NVN and 95
geometry checks; three pipeline-key serialization cases; full host test
suite; Mac host build; iOS loader syntax checks; git diff --check.
Gameplay and controlled performance A/B measurements were not run.

Co-authored-by: blindlight86 <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
@seedds

seedds commented Oct 24, 2026

Copy link
Copy Markdown
Owner

Integrated into main in d979c34, with coauthor attribution. Thanks for the contribution.

The integration includes additional fixes for runtime activation order in symbol lookup, synchronization of global lookups with module activation, preservation of refused-only manifests, and collection-cache invalidation when archive readers or symbol parsing change.

Added synthetic loader coverage for reversed load order, unload/reload, rebinding, weak symbols, init/fini, data reset, and online-SDK refusal, plus packaging-cache regression tests. All 41 Python tools tests, the full host test suite, the Mac host build, and iOS syntax checks for the changed loader files passed.

Executable NRO embedding on iOS remains unimplemented and is tracked separately in #94. No new gameplay validation was performed during this integration. Closing as integrated.

@seedds seedds closed this Oct 24, 2026
@v0lumehi
v0lumehi deleted the nro-loading branch October 24, 2026 07:53
Know-It-All-Brother pushed a commit to Know-It-All-Brother/nxnative that referenced this pull request Nov 9, 2026
Integrate PRs seedds#75, seedds#90 and seedds#91 with focused correctness fixes:
- Prioritize demanded render pipelines and bound speculative compilation.
- Follow copied jump-table bases and reject W/X register clobbers.
- Collect and rewrite registered NROs, load them on the Mac, and preserve
  runtime activation order through unload/reload and symbol rebinding.
- Preserve refused-only manifests and invalidate collection caches when
  archive readers or symbol parsing change.

Add pipeline scheduling, register tracing, NRO packaging and loader
lifecycle regression coverage. Document that executable NRO embedding
on iOS remains outside this integration.

Validation: 41 Python tests; 48 pipeline scheduling, 102 NVN and 95
geometry checks; three pipeline-key serialization cases; full host test
suite; Mac host build; iOS loader syntax checks; git diff --check.
Gameplay and controlled performance A/B measurements were not run.

Co-authored-by: blindlight86 <[email protected]>
Co-authored-by: v0lumehi <[email protected]>
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