Beispiel #1
0
 /// <summary>
 /// Execute a left mouse click and return the mouse to its original position
 /// </summary>
 /// <param name="x">pixels from left of client</param>
 /// <param name="y">pixels from top of client</param>
 public static Point LeftClick(int x, int y, int randomize = 0, int hoverDelay = HOVER_DELAY)
 {
     if (ScreenScraper.ProcessExists(RSClient))
     {
         return(Click(x, y, MOUSEEVENTF_LEFTDOWN, MOUSEEVENTF_LEFTUP, hoverDelay, randomize));
     }
     return(new Point(0, 0));
 }
Beispiel #2
0
 /// <summary>
 /// Moves a mouse across a screen like a human would
 /// </summary>
 /// <param name="x">x-coordinate within the game screen</param>
 /// <param name="y">y-coordinate within the game screen</param>
 public static void Move(int x, int y)
 {
     if (ScreenScraper.ProcessExists(RSClient))
     {
         ScreenScraper.GameScreenToWindow(ref x, ref y);
         NaturalMove(x, y);
     }
 }
Beispiel #3
0
 /// <summary>
 /// Verifies that the client exists and that it is visible and maximized
 /// </summary>
 /// <returns></returns>
 private bool PrepareClientForInput()
 {
     if (BotProgram.StopFlag)
     {
         return(false);
     }
     if (ScreenScraper.ProcessExists(RSClient))
     {
         ScreenScraper.BringToForeGround();
         return(true);
     }
     else
     {
         return(false);
     }
 }
Beispiel #4
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);
        }