From e426d837e0658c82d33527d98caf4da075fae26d Mon Sep 17 00:00:00 2001 From: JerryALT Date: Tue, 18 Jun 2024 15:03:00 +0300 Subject: [PATCH] [CommonPatch]: Added Enhanced debug information when cg_drawFPS value more than 1 --- src/Components/Modules/CommonPatch.cpp | 78 ++++++++++++++++++++++++++ src/Components/Modules/CommonPatch.hpp | 7 +++ 2 files changed, 85 insertions(+) diff --git a/src/Components/Modules/CommonPatch.cpp b/src/Components/Modules/CommonPatch.cpp index e5e5557..cf94d2c 100644 --- a/src/Components/Modules/CommonPatch.cpp +++ b/src/Components/Modules/CommonPatch.cpp @@ -481,6 +481,72 @@ namespace Components } } + float CommonPatch::CG_DrawViewpos(float previous_y, float posX, float labelWidth) + { + const float color[4] = { 1.00f, 1.00f, 1.00f, 1.00f }; + const char* mapname = Dvars::Functions::Dvar_FindVar("mapname")->current.string; + const char* text = Utils::String::VA("%s (%.1f %.1f %.1f) %.1f %.1f", mapname, Game::g_clients->ps.origin[0], Game::g_clients->ps.origin[1], Game::g_clients->ps.origin[2], Game::cgs->refdefViewAngles[1], Game::cgs->refdefViewAngles[0]); + float final_pos = Game::CG_CornerDebugPrint(color, text, Game::scrPlaceFull, posX, previous_y, labelWidth, " viewpos") + previous_y; + return final_pos; + } + + float CommonPatch::CG_DrawDObjInfo(float previous_y, float posX, float labelWidth) + { + int objFreeCount = *(int*)(0xFC1918); + const float color[4] = { 1.00f, 1.00f, 1.00f, 1.00f }; + const char* text = Utils::String::VA("%d/%d", 2048 - objFreeCount, 2048); + float final_pos = Game::CG_CornerDebugPrint(color, text, Game::scrPlaceFull, posX, previous_y, labelWidth, " used DObjs") + previous_y; + return final_pos; + } + + float CommonPatch::CG_DrawEntitiesCountInfo(float previous_y, float posX, float labelWidth) + { + int level_num_entities = *(int*)(0xE18E24); + const float color[4] = { 1.00f, 1.00f, 1.00f, 1.00f }; + const char* text = Utils::String::VA("%d/%d", level_num_entities, 2174); + float final_pos = Game::CG_CornerDebugPrint(color, text, Game::scrPlaceFull, posX, previous_y, labelWidth, " total ents") + previous_y; + return final_pos; + } + + float CommonPatch::CG_DrawAICount(float previous_y, float posX, float labelWidth) + { + int level_actorCount = *(int*)(0xE18E64); + const float color[4] = { 1.00f, 1.00f, 1.00f, 1.00f }; + const char* text = Utils::String::VA("%d/%d", level_actorCount, 32); + float final_pos = Game::CG_CornerDebugPrint(color, text, Game::scrPlaceFull, posX, previous_y, labelWidth, " total AI") + previous_y; + return final_pos; + } + + void CommonPatch::EnhancedDebugInformation() + { + float x = Game::scrPlaceFull->virtualViewableMax[0] - Game::scrPlaceFull->virtualViewableMin[0] + Dvars::Functions::Dvar_FindVar("cg_debugInfoCornerOffset")->current.value; + float y = Dvars::Functions::Dvar_FindVar("cg_debugInfoCornerOffset")->current.vector[1]; + float labelWidth = Dvars::Functions::Dvar_FindVar("cg_small_dev_string_fontscale")->current.value * (Game::R_TextWidth(" cg ms/frame", 0, Game::cgMedia->smallDevFont) * 0.75f); + + if(Dvars::cg_drawViewpos->current.enabled) + y = CG_DrawViewpos(y, x, labelWidth); + if (Dvars::Functions::Dvar_FindVar("cg_drawFPS")->current.integer) + { + y = Utils::Hook::Call(0x411510)(y); //CG_DrawFPS + if (Dvars::Functions::Dvar_FindVar("cg_drawFPS")->current.integer > 1) + { + y = CG_DrawDObjInfo(y, x, labelWidth); + y = CG_DrawEntitiesCountInfo(y, x, labelWidth); + y = CG_DrawAICount(y, x, labelWidth); + } + } + } + + void __declspec(naked) CommonPatch::CG_DrawFPSStub() + { + const static uint32_t retn_addr = 0x411167; + __asm + { + mov dword ptr ds:[0x1628E68], 0; + call EnhancedDebugInformation; + jmp retn_addr; + } + } Game::dvar_s* CommonPatch::fs_usedevdir_fix(const char* dvarName, int type, unsigned __int16 flags, float r, float g, float b, float a, float min, float max, const char* description) { @@ -539,6 +605,11 @@ namespace Components Game::dvar_s* snd_hitsoundDisabled = Dvars::Register::Dvar_RegisterBool("snd_hitsoundDisabled", "Disable the hit indicator sound", true, Game::saved); Game::dvar_s* sv_allowCheats = Dvars::Register::Dvar_RegisterBool("sv_allowCheats", "Enable/Disable the game cheats", false, Game::saved); Dvars::allowCompactFolderForMod = Dvars::Register::Dvar_RegisterBool("allowCompactFolderForMod", "Enable/Disable compact loading of the mod files.", false, Game::saved); + + if (Game::DebugModeEnabled()) + { + Dvars::cg_drawViewpos = Dvars::Register::Dvar_RegisterBool("cg_drawViewpos", "Draw viewpos", false, Game::saved); + } }); // Change the folder for loading files from miles @@ -636,6 +707,13 @@ namespace Components // Fix the 'fs_usedevdir' skill issue Utils::Hook(0x57AC04, fs_usedevdir_register_stub, HOOK_JUMP).install()->quick(); + if (Game::DebugModeEnabled()) + { + // Additional debug information + Utils::Hook::Nop(0x411140, 10); + Utils::Hook(0x411140, CG_DrawFPSStub, HOOK_JUMP).install()->quick(); + } + // Mouse fix Utils::Hook::Nop(0x59681C, 8); Scheduler::Loop([] diff --git a/src/Components/Modules/CommonPatch.hpp b/src/Components/Modules/CommonPatch.hpp index 0d2d3c7..dd4d9dc 100644 --- a/src/Components/Modules/CommonPatch.hpp +++ b/src/Components/Modules/CommonPatch.hpp @@ -25,6 +25,13 @@ namespace Components static void RegisterConColorStub5(); static void LanguageSetValueConfig(int langIndex); + static void CG_DrawFPSStub(); + static void EnhancedDebugInformation(); + static float CG_DrawAICount(float previous_y, float posX, float labelWidth); + static float CG_DrawEntitiesCountInfo(float previous_y, float posX, float labelWidth); + static float CG_DrawDObjInfo(float previous_y, float posX, float labelWidth); + static float CG_DrawViewpos(float previous_y, float posX, float labelWidth); + static bool CheckMilesFiles(); static const char* __stdcall AIL_set_redist_directory_Stub(const char* directory);