sourcemm/sourcemm.cpp
changeset 17 2d86867713af
parent 15 6c861b24941b
child 18 8848d3ef28d8
     1.1 --- a/sourcemm/sourcemm.cpp	Mon Apr 18 15:51:13 2005 +0000
     1.2 +++ b/sourcemm/sourcemm.cpp	Mon Apr 18 16:18:02 2005 +0000
     1.3 @@ -217,10 +217,6 @@
     1.4  			//Everything's done.
     1.5  			g_GameDll.loaded = true;
     1.6  
     1.7 -			//Get call class, etc
     1.8 -			g_GameDll.serverDll = serverDll;
     1.9 -			g_GameDll.serverDll_CC = SH_GET_CALLCLASS(IServerGameDLL, serverDll);
    1.10 -
    1.11  			//Initialize our console hooks
    1.12  			ConCommandBaseMgr::OneTimeInit(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
    1.13              
    1.14 @@ -243,28 +239,42 @@
    1.15  	return false;
    1.16  }
    1.17  
    1.18 +// The engine uses the DLL even after it has call DLLShutdown, so we unload it
    1.19 +// when it unloads us
    1.20 +#if defined _WIN32
    1.21 +	BOOL WINAPI DllMain(
    1.22 +						HINSTANCE hinstDLL,
    1.23 +						DWORD fdwReason,
    1.24 +						LPVOID lpvReserved
    1.25 +						)
    1.26 +	{
    1.27 +		if (fdwReason == DLL_PROCESS_DETACH)
    1.28 +		{
    1.29 +			if (g_GameDll.lib && g_GameDll.loaded)
    1.30 +				//dlclose(g_GameDll.lib);
    1.31 +			memset(&g_GameDll, 0, sizeof(GameDllInfo));
    1.32 +		}
    1.33 +		return TRUE;
    1.34 +	}
    1.35 +#elif defined __linux__
    1.36 +	void __attribute__ ((destructor)) app_fini(void)
    1.37 +	{
    1.38 +		if (g_GameDll.lib && g_GameDll.loaded)
    1.39 +			dlclose(g_GameDll.lib);
    1.40 +		memset(&g_GameDll, 0, sizeof(GameDllInfo));
    1.41 +	}
    1.42 +#endif
    1.43 +
    1.44  void CServerGameDLL::DLLShutdown()
    1.45  {
    1.46 -	//cancel if we're shutting down already
    1.47 -	if (bInShutdown)
    1.48 -		return;
    1.49 -
    1.50 -	//we're not re-entrant
    1.51 -	bInShutdown = true;
    1.52 -
    1.53 -    //Call the original function through its call class
    1.54 -	g_GameDll.serverDll_CC->DLLShutdown();
    1.55 +    //Call the original function
    1.56 +	m_pOrig->DLLShutdown();
    1.57  
    1.58  	//Unload plugins
    1.59  	g_PluginMngr.UnloadAll();
    1.60  
    1.61 -	//Shutdown sourcehook now
    1.62 -	SH_RELEASE_CALLCLASS(g_GameDll.serverDll_CC);
    1.63 +	// Shutdown sourcehook now
    1.64  	g_SourceHook.CompleteShutdown();
    1.65 -
    1.66 -	//Unload the DLL forcefully
    1.67 -	dlclose(g_GameDll.lib);
    1.68 -	memset(&g_GameDll, 0, sizeof(GameDllInfo));
    1.69  }
    1.70  
    1.71  int LoadPluginsFromFile(const char *file)