sourcemm/sourcemm.cpp
changeset 15 6c861b24941b
parent 14 a3f323f6f91d
child 17 2d86867713af
     1.1 --- a/sourcemm/sourcemm.cpp	Sun Apr 17 18:43:21 2005 +0000
     1.2 +++ b/sourcemm/sourcemm.cpp	Mon Apr 18 03:30:30 2005 +0000
     1.3 @@ -35,14 +35,12 @@
     1.4  std::string g_ModPath;
     1.5  std::string g_BinPath;
     1.6  PluginId g_PLID = Pl_Console;		//Technically, SourceMM is the "Console" plugin... :p
     1.7 +bool bInShutdown = false;
     1.8  
     1.9  ///////////////////////////////////
    1.10  // Main code for HL2 Interaction //
    1.11  ///////////////////////////////////
    1.12  
    1.13 -void DLLShutdown_handler(void);
    1.14 -SH_DECL_HOOK0_void(IServerGameDLL, DLLShutdown, SH_NOATTRIB, 0);
    1.15 -
    1.16  //This is where the magic happens
    1.17  SMM_API void *CreateInterface(const char *name, int *ret)
    1.18  {
    1.19 @@ -153,8 +151,6 @@
    1.20  				return false;
    1.21  			}
    1.22  
    1.23 -			g_GameDll.serverGameDLL_CC = SH_GET_CALLCLASS(IServerGameDLL, serverDll);
    1.24 -
    1.25  			//Set this information early in case our wrappers are called somehow
    1.26  			g_Engine.engineFactory = engineFactory;
    1.27  			g_Engine.icvar = (ICvar *)(g_Engine.engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL);
    1.28 @@ -221,8 +217,9 @@
    1.29  			//Everything's done.
    1.30  			g_GameDll.loaded = true;
    1.31  
    1.32 -			//Initialize our shutdown hook
    1.33 -			SH_ADD_HOOK_STATICFUNC(IServerGameDLL, DLLShutdown, serverDll, DLLShutdown_handler, false);
    1.34 +			//Get call class, etc
    1.35 +			g_GameDll.serverDll = serverDll;
    1.36 +			g_GameDll.serverDll_CC = SH_GET_CALLCLASS(IServerGameDLL, serverDll);
    1.37  
    1.38  			//Initialize our console hooks
    1.39  			ConCommandBaseMgr::OneTimeInit(static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor));
    1.40 @@ -246,23 +243,28 @@
    1.41  	return false;
    1.42  }
    1.43  
    1.44 -void DLLShutdown_handler(void)
    1.45 +void CServerGameDLL::DLLShutdown()
    1.46  {
    1.47 -	//It's time for us to shut down too!
    1.48 +	//cancel if we're shutting down already
    1.49 +	if (bInShutdown)
    1.50 +		return;
    1.51 +
    1.52 +	//we're not re-entrant
    1.53 +	bInShutdown = true;
    1.54 +
    1.55 +    //Call the original function through its call class
    1.56 +	g_GameDll.serverDll_CC->DLLShutdown();
    1.57 +
    1.58 +	//Unload plugins
    1.59  	g_PluginMngr.UnloadAll();
    1.60  
    1.61 -	//Call the DLL...
    1.62 -	g_GameDll.serverGameDLL_CC->DLLShutdown();
    1.63 -
    1.64 -	// Shutdown sourcehook now
    1.65 +	//Shutdown sourcehook now
    1.66 +	SH_RELEASE_CALLCLASS(g_GameDll.serverDll_CC);
    1.67  	g_SourceHook.CompleteShutdown();
    1.68  
    1.69  	//Unload the DLL forcefully
    1.70  	dlclose(g_GameDll.lib);
    1.71  	memset(&g_GameDll, 0, sizeof(GameDllInfo));
    1.72 -
    1.73 -	//DON'T CALL THE GAMEDLL! IT'S GONE!  pinin' for the fjords
    1.74 -	RETURN_META(MRES_SUPERCEDE);
    1.75  }
    1.76  
    1.77  int LoadPluginsFromFile(const char *file)