public static int ScanLevel(Bitmap bm, ref bool ascended)
        {
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            string text = Scraper.AnalyzeText(n).Trim();

            n.Dispose();
            text = Regex.Replace(text, @"(?![\d/]).", string.Empty);

            if (text.Contains('/'))
            {
                string[] temp = text.Split(new[] { '/' }, 2);

                if (temp.Length == 2)
                {
                    if (int.TryParse(temp[0], out int level) && int.TryParse(temp[1], out int maxLevel))
                    {
                        maxLevel = (int)Math.Round(maxLevel / 10.0, MidpointRounding.AwayFromZero) * 10;
                        ascended = 20 <= level && level < maxLevel;
                        return(level);
                    }
                }
            }
            return(-1);
        }
        public static string ScanEquippedCharacter(Bitmap bm)
        {
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetContrast(60.0, ref n);

            string extractedString = Scraper.AnalyzeText(n);

            n.Dispose();

            if (extractedString != "")
            {
                var regexItem = new Regex("Equipped:");
                if (regexItem.IsMatch(extractedString))
                {
                    var name = extractedString.Split(':')[1];

                    name = Regex.Replace(name, @"[\W]", string.Empty).ToLower();
                    name = Scraper.FindClosestCharacterName(name);

                    return(name);
                }
            }
            // artifact has no equipped character
            return(null);
        }
 public static string ParseMoraFromScreenshot(Bitmap screenshot)
 {
     using (var gray = Scraper.ConvertToGrayscale(screenshot))
     {
         var input = Scraper.AnalyzeText(gray).Split(' ').ToList();
         input.RemoveAll(e => Regex.IsMatch(e.Trim(), @"[^0-9]") || string.IsNullOrWhiteSpace(e.Trim()));
         var mora = input.LastOrDefault();
         return(mora);
     }
 }
Esempio n. 4
0
        private static int ScanArtifactCount()
        {
            //Find artifact count
            var region = new Rectangle(
                x: (int)(1030 / 1280.0 * Navigation.GetWidth()),
                y: (int)(20 / 720.0 * Navigation.GetHeight()),
                width: (int)(175 / 1280.0 * Navigation.GetWidth()),
                height: (int)(25 / 720.0 * Navigation.GetHeight()));

            using (Bitmap countBitmap = Navigation.CaptureRegion(region))
            {
                UserInterface.SetNavigation_Image(countBitmap);

                Bitmap n = Scraper.ConvertToGrayscale(countBitmap);
                Scraper.SetContrast(60.0, ref n);
                Scraper.SetInvert(ref n);

                string text = Scraper.AnalyzeText(n).Trim();
                n.Dispose();

                // Remove any non-numeric and '/' characters
                text = Regex.Replace(text, @"[^0-9/]", string.Empty);

                if (string.IsNullOrWhiteSpace(text))
                {
                    countBitmap.Save($"./logging/artifacts/ArtifactCount.png");
                    Navigation.CaptureWindow().Save($"./logging/artifacts/ArtifactWindow_{Navigation.GetWidth()}x{Navigation.GetHeight()}.png");
                    throw new FormatException("Unable to locate artifact count.");
                }

                int count;

                // Check for slash
                if (Regex.IsMatch(text, "/"))
                {
                    count = int.Parse(text.Split('/')[0]);
                }
                else if (Regex.Matches(text, "1500").Count == 1)                 // Remove the inventory limit from number
                {
                    text  = text.Replace("1500", string.Empty);
                    count = int.Parse(text);
                }
                else                 // Extreme worst case
                {
                    count = 1500;
                    Logger.Debug("Defaulted to 1500 for artifact count");
                }

                return(count);
            }
        }
        private static int ScanLevel(ref bool ascended)
        {
            int level = -1;

            var xRef = 1280.0;
            var yRef = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yRef = 800.0;
            }

            Rectangle region = new RECT(
                Left:   (int)(960 / xRef * Navigation.GetWidth()),
                Top:    (int)(135 / yRef * Navigation.GetHeight()),
                Right:  (int)(1125 / xRef * Navigation.GetWidth()),
                Bottom: (int)(163 / yRef * Navigation.GetHeight()));

            do
            {
                Bitmap bm = Navigation.CaptureRegion(region);

                bm = Scraper.ResizeImage(bm, bm.Width * 2, bm.Height * 2);
                Bitmap n = Scraper.ConvertToGrayscale(bm);
                Scraper.SetInvert(ref n);
                Scraper.SetContrast(30.0, ref bm);

                string text = Scraper.AnalyzeText(n).Trim();

                text = Regex.Replace(text, @"(?![0-9/]).", string.Empty);
                if (text.Contains("/"))
                {
                    var values = text.Split('/');
                    if (int.TryParse(values[0], out level) && int.TryParse(values[1], out int maxLevel))
                    {
                        maxLevel = (int)Math.Round(maxLevel / 10.0, MidpointRounding.AwayFromZero) * 10;
                        ascended = 20 <= level && level < maxLevel;
                        UserInterface.SetCharacter_Level(bm, level, maxLevel);
                        n.Dispose();
                        bm.Dispose();
                        return(level);
                    }
                    n.Dispose();
                    bm.Dispose();
                }
                Navigation.SystemRandomWait(Navigation.Speed.Normal);
            } while (level == -1);

            return(-1);
        }
Esempio n. 6
0
        private static string ScanArtifactGearSlot(Bitmap bm)
        {
            // Process Img
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetContrast(80.0, ref n);
            Scraper.SetInvert(ref n);

            string gearSlot = Scraper.AnalyzeText(n).Trim().ToLower();

            gearSlot = Regex.Replace(gearSlot, @"[\W_]", string.Empty);
            gearSlot = Scraper.FindClosestGearSlot(gearSlot);
            n.Dispose();
            return(gearSlot);
        }
Esempio n. 7
0
        private static string ScanEnhancementMaterialName(Bitmap bm)
        {
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            // Analyze
            string name = Regex.Replace(Scraper.AnalyzeText(n).ToLower(), @"[\W]", string.Empty);

            name = Scraper.FindClosestMaterialName(name, 3);
            n.Dispose();

            return(name);
        }
        public static string ScanMaterialName(InventorySection section, out Bitmap nameplate)
        {
            // Grab item name on right
            var refWidth  = 1280.0;
            var refHeight = Navigation.GetAspectRatio() == new Size(16, 9) ? 720.0 : 800.0;

            var width  = Navigation.GetWidth();
            var height = Navigation.GetHeight();

            var reference = new Rectangle(872, 80, 327, 37);

            // Nameplate is in the same place in 16:9 and 16:10
            var region = new RECT(
                Left:   (int)(reference.Left / refWidth * width),
                Top:    (int)(reference.Top / refHeight * height),
                Right:  (int)(reference.Right / refWidth * width),
                Bottom: (int)(reference.Bottom / refHeight * height));

            Bitmap bm = Navigation.CaptureRegion(region);

            nameplate = (Bitmap)bm.Clone();

            // Alter Image
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            string text = Scraper.AnalyzeText(n);

            text = Regex.Replace(text, @"[\W]", string.Empty).ToLower();

            //UI
            n.Dispose();
            bm.Dispose();

            if (section == InventorySection.CharacterDevelopmentItems)
            {
                return(Scraper.FindClosestDevelopmentName(text));
            }

            if (section == InventorySection.Materials)
            {
                return(Scraper.FindClosestMaterialName(text));
            }

            return(null);
        }
        public static int ScanMaterialCount(Rectangle rectangle, out Bitmap quantity)
        {
            var region = new RECT(
                Left: rectangle.X,
                Top: (int)(rectangle.Y + (0.8 * rectangle.Height)),                 // Only get the bottom of inventory item
                Right: rectangle.Right,
                Bottom: rectangle.Bottom + 10);

            using (Bitmap bm = Navigation.CaptureRegion(region))
            {
                quantity = (Bitmap)bm.Clone();

                using (Bitmap rescaled = Scraper.ResizeImage(bm, (int)(bm.Width * 3), (int)(bm.Height * 3)))
                {
                    Bitmap copy = (Bitmap)rescaled.Clone();
                    Scraper.SetGamma(0.7, 0.7, 0.7, ref copy);
                    // Image Processing
                    Bitmap n = Scraper.ConvertToGrayscale(copy);
                    Scraper.SetContrast(65, ref n);                     // Setting a high contrast seems to be better than thresholding
                    //Scraper.SetThreshold(165, ref n);

                    string old_text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleWord).Trim().ToLower();

                    // Might be worth it to train some more numbers
                    var cleaned = old_text.Replace("mm", "111").Replace("m", "11").Replace("nn", "11").Replace("n", "1");                     // Tesseract struggles with 1's so close together because of font
                    cleaned = cleaned.Replace("a", "4");
                    cleaned = cleaned.Replace("e", "1");
                    //old_text = old_text.Replace("b", "8");
                    //old_text = old_text.Replace("+", "4");

                    cleaned = Regex.Replace(cleaned, @"[^0-9]", string.Empty);

                    _ = int.TryParse(cleaned, out int count);

                    Debug.WriteLine($"{old_text} -> {cleaned} -> {count}");

                    //if (count > 3000 || count == 0)
                    //{
                    //	//Navigation.DisplayBitmap(n);
                    //}
                    copy.Dispose();
                    n.Dispose();
                    return(count);
                }
            }
        }
        public static string ScanName(Bitmap bm)
        {
            Scraper.SetGamma(0.2, 0.2, 0.2, ref bm);
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetInvert(ref n);

            // Analyze
            string text = Regex.Replace(Scraper.AnalyzeText(n).ToLower(), @"[\W]", string.Empty);

            text = Scraper.FindClosestWeapon(text);

            n.Dispose();

            // Check in Dictionary
            return(text);
        }
        public static string ScanMainCharacterName()
        {
            var xReference = 1280.0;
            var yReference = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yReference = 800.0;
            }

            RECT region = new RECT(
                Left:   (int)(185 / xReference * Navigation.GetWidth()),
                Top:    (int)(26 / yReference * Navigation.GetHeight()),
                Right:  (int)(460 / xReference * Navigation.GetWidth()),
                Bottom: (int)(60 / yReference * Navigation.GetHeight()));

            Bitmap nameBitmap = Navigation.CaptureRegion(region);

            //Image Operations
            Scraper.SetGamma(0.2, 0.2, 0.2, ref nameBitmap);
            Scraper.SetInvert(ref nameBitmap);
            Bitmap n = Scraper.ConvertToGrayscale(nameBitmap);

            UserInterface.SetNavigation_Image(nameBitmap);

            string text = Scraper.AnalyzeText(n).Trim();

            if (text != "")
            {
                // Only keep a-Z and 0-9
                text = Regex.Replace(text, @"[\W_]", string.Empty).ToLower();

                // Only keep text up until first space
                text = Regex.Replace(text, @"\s+\w*", string.Empty);

                UserInterface.SetMainCharacterName(text);
            }
            else
            {
                UserInterface.AddError(text);
            }
            n.Dispose();
            nameBitmap.Dispose();
            return(text);
        }
Esempio n. 12
0
        private static int ScanArtifactLevel(Bitmap bm)
        {
            // Process Img
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetContrast(80.0, ref n);
            Scraper.SetInvert(ref n);

            // numbersOnly = true => seems to interpret the '+' as a '4'
            string text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleWord).Trim().ToLower();

            n.Dispose();

            // Get rid of all non digits
            text = Regex.Replace(text, @"[\D]", string.Empty);

            return(int.TryParse(text, out int level) ? level : -1);
        }
        public static int ScanRefinement(Bitmap image)
        {
            for (double factor = 1; factor <= 2; factor += 0.1)
            {
                using (Bitmap up = Scraper.ScaleImage(image, factor))
                {
                    Bitmap n = Scraper.ConvertToGrayscale(up);
                    Scraper.SetInvert(ref n);

                    string text = Scraper.AnalyzeText(n).Trim();
                    n.Dispose();
                    text = Regex.Replace(text, @"[^\d]", string.Empty);

                    // Parse Int
                    if (int.TryParse(text, out int refinementLevel) && 1 <= refinementLevel && refinementLevel <= 5)
                    {
                        return(refinementLevel);
                    }
                }
            }
            return(-1);
        }
Esempio n. 14
0
        private static string ScanArtifactEquippedCharacter(Bitmap bm)
        {
            Bitmap n = Scraper.ConvertToGrayscale(bm);

            Scraper.SetContrast(60.0, ref n);

            string equippedCharacter = Scraper.AnalyzeText(n).ToLower();

            n.Dispose();

            if (equippedCharacter != "")
            {
                if (equippedCharacter.Contains(":"))
                {
                    equippedCharacter = Regex.Replace(equippedCharacter.Split(':')[1], @"[\W]", string.Empty);
                    equippedCharacter = Scraper.FindClosestCharacterName(equippedCharacter);

                    return(equippedCharacter);
                }
            }
            // artifact has no equipped character
            return(null);
        }
        private static int ScanExperience()
        {
            int experience = 0;

            int      xOffset          = 1117;
            int      yOffset          = 151;
            Bitmap   bm               = new Bitmap(90, 10);
            Graphics g                = Graphics.FromImage(bm);
            int      screenLocation_X = Navigation.GetPosition().Left + xOffset;
            int      screenLocation_Y = Navigation.GetPosition().Top + yOffset;

            g.CopyFromScreen(screenLocation_X, screenLocation_Y, 0, 0, bm.Size);

            //Image Operations
            bm = Scraper.ResizeImage(bm, bm.Width * 6, bm.Height * 6);
            //Scraper.ConvertToGrayscale(ref bm);
            //Scraper.SetInvert(ref bm);
            Scraper.SetContrast(30.0, ref bm);

            string text = Scraper.AnalyzeText(bm);

            text = text.Trim();
            text = Regex.Replace(text, @"(?![0-9\s/]).", string.Empty);

            if (Regex.IsMatch(text, "/"))
            {
                string[] temp = text.Split('/');
                experience = Convert.ToInt32(temp[0]);
            }
            else
            {
                Debug.Print("Error: Found " + experience + " instead of experience");
                UserInterface.AddError("Found " + experience + " instead of experience");
            }

            return(experience);
        }
Esempio n. 16
0
        private static string ScanArtifactMainStat(Bitmap bm, string gearSlot)
        {
            switch (gearSlot)
            {
            // Flower of Life. Flat HP
            case "flower":
                return(Scraper.Stats["hp"]);

            // Plume of Death. Flat ATK
            case "plume":
                return(Scraper.Stats["atk"]);

            // Otherwise it's either sands, goblet or circlet.
            default:

                Scraper.SetContrast(100.0, ref bm);
                Bitmap n = Scraper.ConvertToGrayscale(bm);
                Scraper.SetThreshold(135, ref n);
                Scraper.SetInvert(ref n);

                // Get Main Stat
                string mainStat = Scraper.AnalyzeText(n).ToLower().Trim();
                n.Dispose();

                // Remove anything not a-z as well as removes spaces/underscores
                mainStat = Regex.Replace(mainStat, @"[\W_0-9]", string.Empty);
                // Replace double characters (ex. aanemodmgbonus). Seemed to be a somewhat common problem.
                mainStat = Regex.Replace(mainStat, "(.)\\1+", "$1");

                if (mainStat == "def" || mainStat == "atk" || mainStat == "hp")
                {
                    mainStat += "%";
                }

                return(Scraper.FindClosestStat(mainStat));
            }
        }
        private static int[] ScanTalents(string name)
        {
            int[] talents = { -1, -1, -1 };

            int specialOffset = 0;

            // Check if character has a movement talent like
            // Mona or Ayaka
            if (name.Contains("Mona") || name.Contains("Ayaka"))
            {
                specialOffset = 1;
            }

            var xRef = 1280.0;
            var yRef = 720.0;

            if (Navigation.GetAspectRatio() == new Size(8, 5))
            {
                yRef = 800.0;
            }

            Rectangle region = new RECT(
                Left:   (int)(160 / xRef * Navigation.GetWidth()),
                Top:    (int)(116 / yRef * Navigation.GetHeight()),
                Right:  (int)(225 / xRef * Navigation.GetWidth()),
                Bottom: (int)(141 / yRef * Navigation.GetHeight()));

            for (int i = 0; i < 3; i++)
            {
                // Change y-offset for talent clicking
                int yOffset = (int)(110 / yRef * Navigation.GetHeight()) + (i + ((i == 2) ? specialOffset : 0)) * (int)(60 / yRef * Navigation.GetHeight());

                Navigation.SetCursorPos(Navigation.GetPosition().Left + (int)(1130 / xRef * Navigation.GetWidth()), Navigation.GetPosition().Top + yOffset);
                Navigation.Click();
                Navigation.Speed speed = i == 0 ? Navigation.Speed.Normal : Navigation.Speed.Fast;
                Navigation.SystemRandomWait(speed);

                while (talents[i] < 1 || talents[i] > 15)
                {
                    Bitmap talentLevel = Navigation.CaptureRegion(region);

                    talentLevel = Scraper.ResizeImage(talentLevel, talentLevel.Width * 2, talentLevel.Height * 2);

                    Bitmap n = Scraper.ConvertToGrayscale(talentLevel);
                    Scraper.SetContrast(60, ref n);
                    Scraper.SetInvert(ref n);

                    string text = Scraper.AnalyzeText(n).Trim();
                    text = Regex.Replace(text, @"\D", string.Empty);

                    if (int.TryParse(text, out int level))
                    {
                        if (level >= 1 && level <= 15)
                        {
                            talents[i] = level;
                            UserInterface.SetCharacter_Talent(talentLevel, text, i);
                        }
                    }

                    n.Dispose();
                    talentLevel.Dispose();
                }
            }

            Navigation.sim.Keyboard.KeyPress(WindowsInput.Native.VirtualKeyCode.ESCAPE);
            return(talents);
        }
        private static void ScanNameAndElement(ref string name, ref string element)
        {
            int       attempts    = 0;
            int       maxAttempts = 75;
            Rectangle region      = new RECT(
                Left:   (int)(85 / 1280.0 * Navigation.GetWidth()),
                Top:    (int)(10 / 720.0 * Navigation.GetHeight()),
                Right:  (int)(305 / 1280.0 * Navigation.GetWidth()),
                Bottom: (int)(55 / 720.0 * Navigation.GetHeight()));

            do
            {
                Navigation.SystemRandomWait(Navigation.Speed.Fast);
                using (Bitmap bm = Navigation.CaptureRegion(region))
                {
                    Bitmap n = Scraper.ConvertToGrayscale(bm);
                    Scraper.SetThreshold(110, ref n);
                    Scraper.SetInvert(ref n);

                    n = Scraper.ResizeImage(n, n.Width * 2, n.Height * 2);
                    string block = Scraper.AnalyzeText(n, Tesseract.PageSegMode.Auto).ToLower().Trim();
                    string line  = Scraper.AnalyzeText(n, Tesseract.PageSegMode.SingleLine).ToLower().Trim();

                    // Characters with wrapped names will not have a slash
                    string nameAndElement = line.Contains("/") ? line : block;

                    if (nameAndElement.Contains("/"))
                    {
                        var split = nameAndElement.Split('/');

                        // Search for element and character name in block

                        // Long name characters might look like
                        // <Element>   <First Name>
                        // /           <Last Name>
                        element = !split[0].Contains(" ") ? Scraper.FindElementByName(split[0].Trim()) : Scraper.FindElementByName(split[0].Split(' ')[0].Trim());

                        // Find character based on string after /
                        // Long name characters might search by their last name only but it'll still work.
                        name = Scraper.FindClosestCharacterName(Regex.Replace(split[1], @"[\W]", string.Empty));
                        if (name == "Traveler")
                        {
                            foreach (var item in from item in Scraper.Characters
                                     where item.Value["GOOD"].ToString() == "Traveler"
                                     select item)
                            {
                                name = item.Key;
                            }
                        }
                    }
                    n.Dispose();

                    if (!string.IsNullOrWhiteSpace(name) && !string.IsNullOrWhiteSpace(element))
                    {
                        UserInterface.SetCharacter_NameAndElement(bm, name, element);
                        return;
                    }
                }
                attempts++;
                Navigation.SystemRandomWait(Navigation.Speed.Normal);
            } while ((string.IsNullOrWhiteSpace(name) || string.IsNullOrEmpty(element)) && (attempts < maxAttempts));
            name    = null;
            element = null;
        }
Esempio n. 19
0
        private static List <SubStat> ScanArtifactSubStats(Bitmap artifactImage, ref string setName)
        {
            Bitmap bm = (Bitmap)artifactImage.Clone();

            Scraper.SetBrightness(-30, ref bm);
            Scraper.SetContrast(85, ref bm);
            var n    = Scraper.ConvertToGrayscale(bm);
            var text = Scraper.AnalyzeText(n, Tesseract.PageSegMode.Auto).ToLower();

            List <string> lines = new List <string>(text.Split('\n'));

            lines.RemoveAll(line => string.IsNullOrWhiteSpace(line));

            var index = lines.FindIndex(line => line.Contains("piece") || line.Contains("set") || line.Contains("2-"));

            if (index >= 0)
            {
                lines.RemoveRange(index, lines.Count - index);
            }

            n.Dispose();
            bm.Dispose();
            SubStat[]             substats = new SubStat[4];
            List <Task <string> > tasks    = new List <Task <string> >();

            for (int i = 0; i < lines.Count; i++)
            {
                int j    = i;
                var task = Task.Factory.StartNew(() =>
                {
                    var line = Regex.Replace(lines[j], @"(?:^[^a-zA-Z]*)", string.Empty).Replace(" ", string.Empty);

                    if (line.Any(char.IsDigit))
                    {
                        SubStat substat = new SubStat();
                        Regex re        = new Regex(@"([\w]+\W*)(\d+.*\d+)");
                        var result      = re.Match(line);
                        var stat        = Regex.Replace(result.Groups[1].Value, @"[^\w]", string.Empty);
                        var value       = result.Groups[2].Value;

                        string name = line.Contains("%") ? stat + "%" : stat;

                        substat.stat = Scraper.FindClosestStat(name) ?? "";

                        // Remove any non digits.
                        value = Regex.Replace(value, @"[^0-9]", string.Empty);

                        var cultureInfo = new CultureInfo("en-US");
                        if (!decimal.TryParse(value, NumberStyles.Number, cultureInfo, out substat.value))
                        {
                            substat.value = -1;
                        }

                        // Need to retain the decimal place for percent boosts
                        if (substat.stat.Contains("_"))
                        {
                            substat.value /= 10;
                        }

                        substats[j] = substat;
                        return(null);
                    }
                    else                     // if (line.Contains(":")) // Sometimes Tesseract wouldn't detect a ':' making this check troublesome
                    {
                        var name = line.Trim().ToLower();

                        name = Regex.Replace(name, @"[^\w]", string.Empty);

                        name = Scraper.FindClosestSetName(name);

                        return(!string.IsNullOrWhiteSpace(name) ? name : null);
                    }
                });
                tasks.Add(task);
            }
            Stopwatch stopwatch = new Stopwatch();

            stopwatch.Start();
            while (tasks.Count > 0 && stopwatch.Elapsed.TotalSeconds < 10)
            {
                for (int i = 0; i < tasks.Count; i++)
                {
                    Task <string> task = tasks[i];
                    if (!task.IsCompleted)
                    {
                        continue;
                    }
                    setName = string.IsNullOrWhiteSpace(setName) ? task.Result : setName;
                    tasks.Remove(task);
                    break;
                }
            }
            return(substats.ToList());
        }