core/sourcemod.cpp
author Scott Ehlert <ds@alliedmods.net>
Sun Sep 14 02:58:58 2008 -0500 (2008-09-14)
changeset 2287 017a725c9d17
parent 2226 d10b38524be3
child 2289 44045ead61cd
permissions -rw-r--r--
Eliminated head for dead branch: sourcemod-1.1.0
     1 /**
     2  * vim: set ts=4 :
     3  * =============================================================================
     4  * SourceMod
     5  * Copyright (C) 2004-2008 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 <sh_string.h>
    37 #include "PluginSys.h"
    38 #include "ShareSys.h"
    39 #include "CoreConfig.h"
    40 #include "Logger.h"
    41 #include "ExtensionSys.h"
    42 #include "AdminCache.h"
    43 #include "sm_stringutil.h"
    44 #include "PlayerManager.h"
    45 #include "Translator.h"
    46 #include "ForwardSys.h"
    47 #include "TimerSys.h"
    48 #include "GameConfigs.h"
    49 #include "DebugReporter.h"
    50 #include "Profiler.h"
    51 
    52 SH_DECL_HOOK6(IServerGameDLL, LevelInit, SH_NOATTRIB, false, bool, const char *, const char *, const char *, const char *, bool, bool);
    53 SH_DECL_HOOK0_void(IServerGameDLL, LevelShutdown, SH_NOATTRIB, false);
    54 SH_DECL_HOOK1_void(IServerGameDLL, GameFrame, SH_NOATTRIB, false, bool);
    55 SH_DECL_HOOK1_void(IVEngineServer, ServerCommand, SH_NOATTRIB, false, const char *);
    56 
    57 SourceModBase g_SourceMod;
    58 
    59 ILibrary *g_pJIT = NULL;
    60 SourceHook::String g_BaseDir;
    61 ISourcePawnEngine *g_pSourcePawn = NULL;
    62 ISourcePawnEngine2 *g_pSourcePawn2 = NULL;
    63 IdentityToken_t *g_pCoreIdent = NULL;
    64 IForward *g_pOnMapEnd = NULL;
    65 bool g_Loaded = false;
    66 
    67 typedef ISourcePawnEngine *(*GET_SP_V1)();
    68 typedef ISourcePawnEngine2 *(*GET_SP_V2)();
    69 typedef void (*NOTIFYSHUTDOWN)();
    70 
    71 void ShutdownJIT()
    72 {
    73 	NOTIFYSHUTDOWN notify = (NOTIFYSHUTDOWN)g_pJIT->GetSymbolAddress("NotifyShutdown");
    74 	if (notify)
    75 	{
    76 		notify();
    77 	}
    78 
    79 	if (g_pSourcePawn2 != NULL)
    80 	{
    81 		g_pSourcePawn2->Shutdown();
    82 	}
    83 
    84 	g_pJIT->CloseLibrary();
    85 }
    86 
    87 SourceModBase::SourceModBase()
    88 {
    89 	m_IsMapLoading = false;
    90 	m_ExecPluginReload = false;
    91 	m_GotBasePath = false;
    92 }
    93 
    94 ConfigResult SourceModBase::OnSourceModConfigChanged(const char *key, 
    95 									  const char *value, 
    96 									  ConfigSource source, 
    97 									  char *error, 
    98 									  size_t maxlength)
    99 {
   100 	if (strcasecmp(key, "BasePath") == 0)
   101 	{
   102 		if (source == ConfigSource_Console)
   103 		{
   104 			UTIL_Format(error, maxlength, "Cannot be set at runtime");
   105 			return ConfigResult_Reject;
   106 		}
   107 
   108 		if (!m_GotBasePath)
   109 		{
   110 			g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/%s", g_BaseDir.c_str(), value);
   111 			g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), value);
   112 
   113 			m_GotBasePath = true;
   114 		}
   115 
   116 		return ConfigResult_Accept;
   117 	}
   118 
   119 	return ConfigResult_Ignore;
   120 }
   121 
   122 bool SourceModBase::InitializeSourceMod(char *error, size_t maxlength, bool late)
   123 {
   124 	const char *gamepath = g_SMAPI->GetBaseDir();
   125 
   126 	/* Store full path to game */
   127 	g_BaseDir.assign(gamepath);
   128 
   129 	/* Store name of game directory by itself */
   130 	size_t len = strlen(gamepath);
   131 	for (size_t i = len - 1; i >= 0; i--)
   132 	{
   133 		if (gamepath[i] == PLATFORM_SEP_CHAR)
   134 		{
   135 			strncopy(m_ModDir, &gamepath[++i], sizeof(m_ModDir));
   136 			break;
   137 		}
   138 	}
   139 
   140 	/* Initialize CoreConfig so we can get SourceMod base path properly - this basically parses core.cfg */
   141 	g_CoreConfig.Initialize();
   142 
   143 	/* This shouldn't happen, but can't hurt to be safe */
   144 	if (!g_LibSys.PathExists(m_SMBaseDir) || !m_GotBasePath)
   145 	{
   146 		g_LibSys.PathFormat(m_SMBaseDir, sizeof(m_SMBaseDir), "%s/addons/sourcemod", g_BaseDir.c_str());
   147 		g_LibSys.PathFormat(m_SMRelDir, sizeof(m_SMRelDir), "addons/sourcemod");
   148 		m_GotBasePath = true;
   149 	}
   150 
   151 	/* Attempt to load the JIT! */
   152 	char file[PLATFORM_MAX_PATH];
   153 	char myerror[255];
   154 	g_SMAPI->PathFormat(file, sizeof(file), "%s/bin/sourcepawn.jit.x86.%s",
   155 		GetSourceModPath(),
   156 		PLATFORM_LIB_EXT
   157 		);
   158 
   159 	g_pJIT = g_LibSys.OpenLibrary(file, myerror, sizeof(myerror));
   160 	if (!g_pJIT)
   161 	{
   162 		if (error && maxlength)
   163 		{
   164 			snprintf(error, maxlength, "%s (failed to load bin/sourcepawn.jit.x86.%s)", 
   165 				myerror,
   166 				PLATFORM_LIB_EXT);
   167 		}
   168 		return false;
   169 	}
   170 
   171 	GET_SP_V1 getv1 = (GET_SP_V1)g_pJIT->GetSymbolAddress("GetSourcePawnEngine1");
   172 	GET_SP_V2 getv2 = (GET_SP_V2)g_pJIT->GetSymbolAddress("GetSourcePawnEngine2");
   173 
   174 	if (getv1 == NULL)
   175 	{
   176 		if (error && maxlength)
   177 		{
   178 			snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
   179 		}
   180 		ShutdownJIT();
   181 		return false;
   182 	}
   183 	else if (getv2 == NULL)
   184 	{
   185 		if (error && maxlength)
   186 		{
   187 			snprintf(error, maxlength, "JIT is too old; upgrade SourceMod");
   188 		}
   189 		ShutdownJIT();
   190 		return false;
   191 	}
   192 
   193 	g_pSourcePawn = getv1();
   194 	g_pSourcePawn2 = getv2();
   195 
   196 	if (g_pSourcePawn2->GetAPIVersion() < 2)
   197 	{
   198 		g_pSourcePawn2 = NULL;
   199 		if (error && maxlength)
   200 		{
   201 			snprintf(error, maxlength, "JIT version is out of date");
   202 		}
   203 		return false;
   204 	}
   205 
   206 	if (!g_pSourcePawn2->Initialize())
   207 	{
   208 		g_pSourcePawn2 = NULL;
   209 		if (error && maxlength)
   210 		{
   211 			snprintf(error, maxlength, "JIT could not be initialized");
   212 		}
   213 		return false;
   214 	}
   215 
   216 	g_pSourcePawn2->SetDebugListener(&g_DbgReporter);
   217 	g_pSourcePawn2->SetProfiler(&g_Profiler);
   218 
   219 	/* Hook this now so we can detect startup without calling StartSourceMod() */
   220 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   221 
   222 	/* Only load if we're not late */
   223 	if (!late)
   224 	{
   225 		StartSourceMod(false);
   226 	}
   227 
   228 	return true;
   229 }
   230 
   231 void SourceModBase::StartSourceMod(bool late)
   232 {
   233 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   234 	SH_ADD_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false);
   235 
   236 	enginePatch = SH_GET_CALLCLASS(engine);
   237 	gamedllPatch = SH_GET_CALLCLASS(gamedll);
   238 
   239 	g_ShareSys.Initialize();
   240 
   241 	/* Make the global core identity */
   242 	g_pCoreIdent = g_ShareSys.CreateCoreIdentity();
   243 
   244 	/* Notify! */
   245 	SMGlobalClass *pBase = SMGlobalClass::head;
   246 	while (pBase)
   247 	{
   248 		pBase->OnSourceModStartup(false);
   249 		pBase = pBase->m_pGlobalClassNext;
   250 	}
   251 
   252 	/* Notify! */
   253 	pBase = SMGlobalClass::head;
   254 	while (pBase)
   255 	{
   256 		pBase->OnSourceModAllInitialized();
   257 		pBase = pBase->m_pGlobalClassNext;
   258 	}
   259 
   260 	/* Notify! */
   261 	pBase = SMGlobalClass::head;
   262 	while (pBase)
   263 	{
   264 		pBase->OnSourceModAllInitialized_Post();
   265 		pBase = pBase->m_pGlobalClassNext;
   266 	}
   267 
   268 	/* Add us now... */
   269 	g_ShareSys.AddInterface(NULL, this);
   270 
   271 	/* We're loaded! */
   272 	g_Loaded = true;
   273 
   274 	/* Initialize VSP stuff */
   275 	if (vsp_interface != NULL)
   276 	{
   277 		g_SourceMod_Core.OnVSPListening(vsp_interface);
   278 	}
   279 }
   280 
   281 static bool g_LevelEndBarrier = false;
   282 bool SourceModBase::LevelInit(char const *pMapName, char const *pMapEntities, char const *pOldLevel, char const *pLandmarkName, bool loadGame, bool background)
   283 {
   284 	/* If we're not loaded... */
   285 	if (!g_Loaded)
   286 	{
   287 		/* Do all global initialization now */
   288 		StartSourceMod(true);
   289 	}
   290 
   291 	m_IsMapLoading = true;
   292 	m_ExecPluginReload = true;
   293 
   294 	/* Notify! */
   295 	SMGlobalClass *pBase = SMGlobalClass::head;
   296 	while (pBase)
   297 	{
   298 		pBase->OnSourceModLevelChange(pMapName);
   299 		pBase = pBase->m_pGlobalClassNext;
   300 	}
   301 
   302 	DoGlobalPluginLoads();
   303 
   304 	m_IsMapLoading = false;
   305 
   306 	/* Notify! */
   307 	pBase = SMGlobalClass::head;
   308 	while (pBase)
   309 	{
   310 		pBase->OnSourceModPluginsLoaded();
   311 		pBase = pBase->m_pGlobalClassNext;
   312 	}
   313 
   314 	if (!g_pOnMapEnd)
   315 	{
   316 		g_pOnMapEnd = g_Forwards.CreateForward("OnMapEnd", ET_Ignore, 0, NULL);
   317 	}
   318 
   319 	g_LevelEndBarrier = true;
   320 
   321 	RETURN_META_VALUE(MRES_IGNORED, true);
   322 }
   323 
   324 void SourceModBase::LevelShutdown()
   325 {
   326 	if (g_LevelEndBarrier)
   327 	{
   328 		SMGlobalClass *next = SMGlobalClass::head;
   329 		while (next)
   330 		{
   331 			next->OnSourceModLevelEnd();
   332 			next = next->m_pGlobalClassNext;
   333 		}
   334 		
   335 		if (g_pOnMapEnd != NULL)
   336 		{
   337 			g_pOnMapEnd->Execute(NULL);
   338 		}
   339 
   340 		g_Timers.RemoveMapChangeTimers();
   341 
   342 		g_LevelEndBarrier = false;
   343 	}
   344 
   345 	g_OnMapStarted = false;
   346 
   347 	if (m_ExecPluginReload)
   348 	{
   349 		g_PluginSys.ReloadOrUnloadPlugins();
   350 		m_ExecPluginReload = false;
   351 	}
   352 }
   353 
   354 bool SourceModBase::IsMapLoading() const
   355 {
   356 	return m_IsMapLoading;
   357 }
   358 
   359 void SourceModBase::DoGlobalPluginLoads()
   360 {
   361 	char config_path[PLATFORM_MAX_PATH];
   362 	char plugins_path[PLATFORM_MAX_PATH];
   363 
   364 	BuildPath(Path_SM, config_path, 
   365 		sizeof(config_path),
   366 		"configs/plugin_settings.cfg");
   367 	BuildPath(Path_SM, plugins_path,
   368 		sizeof(plugins_path),
   369 		"plugins");
   370 
   371 	/* Load any auto extensions */
   372 	g_Extensions.TryAutoload();
   373 
   374 	/* Fire the extensions ready message */
   375 	g_SMAPI->MetaFactory(SOURCEMOD_NOTICE_EXTENSIONS, NULL, NULL);	
   376 
   377 	/* Load any game extension */
   378 	const char *game_ext;
   379 	if ((game_ext = g_pGameConf->GetKeyValue("GameExtension")) != NULL)
   380 	{
   381 		char path[PLATFORM_MAX_PATH];
   382 		UTIL_Format(path, sizeof(path), "%s.ext." PLATFORM_LIB_EXT, game_ext);
   383 		g_Extensions.LoadAutoExtension(path);
   384 	}
   385 
   386 	/* Run the first pass */
   387 	g_PluginSys.LoadAll_FirstPass(config_path, plugins_path);
   388 
   389 	/* Mark any extensions as loaded */
   390 	g_Extensions.MarkAllLoaded();
   391 
   392 	/* No modules yet, it's safe to call this from here */
   393 	g_PluginSys.LoadAll_SecondPass();
   394 
   395 	/* Re-mark any extensions as loaded */
   396 	g_Extensions.MarkAllLoaded();
   397 
   398 	/* Call OnAllPluginsLoaded */
   399 	g_PluginSys.AllPluginsLoaded();
   400 }
   401 
   402 size_t SourceModBase::BuildPath(PathType type, char *buffer, size_t maxlength, const char *format, ...)
   403 {
   404 	char _buffer[PLATFORM_MAX_PATH];
   405 	va_list ap;
   406 
   407 	va_start(ap, format);
   408 	vsnprintf(_buffer, PLATFORM_MAX_PATH, format, ap);
   409 	va_end(ap);
   410 
   411 	/* If we get a "file://" notation, strip off the file:// part so we're left 
   412 	 * with an absolute path.  Note that the absolute path gets returned, so 
   413 	 * usage with relative paths here is completely invalid.
   414 	 */
   415 	if (type != Path_SM_Rel && strncmp(_buffer, "file://", 7) == 0)
   416 	{
   417 		return g_LibSys.PathFormat(buffer, maxlength, "%s", &_buffer[7]);
   418 	}
   419 
   420 	const char *base = NULL;
   421 	if (type == Path_Game)
   422 	{
   423 		base = GetGamePath();
   424 	}
   425 	else if (type == Path_SM)
   426 	{
   427 		base = GetSourceModPath();
   428 	}
   429 	else if (type == Path_SM_Rel)
   430 	{
   431 		base = m_SMRelDir;
   432 	}
   433 
   434 	if (base)
   435 	{
   436 		return g_LibSys.PathFormat(buffer, maxlength, "%s/%s", base, _buffer);
   437 	}
   438 	else
   439 	{
   440 		return g_LibSys.PathFormat(buffer, maxlength, "%s", _buffer);
   441 	}
   442 }
   443 
   444 void SourceModBase::CloseSourceMod()
   445 {
   446 	/* Force a level end */
   447 	LevelShutdown();
   448 
   449 	/* Unload plugins */
   450 	g_PluginSys.Shutdown();
   451 
   452 	/* Unload extensions */
   453 	g_Extensions.Shutdown();
   454 
   455 	SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelInit, gamedll, this, &SourceModBase::LevelInit, false);
   456 
   457 	if (g_Loaded)
   458 	{
   459 		if (g_pOnMapEnd)
   460 		{
   461 			g_Forwards.ReleaseForward(g_pOnMapEnd);
   462 		}
   463 	
   464 		/* Notify! */
   465 		SMGlobalClass *pBase = SMGlobalClass::head;
   466 		while (pBase)
   467 		{
   468 			pBase->OnSourceModShutdown();
   469 			pBase = pBase->m_pGlobalClassNext;
   470 		}
   471 	
   472 		/* Delete all data packs */
   473 		CStack<CDataPack *>::iterator iter;
   474 		CDataPack *pd;
   475 		for (iter=m_freepacks.begin(); iter!=m_freepacks.end(); iter++)
   476 		{
   477 			pd = (*iter);
   478 			delete pd;
   479 		}
   480 		m_freepacks.popall();
   481 	
   482 		/* Notify! */
   483 		pBase = SMGlobalClass::head;
   484 		while (pBase)
   485 		{
   486 			pBase->OnSourceModAllShutdown();
   487 			pBase = pBase->m_pGlobalClassNext;
   488 		}
   489 	
   490 		if (enginePatch)
   491 		{
   492 			SH_RELEASE_CALLCLASS(enginePatch);
   493 			enginePatch = NULL;
   494 		}
   495 	
   496 		if (gamedllPatch)
   497 		{
   498 			SH_RELEASE_CALLCLASS(gamedllPatch);
   499 			gamedllPatch = NULL;
   500 		}
   501 
   502 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, LevelShutdown, gamedll, this, &SourceModBase::LevelShutdown, false);
   503 		SH_REMOVE_HOOK_MEMFUNC(IServerGameDLL, GameFrame, gamedll, &g_Timers, &TimerSystem::GameFrame, false);
   504 	}
   505 
   506 	/* Rest In Peace */
   507 	ShutdownJIT();
   508 }
   509 
   510 void SourceModBase::LogMessage(IExtension *pExt, const char *format, ...)
   511 {
   512 	IExtensionInterface *pAPI = pExt->GetAPI();
   513 	const char *tag = pAPI->GetExtensionTag();
   514 	char buffer[2048];
   515 	va_list ap;
   516 
   517 	va_start(ap, format);
   518 	vsnprintf(buffer, sizeof(buffer), format, ap);
   519 	va_end(ap);
   520 
   521 	if (tag)
   522 	{
   523 		g_Logger.LogMessage("[%s] %s", tag, buffer);
   524 	} else {
   525 		g_Logger.LogMessage("%s", buffer);
   526 	}
   527 }
   528 
   529 void SourceModBase::LogError(IExtension *pExt, const char *format, ...)
   530 {
   531 	IExtensionInterface *pAPI = pExt->GetAPI();
   532 	const char *tag = pAPI->GetExtensionTag();
   533 	char buffer[2048];
   534 	va_list ap;
   535 
   536 	va_start(ap, format);
   537 	vsnprintf(buffer, sizeof(buffer), format, ap);
   538 	va_end(ap);
   539 
   540 	if (tag)
   541 	{
   542 		g_Logger.LogError("[%s] %s", tag, buffer);
   543 	} else {
   544 		g_Logger.LogError("%s", buffer);
   545 	}
   546 }
   547 
   548 size_t SourceModBase::FormatString(char *buffer, size_t maxlength, IPluginContext *pContext, const cell_t *params, unsigned int param)
   549 {
   550 	char *fmt;
   551 
   552 	pContext->LocalToString(params[param], &fmt);
   553 
   554 	int lparam = ++param;
   555 
   556 	return atcprintf(buffer, maxlength, fmt, pContext, params, &lparam);
   557 }
   558 
   559 const char *SourceModBase::GetSourceModPath() const
   560 {
   561 	return m_SMBaseDir;
   562 }
   563 
   564 const char *SourceModBase::GetGamePath() const
   565 {
   566 	return g_BaseDir.c_str();
   567 }
   568 
   569 unsigned int SourceModBase::SetGlobalTarget(unsigned int index)
   570 {
   571 	unsigned int old = m_target;
   572 	m_target = index;
   573 	return old;
   574 }
   575 
   576 unsigned int SourceModBase::GetGlobalTarget() const
   577 {
   578 	return m_target;
   579 }
   580 
   581 IDataPack *SourceModBase::CreateDataPack()
   582 {
   583 	CDataPack *pack;
   584 	if (m_freepacks.empty())
   585 	{
   586 		pack = new CDataPack;
   587 	} else {
   588 		pack = m_freepacks.front();
   589 		m_freepacks.pop();
   590 		pack->Initialize();
   591 	}
   592 	return pack;
   593 }
   594 
   595 void SourceModBase::FreeDataPack(IDataPack *pack)
   596 {
   597 	m_freepacks.push(static_cast<CDataPack *>(pack));
   598 }
   599 
   600 Handle_t SourceModBase::GetDataPackHandleType(bool readonly)
   601 {
   602 	//:TODO:
   603 	return 0;
   604 }
   605 
   606 const char *SourceModBase::GetGameFolderName() const
   607 {
   608 	return m_ModDir;
   609 }
   610 
   611 ISourcePawnEngine *SourceModBase::GetScriptingEngine()
   612 {
   613 	return g_pSourcePawn;
   614 }
   615 
   616 IVirtualMachine *SourceModBase::GetScriptingVM()
   617 {
   618 	return NULL;
   619 }
   620 
   621 void SourceModBase::AllPluginsLoaded()
   622 {
   623 	SMGlobalClass *base = SMGlobalClass::head;
   624 	while (base)
   625 	{
   626 		base->OnSourceModGameInitialized();
   627 		base = base->m_pGlobalClassNext;
   628 	}
   629 }
   630 
   631 time_t SourceModBase::GetAdjustedTime()
   632 {
   633 	return ::GetAdjustedTime();
   634 }
   635 
   636 void SourceModBase::AddGameFrameHook(GAME_FRAME_HOOK hook)
   637 {
   638 	m_frame_hooks.push_back(hook);
   639 }
   640 
   641 void SourceModBase::RemoveGameFrameHook(GAME_FRAME_HOOK hook)
   642 {
   643 	for (size_t i = 0; i < m_frame_hooks.size(); i++)
   644 	{
   645 		if (m_frame_hooks[i] == hook)
   646 		{
   647 			m_frame_hooks.erase(m_frame_hooks.iterAt(i));
   648 			return;
   649 		}
   650 	}
   651 }
   652 
   653 void SourceModBase::ProcessGameFrameHooks(bool simulating)
   654 {
   655 	if (m_frame_hooks.size() == 0)
   656 	{
   657 		return;
   658 	}
   659 
   660 	for (size_t i = 0; i < m_frame_hooks.size(); i++)
   661 	{
   662 		m_frame_hooks[i](simulating);
   663 	}
   664 }
   665 
   666 SMGlobalClass *SMGlobalClass::head = NULL;
   667 
   668 SMGlobalClass::SMGlobalClass()
   669 {
   670 	m_pGlobalClassNext = SMGlobalClass::head;
   671 	SMGlobalClass::head = this;
   672 }