ROM Hack (HELP)PKsave checksum calculation

Februarysn0w

Well-Known Member
OP
Member
Joined
Oct 31, 2014
Messages
1,206
Trophies
0
Age
36
XP
834
Country
Japan
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
link above checksum section.

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,

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
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).
 

Februarysn0w

Well-Known Member
OP
Member
Joined
Oct 31, 2014
Messages
1,206
Trophies
0
Age
36
XP
834
Country
Japan
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).

Thank you so much for your code. Yes, I confused checksum section only.
Thank you for being so considerate. Very appreciate.
 
  • Like
Reactions: daxtsu

daxtsu

Well-Known Member
Member
Joined
Jun 9, 2007
Messages
5,627
Trophies
2
XP
5,194
Country
Antarctica
Thank you so much for your code. Yes, I confused checksum section only.
Thank you for being so considerate. Very appreciate.

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.
 

Site & Scene News

Popular threads in this forum

General chit-chat
Help Users
    rvtr @ rvtr: Spam bots again.