/// <summary>
        /// Gets the name of a player.
        /// </summary>
        /// <param name="slot">The slot of the player.</param>
        /// <returns>The name of the player.</returns>
        public string GetPlayerName(int slot
#if DEBUG
#pragma warning disable 1573
                                    , string debugLetters = ""
#pragma warning restore 1573
#endif
                                    )
        {
            if (!IsSlotValid(slot))
            {
                throw new InvalidSlotException(slot);
            }

            using (LockHandler.Interactive)
            {
                // Open the career profile.
                bool careerProfileOpenSuccess = Interact.ClickOption(slot, Markups.VIEW_CAREER_PROFILE);
                if (!careerProfileOpenSuccess)
                {
                    return(null);
                }
                WaitForCareerProfileToLoad();

                string name = GetPlayerName(
#if DEBUG
                    debugLetters
#endif
                    );

                GoBack(1);

                return(name);
            }
        }
Example #2
0
        /// <summary>
        /// Invites a player to the game via battletag.
        /// </summary>
        /// <param name="playerName">Battletag of the player to invite. Is case sensitive. Ex: Tracer#1818</param>
        /// <param name="slot">Slot that the invited player will join.</param>
        /// <returns>Returns true if <paramref name="playerName"/> is a valid battletag.</returns>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="playerName"/> is null.</exception>
        public bool InvitePlayer(string playerName, int slot)
        {
            using (LockHandler.Interactive)
            {
                if (playerName == null)
                {
                    throw new ArgumentNullException(nameof(playerName));
                }

                if (!IsSlotValid(slot))
                {
                    throw new InvalidSlotException(slot);
                }

                if (IsSlotInQueue(slot))
                {
                    throw new InvalidSlotException("slot cannot be in queue.");
                }

                if (AllSlots.Contains(slot))
                {
                    return(false);
                }

                LeftClick(Interact.FindSlotLocation(slot));

                LeftClick(Points.INVITE_VIA_BATTLETAG, 100); // click via battletag

                TextInput(playerName);

                Thread.Sleep(200);

                UpdateScreen();

                if (Capture.CompareColor(Points.INVITE_INVITE, Colors.CONFIRM, Fades.CONFIRM))
                {
                    LeftClick(Points.INVITE_INVITE); // invite player
                    //ResetMouse();
                    return(true);
                }
                else
                {
                    LeftClick(Points.INVITE_BACK); // click back
                    //ResetMouse();
                    return(false);
                }
            }
        }
        /// <summary>
        /// Gets the player identity of a slot.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <returns>The player identity of the slot.</returns>
        public PlayerIdentity GetPlayerIdentity(int slot)
        {
            using (LockHandler.Interactive)
            {
                bool careerProfileOpenSuccess = Interact.ClickOption(slot, Markups.VIEW_CAREER_PROFILE);
                if (!careerProfileOpenSuccess)
                {
                    return(null);
                }

                WaitForCareerProfileToLoad();

                UpdateScreen();

                DirectBitmap careerProfile = Capture.Clone(Rectangles.LOBBY_CAREER_PROFILE);

                GoBack(1);

                Thread.Sleep(500);

                return(new PlayerIdentity(careerProfile));
            }
        }
        /// <summary>
        /// Gets the identity and name of a slot.
        /// </summary>
        /// <param name="slot">Slot to check.</param>
        /// <param name="pi">The <see cref="PlayerIdentity" /> of the slot.</param>
        /// <param name="name">The name of the slot.</param>
        public void GetPlayerIdentityAndName(int slot, out PlayerIdentity pi, out string name)
        {
            using (LockHandler.Interactive)
            {
                bool careerProfileOpenSuccess = Interact.ClickOption(slot, Markups.VIEW_CAREER_PROFILE);
                if (!careerProfileOpenSuccess)
                {
                    pi   = null;
                    name = null;
                    return;
                }

                WaitForCareerProfileToLoad();

                UpdateScreen();

                pi   = new PlayerIdentity(Capture.Clone(Rectangles.LOBBY_CAREER_PROFILE));
                name = GetPlayerName();

                GoBack(1);

                Thread.Sleep(500);
            }
        }
Example #5
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();
        }