(HELP)PKsave checksum calculation

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

  1. Februarysn0w
    OP

    Februarysn0w School Idol Festival

    Member
    1,205
    518
    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
    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, Mar 7, 2016
  2. daxtsu

    daxtsu GBAtemp Guru

    Member
    5,546
    3,955
    Jun 9, 2007
    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).
     
    Queno138 and Februarysn0w like this.
  3. Februarysn0w
    OP

    Februarysn0w School Idol Festival

    Member
    1,205
    518
    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. daxtsu

    daxtsu GBAtemp Guru

    Member
    5,546
    3,955
    Jun 9, 2007
    Antarctica
    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.