core/provider/provider_ep2.cpp
author Scott Ehlert <ds@alliedmods.net>
Wed Feb 18 01:38:23 2009 -0600 (2009-02-18)
changeset 637 b66489d8aedc
parent 626 08879e2aa990
child 658 8353605c1d97
permissions -rw-r--r--
Added support for Dark Messiah engine and game. (no bug, r=me).

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