From 0e62280896ec2a243283366205fb8313d6e29a14 Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 24 Dec 2023 20:38:50 +0100 Subject: [PATCH] NVIDIA: add PC_LATENCY_PING marker to msg pump --- src/inputsystem/inputsystem.cpp | 23 +++++++++++++++++++++++ src/inputsystem/inputsystem.h | 15 ++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/inputsystem/inputsystem.cpp b/src/inputsystem/inputsystem.cpp index f181d0ca..01f2a39a 100644 --- a/src/inputsystem/inputsystem.cpp +++ b/src/inputsystem/inputsystem.cpp @@ -6,6 +6,8 @@ #include "core/stdafx.h" #include "vpc/IAppSystem.h" +#include "windows/id3dx.h" +#include "geforce/reflex.h" #include "inputsystem/inputsystem.h" ////----------------------------------------------------------------------------- @@ -49,6 +51,27 @@ // return CallVFunc(index, this, pString); //} +LRESULT CInputSystem::WindowProc(void* unused, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam) +{ + if (g_pInputSystem->m_bEnabled && + ((hwnd == g_pInputSystem->m_hAttachedHWnd) || (uMsg == WM_ACTIVATEAPP)) && + (uMsg != WM_CLOSE)) + { + if (PCLSTATS_IS_PING_MSG_ID(uMsg)) + { + GFX_SetLatencyMarker(D3D11Device(), PC_LATENCY_PING); + } + } + + return v_CInputSystem__WindowProc(unused, hwnd, uMsg, wParam, lParam); +} + + +void VInputSystem::Detour(const bool bAttach) const +{ + DetourSetup(&v_CInputSystem__WindowProc, &CInputSystem::WindowProc, bAttach); +} + /////////////////////////////////////////////////////////////////////////////// CInputSystem* g_pInputSystem = nullptr; bool(**g_fnSyncRTWithIn)(void) = nullptr; diff --git a/src/inputsystem/inputsystem.h b/src/inputsystem/inputsystem.h index 52b666b5..ed667267 100644 --- a/src/inputsystem/inputsystem.h +++ b/src/inputsystem/inputsystem.h @@ -11,6 +11,9 @@ class CInputSystem : public CTier1AppSystem< IInputSystem > { public: // !!!interface implemented in engine!!! +public: + // Hook statics: + static LRESULT WindowProc(void* unused, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); private: enum @@ -162,18 +165,24 @@ private: static_assert(sizeof(CInputSystem) == 0x18E8); /////////////////////////////////////////////////////////////////////////////// +inline LRESULT (*v_CInputSystem__WindowProc)(void* thisptr, HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam); + extern CInputSystem* g_pInputSystem; -extern bool(**g_fnSyncRTWithIn)(void); // Belongs to an array of callbacks, see CMaterialSystem::MatsysMode_Init(). +extern bool(**g_fnSyncRTWithIn)(void); // Belongs to an array of functions, see CMaterialSystem::MatsysMode_Init(). /////////////////////////////////////////////////////////////////////////////// class VInputSystem : public IDetour { virtual void GetAdr(void) const { + LogFunAdr("CInputSystem::WindowProc", reinterpret_cast(v_CInputSystem__WindowProc)); LogVarAdr("g_pInputSystem", reinterpret_cast(g_pInputSystem)); LogVarAdr("g_fnSyncRTWithIn", reinterpret_cast(g_fnSyncRTWithIn)); } - virtual void GetFun(void) const { } + virtual void GetFun(void) const + { + g_GameDll.FindPatternSIMD("48 89 4C 24 ?? 55 56 41 54 41 55 48 83 EC 48", v_CInputSystem__WindowProc); + } virtual void GetVar(void) const { g_pInputSystem = g_GameDll.FindPatternSIMD("48 83 EC 28 48 8B 0D ?? ?? ?? ?? 48 8D 05 ?? ?? ?? ?? 48 89 05 ?? ?? ?? ?? 48 85 C9 74 11") @@ -183,6 +192,6 @@ class VInputSystem : public IDetour g_fnSyncRTWithIn = l_EngineApi_PumpMessages.FindPattern("74 06").FindPatternSelf("FF 15").ResolveRelativeAddressSelf(2, 6).RCast(); } virtual void GetCon(void) const { } - virtual void Detour(const bool bAttach) const { } + virtual void Detour(const bool bAttach) const; }; ///////////////////////////////////////////////////////////////////////////////