core/provider/provider_ep2.cpp
author Scott Ehlert <ds@alliedmods.net>
Thu Oct 29 10:57:27 2009 -0500 (2009-10-29)
changeset 669 2ae87570fab2
parent 658 8353605c1d97
child 674 c4ed595f6248
permissions -rw-r--r--
Added support for Left 4 Dead 2 (bug 4078, 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_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 IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version)
   422 {
   423 	if (version > 2)
   424 	{
   425 		return NULL;
   426 	}
   427 
   428 	g_VspListener.SetLoadable(true);
   429 	return &g_VspListener;
   430 }
   431 
   432 bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
   433 {
   434 	if (baseFs == NULL)
   435 	{
   436 		return false;
   437 	}
   438 
   439 	KeyValues *pValues;
   440 	const char *plugin_file, *p_alias;
   441 
   442 	pValues = new KeyValues("Metamod Plugin");
   443 
   444 	if (!pValues->LoadFromFile(baseFs, file))
   445 	{
   446 		pValues->deleteThis();
   447 		return false;
   448 	}
   449 
   450 	if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
   451 	{
   452 		pValues->deleteThis();
   453 		return false;
   454 	}
   455 
   456 	UTIL_Format(path, path_len, "%s", plugin_file);
   457 
   458 	if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
   459 	{
   460 		UTIL_Format(alias, alias_len, "%s", p_alias);
   461 	}
   462 	else
   463 	{
   464 		UTIL_Format(alias, alias_len, "");
   465 	}
   466 
   467 	pValues->deleteThis();
   468 
   469 	return true;
   470 }
   471 
   472 #if SOURCE_ENGINE >= SE_ORANGEBOX
   473 class GlobCommand : public IMetamodSourceCommandInfo
   474 {
   475 public:
   476 	GlobCommand(const CCommand *cmd) : m_cmd(cmd)
   477 	{
   478 	}
   479 public:
   480 	unsigned int GetArgCount()
   481 	{
   482 		return m_cmd->ArgC() - 1;
   483 	}
   484 
   485 	const char *GetArg(unsigned int num)
   486 	{
   487 		return m_cmd->Arg(num);
   488 	}
   489 
   490 	const char *GetArgString()
   491 	{
   492 		return m_cmd->ArgS();
   493 	}
   494 private:
   495 	const CCommand *m_cmd;
   496 };
   497 #else
   498 class GlobCommand : public IMetamodSourceCommandInfo
   499 {
   500 public:
   501 	unsigned int GetArgCount()
   502 	{
   503 		return engine->Cmd_Argc() - 1;
   504 	}
   505 
   506 	const char *GetArg(unsigned int num)
   507 	{
   508 		return engine->Cmd_Argv(num);
   509 	}
   510 
   511 	const char *GetArgString()
   512 	{
   513 		return engine->Cmd_Args();
   514 	}
   515 };
   516 #endif
   517 
   518 #if SOURCE_ENGINE >= SE_ORANGEBOX
   519 void LocalCommand_Meta(const CCommand &args)
   520 {
   521 	GlobCommand cmd(&args);
   522 #else
   523 void LocalCommand_Meta()
   524 {
   525 	GlobCommand cmd;
   526 #endif
   527 	Command_Meta(&cmd);
   528 }
   529 
   530 #if SOURCE_ENGINE >= SE_ORANGEBOX
   531 void ClientCommand(edict_t *pEdict, const CCommand &_cmd)
   532 {
   533 	GlobCommand cmd(&_cmd);
   534 #else
   535 void ClientCommand(edict_t *pEdict)
   536 {
   537 	GlobCommand cmd;
   538 #endif
   539 	if (strcmp(cmd.GetArg(0), "meta") == 0)
   540 	{
   541 		Command_ClientMeta(pEdict, &cmd);
   542 		RETURN_META(MRES_SUPERCEDE);
   543 	}
   544 
   545 	RETURN_META(MRES_IGNORED);
   546 }
   547 
   548 //////////////////////////////////////////////////////////////////////
   549 // EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED!                      //
   550 // Signatures necessary in finding the pointer to the CUtlDict that //
   551 //   stores user message information.                               //
   552 // IServerGameDLL::GetUserMessageInfo() normally crashes with bad   //
   553 //   message indices. This is our answer to it. Yuck! <:-(          //
   554 //////////////////////////////////////////////////////////////////////
   555 #ifdef OS_WIN32
   556 	/* General Windows sig */
   557 	#define MSGCLASS_SIGLEN		7
   558 	#define MSGCLASS_SIG		"\x8B\x0D\x2A\x2A\x2A\x2A\x56"
   559 	#define MSGCLASS_OFFS		2
   560 
   561 	/* Dystopia Windows hack */
   562 	#define MSGCLASS2_SIGLEN	16
   563 	#define MSGCLASS2_SIG		"\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
   564 	#define MSGCLASS2_OFFS		11
   565 
   566 	/* Windows frame pointer sig */
   567 	#define MSGCLASS3_SIGLEN	18
   568 	#define MSGCLASS3_SIG		"\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
   569 	#define MSGCLASS3_OFFS		13
   570 #elif defined OS_LINUX
   571 	/* No frame pointer sig */
   572 	#define MSGCLASS_SIGLEN		14
   573 	#define MSGCLASS_SIG		"\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   574 	#define MSGCLASS_OFFS		9
   575 
   576 	/* Frame pointer sig */
   577 	#define MSGCLASS2_SIGLEN	16
   578 	#define MSGCLASS2_SIG		"\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
   579 	#define MSGCLASS2_OFFS		11
   580 #endif
   581 
   582 struct UserMessage
   583 {
   584 	int size;
   585 	const char *name;
   586 };
   587 
   588 typedef CUtlDict<UserMessage *, int> UserMsgDict;
   589 
   590 /* This is the ugliest function in all of MM:S */
   591 bool CacheUserMessages()
   592 {
   593 	UserMsgDict *dict = NULL;
   594 
   595 	/* Get address of original GetUserMessageInfo() */
   596 	char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo);
   597 
   598 	/* Oh dear, we have a relative jump on our hands
   599 	 * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
   600 	 */
   601 	if (*vfunc == '\xE9')
   602 	{
   603 		/* Get address from displacement...
   604 		 *
   605 		 * Add 5 because it's relative to next instruction:
   606 		 * Opcode <1 byte> + 32-bit displacement <4 bytes> 
   607 		 */
   608 		vfunc += *reinterpret_cast<int *>(vfunc + 1) + 5;
   609 	}
   610 
   611 	if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
   612 	{
   613 		/* Get address of CUserMessages instance */
   614 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
   615 
   616 		/* Get address of CUserMessages::m_UserMessages */
   617 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   618 	} 
   619 	else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) 
   620 	{
   621 	#ifdef OS_WIN32
   622 		/* If we get here, the code is possibly inlined like in Dystopia */
   623 
   624 		/* Get the address of the CUtlRBTree */
   625 		char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
   626 
   627 		/* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
   628 		dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
   629 	#elif defined OS_LINUX
   630 		/* Get address of CUserMessages instance */
   631 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
   632 
   633 		/* Get address of CUserMessages::m_UserMessages */
   634 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   635 	#endif
   636 	#ifdef OS_WIN32
   637 	} 
   638 	else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN)) 
   639 	{
   640 		/* Get address of CUserMessages instance */
   641 		char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
   642 
   643 		/* Get address of CUserMessages::m_UserMessages */
   644 		dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
   645 	#endif
   646 	}
   647 
   648 	#if !defined OS_WIN32
   649 	if (dict == NULL)
   650 	{
   651 		char path[255];
   652 		if (GetFileOfAddress(vfunc, path, sizeof(path)))
   653 		{
   654 			void *handle = dlopen(path, RTLD_NOW);
   655 			if (handle != NULL)
   656 			{
   657 				void *addr = dlsym(handle, "usermessages");
   658 				if (addr == NULL)
   659 				{
   660 					return false;
   661 				}
   662 				dict = (UserMsgDict *)*(void **)addr;
   663 				dlclose(handle);
   664 			}
   665 		}
   666 	}
   667 	#endif
   668 
   669 	if (dict != NULL)
   670 	{
   671 		int msg_count = dict->Count();
   672 
   673 		/* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
   674 		if (msg_count < 0 || msg_count > 255)
   675 		{
   676 			return false;
   677 		}
   678 
   679 		UserMessage *msg;
   680 		UsrMsgInfo u_msg;
   681 
   682 		/* Cache messages in our CUtlDict */
   683 		for (int i = 0; i < msg_count; i++)
   684 		{
   685 			msg = dict->Element(i);
   686 			u_msg.name = msg->name;
   687 			u_msg.size = msg->size;
   688 			usermsgs_list.push_back(u_msg);
   689 		}
   690 
   691 		return true;
   692 	}
   693 
   694 	return false;
   695 }
   696