ASM -> WiiRD b 0x######## command

Started by live2play, May 01, 2010, 03:48:19 AM

Previous topic - Next topic

live2play

If I know of an address that I want to branch to and I want to add that in as a C2 code using ASM -> WiiRD, how do I do that.  The tool does not allow b 0x########.

wiiztec

#1
Use the C6 codetype instead

C6XXXXXX YYYYYYYY : branch from XXXXXX+ba to YYYYYYYY It writes, at XXXXXXXX+ba, a "b YYYYYYYY" instruction.

If you're going to do it with a C2 code you'll have to count how far away the address you want to jump to is from the address your C2 code hijacks and it cannot be more than FFFF
If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

live2play

#2
Cool! Thanks!

So, if my C2 code hooks at 802555A4 and I want to add a branch (b) to 802555B0 in my C2 code, what would the command look like in ASM -> WiiRD?

wiiztec

If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

live2play

Ok, so I basically take the <destination address> - <C2 address>, right?  Also, it doesn't matter where in my C2 code this branch is located as it is always relative to the C2 hook address, right?

wiiztec

No it's relative to the address of the b instruction

Hmm yeah forget what I said before you should probably just use the C6 codetype
If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

live2play

Used C6 and it worked like a charm!  Thanks!

Romaap

#7
This topic might also provide some information.

dcx2

Wow, that makes so much sense.  I'm surprised I didn't think of it earlier.

You should be careful that ctr and r12 are not being used.  You can push and pop r12 before the beqctr, but I don't think there's any way to push and pop ctr, since it's needed for the beqctr.

You know, you could also use mtlr and blr's instead of bctr's.  lr is usually more safe than ctr.

lis r12
ori r12
mtlr r12
beqlr

wiiztec

r12 is what the code handler uses as a pointer when it writes your codes every frame, so I think it's pretty safe to say that it's always safe
If there's any code at all that you want to be button activated, or even able to toggle on & off, and I have the game, just PM me and I'll make it happen

dcx2

The code handler pushes all the registers onto the stack before it does its work, and then pops them all off when it's done.  That's why it can use all the registers safely, because it will restore them when it's done.