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

Tutorial How to hook IEnumerable methods in Unity's Il2cpp

Numark

Awesome Active Platinian
Hey guys, slice cast here again with another tutorial. I will show you how to hook an IEnumerable.

Let's say you found a method something like Username, Ban, Recoil, Reload, or whatever it is and it's an IEnumerable type. I don't really understand the concept of IEnumerable, but you can find out what it does by searching it.

Anyways let's get started.

We have this method like
C++:
private IEnumerator UnBanPlayer (string playerToKick)

Now if you scroll all the way down of the class, you will find something like this called
<UnbanPlayer>d__507>
Something like that.


We open that and we see some fields. One could say UserID or playername.

lets say we modify UserID and it's an integer/int type. So how do we modify it?


It's simple.

We're basically gonna hook this by calling the method with MoveNext().

C++:
//the void *instance is a self-created variable.
Void (*old_UnbanPlayer_MoveNext)(void *instance);
Void UnbanPlayer_MoveNext(void *instance) {
    //Check if instance is NULL to prevent CRASH
    if (instance != NULL)
    {
        *(int *) ((uint64_t)instance + 0x4C) = 18372819; //Return how many value
    }
    old_UnbanPlayer_MoveNext(instance);
}

Easy, now call your hooks using MSHook if using substrate.

C++:
MSHookFunction((void*)getAbsoluteAddress(OFFSETS), (void*)UnbanPlayer_MoveNext, (void**)&UnbanPlayer_MoveNext;

That's all for now, hope you enjoyed this tutorial.
If you're new to this and don't know how to do it, please don't come into the comment section and asking me for help. This is all the help you will get because I explained it for you since this is a tutorial after all. If you're a newbie, don't try the hard stuff.
 
Last edited:
what if the offset of the methods just like this " 0x6C " the offset are shorter than usual offset? should i just put it straight into the hook?
 
@Tiuu I just need help with what do we hook?
Do we hook this part of an IEnumerable:
C#:
private IEnumerator UnBanPlayer (string playerToKick)
Or this part:
<UnbanPlayer>d__507>
 
@Tiuu I just need help with what do we hook?
Do we hook this part of an IEnumerable:
C#:
private IEnumerator UnBanPlayer (string playerToKick)
Or this part:
<UnbanPlayer>d__507>

You're looking for an IEnumerator or Enumeral method, so yeah you will need to use and hook <UnbanPlayer>d__507>
 
You're looking for an IEnumerator or Enumeral method, so yeah you will need to use and hook <UnbanPlayer>d__507>
if i have an invoke method like this [Address(RVA = "0x1B5AA2C", Offset = "0x1B5AA2C", VA = "0x1B5AA2C", Slot = "12")]
public extern void Invoke(int inXP, bool lVisible);
How to use it ? i can't use pointer function cuz it needs Update method . i can't use Hooking Function cuz that invoke has int inXP, bool lVisible , it does not return like normal functions to hook it like [Address(RVA = "0x1A57F80", Offset = "0x1A57F80", VA = "0x1A57F80")]
public bool IsBuildable()
{
return default(bool);
}
 
//the void *instance is a self-created variable.
Void (*old_UnbanPlayer_MoveNext)(void *instance);
Void UnbanPlayer_MoveNext(void *instance) {
//Check if instance is NULL to prevent CRASH
if (instance != NULL)
{
*(int *) ((uint64_t)instance + 0x4C) = 18372819; //Return how many value
}
old_UnbanPlayer_MoveNext(instance);
}


...............................................................................
Is this work in 32 bit support or I say in arm7
 
Saya sedang mempelajari mod metode kait. Metode ini sangat menarik bagi saya. Apakah ini perlu jika kita ingin tetap berada di dalam ruangan saat kepala ruangan mencoba mengusir kita keluar dari ruangan? Maaf untuk bahasanya yang kasar, karena ini adalah terjemahan mesin.