public static List <int> GetButtonNumbers(CATSimage button)
        {
            Bitmap screen = ADB.TakeScreenshot(button, true);

            CorrectImage(ref screen);
            List <int> toReturn = new List <int>();
            int        parser   = 0;

            try
            {
                Tesseract ocr = new Tesseract();
                ocr.SetVariable("tessedit_char_whitelist", "0123456789");
                ocr.Init(@"english_tessdata\", "eng", false);

                List <Word> results = ocr.DoOCR(screen, Rectangle.Empty);
                if (results != null && results.Count != 0)
                {
                    foreach (Word w in results)
                    {
                        if (int.TryParse(w.Text, out parser))
                        {
                            toReturn.Add(parser);
                        }
                    }
                }
            }
            catch (Exception e)
            {
                Logger.Log("GetButtonNumbers Exception: " + e.Message, debug: true);
            }

            return(toReturn);
        }
Example #2
0
        private static Messages AttackWithMach(CATSimage button)
        {
            if (!Game.RepeatFindButton(Resources.Championship, SettingsManager.settings.GetLatency()))
            {
                return(Messages.Restart);
            }

            Logger.Log("Setting to loadout: " + button.Name);
            SetMach(button);

            if (!Game.FindAndClickButtonWithSleep(Resources.Championship, 3))
            {
                return(Messages.Restart);
            }

            if (!Game.FindAndClickButton(Resources.Fight, 3, 1))
            {
                return(Messages.Restart);
            }
            Logger.Log("Started fighting. ");

            Logger.Log("Waiting to end...", newLine: false);
            if (!Game.FindAndClickButtonWithSleep(Resources.OK, 420, 0.5))
            {
                return(Messages.Restart);
            }

            Logger.Log("Going back to main screen");
            if (!Game.RepeatFindButton(Resources.Championship, SettingsManager.settings.GetLatency() + 2))
            {
                if (Game.RepeatFindButton(Resources.Choose, SettingsManager.settings.GetLatency() - 1))
                {
                    Logger.Log("We got promoted");
                    Game.ClickButton(Resources.Choose, 0.1);
                    Game.RandomSleep(1000, 4000);
                    if (BoxOpener.OpenBox(false) == Messages.Restart)
                    {
                        return(Messages.Restart);
                    }

                    if (!Game.RepeatFindButton(Resources.Championship, SettingsManager.settings.GetLatency()))
                    {
                        return(Messages.Restart);
                    }

                    SettingsManager.settings.champTime.AddHours(48);
                }
                else
                {
                    Logger.Log("Something went wrong");
                    return(Messages.Restart);
                }
            }

            return(Messages.OK);
        }
Example #3
0
        public static void ClickButton(CATSimage button, double tolerance = 0.2)
        {
            RandomSleep();
            Random r          = new Random();
            int    toleranceX = Convert.ToInt32(button.ButtonRectangle.Width * (tolerance >= 1 ? 0.45 : tolerance / 2));
            int    toleranceY = Convert.ToInt32(button.ButtonRectangle.Height * (tolerance >= 1 ? 0.45 : tolerance / 2));
            int    touchX     = r.Next(button.ButtonRectangle.X + toleranceX, button.ButtonRectangle.X + button.ButtonRectangle.Width - toleranceX);
            int    touchY     = r.Next(button.ButtonRectangle.Y + toleranceY, button.ButtonRectangle.Y + button.ButtonRectangle.Height - toleranceY);

            RunCommand("adb.exe", "shell input touchscreen tap " + touchX + " " + touchY);
        }
Example #4
0
        private static void SetMach(CATSimage mach)
        {
            Game.ClickButton(Resources.Edit);
            Game.RandomSleep(1500, 2500);

            Game.ClickButton(mach);
            Game.RandomSleep(1500, 2500);

            Game.ClickBack();
            Game.RandomSleep(1000, 1700);
        }
Example #5
0
        public static bool FindAndClickButton(CATSimage button, int tries = 1, double tolerance = 0.2)
        {
            if (ImageRecognition.FindButton(button, tries) == 0)
            {
                return(false);
            }

            ADB.ClickButton(button, tolerance);

            return(true);
        }
Example #6
0
        public static bool ClickButtonWithFind(CATSimage button, int tries = 1, double tolerance = 0.2)
        {
            Rectangle r = ImageRecognition.FindButtonRectangle(button, tries);

            if (r.IsEmpty)
            {
                return(false);
            }
            else
            {
                ADB.ClickButtonRectangle(r, tolerance);
            }

            return(true);
        }
Example #7
0
        public static bool FindAndClickButtonWithSleep(CATSimage button, int seconds = 2, double tolerance = 0.2)
        {
            for (int i = 0; i < seconds; i++)
            {
                if (ImageRecognition.FindButton(button, 2) > 0)
                {
                    ADB.ClickButton(button, tolerance);
                    return(true);
                }

                Thread.Sleep(1000);
            }

            return(false);
        }
Example #8
0
        public static Bitmap TakeScreenshot(CATSimage button = null, bool keepSize = true)
        {
            try
            {
                string error = "";
                error += RunCommand("adb.exe", "shell screencap -p /sdcard/screenshot.png");
                RunCommand("adb.exe", "pull /sdcard/screenshot.png");
                error += RunCommand("adb.exe", "shell rm /sdcard/screenshot.png");

                if (error != "")
                {
                    Game.RestartApp();
                }

                Bitmap screenBitmap;
                if (File.Exists("screenshot.png"))
                {
                    Image screenImage = Image.FromFile("screenshot.png");
                    screenBitmap = new Bitmap(screenImage.Width, screenImage.Height, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
                    using (Graphics g = Graphics.FromImage(screenBitmap))
                    {
                        g.DrawImage(screenImage, new Rectangle(0, 0, screenImage.Width, screenImage.Height));
                    }
                    screenImage.Dispose();
                }
                else
                {
                    throw new Exception("screenshot.png doesn't exist");
                }

                if (button != null)
                {
                    ImageRecognition.CropImage(button, ref screenBitmap);
                }
                if (!keepSize)
                {
                    ImageRecognition.ResizeImage(ref screenBitmap);
                }
                return(screenBitmap);
            }
            catch (Exception e)
            {
                Logger.Log("TakeScreenshot Exception: " + e.Message + e.StackTrace, debug: true);
                return(null);
            }
        }
        public static int FindButton(CATSimage button, int tries = 1)
        {
            for (int i = 0; i < tries; i++)
            {
                Bitmap screen = ADB.TakeScreenshot(button);

                ExhaustiveTemplateMatching templateMatching = new ExhaustiveTemplateMatching(0.941f);
                TemplateMatch[]            matches          = templateMatching.ProcessImage(screen, button.image);

                if (matches.Count() != 0)
                {
                    return(matches.Count());
                }
            }

            return(0);
        }
        public static Rectangle FindButtonRectangle(CATSimage button, int tries = 1)
        {
            for (int i = 0; i < tries; i++)
            {
                Bitmap screen = ADB.TakeScreenshot(button);

                ExhaustiveTemplateMatching templateMatching = new ExhaustiveTemplateMatching(0.941f);
                TemplateMatch[]            matches          = templateMatching.ProcessImage(screen, button.image);

                if (matches.Count() != 0)
                {
                    Rectangle r = matches.ElementAt(0).Rectangle;
                    r.X += button.ButtonRectangle.X;
                    r.Y += button.ButtonRectangle.Y;
                    return(r);
                }
            }

            return(Rectangle.Empty);
        }
Example #11
0
        public static bool RepeatFindButton(CATSimage button, int seconds = 2, int sleep = 0)
        {
            if (ImageRecognition.FindButton(button, SettingsManager.settings.GetLatency()) > 0)
            {
                return(true);
            }

            for (int i = 0; i < seconds; i++)
            {
                if (ImageRecognition.FindButton(button, 2) > 0)
                {
                    return(true);
                }

                ADB.ClickBack();

                if (sleep > 0)
                {
                    Thread.Sleep(sleep);
                }
            }

            return(false);
        }
Example #12
0
 public static bool FindButton(CATSimage button, int tries = 1)
 {
     return(ImageRecognition.FindButton(button, tries) > 0);
 }
Example #13
0
        public static void ClickButtonRectangle(Rectangle r, double tolerance = 0.2)
        {
            CATSimage c = new CATSimage("", r, "");

            ClickButton(c, tolerance);
        }
Example #14
0
 public static int FindAllButtons(CATSimage button, int tries = 1)
 {
     return(ImageRecognition.FindButton(button, tries));
 }
 public static void CropImage(CATSimage button, ref Bitmap screenshot)
 {
     screenshot = screenshot.Clone(button.ButtonRectangle, System.Drawing.Imaging.PixelFormat.Format24bppRgb);
 }
Example #16
0
 public static void ClickButton(CATSimage button, double tolerance = 0.2)
 {
     ADB.ClickButton(button, tolerance);
 }
Example #17
0
 public static Bitmap TakeScreenshot(CATSimage button = null, bool keepSize = true)
 {
     return(ADB.TakeScreenshot(button, keepSize));
 }
Example #18
0
 public static List <int> ReadImageValue(CATSimage button)
 {
     return(ImageRecognition.GetButtonNumbers(button));
 }