public MK8DTrack GetTrack(Bitmap img) { string result = string.Empty; string resultConsole = string.Empty; Bitmap trackImg = img.extractRegion(410, 630, 515, 60); Bitmap consoleImg = img.extractRegion(320, 630, 105, 60); using (var page = engine.Process(trackImg, PageSegMode.Auto)) { result = page.GetText().Replace("\n", "").Replace("\r", "").Trim(); MeanConfidencesTrack.Add(page.GetMeanConfidence()); if (result.Contains("Maria")) { result = result.Replace("Maria", "Mario"); } if (result.Contains("YOshi")) { result = result.Replace("YOshi", "Yoshi"); } if (result.Contains("lnstrumental")) { result = result.Replace("lnstrumental", "Instrumental"); } if (result.Contains("l3")) { result = result.Replace("l3", "ß"); } if (result.Contains("GroB")) { result = result.Replace("GroB", "Groß"); } } using (var page = consoleEngine.Process(consoleImg, PageSegMode.Auto)) { resultConsole = page.GetText().Replace("\n", "").Replace("\r", "").Trim(); MeanConfidencesConsole.Add(page.GetMeanConfidence()); if (resultConsole == "SDS") { resultConsole = resultConsole = "3DS"; } } var tracks = MK8DTrack.GetAllTracks(); var selection = tracks.Where(p => p.GetName("deu").ToLower() == result.ToLower()).ToList(); if (selection.Count() == 1) { return(selection[0]); } else if (selection.Count() > 1) { GameObjects.Console console = GameObjects.Console.Switch; switch (resultConsole) { case "SNES": console = GameObjects.Console.SNES; break; case "N64": console = GameObjects.Console.N64; break; case "GBA": console = GameObjects.Console.GBA; break; case "GCN": console = GameObjects.Console.GCN; break; case "DS": console = GameObjects.Console.DS; break; case "Wii": console = GameObjects.Console.Wii; break; case "3DS": console = GameObjects.Console._3DS; break; } var selectConsole = selection.Where(p => p.Console == console).ToList(); return(selectConsole[0]); } else { return(null); } }
public override void Execute() { if (isActivated && !isPaused && !isWorking && DateTime.Now >= timeoutEnd) { System.Diagnostics.Stopwatch watch = System.Diagnostics.Stopwatch.StartNew(); isWorking = true; Bitmap img = ((Bitmap)this.currentFrame.Clone()).Resize(1280, 720); // Check, if current frame is track-screen if ((bool)Config["UseTrackTableBot"].Value && trackRecognition.IsTrack(img)) { mainWindow.AddLog(Client.LogType.Success, "current Frame is a Track-image!"); MK8DTrack track = trackRecognition.GetTrack(img); if (track != null && channelId != ulong.MinValue) { mainWindow.AddLog(Client.LogType.Success, $"Selected track is {track.NameENG} ({track.GetAbbreviation()})"); //userBot.SendMessage(channelId, $"_addtrack {track.GetAbbreviation()}"); userBot.SendMessage(channelId, $"_tt {track.GetAbbreviation()}"); timeoutEnd = DateTime.Now.AddSeconds(15); } watch.Stop(); mainWindow.AddLog(Client.LogType.Info, $"Execution took {watch.ElapsedMilliseconds}ms"); } else if (screenshotRecognition.IsScreenshot(img)) { mainWindow.AddLog(Client.LogType.Success, "Screenshot detected."); CachedBitmap[] tagImages = img.ExtractPlayerTags(); Dictionary <int, string> tags = new Dictionary <int, string>(); int clanCount = 0; for (int i = 0; i < 12; i++) { tags.Add((i + 1), recognitionEngine.RecognizePlayer(tagImages[i])); //foreach (string tag in ((string)Config["ClanTag"].Value).Split('|')) //{ if (tags[i + 1].Contains((string)Config["ClanTag"].Value)) { clanCount++; //break; } //} } if (clanCount == 6) { timeoutEnd = DateTime.Now.AddSeconds(7); string output = "_race "; for (int i = 1; i <= 12; i++) { //foreach (string tag in ((string)Config["ClanTag"].Value).Split('|')) //{ if (tags[i].Contains((string)Config["ClanTag"].Value)) { output += i + " "; //break; } //} } userBot.SendMessage(channelId, output); mainWindow.AddLog(Client.LogType.Success, $"Command \"{output}\" sent."); } else { mainWindow.AddLog(Client.LogType.Warning, $"Recognition of players failed! Manual input required..."); userBot.SendMessage(channelId, "Couldn´t read player-tags! Please type the race-command manually..."); } watch.Stop(); mainWindow.AddLog(Client.LogType.Info, $"Execution took {watch.ElapsedMilliseconds}ms"); } } isWorking = false; }