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); }
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); }
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); }
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 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); }
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); }
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; }