Directly "jumpToHack" in C?

This is my accidental discovery when compiling C. Let me take an example:

#include "include/gbafe.h"

int GetUnitPower(const struct Unit* unit){
	int iPow = unit->pow;
	iPow += GetItemPowBonus(GetUnitEquippedWeapon(unit));
	
	// just for test
	iPow++;
	
	return iPow;
}

Note that the file Definitions.h.s, which will be used for linking then, also contains the function definition “GetUnitPower”:

@ inside Definitions.h.s
SET_FUNC GetUnitPower, 0x80191B1

Refer to @StanH 's C tutorial to compile it, and Something interesting happened :

PUSH
ORG $191b0
ALIGN 4
SHORT $4778 $46C0
WORD $E59FC000 $E12FFF1C
POIN GetUnitPower
POP
ALIGN 4
PUSH
ORG CURRENTOFFSET+$1;GetUnitPower:
POP
SHORT $B510 $2414 $4B05 $5704 $F000 $F80C $4B04 $F000 $F809 $1820 $3001 $BC10 $BC02 $4708
BYTE $29 $6B $1 $8 $21 $64 $1 $8
SHORT $4718 $46C0

A “PUSH” and “POP” at 0x80191B1 ???

Then just set the ROM Buildfile.event as this:

ORG $B2A610
#include "src/JumpTest.lyn.event"

No “jumpToHack”, just include lyn file and then everyone get power+1 and this program can be jumpted from the original GetUnitPower (0x80191B0) function Location:
image

image

image

I am not very clear how the compiler implements such a jump at specific location, but this may be an easy way to skip the “jumpToHack” in the Buildfile, and directly jump to C function when compiling.

In particular, when you are intended to replace an original function in Vanilla, this may be an easy way.

This is a lyn feature, not a compiler thing. Lyn has an autohook feature which performs the ARM jump you see here.

Praise Stan :bowing_man:

Yea it’s a lyn feature. (One that I don’t particularily like because of how silent it is).

I’m pretty sure there’s some kind of guide on using it on my lyn thread.

2 Likes

I think it might be good practice to have hooks in its own file, so that it is obvious that the code will hook things. If the installer doesn’t have any hooks, then I used to assume nothing was being hooked, but since lyn can do that for you, I’ve been caught off guard by it before. So I agree with you that it could be made more overt.

Still tho, lyn is awesome