Пример #1
0
        static void Run(string target, JobType job)
        {
            bool existsMainWindow = MainWindowUtility.ExistsMainWindow();

            if (!existsMainWindow && !ScreenUtility.IsForegroundFullScreen())
            {
                if (!Launch(target))
                {
                    return;
                }
            }
            else
            {
                Console.WriteLine("Main windows had been opened");
            }

            if (existsMainWindow)
            {
                MainWindowUtility.ActivateAndWait();
            }

            var screenBounds = ScreenUtility.GetScreenBounds(null);

            Console.WriteLine("Screen: <{0}, {1}, {2}, {3}>",
                              screenBounds.Top, screenBounds.Left, screenBounds.Height, screenBounds.Width);

            IntPtr hwnd = IntPtr.Zero;

            if (!ScreenUtility.IsForegroundFullScreen())
            {
                hwnd = MainWindowUtility.GetMainWindowHandle();

                var windowBounds = ScreenUtility.GetWindowBounds(hwnd);
                var clientRect   = ScreenUtility.GetClientRect(hwnd);

                Console.WriteLine("Window: <{0}, {1}, {2}, {3}>",
                                  windowBounds.Top, windowBounds.Left, windowBounds.Height, windowBounds.Width);

                Console.WriteLine("Client: <{0}, {1}, {2}, {3}>",
                                  clientRect.Top, clientRect.Left, clientRect.Height, clientRect.Width);

                ScreenUtility.SetScreenAttribute(screenBounds, false);
                //int left, width, top, height;
                //if (windowBounds.Left < 0)
                //{
                //    width = windowBounds.Width - 2 * Math.Abs(windowBounds.Left);
                //    left = 0;
                //}
                //else
                //{
                //    width = windowBounds.Width;
                //    left = windowBounds.Left;
                //}

                //if (windowBounds.Top < 0)
                //{
                //    height = windowBounds.Height - 2 * Math.Abs(windowBounds.Top);
                //    top = 0;
                //}
                //else
                //{
                //    height = windowBounds.Height;
                //    top = windowBounds.Top;
                //}
            }
            else
            {
                ScreenUtility.SetScreenAttribute(screenBounds, true);
            }

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                Console.WriteLine("Failed to show main window although main window was opened");
                MainWindowUtility.Close();

                return;
            }

            if (job == JobType.ElementChallenge)
            {
                //if (!CheatEngineUtility.EnableCheating())
                //{
                //    Console.WriteLine("Cheating is not enabled, can't run element challenging job");
                //    return;
                //}
            }

            if (!ScreenUtility.IsForegroundFullScreen())
            {
                MainWindowUtility.ActivateAndWait();
            }

            Run(job);

            if (_stateWaiter.Detector.Detect() != GameState.MainWindow)
            {
                Console.WriteLine("Failed to go back main window after run");
                MainWindowUtility.Close();

                return;
            }
        }