Hunting a "Gift Pokemon" Script in Pokémon Crystal
Posted by: Arkazra
Date: 2018-03-12 23:33:35
Now I've moved on to Pokémon Crystal, and I've been analyzing the ROM/RAM contents in and around the Eevee and Dratini gifts, looking for a similar gift script. I've tracked down where in memory the species and level of the gifts are loaded from, but I'm struggling to find where the code actually gives you the Pokémon.
At the end of the conversations that give you the gift, (Eevee and Dratini at least, the Shuckle seem's to do things differently), the code somehow manoeuvers its way to $7932 (in Bank 25)
$7932 contains "call 26D4". $26D4 has a series of instructions I haven't entirely deduced the purpose of, apart from a few, which notably include:
[li]$26D9 loads register a with the value at $D439, which is the ROM bank containing the gift pokemon infomation (Bank 15 for Eevee, Bank 63 for Dratini)[/li]
[li]$26DD loads register hl with the value at $D43A, which is the address containing the species of the gift pokemon (15:4C06 for Eevee, 63:51D7 for Dratini)[/li]
[li]$26E3 loads that species value into register a[/li]
After returning from the call 26D4, the code continues at $7935, by putting species value currently stored in register a into RAM at $D108.
This is followed by another call 26D4, but this time the value returned in register a is the gift Pokémon's level, which is put into RAM at $D143.
A third call 26D4 retrieves the held item of the gift pokemon, putting it into RAM at $D106.
After all this, the pc is at 7944, the Pokémon's species, level and held item are all in RAM at D108, D143 and D106 respectively, but I lose track of things from there, and can't follow the thread to actually getting the Pokémon. I've almost given up hope of finding a simple script as there was in gen 1, but does anyone have any ideas about how to progress forward? (Or in this case, backward?) It's easy enough work forward through the code (I'm using the debugger on BGB to step through it line by line), but I'm struggling to find how the code reaches $7932 in the first place.
My next step is probably going to be manually setting D108, D143 and D106 and jumping to $7944, just to see what happens, but I thought I'd bring it up here and see if anyone else has been tinkering in this area of the code :)