1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/core-1.4/CSmmAPI.cpp Fri Nov 14 04:25:40 2008 -0600
1.3 @@ -0,0 +1,633 @@
1.4 +/* ======== SourceMM ========
1.5 + * Copyright (C) 2004-2008 Metamod:Source Development Team
1.6 + * No warranties of any kind
1.7 + *
1.8 + * License: zlib/libpng
1.9 + *
1.10 + * Author(s): David "BAILOPAN" Anderson
1.11 + * ============================
1.12 + */
1.13 +
1.14 +#include "convar_smm.h"
1.15 +#include "CSmmAPI.h"
1.16 +#include "sourcemm.h"
1.17 +#include "concommands.h"
1.18 +#include "CPlugin.h"
1.19 +#include "vsp_listener.h"
1.20 +
1.21 +/**
1.22 + * @brief Implementation of main API interface
1.23 + * @file CSmmAPI.cpp
1.24 + */
1.25 +
1.26 +using namespace SourceMM;
1.27 +
1.28 +CSmmAPI g_SmmAPI;
1.29 +
1.30 +CSmmAPI::CSmmAPI()
1.31 +{
1.32 + m_ConPrintf = NULL;
1.33 + m_CmdCache = false;
1.34 + m_MsgCount = -1;
1.35 + m_VSP = false;
1.36 +}
1.37 +
1.38 +CSmmAPI::~CSmmAPI()
1.39 +{
1.40 + m_UserMessages.RemoveAll();
1.41 +}
1.42 +
1.43 +void CSmmAPI::LogMsg(ISmmPlugin *pl, const char *msg, ...)
1.44 +{
1.45 + va_list ap;
1.46 + static char buffer[2048];
1.47 +
1.48 + va_start(ap, msg);
1.49 + UTIL_FormatArgs(buffer, sizeof(buffer), msg, ap);
1.50 + va_end(ap);
1.51 +
1.52 + LogMessage("[%s] %s", pl->GetLogTag(), buffer);
1.53 +}
1.54 +
1.55 +CreateInterfaceFn CSmmAPI::engineFactory(bool syn)
1.56 +{
1.57 + if (syn)
1.58 + return EngineFactory;
1.59 + return g_Engine.engineFactory;
1.60 +}
1.61 +
1.62 +CreateInterfaceFn CSmmAPI::physicsFactory(bool syn)
1.63 +{
1.64 + if (syn)
1.65 + return PhysicsFactory;
1.66 + return g_Engine.physicsFactory;
1.67 +}
1.68 +
1.69 +CreateInterfaceFn CSmmAPI::fileSystemFactory(bool syn)
1.70 +{
1.71 + if (syn)
1.72 + return FileSystemFactory;
1.73 + return g_Engine.fileSystemFactory;
1.74 +}
1.75 +
1.76 +CreateInterfaceFn CSmmAPI::serverFactory(bool syn)
1.77 +{
1.78 + if (syn)
1.79 + return CreateInterface;
1.80 + return g_GameDll.factory;
1.81 +}
1.82 +
1.83 +CGlobalVars *CSmmAPI::pGlobals()
1.84 +{
1.85 + return g_Engine.pGlobals;
1.86 +}
1.87 +
1.88 +void CSmmAPI::SetLastMetaReturn(META_RES res)
1.89 +{
1.90 + m_Res = res;
1.91 +}
1.92 +
1.93 +META_RES CSmmAPI::GetLastMetaReturn()
1.94 +{
1.95 + return m_Res;
1.96 +}
1.97 +
1.98 +IConCommandBaseAccessor *CSmmAPI::GetCvarBaseAccessor()
1.99 +{
1.100 + return static_cast<IConCommandBaseAccessor *>(&g_SMConVarAccessor);
1.101 +}
1.102 +
1.103 +bool CSmmAPI::RegisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1.104 +{
1.105 + if (pCommand->IsCommand())
1.106 + {
1.107 + g_PluginMngr.AddPluginCmd(plugin, pCommand);
1.108 + } else {
1.109 + g_PluginMngr.AddPluginCvar(plugin, pCommand);
1.110 + }
1.111 +
1.112 + return g_SMConVarAccessor.Register(pCommand);
1.113 +}
1.114 +
1.115 +void CSmmAPI::UnregisterConCmdBase(ISmmPlugin *plugin, ConCommandBase *pCommand)
1.116 +{
1.117 + if (pCommand->IsCommand())
1.118 + {
1.119 + g_PluginMngr.RemovePluginCmd(plugin, pCommand);
1.120 + } else {
1.121 + g_PluginMngr.RemovePluginCvar(plugin, pCommand);
1.122 + }
1.123 +
1.124 + g_SMConVarAccessor.Unregister(pCommand);
1.125 +}
1.126 +
1.127 +void CSmmAPI::ConPrint(const char *fmt)
1.128 +{
1.129 + (m_ConPrintf)("%s", fmt);
1.130 +}
1.131 +
1.132 +void CSmmAPI::ConPrintf(const char *fmt, ...)
1.133 +{
1.134 + va_list ap;
1.135 + static char buffer[4096];
1.136 +
1.137 + va_start(ap, fmt);
1.138 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1.139 + va_end(ap);
1.140 +
1.141 + (m_ConPrintf)("%s", buffer);
1.142 +}
1.143 +
1.144 +void CSmmAPI::AddListener(ISmmPlugin *plugin, IMetamodListener *pListener)
1.145 +{
1.146 + CPluginManager::CPlugin *pl = g_PluginMngr.FindByAPI(plugin);
1.147 + CPluginEventHandler cpeh;
1.148 +
1.149 + cpeh.event = pListener;
1.150 + cpeh.got_vsp = false;
1.151 +
1.152 + pl->m_Events.push_back(cpeh);
1.153 +}
1.154 +
1.155 +void *CSmmAPI::MetaFactory(const char *iface, int *_ret, PluginId *id)
1.156 +{
1.157 + if (id)
1.158 + {
1.159 + *id = 0;
1.160 + }
1.161 +
1.162 + if (!iface)
1.163 + {
1.164 + return NULL;
1.165 + }
1.166 +
1.167 + //first check ours... we get first chance!
1.168 + if (strcmp(iface, MMIFACE_SOURCEHOOK) == 0)
1.169 + {
1.170 + if (_ret)
1.171 + {
1.172 + *_ret = IFACE_OK;
1.173 + }
1.174 + return static_cast<void *>(static_cast<SourceHook::ISourceHook *>(&g_SourceHook));
1.175 + } else if (strcmp(iface, MMIFACE_PLMANAGER) == 0) {
1.176 + if (_ret)
1.177 + {
1.178 + *_ret = IFACE_OK;
1.179 + }
1.180 + return static_cast<void *>(static_cast<ISmmPluginManager *>(&g_PluginMngr));
1.181 + }
1.182 +
1.183 + CPluginManager::CPlugin *pl;
1.184 + SourceHook::List<CPluginEventHandler>::iterator event;
1.185 + IMetamodListener *api;
1.186 + int ret = 0;
1.187 + void *val = NULL;
1.188 +
1.189 + for (PluginIter iter = g_PluginMngr._begin(); iter != g_PluginMngr._end(); iter++)
1.190 + {
1.191 + pl = (*iter);
1.192 + for (event=pl->m_Events.begin(); event!=pl->m_Events.end(); event++)
1.193 + {
1.194 + api = (*event).event;
1.195 + ret = IFACE_FAILED;
1.196 + if ( (val=api->OnMetamodQuery(iface, &ret)) != NULL )
1.197 + {
1.198 + if (_ret)
1.199 + *_ret = ret;
1.200 + if (id)
1.201 + *id = pl->m_Id;
1.202 + return val;
1.203 + }
1.204 + }
1.205 + }
1.206 +
1.207 + if (_ret)
1.208 + *_ret = IFACE_FAILED;
1.209 +
1.210 + return NULL;
1.211 +}
1.212 +
1.213 +//////////////////////////////////////////////////////////////////////////
1.214 +//THERE BE HAX HERE!!!! DON'T TELL ALFRED, BUT GABE WANTED IT THAT WAY. //
1.215 +// (note: you can find the offset by looking for the text //
1.216 +// "Echo text to console", you'll find the callback cmd pushed on the //
1.217 +// stack.) //
1.218 +//////////////////////////////////////////////////////////////////////////
1.219 +
1.220 +#define SIGLEN 8
1.221 +#define ENGINE486_SIG "\x55\x89\xE5\x53\x83\xEC\x14\xBB"
1.222 +#define ENGINE486_OFFS 40
1.223 +#define ENGINE686_SIG "\x53\x83\xEC\x08\xBB\x01\x00\x00"
1.224 +#define ENGINE686_OFFS 50
1.225 +#define ENGINEAMD_SIG "\x53\x51\xBB\x01\x00\x00\x00\x51"
1.226 +#define ENGINEAMD_OFFS 47
1.227 +#define ENGINEW32_SIG "\xA1\x2A\x2A\x2A\x2A\x56\xBE\x01"
1.228 +#define ENGINEW32_OFFS 38
1.229 +#define IA32_CALL 0xE8
1.230 +
1.231 +//Thanks to fysh for the idea of extracting info from "echo" and for
1.232 +// having the original offsets at hand!
1.233 +bool CSmmAPI::CacheCmds()
1.234 +{
1.235 + ICvar *pCvar = g_Engine.icvar;
1.236 +
1.237 + ConCommandBase *pBase = pCvar->GetCommands();
1.238 + unsigned char *ptr = NULL;
1.239 + FnCommandCallback callback = NULL;
1.240 + int offs = 0;
1.241 +
1.242 + while (pBase)
1.243 + {
1.244 + if ( strcmp(pBase->GetName(), "echo") == 0 )
1.245 + {
1.246 + //callback = //*((FnCommandCallback *)((char *)pBase + offsetof(ConCommand, m_fnCommandCallback)));
1.247 + callback = ((ConCommand *)pBase)->GetCallback();
1.248 + ptr = (unsigned char *)callback;
1.249 + #ifdef OS_LINUX
1.250 + if (UTIL_VerifySignature(ptr, ENGINE486_SIG, SIGLEN))
1.251 + {
1.252 + offs = ENGINE486_OFFS;
1.253 + }
1.254 + else if (UTIL_VerifySignature(ptr, ENGINE686_SIG, SIGLEN))
1.255 + {
1.256 + offs = ENGINE686_OFFS;
1.257 + }
1.258 + else if (UTIL_VerifySignature(ptr, ENGINEAMD_SIG, SIGLEN))
1.259 + {
1.260 + offs = ENGINEAMD_OFFS;
1.261 + }
1.262 + #elif defined OS_WIN32 // Only one Windows engine binary so far...
1.263 + if (UTIL_VerifySignature(ptr, ENGINEW32_SIG, SIGLEN))
1.264 + {
1.265 + offs = ENGINEW32_OFFS;
1.266 + }
1.267 + #endif
1.268 +
1.269 + if (!offs || ptr[offs - 1] != IA32_CALL)
1.270 + {
1.271 + m_ConPrintf = (CONPRINTF_FUNC)Msg;
1.272 + return false;
1.273 + }
1.274 + //get the relative offset
1.275 + m_ConPrintf = *((CONPRINTF_FUNC *)(ptr + offs));
1.276 + //add the base offset, to the ip (which is the address+offset + 4 bytes for next instruction)
1.277 + m_ConPrintf = (CONPRINTF_FUNC)((unsigned long)m_ConPrintf + (unsigned long)(ptr + offs) + 4);
1.278 +
1.279 + m_CmdCache = true;
1.280 +
1.281 + return true;
1.282 + }
1.283 + pBase = const_cast<ConCommandBase *>(pBase->GetNext());
1.284 + }
1.285 +
1.286 + m_ConPrintf = (CONPRINTF_FUNC)Msg;
1.287 +
1.288 + return false;
1.289 +}
1.290 +
1.291 +bool CSmmAPI::CmdCacheSuccessful()
1.292 +{
1.293 + return m_CmdCache;
1.294 +}
1.295 +
1.296 +void CSmmAPI::GetApiVersions(int &major, int &minor, int &plvers, int &plmin)
1.297 +{
1.298 + major = SM_VERS_API_MAJOR;
1.299 + minor = SM_VERS_API_MINOR;
1.300 + plvers = PLAPI_VERSION;
1.301 + plmin = PLAPI_MIN_VERSION;
1.302 +}
1.303 +
1.304 +void CSmmAPI::GetShVersions(int &shvers, int &shimpl)
1.305 +{
1.306 + shvers = SH_IFACE_VERSION;
1.307 + shimpl = SH_IMPL_VERSION;
1.308 +}
1.309 +
1.310 +int CSmmAPI::FormatIface(char iface[], unsigned int maxlength)
1.311 +{
1.312 + int length = (int)strlen(iface);
1.313 + int i;
1.314 + int num = 0;
1.315 +
1.316 + for (i = length - 1; i >= 0; i--)
1.317 + {
1.318 + if (!isdigit(iface[i]))
1.319 + {
1.320 + if (i != length - 1)
1.321 + {
1.322 + num = 1;
1.323 + }
1.324 + break;
1.325 + }
1.326 + }
1.327 +
1.328 + if ( (num && ((int)maxlength <= length)) || (!num && ((int)maxlength <= length + 3)) )
1.329 + {
1.330 + return -1;
1.331 + }
1.332 +
1.333 + if (i != length - 1)
1.334 + num = atoi(&(iface[++i]));
1.335 +
1.336 + num++;
1.337 +
1.338 + snprintf(&(iface[i]), 4, "%03d", num);
1.339 +
1.340 + return num;
1.341 +}
1.342 +
1.343 +void *CSmmAPI::InterfaceSearch(CreateInterfaceFn fn, const char *iface, int max, int *ret)
1.344 +{
1.345 + char _if[256]; /* assume no interface goes beyond this */
1.346 + size_t len = strlen(iface);
1.347 + int num = 0;
1.348 + void *pf = NULL;
1.349 +
1.350 + if (max > 999)
1.351 + max = 999;
1.352 +
1.353 + if (len + 4 > sizeof(_if))
1.354 + {
1.355 + if (ret)
1.356 + {
1.357 + *ret = IFACE_FAILED;
1.358 + }
1.359 + return NULL;
1.360 + }
1.361 +
1.362 + strcpy(_if, iface);
1.363 +
1.364 + do
1.365 + {
1.366 + if ( (pf = (fn)(_if, ret)) != NULL )
1.367 + break;
1.368 + if (num > max)
1.369 + break;
1.370 + } while (( num = FormatIface(_if, len+1) ));
1.371 +
1.372 + return pf;
1.373 +}
1.374 +
1.375 +void *CSmmAPI::VInterfaceMatch(CreateInterfaceFn fn, const char *iface, int min)
1.376 +{
1.377 + char buffer[256]; /* assume no interface will go beyond this */
1.378 + size_t len = strlen(iface);
1.379 + int ret; /* just in case something doesn't handle NULL properly */
1.380 +
1.381 + if (len > sizeof(buffer) - 4)
1.382 + {
1.383 + return NULL;
1.384 + }
1.385 +
1.386 + strcpy(buffer, iface);
1.387 +
1.388 + if (min != -1)
1.389 + {
1.390 + char *ptr = &buffer[len - 1];
1.391 + int digits = 0;
1.392 + while (isdigit(*ptr) && digits <=3)
1.393 + {
1.394 + *ptr = '\0';
1.395 + digits++;
1.396 + ptr--;
1.397 + }
1.398 + if (digits != 3)
1.399 + {
1.400 + /* for now, assume this is an error */
1.401 + strcpy(buffer, iface);
1.402 + } else {
1.403 + char num[4];
1.404 + min = (min == 0) ? 1 : min;
1.405 + snprintf(num, sizeof(num), "%03d", min);
1.406 + strcat(buffer, num);
1.407 + }
1.408 + }
1.409 +
1.410 + return InterfaceSearch(fn, buffer, IFACE_MAXNUM, &ret);
1.411 +}
1.412 +
1.413 +const char *CSmmAPI::GetBaseDir()
1.414 +{
1.415 + return g_ModPath.c_str();
1.416 +}
1.417 +
1.418 +void CSmmAPI::PathFormat(char *buffer, size_t len, const char *fmt, ...)
1.419 +{
1.420 + va_list ap;
1.421 + va_start(ap, fmt);
1.422 + size_t mylen = UTIL_FormatArgs(buffer, len, fmt, ap);
1.423 + va_end(ap);
1.424 +
1.425 + for (size_t i = 0; i < mylen; i++)
1.426 + {
1.427 + if (buffer[i] == ALT_SEP_CHAR)
1.428 + {
1.429 + buffer[i] = PATH_SEP_CHAR;
1.430 + }
1.431 + }
1.432 +}
1.433 +
1.434 +void CSmmAPI::ClientConPrintf(edict_t *client, const char *fmt, ...)
1.435 +{
1.436 + va_list ap;
1.437 + static char buffer[4096];
1.438 +
1.439 + va_start(ap, fmt);
1.440 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
1.441 + va_end(ap);
1.442 +
1.443 + g_Engine.engine->ClientPrintf(client, buffer);
1.444 +}
1.445 +
1.446 +void CSmmAPI::LoadAsVSP()
1.447 +{
1.448 + size_t len;
1.449 + char engine_file[PATH_SIZE];
1.450 + char rel_path[PATH_SIZE * 2];
1.451 +
1.452 + GetFileOfAddress(g_Engine.engine, engine_file, sizeof(engine_file));
1.453 +
1.454 + /* Chop off the "engine" file part */
1.455 + len = strlen(engine_file);
1.456 + for (size_t i = len - 1; i >= 0 && i < len; i--)
1.457 + {
1.458 + if (engine_file[i] == '/'
1.459 + || engine_file[i] == '\\')
1.460 + {
1.461 + engine_file[i] = '\0';
1.462 + break;
1.463 + }
1.464 + }
1.465 +
1.466 + const char *usepath = g_SmmPath.c_str();
1.467 + if (UTIL_Relatize(rel_path, sizeof(rel_path), engine_file, g_SmmPath.c_str()))
1.468 + {
1.469 + usepath = rel_path;
1.470 + }
1.471 +
1.472 + char command[PATH_SIZE * 2];
1.473 + g_VspListener.SetLoadable(true);
1.474 + UTIL_Format(command, sizeof(command), "plugin_load \"%s\"\n", usepath);
1.475 + g_Engine.engine->ServerCommand(command);
1.476 +}
1.477 +
1.478 +void CSmmAPI::EnableVSPListener()
1.479 +{
1.480 + /* If GameInit already passed and we're not already enabled or loaded, go ahead and LoadAsVSP load */
1.481 + if (bGameInit && !m_VSP && !g_VspListener.IsLoaded() && !g_VspListener.IsRootLoadMethod())
1.482 + {
1.483 + LoadAsVSP();
1.484 + }
1.485 + m_VSP = true;
1.486 +}
1.487 +
1.488 +int CSmmAPI::GetGameDLLVersion()
1.489 +{
1.490 + return g_GameDllVersion;
1.491 +}
1.492 +
1.493 +//////////////////////////////////////////////////////////////////////
1.494 +// EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED! //
1.495 +// Signatures necessary in finding the pointer to the CUtlDict that //
1.496 +// stores user message information. //
1.497 +// IServerGameDLL::GetUserMessageInfo() normally crashes with bad //
1.498 +// message indices. This is our answer to it. Yuck! <:-( //
1.499 +//////////////////////////////////////////////////////////////////////
1.500 +#ifdef OS_WIN32
1.501 + /* General Windows sig */
1.502 + #define MSGCLASS_SIGLEN 7
1.503 + #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
1.504 + #define MSGCLASS_OFFS 2
1.505 +
1.506 + /* Dystopia Wimdows hack */
1.507 + #define MSGCLASS2_SIGLEN 16
1.508 + #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
1.509 + #define MSGCLASS2_OFFS 11
1.510 +
1.511 + /* Windows frame pointer sig */
1.512 + #define MSGCLASS3_SIGLEN 18
1.513 + #define MSGCLASS3_SIG "\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
1.514 + #define MSGCLASS3_OFFS 13
1.515 +#elif defined OS_LINUX
1.516 + /* No frame pointer sig */
1.517 + #define MSGCLASS_SIGLEN 14
1.518 + #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
1.519 + #define MSGCLASS_OFFS 9
1.520 +
1.521 + /* Frame pointer sig */
1.522 + #define MSGCLASS2_SIGLEN 16
1.523 + #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
1.524 + #define MSGCLASS2_OFFS 11
1.525 +#endif
1.526 +
1.527 +/* This is the ugliest function in all of SourceMM */
1.528 +/* :TODO: Make this prettier */
1.529 +bool CSmmAPI::CacheUserMessages()
1.530 +{
1.531 + UserMsgDict *dict = NULL;
1.532 + char *vfunc = UTIL_GetOrigFunction(&IServerGameDLL::GetUserMessageInfo, g_GameDll.pGameDLL, g_GameDllPatch);
1.533 +
1.534 + if (!vfunc)
1.535 + {
1.536 + return false;
1.537 + }
1.538 +
1.539 + if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
1.540 + {
1.541 + /* Get address of CUserMessages instance */
1.542 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
1.543 +
1.544 + /* Get address of CUserMessages::m_UserMessages */
1.545 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.546 + } else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN)) {
1.547 + #ifdef OS_WIN32
1.548 + /* If we get here, the code is possibly inlined like in Dystopia */
1.549 +
1.550 + /* Get the address of the CUtlRBTree */
1.551 + char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
1.552 +
1.553 + /* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
1.554 + dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
1.555 + #elif defined OS_LINUX
1.556 + /* Get address of CUserMessages instance */
1.557 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
1.558 +
1.559 + /* Get address of CUserMessages::m_UserMessages */
1.560 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.561 + #endif
1.562 + #ifdef OS_WIN32
1.563 + } else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN)) {
1.564 + /* Get address of CUserMessages instance */
1.565 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
1.566 +
1.567 + /* Get address of CUserMessages::m_UserMessages */
1.568 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
1.569 + #endif
1.570 + }
1.571 +
1.572 + if (dict)
1.573 + {
1.574 + m_MsgCount = dict->Count();
1.575 +
1.576 + /* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
1.577 + if (m_MsgCount < 0 || m_MsgCount > 255)
1.578 + {
1.579 + m_MsgCount = -1;
1.580 + return false;
1.581 + }
1.582 +
1.583 + UserMessage *msg;
1.584 +
1.585 + /* Cache messages in our CUtlDict */
1.586 + for (int i = 0; i < m_MsgCount; i++)
1.587 + {
1.588 + msg = dict->Element(i);
1.589 + m_UserMessages.Insert(msg->name, msg);
1.590 + }
1.591 +
1.592 + return true;
1.593 + }
1.594 +
1.595 + return false;
1.596 +}
1.597 +
1.598 +bool CSmmAPI::MsgCacheSuccessful()
1.599 +{
1.600 + return m_MsgCount > -1;
1.601 +}
1.602 +
1.603 +int CSmmAPI::GetUserMessageCount()
1.604 +{
1.605 + return m_MsgCount;
1.606 +}
1.607 +
1.608 +int CSmmAPI::FindUserMessage(const char *name, int *size)
1.609 +{
1.610 + int index = m_UserMessages.Find(name);
1.611 +
1.612 + if (size && index > -1)
1.613 + {
1.614 + UserMessage *msg = m_UserMessages.Element(index);
1.615 + *size = msg->size;
1.616 + }
1.617 +
1.618 + return index;
1.619 +}
1.620 +
1.621 +const char *CSmmAPI::GetUserMessage(int index, int *size)
1.622 +{
1.623 + if (m_MsgCount <= 0 || index < 0 || index >= m_MsgCount)
1.624 + {
1.625 + return NULL;
1.626 + }
1.627 +
1.628 + UserMessage *msg = m_UserMessages.Element(index);
1.629 +
1.630 + if (size)
1.631 + {
1.632 + *size = msg->size;
1.633 + }
1.634 +
1.635 + return msg->name;
1.636 +}