From f0180aaf27ad412feccef84f9257c5d6a09d0d4b Mon Sep 17 00:00:00 2001 From: Londo Mollari Date: Sun, 13 Nov 2016 19:32:42 -0800 Subject: [PATCH] version 0.8.1 --- build/Installer32/Product.wxs | 2 +- build/Installer64/Product.wxs | 2 +- source/Core/Root.hpp | 2 +- source/Core/Windows/ShellUi.cpp | 15 +++++--- source/Core/Windows/SystemMonitor.cpp | 15 ++++++-- source/Core/Windows/SystemMonitor.hpp | 3 ++ source/YoloMouse/Dll/App.cpp | 27 ++++++++------- source/YoloMouse/Dll/App.hpp | 1 + source/YoloMouse/Loader/Main.cpp | 50 ++++++++++++++++----------- source/YoloMouse/Share/Constants.hpp | 2 +- 10 files changed, 77 insertions(+), 42 deletions(-) diff --git a/build/Installer32/Product.wxs b/build/Installer32/Product.wxs index 35944d4..0c4081d 100644 --- a/build/Installer32/Product.wxs +++ b/build/Installer32/Product.wxs @@ -1,6 +1,6 @@ - + diff --git a/build/Installer64/Product.wxs b/build/Installer64/Product.wxs index c9dc4c1..0f98d70 100644 --- a/build/Installer64/Product.wxs +++ b/build/Installer64/Product.wxs @@ -1,6 +1,6 @@ - + diff --git a/source/Core/Root.hpp b/source/Core/Root.hpp index f55b2c2..aa3ea5e 100644 --- a/source/Core/Root.hpp +++ b/source/Core/Root.hpp @@ -28,7 +28,7 @@ #define MAKEHUGE(low, high) ((unsigned long long)(low) | ((unsigned long long)(high) << 32)) // defines -#define LOG_PATH "d:\\debug.log"//!!! +#define LOG_PATH "debug.log" #define INVALID_ID (~0) #define INVALID_INDEX (~0) diff --git a/source/Core/Windows/ShellUi.cpp b/source/Core/Windows/ShellUi.cpp index f69d1fe..afb7c05 100644 --- a/source/Core/Windows/ShellUi.cpp +++ b/source/Core/Windows/ShellUi.cpp @@ -321,11 +321,18 @@ namespace Core void ShellUi::Stop() { - // destroy window - DestroyWindow(_hwnd); + // if window created + if( _hwnd != NULL ) + { + // destroy window + DestroyWindow(_hwnd); + + // unregister class + UnregisterClass(_name, _hinstance); - // unregister class - UnregisterClass(_name, _hinstance); + // clear state + _hwnd = NULL; + } } //-------------------------------------------------------------------------- diff --git a/source/Core/Windows/SystemMonitor.cpp b/source/Core/Windows/SystemMonitor.cpp index 3415d42..adff522 100644 --- a/source/Core/Windows/SystemMonitor.cpp +++ b/source/Core/Windows/SystemMonitor.cpp @@ -40,12 +40,23 @@ namespace Core //------------------------------------------------------------------------- Bool SystemMonitor::Start() { - return - SetWinEventHook(EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL, _WinEvent, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS) != 0; + // set window event hook + _handle = SetWinEventHook( EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL, _WinEvent, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS ); + + return _handle != NULL; } //------------------------------------------------------------------------- void SystemMonitor::Stop() { + // if window event hook set + if( _handle != NULL ) + { + // destroy window event hook + UnhookWinEvent(_handle); + + // clear state + _handle = NULL; + } } } diff --git a/source/Core/Windows/SystemMonitor.hpp b/source/Core/Windows/SystemMonitor.hpp index ca8fad0..2b915d6 100644 --- a/source/Core/Windows/SystemMonitor.hpp +++ b/source/Core/Windows/SystemMonitor.hpp @@ -20,5 +20,8 @@ namespace Core /**/ Bool Start(); void Stop(); + + // fields + HWINEVENTHOOK _handle = NULL; }; } diff --git a/source/YoloMouse/Dll/App.cpp b/source/YoloMouse/Dll/App.cpp index c009522..f906553 100644 --- a/source/YoloMouse/Dll/App.cpp +++ b/source/YoloMouse/Dll/App.cpp @@ -7,6 +7,7 @@ namespace YoloMouse // fields //------------------------------------------------------------------------- Bool App::_active (false); + HWND App::_hwnd = NULL; CursorBindings App::_bindings; CursorVault App::_vault; HandleCache App::_cache; @@ -177,6 +178,9 @@ namespace YoloMouse return false; } + // update active window + _hwnd = hwnd; + // get thread id of this thread (the one Loader's CreateRemoteThread created). DWORD current_thread_id = GetCurrentThreadId(); @@ -201,17 +205,8 @@ namespace YoloMouse // set refresh state _refresh_ready = true; - // set current cursor to force update using SetClassLong method - #if CPU_64 - SetClassLongPtrA(hwnd, GCLP_HCURSOR, (LONG_PTR)refresh_cursor); - #else - SetClassLongA(hwnd, GCL_HCURSOR, (LONG)refresh_cursor); - #endif - - // next use SetCursor/PostMassage method in case SetClassLong method doesn't work - // set current cursor to force update - SetCursor(refresh_cursor); + SetCursor( refresh_cursor ); // then trigger application to call SetCursor with its own cursor PostMessage(hwnd, WM_SETCURSOR, (WPARAM)hwnd, MAKELPARAM(HTCLIENT, WM_MOUSEMOVE)); @@ -594,8 +589,16 @@ namespace YoloMouse //------------------------------------------------------------------------- VOID HOOK_CALL App::_OnHookSetCursor( Native* arguments ) { - // update cursor - _OnCursorHook((HCURSOR&)arguments[1], (HCURSOR)arguments[1]); + // update cursor using setclasslong method first + #if CPU_64 + SetClassLongPtrA( _hwnd, GCLP_HCURSOR, (LONG_PTR)arguments[1] ); + #else + SetClassLongA( _hwnd, GCL_HCURSOR, (LONG)arguments[1] ); + #endif + + // if replacement cursor was set pass it out to setcursor method + if( _replace_cursor != NULL ) + arguments[1] = (Native)_replace_cursor; } VOID HOOK_CALL App::_OnHookSetClassLong( Native* arguments ) diff --git a/source/YoloMouse/Dll/App.hpp b/source/YoloMouse/Dll/App.hpp index 11a2acc..85a7834 100644 --- a/source/YoloMouse/Dll/App.hpp +++ b/source/YoloMouse/Dll/App.hpp @@ -49,6 +49,7 @@ namespace YoloMouse // fields: state static Bool _active; + static HWND _hwnd; static CursorBindings _bindings; static CursorVault _vault; static HandleCache _cache; diff --git a/source/YoloMouse/Loader/Main.cpp b/source/YoloMouse/Loader/Main.cpp index 9ad7865..f2dde25 100644 --- a/source/YoloMouse/Loader/Main.cpp +++ b/source/YoloMouse/Loader/Main.cpp @@ -23,22 +23,41 @@ namespace YoloMouse //------------------------------------------------------------------------- static ExitStatus Main() { - App app; + App app; + ExitStatus status; - // start - app.Start(); + // run main + try + { + // start + app.Start(); + + // run + app.Run(); - // run - app.Run(); + // stop + app.Stop(); - // stop - app.Stop(); + // normal or elevated exit + status = app.GetElevate() ? EXIT_ELEVATE : EXIT_NORMAL; + } + // catch eggs + catch( const Char* error ) + { + // show error message + SharedTools::MessagePopup(true, error); + + // stop + app.Stop(); + + // error exit + status = EXIT_PLATFORM_MAIN; + } - // return exit status - return app.GetElevate() ? EXIT_ELEVATE : EXIT_NORMAL; + return status; } - // debugging + // unit testing area //------------------------------------------------------------------------- void _UnitTest() { @@ -84,16 +103,7 @@ int WINAPI WinMain( if(SystemTools::GetProcessDirectory(path, COUNT(path)) && SetCurrentDirectory(path)) { // run main - try - { - status = Main(); - } - // catch eggs - catch( const Char* error ) - { - SharedTools::MessagePopup(true, error); - status = EXIT_PLATFORM_MAIN; - } + status = Main(); } // path change failed else diff --git a/source/YoloMouse/Share/Constants.hpp b/source/YoloMouse/Share/Constants.hpp index 933c841..4d4e6fd 100644 --- a/source/YoloMouse/Share/Constants.hpp +++ b/source/YoloMouse/Share/Constants.hpp @@ -63,7 +63,7 @@ namespace YoloMouse // numeric //------------------------------------------------------------------------- - static const ULong APP_VERSION[] = { 0, 8, 0 }; + static const ULong APP_VERSION[] = { 0, 8, 1 }; static const ULong APP_NAME_LIMIT = 64; static const ULong LOG_MEMORY_LIMIT = KILOBYTES(8); static const ULong LOADER_TARGET_LIMIT = 20;