From 096dfb6a6f750951a68531206d98eb3f2c5a136f Mon Sep 17 00:00:00 2001 From: Pavol Marko Date: Mon, 18 Apr 2005 16:18:02 +0000 Subject: [PATCH] I really don't feel like writing a comment because I don't know what I've just done --HG-- extra : convert_revision : svn%3Ac2935e3e-5518-0410-8daf-afa5dab7d4e3/trunk%4018 --- sourcemm/sourcemm.cpp | 48 ++++++++++++++++++++++++++----------------- sourcemm/sourcemm.h | 2 -- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/sourcemm/sourcemm.cpp b/sourcemm/sourcemm.cpp index 04836dc..f22c46d 100644 --- a/sourcemm/sourcemm.cpp +++ b/sourcemm/sourcemm.cpp @@ -217,10 +217,6 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn //Everything's done. g_GameDll.loaded = true; - //Get call class, etc - g_GameDll.serverDll = serverDll; - g_GameDll.serverDll_CC = SH_GET_CALLCLASS(IServerGameDLL, serverDll); - //Initialize our console hooks ConCommandBaseMgr::OneTimeInit(static_cast(&g_SMConVarAccessor)); @@ -243,28 +239,42 @@ bool CServerGameDLL::DLLInit(CreateInterfaceFn engineFactory, CreateInterfaceFn return false; } +// The engine uses the DLL even after it has call DLLShutdown, so we unload it +// when it unloads us +#if defined _WIN32 + BOOL WINAPI DllMain( + HINSTANCE hinstDLL, + DWORD fdwReason, + LPVOID lpvReserved + ) + { + if (fdwReason == DLL_PROCESS_DETACH) + { + if (g_GameDll.lib && g_GameDll.loaded) + //dlclose(g_GameDll.lib); + memset(&g_GameDll, 0, sizeof(GameDllInfo)); + } + return TRUE; + } +#elif defined __linux__ + void __attribute__ ((destructor)) app_fini(void) + { + if (g_GameDll.lib && g_GameDll.loaded) + dlclose(g_GameDll.lib); + memset(&g_GameDll, 0, sizeof(GameDllInfo)); + } +#endif + void CServerGameDLL::DLLShutdown() { - //cancel if we're shutting down already - if (bInShutdown) - return; - - //we're not re-entrant - bInShutdown = true; - - //Call the original function through its call class - g_GameDll.serverDll_CC->DLLShutdown(); + //Call the original function + m_pOrig->DLLShutdown(); //Unload plugins g_PluginMngr.UnloadAll(); - //Shutdown sourcehook now - SH_RELEASE_CALLCLASS(g_GameDll.serverDll_CC); + // Shutdown sourcehook now g_SourceHook.CompleteShutdown(); - - //Unload the DLL forcefully - dlclose(g_GameDll.lib); - memset(&g_GameDll, 0, sizeof(GameDllInfo)); } int LoadPluginsFromFile(const char *file) diff --git a/sourcemm/sourcemm.h b/sourcemm/sourcemm.h index 065e781..4679de6 100644 --- a/sourcemm/sourcemm.h +++ b/sourcemm/sourcemm.h @@ -55,8 +55,6 @@ struct GameDllInfo bool loaded; HINSTANCE lib; CreateInterfaceFn factory; - IServerGameDLL *serverDll_CC; - IServerGameDLL *serverDll; }; /** @brief Stores information about the HL2 Engine pointers */