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