# (HELP)PKsave checksum calculation

Discussion in '3DS - ROM Hacking, Translations and Utilities' started by Februarysn0w, Mar 7, 2016.

# (HELP)PKsave checksum calculation

498 Views
1. ### Februarysn0wSchool Idol Festival

Member
Oct 31, 2014
Mino city Osaka
I have read some english wiki about pokemon GEN1 save data structure.
but I can't fully understood what the wiki say.
so could you please explain for me more understandable english?
I know, there is many kind of editor but not compatible with jap characters and green version.

http://bulbapedia.bulbagarden.net/wiki/Save_data_structure_in_Generation_I

I'm very appreciate if you tell me the calculation formula or source code or tools.

Thank you so much for your help.
Thank you.

Last edited by Februarysn0w, Mar 7, 2016
2. ### daxtsuGBAtemp Guru

Member
Jun 9, 2007
So you're confused about the checksum section only? It's something like this, as far as I can tell:

Code:
```uint8_t doChecksum(void)
{
uint8_t checksum = 0;
int i = 0;
for(i = 0x2598; i < 0x3523; ++i)
{
checksum += saveFileData[i];
}

checksum = ~checksum;

return checksum;
}
```
Or, slightly less complicated:

Code:
```uint8_t doChecksum(void)
{
uint8_t checksum = 255;
int i = 0;
for(i = 0x2598; i < 0x3523; ++i)
{
checksum -= saveFileData[i];
}

return checksum;
}
```
Basically, it takes an 8-bit variable, sets it to 0 (or 255), and then begins adding (or subtracting, if you started with 255) the values of every byte at that specific place in the save file (0x2598 to 0x3522, including 0x3522 itself also), and then does a bitwise NOT on the result (if you started with 0, and not 255).

Queno138 and Februarysn0w like this.
3. ### Februarysn0wSchool Idol Festival

Member
Oct 31, 2014
Mino city Osaka
Thank you so much for your code. Yes, I confused checksum section only.
Thank you for being so considerate. Very appreciate.

daxtsu likes this.
4. ### daxtsuGBAtemp Guru

Member
Jun 9, 2007
No problem. If you're making an editor of your own, don't forget to update the checksum byte at 0x3523 afterward, or the game won't accept any changes your editor makes, since the new checksum it will calculate (from the edits your editor made) won't match the one it has stored there.

Ryuzaki_MrL and Februarysn0w like this.
Similar Threads - HELP PKsave checksum