From 6575f80447e3205578a21b079d271d9c2f4ad80d Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Sun, 24 Dec 2023 22:32:58 +0100 Subject: [PATCH] NVIDIA: add TRIGGER_FLASH marker to input event handler --- src/engine/keys.cpp | 32 +++++++++++++++++++++++++++++++- src/engine/keys.h | 13 ++++++++----- src/engine/sys_dll2.cpp | 2 +- src/engine/sys_mainwind.cpp | 2 +- src/vgui/vgui_baseui_interface.h | 6 +++--- 5 files changed, 44 insertions(+), 11 deletions(-) diff --git a/src/engine/keys.cpp b/src/engine/keys.cpp index 84fad325..ea120c6e 100644 --- a/src/engine/keys.cpp +++ b/src/engine/keys.cpp @@ -1,5 +1,35 @@ #include "keys.h" +#include "windows/id3dx.h" +#include "geforce/reflex.h" KeyInfo_t* g_pKeyInfo = nullptr; ButtonCode_t* g_pKeyEventTicks = nullptr; -short* g_nKeyEventCount = nullptr; \ No newline at end of file +short* g_nKeyEventCount = nullptr; + + +bool Input_Event(const InputEvent_t& inputEvent, const int noKeyUpCheck) +{ + bool runTriggerMarker = inputEvent.m_nData == ButtonCode_t::MOUSE_LEFT; + const KeyInfo_t& keyInfo = g_pKeyInfo[inputEvent.m_nData]; + + if (noKeyUpCheck) + { + const int v = (inputEvent.m_nType & 0xFFFFFFFD) == 0; + + if (keyInfo.m_nKeyDownTarget == v) + runTriggerMarker = false; + } + + if (runTriggerMarker && (inputEvent.m_nType != IE_ButtonReleased || keyInfo.m_bTrapKeyUp)) + { + GFX_SetLatencyMarker(D3D11Device(), TRIGGER_FLASH); + } + + return v_Input_Event(inputEvent, noKeyUpCheck); +} + +/////////////////////////////////////////////////////////////////////////////// +void VKeys::Detour(const bool bAttach) const +{ + DetourSetup(&v_Input_Event, &Input_Event, bAttach); +} diff --git a/src/engine/keys.h b/src/engine/keys.h index c4b7e829..431ab29d 100644 --- a/src/engine/keys.h +++ b/src/engine/keys.h @@ -35,13 +35,14 @@ struct KeyInfo_t bool m_bKeyDown; bool m_bEventIsButtonKey; // Is the event a button key (< ButtonCode_t::KEY_LAST) - bool m_bBoundKeyDown; + bool m_bTrapKeyUp; bool m_bBoundSecondKey; // Is the key bound to the second row? short paddingMaybe; }; -inline bool(*Key_Event)(const KeyEvent_t& keyEvent); +inline bool (*v_Input_Event)(const InputEvent_t& inputEvent, const int noKeyUpCheck); +inline bool(*v_Key_Event)(const KeyEvent_t& keyEvent); extern KeyInfo_t* g_pKeyInfo; // ARRAYSIZE = ButtonCode_t::BUTTON_CODE_LAST extern ButtonCode_t* g_pKeyEventTicks; // ARRAYSIZE = ButtonCode_t::BUTTON_CODE_LAST @@ -51,14 +52,16 @@ class VKeys : public IDetour { virtual void GetAdr(void) const { - LogFunAdr("Key_Event", reinterpret_cast(Key_Event)); + LogFunAdr("Input_Event", reinterpret_cast(v_Input_Event)); + LogFunAdr("Key_Event", reinterpret_cast(v_Key_Event)); LogVarAdr("g_pKeyInfo", reinterpret_cast(g_pKeyInfo)); LogVarAdr("g_pKeyEventTicks", reinterpret_cast(g_pKeyEventTicks)); LogVarAdr("g_nKeyEventCount", reinterpret_cast(g_nKeyEventCount)); } virtual void GetFun(void) const { - Key_Event = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 4C 63 41 08").RCast(); + g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 48 89 7C 24 ?? 55 41 54 41 56", v_Input_Event); + g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 83 EC 20 4C 63 41 08", v_Key_Event); } virtual void GetVar(void) const { @@ -72,7 +75,7 @@ class VKeys : public IDetour g_pKeyEventTicks = l_EngineApi_PumpMessages.FindPatternSelf("48 8D 35").ResolveRelativeAddressSelf(3, 7).RCast(); } virtual void GetCon(void) const { } - virtual void Detour(const bool bAttach) const { } + virtual void Detour(const bool bAttach) const; }; #endif // ENGINE_KEYS_H diff --git a/src/engine/sys_dll2.cpp b/src/engine/sys_dll2.cpp index 9abae8d9..32cb51e8 100644 --- a/src/engine/sys_dll2.cpp +++ b/src/engine/sys_dll2.cpp @@ -174,7 +174,7 @@ void CEngineAPI::PumpMessages() if (in_syncRT->GetBool()) (*g_fnSyncRTWithIn)(); - g_pInputSystem->PollInputState(UIInputEventHandler); + g_pInputSystem->PollInputState(v_UIInputEventHandler); g_pGame->DispatchAllStoredGameMessages(); #endif // !DEDICATED } diff --git a/src/engine/sys_mainwind.cpp b/src/engine/sys_mainwind.cpp index e963a551..b08353e2 100644 --- a/src/engine/sys_mainwind.cpp +++ b/src/engine/sys_mainwind.cpp @@ -134,7 +134,7 @@ void CGame::DispatchKeyEvent(const uint64_t msTime, const ButtonCode_t buttonCod keyEvent.m_nTick = buttonCode; keyEvent.m_bDown = true; - Key_Event(keyEvent); + v_Key_Event(keyEvent); keyInfo.m_bKeyDown = true; } } diff --git a/src/vgui/vgui_baseui_interface.h b/src/vgui/vgui_baseui_interface.h index d4a5b4ea..035f0ffd 100644 --- a/src/vgui/vgui_baseui_interface.h +++ b/src/vgui/vgui_baseui_interface.h @@ -86,7 +86,7 @@ inline void*(*CEngineVGui_RenderStart)(CMatSystemSurface* pMatSystemSurface); inline CMemory p_CEngineVGui_RenderEnd; inline void*(*CEngineVGui_RenderEnd)(void); -inline InputEventCallback_t UIInputEventHandler = nullptr; +inline InputEventCallback_t v_UIInputEventHandler = nullptr; inline CEngineVGui* g_pEngineVGui = nullptr; /////////////////////////////////////////////////////////////////////////////// @@ -97,7 +97,7 @@ class VEngineVGui : public IDetour LogFunAdr("CEngineVGui::Paint", p_CEngineVGui_Paint.GetPtr()); LogFunAdr("CEngineVGui::RenderStart", p_CEngineVGui_RenderStart.GetPtr()); LogFunAdr("CEngineVGui::RenderEnd", p_CEngineVGui_RenderEnd.GetPtr()); - LogFunAdr("UIInputEventHandler", reinterpret_cast(UIInputEventHandler)); + LogFunAdr("UIInputEventHandler", reinterpret_cast(v_UIInputEventHandler)); LogVarAdr("g_pEngineVGui", reinterpret_cast(g_pEngineVGui)); } virtual void GetFun(void) const @@ -118,7 +118,7 @@ class VEngineVGui : public IDetour p_CEngineVGui_RenderEnd = g_GameDll.FindPatternSIMD("40 53 48 83 EC 20 48 8B 0D ?? ?? ?? ?? C6 05 ?? ?? ?? ?? ?? 48 8B 01"); CEngineVGui_RenderEnd = p_CEngineVGui_RenderEnd.RCast(); /*40 53 48 83 EC 20 48 8B 0D ?? ?? ?? ?? C6 05 ?? ?? ?? ?? ?? 48 8B 01*/ - UIInputEventHandler = g_GameDll.FindPatternSIMD("40 53 48 83 EC 40 48 63 01").RCast(); + g_GameDll.FindPatternSIMD("40 53 48 83 EC 40 48 63 01", v_UIInputEventHandler); } virtual void GetVar(void) const {