Sonic and Sega Retro Message Board: Hacking Pokemon Yellow using Pokemon Yellow - Sonic and Sega Retro Message Board

Jump to content

Hey there, Guest!  (Log In · Register) Help
  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

Hacking Pokemon Yellow using Pokemon Yellow Pikaception

#1 User is offline Metal Knuckles 

Posted 28 November 2012 - 06:46 PM

  • HAVE SOME FUN WITH MIKU
  • Posts: 4371
  • Joined: 22-February 06
  • Gender:Male
  • Location:New Hampshire, USA
  • Project:Shadow Alpha, an awesome hack of Sonic 1
  • Wiki edits:10
source

Quote



Introduction

Think of pokemon yellow as creating a little universe with certain rules. Inside that universe, you can buy items, defeat rival trainers, and raise your pokemon. But within that universe, you are bound by the rules of pokemon. You can't build new buildings, or change the music, or change your clothes.. There are some games (like chess), where it is not possible to alter the rules of the game from within the game. No matter what moves you make in chess, you can never change the rules of the game so that it becomes checkers or basketball. The point of this run is to show that you CAN change the rules in pokemon yellow. There is a certain sequence of valid actions (like walking from one place to another or buying items) that will allow you to transform pokemon yellow into Pacman, or Tetris, or Pong, or a MIDI player, or anything else you can imagine.

Background

The speedrun (http://tasvideos.org/2913S.html) by Felipe Lopes de Freitas (p4wn3r), beats pokemon yellow in only 1 minute and 36 seconds. It does it by corrupting the in-game item list so that he can advance the list past its normal limit of 20 items. The memory immediately after the item list includes the warp points for the current map, and by treating that data as items and switching and dropping them, he can make the door from his house take him directly to the end of the game.

When I first saw that speedrun, I was amazed at how fast pokemon yellow could be beaten, and that it was possible to manipulate the game from the inside, using only the item list. I wondered how far I could extend the techniques found in p4wn3r's run.

The gameboy is an 8 bit computer. That means that ultimately, anything that happens in pokemon is a result of the gameboy's CPU reading a stream of 8 bit numbers and doing whatever those numbers mean. For example, in the gameboy, the numbers:

62 16 37 224 47 240 37 230 15 55

mean to check which buttons are currently pressed and copy that result into the "A" register. With enough numbers, you can spell out an interactive program that reads input from the buttons and allows you to write any program you want to the gameboy. Once you have assembled such a program and forced the game to run it, you have won, since you can use that program to write any other program (like Tetris or Pacman) over pokemon yellow's code. I call a program that allows you to write any other program a "bootstrapping program". So, the goal is to somehow get a bootstrapping program into pokemon yellow and then force yellow to run that program instead of its own.

How can we spell out such a program? Everything in the game is ultimately numbers, including all items, pokemon, levels, etc. In particular, the item list looks like:

item-one-id (0-255)
item-one-quantity (0-255)
item-two-id (0-255)
item-two-quantity (0-255)
.
.
.

Let's consider the button measuring program [37 62 16 37 224 37 240 37 230 15 55] from before. Interpreted as items and item quantities, it is

lemonade x16
guard spec. x224
leaf stone x240
guard spec. x230
parlyz heal x55

So, if we can get the right items in the right quantities, we can spell out a bootstrapping program. Likewise, when writing the bootstrapping program, we must be careful to only use numbers that are also valid items and quantities. This is hard because there aren't many different items to work with, and many machine instructions actually take 2 or even 3 numbers in a row, which severely restricts the types of items you can use. I ended up needing about 92 numbers to implement a bootstrap program. Half of those numbers were elaborate ways of doing nothing and were just there so that the entire program was also a valid item list.

The final part of the hack is getting pokemon yellow to execute the new program after it has been assembled with items. Fortunately, pokemon keeps a number called a function pointer within easy reach of the corrupted item list. This function pointer is the starting point (address) of a program which the game runs every so often to check for poison and do general maintenance. By shifting an item over this function pointer, I can rewrite that address to point to the bootstrapping program, and make the game execute it. Without this function pointer, it would not be possible to take over the game.

The Run

Pallet


I start off and name my rival Lp/k. These characters will eventually be treated as items and shifted over the function pointer, causing it to execute the bootstrapping program that will soon be constructed. I start the run the same as p4wn3r's and restart the game while saving, so that the pokemon list is corrupted. By switching the 8th and 10th pokemon, I corrupt the item list and can now scroll down past the 20th item. I shift items around to increase the text speed to maximum and rewrite the warp point of my house to Celadon Dept. Store. (p4wn3r used this to go directly to the hall of fame and win the game in his run.) I deposit many 0x00 glitch items into the PC from my corrupted inventory for later use. Then, I withdraw the potion from the PC. This repairs my item list by overflowing the item counter from 0xFF back to 0x00, though the potion is obliterated in the process. I then take 255 glitch items with ID 0x00 from the computer into my personal items.

Celadon Dept. Store

Leaving my house takes me directly to Celadon Dept. store, where I sell two 0x00 items for 414925 each, giving myself essentially max money. I hit every floor of the department store, gathering the following items:

+-------------------+----------+
|##| Item | Quantity |
+--+----------------+----------+
|1 | TM02 | 98 |
|2 | TM37 | 71 |
|3 | TM05 | 1 |
|4 | TM09 | 1 |
|5 | burn-heal | 12 |
|6 | ice-heal | 55 |
|7 | parlyz-heal | 99 |
|8 | parlyz-heal | 55 |
|9 | TM18 | 1 |
|10| fire-stone | 23 |
|11| water-stone | 29 |
|12| x-accuracy | 58 |
|13| guard-spec | 99 |
|14| guard-spec | 24 |
|15| lemonade | 16 |
|16| TM13 | 1 |
+--+----------------+----------+

After gathering these items, I deposit them in the appropriate order into the item PC to spell out my bootstrapping program. Writing a full bootstrap program in one go using only items turned out to be too hard, so I split the process up into three parts. The program that I actually construct using items is very limited. It reads only from the A, B, start, and select buttons, and writes 4 bits each frame starting at a fixed point in memory. After it writes 200 or so bytes, it jumps directly to what it just wrote. In my run, I use this program to write another bootstrapping program that can write any number of bytes to any location in memory, and then jump to any location in memory. This new program can also write 8 bits per frame by using all the buttons. Using this new bootstrap program, I write a final bootstrapping program that does everything the previous bootstrapping program does except it also displays the bytes it is writing to memory on the screen.

Finale

After completing this bootstrapping program, I go to the Celadon mansion, because I find the metaness of that building to be sufficiently high to serve as an exit point for the pokemon universe. I corrupt my item list again by switching corrupted pokemon, scroll down to my rival's name and discard until it is equal to the address of my bootstrapping program, and then swap it with the function pointer. Once the menu is closed, the bootstrapping program takes over, and I write the payload....

Other comments

The entire video was played by the computer using bots. I used functional programming to write search programs over different possible game states to find the most efficient way of performing general actions. Some interesting things I developed but didn't use were pretty printing functions to display the game's internal data structures, and an "improbability drive" that forces improbable events to happen automatically using search.

Here are a few example scripts:

  (defn-memo viridian-store->oaks-lab
    ([] (viridian-store->oaks-lab
         (get-oaks-parcel) ) )
    ([ script \]
       (->> script
            (walk [↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
                   ← ← ← ← ← ← ← ← ←
                   ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
                   ← ←
                   ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
                   ↓ ↓ ↓ ↓ ↓ ↓ ↓
                   → → → → → → → →
                   ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓ ↓
                   ← ← ← ← ←
                   ↓ ↓ ↓ ↓
                   ])
            (walk-through-grass
             [↓ ↓ ↓ ↓ ↓ ↓ ↓])
            (walk [↓ ↓ ← ↓ ↓ ↓ ←
                   ↓ ↓ ↓ ↓ ↓ ↓
                   → → → ↑])

            (do-nothing 1) ) ) )


This script walks from the Viridian City pokemon store to Oak's Lab in the most efficient way possible. The walk-through-grass function guarantees that no wild battles will happen by manipulating the game's random number generator.

  (defn-memo hacking-10
    ([] (hacking-10 (hacking-9) ) )
    ([ script \]
       (->> script
            begin-deposit
            (deposit-held-item 17 230)
            (deposit-held-item-named :parlyz-heal 55)
            (deposit-held-item 14 178)
            (deposit-held-item-named :water-stone 29)
            (deposit-held-item 14 32)
            (deposit-held-item-named :TM18 1)
            (deposit-held-item 13 1)
            (deposit-held-item 13 191)
            (deposit-held-item-named :TM02 98)
            (deposit-held-item-named :TM09 1)
            close-menu) ) )


This script calculates the fastest sequence of key presses to deposit the requested items into a PC, assuming that the character starts out in front of a computer.

Other Comments

The final payload program is multiple programs. I created a reduced form of MIDI and implemented it in gameboy machine language. Then I translated a midi file from http://www.everyponysings.com/ into this reduced MIDI language. The payload program contains both the music data and the MIDI interpreter to play that data. The picture works in a similar way. There is code to translate a png file into a form that can be displayed on a gameboy, and other code to actually display that image. Both the image and the display code are also written by the final bootstrapping program. Even though my final payload is rather simple, you can write any program at all as the payload. The source for the sound and image displaying code is at http://hg.bortreb.com/vba-clojure

This entire project is open source and I encourage anyone who wants to take the code and play around!


A more creepy-pasta-esque example of what this is capable of doing



#2 User is offline Sonic Scotland 

Posted 28 November 2012 - 08:27 PM

  • Posts: 10
  • Joined: 04-November 12
  • Gender:Male
  • Location:Glasgow, Scotland
  • Project:Project Hawick
This is insanely brilliant. I'm away to hunt down a G.B.C....

#3 User is offline Aerosol 

Posted 28 November 2012 - 09:03 PM

  • FML and FU2
  • Posts: 7627
  • Joined: 27-April 08
  • Gender:Male
  • Location:Not where I want to be.
  • Project:Sonic (?): Coming summer of 2055...?
Brilliant, and devious. I don't think you could straight up program completely separate games like this.....could you?

#4 User is offline Ravenfreak 

Posted 28 November 2012 - 09:15 PM

  • It's a bird, it's a plane, nope it's a ring!
  • Posts: 2289
  • Joined: 24-November 08
  • Gender:Male
  • Location:O'Fallon Mo
  • Project:Mighty No. 9 Universe,various hacking projects
  • Wiki edits:112
It's pretty cool to see what happens and what can occur from messing around with glitches in the first gen games but this is definitely taking that to a whole new level. O.O I'll have to try this sometime, it'll be different from just simply glitching out the game. :)

#5 User is offline LordOfSquad 

Posted 28 November 2012 - 09:30 PM

  • don't get butthurt if your get memed on
  • Posts: 4056
  • Joined: 19-February 08
  • Gender:Male
  • Location:Winnipeg, MB
  • Project:Scriptwriting, working, dying.
  • Wiki edits:1
Talk about a buzzkill. I watched that entire video waiting to see what would happen, and got greeted with My Little Pony. Siiigh.

It's certainly a neat technical achievement though. Now to just wait and see someone do something good with it.

#6 User is offline Aesculapius Piranha 

Posted 28 November 2012 - 10:02 PM

  • つづく
  • Posts: 3654
  • Joined: 14-March 08
  • Gender:Male
  • Location:Surrounded by water.
  • Project:Diva
  • Wiki edits:6
Yo dawg, I heard you like hacking Pokemon Yellow, so I decided to hack your Pokemon Yellow with Pokemon Yellow.

Seriously though, here I was thinking the Mew glitch was fun and impressive....

#7 User is offline LocalH 

Posted 29 November 2012 - 02:42 AM

  • roxoring your soxors
  • Posts: 3147
  • Joined: 11-January 03
  • Gender:Male
  • Location:wouldn't you like to know
  • Project:MDEM - Genesis programming stufz
  • Wiki edits:3
Wow, what the everloving fuck. This is the epitome of TAS runs at the moment. I say that as neither a fan of Pokemon nor MLP.

#8 User is offline ashthedragon 

Posted 29 November 2012 - 07:20 AM

  • Dragon Team
  • Posts: 1146
  • Joined: 23-February 08
  • Gender:Female
  • Location:Spain
  • Project:Sonic Paradise & Sonic Ages
This is amazing.

#9 User is offline Covarr 

Posted 30 November 2012 - 04:40 PM

  • Sentient Cash Register
  • Posts: 3253
  • Joined: 05-February 07
  • Gender:Male
  • Location:The desert of nowhere, USA
  • Wiki edits:1

View PostAerosolSP, on 28 November 2012 - 09:03 PM, said:

Brilliant, and devious. I don't think you could straight up program completely separate games like this.....could you?

If it's small enough, yes. But the entire game, and all its data needs to fit in RAM, so you're pretty limited.

#10 User is offline Epsilonsama 

Posted 02 December 2012 - 04:24 PM

  • THE FASTEST TAPE ALIVE!
  • Posts: 592
  • Joined: 15-November 08
  • Gender:Male
  • Location:Earth
  • Wiki edits:7

View PostLordOfSquad, on 28 November 2012 - 09:30 PM, said:

Talk about a buzzkill. I watched that entire video waiting to see what would happen, and got greeted with My Little Pony. Siiigh.

It's certainly a neat technical achievement though. Now to just wait and see someone do something good with it.


Indeed, If one should ever want to publish something of technical importance the last thing the person should do is use something MLP related as the pay off. It completely undermines the credibility of the individual and the technical work of it.

j/k. In all seriousness its quite an accomplishment and goes to show how poorly coded and broken the Pokemon games were. And yet that did not stop one from enjoying the game in question.

#11 User is offline Cinossu 

Posted 04 December 2012 - 10:44 AM

  • inverted with love~
  • Posts: 2718
  • Joined: 21-June 04
  • Gender:Male
  • Location:London, UK
  • Project:Sonic the Hedgehog Extended Edition
  • Wiki edits:474
180
I wouldn't exactly say they were "poorly coded and broken", seeing as everything does work as it's meant to in the first place, just with added extras. :P

Nice to see something like this actually being used with actual programming in mind (minus the MLP, of course); could lead to some interesting ideas if utilised correctly.

#12 User is offline Epsilonsama 

Posted 04 December 2012 - 11:46 AM

  • THE FASTEST TAPE ALIVE!
  • Posts: 592
  • Joined: 15-November 08
  • Gender:Male
  • Location:Earth
  • Wiki edits:7

View PostCinossu, on 04 December 2012 - 10:44 AM, said:

I wouldn't exactly say they were "poorly coded and broken", seeing as everything does work as it's meant to in the first place, just with added extras. :P

Nice to see something like this actually being used with actual programming in mind (minus the MLP, of course); could lead to some interesting ideas if utilised correctly.


Well from a technical stand point it is kinda poorly coded. To many places were the game could do something that wasnt planned and could have unforeseen consequences.

Still awesome thought.

#13 User is offline Aesculapius Piranha 

Posted 04 December 2012 - 11:11 PM

  • つづく
  • Posts: 3654
  • Joined: 14-March 08
  • Gender:Male
  • Location:Surrounded by water.
  • Project:Diva
  • Wiki edits:6
It's poor coding if you approach it from a modern industry standard sort of viewpoint where QA must absolutely address any sort of bugs and exploits a gamer may come across. Otherwise when you take into account that the game is 15 years old and the hardware it was on and that a vast majority of the bugs and exploits in the game added to the fun of it all which is the purpose of a game app, it's hard to criticize the coding.

That and from all accounts Satoshi Tajiri is a bug fanatic and the game is about bug collecting. Why shouldn't it have bugs? :v:
This post has been edited by Aesculapius Piranha: 04 December 2012 - 11:26 PM

#14 User is offline Josh 

Posted 05 December 2012 - 01:21 AM

  • TGC Warrior
  • Posts: 926
  • Joined: 22-January 08
  • Gender:Male
  • Location:USA
  • Wiki edits:1
Hahaha, I love this. I have a friend who's really into programming. He's a Computer Science major. So I showed him this, he's a big Pokemon fan, really into it. Got SO butthurt when MLP came up at the end. Awesome!

As for the Gen I's stability... I think it's more than just looking at it from the perspective "of the time". I mean, QA and bug-testing was a huge deal even then, as we saw with the INSANE amounts of QA Sonic 3D had to go through. What made Pokemon unique is that it was pretty much the most technical, ambitious and complicated thing that had ever been done on the Game Boy. I mean, what other game had EVER pushed the system like that? Given that, I think GameFreak should be commended for getting it to work as well as it did, where the bugs and glitches are just fun extras, extremely unlikely to screw up anything too badly.

#15 User is offline Captain L 

Posted 06 December 2012 - 10:24 PM

  • The guy who likes Shadow the Hedgehog
  • Posts: 2143
  • Joined: 13-September 10
  • Gender:Male
  • Project:Waiting for the coming of the Great White Hankerchief
I don't even know why I bothered to watch the video. I know next to nothing about Pokemon, and I had no idea what was happening throughout the entire video. But the concept was absolutely fascinating.

And that MLP 8 bit remix was good.

  • 2 Pages +
  • 1
  • 2
    Locked
    Locked Forum

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users