WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: Deathwolf on August 02, 2010, 03:05:10 PM

Title: C0 codetype....
Post by: Deathwolf on August 02, 2010, 03:05:10 PM
execute codetype?
how should this work without any hook address?
what does execute mean?
it only activate it, if you do someting?

C0000000 NNNNNNNN <--- how many instructions
ZZZZZZZZ ZZZZZZZZ<-- which instructions?
ZZZZZZZZ ZZZZZZZZ
4E800020 00000000 <-- blr 4E800020

thanks for any help
Title: Re: C0 codetype....
Post by: wiiztec on August 02, 2010, 03:07:19 PM
It runs once every frame
Title: Re: C0 codetype....
Post by: Deathwolf on August 02, 2010, 03:13:09 PM
can I use instruction from a C2 code on this?
Title: Re: C0 codetype....
Post by: dcx2 on August 02, 2010, 08:38:40 PM
C2 codes hook the game (thus, the hook address).  C0 codes "hook" the code handler, so there's no hook address.

C2 codes have easy access to pointers because they hook while the game is running.  For instance, my Teleportation code has access to Mario's coordinates via the pointer in r3.  They are executed when the game would normally run the hook address.

C0 codes have no easy access to those pointers.  However, C0 codes have easy access to ba, po, and Gecko registers.  C0 codes are run like other codes (04, 28, etc); once per frame by the code handler.

PyiiASMH can assemble C0 codes for you, so you don't need to worry about including the blr, or how many instructions = NNNNNNNN.
Title: Re: C0 codetype....
Post by: Deathwolf on August 02, 2010, 08:45:45 PM
what happens if I do this?

C203CAE8 00000003
3D800000 618C0BB8
919F0030 807F0030
60000000 00000000

code:
lis r12,0
ori r12,r12,3000
stw r12,48(r31)
lwz r3,48(r31)

to C0

C0000000 00000003
3D800000 618C0BB8
919F0030 807F0030
4E800020 00000000

lis r12,0
ori r12,r12,3000
stw r12,48(r31)
lwz r3,48(r31)
blr


Title: Re: C0 codetype....
Post by: dcx2 on August 02, 2010, 08:48:14 PM
Total Fail happens.  C2 codes have easy access to pointers because they hook while the game is running.

When the game is running and it executes instruction 8003CAE8, it just so happens that a useful pointer is in r31.

When the code handler is running and it executes your C0 code, r31 DOES NOT have this useful pointer!
Title: Re: C0 codetype....
Post by: Deathwolf on August 02, 2010, 08:51:10 PM
ohhh okay lol...

how should I write it now to get it worked in C0?
I've never done something like this.
Did you need more information?
Title: Re: C0 codetype....
Post by: dcx2 on August 02, 2010, 08:56:26 PM
C2 codes and C0 codes are not generally interchangeable, even though they both use ASM.  C2 codes rely on the contents of the registers during the hook.  C0 codes never have access to those contents.

Most non-ASM WiiRD codes (04, 28, 4E, 86, etc) can be "ported" to C0 codes.  In some cases, this can make a complicated code shorter.
Title: Re: C0 codetype....
Post by: Deathwolf on August 02, 2010, 09:04:22 PM
so okay I've tried around and got this.

0423EDD4 00000000


code:
.word 0xEDD4
.word 0xEDD4


to C0:
C0000000 00000001
EDD4EDD4 4E800020
Title: Re: C0 codetype....
Post by: dcx2 on August 02, 2010, 09:15:35 PM
lol, no...you still use ASM codes, but they do the same things as WiiRD codes...

WiiRD ->

0423EDD4 00000000
0423ED64 00000000

---

C0 ->

lis r12,0x8023
ori r12,r12,0xED64
li r0,0
stw r0,0(r12)      # 0423ED64 00000000
stw r0,112(r12)      # 0423EDD4 00000000

---

C0 codes aren't really useful until you start getting epic WiiRD codes.  For example, my Mario Size Roller would probably be shorter if I ported it to C0.  http://wiird.l0nk.org/forum/index.php/topic,5791.msg54813.html#msg54813
Title: Re: C0 codetype....
Post by: Deathwolf on August 02, 2010, 09:24:44 PM
this is the code?

C0000000 00000003
3D808023 618CED64
38000000 900C0000
900C0070 4E800020
Title: Re: C0 codetype....
Post by: dcx2 on August 02, 2010, 09:27:09 PM
That looks right but I can't test it because I don't have the game (I don't even know what game it's for)
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 10:41:57 AM
what do you mean with this?

lis r12,0x8023 <---- load into address 8023ED64
ori r12,r12,0xED64
li r0,0 <--- value
stw r0,0(r12)      # 0423ED64 00000000 <--- ???
stw r0,112(r12)      # 0423EDD4 00000000 <--- but what about this?

does it loads only in 8023ED64?
if yes, how to write more than one address into one C0 code?
thanks...
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:07:04 PM
Did you suddenly forget what stw does?

The code loads r12 with the first address to write to, 8023ED64.  Then it loads r0 with the value 0.  Then it writes r0 to 0(r12).  Then it writes r0 to 112(r12).  0x8023ED64 + 112 = 8023EDD4
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 01:09:58 PM
oh but I can't write every time the same value on different addresses...
is there maybe another way?
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:14:14 PM
If the value is different, li r0 with the different value.

If the address is different, you can either re-load r12 with the new address, or you can figure out how far away the second address is from the first and use the displacement - displacement is the 112 in 112(r12).
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 01:19:32 PM
hmm....
does it works again with li or something like that?
btw if I want to write 32 bit, does lis and ori work on this?

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0000
stw r0,0(r12)
stw r0,112(r12)
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:22:20 PM
Yes, you still use lis/ori to load the upper/lower 16 bits.
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 01:27:38 PM
okay thanks.

example:

0423EDD4 00000038
0423ED64 0000002C

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0038
stw r0,0(r12)
lis r0,0x0000
ori r0,r0,0x002C
stw r0,112(r12)

C0000000 00000005
3D808023 618CED64
3C000000 60000038
900C0000 3C000000
6000002C 900C0070
4E800020 00000000

store 00000038 to 8023ED64 and 2C to 8023EDD4.
right?
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:30:20 PM
Almost...

What do you think is going to happen on the bolded line?

lis r12,0x8023
ori r12,r12,0xED64
lis r0,0x0000
ori r0,r0,0x0038
stw r0,0(r12)
lis r0,0x0000
ori r0,r0,0x002C
stw r0,0(r12)
stw r0,112(r12)

btw, lis r0,0x0000 is unnecessary.
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 01:32:11 PM
yep I have edit it.

lis r12,0x8023
ori r12,r12,0xED64 <-- 8 bit
li r0,0x38
stw r0,0(r12)
li r0,0x2C
stw r0,112(r12)

C0000000 00000004
3D808023 618CED64
38000038 900C0000
3800002C 900C0070
4E800020 00000000

my fail lol

if I write stw r0,0(r12) again, it will be overwritten with 2C
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:46:59 PM
 ;D  Learning by doing!

Do you understand that since 112 = 0x70, then 112(r12) = 0x70 + 0x8023ED64 = 0x8023EDD4?

I'm making this up, so don't apply this code.  But pretend with me for a second that we wanted to write 0x1F to 8023EE44.

address = d + rX

8023EE44 = d + 8023ED64

homework...what is d?  (both in hex and decimal)
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 01:52:46 PM
8023EE44 - 8023ED64  = d

d=E0/224
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 01:59:35 PM
 ;D

Last two things...

1) it's okay for offsets displacements to be negative
2) offsets displacements have limits.  the assembler will fail at you if it is too much.
Title: Re: C0 codetype....
Post by: Deathwolf on August 03, 2010, 02:05:05 PM
oh okay thank you dcx2  :)
Title: Re: C0 codetype....
Post by: wiiztec on August 03, 2010, 04:46:56 PM
dcx2 why do you prefer the term displacement to offset?
Title: Re: C0 codetype....
Post by: dcx2 on August 03, 2010, 05:12:34 PM
In particular, in the post back here (http://wiird.l0nk.org/forum/index.php/topic,6566.msg55930.html#msg55930), I had used the term displacement to describe it.

In general, offset is a very generic term.  It can be applied to many places, so I wanted to avoid it.

In the references for the ASM (http://pds.twi.tudelft.nl/vakken/in1200/labcourse/instruction-set/), you will see that it's described as stw rS,d(rA).  I'm pretty sure the d is for displacement, although it could stand for something similar.  I do know that I've seen "base displacement operand" used to describe d(rA) before.  I also know that it's quite common to refer to a branch's immediate field as the branch displacement.