Pages: 1
Posted on 01-09-17, 08:32 am
Micro-Goomba


Karma: 43
Posts: 8/19
Since: 01-04-17
Hello,

I am experimenting with ASM a bit lately and I have a little question: Would it be possible to prevent/replace a function only on certain conditions? Sorry if that was already asked but I couldn't find anything.

So what I am trying to do is something like this:

repl_marioActorJumpfunction {
  if(something)
    //execute the default and unaltered jump function of the mario actor
  else
    //Don't do anything/don't jump
}


I already managed to just replace the function (which was pretty easy) but now Mario just can't jump (which makes sense).

Any way to do this or would I have to rewrite the entire jump function? And if I have to do so, is there a way I could find the function?
Posted on 01-09-17, 10:31 am


Karma: 19752
Posts: 883/1100
Since: 04-02-13
Would be easy to do in assembly, not so much in C
Posted on 01-09-17, 10:35 am
Micro-Goomba


Karma: 43
Posts: 9/19
Since: 01-04-17
So, "how" would I do that in assembly? I think it would be possible with something like hooking into the jump function, if my condition happens jump back to the original code and if not just jump to the end of the code. Would something like this work or am I completely wrong?

Don't want to bother you, just trying to learn and understand it...
Posted on 01-09-17, 10:44 am


Karma: 19752
Posts: 884/1100
Since: 04-02-13
Yes, something like that.

If you tell me where your instruction is and what your condition is, I can write this for you.
Posted on 01-09-17, 10:49 am
Micro-Goomba


Karma: 43
Posts: 10/19
Since: 01-04-17
I guess you mean the adress of the function I am replacing with where my instruction is? If so, it would be
0x21022B4 (MarioActor_Jump)
. My condition would be basically if the coin counter (
0x208B37C
) is higher than 0 the player should be able to jump, if it is not, he shouldn't be able to. I plan to subtract a coin for every jump but I would like to try to add that myself. But I think a reference/example code would definetly be helpful.
Posted on 01-09-17, 11:23 am (rev. 1 by  skawo on 01-09-17, 11:24 am)


Karma: 19752
Posts: 885/1100
Since: 04-02-13
Heh, that function's a bit too simple to be the jumping one.
Here you go, though, this should do what you want:
nsub_021135BC_ov_0A: MOV R4, R0 LDR R0, =0x208B37C LDRB R0, [R0] CMP R0, #0 LDREQ R0, =0x02115AAC STREQ R0, [R4, #0x980] LDMEQFD SP!, {R4,PC} B 0x21135C0
Posted on 01-09-17, 11:41 am (rev. 1 by  dhowdy on 01-09-17, 11:42 am)
Micro-Goomba


Karma: 43
Posts: 11/19
Since: 01-04-17
Okay so first of all: thank you. But I have a few questions, I hope it is not too much to ask.

At first: What does this "_ov_0A" mean? I guess it has something to do with overlays (because of the "ov")?

Also: Could you explain the code a bit? I get the main part of it (getting the amount of coins and comparing them to 0) but where do you have the other addresses from? I would look into the symbols.x but I can't right now...

Sorry for having that many questions, I hope they aren't too dumb.

EDIT: And what do you mean with "That function is a bit too simple to be the jumping function"?
Posted on 01-09-17, 11:47 am (rev. 3 by  skawo on 01-09-17, 11:49 am)


Karma: 19752
Posts: 886/1100
Since: 04-02-13
Overlay 10, i.e where the code is.

Code goes like this

MOV R4, R0 <- Original instruction that was there. Moves the Player Address to R4 so we can operate on R0-R3.
LDR R0, =0x208B37 <- Loading the coin counter address into R0
LDRB R0, [R0] <- Loading a byte (coin count) from address in R0 into R0
CMP R0, #0 <- Comparing R0 to 0
LDREQ R0, =0x02115AAC <- If they're equal, put address of idle standing state into R0
STREQ R0, [R4, #0x980] <- If they're equal, put R0 into Mario's state field
LDMEQFD SP!, {R4,PC} <- If equal, restore R4 and Program Counter (i.e return)
B 0x21135C0 <- Jump to next

I got both this function's address and the idle function address by watching Mario's state field in memory (Player address + 0x980). Death state is at 0x990.

And, uh, I meant that the function you found wasn't the jumping function. It seems to actually be what sets Mario's jump height or something, and it's called every frame.
Posted on 01-09-17, 12:04 pm
Micro-Goomba


Karma: 43
Posts: 12/19
Since: 01-04-17
Okay so one last question (thank you for your patience): is the _ov_0A thing really necessary? And if so, how do I find out what overlay the code is in?

I will play around with what I just learned when I am at home, I will edit this when I got any more problems regarding this topic. :)
Posted on 01-09-17, 12:05 pm


Karma: 19752
Posts: 887/1100
Since: 04-02-13
You'd have to use IDA, sadly
Pages: 1