mirror of
https://gitlab.com/Mr_Goldberg/goldberg_emulator.git
synced 2025-12-05 11:44:53 +01:00
Update nemirtingas overlay.
This commit is contained in:
parent
b72b4da8fb
commit
743a810463
22 changed files with 235 additions and 79 deletions
|
|
@ -35,7 +35,7 @@ inline void SafeRelease(T*& pUnk)
|
|||
}
|
||||
}
|
||||
|
||||
bool DX10_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool DX10_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
|
|
@ -45,7 +45,7 @@ bool DX10_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <dxgi1_2.h>
|
||||
|
||||
class DX10_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
virtual ~DX10_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static DX10_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -45,7 +45,7 @@ static HRESULT GetDeviceAndCtxFromSwapchain(IDXGISwapChain* pSwapChain, ID3D11De
|
|||
return ret;
|
||||
}
|
||||
|
||||
bool DX11_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool DX11_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
|
|
@ -55,7 +55,7 @@ bool DX11_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <dxgi1_2.h>
|
||||
|
||||
class DX11_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -65,7 +65,7 @@ public:
|
|||
|
||||
virtual ~DX11_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static DX11_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -35,7 +35,7 @@ inline void SafeRelease(T*& pUnk)
|
|||
}
|
||||
}
|
||||
|
||||
bool DX12_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool DX12_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
|
|
@ -45,7 +45,7 @@ bool DX12_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
#include <dxgi1_4.h>
|
||||
|
||||
class DX12_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -127,7 +127,7 @@ public:
|
|||
|
||||
virtual ~DX12_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static DX12_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@ inline void SafeRelease(T*& pUnk)
|
|||
}
|
||||
}
|
||||
|
||||
bool DX9_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool DX9_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
|
|
@ -46,7 +46,7 @@ bool DX9_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <d3d9.h>
|
||||
|
||||
class DX9_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
virtual ~DX9_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static DX9_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
OpenGL_Hook* OpenGL_Hook::_inst = nullptr;
|
||||
|
||||
bool OpenGL_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool OpenGL_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
|
|
@ -37,7 +37,7 @@ bool OpenGL_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@
|
|||
#include "../internal_includes.h"
|
||||
|
||||
class OpenGL_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -56,7 +56,7 @@ public:
|
|||
|
||||
virtual ~OpenGL_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static OpenGL_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
|
||||
Vulkan_Hook* Vulkan_Hook::_inst = nullptr;
|
||||
|
||||
bool Vulkan_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
||||
bool Vulkan_Hook::StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys)
|
||||
{
|
||||
SPDLOG_WARN("Vulkan overlay is not yet supported.");
|
||||
return false;
|
||||
|
|
@ -37,7 +37,7 @@ bool Vulkan_Hook::StartHook(std::function<bool(bool)> key_combination_callback)
|
|||
return false;
|
||||
}
|
||||
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback))
|
||||
if (!Windows_Hook::Inst()->StartHook(key_combination_callback, toggle_keys))
|
||||
return false;
|
||||
|
||||
_WindowsHooked = true;
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include <vulkan/vulkan.h>
|
||||
|
||||
class Vulkan_Hook :
|
||||
public Renderer_Hook,
|
||||
public ingame_overlay::Renderer_Hook,
|
||||
public Base_Hook
|
||||
{
|
||||
public:
|
||||
|
|
@ -54,7 +54,7 @@ public:
|
|||
|
||||
virtual ~Vulkan_Hook();
|
||||
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback);
|
||||
virtual bool StartHook(std::function<bool(bool)> key_combination_callback, std::set<ingame_overlay::ToggleKey> toggle_keys);
|
||||
virtual bool IsStarted();
|
||||
static Vulkan_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
|
|
|
|||
|
|
@ -29,10 +29,55 @@ constexpr decltype(Windows_Hook::DLL_NAME) Windows_Hook::DLL_NAME;
|
|||
|
||||
Windows_Hook* Windows_Hook::_inst = nullptr;
|
||||
|
||||
bool Windows_Hook::StartHook(std::function<bool(bool)>& _key_combination_callback)
|
||||
int ToggleKeyToNativeKey(ingame_overlay::ToggleKey k)
|
||||
{
|
||||
struct {
|
||||
ingame_overlay::ToggleKey lib_key;
|
||||
int native_key;
|
||||
} mapping[] = {
|
||||
{ ingame_overlay::ToggleKey::ALT , VK_MENU },
|
||||
{ ingame_overlay::ToggleKey::CTRL , VK_CONTROL },
|
||||
{ ingame_overlay::ToggleKey::SHIFT, VK_SHIFT },
|
||||
{ ingame_overlay::ToggleKey::TAB , VK_TAB },
|
||||
{ ingame_overlay::ToggleKey::F1 , VK_F1 },
|
||||
{ ingame_overlay::ToggleKey::F2 , VK_F2 },
|
||||
{ ingame_overlay::ToggleKey::F3 , VK_F3 },
|
||||
{ ingame_overlay::ToggleKey::F4 , VK_F4 },
|
||||
{ ingame_overlay::ToggleKey::F5 , VK_F5 },
|
||||
{ ingame_overlay::ToggleKey::F6 , VK_F6 },
|
||||
{ ingame_overlay::ToggleKey::F7 , VK_F7 },
|
||||
{ ingame_overlay::ToggleKey::F8 , VK_F8 },
|
||||
{ ingame_overlay::ToggleKey::F9 , VK_F9 },
|
||||
{ ingame_overlay::ToggleKey::F10 , VK_F10 },
|
||||
{ ingame_overlay::ToggleKey::F11 , VK_F11 },
|
||||
{ ingame_overlay::ToggleKey::F12 , VK_F12 },
|
||||
};
|
||||
|
||||
for (auto const& item : mapping)
|
||||
{
|
||||
if (item.lib_key == k)
|
||||
return item.native_key;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool Windows_Hook::StartHook(std::function<bool(bool)>& _key_combination_callback, std::set<ingame_overlay::ToggleKey> const& toggle_keys)
|
||||
{
|
||||
if (!_Hooked)
|
||||
{
|
||||
if (!_key_combination_callback)
|
||||
{
|
||||
SPDLOG_ERROR("Failed to hook Windows: No key combination callback.");
|
||||
return false;
|
||||
}
|
||||
|
||||
if (toggle_keys.empty())
|
||||
{
|
||||
SPDLOG_ERROR("Failed to hook Windows: No key combination.");
|
||||
return false;
|
||||
}
|
||||
|
||||
void* hUser32 = System::Library::GetLibraryHandle(DLL_NAME);
|
||||
if (hUser32 == nullptr)
|
||||
{
|
||||
|
|
@ -71,6 +116,15 @@ bool Windows_Hook::StartHook(std::function<bool(bool)>& _key_combination_callbac
|
|||
SPDLOG_INFO("Hooked Windows");
|
||||
_KeyCombinationCallback = std::move(_key_combination_callback);
|
||||
|
||||
for (auto& key : toggle_keys)
|
||||
{
|
||||
uint32_t k = ToggleKeyToNativeKey(key);
|
||||
if (k != 0)
|
||||
{
|
||||
_NativeKeyCombination.insert(k);
|
||||
}
|
||||
}
|
||||
|
||||
BeginHook();
|
||||
HookFuncs(
|
||||
std::make_pair<void**, void*>(&(PVOID&)GetRawInputBuffer, &Windows_Hook::MyGetRawInputBuffer),
|
||||
|
|
@ -134,12 +188,9 @@ bool Windows_Hook::PrepareForOverlay(HWND hWnd)
|
|||
POINT pos;
|
||||
if (this->GetCursorPos(&pos) && ScreenToClient(hWnd, &pos))
|
||||
{
|
||||
io.MousePos = ImVec2((float)pos.x, (float)pos.y);
|
||||
io.AddMousePosEvent((float)pos.x, (float)pos.y);
|
||||
}
|
||||
|
||||
io.KeyCtrl = (this->GetKeyState(VK_CONTROL) & 0x8000) != 0;
|
||||
io.KeyShift = (this->GetKeyState(VK_SHIFT) & 0x8000) != 0;
|
||||
io.KeyAlt = (this->GetKeyState(VK_MENU) & 0x8000) != 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -219,13 +270,18 @@ LRESULT CALLBACK Windows_Hook::HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||
if (inst->_Initialized)
|
||||
{
|
||||
// Is the event is a key press
|
||||
if (uMsg == WM_KEYDOWN)
|
||||
if (uMsg == WM_KEYDOWN || uMsg == WM_SYSKEYDOWN || uMsg == WM_KEYUP || uMsg == WM_SYSKEYUP)
|
||||
{
|
||||
// Tab is pressed and was not pressed before
|
||||
if (wParam == VK_TAB && !(lParam & (1 << 30)))
|
||||
int key_count = 0;
|
||||
for (auto const& key : inst->_NativeKeyCombination)
|
||||
{
|
||||
// If Left Shift is pressed
|
||||
if (inst->GetAsyncKeyState(VK_LSHIFT) & (1 << 15))
|
||||
if (inst->GetAsyncKeyState(key) & (1 << 15))
|
||||
++key_count;
|
||||
}
|
||||
|
||||
if (key_count == inst->_NativeKeyCombination.size())
|
||||
{// All shortcut keys are pressed
|
||||
if (!inst->_KeyCombinationPushed)
|
||||
{
|
||||
if (inst->_KeyCombinationCallback(true))
|
||||
{
|
||||
|
|
@ -234,12 +290,13 @@ LRESULT CALLBACK Windows_Hook::HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||
// so we can spoof the GetCursorPos return value.
|
||||
inst->GetCursorPos(&inst->_SavedCursorPos);
|
||||
}
|
||||
else
|
||||
{
|
||||
clean_keys = true;
|
||||
}
|
||||
inst->_KeyCombinationPushed = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
inst->_KeyCombinationPushed = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (skip_input && IgnoreMsg(uMsg))
|
||||
|
|
@ -248,7 +305,8 @@ LRESULT CALLBACK Windows_Hook::HookWndProc(HWND hWnd, UINT uMsg, WPARAM wParam,
|
|||
if (clean_keys)
|
||||
{
|
||||
auto& io = ImGui::GetIO();
|
||||
memset(io.KeysDown, 0, sizeof(io.KeysDown));
|
||||
io.ClearInputKeys();
|
||||
io.ClearInputCharacters();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -369,6 +427,7 @@ Windows_Hook::Windows_Hook() :
|
|||
_RecurseCallCount(0),
|
||||
_GameHwnd(nullptr),
|
||||
_GameWndProc(nullptr),
|
||||
_KeyCombinationPushed(false),
|
||||
GetRawInputBuffer(nullptr),
|
||||
GetRawInputData(nullptr),
|
||||
GetKeyState(nullptr),
|
||||
|
|
|
|||
|
|
@ -38,6 +38,12 @@ private:
|
|||
WNDPROC _GameWndProc;
|
||||
POINT _SavedCursorPos;
|
||||
|
||||
// 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;
|
||||
|
||||
// Functions
|
||||
Windows_Hook();
|
||||
|
||||
|
|
@ -59,10 +65,6 @@ private:
|
|||
static BOOL WINAPI MyGetCursorPos(LPPOINT lpPoint);
|
||||
static BOOL WINAPI MySetCursorPos(int X, int Y);
|
||||
|
||||
// In (bool): Is toggle wanted
|
||||
// Out(bool): Is the overlay visible, if true, inputs will be disabled
|
||||
std::function<bool(bool)> _KeyCombinationCallback;
|
||||
|
||||
public:
|
||||
std::string LibraryName;
|
||||
|
||||
|
|
@ -75,7 +77,7 @@ public:
|
|||
HWND GetGameHwnd() const;
|
||||
WNDPROC GetGameWndProc() const;
|
||||
|
||||
bool StartHook(std::function<bool(bool)>& key_combination_callback);
|
||||
bool StartHook(std::function<bool(bool)>& key_combination_callback, std::set<ingame_overlay::ToggleKey> const& toggle_keys);
|
||||
static Windows_Hook* Inst();
|
||||
virtual std::string GetLibraryName() const;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue