Tutorial Basic Hooking Tutorial

Numark

Awesome Active Platinian
Original poster
May 23, 2017
116
925
193
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.

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:

Galaxy169

Approved Modder
Approved Modder
Apr 28, 2020
29
645
78
Home
what if the game have not lateupadte function? where should i placee my hook?
Then use other methods available in the class i.e update, fixedupdate, etc... avoid using awake and start as they get called only once per object (unless you don't have any other choice).
 

DawnBreaker

Platinian
Nov 4, 2018
39
3,795
183
24
Earth
what make me confused is, how and where should i put that code ? i just know how to edit game that have il2cpp and globalmetada in it otherwise i dont know how to grab the assemblycsharp
 

Numark

Awesome Active Platinian
Original poster
May 23, 2017
116
925
193
what make me confused is, how and where should i put that code ? i just know how to edit game that have il2cpp and globalmetada in it otherwise i dont know how to grab the assemblycsharp
[/QUOTE
basically what i'm getting out of this is,

[Hidden content]

only question is do i include the get_ part of my function?
No, it doesn't. Including the names in the code does not matter at all, you just need to memorize the method/function and make sure the code is used/recognize in Android Studio or whatever tool you're using it to compile with.
 

Numark

Awesome Active Platinian
Original poster
May 23, 2017
116
925
193
what if the game have not lateupadte function? where should i placee my hook?
If your game doesn't have a late update, then then use other functions that calls the method 60 fps or create your own hooks, if not... Out of look :)
 

LEIIKUN

Retired Staff
Retired but loved <3
Oct 13, 2019
502
10,946
1,193
20
Davao
i know the basic c++ (really basic), but what i dont know is how and where to put that code. did you just put it on the assembly csharp ? isn't that make the game crash ?
Put it and hook it inside main.cpp. You can find main.cpp if you use the lgl mod menu template.
 
  • Like
Reactions: TeddyMods

DawnBreaker

Platinian
Nov 4, 2018
39
3,795
183
24
Earth
Put it and hook it inside main.cpp. You can find main.cpp if you use the lgl mod menu template.
lgl mod menu ? where i can get one ? oh and maybe this is out of context but.. what code that when you buy something in the game, instead of decreasing its increasing ? because some game that i mod,the value is turning into minus even though the value that i mess with is a int, a flat number.
ty for your response btw
 

DawnBreaker

Platinian
Nov 4, 2018
39
3,795
183
24
Earth
and how to edit this ?
public partial class ActorMonster : ActorBase
{
// Token: 0x060000AF RID: 175 RVA: 0x00002050 File Offset: 0x00000250
[Token(Token = "0x60000A2")]
[Address(RVA = "0xBDAF90", Offset = "0xBDAF90", VA = "0xBDAF90", Slot = "33")]
protected virtual void Attack()
{
}
}

i want the monster become unable to attack me but instead edit it on hex editor ( i already do that and yes it work ) that can't be turned off, i want this function have a switch
 

LEIIKUN

Retired Staff
Retired but loved <3
Oct 13, 2019
502
10,946
1,193
20
Davao
and how to edit this ?
public partial class ActorMonster : ActorBase
{
// Token: 0x060000AF RID: 175 RVA: 0x00002050 File Offset: 0x00000250
[Token(Token = "0x60000A2")]
[Address(RVA = "0xBDAF90", Offset = "0xBDAF90", VA = "0xBDAF90", Slot = "33")]
protected virtual void Attack()
{
}
}

i want the monster become unable to attack me but instead edit it on hex editor ( i already do that and yes it work ) that can't be turned off, i want this function have a switch
Learn patching instead of using hex editor so you could turn it off. We already have a tutorial here on platinmods, search it.
 

DawnBreaker

Platinian
Nov 4, 2018
39
3,795
183
24
Earth
Learn patching instead of using hex editor so you could turn it off. We already have a tutorial here on platinmods, search it.
i have click all of the tutorial threads on this site, i learn modding using ida pro, hex patching, making mod menu (open dll), basic modding, etc from @DVAツ , @G-Bo ッ @AndnixSH , you @LEIIKUN , and other ( big thanks for all of you that want to share your knowledge in here ) . but, when i see the comment on How to make a Floatable Mod Menu [Team LGL] - {Beginners Tutorial} {All Explained} - Part 3 - Platinmods.com - Android & iOS MODs, Mobile Games & Apps , lot of friends in there saying that is morelike patching than hooking or something like that, that's why im curious what is a real hooking look like, and yeah although i almost reach the end of the tutorial threads, im not find something like " hooking tutorial full explained" that's why i asked in this thread's comment section about how to hook with a whole function than just hook with a offset. hooking with offset it's just like modding using hex editor with extra step. ty for your reply btw
 
  • Like
Reactions: iwnzjks

LEIIKUN

Retired Staff
Retired but loved <3
Oct 13, 2019
502
10,946
1,193
20
Davao
i have click all of the tutorial threads on this site, i learn modding using ida pro, hex patching, making mod menu (open dll), basic modding, etc from @DVAツ , @G-Bo ッ @AndnixSH , you @LEIIKUN , and other ( big thanks for all of you that want to share your knowledge in here ) . but, when i see the comment on How to make a Floatable Mod Menu [Team LGL] - {Beginners Tutorial} {All Explained} - Part 3 - Platinmods.com - Android & iOS MODs, Mobile Games & Apps , lot of friends in there saying that is morelike patching than hooking or something like that, that's why im curious what is a real hooking look like, and yeah although i almost reach the end of the tutorial threads, im not find something like " hooking tutorial full explained" that's why i asked in this thread's comment section about how to hook with a whole function than just hook with a offset. hooking with offset it's just like modding using hex editor with extra step. ty for your reply btw
Uhmm, inside the lgl mod menu original 'main.cpp', you can find several hooking examples, it is a completely example. Find it out and analyze!

lot of friends in there saying that is morelike patching than hooking
Yeah, indeed that video tutorial is showing a patching instead of hooking. Patching is when you still use hex codes.
 

DawnBreaker

Platinian
Nov 4, 2018
39
3,795
183
24
Earth
Uhmm, inside the lgl mod menu original 'main.cpp', you can find several hooking examples, it is a completely example. Find it out and analyze!


Yeah, indeed that video tutorial is showing a patching instead of hooking. Patching is when you still use hex codes.
i find the hooking example from the original lgl mod menu and i think i already find it out, but i have feeling it will be a million of trial and error. ty for your response