WiiRd forum

Wii & Gamecube Hacking => Wii Game hacking help => Topic started by: Bully@Wiiplaza on September 28, 2010, 12:08:15 PM

Title: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 12:08:15 PM
Hey guys,
I was wondering how you can make such a code, because I only know, how to do it with direct RAM write...

example Fifa10 (R4X69)

[spoiler][increase/decrease Home Goals]
28187210 00000200
4A000000 809FD093
A8000008 00000008
94010000 00000000
86000000 00000001
94010000 00000000
E0000000 80008000
28187210 00000100
4A000000 809FD093
A8000008 00000008
94010000 00000000
86000000 FFFFFFFF
94010000 00000000
E0000000 80008000[/spoiler]

for this game, it works always, but not every game is as "kind" as fifa and may use non static adresses ...
But how to generally make this same score manipulation code from fifa in ASM? An example, how mdmwii made one:

mario kart wii (RMCP01)

[spoiler][Battle hacking - PAL -mdmwii]
C2538730 0000000A
3E208000 82311508
7C84002E 7C008800
40820038 3E208034
A231XXXX 2C11YYYY
40820014 8A240023
3A310001 9A240023
48000018 2C11ZZZZ
40820010 8A240023
3A31FFFF 9A240023
60000000 00000000
C27EEFB0 00000003
3FA08000 1CA00004
90BD1508 1FA00248
60000000 00000000
04539878 60000000

xxxx= controller address
yyyy= increase button
zzzz=decrease button

instructions:
lis r17,-32768
lwz r17,5384(r17)
lwzx r4,r4,r0
cmpw r0,r17
bne- 0x38
lis r17,-32716
lhz r17,XXXX(r17)
cmpwi r17,YYYY
bne- 0x14
lbz r17,35(r4)
addi r17,r17,1
stb r17,35(r4)
b 0x18
cmpwi r17,ZZZZ
bne- 0x10
lbz r17,35(r4)
subi r17,r17,1
stb r17,35(r4)
nop[/spoiler]

Thx for replyz and use line explanations ect. pls ;D
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 01:02:27 PM
inc -

lbz r17,35(r4)
addi r17,r17,1
stb r17,35(r4)

dec -

lbz r17,35(r4)
subi r17,r17,1
stb r17,35(r4)

The rest is just making sure that the code is currently processing the right pointer in r4 by testing r0 (cmpw r0,r17/bne will skip other pointers, I think) and testing button activators (cmpwi r17/bne)
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 08:22:27 PM
Quote from: dcx2 on September 28, 2010, 01:02:27 PM
inc -

lbz r17,35(r4)
addi r17,r17,1
stb r17,35(r4)

dec -

lbz r17,35(r4)
subi r17,r17,1
stb r17,35(r4)

The rest is just making sure that the code is currently processing the right pointer in r4 by testing r0 (cmpw r0,r17/bne will skip other pointers, I think) and testing button activators (cmpwi r17/bne)

Means that I also could only use these parts?

Button Activator for increase
lbz r17,35(r4)
addi r17,r17,1
stb r17,35(r4)
Terminator
Button Activator for decrease
lbz r17,35(r4)
subi r17,r17,1
stb r17,35(r4)

for sure, I need to refer to the right registers and stuff.

Would that work?
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 08:28:59 PM
ASM does not usually have terminators.

Assuming that you did the button activators correctly, that is the general template.  Note that cmpwi/bne is how you do the non-masked button activators (i.e. 00000001 for left [I think] and ONLY left, no other keys).  To do masked button activators (i.e. FFFE0001 for left with or without other keys), you must use andi./beq.
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 08:35:38 PM
yeah I don´t care about button activators in ASM, the normal 28 line is "good enough" :p
But it´s cool though, if you can do them in ASM 8)
Title: Re: How to make an increase/decrease ASM code?
Post by: Deathwolf on September 28, 2010, 08:41:19 PM
just load into address with lis,ori and read 16 bit with lhz xD
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 08:43:39 PM
You can't use 28-code type button activators with C2 hooks.  The 28-code will conditionally apply the C2 hook; once applied, nothing will un-apply the C2 hook.

In order to make a 28-code work with a C2 hook, you will need an E2-code (endif + else), which will patch the original instruction/"anti-code" when you aren't using the button activator.

It really is much easier to just use ASM button activators.  And the code will be shorter.
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 08:44:49 PM
Quote from: Deathwolf on September 28, 2010, 08:41:19 PM
just load into address with lis,ori and read 16 bit with lhz xD
you load the button adress into a register with lis and ori, I couldn´t find out further with this reply... :rolleyes:
Anyway, i bet there is already a thread for button activator in ASM, but where? :eek:

found it: http://wiird.l0nk.org/forum/index.php/topic,6496.0.html

@dcx2:
thanks for letting me know, i thought it works with 28 aswell... :-\
Title: Re: How to make an increase/decrease ASM code?
Post by: Deathwolf on September 28, 2010, 08:46:45 PM
wtf... btw no that is with 28 ;)
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 08:53:17 PM
@Bully - yeah, that's a good thread.  A few posts down is a pretty good post I made, with a line-by-line breakdown.  I also mention the WiiRD-style template

28 if-equal button activator
C2 hook
E2 else
04 write original instruction
E0 terminator

Honestly, ASM button activators are easy once you understand how branching works.
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 08:55:05 PM
hey I picked out your post:

You can also do it in pure ASM.

lis r12,0xXXXX      # r12 = controller pointer
ori r12,r12,0xYYYY
lhz r12,0(r12)      # r12 = controller value
cmpwi r12,ZZZZ      # compare r12 to ZZZZ
bne- 0x0C         # if Not Equal, branch
lis r12,0x4100      # if equal, write 41000000...
stw r12,428(r28)      # ...to 428(r28)
lwz r6,428(r28)      # bne- would take you here

You insert the button activator value in the ZZZZ values, don´t you?

should work then :)
Title: Re: How to make an increase/decrease ASM code?
Post by: Deathwolf on September 28, 2010, 08:57:44 PM
Quote from: Bully@Wiiplaza on September 28, 2010, 08:55:05 PM
hey I picked out your post:

You can also do it in pure ASM.

lis r12,0x8040      # r12 = controller pointer
ori r12,r12,0xA5E0
lhz r12,0(r12)      # r12 = controller value
cmpwi r12,YYYY      # compare r12 to YYYY
bne- 0x0C         # if Not Equal, branch
lis r12,0x4100      # if equal, write 41000000...
stw r12,428(r28)      # ...to 428(r28)
lwz r6,428(r28)      # bne- would take you here

should work :)

bne- 0xXX, it not every time 0C. PyiiASMH will calculate it for you.

lis r12,0x8040      # r12 = load into button address
ori r12,r12,0xA5E0
lhz r12,0(r12)      # r12 = read 16 bit (2bytes)
cmpwi r12,YYYY      # compare r12 to YYYY
bne- 0x0C         # if Not Equal, branch
lis r12,0x4100      # if equal, write 41000000...
stw r12,428(r28)      # ...to 428(r28)
lwz r6,428(r28)      # bne- would take you here

or use andi. r12,r12,YYYY
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 08:59:22 PM
PyshASM doesn´t work for me...
I still use ASMWiiRD :eek:
Title: Re: How to make an increase/decrease ASM code?
Post by: Deathwolf on September 28, 2010, 09:00:16 PM
okay that's not good for branchs xD
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 09:01:08 PM
damn, can you do it manually? <.<
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 09:02:05 PM
Yes, YYYY = the button combination you want to activate your code.

Very important: this is like 28______ 0000YYYY if code.

You must use andi./beq- if you want 28______ MMMMYYYY if code.

PyiiASMH should work.  I don't think ASMWiiRD does branch labels.  So you have to manually calculate each branch distance.  If you add any instructions between the branch and the destination, you must recalculate that branch.  This is quite tedious and error prone...you would be better off making PyiiASMH work.
Title: Re: How to make an increase/decrease ASM code?
Post by: Deathwolf on September 28, 2010, 09:03:45 PM
lis r12,0x8075
ori r12,r12,0x6102
lhz   r12,0(r12)
andi. r12,r12,0x0200
beq- THE_END
li r12,0x777
stw r12,48(r31)

THE_END:

lwz   r3,48(r31)

wanna claculate it? lol  :p
it's very hard without pyiiASMH
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 09:07:55 PM
That's an easy one.

branch distance = (number of instructions to skip + 1) * 4

In that example, we want to skip 2 instructions.  (2 + 1) * 4 = 12 = 0x0C.

Try calculating these branch distances...

http://wiird.l0nk.org/forum/index.php/topic,6517.msg55339.html#msg55339
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 09:12:28 PM
I try to get it working now, if it´s that good :P

PyiiASMH.py is a text data and not the program self... that´s why it´s not working, there is nowhere an exe data to launch it!
I installed Phyton.
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 10:49:10 PM
Make sure you install Python 2.6.5 and PyQt4 for Python 2.6.  Use these links.

http://wiird.l0nk.org/forum/index.php/topic,4845.msg55412.html#msg55412

You are correct, .py files are text data.  Python is an interpreted language, which means that you're given the source code and the program is "compiled" on the fly.  Once you have Python installed properly, double-clicking on a py file should automatically launch the app.
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 11:21:54 PM
yes it works!
lol... I have never delt with such a crazy program, so I didn´t know how it works, time for some ASM codes with branches :)

xD
Title: Re: How to make an increase/decrease ASM code?
Post by: matt123337 on September 28, 2010, 11:22:26 PM
Quote from: Deathwolf on September 28, 2010, 09:03:45 PM
lis r12,0x8075
ori r12,r12,0x6102
lhz   r12,0(r12)
andi. r12,r12,0x0200
beq- THE_END
li r12,0x777
stw r12,48(r31)

THE_END:

lwz   r3,48(r31)

wanna claculate it? lol  :p
it's very hard without pyiiASMH
Buddy:

lfs f29, 132(r7)    # water offset
  lfs f27, 40(r7)     # Link's Y
  lis r9, 0xC000      # conditinal value
  lis r12, 0x8000     # Base address
  stw r9, 0x98(r12)   # stores conditinal to memory
  lfs f17, 0x98(r12)  # loads conditinal as a float
  mcrf cr4,cr0        # saves cr0 to cr4
  fcmpo cr0, f29, f17 # checks if in water or not
  ble END             # if we arn't, goto end
    lis r9, 0x40F0      # 7.5 in float
    stw r9, 0x98(r12)   # stores 7.5 in float to memory
    lfs f17, 0x98(r12)  # loads the 7.5 as float
    fadd f27, f27, f17  # adds 7.5 to links Y pos
    fadd f27, f27, f29  # adds water offset
    stfs f27, 0x98(r12) # stores final float to mem
    lwz r5 ,0x98(r12)   # loads final float into register 5
END:
mcrf cr0,cr4        # restores cr0 from cr4
stw r5, 128(r7)     # writes to ground Y

Will be made fine in Wiird (not the python one), just maximize the window :P

BTW this in my OOT walk on water code.
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 28, 2010, 11:23:34 PM
wtf, is this a jesus mode code O.o
oh yeah, walk on water, but I will NEVER ask for a TuT, too hard for now at least xD
Title: Re: How to make an increase/decrease ASM code?
Post by: matt123337 on September 28, 2010, 11:27:44 PM
lol I was following parasite's notes on his original n64 code XD, it's not that hard of a code (for OOT at least)...
Title: Re: How to make an increase/decrease ASM code?
Post by: dcx2 on September 28, 2010, 11:29:00 PM
I could never make ASMWiiRD accept branch labels or line comments.  :confused:  Was I using the wrong version or something?
Title: Re: How to make an increase/decrease ASM code?
Post by: matt123337 on September 28, 2010, 11:30:59 PM
idk. want me to zip mine with the file needed?

EDIT:http://www.mediafire.com/?19iz5r7daqdprmr (http://www.mediafire.com/?19iz5r7daqdprmr)
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on September 29, 2010, 01:27:35 PM
but everybody already has this files, if he is running gecko dotnet or wiiRd... :P
Title: Re: How to make an increase/decrease ASM code?
Post by: matt123337 on September 29, 2010, 08:39:07 PM
I know, just for some reason mine supports labels & comments, and his doesn't :|
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on January 02, 2011, 08:01:39 PM
hmm how would you do this with masked button activators?

lis r12,-32736
ori r12,r12,3904
lhz r12,0(r12)
cmpwi r12, ZZZZ
bne- _END

thx for replys!
Title: Re: How to make an increase/decrease ASM code?
Post by: trackme on January 02, 2011, 09:02:55 PM
lis r12,-32736
ori r12,r12,3904
lhz r12,0(r12)
andi. r12, r12, ZZZZ
beq- _END

xD :D
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on January 03, 2011, 12:26:31 AM
 :p
Title: Re: How to make an increase/decrease ASM code?
Post by: wiiztec on January 04, 2011, 02:17:46 AM
All you need to do is put the anticode before the 28 then you don't need an E2
Title: Re: How to make an increase/decrease ASM code?
Post by: Bully@Wiiplaza on January 04, 2011, 06:12:49 PM
Quote from: wiiztec on January 04, 2011, 02:17:46 AM
All you need to do is put the anticode before the 28 then you don't need an E2
I know, it´s like this:

04xxxxxx yyyyyyyy
28zzzzzz HHHHTTTT
C2xxxxxx 0000000K
etc.
E0000000 80008000

But I didn´t ask that though