WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: doomkaiber001 on November 17, 2010, 07:24:33 PM

Title: Structure of codes
Post by: doomkaiber001 on November 17, 2010, 07:24:33 PM
Can someone teach me about the structure of codes? Thanks.
Title: Re: Structure of codes
Post by: Bully@Wiiplaza on November 17, 2010, 08:21:05 PM
there are a lot of different code structures...
ask for specific ones.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 17, 2010, 08:32:41 PM
How about this one?

Super Smash Bros Brawl PAL
P1 Samus' Blaster is always full   - agrs700

4A000000 81000000
1425E9C6 00000007
Title: Re: Structure of codes
Post by: James0x57 on November 17, 2010, 10:34:10 PM
code lines in this post from agrs700

First line:
4A000000 81000000 (http://geckocodes.org/index.php?arsenal=1&ct=4A000000%2081000000)

Second line:
1425E9C6 00000007 (http://geckocodes.org/index.php?arsenal=1&ct=1425E9C6%2000000007)


And that code should have a 3rd line:
E0000000 80008000 (http://geckocodes.org/index.php?arsenal=1&ct=E0000000%2080008000)
Title: Re: Structure of codes
Post by: wiiztec on November 17, 2010, 11:29:23 PM
Or you could just do this

0525E9C6 00000007
Title: Re: Structure of codes
Post by: James0x57 on November 18, 2010, 12:34:14 AM
Also true. lol
Title: Re: Structure of codes
Post by: dcx2 on November 18, 2010, 03:20:02 AM
Codes are arranged in lines of two 32-bit values in hexadecimal.  Thus, 0525E9C6 00000007 as wiiztec said.  Each hex digit corresponds to 4 bits, 8 digits * 4 bits = 32 bits total.  I will refer to these as the "first code word" (0525E9C6) and "second code word" (00000007)

The first 7 bits of the first code word determine the code type.  The remaining 25 bits of the first word, and all 32 bits of the second word, will have different meanings depending on the code type.  For a list of the code types, see the following page.

http://geckocodes.org/index.php?arsenal=1

Following is a diagram of the binary breakdown of the first code word, assuming the remaining 25 bits are an address (which is typical, but not always true)


Hex Digit  |         First         |        Second         |        Third     |   Fourth ...
Bit#       |   0   1   2   |   3   |   4   5   6   |   7   |   8   9  10  11  |   12     ...
is         |   Code Type   | ba/po | Code Sub Type |  address or operands...................


The first 8 bits of the first word are 05.  In binary, this is 0000 0101.  The code type is 000, which is the Direct RAM Write Code Type.  The 0 indicates this uses the ba.  The 010 indicates a 32-bit Write Code Subtype.  The remaining 1 is added to the address, which is why 0525E9C6 writes to the address 8125E9C6.  The value written is specified by the second word.

Other code types are more complicated; they may make use of the second code word or even extra lines to specify other parameters (like the Serial Write), or the remaining 25 bits of the first word may not be an address (like Gecko Register Code Types).  But the first 7 bits of the first word always determine what the other bits mean.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 18, 2010, 04:47:41 PM
Ok, there are a couple of things I don't quite understand;
I couldn't find 05 in the link?
And why does 0525E9C6 become 8125E9C6? I understand the 'Add 1' part, but what makes the 05 become 8? Thanks for all the help.
Title: Re: Structure of codes
Post by: GMO on November 18, 2010, 04:55:19 PM
Quote from: doomkaiber001 on November 18, 2010, 04:47:41 PM
Ok, there are a couple of things I don't quite understand;
I couldn't find 05 in the link?
And why does 0525E9C6 become 8125E9C6? I understand the 'Add 1' part, but what makes the 05 become 8? Thanks for all the help.

8125E9C6 is the RAM address
Title: Re: Structure of codes
Post by: dcx2 on November 18, 2010, 05:11:03 PM
You didn't find an 05 code type because there isn't one.  It's an 04 code type.  Remember, hex digits are 4 bits, but code types only use 7 bits.  That 8th bit - a 1 in the case of an 05 - is part of the address.

This is a cause of great confusion.  Just remember that code types will never be odd because that last bit isn't part of the code type.  If the second digit is odd, subtract 1.

By default, the ba and po are 80000000.  Additionally, only the first 7 bits of the ba are used, but all 32 bits of the po are used.  There are other code types that modify the ba and po, so that you can access other memory ranges like 9xxxxxxx.

Recall the colored text above.  Notice how the 04 code type uses the ba, and the 14 code type uses the po.  If the first digit is even it uses the ba, and if it's odd it uses the po instead.
Title: Re: Structure of codes
Post by: James0x57 on November 18, 2010, 05:45:39 PM
Since you're just starting with this, if you need replies with less (potentially intimidating) technical jargon, don't hesitate to ask. ^^
Title: Re: Structure of codes
Post by: doomkaiber001 on November 18, 2010, 06:04:40 PM
lol thanks James! So by writing, you mean? I have an idea, but don't want to be humiliated if...
Title: Re: Structure of codes
Post by: James0x57 on November 18, 2010, 06:51:47 PM
Not a problem!

'write' is to change something in memory


(all following numbers are hexidecimal)


For your previous question:
The 80000000 that is automatically added to calculate the address comes from one of two places..
If the first digit of the write codetype is:
* even: then you use the 'ba' to get that 80000000
* odd: then you use the 'po' to get that 80000000

This code type: http://geckocodes.org/index.php?arsenal=1&ct=42 will change the 'ba' to other values instead of the default 80000000.

This code type: http://geckocodes.org/index.php?arsenal=1&ct=4A will change the 'po' to other values instead of the default 80000000.

This code type changes them both AND breaks out of any if/then logic in the code: E0000000 80008000 (http://geckocodes.org/index.php?arsenal=1&ct=E0000000%2080008000)




When the second digit of a codetype is odd, you're adding 1000000 to the address calculation. (see dcx2's post if you really want to know why)



So:
15222220 0000000A
first digit is odd, so use 'po' (default value is 80000000)
second digit is odd, so add 1000000
Address = 81222220
Title: Re: Structure of codes
Post by: doomkaiber001 on November 18, 2010, 07:07:23 PM
Ok! That makes alot of sense. So... How is the second code word dependant on the first? How do you determine it?
Title: Re: Structure of codes
Post by: James0x57 on November 18, 2010, 07:43:50 PM
The second word in a 04 codetyped code is simply the value that you write to the address!

If the code was to write how much money you had, the value would be that amount (in hexadecimal).


Make sense? Do you need a better understanding of the memory address/value relation?
Title: Re: Structure of codes
Post by: doomkaiber001 on November 18, 2010, 07:49:11 PM
Yes... I think I understand (the money part). You're probably right. I do need a better understanding of memory.
Thanks!
Title: Re: Structure of codes
Post by: doomkaiber001 on November 18, 2010, 09:06:18 PM
http://wiird.l0nk.org/forum/index.php/topic,5249.msg60636.html

Is this an example of writing values to memory, but with using ASM? I think it is.

MOD EDIT: fixed link
Title: Re: Structure of codes
Post by: James0x57 on November 18, 2010, 10:16:18 PM
Memory is an ice cube tray.
Each place for a cube is numbered.
Each of these holes are filled with different flavors.

The number of the hole is the address, the flavor is the value.


80123450 is an address that holds a value of something (health, money, color, speed, etc).



I can't look at the asm example right yet; will reply later
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 07:07:50 AM
That makes sense. :)
Title: Re: Structure of codes
Post by: dcx2 on November 19, 2010, 03:40:31 PM
Just a heads up, I'm going to move this thread out of OT board to the WGHH board...because this isn't actually an off topic discussion.  Not sure how it got here...
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 04:07:54 PM
Ok.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 07:22:11 PM
Well, Is it an example of memory writing?
Title: Re: Structure of codes
Post by: James0x57 on November 19, 2010, 08:53:47 PM
That url doesn't work for me.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 09:47:44 PM
Ok. Its 'An Introduction To Cpu Architecture and ASM'. I found it in The colective under Wii Game Hacking Guides.
Title: Re: Structure of codes
Post by: dcx2 on November 19, 2010, 10:25:37 PM
I fixed the link for you, you left off the .org part and that's why it wouldn't work.

In that link, the ASM instruction "stw" writes to memory.  Memory is represented by the box "MEM" in the pictures.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 10:30:44 PM
Thanks for fixing the link :) Do you follow the / a similar process in the link whenever you write a value to memory?
Title: Re: Structure of codes
Post by: dcx2 on November 19, 2010, 10:40:15 PM
The link is an explanation of what happens while a game is running on the Wii.  It's meant to give you an example of how data is flowing to and from memory, and how ASM instructions modify the values.

If you write an ASM code, then you will probably be using stw or some derivative (sth, stb, stwu, etc).  When the CPU executes your stw instruction, it will write to memory.

You don't need ASM, though.  When you use code types like the 04 code type, you are telling the code handler to do the writing for you.  If you were to follow the code handler along while it executes your 04 code, you would eventually see a stw somewhere.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 19, 2010, 11:55:03 PM
So, let's see if I understand this;
0525E9C6 00000007
05 = 0000 0101
0 = ba ( Because its a Positive Number)
1 = Add to address

So...
ba (add 80000000 to address)

8125E9C6 Is the address that 7 has to be written to.

I hope thats right. It seems so.
Title: Re: Structure of codes
Post by: dcx2 on November 20, 2010, 01:13:20 AM
Yes, you're right.  One minor correction though...it's not ba because it's positive, it's ba because it's even.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 20, 2010, 08:37:12 AM
Yeah sorry! I did mean that but it was late... Anyway, if you could help me with one other thing. What about multi-lined codes?

Sorry if I'm asking too much.
Title: Re: Structure of codes
Post by: Bully@Wiiplaza on November 20, 2010, 06:14:06 PM
Quote from: doomkaiber001 on November 20, 2010, 08:37:12 AM
Yeah sorry! I did mean that but it was late... Anyway, if you could help me with one other thing. What about multi-lined codes?

Sorry if I'm asking too much.

like this?

0525E9C6 00000007
0525E9F6 00000008
0525E9C6 00000009
0525E9A6 00000007
Title: Re: Structure of codes
Post by: doomkaiber001 on November 20, 2010, 07:18:40 PM
Yeah exactly that.
Title: Re: Structure of codes
Post by: James0x57 on November 20, 2010, 11:51:10 PM
It's just doing multiple things. Writing to change multiple values.


Multi line codes can do other things too- like comparisons, so it only writes on a condition.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 21, 2010, 08:43:31 AM
Ok.

Blue Shell Speed Modifier MKW
048A5BC4 43960000
048A5C24 43960000
048A5C34 43960000

Why is the speed value being stored to three addresses?
Title: Re: Structure of codes
Post by: Bully@Wiiplaza on November 21, 2010, 09:48:43 AM
Quote from: doomkaiber001 on November 21, 2010, 08:43:31 AM
Ok.

Blue Shell Speed Modifier MKW
048A5BC4 43960000
048A5C24 43960000
048A5C34 43960000

Why is the speed value being stored to three addresses?
maybe it´s only one of them which is needed and the hacker just took the 3, because he was too lazy to find out, which one works.
However, I think that this 3 lines are all needed... could happen.
Title: Re: Structure of codes
Post by: doomkaiber001 on November 21, 2010, 09:52:07 AM
Hold on... If they aren't needed, couldn't they be changing something important? And, if each line is needed, what exactly are they needed for? Similar codes (for both red and green shells) contain only one line of coding.
Title: Re: Structure of codes
Post by: dcx2 on November 21, 2010, 03:35:30 PM
That's just the way some hacks are.  For instance, Okami is a game where the main character can double jump.  I wrote a code that allowed you to "infinite jump" - you could keep double-jumping after the double-jump.

One would think this is as simple as nopping the stw that wrote the value that says "I have now double jumped", but it turned out I needed to modify no less than *six* places in order to make the code work without glitches.  If you modify only one, then the infinite double jump only works sometimes (i.e. when rising, but not falling).
Title: Re: Structure of codes
Post by: Bully@Wiiplaza on November 21, 2010, 03:48:40 PM
yeah, the 3 lines are needed to make it always work.
MKWii is a bit weird in this case, you need more than jut one adress to make it working in every game mode.
Actually, it also works online, should be one of the purpoises. (this one is harmless anyway, because it won´t change the game play for others when the blue shell is only slower/faster for your screen xD)
Title: Re: Structure of codes
Post by: doomkaiber001 on November 21, 2010, 04:51:09 PM
So each address is for one game type?
Title: Re: Structure of codes
Post by: James0x57 on November 21, 2010, 07:06:19 PM
For this code, it *probably* has 3 addresses because:
one is modifying the X speed, one is the Y speed, and the other is the Z speed.