Beispiel #1
0
        public static void SetFocusToDesktop()
        {
            Action d = delegate()
            {
                IntPtr winHandle = WindowsUtilities.FindWindow("CrypticWindow", null);
                WindowsUtilities.SetForegroundWindow(winHandle);
            };

            System.Windows.Application.Current?.Dispatcher?.Invoke(d);
        }
Beispiel #2
0
 internal IntPtr HandleKeyboardEvent(int nCode, IntPtr wParam, IntPtr lParam)
 {
     if (nCode >= 0)
     {
         KBDLLHOOKSTRUCT keyboardLLHookStruct = (KBDLLHOOKSTRUCT)(Marshal.PtrToStructure(lParam, typeof(KBDLLHOOKSTRUCT)));
         this.vkCode = (Keys)keyboardLLHookStruct.vkCode;
         KeyboardMessage wmKeyboard = (KeyboardMessage)wParam;
         if ((wmKeyboard == KeyboardMessage.WM_KEYDOWN || wmKeyboard == KeyboardMessage.WM_SYSKEYDOWN))
         {
             IntPtr foregroundWindow = WindowsUtilities.GetForegroundWindow();
             uint   wndProcId;
             uint   wndProcThread = WindowsUtilities.GetWindowThreadProcessId(foregroundWindow, out wndProcId);
             if (foregroundWindow == WindowsUtilities.FindWindow("CrypticWindow", null) ||
                 Process.GetCurrentProcess().Id == wndProcId)
             {
                 System.Windows.Input.Key inputKey = InputKey;
                 if ((inputKey == Key.Left || inputKey == Key.Right) && Keyboard.Modifiers == ModifierKeys.Control)
                 {
                     DesktopManager.SetFocusToDesktop();
                 }
                 else
                 {
                     lock (lockObj)
                     {
                         try
                         {
                             foreach (HandleKeyEvent _handleKeyEvent in _handleKeyEvents.Where(handler => !_suspendedHandleKeyEvents.Contains(handler)))
                             {
                                 EventMethod handler = _handleKeyEvent(vkCode, inputKey);
                                 if (handler != null)
                                 {
                                     handler();
                                 }
                             }
                         }
                         catch (Exception ex)
                         {
                         }
                     }
                 }
             }
         }
     }
     return(CallNextHook(hookID, nCode, wParam, lParam));
 }
Beispiel #3
0
        public void InitializeDlll(string path)
        {
            //TO DO FIX
            dllHandle = WindowsUtilities.LoadLibrary(Path.Combine(path, "HookCostume.dll"));
            if (dllHandle != null)
            {
                var initGameAddress = WindowsUtilities.GetProcAddress(dllHandle, "InitGame");
                if (initGameAddress != IntPtr.Zero)
                {
                    initGame = (InitGame)Marshal.GetDelegateForFunctionPointer(initGameAddress, typeof(InitGame));
                }

                var closeGameAddress = WindowsUtilities.GetProcAddress(dllHandle, "CloseGame");
                if (closeGameAddress != IntPtr.Zero)
                {
                    closeGame = (CloseGame)Marshal.GetDelegateForFunctionPointer(closeGameAddress, typeof(CloseGame));
                }

                var setUserHWndAddress = WindowsUtilities.GetProcAddress(dllHandle, "SetUserHWND");
                if (setUserHWndAddress != IntPtr.Zero)
                {
                    setUserHWnd =
                        (SetUserHWND)Marshal.GetDelegateForFunctionPointer(setUserHWndAddress, typeof(SetUserHWND));
                }

                var executeCmdAddress = WindowsUtilities.GetProcAddress(dllHandle, "ExecuteCommand");
                if (executeCmdAddress != IntPtr.Zero)
                {
                    executeCmd =
                        (ExecuteCommand)
                        Marshal.GetDelegateForFunctionPointer(executeCmdAddress, typeof(ExecuteCommand));
                }

                var getHoveredNPCInfoAddress = WindowsUtilities.GetProcAddress(dllHandle, "GetHoveredNPCInfo");
                if (getHoveredNPCInfoAddress != IntPtr.Zero)
                {
                    getHoveredNPCInfo =
                        (GetHoveredNPCInfo)
                        Marshal.GetDelegateForFunctionPointer(getHoveredNPCInfoAddress, typeof(GetHoveredNPCInfo));
                }

                var getMouseXYZInGameAddress = WindowsUtilities.GetProcAddress(dllHandle, "GetMouseXYZInGame");
                if (getMouseXYZInGameAddress != IntPtr.Zero)
                {
                    getMouseXYZInGame =
                        (GetMouseXYZInGame)
                        Marshal.GetDelegateForFunctionPointer(getMouseXYZInGameAddress, typeof(GetMouseXYZInGame));
                }

                var checkGameDoneAddress = WindowsUtilities.GetProcAddress(dllHandle, "CheckGameDone");
                if (checkGameDoneAddress != IntPtr.Zero)
                {
                    checkIfGameLoaded =
                        (CheckIfGameLoaded)
                        Marshal.GetDelegateForFunctionPointer(checkGameDoneAddress, typeof(CheckIfGameLoaded));
                }

                var detectCollisionAddress = WindowsUtilities.GetProcAddress(dllHandle, "CollisionDetection");
                if (checkGameDoneAddress != IntPtr.Zero)
                {
                    detectCollision =
                        (DetectCollision)
                        Marshal.GetDelegateForFunctionPointer(detectCollisionAddress, typeof(DetectCollision));
                }
            }
        }
        internal IntPtr HandleMouseEvent(int nCode, IntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
            {
                if (MouseMessage.WM_LBUTTONDOWN == (MouseMessage)wParam)
                {
                    MouseClickCount++;
                    switch (MouseClickCount)
                    {
                    case 1:
                        MouseState = DesktopMouseState.LEFT_CLICK;
                        Action action = delegate()
                        {
                            mouseClicksTracker.Start();
                        };
                        System.Windows.Application.Current.Dispatcher.BeginInvoke(action);
                        break;

                    case 2:
                        MouseState = DesktopMouseState.DOUBLE_CLICK;
                        break;

                    case 3: MouseState = DesktopMouseState.TRIPLE_CLICK; break;

                    case 4: MouseState = DesktopMouseState.QUAD_CLICK; break;
                    }
                }
                else if (MouseMessage.WM_RBUTTONDOWN == (MouseMessage)wParam)
                {
                    MouseState = DesktopMouseState.RIGHT_CLICK;
                }
                else if (MouseMessage.WM_RBUTTONUP == (MouseMessage)wParam)
                {
                    MouseState = DesktopMouseState.RIGHT_CLICK_UP;
                }
                else if (MouseMessage.WM_LBUTTONUP == (MouseMessage)wParam)
                {
                    MouseState = DesktopMouseState.LEFT_CLICK_UP;
                }
                else if (MouseMessage.WM_MOUSEMOVE == (MouseMessage)wParam)
                {
                    MouseState = DesktopMouseState.MOUSE_MOVE;
                }
                IntPtr foregroundWindow = WindowsUtilities.GetForegroundWindow();
                if (foregroundWindow == WindowsUtilities.FindWindow("CrypticWindow", null))
                {
                    if (MouseState == DesktopMouseState.MOUSE_MOVE)
                    {
                        FireMouseMoveEvent();
                    }
                    else if (MouseState == DesktopMouseState.LEFT_CLICK)
                    {
                        FireMouseLeftClick();
                    }
                    else if (MouseState == DesktopMouseState.RIGHT_CLICK)
                    {
                        FireMouseRightClick();
                    }
                    else if (MouseState == DesktopMouseState.LEFT_CLICK_UP)
                    {
                        FireMouseLeftClickUp();
                    }
                    else if (MouseState == DesktopMouseState.RIGHT_CLICK_UP)
                    {
                        FireMouseRightClickUp();
                    }
                    else if (MouseState == DesktopMouseState.DOUBLE_CLICK)
                    {
                        FireMouseDoubleClick();
                    }
                    else if (MouseState == DesktopMouseState.TRIPLE_CLICK)
                    {
                        FireMouseTripleCLick();
                    }
                }
            }
            return(MouseHook.CallNextHookEx(MouseHookID, nCode, wParam, lParam));
        }