core-legacy/CSmmAPI.cpp
author Scott Ehlert <ds@alliedmods.net>
Tue Nov 24 07:33:52 2009 -0600 (2009-11-24)
changeset 685 522727461c0d
parent 683 b507295429f9
child 689 4065ba5e9155
permissions -rw-r--r--
Fixed crashes in code generated by SourceHook's HookManGen on Mac OS X (bug 3514, r=dvander).

This fixes two problems:
1) On OS X structures/objects with sizes of 1, 2, 4, or 8 are returned from functions in registers, not memory addresses.
2) A function returning anything which was 8 bytes in size was crashing. This problem affected all compilers/operating systems.
     1 /* ======== SourceMM ========
     2  * Copyright (C) 2004-2009 Metamod:Source Development Team
     3  * No warranties of any kind
     4  *
     5  * License: zlib/libpng
     6  *
     7  * Author(s): David "BAILOPAN" Anderson
     8  * ============================
     9  */
    10 
    11 #include "convar_smm.h"
    12 #include "CSmmAPI.h"
    13 #include "sourcemm.h"
    14 #include "concommands.h"
    15 #include "CPlugin.h"
    16 #include "util.h"
    17 
    18 /**
    19  * @brief Implementation of main API interface
    20  * @file CSmmAPI.cpp
    21  */
    22 
    23 using namespace SourceMM;
    24 
    25 CSmmAPI g_SmmAPI;
    26 
    27 CSmmAPI::CSmmAPI()
    28 {
    29 	m_ConPrintf = NULL;
    30 	m_CmdCache = false;
    31 	m_MsgCount = -1;
    32 	m_VSP = false;
    33 }
    34 
    35 CSmmAPI::~CSmmAPI()
    36 {
    37 	m_UserMessages.RemoveAll();
    38 }
    39 
    40 void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
    41 {
    42 	va_list ap;
    43 	static char buffer[2048];
    44 
    45 	va_start(ap, msg);
    46 	UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
    47 	va_end(ap);
    48 
    49 	LogMessage("[%s] %s", pl->GetLogTag(), buffer);
    50 }
    51 
    52 CreateInterfaceFn CSmmAPI::engineFactory(bool syn)
    53 {
    54 	if (syn)
    55 		return EngineFactory;
    56 	return g_Engine.engineFactory;
    57 }
    58 
    59 CreateInterfaceFn CSmmAPI::physicsFactory(bool syn)
    60 {
    61 	if (syn)
    62 		return PhysicsFactory;
    63 	return g_Engine.physicsFactory;
    64 }
    65 
    66 CreateInterfaceFn CSmmAPI::fileSystemFactory(bool syn)
    67 {
    68 	if (syn)
    69 		return FileSystemFactory;
    70 	return g_Engine.fileSystemFactory;
    71 }
    72 
    73 CreateInterfaceFn CSmmAPI::serverFactory(bool syn)
    74 {
    75 	if (syn)
    76 		return ServerFactory;
    77 	return g_GameDll.factory;
    78 }
    79 
    80 CGlobalVars *CSmmAPI::pGlobals()
    81 {
    82 	return g_Engine.pGlobals;
    83 }
    84 
    85 void CSmmAPI::SetLastMetaReturn(META_RES res)
    86 {
    87 	m_Res = res;
    88 }
    89 
    90 META_RES CSmmAPI::GetLastMetaReturn()
    91 {
    92 	return m_Res;
    93 }
    94 
    95 IConCommandBaseAccessor *CSmmAPI::GetCvarBaseAccessor()
    96 {
    97 	return static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor);
    98 }
    99 
   100 bool CSmmAPI::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
   101 {
   102 	if (pCommand->IsCommand())
   103 	{
   104 		g_PluginMngr.AddPluginCmd(plugin, pCommand);
   105 	} else {
   106 		g_PluginMngr.AddPluginCvar(plugin, pCommand);
   107 	}
   108 
   109 	return g_SMConVarAccessor.Register(pCommand);
   110 }
   111 
   112 void CSmmAPI::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
   113 {
   114 	if (pCommand->IsCommand())
   115 	{
   116 		g_PluginMngr.RemovePluginCmd(plugin, pCommand);
   117 	} else {
   118 		g_PluginMngr.RemovePluginCvar(plugin, pCommand);
   119 	}
   120 
   121 	CPluginManager::CPlugin *pPlugin = g_PluginMngr.FindByAPI(plugin);
   122 	PluginId id = (pPlugin != NULL) ? pPlugin->m_Id : Pl_BadLoad;
   123 
   124 	NotifyConCommandBaseDrop(id, pCommand);
   125 
   126 	g_SMConVarAccessor.Unregister(pCommand);
   127 }
   128 
   129 void CSmmAPI::ConPrint(const char *fmt)
   130 {
   131 	(m_ConPrintf)("%s", fmt);
   132 }
   133 
   134 void CSmmAPI::ConPrintf(const char *fmt, ...)
   135 {
   136 	va_list ap;
   137 	static char buffer[4096];
   138 
   139 	va_start(ap, fmt);
   140 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   141 	va_end(ap);
   142 
   143 	(m_ConPrintf)("%s", buffer);
   144 }
   145 
   146 void CSmmAPI::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
   147 {
   148 	CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
   149 	CPluginEventHandler cpeh;
   150 
   151 	cpeh.event = pListener;
   152 	cpeh.got_vsp = false;
   153 
   154 	pl->m_Events.push_back(cpeh);
   155 }
   156 
   157 void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id)
   158 {
   159 	if (id)
   160 	{
   161 		*id = 0;
   162 	}
   163 
   164 	if (!iface)
   165 	{
   166 		return NULL;
   167 	}
   168 
   169 	//first check ours... we get first chance!
   170 	if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
   171 	{
   172 		if (_ret)
   173 		{
   174 			*_ret = IFACE_OK;
   175 		}
   176 		return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
   177 	} else if (strcmp(iface, MMIFACE_PLMANAGER) == 0) {
   178 		if (_ret)
   179 		{
   180 			*_ret = IFACE_OK;
   181 		}
   182 		return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
   183 	}
   184 
   185 	CPluginManager::CPlugin *pl;
   186 	SourceHook::List<CPluginEventHandler>::iterator event;
   187 	IMetamodListener *api;
   188 	int ret = 0;
   189 	void *val = NULL;
   190 
   191 	for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++)
   192 	{
   193 		pl = (*iter);
   194 		for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++)
   195 		{
   196 			api = (*event).event;
   197 			ret = IFACE_FAILED;
   198 			if ( (val=api->OnMetamodQuery(iface, &ret)) != NULL )
   199 			{
   200 				if (_ret)
   201 					*_ret = ret;
   202 				if (id)
   203 					*id = pl->m_Id;
   204 				return val;
   205 			}
   206 		}
   207 	}
   208 
   209 	if (_ret)
   210 		*_ret = IFACE_FAILED;
   211 
   212 	return NULL;
   213 }
   214 
   215 //////////////////////////////////////////////////////////////////////////
   216 //THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
   217 // (note: you can find the offset by looking for the text               //
   218 //   "Echo text to console", you'll find the callback cmd pushed on the //
   219 //   stack.)                                                            //
   220 //////////////////////////////////////////////////////////////////////////
   221 
   222 #define SIGLEN			8
   223 #define ENGINE486_SIG	"\x55\x89\xE5\x53\x83\xEC\x14\xBB"
   224 #define ENGINE486_OFFS	40
   225 #define ENGINE686_SIG	"\x53\x83\xEC\x08\xBB\x01\x00\x00"
   226 #define ENGINE686_OFFS	50
   227 #define	ENGINEAMD_SIG	"\x53\x51\xBB\x01\x00\x00\x00\x51"
   228 #define	ENGINEAMD_OFFS	47
   229 #define ENGINEW32_SIG	"\xA1\x2A\x2A\x2A\x2A\x56\xBE\x01"
   230 #define ENGINEW32_OFFS	38
   231 #define IA32_CALL		0xE8
   232 
   233 //Thanks to fysh for the idea of extracting info from "echo" and for
   234 // having the original offsets at hand!
   235 bool CSmmAPI::CacheCmds()
   236 {
   237 	ICvar *pCvar = g_Engine.icvar;
   238 
   239 	ConCommandBase *pBase = pCvar->GetCommands();
   240 	unsigned char *ptr = NULL;
   241 	FnCommandCallback callback = NULL;
   242 	int offs = 0;
   243 
   244 	while (pBase)
   245 	{
   246 		if ( strcmp(pBase->GetName(), "echo") == 0 )
   247 		{
   248 			//callback = //*((FnCommandCallback *)((char *)pBase + offsetof(ConCommand, m_fnCommandCallback)));
   249 			callback = ((ConCommand *)pBase)->GetCallback();
   250 			ptr = (unsigned char *)callback;
   251 		#ifdef OS_LINUX
   252 			if (UTIL_VerifySignature(ptr, ENGINE486_SIG, SIGLEN))
   253 			{
   254 				offs = ENGINE486_OFFS;
   255 			}
   256 			else if (UTIL_VerifySignature(ptr, ENGINE686_SIG, SIGLEN))
   257 			{
   258 				offs = ENGINE686_OFFS;
   259 			}
   260 			else if (UTIL_VerifySignature(ptr, ENGINEAMD_SIG, SIGLEN))
   261 			{
   262 				offs = ENGINEAMD_OFFS;
   263 			}
   264 		#elif defined OS_WIN32 // Only one Windows engine binary so far...
   265 			if (UTIL_VerifySignature(ptr, ENGINEW32_SIG, SIGLEN))
   266 			{
   267 				offs = ENGINEW32_OFFS;
   268 			}
   269 		#endif
   270 
   271 			if (!offs || ptr[offs - 1] != IA32_CALL)
   272 			{
   273 				m_ConPrintf = (CONPRINTF_FUNC)Msg;
   274 				return false;
   275 			}
   276 			//get the relative offset
   277 			m_ConPrintf = *((CONPRINTF_FUNC *)(ptr + offs));
   278 			//add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction)
   279 			m_ConPrintf = (CONPRINTF_FUNC)((unsigned long)m_ConPrintf + (unsigned long)(ptr + offs) + 4);
   280 
   281 			m_CmdCache = true;
   282 
   283 			return true;
   284 		}
   285 		pBase = const_cast<ConCommandBase *>(pBase->GetNext());
   286 	}
   287 
   288 	m_ConPrintf = (CONPRINTF_FUNC)Msg;
   289 
   290 	return false;
   291 }
   292 
   293 bool CSmmAPI::CmdCacheSuccessful()
   294 {
   295 	return m_CmdCache;
   296 }
   297 
   298 void CSmmAPI::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
   299 {
   300 	major = SM_VERS_API_MAJOR;
   301 	minor = SM_VERS_API_MINOR;
   302 	plvers = PLAPI_VERSION;
   303 	plmin = PLAPI_MIN_VERSION;
   304 }
   305 
   306 void CSmmAPI::GetShVersions(int &shvers, int &shimpl)
   307 {
   308 	shvers = SH_IFACE_VERSION;
   309 	shimpl = SH_IMPL_VERSION;
   310 }
   311 
   312 int CSmmAPI::FormatIface(char iface[], unsigned int maxlength)
   313 {
   314 	int length = (int)strlen(iface);
   315 	int i;
   316 	int num = 0;
   317 
   318 	for (i = length - 1; i >= 0; i--)
   319 	{
   320 		if (!isdigit(iface[i]))
   321 		{
   322 			if (i != length - 1)
   323 			{
   324 				num = 1;
   325 			}
   326 			break;
   327 		}
   328 	}
   329 
   330 	if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
   331 	{
   332 		return -1;
   333 	}
   334 
   335 	if (i != length - 1)
   336 		num = atoi(&(iface[++i]));
   337 
   338 	num++;
   339 
   340 	snprintf(&(iface[i]), 4, "%03d", num);
   341 
   342 	return num;
   343 }
   344 
   345 void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
   346 {
   347 	char _if[256];	/* assume no interface goes beyond this */
   348 	size_t len = strlen(iface);
   349 	int num = 0;
   350 	void *pf = NULL;
   351 
   352 	if (max > 999)
   353 		max = 999;
   354 
   355 	if (len + 4 > sizeof(_if))
   356 	{
   357 		if (ret)
   358 		{
   359 			*ret = IFACE_FAILED;
   360 		}
   361 		return NULL;
   362 	}
   363 
   364 	strcpy(_if, iface);
   365 
   366 	do
   367 	{
   368 		if ( (pf = (fn)(_if, ret)) != NULL )
   369 			break;
   370 		if (num > max)
   371 			break;
   372 	} while (( num = FormatIface(_if, len+1) ));
   373 
   374 	return pf;
   375 }
   376 
   377 void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
   378 {
   379 	char buffer[256];	/* assume no interface will go beyond this */
   380 	size_t len = strlen(iface);
   381 	int ret;			/* just in case something doesn't handle NULL properly */
   382 
   383 	if (len > sizeof(buffer) - 4)
   384 	{
   385 		return NULL;
   386 	}
   387 
   388 	strcpy(buffer, iface);
   389 
   390 	if (min != -1)
   391 	{
   392 		char *ptr = &buffer[len - 1];
   393 		int digits = 0;
   394 		while (isdigit(*ptr) && digits <=3)
   395 		{
   396 			*ptr = '\0';
   397 			digits++;
   398 			ptr--;
   399 		}
   400 		if (digits != 3)
   401 		{
   402 			/* for now, assume this is an error */
   403 			strcpy(buffer, iface);
   404 		} else {
   405 			char num[4];
   406 			min = (min == 0) ? 1 : min;
   407 			snprintf(num, sizeof(num), "%03d", min);
   408 			strcat(buffer, num);
   409 		}
   410 	}
   411 
   412 	return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
   413 }
   414 
   415 const char *CSmmAPI::GetBaseDir()
   416 {
   417 	return g_ModPath.c_str();
   418 }
   419 
   420 void CSmmAPI::PathFormat(char *buffer, size_t len, const char *fmt, ...)
   421 {
   422 	va_list ap;
   423 	va_start(ap, fmt);
   424 	size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
   425 	va_end(ap);
   426 
   427 	for (size_t i = 0; i < mylen; i++)
   428 	{
   429 		if (buffer[i] == ALT_SEP_CHAR)
   430 		{
   431 			buffer[i] = PATH_SEP_CHAR;
   432 		}
   433 	}
   434 }
   435 
   436 void CSmmAPI::ClientConPrintf(edict_t *client, const char *fmt, ...)
   437 {
   438 	va_list ap;
   439 	static char buffer[4096];
   440 
   441 	va_start(ap, fmt);
   442 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   443 	va_end(ap);
   444 
   445 	g_Engine.engine->ClientPrintf(client, buffer);
   446 }
   447 
   448 void CSmmAPI::LoadAsVSP()
   449 {
   450 	size_t len;
   451 	char engine_file[PATH_SIZE];
   452 	char rel_path[PATH_SIZE * 2];
   453 
   454 	GetFileOfAddress(g_Engine.engine, engine_file, sizeof(engine_file));
   455 
   456 	/* Chop off the "engine" file part */
   457 	len = strlen(engine_file);
   458 	for (size_t i = len - 1; i >= 0 && i < len; i--)
   459 	{
   460 		if (engine_file[i] == '/'
   461 			|| engine_file[i] == '\\')
   462 		{
   463 			engine_file[i] = '\0';
   464 			break;
   465 		}
   466 	}
   467 
   468 	const char *usepath = g_MetamodPath.c_str();
   469 	if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, g_MetamodPath.c_str()))
   470 	{
   471 		usepath = rel_path;
   472 	}
   473 	
   474 	char command[PATH_SIZE * 2];
   475 	UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
   476 	g_Engine.engine->ServerCommand(command);
   477 }
   478 
   479 void CSmmAPI::EnableVSPListener()
   480 {
   481 	/* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */
   482 	if (g_bGameInit && !m_VSP && !g_bIsBridgedAsVsp)
   483 	{
   484 		LoadAsVSP();
   485 	}
   486 	m_VSP = true;
   487 }
   488 
   489 int CSmmAPI::GetGameDLLVersion()
   490 {
   491 	return g_GameDllVersion;
   492 }
   493 
   494 //////////////////////////////////////////////////////////////////////
   495 // EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED!                      //
   496 // Signatures necessary in finding the pointer to the CUtlDict that //
   497 //   stores user message information.                               //
   498 // IServerGameDLL::GetUserMessageInfo() normally crashes with bad   //
   499 //   message indices. This is our answer to it. Yuck! <:-(          //
   500 //////////////////////////////////////////////////////////////////////
   501 #ifdef OS_WIN32
   502 	/* General Windows sig */
   503 	#define MSGCLASS_SIGLEN		7
   504 	#define MSGCLASS_SIG		"\x8B\x0D\x2A\x2A\x2A\x2A\x56"
   505 	#define MSGCLASS_OFFS		2
   506 
   507 	/* Dystopia Wimdows hack */
   508 	#define MSGCLASS2_SIGLEN	16
   509 	#define MSGCLASS2_SIG		"\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
   510 	#define MSGCLASS2_OFFS		11
   511 
   512 	/* Windows frame pointer sig */
   513 	#define MSGCLASS3_SIGLEN	18
   514 	#define MSGCLASS3_SIG		"\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
   515 	#define MSGCLASS3_OFFS		13
   516 #elif defined OS_LINUX
   517 	/* No frame pointer sig */
   518 	#define MSGCLASS_SIGLEN		14
   519 	#define MSGCLASS_SIG		"\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   520 	#define MSGCLASS_OFFS		9
   521 
   522 	/* Frame pointer sig */
   523 	#define MSGCLASS2_SIGLEN	16
   524 	#define MSGCLASS2_SIG		"\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   525 	#define MSGCLASS2_OFFS		11
   526 #endif
   527 
   528 /* This is the ugliest function in all of SourceMM */
   529 /* :TODO: Make this prettier */
   530 bool CSmmAPI::CacheUserMessages()
   531 {
   532 	UserMsgDict *dict = NULL;
   533 	char *vfunc = UTIL_GetOrigFunction(&IServerGameDLL::GetUserMessageInfo, g_GameDll.pGameDLL);
   534 
   535 	if (!vfunc)
   536 	{
   537 		return false;
   538 	}
   539 
   540 	if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
   541 	{
   542 		/* Get address of CUserMessages instance */
   543 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
   544 
   545 		/* Get address of CUserMessages::m_UserMessages */
   546 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   547 	} else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) {
   548 	#ifdef OS_WIN32
   549 		/* If we get here, the code is possibly inlined like in Dystopia */
   550 
   551 		/* Get the address of the CUtlRBTree */
   552 		char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
   553 
   554 		/* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
   555 		dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
   556 	#elif defined OS_LINUX
   557 		/* Get address of CUserMessages instance */
   558 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
   559 
   560 		/* Get address of CUserMessages::m_UserMessages */
   561 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   562 	#endif
   563 	#ifdef OS_WIN32
   564 	} else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN)) {
   565 		/* Get address of CUserMessages instance */
   566 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
   567 
   568 		/* Get address of CUserMessages::m_UserMessages */
   569 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   570 	#endif
   571 	}
   572 
   573 	if (dict)
   574 	{
   575 		m_MsgCount = dict->Count();
   576 
   577 		/* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
   578 		if (m_MsgCount < 0 || m_MsgCount > 255)
   579 		{
   580 			m_MsgCount = -1;
   581 			return false;
   582 		}
   583 
   584 		UserMessage *msg;
   585 
   586 		/* Cache messages in our CUtlDict */
   587 		for (int i = 0; i < m_MsgCount; i++)
   588 		{
   589 			msg = dict->Element(i);
   590 			m_UserMessages.Insert(msg->name, msg);
   591 		}
   592 
   593 		return true;
   594 	}
   595 
   596 	return false;
   597 }
   598 
   599 bool CSmmAPI::MsgCacheSuccessful()
   600 {
   601 	return m_MsgCount > -1;
   602 }
   603 
   604 int CSmmAPI::GetUserMessageCount()
   605 {
   606 	return m_MsgCount;
   607 }
   608 
   609 int CSmmAPI::FindUserMessage(const char *name, int *size)
   610 {
   611 	int index = m_UserMessages.Find(name);
   612 
   613 	if (size && index > -1)
   614 	{
   615 		UserMessage *msg = m_UserMessages.Element(index);
   616 		*size = msg->size;
   617 	}
   618 
   619 	return index;
   620 }
   621 
   622 const char *CSmmAPI::GetUserMessage(int index, int *size)
   623 {
   624 	if (m_MsgCount <= 0 || index < 0 || index >= m_MsgCount)
   625 	{
   626 		return NULL;
   627 	}
   628 
   629 	UserMessage *msg = m_UserMessages.Element(index);
   630 
   631 	if (size)
   632 	{
   633 		*size = msg->size;
   634 	}
   635 
   636 	return msg->name;
   637 }
   638 
   639 IServerPluginCallbacks *CSmmAPI::GetVSPInfo(int *pVersion)
   640 {
   641 	if (pVersion != NULL)
   642 		*pVersion = g_vsp_version;
   643 
   644 	return g_pRealVspCallbacks;
   645 }
   646 
   647 int CSmmAPI::GetSourceEngineBuild()
   648 {
   649 	return g_Engine.original ? SOURCE_ENGINE_ORIGINAL : SOURCE_ENGINE_EPISODEONE;
   650 }