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