Cleanup detour structures properly on unload

This commit is contained in:
Peace-Maker 2016-12-11 22:18:53 -07:00
parent 2e52ab24b7
commit 63ccb7448f
3 changed files with 32 additions and 2 deletions

View File

@ -150,6 +150,36 @@ void RemoveAllCallbacksForContext(IPluginContext *pContext)
RemoveAllCallbacksForContext(HOOKTYPE_POST, &g_pPostDetours, pContext); RemoveAllCallbacksForContext(HOOKTYPE_POST, &g_pPostDetours, pContext);
} }
void CleanupDetours(HookType_t hookType, DetourMap *map)
{
PluginCallbackList *wrappers;
CDynamicHooksSourcePawn *pWrapper;
DetourMap::iterator it = map->iter();
// Run through all active detours we added.
for (; !it.empty(); it.next())
{
wrappers = it->value;
// See if there are callbacks of this plugin context registered
// and remove them.
for (int i = wrappers->length() - 1; i >= 0; i--)
{
pWrapper = wrappers->at(i);
delete pWrapper;
}
// Unhook the function
delete wrappers;
UnhookFunction(hookType, it->key);
}
map->clear();
}
void CleanupDetours()
{
CleanupDetours(HOOKTYPE_PRE, &g_pPreDetours);
CleanupDetours(HOOKTYPE_POST, &g_pPostDetours);
}
ICallingConvention *ConstructCallingConvention(HookSetup *setup) ICallingConvention *ConstructCallingConvention(HookSetup *setup)
{ {
std::vector<DataTypeSized_t> vecArgTypes; std::vector<DataTypeSized_t> vecArgTypes;

View File

@ -37,5 +37,6 @@ bool HandleDetour(HookType_t hookType, CHook* pDetour);
bool AddDetourPluginHook(HookType_t hookType, CHook *pDetour, HookSetup *setup, IPluginFunction *pCallback); bool AddDetourPluginHook(HookType_t hookType, CHook *pDetour, HookSetup *setup, IPluginFunction *pCallback);
bool RemoveDetourPluginHook(HookType_t hookType, CHook *pDetour, IPluginFunction *pCallback); bool RemoveDetourPluginHook(HookType_t hookType, CHook *pDetour, IPluginFunction *pCallback);
void RemoveAllCallbacksForContext(IPluginContext *pContext); void RemoveAllCallbacksForContext(IPluginContext *pContext);
void CleanupDetours();
#endif #endif

View File

@ -89,8 +89,7 @@ void DHooks::SDK_OnAllLoaded()
void DHooks::SDK_OnUnload() void DHooks::SDK_OnUnload()
{ {
CleanupHooks(); CleanupHooks();
// FIXME: Unhook only functions that are hooked by a plugin. + cleanup CleanupDetours();
GetHookManager()->UnhookAllFunctions();
if(g_pEntityListener) if(g_pEntityListener)
{ {
g_pEntityListener->CleanupListeners(); g_pEntityListener->CleanupListeners();