Numark
Awesome Active Platinian
Hey guys, it's SliceCast here. This tutorial is for Advanced Modders who wants to step up their games to get better! Could be for newbies too.
I will show you some basics examples on how to hook a function.
Now let's say our Type Functions are (int, float, bool, double) and that we're doing a int/integer type.
Also make sure to call your hooks with MsHook or your mod won't work.
Example:
Field Hooking with Class. We basically create this function to manipulate/hijack our methods and fields.
Call the GameMode Update with MSHook
Why do we use Update or LateUpdate method from the GameMode class?
It is because every frame is called 60 Frames Per Second. IT is a non-static function called by Unity's once per frame. We wouldn't want to get and set instance variables on a Player object that hasn't been updated for a while right?
If it's a bool, then simple. Just return/put "true" or "false".
If it's a float, then return a 99.0 or whatever.
This is way better than Patching. We don't need to use Hex Values for hooking. Hooking is way better, you can return any value you want.
As of now in this era of 2023, you can use ByNameModding to automatically use auto-updating offsets and create your own classes and hooks.
I will show you some basics examples on how to hook a function.
Now let's say our Type Functions are (int, float, bool, double) and that we're doing a int/integer type.
C++:
//the void *instance is a self-created variable.
int (*old_Kills)(void *instance);
int Kills(void *instance) {
//Check if instance is NULL to prevent CRASH
if (instance != NULL)
{
return 99999; //Return how many value
}
//return the original value (this code isn't really needed if you have a toggle/switch)
return old_Kills(instance);
}
Also make sure to call your hooks with MsHook or your mod won't work.
Example:
C++:
MsHookFunction((void*)getAbsoluteAddress(OFFSETS), (void*)Kills, (void**)&old_Kills);
Field Hooking with Class. We basically create this function to manipulate/hijack our methods and fields.
C++:
void(*old_GameMode_Update)(void *instance);
void GameMode_Update(void *instance) {
if(instance != NULL) { //check if instance is NULL to prevent crashes.
if (xpPerKill) { //if Toggle
*(int *) ((uint64_t) instance + 0x30) = 5000;
}
}
old_GameMode_Update(instance);
}
Call the GameMode Update with MSHook
Why do we use Update or LateUpdate method from the GameMode class?
It is because every frame is called 60 Frames Per Second. IT is a non-static function called by Unity's once per frame. We wouldn't want to get and set instance variables on a Player object that hasn't been updated for a while right?
C++:
MSHookFunction((void *)getAbsoluteAddress("libil2cpp.so", 0x00000), (void *) GameMode_Update, (void **) &old_GameMode_Update);
If it's a bool, then simple. Just return/put "true" or "false".
If it's a float, then return a 99.0 or whatever.
This is way better than Patching. We don't need to use Hex Values for hooking. Hooking is way better, you can return any value you want.
As of now in this era of 2023, you can use ByNameModding to automatically use auto-updating offsets and create your own classes and hooks.
Last edited: