File tree Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Expand file tree Collapse file tree 3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change @@ -71,6 +71,25 @@ void hook_luaL_openlibs(lua_State* L)
7171 lua_pop (L, 1 );
7272}
7373
74+ /*
75+ Removes vprof.
76+ Why? Because in this case, lua_type is too fast and vprof creates a huge slowdown.
77+ */
78+ static Detouring::Hook detour_CLuaInterface_GetType;
79+ int hook_CLuaInterface_GetType (GarrysMod::Lua::ILuaInterface* pLua, int iStackPos)
80+ {
81+ int type = lua_type (pLua->GetState (), iStackPos);
82+
83+ if (type == GarrysMod::Lua::Type::UserData)
84+ {
85+ GarrysMod::Lua::ILuaBase::UserData* udata = (GarrysMod::Lua::ILuaBase::UserData*)pLua->GetUserdata (iStackPos);
86+ if (udata)
87+ type = udata->type ;
88+ }
89+
90+ return type == -1 ? GarrysMod::Lua::Type::Nil : type;
91+ }
92+
7493void CLuaJITModule::LuaInit (bool bServerInit)
7594{
7695 if (bServerInit)
@@ -235,4 +254,10 @@ void CLuaJITModule::InitDetour(bool bPreServer)
235254 Override (luaopen_package);
236255 Override (luaopen_string);
237256 Override (luaopen_table);
257+
258+ Detour::Create (
259+ &detour_CLuaInterface_GetType, " CLuaInterface::GetType" ,
260+ lua_shared_loader.GetModule (), Symbols::CLuaInterface_GetTypeSym,
261+ (void *)hook_CLuaInterface_GetType, m_pID
262+ );
238263}
Original file line number Diff line number Diff line change @@ -618,4 +618,11 @@ namespace Symbols
618618 const std::vector<Symbol> g_StartedSym = {
619619 Symbol::FromName (" _ZL9g_Started" ),
620620 };
621+
622+ // ---------------------------------------------------------------------------------
623+ // Purpose: luajit Symbols
624+ // ---------------------------------------------------------------------------------
625+ const std::vector<Symbol> CLuaInterface_GetTypeSym = {
626+ Symbol::FromName (" _ZN13CLuaInterface7GetTypeEi" ),
627+ };
621628}
Original file line number Diff line number Diff line change @@ -460,4 +460,10 @@ namespace Symbols
460460 extern const std::vector<Symbol> g_NetIncomingSym; // bf_read*
461461 extern const std::vector<Symbol> g_WriteSym; // bf_write*
462462 extern const std::vector<Symbol> g_StartedSym; // bool
463+
464+ // ---------------------------------------------------------------------------------
465+ // Purpose: luajit Symbols
466+ // ---------------------------------------------------------------------------------
467+ typedef int (*CLuaInterface_GetType)(GarrysMod::Lua::ILuaInterface* pLua);
468+ extern const std::vector<Symbol> CLuaInterface_GetTypeSym;
463469}
You can’t perform that action at this time.
0 commit comments