From cb4e422724c4d3cb1a82fb7465c6546f323bd2b9 Mon Sep 17 00:00:00 2001 From: rexx <67599507+r-ex@users.noreply.github.com> Date: Wed, 20 Jul 2022 22:50:55 +0100 Subject: [PATCH] reimplement stream overlay drawing --- r5dev/rtech/rtech_utils.cpp | 13 ++++++++++++- r5dev/rtech/rtech_utils.h | 8 ++++++++ r5dev/tier1/IConVar.cpp | 2 ++ r5dev/tier1/cvar.cpp | 2 ++ r5dev/tier1/cvar.h | 2 ++ r5dev/vgui/vgui_debugpanel.cpp | 14 ++++++++++++++ r5dev/vgui/vgui_debugpanel.h | 1 + 7 files changed, 41 insertions(+), 1 deletion(-) diff --git a/r5dev/rtech/rtech_utils.cpp b/r5dev/rtech/rtech_utils.cpp index 29f54091..7baacf75 100644 --- a/r5dev/rtech/rtech_utils.cpp +++ b/r5dev/rtech/rtech_utils.cpp @@ -5,7 +5,6 @@ #include "materialsystem/cshaderglue.h" #endif // !DEDICATED - /****************************************************************************** ------------------------------------------------------------------------------- File : rtech.cpp @@ -655,10 +654,21 @@ RPakLoadedInfo_t* RTech::GetPakLoadedInfo(const char* szPakName) return nullptr; } +#if not defined DEDICATED && defined (GAMEDLL_S3) +void RTech_GetStreamOverlay(const char* mode, char* buf, size_t bufSize) +{ + // call original first to populate the buffer + GetStreamOverlay(mode, buf, bufSize); + + s_StreamOverlayBuf = std::string(buf); +} +#endif + void RTech_Utils_Attach() { #if not defined DEDICATED && defined (GAMEDLL_S3) DetourAttach((LPVOID*)&RTech_CreateDXTexture, &RTech::CreateDXTexture); + DetourAttach((LPVOID*)&GetStreamOverlay, &RTech_GetStreamOverlay); #endif } @@ -666,6 +676,7 @@ void RTech_Utils_Detach() { #if not defined DEDICATED && defined (GAMEDLL_S3) DetourDetach((LPVOID*)&RTech_CreateDXTexture, &RTech::CreateDXTexture); + DetourDetach((LPVOID*)&GetStreamOverlay, &RTech_GetStreamOverlay); #endif } diff --git a/r5dev/rtech/rtech_utils.h b/r5dev/rtech/rtech_utils.h index 95b0756b..ea57f867 100644 --- a/r5dev/rtech/rtech_utils.h +++ b/r5dev/rtech/rtech_utils.h @@ -450,6 +450,11 @@ public: #if not defined DEDICATED && defined (GAMEDLL_S3) inline CMemory p_RTech_CreateDXTexture; inline auto RTech_CreateDXTexture = p_RTech_CreateDXTexture.RCast(); + +inline CMemory p_GetStreamOverlay; +inline auto GetStreamOverlay = p_GetStreamOverlay.RCast(); + +inline std::string s_StreamOverlayBuf; #endif inline RPakLoadedInfo_t* g_pLoadedPakInfo; @@ -494,6 +499,9 @@ class VPakFile : public IDetour #if not defined DEDICATED && defined (GAMEDLL_S3) p_RTech_CreateDXTexture = g_mGameDll.FindPatternSIMD(reinterpret_cast("\xE8\x00\x00\x00\x00\x4C\x8B\xC7\x48\x8B\xD5\x48\x8B\xCB\x48\x83\xC4\x60"), "x????xxxxxxxxxxxxx").FollowNearCallSelf(); RTech_CreateDXTexture = p_RTech_CreateDXTexture.RCast(); /*E8 ? ? ? ? 4C 8B C7 48 8B D5 48 8B CB 48 83 C4 60*/ + + p_GetStreamOverlay = g_mGameDll.FindPatternSIMD(reinterpret_cast("\xE8\x00\x00\x00\x00\x80\x7C\x24\x00\x00\x0F\x84\x00\x00\x00\x00\x48\x89\x9C\x24\x00\x00\x00\x00"), "x????xxx??xx????xxxx????").FollowNearCallSelf(); + GetStreamOverlay = p_GetStreamOverlay.RCast(); #endif } virtual void GetVar(void) const diff --git a/r5dev/tier1/IConVar.cpp b/r5dev/tier1/IConVar.cpp index f61b2a44..9b11000a 100644 --- a/r5dev/tier1/IConVar.cpp +++ b/r5dev/tier1/IConVar.cpp @@ -192,6 +192,8 @@ void ConVar::InitShipped(void) const host_hasIrreversibleShutdown = g_pCVar->FindVar("host_hasIrreversibleShutdown"); net_usesocketsforloopback = g_pCVar->FindVar("net_usesocketsforloopback"); + stream_overlay = g_pCVar->FindVar("stream_overlay"); + mp_gamemode->SetCallback(&MP_GameMode_Changed_f); } diff --git a/r5dev/tier1/cvar.cpp b/r5dev/tier1/cvar.cpp index fb13f02e..e2114675 100644 --- a/r5dev/tier1/cvar.cpp +++ b/r5dev/tier1/cvar.cpp @@ -38,6 +38,8 @@ ConVar* r_debug_overlay_zbuffer = nullptr; ConVar* r_drawWorldMeshes = nullptr; ConVar* r_drawWorldMeshesDepthOnly = nullptr; ConVar* r_drawWorldMeshesDepthAtTheEnd = nullptr; + +ConVar* stream_overlay = nullptr; //----------------------------------------------------------------------------- // SERVER | ConVar* ai_ainDumpOnLoad = nullptr; diff --git a/r5dev/tier1/cvar.h b/r5dev/tier1/cvar.h index caa1f5d2..cd549bdd 100644 --- a/r5dev/tier1/cvar.h +++ b/r5dev/tier1/cvar.h @@ -37,6 +37,8 @@ extern ConVar* r_debug_overlay_zbuffer; extern ConVar* r_drawWorldMeshes; extern ConVar* r_drawWorldMeshesDepthOnly; extern ConVar* r_drawWorldMeshesDepthAtTheEnd; + +extern ConVar* stream_overlay; //------------------------------------------------------------------------- // SERVER | extern ConVar* ai_ainDumpOnLoad; diff --git a/r5dev/vgui/vgui_debugpanel.cpp b/r5dev/vgui/vgui_debugpanel.cpp index 57f9735e..b5365aed 100644 --- a/r5dev/vgui/vgui_debugpanel.cpp +++ b/r5dev/vgui/vgui_debugpanel.cpp @@ -21,6 +21,7 @@ #ifndef CLIENT_DLL #include #endif +#include //----------------------------------------------------------------------------- // Purpose: proceed a log update @@ -51,6 +52,10 @@ void CLogSystem::Update(void) { DrawCrosshairMaterial(); } + if (stream_overlay->GetBool()) + { + DrawStreamOverlay(); + } } //----------------------------------------------------------------------------- @@ -211,6 +216,15 @@ void CLogSystem::DrawCrosshairMaterial(void) const CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, cl_materialinfo_offset_x->GetInt(), cl_materialinfo_offset_y->GetInt(), c.r(), c.g(), c.b(), c.a(), (char*)szLogbuf); } +void CLogSystem::DrawStreamOverlay(void) const +{ + std::string buf = s_StreamOverlayBuf; + + static Color c = { 255, 255, 255, 255 }; + + CMatSystemSurface_DrawColoredText(g_pMatSystemSurface, v_Rui_GetFontFace(), m_nFontHeight, 20, 300, c.r(), c.g(), c.b(), c.a(), (char*)buf.c_str()); +} + //----------------------------------------------------------------------------- // Purpose: get log color for passed type. //----------------------------------------------------------------------------- diff --git a/r5dev/vgui/vgui_debugpanel.h b/r5dev/vgui/vgui_debugpanel.h index c07bf0e5..bedb4150 100644 --- a/r5dev/vgui/vgui_debugpanel.h +++ b/r5dev/vgui/vgui_debugpanel.h @@ -43,6 +43,7 @@ public: void DrawSimStats(void) const; void DrawGPUStats(void) const; void DrawCrosshairMaterial(void) const; + void DrawStreamOverlay(void) const; private: Color GetLogColorForType(LogType_t type) const;