Fix gen1 bug reported by /u/imranFZakhaev

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.
This commit is contained in:
risingPhil 2024-07-26 21:49:39 +02:00
parent 8e569b9141
commit 5b85c04b5a
2 changed files with 2 additions and 0 deletions

View File

@ -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);

View File

@ -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())