ByNameModding / BNM-Android

Modding il2cpp games by classes, methods, field names on Android.
MIT License
173 stars 37 forks source link

I tried but without success look what I did: #24

Closed evilmu closed 6 months ago

evilmu commented 6 months ago

Hello, ByNameModding!

I hope you are doing well. I want to take this moment to express my admiration for the work you are doing on BNM. The effort and creativity you've applied are remarkable, and it really makes a difference in the community.

Recently, I tried exploring a bit of BNM. Although I faced some personal challenges in the process, it only reinforced my respect for the complexity and depth of your work.

I want to highlight that, even without mastering it, I am genuinely impressed with what you have accomplished. It's incredible to see how the project is evolving and contributing to our field.

Please continue with this excellent work. You have my full support and admiration. I'm looking forward to seeing the next developments for BNM.

A big hug and all the best to you!

Sincerely, Evilmu

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;
        }

Thank you for posting BNM, even though I haven't gotten it yet, your work is perfect

Creator1A commented 6 months ago

There could be many different reasons as to why this isn't working. First of all, did you try other ways to hook the void method you're trying to mod? CreateFarmerNameMethod is a void method but then you're trying to do BNM::Method<monoString*> CreateFarmerNameMethod{};

Try this maybe:

BNM::LoadClass FarmerNameManagerClass{};

// assuming that the function you're trying to hook is a void
// if it is then it will only be called once the method CreateFarmerName is called since you did not use an update method 
void (*old_CreateFarmerNameA)(BNM::UnityEngine::Object*, monoString*);
void NewCreateFarmerName(BNM::UnityEngine::Object* instance, monoString* originalName) {
    // check if instance is not nullptr to avoid crashes(and since you're not hooking a static method):
    if(instance){
    monoString* newNameA = BNM::CreateMonoString("BILL GATES");
    old_CreateFarmerNameA(instance, newNameA);
    }
}

void OnLoaded() {
    using namespace BNM;
    FarmerNameManagerClass = LoadClass(OBFUSCATE_BNM("Assembly-CSharp"), OBFUSCATE_BNM("FarmerNameManager"));

    // same thing:
        HOOK(FarmerNameManagerClass.GetMethodByName(OBFUSCATE_BNM("CreateFarmerName"), 1), NewCreateFarmerName, old_CreateFarmerNameA);

}
evilmu commented 6 months ago

Tks

Creator1A commented 6 months ago

Hooking issue solved.

What they need is related to a BNM implementation method rather than the hooking itself.