Ejemplo n.º 1
0
        public static void ReportTableException(Exception ex, Image image, string error)
        {
            // console
            Log.Error("Cannot identify table");
            Log.Error(error + " -> " + ex.Message);

            // file
            string filename = ErrorDir + "Error_Unable_Identify_Table_" + Math.Abs(DateTime.Now.Ticks);

            // save exception
            StreamWriter log = File.CreateText(filename + ".txt");

            log.WriteLine("Date: " + DateTime.Now.ToShortTimeString());
            log.WriteLine("Message: " + error + " -> " + ex.Message);
            log.WriteLine("Inner: " + ex.InnerException);
            log.WriteLine("Source: " + ex.Source);
            log.WriteLine("Trace: " + ex.StackTrace);
            log.Close();

            // save image
            ImageTools.toBitmap(image).Save(filename + ".bmp");
        }
Ejemplo n.º 2
0
        public static void ReportExceptionWithImage(Exception ex, string error, Image image)
        {
            BeepError();

            // console
            Log.Error(error + " -> " + ex.Message);

            // file
            string filename = ErrorDir + "Error_Exception_" + Math.Abs(DateTime.Now.Ticks);

            // save exception
            StreamWriter log = File.CreateText(filename + ".txt");

            log.WriteLine("Date: " + DateTime.Now.ToShortTimeString());
            log.WriteLine("Message: " + error + " -> " + ex.Message);
            log.WriteLine("Inner: " + ex.InnerException);
            log.WriteLine("Source: " + ex.Source);
            log.WriteLine("Trace: " + ex.StackTrace);
            log.Close();

            // save image
            ImageTools.toBitmap(image).Save(filename + "_Image.bmp");
        }
Ejemplo n.º 3
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.º 4
0
 public void renderImage(Image image, Point point)
 {
     renderImagesList.Add(new RenderImage(ImageTools.toBitmap(image), point));
 }
Ejemplo n.º 5
0
 public void renderImage(Image image, int x, int y)
 {
     renderImagesList.Add(new RenderImage(ImageTools.toBitmap(image), new Point(x, y)));
 }
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);
        }
Ejemplo n.º 8
0
        public List <TableContainer> OpenNewTables(Settings settings, ImageRenderer imageRenderer, TableFoundDelegate tableDelegate)
        {
            Log.Info("## scanning for lobby ##");

            // identifier
            LobbyIdentifier lobbyIdentifier = new LobbyIdentifier();

            // set renderer
            tableIdentifier.Renderer = imageRenderer;
            lobbyIdentifier.Renderer = imageRenderer;

            // screen
            Iterator <Image> screen = new ScreenImageIterator(deviceControl);
            LobbyLayout      layout = new LobbyLayout();

            // find lobby
            FocusLobby(layout, screen);
            Image screenshot  = screen.next();
            Point lobbyOffset = PatternLocator.locateLobby(screenshot);

            // loop until we got enough tables
            List <TableContainer> tables = new List <TableContainer>();

            while (knownTables.Count < settings.AutoLocateTablesNum)
            {
                // check for tables
                PressCheckOrFold(screenshot);

                // scan lobby
                List <LobbyTable> lobbyTables = IdentifyLobbyTables(lobbyIdentifier, layout, screen, lobbyOffset);

                // open tables?
                if (HasOpenTables(lobbyTables))
                {
                    // select table
                    LobbyTable bestTable = SelectBestTable(lobbyTables);

                    // render
                    if (imageRenderer != null)
                    {
                        imageRenderer.renderImage(ImageTools.rectImage(), new Point(bestTable.RelX, bestTable.RelY));
                    }

                    // open table
                    Log.Info("opening table " + bestTable.ToString() + " with score " + String.Format("{0:0.00}", bestTable.Score));
                    TableContainer container = OpenTable(bestTable, settings, screen, bestTable);
                    if (container != TABLE_ALREADY_JOINED && container != TABLE_NOT_FOUND && container != CANNOT_FIND_SEAT)
                    {
                        // add to known tables
                        tables.Add(container);
                        knownTables.Add(container);
                        Log.Info("added new table " + tables.Count);

                        // invoke delegate
                        if (tableDelegate != null)
                        {
                            tableDelegate(container);
                        }
                    }

                    // reselect lobby (otherwise automatically selected by pokerstars -> close table)
                    if (container == TABLE_NOT_FOUND || knownTables.Count > 0)
                    {
                        FocusLobby(layout, screen);
                        keyboard.pressPageUp(3);
                    }
                    // move up for "better" tables
                    else
                    {
                        keyboard.pressPageUp(2);
                        Thread.Sleep(100);
                    }
                }
                else
                {
                    // scroll
                    keyboard.pressPageDown();
                    Thread.Sleep(1000);
                }
            }

            // minimize lobby
            Thread.Sleep(1000);

            return(tables);
        }