ByNameModding / BNM-Android

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

An error occurred while running the StartCoroutine function #46

Closed solomode0001 closed 1 week ago

solomode0001 commented 1 week ago

Logs:

MethodAccessException: Attempt to access method 'System.Collections.IEnumerator.MoveNext' on type 'IEnumerator.BNM.Coroutine' failed.

Code:

BNM::Method<void*> StartCoroutine;

BNM::Coroutine::IEnumerator MyEnumerator() {
    LOGI("MyEnumerator Started");
    co_yield BNM::Coroutine::WaitForSeconds(5.0f);
    LOGI("MyEnumerator Finished");
   co_return;
}

void (*_PlayerScript_Start)(void*);
void PlayerScript_Start(BNM::UnityEngine::MonoBehaviour *ins) {
    _PlayerScript_Start(ins);

    auto enumerator = MyEnumerator().get();
    auto r = StartCoroutine[ins](enumerator);
    LOGI("Invoked: %p", r);
}

void OnLoad() {
    StartCoroutine = BNM::Class(OBFUSCATE_BNM("UnityEngine"), OBFUSCATE_BNM("MonoBehaviour")).GetMethod(OBFUSCATE_BNM("StartCoroutine"), {OBFUSCATE_BNM("routine")});

    auto playerScript = BNM::Class("", "PlayerScript");
    BNM::InvokeHook(playerScript.GetMethod("Start"), PlayerScript_Start, _PlayerScript_Start);
}
solomode0001 commented 1 week ago

Fixed...