WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: wiiztec on April 16, 2010, 10:37:14 PM

Title: Make a game execute an ASM routine when it normally wouldn't?
Post by: wiiztec on April 16, 2010, 10:37:14 PM
I'm trying to make this code's effect toggleable in the middle of a match

this is just jose gallardo's control all characters with player 1's controller brawl code after I added button activators and switches
284F7880 00008000
CC000000 00000001
48000000 815E7624
DE000000 80008180
140001DC 00000000
140001E0 00000000
E0000000 80008000
284F7880 00008000
CC000000 00000001
48000000 815E7628
DE000000 80008180
140001DC 00000000
140001E0 00000000
E0000000 80008000
284F7880 00008000
CC000000 00000001
48000000 815E762C
DE000000 80008180
140001DC 00000000
140001E0 00000000
E0000000 80008000
284F7880 00008000
CC000000 00000001
48000000 815E7630
DE000000 80008180
140001DC 00000000
140001E0 00000000
E0000000 80008000

The problem is the game only reads these values at the CSS, is there some kind of way I could make the game read the values in the middle of a match? could I use a C0 code to jump to the routine the game uses when it read these values, or would the jump have to be bigger than what can be done with 16 bits?
Title: Re: Make a game execute an ASM routine when it normally wouldn't?
Post by: dcx2 on April 17, 2010, 12:15:30 AM
It's really difficult to just "call" an ASM routine randomly, because it requires that certain values be set up in certain registers.  If you take the time to set up and tear down the registers, you might be able to get the ASM routine to run.

I think the better option would be to find the ASM that reads the values, and follow it back to see which branch decides whether to run that ASM.  You might be able to put in a button activator that tricks the game into believing it's supposed to execute that branch.

You could also try to use breakpoints to figure out where the values that are read are going, and you could instead over-write their destination.
Title: Re: Make a game execute an ASM routine when it normally wouldn't?
Post by: wiiztec on April 17, 2010, 02:57:25 AM
I tried the second option you proposed, a while ago I had read your guide about following the stack but I think I have come across a scenario not covered by it, I had followed the ASM 3 stwu's up but the bl that should lead to the 3 stwu leads nowhere even close to it farther away than a simple jump or branch could lead to. the 3rd stwu is at 806876D4 the bl that should lead to it leads to 8002DC74
Title: Re: Make a game execute an ASM routine when it normally wouldn't?
Post by: dcx2 on April 17, 2010, 04:39:25 AM
Remember that the goal isn't to follow the stwu's until the beginning, but to follow the stwu's back until you get to code that gets called once per frame.  Somewhere along the way, some code will be making a decision about whether to call the ASM you want.

There are two ways to walk the stack (three actually, if you include black arts).  Look at the LR during the stwu, and that should point you back in the right direction.  If not, find the blr at the end of the function, and follow that back.  Sometimes the bl won't match, but if it doesn't, just Step into the bl and follow it along..it should jump to the stwu in relatively short order, if it's going to.

Or, if you like black magic, you can try to parse the stack frames for the LR Save Word (the mflr r0, stw r0 stores the LR Save Word), but it's weird 'cos the LR Save Word and Back Chain Word are saved to the top of the *previous* stack frame.

If you can read datasheet, then check this out.  https://www-01.ibm.com/chips/techlib/techlib.nsf/techdocs/852569B20050FF77852569970071B0D6/$file/eabi_app.pdf

Section 5 goes into detail regarding stack frames.  You can use the Back Chain Word and LR Save Word to walk the whole call stack without even following the disassembly.
Title: Re: Make a game execute an ASM routine when it normally wouldn't?
Post by: wiiztec on April 17, 2010, 05:01:05 AM
I was looking to follow it back to an instruction that excuted during a match instead of just the CSS and that was the bl that lead to 8002DC74