Re: Arbitrary code execution in Red/Blue using the "8F" item
Posted by: Torchickens
Date: 2015-08-24 15:13:13
Does anyone know any gameshark code for changing the moves of pokemon IN THE BOX? There's gameshark codes for changing party pokemon moves that can I wanted to try to convert to code exec using Chickasaurus' post info but all I can find is codes for the party, not the box, which is useless since we're forced to use a full predefined party for the bootstrap.
Damn. I overlooked that we wouldn't be able to use the code in Red/Blue (with x115 instead of x114) because of 8F requiring specific party Pokémon (unless you wanted to change your Pidgey, Onix etc's moves). The code works in Yellow, but I didn't think about the party Pokémon problem for Red/Blue, sorry.
The code I made works in Pokémon Yellow with ws m because that requires specific stored Pokémon; so in Yellow you can manipulate the moves of party Pokémon.
The glitch item -g m (hex:6A) in Red/Blue can be used with a stored Pokémon bootstrap code akin Pokémon Yellow, provided there aren't bad values in Safari Balls, Day Care (if you have ever deposited a Pokémon in the Day Care this may not be an option as values stay even after withdrawing). Hence that can be used to alter party Pokémon moves in Red/Blue.
If you cannot find a memory address on DataCrystal, another good two places are the GameShark codes archive (as you know, if you reverse the order of the last two bytes you will get the memory address, e.g. 01??81DA 01??96DA means modify DA81 and DA96) as well as Pokémon Red disassembly.
Firstly Chickasaurus' post I linked in my previous post didn't work for me. Second, it requires a different item ID for each move which is slightly clunky. At first I had the idea of perhaps attempting a .j as a NOP to bring ID parity back and execute the instruction back in item amount instead of ID, but realised I was getting in way over my head since I would have to then figure out how to redirect to the address with another item and do not fully understand ASM instructions.
I'm not sure if you did something wrong if it requires a different item ID. You could use that skeleton to create this code to change stored Pokémon 1:
3E xx
EA 9E DA
C9
Lemonade x(move)
TM34 x158 (or 159 for changing move 2, 160 for move 3, 161 for move 4)
TM18 x209
There may be confusion because the endianness is different for this method (9EDA instead of DA9E)
compared to using the h and l registers (DA in h, 9E in l).
I then went to try and find the memory address with VBA's cheat maker. For reasons completely beyond me the cheat searcher finds the address CA9E as the location instead of DA9E, and obviously the cheat doesn't work. Why this is so baffles me. I'm using a modded VBA called VBA-M, svn926. I'm not sure if it's got a bug with memory offset representation but it lead me to a dead end.
Yeah, it is a bug. When you see a CXXX address in cheat searcher, make sure to try it as DXXX as well.
Have the Pokemon to be altered be the first one in the PC. Have its move to be altered be put in first slot.8F
<any item>
X Accuracy x158 (changing this from 158 for first move to 161 for 4th move SHOULD change the move that's altered, though I have ONLY tested with the first move!)
Carbos x218
Max Revive x<MOVE ID>
Poke Ball x201
Where move ID obviously corresponds to the move's ID.
This will change the first move of the first Pokemon in your active box.
Congratulations on doing this yourself! I see you used l and h. Your code is a little more flexible than the earlier skeleton Wack0 posted for built in GameShark if used as:
X Accuracy x(address byte 2 e.g. 9E)
Carbos x(address byte 1 e.g. DA)
Max Revive x<MOVE ID>
Poke Ball x201
Because the value (move ID) and both address bytes depend on the quantity - you can access every quantity easily (plus 00 if you got the X Accuracy with item underflow because you can have y-block values (following x coordinate) of 00), though you can't edit 00XX as it is in ROM (though you could 'write' 0A to 0000 0A as that opens up SRAM (A000+) for write access, I'm not sure how that works exactly).
Plus, it's a bit messy, but we can use this altered code to set every quantity from item 3-5 to 0 (256, you can toss to get 1-255) upon use if you can force extra stacks of X Accuracy and Carbos and get two Water Stone stacks (by withdrawing two stacks of 99). This lets us change multiple addresses (even if you require a greater quantity) with multiple 8F uses.
X Accuracy x(address byte 2 e.g. 9E)
Carbos x(address byte 1 e.g. DA)
Max Revive x<MOVE ID>
Carbos x 211
X Accuracy x 35
Soda Pop x175
Water Stone x44
Poké Ball x34
Great Ball x44
Water Stone (or PP Up if you don't want two Water Stone stacks) x201
ASM for the footer (set item 3-5 quantities to 0):
ld h,D3
ld l,23
dec a
xor a
ldi (hl),a
inc l
inc b
ldi (hl),a
inc bc
inc l
ldd (hl),a