Skip to content

Read Soul Gold natures and EVs as the game does - #21

Merged
DankMiimer merged 1 commit into
linuxfrom
fix/soulgold-stats
Nov 16, 2026
Merged

DankMiimer merged 1 commit into
linuxfrom
fix/soulgold-stats

Conversation

@DankMiimer

Copy link
Copy Markdown
Owner

Upstream sofianeelhor#80 reports that Soul Gold (the GBA ROM hack) edits gain EVs on every save. The Linux port runs the same Soul Gold engine, so I checked it on a real Soul Gold save (BX19 layout, 19 boxes), read-only copied from a reference handheld.

What was wrong

After any party edit, the engine recomputes the party member's stats. On the real save, the recomputed stats differed from the game's own for 3 of 5 Pokémon. Three errors in PKForge.Engine/SoulGold:

  1. Nature (SoulGoldMon.Nature): the hidden-nature modifier was read as the nature itself. As in pokeemerald-expansion, the nature is the PID's nature XOR the modifier. Every modifier on the save is 0, and the game's stored stats follow PID % 25 (Quiet, Docile, Naive, Quirky, Jolly). Every Pokémon without a mint showed as Hardy. Writes now store the XOR, so the PID (shininess, identity) never changes.
  2. Nature boost (SoulGoldData.ComputeStats): natures number their stats Atk, Def, Spe, SpA, SpD; the formula used the app's order, so a Speed nature raised Sp. Atk.
  3. EV order (SoulGoldMon.Evs): EVs were read with the write permutation, so Spe's EVs showed as SpD, SpA's as Spe and SpD's as SpA. Maxing a stat that showed as 0 added EVs to another one, which matches "every time I hit save it adds more EVs".

With the fixes, every recomputed stat on that save equals the game's. Every other engine (Unbound, CFRU, Expansion, FireRed hacks, Elite Redux, Origin HeartGold) was checked for the same three patterns; none has them.

Tests

  • SoulGoldStatTests (no save needed, each fails on the old code): the nature XOR rule, including a mint that keeps the PID; EV order in both storage layouts; the nature boost on the right stat.
  • A real-save check runs on any soulgold*.sav in .local-testdata/romhacks (gitignored) and skips without one: it compares recomputed party stats with the game's.
  • All suites: 3,459 pass (Engine 1,746, 5 new).

Not covered

  • A Soul Gold 1.2.1 (BX21) save, the version Soul Gold Save won’t work sofianeelhor/PKForge#80 reports. Its "boxes empty apart from a shiny Torchic" symptom may have another cause. The BX21 layout is still only synthesized from the hack's source.
  • Loading an edited save in the game itself; the evidence is that recomputed stats now match the game's own.
  • The older Soul Gold tests assert one owner's save and still skip without it, as do many ROM-hack tests in CI. That's worth a separate look.

🤖 Generated with Claude Code

Upstream sofianeelhor#80 reports Soul Gold edits gaining EVs on every save. On a real
Soul Gold save (BX19), the stats PKForge recomputed after any party edit
differed from the game's own for 3 of 5 Pokemon. Three errors in the Soul
Gold engine:

- The hidden-nature modifier was read as the nature itself. As in
  pokeemerald-expansion, the nature is the PID's XOR the modifier: every
  modifier on the save is 0 and the game's stats follow PID % 25. Every
  Pokemon without a mint showed as Hardy. Writes now store the XOR, so the
  PID never changes.
- Natures number their stats Atk, Def, Spe, SpA, SpD; the stat formula used
  the app's order, so a Speed nature raised Sp. Atk.
- EVs were read with the write permutation: Spe's EVs showed as SpD, SpA's
  as Spe and SpD's as SpA, so re-maxing a stat added EVs elsewhere.

With the fixes every recomputed stat on that save equals the game's. Tests:
the nature rule, EV order in both storage layouts and the nature boost need
no save; a real-save check (any soulgold*.sav in .local-testdata/romhacks)
compares recomputed stats with the game's.

Not covered: a Soul Gold 1.2.1 (BX21) save, the version sofianeelhor#80 reports, whose
empty-boxes symptom may have another cause.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DankMiimer
DankMiimer merged commit 32a8548 into linux Nov 16, 2026
6 checks passed
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.

1 participant