private async Task SwipeDown(AndroidConnector android)
        {
            await Task.Delay(250);

            await android.Swipe(1160, 860, 1160, -350, 1000);

            await Task.Delay(250);

            await android.Tap(530, 845); // against overlay

            await Task.Delay(500);
        }
        private async Task <bool> NextPage(AndroidConnector android)
        {
            using (var image = Image.Load <Rgba32>("shopitems.png"))
            {
                var maxPageImage = image.Clone(ctx => ctx.Crop(new Rectangle(763, 956, 39, 52)));
                int maxPage      = -1;
                //TODO: cache these
                foreach (var file in Directory.GetFiles("data/pagenumbers/total"))
                {
                    using (var pageImage = Image.Load <Rgba32>(file))
                        if (IsSame(pageImage, maxPageImage))
                        {
                            maxPage = int.Parse(Path.GetFileNameWithoutExtension(file), CultureInfo.InvariantCulture);
                        }
                }

                if (maxPage == -1)
                {
                    maxPageImage.Save($"unknown/maxpage{Directory.GetFiles("unknown").Length}.png");
                }

                var curPageImage = image.Clone(ctx => ctx.Crop(new Rectangle(700, 962, 63, 44)));
                int curPage      = -1;
                //TODO: cache these
                foreach (var file in Directory.GetFiles("data/pagenumbers/current"))
                {
                    using (var pageImage = Image.Load <Rgba32>(file))
                        if (IsSame(pageImage, curPageImage))
                        {
                            curPage = int.Parse(Path.GetFileNameWithoutExtension(file), CultureInfo.InvariantCulture);
                        }
                }
                if (curPage == -1)
                {
                    curPageImage.Save($"unknown/curpage{Directory.GetFiles("unknown").Length}.png");
                }


                if (curPage < maxPage)
                {
                    await android.Tap(944, 982);

                    await Task.Delay(500); // wait for next page to load

                    return(false);
                }
            }


            return(true);
        }
        public async Task <ScanResultEquip> ParseResultWindowEquip(string fileName, ScanInfo scanInfo, AndroidConnector android)
        {
            ScanResultEquip exchangeInfo = new ScanResultEquip()
            {
                Found    = true,
                ScanInfo = scanInfo
            };

            using (var image = Image.Load <Rgba32>(fileName))
            {
                image.Clone(ctx => ctx.Crop(new Rectangle(996, 159, 549, 66))).Save($"itemname.png");
                string itemName = GetTextFromImage("itemname.png");
                if (itemName.ToLower() != scanInfo.RealName.ToLower())
                {
                    scanInfo.Message = $"Something is wrong, names do NOT match. Expected {scanInfo.RealName.ToLower()} but got {itemName.ToLower()}";
                    return(ScanResult.BuildError <ScanResultEquip>(scanInfo));
                }

                exchangeInfo.Price    = int.Parse(GetPriceEquip(image), CultureInfo.InvariantCulture);
                exchangeInfo.SnapTime = GetSnapTime(image);

                int i = 0;
                //scan for multiple items
                bool enchanted   = false;
                bool foundRefine = false;
                while (!Program.CancelScan)
                {
                    using (var image2 = Image.Load <Rgba32>(fileName))
                        image2.Clone(ctx => ctx.Crop(new Rectangle(383, 261, 553, 453))).Save($"enchant{i}.png");
                    string hasEnchant = GetTextFromImage($"enchant{i}.png");
                    Console.WriteLine($"- Text Read: \n\n{hasEnchant}\n\n");
                    if (hasEnchant.ToLower().Contains("refine ") && !foundRefine && !enchanted && hasEnchant.ToLower().IndexOf("refine ") != hasEnchant.ToLower().IndexOf("refine +6 effective"))
                    {
                        string refine = hasEnchant.ToLower();
                        refine = refine.Replace("\r\n", "\n");
                        while (refine.Contains("\n\n"))
                        {
                            refine = refine.Replace("\n\n", "\n");
                        }
                        refine = refine.Substring(refine.IndexOf("\nrefine ") + 8).Trim();
                        if (refine.IndexOf("\n") > 0)
                        {
                            refine = refine.Substring(0, refine.IndexOf("\n")).Trim();
                        }
                        Console.WriteLine(refine);
                        int refineLevel = 0;
                        if (refine.Contains("/"))
                        {
                            try
                            {
                                refineLevel = int.Parse(refine.Substring(0, refine.IndexOf("/")));
                                foundRefine = true;
                            }
                            catch (FormatException e)
                            {
                                scanInfo.Message = "Something is wrong, error parsing refine level: " + refine;
                                Console.WriteLine(e);
                                return(ScanResult.BuildError <ScanResultEquip>(scanInfo));
                            }
                        }
                        if (refine.Contains("atk+"))
                        {
                            int atk = int.Parse(refine.Substring(refine.IndexOf("atk+") + 4));
                            foundRefine = true;
                            //TODO: check if atk matches refineLevel
                        }
                        exchangeInfo.RefinementLevel = refineLevel;
                    }


                    if (hasEnchant.ToLower().Contains("enchanted"))
                    {
                        enchanted = true;
                    }
                    if (hasEnchant.ToLower().Contains("equipment upgrade"))
                    {
                        if (enchanted)
                        {
                            MemoryStream ms          = new MemoryStream();
                            var          jpegEncoder = new SixLabors.ImageSharp.Formats.Jpeg.JpegEncoder {
                                Quality = 10
                            };
                            using (var image2 = Image.Load <Rgba32>($"enchant{i}.png"))
                                image2.Clone(ctx => ctx.Resize(new ResizeOptions {
                                    Size = image2.Size() / 2
                                })).SaveAsJpeg(ms, jpegEncoder);

                            exchangeInfo.EnchantmentImage = System.Convert.ToBase64String(ms.GetBuffer());
                            if (!hasEnchant.ToLower().Contains("enchanted"))
                            {
                                Console.WriteLine("Scrolled too far");
                                exchangeInfo.Enchantments = new List <string>()
                                {
                                    "scrolled too far"
                                };
                                break;
                            }
                            hasEnchant = hasEnchant.ToLower();
                            hasEnchant = hasEnchant.Replace("\r\n", "\n");
                            while (hasEnchant.Contains("\n\n"))
                            {
                                hasEnchant = hasEnchant.Replace("\n\n", "\n");
                            }
                            hasEnchant = hasEnchant.Substring(hasEnchant.IndexOf("enchanted attribute:") + 20).Trim();
                            hasEnchant = hasEnchant.Substring(0, hasEnchant.IndexOf("equipment upgrade")).Trim();

                            hasEnchant = hasEnchant.Replace("mapr ", "maxhp ");
                            exchangeInfo.Enchantments = hasEnchant.Split("\n", 4).ToList();
                        }
                        break;
                    }
                    if (hasEnchant.ToLower().Contains("exchange price"))
                    {
                        Console.WriteLine("Scrolled wayyyyyy too far");
                        break;
                    }


                    await android.Swipe(555, 500, 555, 300, 500);

                    await Task.Delay(100);

                    await android.Tap(1500, 960);

                    await android.Screenshot(fileName);

                    i++;
                }
                exchangeInfo.Found = true;
            }
            return(exchangeInfo);
        }
        public async Task RestartRo(AndroidConnector android)
        {
            Program.status.SetSubStatus("Stopping RO");
            await android.StopRo();

            await Task.Delay(1000);

            Program.status.SetSubStatus("Starting RO");
            await android.StartRo();

            await Task.Delay(30000);

            Program.status.SetSubStatus("Scanning if logged in");
            //TODO: check for google/facebook popup
            for (int i = 0; i < 25; i++)
            {
                await android.Screenshot("login.png");

                using (var image = Image.Load <Rgba32>("login.png"))
                    image.Clone(ctx => ctx.Crop(new Rectangle(855, 585, 215, 55))).Save($"servername.png");
                string servername = GetTextFromImage("servername.png");
                Console.WriteLine(servername);
                if (servername.ToLower() == "eternal love")
                {
                    break;
                }
                await Task.Delay(5000);

                if (i == 24)
                {
                    Program.status.SetSubStatus("Unable to login");
                    return;
                }
            }
            Program.status.SetSubStatus("Tapping Login");
            await android.Tap(500, 500);        //login tap

            await Task.Delay(10000);

            for (int i = 0; i < 25; i++)
            {
                await android.Screenshot("charselect.png");

                using (var image = Image.Load <Rgba32>("charselect.png"))
                    using (var cmp = Image.Load <Rgba32>("data/startbutton.png"))
                        if (IsSame(image.Clone(ctx => ctx.Crop(new Rectangle(1518, 943, 243, 67))), cmp))
                        {
                            break;
                        }
                await Task.Delay(2000);

                if (i == 24)
                {
                    Program.status.SetSubStatus("Unable to select character");
                    return;
                }
            }
            Program.status.SetSubStatus("Selecting char");
            await android.Tap(1624, 975);       //select char button

            await Task.Delay(30000);

            Program.status.SetSubStatus("Closing stupid ninja popup");
            await android.Tap(1893, 50);       //

            await Task.Delay(1000);

            Program.status.SetSubStatus("Closing event popup");
            await android.Tap(1400, 133);       //close event popup

            await android.Tap(1495, 111);       //close anotherpopup
        }
 private async Task ClickShopBuyButton(AndroidConnector android)
 {
     await android.Tap(1600, 984);
 }
 private async Task ClickShopCloseItem(AndroidConnector android)
 {
     await android.Tap(525, 900);
 }
 private async Task ClickSearchWindowIndex(AndroidConnector android, int index)
 {
     await android.Tap(SearchResultPositions[index].X + 155, SearchResultPositions[index].Y + 44);
 }
 private async Task ClickShopItem(AndroidConnector android, int index, int offsety = 0)
 {
     await android.Tap(800 + (index % 2) * 600, offsety + 302 + 180 *(index / 2));
 }
 private async Task ClickSearchWindowSearchButton(AndroidConnector android)
 {
     await android.Tap(1400, 260);
 }
 private async Task ClickSearchBox(AndroidConnector android)
 {
     await android.Tap(800, 270);
 }
 private async Task CloseSearch(AndroidConnector android)
 {
     await android.Tap(1467, 187);
 }
 private async Task ClickSearchButton(AndroidConnector android)
 {
     await android.Tap(300, 200);
 }
        public async Task OpenExchange(AndroidConnector android, int map)
        {
            await android.Tap(1800, 160);       //open minimap

            await Task.Delay(500);

            await android.Screenshot("minimap.png");

            using (var image = Image.Load <Rgba32>("minimap.png"))
                image.Clone(ctx => ctx.Crop(new Rectangle(1309, 175, 523, 60))).Save($"mapname.png");
            string mapname = GetTextFromImage("mapname.png").ToLower();
            await android.Tap(1325, 861);       //click world button

            await Task.Delay(1500);

            if (mapname == "prontera south gate")
            {
                await android.Tap(1100, 700);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 665);       //click big cat man
            }
            else if (mapname == "prontera")
            {
                await android.Tap(1100, 600);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 831);       //click big cat man
            }
            else if (mapname == "morroc")
            {
                await android.Tap(1000, 800);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 782);       //click big cat man
            }
            else if (mapname == "geffen")
            {
                await android.Tap(900, 600);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 718);       //click big cat man            }
            }
            else if (mapname == "payon")
            {
                await android.Tap(1300, 800);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 716);       //click big cat man
            }
            else if (mapname == "izlude island")
            {
                await android.Tap(1200, 700);       //click map

                await Task.Delay(1500);

                await android.Tap(700, 432);        //click big cat man
            }
            else
            {
                Program.status.SetSubStatus("Player is at unknown map: " + mapname);
            }


            Program.status.SetSubStatus("Waiting for exchange popup");
            await Task.Delay(1000);

            //wait for buy button to appear
            while (true)
            {
                await android.Screenshot("exchange.png");

                using (var image = Image.Load <Rgba32>("exchange.png"))
                    using (var cmp = Image.Load <Rgba32>("data/exchange.png"))
                        if (IsSame(image.Clone(ctx => ctx.Crop(new Rectangle(1525, 683, 329, 54))), cmp))
                        {
                            break;
                        }
                await Task.Delay(2000);
            }
            Program.status.SetSubStatus("Exchange opened, done");
            await android.Tap(1660, 705);
        }