From e2438e1ff18d1c5cdbe15e47a51a0388bb011b26 Mon Sep 17 00:00:00 2001 From: Peter Repukat Date: Sat, 30 Dec 2017 17:36:26 +0100 Subject: [PATCH] Use memory adress of overlay instead of winmessages --- SteamTarget/SteamTargetRenderer.cpp | 39 ++++------------------------- SteamTarget/SteamTargetRenderer.h | 3 +-- 2 files changed, 6 insertions(+), 36 deletions(-) diff --git a/SteamTarget/SteamTargetRenderer.cpp b/SteamTarget/SteamTargetRenderer.cpp index 778d5da..dd971d8 100644 --- a/SteamTarget/SteamTargetRenderer.cpp +++ b/SteamTarget/SteamTargetRenderer.cpp @@ -15,10 +15,8 @@ limitations under the License. */ #include "SteamTargetRenderer.h" -std::atomic SteamTargetRenderer::overlayOpen = false; -HHOOK SteamTargetRenderer::hook = nullptr; -std::atomic SteamTargetRenderer::bHookSteam = false; +std::atomic SteamTargetRenderer::bHookSteam = false; SteamTargetRenderer::SteamTargetRenderer(int& argc, char** argv) : QApplication(argc, argv) { @@ -88,9 +86,9 @@ SteamTargetRenderer::SteamTargetRenderer(int& argc, char** argv) : QApplication( if (hmodGameOverlayRenderer != nullptr) { - //Hook MessageQueue to detect if overlay gets opened / closed - //Steam Posts a Message with 0x14FA / 0x14F7 when the overlay gets opened / closed - hook = SetWindowsHookEx(WH_GETMESSAGE, HookCallback, nullptr, GetCurrentThreadId()); + + overlayOpen = reinterpret_cast(uint64_t(hmodGameOverlayRenderer) + 0x13A63C); + } @@ -110,12 +108,6 @@ SteamTargetRenderer::SteamTargetRenderer(int& argc, char** argv) : QApplication( SteamTargetRenderer::~SteamTargetRenderer() { - - if (hmodGameOverlayRenderer != nullptr) - { - UnhookWindowsHookEx(hook); - } - renderThread.join(); if (controllerThread.isRunning()) controllerThread.stop(); @@ -179,7 +171,7 @@ void SteamTargetRenderer::RunSfWindowLoop() //Window focus trickery if (hmodGameOverlayRenderer != nullptr) { - if (overlayOpen) + if (*overlayOpen) { if (!bNeedFocusSwitch) { @@ -356,27 +348,6 @@ void SteamTargetRenderer::moveMouseIntoOverlay() } -//WinHook Callback to check if the overlay is opened/closed -LRESULT WINAPI SteamTargetRenderer::HookCallback(int nCode, WPARAM wParam, LPARAM lParam) -{ - if (nCode >= 0) - { - PMSG msg = reinterpret_cast(lParam); - std::cout << "DEBUG: " << "message: " << msg->message << std::endl; - if (msg->message == 0x14FA) //Posted when the overlay gets opened - { - overlayOpen = true; - std::cout << "Overlay Opened!\n"; - } - else if (msg->message == 0x14F7 || msg->message == 0x14FD || msg->message == 512 || msg->message == 0x2a3) - { - overlayOpen = false; - std::cout << "Overlay closed!\n"; - } - } - return CallNextHookEx(hook, nCode, wParam, lParam); -} - void SteamTargetRenderer::unhookBindings() { if (bHookSteam) diff --git a/SteamTarget/SteamTargetRenderer.h b/SteamTarget/SteamTargetRenderer.h index 016b71f..a2ad4f7 100644 --- a/SteamTarget/SteamTargetRenderer.h +++ b/SteamTarget/SteamTargetRenderer.h @@ -91,8 +91,7 @@ private: #else WCHAR* overlayModuleName = L"GameOverlayRenderer.dll"; #endif - static std::atomic overlayOpen; - static HHOOK hook; + uint64_t *overlayOpen; HWND hwForeGroundWindow = nullptr; bool bNeedFocusSwitch = false;