This is the AMP version of this page.
If you want to load the real page instead, click this text.

Help! Field offset hooking with switch

TimidNova

Platinian
so here's my hook

void (*old_isPremium)(void *instance);
void isPremium(void *instance) {
instanceBtn = instance;
if (instance != NULL) {
if (Premium) {
*(bool *) ((uint32_t) instance + 0x320) = true;

}
}
return old_isPremium(instance);
}

HOOK_LIB("libil2cpp.so", "0x156C100", isPremium, old_isPremium);

and then my switch case

case 5:
Premium = boolean;
break;

would this be the correct way to make it modify the value when the switch is on and then return when off?
 
Your everything is right but just remove your
instanceBtn = instance; from that like this

void (*old_isPremium)(void *instance);
void isPremium(void *instance) {
if (instance != NULL) {
if (Premium) {
*(bool *) ((uint32_t) instance + 0x320) = true;

}
}
return old_isPremium(instance);
}

And try to use
This MSHookFunction((void*)getAbsoluteAddress("libil2cpp.so", 0x156C100), (void*)isPremium, (void**)&old_isPremium);

in the place of
HOOK_LIB("libil2cpp.so", "0x156C100", isPremium, old_isPremium);


And
Make sour your Switch will like this

OBFUSCATE("5_Toggle_Premium Unlock"),

And the case like this

Case 5:
Premium = boolean;
break;

Now you will not get any kind of problem
 
Also If I use an Update function outside of the class how exactly would that work? Would I have to do anything special
then it's all about the instance, if you can get the instance of the field from another class then of course you can, here are some examples:

 
how do i restore the field offset when it's turned on, when i turn off it's not restoring

how do i restore?
In full details
bool Premium = false;
void (*old_isPremium)(void *instance);
void isPremium(void *instance) {
if (instance != NULL) {
if (Premium) {
*(bool *) ((uint32_t) instance + 0x320) = true;

}
}
return old_isPremium(instance);
}

And try to use
This MSHookFunction((void*)getAbsoluteAddress("libil2cpp.so", 0x156C100), (void*)isPremium, (void**)&old_isPremium);

in the place of
HOOK_LIB("libil2cpp.so", "0x156C100", isPremium, old_isPremium);


And
Make sour your Switch will like this

OBFUSCATE("5_Toggle_Premium Unlock"),

And the case like this

Case 5:
Premium = boolean;
break;

It will restore it :);
 
Simple.
C++:
void (*old_isPremium)(void *instance);
void isPremium(void *instance) {
instanceBtn = instance;
if (instance != NULL) {

if (Premium) {
*(bool *) ((uint32_t) instance + 0x320) = Premium;

}
}
return old_isPremium(instance);
}

HOOK_LIB("libil2cpp.so", "0x156C100", isPremium, old_isPremium);