Solved need help with modding

root256

Approved Modder
Approved Modder
So, I don’t really know how to explain it, but here goes:

In Unity games, there’s a set thing (like set_health or something similar). The normal hooks don’t work I Searched over the internet, and I’m not sure what this is :/

For example, the set_health function requires the character instance.

The main question is: How do I get the current character instance and use it when calling set_health in an Android mod menu (by LGL team)?
 
C++:
#define targetLibName OBFUSCATE("libil2cpp.so")

void (*set_health)(void *instance, float amount);

// You can use Start, Awake, Update, LateUpdate, FixedUpdate, or any other method that you know will eventually get called within the game.
void *classInstance;
void (*old_Start)(void *instance);
void Start(void *instance) {
    if (instance != nullptr) {
        classInstance = instance;
    }
    old_Start(instance);
}

// If the method is called multiple times, make sure that "classInstance" is only initialized once.
/*void (*old_Update)(void *instance);
void Update(void *instance) {
    if (instance != nullptr) {
        if (classInstance == nullptr) {
            classInstance = instance;
        }
    }
    old_Update(instance);
}*/

void *hack_thread(void *) {
    HOOK("0x1234567", Start, old_Start);
    set_health = (void (*)(void *, float))getAbsoluteAddress(targetLibName, string2Offset(OBFUSCATE("0x1234567")));
    return nullptr;
}

// Call the method like this:
set_health(classInstance, 69.0f);
Good luck!
 
Still don't get some stuff
So first offset hook_lib is for update?
And second is for set_health offset?
And how does it gets character instance?

Does update() holds character istance? :/

And if update offset is called like non stop needs to be second template?
 
So first offset hook_lib is for update?
In the code I gave, it's for Start, but you can modify it to use Update (or any other method) if you want.

And second is for set_health offset?
Yes.

And how does it gets character instance?
When you hook a non-static method, the first parameter will always be the object instance that called the method (could be the character, enemy, etc.).

Does update() holds character istance? :/
If the Update() method is inside the character class, yes.

And if update offset is called like non stop needs to be second template?
You don't have to, since the only thing I added is the "if (classInstance == nullptr) { }" statement, so that it doesn't get reinitialized every frame.
 
Still don't get some stuff
So first offset hook_lib is for update?
And second is for set_health offset?
And how does it gets character instance?

Does update() holds character istance? :/

And if update offset is called like non stop needs to be second template?
To your question, EVERY method within your dump.cs or Assembly-CSharp.dll HOLDS an "Instance".

Static Methods DO NOT have an instance, as static methods belongs to its own class.

If you see a method like "public static time", you can modify it in any class as it is part of the main class, so you can call it anywhere without instance.

So yes, Update() when you're hooking it, you will need to create an instance for it.

Instance methods hold an instance because they require a OBJECT pointer.
Static methods do not hold an instance because they belong to the class itself.
IL2CPP converts instance methods into functions with an explicit OBJECT pointer.
 
Back
Top Bottom