📖 Tutorial Basic Hooking Tutorial

Sbenny.com is trusted by 1,313,220 happy users since 2014.
Register

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years
Heya Everyone 👋 . Hope Everyone is doing alright. Today I am making this tutorial as per @DDeveloper's Request. On this tutorial I will show you how to use basic hooks.
Lets Get Started ....

Lets Say We Are Going To hook a function called get_Coins.

Screenshot_15.png


First of all we need to copy a original instance of that function.
C++:
int (*org_getCoins)(void *instance);

Next We need to make our function to replace that old function on the game after hooking.
C++:
int getCoins(void *instance) {

}

Now We can modify the function as per we want. But Most of the case we simply return a value. Lets do that for the sake of this tutorial.
First we need to check this function's validity on runtime. We can simply use "if" statement for that .
C++:
int getCoins(void *instance) {
    
    if (instance != NULL) {
        
    }
    
}

Now Here we can if instance is valid we can simply return our value . (Knowledge about data types will help a bit).
C++:
int getCoins(void *instance) {

    if (instance != NULL) {
        return 99999;
    }
    
}

But when its not valid (and for some other cases) we should return that original instance we copied.
C++:
int getCoins(void *instance) {

    if (instance != NULL) {
        return 99999;
    }
    return org_getCoins(instance);
}

Now the code shlould look like this.
C++:
int (*org_getCoins)(void *instance);

int getCoins(void *instance) {
    
    if (instance != NULL) {
        return 99999;
    }
    return org_getCoins(instance);
}

Now if you use Mod menus you can simply use your switch boolean here.
C++:
int getCoins(void *instance) {

    if (instance != NULL) {

        if (feature1){        //your switch boolean
            return 99999;
        }

    }
    return org_getCoins(instance);
}

At last hook you offsets on hack thread (LGL Menu) using MSHook or A64InlineHook.
C++:
MSHookFunction((void *) getAbsoluteAddress(targetLibName, string2Offset(OBFUSCATE_KEY("0x123456", 'a'))), (void *) getCoins, (void **) &org_getCoins);

For other returning types just change the data type of your hook functions. Like ...
C++:
float (*org_getCoins)(void *instance);

float getCoins(void *instance) {
    
    if (instance != NULL) {
        return 99999.0f;
    }
    return org_getCoins(instance);
}
C++:
bool (*org_isUnlocked)(void *instance);

bool isUnlocked(void *instance) {

    if (instance != NULL) {
        return true;
    }
    return org_isUnlocked(instance);
}


Thats all for today. Hope this tutorial helps you a bit . :)
 

Attachments

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years
Kasami who has no idea what these means:
InTeREsTiNg...xD
And Kasami have no idea that she is using universal naming conventions for programming xD
 

PixelYT

Apprentice Lv2️⃣
Member for 5 years
Nice tutorial but you missed one important thing: make sure to hook an Update or LateUpdate function from that class using MSHook.
 

Sbenny

A crazy scientist
Staff member
Admin
SB Mod Squad ⭐
✔ Approved Releaser
Active User
Nice tutorial but you missed one important thing: make sure to hook an Update or LateUpdate function from that class using MSHook.
This isn't really necessary in the examples he provided, don't forget Update and LateUpdate functions keep spamming every frame, which means you run it around 60 times every second which is a waste of resources when you're just aiming at changing the amount of coins you have or if you want to unlock something.
 

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years
Nice tutorial but you missed one important thing: make sure to hook an Update or LateUpdate function from that class using MSHook.
This isn't really necessary in the examples he provided, don't forget Update and LateUpdate functions keep spamming every frame, which means you run it around 60 times every second which is a waste of resources when you're just aiming at changing the amount of coins you have or if you want to unlock something.
Also its not that necessary as we are not hooking field or function pointers here.
 

PixelYT

Apprentice Lv2️⃣
Member for 5 years
wow i didn´t knew that since i only hook fields because for methods i just do the regular hex patching which we are unable to do with fields (instance variables).
 

PolarBear

Novice Lv1️⃣
Member for 2 years
Gourov
where to put this code? and all of the codes above?
MSHookFunction((void *) getAbsoluteAddress(targetLibName, string2Offset(OBFUSCATE_KEY("0x123456", 'a'))), (void *) getCoins, (void **) &org_getCoins);
and where did you get this offset from 0x123456 and also this 'a'???
 

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years
Gourov
where to put this code? and all of the codes above?
MSHookFunction((void *) getAbsoluteAddress(targetLibName, string2Offset(OBFUSCATE_KEY("0x123456", 'a'))), (void *) getCoins, (void **) &org_getCoins);
and where did you get this offset from 0x123456 and also this 'a'???
You ever modded a game ?
 

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years

PolarBear

Novice Lv1️⃣
Member for 2 years
Then you should know what is offset , also used any template before ? Like LGL or Octwolves ?
buddy i know what is offset but i got confused cuz you suddenly used offset you didn`t mention before in this thread+no
 

Gourov

Dimitri Petrenko
✌️ Community Team
Member for 5 years
buddy i know what is offset but i got confused cuz you suddenly used offset you didn`t mention before in this thread+no
Hmm my bad then ... Well you should first learn to use LGL or Octwolve template with Memory Patching. I prefer LGL because its easier.
 

Asoul Modder

Hardcore Lv9️⃣
SB Mod Squad ⭐
✔ Approved Releaser
Active User
Member for 2 years
I have hook like this but not working
IMG_20221222_114332.png

IMG_20221222_114418.png

IMG_20221222_114448.png

IMG_20221222_114759.png



I have done like this but not working can you help me what is wrong
 
Top