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