core/provider/provider_ep2.cpp
author Scott Ehlert <ds@alliedmods.net>
Tue Nov 17 04:49:17 2009 -0500 (2009-11-17)
changeset 682 f125dd3ed7d0
parent 674 c4ed595f6248
child 683 b507295429f9
permissions -rw-r--r--
Fixed exit crash on Linux on Left 4 Dead 2 (bug 4114, r=dvander).
     1 /**
     2  * vim: set ts=4 sw=4 tw=99 noet :
     3  * ======================================================
     4  * Metamod:Source
     5  * Copyright (C) 2004-2009 AlliedModders LLC and authors.
     6  * All rights reserved.
     7  * ======================================================
     8  *
     9  * This software is provided 'as-is', without any express or implied warranty.
    10  * In no event will the authors be held liable for any damages arising from 
    11  * the use of this software.
    12  * 
    13  * Permission is granted to anyone to use this software for any purpose, 
    14  * including commercial applications, and to alter it and redistribute it 
    15  * freely, subject to the following restrictions:
    16  *
    17  * 1. The origin of this software must not be misrepresented; you must not 
    18  * claim that you wrote the original software. If you use this software in a 
    19  * product, an acknowledgment in the product documentation would be 
    20  * appreciated but is not required.
    21  * 2. Altered source versions must be plainly marked as such, and must not be
    22  * misrepresented as being the original software.
    23  * 3. This notice may not be removed or altered from any source distribution.
    24  */
    25 
    26 #include <stdio.h>
    27 #include "../metamod_oslink.h"
    28 #include <sourcehook.h>
    29 #include <convar.h>
    30 #include <eiface.h>
    31 #include <tier0/icommandline.h>
    32 #include <tier1/utldict.h>
    33 #include <sh_vector.h>
    34 #include <sh_string.h>
    35 #include "../metamod_util.h"
    36 #include "provider_ep2.h"
    37 #include "console.h"
    38 #include "metamod_console.h"
    39 #include "vsp_listener.h"
    40 #include <filesystem.h>
    41 #include "metamod.h"
    42 
    43 /* Types */
    44 typedef void (*CONPRINTF_FUNC)(const char *, ...);
    45 struct UsrMsgInfo
    46 {
    47 	UsrMsgInfo()
    48 	{
    49 	}
    50 	UsrMsgInfo(int s, const char *t) : size(s), name(t)
    51 	{
    52 	}
    53 	int size;
    54 	String name;
    55 };
    56 
    57 /* Imports */
    58 #if SOURCE_ENGINE == SE_DARKMESSIAH
    59 #undef CommandLine
    60 DLL_IMPORT ICommandLine *CommandLine();
    61 #endif
    62 
    63 /* Functions */
    64 bool CacheUserMessages();
    65 #if SOURCE_ENGINE >= SE_ORANGEBOX
    66 void ClientCommand(edict_t *pEdict, const CCommand &args);
    67 void LocalCommand_Meta(const CCommand &args);
    68 #else
    69 void ClientCommand(edict_t *pEdict);
    70 void LocalCommand_Meta();
    71 #endif
    72 
    73 void _ServerCommand();
    74 /* Variables */
    75 static bool usermsgs_extracted = false;
    76 static CVector<UsrMsgInfo> usermsgs_list;
    77 static VSPListener g_VspListener;
    78 static BaseProvider g_Ep1Provider;
    79 static List<ConCommandBase *> conbases_unreg;
    80 
    81 ICvar *icvar = NULL;
    82 IFileSystem *baseFs = NULL;
    83 IServerGameDLL *server = NULL;
    84 IVEngineServer *engine = NULL;
    85 IServerGameClients *gameclients = NULL;
    86 IMetamodSourceProvider *provider = &g_Ep1Provider;
    87 ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
    88 
    89 #if SOURCE_ENGINE >= SE_ORANGEBOX
    90 SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
    91 #else
    92 SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
    93 #endif
    94 
    95 bool AssumeUserMessages()
    96 {
    97 	int q, size;
    98 	char buffer[256];
    99 
   100 	q = 0;
   101 
   102 	while (server->GetUserMessageInfo(q, buffer, sizeof(buffer), size))
   103 	{
   104 		usermsgs_list.push_back(UsrMsgInfo(size, buffer));
   105 		q++;
   106 	}
   107 
   108 	return true;
   109 }
   110 
   111 void BaseProvider::ConsolePrint(const char *str)
   112 {
   113 #if SOURCE_ENGINE >= SE_ORANGEBOX
   114 	ConMsg("%s", str);
   115 #else
   116 	Msg("%s", str);
   117 #endif
   118 }
   119 
   120 void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, 
   121 									  CreateInterfaceFn serverFactory)
   122 {
   123 	engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
   124 	if (!engine)
   125 	{
   126 		DisplayError("Could not find IVEngineServer! Metamod cannot load.");
   127 		return;
   128 	}
   129 #if SOURCE_ENGINE >= SE_ORANGEBOX
   130 	icvar = (ICvar *)((engineFactory)(CVAR_INTERFACE_VERSION, NULL));
   131 #else
   132 	icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL));
   133 #endif
   134 	if (!icvar)
   135 	{
   136 		DisplayError("Could not find ICvar! Metamod cannot load.");
   137 		return;
   138 	}
   139 
   140 
   141 	if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL)))
   142 		== NULL)
   143 	{
   144 		gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
   145 	}
   146 
   147 	baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
   148 	if (baseFs == NULL)
   149 	{
   150 		mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
   151 		return;
   152 	}
   153 
   154 #if SOURCE_ENGINE >= SE_ORANGEBOX
   155 	g_pCVar = icvar;
   156 #endif
   157 
   158 	g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd);
   159 
   160 	if ((usermsgs_extracted = CacheUserMessages()) == false)
   161 	{
   162 		usermsgs_extracted = AssumeUserMessages();
   163 	}
   164 
   165 #if SOURCE_ENGINE == SE_DARKMESSIAH
   166 	if (!g_SMConVarAccessor.InitConCommandBaseList())
   167 	{
   168 		/* This is very unlikely considering it's old engine */
   169 		mm_LogMessage("[META] Warning: Failed to find ConCommandBase list!");
   170 		mm_LogMessage("[META] Warning: ConVars and ConCommands cannot be unregistered properly! Please file a bug report.");
   171 	}
   172 #endif
   173 
   174 	if (gameclients)
   175 	{
   176 		SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, false);
   177 	}
   178 }
   179 
   180 void BaseProvider::Notify_DLLShutdown_Pre()
   181 {
   182 	g_SMConVarAccessor.RemoveMetamodCommands();
   183 
   184 #if SOURCE_ENGINE == SE_DARKMESSIAH
   185 	if (g_Metamod.IsLoadedAsGameDLL())
   186 	{
   187 		icvar->UnlinkVariables(FCVAR_GAMEDLL);
   188 	}
   189 #endif
   190 }
   191 
   192 bool BaseProvider::IsRemotePrintingAvailable()
   193 {
   194 	return true;
   195 }
   196 
   197 void BaseProvider::ClientConsolePrint(edict_t *client, const char *message)
   198 {
   199 	engine->ClientPrintf(client, message);
   200 }
   201 
   202 void BaseProvider::ServerCommand(const char *cmd)
   203 {
   204 	engine->ServerCommand(cmd);
   205 }
   206 
   207 const char *BaseProvider::GetConVarString(ConVar *convar)
   208 {
   209 	if (convar == NULL)
   210 	{
   211 		return NULL;
   212 	}
   213 
   214 	return convar->GetString();
   215 }
   216 
   217 void BaseProvider::SetConVarString(ConVar *convar, const char *str)
   218 {
   219 	convar->SetValue(str);
   220 }
   221 
   222 bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
   223 {
   224 	return pCommand->IsCommand();
   225 }
   226 
   227 
   228 bool BaseProvider::IsSourceEngineBuildCompatible(int build)
   229 {
   230 	return (build == SOURCE_ENGINE_ORIGINAL
   231 			|| build == SOURCE_ENGINE_EPISODEONE);
   232 }
   233 
   234 const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval)
   235 {
   236 	if (key[0] == '-' || key[0] == '+')
   237 	{
   238 		return CommandLine()->ParmValue(key, defval);
   239 	}
   240 	else if (icvar)
   241 	{
   242 		const char *val;
   243 		if ((val = icvar->GetCommandLineValue(key)) == NULL)
   244 		{
   245 			return defval;
   246 		}
   247 
   248 		return val;
   249 	}
   250 
   251 	return NULL;
   252 }
   253 
   254 int BaseProvider::TryServerGameDLL(const char *iface)
   255 {
   256 	if (strncmp(iface, "ServerGameDLL", 13) != 0)
   257 	{
   258 		return 0;
   259 	}
   260 
   261 	return atoi(&iface[13]);
   262 }
   263 
   264 bool BaseProvider::LogMessage(const char *buffer)
   265 {
   266 	if (!engine)
   267 	{
   268 		return false;
   269 	}
   270 
   271 	engine->LogPrint(buffer);
   272 
   273 	return true;
   274 }
   275 
   276 bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo)
   277 {
   278 	SourceHook::MemFuncInfo mfi = {true, -1, 0, 0};
   279 
   280 	if (hook == ProvidedHook_LevelInit)
   281 	{
   282 		SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi);
   283 	}
   284 	else if (hook == ProvidedHook_LevelShutdown)
   285 	{
   286 		SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi);
   287 	}
   288 	else if (hook == ProvidedHook_GameInit)
   289 	{
   290 		SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi);
   291 	}
   292 
   293 	*pInfo = mfi;
   294 
   295 	return (mfi.thisptroffs >= 0);
   296 }
   297 
   298 void BaseProvider::DisplayError(const char *fmt, ...)
   299 {
   300 	va_list ap;
   301 	char buffer[2048];
   302 
   303 	va_start(ap, fmt);
   304 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   305 	va_end(ap);
   306 
   307 	Error(buffer);
   308 }
   309 
   310 void BaseProvider::DisplayWarning(const char *fmt, ...)
   311 {
   312 	va_list ap;
   313 	char buffer[2048];
   314 
   315 	va_start(ap, fmt);
   316 	UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
   317 	va_end(ap);
   318 
   319 	Warning(buffer);
   320 }
   321 
   322 IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor()
   323 {
   324 	return &g_SMConVarAccessor;
   325 }
   326 
   327 bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand)
   328 {
   329 	return g_SMConVarAccessor.Register(pCommand);
   330 }
   331 
   332 void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand)
   333 {
   334 	return g_SMConVarAccessor.Unregister(pCommand);
   335 }
   336 
   337 int BaseProvider::GetUserMessageCount()
   338 {
   339 	if (!usermsgs_extracted)
   340 	{
   341 		return -1;
   342 	}
   343 
   344 	return (int)usermsgs_list.size();
   345 }
   346 
   347 int BaseProvider::FindUserMessage(const char *name, int *size)
   348 {
   349 	for (size_t i = 0; i < usermsgs_list.size(); i++)
   350 	{
   351 		if (usermsgs_list[i].name.compare(name) == 0)
   352 		{
   353 			if (size)
   354 			{
   355 				*size = usermsgs_list[i].size;
   356 			}
   357 			return (int)i;
   358 		}
   359 	}
   360 	
   361 	return -1;
   362 }
   363 
   364 const char *BaseProvider::GetUserMessage(int index, int *size)
   365 {
   366 	if (!usermsgs_extracted || index < 0 || index >= (int)usermsgs_list.size())
   367 	{
   368 		return NULL;
   369 	}
   370 
   371 	if (size)
   372 	{
   373 		*size = usermsgs_list[index].size;
   374 	}
   375 
   376 	return usermsgs_list[index].name.c_str();
   377 }
   378 
   379 const char *BaseProvider::GetGameDescription()
   380 {
   381 	return server->GetGameDescription();
   382 }
   383 
   384 int BaseProvider::DetermineSourceEngine(const char *game)
   385 {
   386 #if SOURCE_ENGINE == SE_LEFT4DEAD2
   387 	return SOURCE_ENGINE_LEFT4DEAD2;
   388 #elif SOURCE_ENGINE == SE_LEFT4DEAD
   389 	return SOURCE_ENGINE_LEFT4DEAD;
   390 #elif SOURCE_ENGINE == SE_ORANGEBOX
   391 	return SOURCE_ENGINE_ORANGEBOX;
   392 #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE
   393 	return SOURCE_ENGINE_ORANGEBOXVALVE;
   394 #elif SOURCE_ENGINE == SE_DARKMESSIAH
   395 	return SOURCE_ENGINE_DARKMESSIAH;
   396 #else
   397 #error "SOURCE_ENGINE not defined to a known value"
   398 #endif
   399 }
   400 
   401 ConVar *BaseProvider::CreateConVar(const char *name,
   402 								   const char *defval,
   403 								   const char *help,
   404 								   int flags)
   405 {
   406 	int newflags = 0;
   407 	if (flags & ConVarFlag_Notify)
   408 	{
   409 		newflags |= FCVAR_NOTIFY;
   410 	}
   411 	if (flags & ConVarFlag_SpOnly)
   412 	{
   413 		newflags |= FCVAR_SPONLY;
   414 	}
   415 
   416 	ConVar *pVar = new ConVar(name, defval, newflags, help);
   417 
   418 	g_SMConVarAccessor.RegisterConCommandBase(pVar);
   419 
   420 	return pVar;
   421 }
   422 
   423 IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version)
   424 {
   425 	if (version > 2)
   426 	{
   427 		return NULL;
   428 	}
   429 
   430 	g_VspListener.SetLoadable(true);
   431 	return &g_VspListener;
   432 }
   433 
   434 bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
   435 {
   436 	if (baseFs == NULL)
   437 	{
   438 		return false;
   439 	}
   440 
   441 	KeyValues *pValues;
   442 	const char *plugin_file, *p_alias;
   443 
   444 	pValues = new KeyValues("Metamod Plugin");
   445 
   446 	if (!pValues->LoadFromFile(baseFs, file))
   447 	{
   448 		pValues->deleteThis();
   449 		return false;
   450 	}
   451 
   452 	if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
   453 	{
   454 		pValues->deleteThis();
   455 		return false;
   456 	}
   457 
   458 	UTIL_Format(path, path_len, "%s", plugin_file);
   459 
   460 	if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
   461 	{
   462 		UTIL_Format(alias, alias_len, "%s", p_alias);
   463 	}
   464 	else
   465 	{
   466 		UTIL_Format(alias, alias_len, "");
   467 	}
   468 
   469 	pValues->deleteThis();
   470 
   471 	return true;
   472 }
   473 
   474 #if SOURCE_ENGINE >= SE_ORANGEBOX
   475 class GlobCommand : public IMetamodSourceCommandInfo
   476 {
   477 public:
   478 	GlobCommand(const CCommand *cmd) : m_cmd(cmd)
   479 	{
   480 	}
   481 public:
   482 	unsigned int GetArgCount()
   483 	{
   484 		return m_cmd->ArgC() - 1;
   485 	}
   486 
   487 	const char *GetArg(unsigned int num)
   488 	{
   489 		return m_cmd->Arg(num);
   490 	}
   491 
   492 	const char *GetArgString()
   493 	{
   494 		return m_cmd->ArgS();
   495 	}
   496 private:
   497 	const CCommand *m_cmd;
   498 };
   499 #else
   500 class GlobCommand : public IMetamodSourceCommandInfo
   501 {
   502 public:
   503 	unsigned int GetArgCount()
   504 	{
   505 		return engine->Cmd_Argc() - 1;
   506 	}
   507 
   508 	const char *GetArg(unsigned int num)
   509 	{
   510 		return engine->Cmd_Argv(num);
   511 	}
   512 
   513 	const char *GetArgString()
   514 	{
   515 		return engine->Cmd_Args();
   516 	}
   517 };
   518 #endif
   519 
   520 #if SOURCE_ENGINE >= SE_ORANGEBOX
   521 void LocalCommand_Meta(const CCommand &args)
   522 {
   523 	GlobCommand cmd(&args);
   524 #else
   525 void LocalCommand_Meta()
   526 {
   527 	GlobCommand cmd;
   528 #endif
   529 	Command_Meta(&cmd);
   530 }
   531 
   532 #if SOURCE_ENGINE >= SE_ORANGEBOX
   533 void ClientCommand(edict_t *pEdict, const CCommand &_cmd)
   534 {
   535 	GlobCommand cmd(&_cmd);
   536 #else
   537 void ClientCommand(edict_t *pEdict)
   538 {
   539 	GlobCommand cmd;
   540 #endif
   541 	if (strcmp(cmd.GetArg(0), "meta") == 0)
   542 	{
   543 		Command_ClientMeta(pEdict, &cmd);
   544 		RETURN_META(MRES_SUPERCEDE);
   545 	}
   546 
   547 	RETURN_META(MRES_IGNORED);
   548 }
   549 
   550 //////////////////////////////////////////////////////////////////////
   551 // EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED!                      //
   552 // Signatures necessary in finding the pointer to the CUtlDict that //
   553 //   stores user message information.                               //
   554 // IServerGameDLL::GetUserMessageInfo() normally crashes with bad   //
   555 //   message indices. This is our answer to it. Yuck! <:-(          //
   556 //////////////////////////////////////////////////////////////////////
   557 #ifdef OS_WIN32
   558 	/* General Windows sig */
   559 	#define MSGCLASS_SIGLEN		7
   560 	#define MSGCLASS_SIG		"\x8B\x0D\x2A\x2A\x2A\x2A\x56"
   561 	#define MSGCLASS_OFFS		2
   562 
   563 	/* Dystopia Windows hack */
   564 	#define MSGCLASS2_SIGLEN	16
   565 	#define MSGCLASS2_SIG		"\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
   566 	#define MSGCLASS2_OFFS		11
   567 
   568 	/* Windows frame pointer sig */
   569 	#define MSGCLASS3_SIGLEN	18
   570 	#define MSGCLASS3_SIG		"\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
   571 	#define MSGCLASS3_OFFS		13
   572 #elif defined OS_LINUX
   573 	/* No frame pointer sig */
   574 	#define MSGCLASS_SIGLEN		14
   575 	#define MSGCLASS_SIG		"\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   576 	#define MSGCLASS_OFFS		9
   577 
   578 	/* Frame pointer sig */
   579 	#define MSGCLASS2_SIGLEN	16
   580 	#define MSGCLASS2_SIG		"\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   581 	#define MSGCLASS2_OFFS		11
   582 #endif
   583 
   584 struct UserMessage
   585 {
   586 	int size;
   587 	const char *name;
   588 };
   589 
   590 typedef CUtlDict<UserMessage *, int> UserMsgDict;
   591 
   592 /* This is the ugliest function in all of MM:S */
   593 bool CacheUserMessages()
   594 {
   595 	UserMsgDict *dict = NULL;
   596 
   597 	/* Get address of original GetUserMessageInfo() */
   598 	char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo);
   599 
   600 	/* Oh dear, we have a relative jump on our hands
   601 	 * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
   602 	 */
   603 	if (*vfunc == '\xE9')
   604 	{
   605 		/* Get address from displacement...
   606 		 *
   607 		 * Add 5 because it's relative to next instruction:
   608 		 * Opcode <1 byte> + 32-bit displacement <4 bytes> 
   609 		 */
   610 		vfunc += *reinterpret_cast<int *>(vfunc + 1) + 5;
   611 	}
   612 
   613 	if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
   614 	{
   615 		/* Get address of CUserMessages instance */
   616 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
   617 
   618 		/* Get address of CUserMessages::m_UserMessages */
   619 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   620 	} 
   621 	else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) 
   622 	{
   623 	#ifdef OS_WIN32
   624 		/* If we get here, the code is possibly inlined like in Dystopia */
   625 
   626 		/* Get the address of the CUtlRBTree */
   627 		char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
   628 
   629 		/* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
   630 		dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
   631 	#elif defined OS_LINUX
   632 		/* Get address of CUserMessages instance */
   633 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
   634 
   635 		/* Get address of CUserMessages::m_UserMessages */
   636 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   637 	#endif
   638 	#ifdef OS_WIN32
   639 	} 
   640 	else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN)) 
   641 	{
   642 		/* Get address of CUserMessages instance */
   643 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
   644 
   645 		/* Get address of CUserMessages::m_UserMessages */
   646 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   647 	#endif
   648 	}
   649 
   650 	#if !defined OS_WIN32
   651 	if (dict == NULL)
   652 	{
   653 		char path[255];
   654 		if (GetFileOfAddress(vfunc, path, sizeof(path)))
   655 		{
   656 			void *handle = dlopen(path, RTLD_NOW);
   657 			if (handle != NULL)
   658 			{
   659 				void *addr = dlsym(handle, "usermessages");
   660 				if (addr == NULL)
   661 				{
   662 					dlclose(handle);
   663 					return false;
   664 				}
   665 				dict = (UserMsgDict *)*(void **)addr;
   666 				dlclose(handle);
   667 			}
   668 		}
   669 	}
   670 	#endif
   671 
   672 	if (dict != NULL)
   673 	{
   674 		int msg_count = dict->Count();
   675 
   676 		/* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
   677 		if (msg_count < 0 || msg_count > 255)
   678 		{
   679 			return false;
   680 		}
   681 
   682 		UserMessage *msg;
   683 		UsrMsgInfo u_msg;
   684 
   685 		/* Cache messages in our CUtlDict */
   686 		for (int i = 0; i < msg_count; i++)
   687 		{
   688 			msg = dict->Element(i);
   689 			u_msg.name = msg->name;
   690 			u_msg.size = msg->size;
   691 			usermsgs_list.push_back(u_msg);
   692 		}
   693 
   694 		return true;
   695 	}
   696 
   697 	return false;
   698 }
   699