Talk:Pokémon data structure (Generation IV)

From Bulbapedia, the community-driven Pokémon encyclopedia.
Revision as of 14:15, 9 July 2008 by Whivel (talk | contribs)
Jump to navigationJump to search

A checksum calculation algorithm is outlined (in Deutsch) at Pokemon Inside. I coded up a version of it in Perl; the first byte of the checksum calculates properly, but the algorithm listed there doesn't seem to work for the second byte. Can anyone shed some light on this? -Tsanth 23:15, 12 December 2007 (UTC)

  • Okay, I found the problem: the algorithm described on the page is incorrect in regards to the second checksum byte. The first checksum byte is indeed calculated as [sum of even-numbered bytes in blocks] % 0x100. However, to get the second byte of the checksum, we need to do ([sum of all bytes in blocks] + ([sum of even-numbered bytes in blocks] / 0x100)) % 0x100. Instead of taking the modulus for the second byte, we need the quotient. I just tested it on two pkm files I have on-hand; I'll do some more testing later. -Tsanth 00:00, 13 December 2007 (UTC)
  • I found another way to calculate checksum. I analyzed a software, Legit.exe and it use another algorithm.

It divides the 80 bytes that describe the pokemon in groups of two bytes (words). The groups are added to each other. You take the last word's bytes. Note: you must adjust the bytes of words (from little endian to big endian), sum it, adjust it again and then divide the result. XX YY ZZ AA BB CC (the 80 bytes) -> YY XX AA ZZ CC BB (adjusted words) -> YY XX + AA ZZ + CC BB (sum) -> MODULE 0x100 (take the last word) -> MM NN (checksum) -Qhivel 16:14, 9 July 2008 (UTC)