Pages: 1
Posted on 12-15-15, 11:29 pm
Flurry


Karma: 724
Posts: 204/258
Since: 10-14-11
So I've been messing around with the NSMB.ida and copying code , editing it and recompiling it just for fun to see some funny results and have been doing so no problem.

However, when it comes to editing lines such as "BL get1up" etc I am having difficulty.
How do I tell the compiler that there is a function called get1up?
Yes, I have read http://nsmbhd.net/thread/1281-how-asm-hacks-are-setup-tutorial/ and how it declares a function there but just need a little more clarification.

For example, compiling the following code will just cause nothing to happen in the game when 100 coins is reached.

Posted on 01-29-16, 06:50 pm (rev. 1 by  Dirbaio on 01-29-16, 06:56 pm)
Super Mario
( ͡° ͜ʖ ͡°)

Karma: 9979
Posts: 4316/4456
Since: 06-08-11
Posted by Shadey21
How do I tell the compiler that there is a function called get1up?


You need to do two things:

1- Define the function in a header file. This lets the compiler know the "signature" of the function (what parameters does it take and what does it return).
2- Add its address to symbols.x. This lets the compiler know where the function is in RAM.

(You actually need to do 1 only if you call the function from a c/c++ file. Not from a .s file)

If you do either thing wrong, the hack probably won't compile. So if it compiled you did it right I guess. (The ASM patch template already has get1up in symbols.x)

So... I'm not sure why is it not working.

Can you post the disassembly around 020203EC including the addresses? (from the text view in IDA Pro)
Maybe there's something wrong with the hook addr

EDIT: To debug it you can try this:

- A nice trick to see if your code is being called is printing something to the console. Try something like this:
repl_020203EC: print "HELLOOO" BL get1up


'print' is not an ASM instruction, it's a macro defined here: https://github.com/Dirbaio/ASMPatchTemplate/blob/master/source/print.s#L52
You'll probably have to copypaste it in your .s file if it doesn't find it (macros from one .s file are not usable in other .s files).

- If it prints nothing, your code is not being executed. You need to check the address you're hooking (020203EC) is correct.
- If it prints HELLOOO, then your code is executing but doesn't do what you want. Check it's correct
For example, I see on the tutorial get1up is supposed to take 2 arguments. First one is 8, second one is the player number (0 in singleplayer always.) You're not setting the parameters, so get1up will take as parameters whatever was on r0 and r1 before, which is probably not what you want.
You can set the parameters like this:
repl_020203EC: mov r0, #8 mov r1, #0 BL get1up

Pages: 1