示例#1
0
        public MainUI()
            : base("http://zip.app.local/index.html")
        {
            InitializeComponent();
            int SH = Screen.PrimaryScreen.Bounds.Height;
            int SW = Screen.PrimaryScreen.Bounds.Width;

            using (Graphics graphics = Graphics.FromHwnd(IntPtr.Zero))
            {
                SW = (int)(SW * 96 / graphics.DpiX);
                SH = (int)(SH * 96 / graphics.DpiY);
            }
            if (SW < 1400)
            {
                GlobDef.globle_scale = 2.0;
            }
            this.WindowState       = FormWindowState.Maximized;
            LoadHandler.OnLoadEnd += LoadHandler_OnLoadEnd;

            RegisterJSFunc();
            if (adbWrapper == null)
            {
                adbWrapper = new AdbWrapper();
                adbWrapper.Init();
                adbWrapper.prjDataCallBack += UpdateFlow;
            }
            ImgMgr.Get().dataChangedHandler += UpdateVideo;
            CellPhoneProxy.Instance.notifyUpdateHoverRect   += UpdateHoverRect;
            CellPhoneProxy.Instance.notifyEnanleAddFlowItem += EnableAddFlowItem;
        }
示例#2
0
        private static void Main(string[] args)
        {
            Console.Title = string.Format("Grand Hero Farmer v{0}", Helpers.GetProgramVersion());
            Console.Clear();

            Console.WriteLine();
            ConsoleLogger.WriteCenter("Grand Hero Farmer", textColor: ConsoleColor.Cyan, backgroundColor: ConsoleColor.DarkCyan);
            ConsoleLogger.WriteCenter(puns[rnd.Next(puns.Count)], newLine: true, textColor: ConsoleColor.Magenta);
            ConsoleLogger.WriteTime("Starting program...");

            try
            {
                AdbWrapper adb = new AdbWrapper();

                // Initializing Bot Configurations
                ConsoleLogger.WriteTime("Loading bot configurations from xml... ", false);
                BotConfiguration botConfig = new BotConfiguration("configs");
                ConsoleLogger.Write("OK", textColor: ConsoleColor.Cyan);

                ConsoleLogger.WriteTime("Initializing bot instance... ", false);
                FehBot bot = new FehBot(botConfig);
                ConsoleLogger.Write("OK", textColor: ConsoleColor.Cyan);

                ConsoleLogger.WriteTime("Setup is done, press enter to start earning feathers.", textColor: ConsoleColor.Cyan);
                ConsoleLogger.WriteTime("Press 'Ctrl + C' to exit the application.", newLine: false, textColor: ConsoleColor.Cyan);
                Console.ReadLine();

                Thread thread = new Thread(() =>
                {
                    Console.Title = string.Format("{0} - Farming", Console.Title);

                    while (true)
                    {
                        bot.Run(adb);
                    }
                });

                thread.Start();
            }
            catch (FileNotFoundException)
            {
                ConsoleLogger.Write("FAILED", textColor: ConsoleColor.Red);
                ConsoleLogger.WriteTime("Couldn't Load XML File. Press Enter to exit the application.");
            }
            catch (NullReferenceException)
            {
                ConsoleLogger.Write("FAILED", textColor: ConsoleColor.Red);
                ConsoleLogger.WriteTime("Looks like your XML file is malformed. Press Enter to exit the application.");
            }
            catch (Exception ex)
            {
                ConsoleLogger.Write(ex.ToString(), textColor: ConsoleColor.Red);
            }
            finally
            {
                Console.ReadLine();
            }
        }
        private async Task <Tuple <bool, String> > CheckAdbAsync()
        {
            String strResult  = "";
            String strAdbPath = AdbWrapper.GetAdbLocation(false);

            if (strAdbPath == null)
            {
                return(new Tuple <bool, string>(false, "Adb.exe not found in specified directory"));
            }
            else
            {
                Version adbVersion = await AdbWrapper.GetAdbVersionAsync(strAdbPath);

                if (adbVersion == null)
                {
                    return(new Tuple <bool, string>(false, "Unable to communicate with Adb.exe or invalid version"));
                }
                else if (adbVersion < new Version(1, 0, 39))
                {
                    strResult += "ADB version outdated. ";
                }
                else
                {
                    strResult += "ADB version ok. ";
                }
                UpdateTestStatus(strResult);

                int nDevices = await AdbWrapper.GetADBConnectedDevicesAsync(strAdbPath);

                if (nDevices == 0)
                {
                    return(new Tuple <bool, string>(false, strResult + "No connected device found (Is debugging enabled?)."));
                }
                else if (nDevices < 0)
                {
                    return(new Tuple <bool, string>(false, strResult + "Error while getting connected devices."));
                }
                else if (nDevices > 1)
                {
                    return(new Tuple <bool, string>(false, strResult + "Multiple devices found connected - please connect only one."));
                }
                strResult += "Device found. ";
                UpdateTestStatus(strResult);
                if (await AdbWrapper.GetADBScreenCapAsync(strAdbPath, default(CancellationToken), false) == null)
                {
                    if (await AdbWrapper.GetADBScreenCapAsync(strAdbPath, default(CancellationToken), true) == null)
                    {
                        return(new Tuple <bool, string>(false, strResult + "Unable to get/decode screen capture."));
                    }
                    strResult += "Using fallback method. ";
                }
                return(new Tuple <bool, string>(true, strResult + "Successfully received screen capture."));
            }
        }
 private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
 {
     if (e.NewValue as bool? == true)
     {
         tbResultText.Visibility = Visibility.Collapsed;
         rectFailIcon.Visibility = Visibility.Collapsed;
         rectOKIcon.Visibility   = Visibility.Collapsed;
         if (!String.IsNullOrEmpty(AdbWrapper.GetAdbLocation(true)))
         {
             TextBoxHelper.SetWatermark(tbDirectory, AdbWrapper.GetAdbLocation(true));
         }
     }
 }
示例#5
0
        public void Run(AdbWrapper adb)
        {
            Console.WriteLine();
            ConsoleLogger.WriteTime("Starting cicle ", false);
            ConsoleLogger.Write(string.Format("[{0}]", cicles.ToString()), textColor: ConsoleColor.Cyan);

            // Click Lunatic Button
            adb.Tap(config.startButton.GenerateRandomCoords());

            // Click Fight Button
            adb.Tap(config.fightButton.GenerateRandomCoords());

            // Communicate Server
            Thread.Sleep(config.communicateServerTimer);

            // Click to skip initial animations
            adb.Tap(config.fightButton.GenerateRandomCoords());

            // Wait until Dialog starts
            Thread.Sleep(2000);

            // Skip Dialog
            ConsoleLogger.WriteTime("Skipping initial dialog");
            adb.Tap(config.skipDialogButton.GenerateRandomCoords());

            // Wait for initial animations
            Thread.Sleep(3000);

            // Click Auto Battle
            ConsoleLogger.WriteTime("Initializing Auto-Battle");
            adb.Tap(config.autoBattleButton.GenerateRandomCoords());

            // CLick Accept
            adb.Tap(config.acceptAutoBattle.GenerateRandomCoords());

            // Wait for battle to end
            ConsoleLogger.WriteTime("Waiting for battle to end");
            Thread.Sleep(config.stageTimer);

            // Click again to skip animations
            adb.Tap(config.fightButton.GenerateRandomCoords());

            // All done!
            ConsoleLogger.WriteTime("Finished cicle ", false);
            ConsoleLogger.Write(string.Format("[{0}]", cicles.ToString()), textColor: ConsoleColor.Cyan);

            // Wait to send result to server
            Thread.Sleep(config.communicateServerTimer + 1000);

            cicles++;
        }
示例#6
0
        private bool disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!disposedValue)
            {
                if (disposing)
                {
                    _deviceWatcher.Dispose();
                }

                AdbWrapper.KillServer();

                disposedValue = true;
            }
        }
示例#7
0
 private static void Main(string[] args)
 {
     try
     {
         AdbWrapper adbWrapper = new AdbWrapper();
         using (Bitmap screenshot = adbWrapper.GetScreenshot())
         {
             using (Form form = new Form())
             {
                 int maxWinSize = Math.Min(Screen.PrimaryScreen.WorkingArea.Height, Screen.PrimaryScreen.WorkingArea.Width);
                 int maxImgSize = Math.Max(screenshot.Width, screenshot.Height);
                 int scale      = (int)Math.Ceiling((double)maxImgSize / (double)maxWinSize);
                 int w          = 1080 / scale;
                 int h          = 1920 / scale;
                 form.ClientSize      = new Size(w, h);
                 form.FormBorderStyle = FormBorderStyle.FixedToolWindow;
                 form.BackgroundImage = screenshot.GetThumbnailImage(w, h, null, IntPtr.Zero);
                 form.MouseClick     += Program.Form_MouseClick;
                 form.ShowDialog();
                 Point  point  = (Point)form.Tag;
                 Random random = new Random();
                 for (; ;)
                 {
                     int dx = (int)((random.NextDouble() * 2.0 - 1.0) * 10.0);
                     int dy = (int)((random.NextDouble() * 2.0 - 1.0) * 10.0);
                     int x  = point.X * scale + dx;
                     int y  = point.Y * scale + dy;
                     Console.WriteLine(string.Format("tap {0} {1} ({2})", x, y, DateTime.Now));
                     adbWrapper.Tap(x, y, 200);
                     Thread.Sleep(1000 + (int)(random.NextDouble() * 1000.0));
                 }
             }
         }
     }
     catch (Exception innerException)
     {
         while (innerException != null)
         {
             Console.WriteLine(innerException.Message);
             Console.WriteLine(innerException.StackTrace);
             Console.WriteLine(innerException.Source);
             innerException = innerException.InnerException;
         }
         Console.ReadKey();
     }
 }
示例#8
0
        static void Main(string[] args)
        {
            Console.WriteLine("x for demo");
            bool demo = Console.ReadLine() == "x";

            if (demo)
            {
                ROITop    = 268;
                ROIBottom = 1651;
            }

            Color[][] raw   = new Color[Rows][];
            int[][]   board = new int[Rows][];
            for (int i = 0; i < Rows; i++)
            {
                raw[i]   = new Color[Cols];
                board[i] = new int[Cols];
            }

            AdbWrapper adb      = new AdbWrapper();
            Rectangle  ROI      = new Rectangle(ROILeft, ROITop, ROIRight - ROILeft + 1, ROIBottom - ROITop + 1);
            double     cwidth   = (double)ROI.Width / Cols;
            double     cheight  = (double)ROI.Height / Rows;
            int        icwidth  = (int)Math.Round(cwidth);
            int        icheight = (int)Math.Round(cheight);

            using (var img = adb.GetScreenshot())
                //using (var img = new Bitmap(@"D:\WeChat Image_20180711125059.jpg"))
                using (var crop = img.Clone(ROI, img.PixelFormat))
                {
                    BitmapData srcData = crop.LockBits(
                        new Rectangle(0, 0, crop.Width, crop.Height),
                        ImageLockMode.ReadOnly,
                        PixelFormat.Format32bppArgb);

                    for (int i = 0; i < Rows; i++)
                    {
                        for (int j = 0; j < Cols; j++)
                        {
                            int oft  = 20;
                            var rect = new Rectangle(
                                (int)Math.Round(j * cwidth) + oft,
                                (int)Math.Round(i * cheight) + oft,
                                icwidth - oft * 2,
                                icheight - oft * 2);
                            raw[i][j]   = CalculateAverageColor(srcData, rect);
                            board[i][j] = ClosestColorIndex(raw[i][j]);
                        }
                    }

                    crop.UnlockBits(srcData);
                }

            if (demo)
            {
                using (var sw = new StreamWriter(@"D:\a.txt"))
                {
                    sw.WriteLine("[");
                    for (int i = 0; i < Rows; i++)
                    {
                        for (int j = 0; j < Cols; j++)
                        {
                            var c = raw[i][j];
                            sw.WriteLine($"{c.R},{c.G},{c.B};");
                        }
                    }
                    sw.WriteLine("]");
                }
            }

            PrintBoard(board);

            Queue <Tuple <Point, Point> > solution = new Queue <Tuple <Point, Point> >();

            for (int i = 0; i < Rows - 1; i++)
            {
                for (int j = 0; j < Cols - 1; j++)
                {
                    if (board[i][j] > 0)
                    {
                        if (board[i][j] == board[i + 1][j])
                        {
                            solution.Enqueue(Tuple.Create(new Point(i, j), new Point(i + 1, j)));
                            board[i][j] = board[i + 1][j] = 0;
                        }
                        if (board[i][j] == board[i][j + 1])
                        {
                            solution.Enqueue(Tuple.Create(new Point(i, j), new Point(i, j + 1)));
                            board[i][j] = board[i][j + 1] = 0;
                        }
                    }
                }
            }

            while (solution.Count < Rows * Cols / 2)
            {
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Cols; j++)
                    {
                        if (board[i][j] > 0)
                        {
                            var tar = BFS(new Point(i, j), board);
                            if (tar.X >= 0)
                            {
                                board[tar.X][tar.Y] = board[i][j] = 0;
                                solution.Enqueue(Tuple.Create(new Point(i, j), tar));
                                Console.WriteLine(solution.Count);
                            }
                        }
                    }
                }
            }

            PrintSolution(solution);

            while (solution.Count > 0)
            {
                var p = solution.Dequeue();
                adb.Tap(ROILeft + p.Item1.Y * icwidth + Offset, ROITop + p.Item1.X * icheight + Offset);
                adb.Tap(ROILeft + p.Item2.Y * icwidth + Offset, ROITop + p.Item2.X * icheight + Offset);
            }

            Console.WriteLine("End");
            Console.ReadKey();
        }
示例#9
0
        static void Main(string[] args)
        {
            Console.WriteLine("Single Plyaer Mode?(Y/y)");
            bool singlePlayer = Console.ReadLine().ToLower().Contains("y");

            AdbWrapper adb = new AdbWrapper();

            int[][]       board       = new int[9][];
            StringBuilder sboard      = new StringBuilder();
            Rectangle     boardRegion = singlePlayer ? new Rectangle(55, 407, 966, 966) : new Rectangle(55, 330, 966, 966);
            float         offset      = 5;

            using (var img = adb.GetScreenshot())
                using (var boardImg = img.Clone(boardRegion, img.PixelFormat))
                {
                    using (var engine = new TesseractEngine(@"./tessdata", "eng", EngineMode.TesseractAndCube))
                    {
                        engine.SetVariable("tessedit_char_whitelist", "0123456789");
                        for (int i = 0; i < 9; i++)
                        {
                            board[i] = new int[9];
                            for (int j = 0; j < 9; j++)
                            {
                                float x = boardImg.Width / 9f * j + offset;
                                float y = boardImg.Height / 9f * i + offset;
                                float w = boardImg.Width / 9f - offset * 2f;
                                float h = boardImg.Height / 9f - offset * 2f;
                                using (var cell = boardImg.Clone(new RectangleF(x, y, w, h), boardImg.PixelFormat))
                                    using (var cellx = new Bitmap(cell, new Size(cell.Width / 4, cell.Height / 4)))
                                        using (var page = engine.Process(cellx, PageSegMode.SingleChar))
                                        {
                                            var text = page.GetText();
                                            if (string.IsNullOrWhiteSpace(text))
                                            {
                                                board[i][j] = 0;
                                                sboard.Append('.');
                                            }
                                            else
                                            {
                                                board[i][j] = text[0] - '0';
                                                sboard.Append(text[0]);
                                            }
                                        }
                            }
                            sboard.Append('\n');
                        }
                    }
                }

            Console.WriteLine(sboard);
            var option = StringSplitOptions.RemoveEmptyEntries;
            var mod    = Console.ReadLine().Split(new char[] { ' ' }, option).Select(a => int.Parse(a)).ToArray();

            while (mod.Length == 3)
            {
                sboard[mod[0] * 10 + mod[1]] = (char)(mod[2] + '0');
                mod = Console.ReadLine().Split(new char[] { ' ' }, option).Select(a => int.Parse(a)).ToArray();
            }
            Console.WriteLine(sboard);

            var puzzle = SudokuPuzzle.FromString(sboard.ToString(), 3, 3);

            puzzle.SolveGrid();
            Console.WriteLine(puzzle);

            int kx    = 160 + 75;
            int ky    = singlePlayer ? 1460 + 75 : 1356 + 75;
            int cellh = boardRegion.Height / 9;
            int cellw = boardRegion.Width / 9;
            int bx    = boardRegion.X + boardRegion.Width / 18;
            int by    = boardRegion.Y + boardRegion.Height / 18;

            int index = 0;

            foreach (var node in puzzle.GetNodes())
            {
                int v = node.Value;
                adb.Tap(kx + v % 5 * 150, ky + v / 5 * 150);
                adb.Tap(bx + index % 9 * cellw, by + index / 9 * cellh);
                index++;
            }
        }