Repository navigation
Read Soul Gold natures and EVs as the game does - #21
Merged
Merged
Conversation
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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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: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.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.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.soulgold*.savin.local-testdata/romhacks(gitignored) and skips without one: it compares recomputed party stats with the game's.Not covered
🤖 Generated with Claude Code