Quote:
Originally Posted by Magic
Code:
push {r0-r1, lr}
mov r0, #0xValue @changes r0 to 0xValue?
ldr r1, .var @loads variable value to r1
strh r0, [r1] @stores r0's value to the var
pop {r0-r1, pc}
All this lingo still confuses me XD.
Sorry I'm not sure what you mean :<. Your code doesn't have any locations other than the var, so how can it set a byte to the value of the var? It might have just been I wasn't clear in my last post >< haha.
Also in regards to your tutorial (and our VMs) how do you know when you need to 'hook' and things?
Latest attempt of a routine. Think I must have oversimplified something? I get nothing ><. It runs but obviously not doing what I'd like it to XD. Vague comments about what I think ought to be happenin on the side :').
It now tells me 55 - which is correct! :o 50+5 power. How can I then extend this routine to replace the 50 (0x32) in the ROM with 55 (0x37)?
IM SO SORRY FOR ALL THE NOTIFICATIONS ;-; /thousanth edit
|
OK, so when you do "ldr r0, move_data" you don't load it as a byte. move_data is a symbol which represents a pointer (in this case 0x8250CB8 + 1). We want a byte at that pointer so we do:
ldr r0, move_data @load the actual pointer
ldrb r0, [r0] @load a byte from the value of the pointer
If you did ldrb r0, move_data, it would just take move_data as a hex value and load the first byte of it, rather than the first byte of the value it's pointing to (power).
The rest of this is right. Also you seem to be confusing yourself with the names on the bottom. They're just definitions. It's the same thing to do ldr r0, move_data as it is to do ldr r0, =(0x8250CB8 +1).
Addressing your questions about what I've said last time, 0xValue is just a name I came up with. It's supposed to be some arbitrary, valid, constant. Replace it with 0xA or 0x50 or whatever your favorite hex value is.
mov r0, #0x50 @Sets r0 to be 0x50
ldr r1, =(0x20370D0) @loads address of Lastresult into r1. I.e pointer to the value in 0x800D (last result)
strh r0, [r1] @stores 2 bytes of whatever is in r0 into the address/location specified by r1. In this case stores 0x50 in the last result
I hope you see what we're doing with the pointers/symbols/storing now. With that out of the way I can address hooking.
I'm going to explain assuming you already know what a hook is. You basically know that a hook is required when you're reworking or adding additional features to existing game code. In this case you're changing the damage of a move's power based on badges. Thus you're added a feature to existing game code. If you were to just paste your code over the existing code at that region, then obviously you would be overwriting some other important code. This is why we place a hook.
Sometimes it's possible that the game code lends itself to be easily reworked and thus you just overwrite some existing bytes to do that (an example would be my "catch trainer's pokemon" thing). In these cases you don't need hooks (though it's kind of rare in comparison).
I should warn you, to hook successfully into some routines are harder than others. You need to analyze the code at said routine and note to yourself which registers are free, which registers contain information you need after you hook and of course which register you will use for the hook. In complex functions you often don't have a lot of resources, so you need to draw conclusions based on what the analyzed code is like.
Worst case scenario is usually that there's no registers you can use for the hook at the place you want to hook from. If that's the case you just hook early enough to a point where there are registers available and just derive their values and do your code from where you wanted to hook. OK, that last part doesn't make sense unless you've experienced what I'm talking about :P
This last paragraph isn't that important anyways, just me rambling, lol.