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

il2cpp下是否无法使用 #27

Open
AxelHu opened this issue Dec 3, 2020 · 2 comments
Open

il2cpp下是否无法使用 #27

AxelHu opened this issue Dec 3, 2020 · 2 comments

Comments

@AxelHu
Copy link

AxelHu commented Dec 3, 2020

最近在尝试使用Miku-LuaProfiler测试项目中的lua代码的性能。

项目使用的是2018.4/tolua,用的是Miku-LuaProfiler的master分支,开启了il2cpp。

打包之后在安卓机器上运行会crash,看logcat信息发现是空指针错误导致的,通过定位最后检查到出错的是这段代码。

在NativeAPI.cs类中(MikuHook.dll里的)

public static IntPtr GetFunctionAddr(MethodBase method)
{
	return method?.MethodHandle.GetFunctionPointer() ?? IntPtr.Zero;
}

从后续的排查来看是MethodHandle是非空的,但GetFunctionPointer()返回的是null或者IntPtr.Zero。

我搜了搜没搜到有特地提到这个方法未实现的帖子或问答,从unity的scripting restrictions页面来看,这个方法所在类使用了System.Runtime.Serialization,确实很有可能没被il2cpp支持。

发这个issue还是想确认下il2cpp下是否无法使用,因为没有看到有相关的issue。以及如果确定无法使用,是否有支持的办法/支持的打算。

顺便,mono下是可以跑并接收到数据的,可以在mono下对比并进行优化。只是因为最后发的包都是il2cpp的,如果可以的话,还是希望能在il2cpp下直接收集到数据。

@leinlin
Copy link
Owner

leinlin commented Dec 10, 2020

对的 用了 C#的hook库无法在IL2CPP下使用,可以用mono的....当然你如果知道我HOOK后都干了什么可以自己把代码加上就可以了....

@AxelHu
Copy link
Author

AxelHu commented Dec 11, 2020

这个听起来确实可行,我照着LuaDLL.Install()里面的写法改了一下tolua里的LuaDLL.cs,然后注掉了Install()里面的BindHook(),确实可以在il2cpp下在手机上运行并收到数据。

不过不是很确定改的对不对,其他应该没什么问题,主要是toluaL_ref_replace,我看了下master分支上有个toluaL_ref_proxy,里面除了fxxk misaka之外没做其他事就注释掉了,按照tolua的写法获取了ref的值并且作为参数传进去了。

public static int toluaL_ref_replace(IntPtr L)
{
    lock (MikuLuaProfiler.LuaDLL.m_Lock)
    {
        //int num = toluaL_ref_proxy(L);
        //LuaHook.HookRef(L, num, tolua_Getref_Fun);
        lua_pushvalue(L, -1);
        int refVal = toluaL_ref(L);
        MikuLuaProfiler.LuaHook.HookRef(L, refVal, MikuLuaProfiler.LuaDLL.tolua_Getref_Fun);
        //return num;
        return refVal;
    }
}

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