Ejemplo n.º 1
0
        private static CSharpMethodHooker BindHook(Type oldType, Type replaceType, string oldName, string replaceName)
        {
            MethodInfo oldFun     = oldType.GetMethod(oldName);
            MethodInfo replaceFun = replaceType.GetMethod(replaceName);

            CSharpMethodHooker result = CSharpMethodHooker.HookCSMethod(oldFun, replaceFun);

            return(result);
        }
Ejemplo n.º 2
0
        public static void Install()
        {
#if TOLUA || XLUA || SLUA
            if (m_hooked)
            {
                return;
            }

            Type oldType     = typeof(OldLuaDLL);
            Type replaceType = typeof(LuaDLL);
            if (luaL_newstate_hooker == null)
            {
                luaL_newstate_hooker = BindHook(oldType, replaceType, "luaL_newstate", "luaL_newstate_replace");
            }

            if (lua_close_hooker == null)
            {
                lua_close_hooker = BindHook(oldType, replaceType, "lua_close", "lua_close_replace");
            }

            if (luaL_ref_hooker == null)
            {
                luaL_ref_hooker = BindHook(oldType, replaceType, "luaL_ref", "luaL_ref_replace");
            }

            if (luaL_unref_hooker == null)
            {
                luaL_unref_hooker = BindHook(oldType, replaceType, "luaL_unref", "luaL_unref_replace");
            }


            if (lua_load_buffer_hooker == null)
            {
#if TOLUA
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "tolua_loadbuffer", "luaL_loadbuffer_replace");
#elif XLUA
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "xluaL_loadbuffer", "luaL_loadbuffer_replace");
#elif SLUA
                oldType = typeof(SLua.LuaDLLWrapper);
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "luaLS_loadbuffer", "luaL_loadbuffer_replace");
#endif
            }
#if TOLUA
            if (tolua_ref_hooker == null)
            {
                tolua_ref_hooker = BindHook(oldType, replaceType, "toluaL_ref", "toluaL_ref_replace");
            }

            if (tolua_unref_hooker == null)
            {
                tolua_unref_hooker = BindHook(oldType, replaceType, "toluaL_unref", "toluaL_unref_replace");
            }
#endif
            m_hooked = true;
#endif
        }
Ejemplo n.º 3
0
        public static void Install()
        {
#if TOLUA || XLUA || SLUA
            if (m_hooked)
            {
                return;
            }

            Type oldType     = typeof(OldLuaDLL);
            Type replaceType = typeof(LuaDLL);
            if (luaL_newstate_hooker == null)
            {
                luaL_newstate_hooker = BindHook(oldType, replaceType, "luaL_newstate", "luaL_newstate_replace");
            }

            if (lua_close_hooker == null)
            {
                lua_close_hooker = BindHook(oldType, replaceType, "lua_close", "lua_close_replace");
            }

            if (luaRefFun == null)
            {
                luaRefFun = (LuaRefFun)BindNative <LuaRefFun>("luaL_ref", new LuaRefFun(luaL_ref_replace));
            }

            if (luaUnrefFun == null)
            {
                luaUnrefFun = (LuaUnrefFun)BindNative <LuaUnrefFun>("luaL_unref", new LuaUnrefFun(luaL_unref_replace));
            }

            if (luaLoadbufferFun == null)
            {
#if XLUA
                luaLoadbufferFun = (LuaLoadbufferFun)BindNative <LuaLoadbufferFun>("xluaL_loadbuffer", new LuaLoadbufferFun(luaL_loadbuffer_replace));
#else
                luaLoadbufferFun = (LuaLoadbufferFun)BindNative <LuaLoadbufferFun>("luaL_loadbuffer", new LuaLoadbufferFun(luaL_loadbuffer_replace));
#endif
            }
#if TOLUA
            if (tolua_ref_hooker == null)
            {
                tolua_ref_hooker = BindHook(oldType, replaceType, "toluaL_ref", "toluaL_ref_replace");
            }

            if (tolua_unref_hooker == null)
            {
                tolua_unref_hooker = BindHook(oldType, replaceType, "toluaL_unref", "toluaL_unref_replace");
            }
#endif
            m_hooked = true;
#endif
        }
Ejemplo n.º 4
0
        public static void UnInstall()
        {
#if TOLUA || XLUA || SLUA
            if (luaL_newstate_hooker != null)
            {
                luaL_newstate_hooker.Uninstall();
                luaL_newstate_hooker = null;
            }

            if (lua_close_hooker != null)
            {
                lua_close_hooker.Uninstall();
                lua_close_hooker = null;
            }

            if (lua_load_buffer_hooker != null)
            {
                lua_load_buffer_hooker.Uninstall();
                lua_load_buffer_hooker = null;
            }

            if (luaL_ref_hooker != null)
            {
                luaL_ref_hooker.Uninstall();
                luaL_ref_hooker = null;
            }

            if (luaL_unref_hooker != null)
            {
                luaL_unref_hooker.Uninstall();
                luaL_unref_hooker = null;
            }

#if TOLUA
            if (tolua_ref_hooker != null)
            {
                tolua_ref_hooker.Uninstall();
                tolua_ref_hooker = null;
            }

            if (tolua_unref_hooker != null)
            {
                tolua_unref_hooker.Uninstall();
                tolua_unref_hooker = null;
            }
#endif
            m_hooked = false;
#endif
        }
Ejemplo n.º 5
0
        private static CSharpMethodHooker BindHook(Type oldType, Type replaceType, string oldName, string replaceName)
        {
            MethodInfo oldFun = null;

            if (oldName == "luaL_ref")
            {
                oldFun = oldType.GetMethod(oldName, new Type[] { typeof(IntPtr), typeof(int) });
            }
            else if (oldName == "luaL_unref")
            {
                oldFun = oldType.GetMethod(oldName, new Type[] { typeof(IntPtr), typeof(int), typeof(int) });
            }
            else
            {
                oldFun = oldType.GetMethod(oldName);
            }
            MethodInfo replaceFun = replaceType.GetMethod(replaceName);

            CSharpMethodHooker result = CSharpMethodHooker.HookCSMethod(oldFun, replaceFun);

            return(result);
        }
Ejemplo n.º 6
0
        public static void Install()
        {
#if TOLUA || XLUA || SLUA
            if (m_hooked)
            {
                return;
            }

            Type oldType     = typeof(OldLuaDLL);
            Type replaceType = typeof(LuaDLL);
            if (luaL_newstate_hooker == null)
            {
                luaL_newstate_hooker = BindHook(oldType, replaceType, "luaL_newstate", "luaL_newstate_replace");
            }

            if (lua_close_hooker == null)
            {
                lua_close_hooker = BindHook(oldType, replaceType, "lua_close", "lua_close_replace");
            }

            if (luaL_ref_hooker == null)
            {
                luaL_ref_hooker = BindHook(oldType, replaceType, "luaL_ref", "luaL_ref_replace");
            }

            if (luaL_unref_hooker == null)
            {
                luaL_unref_hooker = BindHook(oldType, replaceType, "luaL_unref", "luaL_unref_replace");
            }


            if (lua_load_buffer_hooker == null)
            {
#if TOLUA
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "tolua_loadbuffer", "luaL_loadbuffer_replace");
#elif XLUA
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "xluaL_loadbuffer", "luaL_loadbuffer_replace");
#elif SLUA
                oldType = typeof(SLua.LuaDLLWrapper);
                lua_load_buffer_hooker = BindHook(oldType, replaceType, "luaLS_loadbuffer", "luaL_loadbuffer_replace");
#endif
            }
#if TOLUA
            if (tolua_ref_hooker == null)
            {
                MethodInfo oldFun     = oldType.GetMethod("toluaL_ref");
                MethodInfo replaceFun = replaceType.GetMethod("toluaL_ref_replace");
                MethodInfo proxyFun   = replaceType.GetMethod("toluaL_ref_proxy");

                tolua_ref_hooker = CSharpMethodHooker.HookCSMethod(oldFun, replaceFun, proxyFun);
            }

            if (tolua_unref_hooker == null)
            {
                MethodInfo oldFun     = oldType.GetMethod("toluaL_unref");
                MethodInfo replaceFun = replaceType.GetMethod("toluaL_unref_replace");
                MethodInfo proxyFun   = replaceType.GetMethod("toluaL_unref_proxy");

                tolua_unref_hooker = CSharpMethodHooker.HookCSMethod(oldFun, replaceFun, proxyFun);
            }
#endif
            m_hooked = true;
#endif
        }