mirror of
https://github.com/Mauler125/r5sdk.git
synced 2025-02-09 19:15:03 +01:00
EngineAPI: key event dispatcher rebuild
This commit is contained in:
parent
30518e1f64
commit
d42ca04e8c
@ -28,6 +28,8 @@ ConVar* fps_max_rt = nullptr;
|
||||
ConVar* fps_max_rt_tolerance = nullptr;
|
||||
ConVar* fps_max_rt_sleep_threshold = nullptr;
|
||||
ConVar* fps_max_gfx = nullptr;
|
||||
|
||||
ConVar* in_syncRT = nullptr;
|
||||
#endif // !DEDICATED
|
||||
|
||||
ConVar* base_tickinterval_sp = nullptr;
|
||||
@ -565,6 +567,7 @@ void ConVar_InitShipped(void)
|
||||
#ifndef DEDICATED
|
||||
miles_language = g_pCVar->FindVar("miles_language");
|
||||
rui_defaultDebugFontFace = g_pCVar->FindVar("rui_defaultDebugFontFace");
|
||||
in_syncRT = g_pCVar->FindVar("in_syncRT");
|
||||
r_visualizetraces = g_pCVar->FindVar("r_visualizetraces");
|
||||
r_visualizetraces_duration = g_pCVar->FindVar("r_visualizetraces_duration");
|
||||
#endif // !DEDICATED
|
||||
|
@ -19,6 +19,8 @@ extern ConVar* fps_max_rt;
|
||||
extern ConVar* fps_max_rt_tolerance;
|
||||
extern ConVar* fps_max_rt_sleep_threshold;
|
||||
extern ConVar* fps_max_gfx;
|
||||
|
||||
extern ConVar* in_syncRT;
|
||||
#endif // !DEDICATED
|
||||
|
||||
extern ConVar* base_tickinterval_sp;
|
||||
|
@ -41,6 +41,8 @@ struct KeyInfo_t
|
||||
short paddingMaybe;
|
||||
};
|
||||
|
||||
inline bool(*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
|
||||
extern short* g_nKeyEventCount;
|
||||
@ -49,11 +51,15 @@ class VKeys : public IDetour
|
||||
{
|
||||
virtual void GetAdr(void) const
|
||||
{
|
||||
LogFunAdr("Key_Event", reinterpret_cast<uintptr_t>(Key_Event));
|
||||
LogVarAdr("g_pKeyInfo", reinterpret_cast<uintptr_t>(g_pKeyInfo));
|
||||
LogVarAdr("g_pKeyEventTicks", reinterpret_cast<uintptr_t>(g_pKeyEventTicks));
|
||||
LogVarAdr("g_nKeyEventCount", reinterpret_cast<uintptr_t>(g_nKeyEventCount));
|
||||
}
|
||||
virtual void GetFun(void) const { }
|
||||
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<bool(*)(const KeyEvent_t&)>();
|
||||
}
|
||||
virtual void GetVar(void) const
|
||||
{
|
||||
g_pKeyInfo = g_GameDll.FindPatternSIMD("48 83 EC 28 33 D2 48 8D 0D ?? ?? ?? ?? 41 B8 ?? ?? ?? ?? E8 ?? ?? ?? ?? 33 C0 C6 05 ?? ?? ?? ?? ??")
|
||||
|
@ -17,6 +17,8 @@
|
||||
#include "engine/traceinit.h"
|
||||
#ifndef DEDICATED
|
||||
#include "engine/sys_mainwind.h"
|
||||
#include "inputsystem/inputsystem.h"
|
||||
#include "vgui/vgui_baseui_interface.h"
|
||||
#include "materialsystem/cmaterialsystem.h"
|
||||
#include "windows/id3dx.h"
|
||||
#include "client/vengineclient_impl.h"
|
||||
@ -162,7 +164,18 @@ void CEngineAPI::VSetStartupInfo(CEngineAPI* pEngineAPI, StartupInfo_t* pStartup
|
||||
void CEngineAPI::PumpMessages()
|
||||
{
|
||||
#ifndef DEDICATED
|
||||
CEngineAPI_PumpMessages();
|
||||
MSG msg;
|
||||
while (PeekMessageW(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessageW(&msg);
|
||||
}
|
||||
|
||||
if (in_syncRT->GetBool())
|
||||
(*g_fnSyncRTWithIn)();
|
||||
|
||||
g_pInputSystem->PollInputState(UIInputEventHandler);
|
||||
g_pGame->DispatchAllStoredGameMessages();
|
||||
#endif // !DEDICATED
|
||||
}
|
||||
|
||||
|
@ -9,6 +9,7 @@
|
||||
#include "windows/input.h"
|
||||
#include "engine/sys_mainwind.h"
|
||||
#include "engine/sys_engine.h"
|
||||
#include "engine/keys.h"
|
||||
#include "gameui/IConsole.h"
|
||||
#include "gameui/IBrowser.h"
|
||||
|
||||
@ -97,7 +98,7 @@ int CGame::WindowProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: gets the window rect
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGame::GetWindowRect(int* x, int* y, int* w, int* h)
|
||||
void CGame::GetWindowRect(int* const x, int* const y, int* const w, int* const h) const
|
||||
{
|
||||
if (x)
|
||||
{
|
||||
@ -117,6 +118,41 @@ void CGame::GetWindowRect(int* x, int* y, int* w, int* h)
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: dispatch key event
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGame::DispatchKeyEvent(const uint64_t msTime, const ButtonCode_t buttonCode) const
|
||||
{
|
||||
const float duration = buttonCode == KEY_XBUTTON_BACK ? 1.0f : 0.2f;
|
||||
KeyInfo_t& keyInfo = g_pKeyInfo[buttonCode];
|
||||
|
||||
if (keyInfo.m_bKeyDown && ((msTime - keyInfo.m_nEventTick) * 0.001f) >= duration)
|
||||
{
|
||||
KeyEvent_t keyEvent;
|
||||
|
||||
keyEvent.m_pCommand = keyInfo.m_pKeyBinding[KeyInfo_t::KEY_HELD_BIND];
|
||||
keyEvent.m_nTick = buttonCode;
|
||||
keyEvent.m_bDown = true;
|
||||
|
||||
Key_Event(keyEvent);
|
||||
keyInfo.m_bKeyDown = true;
|
||||
}
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: dispatch all the queued up messages
|
||||
//-----------------------------------------------------------------------------
|
||||
void CGame::DispatchAllStoredGameMessages() const
|
||||
{
|
||||
const uint64_t ticks = Plat_MSTime();
|
||||
const short eventCount = *g_nKeyEventCount;
|
||||
|
||||
for (short i = 0; i < eventCount; i++)
|
||||
{
|
||||
DispatchKeyEvent(ticks, g_pKeyEventTicks[i]);
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
void VGame::Detour(const bool bAttach) const
|
||||
{
|
||||
|
@ -5,6 +5,7 @@
|
||||
//===========================================================================//
|
||||
#ifndef SYS_MAINWIND_H
|
||||
#define SYS_MAINWIND_H
|
||||
#include "inputsystem/iinputsystem.h"
|
||||
|
||||
inline CMemory p_CGame__AttachToWindow;
|
||||
inline void (*v_CGame__AttachToWindow)(void);
|
||||
@ -25,7 +26,7 @@ public:
|
||||
|
||||
|
||||
inline HWND GetWindow() const { return m_hWindow; }
|
||||
void GetWindowRect(int* x, int* y, int* w, int* h);
|
||||
void GetWindowRect(int* const x, int* const y, int* const w, int* const h) const;
|
||||
|
||||
inline int GetDesktopWidth() const { return m_iDesktopWidth; }
|
||||
inline int GetDesktopHeight() const { return m_iDesktopHeight; }
|
||||
@ -33,6 +34,9 @@ public:
|
||||
inline float GetTVRefreshRate() const // Avoid stutter on TV's running on broadcast frame rates.
|
||||
{ return ((float)m_iDesktopRefreshRate == 59.0f || (float)m_iDesktopRefreshRate == 60.0f) ? 59.939999f : (float)m_iDesktopRefreshRate; }
|
||||
|
||||
void DispatchKeyEvent(const uint64_t msTime, const ButtonCode_t buttonCode) const;
|
||||
void DispatchAllStoredGameMessages() const;
|
||||
|
||||
private:
|
||||
HWND m_hWindow;
|
||||
HINSTANCE m_hInstance;
|
||||
|
@ -51,3 +51,4 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
CInputSystem* g_pInputSystem = nullptr;
|
||||
bool(**g_fnSyncRTWithIn)(void) = nullptr;
|
||||
|
@ -163,6 +163,7 @@ static_assert(sizeof(CInputSystem) == 0x18E8);
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
extern CInputSystem* g_pInputSystem;
|
||||
extern bool(**g_fnSyncRTWithIn)(void); // Belongs to an array of callbacks, see CMaterialSystem::MatsysMode_Init().
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
class VInputSystem : public IDetour
|
||||
@ -170,12 +171,16 @@ class VInputSystem : public IDetour
|
||||
virtual void GetAdr(void) const
|
||||
{
|
||||
LogVarAdr("g_pInputSystem", reinterpret_cast<uintptr_t>(g_pInputSystem));
|
||||
LogVarAdr("g_fnSyncRTWithIn", reinterpret_cast<uintptr_t>(g_fnSyncRTWithIn));
|
||||
}
|
||||
virtual void GetFun(void) const { }
|
||||
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")
|
||||
.FindPatternSelf("48 89 05", CMemory::Direction::DOWN, 40).ResolveRelativeAddressSelf(0x3, 0x7).RCast<CInputSystem*>();
|
||||
|
||||
const CMemory l_EngineApi_PumpMessages = g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 55 48 81 EC ?? ?? ?? ?? 45 33 C9");
|
||||
g_fnSyncRTWithIn = l_EngineApi_PumpMessages.FindPattern("74 06").FindPatternSelf("FF 15").ResolveRelativeAddressSelf(2, 6).RCast<bool(**)(void)>();
|
||||
}
|
||||
virtual void GetCon(void) const { }
|
||||
virtual void Detour(const bool bAttach) const { }
|
||||
|
@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
#include <engine/server/sv_main.h>
|
||||
#include <vguimatsurface/MatSystemSurface.h>
|
||||
#include "inputsystem/iinputsystem.h"
|
||||
|
||||
enum class PaintMode_t
|
||||
{
|
||||
@ -85,6 +86,7 @@ inline void*(*CEngineVGui_RenderStart)(CMatSystemSurface* pMatSystemSurface);
|
||||
inline CMemory p_CEngineVGui_RenderEnd;
|
||||
inline void*(*CEngineVGui_RenderEnd)(void);
|
||||
|
||||
inline InputEventCallback_t UIInputEventHandler = nullptr;
|
||||
inline CEngineVGui* g_pEngineVGui = nullptr;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -95,6 +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<uintptr_t>(UIInputEventHandler));
|
||||
LogVarAdr("g_pEngineVGui", reinterpret_cast<uintptr_t>(g_pEngineVGui));
|
||||
}
|
||||
virtual void GetFun(void) const
|
||||
@ -114,6 +117,8 @@ class VEngineVGui : public IDetour
|
||||
#endif
|
||||
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<void* (*)(void)>(); /*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<InputEventCallback_t>();
|
||||
}
|
||||
virtual void GetVar(void) const
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user