liaF cipE Posted September 18, 2011 Posted September 18, 2011 I was looking into the manually set stats for a code I'm trying to make, (I want to change them based on a formula, and they will only be used where both species and PID (and the capture/met stuff) are constant) I found the hex values affected by the values I set, and they seemed to be calculated in an unusual way... Thus far, I have found ineligant ways to calculate some of them to edit an individual stat, but it seems like they are calculated with some sort of bitwise operator.... Only I have no idea what exact formula it is... So, my question is how the hex values pertaining to the manual editing of stats are calculated? If it helps, here are all the values that differed in the pokegen codes between two pokemon where the only difference was what their stats were set to: 02234A40 XXXXXXXX (has to do with hp somehow, but the next one seemed to work by itself...) 02234A44 XXXXXXXX (early digits changed by atk. later ones by hp.) 02234A48 XXXXXXXX (later digits changed by def. early by splAtk?) 02234A4C XXXXXXXX (early by speed? later by spl def?)
Delta Blast Burn Posted September 18, 2011 Posted September 18, 2011 The encryption uses the pseudorandom number generator (PRNG), a linear congruential generator. Elements of the PRNG can be described with the recursive function: X[n+1] = (0x41C64E6D * X[n] + 0x6073) To decrypt the data, given a function rand() which returns the upper 16 bits of consecutive results of the above given function: Seed the PRNG with the checksum (let X[n] be the checksum). Sequentially, for each 2-byte word Y from 0x08 to 0x87, apply the transformation: unencryptedByte = Y xor rand() Unshuffle the blocks using the block shuffling algorithm above. To encrypt the data: Shuffle the blocks using the block shuffling algorithm above. Seed the PRNG with the checksum (let X[n] be the checksum), Sequentially, for each 2-byte word Y from 0x08 to 0x87, apply the transformation: unencryptedByte = Y xor rand() ^^ From the Wiki^^
Bond697 Posted September 18, 2011 Posted September 18, 2011 this is in the wrong place. the spots you're trying to edit are the pokemon(pkm files) in memory: 00013 022349D4 d h 0 Slot1 PID(W) 00014 02234AB0 d h 0 Slot2 PID(W) 00015 02234B8C d h 0 Slot3 PID(W) 00016 02234C68 d h 0 Slot4 PID(W) 00017 02234D44 d h 0 Slot5 PID(W) 00018 02234E20 d h 0 Slot6 PID(W) (from my ram watch file) the pid is right at the beginning of the pkm. are the numbers you found the current hp/atk/etc or the ivs, or the evs? i'm pretty sure they're unencrypted at that point, so that shouldn;t be a problem. e: i think i see. you're trying to edit the party stats in ram. each stat is a short, so 2 bytes. keep in mind, though arm cpus can run in big or little-endian, the nds uses little endian. you'll have to reverse what you're seeing in memory if you have the memory viewer set to 8-bit.
liaF cipE Posted September 18, 2011 Author Posted September 18, 2011 this is in the wrong place.the spots you're trying to edit are the pokemon(pkm files) in memory: 00013 022349D4 d h 0 Slot1 PID(W) 00014 02234AB0 d h 0 Slot2 PID(W) 00015 02234B8C d h 0 Slot3 PID(W) 00016 02234C68 d h 0 Slot4 PID(W) 00017 02234D44 d h 0 Slot5 PID(W) 00018 02234E20 d h 0 Slot6 PID(W) (from my ram watch file) the pid is right at the beginning of the pkm. are the numbers you found the current hp/atk/etc or the ivs, or the evs? i'm pretty sure they're unencrypted at that point, so that shouldn;t be a problem. I changed the Stat number (under the Stats section, with the manual stat box checked), which cooresponds to the actual stat the pokemon has. I was looking into how the pokegen programs generates those values, so I could set HP=386 for example, and know, given a certain PID (and species?) what the X's in 02234A40 XXXXXXXX should be edited to in the code. I used pokegen to make a pokemon in the pc, put it in my party and used 94000130 FFFB0000 02234A44 XXXXXXXX D2000000 00000000 which changed the hp stat to what it was from the pokegen code with the exact same pokemon, only the HP stat was set to the value from the pokegen code. (I don't remember what the x's were...) I found that: 02234A40 is changed by hp, but it doesn't really seem to matter as the other one worked on its own.... 02234A44 value is changed by the hp(changes the last 4 digits) and atk(first 4 digits) 02234A48 value is changed by def(last 4) and speed(first 4) 02234A4C value is changed by splatk(last 4) and spl def(first 4) As the earlier code, using only one line of pokegen code, changes the 02234A44 value which, in this case, changed the HP stat (as I only changed the relavent digits), changing those hex values appropriately would manually set the stats to how I want. (I know the PID as the pokemon being edited are made with pokegen in the first place) The problem is, I don't have a good formula for how pokegen gets those values, so I put this thread here to learn how pokegen comes up with those values. Edit: techincally the stat values from pokegen only effect the last 3 digits in their range, not all 4 (ie "first four means" xXXXxxxx while "last four" means xxxxxXXX)
Delta Blast Burn Posted September 18, 2011 Posted September 18, 2011 (edited) Formulae for calculating stats are at http://www.serebii.net/games/stats.shtml Also, if you want codes that only edit one stat try: 12234A44 0000XXXX atk. 12234A46 0000XXXX current hp 12234A48 0000XXXX def. 12234A4A 0000XXXX sp. atk 12234A4C 0000XXXX speed 12234A4E 0000XXXX spl def Note* all are little endian Edited December 30, 2011 by Delta Blast Burn
liaF cipE Posted September 18, 2011 Author Posted September 18, 2011 Formulae for calculating stats are at http://www.serebii.net/games/stats.shtmlAlso, if you want codes that only edit one stat try: 12234A44 0000XXXX atk. 12234A46 0000XXXX hp 12234A48 0000XXXX def. 12234A4A 0000XXXX sp. atk. 12234A4C 0000XXXX speed 12234A4E 0000XXXX spl def I already knew the stat formula, and I wanted to know how pokegen translated manually setting a stat as 423 for example, to the hex code, as it was no where near linear. In one case, incrementing a stat by one made delta Hex = +1, -3, +1, +5 and so on, (0 was F82) yet the 3rd hex digit to the left went down when it was supposed to go up Then, not all stats even followed that pattern... So I thought it could be some weird bitwise operator or something. Anyway, that is kind of moot now, assuming you put the hex equivalent of the number desired in for the X's... Thanks for the help! Edit: realized I needed the 02234A40 value for hp to be right, the hp code does not change current hp(though 12234a42 does ), and those codes gave me REALLY weird values(always with a "?"), even for small numbers like 100 (64 in hex), and despite the same input they all were different .... they do work with the values pokegen gives , but how are they even calculated in the first place? ex: 1 for max hp -> 9F83, 2 for max hp -> 9F81 how are THOSE values determined?? How would one translate X where 0<=x<=FFFF(65535 in dec) to the right hex code such that when the hex equivalent of X is put into the code the stat returns X?
liaF cipE Posted September 19, 2011 Author Posted September 19, 2011 wow, I just realized how stupid this is. If it is any bitwise function, it is probably xor so there are no overlappings (like AND with a 0 in the constant input) Plus xor looks like it works anyway!
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