ds@658: /** ds@669: * vim: set ts=4 sw=4 tw=99 noet : ds@658: * ====================================================== ds@658: * Metamod:Source ds@669: * Copyright (C) 2004-2009 AlliedModders LLC and authors. ds@658: * All rights reserved. ds@658: * ====================================================== ds@658: * ds@658: * This software is provided 'as-is', without any express or implied warranty. ds@658: * In no event will the authors be held liable for any damages arising from ds@658: * the use of this software. ds@658: * ds@658: * Permission is granted to anyone to use this software for any purpose, ds@658: * including commercial applications, and to alter it and redistribute it ds@658: * freely, subject to the following restrictions: ds@658: * ds@658: * 1. The origin of this software must not be misrepresented; you must not ds@658: * claim that you wrote the original software. If you use this software in a ds@658: * product, an acknowledgment in the product documentation would be ds@658: * appreciated but is not required. ds@658: * 2. Altered source versions must be plainly marked as such, and must not be ds@658: * misrepresented as being the original software. ds@658: * 3. This notice may not be removed or altered from any source distribution. ds@658: */ ds@658: ds@658: #include ds@658: #include "../metamod_oslink.h" ds@658: #include ds@658: #include ds@658: #include ds@658: #include ds@658: #include ds@658: #include ds@658: #include ds@658: #include "../metamod_util.h" ds@658: #include "provider_ep2.h" ds@658: #include "console.h" ds@658: #include "metamod_console.h" ds@658: #include "vsp_listener.h" ds@658: #include ds@658: #include "metamod.h" ds@658: ds@658: /* Types */ ds@658: typedef void (*CONPRINTF_FUNC)(const char *, ...); ds@658: struct UsrMsgInfo ds@658: { ds@658: UsrMsgInfo() ds@658: { ds@658: } ds@658: UsrMsgInfo(int s, const char *t) : size(s), name(t) ds@658: { ds@658: } ds@658: int size; ds@658: String name; ds@658: }; ds@658: ds@658: /* Imports */ ds@658: #if SOURCE_ENGINE == SE_DARKMESSIAH ds@658: #undef CommandLine ds@658: DLL_IMPORT ICommandLine *CommandLine(); ds@658: #endif ds@658: ds@658: /* Functions */ ds@658: bool CacheUserMessages(); ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: void ClientCommand(edict_t *pEdict, const CCommand &args); ds@658: void LocalCommand_Meta(const CCommand &args); ds@658: #else ds@658: void ClientCommand(edict_t *pEdict); ds@658: void LocalCommand_Meta(); ds@658: #endif ds@658: ds@658: void _ServerCommand(); ds@658: /* Variables */ ds@658: static bool usermsgs_extracted = false; ds@658: static CVector usermsgs_list; ds@658: static VSPListener g_VspListener; ds@658: static BaseProvider g_Ep1Provider; ds@658: static List conbases_unreg; ds@658: ds@658: ICvar *icvar = NULL; ds@658: IFileSystem *baseFs = NULL; ds@658: IServerGameDLL *server = NULL; ds@658: IVEngineServer *engine = NULL; ds@658: IServerGameClients *gameclients = NULL; ds@658: IMetamodSourceProvider *provider = &g_Ep1Provider; ds@658: ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options"); ds@658: ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &); ds@658: #else ds@658: SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *); ds@658: #endif ds@658: ds@658: bool AssumeUserMessages() ds@658: { ds@658: int q, size; ds@658: char buffer[256]; ds@658: ds@658: q = 0; ds@658: ds@658: while (server->GetUserMessageInfo(q, buffer, sizeof(buffer), size)) ds@658: { ds@658: usermsgs_list.push_back(UsrMsgInfo(size, buffer)); ds@658: q++; ds@658: } ds@658: ds@658: return true; ds@658: } ds@658: ds@658: void BaseProvider::ConsolePrint(const char *str) ds@658: { ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: ConMsg("%s", str); ds@658: #else ds@658: Msg("%s", str); ds@658: #endif ds@658: } ds@658: ds@658: void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory, ds@658: CreateInterfaceFn serverFactory) ds@658: { ds@658: engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL)); ds@658: if (!engine) ds@658: { ds@658: DisplayError("Could not find IVEngineServer! Metamod cannot load."); ds@658: return; ds@658: } ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: icvar = (ICvar *)((engineFactory)(CVAR_INTERFACE_VERSION, NULL)); ds@658: #else ds@658: icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL)); ds@658: #endif ds@658: if (!icvar) ds@658: { ds@658: DisplayError("Could not find ICvar! Metamod cannot load."); ds@658: return; ds@658: } ds@658: ds@658: ds@658: if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL))) ds@658: == NULL) ds@658: { ds@658: gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL)); ds@658: } ds@658: ds@658: baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL)); ds@658: if (baseFs == NULL) ds@658: { ds@658: mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION); ds@658: return; ds@658: } ds@658: ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: g_pCVar = icvar; ds@658: #endif ds@658: ds@658: g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd); ds@658: ds@658: if ((usermsgs_extracted = CacheUserMessages()) == false) ds@658: { ds@658: usermsgs_extracted = AssumeUserMessages(); ds@658: } ds@658: ds@658: #if SOURCE_ENGINE == SE_DARKMESSIAH ds@637: if (!g_SMConVarAccessor.InitConCommandBaseList()) ds@637: { ds@637: /* This is very unlikely considering it's old engine */ ds@637: mm_LogMessage("[META] Warning: Failed to find ConCommandBase list!"); ds@637: mm_LogMessage("[META] Warning: ConVars and ConCommands cannot be unregistered properly! Please file a bug report."); ds@658: } ds@658: #endif ds@658: ds@658: if (gameclients) ds@658: { ds@658: SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, false); ds@658: } ds@658: } ds@658: ds@658: void BaseProvider::Notify_DLLShutdown_Pre() ds@658: { ds@658: g_SMConVarAccessor.RemoveMetamodCommands(); ds@658: ds@658: #if SOURCE_ENGINE == SE_DARKMESSIAH ds@658: if (g_Metamod.IsLoadedAsGameDLL()) ds@658: { ds@658: icvar->UnlinkVariables(FCVAR_GAMEDLL); ds@658: } ds@658: #endif ds@658: } ds@658: ds@658: bool BaseProvider::IsRemotePrintingAvailable() ds@658: { ds@658: return true; ds@658: } ds@658: ds@658: void BaseProvider::ClientConsolePrint(edict_t *client, const char *message) ds@658: { ds@658: engine->ClientPrintf(client, message); ds@658: } ds@658: ds@658: void BaseProvider::ServerCommand(const char *cmd) ds@658: { ds@658: engine->ServerCommand(cmd); ds@658: } ds@658: ds@658: const char *BaseProvider::GetConVarString(ConVar *convar) ds@658: { ds@658: if (convar == NULL) ds@658: { ds@658: return NULL; ds@658: } ds@658: ds@658: return convar->GetString(); ds@658: } ds@658: ds@658: void BaseProvider::SetConVarString(ConVar *convar, const char *str) ds@658: { ds@658: convar->SetValue(str); ds@658: } ds@658: ds@658: bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand) ds@658: { ds@658: return pCommand->IsCommand(); ds@658: } ds@658: ds@658: ds@658: bool BaseProvider::IsSourceEngineBuildCompatible(int build) ds@658: { ds@658: return (build == SOURCE_ENGINE_ORIGINAL ds@658: || build == SOURCE_ENGINE_EPISODEONE); ds@658: } ds@658: ds@658: const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval) ds@658: { ds@658: if (key[0] == '-' || key[0] == '+') ds@658: { ds@658: return CommandLine()->ParmValue(key, defval); ds@658: } ds@658: else if (icvar) ds@658: { ds@658: const char *val; ds@658: if ((val = icvar->GetCommandLineValue(key)) == NULL) ds@658: { ds@658: return defval; ds@658: } ds@658: ds@658: return val; ds@658: } ds@658: ds@658: return NULL; ds@658: } ds@658: ds@658: int BaseProvider::TryServerGameDLL(const char *iface) ds@658: { ds@658: if (strncmp(iface, "ServerGameDLL", 13) != 0) ds@658: { ds@658: return 0; ds@658: } ds@658: ds@658: return atoi(&iface[13]); ds@658: } ds@658: ds@658: bool BaseProvider::LogMessage(const char *buffer) ds@658: { ds@658: if (!engine) ds@658: { ds@658: return false; ds@658: } ds@658: ds@658: engine->LogPrint(buffer); ds@658: ds@658: return true; ds@658: } ds@658: ds@658: bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo) ds@658: { ds@658: SourceHook::MemFuncInfo mfi = {true, -1, 0, 0}; ds@658: ds@658: if (hook == ProvidedHook_LevelInit) ds@658: { ds@658: SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi); ds@658: } ds@658: else if (hook == ProvidedHook_LevelShutdown) ds@658: { ds@658: SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi); ds@658: } ds@658: else if (hook == ProvidedHook_GameInit) ds@658: { ds@658: SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi); ds@658: } ds@658: ds@658: *pInfo = mfi; ds@658: ds@658: return (mfi.thisptroffs >= 0); ds@658: } ds@658: ds@658: void BaseProvider::DisplayError(const char *fmt, ...) ds@658: { ds@658: va_list ap; ds@658: char buffer[2048]; ds@658: ds@658: va_start(ap, fmt); ds@658: UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap); ds@658: va_end(ap); ds@658: ds@658: Error(buffer); ds@658: } ds@658: ds@658: void BaseProvider::DisplayWarning(const char *fmt, ...) ds@658: { ds@658: va_list ap; ds@658: char buffer[2048]; ds@658: ds@658: va_start(ap, fmt); ds@658: UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap); ds@658: va_end(ap); ds@658: ds@658: Warning(buffer); ds@658: } ds@658: ds@658: IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor() ds@658: { ds@658: return &g_SMConVarAccessor; ds@658: } ds@658: ds@658: bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand) ds@658: { ds@658: return g_SMConVarAccessor.Register(pCommand); ds@658: } ds@658: ds@658: void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand) ds@658: { ds@658: return g_SMConVarAccessor.Unregister(pCommand); ds@658: } ds@658: ds@658: int BaseProvider::GetUserMessageCount() ds@658: { ds@658: if (!usermsgs_extracted) ds@658: { ds@658: return -1; ds@658: } ds@658: ds@658: return (int)usermsgs_list.size(); ds@658: } ds@658: ds@658: int BaseProvider::FindUserMessage(const char *name, int *size) ds@658: { ds@658: for (size_t i = 0; i < usermsgs_list.size(); i++) ds@658: { ds@658: if (usermsgs_list[i].name.compare(name) == 0) ds@658: { ds@658: if (size) ds@658: { ds@658: *size = usermsgs_list[i].size; ds@658: } ds@658: return (int)i; ds@658: } ds@658: } ds@658: ds@658: return -1; ds@658: } ds@658: ds@658: const char *BaseProvider::GetUserMessage(int index, int *size) ds@658: { ds@658: if (!usermsgs_extracted || index < 0 || index >= (int)usermsgs_list.size()) ds@658: { ds@658: return NULL; ds@658: } ds@658: ds@658: if (size) ds@658: { ds@658: *size = usermsgs_list[index].size; ds@658: } ds@658: ds@658: return usermsgs_list[index].name.c_str(); ds@658: } ds@658: ds@658: const char *BaseProvider::GetGameDescription() ds@658: { ds@658: return server->GetGameDescription(); ds@658: } ds@658: ds@658: int BaseProvider::DetermineSourceEngine(const char *game) ds@658: { ds@669: #if SOURCE_ENGINE == SE_LEFT4DEAD2 ds@669: return SOURCE_ENGINE_LEFT4DEAD2; ds@669: #elif SOURCE_ENGINE == SE_LEFT4DEAD ds@658: return SOURCE_ENGINE_LEFT4DEAD; ds@658: #elif SOURCE_ENGINE == SE_ORANGEBOX ds@658: return SOURCE_ENGINE_ORANGEBOX; ds@674: #elif SOURCE_ENGINE == SE_ORANGEBOXVALVE ds@674: return SOURCE_ENGINE_ORANGEBOXVALVE; ds@669: #elif SOURCE_ENGINE == SE_DARKMESSIAH ds@669: return SOURCE_ENGINE_DARKMESSIAH; ds@658: #else ds@669: #error "SOURCE_ENGINE not defined to a known value" ds@658: #endif ds@658: } ds@658: ds@658: ConVar *BaseProvider::CreateConVar(const char *name, ds@658: const char *defval, ds@658: const char *help, ds@658: int flags) ds@658: { ds@658: int newflags = 0; ds@658: if (flags & ConVarFlag_Notify) ds@658: { ds@658: newflags |= FCVAR_NOTIFY; ds@658: } ds@658: if (flags & ConVarFlag_SpOnly) ds@658: { ds@658: newflags |= FCVAR_SPONLY; ds@658: } ds@658: ds@658: ConVar *pVar = new ConVar(name, defval, newflags, help); ds@658: ds@658: g_SMConVarAccessor.RegisterConCommandBase(pVar); ds@658: ds@658: return pVar; ds@658: } ds@658: ds@658: IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version) ds@658: { ds@658: if (version > 2) ds@658: { ds@658: return NULL; ds@658: } ds@658: ds@658: g_VspListener.SetLoadable(true); ds@658: return &g_VspListener; ds@658: } ds@658: ds@658: bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len) ds@658: { ds@658: if (baseFs == NULL) ds@658: { ds@658: return false; ds@658: } ds@658: ds@658: KeyValues *pValues; ds@658: const char *plugin_file, *p_alias; ds@658: ds@658: pValues = new KeyValues("Metamod Plugin"); ds@658: ds@658: if (!pValues->LoadFromFile(baseFs, file)) ds@658: { ds@658: pValues->deleteThis(); ds@658: return false; ds@658: } ds@658: ds@658: if ((plugin_file = pValues->GetString("file", NULL)) == NULL) ds@658: { ds@658: pValues->deleteThis(); ds@658: return false; ds@658: } ds@658: ds@658: UTIL_Format(path, path_len, "%s", plugin_file); ds@658: ds@658: if ((p_alias = pValues->GetString("alias", NULL)) != NULL) ds@658: { ds@658: UTIL_Format(alias, alias_len, "%s", p_alias); ds@658: } ds@658: else ds@658: { ds@658: UTIL_Format(alias, alias_len, ""); ds@658: } ds@658: ds@658: pValues->deleteThis(); ds@658: ds@658: return true; ds@658: } ds@658: ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: class GlobCommand : public IMetamodSourceCommandInfo ds@658: { ds@658: public: ds@658: GlobCommand(const CCommand *cmd) : m_cmd(cmd) ds@658: { ds@658: } ds@658: public: ds@658: unsigned int GetArgCount() ds@658: { ds@658: return m_cmd->ArgC() - 1; ds@658: } ds@658: ds@658: const char *GetArg(unsigned int num) ds@658: { ds@658: return m_cmd->Arg(num); ds@658: } ds@658: ds@658: const char *GetArgString() ds@658: { ds@658: return m_cmd->ArgS(); ds@658: } ds@658: private: ds@658: const CCommand *m_cmd; ds@658: }; ds@658: #else ds@658: class GlobCommand : public IMetamodSourceCommandInfo ds@658: { ds@658: public: ds@658: unsigned int GetArgCount() ds@658: { ds@658: return engine->Cmd_Argc() - 1; ds@658: } ds@658: ds@658: const char *GetArg(unsigned int num) ds@658: { ds@658: return engine->Cmd_Argv(num); ds@658: } ds@658: ds@658: const char *GetArgString() ds@658: { ds@658: return engine->Cmd_Args(); ds@658: } ds@658: }; ds@658: #endif ds@658: ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: void LocalCommand_Meta(const CCommand &args) ds@658: { ds@658: GlobCommand cmd(&args); ds@658: #else ds@658: void LocalCommand_Meta() ds@658: { ds@658: GlobCommand cmd; ds@658: #endif ds@658: Command_Meta(&cmd); ds@658: } ds@658: ds@658: #if SOURCE_ENGINE >= SE_ORANGEBOX ds@658: void ClientCommand(edict_t *pEdict, const CCommand &_cmd) ds@658: { ds@658: GlobCommand cmd(&_cmd); ds@658: #else ds@658: void ClientCommand(edict_t *pEdict) ds@658: { ds@658: GlobCommand cmd; ds@658: #endif ds@658: if (strcmp(cmd.GetArg(0), "meta") == 0) ds@658: { ds@658: Command_ClientMeta(pEdict, &cmd); ds@658: RETURN_META(MRES_SUPERCEDE); ds@658: } ds@658: ds@658: RETURN_META(MRES_IGNORED); ds@658: } ds@658: ds@658: ////////////////////////////////////////////////////////////////////// ds@658: // EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED! // ds@658: // Signatures necessary in finding the pointer to the CUtlDict that // ds@658: // stores user message information. // ds@658: // IServerGameDLL::GetUserMessageInfo() normally crashes with bad // ds@658: // message indices. This is our answer to it. Yuck! <:-( // ds@658: ////////////////////////////////////////////////////////////////////// ds@658: #ifdef OS_WIN32 ds@658: /* General Windows sig */ ds@658: #define MSGCLASS_SIGLEN 7 ds@658: #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56" ds@658: #define MSGCLASS_OFFS 2 ds@658: ds@658: /* Dystopia Windows hack */ ds@658: #define MSGCLASS2_SIGLEN 16 ds@658: #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D" ds@658: #define MSGCLASS2_OFFS 11 ds@658: ds@658: /* Windows frame pointer sig */ ds@658: #define MSGCLASS3_SIGLEN 18 ds@658: #define MSGCLASS3_SIG "\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8" ds@658: #define MSGCLASS3_OFFS 13 ds@658: #elif defined OS_LINUX ds@658: /* No frame pointer sig */ ds@658: #define MSGCLASS_SIGLEN 14 ds@658: #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89" ds@658: #define MSGCLASS_OFFS 9 ds@658: ds@658: /* Frame pointer sig */ ds@658: #define MSGCLASS2_SIGLEN 16 ds@658: #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89" ds@658: #define MSGCLASS2_OFFS 11 ds@658: #endif ds@658: ds@658: struct UserMessage ds@658: { ds@658: int size; ds@658: const char *name; ds@658: }; ds@658: ds@658: typedef CUtlDict UserMsgDict; ds@658: ds@658: /* This is the ugliest function in all of MM:S */ ds@658: bool CacheUserMessages() ds@658: { ds@658: UserMsgDict *dict = NULL; ds@658: ds@658: /* Get address of original GetUserMessageInfo() */ ds@658: char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo); ds@658: ds@658: /* Oh dear, we have a relative jump on our hands ds@658: * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too... ds@658: */ ds@658: if (*vfunc == '\xE9') ds@658: { ds@658: /* Get address from displacement... ds@658: * ds@658: * Add 5 because it's relative to next instruction: ds@658: * Opcode <1 byte> + 32-bit displacement <4 bytes> ds@658: */ ds@658: vfunc += *reinterpret_cast(vfunc + 1) + 5; ds@658: } ds@658: ds@658: if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN)) ds@658: { ds@658: /* Get address of CUserMessages instance */ ds@658: char **userMsgClass = *reinterpret_cast(vfunc + MSGCLASS_OFFS); ds@658: ds@658: /* Get address of CUserMessages::m_UserMessages */ ds@658: dict = reinterpret_cast(*userMsgClass); ds@658: } ds@658: else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) ds@658: { ds@658: #ifdef OS_WIN32 ds@658: /* If we get here, the code is possibly inlined like in Dystopia */ ds@658: ds@658: /* Get the address of the CUtlRBTree */ ds@658: char *rbtree = *reinterpret_cast(vfunc + MSGCLASS2_OFFS); ds@658: ds@658: /* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */ ds@658: dict = reinterpret_cast(rbtree - 8); ds@658: #elif defined OS_LINUX ds@658: /* Get address of CUserMessages instance */ ds@658: char **userMsgClass = *reinterpret_cast(vfunc + MSGCLASS2_OFFS); ds@658: ds@658: /* Get address of CUserMessages::m_UserMessages */ ds@658: dict = reinterpret_cast(*userMsgClass); ds@658: #endif ds@658: #ifdef OS_WIN32 ds@658: } ds@658: else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN)) ds@658: { ds@658: /* Get address of CUserMessages instance */ ds@658: char **userMsgClass = *reinterpret_cast(vfunc + MSGCLASS3_OFFS); ds@658: ds@658: /* Get address of CUserMessages::m_UserMessages */ ds@658: dict = reinterpret_cast(*userMsgClass); ds@658: #endif ds@658: } ds@658: ds@658: #if !defined OS_WIN32 ds@658: if (dict == NULL) ds@658: { ds@658: char path[255]; ds@658: if (GetFileOfAddress(vfunc, path, sizeof(path))) ds@658: { ds@658: void *handle = dlopen(path, RTLD_NOW); ds@658: if (handle != NULL) ds@658: { ds@658: void *addr = dlsym(handle, "usermessages"); ds@658: if (addr == NULL) ds@658: { ds@658: return false; ds@658: } ds@658: dict = (UserMsgDict *)*(void **)addr; ds@658: dlclose(handle); ds@658: } ds@658: } ds@658: } ds@658: #endif ds@658: ds@658: if (dict != NULL) ds@658: { ds@658: int msg_count = dict->Count(); ds@658: ds@658: /* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */ ds@658: if (msg_count < 0 || msg_count > 255) ds@658: { ds@658: return false; ds@658: } ds@658: ds@658: UserMessage *msg; ds@658: UsrMsgInfo u_msg; ds@658: ds@658: /* Cache messages in our CUtlDict */ ds@658: for (int i = 0; i < msg_count; i++) ds@658: { ds@658: msg = dict->Element(i); ds@658: u_msg.name = msg->name; ds@658: u_msg.size = msg->size; ds@658: usermsgs_list.push_back(u_msg); ds@658: } ds@658: ds@658: return true; ds@658: } ds@658: ds@658: return false; ds@658: } ds@658: