core/sourcemod.cpp
author David Anderson <dvander@alliedmods.net>
Thu Jun 21 23:06:37 2007 +0000 (2007-06-21)
changeset 997 2fc3152c3118
parent 978 54782a83a1ef
child 1018 e466e7319a68
permissions -rw-r--r--
bumped menu api again - added feature to get menu end reason
     1 /**
     2  * vim: set ts=4 :
     3  * ===============================================================
     4  * SourceMod (C)2004-2007 AlliedModders LLC.  All rights reserved.
     5  * ===============================================================
     6  *
     7  * This file is not open source and may not be copied without explicit
     8  * written permission of AlliedModders LLC.  This file may not be redistributed 
     9  * in whole or significant part.
    10  * For information, see LICENSE.txt or http://www.sourcemod.net/license.php
    11  *
    12  * Version: $Id$
    13  */
    14 
    15 #include <stdio.h>
    16 #include "sourcemod.h"
    17 #include "sourcemm_api.h"
    18 #include "systems/LibrarySys.h"
    19 #include "vm/sp_vm_engine.h"
    20 #include <sh_string.h>
    21 #include "PluginSys.h"
    22 #include "ShareSys.h"
    23 #include "CoreConfig.h"
    24 #include "Logger.h"
    25 #include "ExtensionSys.h"
    26 #include "AdminCache.h"
    27 #include "sm_stringutil.h"
    28 #include "PlayerManager.h"
    29 #include "Translator.h"
    30 #include "ForwardSys.h"
    31 #include "TimerSys.h"
    32 #include "MenuStyle_Valve.h"
    33 #include "MenuStyle_Radio.h"
    34 
    35 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    36 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    37 SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool);
    38 SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *);
    39 
    40 SourcePawnEngine g_SourcePawn;
    41 SourceModBase g_SourceMod;
    42 
    43 ILibrary *g_pJIT = NULL;
    44 SourceHook::String g_BaseDir;
    45 ISourcePawnEngine *g_pSourcePawn = &g_SourcePawn;
    46 IVirtualMachine *g_pVM;
    47 IdentityToken_t *g_pCoreIdent = NULL;
    48 float g_LastTime = 0.0f;
    49 float g_LastMenuTime = 0.0f;
    50 float g_LastAuthCheck = 0.0f;
    51 IForward *g_pOnGameFrame = NULL;
    52 IForward *g_pOnMapEnd = NULL;
    53 bool g_Loaded = false;
    54 int g_StillFrames = 0;
    55 float g_StillTime = 0.0f;
    56 
    57 typedef int (*GIVEENGINEPOINTER)(ISourcePawnEngine *);
    58 typedef unsigned int (*GETEXPORTCOUNT)();
    59 typedef IVirtualMachine *(*GETEXPORT)(unsigned int);
    60 typedef void (*NOTIFYSHUTDOWN)();
    61 
    62 void ShutdownJIT()
    63 {
    64 	NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
    65 	if (notify)
    66 	{
    67 		notify();
    68 	}
    69 
    70 	g_pJIT->CloseLibrary();
    71 }
    72 
    73 SourceModBase::SourceModBase()
    74 {
    75 	m_IsMapLoading = false;
    76 	m_ExecPluginReload = false;
    77 	m_ExecOnMapEnd = false;
    78 	m_GotBasePath = false;
    79 }
    80 
    81 ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, 
    82 									  const char *value, 
    83 									  ConfigSource source, 
    84 									  char *error, 
    85 									  size_t maxlength)
    86 {
    87 	if (strcasecmp(key, "BasePath") == 0)
    88 	{
    89 		if (source == ConfigSource_Console)
    90 		{
    91 			UTIL_Format(error, maxlength, "Cannot be set at runtime");
    92 			return ConfigResult_Reject;
    93 		}
    94 
    95 		if (!m_GotBasePath)
    96 		{
    97 			g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value);
    98 			g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value);
    99 
   100 			m_GotBasePath = true;
   101 		}
   102 
   103 		return ConfigResult_Accept;
   104 	}
   105 
   106 	return ConfigResult_Ignore;
   107 }
   108 
   109 bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late)
   110 {
   111 	const char *gamepath = g_SMAPI->GetBaseDir();
   112 
   113 	/* Store full path to game */
   114 	g_BaseDir.assign(gamepath);
   115 
   116 	/* Store name of game directory by itself */
   117 	size_t len = strlen(gamepath);
   118 	for (size_t i = len - 1; i >= 0; i--)
   119 	{
   120 		if (gamepath[i] == PLATFORM_SEP_CHAR)
   121 		{
   122 			strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir));
   123 			break;
   124 		}
   125 	}
   126 
   127 	/* Initialize CoreConfig so we can get SourceMod base path properly - this basically parses core.cfg */
   128 	g_CoreConfig.Initialize();
   129 
   130 	/* This shouldn't happen, but can't hurt to be safe */
   131 	if (!g_LibSys.PathExists(m_SMBaseDir) || !m_GotBasePath)
   132 	{
   133 		g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str());
   134 		g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod");
   135 		m_GotBasePath = true;
   136 	}
   137 
   138 	/* Attempt to load the JIT! */
   139 	char file[PLATFORM_MAX_PATH];
   140 	char myerror[255];
   141 	g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
   142 		GetSourceModPath(),
   143 		PLATFORM_LIB_EXT
   144 		);
   145 
   146 	g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
   147 	if (!g_pJIT)
   148 	{
   149 		if (error && maxlength)
   150 		{
   151 			snprintf(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", 
   152 				myerror,
   153 				PLATFORM_LIB_EXT);
   154 		}
   155 		return false;
   156 	}
   157 
   158 	int err;
   159 	GIVEENGINEPOINTER jit_init = (GIVEENGINEPOINTER)g_pJIT->GetSymbolAddress("GiveEnginePointer");
   160 	if (!jit_init)
   161 	{
   162 		ShutdownJIT();
   163 		if (error && maxlength)
   164 		{
   165 			snprintf(error, maxlength, "Failed to find GiveEnginePointer in JIT!");
   166 		}
   167 		return false;
   168 	}
   169 
   170 	if ((err=jit_init(g_pSourcePawn)) != 0)
   171 	{
   172 		ShutdownJIT();
   173 		if (error && maxlength)
   174 		{
   175 			snprintf(error, maxlength, "GiveEnginePointer returned %d in the JIT", err);
   176 		}
   177 		return false;
   178 	}
   179 
   180 	GETEXPORTCOUNT jit_getnum = (GETEXPORTCOUNT)g_pJIT->GetSymbolAddress("GetExportCount");
   181 	GETEXPORT jit_get = (GETEXPORT)g_pJIT->GetSymbolAddress("GetExport");
   182 	if (!jit_get)
   183 	{
   184 		ShutdownJIT();
   185 		if (error && maxlength)
   186 		{
   187 			snprintf(error, maxlength, "JIT is missing a necessary export!");
   188 		}
   189 		return false;
   190 	}
   191 
   192 	unsigned int num = jit_getnum();
   193 	if (!num || ((g_pVM=jit_get(0)) == NULL))
   194 	{
   195 		ShutdownJIT();
   196 		if (error && maxlength)
   197 		{
   198 			snprintf(error, maxlength, "JIT did not export any virtual machines!");
   199 		}
   200 		return false;
   201 	}
   202 
   203 	unsigned int api = g_pVM->GetAPIVersion();
   204 	/* :TODO: clean this up (see amb398) */
   205 	if (api > SOURCEPAWN_VM_API_VERSION || api < 2)
   206 	{
   207 		ShutdownJIT();
   208 		if (error && maxlength)
   209 		{
   210 			snprintf(error, maxlength, "JIT is not a compatible version");
   211 		}
   212 		return false;
   213 	}
   214 
   215 	/* Hook this now so we can detect startup without calling StartSourceMod() */
   216 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   217 
   218 	/* Only load if we're not late */
   219 	if (!late)
   220 	{
   221 		StartSourceMod(false);
   222 	}
   223 
   224 	return true;
   225 }
   226 
   227 void SourceModBase::StartSourceMod(bool late)
   228 {
   229 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   230 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
   231 
   232 	enginePatch = SH_GET_CALLCLASS(engine);
   233 	gamedllPatch = SH_GET_CALLCLASS(gamedll);
   234 
   235 	/* Notify! */
   236 	SMGlobalClass *pBase = SMGlobalClass::head;
   237 	while (pBase)
   238 	{
   239 		pBase->OnSourceModStartup(false);
   240 		pBase = pBase->m_pGlobalClassNext;
   241 	}
   242 
   243 	/* Make the global core identity */
   244 	g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
   245 
   246 	/* Notify! */
   247 	pBase = SMGlobalClass::head;
   248 	while (pBase)
   249 	{
   250 		pBase->OnSourceModAllInitialized();
   251 		pBase = pBase->m_pGlobalClassNext;
   252 	}
   253 
   254 	/* Add us now... */
   255 	g_ShareSys.AddInterface(NULL, this);
   256 
   257 	/* We're loaded! */
   258 	g_Loaded = true;
   259 }
   260 
   261 static bool g_LevelEndBarrier = false;
   262 bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
   263 {
   264 	/* If we're not loaded... */
   265 	if (!g_Loaded)
   266 	{
   267 		/* Do all global initialization now */
   268 		StartSourceMod(true);
   269 	}
   270 
   271 	m_IsMapLoading = true;
   272 	m_ExecPluginReload = true;
   273 	m_ExecOnMapEnd = true;
   274 	g_LastTime = 0.0f;
   275 	g_LastMenuTime = 0.0f;
   276 	g_LastAuthCheck = 0.0f;
   277 	g_SimTicks.ticking = true;
   278 	g_SimTicks.tickcount = 0;
   279 	g_StillTime = 0.0f;
   280 	g_StillFrames = 0;
   281 
   282 	/* Notify! */
   283 	SMGlobalClass *pBase = SMGlobalClass::head;
   284 	while (pBase)
   285 	{
   286 		pBase->OnSourceModLevelChange(pMapName);
   287 		pBase = pBase->m_pGlobalClassNext;
   288 	}
   289 
   290 	DoGlobalPluginLoads();
   291 
   292 	m_IsMapLoading = false;
   293 
   294 	/* Notify! */
   295 	pBase = SMGlobalClass::head;
   296 	while (pBase)
   297 	{
   298 		pBase->OnSourceModPluginsLoaded();
   299 		pBase = pBase->m_pGlobalClassNext;
   300 	}
   301 
   302 	if (!g_pOnGameFrame)
   303 	{
   304 		g_pOnGameFrame = g_Forwards.CreateForward("OnGameFrame", ET_Ignore, 0, NULL);
   305 	}
   306 
   307 	if (!g_pOnMapEnd)
   308 	{
   309 		g_pOnMapEnd = g_Forwards.CreateForward("OnMapEnd", ET_Ignore, 0, NULL);
   310 	}
   311 
   312 	g_LevelEndBarrier = true;
   313 
   314 	RETURN_META_VALUE(MRES_IGNORED, true);
   315 }
   316 
   317 void StartTickSimulation()
   318 {
   319 	g_SimTicks.ticking = false;
   320 	g_SimTicks.tickcount = 0;
   321 	g_SimTicks.ticktime = gpGlobals->curtime;
   322 }
   323 
   324 void StopTickSimulation()
   325 {
   326 	g_SimTicks.ticking = true;
   327 	g_Timers.MapChange();
   328 	g_StillFrames = 0;
   329 	g_LastTime = gpGlobals->curtime;
   330 }
   331 
   332 void SimulateTick()
   333 {
   334 	g_SimTicks.tickcount++;
   335 	g_SimTicks.ticktime = g_StillTime + (g_SimTicks.tickcount * gpGlobals->interval_per_tick);
   336 }
   337 
   338 void SourceModBase::GameFrame(bool simulating)
   339 {
   340 	/**
   341 	 * Note: This is all hardcoded rather than delegated to save
   342 	 * precious CPU cycles.
   343 	 */
   344 	float curtime = gpGlobals->curtime;
   345 	int framecount = gpGlobals->framecount;
   346 
   347 	/* Verify that we're still ticking */
   348 	if (g_SimTicks.ticking)
   349 	{
   350 		if (g_StillFrames == 0)
   351 		{
   352 			g_StillFrames = framecount;
   353 			g_StillTime = curtime;
   354 		} else {
   355 			/* Try to detect when we've stopped ticking.
   356 			 * We do this once 10 frames pass and there have been no ticks.
   357 			 */
   358 			if (g_StillTime == curtime)
   359 			{
   360 				if (framecount - g_StillFrames >= 5)
   361 				{
   362 					StartTickSimulation();
   363 					return;
   364 				}
   365 			} else {
   366 				/* We're definitely ticking we get here, 
   367 				 * but update everything as a precaution */
   368 				g_StillFrames = framecount;
   369 				g_StillTime = curtime;
   370 			}
   371 		}
   372 	} else {
   373 		/* We need to make sure we should still be simulating. */
   374 		if (g_StillTime != curtime)
   375 		{
   376 			/* Wow, we're ticking again! It's time to revert. */
   377 			StopTickSimulation();
   378 			return;
   379 		}
   380 		/* Nope, not ticking.  Simulate! */
   381 		SimulateTick();
   382 		curtime = g_SimTicks.ticktime;
   383 	}
   384 
   385 	if (curtime - g_LastTime >= 0.1f)
   386 	{
   387 		if (m_CheckingAuth
   388 			&& (gpGlobals->curtime - g_LastAuthCheck > 0.7f))
   389 		{
   390 			g_LastAuthCheck = gpGlobals->curtime;
   391 			g_Players.RunAuthChecks();
   392 		}
   393 
   394 		g_Timers.RunFrame();
   395 		g_LastTime = curtime;
   396 	}
   397 
   398 	if (g_SimTicks.ticking && curtime - g_LastMenuTime >= 1.0f)
   399 	{
   400 		g_ValveMenuStyle.ProcessWatchList();
   401 		g_RadioMenuStyle.ProcessWatchList();
   402 		g_LastMenuTime = curtime;
   403 	}
   404 
   405 	if (g_pOnGameFrame && g_pOnGameFrame->GetFunctionCount())
   406 	{
   407 		g_pOnGameFrame->Execute(NULL);
   408 	}
   409 }
   410 
   411 void SourceModBase::LevelShutdown()
   412 {
   413 	if (g_LevelEndBarrier)
   414 	{
   415 		SMGlobalClass *next = SMGlobalClass::head;
   416 		while (next)
   417 		{
   418 			next->OnSourceModLevelEnd();
   419 			next = next->m_pGlobalClassNext;
   420 		}
   421 		g_LevelEndBarrier = false;
   422 	}
   423 
   424 	if (g_pOnMapEnd && m_ExecOnMapEnd)
   425 	{
   426 		g_pOnMapEnd->Execute(NULL);
   427 		m_ExecOnMapEnd = false;
   428 	}
   429 
   430 	g_OnMapStarted = false;
   431 
   432 	if (m_ExecPluginReload)
   433 	{
   434 		g_PluginSys.ReloadOrUnloadPlugins();
   435 		m_ExecPluginReload = false;
   436 	}
   437 }
   438 
   439 bool SourceModBase::IsMapLoading() const
   440 {
   441 	return m_IsMapLoading;
   442 }
   443 
   444 void SourceModBase::DoGlobalPluginLoads()
   445 {
   446 	char config_path[PLATFORM_MAX_PATH];
   447 	char plugins_path[PLATFORM_MAX_PATH];
   448 
   449 	BuildPath(Path_SM, config_path, 
   450 		sizeof(config_path),
   451 		"configs/plugin_settings.cfg");
   452 	BuildPath(Path_SM, plugins_path,
   453 		sizeof(plugins_path),
   454 		"plugins");
   455 
   456 	/* Load any auto extensions */
   457 	g_Extensions.TryAutoload();
   458 
   459 	/* Run the first pass */
   460 	g_PluginSys.LoadAll_FirstPass(config_path, plugins_path);
   461 
   462 	/* Mark any extensions as loaded */
   463 	g_Extensions.MarkAllLoaded();
   464 
   465 	/* No modules yet, it's safe to call this from here */
   466 	g_PluginSys.LoadAll_SecondPass();
   467 
   468 	/* Re-mark any extensions as loaded */
   469 	g_Extensions.MarkAllLoaded();
   470 }
   471 
   472 size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, char *format, ...)
   473 {
   474 	char _buffer[PLATFORM_MAX_PATH];
   475 	va_list ap;
   476 
   477 	va_start(ap, format);
   478 	vsnprintf(_buffer, PLATFORM_MAX_PATH, format, ap);
   479 	va_end(ap);
   480 
   481 	const char *base = NULL;
   482 	if (type == Path_Game)
   483 	{
   484 		base = GetGamePath();
   485 	} else if (type == Path_SM) {
   486 		base = GetSourceModPath();
   487 	} else if (type == Path_SM_Rel) {
   488 		base = m_SMRelDir;
   489 	}
   490 
   491 	if (base)
   492 	{
   493 		return g_LibSys.PathFormat(buffer, maxlength, "%s/%s", base, _buffer);
   494 	} else {
   495 		return g_LibSys.PathFormat(buffer, maxlength, "%s", _buffer);
   496 	}
   497 }
   498 
   499 void SourceModBase::CloseSourceMod()
   500 {
   501 	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   502 
   503 	if (g_Loaded)
   504 	{
   505 		if (g_pOnGameFrame)
   506 		{
   507 			g_Forwards.ReleaseForward(g_pOnGameFrame);
   508 		}
   509 
   510 		if (g_pOnMapEnd)
   511 		{
   512 			g_Forwards.ReleaseForward(g_pOnMapEnd);
   513 		}
   514 	
   515 		/* Notify! */
   516 		SMGlobalClass *pBase = SMGlobalClass::head;
   517 		while (pBase)
   518 		{
   519 			pBase->OnSourceModShutdown();
   520 			pBase = pBase->m_pGlobalClassNext;
   521 		}
   522 	
   523 		/* Delete all data packs */
   524 		CStack<CDataPack *>::iterator iter;
   525 		CDataPack *pd;
   526 		for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++)
   527 		{
   528 			pd = (*iter);
   529 			delete pd;
   530 		}
   531 		m_freepacks.popall();
   532 	
   533 		/* Notify! */
   534 		pBase = SMGlobalClass::head;
   535 		while (pBase)
   536 		{
   537 			pBase->OnSourceModAllShutdown();
   538 			pBase = pBase->m_pGlobalClassNext;
   539 		}
   540 	
   541 		if (enginePatch)
   542 		{
   543 			SH_RELEASE_CALLCLASS(enginePatch);
   544 			enginePatch = NULL;
   545 		}
   546 	
   547 		if (gamedllPatch)
   548 		{
   549 			SH_RELEASE_CALLCLASS(gamedllPatch);
   550 			gamedllPatch = NULL;
   551 		}
   552 
   553 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   554 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
   555 	}
   556 
   557 	/* Rest In Peace */
   558 	ShutdownJIT();
   559 }
   560 
   561 void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...)
   562 {
   563 	IExtensionInterface *pAPI = pExt->GetAPI();
   564 	const char *tag = pAPI->GetExtensionTag();
   565 	char buffer[2048];
   566 	va_list ap;
   567 
   568 	va_start(ap, format);
   569 	vsnprintf(buffer, sizeof(buffer), format, ap);
   570 	va_end(ap);
   571 
   572 	if (tag)
   573 	{
   574 		g_Logger.LogMessage("[%s] %s", tag, buffer);
   575 	} else {
   576 		g_Logger.LogMessage("%s", buffer);
   577 	}
   578 }
   579 
   580 void SourceModBase::LogError(IExtension *pExt, const char *format, ...)
   581 {
   582 	IExtensionInterface *pAPI = pExt->GetAPI();
   583 	const char *tag = pAPI->GetExtensionTag();
   584 	char buffer[2048];
   585 	va_list ap;
   586 
   587 	va_start(ap, format);
   588 	vsnprintf(buffer, sizeof(buffer), format, ap);
   589 	va_end(ap);
   590 
   591 	if (tag)
   592 	{
   593 		g_Logger.LogError("[%s] %s", tag, buffer);
   594 	} else {
   595 		g_Logger.LogError("%s", buffer);
   596 	}
   597 }
   598 
   599 size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param)
   600 {
   601 	char *fmt;
   602 
   603 	pContext->LocalToString(params[param], &fmt);
   604 
   605 	int lparam = ++param;
   606 
   607 	return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam);
   608 }
   609 
   610 const char *SourceModBase::GetSourceModPath() const
   611 {
   612 	return m_SMBaseDir;
   613 }
   614 
   615 const char *SourceModBase::GetGamePath() const
   616 {
   617 	return g_BaseDir.c_str();
   618 }
   619 
   620 void SourceModBase::SetGlobalTarget(unsigned int index)
   621 {
   622 	m_target = index;
   623 }
   624 
   625 void SourceModBase::SetAuthChecking(bool set)
   626 {
   627 	m_CheckingAuth = set;
   628 }
   629 
   630 unsigned int SourceModBase::GetGlobalTarget() const
   631 {
   632 	return m_target;
   633 }
   634 
   635 IDataPack *SourceModBase::CreateDataPack()
   636 {
   637 	CDataPack *pack;
   638 	if (m_freepacks.empty())
   639 	{
   640 		pack = new CDataPack;
   641 	} else {
   642 		pack = m_freepacks.front();
   643 		m_freepacks.pop();
   644 		pack->Initialize();
   645 	}
   646 	return pack;
   647 }
   648 
   649 void SourceModBase::FreeDataPack(IDataPack *pack)
   650 {
   651 	m_freepacks.push(static_cast<CDataPack *>(pack));
   652 }
   653 
   654 Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
   655 {
   656 	//:TODO:
   657 	return 0;
   658 }
   659 
   660 const char *SourceModBase::GetGameFolderName() const
   661 {
   662 	return m_ModDir;
   663 }
   664 
   665 ISourcePawnEngine *SourceModBase::GetScriptingEngine()
   666 {
   667 	return g_pSourcePawn;
   668 }
   669 
   670 IVirtualMachine *SourceModBase::GetScriptingVM()
   671 {
   672 	return g_pVM;
   673 }
   674 
   675 void SourceModBase::AllPluginsLoaded()
   676 {
   677 	SMGlobalClass *base = SMGlobalClass::head;
   678 	while (base)
   679 	{
   680 		base->OnSourceModGameInitialized();
   681 		base = base->m_pGlobalClassNext;
   682 	}
   683 }
   684 
   685 SMGlobalClass *SMGlobalClass::head = NULL;
   686 
   687 SMGlobalClass::SMGlobalClass()
   688 {
   689 	m_pGlobalClassNext = SMGlobalClass::head;
   690 	SMGlobalClass::head = this;
   691 }