Ejemplo n.º 1
0
        /// <summary>
        /// Creates new CustomGame object.
        /// </summary>
        public CustomGame(CustomGameBuilder customGameBuilder = default)
        {
            if (customGameBuilder == null)
            {
                customGameBuilder = new CustomGameBuilder();
            }

            if (customGameBuilder.OverwatchHandle == IntPtr.Zero)
            {
                // Get the overwatch process
                Process[] overwatchProcesses = Process.GetProcessesByName("Overwatch");
                if (overwatchProcesses.Length > 0)
                {
                    OverwatchHandle = overwatchProcesses[0].MainWindowHandle;
                }
            }
            else
            {
                OverwatchHandle = customGameBuilder.OverwatchHandle;
            }

            if (OverwatchHandle == IntPtr.Zero)
            {
                throw new MissingOverwatchProcessException("Could not find any Overwatch processes running.");
            }

            SetupWindow(OverwatchHandle, ScreenshotMethod);
            Thread.Sleep(500);

            // Set up debug window if debugmode is set to true.
            if (debugmode)
            {
                new Task(() =>
                {
                    debug        = new Form();
                    debug.Width  = 1500;
                    debug.Height = 1000;
                    debug.Show();
                    g = debug.CreateGraphics();
                    g.InterpolationMode = System.Drawing.Drawing2D.InterpolationMode.NearestNeighbor;
                    Application.Run(debug);
                }).Start();
            }

            Commands   = new Commands(this);
            AI         = new AI(this);
            Chat       = new Chat(this);
            Pause      = new Pause(this);
            PlayerInfo = new PlayerInfo(this);
            Interact   = new Interact(this);
            Settings   = new Settings(this);

            ScreenshotMethod  = customGameBuilder.ScreenshotMethod;
            OpenChatIsDefault = customGameBuilder.OpenChatIsDefault;
            DefaultKeys       = customGameBuilder.DefaultKeys;

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }

            SetupGameOverCheck();
        }
        /// <summary>
        /// Creates new CustomGame object.
        /// </summary>
        public CustomGame(CustomGameBuilder customGameBuilder = null)
        {
            if (customGameBuilder == null)
            {
                customGameBuilder = new CustomGameBuilder();
            }

            // Get the overwatch process.
            if (customGameBuilder.OverwatchProcess != null)
            {
                OverwatchProcess = customGameBuilder.OverwatchProcess;
            }
            else
            {
                OverwatchProcess = GetOverwatchProcess();
            }

            if (OverwatchProcess == null)
            {
                throw new MissingOverwatchProcessException("Could not find any Overwatch processes running.");
            }

            // Initialize the LockHandler.
            LockHandler = new LockHandler(this);

            // Save the customGameBuilder values to the class.
            ScreenshotMethod  = customGameBuilder.ScreenshotMethod;
            OpenChatIsDefault = customGameBuilder.OpenChatIsDefault;
            DefaultKeys       = customGameBuilder.DefaultKeys;
            DisableInput      = customGameBuilder.DisableInput;

            // Create a link between OnExit and OverwatchProcess.Exited.
            OverwatchProcess.EnableRaisingEvents = true;
            OverwatchProcess.Exited += InvokeOnExit;

            // Move the window to the correct position on the desktop for scanning and input.
            SetupWindow(OverwatchHandle, ScreenshotMethod);
            Thread.Sleep(250);

            // Create subclass instances.
            Commands   = new Commands(this);
            AI         = new AI(this);
            Chat       = new Chat(this);
            Pause      = new Pause(this);
            PlayerInfo = new PlayerInfo(this);
            Interact   = new Interact(this);
            Settings   = new Settings(this);

            UpdateScreen();

#if DEBUG
            if (customGameBuilder.DebugMode)
            {
                SetupDebugWindow();
            }
#endif

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
            else
            {
                Chat.CloseChat();
            }

            StartPersistentScanning();
        }