+ Reply to Thread
Results 1 to 3 of 3

Thread: pkm file fine in Pokesav, garbled in Pokegen

  1. #1

    pkm file fine in Pokesav, garbled in Pokegen

    So I just finished a project called CC4Wifi (Challenge Cup for Wi-Fi), which generates pkm files for random pokemon with random movesets, as per "Challenge Cup" rules.

    Here's the weird thing, though--while the files import fine into Pokesav, when I try importing one into Pokegen, it's complete nonsense.

    I've done some additional testing. My template file imports fine. But when I load the template, change just *one* byte (see below)--even something as innocuous as an EV value--and write it back, Pokegen refuses to read it any more. Does Pokegen have some sort of weird checksum thing that Pokesav does not? Or is something else going on?

    Test code (in python):
    Code:
    from array import *
    p=array('B'); p.fromstring(open("template.pkm",'rb').read()) #template.pkm imports fine into Pokegen
    p[0x18]=120
    p.tofile(open("test.pkm",'wb')) #test.pkm imports as garbage
    And I've tried looking at the files in a hex editor--the only difference between the files is indeed the value at 0x18.

    Edit: Looked back over this handy reference. So there is indeed a checksum. Now I just gotta figure out how to calculate it...

  2. #2

    Re: pkm file fine in Pokesav, garbled in Pokegen

    You can go ahead and close this. I figured it out from here:

    Code:
    checksum=0
    for i in range(8,137,2):
    	checksum = (checksum+p[i]+p[i+1]*256)%65536
    p[0x06]=checksum%256
    p[0x07]=checksum/256

  3. #3
    Like A BOSS Delta Blast Burn's Avatar
    Join Date
    Apr 2009
    Location
    The Distortion portion of a neighboring universe
    Age
    18
    Posts
    597

    Re: pkm file fine in Pokesav, garbled in Pokegen

    The checksum(cs) is the sum of words starting at 0x06, in an unencrypted pkm file(pid is bytes 0x00-03, cs is 0x04-05) just take the lowest two bytes little endian(le) ie if the sum of bytes is 0x3144bc then the cs would be "bc 44".

    Bananas!

+ Reply to Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
PPN Top 50