Help! 2 Fields with same update code doesn't work in my mod menu

Chester Codm

Platinian
Original poster
Dec 21, 2019
34
8
8
26
Brasil
void (*old_gravity)(void *instance);
void gravity(void *instance) {
if (instance != NULL) {
if (Gravity) {
*(float *) ((uint32_t) instance + 0x30) = 0;
}
}
return old_gravity(instance);
}

void (*old_fly)(void *instance);
void fly(void *instance) {
if (instance != NULL) {
if (Fly) {
*(float *) ((uint32_t) instance + 0x40) = 0.5;
}
}
return old_fly(instance);
}

HOOK_LIB("libil2cpp.so", "0xA64C08", gravity, old_gravity);
HOOK_LIB("libil2cpp.so", "0xA64C08", fly, old_fly);

What's wrong for only one to work? (I'm a beginner)
 
  • Like
Reactions: HaxPlayz

NullCoder

Inactive Approved Modder
Jun 8, 2020
110
901
93
21
None
One address cannot be hooked twice, and indeed ... For example, one variable field cannot be divided into two during the game and work differently.
 
  • Like
Reactions: BeginnerCodes

sobogamer_2020

Approved Modder
Approved Modder
Apr 6, 2022
383
14,915
1,193
23
Romania
void(*old_GameManager)(void *instance);
void GameManager(void *instance) {
if(instance != NULL) {
if (isReloading) {
*(float *) ((uint32_t) instance + 0x30) = 0.0f;
}

if (Ammo) { //if Toggle
*(int *) ((uint32_t) instance + 0x32) = 99999;
}

if (UnlockPremium) { //if Toggle
*(bool *) ((uint32_t) instance + 0x343) = true;
}


}
old_GameManager(instance);
}


U gotta use them in one hook

HOOK_LIB("libil2cpp.so", "0x00000", GameManager, old_GameManager);
 

Yaskashije

PMT Elite Modder
Staff member
Modding-Team
Sep 9, 2018
4,384
850,765
1,213
Minkowski Space
void (*old_gravity)(void *instance);
void gravity(void *instance) {
if (instance != NULL) {
if (Gravity) {
*(float *) ((uint32_t) instance + 0x30) = 0;
}
}
return old_gravity(instance);
}

void (*old_fly)(void *instance);
void fly(void *instance) {
if (instance != NULL) {
if (Fly) {
*(float *) ((uint32_t) instance + 0x40) = 0.5;
}
}
return old_fly(instance);
}

HOOK_LIB("libil2cpp.so", "0xA64C08", gravity, old_gravity);
HOOK_LIB("libil2cpp.so", "0xA64C08", fly, old_fly);

What's wrong for only one to work? (I'm a beginner)
void(*old_GameManager)(void *instance);
void GameManager(void *instance) {
if(instance != NULL) {
if (isReloading) {
*(float *) ((uint32_t) instance + 0x30) = 0.0f;
}

if (Ammo) { //if Toggle
*(int *) ((uint32_t) instance + 0x32) = 99999;
}

if (UnlockPremium) { //if Toggle
*(bool *) ((uint32_t) instance + 0x343) = true;
}


}
old_GameManager(instance);
}


U gotta use them in one hook

HOOK_LIB("libil2cpp.so", "0x00000", GameManager, old_GameManager);

Please, when writing long code snippets, use the Insert Code option.
1659468937478.png
1659468980948.png



It's also recommended to use proper indentation for readability purposes.
 

dani olmo

Platinian
Apr 26, 2022
19
2
1
24
in your home :0
C++:
void (*old_PlayerClass)(void *instance);
void PlayerClass(void *instance) {
if (instance != NULL) {
if (Gravity) {
    *(float *) ((uint32_t) instance + 0x30) = 0.00f;
}
if (fly) {
    *(float *) ((uint32_t) instance + 0x40) = 0.00f;
}
}
return old_PlayerClass(instance);
}
 

Chester Codm

Platinian
Original poster
Dec 21, 2019
34
8
8
26
Brasil
One address cannot be hooked twice, and indeed ... For example, one variable field cannot be divided into two during the game and work differently.
void(*old_GameManager)(void *instance);
void GameManager(void *instance) {
if(instance != NULL) {
if (isReloading) {
*(float *) ((uint32_t) instance + 0x30) = 0.0f;
}

if (Ammo) { //if Toggle
*(int *) ((uint32_t) instance + 0x32) = 99999;
}

if (UnlockPremium) { //if Toggle
*(bool *) ((uint32_t) instance + 0x343) = true;
}


}
old_GameManager(instance);
}


U gotta use them in one hook

HOOK_LIB("libil2cpp.so", "0x00000", GameManager, old_GameManager);
void(*old_GameManager)(void *instance);
void GameManager(void *instance) {
if(instance != NULL) {
if (isReloading) {
*(float *) ((uint32_t) instance + 0x30) = 0.0f;
}

if (Ammo) { //if Toggle
*(int *) ((uint32_t) instance + 0x32) = 99999;
}

if (UnlockPremium) { //if Toggle
*(bool *) ((uint32_t) instance + 0x343) = true;
}


}
old_GameManager(instance);
}


U gotta use them in one hook

HOOK_LIB("libil2cpp.so", "0x00000", GameManager, old_GameManager);
Thanks!
 

Francois284Modz

Awesome Active Platinian
Jun 10, 2018
188
2,446
193
26
france
C++:
void (*old_PlayerClass)(void *instance);
void PlayerClass(void *instance) {
if (instance != NULL) {
if (Gravity) {
    *(float *) ((uint32_t) instance + 0x30) = 0.00f;
}
if (fly) {
    *(float *) ((uint32_t) instance + 0x40) = 0.00f;
}
}
;
}
Void can return value replace return old_PlayerClass(instance) just de return