Style fixes

This commit is contained in:
GEEKiDoS 2022-04-30 01:42:47 +08:00
parent 237a89fa71
commit c2c62cd72e
5 changed files with 24 additions and 26 deletions

View File

@ -134,8 +134,6 @@ namespace Components
#include "Modules/Movement.hpp" #include "Modules/Movement.hpp"
#include "Modules/Elevators.hpp" #include "Modules/Elevators.hpp"
#include "Modules/ClientCommand.hpp" #include "Modules/ClientCommand.hpp"
#include "Modules/Gamepad.hpp" #include "Modules/Gamepad.hpp"
#include "Modules/ScriptExtension.hpp" #include "Modules/ScriptExtension.hpp"
#include "Modules/RawMouse.hpp" #include "Modules/RawMouse.hpp"

View File

@ -2,7 +2,9 @@
namespace Components namespace Components
{ {
Dvar::Var RawMouse::m_rawinput; Dvar::Var RawMouse::useRawInput;
int RawMouse::mouseRawX = 0;
int RawMouse::mouseRawY = 0;
void RawMouse::IN_ClampMouseMove() void RawMouse::IN_ClampMouseMove()
{ {
@ -11,7 +13,7 @@ namespace Components
GetCursorPos(&curPos); GetCursorPos(&curPos);
GetWindowRect(Game::g_wv->hWnd, &rc); GetWindowRect(Game::g_wv->hWnd, &rc);
bool isClamped = false; auto isClamped = false;
if (curPos.x >= rc.left) if (curPos.x >= rc.left)
{ {
if (curPos.x >= rc.right) if (curPos.x >= rc.right)
@ -45,12 +47,9 @@ namespace Components
} }
} }
int RawMouse::mouseRawX = 0;
int RawMouse::mouseRawY = 0;
BOOL RawMouse::OnRawInput(LPARAM lParam, WPARAM) BOOL RawMouse::OnRawInput(LPARAM lParam, WPARAM)
{ {
UINT dwSize = sizeof(RAWINPUT); auto dwSize = sizeof(RAWINPUT);
static BYTE lpb[sizeof(RAWINPUT)]; static BYTE lpb[sizeof(RAWINPUT)];
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER)); GetRawInputData((HRAWINPUT)lParam, RID_INPUT, lpb, &dwSize, sizeof(RAWINPUTHEADER));
@ -76,17 +75,17 @@ namespace Components
void RawMouse::IN_RawMouseMove() void RawMouse::IN_RawMouseMove()
{ {
static Game::dvar_t* r_fullscreen = Game::Dvar_FindVar("r_fullscreen"); static auto r_fullscreen = Dvar::Var("r_fullscreen");
if (GetForegroundWindow() == Game::g_wv->hWnd) if (GetForegroundWindow() == Game::g_wv->hWnd)
{ {
if (r_fullscreen->current.enabled) if (r_fullscreen.get<bool>())
IN_ClampMouseMove(); IN_ClampMouseMove();
static int oldX = 0, oldY = 0; static auto oldX = 0, oldY = 0;
int dx = mouseRawX - oldX; auto dx = mouseRawX - oldX;
int dy = mouseRawY - oldY; auto dy = mouseRawY - oldY;
oldX = mouseRawX; oldX = mouseRawX;
oldY = mouseRawY; oldY = mouseRawY;
@ -109,9 +108,9 @@ namespace Components
void RawMouse::IN_RawMouse_Init() void RawMouse::IN_RawMouse_Init()
{ {
static bool init = false; static auto init = false;
if (Game::g_wv->hWnd && !init && m_rawinput.get<bool>()) if (Game::g_wv->hWnd && !init && RawMouse::useRawInput.get<bool>())
{ {
#ifdef DEBUG #ifdef DEBUG
Logger::Print("Raw Mouse Init.\n"); Logger::Print("Raw Mouse Init.\n");
@ -137,7 +136,7 @@ namespace Components
void RawMouse::IN_MouseMove() void RawMouse::IN_MouseMove()
{ {
if (m_rawinput.get<bool>()) if (RawMouse::useRawInput.get<bool>())
{ {
IN_RawMouseMove(); IN_RawMouseMove();
} }
@ -156,10 +155,12 @@ namespace Components
Utils::Hook(0x467C03, RawMouse::IN_Init, HOOK_CALL).install()->quick(); Utils::Hook(0x467C03, RawMouse::IN_Init, HOOK_CALL).install()->quick();
Utils::Hook(0x64D095, RawMouse::IN_Init, HOOK_JUMP).install()->quick(); Utils::Hook(0x64D095, RawMouse::IN_Init, HOOK_JUMP).install()->quick();
m_rawinput = Dvar::Register<bool>("m_rawinput", true, Game::dvar_flag::DVAR_ARCHIVE, "Use raw mouse input, use in_restart to take effect if not enabled."); Dvar::OnInit([]()
{
RawMouse::useRawInput = Dvar::Register<bool>("m_rawinput", true, Game::dvar_flag::DVAR_ARCHIVE, "Use raw mouse input, use in_restart to take effect if not enabled.");
});
Window::OnWndMessage(WM_INPUT, RawMouse::OnRawInput); Window::OnWndMessage(WM_INPUT, RawMouse::OnRawInput);
Window::OnCreate(RawMouse::IN_RawMouse_Init); Window::OnCreate(RawMouse::IN_RawMouse_Init);
} }
} }

View File

@ -7,7 +7,7 @@ namespace Components
public: public:
RawMouse(); RawMouse();
private: private:
static Dvar::Var m_rawinput; static Dvar::Var useRawInput;
static int mouseRawX, mouseRawY; static int mouseRawX, mouseRawY;
static void IN_ClampMouseMove(); static void IN_ClampMouseMove();

View File

@ -147,9 +147,9 @@ namespace Components
BOOL WINAPI Window::MessageHandler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) BOOL WINAPI Window::MessageHandler(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{ {
if (WndMessageCallbacks.find(Msg) != WndMessageCallbacks.end()) if (const auto cb = WndMessageCallbacks.find(Msg); cb != WndMessageCallbacks.end())
{ {
return WndMessageCallbacks[Msg](lParam, wParam); return cb->second(lParam, wParam);
} }
return Utils::Hook::Call<BOOL(__stdcall)(HWND, UINT, WPARAM, LPARAM)>(0x4731F0)(hWnd, Msg, wParam, lParam); return Utils::Hook::Call<BOOL(__stdcall)(HWND, UINT, WPARAM, LPARAM)>(0x4731F0)(hWnd, Msg, wParam, lParam);

View File

@ -1008,16 +1008,16 @@ namespace Game
typedef int(__cdecl * CL_MouseEvent_t)(int x, int y, int dx, int dy); typedef int(__cdecl * CL_MouseEvent_t)(int x, int y, int dx, int dy);
extern CL_MouseEvent_t CL_MouseEvent; extern CL_MouseEvent_t CL_MouseEvent;
typedef void(*IN_RecenterMouse_t)(); typedef void(__cdecl * IN_RecenterMouse_t)();
extern IN_RecenterMouse_t IN_RecenterMouse; extern IN_RecenterMouse_t IN_RecenterMouse;
typedef void(*IN_MouseMove_t)(); typedef void(__cdecl * IN_MouseMove_t)();
extern IN_MouseMove_t IN_MouseMove; extern IN_MouseMove_t IN_MouseMove;
typedef void(*IN_Init_t)(); typedef void(__cdecl * IN_Init_t)();
extern IN_Init_t IN_Init; extern IN_Init_t IN_Init;
typedef void(*IN_Shutdown_t)(); typedef void(__cdecl * IN_Shutdown_t)();
extern IN_Shutdown_t IN_Shutdown; extern IN_Shutdown_t IN_Shutdown;
extern XAssetHeader* DB_XAssetPool; extern XAssetHeader* DB_XAssetPool;
@ -1154,7 +1154,6 @@ namespace Game
extern int* window_center_x; extern int* window_center_x;
extern int* window_center_y; extern int* window_center_y;
void Sys_LockRead(FastCriticalSection* critSect); void Sys_LockRead(FastCriticalSection* critSect);
void Sys_UnlockRead(FastCriticalSection* critSect); void Sys_UnlockRead(FastCriticalSection* critSect);