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