Antar Posted February 2, 2012 Posted February 2, 2012 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): 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...
Antar Posted February 2, 2012 Author Posted February 2, 2012 You can go ahead and close this. I figured it out from here: 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
Delta Blast Burn Posted February 2, 2012 Posted February 2, 2012 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".
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now