WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: live2play on April 18, 2010, 06:30:07 PM

Title: Replacing ASM with stw
Post by: live2play on April 18, 2010, 06:30:07 PM
I'm trying to get a line of assembly to change the line of assembly just above it.  For instance:

Original code
802666A4:  FC010040   fcmpo   cr0,f1,f0
802666A8:  4C401382   cror   2,0,2
802666AC:  40820024   bne-   0x802666d0
802666B0:  881F0180   lbz   r0,384(r31)

I created a code using the Gecko button activator for the game that triggers a C2 code that switches the fcmpo cr0,f1,f0 to fcmpo cr0,f1,f1.  This works without an issue.  However, I then added the following  C2 code at the cror 2,0,2 command, but this code only consistently does the cror, not the rewrite of the assembly at 802666A4.

lis r5,0xFC01
ori r5,r5,0x0040
lis r6,0x8026
ori r6,r6,0x66A4
stw r5,0(r6)
cror 2,0,2

Given that the cror always executes right after the fcmpo, why isn't the assembly at the fcmpo address getting rewritten back to fcmpo cr0,f1,f0 ?
Title: Re: Replacing ASM with stw
Post by: dcx2 on April 18, 2010, 09:01:04 PM
So you have two things writing to 802666A4?  They might be getting into a fight.  Try setting a write breakpoint a few times on 802666A4 and see who writes to it.

Also, there should be an instruction that moves a float register from one to another (fmr, I think).  Instead of re-writing an instruction in memory, you should consider copying f1 into f0 when your certain condition is met.
Title: Re: Replacing ASM with stw
Post by: live2play on April 19, 2010, 03:54:31 AM
I would think that nothing would write to 802666A4 after the game is loaded in the Wii as this is the assembly code area, not variables.  Is my thinking correct?  Also, I think that I'll first try to use the button pressed/not pressed code you mentioned in another post first.  It seems that it would be easier to just set the value of 802666A4 using that code.
Title: Re: Replacing ASM with stw
Post by: live2play on April 20, 2010, 12:21:13 AM
I was able to get the desired effect by using the pressed/depressed button code.  Thanks again!
Title: Re: Replacing ASM with stw
Post by: dcx2 on April 20, 2010, 12:39:05 AM
Quote from: live2play on April 19, 2010, 03:54:31 AMI would think that nothing would write to 802666A4 after the game is loaded in the Wii as this is the assembly code area, not variables.  Is my thinking correct?

Well, the Wii only loads the game code once, but in order to patch the fcmpo so that it can be changed, *someone* has to write to 802666A4.  That "someone" would be your code(s).

In fact, if you were to make a simple nop-code, and then set a write breakpoint on the address you're noping, you'll see the code handler writing to that address each frame.