From 77506fff8d5d86f32e0874d2957161dbb99827bf Mon Sep 17 00:00:00 2001 From: momo5502 Date: Mon, 14 Mar 2016 18:29:45 +0100 Subject: [PATCH] Scoreboard stuff --- deps/protobuf | 2 +- src/Components/Modules/Node.cpp | 2 +- src/Components/Modules/ServerInfo.cpp | 36 +++++++++++++++++++++++++++ src/Components/Modules/ServerInfo.hpp | 3 +++ src/Game/Functions.cpp | 13 ++++++++++ src/Game/Functions.hpp | 10 ++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) diff --git a/deps/protobuf b/deps/protobuf index 9aea0ef0..44fdead9 160000 --- a/deps/protobuf +++ b/deps/protobuf @@ -1 +1 @@ -Subproject commit 9aea0ef0cd836fb998d2eb27bd84897f3c9a14f6 +Subproject commit 44fdead9d2652f958cb6e7e29a6d871ef132bb4c diff --git a/src/Components/Modules/Node.cpp b/src/Components/Modules/Node.cpp index af075b17..50a8155f 100644 --- a/src/Components/Modules/Node.cpp +++ b/src/Components/Modules/Node.cpp @@ -249,7 +249,7 @@ namespace Components { // Frame limit static int lastFrame = 0; - if ((Game::Com_Milliseconds() - lastFrame) < (1000 / NODE_FRAME_LOCK)) return; + if ((Game::Com_Milliseconds() - lastFrame) < (1000 / NODE_FRAME_LOCK) || Game::Com_Milliseconds() < 5000) return; lastFrame = Game::Com_Milliseconds(); int registerCount = 0; diff --git a/src/Components/Modules/ServerInfo.cpp b/src/Components/Modules/ServerInfo.cpp index f0c2524f..90204010 100644 --- a/src/Components/Modules/ServerInfo.cpp +++ b/src/Components/Modules/ServerInfo.cpp @@ -68,11 +68,47 @@ namespace Components } } + void ServerInfo::DrawScoreboardInfo(void* a1) + { + Game::Font* font = Game::R_RegisterFont("fonts/bigfont"); + void* cxt = Game::UI_GetContext(a1); + + Network::Address address(reinterpret_cast(0xA1E888)); + std::string addressText = address.GetString(); + if (addressText == "0.0.0.0:0") addressText = "Listen Server"; + + // get x positions + float fontSize = 0.35f; + float y = (480.0f - Dvar::Var("cg_scoreboardHeight").Get()) * 0.5f; + y += Dvar::Var("cg_scoreboardHeight").Get() + 6.0f; + + float x = 320.0f - Dvar::Var("cg_scoreboardWidth").Get() * 0.5f; + float x2 = 320.0f + Dvar::Var("cg_scoreboardWidth").Get() * 0.5f; + + Game::UI_DrawText(cxt, reinterpret_cast(0x7ED3F8), 0x7FFFFFFF, font, x, y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); + Game::UI_DrawText(cxt, addressText.data(), 0x7FFFFFFF, font, x2 - Game::UI_TextWidth(addressText.data(), 0, font, fontSize), y, 0, 0, fontSize, reinterpret_cast(0x747F34), 3); + } + + void __declspec(naked) ServerInfo::DrawScoreboardStub() + { + __asm + { + push eax + call ServerInfo::DrawScoreboardInfo + pop eax + mov ecx, 591B70h + jmp ecx + } + } + ServerInfo::ServerInfo() { ServerInfo::PlayerContainer.CurrentPlayer = 0; ServerInfo::PlayerContainer.PlayerList.clear(); + // Draw IP and hostname on the scoreboard + Utils::Hook(0x4FC6EA, ServerInfo::DrawScoreboardStub, HOOK_CALL).Install()->Quick(); + // Ignore native getStatus implementation Utils::Hook::Nop(0x62654E, 6); diff --git a/src/Components/Modules/ServerInfo.hpp b/src/Components/Modules/ServerInfo.hpp index b53a90ea..c96d138b 100644 --- a/src/Components/Modules/ServerInfo.hpp +++ b/src/Components/Modules/ServerInfo.hpp @@ -29,5 +29,8 @@ namespace Components static unsigned int GetPlayerCount(); static const char* GetPlayerText(unsigned int index, int column); static void SelectPlayer(unsigned int index); + + static void DrawScoreboardInfo(void* a1); + static void DrawScoreboardStub(); }; } diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index cbc73ee2..d32430b7 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -141,6 +141,9 @@ namespace Game UI_AddMenuList_t UI_AddMenuList = (UI_AddMenuList_t)0x4533C0; UI_LoadMenus_t UI_LoadMenus = (UI_LoadMenus_t)0x641460; UI_DrawHandlePic_t UI_DrawHandlePic = (UI_DrawHandlePic_t)0x4D0EA0; + UI_GetContext_t UI_GetContext = (UI_GetContext_t)0x4F8940; + UI_TextWidth_t UI_TextWidth = (UI_TextWidth_t)0x6315C0; + UI_DrawText_t UI_DrawText = (UI_DrawText_t)0x49C0D0; Win_GetLanguage_t Win_GetLanguage = (Win_GetLanguage_t)0x45CBA0; @@ -255,6 +258,16 @@ namespace Game return gameType; } + float UI_GetScoreboardLeft(void* a1) + { + static int func = 0x590390; + __asm + { + mov eax, [esp + 4h] + call func + } + } + const char *DB_GetXAssetName(XAsset *asset) { if (!asset) return ""; diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index d4a13220..e0b860e8 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -329,6 +329,15 @@ namespace Game typedef void(__cdecl * UI_DrawHandlePic_t)(/*ScreenPlacement*/void *scrPlace, float x, float y, float w, float h, int horzAlign, int vertAlign, const float *color, Material *material); extern UI_DrawHandlePic_t UI_DrawHandlePic; + typedef void* (__cdecl * UI_GetContext_t)(void*); + extern UI_GetContext_t UI_GetContext; + + typedef int(__cdecl * UI_TextWidth_t)(const char *text, int maxChars, Font *font, float scale); + extern UI_TextWidth_t UI_TextWidth; + + typedef void(__cdecl * UI_DrawText_t)(void* scrPlace, const char *text, int maxChars, Font *font, float x, float y, int horzAlign, int vertAlign, float scale, const float *color, int style); + extern UI_DrawText_t UI_DrawText; + typedef const char * (__cdecl * Win_GetLanguage_t)(); extern Win_GetLanguage_t Win_GetLanguage; @@ -381,6 +390,7 @@ namespace Game const char* TabeLookup(StringTable* stringtable, int row, int column); const char* UI_LocalizeMapName(const char* mapName); const char* UI_LocalizeGameType(const char* gameType); + float UI_GetScoreboardLeft(void*); const char *DB_GetXAssetName(XAsset *asset); XAssetType DB_GetXAssetNameType(const char* name);