As is probably evident by now, I really do not know a lot about what I am doing, mainly because my programming experience is with stuff like C++ and Java…
Yes, I do know basics like what hexadecimal is, AR codes are CPU instructions, etc. But I lack on some of the more advanced stuff and notations, and I am not sure of exactly where I stand in terms of how much I know.
For example, I don’t really know what
00013 022349D4 d h 0 Slot1 PID(W)
means, or how I can change that to give the hex address/1st chunk in an AR code line
(Is it 022349D4? Does that number need to be changed somehow?)
As such, here is a list of what (I think) I know, and what I need:
I thank whoever helps me in advance. (Especially since it will probably be the same people, and I’m sure they are starting to get annoyed by now…)
everything you want to change is encrypted. since you're proficient with java/c++, your best bet is to read about how the encryption works(i think there's a wiki article) and write an app to decrypt the pkm and the re-encrypt it so you know what values you want to change to what. however, if you want to somehow reuse an ar code that does this, that's a much different vastly more challenging story. is this something just for you or something you're making for a lot of people to use? if it's the former, doing so might be a bit easier. we can just cut out the encryption.
e: well, you would need to use the cut encryption on a new game or edit all your pokes to not be encrypted. if everything isn't encrypted with the 4th gen rng, but the game tries to decrypt with it, Bad Things(tm) will happen. srsly.
Is the .pkm file structure the same as the wiki says it is here: http://projectpokemon.org/wiki/Pokem...ure#Encryption ?
Also, pokegen says it can "ignore save file checksum". Would that actually change anything about the pokemon's code (maybe make this easier?), and if so would it still work in-game? I don't care if it would be illegal, but it still needs to not break the game .
For the action replay codes I mentioned for stats (the 2nd half is 0000XXXX), I know they change the desired stat (I assume the encrypted value) to XXXX, and I can calculate XXXX to give me the right number in the stat. Am I right that the first half is the hex address, or is it something completely different? If it is different, would decrypting the .pkm file tell me what the right hex address is so I can use it in assembler?
e: at the link above, it says the stats (and level, I should probably recheck pokegen (although exp using the other stuff ) are encrypted via the PID, which might explain why I could isolate the lines that changed each stat in the pokegen code. Perhaps the ignore checksum stuff in pokegen would allow me to isolate a line that gives the check sum, and what lines give the other values I want. However, I do not know if I am right about the hex address thing in the first place....
Also in X[n+1] = (0x41C64E6D * X[n] + 0x6073) from the link, are * and + bitwise operators?
e2: nvm, the ignore checksum does not seem to change anything in the AR code.... (confirmed by Codr)
e3: better link: http://www.projectpokemon.org/wiki/P..._NDS_Structure although it does lack some info, it is for B/W
Last edited by liaF cipE; Sep 25th, 2011 at 04:26 PM.
I just looked back @ a testing code, and it turns out that 12234A44 was max HP, not attack. In fact, I noticed that all of the endings are 2 away from each other, and (when fixed) the ording will probably be consistant with the pkm structure, as there too are the stats offset 2 away from eachother, with the ordering of current hp, max hp, atk, ... (I will probably double check this). If so, then I might be able to adapt those codes and the ones I isolated from pokegen that changed 2 stats (weirdly enough with the later stat first so AAAAHHHH where A is for atk and H is for max Hp. Current hp was in the first 4 digits in its line, further being consistent) to obtain general codes to fix any offset value in the file.
If this is the case, how could recycle the code so I can get the hex addresses it writes to for the assembler code?
Edit: It turns out that execpt the 1st and last line, the 1st 8 hex digits go in order, adding 4 each time from 0x022349B4 to 0x02234A8C, or a difference of 0xD8, which hits all the pkm offsets execpt the 4 at the end in the trash bites section. (actually, the last code hits the next 4 offsets in the pkm code, so it does get all of them)
Last edited by liaF cipE; Sep 26th, 2011 at 02:03 PM.
Alright, this is the only real important thing: By adapting the pokegen code with the encryption algorithm
I can get AR codes to change the values in the pokemon data, calculate the encrypted value, as well as unencrypt a value and know what value is what. (In say a pokegen code)
So, how can I transfer the AR code into what assembler needs to read at write to the place the code edits?
you would need to decrypt and re-encrypt the data on the fly. using the ar. in assembly. i can see this turning into a mess. i still don;t understand exactly what you're trying to do?
Since PID is constant for ALL pokemon that get the code, I won't have block shuffling issues, and since the stats are encrypted via the PID I won't have issues with check sum changing. (plus I can read the check sum and PID as they are in the codes I can use)
So it might be somewhat annoying, but it should be quite doable. The only issue is getting the hex address so I can get assembler to read/write to where the line writes.
Am I right that it is the 1st 8 hex digits of a line that only writes in values?
The document I'm attching should help you when it comes to the codes themselves. Make sure Word Wrap is off, because reading it with word wrap on can be a little confusing. Just make the window large.
Last edited by Delta Blast Burn; Sep 26th, 2011 at 07:24 PM. Reason: forgot something
looks great! but, what does 'offset' mean....
E: nvm, it looks like it does not really matter unless I do that offset adder thingy
you're gonna want this:
Alright looks good, the hex addresses were what I hoped, so I can actually make the code now. XD Thanks!
During debugging the code seemed to do nothing, so I tried a simple code in assembler and in the raw hex code, but the assembler version did not work, as in it seemed to nothing.
raw hex output from converter and codes:Spoiler
manual hex code that worked:Spoiler
So, what is the issue with the assembler code, and if there isn't one, what in general do I do to the raw hex output to get a working code? Yeah, I know it is supposed to be
"94000130 FFFB0000(run on hitting select, can be changed to whatever)
E0000000 0000XXXX(the Xs here are the number of bytes being run in total, 4 per word)
but the code had 023FE074 012FFF11 built in, and I tried to put in E12FFF1E at the end, but it didn't work.......
edit: I also tried this:Spoiler
note: If someone is about to go test the ar code for themselves, a lvl 100 pokemon with the PID of 1739113929 needs to be the 1st pokemon in the party, and the code should make every stat 0 for said pokemon. (I made the poke I tested with in Pokegen, so I know 100% that it has that PID)
where are you trying this? desmume?
ldr r1, =0x4EBAA14D
ldr r12, =0x2234A40
str r1, [r12]
ldr r1, =0xB4E89F82
str r1, [r12, #0x4]
ldr r1, =0x0E6C13CE
str r1, [r12, #0x8]
ldr r1, =0xAA1A10A6
str r1, [r12, #0xC]
no need for that extra space in the literal pool.
ok, what you want to do is something like this:
the ar just runs the code, so i think something like this should be good.Code:94000130 FFFB0000 023FE074 012FFF11 E0000000 00000044 E92D1002 E59F1024 E59FC024 E58C1000 E59F1020 E58C1004 E59F101C E58C1008 E59F1018 E58C100C E8BD1002 E12FFF1E 4EBAA14D 02234A40 B4E89F82 0E6C13CE AA1A10A6 00000000 023FE074 E3520003 D2000000 00000000
e: also, desmume/no$ don;t keep the ar code handler at its normal spot. they just handle the ar themselves, so the ar hack to create executable code doesn't work on them, i don't think? i should try that now.
also, you can use kodinator for branches and asm to ards to compile, no need for anything else.
e2: yep! the ar hack doesn't seem to work.
here's an example, the backlight adjustment code for white:
you can see, yours is set up just like this code, so it should be working.Code:94000130 FCFB0000 023FE074 012FFF11 E0000000 000000A8 E28F0001 E12FFF10 A21AB5F0 88234C24 80138811 D02A428B 25803490 F0002000 1C06F82A F0002004 2703F826 21404007 D003420B 420B2180 E018D00C 4231210C 2F03D006 1C79D013 F0002004 E00EF816 E0094331 438E210C 2F001C31 1E79D004 F0002004 E002F80A F0002000 BCF0F806 4718BC08 30800000 88222100 D1FC422A 80224A08 88208060 D1FC4228 80220C12 88228061 D1FC422A 21FF8860 47704008 04000130 80028802 023FE074 E3520003 D2000000 00000000