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