core/sourcemod.cpp
author Borja Ferrer <faluco@alliedmods.net>
Thu Jul 05 14:47:36 2007 +0000 (2007-07-05)
changeset 1041 f7b2073013df
parent 1018 e466e7319a68
child 1096 8e11b2ebdc22
permissions -rw-r--r--
added a time stamp argument to FormatTime
     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 	/* Force a level end */
   502 	LevelShutdown();
   503 
   504 	/* Unload plugins */
   505 	g_PluginSys.Shutdown();
   506 
   507 	/* Unload extensions */
   508 	g_Extensions.Shutdown();
   509 
   510 	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   511 
   512 	if (g_Loaded)
   513 	{
   514 		if (g_pOnGameFrame)
   515 		{
   516 			g_Forwards.ReleaseForward(g_pOnGameFrame);
   517 		}
   518 
   519 		if (g_pOnMapEnd)
   520 		{
   521 			g_Forwards.ReleaseForward(g_pOnMapEnd);
   522 		}
   523 	
   524 		/* Notify! */
   525 		SMGlobalClass *pBase = SMGlobalClass::head;
   526 		while (pBase)
   527 		{
   528 			pBase->OnSourceModShutdown();
   529 			pBase = pBase->m_pGlobalClassNext;
   530 		}
   531 	
   532 		/* Delete all data packs */
   533 		CStack<CDataPack *>::iterator iter;
   534 		CDataPack *pd;
   535 		for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++)
   536 		{
   537 			pd = (*iter);
   538 			delete pd;
   539 		}
   540 		m_freepacks.popall();
   541 	
   542 		/* Notify! */
   543 		pBase = SMGlobalClass::head;
   544 		while (pBase)
   545 		{
   546 			pBase->OnSourceModAllShutdown();
   547 			pBase = pBase->m_pGlobalClassNext;
   548 		}
   549 	
   550 		if (enginePatch)
   551 		{
   552 			SH_RELEASE_CALLCLASS(enginePatch);
   553 			enginePatch = NULL;
   554 		}
   555 	
   556 		if (gamedllPatch)
   557 		{
   558 			SH_RELEASE_CALLCLASS(gamedllPatch);
   559 			gamedllPatch = NULL;
   560 		}
   561 
   562 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   563 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, this, &SourceModBase::GameFrame, false);
   564 	}
   565 
   566 	/* Rest In Peace */
   567 	ShutdownJIT();
   568 }
   569 
   570 void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...)
   571 {
   572 	IExtensionInterface *pAPI = pExt->GetAPI();
   573 	const char *tag = pAPI->GetExtensionTag();
   574 	char buffer[2048];
   575 	va_list ap;
   576 
   577 	va_start(ap, format);
   578 	vsnprintf(buffer, sizeof(buffer), format, ap);
   579 	va_end(ap);
   580 
   581 	if (tag)
   582 	{
   583 		g_Logger.LogMessage("[%s] %s", tag, buffer);
   584 	} else {
   585 		g_Logger.LogMessage("%s", buffer);
   586 	}
   587 }
   588 
   589 void SourceModBase::LogError(IExtension *pExt, const char *format, ...)
   590 {
   591 	IExtensionInterface *pAPI = pExt->GetAPI();
   592 	const char *tag = pAPI->GetExtensionTag();
   593 	char buffer[2048];
   594 	va_list ap;
   595 
   596 	va_start(ap, format);
   597 	vsnprintf(buffer, sizeof(buffer), format, ap);
   598 	va_end(ap);
   599 
   600 	if (tag)
   601 	{
   602 		g_Logger.LogError("[%s] %s", tag, buffer);
   603 	} else {
   604 		g_Logger.LogError("%s", buffer);
   605 	}
   606 }
   607 
   608 size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param)
   609 {
   610 	char *fmt;
   611 
   612 	pContext->LocalToString(params[param], &fmt);
   613 
   614 	int lparam = ++param;
   615 
   616 	return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam);
   617 }
   618 
   619 const char *SourceModBase::GetSourceModPath() const
   620 {
   621 	return m_SMBaseDir;
   622 }
   623 
   624 const char *SourceModBase::GetGamePath() const
   625 {
   626 	return g_BaseDir.c_str();
   627 }
   628 
   629 void SourceModBase::SetGlobalTarget(unsigned int index)
   630 {
   631 	m_target = index;
   632 }
   633 
   634 void SourceModBase::SetAuthChecking(bool set)
   635 {
   636 	m_CheckingAuth = set;
   637 }
   638 
   639 unsigned int SourceModBase::GetGlobalTarget() const
   640 {
   641 	return m_target;
   642 }
   643 
   644 IDataPack *SourceModBase::CreateDataPack()
   645 {
   646 	CDataPack *pack;
   647 	if (m_freepacks.empty())
   648 	{
   649 		pack = new CDataPack;
   650 	} else {
   651 		pack = m_freepacks.front();
   652 		m_freepacks.pop();
   653 		pack->Initialize();
   654 	}
   655 	return pack;
   656 }
   657 
   658 void SourceModBase::FreeDataPack(IDataPack *pack)
   659 {
   660 	m_freepacks.push(static_cast<CDataPack *>(pack));
   661 }
   662 
   663 Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
   664 {
   665 	//:TODO:
   666 	return 0;
   667 }
   668 
   669 const char *SourceModBase::GetGameFolderName() const
   670 {
   671 	return m_ModDir;
   672 }
   673 
   674 ISourcePawnEngine *SourceModBase::GetScriptingEngine()
   675 {
   676 	return g_pSourcePawn;
   677 }
   678 
   679 IVirtualMachine *SourceModBase::GetScriptingVM()
   680 {
   681 	return g_pVM;
   682 }
   683 
   684 void SourceModBase::AllPluginsLoaded()
   685 {
   686 	SMGlobalClass *base = SMGlobalClass::head;
   687 	while (base)
   688 	{
   689 		base->OnSourceModGameInitialized();
   690 		base = base->m_pGlobalClassNext;
   691 	}
   692 }
   693 
   694 SMGlobalClass *SMGlobalClass::head = NULL;
   695 
   696 SMGlobalClass::SMGlobalClass()
   697 {
   698 	m_pGlobalClassNext = SMGlobalClass::head;
   699 	SMGlobalClass::head = this;
   700 }