├── LICENSE.md ├── README.TXT ├── bin └── Cursors │ └── Default │ ├── 0.cur │ ├── 1.cur │ ├── 10.cur │ ├── 11.cur │ ├── 12.cur │ ├── 13.cur │ ├── 14.cur │ ├── 15.cur │ ├── 16.cur │ ├── 17.cur │ ├── 18.cur │ ├── 19.cur │ ├── 2.cur │ ├── 20.cur │ ├── 21.cur │ ├── 22.cur │ ├── 23.cur │ ├── 24.cur │ ├── 25.cur │ ├── 26.cur │ ├── 27.cur │ ├── 28.cur │ ├── 29.cur │ ├── 3.cur │ ├── 30.cur │ ├── 31.cur │ ├── 32.cur │ ├── 33.cur │ ├── 34.cur │ ├── 35.cur │ ├── 36.cur │ ├── 37.cur │ ├── 38.cur │ ├── 39.cur │ ├── 4.cur │ ├── 5.cur │ ├── 6.cur │ ├── 7.cur │ ├── 8.cur │ ├── 80.ani │ └── 9.cur ├── build ├── Core │ ├── Core.vcxproj │ ├── Core.vcxproj.filters │ └── Core.vcxproj.user ├── Installer32 │ ├── Installer32.wixproj │ └── Product.wxs ├── Installer64 │ ├── Installer64.wixproj │ └── Product.wxs ├── Snoopy │ ├── Snoopy.vcxproj │ └── Snoopy.vcxproj.filters ├── YoloMouse.Dll │ ├── YoloMouse.Dll.vcxproj │ ├── YoloMouse.Dll.vcxproj.filters │ └── YoloMouse.Dll.vcxproj.user ├── YoloMouse.Loader │ ├── YoloMouse.Loader.vcxproj │ ├── YoloMouse.Loader.vcxproj.filters │ └── YoloMouse.Loader.vcxproj.user ├── YoloMouse.Share │ ├── YoloMouse.Share.vcxproj │ ├── YoloMouse.Share.vcxproj.filters │ └── YoloMouse.Share.vcxproj.user └── YoloMouse.sln ├── etc └── EULA.rtf └── source ├── Core ├── Constants.hpp ├── Container │ ├── Array.hpp │ ├── Array2.hpp │ ├── List.hpp │ ├── Map.hpp │ └── String.hpp ├── Events │ ├── SystemMonitorEvent.hpp │ └── WindowEvent.hpp ├── Math │ ├── Math.cpp │ ├── Math.hpp │ ├── Matrix4.cpp │ ├── Matrix4.hpp │ ├── Number.cpp │ ├── Number.hpp │ ├── Quaternion.cpp │ ├── Quaternion.hpp │ ├── Transform3.cpp │ ├── Transform3.hpp │ ├── Vector2.cpp │ ├── Vector2.hpp │ ├── Vector3.cpp │ ├── Vector3.hpp │ ├── Vector4.cpp │ └── Vector4.hpp ├── Root.cpp ├── Root.hpp ├── Support │ ├── Enum.hpp │ ├── EventDispatcher.hpp │ ├── Settings.cpp │ ├── Settings.hpp │ ├── Singleton.hpp │ ├── Tools.cpp │ └── Tools.hpp ├── System │ ├── Debug.cpp │ ├── Debug.hpp │ ├── IpcPair.cpp │ ├── IpcPair.hpp │ ├── SystemTools.cpp │ └── SystemTools.hpp ├── Type │ ├── Default.hpp │ └── Tuple.hpp ├── Types.hpp ├── UI │ ├── Window.cpp │ └── Window.hpp └── Windows │ ├── InputMonitor.cpp │ ├── InputMonitor.hpp │ ├── SharedMemory.hpp │ ├── ShellUi.cpp │ ├── ShellUi.hpp │ ├── SystemMonitor.cpp │ ├── SystemMonitor.hpp │ ├── WindowTools.cpp │ └── WindowTools.hpp ├── Snoopy ├── Hook │ ├── Hook.cpp │ └── Hook.hpp ├── Inject │ ├── Injector.cpp │ └── Injector.hpp ├── Root.hpp └── X86 │ ├── Assembly.cpp │ ├── Assembly.hpp │ ├── Enums.hpp │ ├── Types.hpp │ └── hde │ ├── hde32.cpp │ ├── hde32.hpp │ ├── hde64.cpp │ ├── hde64.hpp │ ├── table32.hpp │ └── table64.hpp └── YoloMouse ├── Dll ├── Core │ ├── App.cpp │ └── App.hpp ├── Cursor │ ├── HandleCache.cpp │ └── HandleCache.hpp └── Main.cpp ├── Loader ├── Core │ ├── App.cpp │ └── App.hpp ├── Events │ ├── InjectSessionEvent.hpp │ └── OverlayEvent.hpp ├── Inject │ ├── InjectEnvironment.cpp │ ├── InjectEnvironment.hpp │ ├── InjectSession.cpp │ └── InjectSession.hpp ├── Main.cpp ├── Overlay │ ├── Cursor │ │ ├── CursorFactory.cpp │ │ ├── CursorFactory.hpp │ │ ├── Cursors │ │ │ ├── ArrowCursor.cpp │ │ │ ├── ArrowCursor.hpp │ │ │ ├── BaseCursor.cpp │ │ │ ├── BaseCursor.hpp │ │ │ ├── BasicCursor.cpp │ │ │ ├── BasicCursor.hpp │ │ │ ├── CircleCursor.cpp │ │ │ └── CircleCursor.hpp │ │ ├── IOverlayCursor.hpp │ │ ├── OverlayCursorVault.cpp │ │ └── OverlayCursorVault.hpp │ ├── Mouse │ │ ├── MousePositionMonitor.cpp │ │ └── MousePositionMonitor.hpp │ ├── Overlay.cpp │ ├── Overlay.hpp │ ├── Rendering │ │ ├── Assets │ │ │ ├── Mesh.cpp │ │ │ ├── Mesh.hpp │ │ │ ├── Texture.cpp │ │ │ └── Texture.hpp │ │ ├── RenderContext.cpp │ │ ├── RenderContext.hpp │ │ ├── Shaders │ │ │ ├── Default │ │ │ │ ├── PixelShader.hlsl │ │ │ │ ├── PixelShader.hpp │ │ │ │ ├── VertexShader.hlsl │ │ │ │ └── VertexShader.hpp │ │ │ └── ShaderTypes.hpp │ │ ├── Support │ │ │ ├── RenderTimingController.cpp │ │ │ ├── RenderTimingController.hpp │ │ │ ├── RenderTools.cpp │ │ │ └── RenderTools.hpp │ │ └── Types.hpp │ └── Text │ │ ├── FontAtlas.cpp │ │ ├── FontAtlas.hpp │ │ ├── FontMapBuilder.cpp │ │ ├── FontMapBuilder.hpp │ │ ├── TextMesh.cpp │ │ ├── TextMesh.hpp │ │ ├── TextPopup.cpp │ │ └── TextPopup.hpp ├── Resource │ ├── AppIcon.ico │ ├── Resource.aps │ ├── Resource.rc │ └── resource.h └── Target │ ├── Support │ ├── CursorVisibilityHacker.cpp │ └── CursorVisibilityHacker.hpp │ ├── Target.cpp │ ├── Target.hpp │ ├── TargetController.cpp │ └── TargetController.hpp └── Share ├── Constants.cpp ├── Constants.hpp ├── Cursor ├── CursorBindings.cpp ├── CursorBindings.hpp ├── CursorBindingsSerializer.cpp ├── CursorBindingsSerializer.hpp ├── CursorInfo.cpp ├── CursorInfo.hpp ├── CursorTools.cpp ├── CursorTools.hpp ├── CursorTypes.hpp ├── CursorVault.cpp └── CursorVault.hpp ├── Enums.hpp ├── Ipc ├── IpcMessage.hpp ├── IpcMessenger.cpp └── IpcMessenger.hpp ├── Root.cpp └── Root.hpp /LICENSE.md: -------------------------------------------------------------------------------- 1 | This is free and unencumbered software released into the public domain. 2 | 3 | Anyone is free to copy, modify, publish, use, compile, sell, or 4 | distribute this software, either in source code form or as a compiled 5 | binary, for any purpose, commercial or non-commercial, and by any 6 | means. 7 | 8 | In jurisdictions that recognize copyright laws, the author or authors 9 | of this software dedicate any and all copyright interest in the 10 | software to the public domain. We make this dedication for the benefit 11 | of the public at large and to the detriment of our heirs and 12 | successors. We intend this dedication to be an overt act of 13 | relinquishment in perpetuity of all present and future rights to this 14 | software under copyright law. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 19 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 20 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 21 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 22 | OTHER DEALINGS IN THE SOFTWARE. 23 | 24 | For more information, please refer to 25 | -------------------------------------------------------------------------------- /README.TXT: -------------------------------------------------------------------------------- 1 | Users 2 | ------------------------------------------------------------------------------- 3 | Please visit https://pandateemo.github.io/YoloMouse/ 4 | 5 | Engineers 6 | ------------------------------------------------------------------------------- 7 | Not much to say at the moment other than that it requires Wix to build the 8 | installer. Get it at http://wixtoolset.org/ 9 | 10 | Also build win32 before x64 because 64 bit yolomouse depends on the 32 bit dll. 11 | -------------------------------------------------------------------------------- /bin/Cursors/Default/0.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/0.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/1.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/1.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/10.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/10.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/11.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/11.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/12.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/12.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/13.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/13.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/14.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/14.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/15.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/15.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/16.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/16.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/17.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/17.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/18.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/18.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/19.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/19.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/2.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/2.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/20.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/20.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/21.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/21.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/22.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/22.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/23.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/23.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/24.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/24.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/25.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/25.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/26.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/26.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/27.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/27.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/28.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/28.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/29.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/29.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/3.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/3.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/30.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/30.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/31.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/31.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/32.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/32.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/33.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/33.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/34.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/34.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/35.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/35.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/36.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/36.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/37.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/37.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/38.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/38.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/39.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/39.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/4.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/4.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/5.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/5.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/6.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/6.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/7.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/7.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/8.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/8.cur -------------------------------------------------------------------------------- /bin/Cursors/Default/80.ani: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/80.ani -------------------------------------------------------------------------------- /bin/Cursors/Default/9.cur: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/bin/Cursors/Default/9.cur -------------------------------------------------------------------------------- /build/Core/Core.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /build/Installer32/Installer32.wixproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 3.8 7 | 438cb4f0-1123-469b-abf3-a108cf8daeee 8 | 2.0 9 | YoloMouse32 10 | Package 11 | $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets 12 | $(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets 13 | 14 | 15 | bin\$(Configuration)\ 16 | obj\$(Configuration)\ 17 | Debug 18 | 19 | 20 | ..\..\final\ 21 | obj\$(Configuration)\ 22 | ICE69 23 | True 24 | 25 | 26 | 27 | 28 | 29 | 30 | $(WixExtDir)\WixUtilExtension.dll 31 | WixUtilExtension 32 | 33 | 34 | $(WixExtDir)\WixUIExtension.dll 35 | WixUIExtension 36 | 37 | 38 | 39 | 40 | YoloMouse.Dll 41 | {72a90a09-4805-4396-9922-cf33e648a286} 42 | True 43 | True 44 | Binaries;Content;Satellites 45 | INSTALLFOLDER 46 | 47 | 48 | YoloMouse.Loader 49 | {2e39b614-b7de-44df-8fdd-2021ef7918c8} 50 | True 51 | True 52 | Binaries;Content;Satellites 53 | INSTALLFOLDER 54 | 55 | 56 | 57 | 65 | -------------------------------------------------------------------------------- /build/Installer64/Installer64.wixproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | Debug 5 | x86 6 | 3.8 7 | 971aee4d-ce99-44fc-b9ed-11420005f5ef 8 | 2.0 9 | YoloMouse64 10 | Package 11 | $(MSBuildExtensionsPath32)\Microsoft\WiX\v3.x\Wix.targets 12 | $(MSBuildExtensionsPath)\Microsoft\WiX\v3.x\Wix.targets 13 | 14 | 15 | bin\$(Configuration)\ 16 | obj\$(Configuration)\ 17 | Debug 18 | 19 | 20 | ..\..\final\ 21 | obj\$(Configuration)\ 22 | True 23 | ICE69 24 | 25 | 26 | 27 | 28 | 29 | 30 | $(WixExtDir)\WixUtilExtension.dll 31 | WixUtilExtension 32 | 33 | 34 | $(WixExtDir)\WixUIExtension.dll 35 | WixUIExtension 36 | 37 | 38 | 39 | 40 | YoloMouse.Dll 41 | {72a90a09-4805-4396-9922-cf33e648a286} 42 | True 43 | True 44 | Binaries;Content;Satellites 45 | INSTALLFOLDER 46 | 47 | 48 | YoloMouse.Loader 49 | {2e39b614-b7de-44df-8fdd-2021ef7918c8} 50 | True 51 | True 52 | Binaries;Content;Satellites 53 | INSTALLFOLDER 54 | 55 | 56 | 57 | 65 | -------------------------------------------------------------------------------- /build/Snoopy/Snoopy.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | {dd8f2561-8980-48f0-9ef5-76e1ab620847} 6 | 7 | 8 | {e150bfb1-5658-4ac9-b4ed-4fea896032f6} 9 | 10 | 11 | {30b390f8-7ef5-46ba-a996-aa73c41ca632} 12 | 13 | 14 | {c4108095-0ca9-406d-ac9d-ae35a3a9eb66} 15 | 16 | 17 | 18 | 19 | 20 | X86 21 | 22 | 23 | X86 24 | 25 | 26 | X86 27 | 28 | 29 | X86\hde 30 | 31 | 32 | X86\hde 33 | 34 | 35 | X86\hde 36 | 37 | 38 | X86\hde 39 | 40 | 41 | Inject 42 | 43 | 44 | Hook 45 | 46 | 47 | 48 | 49 | X86 50 | 51 | 52 | X86\hde 53 | 54 | 55 | X86\hde 56 | 57 | 58 | Inject 59 | 60 | 61 | Hook 62 | 63 | 64 | -------------------------------------------------------------------------------- /build/YoloMouse.Dll/YoloMouse.Dll.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Core 7 | 8 | 9 | Cursor 10 | 11 | 12 | 13 | 14 | {9d26c30b-b465-4fca-9b8e-01408f3822b1} 15 | 16 | 17 | {d84faf92-b37e-49db-aec4-d23346efc97a} 18 | 19 | 20 | 21 | 22 | Core 23 | 24 | 25 | Cursor 26 | 27 | 28 | -------------------------------------------------------------------------------- /build/YoloMouse.Dll/YoloMouse.Dll.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutDir) 5 | WindowsLocalDebugger 6 | 7 | 8 | $(OutDir) 9 | WindowsLocalDebugger 10 | 11 | 12 | $(OutDir) 13 | WindowsLocalDebugger 14 | 15 | 16 | $(OutDir) 17 | WindowsLocalDebugger 18 | 19 | -------------------------------------------------------------------------------- /build/YoloMouse.Loader/YoloMouse.Loader.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(OutDir) 5 | WindowsLocalDebugger 6 | _NO_DEBUG_HEAP=1 7 | 8 | 9 | $(OutDir) 10 | WindowsLocalDebugger 11 | _NO_DEBUG_HEAP=1 12 | 13 | 14 | $(OutDir) 15 | WindowsLocalDebugger 16 | 17 | 18 | $(OutDir) 19 | WindowsLocalDebugger 20 | 21 | -------------------------------------------------------------------------------- /build/YoloMouse.Share/YoloMouse.Share.vcxproj.filters: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | Ipc 7 | 8 | 9 | 10 | Cursor 11 | 12 | 13 | Cursor 14 | 15 | 16 | Cursor 17 | 18 | 19 | Cursor 20 | 21 | 22 | Cursor 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | Ipc 31 | 32 | 33 | Ipc 34 | 35 | 36 | Cursor 37 | 38 | 39 | Cursor 40 | 41 | 42 | Cursor 43 | 44 | 45 | Cursor 46 | 47 | 48 | Cursor 49 | 50 | 51 | Cursor 52 | 53 | 54 | 55 | 56 | {e52f3b00-ca6d-4bcf-90fa-96e765c75da0} 57 | 58 | 59 | {2baec6ad-ce25-435b-ac5b-40b0ac161089} 60 | 61 | 62 | -------------------------------------------------------------------------------- /build/YoloMouse.Share/YoloMouse.Share.vcxproj.user: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | -------------------------------------------------------------------------------- /source/Core/Constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | // enums 7 | //------------------------------------------------------------------------- 8 | enum Bitness 9 | { 10 | BITNESS_32, 11 | BITNESS_64, 12 | BITNESS_COUNT, 13 | BITNESS_UNKNOWN, 14 | }; 15 | 16 | enum OsVersion 17 | { 18 | OSVERSION_UNKNOWN, 19 | OSVERSION_WIN2K = 0x0500, 20 | OSVERSION_WINXP = 0x0501, 21 | OSVERSION_WINXPPRO = 0x0502, 22 | OSVERSION_WINVISTA = 0x0600, 23 | OSVERSION_WIN7 = 0x0601, 24 | OSVERSION_WIN8 = 0x0602, 25 | OSVERSION_WIN81 = 0x0603, 26 | }; 27 | 28 | // numeric 29 | //------------------------------------------------------------------------- 30 | static const ULong STRING_SHORT_SIZE = 16; 31 | static const ULong STRING_MEDIUM_SIZE = 64; 32 | static const ULong STRING_MAX_SIZE = 512; 33 | static const ULong STRING_LINE_SIZE = 128; 34 | static const ULong STRING_PATH_SIZE = STRING_MAX_SIZE; 35 | static const ULong GAME_WINDOW_MIN_WIDTH = 240; 36 | static const ULong GAME_WINDOW_MIN_HEIGHT = 240; 37 | } 38 | -------------------------------------------------------------------------------- /source/Core/Events/SystemMonitorEvent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | /**/ 8 | struct SystemMonitorEvent 9 | { 10 | // enums 11 | enum EventId: Id 12 | { 13 | WINDOW_FOREGROUND, 14 | }; 15 | 16 | // fields 17 | EventId id; 18 | HWND hwnd; 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /source/Core/Events/WindowEvent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | // forward defs 8 | //------------------------------------------------------------------------- 9 | class Window; 10 | 11 | /**/ 12 | struct WindowEvent 13 | { 14 | Window* window; 15 | UINT msg; 16 | WPARAM wparam; 17 | LPARAM lparam; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /source/Core/Math/Math.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Core 5 | { 6 | // explicit instantiations 7 | //------------------------------------------------------------------------- 8 | template class Math; 9 | template class Math; 10 | template class Math; 11 | 12 | // statics 13 | //------------------------------------------------------------------------- 14 | template<> const Float Math::PI = 3.14159274f; 15 | template<> const Long Math::PI = 3; 16 | template<> const ULong Math::PI = 3; 17 | template<> const Float Math::PI2 = 6.28318530f; 18 | template<> const Long Math::PI2 = 6; 19 | template<> const ULong Math::PI2 = 6; 20 | 21 | //------------------------------------------------------------------------- 22 | template<> 23 | Float Math::SquareRoot( Float value ) 24 | { 25 | return std::sqrtf(value); 26 | } 27 | template<> 28 | Long Math::SquareRoot( Long value ) 29 | { 30 | return 0; 31 | } 32 | template<> 33 | ULong Math::SquareRoot( ULong value ) 34 | { 35 | return 0; 36 | } 37 | 38 | //------------------------------------------------------------------------- 39 | template<> 40 | Float Math::Absolute( Float value ) 41 | { 42 | return static_cast(std::fabs( value )); 43 | } 44 | template<> 45 | Long Math::Absolute( Long value ) 46 | { 47 | return static_cast(std::abs( value )); 48 | } 49 | template<> 50 | ULong Math::Absolute( ULong value ) 51 | { 52 | return value; 53 | } 54 | 55 | //------------------------------------------------------------------------- 56 | template<> 57 | Float Math::Sin( Float radians ) 58 | { 59 | return std::sinf(radians); 60 | } 61 | template 62 | TYPE Math::Sin( TYPE radians ) 63 | { 64 | ASSERT_TODO; 65 | return 0; 66 | } 67 | 68 | template<> 69 | Float Math::ArcSin( Float radians ) 70 | { 71 | return std::asinf(radians); 72 | } 73 | template 74 | TYPE Math::ArcSin( TYPE radians ) 75 | { 76 | ASSERT_TODO; 77 | return 0; 78 | } 79 | 80 | template<> 81 | Float Math::Cos( Float radians ) 82 | { 83 | return std::cosf(radians); 84 | } 85 | template 86 | TYPE Math::Cos( TYPE radians ) 87 | { 88 | ASSERT_TODO; 89 | return 0; 90 | } 91 | 92 | template<> 93 | Float Math::ArcCos( Float radians ) 94 | { 95 | return std::acosf(radians); 96 | } 97 | template 98 | TYPE Math::ArcCos( TYPE radians ) 99 | { 100 | ASSERT_TODO; 101 | return 0; 102 | } 103 | 104 | template<> 105 | Float Math::Tan( Float radians ) 106 | { 107 | return std::tanf(radians); 108 | } 109 | template 110 | TYPE Math::Tan( TYPE radians ) 111 | { 112 | ASSERT_TODO; 113 | return 0; 114 | } 115 | 116 | template<> 117 | Float Math::ArcTan( Float x, Float y ) 118 | { 119 | return std::atan2f(y, x); 120 | } 121 | template 122 | TYPE Math::ArcTan( TYPE x, TYPE y ) 123 | { 124 | ASSERT_TODO; 125 | return 0; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /source/Core/Math/Math.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class Math 9 | { 10 | public: 11 | // constants 12 | static const TYPE PI; 13 | static const TYPE PI2; 14 | 15 | /**/ 16 | static TYPE SquareRoot( TYPE value ); 17 | 18 | /**/ 19 | static TYPE Absolute( TYPE value ); 20 | 21 | /**/ 22 | static TYPE Sin( TYPE radians ); 23 | static TYPE ArcSin( TYPE radians ); 24 | 25 | static TYPE Cos( TYPE radians ); 26 | static TYPE ArcCos( TYPE radians ); 27 | 28 | static TYPE Tan( TYPE radians ); 29 | static TYPE ArcTan( TYPE x, TYPE y ); 30 | }; 31 | } 32 | -------------------------------------------------------------------------------- /source/Core/Math/Matrix4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class BaseMatrix4 9 | { 10 | public: 11 | // types 12 | typedef TYPE Type; 13 | typedef BaseVector3 VectorType; 14 | 15 | // constants 16 | static BaseMatrix4 IDENTITY(); 17 | static BaseMatrix4 ZERO(); 18 | 19 | /**/ 20 | BaseMatrix4() = default; 21 | BaseMatrix4( 22 | TYPE e00_, TYPE e01_, TYPE e02_, TYPE e03_, 23 | TYPE e10_, TYPE e11_, TYPE e12_, TYPE e13_, 24 | TYPE e20_, TYPE e21_, TYPE e22_, TYPE e23_, 25 | TYPE e30_, TYPE e31_, TYPE e32_, TYPE e33_ ); 26 | 27 | /**/ 28 | TYPE* operator[]( Index row ); 29 | const TYPE* operator[]( Index row ) const; 30 | BaseMatrix4 operator * ( const BaseMatrix4 &o ) const; 31 | VectorType operator * ( const VectorType& v ) const; 32 | BaseMatrix4 operator + ( const BaseMatrix4 &w ) const; 33 | BaseMatrix4 operator - ( const BaseMatrix4 &w ) const; 34 | 35 | /**/ 36 | void Set( 37 | TYPE e00_, TYPE e01_, TYPE e02_, TYPE e03_, 38 | TYPE e10_, TYPE e11_, TYPE e12_, TYPE e13_, 39 | TYPE e20_, TYPE e21_, TYPE e22_, TYPE e23_, 40 | TYPE e30_, TYPE e31_, TYPE e32_, TYPE e33_ ); 41 | 42 | /**/ 43 | void Translate( TYPE x, TYPE y, TYPE z ); 44 | void Scale( TYPE x, TYPE y, TYPE z ); 45 | 46 | /**/ 47 | BaseMatrix4 Transpose(void) const; 48 | BaseMatrix4 Inverse() const; 49 | 50 | // fields 51 | union 52 | { 53 | TYPE m1[16]; 54 | TYPE m2[4][4]; 55 | struct 56 | { 57 | TYPE e00; TYPE e01; TYPE e02; TYPE e03; 58 | TYPE e10; TYPE e11; TYPE e12; TYPE e13; 59 | TYPE e20; TYPE e21; TYPE e22; TYPE e23; 60 | TYPE e30; TYPE e31; TYPE e32; TYPE e33; 61 | }; 62 | }; 63 | }; 64 | 65 | // common typedefs 66 | //------------------------------------------------------------------------- 67 | typedef BaseMatrix4 Matrix4f; 68 | } 69 | -------------------------------------------------------------------------------- /source/Core/Math/Number.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Core 5 | { 6 | // explicit instantiations 7 | //------------------------------------------------------------------------- 8 | template class Number; 9 | template class Number; 10 | template class Number; 11 | template class Number; 12 | template class Number; 13 | template class Number; 14 | 15 | // local 16 | //------------------------------------------------------------------------- 17 | namespace 18 | { 19 | /**/ 20 | template 21 | Index _GetLowBit( TYPE value ) 22 | { 23 | ASSERT( value != 0 ); 24 | Index index = 0; 25 | 26 | while( true ) 27 | { 28 | if( value & 1 ) 29 | return index; 30 | ++index; 31 | value >>= 1; 32 | } 33 | } 34 | 35 | template 36 | Index _GetHighBit( TYPE value ) 37 | { 38 | ASSERT( value != 0 ); 39 | Index index = (sizeof(TYPE) * 8) - 1; 40 | 41 | while( value >>= 1 ) 42 | --index; 43 | 44 | return index; 45 | } 46 | } 47 | 48 | // public 49 | //------------------------------------------------------------------------- 50 | template 51 | Number::Number( TYPE value ): 52 | _value(value) 53 | {} 54 | 55 | //------------------------------------------------------------------------- 56 | template 57 | Number::operator TYPE() const 58 | { 59 | return _value; 60 | } 61 | template 62 | Number Number::operator=( TYPE value ) 63 | { 64 | _value = value; 65 | return *this; 66 | } 67 | 68 | template<> 69 | Number Number::operator - () const 70 | { 71 | return 0; 72 | } 73 | template<> 74 | Number Number::operator - () const 75 | { 76 | return 0; 77 | } 78 | template 79 | Number Number::operator - () const 80 | { 81 | return -_value; 82 | } 83 | 84 | //------------------------------------------------------------------------- 85 | template 86 | Bool Number::IsNaN() const 87 | { 88 | return _value != _value; 89 | } 90 | 91 | //------------------------------------------------------------------------- 92 | template<> 93 | Number Number::GetRandom( Float min, Float max ) 94 | { 95 | return static_cast(::rand()) * (max - min) / static_cast(RAND_MAX) + min; 96 | } 97 | template<> 98 | Number Number::GetRandom( Double min, Double max ) 99 | { 100 | ASSERT_TODO; 101 | return 0; 102 | } 103 | template 104 | Number Number::GetRandom( TYPE min, TYPE max ) 105 | { 106 | ASSERT( max >= min ); 107 | //TODO3: improve 108 | return min + static_cast(((TYPE)::rand() * (TYPE)::rand()) % static_cast(max - min + 1)); 109 | } 110 | 111 | //------------------------------------------------------------------------- 112 | template 113 | void Number::SetRandomSeed( TYPE value ) 114 | { 115 | return ::srand( static_cast(value) ); 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /source/Core/Math/Number.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class Number 9 | { 10 | public: 11 | /**/ 12 | Number() = default; 13 | Number( TYPE value ); 14 | 15 | /**/ 16 | operator TYPE () const; 17 | Number operator = ( TYPE value ); 18 | Number operator - () const; 19 | 20 | /**/ 21 | Bool IsNaN() const; 22 | 23 | /**/ 24 | static Number GetRandom( TYPE min, TYPE max ); 25 | 26 | /**/ 27 | static void SetRandomSeed( TYPE value ); 28 | /**/ 29 | 30 | private: 31 | // fields 32 | TYPE _value; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /source/Core/Math/Quaternion.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | /* 8 | yaw: Z 9 | pitch: Y 10 | roll: X 11 | */ 12 | template 13 | class BaseQuaternion 14 | { 15 | public: 16 | // types 17 | typedef BaseVector3 VectorType; 18 | 19 | // constants 20 | static BaseQuaternion IDENTITY(); 21 | 22 | /**/ 23 | BaseQuaternion() = default; 24 | BaseQuaternion( TYPE x, TYPE y, TYPE z, TYPE w ); 25 | BaseQuaternion( TYPE yaw, TYPE pitch, TYPE roll ); 26 | 27 | /**/ 28 | BaseQuaternion operator * ( const BaseQuaternion& other ) const; 29 | VectorType operator * ( const VectorType& vector ) const; 30 | BaseQuaternion operator - ( const BaseQuaternion& other ) const; 31 | 32 | /**/ 33 | TYPE GetX() const; 34 | TYPE GetY() const; 35 | TYPE GetZ() const; 36 | TYPE GetW() const; 37 | 38 | /**/ 39 | void FromAngleAxis( const TYPE angle, const VectorType& axis ); 40 | void FromEuler( TYPE yaw, TYPE pitch, TYPE roll ); 41 | 42 | /**/ 43 | void ToAngleAxis( TYPE& angle, VectorType& axis ); 44 | void ToEuler( VectorType& euler ) const; 45 | void ToMatrix( BaseMatrix4& matrix ) const; 46 | 47 | /**/ 48 | BaseQuaternion Inverse() const; 49 | 50 | /**/ 51 | void Normalize(); 52 | 53 | private: 54 | // fields 55 | TYPE _x, _y, _z, _w; 56 | }; 57 | 58 | // common typedefs 59 | //------------------------------------------------------------------------- 60 | typedef BaseQuaternion Quaternionf; 61 | } 62 | -------------------------------------------------------------------------------- /source/Core/Math/Transform3.cpp: -------------------------------------------------------------------------------- 1 | //TODO: handle scale better 2 | #include 3 | 4 | namespace Core 5 | { 6 | // explicit instantiations 7 | //------------------------------------------------------------------------- 8 | template class BaseTransform3; 9 | 10 | // statics 11 | //------------------------------------------------------------------------- 12 | template BaseTransform3 BaseTransform3::IDENTITY() 13 | { 14 | return BaseTransform3( VectorType::ZERO(), RotationType::IDENTITY() ); 15 | } 16 | 17 | // public 18 | //------------------------------------------------------------------------- 19 | template 20 | BaseTransform3::BaseTransform3( VectorType translation_ ): 21 | translation (translation_), 22 | orientation (RotationType::IDENTITY()) 23 | {} 24 | 25 | template 26 | BaseTransform3::BaseTransform3( VectorType translation_, RotationType orientation_ ): 27 | translation(translation_), 28 | orientation(orientation_) 29 | {} 30 | 31 | //------------------------------------------------------------------------- 32 | template 33 | BaseTransform3 BaseTransform3::operator * ( const BaseTransform3& other ) const 34 | { 35 | return BaseTransform3 36 | ( 37 | operator * (other.translation), 38 | orientation * other.orientation 39 | ); 40 | } 41 | 42 | template 43 | typename BaseTransform3::VectorType BaseTransform3::operator * ( VectorType vector ) const 44 | { 45 | return translation + orientation * vector; 46 | } 47 | 48 | //------------------------------------------------------------------------- 49 | template 50 | BaseTransform3 BaseTransform3::Inverse() const 51 | { 52 | RotationType iorientation = orientation.Inverse(); 53 | 54 | return BaseTransform3( 55 | iorientation * -translation, 56 | iorientation 57 | ); 58 | } 59 | 60 | //------------------------------------------------------------------------- 61 | template 62 | void BaseTransform3::ToMatrix4( Matrix4Type& m ) const 63 | { 64 | // apply orientation 65 | orientation.ToMatrix(m); 66 | 67 | // apply translation 68 | m.e30 = translation.x; 69 | m.e31 = translation.y; 70 | m.e32 = translation.z; 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /source/Core/Math/Transform3.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | template 10 | class BaseTransform3 11 | { 12 | public: 13 | // types 14 | typedef BaseVector3 VectorType; 15 | typedef BaseQuaternion RotationType; 16 | typedef BaseMatrix4 Matrix4Type; 17 | 18 | // constants 19 | static BaseTransform3 IDENTITY(); 20 | 21 | /**/ 22 | BaseTransform3() = default; 23 | BaseTransform3( VectorType translation_ ); 24 | BaseTransform3( VectorType translation_, RotationType orientation_ ); 25 | 26 | /**/ 27 | BaseTransform3 operator * ( const BaseTransform3& other ) const; 28 | VectorType operator * ( VectorType vector ) const; 29 | 30 | /**/ 31 | BaseTransform3 Inverse() const; 32 | 33 | /**/ 34 | void ToMatrix4( Matrix4Type& m ) const; 35 | 36 | // fields 37 | VectorType translation; 38 | RotationType orientation; 39 | }; 40 | 41 | // common typedefs 42 | //------------------------------------------------------------------------- 43 | typedef BaseTransform3 Transform3f; 44 | } 45 | -------------------------------------------------------------------------------- /source/Core/Math/Vector2.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class BaseVector2 9 | { 10 | public: 11 | // constants 12 | static BaseVector2 ZERO(); 13 | 14 | // types 15 | typedef TYPE Type; 16 | 17 | /**/ 18 | BaseVector2() = default; 19 | BaseVector2( TYPE xy ); 20 | BaseVector2( TYPE x_, TYPE y_ ); 21 | BaseVector2( const BaseVector2& other ); 22 | 23 | /**/ 24 | Bool operator == ( const BaseVector2& other ) const; 25 | Bool operator != ( const BaseVector2& other ) const; 26 | Bool operator < ( const BaseVector2& other ) const; 27 | Bool operator <= ( const BaseVector2& other ) const; 28 | Bool operator > ( const BaseVector2& other ) const; 29 | Bool operator >= ( const BaseVector2& other ) const; 30 | BaseVector2 operator + ( const BaseVector2& other ) const; 31 | BaseVector2 operator - ( const BaseVector2& other ) const; 32 | BaseVector2 operator * ( const BaseVector2& other ) const; 33 | BaseVector2 operator / ( const BaseVector2& other ) const; 34 | BaseVector2 operator += ( const BaseVector2& other ); 35 | BaseVector2 operator -= ( const BaseVector2& other ); 36 | BaseVector2 operator *= ( const BaseVector2& other ); 37 | BaseVector2 operator /= ( const BaseVector2& other ); 38 | BaseVector2 operator - () const; 39 | 40 | /**/ 41 | template 42 | BaseVector2 Cast() const 43 | { 44 | return BaseVector2( 45 | static_cast(x), 46 | static_cast(y) ); 47 | } 48 | 49 | /**/ 50 | void Set( TYPE xy ); 51 | void Set( TYPE x_, TYPE y_ ); 52 | 53 | /**/ 54 | TYPE CrossProduct( const BaseVector2& other ) const; 55 | TYPE DotProduct( const BaseVector2& other ) const; 56 | TYPE Sum() const; 57 | 58 | // fields: public 59 | TYPE x, y; 60 | }; 61 | 62 | // common typedefs 63 | //------------------------------------------------------------------------- 64 | typedef BaseVector2 Vector2l; 65 | typedef BaseVector2 Vector2f; 66 | } 67 | -------------------------------------------------------------------------------- /source/Core/Math/Vector3.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class BaseVector3 9 | { 10 | public: 11 | // constants 12 | static BaseVector3 ZERO(); 13 | 14 | // types 15 | typedef TYPE Type; 16 | 17 | /**/ 18 | BaseVector3() = default; 19 | BaseVector3( TYPE xyz ); 20 | BaseVector3( TYPE x_, TYPE y_, TYPE z_ ); 21 | BaseVector3( const BaseVector3& other ); 22 | 23 | /**/ 24 | Bool operator == ( const BaseVector3& other ) const; 25 | Bool operator != ( const BaseVector3& other ) const; 26 | Bool operator < ( const BaseVector3& other ) const; 27 | Bool operator <= ( const BaseVector3& other ) const; 28 | Bool operator > ( const BaseVector3& other ) const; 29 | Bool operator >= ( const BaseVector3& other ) const; 30 | BaseVector3 operator + ( const BaseVector3& other ) const; 31 | BaseVector3 operator - ( const BaseVector3& other ) const; 32 | BaseVector3 operator * ( const BaseVector3& other ) const; 33 | BaseVector3 operator / ( const BaseVector3& other ) const; 34 | BaseVector3 operator += ( const BaseVector3& other ); 35 | BaseVector3 operator -= ( const BaseVector3& other ); 36 | BaseVector3 operator *= ( const BaseVector3& other ); 37 | BaseVector3 operator /= ( const BaseVector3& other ); 38 | BaseVector3 operator - () const; 39 | 40 | /**/ 41 | void Set( TYPE xyz ); 42 | void Set( TYPE x_, TYPE y_, TYPE z_ ); 43 | 44 | /**/ 45 | TYPE Length() const; 46 | TYPE SquareLength() const; 47 | BaseVector3 Normal() const; 48 | BaseVector3 CrossProduct( const BaseVector3& other ) const; 49 | TYPE DotProduct( const BaseVector3& other ) const; 50 | TYPE Sum() const; 51 | 52 | // fields: public 53 | TYPE x, y, z; 54 | }; 55 | 56 | // common typedefs 57 | //------------------------------------------------------------------------- 58 | typedef BaseVector3 Vector3f; 59 | typedef BaseVector3 Vector3u; 60 | } 61 | -------------------------------------------------------------------------------- /source/Core/Math/Vector4.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class BaseVector4 9 | { 10 | public: 11 | // constants 12 | static const BaseVector4 ZERO; 13 | 14 | // types 15 | typedef TYPE Type; 16 | 17 | /**/ 18 | BaseVector4() = default; 19 | BaseVector4( TYPE xyzw ); 20 | BaseVector4( TYPE x_, TYPE y_, TYPE z_, TYPE w_ ); 21 | BaseVector4( const BaseVector4& other ); 22 | 23 | /**/ 24 | Bool operator == ( const BaseVector4& other ) const; 25 | Bool operator != ( const BaseVector4& other ) const; 26 | Bool operator < ( const BaseVector4& other ) const; 27 | Bool operator <= ( const BaseVector4& other ) const; 28 | Bool operator > ( const BaseVector4& other ) const; 29 | Bool operator >= ( const BaseVector4& other ) const; 30 | BaseVector4 operator + ( const BaseVector4& other ) const; 31 | BaseVector4 operator - ( const BaseVector4& other ) const; 32 | BaseVector4 operator * ( const BaseVector4& other ) const; 33 | BaseVector4 operator / ( const BaseVector4& other ) const; 34 | BaseVector4 operator += ( const BaseVector4& other ); 35 | BaseVector4 operator -= ( const BaseVector4& other ); 36 | BaseVector4 operator *= ( const BaseVector4& other ); 37 | BaseVector4 operator /= ( const BaseVector4& other ); 38 | 39 | /**/ 40 | void Set( TYPE xyzw ); 41 | void Set( TYPE x_, TYPE y_, TYPE z_, TYPE w_ ); 42 | 43 | // fields: public 44 | TYPE x, y, z, w; 45 | }; 46 | 47 | // common typedefs 48 | //------------------------------------------------------------------------- 49 | typedef BaseVector4 Vector4u; 50 | typedef BaseVector4 Vector4f; 51 | } 52 | -------------------------------------------------------------------------------- /source/Core/Root.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | // local 8 | //------------------------------------------------------------------------- 9 | namespace 10 | { 11 | // constants 12 | //--------------------------------------------------------------------- 13 | static const ULong LOG_STRING_LIMIT = 1024; 14 | } 15 | 16 | // logging 17 | //------------------------------------------------------------------------- 18 | void DebugLog( const Char* format, ... ) 19 | { 20 | va_list vargs; 21 | Char message[LOG_STRING_LIMIT]; 22 | ASSERT(format != nullptr); 23 | 24 | // build log message 25 | va_start(vargs, format); 26 | vsnprintf(message, COUNT(message), format, vargs); 27 | va_end(vargs); 28 | 29 | // log message 30 | Debug::Log(String(message)); 31 | } 32 | 33 | // failure 34 | //------------------------------------------------------------------------- 35 | void DebugFatal( const Char* format, ... ) 36 | { 37 | va_list vargs; 38 | Char message[LOG_STRING_LIMIT]; 39 | ASSERT(format != nullptr); 40 | 41 | // build log message 42 | va_start(vargs, format); 43 | vsnprintf(message, COUNT(message), format, vargs); 44 | va_end(vargs); 45 | 46 | // log message 47 | Debug::Log(String(message)); 48 | 49 | // exit 50 | Debug::Exit(); 51 | } 52 | 53 | void DebugAssert( const Char* message, const Char *file, ULong line ) 54 | { 55 | DebugFatal( "ASSERT:%s (%s:%u)", message, file, line ); 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /source/Core/Support/Enum.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | template 10 | class Enum 11 | { 12 | public: 13 | struct KeyValue 14 | { 15 | TYPE key; 16 | String value; 17 | }; 18 | 19 | public: 20 | typedef Array KeyValueCollection; 21 | typedef typename KeyValueCollection::Iterator KeyValueIterator; 22 | 23 | private: 24 | KeyValueCollection _items; 25 | 26 | public: 27 | /**/ 28 | Enum( KeyValue* items, UShort count ): 29 | _items(items, count) 30 | { 31 | } 32 | 33 | /**/ 34 | Bool GetValue( String& value, const TYPE& key ) const 35 | { 36 | String s; 37 | 38 | for( KeyValueIterator i = _items.Begin(); i != _items.End(); ++i ) 39 | { 40 | if( key == i->key ) 41 | { 42 | value = i->value; 43 | return true; 44 | } 45 | } 46 | 47 | return false; 48 | } 49 | 50 | /**/ 51 | Bool GetKey( TYPE& key, const String& value ) const 52 | { 53 | String s; 54 | 55 | for( KeyValueIterator i = _items.begin(); i != _items.end(); ++i ) 56 | { 57 | if( value == i->value ) 58 | { 59 | key = i->key; 60 | return true; 61 | } 62 | } 63 | 64 | return false; 65 | } 66 | }; 67 | 68 | /* common types */ 69 | typedef Enum IdEnum; 70 | } 71 | -------------------------------------------------------------------------------- /source/Core/Support/EventDispatcher.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class EventListener: 9 | public InlineListNode> 10 | { 11 | template friend class EventDispatcher; 12 | public: 13 | /**/ 14 | virtual Bool _OnEvent( const EVENT& event ) = 0; 15 | 16 | /**/ 17 | Bool operator<( const EventListener& other ) const 18 | { 19 | return _order < other._order; 20 | } 21 | 22 | /**/ 23 | Long GetEventOrder() const 24 | { 25 | return _order; 26 | } 27 | 28 | private: 29 | // fields 30 | Long _order; 31 | }; 32 | 33 | /**/ 34 | template 35 | class EventDispatcher 36 | { 37 | public: 38 | // aliases 39 | typedef EventListener ListenerType; 40 | typedef InlineList> ListenerCollection; 41 | typedef typename ListenerCollection::Iterator ListenerIterator; 42 | 43 | /**/ 44 | const ListenerCollection& GetListeners() const 45 | { 46 | return _listeners; 47 | } 48 | 49 | /**/ 50 | ListenerCollection& EditListeners() 51 | { 52 | return _listeners; 53 | } 54 | 55 | /**/ 56 | void Add( EventListener& listener ) 57 | { 58 | // add to listener list 59 | _listeners.Add( listener ); 60 | } 61 | 62 | void Add( EventListener& listener, Long order ) 63 | { 64 | listener._order = order; 65 | 66 | // add to listener list in specified order 67 | _listeners.AddSorted( listener ); 68 | } 69 | 70 | /**/ 71 | void Remove( EventListener& listener ) 72 | { 73 | // remove listener from list using find comparator 74 | _listeners.Remove( listener); 75 | } 76 | 77 | /**/ 78 | Bool Notify( const EVENT& event ) const 79 | { 80 | // for each listener 81 | for( ListenerIterator i = _listeners.begin() ; i != _listeners.end(); ) 82 | { 83 | // preiterate in case event handler deletes this entry 84 | ListenerType& listener = i; 85 | ++i; 86 | 87 | // call event handler 88 | if( listener._OnEvent( event ) ) 89 | return true; 90 | } 91 | 92 | return false; 93 | } 94 | 95 | Bool NotifyReverse( const EVENT& event ) const 96 | { 97 | // for each listener 98 | for( ListenerIterator i = _listeners.rend() ; i != _listeners.rbegin(); ) 99 | { 100 | // preiterate in case event handler deletes this entry 101 | ListenerType& listener = i; 102 | --i; 103 | 104 | // call event handler 105 | if( listener._OnEvent( event ) ) 106 | return true; 107 | } 108 | 109 | return false; 110 | } 111 | 112 | protected: 113 | // fields 114 | ListenerCollection _listeners; 115 | }; 116 | } 117 | -------------------------------------------------------------------------------- /source/Core/Support/Settings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Core 5 | { 6 | // public 7 | //------------------------------------------------------------------------- 8 | Settings::Settings( KeyValueCollection& keyvalues ): 9 | _keyvalues (keyvalues), 10 | _ready (false), 11 | _accessed (0) 12 | { 13 | _path.Zero(); 14 | } 15 | 16 | //------------------------------------------------------------------------- 17 | void Settings::SetPath( const PathString& path ) 18 | { 19 | _path = path; 20 | } 21 | 22 | //------------------------------------------------------------------------- 23 | Bool Settings::Load() 24 | { 25 | Char line[STRING_MEDIUM_SIZE]; 26 | FILE* file; 27 | 28 | if(_wfopen_s(&file, _path.GetMemory(), L"rt") == 0) 29 | { 30 | while(fgets(line, sizeof(line), file)) 31 | { 32 | Char* equal = strchr(line, '='); 33 | if(equal) 34 | { 35 | Char* nl = strchr(line, '\n'); 36 | if(nl) 37 | *nl = 0; 38 | *equal = 0; 39 | 40 | Id id = Find(line); 41 | if( id != INVALID_INDEX ) 42 | Set(id, equal+1); 43 | } 44 | } 45 | 46 | fclose(file); 47 | return true; 48 | } 49 | else 50 | return Save(); 51 | } 52 | 53 | //------------------------------------------------------------------------- 54 | Bool Settings::Save() 55 | { 56 | FILE* file; 57 | 58 | if(_wfopen_s(&file, _path.GetMemory(), L"wt") == 0) 59 | { 60 | for( KeyValueIterator i = _keyvalues.begin(); i != _keyvalues.end(); ++i ) 61 | fprintf(file, "%s=%s\n", i->key.GetMemory(), i->value.GetMemory()); 62 | 63 | fclose(file); 64 | return true; 65 | } 66 | 67 | return false; 68 | } 69 | 70 | //------------------------------------------------------------------------- 71 | String Settings::Get( Id id ) const 72 | { 73 | ASSERT( static_cast(id) < _keyvalues.GetCount() ); 74 | return _keyvalues[id].value; 75 | } 76 | 77 | Bool Settings::GetBoolean( Id id ) const 78 | { 79 | String string = Get(id); 80 | return string.GetCount() && string[0] == '1'; 81 | } 82 | 83 | Long Settings::GetNumber( Id id ) const 84 | { 85 | String string = Get(id); 86 | return atoi(string.GetMemory()); 87 | } 88 | 89 | const Settings::KeyValueCollection& Settings::GetCollection() const 90 | { 91 | return _keyvalues; 92 | } 93 | 94 | //------------------------------------------------------------------------- 95 | void Settings::Set( Id id, const String& value ) 96 | { 97 | return _keyvalues[id].value.CopyZ(value); 98 | } 99 | 100 | void Settings::SetBoolean( Id id, Bool boolean ) 101 | { 102 | return _keyvalues[id].value.CopyZ(boolean ? "1" : "0"); 103 | } 104 | 105 | void Settings::SetNumber( Id id, Long number ) 106 | { 107 | Char buffer[STRING_SHORT_SIZE]; 108 | _itoa_s(number, buffer, sizeof(STRING_SHORT_SIZE), 10); 109 | return _keyvalues[id].value.CopyZ(buffer); 110 | } 111 | 112 | //------------------------------------------------------------------------- 113 | Id Settings::Find( String key ) 114 | { 115 | for( Index i = 0; i < _keyvalues.GetCount(); ++i ) 116 | if(key == _keyvalues[i].key) 117 | return i; 118 | 119 | return INVALID_ID; 120 | } 121 | } 122 | -------------------------------------------------------------------------------- /source/Core/Support/Settings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | class Settings 10 | { 11 | public: 12 | // types 13 | struct KeyValue 14 | { 15 | MediumString key; 16 | MediumString value; 17 | }; 18 | 19 | typedef Array KeyValueCollection; 20 | typedef KeyValueCollection::Iterator KeyValueIterator; 21 | 22 | /**/ 23 | Settings( KeyValueCollection& items ); 24 | 25 | /**/ 26 | void SetPath( const PathString& path ); 27 | 28 | /**/ 29 | Bool Load(); 30 | Bool Save(); 31 | 32 | /**/ 33 | String Get( Id id ) const; 34 | Bool GetBoolean( Id id ) const; 35 | Long GetNumber( Id id ) const; 36 | const KeyValueCollection& GetCollection() const; 37 | 38 | /**/ 39 | void Set( Id id, const String& value ); 40 | void SetBoolean( Id id, Bool boolean ); 41 | void SetNumber( Id id, Long number ); 42 | 43 | /**/ 44 | Id Find( String key ); 45 | 46 | private: 47 | // fields 48 | KeyValueCollection _keyvalues; 49 | PathString _path; 50 | Bool _ready; 51 | ULong _accessed; 52 | }; 53 | } 54 | -------------------------------------------------------------------------------- /source/Core/Support/Singleton.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class Singleton 9 | { 10 | public: 11 | /**/ 12 | static TYPE& Instance() 13 | { 14 | static TYPE instance; 15 | return instance; 16 | } 17 | }; 18 | } 19 | -------------------------------------------------------------------------------- /source/Core/Support/Tools.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Core 8 | { 9 | // public 10 | //------------------------------------------------------------------------- 11 | ULong Tools::CStrLen( const Char* string ) 12 | { 13 | assert(string); 14 | return (ULong)strlen(string); 15 | } 16 | 17 | const CHAR* Tools::WToCString( const WCHAR* wstring ) 18 | { 19 | static CHAR cstring[STRING_MAX_SIZE]; 20 | 21 | if( WideCharToMultiByte( CP_ACP, 0, wstring, -1, cstring, sizeof( cstring ), NULL, NULL ) == 0 ) 22 | return nullptr; 23 | 24 | return cstring; 25 | } 26 | 27 | Bool Tools::StripFileName( WCHAR* path ) 28 | { 29 | WCHAR* end = path + wcslen(path); 30 | for( ; *end != '\\' && end != path; end-- ); 31 | *end = 0; 32 | 33 | return true; 34 | } 35 | 36 | Bool Tools::DoesFileExist( const WCHAR* path ) 37 | { 38 | FILE* file; 39 | 40 | if(_wfopen_s(&file, path, L"rt") == 0) 41 | { 42 | fclose(file); 43 | return true; 44 | } 45 | 46 | return false; 47 | } 48 | 49 | Hash Tools::Fnv164Hash( const void* memory, ULong count ) 50 | { 51 | const Byte* bmemory = reinterpret_cast(memory); 52 | UHuge hash = 0xCBF29CE484222325; 53 | 54 | for( Index i = 0; i < count; i++ ) 55 | { 56 | Byte byte = bmemory[i]; 57 | 58 | hash = hash ^ byte; 59 | hash = hash * 0x100000001B3; 60 | hash = hash & 0xFFFFFFFFFFFFFFFF; 61 | } 62 | 63 | return hash; 64 | } 65 | 66 | //------------------------------------------------------------------------- 67 | void Tools::MemSet( Byte* memory, Byte value, ULong count ) 68 | { 69 | ::memset(memory, value, count); 70 | } 71 | 72 | // private 73 | //------------------------------------------------------------------------- 74 | void Tools::_MemCpy( void* to, const void* from, ULong size ) 75 | { 76 | ::memcpy(to, from, size); 77 | } 78 | 79 | Long Tools::_MemCmp( const void* a, const void* b, ULong size ) 80 | { 81 | return ::memcmp(a, b, size); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /source/Core/Support/Tools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | class Tools 7 | { 8 | public: 9 | /**/ 10 | template 11 | static void Swap( TYPE& a, TYPE& b ) 12 | { 13 | TYPE t = a; 14 | a = b; 15 | b = t; 16 | } 17 | 18 | /**/ 19 | template 20 | static TYPE Min( TYPE a, TYPE b ) 21 | { 22 | return a < b ? a : b; 23 | } 24 | template 25 | static TYPE Max( TYPE a, TYPE b ) 26 | { 27 | return a > b ? a : b; 28 | } 29 | 30 | /**/ 31 | template 32 | static TYPE Clamp( TYPE value, TYPE min, TYPE max ) 33 | { 34 | return ((value > max) ? (max) : ((value < min) ? (min) : (value))); 35 | } 36 | 37 | /**/ 38 | template 39 | static void MemCopy( TYPE* to, const TYPE* from, ULong count=1 ) 40 | { 41 | _MemCpy(to, from, count * sizeof(TYPE)); 42 | } 43 | 44 | template 45 | static void MemCopy( TYPE& to, const TYPE& from ) 46 | { 47 | _MemCpy(&to, &from, sizeof(TYPE)); 48 | } 49 | 50 | /**/ 51 | template 52 | static inline Long MemCompare( const TYPE* a, const TYPE* b, ULong count ) 53 | { 54 | return _MemCmp(a, b, count * sizeof(TYPE)); 55 | } 56 | 57 | template 58 | static inline Long MemCompare( const TYPE& a, const TYPE& b ) 59 | { 60 | return _MemCmp(&a, &b, sizeof(TYPE)); 61 | } 62 | 63 | /**/ 64 | template 65 | static inline void MemZero( TYPE& object ) 66 | { 67 | MemSet(reinterpret_cast(&object), 0, sizeof(TYPE)); 68 | } 69 | template 70 | static inline void MemZero( TYPE* memory, ULong count ) 71 | { 72 | MemSet(reinterpret_cast(memory), 0, count * sizeof(TYPE)); 73 | } 74 | 75 | /**/ 76 | static void MemSet( Byte* memory, Byte value, ULong count ); 77 | 78 | /**/ 79 | static ULong CStrLen( const Char* string ); 80 | static const CHAR* WToCString( const WCHAR* wstring ); 81 | 82 | /**/ 83 | static Bool StripFileName( WCHAR* path ); 84 | static Bool DoesFileExist( const WCHAR* path ); 85 | 86 | /**/ 87 | static Hash Fnv164Hash( const void* memory, ULong count ); 88 | 89 | private: 90 | /**/ 91 | static void _MemCpy( void* to, const void* from, ULong size ); 92 | static Long _MemCmp( const void* a, const void* b, ULong size ); 93 | }; 94 | } 95 | -------------------------------------------------------------------------------- /source/Core/System/Debug.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Core 5 | { 6 | // staitcs 7 | //------------------------------------------------------------------------- 8 | PathString Debug::_log_path; 9 | 10 | // public 11 | //------------------------------------------------------------------------- 12 | void Debug::Initialize( const PathString& log_path, Bool host ) 13 | { 14 | #ifdef OPTION_DEBUG_LOG_FILE 15 | // initialize file logging 16 | _InitializeFileLog(log_path, host); 17 | #endif 18 | #ifdef OPTION_DEBUG_LOG_CONSOLE 19 | // initialize console logging 20 | _InitializeConsoleLog(); 21 | #endif 22 | } 23 | 24 | void Debug::Shutdown() 25 | { 26 | #ifdef OPTION_DEBUG_LOG_CONSOLE 27 | // shutdown console logging 28 | FreeConsole(); 29 | #endif 30 | } 31 | 32 | //------------------------------------------------------------------------- 33 | void Debug::Exit() 34 | { 35 | // abort/exit/terminate (which one!) 36 | abort(); 37 | } 38 | 39 | //------------------------------------------------------------------------- 40 | void Debug::Log( const String& message ) 41 | { 42 | // log message 43 | #ifdef OPTION_DEBUG_LOG_FILE 44 | Debug::LogFile(String(message)); 45 | #endif 46 | #ifdef OPTION_DEBUG_LOG_CONSOLE 47 | Debug::LogConsole(String(message)); 48 | #endif 49 | } 50 | 51 | void Debug::LogFile( const String& message ) 52 | { 53 | FILE* file; 54 | 55 | // open log file, write, and close. this is ghetto way to allow parallel writes. 56 | if( _log_path[0] && _wfopen_s(&file, _log_path.GetMemory(), L"at") == 0 ) 57 | { 58 | fwrite( message.GetMemory(), 1, message.GetCount(), file ); 59 | fputc( '\n', file ); 60 | fclose(file); 61 | } 62 | } 63 | 64 | void Debug::LogConsole( const String& message ) 65 | { 66 | fwrite( message.GetMemory(), 1, message.GetCount(), stdout ); 67 | fputc( '\n', stdout ); 68 | } 69 | 70 | // private 71 | //------------------------------------------------------------------------- 72 | void Debug::_InitializeFileLog( const PathString& log_path, Bool host ) 73 | { 74 | // set fields 75 | _log_path = log_path; 76 | 77 | // if host, delete existing log file 78 | if( host ) 79 | _wunlink(_log_path.GetMemory()); 80 | } 81 | 82 | void Debug::_InitializeConsoleLog() 83 | { 84 | FILE* file; 85 | 86 | // allocate console 87 | AllocConsole(); 88 | 89 | // associate standard streams with console 90 | freopen_s(&file, "conin$", "r", stdin); 91 | freopen_s(&file, "conout$", "w", stdout); 92 | freopen_s(&file, "conout$", "w", stderr); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /source/Core/System/Debug.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | class Debug 10 | { 11 | public: 12 | /**/ 13 | static void Initialize( const PathString& log_path, Bool host ); 14 | static void Shutdown(); 15 | 16 | /**/ 17 | static void Exit(); 18 | 19 | /**/ 20 | static void Log( const String& message ); 21 | static void LogFile( const String& message ); 22 | static void LogConsole( const String& message ); 23 | 24 | private: 25 | /**/ 26 | static void _InitializeFileLog( const PathString& log_path, Bool host ); 27 | static void _InitializeConsoleLog(); 28 | 29 | // fields 30 | static PathString _log_path; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /source/Core/System/IpcPair.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | class IpcPair 8 | { 9 | public: 10 | // constants 11 | static constexpr ULong IPC_NAME_LIMIT = 64; 12 | 13 | /**/ 14 | struct IListener 15 | { 16 | /**/ 17 | virtual void OnRecv( const void* message ) = 0; 18 | }; 19 | 20 | /**/ 21 | IpcPair(); 22 | ~IpcPair(); 23 | 24 | /**/ 25 | Bool Initialize( const Char* name, ULong size, IListener& listener ); 26 | void Shutdown(); 27 | 28 | /**/ 29 | Bool IsInitialized() const; 30 | 31 | /**/ 32 | Index GetInstance() const; 33 | 34 | /**/ 35 | Bool Send( const void* message, ULong size, ULong wait_ms=0 ); 36 | 37 | private: 38 | // types 39 | struct MemoryEntry 40 | { 41 | Byte4 lock; 42 | Byte data[1]; 43 | }; 44 | 45 | /**/ 46 | Bool _Initialize( const Char* name, ULong size, IListener& listener ); 47 | void _Shutdown(); 48 | 49 | /**/ 50 | static VOID CALLBACK _EventWakeHandler( _In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired ); 51 | 52 | // fields: parameters 53 | ULong _size; 54 | IListener* _listener; 55 | // fields: state 56 | Index _instance; 57 | HANDLE _hmap; 58 | HANDLE _hwait; 59 | HANDLE _hevent[2]; 60 | MemoryEntry* _memory[2]; 61 | }; 62 | } 63 | -------------------------------------------------------------------------------- /source/Core/System/SystemTools.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Core 8 | { 9 | // public 10 | //------------------------------------------------------------------------- 11 | Bitness SystemTools::GetProcessBitness( HANDLE process ) 12 | { 13 | SYSTEM_INFO system_info; 14 | 15 | // check if everything is 32bit 16 | GetNativeSystemInfo(&system_info); 17 | 18 | // select cpu architecture 19 | switch( system_info.wProcessorArchitecture ) 20 | { 21 | // 64bit 22 | case PROCESSOR_ARCHITECTURE_AMD64: 23 | case PROCESSOR_ARCHITECTURE_IA64: 24 | { 25 | BOOL is_wow64; 26 | 27 | // get wow64 (emulated 32) status 28 | if( process==NULL || !IsWow64Process(process, &is_wow64) ) 29 | return BITNESS_UNKNOWN; 30 | 31 | // if emulated then 32 else 64 32 | return is_wow64 ? BITNESS_32 : BITNESS_64; 33 | } 34 | 35 | // 32bit 36 | case PROCESSOR_ARCHITECTURE_INTEL: 37 | return BITNESS_32; 38 | } 39 | 40 | return BITNESS_UNKNOWN; 41 | } 42 | 43 | Bool SystemTools::GetProcessDirectory( PathString& path ) 44 | { 45 | if( GetModuleFileName( NULL, path.EditMemory(), path.GetLimit() ) == 0 ) 46 | return false; 47 | 48 | Tools::StripFileName(path.EditMemory()); 49 | return true; 50 | } 51 | 52 | ULong SystemTools::GetTimeMs() 53 | { 54 | return GetTickCount(); 55 | } 56 | 57 | UHuge SystemTools::GetTickTime() 58 | { 59 | UHuge counter = 0; 60 | QueryPerformanceCounter((LARGE_INTEGER*)&counter); 61 | return counter; 62 | } 63 | 64 | UHuge SystemTools::GetTickFrequency() 65 | { 66 | UHuge frequency = 0; 67 | QueryPerformanceFrequency((LARGE_INTEGER*)&frequency); 68 | return frequency; 69 | } 70 | 71 | Float SystemTools::GetTicksToSeconds( UHuge ticks ) 72 | { 73 | static UHuge frequency = SystemTools::GetTickFrequency(); 74 | 75 | // calculate frame time 76 | return static_cast((ticks * 1000000) / frequency) / 1000000.0f; 77 | } 78 | 79 | //------------------------------------------------------------------------- 80 | Bool SystemTools::AccessUserPath( PathString& path, const WCHAR* app_name ) 81 | { 82 | PathString wpath; 83 | Bool status = false; 84 | 85 | // get appdata folder 86 | if( SHGetFolderPath( NULL, CSIDL_LOCAL_APPDATA | CSIDL_FLAG_CREATE, NULL, SHGFP_TYPE_CURRENT, wpath.EditMemory() ) != S_OK ) 87 | return false; 88 | 89 | // build save path 90 | if( swprintf_s( path.EditMemory(), path.GetCount(), L"%s\\%s", wpath.GetMemory(), app_name ) <= 0 ) 91 | return false; 92 | 93 | // ensure save path exists 94 | if( !CreateDirectory(path.GetMemory(), NULL) && GetLastError() != ERROR_ALREADY_EXISTS ) 95 | return false; 96 | 97 | return true; 98 | } 99 | 100 | //------------------------------------------------------------------------- 101 | Bool SystemTools::EnableAutoStart( const WCHAR* name, const PathString& path, Bool enable ) 102 | { 103 | const WCHAR* REGISTRY_PATH = L"Software\\Microsoft\\Windows\\CurrentVersion\\Run"; 104 | Bool status = false; 105 | HKEY hkey; 106 | 107 | // if enabling 108 | if(enable) 109 | { 110 | // open/create key 111 | if(RegCreateKeyEx(HKEY_CURRENT_USER, REGISTRY_PATH, 0, NULL, 0, KEY_SET_VALUE, NULL, &hkey, NULL) == ERROR_SUCCESS) 112 | { 113 | // set value 114 | if(RegSetValueEx (hkey, name, 0, REG_SZ, (Byte*)path.GetMemory(), (DWORD)(wcslen(path.GetMemory()) * sizeof(WCHAR))) == ERROR_SUCCESS) 115 | status = true; 116 | 117 | // close key 118 | RegCloseKey(hkey); 119 | } 120 | } 121 | // open key 122 | else if( RegOpenKey(HKEY_CURRENT_USER, REGISTRY_PATH, &hkey) == ERROR_SUCCESS ) 123 | { 124 | // delete value 125 | if( RegDeleteValue(hkey, name) == ERROR_SUCCESS ) 126 | status = true; 127 | 128 | // close key 129 | RegCloseKey(hkey); 130 | } 131 | 132 | return status; 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /source/Core/System/SystemTools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | /**/ 8 | class SystemTools 9 | { 10 | public: 11 | /**/ 12 | static Bitness GetProcessBitness( HANDLE process ); 13 | static Bool GetProcessDirectory( PathString& path ); 14 | static ULong GetTimeMs(); 15 | static UHuge GetTickTime(); 16 | static UHuge GetTickFrequency(); 17 | static Float GetTicksToSeconds( UHuge ticks ); 18 | 19 | /**/ 20 | static Bool AccessUserPath( PathString& path, const WCHAR* app_name ); 21 | 22 | /**/ 23 | static Bool EnableAutoStart( const WCHAR* name, const PathString& path, Bool enable ); 24 | 25 | /**/ 26 | static HANDLE OpenDebugPrivileges(); 27 | static void CloseDebugPrivileges( HANDLE handle ); 28 | }; 29 | } 30 | -------------------------------------------------------------------------------- /source/Core/Type/Default.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | struct Default 8 | { 9 | /**/ 10 | template 11 | static Bool Equator( const TYPE& l, const TYPE& r ) 12 | { 13 | return l == r; 14 | } 15 | 16 | /**/ 17 | template 18 | static Bool Comparator( const TYPE& l, const TYPE& r ) 19 | { 20 | return l < r; 21 | } 22 | }; 23 | } 24 | -------------------------------------------------------------------------------- /source/Core/Type/Tuple.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | #pragma pack(1) 7 | /**/ 8 | template struct Tuple; 9 | 10 | /**/ 11 | template 12 | struct Tuple 13 | { 14 | /**/ 15 | Tuple() = default; 16 | Tuple( const A& a_ ): 17 | a(a_) 18 | {} 19 | 20 | // common value names for 1st field 21 | union 22 | { 23 | A a; 24 | A x; 25 | A width; 26 | }; 27 | }; 28 | 29 | /**/ 30 | template 31 | struct Tuple: 32 | public Tuple 33 | { 34 | /**/ 35 | Tuple() = default; 36 | Tuple( const A& a_, const B& b_ ): 37 | Tuple(a_), 38 | b(b_) 39 | {} 40 | 41 | using Tuple::a; 42 | // common value names for 2nd field 43 | union 44 | { 45 | B b; 46 | B y; 47 | B height; 48 | }; 49 | }; 50 | 51 | /**/ 52 | template 53 | struct Tuple: 54 | public Tuple 55 | { 56 | /**/ 57 | Tuple() = default; 58 | Tuple( const A& a_, const B& b_, const C& c_ ): 59 | Tuple(a_, b_), 60 | c(c_) 61 | {} 62 | 63 | // common value names for 3rd field 64 | union 65 | { 66 | C c; 67 | C z; 68 | C depth; 69 | }; 70 | }; 71 | 72 | /**/ 73 | template 74 | struct Tuple: 75 | public Tuple 76 | { 77 | /**/ 78 | Tuple() = default; 79 | Tuple( const A& a_, const B& b_, const C& c_, const D& d_ ): 80 | Tuple(a_, b_, c_), 81 | d(d_) 82 | {} 83 | 84 | // common value names for 4th field 85 | union 86 | { 87 | D d; 88 | D w; 89 | }; 90 | }; 91 | 92 | /**/ 93 | template 94 | struct Tuple: 95 | public Tuple 96 | { 97 | /**/ 98 | Tuple() = default; 99 | Tuple( const A& a_, const B& b_, const C& c_, const D& d_, const E& e_ ): 100 | Tuple(a_, b_, c_, d_), 101 | e(e_) 102 | {} 103 | 104 | // common value names for 5th field 105 | union 106 | { 107 | E e; 108 | }; 109 | }; 110 | #pragma pack() 111 | } 112 | -------------------------------------------------------------------------------- /source/Core/Types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | // strings 8 | //------------------------------------------------------------------------- 9 | typedef FlatArray PathString; 10 | } 11 | -------------------------------------------------------------------------------- /source/Core/UI/Window.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Core 8 | { 9 | /**/ 10 | class Window 11 | { 12 | public: 13 | // enums 14 | enum: Bits 15 | { 16 | OPTION_OVERLAY = BIT( 0 ) 17 | }; 18 | 19 | // types 20 | struct InitializeDef 21 | { 22 | HINSTANCE hinstance; 23 | Vector2l size; 24 | const WCHAR* class_name; 25 | const WCHAR* title; 26 | Bits options; 27 | }; 28 | 29 | /**/ 30 | Window(); 31 | ~Window(); 32 | 33 | /**/ 34 | Bool Initialize( const InitializeDef& def ); 35 | void Shutdown(); 36 | 37 | /**/ 38 | Bool IsInitialized() const; 39 | 40 | /**/ 41 | HWND GetHandle() const; 42 | Vector2l GetSize() const; 43 | Float GetAspectRatio() const; 44 | 45 | /**/ 46 | void SetSize( const Vector2l& size ); 47 | 48 | // events 49 | EventDispatcher events; 50 | 51 | private: 52 | // constants 53 | static constexpr ULong TOPMOST_REFRESH_TIMER = 1000; // ms 54 | 55 | /**/ 56 | void _SetTop(); 57 | 58 | /**/ 59 | void _SizeTweak(); 60 | 61 | /**/ 62 | static LRESULT CALLBACK _WindowProcedure( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam ); 63 | 64 | // fields: parameters 65 | HINSTANCE _hinstance; 66 | const WCHAR* _class_name; 67 | // fields: state 68 | HWND _hwnd; 69 | Vector2l _size; 70 | Float _aspect_ratio; 71 | }; 72 | } 73 | -------------------------------------------------------------------------------- /source/Core/Windows/InputMonitor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | class InputMonitor: 10 | public ShellUi::IListener 11 | { 12 | public: 13 | // constants 14 | static const ULong STATE_LIMIT = 0xff; 15 | static const ULong KEY_LIMIT = 4; 16 | static const ULong COMBO_LIMIT = 50; 17 | static const ULong COMBO_EXPIRATION = 6000; 18 | static const ULong NONCOMBO_EXPIRATION = 2000; 19 | static const ULong QUEUED_EXPIRATION = 10; 20 | 21 | /**/ 22 | struct IListener 23 | { 24 | virtual void OnKey( ULong key, Bool down ) {} 25 | virtual void OnKeyCombo( Id id ) {} 26 | }; 27 | 28 | /**/ 29 | InputMonitor( ShellUi& ui ); 30 | ~InputMonitor(); 31 | 32 | /**/ 33 | Bool IsStarted() const; 34 | 35 | /**/ 36 | Bool Start( IListener& listener ); 37 | void Stop(); 38 | 39 | /**/ 40 | Bool CreateCombo( Id id, String format ); 41 | 42 | private: 43 | // types 44 | typedef DynamicFlatArray StateTable; 45 | typedef DynamicFlatArray KeyCollection; 46 | typedef KeyCollection::Iterator KeyIterator; 47 | 48 | struct Combo 49 | { 50 | Id id; 51 | KeyCollection keys; 52 | }; 53 | 54 | typedef DynamicFlatArray ComboCollection; 55 | typedef ComboCollection::Iterator ComboIterator; 56 | 57 | /**/ 58 | void OnMessage( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ); 59 | 60 | /**/ 61 | Bool _OnInputKeyboard( const RAWKEYBOARD& kb ); 62 | 63 | /**/ 64 | Combo* _FindCombo(); 65 | 66 | /**/ 67 | ULong _GetAlternateKey( ULong key ); 68 | 69 | // fields 70 | ShellUi& _ui; 71 | StateTable _state; 72 | ComboCollection _combos; 73 | ULONGLONG _input_time; 74 | Bool _combo_pressed; 75 | // fields: objects 76 | RAWINPUTDEVICE _rawinput_kb; 77 | // fields: state 78 | Bool _started; 79 | }; 80 | } 81 | -------------------------------------------------------------------------------- /source/Core/Windows/SharedMemory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Core 5 | { 6 | /**/ 7 | template 8 | class SharedMemory 9 | { 10 | private: 11 | const WCHAR* _name; 12 | HANDLE _handle; 13 | TYPE* _memory; 14 | 15 | public: 16 | /**/ 17 | SharedMemory( const WCHAR* name ): 18 | _name (name), 19 | _handle (NULL), 20 | _memory (NULL) 21 | { 22 | } 23 | 24 | ~SharedMemory() 25 | { 26 | Close(); 27 | } 28 | 29 | /**/ 30 | Bool Open( Bool host ) 31 | { 32 | ASSERT(_memory == NULL); 33 | ASSERT(_handle == NULL); 34 | 35 | // if host create 36 | if( host ) 37 | _handle = CreateFileMapping( INVALID_HANDLE_VALUE, NULL, PAGE_READWRITE, 0, sizeof(TYPE), _name ); 38 | // else use existing 39 | else 40 | _handle = OpenFileMapping( FILE_MAP_ALL_ACCESS, FALSE, _name ); 41 | if(_handle == NULL) 42 | return false; 43 | 44 | // map to memory 45 | _memory = (TYPE*)MapViewOfFile( _handle, FILE_MAP_ALL_ACCESS, 0, 0, sizeof(TYPE)); 46 | if(_memory == NULL) 47 | { 48 | CloseHandle(_handle); 49 | _handle = NULL; 50 | return false; 51 | } 52 | 53 | return true; 54 | } 55 | 56 | void Close() 57 | { 58 | // if loaded 59 | if( _handle ) 60 | { 61 | // unmap from memory 62 | if( _memory ) 63 | { 64 | UnmapViewOfFile(_memory); 65 | _memory = NULL; 66 | } 67 | 68 | // close shared memory handle 69 | CloseHandle(_handle); 70 | _handle = NULL; 71 | } 72 | } 73 | 74 | /**/ 75 | TYPE& Object() 76 | { 77 | ASSERT(_memory); 78 | return *_memory; 79 | } 80 | 81 | /**/ 82 | TYPE* operator->() const 83 | { 84 | ASSERT(_memory); 85 | return _memory; 86 | } 87 | }; 88 | } 89 | -------------------------------------------------------------------------------- /source/Core/Windows/ShellUi.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Core 6 | { 7 | /**/ 8 | class ShellUi: 9 | public Singleton 10 | { 11 | public: 12 | // types 13 | struct IListener 14 | { 15 | virtual void OnMessage( HWND hwnd, UINT message, WPARAM wparam, LPARAM lparam ) {} 16 | virtual Bool OnMenuOption( Id id, Bool enabled ) { return false; } 17 | }; 18 | 19 | /**/ 20 | ShellUi(); 21 | 22 | /**/ 23 | Bool IsStarted() const; 24 | 25 | /**/ 26 | HWND GetHwnd(); 27 | 28 | /**/ 29 | void AddMenu(); 30 | void AddMenuBreak(); 31 | void AddMenuOption( Id id, const WCHAR* name, Bool enabled ); 32 | 33 | /**/ 34 | void HideMenu(); 35 | 36 | /**/ 37 | void SetIcon( Id icon_id ); 38 | void SetName( const WCHAR* name ); 39 | void SetMenuOption( Id id, Bool enabled ); 40 | 41 | /**/ 42 | void AddListener( IListener& listener ); 43 | void RemoveListener( IListener& listener ); 44 | 45 | /**/ 46 | Bool Start(); 47 | void Stop(); 48 | 49 | /**/ 50 | void Exit(); 51 | }; 52 | } 53 | -------------------------------------------------------------------------------- /source/Core/Windows/SystemMonitor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Core 4 | { 5 | // local 6 | //------------------------------------------------------------------------- 7 | namespace 8 | { 9 | // event handler 10 | //--------------------------------------------------------------------- 11 | static VOID CALLBACK _WinEvent( 12 | HWINEVENTHOOK hWinEventHook, 13 | DWORD event, 14 | HWND hwnd, 15 | LONG idObject, 16 | LONG idChild, 17 | DWORD idEventThread, 18 | DWORD dwmsEventTime) 19 | { 20 | if( idObject == OBJID_WINDOW && idChild == CHILDID_SELF ) 21 | { 22 | SystemMonitor& system_monitor = SystemMonitor::Instance(); 23 | 24 | switch(event) 25 | { 26 | case EVENT_SYSTEM_FOREGROUND: 27 | system_monitor.events.Notify( { SystemMonitorEvent::WINDOW_FOREGROUND, hwnd } ); 28 | /* 29 | system_monitor.events.Notify( { SystemMonitorEvent::WINDOW_ZORDER, hwnd } ); 30 | break; 31 | 32 | case EVENT_OBJECT_REORDER: 33 | case EVENT_OBJECT_LOCATIONCHANGE: 34 | case EVENT_OBJECT_PARENTCHANGE: 35 | system_monitor.events.Notify( { SystemMonitorEvent::WINDOW_ZORDER, hwnd } ); 36 | break; 37 | */ 38 | } 39 | } 40 | } 41 | } 42 | 43 | // public 44 | //------------------------------------------------------------------------- 45 | SystemMonitor::SystemMonitor(): 46 | _handle (NULL) 47 | { 48 | } 49 | 50 | SystemMonitor::~SystemMonitor() 51 | { 52 | } 53 | 54 | //------------------------------------------------------------------------- 55 | Bool SystemMonitor::Initialize() 56 | { 57 | // set window event hook 58 | _handle = SetWinEventHook( EVENT_SYSTEM_FOREGROUND, EVENT_SYSTEM_FOREGROUND, NULL, _WinEvent, 0, 0, WINEVENT_OUTOFCONTEXT | WINEVENT_SKIPOWNPROCESS ); 59 | 60 | return _handle != NULL; 61 | } 62 | 63 | void SystemMonitor::Shutdown() 64 | { 65 | // if window event hook set 66 | if( _handle != NULL ) 67 | { 68 | // destroy window event hook 69 | UnhookWinEvent(_handle); 70 | 71 | // clear state 72 | _handle = NULL; 73 | } 74 | } 75 | 76 | //------------------------------------------------------------------------- 77 | Bool SystemMonitor::IsInitialized() const 78 | { 79 | return _handle != NULL; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /source/Core/Windows/SystemMonitor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Core 7 | { 8 | /**/ 9 | class SystemMonitor: 10 | public Singleton 11 | { 12 | public: 13 | // enums 14 | enum EventId: Id 15 | { 16 | WINDOW_FOREGROUND, 17 | WINDOW_ZORDER, 18 | }; 19 | 20 | /**/ 21 | SystemMonitor(); 22 | ~SystemMonitor(); 23 | 24 | /**/ 25 | Bool Initialize(); 26 | void Shutdown(); 27 | 28 | /**/ 29 | Bool IsInitialized() const; 30 | 31 | // events 32 | EventDispatcher events; 33 | 34 | private: 35 | // fields 36 | HWINEVENTHOOK _handle; 37 | }; 38 | } 39 | -------------------------------------------------------------------------------- /source/Core/Windows/WindowTools.hpp: -------------------------------------------------------------------------------- 1 | //TODO2: refactor dis random crap 2 | #pragma once 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Core 8 | { 9 | /**/ 10 | class WindowTools 11 | { 12 | public: 13 | /**/ 14 | static void RunWindowLoop(); 15 | 16 | /**/ 17 | static HWND GetFocusWindow(); 18 | 19 | /**/ 20 | static Bool TestGameWindow( HWND hwnd ); 21 | 22 | /**/ 23 | static Bool IsValidGameWindowSize( const SIZE& size ); 24 | 25 | /**/ 26 | static Bool TestFramesUpdating( const RECT& region, HWND hwnd, ULong test_count=1 ); 27 | 28 | /**/ 29 | static SIZE RectToSize( const RECT& rect ); 30 | 31 | /**/ 32 | static Bool ReadHBitmapPixels( Byte4*& pixels, Vector2l& size, HBITMAP hbitmap ); 33 | 34 | /**/ 35 | static void MessagePopup( const Char* title, Bool error, const Char* format, ... ); 36 | 37 | private: 38 | /**/ 39 | static Bool _TestFramesUpdating( const RECT& region, HDC hdc ); 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /source/Snoopy/Hook/Hook.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Snoopy 7 | { 8 | /**/ 9 | class Hook 10 | { 11 | public: 12 | /**/ 13 | Hook(); 14 | ~Hook(); 15 | 16 | /**/ 17 | Bool IsInitialized() const; 18 | Bool IsEnabled() const; 19 | 20 | /**/ 21 | Bool Initialize( void* target_address, x86::HookFunction hook_function ); 22 | void Shutdown(); 23 | 24 | /**/ 25 | Bool Enable(); 26 | Bool Disable(); 27 | 28 | private: 29 | // constants 30 | // largest size of a code segment (target or trampoline) 31 | static const ULong CODE_BUFFER_SIZE = 64; 32 | // minimum length of target code (a jmp instruction to trampoline) 33 | static const ULong TARGET_MIN_SIZE = 5; 34 | 35 | // types 36 | typedef DynamicFlatArray CodeBuffer; 37 | 38 | /**/ 39 | Bool _InitializeTarget( void* target_address ); 40 | Bool _InitializeTargetBackup(); 41 | Bool _InitializeTrampoline( void* hook_address ); 42 | 43 | /**/ 44 | Byte* _AllocTrampolineAddress(); 45 | 46 | // fields: parameters 47 | void* _target_address; 48 | x86::HookFunction _hook_function; 49 | 50 | // fields: state 51 | Bool _enabled; 52 | Bool _initialized; 53 | x86::Assembly _target; 54 | x86::Assembly _target_backup; 55 | x86::Assembly _trampoline; 56 | CodeBuffer _target_buffer; 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /source/Snoopy/Inject/Injector.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Snoopy 6 | { 7 | /**/ 8 | class Injector 9 | { 10 | public: 11 | /**/ 12 | Injector(); 13 | ~Injector(); 14 | 15 | /**/ 16 | Bool IsLoaded() const; 17 | 18 | /**/ 19 | Bool Load( HANDLE process, const CHAR* dll_path ); 20 | 21 | /**/ 22 | void Unload(); 23 | 24 | private: 25 | /**/ 26 | Bool _Load( const CHAR* dll_path ); 27 | void _Unload(); 28 | 29 | /**/ 30 | Bool _CallRemoteLoadLibrary( const CHAR* dll_path ); 31 | 32 | /**/ 33 | Bool _LoadSymbolModule( DWORD64& address, const CHAR* name ); 34 | 35 | // fields 36 | HANDLE _process; 37 | Bool _loaded; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /source/Snoopy/Root.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Snoopy 5 | { 6 | using namespace Core; 7 | } 8 | -------------------------------------------------------------------------------- /source/Snoopy/X86/Assembly.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Snoopy { namespace x86 7 | { 8 | /**/ 9 | class Assembly 10 | { 11 | private: 12 | Byte* _source_address; 13 | ByteBufferArray _code; 14 | 15 | public: 16 | /**/ 17 | Assembly(); 18 | 19 | /**/ 20 | Byte* GetSourceAddress() const; 21 | ByteBufferArray& GetCode(); 22 | ULong GetCodeLength() const; 23 | const Byte* GetCodeMemory() const; 24 | 25 | /**/ 26 | void SetSourceAddress( void* address ); 27 | void SetCodeBuffer( ByteArray buffer ); 28 | 29 | /**/ 30 | void Empty(); 31 | 32 | /**/ 33 | void OpNop (); 34 | void OpPushReg ( RegisterId register_id ); 35 | void OpPopReg ( RegisterId register_id ); 36 | void OpMovRegReg( RegisterId register_to, RegisterId register_from ); 37 | void OpMovRegImm( RegisterId register_id, Native imm ); 38 | void OpCallReg ( RegisterId register_id ); 39 | Bool OpCallRel ( void* address ); 40 | void OpJmpReg ( RegisterId register_id ); 41 | Bool OpJmpRel ( void* address ); 42 | 43 | /**/ 44 | Bool Relocate( const Assembly& source ); 45 | 46 | /**/ 47 | Bool Read( Operation& op ); 48 | 49 | private: 50 | /**/ 51 | Bool _ArgRelativeAddress32( void* address ); 52 | }; 53 | }} 54 | -------------------------------------------------------------------------------- /source/Snoopy/X86/Enums.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Snoopy { namespace x86 5 | { 6 | // x86 register ids 7 | //------------------------------------------------------------------------- 8 | enum RegisterId 9 | { 10 | REGISTER_AX = 0, 11 | REGISTER_CX = 1, 12 | REGISTER_DX = 2, 13 | REGISTER_BX = 3, 14 | REGISTER_SP = 4, 15 | REGISTER_BP = 5, 16 | REGISTER_SI = 6, 17 | REGISTER_DI = 7, 18 | 19 | REGISTER_R8 = 100, 20 | REGISTER_R9 = 101, 21 | REGISTER_R10 = 102, 22 | REGISTER_R11 = 103, 23 | REGISTER_R12 = 104, 24 | REGISTER_R13 = 105, 25 | REGISTER_R14 = 106, 26 | REGISTER_R15 = 107, 27 | 28 | REGISTER_BASIC_COUNT = 8, 29 | REGISTER_EXT_COUNT = 8, 30 | 31 | REGISTER_EXT_DIV = 100, 32 | }; 33 | 34 | // x86 op codes 35 | //------------------------------------------------------------------------- 36 | enum OpCodeId 37 | { 38 | OP_NOP = 0x90, 39 | 40 | OP_CALL_REG = 0xd0, 41 | OP_CALL_REL = 0xe8, 42 | OP_JMP_REG = 0xe0, 43 | OP_JMP_REL = 0xe9, 44 | OP_PUSH_REG = 0x50, 45 | OP_POP_REG = 0x58, 46 | OP_MOV_REG_IMM = 0xb8, 47 | OP_MOV_REG_REG = 0x8b, 48 | 49 | OP_ARG_MOV_REG_REG = 0xc0, 50 | 51 | OP_PREFIX_MOV_64 = 0x48, 52 | OP_PREFIX_CALL_REG = 0xFF, 53 | OP_PREFIX_JMP_REG = 0xFF, 54 | OP_PREFIX_PUSH_64 = 0x41, 55 | OP_PREFIX_POP_64 = 0x41, 56 | }; 57 | }} 58 | -------------------------------------------------------------------------------- /source/Snoopy/X86/Types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #if CPU_64 4 | #include 5 | #else 6 | #include 7 | #endif 8 | 9 | namespace Snoopy { namespace x86 10 | { 11 | /**/ 12 | #define HOOK_CALL __cdecl 13 | 14 | /**/ 15 | #if CPU_64 16 | typedef hde64s Operation; 17 | #define hde_disasm hde64_disasm 18 | #else 19 | typedef hde32s Operation; 20 | #define hde_disasm hde32_disasm 21 | #endif 22 | 23 | /**/ 24 | typedef void (HOOK_CALL *HookFunction)( volatile Native* arguments ); 25 | }} 26 | -------------------------------------------------------------------------------- /source/Snoopy/X86/hde/hde32.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 3 | * Copyright (c) 2006-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde32.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE32_H_ 11 | #define _HDE32_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0 30 | #define F_DISP8 0x00000020 31 | #define F_DISP16 0x00000040 32 | #define F_DISP32 0x00000080 33 | #define F_RELATIVE 0x00000100 34 | #define F_2IMM16 0x00000800 35 | #define F_ERROR 0x00001000 36 | #define F_ERROR_OPCODE 0x00002000 37 | #define F_ERROR_LENGTH 0x00004000 38 | #define F_ERROR_LOCK 0x00008000 39 | #define F_ERROR_OPERAND 0x00010000 40 | #define F_PREFIX_REPNZ 0x01000000 41 | #define F_PREFIX_REPX 0x02000000 42 | #define F_PREFIX_REP 0x03000000 43 | #define F_PREFIX_66 0x04000000 44 | #define F_PREFIX_67 0x08000000 45 | #define F_PREFIX_LOCK 0x10000000 46 | #define F_PREFIX_SEG 0x20000000 47 | #define F_PREFIX_REX 0 48 | #define F_PREFIX_ANY 0x3f000000 49 | 50 | #define PREFIX_SEGMENT_CS 0x2e 51 | #define PREFIX_SEGMENT_SS 0x36 52 | #define PREFIX_SEGMENT_DS 0x3e 53 | #define PREFIX_SEGMENT_ES 0x26 54 | #define PREFIX_SEGMENT_FS 0x64 55 | #define PREFIX_SEGMENT_GS 0x65 56 | #define PREFIX_LOCK 0xf0 57 | #define PREFIX_REPNZ 0xf2 58 | #define PREFIX_REPX 0xf3 59 | #define PREFIX_OPERAND_SIZE 0x66 60 | #define PREFIX_ADDRESS_SIZE 0x67 61 | 62 | #pragma pack(push,1) 63 | 64 | typedef struct { 65 | uint8_t len; 66 | uint8_t p_rep; 67 | uint8_t p_lock; 68 | uint8_t p_seg; 69 | uint8_t p_66; 70 | uint8_t p_67; 71 | uint8_t opcode; 72 | uint8_t opcode2; 73 | uint8_t modrm; 74 | uint8_t modrm_mod; 75 | uint8_t modrm_reg; 76 | uint8_t modrm_rm; 77 | uint8_t sib; 78 | uint8_t sib_scale; 79 | uint8_t sib_index; 80 | uint8_t sib_base; 81 | union { 82 | uint8_t imm8; 83 | uint16_t imm16; 84 | uint32_t imm32; 85 | uint64_t imm64; 86 | } imm; 87 | union { 88 | uint8_t disp8; 89 | uint16_t disp16; 90 | uint32_t disp32; 91 | } disp; 92 | uint32_t flags; 93 | } hde32s; 94 | 95 | #pragma pack(pop) 96 | 97 | #ifdef __cplusplus 98 | extern "C" { 99 | #endif 100 | 101 | /* __cdecl */ 102 | unsigned int hde32_disasm(const void *code, hde32s *hs); 103 | 104 | #ifdef __cplusplus 105 | } 106 | #endif 107 | 108 | #endif /* _HDE32_H_ */ 109 | -------------------------------------------------------------------------------- /source/Snoopy/X86/hde/hde64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | * hde64.h: C/C++ header file 7 | * 8 | */ 9 | 10 | #ifndef _HDE64_H_ 11 | #define _HDE64_H_ 12 | 13 | /* stdint.h - C99 standard header 14 | * http://en.wikipedia.org/wiki/stdint.h 15 | * 16 | * if your compiler doesn't contain "stdint.h" header (for 17 | * example, Microsoft Visual C++), you can download file: 18 | * http://www.azillionmonkeys.com/qed/pstdint.h 19 | * and change next line to: 20 | * #include "pstdint.h" 21 | */ 22 | #include 23 | 24 | #define F_MODRM 0x00000001 25 | #define F_SIB 0x00000002 26 | #define F_IMM8 0x00000004 27 | #define F_IMM16 0x00000008 28 | #define F_IMM32 0x00000010 29 | #define F_IMM64 0x00000020 30 | #define F_DISP8 0x00000040 31 | #define F_DISP16 0x00000080 32 | #define F_DISP32 0x00000100 33 | #define F_RELATIVE 0x00000200 34 | #define F_2IMM16 0 35 | #define F_ERROR 0x00001000 36 | #define F_ERROR_OPCODE 0x00002000 37 | #define F_ERROR_LENGTH 0x00004000 38 | #define F_ERROR_LOCK 0x00008000 39 | #define F_ERROR_OPERAND 0x00010000 40 | #define F_PREFIX_REPNZ 0x01000000 41 | #define F_PREFIX_REPX 0x02000000 42 | #define F_PREFIX_REP 0x03000000 43 | #define F_PREFIX_66 0x04000000 44 | #define F_PREFIX_67 0x08000000 45 | #define F_PREFIX_LOCK 0x10000000 46 | #define F_PREFIX_SEG 0x20000000 47 | #define F_PREFIX_REX 0x40000000 48 | #define F_PREFIX_ANY 0x7f000000 49 | 50 | #define PREFIX_SEGMENT_CS 0x2e 51 | #define PREFIX_SEGMENT_SS 0x36 52 | #define PREFIX_SEGMENT_DS 0x3e 53 | #define PREFIX_SEGMENT_ES 0x26 54 | #define PREFIX_SEGMENT_FS 0x64 55 | #define PREFIX_SEGMENT_GS 0x65 56 | #define PREFIX_LOCK 0xf0 57 | #define PREFIX_REPNZ 0xf2 58 | #define PREFIX_REPX 0xf3 59 | #define PREFIX_OPERAND_SIZE 0x66 60 | #define PREFIX_ADDRESS_SIZE 0x67 61 | 62 | #pragma pack(push,1) 63 | 64 | typedef struct { 65 | uint8_t len; 66 | uint8_t p_rep; 67 | uint8_t p_lock; 68 | uint8_t p_seg; 69 | uint8_t p_66; 70 | uint8_t p_67; 71 | uint8_t rex; 72 | uint8_t rex_w; 73 | uint8_t rex_r; 74 | uint8_t rex_x; 75 | uint8_t rex_b; 76 | uint8_t opcode; 77 | uint8_t opcode2; 78 | uint8_t modrm; 79 | uint8_t modrm_mod; 80 | uint8_t modrm_reg; 81 | uint8_t modrm_rm; 82 | uint8_t sib; 83 | uint8_t sib_scale; 84 | uint8_t sib_index; 85 | uint8_t sib_base; 86 | union { 87 | uint8_t imm8; 88 | uint16_t imm16; 89 | uint32_t imm32; 90 | uint64_t imm64; 91 | } imm; 92 | union { 93 | uint8_t disp8; 94 | uint16_t disp16; 95 | uint32_t disp32; 96 | } disp; 97 | uint32_t flags; 98 | } hde64s; 99 | 100 | #pragma pack(pop) 101 | 102 | #ifdef __cplusplus 103 | extern "C" { 104 | #endif 105 | 106 | /* __cdecl */ 107 | unsigned int hde64_disasm(const void *code, hde64s *hs); 108 | 109 | #ifdef __cplusplus 110 | } 111 | #endif 112 | 113 | #endif /* _HDE64_H_ */ 114 | -------------------------------------------------------------------------------- /source/Snoopy/X86/hde/table32.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 32 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xf1 30 | #define DELTA_FPU_MODRM 0xf8 31 | #define DELTA_PREFIXES 0x130 32 | #define DELTA_OP_LOCK_OK 0x1a1 33 | #define DELTA_OP2_LOCK_OK 0x1b9 34 | #define DELTA_OP_ONLY_MEM 0x1cb 35 | #define DELTA_OP2_ONLY_MEM 0x1da 36 | 37 | unsigned char hde32_table[] = { 38 | 0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3,0xa8,0xa3, 39 | 0xa8,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xaa,0xac,0xaa,0xb2,0xaa,0x9f,0x9f, 40 | 0x9f,0x9f,0xb5,0xa3,0xa3,0xa4,0xaa,0xaa,0xba,0xaa,0x96,0xaa,0xa8,0xaa,0xc3, 41 | 0xc3,0x96,0x96,0xb7,0xae,0xd6,0xbd,0xa3,0xc5,0xa3,0xa3,0x9f,0xc3,0x9c,0xaa, 42 | 0xaa,0xac,0xaa,0xbf,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0x90, 43 | 0x82,0x7d,0x97,0x59,0x59,0x59,0x59,0x59,0x7f,0x59,0x59,0x60,0x7d,0x7f,0x7f, 44 | 0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x9a,0x88,0x7d, 45 | 0x59,0x50,0x50,0x50,0x50,0x59,0x59,0x59,0x59,0x61,0x94,0x61,0x9e,0x59,0x59, 46 | 0x85,0x59,0x92,0xa3,0x60,0x60,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59,0x59, 47 | 0x59,0x59,0x9f,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xcc,0x01,0xbc,0x03,0xf0, 48 | 0x10,0x10,0x10,0x10,0x50,0x50,0x50,0x50,0x14,0x20,0x20,0x20,0x20,0x01,0x01, 49 | 0x01,0x01,0xc4,0x02,0x10,0x00,0x00,0x00,0x00,0x01,0x01,0xc0,0xc2,0x10,0x11, 50 | 0x02,0x03,0x11,0x03,0x03,0x04,0x00,0x00,0x14,0x00,0x02,0x00,0x00,0xc6,0xc8, 51 | 0x02,0x02,0x02,0x02,0x00,0x00,0xff,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0xca, 52 | 0x01,0x01,0x01,0x00,0x06,0x00,0x04,0x00,0xc0,0xc2,0x01,0x01,0x03,0x01,0xff, 53 | 0xff,0x01,0x00,0x03,0xc4,0xc4,0xc6,0x03,0x01,0x01,0x01,0xff,0x03,0x03,0x03, 54 | 0xc8,0x40,0x00,0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00, 55 | 0x00,0x00,0x00,0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00, 56 | 0x00,0xff,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 57 | 0x00,0xff,0xff,0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 58 | 0x7f,0x00,0x00,0xff,0x4a,0x4a,0x4a,0x4a,0x4b,0x52,0x4a,0x4a,0x4a,0x4a,0x4f, 59 | 0x4c,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x55,0x45,0x40,0x4a,0x4a,0x4a, 60 | 0x45,0x59,0x4d,0x46,0x4a,0x5d,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a,0x4a, 61 | 0x4a,0x4a,0x4a,0x4a,0x4a,0x61,0x63,0x67,0x4e,0x4a,0x4a,0x6b,0x6d,0x4a,0x4a, 62 | 0x45,0x6d,0x4a,0x4a,0x44,0x45,0x4a,0x4a,0x00,0x00,0x00,0x02,0x0d,0x06,0x06, 63 | 0x06,0x06,0x0e,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x00,0x06,0x06,0x02,0x06, 64 | 0x00,0x0a,0x0a,0x07,0x07,0x06,0x02,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 65 | 0x04,0x04,0x00,0x00,0x00,0x0e,0x05,0x06,0x06,0x06,0x01,0x06,0x00,0x00,0x08, 66 | 0x00,0x10,0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01, 67 | 0x86,0x00,0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba, 68 | 0xf8,0xbb,0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00, 69 | 0xc4,0xff,0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00, 70 | 0x13,0x09,0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07, 71 | 0xb2,0xff,0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf, 72 | 0xe7,0x08,0x00,0xf0,0x02,0x00 73 | }; 74 | -------------------------------------------------------------------------------- /source/Snoopy/X86/hde/table64.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Hacker Disassembler Engine 64 C 3 | * Copyright (c) 2008-2009, Vyacheslav Patkov. 4 | * All rights reserved. 5 | * 6 | */ 7 | 8 | #define C_NONE 0x00 9 | #define C_MODRM 0x01 10 | #define C_IMM8 0x02 11 | #define C_IMM16 0x04 12 | #define C_IMM_P66 0x10 13 | #define C_REL8 0x20 14 | #define C_REL32 0x40 15 | #define C_GROUP 0x80 16 | #define C_ERROR 0xff 17 | 18 | #define PRE_ANY 0x00 19 | #define PRE_NONE 0x01 20 | #define PRE_F2 0x02 21 | #define PRE_F3 0x04 22 | #define PRE_66 0x08 23 | #define PRE_67 0x10 24 | #define PRE_LOCK 0x20 25 | #define PRE_SEG 0x40 26 | #define PRE_ALL 0xff 27 | 28 | #define DELTA_OPCODES 0x4a 29 | #define DELTA_FPU_REG 0xfd 30 | #define DELTA_FPU_MODRM 0x104 31 | #define DELTA_PREFIXES 0x13c 32 | #define DELTA_OP_LOCK_OK 0x1ae 33 | #define DELTA_OP2_LOCK_OK 0x1c6 34 | #define DELTA_OP_ONLY_MEM 0x1d8 35 | #define DELTA_OP2_ONLY_MEM 0x1e7 36 | 37 | unsigned char hde64_table[] = { 38 | 0xa5,0xaa,0xa5,0xb8,0xa5,0xaa,0xa5,0xaa,0xa5,0xb8,0xa5,0xb8,0xa5,0xb8,0xa5, 39 | 0xb8,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xc0,0xac,0xc0,0xcc,0xc0,0xa1,0xa1, 40 | 0xa1,0xa1,0xb1,0xa5,0xa5,0xa6,0xc0,0xc0,0xd7,0xda,0xe0,0xc0,0xe4,0xc0,0xea, 41 | 0xea,0xe0,0xe0,0x98,0xc8,0xee,0xf1,0xa5,0xd3,0xa5,0xa5,0xa1,0xea,0x9e,0xc0, 42 | 0xc0,0xc2,0xc0,0xe6,0x03,0x7f,0x11,0x7f,0x01,0x7f,0x01,0x3f,0x01,0x01,0xab, 43 | 0x8b,0x90,0x64,0x5b,0x5b,0x5b,0x5b,0x5b,0x92,0x5b,0x5b,0x76,0x90,0x92,0x92, 44 | 0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x6a,0x73,0x90, 45 | 0x5b,0x52,0x52,0x52,0x52,0x5b,0x5b,0x5b,0x5b,0x77,0x7c,0x77,0x85,0x5b,0x5b, 46 | 0x70,0x5b,0x7a,0xaf,0x76,0x76,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b,0x5b, 47 | 0x5b,0x5b,0x86,0x01,0x03,0x01,0x04,0x03,0xd5,0x03,0xd5,0x03,0xcc,0x01,0xbc, 48 | 0x03,0xf0,0x03,0x03,0x04,0x00,0x50,0x50,0x50,0x50,0xff,0x20,0x20,0x20,0x20, 49 | 0x01,0x01,0x01,0x01,0xc4,0x02,0x10,0xff,0xff,0xff,0x01,0x00,0x03,0x11,0xff, 50 | 0x03,0xc4,0xc6,0xc8,0x02,0x10,0x00,0xff,0xcc,0x01,0x01,0x01,0x00,0x00,0x00, 51 | 0x00,0x01,0x01,0x03,0x01,0xff,0xff,0xc0,0xc2,0x10,0x11,0x02,0x03,0x01,0x01, 52 | 0x01,0xff,0xff,0xff,0x00,0x00,0x00,0xff,0x00,0x00,0xff,0xff,0xff,0xff,0x10, 53 | 0x10,0x10,0x10,0x02,0x10,0x00,0x00,0xc6,0xc8,0x02,0x02,0x02,0x02,0x06,0x00, 54 | 0x04,0x00,0x02,0xff,0x00,0xc0,0xc2,0x01,0x01,0x03,0x03,0x03,0xca,0x40,0x00, 55 | 0x0a,0x00,0x04,0x00,0x00,0x00,0x00,0x7f,0x00,0x33,0x01,0x00,0x00,0x00,0x00, 56 | 0x00,0x00,0xff,0xbf,0xff,0xff,0x00,0x00,0x00,0x00,0x07,0x00,0x00,0xff,0x00, 57 | 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xff,0xff, 58 | 0x00,0x00,0x00,0xbf,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x7f,0x00,0x00, 59 | 0xff,0x40,0x40,0x40,0x40,0x41,0x49,0x40,0x40,0x40,0x40,0x4c,0x42,0x40,0x40, 60 | 0x40,0x40,0x40,0x40,0x40,0x40,0x4f,0x44,0x53,0x40,0x40,0x40,0x44,0x57,0x43, 61 | 0x5c,0x40,0x60,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, 62 | 0x40,0x40,0x64,0x66,0x6e,0x6b,0x40,0x40,0x6a,0x46,0x40,0x40,0x44,0x46,0x40, 63 | 0x40,0x5b,0x44,0x40,0x40,0x00,0x00,0x00,0x00,0x06,0x06,0x06,0x06,0x01,0x06, 64 | 0x06,0x02,0x06,0x06,0x00,0x06,0x00,0x0a,0x0a,0x00,0x00,0x00,0x02,0x07,0x07, 65 | 0x06,0x02,0x0d,0x06,0x06,0x06,0x0e,0x05,0x05,0x02,0x02,0x00,0x00,0x04,0x04, 66 | 0x04,0x04,0x05,0x06,0x06,0x06,0x00,0x00,0x00,0x0e,0x00,0x00,0x08,0x00,0x10, 67 | 0x00,0x18,0x00,0x20,0x00,0x28,0x00,0x30,0x00,0x80,0x01,0x82,0x01,0x86,0x00, 68 | 0xf6,0xcf,0xfe,0x3f,0xab,0x00,0xb0,0x00,0xb1,0x00,0xb3,0x00,0xba,0xf8,0xbb, 69 | 0x00,0xc0,0x00,0xc1,0x00,0xc7,0xbf,0x62,0xff,0x00,0x8d,0xff,0x00,0xc4,0xff, 70 | 0x00,0xc5,0xff,0x00,0xff,0xff,0xeb,0x01,0xff,0x0e,0x12,0x08,0x00,0x13,0x09, 71 | 0x00,0x16,0x08,0x00,0x17,0x09,0x00,0x2b,0x09,0x00,0xae,0xff,0x07,0xb2,0xff, 72 | 0x00,0xb4,0xff,0x00,0xb5,0xff,0x00,0xc3,0x01,0x00,0xc7,0xff,0xbf,0xe7,0x08, 73 | 0x00,0xf0,0x02,0x00 74 | }; 75 | -------------------------------------------------------------------------------- /source/YoloMouse/Dll/Core/App.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | 11 | namespace Yolomouse 12 | { 13 | /**/ 14 | class App: 15 | public Singleton, 16 | public IpcMessenger::IListener 17 | { 18 | public: 19 | /**/ 20 | App(); 21 | ~App(); 22 | 23 | /**/ 24 | Bool IsInitialized() const; 25 | Bool IsLoaded() const; 26 | 27 | /**/ 28 | Bool Initialize( HINSTANCE hdll ); 29 | void Shutdown(); 30 | 31 | /**/ 32 | Bool Load( const PathString& host_path, const PathString& log_path, const PathString& bindings_path ); 33 | void Unload(); 34 | 35 | private: 36 | // implement:IpcMessenger::IListener 37 | void OnRecv( const IpcMessage& message ); 38 | 39 | private: 40 | // types 41 | struct WindowCursorEntry 42 | { 43 | HWND hwnd = NULL; 44 | HCURSOR last_cursor = NULL; 45 | Bool original_class_set = false; 46 | HCURSOR original_class_cursor = NULL; 47 | }; 48 | // key is window class ATOM value 49 | typedef Map WindowCursorMap; 50 | 51 | // enums 52 | enum ClassLongNIndex: int 53 | { 54 | CLASSLONG_NINDEX_DEFAULT = 0, 55 | CLASSLONG_NINDEX_REFRESH = -1000, 56 | CLASSLONG_NINDEX_SETCURSOR = -1001, 57 | }; 58 | 59 | /**/ 60 | void _LoadBindings(); 61 | Bool _LoadHooks(); 62 | 63 | /**/ 64 | void _UnloadHooks(); 65 | 66 | /**/ 67 | void _RefreshCursor( HCURSOR hcursor, HWND hwnd ); 68 | void _RefreshCurrentCursor(); 69 | 70 | /**/ 71 | CursorInfo* _UpdateCursorBinding( HCURSOR hcursor, Hash cursor_hash, const CursorInfo& updates, CursorUpdateFlags flags ); 72 | 73 | /**/ 74 | HCURSOR _LoadBoundCursor( HCURSOR hcursor, Hash cursor_hash, CursorInfo& info ); 75 | HCURSOR _LoadBoundBasicCursor( CursorInfo& info ); 76 | HCURSOR _LoadBoundCloneCursor( HCURSOR hcursor, Hash cursor_hash, CursorInfo& info ); 77 | void _UnloadBoundCursor( Hash cursor_hash, const CursorInfo& info ); 78 | HCURSOR _GetBoundCursor( Hash cursor_hash, const CursorInfo& info ); 79 | 80 | /**/ 81 | Bool _GetCurrentCursor( HCURSOR& hcursor, HWND& hwnd ); 82 | HCURSOR _GetClassCursor( HWND hwnd ); 83 | void _SetClassCursor( HWND hwnd, HCURSOR hcursor, ClassLongNIndex nindex_override ); 84 | void _RestoreClassCursors(); 85 | 86 | /**/ 87 | Bool _NotifyCursorChanging( const CursorInfo& info ); 88 | Bool _NotifyCursorShowing( Bool showing ); 89 | 90 | /**/ 91 | void _OnRequestLoad( const LoadIpcMessage& message ); 92 | void _OnRequestExit(); 93 | void _OnRequestSetCursor( const SetCursorIpcMessage& message ); 94 | void _OnRequestSetDefaultCursor(); 95 | void _OnRequestResetCursor(); 96 | 97 | /**/ 98 | void _OnInjectedCursorChanging( HCURSOR& out_cursor, HCURSOR in_cursor ); 99 | void _OnInjectedCursorShowing( Bool showing ); 100 | 101 | /**/ 102 | static VOID HOOK_CALL _OnHookSetCursor( volatile Native* arguments ); 103 | static VOID HOOK_CALL _OnHookSetClassLong( volatile Native* arguments ); 104 | static VOID HOOK_CALL _OnHookShowCursor( volatile Native* arguments ); 105 | 106 | // fields: parameters 107 | HINSTANCE _hdll; 108 | PathString _bindings_path; 109 | // fields: state 110 | Bool _initialized; 111 | Bool _loaded; 112 | Long _update_size_delta; 113 | WindowCursorMap _window_cursor_map; 114 | // fields: objects 115 | IpcMessenger _ipc; 116 | CursorBindings _bindings; 117 | CursorVault _cursor_vault; 118 | HandleCache _cache; 119 | Snoopy::Hook _hook_setcursor; 120 | Snoopy::Hook _hook_setclasslonga; 121 | Snoopy::Hook _hook_setclasslongw; 122 | Snoopy::Hook _hook_showcursor; 123 | }; 124 | } 125 | -------------------------------------------------------------------------------- /source/YoloMouse/Dll/Cursor/HandleCache.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // Entry 6 | //------------------------------------------------------------------------- 7 | HandleCache::Entry::Entry(): 8 | handle (NULL), 9 | hash (0) 10 | { 11 | } 12 | 13 | // public 14 | //------------------------------------------------------------------------- 15 | HandleCache::HandleCache(): 16 | _next_index(0) 17 | { 18 | _cache.Zero(); 19 | } 20 | 21 | //------------------------------------------------------------------------- 22 | Hash HandleCache::GetHash( HCURSOR handle ) 23 | { 24 | // ignore invalid handle 25 | if( handle == NULL ) 26 | return 0; 27 | 28 | // if cache limit reached recalculate manually every time 29 | if( _next_index == CURSOR_CACHE_LIMIT ) 30 | return _CalculateHash(handle); 31 | 32 | // locate existing handle 33 | for( CacheIterator i = _cache.begin(); i != _cache.end(); ++i ) 34 | if( i->handle == handle ) 35 | return i->hash; 36 | 37 | // calculate hash of cursor 38 | Hash hash = _CalculateHash(handle); 39 | if( hash ) 40 | { 41 | // create entry 42 | Entry& entry = _cache[_next_index++]; 43 | entry.handle = handle; 44 | entry.hash = hash; 45 | } 46 | 47 | return hash; 48 | } 49 | 50 | // private 51 | //------------------------------------------------------------------------- 52 | Hash HandleCache::_CalculateHash( HCURSOR hcursor ) 53 | { 54 | ICONINFO iconinfo = {0}; 55 | LONG buffer_limit; 56 | Byte* buffer; 57 | BITMAP bitmap; 58 | HBITMAP hbitmap; 59 | Hash hash = 0; 60 | 61 | // require valid 62 | if( hcursor == NULL ) 63 | { 64 | LOG("HandleCache.CalculateHash.CursorIsNull"); 65 | return 0; 66 | } 67 | 68 | // get icon info 69 | if( GetIconInfo(hcursor, &iconinfo) == FALSE ) 70 | { 71 | LOG("HandleCache.CalculateHash.GetIconInfo: %u", GetLastError()); 72 | return 0; 73 | } 74 | 75 | // select color else mask bitmap 76 | hbitmap = iconinfo.hbmColor ? iconinfo.hbmColor : iconinfo.hbmMask; 77 | 78 | // get icon bitmap object 79 | if( GetObject(hbitmap, sizeof(BITMAP), &bitmap) == 0 ) 80 | { 81 | LOG("HandleCache.CalculateHash.GetObject"); 82 | return 0; 83 | } 84 | 85 | // allocate buffer 86 | buffer_limit = bitmap.bmWidthBytes * bitmap.bmHeight; 87 | /* 88 | TODO: this is a temporary hack added to 0.9.1 to make earlier 8k buffer 89 | limit cursors semi backward compatible. remove in 2019. 90 | */ 91 | //HACK:begin 92 | if( buffer_limit > KILOBYTES( 8 ) && buffer_limit <= KILOBYTES( 12 ) ) 93 | buffer_limit = KILOBYTES( 8 ); 94 | //HACK:end 95 | buffer = new Byte[buffer_limit]; 96 | 97 | // if buffer created 98 | if( buffer != nullptr ) 99 | { 100 | // read icon bitmap pixel data 101 | ULong buffer_count = GetBitmapBits( hbitmap, buffer_limit, buffer ); 102 | 103 | // log if failed 104 | if( buffer_count == 0 ) 105 | LOG("HandleCache.CalculateHash.GetBitmapBits"); 106 | // else generate hash 107 | else 108 | hash = Tools::Fnv164Hash(buffer, buffer_count); 109 | 110 | // cleanup buffer 111 | delete[] buffer; 112 | } 113 | 114 | // cleanup icon info 115 | if( iconinfo.hbmColor ) 116 | DeleteObject(iconinfo.hbmColor); 117 | if( iconinfo.hbmMask ) 118 | DeleteObject(iconinfo.hbmMask); 119 | 120 | return hash; 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /source/YoloMouse/Dll/Cursor/HandleCache.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | This optimizes the need to recalculate the hash of a cursor every time 3 | it changes by keeping a cache of handles-to-hashes. 4 | 5 | Unfortunately some games (like Diablo3) are written by tards where they 6 | constantly create new cursor handles for no good reason. If this happens 7 | the cache limit will reach quickly, but instead of rotating GetHash() will 8 | just recalculate the hash each time from that point on. This limit should 9 | not be reached for properly engineered games. 10 | */ 11 | #pragma once 12 | #include 13 | #include 14 | 15 | namespace Yolomouse 16 | { 17 | /**/ 18 | class HandleCache 19 | { 20 | public: 21 | /**/ 22 | HandleCache(); 23 | 24 | /**/ 25 | Hash GetHash( HCURSOR handle ); 26 | 27 | private: 28 | // types 29 | struct Entry 30 | { 31 | HCURSOR handle; 32 | Hash hash; 33 | 34 | Entry(); 35 | }; 36 | typedef FlatArray CacheMap; 37 | typedef CacheMap::Iterator CacheIterator; 38 | 39 | /**/ 40 | Hash _CalculateHash( HCURSOR hcursor ); 41 | 42 | // fields 43 | CacheMap _cache; 44 | Index _next_index; 45 | }; 46 | } 47 | -------------------------------------------------------------------------------- /source/YoloMouse/Dll/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | //#include 3 | using namespace Yolomouse; 4 | 5 | 6 | // exports 7 | //----------------------------------------------------------------------------- 8 | /* 9 | void __declspec(dllexport) 10 | YoloNotify( void* arg ) 11 | { 12 | NotifyMessage& m = *reinterpret_cast(arg); 13 | 14 | // handle notify 15 | switch(m.id) 16 | { 17 | case NOTIFY_INIT: 18 | App::Load(); 19 | break; 20 | 21 | case NOTIFY_UPDATEPRESET: 22 | App::UpdatePreset(static_cast(m.parameter)); 23 | break; 24 | 25 | case NOTIFY_UPDATESIZE: 26 | App::UpdateSize(static_cast(m.parameter)); 27 | break; 28 | 29 | case NOTIFY_REFRESH: 30 | App::Refresh(); 31 | break; 32 | } 33 | } 34 | */ 35 | 36 | // platform 37 | //----------------------------------------------------------------------------- 38 | BOOL WINAPI DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) 39 | { 40 | // get app 41 | App& app = App::Instance(); 42 | 43 | // dll requests 44 | switch(fdwReason) 45 | { 46 | case DLL_PROCESS_ATTACH: 47 | // initialize app 48 | if( !app.IsInitialized() ) 49 | app.Initialize(hinstDLL); 50 | break; 51 | case DLL_PROCESS_DETACH: 52 | // unload and shutdown app 53 | if( app.IsInitialized() ) 54 | { 55 | if( app.IsLoaded() ) 56 | app.Unload(); 57 | app.Shutdown(); 58 | } 59 | break; 60 | } 61 | 62 | return TRUE; 63 | } 64 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Core/App.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Yolomouse 9 | { 10 | /**/ 11 | class App: 12 | public Singleton, 13 | public InputMonitor::IListener, 14 | public ShellUi::IListener 15 | { 16 | public: 17 | /**/ 18 | App(); 19 | ~App(); 20 | 21 | /**/ 22 | Bool Initialize( HINSTANCE hinstance ); 23 | void Shutdown(); 24 | 25 | /**/ 26 | Bool IsInitialized() const; 27 | Bool IsElevated() const; 28 | 29 | /**/ 30 | Bool GetElevate() const; 31 | const PathString& GetHostPath() const; 32 | const PathString& GetUserPath() const; 33 | const PathString& GetLogPath() const; 34 | 35 | private: 36 | // impl: InputMonitor::IListener, ShellUi::IListener 37 | /**/ 38 | void OnKeyCombo( Id combo_id ); 39 | Bool OnMenuOption( Id id, Bool enabled ); 40 | 41 | private: 42 | /**/ 43 | Bool _InitializePaths(); 44 | Bool _InitializeSettings(); 45 | Bool _InitializeUi(); 46 | Bool _InitializeInput(); 47 | Bool _InitializeOptions(); 48 | Bool _InitializeOverlay( HINSTANCE hinstance ); 49 | void _InstallOverlayCursors(); 50 | 51 | /**/ 52 | void _ShutdownUi(); 53 | void _ShutdownInput(); 54 | void _ShutdownOverlay(); 55 | void _UninstallOverlayCursors(); 56 | 57 | /**/ 58 | void _OptionAbout(); 59 | void _OptionErrors(); 60 | Bool _OptionAutoStart( Bool enable, Bool save ); 61 | void _OptionReduceOverlayLag( Bool enable, Bool save ); 62 | Bool _OptionRunAsAdmin(); 63 | void _OptionSettingsFolder(); 64 | 65 | // fields: parameters 66 | Bool _elevate; 67 | 68 | // fields: state 69 | Bool _initialized; 70 | 71 | // fields: info 72 | PathString _host_path; 73 | PathString _user_path; 74 | PathString _log_path; 75 | 76 | // fields: objects 77 | OverlayCursorVault _overlay_cursor_vault; 78 | ShellUi& _ui; 79 | InputMonitor _input_monitor; 80 | Settings _settings; 81 | }; 82 | } 83 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Events/InjectSessionEvent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | struct InjectSessionEvent 9 | { 10 | // enums 11 | enum EventId: Id 12 | { 13 | CURSOR_CHANGING, 14 | CURSOR_SHOWING0, 15 | }; 16 | 17 | // fields 18 | EventId id; 19 | 20 | // data 21 | union U 22 | { 23 | // CURSOR_CHANGING 24 | CursorInfo cursor_changing; 25 | // CURSOR_SHOWING0 26 | Bool cursor_showing; 27 | 28 | U(){} 29 | } 30 | u; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Events/OverlayEvent.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | struct OverlayEvent 8 | { 9 | // enums 10 | enum EventId: Id 11 | { 12 | WINDOW_HOVER, 13 | }; 14 | 15 | // fields 16 | EventId id; 17 | HWND hwnd; 18 | }; 19 | } 20 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Inject/InjectEnvironment.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Yolomouse 8 | { 9 | /**/ 10 | class InjectEnvironment: 11 | public Singleton 12 | { 13 | public: 14 | /**/ 15 | InjectEnvironment(); 16 | ~InjectEnvironment(); 17 | 18 | /**/ 19 | void Initialize(); 20 | void Shutdown(); 21 | 22 | /**/ 23 | Bool IsInitialized() const; 24 | 25 | private: 26 | /**/ 27 | Bool _InitializePrivileges(); 28 | 29 | /**/ 30 | void _ShutdownPrivileges(); 31 | 32 | // fields 33 | HANDLE _hprivileges; 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Inject/InjectSession.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Yolomouse 8 | { 9 | /**/ 10 | class InjectSession: 11 | public IpcMessenger::IListener 12 | { 13 | public: 14 | /**/ 15 | InjectSession(); 16 | ~InjectSession(); 17 | 18 | /**/ 19 | Bool Initialize( Id process_id ); 20 | void Shutdown(); 21 | 22 | /**/ 23 | Bool IsInitialized() const; 24 | Bool IsLoaded() const; 25 | 26 | /**/ 27 | Id GetProcessId() const; 28 | 29 | /**/ 30 | Bool Load( const PathString& bindings_path ); 31 | void Unload(); 32 | 33 | /**/ 34 | Bool SendSetCursor( const CursorInfo& updates, CursorUpdateFlags flags ); 35 | Bool SendSetDefaultCursor(); 36 | Bool SendResetCursor(); 37 | Bool SendRefreshCursor(); 38 | 39 | // events 40 | EventDispatcher events; 41 | 42 | private: 43 | /**/ 44 | Bool _SendLoad( const PathString& bindings_path ); 45 | Bool _SendExit(); 46 | 47 | /**/ 48 | static const CHAR* _ChooseInjectDll( HANDLE process ); 49 | 50 | /**/ 51 | void _OnRecvCursorChanging( const OnCursorChangingIpcMessage& message ); 52 | void _OnRecvCursorShowing( const OnCursorShowingIpcMessage& message ); 53 | void OnRecv( const IpcMessage& message ); 54 | 55 | // fields: parameters 56 | Id _process_id; 57 | // fields: state 58 | Bool _loaded; 59 | // fields: objects 60 | Snoopy::Injector _injector; 61 | IpcMessenger _ipc; 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | // types 8 | //------------------------------------------------------------------------- 9 | enum ExitStatus 10 | { 11 | EXIT_NORMAL, 12 | EXIT_ELEVATE, 13 | EXIT_ERROR, 14 | EXIT_PLATFORM, 15 | EXIT_PLATFORM_MUTEX, 16 | EXIT_PLATFORM_DUPLICATE, 17 | EXIT_PLATFORM_MAIN, 18 | EXIT_PLATFORM_PATH, 19 | EXIT_PLATFORM_RUNASADMIN, 20 | }; 21 | 22 | // main 23 | //------------------------------------------------------------------------- 24 | static ExitStatus Main( HINSTANCE hinstance ) 25 | { 26 | App& app = App::Instance(); 27 | ExitStatus status = EXIT_NORMAL; 28 | 29 | // initialize app 30 | if( app.Initialize( hinstance ) ) 31 | { 32 | // run window loop 33 | WindowTools::RunWindowLoop(); 34 | 35 | // shutdown app 36 | app.Shutdown(); 37 | } 38 | // else error 39 | else 40 | status = EXIT_ERROR; 41 | 42 | // return status if error 43 | if( status ) 44 | return status; 45 | 46 | // if elevated requested, return elevate status 47 | if( app.GetElevate() ) 48 | return EXIT_ELEVATE; 49 | 50 | return EXIT_NORMAL; 51 | } 52 | 53 | // temporary unit testing area 54 | //------------------------------------------------------------------------- 55 | void _UnitTest( HINSTANCE hInstance ) 56 | { 57 | /* 58 | Overlay& w = Overlay::Instance(); 59 | w.Initialize( hInstance ); 60 | w.Run(); 61 | w.Shutdown(); 62 | */ 63 | } 64 | } 65 | 66 | // platform 67 | //----------------------------------------------------------------------------- 68 | int WINAPI WinMain( 69 | HINSTANCE hInstance, 70 | HINSTANCE hPrevInstance, 71 | LPSTR lpCmdLine, 72 | int iCmdShow) 73 | { 74 | using namespace Core; 75 | using namespace Yolomouse; 76 | 77 | //YoloMouse::_UnitTest(hInstance); return 0; 78 | 79 | // restart loop 80 | while( true ) 81 | { 82 | // default exit status 83 | int status = EXIT_NORMAL; 84 | 85 | // create duplicate instance prevention mutex 86 | HANDLE instance_mutex = CreateMutex( NULL, TRUE, IPC_MUTEX_NAME ); 87 | 88 | // if failed to create 89 | if( instance_mutex == NULL ) 90 | status = EXIT_PLATFORM_MUTEX; 91 | else 92 | { 93 | // if duplicate instance 94 | if( GetLastError() == ERROR_ALREADY_EXISTS ) 95 | status = EXIT_PLATFORM_DUPLICATE; 96 | // else good to go 97 | else 98 | { 99 | PathString path; 100 | 101 | // ensure working directory is that of the main executable 102 | if( SystemTools::GetProcessDirectory(path) && SetCurrentDirectory(path.GetMemory()) ) 103 | { 104 | // raise our priority to improve overlay cursor accuracy (allow fail) 105 | SetPriorityClass(GetCurrentProcess(), HIGH_PRIORITY_CLASS); 106 | 107 | // run main 108 | status = Main(hInstance); 109 | } 110 | // path change failed 111 | else 112 | status = EXIT_PLATFORM_PATH; 113 | } 114 | 115 | // cleanup 116 | CloseHandle( instance_mutex ); 117 | } 118 | 119 | // if elevate requested relaunch as administrator 120 | if( status == EXIT_ELEVATE ) 121 | { 122 | // relaunch self as administrator. return value over 32 indicates success 123 | if( (Long)(Huge)ShellExecute(NULL, L"runas", PATH_LOADER, L"", NULL, SW_SHOWNORMAL) > 32 ) 124 | return 0; 125 | else 126 | { 127 | WindowTools::MessagePopup(APP_NAMEC, true, "Run As Administrator Failed"); 128 | return EXIT_PLATFORM_RUNASADMIN; 129 | } 130 | } 131 | // normal exit 132 | else 133 | { 134 | // report exit error except duplicate 135 | if( status && status != EXIT_PLATFORM_DUPLICATE ) 136 | WindowTools::MessagePopup(APP_NAMEC, true, "Start Error: %d", status); 137 | 138 | return status; 139 | } 140 | } 141 | } 142 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/CursorFactory.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | // public 8 | //------------------------------------------------------------------------- 9 | IOverlayCursor* CursorFactory::CreateCursor( CursorId id ) 10 | { 11 | switch( id ) 12 | { 13 | case 0: 14 | return new ArrowCursor(); 15 | case 1: 16 | return new CircleCursor(); 17 | default: 18 | return nullptr; 19 | } 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/CursorFactory.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class CursorFactory 9 | { 10 | public: 11 | /**/ 12 | static IOverlayCursor* CreateCursor( CursorId id ); 13 | }; 14 | } -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | // local 8 | //------------------------------------------------------------------------- 9 | namespace 10 | { 11 | // constants 12 | //--------------------------------------------------------------------- 13 | const Float ROTATION_SPEED = 0.2f; // rotations/sec 14 | const Vector3f LIGHT_VECTOR = Vector3f(0,-1,0).Normal(); 15 | 16 | // vertices 17 | ShaderVertex VERTEX_DATA[] = 18 | { 19 | {{ 0.0f, 0.0f, 0.0f}, {0,0,0,1}}, 20 | {{ 3.2f, 0.866f,-0.5f}, {0,0,0,0.5f}}, 21 | {{ 3.2f, -0.866f,-0.5f}, {0,0,0,0.5f}}, 22 | 23 | {{ 0.0f, 0.0f, 0.0f}, {0,0,0,1}}, 24 | {{ 3.2f, -0.866f,-0.5f}, {0,0,0,0.5f}}, 25 | {{ 3.2f, 0.0f, 1.0f}, {0,0,0,0.5f}}, 26 | 27 | {{ 0.0f, 0.0f, 0.0f}, {0,0,0,1}}, 28 | {{ 3.2f, 0.0f, 1.0f}, {0,0,0,0.5f}}, 29 | {{ 3.2f, 0.866f,-0.5f}, {0,0,0,0.5f}}, 30 | 31 | {{ 3.2f, 0.0f, 1.0f}, {0,0,0,0.5f}}, 32 | {{ 3.2f, -0.866f,-0.5f}, {0,0,0,0.5f}}, 33 | {{ 3.2f, 0.866f,-0.5f}, {0,0,0,0.5f}}, 34 | }; 35 | Array VERTICES( VERTEX_DATA, COUNT(VERTEX_DATA) ); 36 | 37 | // indices 38 | Index3 INDEX_DATA[] = 39 | { 40 | { 0, 1, 2 }, 41 | { 3, 4, 5 }, 42 | { 6, 7, 8 }, 43 | { 9, 10, 11 } 44 | }; 45 | Array INDICES( INDEX_DATA, COUNT(INDEX_DATA) ); 46 | } 47 | 48 | // public 49 | //------------------------------------------------------------------------- 50 | ArrowCursor::ArrowCursor(): 51 | _rotater(0) 52 | { 53 | } 54 | 55 | ArrowCursor::~ArrowCursor() 56 | { 57 | } 58 | 59 | //------------------------------------------------------------------------- 60 | Bool ArrowCursor::_OnInitialize() 61 | { 62 | // calculate face normals 63 | _CalculateFaceNormals( VERTICES, INDICES ); 64 | 65 | // initialize mesh 66 | if( !BaseCursor::_mesh.Initialize({*_render_context,INDICES,VERTICES}) ) 67 | return false; 68 | 69 | return true; 70 | } 71 | 72 | void ArrowCursor::_OnShutdown() 73 | { 74 | ASSERT( IsInitialized() ); 75 | 76 | // shutdown mesh 77 | _mesh.Shutdown(); 78 | } 79 | 80 | void ArrowCursor::_OnUpdate( UpdateDef& def ) 81 | { 82 | // update light vector 83 | def.light_vector = LIGHT_VECTOR; 84 | 85 | // update transform 86 | def.orientation = Quaternionf( Math::PI / 4.0f, -Math::PI / 8.0f, _rotater ); 87 | 88 | // iterate rotator 89 | _rotater += ROTATION_SPEED * def.frame_time * Math::PI2; 90 | if( _rotater > Math::PI2 ) 91 | _rotater -= Math::PI2; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/Cursors/ArrowCursor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | class ArrowCursor: 8 | public BaseCursor 9 | { 10 | public: 11 | /**/ 12 | ArrowCursor(); 13 | ~ArrowCursor(); 14 | 15 | private: 16 | /**/ 17 | Bool _OnInitialize(); 18 | 19 | /**/ 20 | void _OnShutdown(); 21 | 22 | /**/ 23 | void _OnUpdate( UpdateDef& def ); 24 | 25 | private: 26 | // fields: state 27 | Float _rotater; 28 | }; 29 | } -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/Cursors/BaseCursor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Yolomouse 9 | { 10 | /**/ 11 | class BaseCursor: 12 | public IOverlayCursor 13 | { 14 | public: 15 | // types 16 | struct GeometryDef 17 | { 18 | Array vertices; 19 | Array indices; 20 | }; 21 | 22 | struct TextureDef 23 | { 24 | Vector2l size; 25 | void* pixels; 26 | }; 27 | 28 | struct UpdateDef 29 | { 30 | Float frame_time; 31 | Vector3f& light_vector; 32 | Quaternionf& orientation; 33 | }; 34 | 35 | struct DrawDef 36 | { 37 | Index begin; 38 | Index end; 39 | }; 40 | 41 | /**/ 42 | BaseCursor(); 43 | ~BaseCursor(); 44 | 45 | /**/ 46 | Bool Initialize( RenderContext& render_context ); 47 | void Shutdown(); 48 | 49 | /**/ 50 | Bool IsInitialized() const; 51 | 52 | /**/ 53 | CursorId GetId() const; 54 | CursorVariation GetVariation() const; 55 | CursorSize GetSize() const; 56 | 57 | /**/ 58 | virtual Bool SetCursor( CursorId id, CursorVariation variation, CursorSize size ); 59 | void SetAspectRatio( Float aspect_ratio ); 60 | 61 | /**/ 62 | void Draw( const Vector2f& position ); 63 | 64 | protected: 65 | /**/ 66 | virtual Bool _OnInitialize() = 0; 67 | virtual void _OnShutdown() = 0; 68 | virtual void _OnUpdate( UpdateDef& def ) = 0; 69 | 70 | /**/ 71 | void _SetAutoScale( Bool enable ); 72 | 73 | /**/ 74 | void _CalculateFaceNormals( Array& vertices, const Array& indices ); 75 | 76 | // fields 77 | Mesh _mesh; 78 | Texture _texture; 79 | RenderContext* _render_context; 80 | 81 | private: 82 | // constants 83 | // SIZEID_TO_SCALE * SizeId = cursor size relative to resolution height 84 | static constexpr Float SIZEID_TO_SCALE = 0.0032f; 85 | 86 | // fields: parameters 87 | CursorId _id; 88 | CursorVariation _variation; 89 | CursorSize _size; 90 | Float _cursor_scale; 91 | Bool _auto_scale; 92 | // fields: state 93 | Matrix4f _projection_matrix; 94 | }; 95 | } 96 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/Cursors/BasicCursor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class BasicCursor: 9 | public BaseCursor 10 | { 11 | public: 12 | /**/ 13 | BasicCursor(); 14 | ~BasicCursor(); 15 | 16 | /**/ 17 | Bool SetCursor( CursorId id, CursorVariation variation, CursorSize size ); 18 | 19 | private: 20 | /**/ 21 | Bool _OnInitialize(); 22 | 23 | /**/ 24 | void _OnShutdown(); 25 | 26 | /**/ 27 | void _OnUpdate( UpdateDef& def ); 28 | 29 | /**/ 30 | Bool _InitializeGeometry( const Vector2f& hotspot, const Vector2f& size ); 31 | 32 | /**/ 33 | Bool _UpdateTextureFromCursor( HCURSOR hcursor ); 34 | 35 | // fields: state 36 | Bool _cursor_loaded; 37 | CursorVault _cursor_vault; 38 | }; 39 | } -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/Cursors/CircleCursor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | class CircleCursor: 8 | public BaseCursor 9 | { 10 | public: 11 | /**/ 12 | CircleCursor(); 13 | ~CircleCursor(); 14 | 15 | private: 16 | /**/ 17 | Bool _OnInitialize(); 18 | 19 | /**/ 20 | void _OnShutdown(); 21 | 22 | /**/ 23 | void _OnUpdate( UpdateDef& def ); 24 | 25 | private: 26 | /**/ 27 | Bool _InitializeMesh(); 28 | 29 | // fields: state 30 | Float _rotater; 31 | }; 32 | } 33 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/IOverlayCursor.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Yolomouse 7 | { 8 | /**/ 9 | class IOverlayCursor 10 | { 11 | public: 12 | /**/ 13 | virtual Bool Initialize( RenderContext& render_context ) = 0; 14 | virtual void Shutdown() = 0; 15 | 16 | /**/ 17 | virtual Bool IsInitialized() const = 0; 18 | 19 | /**/ 20 | virtual Bool SetCursor( CursorId id, CursorVariation variation, CursorSize size ) = 0; 21 | virtual void SetAspectRatio( Float aspect_ratio ) = 0; 22 | 23 | /**/ 24 | virtual void Draw( const Vector2f& position ) = 0; 25 | }; 26 | } 27 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/OverlayCursorVault.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | // public 7 | //------------------------------------------------------------------------- 8 | OverlayCursorVault::OverlayCursorVault(): 9 | _initialized(false) 10 | { 11 | _cursors.Zero(); 12 | } 13 | 14 | OverlayCursorVault::~OverlayCursorVault() 15 | { 16 | ASSERT( !IsInitialized() ); 17 | } 18 | 19 | //------------------------------------------------------------------------- 20 | void OverlayCursorVault::Initialize() 21 | { 22 | ASSERT( !IsInitialized() ); 23 | 24 | // for each cursor id 25 | for( Id id = 0; id < CURSOR_ID_COUNT; ++id ) 26 | { 27 | // create cursor (can be null) 28 | _cursors[id] = CursorFactory::CreateCursor( static_cast(id) ); 29 | } 30 | 31 | // set initialized 32 | _initialized = true; 33 | } 34 | 35 | void OverlayCursorVault::Shutdown() 36 | { 37 | ASSERT( IsInitialized() ); 38 | 39 | // for each cursor id 40 | for( Id id = 0; id < CURSOR_ID_COUNT; ++id ) 41 | { 42 | // get cursor if created 43 | IOverlayCursor*& cursor = _cursors[id]; 44 | 45 | // if created 46 | if( cursor != nullptr ) 47 | { 48 | // free cursor 49 | delete cursor; 50 | cursor = nullptr; 51 | } 52 | } 53 | 54 | // reset built 55 | _initialized = false; 56 | } 57 | 58 | //------------------------------------------------------------------------- 59 | const OverlayCursorVault::CursorTable& OverlayCursorVault::GetCursors() const 60 | { 61 | return _cursors; 62 | } 63 | 64 | //------------------------------------------------------------------------- 65 | Bool OverlayCursorVault::IsInitialized() const 66 | { 67 | return _initialized; 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Cursor/OverlayCursorVault.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class OverlayCursorVault 9 | { 10 | public: 11 | // aliases 12 | typedef FlatArray CursorTable; 13 | 14 | /**/ 15 | OverlayCursorVault(); 16 | ~OverlayCursorVault(); 17 | 18 | /**/ 19 | void Initialize(); 20 | void Shutdown(); 21 | 22 | /**/ 23 | Bool IsInitialized() const; 24 | 25 | /**/ 26 | const CursorTable& GetCursors() const; 27 | 28 | private: 29 | // fields 30 | Bool _initialized; 31 | Overlay* _overlay; 32 | CursorTable _cursors; 33 | 34 | }; 35 | } 36 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Mouse/MousePositionMonitor.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | attempts to reduce cursor positioning latency. ideally should be called right before vblank. 3 | 4 | the main drawback to a software cursor is it falls behind the system/hardware cursor which has 5 | privileged access to the a special place in display hardware thats independent of current 6 | framerate. 7 | 8 | by only using GetCursorPos the lag is very noticeable. instead this should wait for as clonse to vblank 9 | as possible to get cursor position + whatever corresponding display of this position. the idea is that 10 | at this point we have the most current update from GetCursorPos plus relative/mickey coordinates from raw 11 | input. relative coordinates are also adjusted for system mouse speed and acceleration. 12 | 13 | its as close to hardware impl as i could come up with without diving into kernel land. its good 14 | enough for most gamers, save the FPS crowd, who dont use a cursor anyway :) 15 | */ 16 | #pragma once 17 | #include 18 | #include 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | #include 26 | #include 27 | 28 | namespace Yolomouse 29 | { 30 | /**/ 31 | class MousePositionMonitor: 32 | public EventListener 33 | { 34 | public: 35 | /**/ 36 | MousePositionMonitor(); 37 | ~MousePositionMonitor(); 38 | 39 | /**/ 40 | Bool Initialize( Window& window ); 41 | void Shutdown(); 42 | 43 | /**/ 44 | Bool IsInitialized() const; 45 | 46 | /**/ 47 | Bool GetCursorPosition( Vector2l& windows_position, Vector2f& nds_position ); 48 | 49 | /**/ 50 | void SetImprovedPrecision( Bool enabled ); 51 | 52 | private: 53 | // constants 54 | static constexpr Float MICKEY_MULTIPLIER_DAMPENER = 0.7f; 55 | 56 | /**/ 57 | void _UpdateMouseSettings(); 58 | 59 | /**/ 60 | void _OnRawInput( HRAWINPUT hrawinput ); 61 | 62 | /**/ 63 | Bool _OnEvent( const WindowEvent& event ); 64 | 65 | // fields: parameters 66 | Window* _window; 67 | Bool _option_improved_precision; 68 | // fields: state 69 | Bool _initialized; 70 | Float _mickey_multiplier; 71 | Vector2l _cursor_position_delta; 72 | HWND _hover_hwnd; 73 | // fields: input 74 | RAWINPUTDEVICE _rawinput_mouse; 75 | }; 76 | } 77 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // public 6 | //------------------------------------------------------------------------- 7 | Mesh::Mesh(): 8 | _render_context (nullptr), 9 | _index_count (0), 10 | _index_buffer (nullptr), 11 | _vertex_buffer (nullptr) 12 | { 13 | } 14 | 15 | Mesh::~Mesh() 16 | { 17 | ASSERT( !IsInitialized() ); 18 | } 19 | 20 | //------------------------------------------------------------------------- 21 | Bool Mesh::Initialize( const InitializeDef& def ) 22 | { 23 | ASSERT( !IsInitialized() ); 24 | D3D11_BUFFER_DESC index_buffer_desc = {}; 25 | D3D11_BUFFER_DESC vertex_buffer_desc = {}; 26 | D3D11_SUBRESOURCE_DATA subresource_data = {}; 27 | HRESULT hresult; 28 | 29 | // set fields 30 | _render_context = &def.render_context; 31 | 32 | // save index count 33 | _index_count = def.indices.GetCount() * 3; 34 | 35 | // describe index buffer 36 | index_buffer_desc.Usage = D3D11_USAGE_DEFAULT; 37 | index_buffer_desc.ByteWidth = sizeof(Index) * _index_count; 38 | index_buffer_desc.BindFlags = D3D11_BIND_INDEX_BUFFER; 39 | 40 | // create index buffer 41 | subresource_data.pSysMem = def.indices.GetMemory(); 42 | if( (hresult = _render_context->GetDevice().CreateBuffer(&index_buffer_desc, &subresource_data, &_index_buffer)) != S_OK ) 43 | return false; 44 | 45 | // describe vertex buffer 46 | vertex_buffer_desc.Usage = D3D11_USAGE_DEFAULT; 47 | vertex_buffer_desc.ByteWidth = sizeof(ShaderVertex) * def.vertices.GetCount(); 48 | vertex_buffer_desc.BindFlags = D3D11_BIND_VERTEX_BUFFER; 49 | vertex_buffer_desc.CPUAccessFlags = 0; 50 | vertex_buffer_desc.MiscFlags = 0; 51 | 52 | // create vertex buffer 53 | subresource_data.pSysMem = def.vertices.GetMemory(); 54 | if( (hresult = _render_context->GetDevice().CreateBuffer(&vertex_buffer_desc, &subresource_data, &_vertex_buffer)) != S_OK ) 55 | return false; 56 | 57 | return true; 58 | } 59 | 60 | void Mesh::Shutdown() 61 | { 62 | ASSERT( IsInitialized() ); 63 | 64 | // shutdown vertex buffer 65 | if( _vertex_buffer ) 66 | { 67 | _vertex_buffer->Release(); 68 | _vertex_buffer = nullptr; 69 | } 70 | 71 | // shutdown index buffer 72 | if( _index_buffer ) 73 | { 74 | _index_buffer->Release(); 75 | _index_buffer = nullptr; 76 | } 77 | 78 | // reset fields 79 | _render_context = nullptr; 80 | } 81 | 82 | //------------------------------------------------------------------------- 83 | Bool Mesh::IsInitialized() const 84 | { 85 | return _render_context != nullptr; 86 | } 87 | 88 | //------------------------------------------------------------------------- 89 | void Mesh::Draw() const 90 | { 91 | ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); 92 | 93 | // set index buffer 94 | device_context.IASetIndexBuffer(_index_buffer, DXGI_FORMAT_R32_UINT, 0); 95 | 96 | // set vertex buffer 97 | UINT stride = sizeof(ShaderVertex); 98 | UINT offset = 0; 99 | device_context.IASetVertexBuffers(0, 1, &_vertex_buffer, &stride, &offset); 100 | 101 | // draw shape 102 | device_context.DrawIndexed(_index_count, 0, 0); 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Assets/Mesh.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class Mesh 9 | { 10 | public: 11 | // types 12 | struct InitializeDef 13 | { 14 | RenderContext& render_context; 15 | Array indices; 16 | Array vertices; 17 | }; 18 | 19 | /**/ 20 | Mesh(); 21 | ~Mesh(); 22 | 23 | /**/ 24 | Bool Initialize( const InitializeDef& def ); 25 | void Shutdown(); 26 | 27 | /**/ 28 | Bool IsInitialized() const; 29 | 30 | /**/ 31 | void Draw() const; 32 | 33 | private: 34 | // fields 35 | RenderContext* _render_context; 36 | Index _index_count; 37 | ID3D11Buffer* _index_buffer; 38 | ID3D11Buffer* _vertex_buffer; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // public 6 | //------------------------------------------------------------------------- 7 | Texture::Texture(): 8 | _render_context (nullptr), 9 | _texture (nullptr), 10 | _texture_view (nullptr) 11 | { 12 | } 13 | 14 | Texture::~Texture() 15 | { 16 | ASSERT( !IsInitialized() ); 17 | } 18 | 19 | //------------------------------------------------------------------------- 20 | Bool Texture::Initialize( const InitializeDef& def ) 21 | { 22 | ASSERT( !IsInitialized() ); 23 | D3D11_TEXTURE2D_DESC texture_desc = {}; 24 | D3D11_SUBRESOURCE_DATA subresource_data = {}; 25 | ID3D11Device& device = def.render_context.GetDevice(); 26 | 27 | // set fields 28 | _render_context = &def.render_context; 29 | 30 | // define texture 31 | texture_desc.Width = def.size.x; 32 | texture_desc.Height = def.size.y; 33 | texture_desc.MipLevels = 1; 34 | texture_desc.ArraySize = 1; 35 | texture_desc.Format = DXGI_FORMAT_R8G8B8A8_UNORM; 36 | texture_desc.SampleDesc.Count = 1; 37 | texture_desc.SampleDesc.Quality = 0; 38 | texture_desc.Usage = D3D11_USAGE_IMMUTABLE; 39 | texture_desc.BindFlags = D3D11_BIND_SHADER_RESOURCE; 40 | texture_desc.CPUAccessFlags = 0; 41 | texture_desc.MiscFlags = 0; 42 | 43 | // define subresource data 44 | subresource_data.pSysMem = def.pixel_data; 45 | subresource_data.SysMemPitch = def.size.x * 4; 46 | 47 | // create texture 48 | if( device.CreateTexture2D( &texture_desc, &subresource_data, &_texture ) == S_OK ) 49 | { 50 | D3D11_SHADER_RESOURCE_VIEW_DESC shader_resource_view_desc = {}; 51 | 52 | // define shader resource view desc 53 | shader_resource_view_desc.Format = texture_desc.Format; 54 | shader_resource_view_desc.ViewDimension = D3D11_SRV_DIMENSION_TEXTURE2D; 55 | shader_resource_view_desc.Texture2D.MipLevels = -1; 56 | shader_resource_view_desc.Texture2D.MostDetailedMip = 0; 57 | 58 | // create texture view 59 | if( device.CreateShaderResourceView( _texture, &shader_resource_view_desc, &_texture_view ) == S_OK ) 60 | return true; 61 | } 62 | 63 | return false; 64 | } 65 | 66 | void Texture::Shutdown() 67 | { 68 | ASSERT( IsInitialized() ); 69 | 70 | // shutdown texture view 71 | if( _texture_view ) 72 | { 73 | _texture_view->Release(); 74 | _texture_view = nullptr; 75 | } 76 | 77 | // shutdown texture 78 | if( _texture ) 79 | { 80 | _texture->Release(); 81 | _texture = nullptr; 82 | } 83 | 84 | // reset fields 85 | _render_context = nullptr; 86 | } 87 | 88 | //------------------------------------------------------------------------- 89 | Bool Texture::IsInitialized() const 90 | { 91 | return _render_context != nullptr; 92 | } 93 | 94 | //------------------------------------------------------------------------- 95 | void Texture::Draw() const 96 | { 97 | ID3D11DeviceContext& device_context = _render_context->GetDeviceContext(); 98 | 99 | // bind texture to pixel shader 100 | device_context.PSSetShaderResources(0, 1, &_texture_view); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Assets/Texture.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class Texture 9 | { 10 | public: 11 | // types 12 | struct InitializeDef 13 | { 14 | RenderContext& render_context; 15 | const void* pixel_data; 16 | Vector2l size; 17 | }; 18 | 19 | /**/ 20 | Texture(); 21 | ~Texture(); 22 | 23 | /**/ 24 | Bool Initialize( const InitializeDef& def ); 25 | void Shutdown(); 26 | 27 | /**/ 28 | Bool IsInitialized() const; 29 | 30 | /**/ 31 | void Draw() const; 32 | 33 | private: 34 | // fields 35 | RenderContext* _render_context; 36 | ID3D11Texture2D* _texture; 37 | ID3D11ShaderResourceView* _texture_view; 38 | }; 39 | } 40 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/RenderContext.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Yolomouse 9 | { 10 | /**/ 11 | class RenderContext 12 | { 13 | public: 14 | /**/ 15 | RenderContext(); 16 | ~RenderContext(); 17 | 18 | /**/ 19 | Bool Initialize( HWND hwnd, const Vector2l& size ); 20 | void Shutdown(); 21 | 22 | /**/ 23 | Bool IsInitialized() const; 24 | Bool IsStarted() const; 25 | 26 | /**/ 27 | ID3D11Device& GetDevice() const; 28 | ID3D11DeviceContext& GetDeviceContext() const; 29 | const RenderTimingController& GetRenderTimingController() const; 30 | const Vector2l& GetSize() const; 31 | 32 | /**/ 33 | void SetReduceLatency( Bool enabled ); 34 | 35 | /**/ 36 | Bool Resize( const Vector2l& size ); 37 | 38 | /**/ 39 | void CommitShaderContants( const VertexShaderConstantValue& vs, const PixelShaderConstantValue& ps ); 40 | 41 | /**/ 42 | void RenderBegin(); 43 | void RenderComplete( Bool idle=false ); 44 | 45 | private: 46 | /**/ 47 | Bool _InitializeD3d( HWND hwnd ); 48 | Bool _InitializeD3dBuffer( ID3D11Buffer*& buffer, D3D11_USAGE usage, ULong size, UINT BindFlags ); 49 | Bool _InitializeD3dDepthStencilView(); 50 | Bool _InitializeD3dRenderTargetView(); 51 | Bool _InitializeBlending(); 52 | void _InitializeView(); 53 | 54 | /**/ 55 | void _ShutdownD3d(); 56 | void _ShutdownD3dDepthStencilView(); 57 | void _ShutdownBlending(); 58 | void _ShutdownD3dRenderTargetView(); 59 | 60 | /**/ 61 | void _Render(); 62 | 63 | // fields: parameters 64 | Vector2l _size; 65 | // fields: state 66 | Bool _initialized; 67 | Bool _started; 68 | Bool _cleared; 69 | RenderTimingController _render_timing_controller; 70 | // fields: state 71 | ID3D11Device* _device; 72 | ID3D11DeviceContext* _device_context; 73 | IDXGIFactory2* _factory; 74 | IDXGISwapChain1* _swapchain; 75 | IDXGIOutput* _swapchain_output; 76 | ID3D11DepthStencilState* _depthstencil_state; 77 | ID3D11Texture2D* _depthstencil_buffer; 78 | ID3D11DepthStencilView* _depthstencil_view; 79 | ID3D11BlendState* _blend_state; 80 | ID3D11RenderTargetView* _render_target_view; 81 | ID3D11VertexShader* _vertex_shader; 82 | ID3D11PixelShader* _pixel_shader; 83 | ID3D11SamplerState* _sampler; 84 | ID3D11InputLayout* _shader_input_layout; 85 | ID3D11Buffer* _vs_constant_buffer; 86 | ID3D11Buffer* _ps_constant_buffer; 87 | ID3D11RasterizerState* _rasterizer_state; 88 | }; 89 | } 90 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/PixelShader.hlsl: -------------------------------------------------------------------------------- 1 | // enums 2 | static const uint TYPE_UNLIT_BASIC = 0; 3 | static const uint TYPE_LIT_BASIC = 1; 4 | static const uint TYPE_UNLIT_TEXTURE = 2; 5 | 6 | // constants 7 | static const float SATURATION = 1.5; 8 | 9 | // texture 10 | SamplerState sampler0: register( s0 ); 11 | Texture2D texture0; 12 | 13 | // constants 14 | cbuffer ConstantBuffer 15 | { 16 | float3 light_vector; 17 | uint type; 18 | }; 19 | 20 | // input 21 | struct PS_INPUT 22 | { 23 | float4 position : SV_POSITION; 24 | float4 color : COLOR; 25 | float3 normal : NORMAL; 26 | float2 uv : UV; 27 | }; 28 | 29 | // main 30 | float4 PS(PS_INPUT input) : SV_Target 31 | { 32 | //return float4(1,1,1,1); 33 | 34 | switch( type ) 35 | { 36 | case TYPE_UNLIT_BASIC: 37 | return input.color; 38 | 39 | case TYPE_LIT_BASIC: 40 | { 41 | float light = dot( input.normal, light_vector ); 42 | return float4(input.color.rgb * SATURATION + light, input.color.a); 43 | } 44 | 45 | case TYPE_UNLIT_TEXTURE: 46 | return texture0.Sample( sampler0, input.uv ) * input.color; 47 | 48 | default: 49 | return float4(1,1,1,1); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Shaders/Default/VertexShader.hlsl: -------------------------------------------------------------------------------- 1 | cbuffer ConstantBuffer 2 | { 3 | float4x4 mvp; 4 | float4x4 model; 5 | float4 variation_color; 6 | }; 7 | 8 | struct VS_INPUT 9 | { 10 | float3 position : POSITION; 11 | float4 color : COLOR; 12 | float3 normal : NORMAL; 13 | float2 uv : UV; 14 | }; 15 | 16 | struct VS_OUTPUT 17 | { 18 | float4 position : SV_POSITION; 19 | float4 color : COLOR; 20 | float3 normal : NORMAL; 21 | float2 uv : UV; 22 | }; 23 | 24 | VS_OUTPUT VS(const VS_INPUT input) 25 | { 26 | VS_OUTPUT output; 27 | 28 | output.position = mul( float4(input.position, 1), mvp ); 29 | output.normal = mul( model, float4(input.normal, 1) ).xyz; 30 | output.uv = input.uv; 31 | 32 | if( input.color.r == 0 && input.color.g == 0 && input.color.b == 0 ) 33 | output.color = float4(variation_color.r, variation_color.g, variation_color.b, input.color.a * variation_color.a); 34 | else 35 | output.color = input.color; 36 | 37 | return output; 38 | } 39 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Shaders/ShaderTypes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | namespace Yolomouse 9 | { 10 | // enum 11 | // TODO3: convert to flags 12 | enum PixelShaderType : Byte4 13 | { 14 | PIXELSHADERTYPE_UNLIT_BASIC = 0, 15 | PIXELSHADERTYPE_LIT_BASIC = 1, 16 | PIXELSHADERTYPE_UNLIT_TEXTURE = 2, 17 | }; 18 | 19 | // types 20 | struct ShaderVertex 21 | { 22 | Vector3f position; 23 | Vector4f color; 24 | Vector3f normal; 25 | Vector2f uv; 26 | }; 27 | 28 | struct VertexShaderConstantValue 29 | { 30 | Matrix4f mvp; 31 | Matrix4f model; 32 | Vector4f variation_color; 33 | }; 34 | 35 | struct PixelShaderConstantValue 36 | { 37 | Vector3f light_vector; 38 | PixelShaderType type; 39 | }; 40 | } 41 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTimingController.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Yolomouse 8 | { 9 | /* 10 | estimates render time based on recent frame skips and uses that to 11 | delay next rendering. call begin/end around all frame processing+ 12 | rendering right after a vblank. 13 | */ 14 | class RenderTimingController 15 | { 16 | public: 17 | /**/ 18 | RenderTimingController(); 19 | ~RenderTimingController(); 20 | 21 | /**/ 22 | void Initialize( IDXGIOutput& dxgi_output, const Vector2l& resolution ); 23 | void Shutdown(); 24 | 25 | /**/ 26 | Bool IsInitialized() const; 27 | 28 | /**/ 29 | Float GetFrameTime() const; // sec 30 | 31 | /**/ 32 | void SetFillTime( Bool enabled ); 33 | 34 | /**/ 35 | void Begin(); 36 | void End(); 37 | 38 | private: 39 | /**/ 40 | void _UpdateFillTime(); 41 | void _CalculateRefreshRate( const Vector2l& resolution ); 42 | 43 | // fields: parameters 44 | IDXGIOutput* _dxgi_output; 45 | Bool _option_fill_time; 46 | // fields: info 47 | Float _refresh_time; 48 | Float _frameskip_threshold; 49 | // fields: state 50 | ULong _fill_time; 51 | Float _render_time; 52 | Float _frame_time; 53 | UHuge _begin_ticks; 54 | }; 55 | } 56 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // public 6 | //------------------------------------------------------------------------- 7 | void RenderTools::BuildOrthoProjectionMatrix( Matrix4f& matrix, Float aspect_ratio ) 8 | { 9 | // calculate x,y cells. scale to NDC (normalized device coordinates) 10 | Float xx = 2.0f / aspect_ratio; 11 | Float yy = 2.0f; 12 | 13 | // update projection matrix 14 | matrix.Set( 15 | xx, 0, 0, 0, 16 | 0, -yy, 0, 0, 17 | 0, 0, 1, 0, 18 | 0, 0, 0, 1 19 | ); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Support/RenderTools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | struct RenderTools 9 | { 10 | /**/ 11 | static void BuildOrthoProjectionMatrix( Matrix4f& matrix, Float aspect_ratio ); 12 | }; 13 | } -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Rendering/Types.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | // types 8 | typedef Vector3u Index3; 9 | } 10 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Text/FontAtlas.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class FontAtlas 9 | { 10 | public: 11 | // types 12 | struct Glyph 13 | { 14 | Bool active = false; 15 | Vector2f offset; 16 | Vector2f size; 17 | Vector2f uv_min; 18 | Vector2f uv_max; 19 | }; 20 | 21 | /**/ 22 | FontAtlas(); 23 | ~FontAtlas(); 24 | 25 | /**/ 26 | Bool Initialize( RenderContext& render_context, const WChar* font_name ); 27 | void Shutdown(); 28 | 29 | /**/ 30 | Bool IsInitialized() const; 31 | 32 | /**/ 33 | const Glyph* GetGlyph( Char character ) const; 34 | const Texture& GetTexture() const; 35 | 36 | private: 37 | // aliases 38 | typedef FlatArray GlyphTable; 39 | 40 | // fields: parameters 41 | RenderContext* _render_context; 42 | Texture _texture; 43 | GlyphTable _glyphs; 44 | }; 45 | } 46 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Text/FontMapBuilder.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Yolomouse 7 | { 8 | /**/ 9 | class FontMapBuilder 10 | { 11 | public: 12 | /**/ 13 | FontMapBuilder(); 14 | ~FontMapBuilder(); 15 | 16 | /**/ 17 | Bool Initialize( const WChar* font_name, Float font_size, ULong map_size ); 18 | void Shutdown(); 19 | 20 | /**/ 21 | Bool IsInitialized() const; 22 | 23 | /**/ 24 | Bool GetCharacterSize( Vector2f& size, WChar character ); 25 | 26 | /**/ 27 | Bool WriteCharacter( const Vector2f& offset, WChar character ); 28 | 29 | /**/ 30 | Bool ToDxMap( Texture& texture, RenderContext& render_context ); 31 | 32 | private: 33 | // fields 34 | ULong _map_size; 35 | ULONG_PTR _token; 36 | Gdiplus::Graphics* _graphics; 37 | Gdiplus::Font* _font; 38 | Gdiplus::Bitmap* _bitmap; 39 | Gdiplus::StringFormat* _string_format; 40 | }; 41 | } 42 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Text/TextMesh.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | 7 | namespace Yolomouse 8 | { 9 | /**/ 10 | class TextMesh 11 | { 12 | public: 13 | /**/ 14 | TextMesh(); 15 | ~TextMesh(); 16 | 17 | /**/ 18 | void Initialize( RenderContext& render_context, const FontAtlas& atlas ); 19 | void Shutdown(); 20 | 21 | /**/ 22 | Bool IsInitialized() const; 23 | 24 | /**/ 25 | Bool SetText( Float& total_width, const String& text, Float height ); 26 | void SetAspectRatio( Float aspect_ratio ); 27 | 28 | /**/ 29 | void Draw( const Vector2f& position, const Vector4f& color ) const; 30 | 31 | private: 32 | /**/ 33 | Bool _BuildTextMesh( Float& total_width, const String& text, Float height ); 34 | 35 | // fields: parameters 36 | RenderContext* _render_context; 37 | const FontAtlas* _atlas; 38 | // fields: state 39 | Mesh _mesh; 40 | Matrix4f _projection_matrix; 41 | }; 42 | } 43 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Overlay/Text/TextPopup.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class TextPopup 9 | { 10 | public: 11 | /**/ 12 | TextPopup(); 13 | ~TextPopup(); 14 | 15 | /**/ 16 | Bool Initialize( RenderContext& render_context ); 17 | void Shutdown(); 18 | 19 | /**/ 20 | Bool IsInitialized() const; 21 | Bool IsActive() const; 22 | 23 | /**/ 24 | Bool SetText( const String& text, const Vector2f& position, ULong timeout ); 25 | void SetAspectRatio( Float aspect_ratio ); 26 | 27 | /**/ 28 | void Draw(); 29 | 30 | private: 31 | // enums 32 | enum State: Byte 33 | { 34 | STATE_IDLE, 35 | STATE_VISIBLE, 36 | STATE_FADING 37 | }; 38 | /**/ 39 | Bool _InitializeBackgrounMesh( const Vector2f& size ); 40 | 41 | /**/ 42 | void _DrawPopup() const; 43 | void _DrawBackgrounMesh( const Vector2f& position, const Vector4f& color ) const; 44 | 45 | // fields: parameters 46 | RenderContext* _render_context; 47 | Vector2f _position; 48 | ULong _timeout; 49 | // fields: state 50 | State _state; 51 | Float _fade; 52 | Float _message_width; 53 | Vector2f _message_position; 54 | Vector2f _header_position; 55 | //TODO2: put into view/scene constantbuffer and call for whole sene 56 | Matrix4f _projection_matrix; 57 | // fields: objects 58 | FontAtlas _font_atlas; 59 | TextMesh _message_mesh; 60 | TextMesh _header_mesh; 61 | Mesh _background_mesh; 62 | }; 63 | } 64 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Resource/AppIcon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/source/YoloMouse/Loader/Resource/AppIcon.ico -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Resource/Resource.aps: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/source/YoloMouse/Loader/Resource/Resource.aps -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Resource/Resource.rc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/source/YoloMouse/Loader/Resource/Resource.rc -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Resource/resource.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PandaTeemo/YoloMouse/982ad68a65f17f3926d713283f73ac858b6820e0/source/YoloMouse/Loader/Resource/resource.h -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Target/Support/CursorVisibilityHacker.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | this is a complete hack to control cursor visibility of another window/process. 3 | 4 | you'd think hiding an app's cursor would be simple (or maybe it is and i missed something) but it requires 5 | injecting into the process. instead i roll with a windows hooks exploit whereby i provide the hook an 6 | already loaded dll (user32.dll) and a pointer to ShowCursor(bool) instead of a legit hook callback. this hook 7 | is then externally triggered such that ShowCursor gets the first argument of a hook routine (nCode) such that 8 | the value is 0 aka FALSE. 9 | */ 10 | #pragma once 11 | #include 12 | #include 13 | #include 14 | 15 | namespace Yolomouse 16 | { 17 | /**/ 18 | class CursorVisibilityHacker: 19 | public Singleton 20 | { 21 | public: 22 | /**/ 23 | CursorVisibilityHacker(); 24 | ~CursorVisibilityHacker(); 25 | 26 | /**/ 27 | Bool Initialize(); 28 | void Shutdown(); 29 | 30 | /**/ 31 | Bool IsInitialized() const; 32 | 33 | /**/ 34 | Bool Show( HWND hwnd, ULong timeout_ms ); 35 | Bool Hide( HWND hwnd, ULong timeout_ms ); 36 | 37 | private: 38 | /**/ 39 | static Bool _IsCursorVisible(); 40 | 41 | /**/ 42 | Bool _TriggerLoop( Bool visibility, ULong timeout_ms ); 43 | 44 | // fields: state 45 | Bool _initialized; 46 | HMODULE _hook_dll; 47 | void* _hook_proc; 48 | }; 49 | } 50 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Target/Target.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Yolomouse 7 | { 8 | /**/ 9 | class Target: 10 | public EventListener 11 | { 12 | public: 13 | /**/ 14 | Target(); 15 | ~Target(); 16 | 17 | /**/ 18 | Bool IsInitialized() const; 19 | Bool IsStarted() const; 20 | Bool IsRestricted() const; 21 | 22 | /**/ 23 | Id GetProcessId() const; 24 | 25 | /**/ 26 | Bool SetCursor( const CursorInfo& updates, CursorUpdateFlags flags ); 27 | Bool SetDefaultCursor(); 28 | Bool ResetCursor(); 29 | 30 | private: 31 | friend class TargetController; 32 | 33 | // types 34 | struct IEventHandler 35 | { 36 | virtual void OnTargetShutdown( Id process_id ) = 0; 37 | }; 38 | 39 | /**/ 40 | Bool Initialize( Id process_id, Bool require_configured, IEventHandler& event_handler ); 41 | void Shutdown(); 42 | 43 | /**/ 44 | Bool Start( Bool allow_restricted_mode ); 45 | void Stop(); 46 | 47 | /**/ 48 | void OnHover( HWND hwnd ); 49 | void OnHoverOut(); 50 | 51 | private: 52 | // constants 53 | static constexpr ULong HACK_VISIBILITY_TIMEOUT = 300; // ms 54 | 55 | /**/ 56 | Bool _InitializeProcessListener(); 57 | void _ShutdownProcessListener(); 58 | 59 | /**/ 60 | static Bool _IsValidCursor( const CursorInfo& properties ); 61 | 62 | /**/ 63 | Bool _SetRestrictedBinding( const CursorInfo& updates, CursorUpdateFlags flags ); 64 | void _ResetRestrictedBinding(); 65 | 66 | /**/ 67 | void _UpdateCursor(); 68 | 69 | /**/ 70 | Bool _BuildBindingsPath(); 71 | 72 | /**/ 73 | void _OnInjectedCursorChanging( const CursorInfo& info ); 74 | void _OnInjectedCursorShowing( Bool showing ); 75 | Bool _OnEvent( const InjectSessionEvent& event ); 76 | 77 | /**/ 78 | static VOID CALLBACK _OnProcessExit( _In_ PVOID lpParameter, _In_ BOOLEAN TimerOrWaitFired ); 79 | 80 | /**/ 81 | static void _BuildDefaultCursor( CursorInfo& info ); 82 | 83 | // fields: parameters 84 | Id _process_id; 85 | IEventHandler* _event_handler; 86 | // fields: info 87 | PathString _bindings_path; 88 | // fields: state 89 | Bool _initialized; 90 | Bool _started; 91 | HWND _hover_hwnd; 92 | Bool _showing; 93 | CursorInfo _active_cursor; 94 | // fields: objects 95 | CursorBindings _restricted_bindings; 96 | InjectSession _inject_session; 97 | HANDLE _process; 98 | HANDLE _wait_handle; 99 | }; 100 | } 101 | -------------------------------------------------------------------------------- /source/YoloMouse/Loader/Target/TargetController.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | namespace Yolomouse 11 | { 12 | /**/ 13 | class TargetController: 14 | public Singleton, 15 | public EventListener, 16 | public EventListener, 17 | public Target::IEventHandler 18 | { 19 | public: 20 | /**/ 21 | TargetController(); 22 | ~TargetController(); 23 | 24 | /**/ 25 | Bool Initialize(); 26 | void Shutdown(); 27 | 28 | /**/ 29 | Bool IsInitialized() const; 30 | 31 | /**/ 32 | void SetGamesOnly( Bool enable ); 33 | 34 | /**/ 35 | Bool AccessTarget( Target*& target, Bool allow_restricted_mode ); 36 | 37 | private: 38 | // impl 39 | void OnTargetShutdown( Id process_id ); 40 | 41 | private: 42 | // types 43 | typedef Map TargetMap; 44 | 45 | /**/ 46 | void _ShutdownTargets(); 47 | 48 | /**/ 49 | Target* _SpawnTarget( Id process_id, Bool require_configured, Bool allow_restricted_mode ); 50 | 51 | /**/ 52 | void _OnWindowForeground( HWND hwnd ); 53 | void _OnWindowHover( HWND hwnd ); 54 | Bool _OnEvent( const SystemMonitorEvent& event ); 55 | Bool _OnEvent( const OverlayEvent& event ); 56 | 57 | // fields: parameters 58 | Bool _games_only; 59 | // fields: state 60 | Bool _initialized; 61 | TargetMap _targets; 62 | Target* _hover_target; 63 | }; 64 | } 65 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Constants.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | //------------------------------------------------------------------------ 6 | const WCHAR* APP_MENU_STRINGS[MENU_OPTION_COUNT] = 7 | { 8 | // info 9 | L"About", //MENU_OPTION_ABOUT 10 | L"Errors", //MENU_OPTION_ERRORS 11 | // settings 12 | L"Start with Windows", //MENU_OPTION_AUTOSTART 13 | L"Reduce overlay pointer lag", //MENU_OPTION_REDUCEOVERLAYLAG 14 | // etc 15 | L"Run as Administrator", //MENU_OPTION_RUNASADMIN 16 | L"Open settings folder", //MENU_OPTION_SETTINGSFOLDER 17 | }; 18 | 19 | //------------------------------------------------------------------------ 20 | static Settings::KeyValue _settings[SETTING_COUNT] = 21 | { 22 | { "CursorKeyBasic", "CONTROL ALT 1" }, 23 | { "CursorKeyOverlay", "CONTROL ALT 2" }, 24 | { "CursorKeyVariation", "CONTROL ALT 3" }, 25 | { "CursorKeyDefault", "CONTROL ALT D" }, 26 | { "CursorKeyReset", "CONTROL ALT 0" }, 27 | { "CursorKeySmaller", "CONTROL ALT -" }, 28 | { "CursorKeyLarger", "CONTROL ALT =" }, 29 | { "AutoStart", "1" }, 30 | { "ReduceOverlayLag", "0" }, 31 | { "ShowMenu", "1" }, 32 | }; 33 | Settings::KeyValueCollection SETTINGS_ITEMS(_settings, SETTING_COUNT); 34 | } 35 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Constants.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | // numeric 8 | //------------------------------------------------------------------------- 9 | static const ULong APP_VERSION[] = { 0, 11, 3 }; 10 | static const ULong CURSOR_CACHE_LIMIT = 50; 11 | 12 | // strings 13 | //------------------------------------------------------------------------- 14 | extern const WCHAR* APP_MENU_STRINGS[]; 15 | static const WCHAR* APP_NAME = L"YoloMouse"; 16 | static const Char* APP_NAMEC = "YoloMouse"; 17 | static const WCHAR* OVERLAY_NAME = L"YoloCursorOverlay"; 18 | static const WCHAR* OVERLAY_CLASS = L"YoloCursorClass"; 19 | 20 | static const WCHAR* PATH_LOADER = L"YoloMouse.exe"; 21 | static const CHAR* PATH_DLL32 = "Yolo32.dll"; 22 | static const CHAR* PATH_DLL64 = "Yolo64.dll"; 23 | static const WCHAR* PATH_LOG_NAME = L"log.txt"; 24 | static const WCHAR* PATH_SETTINGS = L"Settings.ini"; 25 | static const WCHAR* PATH_CURSORS_CUSTOM = L"Cursors"; 26 | static const WCHAR* PATH_CURSORS_DEFAULT = L"Cursors\\Default"; 27 | static const WCHAR* EXTENSION_INI = L"ini"; 28 | static const WCHAR* EXTENSION_STATIC_CURSOR = L"cur"; 29 | static const WCHAR* EXTENSION_ANIMATED_CURSOR = L"ani"; 30 | 31 | static const WCHAR* IPC_MUTEX_NAME = L"YoloMouseMutex"; 32 | static const WCHAR* IPC_MEMORY_NAME = L"YoloMouseMemory"; 33 | 34 | static const Char* NOTIFY_REQUIRE_RESTRICTED_MODE = "Cursor binding failed. Try running Yolomouse as Administrator."; 35 | static const Char* NOTIFY_ENTERED_RESTRICTED_MODE = "Cursor binding failed. Using overlay cursors instead."; 36 | 37 | static const Char* TEXT_ABOUT = "Version %u.%u.%u %u-Bit\nBy HaPpY :)"; 38 | static const Char* TEXT_NOLOG = "No log :P"; 39 | 40 | // tables 41 | //------------------------------------------------------------------------- 42 | extern Settings::KeyValueCollection SETTINGS_ITEMS; 43 | } 44 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorBindings.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // public 6 | //------------------------------------------------------------------------- 7 | CursorBindings::CursorBindings() 8 | { 9 | } 10 | 11 | CursorBindings::~CursorBindings() 12 | { 13 | } 14 | 15 | //------------------------------------------------------------------------- 16 | CursorInfo* CursorBindings::GetBinding( Hash hash ) 17 | { 18 | return _bindings.Get( hash ); 19 | } 20 | 21 | const CursorBindings::BindingMap& CursorBindings::GetBindings() const 22 | { 23 | return _bindings; 24 | } 25 | 26 | CursorInfo& CursorBindings::GetDefaultBinding() 27 | { 28 | return _default_binding; 29 | } 30 | 31 | const CursorInfo& CursorBindings::GetDefaultBinding() const 32 | { 33 | return _default_binding; 34 | } 35 | 36 | //------------------------------------------------------------------------- 37 | CursorInfo* CursorBindings::CreateBinding( Hash hash ) 38 | { 39 | return &_bindings.Set( hash ); 40 | } 41 | 42 | //------------------------------------------------------------------------- 43 | Bool CursorBindings::RemoveBinding( Hash hash ) 44 | { 45 | return _bindings.Remove( hash ); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorBindings.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | 6 | namespace Yolomouse 7 | { 8 | /**/ 9 | class CursorBindings 10 | { 11 | public: 12 | // aliases 13 | typedef Map BindingMap; 14 | 15 | /**/ 16 | CursorBindings(); 17 | ~CursorBindings(); 18 | 19 | /**/ 20 | CursorInfo* GetBinding( Hash cursor_hash ); 21 | const BindingMap& GetBindings() const; 22 | CursorInfo& GetDefaultBinding(); 23 | const CursorInfo& GetDefaultBinding() const; 24 | 25 | /**/ 26 | CursorInfo* CreateBinding( Hash hash ); 27 | 28 | /**/ 29 | Bool RemoveBinding( Hash hash ); 30 | 31 | private: 32 | // fields 33 | BindingMap _bindings; 34 | CursorInfo _default_binding; 35 | }; 36 | } 37 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorBindingsSerializer.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /**/ 8 | class CursorBindingsSerializer 9 | { 10 | public: 11 | /**/ 12 | static Bool Load( CursorBindings& bindings, const PathString& bindings_path ); 13 | static Bool Save( const CursorBindings& bindings, const PathString& bindings_path ); 14 | 15 | private: 16 | /**/ 17 | static Bool _ReadBindingLine( Hash& hash, CursorInfo& info, FILE* file ); 18 | static Bool _WriteBindingLine( const Hash hash, const CursorInfo& info, FILE* file ); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorInfo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | // public 6 | //------------------------------------------------------------------------- 7 | CursorInfo::CursorInfo( CursorType type_, CursorId id_, CursorVariation variation_, CursorSize size_ ): 8 | type (type_), 9 | id (id_), 10 | variation(variation_), 11 | size (size_) 12 | { 13 | } 14 | 15 | //------------------------------------------------------------------------- 16 | Bool CursorInfo::IsValid() const 17 | { 18 | // validate type and associated parameters 19 | switch( type ) 20 | { 21 | case CURSOR_TYPE_BASIC: 22 | case CURSOR_TYPE_OVERLAY: 23 | return id < CURSOR_ID_COUNT && variation < CURSOR_VARIATION_COUNT && size >= CURSOR_SIZE_MIN && size < CURSOR_SIZE_COUNT; 24 | case CURSOR_TYPE_CLONE: 25 | return size >= CURSOR_SIZE_MIN && size < CURSOR_SIZE_COUNT; 26 | default: 27 | return false; 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorInfo.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | struct CursorInfo 8 | { 9 | // fields 10 | CursorType type; 11 | CursorId id; 12 | CursorVariation variation; 13 | CursorSize size; 14 | 15 | /**/ 16 | CursorInfo( 17 | CursorType type_ = CURSOR_TYPE_INVALID, 18 | CursorId id_ = CURSOR_ID_INVALID, 19 | CursorVariation variation_ = CURSOR_VARIATION_INVALID, 20 | CursorSize size_ = CURSOR_SIZE_INVALID ); 21 | 22 | /**/ 23 | Bool IsValid() const; 24 | }; 25 | } 26 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorTools.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | class CursorTools 8 | { 9 | public: 10 | /**/ 11 | static CursorSize SizeToId( ULong size ); 12 | static ULong IdToSize( CursorSize id ); 13 | static ULong HandleToSize( HCURSOR hcursor ); 14 | static Bool IdVariationToIndex( Index& index, CursorId id, CursorVariation variation ); 15 | static Bool IndexToIdVariation( CursorId& id, CursorVariation& variation, Index index ); 16 | 17 | /**/ 18 | static void PatchProperties( CursorInfo& properties, const CursorInfo& updates, CursorUpdateFlags flags ); 19 | }; 20 | } 21 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorTypes.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | // enums 7 | //------------------------------------------------------------------------- 8 | enum CursorType: Byte 9 | { 10 | CURSOR_TYPE_BASIC, // one of preinstalled (or user provided) cur/ani files 11 | CURSOR_TYPE_CLONE, // clone of existing application cursor, used to modding that cursor such as resize 12 | CURSOR_TYPE_OVERLAY, // a directx overlay cursor, this has a little lag despite methods to reduce it, but its much prettier! 13 | CURSOR_TYPE_INVALID 14 | }; 15 | 16 | typedef Byte CursorId; 17 | enum: Byte 18 | { 19 | CURSOR_ID_COUNT = 10, 20 | CURSOR_ID_INVALID, 21 | CURSOR_ID_OVERLAY_COUNT = 2, 22 | }; 23 | 24 | typedef Byte CursorVariation; 25 | enum: Byte 26 | { 27 | CURSOR_VARIATION_COUNT = 10, 28 | CURSOR_VARIATION_INVALID 29 | }; 30 | 31 | typedef Char CursorSize; 32 | enum: Char 33 | { 34 | CURSOR_SIZE_INVALID, 35 | CURSOR_SIZE_MIN = 1, 36 | CURSOR_SIZE_DEFAULT = 7, 37 | CURSOR_SIZE_COUNT = 16 38 | }; 39 | 40 | typedef Byte CursorUpdateFlags; 41 | enum: Byte 42 | { 43 | CURSOR_UPDATE_INCREMENT_TYPE = BIT(0), 44 | CURSOR_UPDATE_INCREMENT_ID = BIT(1), 45 | CURSOR_UPDATE_INCREMENT_VARIATION = BIT(2), 46 | CURSOR_UPDATE_INCREMENT_SIZE = BIT(3), 47 | CURSOR_UPDATE_DECREMENT_SIZE = BIT(4), 48 | }; 49 | 50 | typedef Byte CursorIterateFlags; 51 | enum: Byte 52 | { 53 | CURSOR_ITERATE_TYPE = BIT(0), 54 | CURSOR_ITERATE_ID = BIT(1), 55 | CURSOR_ITERATE_VARIATION = BIT(2), 56 | CURSOR_ITERATE_SIZE = BIT(3), 57 | }; 58 | } 59 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Cursor/CursorVault.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | namespace Yolomouse 10 | { 11 | /**/ 12 | class CursorVault 13 | { 14 | public: 15 | /**/ 16 | CursorVault(); 17 | ~CursorVault(); 18 | 19 | /**/ 20 | void Initialize( const PathString& host_path ); 21 | void Shutdown(); 22 | 23 | /**/ 24 | Bool IsInitialized() const; 25 | 26 | /**/ 27 | Bool HasCursor( HCURSOR hcursor ); 28 | 29 | /**/ 30 | HCURSOR GetBasic( CursorId id, CursorVariation variation, CursorSize size ); 31 | HCURSOR GetClone( Hash cursor_hash, CursorSize size ); 32 | HCURSOR GetHidden(); 33 | 34 | /**/ 35 | HCURSOR LoadBasic( CursorId id, CursorVariation variation, CursorSize size ); 36 | HCURSOR LoadClone( HCURSOR hcursor, Hash cursor_hash, CursorSize size ); 37 | 38 | /**/ 39 | void UnloadBasic( CursorId id, CursorVariation variation, CursorSize size ); 40 | void UnloadClone( Hash cursor_hash, CursorSize size ); 41 | void UnloadAll(); 42 | 43 | private: 44 | // enums 45 | enum ResourceState 46 | { 47 | RESOURCE_NONE, 48 | RESOURCE_READY, 49 | RESOURCE_FAILED, 50 | }; 51 | 52 | // types 53 | struct CursorCache 54 | { 55 | // fields 56 | HCURSOR hcursor; 57 | ULong referenced; 58 | 59 | /**/ 60 | CursorCache(); 61 | ~CursorCache(); 62 | }; 63 | typedef FlatArray CacheTable; 64 | 65 | struct BasicEntry 66 | { 67 | // fields 68 | ResourceState state; 69 | Bool resizable; 70 | ULong width; 71 | ULong height; 72 | PathString path; 73 | UINT loadimage_flags; 74 | CacheTable cache_table; 75 | 76 | /**/ 77 | BasicEntry(); 78 | }; 79 | typedef FlatArray2 BasicTable; 80 | 81 | struct CloneEntry 82 | { 83 | // fields 84 | CacheTable cache_table; 85 | }; 86 | typedef Map CloneMap; 87 | 88 | /**/ 89 | void _InitializeHiddenCursor(); 90 | 91 | /**/ 92 | void _ShutdownCaches(); 93 | void _ShutdownHiddenCursor(); 94 | 95 | /**/ 96 | Bool _PreLoadBasic( BasicEntry& entry, CursorId id, CursorVariation variation ); 97 | Bool _PreLoadBasicEntry( BasicEntry& entry ); 98 | HCURSOR _LoadBasic( BasicEntry& entry, CursorSize size ); 99 | void _UnloadBasic( BasicEntry& entry, CursorSize size ); 100 | 101 | /**/ 102 | HCURSOR _LoadClone( CloneEntry& entry, HCURSOR hcursor, CursorSize size ); 103 | void _UnloadClone( CloneEntry& entry, CursorSize size ); 104 | 105 | /**/ 106 | void _ShutdownCache( CursorCache& cache ); 107 | 108 | // fields: parameters 109 | PathString _host_path; 110 | // fields: state 111 | Bool _initialized; 112 | BasicTable _basic_table; 113 | CloneMap _clone_map; 114 | HCURSOR _hidden_cursor; 115 | }; 116 | } 117 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Enums.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | // enums 7 | //------------------------------------------------------------------------- 8 | enum IpcRequest: Byte 9 | { 10 | IPC_REQUEST_INVALID, 11 | IPC_REQUEST_LOAD, 12 | IPC_REQUEST_EXIT, 13 | IPC_REQUEST_SET_CURSOR, 14 | IPC_REQUEST_SET_DEFAULT_CURSOR, 15 | IPC_REQUEST_RESET_CURSOR, 16 | IPC_REQUEST_REFRESH_CURSOR, 17 | IPC_REQUEST_ON_CURSOR_CHANGING, 18 | IPC_REQUEST_ON_CURSOR_SHOWING, 19 | }; 20 | 21 | enum 22 | { 23 | SETTING_CURSORKEY_BASIC, 24 | SETTING_CURSORKEY_OVERLAY, 25 | SETTING_CURSORKEY_VARIATION, 26 | SETTING_CURSORKEY_DEFAULT, 27 | SETTING_CURSORKEY_RESET, 28 | SETTING_CURSORKEY_SMALLER, 29 | SETTING_CURSORKEY_LARGER, 30 | SETTING_AUTOSTART, 31 | SETTING_REDUCEOVERLAYLAG, 32 | SETTING_SHOWMENU, 33 | SETTING_COUNT 34 | }; 35 | 36 | enum 37 | { 38 | // info 39 | MENU_OPTION_ABOUT, 40 | MENU_OPTION_ERRORS, 41 | // options 42 | MENU_OPTION_AUTOSTART, 43 | MENU_OPTION_REDUCEOVERLAYLAG, 44 | // etc 45 | MENU_OPTION_RUNASADMIN, 46 | MENU_OPTION_SETTINGSFOLDER, 47 | 48 | MENU_OPTION_COUNT 49 | }; 50 | } 51 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Ipc/IpcMessage.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | #include 4 | 5 | namespace Yolomouse 6 | { 7 | /* 8 | message object communicated between loader and dll. must coexist between 32 and 64 bit. 9 | */ 10 | #pragma pack(4) 11 | struct IpcMessage 12 | { 13 | // request id 14 | IpcRequest request; 15 | }; 16 | 17 | struct LoadIpcMessage: 18 | public IpcMessage 19 | { 20 | PathString host_path; 21 | PathString log_path; 22 | PathString bindings_path; 23 | }; 24 | 25 | struct SetCursorIpcMessage: 26 | public IpcMessage 27 | { 28 | CursorInfo properties; 29 | CursorUpdateFlags flags; 30 | }; 31 | 32 | struct OnCursorChangingIpcMessage: 33 | public IpcMessage 34 | { 35 | CursorInfo info; 36 | }; 37 | 38 | struct OnCursorShowingIpcMessage: 39 | public IpcMessage 40 | { 41 | Bool showing; 42 | }; 43 | #pragma pack() 44 | } 45 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Ipc/IpcMessenger.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | // public 7 | //------------------------------------------------------------------------- 8 | Bool IpcMessenger::Initialize( ULong process_id, IListener& listener ) 9 | { 10 | Char temp_name[IpcPair::IPC_NAME_LIMIT]; 11 | 12 | // build name 13 | sprintf_s( temp_name, sizeof(temp_name), IPC_NAME_FORMAT, process_id ); 14 | 15 | // determine max size required 16 | ULong size = static_cast(Tools::Max( sizeof( LoadIpcMessage ), sizeof( SetCursorIpcMessage ) )); 17 | 18 | // initialize ipc pair 19 | //WARN: IListener ghetto casting IpcPair::IListener 20 | return _ipc.Initialize( temp_name, size, reinterpret_cast(listener) ); 21 | } 22 | 23 | void IpcMessenger::Shutdown() 24 | { 25 | // shutdown ipc pair 26 | _ipc.Shutdown(); 27 | } 28 | 29 | //------------------------------------------------------------------------- 30 | Bool IpcMessenger::Send( const IpcMessage& message, ULong size, ULong timeout ) 31 | { 32 | return _ipc.Send( &message, size, timeout ); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Ipc/IpcMessenger.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | namespace Yolomouse 5 | { 6 | /**/ 7 | class IpcMessenger 8 | { 9 | public: 10 | /**/ 11 | struct IListener 12 | { 13 | /**/ 14 | virtual void OnRecv( const IpcMessage& message ) = 0; 15 | }; 16 | 17 | // constants 18 | static const ULong SEND_TIMEOUT = 100; // ms 19 | 20 | /**/ 21 | Bool Initialize( ULong process_id, IListener& listener ); 22 | void Shutdown(); 23 | 24 | /**/ 25 | Bool Send( const IpcMessage& message, ULong size, ULong timeout=SEND_TIMEOUT ); 26 | 27 | private: 28 | // constants 29 | static constexpr Char* IPC_NAME_FORMAT = "YoloIpc.%u"; 30 | 31 | // fields 32 | IpcPair _ipc; 33 | }; 34 | } 35 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Root.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | namespace Yolomouse 4 | { 5 | //------------------------------------------------------------------------ 6 | void LogShared( const Char* format, ... ) 7 | { 8 | //SharedState::Instance().GetLog(); 9 | // macros 10 | //SharedState::Instance().GetLog().Write 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /source/YoloMouse/Share/Root.hpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #include 3 | //#include 4 | 5 | namespace Yolomouse 6 | { 7 | using namespace Core; 8 | //using namespace Snoopy; 9 | 10 | /**/ 11 | //TODO: write to userpath/log.txt 12 | //extern void LogShared( const Char* format, ... ); 13 | //#define LOG LogShared 14 | //#define LOG LogFile 15 | } 16 | --------------------------------------------------------------------------------