ByNameModding / BNM-Android

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

ModMenu(LGL) file Android.mk #16

Closed evilmu closed 9 months ago

evilmu commented 10 months ago

Thanks, could you show an example with a class

public class ProtoPartnerAnimalBreed : ProtoData // TypeDefIndex: 12771 { // Fields [ProtoMemberAttribute] // RVA: 0x3A5218 Offset: 0x3A5218 VA: 0x3A5218 public float OrderScore; // 0x10

add a value to

OrderScore = 10000.0f;

BNM-Dev commented 9 months ago

You can't just set OrderScore to 10000.0f;. You need instance of ProtoPartnerAnimalBreed

evilmu commented 9 months ago

ProtoPartnerAnimalBreed MyAnimal= new ProtoPartnerAnimalBreed();

MyAnimal.OrderScore = 10000.0f;

I really didn't understand how to use it.

BNM-Dev commented 9 months ago

BNM has a lot of comments in src code. You can use: LoadClass::CreateNewInstance, LoadClass::CreateNewObject, LoadClass::CreateNewObjectArgs. I don't know which one is better for you. Read comments in BNM.h to find API that will be better for your problem.

evilmu commented 8 months ago

I tried but without success look what I did:

Class: public sealed class FarmerNameManager : MonoBehaviour, IUserBlobCallbacks2, IUserBlobCallbacksBase Method: public void CreateFarmerName(string farmerName) { }

#if !BNM_DISABLE_NEW_CLASSES
using namespace BNM::Structures::Mono;
using namespace BNM::Operators;

BNM::LoadClass FarmerNameManagerClass{};
BNM::Method<monoString*> CreateFarmerNameMethod{};

void (*old_CreateFarmerNameA)(BNM::UnityEngine::Object*, monoString*);
void NewCreateFarmerName(BNM::UnityEngine::Object* instance, monoString* originalName) {
    monoString* newNameA = BNM::CreateMonoString("BILL GATES");
    old_CreateFarmerNameA(instance, newNameA);
}

void OnLoaded() {
    using namespace BNM;
    FarmerNameManagerClass = LoadClass(OBFUSCATE_BNM("Assembly-CSharp"), OBFUSCATE_BNM("FarmerNameManager"));
    CreateFarmerNameMethod = FarmerNameManagerClass.GetMethodByName(OBFUSCATE_BNM("CreateFarmerName"), 1);

    InvokeHook(CreateFarmerNameMethod, NewCreateFarmerName, old_CreateFarmerNameA);
}
#endif
 case 14: {
      BNM::AddOnLoadedEvent(OnLoaded);
            break;
        }