Help! Is this hooking right?

ed esoj

Rookie

[Address(RVA = "0xF709D0", Offset = "0xF709D0", VA = "0xF709D0")]

public void TakeDamage(float amount, bool isGasDamage = false, EFieldObject zombieType = EFieldObject.Ammo, float zombieXPos = 0f)

[Address(RVA = "0xF70784", Offset = "0xF70784", VA = "0xF70784")]

private void Update()


So my code is:

C++:
bool GodMode = false;


void (*takedamage)(void *instance, float, bool, int, float);
void (*old_update)(void *instance);
void Update(void *instance) {
if (instance != NULL){
 if (GodMode) {
takedamage(instance, 0, false, 0, 0);
        }
    }
    old_update(instance);
}


takedamage = (void (*)(void *, float, bool, int, float)) getAbsoluteAddress("libil2cpp.so", 0xF709D0);
A64HookFunction((void *) getAbsoluteAddress("libil2cpp.so", 0xF70784), (void *) &Update, (void **) &old_update);




will it work? any tips for making better?
 
I always using this code for unity method calling, maybe it will be useful for you too

C++:
template<typename Ret, typename... Args>
Ret CALL_METHOD(uintptr_t address, void* instance, Args... args) {
    using NativeFn = Ret(*)(void*, Args..., void*);
    auto func = reinterpret_cast<NativeFn>(address);
    return func(instance, args..., nullptr);
}

template<typename Ret, typename... Args>
Ret CALL_STATIC_METHOD(uintptr_t address, Args... args) {
    using NativeFn = Ret(*)(Args..., void*);
    auto func = reinterpret_cast<NativeFn>(address);
    return func(args..., nullptr);
}

this is how to use it
C++:
// this is for the function that requires instance
// you can change <void> depending on the type data of the function, in this case TakeDamage is void
// if the function are returning int, just change it to <int>
if (god_mode){
    uintptr_t addr = il2cpp_base + 0xF709D0;
    CALL_METHOD<void>(addr, instance , 0.0f, false, 0 , 0.0f);
}
 
C++:
bool GodMode = false;

void (*old_takedamage)(void*, float, bool, int, float)
void takedamage(void *instance, float a, bool b, int c, float d) {
    if (GodMode) {
        a = 0;
    }
    return old_takedamage(instance, a, b, c, d);
}
 
Back
Top Bottom