Jump to content

Recommended Posts

Posted

Alright, so I'm developing a My Pokemon Ranch save editor. I've figured everything out thus far except how to decrypt the .pkm files. As of now, I allow exporting pokemon for Pokesav to handle any editing, but I'd love to at least be able to display the icon for each pokemon in the box. As of now, they're all egg icons, and you have to export and view in pokesav to see which pokemon you're editing (which makes changing the depositor for specific pokemon pretty danged hard).

I've seen the breakdown of the algorithm here and on Bulbapedia, but no matter what I do, I can't get results. I've tried reversing bytes in bytewords for big/little endian changes, and nothing. I thought this may be the best place to go for this, as there's really no example data to go off of anywhere online that I could find. Chances are I'm misreading the text or misprogrammed something, so if someone who knows this algorithm could help me through a decryption, I'd be quite thankful.

So, here's an example of mine (code broken up as my program uses it):

CODE:

{"6C4BF71F","0000","39AC",

"95E1","747E","D327","B69D","523F","F719","2A57","2CC0",

"FD8C","023C","5755","8CC2","7D33","92EB","888C","1B54",

"9723","9C8E","D706","9DDA","CDF4","32DD","B2AC","0124",

"5276","FCFA","90A7","ADEB","89F3","A23A","B2A0","3210",

"CC26","813E","1056","F4C7","F4A4","8A95","D584","540D",

"3AE7","04B7","8968","C8C1","C22A","64CE","9769","2AB5",

"B092","0E2C","50A5","DA78","4085","D63D","8E5B","F692",

"F672","C612","4F9C","B2FE","9418","37B1","CD85","2847"};

WHAT IT IS:

A Golem (pokemon #76, = 0x4C)

Holding a Blue Scarf (dunno the hex for this)

TID: 20202 = 0x4EEA

SID: 4916 = 0x1334

Level: 31 = 0x1F

XP: 24294 = 0x5EE6

IVs: 15/18/15/0/6/18 => 0x7c9e0348, I think?

So, step 0 would be to find out the block order, I guess:

pv = 0x6C4BF71F = 1816917791

((pv >> 0xD) & 0x1F) % 24

(221791 & 0x1F) % 24

31 % 24

7

So the block order is BADC.

Next is what I assume I'm getting wrong:

Seeding rand with the checksum:

rand(X[n]): X[n+1] = (0x41C64E6D * X[n] + 0x6073) % 0x100000000

rand(chksm) = rand (0x39AC) =

(0x41C64E6D * 0x39AC + 0x6073) % 0x100000000

(0x41C64E6D * 0x39AC + 0x6073) % 0x100000000

(0xED158B2F63C + 0x6073) % 0x100000000

0xED158B356AF % 0x100000000

0x58B356AF

And we take the first 16 bits, so X[1] = 0x58B3.

Now, I found a Japanese site that says to seed rand with the PID, not the checksum. I'm assuming what I've read here is correct, though, and used the checksum. (Even with the PID used, however, the result is incorrect.)

So, an XOR with the first byte word gives us 0xCD52.

We use the output of rand(1) for rand(2):

(0x41C64E6D * 0x58B3 + 0x6073) % 0x100000000

(0x16CA289E4E37 + 0x6073) % 0x100000000

0x16CA289EAEAA % 0x100000000

0x289EAEAA

X[2] = 0x289E

So the second word decrypted is 0x289E XOR 0x747E = 0x5CE0. (I tried using the full 4-byte output as well. Still didn't work.)

Continuing this, we get the decrypted pkm data as:

B:

cd525ce04782bcba9679275cf07b001e

e2ff8da89b21589825994a4e3e70a1a3

A:

1c72e0da7408411203a7d4ba1393e604

7bf8c275546382343dd70d322f6fff62

D:

db3a8382ca683817833a4c4cf4457290

fca5517fb39facdbe6eca6a66897e055

C:

b7f5ecc2673c30262a05299d2a54124e

d2369da6f2cc472180d51e5c6aa308de

Now, since the order is BADC, I expect to see either 0x004C or 0x4C00 at the beginning of the A Block...yet it's not. None of the other values show up either. Obviously, there's something wrong here. Can anyone help me figure out what it is? I'm completely lost.

EDIT: Man, something with the auto-logout and editing features created a duplicate topic somehow. I apologize to the mods. No clue how that happened.

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...