Help! How to Hook "m_name" field name?

CreeperMods

Platinian
Original poster
May 1, 2022
31
10
8
16
Philippines
How to hook m???
C#:
public class Player : MonoBehavior
{
    // Fields
    private float m_baseSpeed; // 0x68
}
Here’s my hook:
C++:
void (*old_m_baseSpeed)(void *instance);
void m_baseSpeed(void *instance) {
    if (speed6 > 1) {
        *(float *) ((uint32_t) instance + 0x68) = speed6;
    }
    return old_m_baseSpeed(instance);
}
Correct???
 

NepMods69

Inactive Approved Modder
Mar 6, 2022
122
5,164
193
Nepal
C++:
void(*old_speed)(void *instance);
void speed(void *instance) {
        if (isSpeed) {
            *(float *) ((uint64_t) instance + FieldOffset) = 50.0;
    }
    old_speed(instance);
}


And
HOOK_LIB("libil2cpp.so", "UpdateOffset", speed, old_speed);
like:



Screenshot_20220519-070714.png



you can use update() or fixedUpdate() to hook

for my hook:

C++:
void(*_NoTut)(void *instance); //this can also be done within the player update hook
void NoTut(void *instance) {
    if (NoTutOn) {
        *(bool *) ((uint64_t) instance + 0xC) = true;
    }
    else {
        *(bool *) ((uint64_t) instance + 0xC) = *(bool *) ((uint64_t) instance + 0xC);
    }
    _NoTut(instance);
}


HOOK_LIB("libil2cpp.so", "0x52C5EC", NoTut, _NoTut); //1
 
Last edited:

GamerUprise

Rookie
May 14, 2022
4
1
1
26
United States
C++:
void(*old_speed)(void *instance);
void speed(void *instance) {
        if (isSpeed) {
            *(float *) ((uint64_t) instance + FieldOffset) = 50.0;
    }
    old_speed(instance);
}


And
HOOK_LIB("libil2cpp.so", "UpdateOffset", speed, old_speed);
like:



View attachment 413878


you can use update() or fixedUpdate() to hook

for my hook:

C++:
void(*_NoTut)(void *instance); //this can also be done within the player update hook
void NoTut(void *instance) {
    if (NoTutOn) {
        *(bool *) ((uint64_t) instance + 0xC) = true;
    }
    else {
        *(bool *) ((uint64_t) instance + 0xC) = *(bool *) ((uint64_t) instance + 0xC);
    }
    _NoTut(instance);
}


HOOK_LIB("libil2cpp.so", "0x52C5EC", NoTut, _NoTut); //1

How would you be able to modify different classes within the same hook? Because I have a class with no update hook in it, and it's using 2 ints that are Field Offsets.

Update Hook Offset: (Class Name - WeaponInterface)
C#:
// Token: 0x06002E73 RID: 11891 RVA: 0x0000209A File Offset: 0x0000029A
[Token(Token = "0x6002E73")]
[Address(RVA = "0x121B3D8", Offset = "0x121B3D8", VA = "0x121B3D8", Slot = "4")]
public virtual void Update()
{
}

Bullet Counter Field Offset: (Class Name - WeaponInterface)
C#:
// Token: 0x040033F3 RID: 13299
[Token(Token = "0x40033F3")]
[FieldOffset(Offset = "0x90")]
[HideInInspector]
public int BulletsInClip;

Ammo Field Offset: (Class Name - WeaponInterface)
C#:
// Token: 0x04003409 RID: 13321
[Token(Token = "0x4003409")]
[FieldOffset(Offset = "0x110")]
public CapacityClass CapacityProperties;

Current Ammo + Max Ammo Field Offsets: (Class Name - CapacityClass)
C#:
using System;
using Il2CppDummyDll;

// Token: 0x02000999 RID: 2457
[Token(Token = "0x2000999")]
[Serializable]
public class CapacityClass
{
    // Token: 0x06002DBA RID: 11706 RVA: 0x0000209A File Offset: 0x0000029A
    [Token(Token = "0x6002DBA")]
    [Address(RVA = "0x1429EF0", Offset = "0x1429EF0", VA = "0x1429EF0")]
    public CapacityClass()
    {
    }

    // Token: 0x0400331B RID: 13083
    [Token(Token = "0x400331B")]
    [FieldOffset(Offset = "0x14")]
    [Attribute(Name = "RangeAttribute", RVA = "0x9FE1BC", Offset = "0x9FE1BC")]
    public int MagazineSize;

    // Token: 0x0400331C RID: 13084
    [Token(Token = "0x400331C")]
    [FieldOffset(Offset = "0x18")]
    public int TotalAmmo;
}

Initialize Hooks: (Android Studio)
C++:
void *hack_thread(void *) {
    LOGI(OBFUSCATE("pthread created"));

    do {
        sleep(1);
    } while (!isLibraryLoaded(targetLibName));

    LOGI(OBFUSCATE("%s has been loaded"), (const char *) targetLibName);

#if defined(__aarch64__)

    LOGI(OBFUSCATE("Hooking Addresses (x64-Bit)... "));
    HOOK_LIB("libil2cpp.so", "0x121B3D8", HookAmmo, UnHookAmmo);
    GetCapacityClass = (void *)getAbsoluteAddress(targetLibName, 0x1429EF0);
    LOGI(OBFUSCATE("Hooking Addresses (x64-Bit) - Completed "));

#else

    LOGI(OBFUSCATE("Hooking Addresses (x32-Bit)... "));
    HOOK_LIB("libil2cpp.so", "0x121B3D8", HookAmmo, UnHookAmmo);
    GetCapacityClass = (void *)getAbsoluteAddress(targetLibName, 0x1429EF0);
    LOGI(OBFUSCATE("Hooking Addresses (x32-Bit) - Completed "));


#endif

    return NULL;
}

My Hook: (Android Studio - Project)
C++:
bool unlimitedAmmoToggle;
int bulletCounter, currentAmmo, maxAmmo;
void *GetCapacityClass;

void (*UnHookAmmo)(void *instance);
void HookAmmo(void *instance) {
    if (instance != NULL) {
        if (GetCapacityClass != NULL) {
            if (unlimitedAmmoToggle) {
                if (bulletCounter == 0 && *(int *) ((uint64_t) instance + 0x90) != 0) {
                    bulletCounter = *(int *) ((uint64_t) instance + 0x90);
                    currentAmmo = *(int *) ((uint64_t) GetCapacityClass + 0x14);
                    maxAmmo = *(int *) ((uint64_t) GetCapacityClass + 0x18);
                    LOGI(OBFUSCATE("Bullet Counter: %d"), bulletCounter);
                    LOGI(OBFUSCATE("Current Ammo: %d"), currentAmmo);
                    LOGI(OBFUSCATE("Max Ammo: %d"), maxAmmo);
                }
                *(int *) ((uint64_t) instance + 0x90) = 90;
            } else {
                if (bulletCounter != 0) {
                    *(int *) ((uint64_t) instance + 0x90) = bulletCounter;
                    bulletCounter = 0;
                }
                return UnHookAmmo(instance);
            }
        }
    }
}

Final Results: (Android Studio - Logcat)
Code:
I/Mod_Menu: Bullet Counter: 30 //Correct Value & Offset (WeaponInterface)
I/Mod_Menu: Current Ammo: 840893416 //Incorrect Value & Offset (CapacityClass)
I/Mod_Menu: Max Ammo: -1191163896 //Incorrect Value & Offset (CapacityClass)
 

NepMods69

Inactive Approved Modder
Mar 6, 2022
122
5,164
193
Nepal
  • Love
Reactions: GamerUprise

GamerUprise

Rookie
May 14, 2022
4
1
1
26
United States

This Might Help You
It did help me, thank god after 5 days of searching and testing somehow I manage to find this and then you posted it lol.
 

GamerUprise

Rookie
May 14, 2022
4
1
1
26
United States
Glad to hear that
Any chance I would be able to call an enum class and return the int value from it? Trying to use the same method I did with the other one, but the game crashes as soon as it loads halfway onto level.

C++:
bool unlimitedAmmoToggle;
int weaponOwner, bulletCounter, currentAmmo, maxAmmo;
void *GetCapacityClass;
void *GetWeaponOwnerClass;

void (*UnHookAmmo)(void *instance);
void HookAmmo(void *instance) {
    if (instance != NULL) {
        //*
        // private Enumerations.WeaponOwner weaponOwner;
        //*
        GetWeaponOwnerClass = *(void **) ((uint64_t) instance + 0x30C); //Field Offset For WeaponOwner Enumeration
        if (GetWeaponOwnerClass != NULL) {
            //*
            // public CapacityClass CapacityProperties;
            //*
            GetCapacityClass = *(void **) ((uint64_t) instance + 0x110); //Field Offset For Capacity Class
            if (GetCapacityClass != NULL) {
                weaponOwner = *(int *) ((uint64_t) GetWeaponOwnerClass); //Converting Enum to Int
                if (weaponOwner == 0) { // ENUMS: [0 = Player; 1 = Enemy; 2 = Friendly; 3 = ServerPlayer]
                    if (unlimitedAmmoToggle) {
                        if (bulletCounter == 0 && *(int *) ((uint64_t) instance + 0x90) != 0) {
                            bulletCounter = *(int *) ((uint64_t) instance + 0x90);
                            currentAmmo = *(int *) ((uint64_t) GetCapacityClass + 0x14);
                            maxAmmo = *(int *) ((uint64_t) GetCapacityClass + 0x18);
                            LOGI(OBFUSCATE("Bullet Counter: %d"), bulletCounter);
                            LOGI(OBFUSCATE("Current Ammo: %d"), currentAmmo);
                            LOGI(OBFUSCATE("Max Ammo: %d"), maxAmmo);
                        }
                        *(int *) ((uint64_t) instance + 0x90) = 90;
                        *(int *) ((uint64_t) GetCapacityClass + 0x14) = 999;
                        *(int *) ((uint64_t) GetCapacityClass + 0x18) = 999;
                    } else {
                        if (bulletCounter != 0) {
                            *(int *) ((uint64_t) instance + 0x90) = bulletCounter;
                            *(int *) ((uint64_t) GetCapacityClass + 0x14) = currentAmmo;
                            *(int *) ((uint64_t) GetCapacityClass + 0x18) = maxAmmo;
                            bulletCounter = 0;
                        }
                        UnHookAmmo(instance);
                    }
                }
            }
        }
    }
}
 
  • Like
Reactions: Hackmodjoaogame