예제 #1
0
파일: Runner.cs 프로젝트: guipaz/venomsw
        public void Start()
        {
            analyzer        = new BasicAnalyzer();
            referenceImages = new Dictionary <string, Bitmap>();
            State currentState = DefineStates();

            if (DEBUG_MODE)
            {
                Console.WriteLine("DEBUG MODE");
                Console.WriteLine("ESC - Close");
                Console.WriteLine("S - Save screenshot");
                Console.WriteLine("C - Show coordinates");
                Console.WriteLine("Enter - Run");
                Console.WriteLine("D - Run in debug mode (Press any key for next check)");
                Console.WriteLine("F - Save references");
                int savedImages = 0;
                while (true)
                {
                    ConsoleKey k = Console.ReadKey().Key;
                    Console.Write("\n");

                    if (k == ConsoleKey.Escape)
                    {
                        return;
                    }

                    if (k == ConsoleKey.T)
                    {
                        TesseractTest.Run();
                    }
                    else if (k == ConsoleKey.S)
                    {
                        Bitmap b = User32.CaptureApplication(PROCESS_NAME);
                        b.Save(PATH + "images\\saved\\saved_" + savedImages++ + ".png");
                        Console.WriteLine("Image saved");
                    }
                    else if (k == ConsoleKey.C)
                    {
                        Point p;
                        User32.GetCursorPos(out p);
                        Point p2 = ClickOnPointTool.GetWindowCoordinates(Process.GetProcessesByName("mobizen")[0].MainWindowHandle, p);
                        Console.WriteLine(p2);
                    }
                    else if (k == ConsoleKey.Enter)
                    {
                        break;
                    }
                    else if (k == ConsoleKey.D)
                    {
                        RUN_DEBUG = true;
                        break;
                    }
                    else if (k == ConsoleKey.F)
                    {
                        foreach (var pattern in Pattern.All)
                        {
                            pattern.reference.Save(PATH + "images\\references\\" + pattern.name + ".png");
                        }

                        Console.WriteLine("References saved");
                    }
                }
            }

            Console.Write("Repeat: ");
            string repeat      = Console.ReadLine();
            int    maxDungeons = 0;

            int.TryParse(repeat, out maxDungeons);

            Comparer c      = new Comparer();
            bool     active = true;

            while (active)
            {
                if (RUN_DEBUG)
                {
                    ConsoleKey k = Console.ReadKey().Key;
                }
                else
                {
                    Thread.Sleep(currentState.cooldown * 1000);
                }

                Bitmap screen = User32.CaptureApplication(PROCESS_NAME);
                Console.WriteLine("Checking...");
                foreach (Road r in currentState.roads)
                {
                    if (r.pattern != null && r.pattern.reference != null && c.IsValid(r.pattern, screen))
                    {
                        Console.WriteLine("Found pattern");
                        if (r.clickX != 0 || r.clickY != 0)
                        {
                            if (r.wait > 0)
                            {
                                Thread.Sleep(r.wait * 1000);
                            }

                            Execute(r, screen);
                        }

                        // waits a second
                        Thread.Sleep(1000);

                        Console.WriteLine("Changing to " + r.destination.name);

                        // Counts dungeons completed
                        if (r.destination.name.Equals("Team selection") &&
                            !currentState.name.Equals("Energy shop leave"))
                        {
                            completedDungeons++;
                            Console.WriteLine("Dungeons completed: " + completedDungeons);

                            if (maxDungeons > 0 && completedDungeons >= maxDungeons)
                            {
                                Console.WriteLine("Maximum amount of dungeons reached");
                                active = false;
                            }
                        }

                        currentState = r.destination;

                        break;
                    }
                }
            }

            Console.WriteLine("VenomSW is done working, press any key to exit.");
            Console.ReadKey();
        }