Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CallMethod results in a crash #21

Closed
ALittlePatate opened this issue Sep 27, 2022 · 1 comment
Closed

CallMethod results in a crash #21

ALittlePatate opened this issue Sep 27, 2022 · 1 comment

Comments

@ALittlePatate
Copy link

I am currently rewriting my cheat for Devour using your library but i can't call a function without an access violation happening.
Original C# code (using MelonLoader) :

NolanRankController NolanRank = UnityEngine.Object.FindObjectOfType<NolanRankController>();
NolanRank.SetRank(50);

New C++ code (using IL2CPP Resolver) :

void OnUpdate() {
    if (settings::spoof_level) {
        Unity::CGameObject* NolanBehaviour = Unity::Object::FindObjectOfType<Unity::CGameObject>("NolanRankController");
        NolanBehaviour->CallMethodSafe<void*>("SetRank", 50);
    }
}

The code crashes at void* GetMethodPointer(Unity::il2cppClass* m_pClass, const char* m_pMethodName, int m_iArgs), line 176 of Class.cpp :

Unity::il2cppMethodInfo* pMethod = reinterpret_cast<Unity::il2cppMethodInfo*(IL2CPP_CALLING_CONVENTION)(void*, const char*, int)>(Data.Functions.m_pClassGetMethodFromName)(m_pClass, m_pMethodName, m_iArgs);

Result : "Access violation in GameAssembly.dll when reading at 0xFFFFFFFF20000133."

What am i missing there ?

@extremeblackliu
Copy link
Collaborator

extremeblackliu commented Sep 27, 2022

component is attached to a gameobject, you need to get component first.

Unity::CGameObject* AnyObject = Unity::GameObject::Find("TargetGameObjectName");
Unity::CComponent*  NolanRankController = AnyObject->GetComponent("NolanRankController");
NolanRankController->CallMethod<void*>("SetRank", 50);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants