Talk:Pokémon data structure (Generation IV): Difference between revisions

From Bulbapedia, the community-driven Pokémon encyclopedia.
Jump to navigationJump to search
(Added section for checksums; added TO DO list to complete article.)
(Removed my outdated discussion re: checksum.)
Line 29: Line 29:


== Checksum ==
== Checksum ==
A checksum calculation algorithm is outlined (in Deutsch) at [http://www.pokemon-inside.net/forum/viewtopic.php?f=26&t=6592 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?  -[[User:Tsanth|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 <b>[sum of even-numbered bytes in blocks] % 0x100</b>.  However, to get the second byte of the checksum, we need to do <b>([sum of all bytes in blocks] + ([sum of even-numbered bytes in blocks] / 0x100)) % 0x100</b>.  Instead of taking the <i>modulus</i> for the second byte, we need the <i>quotient</i>.  I just tested it on two <i>pkm</i> files I have on-hand; I'll do some more testing later.  -[[User:Tsanth|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)  -[[User:Whivel|Whivel]] 16:14, 9 July 2008 (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)  -[[User:Whivel|Whivel]] 16:14, 9 July 2008 (UTC)


* I have a Python implementation of the pkm encryption code up [http://www.tsanth.com/pokemon/ here].  -[[User:Tsanth|Tsanth]] 06:41, 12 July 2008 (UTC)
* I have a Python implementation of the pkm encryption code up [http://www.tsanth.com/pokemon/ here].  -[[User:Tsanth|Tsanth]] 06:41, 12 July 2008 (UTC)
* My edits to this article are done for tonight.  I am planning a Python-based GUI program to allow viewing/editing Pokémon data (like Pokesav, but the first iteration will deal only with ''pkm'' files); in order to make that program, I will have to map the bitfields in the unencrypted data.  I am planning to make time to update this article with that information after it's available.  -[[User:Tsanth|Tsanth]] 09:32, 12 July 2008 (UTC)


== Data Block's order ==
== Data Block's order ==

Revision as of 11:55, 14 July 2008

TO DO

  • Chart showing character mapping for nickname and OT name
  • Describe layout of pkm blocks in relation to the main save file
  • 0x08-0x09: List species IDs
  • 0x0A-0x0B: List held items
  • 0x14: Explain dual purpose of offset
  • 0x15: List abilities
  • 0x16: Describe bitfield
  • 0x17: List countries
  • 0x18-0x1D: Split up into individual EV bytes (1 byte/EV type)
  • 0x1E-0x23: Split into individual contest stats (1 byte/stat)
  • 0x28-0x2F: List moves
  • 0x30-0x33: Split into PP/moveslot
  • 0x34-0x37: Split into PPUp/moveslot, describe effects out of range [0..3]
  • 0x38-0x3B: Describe bitfield packing of IVs, significance and use of highest two bits
  • 0x40-0x41: Describe spot encoding
  • 0x48-0x5D: Describe limitations on nickname
  • 0x5E-0x5F: List hometowns
  • 0x60-0x63: Describe bitfield packing for contests
  • 0x68-0x77: Describe limitations on OT name
  • 0x78-0x7A: Describe date format
  • 0x7B-0x7D: Describe date format
  • 0x7E-0x7F: List locations
  • 0x80-0x81: List locations
  • 0x82: Describe bitfield packing for Pokérus status (contagious/immune)
  • 0x83: List Poké Balls
  • 0x84-0x85: Describe coding

Checksum

  • 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) -Whivel 16:14, 9 July 2008 (UTC)
  • I have a Python implementation of the pkm encryption code up here. -Tsanth 06:41, 12 July 2008 (UTC)

Data Block's order

I'm analizyng pokesav. I try to understand encrypt algorithm. I found the system used by ds game for ordering the blocks. i'll test it and may write the algorithm -Whivel 20:45, 9 July 2008 (UTC)