Skip to content
Go back

How Cheat Codes Work in Pokémon Games (And How to Create One)

Published:  at  03:27 PM

Table of Contents

Open Table of Contents

Intro

Back in 2015, when I was in middle school, my friend suggested me to play Pokémon FireRed. But my mom only let me play games for two hours on weekends, so it took me about three to four months to become a Pokémon master.

One day my friend handed me a single line of code that gave me unlimited Rare Candy. Unlike legends in the classic ‘90s, I played with an emulator on my tablet, so it was fairly easy to use cheat codes. Just type the codes and enable it, and the magic happens!

I was instantly obsessed. That tiny cheat didn’t just make the game easier but it opened a door to the whole new world.

I was so intrigued that I started learning about other games’ modding, using Lucky Patcher, GameGuardian and other tools. The simple joy of changing a number on the screen and seeing the game obey you. That’s what dragged me into the fascinating world of hacking.

This blog’s purpose is to help you find a way of sharing your first spark!

What you’ll need

To follow this post you’ll want a GBA emulator that has memory-editing tools. I use VisualBoyAdvance but you can use any emulator you like with memory manipulating and disassembling support.

A gba file of Pokémon FireRed. The emulator will let you run the game and peek inside its memory in real time. That’s where cheat codes do their magic.

A quick glance at CodeBreaker and GameShark

Code Breaker, Game Shark and Action Replay were originally physical hardware cartridges that you plugged into your GBA. They had their own mini-processors and software. Their code formats are instructions for that hardware’s software.

They can have different commands for writing different data sizes (8-bit, 16-bit, 32-bit) and can even include conditional logic (like “if player’s health is below 50%, then write this value”).

An illegal discount

Let’s get started our adventure, shall we?

Skip all the preceding scenes; choosing starter Pokemon, first battle, deliver the parcel back to Professor Oak, etc.

In Pokemon Mart, talk with the owner and you have to choose an item to buy. (we’ll buy Pokeball for example). Now let’s see if what we can do something about it.

In VBA, Select Tools > Cheats > Find cheat… > Compare Type (Equal), Signed, Data size (32 Bits), Set Specific Value to 200 and Click Search.

200

You’ll see the value 200 at the address 0x0203993C.
Double click it and set the Description to whatever you want. Change the value 200 to 10 and click ‘OK’. Then click ‘OK’ again and continue the game.

10

Wait a minute. The value actually changed?

200 to 10

Yes!!! You can actually buy 1 Pokeball for only 10 P!

Not just that, you can buy any item you want with only 10 P.

Other items

Of course, our cheat has some limitations. You can buy only one item at a time with that discount price but it’s enough for us to analyze it.

Diving into A Rabbit Hole:

Go to Tools > Cheats > List cheats… and our Buy 1 for 10 P cheat was like this:

List cheat

0203993C:0000000A
Type: Generic Code

Hmmm…it looks really familiar, don’t you think?

In Tools > Memory Viewer, search for the address 0203993C and it was like this:

Memory Viewer

In the address 0203993C, the value is 0000000A, which is 10 in decimal! We did it!

In the left side of the window, you’ll see there is a drop down menu for address areas. Since our address lies around 0x02000000, it’s in WRAM. But what is WRAM?

WRAM stands for Work RAM. Think of it as the GBA’s main workbench or scratchpad.

Both the game’s code that is currently running and the data it’s actively using (like the money and that item price) reside in WRAM.

Back to our cheat, it’s the Generic Code - 0203993C:0000000A. Now we’ve grasped the concept behind it. It’s actually a simple instruction.

“Change the value in the address 0x0203993C to 0000000A”

That’s it and we got our illegal discount.

The format is like:

<address>:<value>

This makes a really good foundation for us to understand how Code Breaker works.

Code Breaker - Easier than you think

The legendary code for master ball is:

82025840 0001
Type: Code Breaker Advance

Similar to our Generic Code 0203993C:0000000A, but the preceding 82025840 doesn’t seem like an address right?

If you have a time, check other Code Breaker cheats. Do you notice something?

Yes! All the codes have a preceding 8!

That 8 at the beginning is not part of the address. It’s a command prefix.

The code 82025840 0001 can be broken down like this for a Code Breaker device:

So, the code is an instruction: “Write the 16-bit value 00000001 to address 0x02025840”.

Creating our own:

Since we know the format of Code Breaker, why don’t we try turning our “Buy 1 for 10 P cheat” from Generic Code to Code Breaker?

Generic Code is “0203993C:0000000A”

Add 8 to the preceding bit and slash some bits. So our code become like this “8203993C 000A”.

Let’s test this out! Go to Tools > Cheats > List cheats… and click (+) to add cheat.

New Code Breaker

Don’t forget to uncheck our previous Generic Code. Now let’s go to the Pokemon Mart and see if it’s really works or not.

Code Breaker works

It works!!! To be sure, go to Tools > Memory Viewer to confirm this.

Observing memory of Code Breaker

Yes! Our injected value is in the address 0x0203993C. We’ve just created our own Code Breaker cheat. Isn’t that amazing?!

How do Game Shark codes work?

Game Shark codes look like total gibberish, and there’s no obvious “address:value” format. That’s because Game Shark codes are encrypted.

Code Breaker speaks a very plain language: “Write this value to this address.” (8 2025840 0044), while Game Shark speaks in a secret code to prevent people from easily stealing their cheats or understanding how they work.

Here’s the process:

So, a Game Shark code is just an encrypted package. The complex string is the locked box, and the Game Shark device has the key to open it and read the simple instruction inside. It was a form of commercial protection to make their codes unique.

Final thoughts and Where to go next

You now know:

If you want to level up more:

The goal is learning how software works. Use the skills responsibly.

And of course, it’s just named as “Creating our own cheat” but in fact, many cheat codes including our illegal discount ones have been discoverd by many hobbyists before.

This is just a demonstration to prove that if we keep exploring and testing, we can discover more and more codes and ways to fiddle with the game.

So stay curious :)
Happy Reversing!


Spotted a Mistake?
Share this post on:

Previous Post
THM, HTB VPN Error ဖြေရှင်းနည်း
Next Post
What the heap? (Part 3)