diff --git a/src/Components/Loader.hpp b/src/Components/Loader.hpp index 34b278d9..583ffed7 100644 --- a/src/Components/Loader.hpp +++ b/src/Components/Loader.hpp @@ -137,3 +137,5 @@ namespace Components #include "Modules/Gamepad.hpp" #include "Modules/ScriptExtension.hpp" + +#include "Modules/RawMouse.hpp" diff --git a/src/Components/Modules/RawMouse.cpp b/src/Components/Modules/RawMouse.cpp new file mode 100644 index 00000000..846024e0 --- /dev/null +++ b/src/Components/Modules/RawMouse.cpp @@ -0,0 +1,81 @@ +#include + +namespace Components +{ + void IN_ClampMouseMove() + { + tagRECT rc; + tagPOINT curPos; + + GetCursorPos(&curPos); + GetWindowRect(Game::g_wv->hWnd, &rc); + bool isClamped = false; + if (curPos.x >= rc.left) + { + if (curPos.x >= rc.right) + { + curPos.x = rc.right - 1; + isClamped = true; + } + } + else + { + curPos.x = rc.left; + isClamped = true; + } + if (curPos.y >= rc.top) + { + if (curPos.y >= rc.bottom) + { + curPos.y = rc.bottom - 1; + isClamped = true; + } + } + else + { + curPos.y = rc.top; + isClamped = true; + } + + if (isClamped) + { + SetCursorPos(curPos.x, curPos.y); + } + } + + void IN_RawMouseMove() + { + static Game::dvar_t* r_fullscreen = Game::Dvar_FindVar("r_fullscreen"); + + if (GetForegroundWindow() == Game::g_wv->hWnd) + { + if (r_fullscreen->current.enabled) + IN_ClampMouseMove(); + + + } + } + + Dvar::Var Mouse_RawInput; + + void IN_MouseMove() + { + if (Mouse_RawInput.get()) + { + IN_RawMouseMove(); + } + else + { + Game::IN_MouseMove(); + } + } + + RawMouse::RawMouse() + { + Utils::Hook(0x475E65, IN_MouseMove, HOOK_JUMP).install()->quick(); + Utils::Hook(0x475E8D, IN_MouseMove, HOOK_JUMP).install()->quick(); + Utils::Hook(0x475E9E, IN_MouseMove, HOOK_JUMP).install()->quick(); + + Mouse_RawInput = Dvar::Register("m_rawinput", true, Game::dvar_flag::DVAR_ARCHIVE, "Use raw mouse input."); + } +} diff --git a/src/Components/Modules/RawMouse.hpp b/src/Components/Modules/RawMouse.hpp new file mode 100644 index 00000000..4c55ab86 --- /dev/null +++ b/src/Components/Modules/RawMouse.hpp @@ -0,0 +1,10 @@ +#pragma once + +namespace Components +{ + class RawMouse : public Component + { + public: + RawMouse(); + }; +} diff --git a/src/Game/Functions.cpp b/src/Game/Functions.cpp index e5d95eb9..2f394389 100644 --- a/src/Game/Functions.cpp +++ b/src/Game/Functions.cpp @@ -421,6 +421,11 @@ namespace Game PM_Trace_t PM_Trace = PM_Trace_t(0x441F60); PM_GetEffectiveStance_t PM_GetEffectiveStance = PM_GetEffectiveStance_t(0x412540); + CL_MouseEvent_t CL_MouseEvent = CL_MouseEvent_t(0x4D7C50); + IN_RecenterMouse_t IN_RecenterMouse = IN_RecenterMouse_t(0x463D80); + + IN_MouseMove_t IN_MouseMove = IN_MouseMove_t(0x64C490); + XAssetHeader* DB_XAssetPool = reinterpret_cast(0x7998A8); unsigned int* g_poolSize = reinterpret_cast(0x7995E8); @@ -543,6 +548,9 @@ namespace Game level_locals_t* level = reinterpret_cast(0x1A831A8); + WinVars_t* g_wv = reinterpret_cast(0x64A3AC8); + WinMouseVars_t* s_wmv = reinterpret_cast(0x649D640); + void Sys_LockRead(FastCriticalSection* critSect) { InterlockedIncrement(&critSect->readCount); diff --git a/src/Game/Functions.hpp b/src/Game/Functions.hpp index 5d705227..044e3c43 100644 --- a/src/Game/Functions.hpp +++ b/src/Game/Functions.hpp @@ -1005,6 +1005,15 @@ namespace Game typedef EffectiveStance(__cdecl * PM_GetEffectiveStance_t)(const playerState_s* ps); extern PM_GetEffectiveStance_t PM_GetEffectiveStance; + typedef int(__cdecl * CL_MouseEvent_t)(int x, int y, int dx, int dy); + extern CL_MouseEvent_t CL_MouseEvent; + + typedef void(*IN_RecenterMouse_t)(); + extern IN_RecenterMouse_t IN_RecenterMouse; + + typedef void(*IN_MouseMove_t)(); + extern IN_MouseMove_t IN_MouseMove; + extern XAssetHeader* DB_XAssetPool; extern unsigned int* g_poolSize; @@ -1133,6 +1142,9 @@ namespace Game extern level_locals_t* level; + extern WinVars_t* g_wv; + extern WinMouseVars_t* s_wmv; + void Sys_LockRead(FastCriticalSection* critSect); void Sys_UnlockRead(FastCriticalSection* critSect); diff --git a/src/Game/Structs.hpp b/src/Game/Structs.hpp index 70beb4a9..487767e8 100644 --- a/src/Game/Structs.hpp +++ b/src/Game/Structs.hpp @@ -7473,6 +7473,30 @@ namespace Game static_assert(sizeof(level_locals_t) == 0x2F78); + struct WinVars_t + { + HINSTANCE reflib_library; + int reflib_active; + HWND hWnd; + HINSTANCE hInstance; + int activeApp; + int isMinimized; + int hasFocus; + int activationStateChanged; + int recenterMouse; + HHOOK lowLevelKeyboardHook; + unsigned int sysMsgTime; + }; + + struct WinMouseVars_t + { + int oldButtonState; + tagPOINT oldPos; + bool mouseActive; + bool mouseInitialized; + }; + + #pragma endregion #ifndef IDA