fixed amb193

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40694
This commit is contained in:
David Anderson 2007-04-12 20:18:24 +00:00
parent 7b74745ceb
commit f3da8efe10

View File

@ -45,6 +45,7 @@ IdentityToken_t *g_pCoreIdent = NULL;
float g_LastTime = 0.0f; float g_LastTime = 0.0f;
float g_LastAuthCheck = 0.0f; float g_LastAuthCheck = 0.0f;
IForward *g_pOnGameFrame = NULL; IForward *g_pOnGameFrame = NULL;
bool g_Loaded = false;
typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *); typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
typedef unsigned int (*GETEXPORTCOUNT)(); typedef unsigned int (*GETEXPORTCOUNT)();
@ -188,15 +189,20 @@ bool SourceModBase::InitializeSourceMod(char *error, size_t err_max, bool late)
return false; return false;
} }
StartSourceMod(late); /* Hook this now so we can detect startup without calling StartSourceMod() */
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
/* Only load if we're not late */
if (!late)
{
StartSourceMod(false);
}
return true; return true;
} }
void SourceModBase::StartSourceMod(bool late) void SourceModBase::StartSourceMod(bool late)
{ {
/* First initialize the global hooks we need */
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false); SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false); SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
@ -224,10 +230,20 @@ void SourceModBase::StartSourceMod(bool late)
/* Add us now... */ /* Add us now... */
g_ShareSys.AddInterface(NULL, this); g_ShareSys.AddInterface(NULL, this);
/* We're loaded! */
g_Loaded = true;
} }
bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background) bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
{ {
/* If we're not loaded... */
if (!g_Loaded)
{
/* Do all global initialization now */
StartSourceMod(true);
}
m_IsMapLoading = true; m_IsMapLoading = true;
m_ExecPluginReload = true; m_ExecPluginReload = true;
g_LastTime = 0.0f; g_LastTime = 0.0f;
@ -358,6 +374,10 @@ size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, c
void SourceModBase::CloseSourceMod() void SourceModBase::CloseSourceMod()
{ {
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
if (g_Loaded)
{
if (g_pOnGameFrame) if (g_pOnGameFrame)
{ {
g_Forwards.ReleaseForward(g_pOnGameFrame); g_Forwards.ReleaseForward(g_pOnGameFrame);
@ -401,9 +421,9 @@ void SourceModBase::CloseSourceMod()
gamedllPatch = NULL; gamedllPatch = NULL;
} }
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false); SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
}
/* Rest In Peace */ /* Rest In Peace */
ShutdownJIT(); ShutdownJIT();