Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
0
        public static List <OsrsScanData> ToList(this OsrsScanData scanData)
        {
            var result = new List <OsrsScanData>();

            result.Add(scanData);

            return(result);
        }
Ejemplo n.º 5
0
        private UiImageData LocateMenuControls()
        {
            var result = new UiImageData();

            result.RightClickMenu.Drop = AllImages.Where(x => x.ImageName == "drop.bmp").FirstOrDefault();

            var menuControls = AllImages.Where(x => x.ImageName == "view pack contents.bmp" ||
                                               x.ImageName == "top left of chat-action window.bmp" ||
                                               x.ImageName == "combat menu.bmp" ||
                                               x.ImageName == "bottom left of full ui view.bmp"
                                               ).ToList();

            var menuControlsScanData = _imageProcessor.SearchScreenForImages(menuControls).ToList();

            foreach (var mcsd in menuControlsScanData)
            {
                switch (mcsd.ImageData.ImageName)
                {
                case "view pack contents.bmp":
                    result.PackContents = mcsd;
                    break;

                case "top left of chat-action window.bmp":
                    var chatWindow = AllImages.Where(x => x.ImageName == "full chat-action window.bmp").FirstOrDefault();
                    result.PerformActionOnAll = AddPoints(mcsd.MatchLocations.FirstOrDefault(), chatWindow.CenterOfImage);
                    break;

                case "combat menu.bmp":
                    var inventoryWindow = AllImages.Where(x => x.ImageName == "inventory list.bmp").FirstOrDefault();
                    mcsd.ImageData   = inventoryWindow;
                    result.Inventory = mcsd;
                    break;

                case "bottom left of full ui view.bmp":
                    var fullUiWindow = AllImages.Where(x => x.ImageName == "full ui view.bmp").FirstOrDefault();
                    var gameField    = AllImages.Where(x => x.ImageName == "gamefield view.bmp").FirstOrDefault();

                    var gameFieldData = new OsrsScanData {
                        ImageData = gameField
                    };
                    var gameFieldLocation =
                        new Point(mcsd.MatchLocations.FirstOrDefault().X,
                                  mcsd.MatchLocations.FirstOrDefault().Y - fullUiWindow.ImageBitmap.Height > 0 ?
                                  mcsd.MatchLocations.FirstOrDefault().Y - fullUiWindow.ImageBitmap.Height : 0);

                    gameFieldData.MatchLocations.Add(gameFieldLocation);

                    result.GameFieldView = gameFieldData;
                    break;

                default:
                    break;
                }
            }

            return(result);
        }