Use smooth native cursor instead of the laggy in-game one.
This commit is contained in:
parent
4a26fc2bb6
commit
8a1a8c6502
@ -5,7 +5,7 @@ solution "iw4x"
|
||||
project "iw4x"
|
||||
kind "SharedLib"
|
||||
language "C++"
|
||||
files { "src/**.hpp", "src/**.cpp" }
|
||||
files { "./src/**.hpp", "./src/**.cpp" }
|
||||
--toolset "v120" -- Compatibility for users
|
||||
|
||||
configuration "Normal"
|
||||
|
@ -2,7 +2,9 @@
|
||||
|
||||
namespace Components
|
||||
{
|
||||
HWND Window::MainWindow;
|
||||
Dvar::Var Window::NoBorder;
|
||||
BOOL Window::CursorVisible;
|
||||
|
||||
void __declspec(naked) Window::StyleHookStub()
|
||||
{
|
||||
@ -18,10 +20,74 @@ namespace Components
|
||||
__asm retn
|
||||
}
|
||||
|
||||
void Window::DrawCursorStub()
|
||||
{
|
||||
Window::CursorVisible = TRUE;
|
||||
}
|
||||
|
||||
int WINAPI Window::ShowCursorHook(BOOL show)
|
||||
{
|
||||
if (GetForegroundWindow() == Window::MainWindow)
|
||||
{
|
||||
static int count = 0;
|
||||
(show ? ++count : --count);
|
||||
|
||||
if (count >= 0)
|
||||
{
|
||||
Window::CursorVisible = TRUE;
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return ShowCursor(show);
|
||||
}
|
||||
|
||||
HWND WINAPI Window::CreateMainWindow(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam)
|
||||
{
|
||||
Window::MainWindow = CreateWindowExA(dwExStyle, lpClassName, lpWindowName, dwStyle, X, Y, nWidth, nHeight, hWndParent, hMenu, hInstance, lpParam);
|
||||
return Window::MainWindow;
|
||||
}
|
||||
|
||||
Window::Window()
|
||||
{
|
||||
// Borderless window
|
||||
Window::NoBorder = Dvar::Register<bool>("r_noborder", true, Game::dvar_flag::DVAR_FLAG_SAVED, "Do not use a border in windowed mode");
|
||||
Utils::Hook(0x507643, Window::StyleHookStub, HOOK_CALL).Install()->Quick();
|
||||
|
||||
// Main window creation
|
||||
Utils::Hook::Nop(0x5076AA, 1);
|
||||
Utils::Hook(0x5076AB, Window::CreateMainWindow, HOOK_CALL).Install()->Quick();
|
||||
|
||||
// Mark the cursor as visible
|
||||
Utils::Hook(0x48E5D3, Window::DrawCursorStub, HOOK_CALL).Install()->Quick();
|
||||
|
||||
// Draw the cursor if necessary
|
||||
Renderer::OnFrame([] ()
|
||||
{
|
||||
if (GetForegroundWindow() == Window::MainWindow)
|
||||
{
|
||||
int value = 0;
|
||||
|
||||
if (Window::CursorVisible)
|
||||
{
|
||||
// TODO: Apply custom cursor
|
||||
SetCursor(LoadCursor(NULL, IDC_ARROW));
|
||||
|
||||
while ((value = ShowCursor(TRUE)) < 0);
|
||||
while (value > 0) { value = ShowCursor(FALSE); } // Set display counter to 0
|
||||
}
|
||||
else
|
||||
{
|
||||
while ((value = ShowCursor(FALSE)) >= 0);
|
||||
while (value < -1) { value = ShowCursor(TRUE); } // Set display counter to -1
|
||||
}
|
||||
|
||||
Window::CursorVisible = FALSE;
|
||||
}
|
||||
});
|
||||
|
||||
// Don't let the game interact with the native cursor
|
||||
Utils::Hook::Set(0x6D7348, Window::ShowCursorHook);
|
||||
}
|
||||
}
|
||||
|
@ -8,5 +8,15 @@ namespace Components
|
||||
|
||||
static Dvar::Var NoBorder;
|
||||
static void Window::StyleHookStub();
|
||||
|
||||
private:
|
||||
static BOOL CursorVisible;
|
||||
|
||||
static int WINAPI ShowCursorHook(BOOL show);
|
||||
static void DrawCursorStub();
|
||||
|
||||
static HWND MainWindow;
|
||||
|
||||
static HWND WINAPI CreateMainWindow(DWORD dwExStyle, LPCSTR lpClassName, LPCSTR lpWindowName, DWORD dwStyle, int X, int Y, int nWidth, int nHeight, HWND hWndParent, HMENU hMenu, HINSTANCE hInstance, LPVOID lpParam);
|
||||
};
|
||||
}
|
||||
|
@ -10,10 +10,6 @@
|
||||
#include <timeapi.h>
|
||||
#include <WinSock2.h>
|
||||
|
||||
#pragma comment(lib, "Winmm.lib")
|
||||
#pragma comment(lib, "Crypt32.lib")
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
|
||||
#include <map>
|
||||
#include <mutex>
|
||||
#include <string>
|
||||
@ -32,3 +28,8 @@
|
||||
#include "Game\Functions.hpp"
|
||||
|
||||
#include "Components\Loader.hpp"
|
||||
|
||||
// Libraries
|
||||
#pragma comment(lib, "Winmm.lib")
|
||||
#pragma comment(lib, "Crypt32.lib")
|
||||
#pragma comment(lib, "Ws2_32.lib")
|
||||
|
Loading…
Reference in New Issue
Block a user