2022-08-05 06:06:42 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) Nemirtingas
|
|
|
|
* This file is part of the ingame overlay project
|
|
|
|
*
|
|
|
|
* The ingame overlay project is free software; you can redistribute it
|
|
|
|
* and/or modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 3 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* The ingame overlay project is distributed in the hope that it will be
|
|
|
|
* useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with the ingame overlay project; if not, see
|
|
|
|
* <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2019-08-18 14:22:07 +00:00
|
|
|
|
2022-08-05 06:06:42 +00:00
|
|
|
#pragma once
|
2019-08-18 14:22:07 +00:00
|
|
|
|
2022-08-05 06:06:42 +00:00
|
|
|
#include "../internal_includes.h"
|
2019-08-18 14:22:07 +00:00
|
|
|
|
2022-08-05 06:06:42 +00:00
|
|
|
class Windows_Hook :
|
|
|
|
public Base_Hook
|
2019-08-18 14:22:07 +00:00
|
|
|
{
|
|
|
|
public:
|
2022-08-05 06:06:42 +00:00
|
|
|
static constexpr const char* DLL_NAME = "user32.dll";
|
2019-08-18 14:22:07 +00:00
|
|
|
|
|
|
|
private:
|
2019-08-27 13:38:07 +00:00
|
|
|
static Windows_Hook* _inst;
|
|
|
|
|
2019-08-18 14:22:07 +00:00
|
|
|
// Variables
|
2022-08-05 06:06:42 +00:00
|
|
|
bool _Hooked;
|
|
|
|
bool _Initialized;
|
|
|
|
int _RecurseCallCount;
|
|
|
|
HWND _GameHwnd;
|
|
|
|
WNDPROC _GameWndProc;
|
|
|
|
POINT _SavedCursorPos;
|
2022-08-16 16:29:58 +00:00
|
|
|
RECT _SavedClipCursor;
|
|
|
|
CONST RECT _DefaultClipCursor;
|
2019-08-18 14:22:07 +00:00
|
|
|
|
2022-08-13 18:32:43 +00:00
|
|
|
// In (bool): Is toggle wanted
|
|
|
|
// Out(bool): Is the overlay visible, if true, inputs will be disabled
|
|
|
|
std::function<bool(bool)> _KeyCombinationCallback;
|
|
|
|
std::set<int> _NativeKeyCombination;
|
|
|
|
bool _KeyCombinationPushed;
|
|
|
|
|
2019-08-18 14:22:07 +00:00
|
|
|
// Functions
|
|
|
|
Windows_Hook();
|
|
|
|
|
|
|
|
// Hook to Windows window messages
|
2022-08-05 06:06:42 +00:00
|
|
|
decltype(::GetRawInputBuffer) *GetRawInputBuffer;
|
|
|
|
decltype(::GetRawInputData) *GetRawInputData;
|
|
|
|
decltype(::GetKeyState) *GetKeyState;
|
|
|
|
decltype(::GetAsyncKeyState) *GetAsyncKeyState;
|
|
|
|
decltype(::GetKeyboardState) *GetKeyboardState;
|
|
|
|
decltype(::GetCursorPos) *GetCursorPos;
|
|
|
|
decltype(::SetCursorPos) *SetCursorPos;
|
2022-08-16 16:29:58 +00:00
|
|
|
decltype(::GetClipCursor) *GetClipCursor;
|
|
|
|
decltype(::ClipCursor) *ClipCursor;
|
2019-08-18 14:22:07 +00:00
|
|
|
|
|
|
|
static LRESULT CALLBACK HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
|
2022-08-05 06:06:42 +00:00
|
|
|
static UINT WINAPI MyGetRawInputBuffer(PRAWINPUT pData, PUINT pcbSize, UINT cbSizeHeader);
|
|
|
|
static UINT WINAPI MyGetRawInputData(HRAWINPUT hRawInput, UINT uiCommand, LPVOID pData, PUINT pcbSize, UINT cbSizeHeader);
|
|
|
|
static SHORT WINAPI MyGetKeyState(int nVirtKey);
|
|
|
|
static SHORT WINAPI MyGetAsyncKeyState(int vKey);
|
|
|
|
static BOOL WINAPI MyGetKeyboardState(PBYTE lpKeyState);
|
|
|
|
static BOOL WINAPI MyGetCursorPos(LPPOINT lpPoint);
|
|
|
|
static BOOL WINAPI MySetCursorPos(int X, int Y);
|
2022-08-16 16:29:58 +00:00
|
|
|
static BOOL WINAPI MyGetClipCursor(RECT* lpRect);
|
|
|
|
static BOOL WINAPI MyClipCursor(CONST RECT* lpRect);
|
2022-08-05 06:06:42 +00:00
|
|
|
|
2019-08-18 14:22:07 +00:00
|
|
|
public:
|
2022-08-05 06:06:42 +00:00
|
|
|
std::string LibraryName;
|
|
|
|
|
2019-08-27 13:38:07 +00:00
|
|
|
virtual ~Windows_Hook();
|
|
|
|
|
2022-08-10 07:22:23 +00:00
|
|
|
void ResetRenderState();
|
|
|
|
void SetInitialWindowSize(HWND hWnd);
|
|
|
|
bool PrepareForOverlay(HWND hWnd);
|
2019-08-18 14:22:07 +00:00
|
|
|
|
|
|
|
HWND GetGameHwnd() const;
|
|
|
|
WNDPROC GetGameWndProc() const;
|
|
|
|
|
2022-08-13 18:32:43 +00:00
|
|
|
bool StartHook(std::function<bool(bool)>& key_combination_callback, std::set<ingame_overlay::ToggleKey> const& toggle_keys);
|
2019-08-27 13:38:07 +00:00
|
|
|
static Windows_Hook* Inst();
|
2022-08-05 06:06:42 +00:00
|
|
|
virtual std::string GetLibraryName() const;
|
2019-08-18 14:22:07 +00:00
|
|
|
};
|