Admiral-Fish / PokeFinder

Cross platform Pokémon RNG tool
GNU General Public License v3.0
317 stars 78 forks source link

Gen 3 Encounter Slot Modifier Bug Affecting Only New Mauville #396

Closed c-poole closed 5 months ago

c-poole commented 5 months ago

When the lead is set to Static or Magnet Pull, you correctly identify that in the special case where there are no encounter slots matching the relevant type, then the forced type RNG call is skipped in favor of the standard encounter slot roll. If 12 encounter slots happen to be a match for the type, then Emerald will do the same thing but this does not appear to be reflected in PokeFinder code. The only place where this causes a difference in behavior is a static lead in New Mauville where all 12 encounter slots are electric types.

Admiral-Fish commented 5 months ago

https://github.com/Admiral-Fish/PokeFinder/blob/master/Source/Core/Parents/EncounterArea.cpp#L58-L92 https://github.com/pret/pokeemerald/blob/master/src/wild_encounter.c#L915-L934

My implementation matches what the game does. Please provide a specific example with how a pokemon you caught in game does not match what pokefinder generated

c-poole commented 5 months ago

Here is an explicit example: I caught a wild voltorb with Sweet Scent using a static lead in the inner-area of New Mauville.

Level 24 PID 0x789195C8 IVs: 11/2/16/14/9/1

This is a wild H1 encounter which pokefinder says with a static lead can should be either a magnemite or a magneton.

The issue in the implementation is not in the Pokefinder function you highlighted, although technically yours does lack the invalid memory access that Emerald has. Emerald always checks the types of 12 "Encounter slots" even though for Surfing encounters there are only 5. This leads to Emerald also checking the Old Rod and Good Rod encounter slots as well as the types of two glitch species (0x0 and 0x0855). Luckily, none of the Old/Good Rod encounter slots are electric types and neither are either of the glitch species, so this ended up being buggy code that didn't produce bad encounters.

The issue for the difference in behavior between Emerald and Pokefinder is in this line in Pokefinder: https://github.com/Admiral-Fish/PokeFinder/blob/master/Source/Core/Gen3/Generators/WildGenerator3.cpp#L92 which does not capture both of the cases of the if statement in Emerald: https://github.com/pret/pokeemerald/blob/master/src/wild_encounter.c#L929

If 12 encounter slots all match the type to be forced, the game recognizes there is no need to change anything about how its generation works and you get the standard encounter table encounter rates instead of every slot getting an equal shake. The only location this is possible to happen is New Mauville, since no other encounter table has 12 steel types or 12 electric types.

Real96 commented 5 months ago

Yeah the issue is correct: image