How to calculate the checksum of 5th gen .PKM files?

Discussion in 'NDS - ROM Hacking and Translations' started by Kyohack, Jun 29, 2011.

  1. Kyohack
    OP

    Newcomer Kyohack Advanced Member

    Joined:
    Mar 27, 2010
    Messages:
    98
    Location:
    Las Vegas, Nevada
    Country:
    United States
    I am programming a web based pokesav in PHP, and I would like to know how to calculate the checksum of 5th gen .PKM files. I am referring to the checksum that is located at hexadecimal offset 0x06 that is 2 bytes long. I have already attempted to use the 4th generation checksum calculation method, but it produces incorrect results.

    This is supposed to already be public knowledge, since there are already dozens of different programs that deal with 5th gen .PKM files. So, I would like to avoid re-researching something such as this.

    Thank you in advance for assistance with this matter.
     
  2. DarkStriker

    Member DarkStriker GBAtemp's Kpop lover!

    Joined:
    Mar 15, 2009
    Messages:
    1,957
    Location:
    NIKU!
    Country:
    Norway
    KazoWAR knows this. You might considering PMing him or go to ProjectPokemon and ask there instead.
     
  3. KazoWAR

    Member KazoWAR GBAtemp Advanced Maniac

    Joined:
    Aug 12, 2008
    Messages:
    1,749
    Location:
    Winter Haven
    Country:
    United States
    It should be the same from 4th gen iirc.

    Here is a C# code snippet from my Poké Transfer program.
    CODE//Updates checksum.
    ms.Position = 0x08;
    UInt32 Checksum = 0;
    for (int j = 0; j < 64; j++)
    {
    ÂÂÂÂChecksum += Convert.ToUInt32(ms.ReadByte()) + (Convert.ToUInt32(ms.ReadByte()) * 0x100);
    ÂÂÂÂChecksum = (Checksum - ((Checksum / 0x10000) * 0x10000));
    }

    ms.Position = 0x06;
    ms.WriteByte(Convert.ToByte((Checksum) - ((Checksum / 0x100) * 0x100)));
    ms.WriteByte(Convert.ToByte(Checksum / 0x100));
     
  4. Kyohack
    OP

    Newcomer Kyohack Advanced Member

    Joined:
    Mar 27, 2010
    Messages:
    98
    Location:
    Las Vegas, Nevada
    Country:
    United States
    Thank you. That snippet of code explains everything.
     

Share This Page