core/provider/provider_ep2.cpp
author Scott Ehlert <ds@alliedmods.net>
Sun Nov 22 23:54:55 2009 -0600 (2009-11-22)
changeset 683 b507295429f9
parent 682 f125dd3ed7d0
child 689 4065ba5e9155
permissions -rw-r--r--
Fixed VSP listener on Linux when loaded via gameinfo.txt on Left 4 Dead 2 (bug 4113, r=dvander).

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