Merge.
Merge.
1.1 --- a/core/metamod_util.cpp Wed Oct 28 23:14:32 2009 -0700
1.2 +++ b/core/metamod_util.cpp Wed Oct 28 23:15:26 2009 -0700
1.3 @@ -342,18 +342,18 @@
1.4 return true;
1.5 }
1.6
1.7 -bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len)
1.8 -{
1.9 - unsigned char *addr1 = (unsigned char *) addr;
1.10 - unsigned char *addr2 = (unsigned char *) sig;
1.11 -
1.12 - for (size_t i = 0; i < len; i++)
1.13 - {
1.14 - if (addr2[i] == '*')
1.15 - continue;
1.16 - if (addr1[i] != addr2[i])
1.17 - return false;
1.18 - }
1.19 -
1.20 - return true;
1.21 -}
1.22 +bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len)
1.23 +{
1.24 + unsigned char *addr1 = (unsigned char *) addr;
1.25 + unsigned char *addr2 = (unsigned char *) sig;
1.26 +
1.27 + for (size_t i = 0; i < len; i++)
1.28 + {
1.29 + if (addr2[i] == '*')
1.30 + continue;
1.31 + if (addr1[i] != addr2[i])
1.32 + return false;
1.33 + }
1.34 +
1.35 + return true;
1.36 +}
2.1 --- a/core/metamod_util.h Wed Oct 28 23:14:32 2009 -0700
2.2 +++ b/core/metamod_util.h Wed Oct 28 23:15:26 2009 -0700
2.3 @@ -85,14 +85,14 @@
2.4 const char *relTo,
2.5 const char *relFrom);
2.6
2.7 -/**
2.8 - * @brief Compares memory address against a signature.
2.9 - *
2.10 - * @param addr Memory address to check.
2.11 - * @param sig Signature used to check against memory address. Accept 0x2A as wildcard.
2.12 - * @param len Length of signature.
2.13 - * @return True if signature was verified, false otherwise.
2.14 - */
2.15 +/**
2.16 + * @brief Compares memory address against a signature.
2.17 + *
2.18 + * @param addr Memory address to check.
2.19 + * @param sig Signature used to check against memory address. Accept 0x2A as wildcard.
2.20 + * @param len Length of signature.
2.21 + * @return True if signature was verified, false otherwise.
2.22 + */
2.23 bool UTIL_VerifySignature(const void *addr, const char *sig, size_t len);
2.24
2.25 #endif //_INCLUDE_UTIL_H
3.1 --- a/core/provider/provider_ep2.cpp Wed Oct 28 23:14:32 2009 -0700
3.2 +++ b/core/provider/provider_ep2.cpp Wed Oct 28 23:15:26 2009 -0700
3.3 @@ -1,695 +1,694 @@
3.4 -
3.5 -/**
3.6 - * vim: set ts=4 :
3.7 - * ======================================================
3.8 - * Metamod:Source
3.9 - * Copyright (C) 2004-2008 AlliedModders LLC and authors.
3.10 - * All rights reserved.
3.11 - * ======================================================
3.12 - *
3.13 - * This software is provided 'as-is', without any express or implied warranty.
3.14 - * In no event will the authors be held liable for any damages arising from
3.15 - * the use of this software.
3.16 - *
3.17 - * Permission is granted to anyone to use this software for any purpose,
3.18 - * including commercial applications, and to alter it and redistribute it
3.19 - * freely, subject to the following restrictions:
3.20 - *
3.21 - * 1. The origin of this software must not be misrepresented; you must not
3.22 - * claim that you wrote the original software. If you use this software in a
3.23 - * product, an acknowledgment in the product documentation would be
3.24 - * appreciated but is not required.
3.25 - * 2. Altered source versions must be plainly marked as such, and must not be
3.26 - * misrepresented as being the original software.
3.27 - * 3. This notice may not be removed or altered from any source distribution.
3.28 - *
3.29 - * Version: $Id$
3.30 - */
3.31 -
3.32 -#include <stdio.h>
3.33 -#include "../metamod_oslink.h"
3.34 -#include <sourcehook.h>
3.35 -#include <convar.h>
3.36 -#include <eiface.h>
3.37 -#include <tier0/icommandline.h>
3.38 -#include <tier1/utldict.h>
3.39 -#include <sh_vector.h>
3.40 -#include <sh_string.h>
3.41 -#include "../metamod_util.h"
3.42 -#include "provider_ep2.h"
3.43 -#include "console.h"
3.44 -#include "metamod_console.h"
3.45 -#include "vsp_listener.h"
3.46 -#include <filesystem.h>
3.47 -#include "metamod.h"
3.48 -
3.49 -/* Types */
3.50 -typedef void (*CONPRINTF_FUNC)(const char *, ...);
3.51 -struct UsrMsgInfo
3.52 -{
3.53 - UsrMsgInfo()
3.54 - {
3.55 - }
3.56 - UsrMsgInfo(int s, const char *t) : size(s), name(t)
3.57 - {
3.58 - }
3.59 - int size;
3.60 - String name;
3.61 -};
3.62 -
3.63 -/* Imports */
3.64 -#if SOURCE_ENGINE == SE_DARKMESSIAH
3.65 -#undef CommandLine
3.66 -DLL_IMPORT ICommandLine *CommandLine();
3.67 -#endif
3.68 -
3.69 -/* Functions */
3.70 -bool CacheUserMessages();
3.71 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.72 -void ClientCommand(edict_t *pEdict, const CCommand &args);
3.73 -void LocalCommand_Meta(const CCommand &args);
3.74 -#else
3.75 -void ClientCommand(edict_t *pEdict);
3.76 -void LocalCommand_Meta();
3.77 -#endif
3.78 -
3.79 -void _ServerCommand();
3.80 -/* Variables */
3.81 -static bool usermsgs_extracted = false;
3.82 -static CVector<UsrMsgInfo> usermsgs_list;
3.83 -static VSPListener g_VspListener;
3.84 -static BaseProvider g_Ep1Provider;
3.85 -static List<ConCommandBase *> conbases_unreg;
3.86 -
3.87 -ICvar *icvar = NULL;
3.88 -IFileSystem *baseFs = NULL;
3.89 -IServerGameDLL *server = NULL;
3.90 -IVEngineServer *engine = NULL;
3.91 -IServerGameClients *gameclients = NULL;
3.92 -IMetamodSourceProvider *provider = &g_Ep1Provider;
3.93 -ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
3.94 -
3.95 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.96 -SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
3.97 -#else
3.98 -SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
3.99 -#endif
3.100 -
3.101 -bool AssumeUserMessages()
3.102 -{
3.103 - int q, size;
3.104 - char buffer[256];
3.105 -
3.106 - q = 0;
3.107 -
3.108 - while (server->GetUserMessageInfo(q, buffer, sizeof(buffer), size))
3.109 - {
3.110 - usermsgs_list.push_back(UsrMsgInfo(size, buffer));
3.111 - q++;
3.112 - }
3.113 -
3.114 - return true;
3.115 -}
3.116 -
3.117 -void BaseProvider::ConsolePrint(const char *str)
3.118 -{
3.119 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.120 - ConMsg("%s", str);
3.121 -#else
3.122 - Msg("%s", str);
3.123 -#endif
3.124 -}
3.125 -
3.126 -void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory,
3.127 - CreateInterfaceFn serverFactory)
3.128 -{
3.129 - engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
3.130 - if (!engine)
3.131 - {
3.132 - DisplayError("Could not find IVEngineServer! Metamod cannot load.");
3.133 - return;
3.134 - }
3.135 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.136 - icvar = (ICvar *)((engineFactory)(CVAR_INTERFACE_VERSION, NULL));
3.137 -#else
3.138 - icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL));
3.139 -#endif
3.140 - if (!icvar)
3.141 - {
3.142 - DisplayError("Could not find ICvar! Metamod cannot load.");
3.143 - return;
3.144 - }
3.145 -
3.146 -
3.147 - if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL)))
3.148 - == NULL)
3.149 - {
3.150 - gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
3.151 - }
3.152 -
3.153 - baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
3.154 - if (baseFs == NULL)
3.155 - {
3.156 - mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
3.157 - return;
3.158 - }
3.159 -
3.160 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.161 - g_pCVar = icvar;
3.162 -#endif
3.163 -
3.164 - g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd);
3.165 -
3.166 - if ((usermsgs_extracted = CacheUserMessages()) == false)
3.167 - {
3.168 - usermsgs_extracted = AssumeUserMessages();
3.169 - }
3.170 -
3.171 -#if SOURCE_ENGINE == SE_DARKMESSIAH
3.172 +/**
3.173 + * vim: set ts=4 :
3.174 + * ======================================================
3.175 + * Metamod:Source
3.176 + * Copyright (C) 2004-2008 AlliedModders LLC and authors.
3.177 + * All rights reserved.
3.178 + * ======================================================
3.179 + *
3.180 + * This software is provided 'as-is', without any express or implied warranty.
3.181 + * In no event will the authors be held liable for any damages arising from
3.182 + * the use of this software.
3.183 + *
3.184 + * Permission is granted to anyone to use this software for any purpose,
3.185 + * including commercial applications, and to alter it and redistribute it
3.186 + * freely, subject to the following restrictions:
3.187 + *
3.188 + * 1. The origin of this software must not be misrepresented; you must not
3.189 + * claim that you wrote the original software. If you use this software in a
3.190 + * product, an acknowledgment in the product documentation would be
3.191 + * appreciated but is not required.
3.192 + * 2. Altered source versions must be plainly marked as such, and must not be
3.193 + * misrepresented as being the original software.
3.194 + * 3. This notice may not be removed or altered from any source distribution.
3.195 + *
3.196 + * Version: $Id$
3.197 + */
3.198 +
3.199 +#include <stdio.h>
3.200 +#include "../metamod_oslink.h"
3.201 +#include <sourcehook.h>
3.202 +#include <convar.h>
3.203 +#include <eiface.h>
3.204 +#include <tier0/icommandline.h>
3.205 +#include <tier1/utldict.h>
3.206 +#include <sh_vector.h>
3.207 +#include <sh_string.h>
3.208 +#include "../metamod_util.h"
3.209 +#include "provider_ep2.h"
3.210 +#include "console.h"
3.211 +#include "metamod_console.h"
3.212 +#include "vsp_listener.h"
3.213 +#include <filesystem.h>
3.214 +#include "metamod.h"
3.215 +
3.216 +/* Types */
3.217 +typedef void (*CONPRINTF_FUNC)(const char *, ...);
3.218 +struct UsrMsgInfo
3.219 +{
3.220 + UsrMsgInfo()
3.221 + {
3.222 + }
3.223 + UsrMsgInfo(int s, const char *t) : size(s), name(t)
3.224 + {
3.225 + }
3.226 + int size;
3.227 + String name;
3.228 +};
3.229 +
3.230 +/* Imports */
3.231 +#if SOURCE_ENGINE == SE_DARKMESSIAH
3.232 +#undef CommandLine
3.233 +DLL_IMPORT ICommandLine *CommandLine();
3.234 +#endif
3.235 +
3.236 +/* Functions */
3.237 +bool CacheUserMessages();
3.238 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.239 +void ClientCommand(edict_t *pEdict, const CCommand &args);
3.240 +void LocalCommand_Meta(const CCommand &args);
3.241 +#else
3.242 +void ClientCommand(edict_t *pEdict);
3.243 +void LocalCommand_Meta();
3.244 +#endif
3.245 +
3.246 +void _ServerCommand();
3.247 +/* Variables */
3.248 +static bool usermsgs_extracted = false;
3.249 +static CVector<UsrMsgInfo> usermsgs_list;
3.250 +static VSPListener g_VspListener;
3.251 +static BaseProvider g_Ep1Provider;
3.252 +static List<ConCommandBase *> conbases_unreg;
3.253 +
3.254 +ICvar *icvar = NULL;
3.255 +IFileSystem *baseFs = NULL;
3.256 +IServerGameDLL *server = NULL;
3.257 +IVEngineServer *engine = NULL;
3.258 +IServerGameClients *gameclients = NULL;
3.259 +IMetamodSourceProvider *provider = &g_Ep1Provider;
3.260 +ConCommand meta_local_cmd("meta", LocalCommand_Meta, "Metamod:Source control options");
3.261 +
3.262 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.263 +SH_DECL_HOOK2_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *, const CCommand &);
3.264 +#else
3.265 +SH_DECL_HOOK1_void(IServerGameClients, ClientCommand, SH_NOATTRIB, 0, edict_t *);
3.266 +#endif
3.267 +
3.268 +bool AssumeUserMessages()
3.269 +{
3.270 + int q, size;
3.271 + char buffer[256];
3.272 +
3.273 + q = 0;
3.274 +
3.275 + while (server->GetUserMessageInfo(q, buffer, sizeof(buffer), size))
3.276 + {
3.277 + usermsgs_list.push_back(UsrMsgInfo(size, buffer));
3.278 + q++;
3.279 + }
3.280 +
3.281 + return true;
3.282 +}
3.283 +
3.284 +void BaseProvider::ConsolePrint(const char *str)
3.285 +{
3.286 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.287 + ConMsg("%s", str);
3.288 +#else
3.289 + Msg("%s", str);
3.290 +#endif
3.291 +}
3.292 +
3.293 +void BaseProvider::Notify_DLLInit_Pre(CreateInterfaceFn engineFactory,
3.294 + CreateInterfaceFn serverFactory)
3.295 +{
3.296 + engine = (IVEngineServer *)((engineFactory)(INTERFACEVERSION_VENGINESERVER, NULL));
3.297 + if (!engine)
3.298 + {
3.299 + DisplayError("Could not find IVEngineServer! Metamod cannot load.");
3.300 + return;
3.301 + }
3.302 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.303 + icvar = (ICvar *)((engineFactory)(CVAR_INTERFACE_VERSION, NULL));
3.304 +#else
3.305 + icvar = (ICvar *)((engineFactory)(VENGINE_CVAR_INTERFACE_VERSION, NULL));
3.306 +#endif
3.307 + if (!icvar)
3.308 + {
3.309 + DisplayError("Could not find ICvar! Metamod cannot load.");
3.310 + return;
3.311 + }
3.312 +
3.313 +
3.314 + if ((gameclients = (IServerGameClients *)(serverFactory("ServerGameClients003", NULL)))
3.315 + == NULL)
3.316 + {
3.317 + gameclients = (IServerGameClients *)(serverFactory("ServerGameClients004", NULL));
3.318 + }
3.319 +
3.320 + baseFs = (IFileSystem *)((engineFactory)(FILESYSTEM_INTERFACE_VERSION, NULL));
3.321 + if (baseFs == NULL)
3.322 + {
3.323 + mm_LogMessage("Unable to find \"%s\": .vdf files will not be parsed", FILESYSTEM_INTERFACE_VERSION);
3.324 + return;
3.325 + }
3.326 +
3.327 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.328 + g_pCVar = icvar;
3.329 +#endif
3.330 +
3.331 + g_SMConVarAccessor.RegisterConCommandBase(&meta_local_cmd);
3.332 +
3.333 + if ((usermsgs_extracted = CacheUserMessages()) == false)
3.334 + {
3.335 + usermsgs_extracted = AssumeUserMessages();
3.336 + }
3.337 +
3.338 +#if SOURCE_ENGINE == SE_DARKMESSIAH
3.339 if (!g_SMConVarAccessor.InitConCommandBaseList())
3.340 {
3.341 /* This is very unlikely considering it's old engine */
3.342 mm_LogMessage("[META] Warning: Failed to find ConCommandBase list!");
3.343 mm_LogMessage("[META] Warning: ConVars and ConCommands cannot be unregistered properly! Please file a bug report.");
3.344 - }
3.345 -#endif
3.346 -
3.347 - if (gameclients)
3.348 - {
3.349 - SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, false);
3.350 - }
3.351 -}
3.352 -
3.353 -void BaseProvider::Notify_DLLShutdown_Pre()
3.354 -{
3.355 - g_SMConVarAccessor.RemoveMetamodCommands();
3.356 -
3.357 -#if SOURCE_ENGINE == SE_DARKMESSIAH
3.358 - if (g_Metamod.IsLoadedAsGameDLL())
3.359 - {
3.360 - icvar->UnlinkVariables(FCVAR_GAMEDLL);
3.361 - }
3.362 -#endif
3.363 -}
3.364 -
3.365 -bool BaseProvider::IsRemotePrintingAvailable()
3.366 -{
3.367 - return true;
3.368 -}
3.369 -
3.370 -void BaseProvider::ClientConsolePrint(edict_t *client, const char *message)
3.371 -{
3.372 - engine->ClientPrintf(client, message);
3.373 -}
3.374 -
3.375 -void BaseProvider::ServerCommand(const char *cmd)
3.376 -{
3.377 - engine->ServerCommand(cmd);
3.378 -}
3.379 -
3.380 -const char *BaseProvider::GetConVarString(ConVar *convar)
3.381 -{
3.382 - if (convar == NULL)
3.383 - {
3.384 - return NULL;
3.385 - }
3.386 -
3.387 - return convar->GetString();
3.388 -}
3.389 -
3.390 -void BaseProvider::SetConVarString(ConVar *convar, const char *str)
3.391 -{
3.392 - convar->SetValue(str);
3.393 -}
3.394 -
3.395 -bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
3.396 -{
3.397 - return pCommand->IsCommand();
3.398 -}
3.399 -
3.400 -
3.401 -bool BaseProvider::IsSourceEngineBuildCompatible(int build)
3.402 -{
3.403 - return (build == SOURCE_ENGINE_ORIGINAL
3.404 - || build == SOURCE_ENGINE_EPISODEONE);
3.405 -}
3.406 -
3.407 -const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval)
3.408 -{
3.409 - if (key[0] == '-' || key[0] == '+')
3.410 - {
3.411 - return CommandLine()->ParmValue(key, defval);
3.412 - }
3.413 - else if (icvar)
3.414 - {
3.415 - const char *val;
3.416 - if ((val = icvar->GetCommandLineValue(key)) == NULL)
3.417 - {
3.418 - return defval;
3.419 - }
3.420 -
3.421 - return val;
3.422 - }
3.423 -
3.424 - return NULL;
3.425 -}
3.426 -
3.427 -int BaseProvider::TryServerGameDLL(const char *iface)
3.428 -{
3.429 - if (strncmp(iface, "ServerGameDLL", 13) != 0)
3.430 - {
3.431 - return 0;
3.432 - }
3.433 -
3.434 - return atoi(&iface[13]);
3.435 -}
3.436 -
3.437 -bool BaseProvider::LogMessage(const char *buffer)
3.438 -{
3.439 - if (!engine)
3.440 - {
3.441 - return false;
3.442 - }
3.443 -
3.444 - engine->LogPrint(buffer);
3.445 -
3.446 - return true;
3.447 -}
3.448 -
3.449 -bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo)
3.450 -{
3.451 - SourceHook::MemFuncInfo mfi = {true, -1, 0, 0};
3.452 -
3.453 - if (hook == ProvidedHook_LevelInit)
3.454 - {
3.455 - SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi);
3.456 - }
3.457 - else if (hook == ProvidedHook_LevelShutdown)
3.458 - {
3.459 - SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi);
3.460 - }
3.461 - else if (hook == ProvidedHook_GameInit)
3.462 - {
3.463 - SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi);
3.464 - }
3.465 -
3.466 - *pInfo = mfi;
3.467 -
3.468 - return (mfi.thisptroffs >= 0);
3.469 -}
3.470 -
3.471 -void BaseProvider::DisplayError(const char *fmt, ...)
3.472 -{
3.473 - va_list ap;
3.474 - char buffer[2048];
3.475 -
3.476 - va_start(ap, fmt);
3.477 - UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
3.478 - va_end(ap);
3.479 -
3.480 - Error(buffer);
3.481 -}
3.482 -
3.483 -void BaseProvider::DisplayWarning(const char *fmt, ...)
3.484 -{
3.485 - va_list ap;
3.486 - char buffer[2048];
3.487 -
3.488 - va_start(ap, fmt);
3.489 - UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
3.490 - va_end(ap);
3.491 -
3.492 - Warning(buffer);
3.493 -}
3.494 -
3.495 -IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor()
3.496 -{
3.497 - return &g_SMConVarAccessor;
3.498 -}
3.499 -
3.500 -bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand)
3.501 -{
3.502 - return g_SMConVarAccessor.Register(pCommand);
3.503 -}
3.504 -
3.505 -void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand)
3.506 -{
3.507 - return g_SMConVarAccessor.Unregister(pCommand);
3.508 -}
3.509 -
3.510 -int BaseProvider::GetUserMessageCount()
3.511 -{
3.512 - if (!usermsgs_extracted)
3.513 - {
3.514 - return -1;
3.515 - }
3.516 -
3.517 - return (int)usermsgs_list.size();
3.518 -}
3.519 -
3.520 -int BaseProvider::FindUserMessage(const char *name, int *size)
3.521 -{
3.522 - for (size_t i = 0; i < usermsgs_list.size(); i++)
3.523 - {
3.524 - if (usermsgs_list[i].name.compare(name) == 0)
3.525 - {
3.526 - if (size)
3.527 - {
3.528 - *size = usermsgs_list[i].size;
3.529 - }
3.530 - return (int)i;
3.531 - }
3.532 - }
3.533 -
3.534 - return -1;
3.535 -}
3.536 -
3.537 -const char *BaseProvider::GetUserMessage(int index, int *size)
3.538 -{
3.539 - if (!usermsgs_extracted || index < 0 || index >= (int)usermsgs_list.size())
3.540 - {
3.541 - return NULL;
3.542 - }
3.543 -
3.544 - if (size)
3.545 - {
3.546 - *size = usermsgs_list[index].size;
3.547 - }
3.548 -
3.549 - return usermsgs_list[index].name.c_str();
3.550 -}
3.551 -
3.552 -const char *BaseProvider::GetGameDescription()
3.553 -{
3.554 - return server->GetGameDescription();
3.555 -}
3.556 -
3.557 -int BaseProvider::DetermineSourceEngine(const char *game)
3.558 -{
3.559 -#if SOURCE_ENGINE == SE_LEFT4DEAD
3.560 - return SOURCE_ENGINE_LEFT4DEAD;
3.561 -#elif SOURCE_ENGINE == SE_ORANGEBOX
3.562 - return SOURCE_ENGINE_ORANGEBOX;
3.563 -#else
3.564 - return SOURCE_ENGINE_DARKMESSIAH;
3.565 -#endif
3.566 -}
3.567 -
3.568 -ConVar *BaseProvider::CreateConVar(const char *name,
3.569 - const char *defval,
3.570 - const char *help,
3.571 - int flags)
3.572 -{
3.573 - int newflags = 0;
3.574 - if (flags & ConVarFlag_Notify)
3.575 - {
3.576 - newflags |= FCVAR_NOTIFY;
3.577 - }
3.578 - if (flags & ConVarFlag_SpOnly)
3.579 - {
3.580 - newflags |= FCVAR_SPONLY;
3.581 - }
3.582 -
3.583 - ConVar *pVar = new ConVar(name, defval, newflags, help);
3.584 -
3.585 - g_SMConVarAccessor.RegisterConCommandBase(pVar);
3.586 -
3.587 - return pVar;
3.588 -}
3.589 -
3.590 -IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version)
3.591 -{
3.592 - if (version > 2)
3.593 - {
3.594 - return NULL;
3.595 - }
3.596 -
3.597 - g_VspListener.SetLoadable(true);
3.598 - return &g_VspListener;
3.599 -}
3.600 -
3.601 -bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
3.602 -{
3.603 - if (baseFs == NULL)
3.604 - {
3.605 - return false;
3.606 - }
3.607 -
3.608 - KeyValues *pValues;
3.609 - const char *plugin_file, *p_alias;
3.610 -
3.611 - pValues = new KeyValues("Metamod Plugin");
3.612 -
3.613 - if (!pValues->LoadFromFile(baseFs, file))
3.614 - {
3.615 - pValues->deleteThis();
3.616 - return false;
3.617 - }
3.618 -
3.619 - if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
3.620 - {
3.621 - pValues->deleteThis();
3.622 - return false;
3.623 - }
3.624 -
3.625 - UTIL_Format(path, path_len, "%s", plugin_file);
3.626 -
3.627 - if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
3.628 - {
3.629 - UTIL_Format(alias, alias_len, "%s", p_alias);
3.630 - }
3.631 - else
3.632 - {
3.633 - UTIL_Format(alias, alias_len, "");
3.634 - }
3.635 -
3.636 - pValues->deleteThis();
3.637 -
3.638 - return true;
3.639 -}
3.640 -
3.641 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.642 -class GlobCommand : public IMetamodSourceCommandInfo
3.643 -{
3.644 -public:
3.645 - GlobCommand(const CCommand *cmd) : m_cmd(cmd)
3.646 - {
3.647 - }
3.648 -public:
3.649 - unsigned int GetArgCount()
3.650 - {
3.651 - return m_cmd->ArgC() - 1;
3.652 - }
3.653 -
3.654 - const char *GetArg(unsigned int num)
3.655 - {
3.656 - return m_cmd->Arg(num);
3.657 - }
3.658 -
3.659 - const char *GetArgString()
3.660 - {
3.661 - return m_cmd->ArgS();
3.662 - }
3.663 -private:
3.664 - const CCommand *m_cmd;
3.665 -};
3.666 -#else
3.667 -class GlobCommand : public IMetamodSourceCommandInfo
3.668 -{
3.669 -public:
3.670 - unsigned int GetArgCount()
3.671 - {
3.672 - return engine->Cmd_Argc() - 1;
3.673 - }
3.674 -
3.675 - const char *GetArg(unsigned int num)
3.676 - {
3.677 - return engine->Cmd_Argv(num);
3.678 - }
3.679 -
3.680 - const char *GetArgString()
3.681 - {
3.682 - return engine->Cmd_Args();
3.683 - }
3.684 -};
3.685 -#endif
3.686 -
3.687 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.688 -void LocalCommand_Meta(const CCommand &args)
3.689 -{
3.690 - GlobCommand cmd(&args);
3.691 -#else
3.692 -void LocalCommand_Meta()
3.693 -{
3.694 - GlobCommand cmd;
3.695 -#endif
3.696 - Command_Meta(&cmd);
3.697 -}
3.698 -
3.699 -#if SOURCE_ENGINE >= SE_ORANGEBOX
3.700 -void ClientCommand(edict_t *pEdict, const CCommand &_cmd)
3.701 -{
3.702 - GlobCommand cmd(&_cmd);
3.703 -#else
3.704 -void ClientCommand(edict_t *pEdict)
3.705 -{
3.706 - GlobCommand cmd;
3.707 -#endif
3.708 - if (strcmp(cmd.GetArg(0), "meta") == 0)
3.709 - {
3.710 - Command_ClientMeta(pEdict, &cmd);
3.711 - RETURN_META(MRES_SUPERCEDE);
3.712 - }
3.713 -
3.714 - RETURN_META(MRES_IGNORED);
3.715 -}
3.716 -
3.717 -//////////////////////////////////////////////////////////////////////
3.718 -// EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED! //
3.719 -// Signatures necessary in finding the pointer to the CUtlDict that //
3.720 -// stores user message information. //
3.721 -// IServerGameDLL::GetUserMessageInfo() normally crashes with bad //
3.722 -// message indices. This is our answer to it. Yuck! <:-( //
3.723 -//////////////////////////////////////////////////////////////////////
3.724 -#ifdef OS_WIN32
3.725 - /* General Windows sig */
3.726 - #define MSGCLASS_SIGLEN 7
3.727 - #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
3.728 - #define MSGCLASS_OFFS 2
3.729 -
3.730 - /* Dystopia Windows hack */
3.731 - #define MSGCLASS2_SIGLEN 16
3.732 - #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
3.733 - #define MSGCLASS2_OFFS 11
3.734 -
3.735 - /* Windows frame pointer sig */
3.736 - #define MSGCLASS3_SIGLEN 18
3.737 - #define MSGCLASS3_SIG "\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
3.738 - #define MSGCLASS3_OFFS 13
3.739 -#elif defined OS_LINUX
3.740 - /* No frame pointer sig */
3.741 - #define MSGCLASS_SIGLEN 14
3.742 - #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
3.743 - #define MSGCLASS_OFFS 9
3.744 -
3.745 - /* Frame pointer sig */
3.746 - #define MSGCLASS2_SIGLEN 16
3.747 - #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
3.748 - #define MSGCLASS2_OFFS 11
3.749 -#endif
3.750 -
3.751 -struct UserMessage
3.752 -{
3.753 - int size;
3.754 - const char *name;
3.755 -};
3.756 -
3.757 -typedef CUtlDict<UserMessage *, int> UserMsgDict;
3.758 -
3.759 -/* This is the ugliest function in all of MM:S */
3.760 -bool CacheUserMessages()
3.761 -{
3.762 - UserMsgDict *dict = NULL;
3.763 -
3.764 - /* Get address of original GetUserMessageInfo() */
3.765 - char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo);
3.766 -
3.767 - /* Oh dear, we have a relative jump on our hands
3.768 - * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
3.769 - */
3.770 - if (*vfunc == '\xE9')
3.771 - {
3.772 - /* Get address from displacement...
3.773 - *
3.774 - * Add 5 because it's relative to next instruction:
3.775 - * Opcode <1 byte> + 32-bit displacement <4 bytes>
3.776 - */
3.777 - vfunc += *reinterpret_cast<int *>(vfunc + 1) + 5;
3.778 - }
3.779 -
3.780 - if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
3.781 - {
3.782 - /* Get address of CUserMessages instance */
3.783 - char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
3.784 -
3.785 - /* Get address of CUserMessages::m_UserMessages */
3.786 - dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.787 - }
3.788 - else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN))
3.789 - {
3.790 - #ifdef OS_WIN32
3.791 - /* If we get here, the code is possibly inlined like in Dystopia */
3.792 -
3.793 - /* Get the address of the CUtlRBTree */
3.794 - char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
3.795 -
3.796 - /* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
3.797 - dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
3.798 - #elif defined OS_LINUX
3.799 - /* Get address of CUserMessages instance */
3.800 - char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
3.801 -
3.802 - /* Get address of CUserMessages::m_UserMessages */
3.803 - dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.804 - #endif
3.805 - #ifdef OS_WIN32
3.806 - }
3.807 - else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN))
3.808 - {
3.809 - /* Get address of CUserMessages instance */
3.810 - char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
3.811 -
3.812 - /* Get address of CUserMessages::m_UserMessages */
3.813 - dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.814 - #endif
3.815 - }
3.816 -
3.817 - #if !defined OS_WIN32
3.818 - if (dict == NULL)
3.819 - {
3.820 - char path[255];
3.821 - if (GetFileOfAddress(vfunc, path, sizeof(path)))
3.822 - {
3.823 - void *handle = dlopen(path, RTLD_NOW);
3.824 - if (handle != NULL)
3.825 - {
3.826 - void *addr = dlsym(handle, "usermessages");
3.827 - if (addr == NULL)
3.828 - {
3.829 - return false;
3.830 - }
3.831 - dict = (UserMsgDict *)*(void **)addr;
3.832 - dlclose(handle);
3.833 - }
3.834 - }
3.835 - }
3.836 - #endif
3.837 -
3.838 - if (dict != NULL)
3.839 - {
3.840 - int msg_count = dict->Count();
3.841 -
3.842 - /* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
3.843 - if (msg_count < 0 || msg_count > 255)
3.844 - {
3.845 - return false;
3.846 - }
3.847 -
3.848 - UserMessage *msg;
3.849 - UsrMsgInfo u_msg;
3.850 -
3.851 - /* Cache messages in our CUtlDict */
3.852 - for (int i = 0; i < msg_count; i++)
3.853 - {
3.854 - msg = dict->Element(i);
3.855 - u_msg.name = msg->name;
3.856 - u_msg.size = msg->size;
3.857 - usermsgs_list.push_back(u_msg);
3.858 - }
3.859 -
3.860 - return true;
3.861 - }
3.862 -
3.863 - return false;
3.864 -}
3.865 -
3.866 + }
3.867 +#endif
3.868 +
3.869 + if (gameclients)
3.870 + {
3.871 + SH_ADD_HOOK_STATICFUNC(IServerGameClients, ClientCommand, gameclients, ClientCommand, false);
3.872 + }
3.873 +}
3.874 +
3.875 +void BaseProvider::Notify_DLLShutdown_Pre()
3.876 +{
3.877 + g_SMConVarAccessor.RemoveMetamodCommands();
3.878 +
3.879 +#if SOURCE_ENGINE == SE_DARKMESSIAH
3.880 + if (g_Metamod.IsLoadedAsGameDLL())
3.881 + {
3.882 + icvar->UnlinkVariables(FCVAR_GAMEDLL);
3.883 + }
3.884 +#endif
3.885 +}
3.886 +
3.887 +bool BaseProvider::IsRemotePrintingAvailable()
3.888 +{
3.889 + return true;
3.890 +}
3.891 +
3.892 +void BaseProvider::ClientConsolePrint(edict_t *client, const char *message)
3.893 +{
3.894 + engine->ClientPrintf(client, message);
3.895 +}
3.896 +
3.897 +void BaseProvider::ServerCommand(const char *cmd)
3.898 +{
3.899 + engine->ServerCommand(cmd);
3.900 +}
3.901 +
3.902 +const char *BaseProvider::GetConVarString(ConVar *convar)
3.903 +{
3.904 + if (convar == NULL)
3.905 + {
3.906 + return NULL;
3.907 + }
3.908 +
3.909 + return convar->GetString();
3.910 +}
3.911 +
3.912 +void BaseProvider::SetConVarString(ConVar *convar, const char *str)
3.913 +{
3.914 + convar->SetValue(str);
3.915 +}
3.916 +
3.917 +bool BaseProvider::IsConCommandBaseACommand(ConCommandBase *pCommand)
3.918 +{
3.919 + return pCommand->IsCommand();
3.920 +}
3.921 +
3.922 +
3.923 +bool BaseProvider::IsSourceEngineBuildCompatible(int build)
3.924 +{
3.925 + return (build == SOURCE_ENGINE_ORIGINAL
3.926 + || build == SOURCE_ENGINE_EPISODEONE);
3.927 +}
3.928 +
3.929 +const char *BaseProvider::GetCommandLineValue(const char *key, const char *defval)
3.930 +{
3.931 + if (key[0] == '-' || key[0] == '+')
3.932 + {
3.933 + return CommandLine()->ParmValue(key, defval);
3.934 + }
3.935 + else if (icvar)
3.936 + {
3.937 + const char *val;
3.938 + if ((val = icvar->GetCommandLineValue(key)) == NULL)
3.939 + {
3.940 + return defval;
3.941 + }
3.942 +
3.943 + return val;
3.944 + }
3.945 +
3.946 + return NULL;
3.947 +}
3.948 +
3.949 +int BaseProvider::TryServerGameDLL(const char *iface)
3.950 +{
3.951 + if (strncmp(iface, "ServerGameDLL", 13) != 0)
3.952 + {
3.953 + return 0;
3.954 + }
3.955 +
3.956 + return atoi(&iface[13]);
3.957 +}
3.958 +
3.959 +bool BaseProvider::LogMessage(const char *buffer)
3.960 +{
3.961 + if (!engine)
3.962 + {
3.963 + return false;
3.964 + }
3.965 +
3.966 + engine->LogPrint(buffer);
3.967 +
3.968 + return true;
3.969 +}
3.970 +
3.971 +bool BaseProvider::GetHookInfo(ProvidedHooks hook, SourceHook::MemFuncInfo *pInfo)
3.972 +{
3.973 + SourceHook::MemFuncInfo mfi = {true, -1, 0, 0};
3.974 +
3.975 + if (hook == ProvidedHook_LevelInit)
3.976 + {
3.977 + SourceHook::GetFuncInfo(&IServerGameDLL::LevelInit, mfi);
3.978 + }
3.979 + else if (hook == ProvidedHook_LevelShutdown)
3.980 + {
3.981 + SourceHook::GetFuncInfo(&IServerGameDLL::LevelShutdown, mfi);
3.982 + }
3.983 + else if (hook == ProvidedHook_GameInit)
3.984 + {
3.985 + SourceHook::GetFuncInfo(&IServerGameDLL::GameInit, mfi);
3.986 + }
3.987 +
3.988 + *pInfo = mfi;
3.989 +
3.990 + return (mfi.thisptroffs >= 0);
3.991 +}
3.992 +
3.993 +void BaseProvider::DisplayError(const char *fmt, ...)
3.994 +{
3.995 + va_list ap;
3.996 + char buffer[2048];
3.997 +
3.998 + va_start(ap, fmt);
3.999 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
3.1000 + va_end(ap);
3.1001 +
3.1002 + Error(buffer);
3.1003 +}
3.1004 +
3.1005 +void BaseProvider::DisplayWarning(const char *fmt, ...)
3.1006 +{
3.1007 + va_list ap;
3.1008 + char buffer[2048];
3.1009 +
3.1010 + va_start(ap, fmt);
3.1011 + UTIL_FormatArgs(buffer, sizeof(buffer), fmt, ap);
3.1012 + va_end(ap);
3.1013 +
3.1014 + Warning(buffer);
3.1015 +}
3.1016 +
3.1017 +IConCommandBaseAccessor *BaseProvider::GetConCommandBaseAccessor()
3.1018 +{
3.1019 + return &g_SMConVarAccessor;
3.1020 +}
3.1021 +
3.1022 +bool BaseProvider::RegisterConCommandBase(ConCommandBase *pCommand)
3.1023 +{
3.1024 + return g_SMConVarAccessor.Register(pCommand);
3.1025 +}
3.1026 +
3.1027 +void BaseProvider::UnregisterConCommandBase(ConCommandBase *pCommand)
3.1028 +{
3.1029 + return g_SMConVarAccessor.Unregister(pCommand);
3.1030 +}
3.1031 +
3.1032 +int BaseProvider::GetUserMessageCount()
3.1033 +{
3.1034 + if (!usermsgs_extracted)
3.1035 + {
3.1036 + return -1;
3.1037 + }
3.1038 +
3.1039 + return (int)usermsgs_list.size();
3.1040 +}
3.1041 +
3.1042 +int BaseProvider::FindUserMessage(const char *name, int *size)
3.1043 +{
3.1044 + for (size_t i = 0; i < usermsgs_list.size(); i++)
3.1045 + {
3.1046 + if (usermsgs_list[i].name.compare(name) == 0)
3.1047 + {
3.1048 + if (size)
3.1049 + {
3.1050 + *size = usermsgs_list[i].size;
3.1051 + }
3.1052 + return (int)i;
3.1053 + }
3.1054 + }
3.1055 +
3.1056 + return -1;
3.1057 +}
3.1058 +
3.1059 +const char *BaseProvider::GetUserMessage(int index, int *size)
3.1060 +{
3.1061 + if (!usermsgs_extracted || index < 0 || index >= (int)usermsgs_list.size())
3.1062 + {
3.1063 + return NULL;
3.1064 + }
3.1065 +
3.1066 + if (size)
3.1067 + {
3.1068 + *size = usermsgs_list[index].size;
3.1069 + }
3.1070 +
3.1071 + return usermsgs_list[index].name.c_str();
3.1072 +}
3.1073 +
3.1074 +const char *BaseProvider::GetGameDescription()
3.1075 +{
3.1076 + return server->GetGameDescription();
3.1077 +}
3.1078 +
3.1079 +int BaseProvider::DetermineSourceEngine(const char *game)
3.1080 +{
3.1081 +#if SOURCE_ENGINE == SE_LEFT4DEAD
3.1082 + return SOURCE_ENGINE_LEFT4DEAD;
3.1083 +#elif SOURCE_ENGINE == SE_ORANGEBOX
3.1084 + return SOURCE_ENGINE_ORANGEBOX;
3.1085 +#else
3.1086 + return SOURCE_ENGINE_DARKMESSIAH;
3.1087 +#endif
3.1088 +}
3.1089 +
3.1090 +ConVar *BaseProvider::CreateConVar(const char *name,
3.1091 + const char *defval,
3.1092 + const char *help,
3.1093 + int flags)
3.1094 +{
3.1095 + int newflags = 0;
3.1096 + if (flags & ConVarFlag_Notify)
3.1097 + {
3.1098 + newflags |= FCVAR_NOTIFY;
3.1099 + }
3.1100 + if (flags & ConVarFlag_SpOnly)
3.1101 + {
3.1102 + newflags |= FCVAR_SPONLY;
3.1103 + }
3.1104 +
3.1105 + ConVar *pVar = new ConVar(name, defval, newflags, help);
3.1106 +
3.1107 + g_SMConVarAccessor.RegisterConCommandBase(pVar);
3.1108 +
3.1109 + return pVar;
3.1110 +}
3.1111 +
3.1112 +IServerPluginCallbacks *BaseProvider::GetVSPCallbacks(int version)
3.1113 +{
3.1114 + if (version > 2)
3.1115 + {
3.1116 + return NULL;
3.1117 + }
3.1118 +
3.1119 + g_VspListener.SetLoadable(true);
3.1120 + return &g_VspListener;
3.1121 +}
3.1122 +
3.1123 +bool BaseProvider::ProcessVDF(const char *file, char path[], size_t path_len, char alias[], size_t alias_len)
3.1124 +{
3.1125 + if (baseFs == NULL)
3.1126 + {
3.1127 + return false;
3.1128 + }
3.1129 +
3.1130 + KeyValues *pValues;
3.1131 + const char *plugin_file, *p_alias;
3.1132 +
3.1133 + pValues = new KeyValues("Metamod Plugin");
3.1134 +
3.1135 + if (!pValues->LoadFromFile(baseFs, file))
3.1136 + {
3.1137 + pValues->deleteThis();
3.1138 + return false;
3.1139 + }
3.1140 +
3.1141 + if ((plugin_file = pValues->GetString("file", NULL)) == NULL)
3.1142 + {
3.1143 + pValues->deleteThis();
3.1144 + return false;
3.1145 + }
3.1146 +
3.1147 + UTIL_Format(path, path_len, "%s", plugin_file);
3.1148 +
3.1149 + if ((p_alias = pValues->GetString("alias", NULL)) != NULL)
3.1150 + {
3.1151 + UTIL_Format(alias, alias_len, "%s", p_alias);
3.1152 + }
3.1153 + else
3.1154 + {
3.1155 + UTIL_Format(alias, alias_len, "");
3.1156 + }
3.1157 +
3.1158 + pValues->deleteThis();
3.1159 +
3.1160 + return true;
3.1161 +}
3.1162 +
3.1163 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.1164 +class GlobCommand : public IMetamodSourceCommandInfo
3.1165 +{
3.1166 +public:
3.1167 + GlobCommand(const CCommand *cmd) : m_cmd(cmd)
3.1168 + {
3.1169 + }
3.1170 +public:
3.1171 + unsigned int GetArgCount()
3.1172 + {
3.1173 + return m_cmd->ArgC() - 1;
3.1174 + }
3.1175 +
3.1176 + const char *GetArg(unsigned int num)
3.1177 + {
3.1178 + return m_cmd->Arg(num);
3.1179 + }
3.1180 +
3.1181 + const char *GetArgString()
3.1182 + {
3.1183 + return m_cmd->ArgS();
3.1184 + }
3.1185 +private:
3.1186 + const CCommand *m_cmd;
3.1187 +};
3.1188 +#else
3.1189 +class GlobCommand : public IMetamodSourceCommandInfo
3.1190 +{
3.1191 +public:
3.1192 + unsigned int GetArgCount()
3.1193 + {
3.1194 + return engine->Cmd_Argc() - 1;
3.1195 + }
3.1196 +
3.1197 + const char *GetArg(unsigned int num)
3.1198 + {
3.1199 + return engine->Cmd_Argv(num);
3.1200 + }
3.1201 +
3.1202 + const char *GetArgString()
3.1203 + {
3.1204 + return engine->Cmd_Args();
3.1205 + }
3.1206 +};
3.1207 +#endif
3.1208 +
3.1209 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.1210 +void LocalCommand_Meta(const CCommand &args)
3.1211 +{
3.1212 + GlobCommand cmd(&args);
3.1213 +#else
3.1214 +void LocalCommand_Meta()
3.1215 +{
3.1216 + GlobCommand cmd;
3.1217 +#endif
3.1218 + Command_Meta(&cmd);
3.1219 +}
3.1220 +
3.1221 +#if SOURCE_ENGINE >= SE_ORANGEBOX
3.1222 +void ClientCommand(edict_t *pEdict, const CCommand &_cmd)
3.1223 +{
3.1224 + GlobCommand cmd(&_cmd);
3.1225 +#else
3.1226 +void ClientCommand(edict_t *pEdict)
3.1227 +{
3.1228 + GlobCommand cmd;
3.1229 +#endif
3.1230 + if (strcmp(cmd.GetArg(0), "meta") == 0)
3.1231 + {
3.1232 + Command_ClientMeta(pEdict, &cmd);
3.1233 + RETURN_META(MRES_SUPERCEDE);
3.1234 + }
3.1235 +
3.1236 + RETURN_META(MRES_IGNORED);
3.1237 +}
3.1238 +
3.1239 +//////////////////////////////////////////////////////////////////////
3.1240 +// EVEN MORE HACKS HERE! YOU HAVE BEEN WARNED! //
3.1241 +// Signatures necessary in finding the pointer to the CUtlDict that //
3.1242 +// stores user message information. //
3.1243 +// IServerGameDLL::GetUserMessageInfo() normally crashes with bad //
3.1244 +// message indices. This is our answer to it. Yuck! <:-( //
3.1245 +//////////////////////////////////////////////////////////////////////
3.1246 +#ifdef OS_WIN32
3.1247 + /* General Windows sig */
3.1248 + #define MSGCLASS_SIGLEN 7
3.1249 + #define MSGCLASS_SIG "\x8B\x0D\x2A\x2A\x2A\x2A\x56"
3.1250 + #define MSGCLASS_OFFS 2
3.1251 +
3.1252 + /* Dystopia Windows hack */
3.1253 + #define MSGCLASS2_SIGLEN 16
3.1254 + #define MSGCLASS2_SIG "\x56\x8B\x74\x24\x2A\x85\xF6\x7C\x2A\x3B\x35\x2A\x2A\x2A\x2A\x7D"
3.1255 + #define MSGCLASS2_OFFS 11
3.1256 +
3.1257 + /* Windows frame pointer sig */
3.1258 + #define MSGCLASS3_SIGLEN 18
3.1259 + #define MSGCLASS3_SIG "\x55\x8B\xEC\x51\x89\x2A\x2A\x8B\x2A\x2A\x50\x8B\x0D\x2A\x2A\x2A\x2A\xE8"
3.1260 + #define MSGCLASS3_OFFS 13
3.1261 +#elif defined OS_LINUX
3.1262 + /* No frame pointer sig */
3.1263 + #define MSGCLASS_SIGLEN 14
3.1264 + #define MSGCLASS_SIG "\x53\x83\xEC\x2A\x8B\x2A\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
3.1265 + #define MSGCLASS_OFFS 9
3.1266 +
3.1267 + /* Frame pointer sig */
3.1268 + #define MSGCLASS2_SIGLEN 16
3.1269 + #define MSGCLASS2_SIG "\x55\x89\xE5\x53\x83\xEC\x2A\x8B\x2A\x2A\xA1\x2A\x2A\x2A\x2A\x89"
3.1270 + #define MSGCLASS2_OFFS 11
3.1271 +#endif
3.1272 +
3.1273 +struct UserMessage
3.1274 +{
3.1275 + int size;
3.1276 + const char *name;
3.1277 +};
3.1278 +
3.1279 +typedef CUtlDict<UserMessage *, int> UserMsgDict;
3.1280 +
3.1281 +/* This is the ugliest function in all of MM:S */
3.1282 +bool CacheUserMessages()
3.1283 +{
3.1284 + UserMsgDict *dict = NULL;
3.1285 +
3.1286 + /* Get address of original GetUserMessageInfo() */
3.1287 + char *vfunc = (char *)SH_GET_ORIG_VFNPTR_ENTRY(server, &IServerGameDLL::GetUserMessageInfo);
3.1288 +
3.1289 + /* Oh dear, we have a relative jump on our hands
3.1290 + * PVK II on Windows made me do this, but I suppose it doesn't hurt to check this on Linux too...
3.1291 + */
3.1292 + if (*vfunc == '\xE9')
3.1293 + {
3.1294 + /* Get address from displacement...
3.1295 + *
3.1296 + * Add 5 because it's relative to next instruction:
3.1297 + * Opcode <1 byte> + 32-bit displacement <4 bytes>
3.1298 + */
3.1299 + vfunc += *reinterpret_cast<int *>(vfunc + 1) + 5;
3.1300 + }
3.1301 +
3.1302 + if (UTIL_VerifySignature(vfunc, MSGCLASS_SIG, MSGCLASS_SIGLEN))
3.1303 + {
3.1304 + /* Get address of CUserMessages instance */
3.1305 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS_OFFS);
3.1306 +
3.1307 + /* Get address of CUserMessages::m_UserMessages */
3.1308 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.1309 + }
3.1310 + else if (UTIL_VerifySignature(vfunc, MSGCLASS2_SIG, MSGCLASS2_SIGLEN))
3.1311 + {
3.1312 + #ifdef OS_WIN32
3.1313 + /* If we get here, the code is possibly inlined like in Dystopia */
3.1314 +
3.1315 + /* Get the address of the CUtlRBTree */
3.1316 + char *rbtree = *reinterpret_cast<char **>(vfunc + MSGCLASS2_OFFS);
3.1317 +
3.1318 + /* CUtlDict should be 8 bytes before the CUtlRBTree (hacktacular!) */
3.1319 + dict = reinterpret_cast<UserMsgDict *>(rbtree - 8);
3.1320 + #elif defined OS_LINUX
3.1321 + /* Get address of CUserMessages instance */
3.1322 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS2_OFFS);
3.1323 +
3.1324 + /* Get address of CUserMessages::m_UserMessages */
3.1325 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.1326 + #endif
3.1327 + #ifdef OS_WIN32
3.1328 + }
3.1329 + else if (UTIL_VerifySignature(vfunc, MSGCLASS3_SIG, MSGCLASS3_SIGLEN))
3.1330 + {
3.1331 + /* Get address of CUserMessages instance */
3.1332 + char **userMsgClass = *reinterpret_cast<char ***>(vfunc + MSGCLASS3_OFFS);
3.1333 +
3.1334 + /* Get address of CUserMessages::m_UserMessages */
3.1335 + dict = reinterpret_cast<UserMsgDict *>(*userMsgClass);
3.1336 + #endif
3.1337 + }
3.1338 +
3.1339 + #if !defined OS_WIN32
3.1340 + if (dict == NULL)
3.1341 + {
3.1342 + char path[255];
3.1343 + if (GetFileOfAddress(vfunc, path, sizeof(path)))
3.1344 + {
3.1345 + void *handle = dlopen(path, RTLD_NOW);
3.1346 + if (handle != NULL)
3.1347 + {
3.1348 + void *addr = dlsym(handle, "usermessages");
3.1349 + if (addr == NULL)
3.1350 + {
3.1351 + return false;
3.1352 + }
3.1353 + dict = (UserMsgDict *)*(void **)addr;
3.1354 + dlclose(handle);
3.1355 + }
3.1356 + }
3.1357 + }
3.1358 + #endif
3.1359 +
3.1360 + if (dict != NULL)
3.1361 + {
3.1362 + int msg_count = dict->Count();
3.1363 +
3.1364 + /* Ensure that count is within bounds of an unsigned byte, because that's what engine supports */
3.1365 + if (msg_count < 0 || msg_count > 255)
3.1366 + {
3.1367 + return false;
3.1368 + }
3.1369 +
3.1370 + UserMessage *msg;
3.1371 + UsrMsgInfo u_msg;
3.1372 +
3.1373 + /* Cache messages in our CUtlDict */
3.1374 + for (int i = 0; i < msg_count; i++)
3.1375 + {
3.1376 + msg = dict->Element(i);
3.1377 + u_msg.name = msg->name;
3.1378 + u_msg.size = msg->size;
3.1379 + usermsgs_list.push_back(u_msg);
3.1380 + }
3.1381 +
3.1382 + return true;
3.1383 + }
3.1384 +
3.1385 + return false;
3.1386 +}
3.1387 +
4.1 --- a/core/sourcehook/sourcehook_impl_chookmaninfo.h Wed Oct 28 23:14:32 2009 -0700
4.2 +++ b/core/sourcehook/sourcehook_impl_chookmaninfo.h Wed Oct 28 23:15:26 2009 -0700
4.3 @@ -1,198 +1,198 @@
4.4 -/* ======== SourceHook ========
4.5 -* Copyright (C) 2004-2008 Metamod:Source Development Team
4.6 -* No warranties of any kind
4.7 -*
4.8 -* License: zlib/libpng
4.9 -*
4.10 -* Author(s): Pavol "PM OnoTo" Marko
4.11 -* ============================
4.12 -*/
4.13 -
4.14 -#ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
4.15 -#define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
4.16 -
4.17 -#include "sh_list.h"
4.18 -#include "sourcehook_impl_cproto.h"
4.19 -
4.20 -namespace SourceHook
4.21 -{
4.22 - namespace Impl
4.23 - {
4.24 - class CVfnPtr;
4.25 -
4.26 - class CHookManager : public IHookManagerInfo
4.27 - {
4.28 - // *** Data ***
4.29 - Plugin m_OwnerPlugin;
4.30 - HookManagerPubFunc m_PubFunc;
4.31 - int m_VtblOffs;
4.32 - int m_VtblIdx;
4.33 - CProto m_Proto;
4.34 - int m_Version;
4.35 -
4.36 - void *m_HookfuncVfnptr;
4.37 -
4.38 - List<CVfnPtr*> m_VfnPtrs;
4.39 - public:
4.40 - // *** Descriptor ***
4.41 - struct Descriptor
4.42 - {
4.43 - Plugin m_OwnerPlugin;
4.44 - HookManagerPubFunc m_PubFunc;
4.45 - Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
4.46 - : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
4.47 - {
4.48 - }
4.49 - };
4.50 -
4.51 - // *** Interface ***
4.52 - inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
4.53 -
4.54 - inline bool operator==(const Descriptor &other) const;
4.55 - inline bool operator==(const CHookManager &other) const;
4.56 -
4.57 - inline operator bool() const;
4.58 - inline Plugin GetOwnerPlugin() const;
4.59 - inline int GetVtblOffs() const;
4.60 - inline int GetVtblIdx() const;
4.61 - inline const CProto &GetProto() const;
4.62 - inline int GetVersion() const;
4.63 - inline void *GetHookFunc() const;
4.64 - inline HookManagerPubFunc GetPubFunc() const;
4.65 -
4.66 - inline void Register();
4.67 - inline void Unregister();
4.68 -
4.69 - inline void IncrRef(CVfnPtr *pVfnPtr);
4.70 - inline void DecrRef(CVfnPtr *pVfnPtr);
4.71 -
4.72 - List<CVfnPtr*> &GetVfnPtrList()
4.73 - {
4.74 - return m_VfnPtrs;
4.75 - }
4.76 -
4.77 - // *** IHookManagerInfo interface ***
4.78 +/* ======== SourceHook ========
4.79 +* Copyright (C) 2004-2008 Metamod:Source Development Team
4.80 +* No warranties of any kind
4.81 +*
4.82 +* License: zlib/libpng
4.83 +*
4.84 +* Author(s): Pavol "PM OnoTo" Marko
4.85 +* ============================
4.86 +*/
4.87 +
4.88 +#ifndef __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
4.89 +#define __SOURCEHOOK_IMPL_CHOOKMANINFO_H__
4.90 +
4.91 +#include "sh_list.h"
4.92 +#include "sourcehook_impl_cproto.h"
4.93 +
4.94 +namespace SourceHook
4.95 +{
4.96 + namespace Impl
4.97 + {
4.98 + class CVfnPtr;
4.99 +
4.100 + class CHookManager : public IHookManagerInfo
4.101 + {
4.102 + // *** Data ***
4.103 + Plugin m_OwnerPlugin;
4.104 + HookManagerPubFunc m_PubFunc;
4.105 + int m_VtblOffs;
4.106 + int m_VtblIdx;
4.107 + CProto m_Proto;
4.108 + int m_Version;
4.109 +
4.110 + void *m_HookfuncVfnptr;
4.111 +
4.112 + List<CVfnPtr*> m_VfnPtrs;
4.113 + public:
4.114 + // *** Descriptor ***
4.115 + struct Descriptor
4.116 + {
4.117 + Plugin m_OwnerPlugin;
4.118 + HookManagerPubFunc m_PubFunc;
4.119 + Descriptor(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
4.120 + : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc)
4.121 + {
4.122 + }
4.123 + };
4.124 +
4.125 + // *** Interface ***
4.126 + inline CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc);
4.127 +
4.128 + inline bool operator==(const Descriptor &other) const;
4.129 + inline bool operator==(const CHookManager &other) const;
4.130 +
4.131 + inline operator bool() const;
4.132 + inline Plugin GetOwnerPlugin() const;
4.133 + inline int GetVtblOffs() const;
4.134 + inline int GetVtblIdx() const;
4.135 + inline const CProto &GetProto() const;
4.136 + inline int GetVersion() const;
4.137 + inline void *GetHookFunc() const;
4.138 + inline HookManagerPubFunc GetPubFunc() const;
4.139 +
4.140 + inline void Register();
4.141 + inline void Unregister();
4.142 +
4.143 + inline void IncrRef(CVfnPtr *pVfnPtr);
4.144 + inline void DecrRef(CVfnPtr *pVfnPtr);
4.145 +
4.146 + List<CVfnPtr*> &GetVfnPtrList()
4.147 + {
4.148 + return m_VfnPtrs;
4.149 + }
4.150 +
4.151 + // *** IHookManagerInfo interface ***
4.152 void SetInfo(int hookman_version, int vtbloffs, int vtblidx,
4.153 - ProtoInfo *proto, void *hookfunc_vfnptr);
4.154 - };
4.155 -
4.156 - class CHookManList : public List<CHookManager>
4.157 - {
4.158 - public:
4.159 - inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
4.160 - inline CHookManager *GetHookMan(CHookManager &hm);
4.161 - };
4.162 -
4.163 - // *** Implementation ***
4.164 - inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
4.165 - : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
4.166 - {
4.167 - // Query pubfunc
4.168 - // -> Should call SetInfo and set all the other variables!
4.169 - if (m_PubFunc(false, this) != 0)
4.170 - {
4.171 - // Error!
4.172 - m_Version = -1;
4.173 - }
4.174 - }
4.175 -
4.176 - inline CHookManager::operator bool() const
4.177 - {
4.178 - return m_Version != -1;
4.179 - }
4.180 -
4.181 - inline bool CHookManager::operator==(const Descriptor &other) const
4.182 - {
4.183 - return m_OwnerPlugin == other.m_OwnerPlugin
4.184 - && m_PubFunc == other.m_PubFunc;
4.185 - }
4.186 -
4.187 - inline bool CHookManager::operator==(const CHookManager &other) const
4.188 - {
4.189 - return m_OwnerPlugin == other.m_OwnerPlugin
4.190 - && m_PubFunc == other.m_PubFunc;
4.191 - }
4.192 -
4.193 - inline Plugin CHookManager::GetOwnerPlugin() const
4.194 - {
4.195 - return m_OwnerPlugin;
4.196 - }
4.197 -
4.198 - inline int CHookManager::GetVtblOffs() const
4.199 - {
4.200 - return m_VtblOffs;
4.201 - }
4.202 -
4.203 - inline int CHookManager::GetVtblIdx() const
4.204 - {
4.205 - return m_VtblIdx;
4.206 - }
4.207 -
4.208 - inline const CProto &CHookManager::GetProto() const
4.209 - {
4.210 - return m_Proto;
4.211 - }
4.212 -
4.213 - inline int CHookManager::GetVersion() const
4.214 - {
4.215 - return m_Version;
4.216 - }
4.217 -
4.218 - inline void *CHookManager::GetHookFunc() const
4.219 - {
4.220 - return *reinterpret_cast<void**>(m_HookfuncVfnptr);
4.221 - }
4.222 -
4.223 - inline HookManagerPubFunc CHookManager::GetPubFunc() const
4.224 - {
4.225 - return m_PubFunc;
4.226 - }
4.227 -
4.228 - inline void CHookManager::Register()
4.229 - {
4.230 - m_PubFunc(true, this);
4.231 - }
4.232 -
4.233 - inline void CHookManager::Unregister()
4.234 - {
4.235 - m_PubFunc(true, NULL);
4.236 - }
4.237 -
4.238 - inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
4.239 - {
4.240 - m_VfnPtrs.push_back(pVfnPtr);
4.241 - if (m_VfnPtrs.size() == 1)
4.242 - Register();
4.243 - }
4.244 -
4.245 - inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
4.246 - {
4.247 - m_VfnPtrs.remove(pVfnPtr);
4.248 - if (m_VfnPtrs.empty())
4.249 - Unregister();
4.250 - }
4.251 -
4.252 - inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
4.253 - {
4.254 - CHookManager hm(plug, pubFunc);
4.255 - return GetHookMan(hm);
4.256 - }
4.257 -
4.258 - inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
4.259 - {
4.260 - iterator iter = find(hm);
4.261 - if (iter == end())
4.262 - {
4.263 - push_back(hm);
4.264 - return &(back());
4.265 - }
4.266 - else
4.267 - {
4.268 - return &(*iter);
4.269 - }
4.270 - }
4.271 - }
4.272 -}
4.273 -
4.274 + ProtoInfo *proto, void *hookfunc_vfnptr);
4.275 + };
4.276 +
4.277 + class CHookManList : public List<CHookManager>
4.278 + {
4.279 + public:
4.280 + inline CHookManager *GetHookMan(Plugin plug, HookManagerPubFunc pubFunc);
4.281 + inline CHookManager *GetHookMan(CHookManager &hm);
4.282 + };
4.283 +
4.284 + // *** Implementation ***
4.285 + inline CHookManager::CHookManager(Plugin ownerPlugin, HookManagerPubFunc pubFunc)
4.286 + : m_OwnerPlugin(ownerPlugin), m_PubFunc(pubFunc), m_Version(-1)
4.287 + {
4.288 + // Query pubfunc
4.289 + // -> Should call SetInfo and set all the other variables!
4.290 + if (m_PubFunc(false, this) != 0)
4.291 + {
4.292 + // Error!
4.293 + m_Version = -1;
4.294 + }
4.295 + }
4.296 +
4.297 + inline CHookManager::operator bool() const
4.298 + {
4.299 + return m_Version != -1;
4.300 + }
4.301 +
4.302 + inline bool CHookManager::operator==(const Descriptor &other) const
4.303 + {
4.304 + return m_OwnerPlugin == other.m_OwnerPlugin
4.305 + && m_PubFunc == other.m_PubFunc;
4.306 + }
4.307 +
4.308 + inline bool CHookManager::operator==(const CHookManager &other) const
4.309 + {
4.310 + return m_OwnerPlugin == other.m_OwnerPlugin
4.311 + && m_PubFunc == other.m_PubFunc;
4.312 + }
4.313 +
4.314 + inline Plugin CHookManager::GetOwnerPlugin() const
4.315 + {
4.316 + return m_OwnerPlugin;
4.317 + }
4.318 +
4.319 + inline int CHookManager::GetVtblOffs() const
4.320 + {
4.321 + return m_VtblOffs;
4.322 + }
4.323 +
4.324 + inline int CHookManager::GetVtblIdx() const
4.325 + {
4.326 + return m_VtblIdx;
4.327 + }
4.328 +
4.329 + inline const CProto &CHookManager::GetProto() const
4.330 + {
4.331 + return m_Proto;
4.332 + }
4.333 +
4.334 + inline int CHookManager::GetVersion() const
4.335 + {
4.336 + return m_Version;
4.337 + }
4.338 +
4.339 + inline void *CHookManager::GetHookFunc() const
4.340 + {
4.341 + return *reinterpret_cast<void**>(m_HookfuncVfnptr);
4.342 + }
4.343 +
4.344 + inline HookManagerPubFunc CHookManager::GetPubFunc() const
4.345 + {
4.346 + return m_PubFunc;
4.347 + }
4.348 +
4.349 + inline void CHookManager::Register()
4.350 + {
4.351 + m_PubFunc(true, this);
4.352 + }
4.353 +
4.354 + inline void CHookManager::Unregister()
4.355 + {
4.356 + m_PubFunc(true, NULL);
4.357 + }
4.358 +
4.359 + inline void CHookManager::IncrRef(CVfnPtr *pVfnPtr)
4.360 + {
4.361 + m_VfnPtrs.push_back(pVfnPtr);
4.362 + if (m_VfnPtrs.size() == 1)
4.363 + Register();
4.364 + }
4.365 +
4.366 + inline void CHookManager::DecrRef(CVfnPtr *pVfnPtr)
4.367 + {
4.368 + m_VfnPtrs.remove(pVfnPtr);
4.369 + if (m_VfnPtrs.empty())
4.370 + Unregister();
4.371 + }
4.372 +
4.373 + inline CHookManager *CHookManList::GetHookMan(Plugin plug, HookManagerPubFunc pubFunc)
4.374 + {
4.375 + CHookManager hm(plug, pubFunc);
4.376 + return GetHookMan(hm);
4.377 + }
4.378 +
4.379 + inline CHookManager *CHookManList::GetHookMan(CHookManager &hm)
4.380 + {
4.381 + iterator iter = find(hm);
4.382 + if (iter == end())
4.383 + {
4.384 + push_back(hm);
4.385 + return &(back());
4.386 + }
4.387 + else
4.388 + {
4.389 + return &(*iter);
4.390 + }
4.391 + }
4.392 + }
4.393 +}
4.394 +
4.395 #endif
4.396