aldelaro5 / GC-pokemon-RNG-manipulation-assistant

A program to aid RTA speedrunners to manipulate the starters in Pokemon Colosseum and Pokemon XD: Gale of Darkness
MIT License
12 stars 8 forks source link

Wrong shiny checking for Gales Seed Searching #10

Open Admiral-Fish opened 4 years ago

Admiral-Fish commented 4 years ago

The TSV value you use for Gales is wrong. Despite the fact that the game generates a TID/SID as you have documented here, the game uses the saves TID/SID. This is the case for both the enemy and your own party.

My starting seed is 0x317f9f7b. The generated values for TID/SID would be 0xc034 and 0xA574. But looking at the registers in dolphin we can see that is not the value being used. For reference register r27 holds the value of TID/SID. For completion r24 is gender, r25 is nature, and r26 is shiny. This gets used in the function at address 80141540. This TID/SID is actually the TID/SID of my save file.

image

The generation here appears to use a random TID/SID (where you advance the 1139 frames). And the generation here appears to use the TID/SID of the save file (the dummy team before the battle menu).

Thurler commented 4 years ago

Since you've mapped out the memory and can check the values for these registers, do you happen to know which value is used when there isn't a save file present? Basically there are two ways to make this consistent after the code is fixed, from what I understand:

Option 1 seems to be the easier fix to this, since there's no real need to have a memory card inserted when running the game. This could also be the cause of issue #5, considering @aldelaro5 did not manage to replicate what was reported by @ryziken, despite following the exact same (meaningful) inputs. This might seem like something that would rarely cause issues, but consider doing 100 rolls, each with 4 pokemon in it, your odds of getting at least one shiny for any given TID/SID would be:

> p = 1/8192.
> 1 - ((1-p)^400)
0.0476

Might seem low, but we speedrun pokemon, 4.7% is to be considered "high odds" for us (for reference, the common 1/16 is 6.25%). :p Either way, this should be further investigated so we can patch it up. I'm sure many runners would be willing to run test cases on real hardware to compare with emulated results, with and without save files.

Admiral-Fish commented 4 years ago

I did 3 trials. I separated the results into the 1st generated PID and every PID that follows. The 1st PID generation uses SID/TID from frame 1001/1002. Every PID that follows uses SID/TID from 2018/2019. I know 3 trials isn't exactly proof of a pattern, but I'd bet this is the case when a save file doesn't exist. The seeds listed are the initial seeds from booting the game.

Seed: 845b7c78
1st PID
SID/TID: e6737680 (1001/1002)

2nd+ PID
SID/TID: 8e8b1672 (2018/2019)

Seed: 86c57798
1st PID
SID/TID: 1e38806f (1001/1002)

2nd+ PID
SID/TID: fca13793 (2018/2019)

Seed: 892f72b8
1st PID
SID/TID: 55fd8a5f (1001/1002)

2nd+ PID
SID/TID: 6ab658b4 (2018/2019)