Add RawMouse Compoment

This commit is contained in:
LittleC 2022-04-29 16:56:51 +08:00
parent ab5ca990ab
commit 08d658644e
6 changed files with 137 additions and 0 deletions

View File

@ -137,3 +137,5 @@ namespace Components
#include "Modules/Gamepad.hpp"
#include "Modules/ScriptExtension.hpp"
#include "Modules/RawMouse.hpp"

View File

@ -0,0 +1,81 @@
#include <STDInclude.hpp>
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<bool>())
{
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<bool>("m_rawinput", true, Game::dvar_flag::DVAR_ARCHIVE, "Use raw mouse input.");
}
}

View File

@ -0,0 +1,10 @@
#pragma once
namespace Components
{
class RawMouse : public Component
{
public:
RawMouse();
};
}

View File

@ -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<XAssetHeader*>(0x7998A8);
unsigned int* g_poolSize = reinterpret_cast<unsigned int*>(0x7995E8);
@ -543,6 +548,9 @@ namespace Game
level_locals_t* level = reinterpret_cast<level_locals_t*>(0x1A831A8);
WinVars_t* g_wv = reinterpret_cast<WinVars_t*>(0x64A3AC8);
WinMouseVars_t* s_wmv = reinterpret_cast<WinMouseVars_t*>(0x649D640);
void Sys_LockRead(FastCriticalSection* critSect)
{
InterlockedIncrement(&critSect->readCount);

View File

@ -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);

View File

@ -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