Ejemplo n.º 1
0
        public static Point locateLobby(Image screen)
        {
            // get a reference to the current assembly
            Log.Debug("screen dimensions {" + screen.width + "," + screen.height + "}");

            // read from assembly
            Log.Debug("reading lobby pattern");
            Image pattern = AssemblyTools.getAssemblyImage("lobby_pattern.png");

            // reduce colors
            Log.Debug("reducing pattern colors");
            ColorReducer reducer = new ColorReducers.Lobby();

            pattern = reducer.reduceColors(pattern);
            screen  = reducer.reduceColors(screen);

            // locate pattern
            Log.Fine("scanning lines ...");
            for (int y = 0; y < screen.height - pattern.height; y++)
            {
                Log.FineIf(y % 100 == 0, y + "/" + screen.height);
                for (int x = 0; x < screen.width - pattern.width; x++)
                {
                    Image sub = screen.crop(x, x + pattern.width, y, y + pattern.height);
                    if (ImageTools.match(sub, pattern))
                    {
                        Log.Info("found lobby pattern x=" + x + ", y=" + y);
                        return(new Point(x, y));
                    }
                }
            }
            throw new Exception("Lobby pattern not found");
        }
Ejemplo n.º 2
0
        public static Point locatePattern(string patternName, ColorReducer reducer, Image screen)
        {
            // get a reference to the current assembly
            Log.Debug("screen dimensions {" + screen.width + "," + screen.height + "}");

            // read from assembly
            Log.Debug("reading " + patternName + " pattern");
            Image pattern = AssemblyTools.getAssemblyImage(patternName);

            // reduce colors
            Log.Debug("reducing pattern colors");
            pattern = reducer.reduceColors(pattern);
            screen  = reducer.reduceColors(screen);

            // locate pattern
            Log.Fine("scanning lines ...");
            for (int y = 0; y < screen.height - pattern.height; y++)
            {
                Log.FineIf(y % 100 == 0, y + "/" + screen.height);
                for (int x = 0; x < screen.width - pattern.width; x++)
                {
                    Image sub = screen.crop(x, x + pattern.width, y, y + pattern.height);
                    if (ImageTools.match(sub, pattern))
                    {
                        Log.Info("found " + patternName + " pattern x=" + x + ", y=" + y);
                        return(new Point(x, y));
                    }
                }
            }
            return(Point.Empty);
        }
Ejemplo n.º 3
0
        public bool IsTableVisible(TableContainer container, Image image)
        {
            Image screenTopLeftCorner     = CropTableTopLeftCorner(image, new Point(0, 0));
            Image screenBottomRightCorner = CropTableBottomRightCorner(image, new Point(0, 0));
            bool  areBothCornersVisible   = ImageTools.match(screenTopLeftCorner, container.CornerTopLeft) &&
                                            ImageTools.match(screenBottomRightCorner, container.CornerBottomRight);

            return(areBothCornersVisible);
        }
Ejemplo n.º 4
0
            private bool IsOpen(ColorReducer reducer, Rectangle seat, Image pattern, Image tableImage, int maxScanY)
            {
                Image seatCropped = tableImage.crop(seat.X, seat.X + seat.Width, seat.Y, seat.Y + seat.Height);
                Image seatReduced = reducer.reduceColors(seatCropped);

                for (int y = 0; y < maxScanY; y++)
                {
                    Log.FineIf(y % 100 == 0, y + "/" + seatReduced.height);
                    for (int x = 0; x < seatReduced.width - pattern.width; x++)
                    {
                        Image sub = seatReduced.crop(x, x + pattern.width, y, y + pattern.height);
                        if (ImageTools.match(sub, pattern))
                        {
                            Log.Info("found open seat pattern x=" + x + ", y=" + y);
                            return(true);
                        }
                    }
                }
                return(false);
            }
Ejemplo n.º 5
0
        private static bool isPatternVisible(Image image, ColorReducer reducer, Image pattern, string patternName)
        {
            // reduce colors
            Log.Debug("reducing pattern colors");
            pattern = reducer.reduceColors(pattern);
            image   = reducer.reduceColors(image);

            // locate pattern
            Log.Debug("scanning lines ...");
            for (int y = 0; y < image.height - pattern.height; y++)
            {
                Log.FineIf(y % 100 == 0, y + "/" + image.height);
                for (int x = 0; x < image.width - pattern.width; x++)
                {
                    Image sub = image.crop(x, x + pattern.width, y, y + pattern.height);
                    if (ImageTools.match(sub, pattern))
                    {
                        Log.Info("found " + patternName + " pattern x=" + x + ", y=" + y);
                        return(true);
                    }
                }
            }
            return(false);
        }
Ejemplo n.º 6
0
        public static List <Point> locateTaskBarPrograms(Image screen, int xOff, int yOff)
        {
            // pattern
            Image originalScreen = screen;
            Image pattern        = iconPattern;

            // reduce if real pattern not set
            if (pattern == Image.Empty)
            {
                pattern = AssemblyTools.getAssemblyImage("taskbar_icon.png");
                ColorReducer reducer = new ColorReducers.TaskBar();
                pattern = reducer.reduceColors(pattern);
                screen  = reducer.reduceColors(screen);
            }

            // locate pattern
            Dictionary <int, List <Point> > icons = new Dictionary <int, List <Point> >();

            for (int y = 0; y < screen.height - pattern.height; y++)
            {
                for (int x = 0; x < screen.width - pattern.width; x++)
                {
                    Image sub = screen.crop(x, x + pattern.width, y, y + pattern.height);
                    if (ImageTools.match(sub, pattern))
                    {
                        // remember pattern
                        if (iconPattern == Image.Empty)
                        {
                            iconPattern = originalScreen.crop(x, x + pattern.width, y, y + pattern.height);
                        }

                        // store
                        Log.Debug("found taskbar_icon.png pattern x=" + x + ", y=" + y);
                        Point point = new Point(xOff + x, yOff + y);
                        bool  found = false;

                        // check for near y
                        foreach (int knownY in icons.Keys)
                        {
                            if (Math.Abs(y - knownY) < 5)
                            {
                                icons[knownY].Add(point);
                                found = true;
                                break;
                            }
                        }

                        // add new y
                        if (!found)
                        {
                            icons.Add(y, new List <Point>()
                            {
                                new Point(xOff + x, yOff + y)
                            });
                        }

                        // skip x
                        x += pattern.width;
                    }
                }
            }

            // sort
            Dictionary <int, List <Point> > .ValueCollection sorted = icons.Values;
            List <Point> result = new List <Point>();

            foreach (List <Point> points in sorted)
            {
                var sortedX = from p in points orderby p.X ascending select p;
                result.AddRange(sortedX);
            }
            return(result);
        }
Ejemplo n.º 7
0
        public static Point locateUnknownTable(Image screen, List <Point> offsets, TableLayout layout)
        {
            // vars
            Image    originalScreen = screen;
            Image    pattern        = tablePattern;
            DateTime start          = DateTime.Now;

            // reduce or use exact image
            if (pattern == Image.Empty)
            {
                // read from assembly
                Log.Debug("reading table pattern");
                pattern = AssemblyTools.getAssemblyImage("table_top_left_corner.png");

                // reduce colors
                Log.Debug("reducing pattern colors");
                ColorReducer reducer = new ColorReducers.Table();
                screen  = reducer.reduceColors(screen);
                pattern = reducer.reduceColors(pattern);
            }

            // first line
            int[] patternFirstLine = pattern.lines[0];

            // locate pattern
            for (int y = 0; y < screen.height - pattern.height; y++)
            {
                int[] screenLine = screen.lines[y];
                for (int x = 0; x < screen.width - pattern.width; x++)
                {
                    // check first line
                    if (match(patternFirstLine, screenLine, x))
                    {
                        // first corner
                        Image cornerTL = screen.crop(x, x + pattern.width, y, y + pattern.height);
                        if (ImageTools.match(cornerTL, pattern))
                        {
                            // second corner
                            Image cornerBR = originalScreen.crop(x + layout.CornerBottom.X, x + layout.CornerBottom.X + layout.CornerBottom.Width,
                                                                 y + layout.CornerBottom.Y, y + layout.CornerBottom.Y + layout.CornerBottom.Height);
                            if (isTableBottomRightCornerVisible(cornerBR))
                            {
                                // remember exact pattern
                                if (tablePattern == Image.Empty)
                                {
                                    tablePattern = originalScreen.crop(x, x + pattern.width, y, y + pattern.height);
                                }

                                // return location
                                Point point = new Point(x, y);
                                if (!offsets.Contains(point))
                                {
                                    Log.Info("found new table pattern x=" + x + ", y=" + y + " took " + DateTime.Now.Subtract(start).TotalMilliseconds + "ms");
                                    return(point);
                                }
                            }
                        }
                    }
                }
            }
            return(Point.Empty);
        }