Mercurial > vba-clojure
view org/tas-submission.txt @ 620:1b52b14868d3 tip
merge.
author | rlm <rlm@aurellem.org> |
---|---|
date | Sun, 07 Feb 2016 23:16:04 -0800 |
parents | b531d490859c |
children |
line wrap: on
line source
1 Pokemon Yellow Total Control Hack. Reprogramming the game from the inside!3 !! Game objectives5 * Emulator used: vba-rerecording 23.56 * Reprogram the Game from the inside8 !! Comments10 I've included a detailed writeup here:11 http://aurellem.org/vba-clojure/html/total-control.html13 There is a video at:14 http://www.youtube.com/watch?v=p5T81yHkHtI with keypress visualizations16 The following are the highlights:18 ! Introduction20 Think of pokemon yellow as creating a little universe with certain21 rules. Inside that universe, you can buy items, defeat rival trainers,22 and raise your pokemon. But within that universe, you are bound by the23 rules of pokemon. You can't build new buildings, or change the music,24 or change your clothes.. There are some games (like chess), where it25 is not possible to alter the rules of the game from within the26 game. No matter what moves you make in chess, you can never change the27 rules of the game so that it becomes checkers or basketball. The point28 of this run is to show that you CAN change the rules in pokemon29 yellow. There is a certain sequence of valid actions (like walking30 from one place to another or buying items) that will allow you to31 transform pokemon yellow into Pacman, or Tetris, or Pong, or a MIDI32 player, or anything else you can imagine.35 ! Background37 The speedrun (http://tasvideos.org/2913S.html) by Felipe Lopes de38 Freitas (p4wn3r), beats pokemon yellow in only 1 minute and 3639 seconds. It does it by corrupting the in-game item list so that he can40 advance the list past its normal limit of 20 items. The memory41 immediately after the item list includes the warp points for the42 current map, and by treating that data as items and switching and43 dropping them, he can make the door from his house take him directly44 to the end of the game.46 When I first saw that speedrun, I was amazed at how fast pokemon47 yellow could be beaten, and that it was possible to manipulate the48 game from the inside, using only the item list. I wondered how far I49 could extend the techniques found in p4wn3r's run.51 The gameboy is an 8 bit computer. That means that ultimately, anything52 that happens in pokemon is a result of the gameboy's CPU reading a53 stream of 8 bit numbers and doing whatever those numbers mean. For54 example, in the gameboy, the numbers:56 62 16 37 224 47 240 37 230 15 5558 mean to check which buttons are currently pressed and copy that result59 into the "A" register. With enough numbers, you can spell out an60 interactive program that reads input from the buttons and allows you61 to write any program you want to the gameboy. Once you have assembled62 such a program and forced the game to run it, you have won, since you63 can use that program to write any other program (like Tetris or64 Pacman) over pokemon yellow's code. I call a program that allows you65 to write any other program a "bootstrapping program". So, the goal is66 to somehow get a bootstrapping program into pokemon yellow and then67 force yellow to run that program instead of its own.69 How can we spell out such a program? Everything in the game is70 ultimately numbers, including all items, pokemon, levels, etc. In71 particular, the item list looks like:74 item-one-id (0-255)75 item-one-quantity (0-255)76 item-two-id (0-255)77 item-two-quantity (0-255)78 .79 .80 .83 Let's consider the button measuring program [37 62 16 37 224 37 24084 37 230 15 55] from before. Interpreted as items and item quantities, it is86 lemonade x1687 guard spec. x22488 leaf stone x24089 guard spec. x23090 parlyz heal x5592 So, if we can get the right items in the right quantities, we can93 spell out a bootstrapping program. Likewise, when writing the94 bootstrapping program, we must be careful to only use numbers that are95 also valid items and quantities. This is hard because there aren't96 many different items to work with, and many machine instructions97 actually take 2 or even 3 numbers in a row, which severely restricts98 the types of items you can use. I ended up needing about 92 numbers to99 implement a bootstrap program. Half of those numbers were elaborate100 ways of doing nothing and were just there so that the entire program101 was also a valid item list.103 The final part of the hack is getting pokemon yellow to execute the104 new program after it has been assembled with items. Fortunately,105 pokemon keeps a number called a function pointer within easy reach of106 the corrupted item list. This function pointer is the starting point107 (address) of a program which the game runs every so often to check for108 poison and do general maintenance. By shifting an item over this109 function pointer, I can rewrite that address to point to the110 bootstrapping program, and make the game execute it. Without this111 function pointer, it would not be possible to take over the game.113 !! The Run115 ! Pallet117 I start off and name my rival Lp/k. These characters will eventually be118 treated as items and shifted over the function pointer, causing it to119 execute the bootstrapping program that will soon be constructed. I120 start the run the same as p4wn3r's and restart the game while saving,121 so that the pokemon list is corrupted. By switching the 8th and 10th122 pokemon, I corrupt the item list and can now scroll down past the 20th123 item. I shift items around to increase the text speed to maximum and124 rewrite the warp point of my house to Celadon Dept. Store. (p4wn3r125 used this to go directly to the hall of fame and win the game in his126 run.) I deposit many 0x00 glitch items into the PC from my corrupted127 inventory for later use. Then, I withdraw the potion from the128 PC. This repairs my item list by overflowing the item counter from129 0xFF back to 0x00, though the potion is obliterated in the process. I130 then take 255 glitch items with ID 0x00 from the computer into my131 personal items.133 ! Celadon Dept. Store135 Leaving my house takes me directly to Celadon Dept. store, where I136 sell two 0x00 items for 414925 each, giving myself essentially max137 money. I hit every floor of the department store, gathering the138 following items:140 +-------------------+----------+141 |##| Item | Quantity |142 +--+----------------+----------+143 |1 | TM02 | 98 |144 |2 | TM37 | 71 |145 |3 | TM05 | 1 |146 |4 | TM09 | 1 |147 |5 | burn-heal | 12 |148 |6 | ice-heal | 55 |149 |7 | parlyz-heal | 99 |150 |8 | parlyz-heal | 55 |151 |9 | TM18 | 1 |152 |10| fire-stone | 23 |153 |11| water-stone | 29 |154 |12| x-accuracy | 58 |155 |13| guard-spec | 99 |156 |14| guard-spec | 24 |157 |15| lemonade | 16 |158 |16| TM13 | 1 |159 +--+----------------+----------+162 After gathering these items, I deposit them in the appropriate order163 into the item PC to spell out my bootstrapping program. Writing a full164 bootstrap program in one go using only items turned out to be too165 hard, so I split the process up into three parts. The program that I166 actually construct using items is very limited. It reads only from the167 A, B, start, and select buttons, and writes 4 bits each frame starting168 at a fixed point in memory. After it writes 200 or so bytes, it jumps169 directly to what it just wrote. In my run, I use this program to write170 another bootstrapping program that can write any number of bytes to171 any location in memory, and then jump to any location in memory. This172 new program also can write 8 bits per frame by using all the173 buttons. Using this new bootstrap program, I write a final174 bootstrapping program that does everything the previous bootstrapping175 program does except it also displays the bytes it is writing to memory176 on the screen.178 ! Finale180 After completing this bootstrapping program, I go to the Celadon181 mansion, because I find the metaness of that building to be182 sufficiently high to serve as an exit point for the pokemon183 universe. I corrupt my item list again by switching corrupted pokemon,184 scroll down to my rival's name and discard until it is equal to the185 address of my bootstrapping program, and then swap it with the186 function pointer. Once the menu is closed, the bootstrapping program187 takes over, and I write the payload....189 !! Other comments191 The entire video was played by the computer using bots. I used192 functional programming to write search programs over different193 possible game states to find the most efficient way of performing194 general actions. Some interesting things I developed but didn't use195 were pretty printing functions to display the game's internal data196 structures, and an "improbability drive" that forces improbable events197 to happen automatically using search.199 Here are a few example scripts:202 (defn-memo viridian-store->oaks-lab203 ([] (viridian-store->oaks-lab204 (get-oaks-parcel) ) )205 ([ script \]206 (->> script207 (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓208 ← ← ← ← ← ← ← ← ←209 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓210 ← ←211 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓212 ↓ ↓ ↓ ↓ ↓ ↓ ↓213 → → → → → → → →214 ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓215 ← ← ← ← ←216 ↓ ↓ ↓ ↓217 ])218 (walk-thru-grass219 [↓ ↓ ↓ ↓ ↓ ↓ ↓])220 (walk [↓ ↓ ← ↓ ↓ ↓ ←221 ↓ ↓ ↓ ↓ ↓ ↓222 → → → ↑])224 (do-nothing 1) ) ) )227 This script walks from the Viridian City pokemon store to Oak's228 Lab in the most efficient way possible. The walk-thru-grass function229 guarantees that no wild battles will happen by manipulating the game's230 random number generator.233 (defn-memo hacking-10234 ([] (hacking-10 (hacking-9) ) )235 ([ script \]236 (->> script237 begin-deposit238 (deposit-held-item 17 230)239 (deposit-held-item-named :parlyz-heal 55)240 (deposit-held-item 14 178)241 (deposit-held-item-named :water-stone 29)242 (deposit-held-item 14 32)243 (deposit-held-item-named :TM18 1)244 (deposit-held-item 13 1)245 (deposit-held-item 13 191)246 (deposit-held-item-named :TM02 98)247 (deposit-held-item-named :TM09 1)248 close-menu) ) )251 This script calculates the fastest sequence of key presses to deposit252 the requested items into a PC, assuming that the character starts out253 in front of a computer.255 !! Other Comments257 The final payload program is multiple programs. I created a reduced258 form of MIDI and implemented it in gameboy machine language. Then I259 translated a midi file from http://www.everyponysings.com/ into this260 reduced MIDI language. The payload program contains both the music261 data and the MIDI interpreter to play that data. The picture works in262 a similar way. There is code to translate a png file into a form that263 can be displayed on a gameboy, and other code to actually display that264 image. Both the image and the display code are also written by the265 final bootstrapping program. Even though my final payload is rather266 simple, you can write any program at all as the payload. The source267 for the sound and image displaying code is at268 http://hg.bortreb.com/vba-clojure.270 This entire project is open source and I encourage anyone who wants to271 take the code and play around!274 !! Suggested Screenshots276 * http://aurellem.org/pokemon-hack/code.png277 * http://aurellem.org/pokemon-hack/code2.png278 * http://aurellem.org/pokemon-hack/matrix.png279 * http://aurellem.org/pokemon-hack/matrix2.png280 * http://aurellem.org/pokemon-hack/pinkie-pie.png282 Or whatever you all think would be best.284 I encoded the video with/without button visualization here:286 * http://aurellem.org/pokemon-hack/rlm-yellow-hack.avi287 * http://aurellem.org/pokemon-hack/rlm-yellow-hack-no-buttons.avi