Cleanup detour structures properly on unload
This commit is contained in:
parent
2e52ab24b7
commit
63ccb7448f
@ -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<DataTypeSized_t> vecArgTypes;
|
||||
|
@ -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
|
@ -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();
|
||||
|
Loading…
Reference in New Issue
Block a user