Jump to content
trigger_segfault

Pokemon Box R&S Save File Structure Research - [Research Complete]

Recommended Posts

I have managed to successfully read and save Pokemon Box saves and have them load without issues on the actual game.

An editor actually does exist for Pokemon Box with source code Here which is what I based some of my findings on however this program doesn't have saving. Thank you Kaphotics for finding it.

Save File Structure:

Size: 0x76000 (+64 if it contains GCI data)

0x0 - GameCube Memory Card Data
0x02000 - Save Slot 1
0x30000 - Save Slot 2

Save Slot Structure:

Size: 0x2E000

0x0 - Array of 23 blocks of data. There is no data after that.

Each save file contains 23 blocks from start to finish. There is no leftover data.

Save data is stored in an almost identical fashion to the GBA games.

Block Structure:

Size: 0x2000

Variables:
0x0 - ushort ChecksumA in big endian
0x2 - ushort ChecksumB in big endian
0x4 - u32 BlockID in big endian (from 0-22 inclusive)
0x8 - u32 SaveCount in big endian
0xC-0x1FFB - Actual Data
0x1FFC - u32 Footer (unsure what this is used for)

Calculating the Checksum (In C#):
uint checksum = (ushort)((ushort)BlockID + (ushort)(BlockID >> 16) + (ushort)SaveCount + (ushort)(SaveCount >> 16));
for (int i = 0xC; i < 0x1FFC; i += 2) {
// Read the next ushort in big endian then add it to the checksum.
uint word = (uint)(((uint)RawData[i] << 8) + RawData[i + 1]);
checksum += word;
}
ChecksumA = (ushort)checksum;
ChecksumB = (ushort)(0xF004 - (ushort)checksum);

Actual Data Structure:

Size: 0x2BEA0

0x04 - u32 CurrentBox in little endian. (The last box the player was viewing before saving)
0x08 - Start of Pokemon Boxes, Each Pokemon is listed every 84 bytes until the last Pokemon in box 25
0x1EC38 - Start of box names, each is spaced 9 bytes appart and uses Gen 3 GBA Character Encoding and is 9 bytes in length.
    A name starting in 0 or 255 is empty and the default name for that box should be used.
0x1ED19 - Start of box wallpapers. Each wallpaper is 1 byte in length. Each wallpaper's id corresponds to its order in the menu.

GBA Pokemon Character Encoding

First load each block then order them from lowest to highest block id.

Then dump each block's actual data into a single array and use that as the save file containing your data.

Pokemon Data Structure:

Size: 0x54 (84 bytes)

0x00-0x4F - Gen 3 GBA PKM Data
0x50 - u16 Trainer ID of sender in little endian
0x52 - u16 Secret ID of sender in little endian

GBA PKM Data Structure

Saving Pokemon Box:

Saving is pretty straight forwards assuming you're reading the file correctly. You don't need to increment the save count or anything and you only need to update the most recent save slot. Keeping the order the blocks were in works when saving the game and loading it on Pokemon Box. I haven't had anyone test it with sorting the blocks.

Edited by trigger_death

Share this post


Link to post
Share on other sites
Since Dolphin-GBA connectivity is shot there's no way to even peak into the contents of what a save contains.

Pokemon Box was fixed with revision 4.0-9242 a few weeks ago.

Just use the latest development version of Dolphin (https://en.dolphin-emu.org/download/) and the latest version of VBA-M (https://sourceforge.net/projects/vbam/files/) and follow these instructions http://web.archive.org/web/20151006182128/http://vba-m.com/forum/Thread-multiple-instances-of-vba-m?pid=7684 (from their official site before the server crashed a while ago).

It works fine for me.

Share this post


Link to post
Share on other sites
Pokemon Box was fixed with revision 4.0-9242 a few weeks ago.

Just use the latest development version of Dolphin (https://en.dolphin-emu.org/download/) and the latest version of VBA-M (https://sourceforge.net/projects/vbam/files/) and follow these instructions http://web.archive.org/web/20151006182128/http://vba-m.com/forum/Thread-multiple-instances-of-vba-m?pid=7684 (from their official site before the server crashed a while ago).

It works fine for me.

Thanks. I'll test it out.

Edit: Hmm. It says I need to save at a Pokemon Center, yet I have. I've tried different Pokemon centers and making sure the save is Flash 128k, Both Ruby, Sapphire and Emerald and still nothing.

Share this post


Link to post
Share on other sites

Stupid question, but are you saving twice in the GBA game before trying to load the save in Pokémon Box? That should guarantee that the 'current' and 'backup' save blocks are identical in case Box is reading the wrong one somehow.

Share this post


Link to post
Share on other sites
Stupid question, but are you saving twice in the GBA game before trying to load the save in Pokémon Box? That should guarantee that the 'current' and 'backup' save blocks are identical in case Box is reading the wrong one somehow.

Yes I have been sadly. If anyone else can actually get it to work on their end that would at least mean it's possible.

Share this post


Link to post
Share on other sites

Wow well that throws all my research out the window. Thank you though. Now my program can have complete Pokemon Box support!

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...