@@ -147,20 +147,14 @@ static void hook_CVProfile_OutputReport(void* fancy, int type, const tchar* pszS
147147 ss.str (" " );
148148}
149149
150- static int pCurrentGamemodeFunction = - 1 ;
150+ static const char * pCurrentGamemodeFunction = NULL ;
151151static std::map<int , std::string> CallWithArgs_strs;
152152static Detouring::Hook detour_CLuaGamemode_CallWithArgs;
153153static void * hook_CLuaGamemode_CallWithArgs (void * funky_srv, int pool)
154154{
155155 if (!g_Lua)
156156 return detour_CLuaGamemode_CallWithArgs.GetTrampoline <Symbols::CLuaGamemode_CallWithArgs>()(funky_srv, pool);
157157
158- #if ARCHITECTURE_IS_X86_64
159- Msg (" Value: %p\n " , (void *)pool);
160- Msg (" Value Int: %i\n " , pool);
161- Msg (" Value Str: %s\n " , (const char *)pool); // Verify: Did we get the symbol for the const char* version?
162- #endif
163-
164158 const char * pStr = nullptr ;
165159 auto it = CallWithArgs_strs.find (pool);
166160 if (it == CallWithArgs_strs.end ())
@@ -171,27 +165,56 @@ static void* hook_CLuaGamemode_CallWithArgs(void* funky_srv, int pool)
171165 pStr = it->second .c_str ();
172166 }
173167
174- pCurrentGamemodeFunction = pool;
168+ pCurrentGamemodeFunction = g_Lua-> GetPooledString ( pool) ;
175169
176170 VPROF_BUDGET (pStr, " GMOD" );
177171
178172 return detour_CLuaGamemode_CallWithArgs.GetTrampoline <Symbols::CLuaGamemode_CallWithArgs>()(funky_srv, pool);
179173}
180174
181- static std::map<int , std::string> CallFinish_strs;
175+ static std::map<std::string_view, std::string> CallWithArgsStr_strs;
176+ static Detouring::Hook detour_CLuaGamemode_CallWithArgsStr;
177+ static void * hook_CLuaGamemode_CallWithArgsStr (void * funky_srv, const char * str)
178+ {
179+ if (!g_Lua)
180+ return detour_CLuaGamemode_CallWithArgs.GetTrampoline <Symbols::CLuaGamemode_CallWithArgsStr>()(funky_srv, str);
181+
182+ const char * pStr = nullptr ;
183+ auto it = CallWithArgsStr_strs.find (str);
184+ if (it == CallWithArgsStr_strs.end ())
185+ {
186+ CallWithArgsStr_strs[str] = " CLuaGamemode::CallWithArgs (" + (std::string)str + " )" ;
187+ pStr = CallWithArgsStr_strs[str].c_str ();
188+ } else {
189+ pStr = it->second .c_str ();
190+ }
191+
192+ pCurrentGamemodeFunction = str;
193+
194+ VPROF_BUDGET (pStr, " GMOD" );
195+
196+ return detour_CLuaGamemode_CallWithArgs.GetTrampoline <Symbols::CLuaGamemode_CallWithArgsStr>()(funky_srv, str);
197+ }
198+
199+ static std::map<std::string_view, std::string> CallFinish_strs;
182200static Detouring::Hook detour_CLuaGamemode_CallFinish;
183201static void * hook_CLuaGamemode_CallFinish (void * funky_srv, int pArgs)
184202{
185- if (!g_Lua || pCurrentGamemodeFunction == - 1 )
203+ if (!g_Lua || ! pCurrentGamemodeFunction)
186204 return detour_CLuaGamemode_CallFinish.GetTrampoline <Symbols::CLuaGamemode_CallFinish>()(funky_srv, pArgs);
187205
188- if (CallFinish_strs.find (pCurrentGamemodeFunction) == CallFinish_strs.end ())
206+ const char * pStr = nullptr ;
207+ auto it = CallFinish_strs.find (pCurrentGamemodeFunction);
208+ if (it == CallFinish_strs.end ())
189209 {
190- CallFinish_strs[pCurrentGamemodeFunction] = " CLuaGamemode::CallFinish (" + (std::string)g_Lua->GetPooledString (pCurrentGamemodeFunction) + " )" ;
210+ CallFinish_strs[pCurrentGamemodeFunction] = " CLuaGamemode::CallFinish (" + (std::string)pCurrentGamemodeFunction + " )" ;
211+ pStr = CallFinish_strs[pCurrentGamemodeFunction].c_str ();
212+ } else {
213+ pStr = it->second .c_str ();
191214 }
192215
193- VPROF_BUDGET (CallFinish_strs[pCurrentGamemodeFunction]. c_str () , " GMOD" );
194- pCurrentGamemodeFunction = - 1 ;
216+ VPROF_BUDGET (pStr , " GMOD" );
217+ pCurrentGamemodeFunction = NULL ;
195218
196219 return detour_CLuaGamemode_CallFinish.GetTrampoline <Symbols::CLuaGamemode_CallFinish>()(funky_srv, pArgs);
197220}
@@ -218,6 +241,28 @@ static void* hook_CLuaGamemode_Call(void* funky_srv, int pool)
218241 return detour_CLuaGamemode_Call.GetTrampoline <Symbols::CLuaGamemode_Call>()(funky_srv, pool);
219242}
220243
244+ static std::map<std::string_view, std::string> CallStr_strs;
245+ static Detouring::Hook detour_CLuaGamemode_CallStr;
246+ static void * hook_CLuaGamemode_CallStr (void * funky_srv, const char * str)
247+ {
248+ if (!g_Lua)
249+ return detour_CLuaGamemode_CallStr.GetTrampoline <Symbols::CLuaGamemode_CallStr>()(funky_srv, str);
250+
251+ const char * pStr = nullptr ;
252+ auto it = CallStr_strs.find (str);
253+ if (it == CallStr_strs.end ())
254+ {
255+ CallStr_strs[str] = " CLuaGamemode::Call (" + (std::string)str + " )" ;
256+ pStr = CallStr_strs[str].c_str ();
257+ } else {
258+ pStr = it->second .c_str ();
259+ }
260+
261+ VPROF_BUDGET (pStr, " GMOD" );
262+
263+ return detour_CLuaGamemode_CallStr.GetTrampoline <Symbols::CLuaGamemode_CallStr>()(funky_srv, str);
264+ }
265+
221266/*
222267 * Scripted Entities calls
223268 *
@@ -354,16 +399,21 @@ static void* hook_Client_CLuaGamemode_CallWithArgs(void* funky_srv, int pool)
354399static Detouring::Hook detour_Client_CLuaGamemode_CallFinish;
355400static void * hook_Client_CLuaGamemode_CallFinish (void * funky_srv, int pArgs)
356401{
357- if (!g_Lua || pClient_CurrentGamemodeFunction == - 1 )
358- return detour_CLuaGamemode_CallFinish .GetTrampoline <Symbols::CLuaGamemode_CallFinish>()(funky_srv, pArgs);
402+ if (!g_Lua || !pCurrentGamemodeFunction )
403+ return detour_Client_CLuaGamemode_CallFinish .GetTrampoline <Symbols::CLuaGamemode_CallFinish>()(funky_srv, pArgs);
359404
360- if (CallFinish_strs.find (pClient_CurrentGamemodeFunction) == CallFinish_strs.end ())
405+ const char * pStr = nullptr ;
406+ auto it = CallFinish_strs.find (pCurrentGamemodeFunction);
407+ if (it == CallFinish_strs.end ())
361408 {
362- CallFinish_strs[pClient_CurrentGamemodeFunction] = " CLuaGamemode::CallFinish (" + (std::string)g_Lua->GetPooledString (pClient_CurrentGamemodeFunction) + " )" ;
409+ CallFinish_strs[pCurrentGamemodeFunction] = " CLuaGamemode::CallFinish (" + (std::string)pCurrentGamemodeFunction + " )" ;
410+ pStr = CallFinish_strs[pCurrentGamemodeFunction].c_str ();
411+ } else {
412+ pStr = it->second .c_str ();
363413 }
364414
365- VPROF_BUDGET (CallFinish_strs[pClient_CurrentGamemodeFunction]. c_str () , " GMOD" );
366- pClient_CurrentGamemodeFunction = - 1 ;
415+ VPROF_BUDGET (pStr , " GMOD" );
416+ pCurrentGamemodeFunction = NULL ;
367417
368418 return detour_Client_CLuaGamemode_CallFinish.GetTrampoline <Symbols::CLuaGamemode_CallFinish>()(funky_srv, pArgs);
369419}
@@ -508,7 +558,13 @@ void CVProfModule::InitDetour(bool bPreServer)
508558
509559 SourceSDK::ModuleLoader server_loader (" server" );
510560 Detour::Create (
511- &detour_CLuaGamemode_Call, " CLuaGamemode::Call" ,
561+ &detour_CLuaGamemode_CallStr, " CLuaGamemode::Call(const char*)" ,
562+ server_loader.GetModule (), Symbols::CLuaGamemode_CallStrSym,
563+ (void *)hook_CLuaGamemode_CallStr, m_pID
564+ );
565+
566+ Detour::Create (
567+ &detour_CLuaGamemode_Call, " CLuaGamemode::Call(int)" ,
512568 server_loader.GetModule (), Symbols::CLuaGamemode_CallSym,
513569 (void *)hook_CLuaGamemode_Call, m_pID
514570 );
@@ -520,7 +576,13 @@ void CVProfModule::InitDetour(bool bPreServer)
520576 );
521577
522578 Detour::Create (
523- &detour_CLuaGamemode_CallWithArgs, " CLuaGamemode::CallWithArgs" ,
579+ &detour_CLuaGamemode_CallWithArgsStr, " CLuaGamemode::CallWithArgs(const char*)" ,
580+ server_loader.GetModule (), Symbols::CLuaGamemode_CallWithArgsStrSym,
581+ (void *)hook_CLuaGamemode_CallWithArgsStr, m_pID
582+ );
583+
584+ Detour::Create (
585+ &detour_CLuaGamemode_CallWithArgs, " CLuaGamemode::CallWithArgs(int)" ,
524586 server_loader.GetModule (), Symbols::CLuaGamemode_CallWithArgsSym,
525587 (void *)hook_CLuaGamemode_CallWithArgs, m_pID
526588 );
0 commit comments