Пример #1
0
        /// <summary>
        /// Locates all of the matching objects on the game screen (minus UI) that fit within the given size constraints
        /// </summary>
        /// <param name="objectFilter">color filter for the object type to search for</param>
        /// <param name="minSize">minimum required pixels</param>
        /// <param name="maxSize">maximum allowed pixels</param>
        /// <returns>List of blobs sorted from biggest to smallest</returns>
        internal List <Blob> LocateObjects(ColorFilter objectFilter, int minimumSize = 1, int maximumSize = int.MaxValue)
        {
            Screen.ReadWindow();
            bool[,] objectPixels = ColorFilter(objectFilter);
            EraseClientUIFromMask(ref objectPixels);
            List <Blob> objects = ImageProcessing.FindBlobs(objectPixels, true, minimumSize, maximumSize);

            return(objects);
        }
Пример #2
0
        /// <summary>
        /// Determines if any of the possible bank types appear on screen.
        /// Sets BankBoothCounter to the first match found.
        /// </summary>
        /// <returns>true if any of them do</returns>
        internal bool IdentifyBank()
        {
            Blob booth;

            Screen.ReadWindow();
            foreach (BankLocator bankLocator in PossibleBankTypes)
            {
                if (bankLocator(out booth))
                {
                    BankBoothLocator = bankLocator;
                    return(true);
                }
            }
            return(false);
        }
Пример #3
0
        /// <summary>
        /// Makes sure that a client is running and starts it if it isn't
        /// </summary>
        /// <param name="forceRestart">Set to true to force a client restart even if the client is already running</param>
        /// <returns>true if client is successfully prepared</returns>
        public bool PrepareClient(bool forceRestart = false)
        {
            if (!forceRestart && ScreenScraper.ProcessExists(Value))
            {
                return(true);
            }

            Process   client    = null;
            Stopwatch longWatch = new Stopwatch();

            longWatch.Start();
            while (longWatch.ElapsedMilliseconds < UnitConversions.HoursToMilliseconds(24) && !BotProgram.StopFlag)
            {
                if (!ScreenScraper.RestartClient(ref client, RunParams.RuneScapeClient, RunParams.ClientFlags))
                {
                    BotProgram.SafeWait(5000);
                    continue;
                }
                //Successful restart
                Value = client;

                Stopwatch watch = new Stopwatch();
                watch.Start();
                //Wait for cient to be visually recognized.
                do
                {
                    BotProgram.SafeWait(UnitConversions.SecondsToMilliseconds(5));
                    if (Screen.ReadWindow(false) && (Screen.IsLoggedOut(false) || Screen.IsLoggedIn(false)))
                    {
                        return(true);
                    }
                }while ((watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(5)) && !BotProgram.StopFlag);
            }

            if (!BotProgram.StopFlag)
            {
                const string errorMessage = "Client did not start correctly";
                MessageBox.Show(errorMessage);
            }

            Value = null;
            return(false);
        }
Пример #4
0
        /// <summary>
        /// Begins iterating after Run is called. Called for the number of iterations specified by the user.
        /// Is only called if both Iterations and FrameRate are specified.
        /// </summary>
        /// <returns>true if execution is finished and the bot should stop. returns false if the bot should continue after a break.</returns>
        private bool Iterate()
        {
            if (StopFlag)
            {
                return(true);
            }
            int randomFrameOffset, randomFrameTime;

            //randomize the time between executions
            if (RunParams.RandomizeFrames)
            {
                randomFrameOffset = (int)(0.6 * RunParams.FrameTime);
            }
            else
            {
                randomFrameOffset = 0;
            }

            RunParams.BotState = BotState.Running;
            long workInterval = RunParams.SlaveDriver ? (long)(RunParams.RunUntil - DateTime.Now).TotalMilliseconds : RandomWorkTime();

            RunParams.SetNewState(workInterval);
            ScreenScraper.BringToForeGround();
            SafeWait(1000); //give the client time to show up on screen

            Stopwatch iterationWatch    = new Stopwatch();
            Stopwatch workIntervalWatch = new Stopwatch();

            workIntervalWatch.Start();

            while ((DateTime.Now < RunParams.RunUntil) && ((RunParams.Iterations > 0) || (RunParams.InfiniteIterations == true)))
            {
                if (StopFlag)
                {
                    return(true);
                }                                //quit immediately if the stop flag has been raised or we can't log back in
                iterationWatch.Restart();
                if (!Screen.ReadWindow() || BotWorldCheck(false))
                {
                    continue;
                }                                                                 //We had to switch out of a bot world

                //Only do the actual botting if we are logged in
                if (CheckLogIn(false))
                {
                    if (Screen.LooksValid()) //Make sure the read is successful before using the bitmap values
                    {
                        if (RunParams.AutoEat)
                        {
                            ManageHitpoints(false);
                        }

                        if (RunParams.Run)
                        {
                            Minimap.RunCharacter(RunParams.RunAbove, false); //Turn on run if the player has run energy
                        }

                        if (!Execute() && !StopFlag) //quit by a bot program
                        {
                            LogError.ScreenShot(Screen, "bot-quit");
                            return(true);
                        }
                        if (StopFlag)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    if (StopFlag)
                    {
                        return(true);
                    }
                    if (!HandleFailedLogIn())
                    {
                        return(true);    //stop if we are unable to recover
                    }
                }

                randomFrameTime = RunParams.FrameTime + RNG.Next(-randomFrameOffset, randomFrameOffset + 1);
                randomFrameTime = Math.Max(0, randomFrameTime);
                if (iterationWatch.ElapsedMilliseconds < randomFrameTime)
                {
                    SafeWait(randomFrameTime - (int)iterationWatch.ElapsedMilliseconds);
                }
                if (StopFlag)
                {
                    return(true);
                }
                if (workIntervalWatch.ElapsedMilliseconds > workInterval)
                {
                    return(RunParams.SlaveDriver);
                }
            }

            return(true);
        }