예제 #1
0
        /// <summary>
        /// Waits for the "Enter amount:" prompt to appear over the chat box
        /// </summary>
        /// <param name="timeout">Gives up after the max wait time has elapsed</param>
        /// <returns>true if the prompt appears</returns>
        public static bool WaitForEnterAmount(Process rsClient, int timeout)
        {
            Point     screenSize = ScreenScraper.GetWindowSize(rsClient);
            const int asterisk   = 91235;
            const int left       = 252;
            const int right      = 265;
            int       top        = screenSize.Y - 81;
            int       bottom     = screenSize.Y - 69;

            Color[,] screen;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            long asteriskHash;

            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }

                screen       = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
                screen       = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
                asteriskHash = ImageProcessing.ColorSum(screen);
                if (Numerical.CloseEnough(asterisk, asteriskHash, 0.01))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #2
0
        /// <summary>
        /// Powershell logic.
        /// </summary>
        protected override void ProcessRecord()
        {
            var ss = new ScreenScraper();

            var pos = ss.Find(ss.CaptureScreen(), Image);

            if (pos.Right == -1 && pos.Left == -1)
            {
                throw new ApplicationException("Can't find image on screen!");
            }

            ss.MoveMouse(pos.X + XOffset, pos.Y + YOffset);

            if (Click)
            {
                ss.MouseClick(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
            else if (Up)
            {
                ss.MouseUp(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
            else if (Down)
            {
                ss.MouseDown(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
        }
예제 #3
0
        /// <summary>
        /// Waits for the furnace crafting popup to appear
        /// </summary>
        /// <returns>true if the popup is found</returns>
        public bool WaitForPopup(int timeout)
        {
            const int popupTitleHash = 842393;

            Color[,] screen;
            Stopwatch watch = new Stopwatch();

            watch.Start();
            long titleHash;

            int left   = Left + 144;
            int right  = Left + 344;
            int top    = Top + 4;
            int bottom = Top + 23;

            while (watch.ElapsedMilliseconds < timeout)
            {
                if (BotProgram.StopFlag)
                {
                    return(false);
                }

                screen    = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
                screen    = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
                titleHash = ImageProcessing.ColorSum(screen);

                if (Numerical.CloseEnough(popupTitleHash, titleHash, 0.001))
                {
                    return(true);
                }
            }

            return(false);
        }
예제 #4
0
        /// <summary>
        /// Drops all of the items in the inventory
        /// </summary>
        /// <param name="safeTab"></param>
        public void DropInventory(bool safeTab = true, bool onlyDropPreviouslyEmptySlots = true)
        {
            Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            OpenInventory(safeTab);
            int effectiveY;

            Keyboard.ShiftDown();
            for (int x = 0; x < INVENTORY_COLUMNS; x++)
            {
                for (int y = 0; y < INVENTORY_ROWS; y++)
                {
                    effectiveY = (x % 2 == 0) ? y : INVENTORY_ROW_MAX - y;
                    if ((!onlyDropPreviouslyEmptySlots || EmptySlots[x, effectiveY]) && !SlotIsEmpty(x, effectiveY, false, false))
                    {
                        if (BotProgram.StopFlag)
                        {
                            Keyboard.ShiftUp();
                            return;
                        }
                        ClickInventory(x, effectiveY, false);
                        BotProgram.SafeWaitPlus(50, 25);
                    }
                }
            }
            Keyboard.ShiftUp();
        }
예제 #5
0
        /// <summary>
        /// Click down and release a mouse button
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="clickTypeDown"></param>
        /// <param name="clickTypeUp"></param>
        private static Point Click(int x, int y, int clickTypeDown, int clickTypeUp, int hoverDelay, int randomize)
        {
            Random rng        = new Random();
            Point  clickPoint = Probability.GaussianCircle(new Point(x, y), 0.35 * randomize, 0, 360, randomize);

            x = clickPoint.X;
            y = clickPoint.Y;

            ScreenScraper.BringToForeGround();
            ScreenScraper.GameScreenToWindow(ref x, ref y);
            if (BotProgram.StopFlag)
            {
                return(new Point(0, 0));
            }
            NaturalMove(x, y);

            BotProgram.SafeWaitPlus(hoverDelay, 0.25 * hoverDelay);  //wait for RS client to recognize the cursor hover
            if (!BotProgram.StopFlag)
            {
                mouse_event(clickTypeDown, x, y, 0, 0);
                mouse_event(clickTypeUp, x, y, 0, 0);
            }

            return(clickPoint);
        }
예제 #6
0
        /// <summary>
        /// Finds the next slot that matches a single color filter
        /// </summary>
        /// <param name="emptySlotNumber">Set to a number higher than 1 to find the second, third, etc empty slot.</param>
        /// <returns>The first matching inventory slot scanning left to right then top to bottom. Returns null if no match is found.</returns>
        public Point?FirstColorMatchingSlot(ColorFilter colorFilter, double matchStrictness = 0.1, bool safeTab = true, int emptySlotNumber = 1)
        {
            emptySlotNumber = (int)Numerical.LimitToRange(emptySlotNumber, 1, INVENTORY_CAPACITY);
            if (OpenInventory(safeTab))
            {
                Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            }
            Point?inventorySlot;

            int slotCount = 0;

            for (int slot = 0; slot < INVENTORY_CAPACITY; slot++)
            {
                inventorySlot = InventoryIndexToCoordinates(slot);
                if (SlotMatchesColorFilter(inventorySlot.Value.X, inventorySlot.Value.Y, colorFilter, matchStrictness, false, false))
                {
                    slotCount++;
                    if (slotCount >= emptySlotNumber)
                    {
                        return(inventorySlot);
                    }
                }

                if (BotProgram.StopFlag)
                {
                    return(null);
                }
            }

            return(null);
        }
예제 #7
0
        public void Integration_Matching_Address()
        {
            // This is an integratino test - actually hits the website

            UspsAddress address = new UspsAddress {
                Street = "7200 Royalgreen Drive",
                City   = "Cincinnati",
                State  = "OH",
            };

            UspsAddressPage page = new ScreenScraper(20000).GetPage <UspsAddressPage>(
                UspsAddressPage.BuildRequest(address)
                );

            Assert.That(page.IsMatch, Is.True);
            Assert.That(page.ReturnedAddresses.Count, Is.EqualTo(1));
            UspsAddress result = page.ReturnedAddresses[0];

            Assert.That(result.Validity, Is.EqualTo(UspsAddressValidity.Valid));

            Assert.That(result.Street, Is.EqualTo("7200 ROYALGREEN DR"));
            Assert.That(result.Street2, Is.Null);
            Assert.That(result.City, Is.EqualTo("CINCINNATI"));
            Assert.That(result.State, Is.EqualTo("OH"));
            Assert.That(result.Zip, Is.EqualTo("45244-3625"));
            Assert.That(result.County, Is.EqualTo("HAMILTON"));
        }
예제 #8
0
        /// <summary>
        /// Wrapper for ScreenScraper.CaptureWindow
        /// </summary>
        internal bool ReadWindow(bool checkClient = true, bool fastCapture = false)
        {
            if (BotProgram.StopFlag || checkClient && !RSClient.PrepareClient())
            {
                return(false);
            }

            Value = null;

            try
            {
                LastScreenShot = DateTime.Now;
                Bitmap         = ScreenScraper.CaptureWindow(fastCapture);
                Value          = ScreenScraper.GetRGB(Bitmap);
            }
            catch
            {
                return(false);
            }
            finally
            {
                if (Bitmap != null)
                {
                    Bitmap.Dispose();
                }
            }

            return((Value != null) && (Height > 0) && (Width > 0));
        }
예제 #9
0
 /// <summary>
 /// Takes a screenshot of the game
 /// </summary>
 /// <param name="overwrite">set to true to take a screenshot even if one already exists</param>
 private void ManuallySetScreen(bool overwrite)
 {
     if (overwrite || Screen == null)
     {
         Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow(true));
     }
 }
예제 #10
0
        public void Run()
        {
            var csvData  = new StandardCsvRepository().Read("StandardPages.csv");
            var htmlData = new WebDownloader().GetAll(csvData);
            var linkUris = new ScreenScraper().GetLinkUris(htmlData);

            repository.Save(linkUris);
        }
예제 #11
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));
 }
예제 #12
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);
     }
 }
예제 #13
0
        /// <summary>
        /// Takes a hash of the textbox dialog area
        /// </summary>
        /// <param name="filter">filter for text colors to look for</param>
        /// <returns>the portion of the dialog text area filled with text color</returns>
        public double DialogBodyText()
        {
            Screen.Value = ScreenScraper.ReadWindow(true);
            ColorFilter filter = RGBHSBRangeGroupFactory.DialogText();
            double      match  = ImageProcessing.FractionalMatchPiece(Screen, filter, Left + 126, Right - 126, Top + 46, Bottom - 38);

            return(match);
        }
예제 #14
0
        public FurnaceCrafting(Process rsClient, Keyboard keyboard)
        {
            this.RSClient = rsClient;
            this.Keyboard = keyboard;
            Point screenSize = ScreenScraper.GetWindowSize(RSClient);

            SetLeft(screenSize.X);
            SetTop(screenSize.Y);
        }
예제 #15
0
        public void TestMethod1()
        {
            string retValue;
            string retTime;

            ScreenScraper.GetRate("http://www.bloomberg.com/markets/stocks/world-indexes/", out retValue, out retTime);
            Console.WriteLine(retValue);
            Console.WriteLine(retTime);
        }
예제 #16
0
        public string GetSourceData(string url)
        {
            string content = string.Empty;

            var scraper = new ScreenScraper(url);

            content = scraper.DisplayData;

            return(content);
        }
예제 #17
0
        public NPCContact(Process rsClient)
        {
            RSClient = rsClient;
            Point screenSize = ScreenScraper.GetWindowSize(RSClient);

            SetLeft(screenSize.X);
            SetRight(screenSize.X);
            SetTop(screenSize.Y);
            SetBottom(screenSize.Y);
        }
예제 #18
0
        public Bank(Process rsClient, Inventory inventory, Keyboard keyboard)
        {
            RSClient = rsClient;
            Keyboard = keyboard;
            Point screenSize = ScreenScraper.GetWindowSize(rsClient);

            InventoryItems = inventory;
            SetLeft(screenSize.X);
            SetRight(screenSize.X);
            SetTop(screenSize.Y);
            SetBottom(screenSize.Y);
        }
예제 #19
0
        /// <summary>
        /// Determines if the bank screen is currently visible
        /// </summary>
        /// <returns>true if the bank is open</returns>
        public bool NPCContactIsOpen()
        {
            int left   = Left + 182;
            int right  = Left + 316;
            int top    = Top + 12;
            int bottom = Top + 25;

            Color[,] screen;
            screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            double titleMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankTitle());

            return(titleMatch > 0.05);
        }
예제 #20
0
        /// <summary>
        /// Set the list of empty inventory slots
        /// </summary>
        public void SetEmptySlots()
        {
            OpenInventory();
            Screen.Value = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            EmptySlots   = new bool[INVENTORY_COLUMNS, INVENTORY_ROWS];

            for (int x = 0; x < INVENTORY_COLUMNS; x++)
            {
                for (int y = 0; y < INVENTORY_ROWS; y++)
                {
                    EmptySlots[x, y] = SlotIsEmpty(x, y, false, false);
                }
            }
        }
예제 #21
0
        /// <summary>
        /// Selects Make All for the single make option that shows up over the chat box
        /// </summary>
        /// <param name="rsClient"></param>
        /// <returns></returns>
        public bool ChatBoxSingleOptionMakeAll(Process rsClient)
        {
            Point  screenSize = ScreenScraper.GetWindowSize(rsClient);
            int    X          = 256;
            int    Y          = screenSize.Y - 90;
            Random rng        = new Random();

            Point leftClick = new Point(X, Y);
            Blob  clickBlob = new Blob(leftClick);

            HandEye.MouseOverDroppedItem(clickBlob, true, 20, 5000);

            return(true);
        }
예제 #22
0
        /// <summary>
        /// Powershell logic.
        /// </summary>
        protected override void ProcessRecord()
        {
            var ss = new ScreenScraper();

            while (true)
            {
                var result = ss.Find(ss.CaptureScreen(), Image);

                if (result.Left != -1 && result.Right != -1)
                {
                    break;
                }
            }
        }
예제 #23
0
        /// <summary>
        /// Powershell logic.
        /// </summary>
        protected override void ProcessRecord()
        {
            var ss = new ScreenScraper();

            if (SearchInImage == null)
            {
                SearchInImage = ss.CaptureScreen();
            }

            var result = ss.Find(SearchInImage, Image);


            //-1 indicates it didn't find the image.
            WriteObject(result.Left != -1 && result.Right != -1);
        }
예제 #24
0
        /// <summary>
        /// Waits for an expected set of text to appear in the textbox
        /// </summary>
        /// <param name="timeout">time in milliseconds to keep trying before giving up</param>
        /// <param name="filter">color filter to match the expected text color</param>
        /// <param name="expectedText">hash of the expected text body</param>
        /// <param name="allowedPixelDifference">maximum allowed deviation from the expected hash value in pixels</param>
        /// <param name="filter">color filter to match the expected text color</param>
        /// <returns>true if matching text appears</returns>
        public bool WaitForExpectedText(double expectedText, int allowedPixelDifference, int timeout)
        {
            Stopwatch watch = new Stopwatch();

            watch.Start();
            while (watch.ElapsedMilliseconds < timeout && !BotProgram.StopFlag)
            {
                Screen.Value = ScreenScraper.ReadWindow(true);
                if (DialogBodyTextMatch(expectedText, allowedPixelDifference))
                {
                    return(true);
                }
                BotProgram.SafeWait(100);
            }
            return(false);
        }
예제 #25
0
        /// <summary>
        /// Adjusts the popup position in cases where the popup runs into the bottom, left, or right of the screen
        /// </summary>
        protected void AdjustPosition()
        {
            Point?screenSize = ScreenScraper.GetScreenSize();

            if (screenSize != null)
            {
                //adjust for hitting the bottom of the screen
                YClick = Math.Min(YClick, screenSize.Value.Y - Height);

                //adjust for hitting the left of the screen
                XClick = Math.Max(XClick, Width / 2);

                //adjust for hitting the right of the screen
                XClick = Math.Min(XClick, screenSize.Value.X - (Width / 2));
            }
        }
예제 #26
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);
     }
 }
예제 #27
0
        /// <summary>
        /// Determines if the bank screen is currently visible
        /// </summary>
        /// <returns>true if the bank is open</returns>
        public bool BankIsOpen()
        {
            const double minTitleMatch = 0.05;
            double       titleMatch;
            int          left   = Left + 162;
            int          right  = Left + 325;
            int          top    = Top + 8;
            int          bottom = Top + 25;

            Color[,] screen;
            screen     = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            screen     = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            titleMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankTitle());

            return(titleMatch > minTitleMatch);
        }
예제 #28
0
        /// <summary>
        /// Powershell logic.
        /// </summary>
        protected override void ProcessRecord()
        {
            var ss = new ScreenScraper();

            if (Click)
            {
                ss.MouseClick(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
            else if (Up)
            {
                ss.MouseUp(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
            else if (Down)
            {
                ss.MouseDown(Button == "Left" ? MouseButton.Left : MouseButton.Right);
            }
        }
예제 #29
0
        /// <summary>
        /// Determines if a bank slot is occupied by an empty placeholder
        /// </summary>
        /// <param name="screen">image of the entire game screen</param>
        /// <returns></returns>
        public bool SlotIsEmpty(int x, int y, Color[,] screen)
        {
            Rectangle counterOffset = new Rectangle(-16, -17, 8, 11);
            Point     slotLocation  = ItemSlotLocation(x, y).Value;
            int       left          = slotLocation.X + counterOffset.X;
            int       right         = slotLocation.X + counterOffset.X + counterOffset.Width;
            int       top           = slotLocation.Y + counterOffset.Y;
            int       bottom        = slotLocation.Y + counterOffset.Y + counterOffset.Height;

            if (screen == null)
            {
                screen = ScreenScraper.GetRGB(ScreenScraper.CaptureWindow());
            }
            screen = ImageProcessing.ScreenPiece(screen, left, right, top, bottom);
            double slotCounterMatch = ImageProcessing.FractionalMatch(screen, RGBHSBRangeFactory.BankSlotPlaceholderZero());

            return(slotCounterMatch > 0.1);
        }
예제 #30
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);
        }