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########.
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
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?
b 0x0C 4800000C
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?
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
Used C6 and it worked like a charm! Thanks!
This (http://wiird.l0nk.org/forum/index.php/topic,3481.0.html) topic might also provide some information.
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
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
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.