diff --git a/dynhooks_sourcepawn.cpp b/dynhooks_sourcepawn.cpp index de4820d..d573f09 100644 --- a/dynhooks_sourcepawn.cpp +++ b/dynhooks_sourcepawn.cpp @@ -150,6 +150,36 @@ void RemoveAllCallbacksForContext(IPluginContext *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) { std::vector vecArgTypes; diff --git a/dynhooks_sourcepawn.h b/dynhooks_sourcepawn.h index 14463e3..6c86820 100644 --- a/dynhooks_sourcepawn.h +++ b/dynhooks_sourcepawn.h @@ -37,5 +37,6 @@ bool HandleDetour(HookType_t hookType, CHook* pDetour); bool AddDetourPluginHook(HookType_t hookType, CHook *pDetour, HookSetup *setup, IPluginFunction *pCallback); bool RemoveDetourPluginHook(HookType_t hookType, CHook *pDetour, IPluginFunction *pCallback); void RemoveAllCallbacksForContext(IPluginContext *pContext); +void CleanupDetours(); #endif \ No newline at end of file diff --git a/extension.cpp b/extension.cpp index 2c78ac2..93d7a9b 100644 --- a/extension.cpp +++ b/extension.cpp @@ -89,8 +89,7 @@ void DHooks::SDK_OnAllLoaded() void DHooks::SDK_OnUnload() { CleanupHooks(); - // FIXME: Unhook only functions that are hooked by a plugin. + cleanup - GetHookManager()->UnhookAllFunctions(); + CleanupDetours(); if(g_pEntityListener) { g_pEntityListener->CleanupListeners();