catlowlevel / ModTemplate

My Template for modding unity(il2cpp) games for android
GNU General Public License v3.0
17 stars 7 forks source link

[feature] add please ByNameModding #5

Closed drakulaboy closed 5 months ago

drakulaboy commented 6 months ago

can you add ByNameModding to the Mod Menu please, i tried but fail to compile

catlowlevel commented 6 months ago

Tell me which feature you need from BNM?

drakulaboy commented 6 months ago

i want to find/hook this kind of fields from the methods that doesn't have some "Update" offset Screenshot_20240107_084559_bin mt plus

i was looking at the example [Finding everything by names (classes, methods, fields) Finding everything by names but couldn't understand how to do a simple field hook

nik2143 commented 6 months ago

You can't hook them without an instance of class

drakulaboy commented 6 months ago

can't hook them

so, for this kind of classes and fields i can't use BNM?

nik2143 commented 6 months ago

But this isn't BNM repo You are asking on wrong repository

Dae-Moon commented 5 months ago

i want to find/hook this kind of fields from the methods that doesn't have some "Update" offset Screenshot_20240107_084559_bin mt plus

i was looking at the example [Finding everything by names (classes, methods, fields) Finding everything by names but couldn't understand how to do a simple field hook

To get the values of the fields, find an instance of the class (in your case, this is instance). Copy the address of 'PlayerController_TypeInfo' from the 'script.json' generated by Il2CppDumper and add the base address to it GameAssembly.dll. Find the offset to the static fields (usually 0x5C for 32 bit, 0x5C * 2 for 64 bit), and add the field offset to the resulting address. Now you have the value of the field!

For example: Безымянный

it is important to note that if there is no reference to the class in the instance field, then the address will be different

catlowlevel commented 5 months ago

i want to find/hook this kind of fields from the methods that doesn't have some "Update" offset Screenshot_20240107_084559_bin mt plus

i was looking at the example [Finding everything by names (classes, methods, fields) Finding everything by names but couldn't understand how to do a simple field hook

If you want to modify the value of a field in a class that has no Update method, find other classes that have the same PlayerController class as a field, but also have an Update method.

For example:

public class PlayerController 
{
    public float damageBullet; // 0x00

    // No Update method
}

public class Character 
{
    public PlayerController playerController; // 0x00

    // Has an Update function
    void Update();
}

the Character class contains both an Update method and a reference to the PlayerController class. with this information, you can hook the Update method. Here's an example how you'd do it with this repo:

void Update(Il2CppObject* character){
    Il2CppObject* playerController = character->getField<Il2CppObject*>("playerController");
    float damageBullet = playerController->getField<float>("damageBullet"); // Retrieve the value from the PlayerController
    playerController->setField<float>("damageBullet", 999.f);
    return character->invoke_method("Update");
}
...
REPLACE_NAME("Character", "Update", Update);

you did not necessarily need an Update method to change a field value, it can be any method inside the same class as long as you are sure it is get called

drakulaboy commented 5 months ago

@catlowlevel this is the most simple and good explanation, and it really worked from the first time, thank you, means i don't need any BNM, yay! Case closed!