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