Part 2: What’s in a Save?

By the time the GameBoy Advance released in 2001, cheating devices like the Game Genie and Action Replay were common. Players could use these devices to modify data within the cartridge, simply by knowing where in memory it was located. For instance, one could modify address $D347 in the original Pokémon Red to increase how much money they had. Essentially, this is what I was doing as well- just through Multiboot instead of an external device. However, developers had learned their lessons by the early 2000’s, and wanted to make using a cheating device as hard as possible. For the five Pokémon games released on the GameBoy Advance, this was accomplished in three different ways.

The first roadblock was the fact that there are truly two save files for each game. Every time the game saves, it alternates which save file is used. This is also used so that the user has a back-up save file, in case save corruption occurs. The solution for this is simple enough- each save file keeps track of how many times the game has been saved, so check which one has the higher number. Simple enough!

flash_mem.cpp

The next roadblock was a bit trickier through. Each save file is broken down into 14 different sections, each 0x1000 bytes in size. These 14 sections cycle every time the game saves, so there are 14 different ways the save data could be ordered. Fortunately, each section has a footer that includes an ID number. To keep things simple, I store the pointer to each memory section in an array, which allows me to modify the section no matter where it is.

flash_mem.cpp

The final road block is a simple checksum. All that’s needed here is to go through the entire save data section in sets of four bytes, and add them together. Then place the final sum in the section’s footer. If the checksum is off, then the game will say that the data is corrupted. The Hall of Fame data section is slightly different, since it has a smaller amount of bytes, and so we have to check for that.

flash_mem.cpp

And with that, we can successfully modify the Pokémon save file! Fortunately for us, all five GameBoy Advance Pokémon games use this save data structure. That means we don’t even have to check what game is loaded- at least yet.

If you want to learn more, Bulbapedia has a whole page dedicated to the save data structure of the generation 3 Pokémon games, which you can find here. This page was where I learned about most of the save data structure, and I can’t recommend it enough!

Originally, I directly added in Pokémon to the user’s PC box. This method made the most sense, but it wasn’t very flashy and was prone to errors due to how the box data was split up. Eventually, I replaced this method with something far more complex, but also far cooler. But more on that later- for now, the next step was to figure out how to get Pokémon data out of the GameBoy, and into the GameBoy Advance.

Previous
Previous

Part 1: The GameBoy Advance

Next
Next

Part 3: A Link Between Worlds