Pages: 1
Posted on 09-25-23, 08:53 pm (rev. 1 by kyuweftea on 09-26-23, 04:05 am)


Karma: 2
Posts: 1/1
Since: 09-25-23
I'm encountering a weird situation where applying hooks to some functions in the game code doesn't seem to work, but it does work for other functions. My starting environment was the Mario vs. Luigi starter pack [https://nsmbhd.net/thread/4878-the-mvsl-starter-pack/] .

To test my sanity, I added the following to asm to print.s:

@ replaces inner function nsub_020f5e48: print "020f5e48 link register: %lr% \n" bx lr @ address in outer function where inner function returns to nsub_020daf34: print "just after\n" ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}


Basically, this should print the return address while inside the inner function, then return to that address, then branch to code that prints "just after".

The weird part is that the output shows only this line repeatedly:

020f5e48 link register: 020DAF34


So this confirms that the inner function is returning to the location of the other hook. But if that's the case, why is "just after" not also being printed? I can't seem to change any behavior in this outer function by using other hooks in other addresses either, but hooks to the inner function work fine.

Are there some functions that can't be hooked? What could be causing this?


EDIT:

I believe I fixed the problem on a whim.

The addresses of these hooks are in "overlays", and I get expected behavior when adding "_ov_0A" to the end of the hook labels. The updated code looks like the following (note that the labels have longer names now):

@ replaces inner function nsub_020f5e48_ov_0A: print "020f5e48 link register: %lr% \n" bx lr @ address in outer function where inner function returns to nsub_020daf34_ov_0A: print "just after\n" ldmia sp!,{r4,r5,r6,r7,r8,r9,r10,r11,pc}


This works because the code is in overlay number 10 (0A in hexadecimal). Alternatively, if I were to hook into code in overlay 52 (34 in hexadecimal), I would append "_ov_34" instead of "_ov_0A".

A list of overlays for the europe and usa versions of nsmb can be found here: https://nsmbhd.net/thread/1581-nsmb-overlay-list/

I barely understand what overlays are or how they work, but this seems to solve the problem. I would appreciate any insight into why this works.
Pages: 1