Inserting ASM codes

Started by Jackal, January 18, 2011, 03:52:20 PM

Previous topic - Next topic

Jackal

I am learning how to use C2 codetype and hope someone can check if I am going the right direction
I have been hacking Tales of Graces (STGJAF)
which I found that damage code is shared by players and enemies

original code:
...
cmplwi r0,2
sub r14,r14,r18 // decrease hp
bne- 0x800a83f8
lwz r3,-22512(r13)
...

which I tried to write a C2 for no damage & 1 hit kill enemy
r3: seems safe to use
r14: hp
r21: address of player/enemy object being attacked

lhz r3,48(r21)  // Load character type
cmpwi r3,0x0100 // check type (seems that 0100 are enemies and 0001 are players)
bne 0x08  // skip if not enemy
li r14,0  // set hp 0
cmplwi r0,2

for the last line, I am adding it as I did a cmpwi in my own code
but not adding it didn't cause any crash or bug
Is it necessary or cmpwi and cmplwi won't cause any conflict?

dcx2

It depends on what address you hook.  I think you hooked the sub; it's absence prevents you from taking damage, and the enemy test will ensure that enemies don't have any hp left.  So I would say yes, you don't know what that branch is doing so you should include the cmplwi because you modified the CR (in this case, with cmpwi, but any instruction that changes CR follows this rule).

Jackal

oh....yes, I forgot to mention where I hooked and I did use the sub
ok, I will keep things what it was after my codes then
thanks