core/sourcemod.cpp
author Scott Ehlert <ds@alliedmods.net>
Fri Nov 06 16:24:40 2009 -0600 (2009-11-06)
changeset 2863 d740d9cdf53a
parent 2728 96022dad7e53
child 3004 e3ac0dc6d9a4
permissions -rw-r--r--
Added IMemoryUtils::ResolveSymbol() for resolving symbols hidden via GCC's -fvisibility=hidden (bug 4091, r=dvander,pred).

Right now, this is only used on L4D2 where it is needed.
     1 /**
     2  * vim: set ts=4 sw=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2009 AlliedModders LLC.  All rights reserved.
     6  * =============================================================================
     7  *
     8  * This program is free software; you can redistribute it and/or modify it under
     9  * the terms of the GNU General Public License, version 3.0, as published by the
    10  * Free Software Foundation.
    11  * 
    12  * This program is distributed in the hope that it will be useful, but WITHOUT
    13  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    14  * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
    15  * details.
    16  *
    17  * You should have received a copy of the GNU General Public License along with
    18  * this program.  If not, see <http://www.gnu.org/licenses/>.
    19  *
    20  * As a special exception, AlliedModders LLC gives you permission to link the
    21  * code of this program (as well as its derivative works) to "Half-Life 2," the
    22  * "Source Engine," the "SourcePawn JIT," and any Game MODs that run on software
    23  * by the Valve Corporation.  You must obey the GNU General Public License in
    24  * all respects for all other code used.  Additionally, AlliedModders LLC grants
    25  * this exception to all derivative works.  AlliedModders LLC defines further
    26  * exceptions, found in LICENSE.txt (as of this writing, version JULY-31-2007),
    27  * or <http://www.sourcemod.net/license.php>.
    28  *
    29  * Version: $Id$
    30  */
    31 
    32 #include <stdio.h>
    33 #include "sourcemod.h"
    34 #include "sourcemm_api.h"
    35 #include "LibrarySys.h"
    36 #include <sh_string.h>
    37 #include "PluginSys.h"
    38 #include "ShareSys.h"
    39 #include "CoreConfig.h"
    40 #include "Logger.h"
    41 #include "ExtensionSys.h"
    42 #include "AdminCache.h"
    43 #include "sm_stringutil.h"
    44 #include "PlayerManager.h"
    45 #include "Translator.h"
    46 #include "ForwardSys.h"
    47 #include "TimerSys.h"
    48 #include "GameConfigs.h"
    49 #include "DebugReporter.h"
    50 #include "frame_hooks.h"
    51 #include "logic_bridge.h"
    52 
    53 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    54 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    55 SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool);
    56 SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *);
    57 
    58 SourceModBase g_SourceMod;
    59 
    60 ILibrary *g_pJIT = NULL;
    61 SourceHook::String g_BaseDir;
    62 ISourcePawnEngine *g_pSourcePawn = NULL;
    63 ISourcePawnEngine2 *g_pSourcePawn2 = NULL;
    64 IdentityToken_t *g_pCoreIdent = NULL;
    65 IForward *g_pOnMapEnd = NULL;
    66 bool g_Loaded = false;
    67 bool sm_show_debug_spew = false;
    68 
    69 typedef ISourcePawnEngine *(*GET_SP_V1)();
    70 typedef ISourcePawnEngine2 *(*GET_SP_V2)();
    71 typedef void (*NOTIFYSHUTDOWN)();
    72 
    73 #ifdef PLATFORM_WINDOWS
    74 ConVar sm_basepath("sm_basepath", "addons\\sourcemod", 0, "SourceMod base path (set via command line)");
    75 #elif defined PLATFORM_LINUX || defined PLATFORM_APPLE
    76 ConVar sm_basepath("sm_basepath", "addons/sourcemod", 0, "SourceMod base path (set via command line)");
    77 #endif
    78 
    79 void ShutdownJIT()
    80 {
    81 	NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
    82 	if (notify)
    83 	{
    84 		notify();
    85 	}
    86 
    87 	if (g_pSourcePawn2 != NULL)
    88 	{
    89 		g_pSourcePawn2->Shutdown();
    90 	}
    91 
    92 	g_pJIT->CloseLibrary();
    93 }
    94 
    95 SourceModBase::SourceModBase()
    96 {
    97 	m_IsMapLoading = false;
    98 	m_ExecPluginReload = false;
    99 	m_GotBasePath = false;
   100 }
   101 
   102 ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, 
   103 									  const char *value, 
   104 									  ConfigSource source, 
   105 									  char *error, 
   106 									  size_t maxlength)
   107 {
   108 	if (strcasecmp(key, "BasePath") == 0)
   109 	{
   110 		if (source == ConfigSource_Console)
   111 		{
   112 			UTIL_Format(error, maxlength, "Cannot be set at runtime");
   113 			return ConfigResult_Reject;
   114 		}
   115 
   116 		if (!m_GotBasePath)
   117 		{
   118 			g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value);
   119 			g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value);
   120 
   121 			m_GotBasePath = true;
   122 		}
   123 
   124 		return ConfigResult_Accept;
   125 	}
   126 	else if (strcasecmp(key, "DebugSpew") == 0)
   127 	{
   128 		sm_show_debug_spew = (strcasecmp(value, "yes") == 0) ? true : false;
   129 
   130 		return ConfigResult_Accept;
   131 	}
   132 
   133 	return ConfigResult_Ignore;
   134 }
   135 
   136 bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late)
   137 {
   138 	const char *gamepath = g_SMAPI->GetBaseDir();
   139 
   140 	/* Store full path to game */
   141 	g_BaseDir.assign(gamepath);
   142 
   143 	/* Store name of game directory by itself */
   144 	size_t len = strlen(gamepath);
   145 	for (size_t i = len - 1; i >= 0; i--)
   146 	{
   147 		if (gamepath[i] == PLATFORM_SEP_CHAR)
   148 		{
   149 			strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir));
   150 			break;
   151 		}
   152 	}
   153 
   154 	const char *basepath = icvar->GetCommandLineValue("sm_basepath");
   155 	/* Set a custom base path if there is one. */
   156 	if (basepath != NULL && basepath[0] != '\0')
   157 	{
   158 		m_GotBasePath = true;
   159 	}
   160 	/* Otherwise, use a default and keep the m_GotBasePath unlocked. */
   161 	else
   162 	{
   163 		basepath = sm_basepath.GetDefault();
   164 	}
   165 
   166 	g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), basepath);
   167 	g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "%s", basepath);
   168 
   169 	if (!StartLogicBridge(error, maxlength))
   170 	{
   171 		return false;
   172 	}
   173 
   174 	/* Initialize CoreConfig to get the SourceMod base path properly - this parses core.cfg */
   175 	g_CoreConfig.Initialize();
   176 
   177 	/* There will always be a path by this point, since it was force-set above. */
   178 	m_GotBasePath = true;
   179 
   180 	/* Attempt to load the JIT! */
   181 	char file[PLATFORM_MAX_PATH];
   182 	char myerror[255];
   183 	g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
   184 		GetSourceModPath(),
   185 		PLATFORM_LIB_EXT
   186 		);
   187 
   188 	g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
   189 	if (!g_pJIT)
   190 	{
   191 		if (error && maxlength)
   192 		{
   193 			UTIL_Format(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", 
   194 				myerror,
   195 				PLATFORM_LIB_EXT);
   196 		}
   197 		return false;
   198 	}
   199 
   200 	GET_SP_V1 getv1 = (GET_SP_V1)g_pJIT->GetSymbolAddress("GetSourcePawnEngine1");
   201 	GET_SP_V2 getv2 = (GET_SP_V2)g_pJIT->GetSymbolAddress("GetSourcePawnEngine2");
   202 
   203 	if (getv1 == NULL)
   204 	{
   205 		if (error && maxlength)
   206 		{
   207 			snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
   208 		}
   209 		ShutdownJIT();
   210 		return false;
   211 	}
   212 	else if (getv2 == NULL)
   213 	{
   214 		if (error && maxlength)
   215 		{
   216 			snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
   217 		}
   218 		ShutdownJIT();
   219 		return false;
   220 	}
   221 
   222 	g_pSourcePawn = getv1();
   223 	g_pSourcePawn2 = getv2();
   224 
   225 	if (g_pSourcePawn2->GetAPIVersion() < 3)
   226 	{
   227 		g_pSourcePawn2 = NULL;
   228 		if (error && maxlength)
   229 		{
   230 			snprintf(error, maxlength, "JIT version is out of date");
   231 		}
   232 		return false;
   233 	}
   234 
   235 	if (!g_pSourcePawn2->Initialize())
   236 	{
   237 		g_pSourcePawn2 = NULL;
   238 		if (error && maxlength)
   239 		{
   240 			snprintf(error, maxlength, "JIT could not be initialized");
   241 		}
   242 		return false;
   243 	}
   244 
   245 	g_pSourcePawn2->SetDebugListener(&g_DbgReporter);
   246 
   247 	/* Hook this now so we can detect startup without calling StartSourceMod() */
   248 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   249 
   250 	/* Only load if we're not late */
   251 	if (!late)
   252 	{
   253 		StartSourceMod(false);
   254 	}
   255 
   256 	return true;
   257 }
   258 
   259 void SourceModBase::StartSourceMod(bool late)
   260 {
   261 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   262 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false);
   263 
   264 	enginePatch = SH_GET_CALLCLASS(engine);
   265 	gamedllPatch = SH_GET_CALLCLASS(gamedll);
   266 
   267 	g_ShareSys.Initialize();
   268 
   269 	/* Make the global core identity */
   270 	g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
   271 
   272 	InitLogicBridge();
   273 
   274 	/* Notify! */
   275 	SMGlobalClass *pBase = SMGlobalClass::head;
   276 	while (pBase)
   277 	{
   278 		pBase->OnSourceModStartup(false);
   279 		pBase = pBase->m_pGlobalClassNext;
   280 	}
   281 
   282 	/* Notify! */
   283 	pBase = SMGlobalClass::head;
   284 	while (pBase)
   285 	{
   286 		pBase->OnSourceModAllInitialized();
   287 		pBase = pBase->m_pGlobalClassNext;
   288 	}
   289 
   290 	/* Notify! */
   291 	pBase = SMGlobalClass::head;
   292 	while (pBase)
   293 	{
   294 		pBase->OnSourceModAllInitialized_Post();
   295 		pBase = pBase->m_pGlobalClassNext;
   296 	}
   297 
   298 	/* Add us now... */
   299 	g_ShareSys.AddInterface(NULL, this);
   300 
   301 	/* We're loaded! */
   302 	g_Loaded = true;
   303 
   304 	/* Initialize VSP stuff */
   305 	if (vsp_interface != NULL)
   306 	{
   307 		g_SourceMod_Core.OnVSPListening(vsp_interface);
   308 	}
   309 
   310 	/* If we want to autoload, do that now */
   311 	const char *disabled = GetCoreConfigValue("DisableAutoUpdate");
   312 	if (disabled == NULL || strcasecmp(disabled, "yes") != 0)
   313 	{
   314 		g_Extensions.LoadAutoExtension("updater.ext." PLATFORM_LIB_EXT);
   315 	}
   316 }
   317 
   318 static bool g_LevelEndBarrier = false;
   319 bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
   320 {
   321 	/* If we're not loaded... */
   322 	if (!g_Loaded)
   323 	{
   324 		/* Do all global initialization now */
   325 		StartSourceMod(true);
   326 	}
   327 
   328 	m_IsMapLoading = true;
   329 	m_ExecPluginReload = true;
   330 
   331 	/* Notify! */
   332 	SMGlobalClass *pBase = SMGlobalClass::head;
   333 	while (pBase)
   334 	{
   335 		pBase->OnSourceModLevelChange(pMapName);
   336 		pBase = pBase->m_pGlobalClassNext;
   337 	}
   338 
   339 	DoGlobalPluginLoads();
   340 
   341 	m_IsMapLoading = false;
   342 
   343 	/* Notify! */
   344 	pBase = SMGlobalClass::head;
   345 	while (pBase)
   346 	{
   347 		pBase->OnSourceModPluginsLoaded();
   348 		pBase = pBase->m_pGlobalClassNext;
   349 	}
   350 
   351 	if (!g_pOnMapEnd)
   352 	{
   353 		g_pOnMapEnd = g_Forwards.CreateForward("OnMapEnd", ET_Ignore, 0, NULL);
   354 	}
   355 
   356 	g_LevelEndBarrier = true;
   357 
   358 	RETURN_META_VALUE(MRES_IGNORED, true);
   359 }
   360 
   361 void SourceModBase::LevelShutdown()
   362 {
   363 	if (g_LevelEndBarrier)
   364 	{
   365 		SMGlobalClass *next = SMGlobalClass::head;
   366 		while (next)
   367 		{
   368 			next->OnSourceModLevelEnd();
   369 			next = next->m_pGlobalClassNext;
   370 		}
   371 		
   372 		if (g_pOnMapEnd != NULL)
   373 		{
   374 			g_pOnMapEnd->Execute(NULL);
   375 		}
   376 
   377 		g_Timers.RemoveMapChangeTimers();
   378 
   379 		g_LevelEndBarrier = false;
   380 	}
   381 
   382 	g_OnMapStarted = false;
   383 
   384 	if (m_ExecPluginReload)
   385 	{
   386 		g_PluginSys.ReloadOrUnloadPlugins();
   387 		m_ExecPluginReload = false;
   388 	}
   389 }
   390 
   391 bool SourceModBase::IsMapLoading() const
   392 {
   393 	return m_IsMapLoading;
   394 }
   395 
   396 void SourceModBase::DoGlobalPluginLoads()
   397 {
   398 	char config_path[PLATFORM_MAX_PATH];
   399 	char plugins_path[PLATFORM_MAX_PATH];
   400 
   401 	BuildPath(Path_SM, config_path, 
   402 		sizeof(config_path),
   403 		"configs/plugin_settings.cfg");
   404 	BuildPath(Path_SM, plugins_path,
   405 		sizeof(plugins_path),
   406 		"plugins");
   407 
   408 	/* Load any auto extensions */
   409 	g_Extensions.TryAutoload();
   410 
   411 	/* Fire the extensions ready message */
   412 	g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL);
   413 
   414 	/* Load any game extension */
   415 	const char *game_ext;
   416 	if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL)
   417 	{
   418 		char path[PLATFORM_MAX_PATH];
   419 		UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext);
   420 		g_Extensions.LoadAutoExtension(path);
   421 	}
   422 
   423 	/* Run the first pass */
   424 	g_PluginSys.LoadAll_FirstPass(config_path, plugins_path);
   425 
   426 	/* Mark any extensions as loaded */
   427 	g_Extensions.MarkAllLoaded();
   428 
   429 	/* No modules yet, it's safe to call this from here */
   430 	g_PluginSys.LoadAll_SecondPass();
   431 
   432 	/* Re-mark any extensions as loaded */
   433 	g_Extensions.MarkAllLoaded();
   434 
   435 	/* Call OnAllPluginsLoaded */
   436 	g_PluginSys.AllPluginsLoaded();
   437 }
   438 
   439 size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...)
   440 {
   441 	char _buffer[PLATFORM_MAX_PATH];
   442 	va_list ap;
   443 
   444 	va_start(ap, format);
   445 	vsnprintf(_buffer, PLATFORM_MAX_PATH, format, ap);
   446 	va_end(ap);
   447 
   448 	/* If we get a "file://" notation, strip off the file:// part so we're left 
   449 	 * with an absolute path.  Note that the absolute path gets returned, so 
   450 	 * usage with relative paths here is completely invalid.
   451 	 */
   452 	if (type != Path_SM_Rel && strncmp(_buffer, "file://", 7) == 0)
   453 	{
   454 		return g_LibSys.PathFormat(buffer, maxlength, "%s", &_buffer[7]);
   455 	}
   456 
   457 	const char *base = NULL;
   458 	if (type == Path_Game)
   459 	{
   460 		base = GetGamePath();
   461 	}
   462 	else if (type == Path_SM)
   463 	{
   464 		base = GetSourceModPath();
   465 	}
   466 	else if (type == Path_SM_Rel)
   467 	{
   468 		base = m_SMRelDir;
   469 	}
   470 
   471 	if (base)
   472 	{
   473 		return g_LibSys.PathFormat(buffer, maxlength, "%s/%s", base, _buffer);
   474 	}
   475 	else
   476 	{
   477 		return g_LibSys.PathFormat(buffer, maxlength, "%s", _buffer);
   478 	}
   479 }
   480 
   481 void SourceModBase::CloseSourceMod()
   482 {
   483 	/* Force a level end */
   484 	LevelShutdown();
   485 
   486 	/* Unload plugins */
   487 	g_PluginSys.Shutdown();
   488 
   489 	/* Unload extensions */
   490 	g_Extensions.Shutdown();
   491 
   492 	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   493 
   494 	if (g_Loaded)
   495 	{
   496 		if (g_pOnMapEnd)
   497 		{
   498 			g_Forwards.ReleaseForward(g_pOnMapEnd);
   499 		}
   500 	
   501 		/* Notify! */
   502 		SMGlobalClass *pBase = SMGlobalClass::head;
   503 		while (pBase)
   504 		{
   505 			pBase->OnSourceModShutdown();
   506 			pBase = pBase->m_pGlobalClassNext;
   507 		}
   508 	
   509 		/* Delete all data packs */
   510 		CStack<CDataPack *>::iterator iter;
   511 		CDataPack *pd;
   512 		for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++)
   513 		{
   514 			pd = (*iter);
   515 			delete pd;
   516 		}
   517 		m_freepacks.popall();
   518 	
   519 		/* Notify! */
   520 		pBase = SMGlobalClass::head;
   521 		while (pBase)
   522 		{
   523 			pBase->OnSourceModAllShutdown();
   524 			pBase = pBase->m_pGlobalClassNext;
   525 		}
   526 	
   527 		if (enginePatch)
   528 		{
   529 			SH_RELEASE_CALLCLASS(enginePatch);
   530 			enginePatch = NULL;
   531 		}
   532 	
   533 		if (gamedllPatch)
   534 		{
   535 			SH_RELEASE_CALLCLASS(gamedllPatch);
   536 			gamedllPatch = NULL;
   537 		}
   538 
   539 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   540 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false);
   541 	}
   542 
   543 	/* Rest In Peace */
   544 	ShutdownLogicBridge();
   545 	ShutdownJIT();
   546 }
   547 
   548 void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...)
   549 {
   550 	IExtensionInterface *pAPI = pExt->GetAPI();
   551 	const char *tag = pAPI->GetExtensionTag();
   552 	char buffer[2048];
   553 	va_list ap;
   554 
   555 	va_start(ap, format);
   556 	vsnprintf(buffer, sizeof(buffer), format, ap);
   557 	va_end(ap);
   558 
   559 	if (tag)
   560 	{
   561 		g_Logger.LogMessage("[%s] %s", tag, buffer);
   562 	} else {
   563 		g_Logger.LogMessage("%s", buffer);
   564 	}
   565 }
   566 
   567 void SourceModBase::LogError(IExtension *pExt, const char *format, ...)
   568 {
   569 	IExtensionInterface *pAPI = pExt->GetAPI();
   570 	const char *tag = pAPI->GetExtensionTag();
   571 	char buffer[2048];
   572 	va_list ap;
   573 
   574 	va_start(ap, format);
   575 	vsnprintf(buffer, sizeof(buffer), format, ap);
   576 	va_end(ap);
   577 
   578 	if (tag)
   579 	{
   580 		g_Logger.LogError("[%s] %s", tag, buffer);
   581 	} else {
   582 		g_Logger.LogError("%s", buffer);
   583 	}
   584 }
   585 
   586 size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param)
   587 {
   588 	char *fmt;
   589 
   590 	pContext->LocalToString(params[param], &fmt);
   591 
   592 	int lparam = ++param;
   593 
   594 	return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam);
   595 }
   596 
   597 const char *SourceModBase::GetSourceModPath() const
   598 {
   599 	return m_SMBaseDir;
   600 }
   601 
   602 const char *SourceModBase::GetGamePath() const
   603 {
   604 	return g_BaseDir.c_str();
   605 }
   606 
   607 unsigned int SourceModBase::SetGlobalTarget(unsigned int index)
   608 {
   609 	unsigned int old = m_target;
   610 	m_target = index;
   611 	return old;
   612 }
   613 
   614 unsigned int SourceModBase::GetGlobalTarget() const
   615 {
   616 	return m_target;
   617 }
   618 
   619 IDataPack *SourceModBase::CreateDataPack()
   620 {
   621 	CDataPack *pack;
   622 	if (m_freepacks.empty())
   623 	{
   624 		pack = new CDataPack;
   625 	} else {
   626 		pack = m_freepacks.front();
   627 		m_freepacks.pop();
   628 		pack->Initialize();
   629 	}
   630 	return pack;
   631 }
   632 
   633 void SourceModBase::FreeDataPack(IDataPack *pack)
   634 {
   635 	m_freepacks.push(static_cast<CDataPack *>(pack));
   636 }
   637 
   638 Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
   639 {
   640 	//:TODO:
   641 	return 0;
   642 }
   643 
   644 const char *SourceModBase::GetGameFolderName() const
   645 {
   646 	return m_ModDir;
   647 }
   648 
   649 ISourcePawnEngine *SourceModBase::GetScriptingEngine()
   650 {
   651 	return g_pSourcePawn;
   652 }
   653 
   654 IVirtualMachine *SourceModBase::GetScriptingVM()
   655 {
   656 	return NULL;
   657 }
   658 
   659 void SourceModBase::AllPluginsLoaded()
   660 {
   661 	SMGlobalClass *base = SMGlobalClass::head;
   662 	while (base)
   663 	{
   664 		base->OnSourceModGameInitialized();
   665 		base = base->m_pGlobalClassNext;
   666 	}
   667 }
   668 
   669 time_t SourceModBase::GetAdjustedTime()
   670 {
   671 	return ::GetAdjustedTime();
   672 }
   673 
   674 void SourceModBase::AddGameFrameHook(GAME_FRAME_HOOK hook)
   675 {
   676 	m_frame_hooks.push_back(hook);
   677 }
   678 
   679 void SourceModBase::RemoveGameFrameHook(GAME_FRAME_HOOK hook)
   680 {
   681 	for (size_t i = 0; i < m_frame_hooks.size(); i++)
   682 	{
   683 		if (m_frame_hooks[i] == hook)
   684 		{
   685 			m_frame_hooks.erase(m_frame_hooks.iterAt(i));
   686 			return;
   687 		}
   688 	}
   689 }
   690 
   691 void SourceModBase::ProcessGameFrameHooks(bool simulating)
   692 {
   693 	if (m_frame_hooks.size() == 0)
   694 	{
   695 		return;
   696 	}
   697 
   698 	for (size_t i = 0; i < m_frame_hooks.size(); i++)
   699 	{
   700 		m_frame_hooks[i](simulating);
   701 	}
   702 }
   703 
   704 size_t SourceModBase::Format(char *buffer, size_t maxlength, const char *fmt, ...)
   705 {
   706 	size_t len;
   707 	va_list ap;
   708 
   709 	va_start(ap, fmt);
   710 	len = FormatArgs(buffer, maxlength, fmt, ap);
   711 	va_end(ap);
   712 
   713 	return len;
   714 }
   715 
   716 size_t SourceModBase::FormatArgs(char *buffer,
   717 								 size_t maxlength,
   718 								 const char *fmt,
   719 								 va_list ap)
   720 {
   721 	return UTIL_FormatArgs(buffer, maxlength, fmt, ap);
   722 }
   723 
   724 void SourceModBase::AddFrameAction(FRAMEACTION fn, void *data)
   725 {
   726 	::AddFrameAction(FrameAction(fn, data));
   727 }
   728 
   729 const char *SourceModBase::GetCoreConfigValue(const char *key)
   730 {
   731 	return g_CoreConfig.GetCoreConfigValue(key);
   732 }
   733 
   734 int SourceModBase::GetPluginId()
   735 {
   736 	return g_PLID;
   737 }
   738 
   739 SMGlobalClass *SMGlobalClass::head = NULL;
   740