Skip to content

patch_nso.py: every rewrite stops with a NameError on main (TEXT_LO); the NRO header skip as seedds/nxnative#397 - #59

Merged
LNPANDY merged 1 commit into
LNPANDY:mainfrom
v0lumehi:fix-text-lo
Oct 27, 2026
Merged

LNPANDY merged 1 commit into
LNPANDY:mainfrom
v0lumehi:fix-text-lo

Conversation

@v0lumehi

Copy link
Copy Markdown
Collaborator

Urgent: every rewrite of every game stops on main.

File "dm/tools/patch_nso.py", line 466, in <module>
    starts = sorted(x for x in starts if x < TEXT_LO + TEXT_END)
NameError: name 'TEXT_LO' is not defined. Did you mean: 'TEXT_END'?

I found this by building Hades from the launcher right after it pulled main. 9f7d421's patch_patch_nso adds TEXT_LO to the site bound on line 466, but assigns TEXT_LO = segs[0][1] only on line 479.

The bound itself was also not the fix. An NRO's text segment starts at offset 0, and the header lies inside it. Hades' EOSSDK-Switch-Shipping.nro has text {0x0, 0xa41000}, so segs[0][1] is 0 and the header was still scanned (see #51).

Change

  • patch_patch_nso applies seedds/nxnative#397 instead:

    • code_start() is 0x80 for an NRO and 0 for an NSO;
    • code_ranges() starts no code range before it;
    • TEXT_END keeps its meaning.

    Once Persona 5 Royal: Unstable frame pacing during shader compilation, dropping to ~20 FPS until window focus changes #397 is upstream, the patcher finds every hunk already applied and can be removed.

  • test_nro_header.py tests behaviour now:

    • the header is outside every code range;
    • an NSO's ranges are unchanged;
    • each bound is assigned before the scan uses it, which covers this NameError.
  • PATCHED additions: front_mac.m, patch_nso.py and Hades II's game.tsv had patchers but were missing from PATCHED, so pr-scope would have refused this PR.

Checked

  • Hades' main and sdk rewrite with exit code 0. That is the step that failed.
  • The patcher rebuilds this tree from upstream's patch_nso.py and is idempotent.
  • A sync run with --old = --new ends with SYNC OK.
  • These pass: test_nro_header, test_jump_copies, test_nso_match, test_patches, test_spin_waits, test_tail_call, test_size_prefixed_frames, test_docs, test_env_switches.

…skip as seedds/nxnative#397

9f7d421 restored the NRO header skip (issue LNPANDY#14) as a carrier, and its
patcher put TEXT_LO into the site bound (starts = sorted(... TEXT_LO +
TEXT_END)) 13 lines above TEXT_LO = segs[0][1]. Every rewrite of every
game stopped there: "NameError: name 'TEXT_LO' is not defined", found
building Hades from the launcher after it pulled main.

The bound itself was also not the fix: an NRO's text segment starts at
offset 0 with the header inside it (Hades' EOSSDK-Switch-Shipping.nro:
text {0x0, 0xa41000}), so segs[0][1] is 0 and the header was still
scanned. patch_patch_nso now applies seedds/nxnative#397 instead:
code_start() is 0x80 for an NRO and 0 for an NSO, code_ranges() starts
no code range before it, and TEXT_END keeps its meaning. When LNPANDY#397 is
merged upstream, every hunk is found applied and the patcher can go.

front_mac.m, patch_nso.py and Hades II's game.tsv had patchers but were
not in PATCHED, so pr-scope refused a PR that touches them; they are in.

Checked: Hades' main and sdk rewrite (exit 0, the step that failed);
the patcher reproduces this tree from upstream's patch_nso.py and is
idempotent; a sync run with --old = --new ends SYNC OK.
test_nro_header now tests the behaviour (the header outside every code
range, an NSO unchanged, each bound assigned before the scan uses it);
test_jump_copies, test_nso_match, test_patches, test_spin_waits,
test_tail_call, test_size_prefixed_frames, test_docs and
test_env_switches pass.
@LNPANDY
LNPANDY merged commit e70a849 into LNPANDY:main Oct 27, 2026
7 checks passed
@LNPANDY

LNPANDY commented Oct 27, 2026

Copy link
Copy Markdown
Owner

Merged as e70a8493. You found a bug I shipped and you were right about both halves of it — thank you for catching this before anyone else hit it.

The NameError was mine. 9f7d421's patch_patch_nso put TEXT_LO in the site bound at line 466 and only assigned it at 479, so patch_nso.py died at module load — every rewrite of every game, not just Hades. Worse, my test_nro_header asserted assertIn('TEXT_LO = segs[0][1]', src), a string check that passes whether or not the code runs. That is the second time this week I have treated "the test is green" as evidence without asking what it proves; the first was a test sitting outside its class so XCTest never collected it. Your test_the_bounds_are_defined_before_the_scan_uses_them — comparing SOURCE.index('CODE_START = ') against the first use — is exactly the check I should have written, and I am keeping it.

And you were right that the bound itself was wrong. I assumed an NRO's segs[0][1] pointed at the text; Hades' EOS NRO has text {0x0, 0xa41000}, so it is 0 and the header stayed in the scan. code_start() returning 0x80 for an NRO is the actual fix, and code_ranges() clamping the first gap is the clean way to do it.

Verified on top of today's main (79a8b198):

  • 352 tool tests, 0 failed; sync_upstream.py --old 75065df --new 75065df ends SYNC OK with every patcher agreeing with the tree
  • TEXT_LO appears nowhere in patch_nso.py; CODE_START is assigned at line ~40 and used after
  • I could not run a real NRO through the rewriter — there is none in this tree and I will not fabricate one — so Hades' successful main/sdk rewrite is the evidence, and I am taking it from your report rather than claiming I reproduced it

On the PATCHED gap you mention: you are right, and it is a class of bug worth a check rather than a fix. pr-scope reads OURS and PATCHED from the script; if an entry has a patcher in PATCHERS and a marker in MARKERS but is missing from PATCHED, the carrier still works and pr-scope still refuses it — which is what you hit. I will add a consistency assertion for the three lists agreeing rather than remember it next time.

One process note: send the next one like this, with the failing traceback in the first paragraph. "Every rewrite stops" is what made me look immediately instead of reading the description first.

LNPANDY added a commit that referenced this pull request Oct 27, 2026
PATCHED, MARKERS and PATCHERS describe one set: a vendored file that carries a fork patch, the
string that proves the patch is in place, and the function that re-applies it. A file in PATCHERS
and MARKERS but missing from PATCHED still gets patched on sync — and pr-scope still refuses any
PR that touches it, because pr-scope reads PATCHED to decide what is fork-owned.

v0lumehi hit this with three entries in PR #59 (front_mac.m, patch_nso.py, Hades II's game.tsv):
all three had patchers and markers, none was in PATCHED, so the PR that carried them was refused
for editing vendored files. The tables agree today after his fix; this assertion keeps them that
way instead of relying on someone noticing.
LNPANDY added a commit that referenced this pull request Oct 27, 2026
The update machinery was already here — checkAppUpdate finds the newest release, performAppUpdate
downloads it, swaps the bundle and relaunches — but the only signal was a status line naming a
tag. A user whose app worked had no way to judge whether the new version mattered, so "Update to
v0.4.8" was a leap of faith, and most people took the leap only when something broke.

Now a found update opens a sheet: the version they have, the one on offer, the release notes for
their interface language, Open the release page, Later, and Update now. It opens from the launch
check and from Check for updates, so an old install learns what changed without visiting GitHub.

The notes are the release body, which this project writes in both languages
(docs/RELEASE-NOTES-GUIDE.md). UpdateSheet.lines splits them by the `**中文**` / `**English**`
markers rather than by looking for Han characters — the first version did the latter and handed an
English reader the Chinese paragraph, because that line contains both. A body with no markers is
shown whole instead of being split in half.

Six tests cover the split, including the two cases that failed on the first attempt (a monolingual
body, and inline **bold** inside a marked paragraph). Checked against the real v0.4.7 body: 19 lines
each way, aligned.

appVersion 0.4.7 → 0.4.8: today's merges (#28, #48, #54–#57, #59, #60 and the #52/#53 fixes) were
shipping under a version number that also names the 0.4.7 release, so a bug report could not say
which one it came from.
@v0lumehi
v0lumehi deleted the fix-text-lo branch November 1, 2026 05:10
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