ByNameModding / BNM-Android

Modding il2cpp games by classes, methods, fields names on Android.
MIT License
210 stars 41 forks source link

How to hook static fields #43

Closed 2079541547 closed 2 months ago

2079541547 commented 3 months ago

I want to do what the hook static field should do. The following is using Tool dump

Screenshot_20240622_103704 Screenshot_20240622_103645

Lsc0x80 commented 3 months ago
//...
auto ItemID_Sets_c = BNM::Class("Terraria.ID", "ItemID").GetInnerClass("Sets");
BNM::Field<BNM::Mono::Array<bool>> Deprecated = ItemID_Sets_c.GetField("Deprecated");
for (const bool& a : Deprecated.Get()->ToVector())
{
    // Code that writes values to file
}
// this line sets 13th element to true
Deprecated.Get()[12] = true;

//...
2079541547 commented 3 months ago

Thank you, good comrade

2079541547 commented 3 months ago

I want to create a new field inside itemid and hook the switch branch of SetDefaults5 in item, I want to be able to call this.DefaultToAccessory(30, 42); What can I do with code like this? image image