private bool FindUsingAlternateMasks(SearchParams search, ref MatchingPoint match) { Stack<StateBitmapType> typesToCheck = new Stack<StateBitmapType>(); typesToCheck.Push(StateBitmapType.Blue); typesToCheck.Push(StateBitmapType.Mask); #if DEBUG typesToCheck.Clear(); // Only check smartmask in debug #endif typesToCheck.Push(StateBitmapType.SmartMask); while (typesToCheck.Count > 0) { if (StopRequested) return false; StateBitmapType maskType = typesToCheck.Pop(); search.Mask = GetBitmapByType(maskType, search.ToFind.Size, search.ToFind.PixelFormat); if (StopRequested) return false; if (FindExact(search, ref match)) return true; if (search.QuickCheck) return false; // First match didnt work, but asked to be quick if (StopRequested) return false; if (FindHazy(search, ref match)) return true; if (StopRequested) return false; } return false; }
private bool FindExact(SearchParams search, ref MatchingPoint match) { if (search.QuickCheck && search.SearchArea.Size == search.ToFind.Size) { match = game.findBitmapWorker.CheckExactMatch(search.SearchArea, search.ToFind, search.Mask, search.MinimumConfidence); if (!match.Confident) { try { if (game.DebugMode) { //string path = String.Format("{0}-notmatched-{1}-{2}.bmp", Assembly.GetCallingAssembly().Location, this.AssetName, DateTime.Now.ToString("hhmmss")); //search.SearchArea.Save(path); } } catch (Exception) { } } return match.Confident; } return false; }
private bool FindHazy(SearchParams search, ref MatchingPoint match) { match = game.findBitmapWorker.FindInScreen(search.SearchArea, search.ToFind, search.Mask, search.QuickCheck, search.MinimumConfidence); if (match.Confident) game.UpdateGameExtents(match.X, match.Y); return match.Confident; }
public MatchingPoint FindStateFromScreen(bool quickCheck = false) { SearchParams search = new SearchParams(); MatchingPoint match = new MatchingPoint(); search.UsingGameExtents = false; search.MinimumConfidence = this.MinimumConfidence; search.QuickCheck = quickCheck; if (StopRequested) return match; //STEP1: Get image to find and mask(if available) search.ToFind = GetBitmapByType(StateBitmapType.RawImage); if (StopRequested) return match; //STEP2: Get area of screen to search GetSearchAreaBitmap(ref search); if (StopRequested) return match; //STEP3: Do search if (FindUsingAlternateMasks(search, ref match)) return match; return match; }