From 9ab9eba5d7400c2ae3be50bf4c12a967f043512d Mon Sep 17 00:00:00 2001 From: Borja Ferrer Date: Thu, 6 Dec 2007 02:25:35 +0000 Subject: [PATCH] added amb1235, added support for the IServer interface added a native to retrieve the spray file of a client added a native to get the net traffic of the server --HG-- extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%401775 --- extensions/sdktools/extension.cpp | 2 + extensions/sdktools/extension.h | 3 ++ extensions/sdktools/vglobals.cpp | 57 ++++++++++++++++++++++++++ extensions/sdktools/vglobals.h | 1 + extensions/sdktools/vhelpers.cpp | 9 ++++ extensions/sdktools/vhelpers.h | 2 + extensions/sdktools/vnatives.cpp | 43 +++++++++++++++++++ gamedata/sdktools.games.ep2.txt | 23 +++++++++++ gamedata/sdktools.games.txt | 23 +++++++++++ plugins/include/sdktools_functions.inc | 20 +++++++++ 10 files changed, 183 insertions(+) diff --git a/extensions/sdktools/extension.cpp b/extensions/sdktools/extension.cpp index e41a165d..c01ff74a 100644 --- a/extensions/sdktools/extension.cpp +++ b/extensions/sdktools/extension.cpp @@ -64,6 +64,7 @@ IServerGameClients *serverClients = NULL; IVoiceServer *voiceserver = NULL; IPlayerInfoManager *playerinfomngr = NULL; ICvar *icvar = NULL; +IServer *iserver = NULL; SourceHook::CallClass *enginePatch = NULL; SourceHook::CallClass *enginesoundPatch = NULL; HandleType_t g_CallHandle = 0; @@ -204,6 +205,7 @@ void SDKTools::SDK_OnAllLoaded() s_TempEntHooks.Initialize(); s_SoundHooks.Initialize(); InitializeValveGlobals(); + GetIServer(); } bool SDKTools::QueryRunning(char *error, size_t maxlength) diff --git a/extensions/sdktools/extension.h b/extensions/sdktools/extension.h index 7a331b55..c13343a9 100644 --- a/extensions/sdktools/extension.h +++ b/extensions/sdktools/extension.h @@ -46,6 +46,8 @@ #include #include #include +#include +#include #include /** @@ -99,6 +101,7 @@ extern IServerGameClients *serverClients; extern IVoiceServer *voiceserver; extern IPlayerInfoManager *playerinfomngr; extern ICvar *icvar; +extern IServer *iserver; /* Interfaces from SourceMod */ extern IBinTools *g_pBinTools; extern IGameConfig *g_pGameConf; diff --git a/extensions/sdktools/vglobals.cpp b/extensions/sdktools/vglobals.cpp index d7cd3e4f..09337a70 100644 --- a/extensions/sdktools/vglobals.cpp +++ b/extensions/sdktools/vglobals.cpp @@ -82,3 +82,60 @@ void InitializeValveGlobals() g_pGameRules = reinterpret_cast(addr); } #endif + +#if defined PLATFORM_WINDOWS + /* Thanks to DS for the sigs */ + #define ISERVER_WIN_SIG "\x8B\x44\x24\x2A\x50\xB9\x2A\x2A\x2A\x2A\xE8" + #define ISERVER_WIN_SIG_LEN 11 +void GetIServer() +{ + /* First check that the IVEngineServer::CreateFakeClient exists */ + if (!memutils->FindPattern(engine, ISERVER_WIN_SIG, ISERVER_WIN_SIG_LEN)) + { + return; + } + + int offset; + void *vfunc = NULL; + + /* Get the offset into CreateFakeClient */ + if (!g_pGameConf->GetOffset("sv", &offset)) + { + return; + } +#if defined METAMOD_PLAPI_VERSION + /* Get the CreateFakeClient function pointer */ + if (!(vfunc=SH_GET_ORIG_VFNPTR_ENTRY(engine, &IVEngineServer::CreateFakeClient))) + { + return; + } + + /* Finally we have the interface we were looking for */ + iserver = *reinterpret_cast(reinterpret_cast(vfunc) + offset); +#else + /* Get the interface manually */ + SourceHook::MemFuncInfo info = {true, -1, 0, 0}; + SourceHook::GetFuncInfo(&IVEngineServer::CreateFakeClient, info); + + vfunc = enginePatch->GetOrigFunc(info.vtbloffs, info.vtblindex); + if (!vfunc) + { + void **vtable = *reinterpret_cast(enginePatch->GetThisPtr() + info.thisptroffs + info.vtbloffs); + vfunc = vtable[info.vtblindex]; + } + + iserver = *reinterpret_cast(reinterpret_cast(vfunc) + offset); +#endif +} +#elif defined PLATFORM_POSIX +void GetIServer() +{ + void *addr; + if (!g_pGameConf->GetMemSig("sv", &addr) || !addr) + { + return; + } + + iserver = *reinterpret_cast(addr); +} +#endif diff --git a/extensions/sdktools/vglobals.h b/extensions/sdktools/vglobals.h index c66f2ada..5e9a65ee 100644 --- a/extensions/sdktools/vglobals.h +++ b/extensions/sdktools/vglobals.h @@ -36,5 +36,6 @@ extern void **g_pGameRules; extern void *g_EntList; void InitializeValveGlobals(); +void GetIServer(); #endif // _INCLUDE_SDKTOOLS_VGLOBALS_H_ diff --git a/extensions/sdktools/vhelpers.cpp b/extensions/sdktools/vhelpers.cpp index 93977c9c..44a577a1 100644 --- a/extensions/sdktools/vhelpers.cpp +++ b/extensions/sdktools/vhelpers.cpp @@ -267,6 +267,15 @@ bool IsEyeAnglesSupported() return SetupGetEyeAngles(); } +bool GetPlayerInfo(int client, player_info_t *info) +{ +#if defined ORANGEBOX_BUILD + return engine->GetPlayerInfo(client, info); +#else + return iserver->GetPlayerInfo(client, info); +#endif +} + void ShutdownHelpers() { s_Teleport.Shutdown(); diff --git a/extensions/sdktools/vhelpers.h b/extensions/sdktools/vhelpers.h index cae47a29..3ba1b116 100644 --- a/extensions/sdktools/vhelpers.h +++ b/extensions/sdktools/vhelpers.h @@ -68,6 +68,8 @@ bool IsEyeAnglesSupported(); int GetClientAimTarget(edict_t *pEdict, bool only_players); +bool GetPlayerInfo(int client, player_info_t *info); + void ShutdownHelpers(); #endif //_INCLUDE_SDKTOOLS_VHELPERS_H_ diff --git a/extensions/sdktools/vnatives.cpp b/extensions/sdktools/vnatives.cpp index 886ad887..ce54958d 100644 --- a/extensions/sdktools/vnatives.cpp +++ b/extensions/sdktools/vnatives.cpp @@ -825,6 +825,47 @@ static cell_t sm_SetEntityModel(IPluginContext *pContext, const cell_t *params) return 1; } +static cell_t GetPlayerDecalFile(IPluginContext *pContext, const cell_t *params) +{ + IGamePlayer *player = playerhelpers->GetGamePlayer(params[1]); + if (player == NULL) + { + return pContext->ThrowNativeError("Invalid client index %d", params[1]); + } + if (!player->IsInGame()) + { + return pContext->ThrowNativeError("Client %d is not in game", params[1]); + } + + player_info_t info; + char *buffer; + + if (!GetPlayerInfo(params[1], &info) || !info.customFiles[0]) + { + return 0; + } + + pContext->LocalToString(params[2], &buffer); + Q_binarytohex((byte *)&info.customFiles[0], sizeof(info.customFiles[0]), buffer, params[3]); + + return 1; +} + +static cell_t GetServerNetStats(IPluginContext *pContext, const cell_t *params) +{ + float in, out; + cell_t *pIn, *pOut; + + pContext->LocalToPhysAddr(params[1], &pIn); + pContext->LocalToPhysAddr(params[2], &pOut); + iserver->GetNetStats(in, out); + + *pIn = sp_ftoc(in); + *pOut = sp_ftoc(out); + + return 1; +} + sp_nativeinfo_t g_Natives[] = { {"ExtinguishPlayer", ExtinguishEntity}, @@ -850,5 +891,7 @@ sp_nativeinfo_t g_Natives[] = {"DispatchKeyValueVector", DispatchKeyValueVector}, {"GetClientAimTarget", sm_GetClientAimTarget}, {"SetEntityModel", sm_SetEntityModel}, + {"GetPlayerDecalFile", GetPlayerDecalFile}, + {"GetServerNetStats", GetServerNetStats}, {NULL, NULL}, }; diff --git a/gamedata/sdktools.games.ep2.txt b/gamedata/sdktools.games.ep2.txt index 7fc52211..ea4e9c58 100644 --- a/gamedata/sdktools.games.ep2.txt +++ b/gamedata/sdktools.games.ep2.txt @@ -178,6 +178,29 @@ } } + /* IServer interface pointer */ + "#default" + { + "Offsets" + { + /* Offset into IVEngineServer::CreateFakeClient */ + "sv" + { + "windows" "6" + } + } + + "Signatures" + { + /* CBaseServer object for IServer interface */ + "sv" + { + "library" "engine" + "linux" "@sv" + } + } + } + /* Team Fortress 2 Offsets */ "tf" { diff --git a/gamedata/sdktools.games.txt b/gamedata/sdktools.games.txt index 5895b6ff..aadea07f 100644 --- a/gamedata/sdktools.games.txt +++ b/gamedata/sdktools.games.txt @@ -216,6 +216,29 @@ } } + /* IServer interface pointer */ + "#default" + { + "Offsets" + { + /* Offset into IVEngineServer::CreateFakeClient */ + "sv" + { + "windows" "6" + } + } + + "Signatures" + { + /* CBaseServer object for IServer interface */ + "sv" + { + "library" "engine" + "linux" "@sv" + } + } + } + /* Counter-Strike: Source */ "cstrike" { diff --git a/plugins/include/sdktools_functions.inc b/plugins/include/sdktools_functions.inc index 4fc3958e..61eb4754 100644 --- a/plugins/include/sdktools_functions.inc +++ b/plugins/include/sdktools_functions.inc @@ -264,6 +264,26 @@ native GetTeamClientCount(index); */ native SetEntityModel(entity, const String:model[]); +/** + * Retrieves the decal file name associated to a given client. + * + * @param client Player's index. + * @param hex Buffer to store the logo filename. + * @param maxlength Maximum length of string buffer. + * @return True on success, otherwise false. + * @error Invalid client or client not in game. + */ +native bool:GetPlayerDecalFile(client, String:hex[], maxlength); + +/** + * Returns the average server network traffic in bytes/sec. + * + * @param in Buffer to store the input traffic velocity. + * @param out Buffer to store the output traffic velocity. + * @noreturn + */ +native GetServerNetStats(&Float:in, &Float:out); + /** * @deprecated */