From 5b85c04b5af56770f1ffd357b6bc4bc2f5fb61d9 Mon Sep 17 00:00:00 2001 From: risingPhil Date: Fri, 26 Jul 2024 21:49:39 +0200 Subject: [PATCH] Fix gen1 bug reported by /u/imranFZakhaev MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When adding a pokémon to a save with a full party, the behaviour is completely broken. Not only did we add a pokémon to every box, but it also would be a completely different one or even crash the game when trying to access the box. Fixes: - Stop after adding a pokemon to a box. Don't add it to all. - In commit 77d5d15 I added a ::setPokemon function and reworked the Gen1Box::add() function to use it. That's where it went wrong: in the add() function, we would modify the number_of_pokemon counter of the box, but not manipulate the species list and write it. Then in the setPokemon() function, we would read the box metadata and correct it because the number did not match the species list. This is what went wrong. To fix it, I just had to modify the species list in the add() function as well again. --- src/gen1/Gen1GameReader.cpp | 1 + src/gen1/Gen1PlayerPokemonStorage.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/src/gen1/Gen1GameReader.cpp b/src/gen1/Gen1GameReader.cpp index 8cec5f7..9cd405b 100644 --- a/src/gen1/Gen1GameReader.cpp +++ b/src/gen1/Gen1GameReader.cpp @@ -455,6 +455,7 @@ uint8_t Gen1GameReader::addPokemon(Gen1TrainerPokemon& poke, const char* origina result = i; updateWholeBoxBankChecksum(getGen1BoxBankIndex(i, currentBoxIndex)); + break; } } setPokedexFlag(PokedexFlag::POKEDEX_SEEN, pokedexNumber); diff --git a/src/gen1/Gen1PlayerPokemonStorage.cpp b/src/gen1/Gen1PlayerPokemonStorage.cpp index 3ea1f1e..b603533 100644 --- a/src/gen1/Gen1PlayerPokemonStorage.cpp +++ b/src/gen1/Gen1PlayerPokemonStorage.cpp @@ -539,6 +539,7 @@ bool Gen1Box::add(Gen1TrainerPokemon& poke, const char* originalTrainerID, const return false; } + boxMeta.species_index_list[index] = poke.poke_index; ++boxMeta.number_of_pokemon; if(boxMeta.number_of_pokemon != getMaxNumberOfPokemon())