예제 #1
0
        public List <OsrsScanData> SearchScreenForImages(List <OsrsImage> osrsImages, ScanBoundaries boundaries = null, bool getSingleOccurrence = false)
        {
            var response       = new List <OsrsScanData>();
            var osrsWindow     = HwndInterface.GetHwndFromTitle("Old School RuneScape");
            var windowSize     = HwndInterface.GetHwndSize(osrsWindow);
            var windowLocation = HwndInterface.GetHwndPos(osrsWindow);

            HwndInterface.ActivateWindow(osrsWindow);

            var screenshot = TakeScreenshot();

            #region Scan Boundaries Calculation
            if (boundaries == null)
            {
                boundaries = new ScanBoundaries();

                var imgMaxX = osrsImages.Max(x => x.ImageBitmap.Width);
                var imgMaxY = osrsImages.Max(x => x.ImageBitmap.Height);

                boundaries.MinX = windowLocation.X < 0 ? 0 : windowLocation.X;
                boundaries.MinY = windowLocation.Y < 0 ? 0 : windowLocation.Y;
                boundaries.MaxX = (windowLocation.X + windowSize.Width) > screenshot.Width ? screenshot.Width - imgMaxX : (windowLocation.X + windowSize.Width) - imgMaxX;
                boundaries.MaxY = (windowLocation.Y + windowSize.Height) > screenshot.Height ? screenshot.Height - imgMaxY : (windowLocation.Y + windowSize.Height) - imgMaxY;
            }
            #endregion

            response = FindAllBitmapsInImage(osrsImages, screenshot, boundaries, getSingleOccurrence);

            return(response);
        }
예제 #2
0
        public OsrsScanData SearchScreenForColors(List <Color> colors, OsrsImage image, ScanBoundaries boundaries = null)
        {
            LoggingUtility.WriteToAuditLog("Starting Color Search");
            OsrsScanData response       = null;
            var          osrsWindow     = HwndInterface.GetHwndFromTitle("Old School RuneScape");
            var          windowSize     = HwndInterface.GetHwndSize(osrsWindow);
            var          windowLocation = HwndInterface.GetHwndPos(osrsWindow);

            HwndInterface.ActivateWindow(osrsWindow);

            var screenshot = TakeScreenshot();

            #region Scan Boundaries Calculation
            if (boundaries == null)
            {
                boundaries = new ScanBoundaries();

                boundaries.MinX = windowLocation.X < 0 ? 0 : windowLocation.X;
                boundaries.MinY = windowLocation.Y < 0 ? 0 : windowLocation.Y;
                boundaries.MaxX = (windowLocation.X + windowSize.Width) > screenshot.Width ? screenshot.Width : (windowLocation.X + windowSize.Width);
                boundaries.MaxY = (windowLocation.Y + windowSize.Height) > screenshot.Height ? screenshot.Height : (windowLocation.Y + windowSize.Height);
            }
            #endregion

            response = FindColorsInImage(colors, screenshot, boundaries);
            //response = FindColorsInImage(colors, image.ImageBitmap, new ScanBoundaries { MinX = 0, MinY = 0, MaxX = image.ImageBitmap.Width, MaxY = image.ImageBitmap.Height });

            LoggingUtility.WriteToAuditLog("Color Search Complete");
            return(response);
        }
예제 #3
0
        // tis doesnt f*****g work right now
        private OsrsScanData FindColorsInImage(List <Color> colors, Bitmap haystack, ScanBoundaries boundaries)
        {
            LoggingUtility.WriteToAuditLog("Beginning Screenshot Examination for Colors");
            var result = new OsrsScanData();

            // The X and Y of the outer loops represent the coordinates on the Screenshot object
            for (int outerX = boundaries.MinX; outerX < boundaries.MaxX; outerX++)
            {
                for (int outerY = boundaries.MinY; outerY < boundaries.MaxY; outerY++)
                {
                    foreach (var c in colors)
                    {
                        Color cHaystack = haystack.GetPixel(outerX, outerY);

                        if (result.MatchLocations.Count > 20)
                        {
                            return(result);
                        }

                        // We compare the color of the pixel in the Screenshot with the Color we are searching for
                        if (c.R == cHaystack.R || c.G == cHaystack.G || c.B == cHaystack.B)
                        {
                            LoggingUtility.WriteToAuditLog(String.Format("Color Found: X = {0}  Y = {1}", outerX, outerY));

                            if (!result.MatchLocations.Where(x => x.X == outerX && x.Y == outerY).Any())
                            {
                                result.MatchLocations.Add(new Point(outerX, outerY));
                            }
                        }
                    }
                }
            }

            return(result);
        }
예제 #4
0
        public void ClickOnGameField(List <OsrsImage> gameObjects)
        {
            #region Determine Scan Boundaries

            var gameFieldCenterLocation = AddPoints(MenuControls.GameFieldView.MatchLocations.FirstOrDefault(), MenuControls.GameFieldView.ImageData.CenterOfImage);
            var gameFieldScanSection    = new ScanBoundaries();
            var xBuffer = 200;
            var yBuffer = 100;

            gameFieldScanSection.MinX = gameFieldCenterLocation.X - xBuffer > 0 ? gameFieldCenterLocation.X - xBuffer : 0;
            gameFieldScanSection.MinY = gameFieldCenterLocation.Y - yBuffer > 0 ? gameFieldCenterLocation.Y - yBuffer : 0;
            gameFieldScanSection.MaxX = gameFieldCenterLocation.X + xBuffer;
            gameFieldScanSection.MaxY = gameFieldCenterLocation.Y + yBuffer;

            #endregion

            var gameObjectsScanData = _imageProcessor.SearchScreenForImages(gameObjects, gameFieldScanSection, getSingleOccurrence: true);

            if (gameObjectsScanData.Any())
            {
                var gObj            = gameObjectsScanData.FirstOrDefault();
                var matchedLocation = gObj.MatchLocations.FirstOrDefault();

                var clickLocation = AddPoints(matchedLocation, gObj.ImageData.CenterOfImage);

                IoSimulator.ClickLocation(clickLocation);
                IoSimulator.PauseThread(600);
                IoSimulator.ClickLocation(clickLocation);
            }
        }
예제 #5
0
        public void UseToolOnResources(List <OsrsImage> resources, OsrsImage tool, int pauseTime = 2000)
        {
            resources.Add(tool);

            #region Determine Scan Boundaries

            var scanBounds = new ScanBoundaries();

            var invLoc = MenuControls.Inventory.MatchLocations.FirstOrDefault();

            scanBounds.MinX = invLoc.X;
            scanBounds.MinY = invLoc.Y;
            scanBounds.MaxX = invLoc.X + MenuControls.Inventory.ImageData.ImageBitmap.Width;
            scanBounds.MaxY = invLoc.Y + MenuControls.Inventory.ImageData.ImageBitmap.Height;

            #endregion

            IoSimulator.ClickLocation(MenuControls.PackContents.MatchLocations.FirstOrDefault());
            var resourceScanData = _imageProcessor.SearchScreenForImages(resources, scanBounds);

            var toolData = resourceScanData.Where(x => x.ImageData.ImageName == tool.ImageName).FirstOrDefault();

            if (toolData != null)
            {
                var toolLocation = toolData.MatchLocations.FirstOrDefault();

                foreach (var r in resourceScanData.Where(x => x.ImageData.ImageName != tool.ImageName))
                {
                    IoSimulator.ClickLocation(toolLocation);

                    IoSimulator.PauseThread(2000);

                    IoSimulator.ClickLocation(r.MatchLocations.FirstOrDefault());

                    IoSimulator.PauseThread(2000);

                    IoSimulator.ClickLocation(MenuControls.PerformActionOnAll);

                    IoSimulator.PauseThread(pauseTime * r.MatchLocations.Count);
                }
            }
            else
            {
                // tool not in inventory
            }
        }
예제 #6
0
        public void DropAllItems(List <OsrsImage> itemIcons)
        {
            IoSimulator.ClickLocation(MenuControls.PackContents.MatchLocations.FirstOrDefault());

            var itemIconScanData = _imageProcessor.SearchScreenForImages(itemIcons);

            var allMatchedLocations = itemIconScanData.SelectMany(x => x.MatchLocations).ToList();
            var centerOfImage       = itemIconScanData.Select(x => x.ImageData.CenterOfImage).FirstOrDefault();

            foreach (var itemIconLocation in allMatchedLocations)
            {
                var paddedItemIconLocation = AddPoints(itemIconLocation, centerOfImage);

                IoSimulator.ClickLocation(paddedItemIconLocation, leftClick: false);

                IoSimulator.PauseThread(100);

                #region Determine Scan Boundaries
                var menuScanSection = new ScanBoundaries();

                var scanBuffer = 150;

                menuScanSection.MinX = paddedItemIconLocation.X - scanBuffer;
                menuScanSection.MinY = paddedItemIconLocation.Y - scanBuffer;
                menuScanSection.MaxX = paddedItemIconLocation.X + scanBuffer;
                menuScanSection.MaxY = paddedItemIconLocation.Y + scanBuffer;
                #endregion

                var dropScanData = _imageProcessor.SearchScreenForImages(MenuControls.RightClickMenu.Drop.ToList(), menuScanSection, getSingleOccurrence: true);

                if (dropScanData.Any())
                {
                    var dsdLocation = dropScanData.FirstOrDefault().MatchLocations.FirstOrDefault();

                    var paddedDropLocation = AddPoints(dsdLocation, MenuControls.RightClickMenu.Drop.CenterOfImage);

                    IoSimulator.ClickLocation(paddedDropLocation);
                }

                IoSimulator.PauseThread(750);
            }
        }
예제 #7
0
        // this should be able to scan for a list of OsrsImages to find multiple items on one scan
        private List <OsrsScanData> FindAllBitmapsInImage(List <OsrsImage> needles, Bitmap haystack, ScanBoundaries boundaries, bool getSingleOccurrence)
        {
            var result = new List <OsrsScanData>();

            // The X and Y of the outer loops represent the coordinates on the Screenshot object
            for (int outerX = boundaries.MinX; outerX < boundaries.MaxX; outerX++)
            {
                for (int outerY = boundaries.MinY; outerY < boundaries.MaxY; outerY++)
                {
                    foreach (var n in needles)
                    {
                        var temp = new OsrsScanData()
                        {
                            ImageData = n
                        };

                        // The X and Y on the inner loops represent the coordinates on the bitmap that we are trying to find in the Screenshot
                        for (int innerX = 0; innerX < n.ImageBitmap.Width; innerX++)
                        {
                            for (int innerY = 0; innerY < n.ImageBitmap.Height; innerY++)
                            {
                                Color cNeedle   = n.ImageBitmap.GetPixel(innerX, innerY);
                                Color cHaystack = haystack.GetPixel(innerX + outerX, innerY + outerY);

                                // We compare the color of the pixel in the Screenshot with the pixel in the bitmap we are searching for
                                if (cNeedle.R != cHaystack.R || cNeedle.G != cHaystack.G || cNeedle.B != cHaystack.B)
                                {
                                    // Stop examining the current bitmap once a single pixel doesn't match
                                    goto notFound;
                                }
                            }
                        }

                        var foundPoint    = new Point(outerX, outerY);
                        var existingEntry = result.Where(x => x.ImageData.ImageName == temp.ImageData.ImageName).FirstOrDefault();

                        if (existingEntry != null)
                        {
                            existingEntry.MatchLocations.Add(foundPoint);
                        }
                        else
                        {
                            temp.MatchLocations.Add(foundPoint);
                            result.Add(temp);
                        }

                        if (getSingleOccurrence)
                        {
                            return(result);
                        }

notFound:
                        continue;
                    }
                }
            }

            return(result);
        }