If you've ever tried to make Emerald run on a 3DS in the native GBA VC, you know that it doesn't want to save initially. If you're using Ultimate GBA VC Injector, which was the only option for the longest time, you have to do some funky hex editing to your rom to get it to save properly. Plus, you have to SRAM patch your game to get it to work. So much nonsense.
WRONG. DON'T FOLLOW THIS GUIDE. (the one that tells you to do the nonsense)
So here's the issue:
First off, but unrelated to the current situation: you don't need to SRAM-patch 3DS CIAs. The GBA hardware on the 3DS supports every save type, as long as the save file is large enough for the game in question.
Now, here's the thing: Pokemon Emerald uses a 128kb-large Flash save file. The CIA we made using Ultimate VC Injector, despite the fact that we specified FLASH-type memory with RTC, only makes a 64kb-large save file. Whoops.
Fun fact: did you know that Pokemon games actually store two save files? They keep track of the latest save, and the save before that in case of save corruption. Problem is that both of those take up, in total, more than 64kb of space. You should start to see the problem here.
The funky hex editing from the guide above is, to simplify, making the game forget where to write the backup save file. That way, you never run over the 64kb of space you have! Easy fix! The only thing you're left with is a perfectly-functional save file and an annoying message of the game complaining that your game is secretly screwed.
FR/LG doesn't need all 128kb of space, so it never becomes an issue there. Once the backup save is deleted, it happily fits itself within the 64kb of allotted space.
Emerald, however, is a bit of a beefier boi. Through the normal game, nothing seems wrong. However, once you become the Champion of the Hoenn region, guess where the hall of fame data has to go. That's right, the latter 64kb of save. (Also mystery gift and battle records, but those only become accessible in the postgame, so you're going to encounter the HoF roadblock first.)
Since the game only has access half the save data it thinks it has, when it tries to write the hall of fame data to the other half of the file, it actually wraps around and overwrites some of the main save data. The game's data storage keeper-tracker-of system gets replaced with the name of your Pikachu, and it can no longer see your 200 hour grinding spree as a valid save file. And since we stopped the game from keeping a backup earlier, your character just ceases to exist.
So let's fix that, shall we? (sidenote: I totally get why some recipes have those three-page essays in front of them now. stories are fun.)
You will need:
A hex editor. I use Hex Workshop, which is currently free and, as far as I can tell, virus-free.
If you're using Hex Workshop, you can download this character filter for it, which lets you read the hexadecimal garble as plaintext on the right side. Also, give the guy some love. To install it, put the .map file in your C:\Program Files\BreakPoint Software\Hex Workshop\CharMaps folder.
If you're using another hex editor, you can see what hex values correspond to each letter here. Just CTRL+F for "Finding Pokemon".
A clean Pokemon Emerald ROM that hasn't been hex-edited with the guide at the top. I trust that you have a legitimate copy of the game that you used a ROM-ripper on, and didn't pirate it you cheaty cheater mccheaterson.
PKHex, a save file editing program. Since part of your data definitely got deleted, be it your Bag, your Party, or a PC Box, you'll probably need to use this to get it/them back.
New Super Ultimate Injector for 3DS. Basically, better UGBAVCI. Unfortunately, it only comes in not-English, so I'll give the instructions for generating a CIA with it as well. (And please give the creator some love; the non-English programming community doesn't get nearly enough respect, and this is an awesome tool for the community.) (And yes, it is also virus-free.)
Steps to Make a 128kb CIA:
Open New Super Ultimate Injector for 3DS. It's in Spanish, I know. Just bear with me here.
(EDIT: Turns out you can go to "Herramientas" > "Opciones" and change the language there. Set "Idioma" to "English" and click "Guardar" in the bottom right, then click "Yes" in the popup to restart the program in English.)
At the upper-left corner, click "Archivo", then select "Nuevo" > "CIA de Game Boy Advance".
(AKA File > New > Game Boy Advance CIA)
A new tab will open in the program. Right-click the name of the new tab, then select "Cargar ROM...".
(AKA "Load ROM...")
Navigate to the .gba file you definitely got through legitimate means, and click "Open".
(AKA "Open")
Since this ROM wasn't hex-edited, pretty much all of the data should autofill. All you need to do is set the icon and 3D banner images for the home screen.
"Descargar" means "download", "desde" means "from". You should be able to figure out what the rest means.
Also, you can click the "Virtual Console" nameplate thing to change the text displayed there.
Once you have it customized to your liking, right-click the tab again, click "Guardar" to save the project, then click "Exportar CIA..." to get your CIA file.
(AKA "Save" and "Export CIA".)
After we finish with the save-editing stuff, put the CIA on your micro SD card and use FBI to install it.
Steps to Fix the Save:
Follow this guide to dump your Emerald save using GodMode9, and open it in the hex editor of your choice.
If you're using Hex Workshop, click the dropdown near the top that says "Legacy ASCII" and select "Pokemon FireRed".
Scroll to the end of the file, click the blank value at the very very end, and add 65,536 bytes with the value "00". In Hex Workshop, you can right click and select "Insert".
This is to make the file 128kb long.
Go to offset 0x0FFC (search bar at the top middle in Hex Workshop) and copy that byte and the byte after it. (Each byte is two numbers, e.g. 00 or B2.)
This is your save index, AKA the number of times you've saved the game, which is how the game distinguishes between "main" and "backup" saves.
Paste those two bytes you just copied into offsets 0xBFFC and 0xCFFC.
Go to offset 0xC000, and replace the data from there to 0xC0B4 with 00. Basically just the whole block until you hit the next wall of 00s.
Don't use "delete" on the data, since that will straight-up delete the bytes from existence instead of zeroing them out. If you're in Hex Workshop, you can highlight all of them, right-click, select "Fill", and fill it with "0". Otherwise, you just have to type the zeroes by hand.
If you're using the character filter I mentioned before, you should be seeing some familiar names here. This is the hall of fame data, just in the wrong place in the file.
Go to offset 0xBFF4 and remember the number it holds. Add 1 to that number and put it in offset 0xCFF4. Then replace the next two bytes with 00.
For the addition: 01 would become 02, 09 would become 0A, 0A would become 0B, and specifically 0D would become 00.
Now, the number you just wrote down is the ID of the section that got overwritten. GBA save data is stored in chunks, and depending on which chunk got overwritten, you'll have to do different things to recover it.
NOTE: All but 02 are just theories right now. I'm currently working on testing each individual case.
If the overwritten section was 01:
Your team, bag, and Pokedex data has been deleted. Use PKHex to recover them, and you should probably be good? I'm working on testing this case right now.
I'd recommend against loading the save file with no Pokemon.
NOTE: No one's 100% sure how the Pokedex part works. It's apparently stored in multiple places, so there's a chance the save won't load if everything doesn't match. I'm working on this one right now.
02:
This section stores the game flags, including gym badges, event triggers, and berry trees. This is probably the easiest part of the core data to resolve, since everyone's at the same point in the story here.
Highlight everything from offset 0xBFFD to 0xCFF7 inclusive (meaning including those offsets, not just the stuff in-between) and paste the following over it. (NOTE: Make sure not to insert.)
After you've done this, you'll want to open up this save file in in PKHex and change them back to however they were. For example, if you haven't caught Rayquaza yet, you can edit the flag for that in PKHex. You can get your hard-earned berries back that way too.
03/04:
I can't find any info on these sections, so if someone could help that would be awesome.
05-0C:
You lost a PC box. Use PKHex to recover your missing Pokemon.
0D:
You lost a PC box too, but you also lost your box names and wallpapers, so there's one more step before using PKHex here.
Highlight everything from offset 0xBFFD to 0xCFFA inclusive and replace it with the following:
00:
This is, or was, your trainer data. There's a lot of stuff in the game's code that ensures that we can't just paste in someone else's, so we need to make a new save file and copy all of our old data to this new one.
NOTE: All of my attempts ended up in the G L I T C H Z O N E, so you'll probably have to do research yourself to get this to work.
Steps:
Load up the 128kb VC game we just created and create a new file.
Play until you can save, save once, then close the game.
Export the save file using GM9 and load it up in a hex editor alongside your broken save file.
You'll need to identify the save data blocks in the old save by their footers, and copy them over to the new one accordingly. See the "File Structure Info" section for more details.
After you're done patching your save file, follow the steps in the second half of the save-dumping guide to inject your save back into the CIA, and you're good to go!
File Structure Info:
GBA saves are divided into 13 sections, 00 to 0D, each one with its own section ID. The sections are stored in the file in order, but the file doesn't necessarily have to start with section 00 and end with section 0D. For instance, it could start with section 04, then halfway through the file reach the end of section 0D, and then the rest of the file would be sections 00 to 03. Basically, it's a loop, but thankfully the sections are still in order.
Each Section is identified by a footer, not a header. The footer format is ID ## ## ## 25 20 01 08 SAVEINDEX. After the save index, there is a 00 00 00 separating sequential sections.
This does not apply to the second save file when there isn't a second save file. The three 00 bytes are FF when there's only one save present in the file.
In order for your save file to validate, the save index needs to be the same across the board. That means if we copy-paste a block of sections, we have to go back over it and make sure all of the save indices are the same.
keywords for time travelers: pokemon ruby and sapphire, pokemon generation 3, save corruption, elite four, save corrupted after beating elite four, save corrupted after beating champion, pokemon emerald, gen 3 save, 3ds, virtual console, save deleted after beating game