protected bool HasMatchingSamples(FastBitmapHSV bitmap, Point[] points, int offsetX, int offsetY, FastPixelMatch match, string debugName) { if (DebugLevel == EDebugLevel.Verbose) { string desc = ""; for (int idx = 0; idx < points.Length; idx++) { if (idx > 0) { desc += ", "; } var testPx = bitmap.GetPixel(points[idx].X + offsetX, points[idx].Y + offsetY); var matching = match.IsMatching(testPx); desc += "(" + testPx + "):" + matching; } Console.WriteLine("HasMatchingSamples: {2}> filter({0}) vs {1}", match, desc, debugName); } for (int idx = 0; idx < points.Length; idx++) { FastPixelHSV testPx = bitmap.GetPixel(points[idx].X + offsetX, points[idx].Y + offsetY); bool isMatch = match.IsMatching(testPx); if (!isMatch) { return(false); } } return(true); }
protected bool HasChatBoxArea(FastBitmapHSV bitmap) { var hasMatch = matchChatBoxInner.IsMatching(bitmap.GetPixel(posChatBoxInner[0].X, posChatBoxInner[0].Y)) && matchChatBoxInner.IsMatching(bitmap.GetPixel(posChatBoxInner[1].X, posChatBoxInner[1].Y)) && matchChatBoxInner.IsMatching(bitmap.GetPixel(posChatBoxInner[2].X, posChatBoxInner[2].Y)) && matchChatBoxInner.IsMatching(bitmap.GetPixel(posChatBoxInner[3].X, posChatBoxInner[3].Y)) && matchChatBoxOuter.IsMatching(bitmap.GetPixel(posChatBoxOuter[0].X, posChatBoxOuter[0].Y)) && matchChatBoxOuter.IsMatching(bitmap.GetPixel(posChatBoxOuter[1].X, posChatBoxOuter[1].Y)) && matchChatBoxOuter.IsMatching(bitmap.GetPixel(posChatBoxOuter[2].X, posChatBoxOuter[2].Y)) && matchChatBoxOuter.IsMatching(bitmap.GetPixel(posChatBoxOuter[3].X, posChatBoxOuter[3].Y)); if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} HasChatBoxArea: {1}", ScannerName, hasMatch); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(" outer samples: {0}, {1}, {2}, {3} => filter({4})", bitmap.GetPixel(posChatBoxOuter[0].X, posChatBoxOuter[0].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxOuter[1].X, posChatBoxOuter[1].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxOuter[2].X, posChatBoxOuter[2].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxOuter[3].X, posChatBoxOuter[3].Y).GetMonochrome(), matchChatBoxOuter); Console.WriteLine(" inner samples: {0}, {1}, {2}, {3} => filter({4})", bitmap.GetPixel(posChatBoxInner[0].X, posChatBoxInner[0].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxInner[1].X, posChatBoxInner[1].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxInner[2].X, posChatBoxInner[2].Y).GetMonochrome(), bitmap.GetPixel(posChatBoxInner[3].X, posChatBoxInner[3].Y).GetMonochrome(), matchChatBoxInner); } return(hasMatch); }
protected void ScanSP(FastBitmapHSV bitmap, ScreenDataBase screenData) { int numMatchFull = 0; int numMatchEmpty = 0; int numChanges = 0; bool wasFull = false; bool wasEmpty = false; int lastPosFull = 0; for (int idx = 0; idx <= rectSPBar.Width; idx++) { var testPx = bitmap.GetPixel(rectSPBar.X + idx, rectSPBar.Y); var isFull = matchSPFull.IsMatching(testPx); var isEmpty = matchSPEmpty.IsMatching(testPx); if (isFull) { lastPosFull = idx; } numChanges += (idx > 0 && isFull != wasFull) ? 1 : 0; numChanges += (idx > 0 && isEmpty != wasEmpty) ? 1 : 0; numMatchFull += isFull ? 1 : 0; numMatchEmpty += isEmpty ? 1 : 0; wasFull = isFull; wasEmpty = isEmpty; } float matchedPct = (numMatchEmpty + numMatchFull) / (float)rectSPBar.Width; screenData.SPIsValid = (matchedPct > 0.75); screenData.SPFillPct = lastPosFull / (float)rectSPBar.Width; screenData.SPIsObstructed = (matchedPct < 0.95); if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} HasSP: {1}, isObstructed:{2}, fillPct:{3}", ScannerName, screenData.SPIsValid, screenData.SPIsObstructed, screenData.SPFillPct); } if (DebugLevel >= EDebugLevel.Verbose) { for (int idx = 0; idx < rectSPBar.Width; idx++) { var testPx = bitmap.GetPixel(rectSPBar.X + idx, rectSPBar.Y); Console.WriteLine(" X:{0},Y:{1} = {2} => Full:{3}, Empty:{4}", rectSPBar.X + idx, rectSPBar.Y, testPx, matchSPFull.IsMatching(testPx), matchSPEmpty.IsMatching(testPx)); } Console.WriteLine(" filterFull({0}), filterEmpty({1})", matchSPFull, matchSPEmpty); Console.WriteLine(" numMatchFull: {0}, numMatchEmpty: {1}, matchedPct: {2}, numChanges:{3}", numMatchFull, numMatchEmpty, matchedPct, numChanges); } }
protected bool HasOpenedChatLine(FastBitmapHSV bitmap, out int mode) { mode = 0; for (int posX = 0; posX < bitmap.Width; posX++) { var testPx = bitmap.GetPixel(posX, posChatBackY); bool isMatching = matchChatLineBack.IsMatching(testPx); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasOpenedChatLine: failed match! ({1},{2})=({3}) vs filter({4})", ScannerName, posX, posChatBackY, testPx, matchChatLineBack); } return(false); } testPx = bitmap.GetPixel(posX, posNoChatBackY); isMatching = matchChatLineBack.IsMatching(testPx); if (isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasOpenedChatLine: failed no match! ({1},{2})=({3}) vs filter({4})", ScannerName, posX, posNoChatBackY, testPx, matchChatLineBack); } return(false); } } for (int testMode = 1; testMode < posChatLineModeY.Length; testMode++) { var avgPx = ScreenshotUtilities.GetAverageColor(bitmap, new Rectangle(rectChatLine.X, posChatLineModeY[testMode], rectChatLine.Width, rectChatLine.Height)); bool isMatching = matchChatLine.IsMatching(avgPx) && !matchChatLineBack.IsMatching(avgPx); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasOpenedChatLine: failed mode:{1}... ({2}) vs filter({3})", ScannerName, testMode, avgPx, matchChatLine); } } else { mode = testMode; return(true); } } return(false); }
protected void ScanPauseButton(FastBitmapHSV bitmap, ScreenData screenData) { var testPx1 = bitmap.GetPixel(posPauseI[0].X, posPauseI[0].Y); var testPx2 = bitmap.GetPixel(posPauseI[1].X, posPauseI[1].Y); screenData.isActive = matchPause.IsMatching(testPx1) && matchPause.IsMatching(testPx2); if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanPauseButton: active:{1}", ScannerName, screenData.isActive); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(">> px1:({0}), px2:({1}) vs ({2})", testPx1, testPx2, matchPause); } }
public static bool TraceLine(FastBitmapHSV bitmap, int posX, int posY, int incX, int incY, int traceLen, FastPixelMatch colorMatch, out Point posHit, bool bDebugMode = false) { if (bDebugMode) { Console.WriteLine("TraceLine [" + posX + ", " + posY + "] -> [" + (posX + (incX * traceLen)) + ", " + (posY + (incY * traceLen)) + "]"); } for (int stepIdx = 0; stepIdx < traceLen; stepIdx++) { int scanX = posX + (stepIdx * incX); int scanY = posY + (stepIdx * incY); FastPixelHSV testPx = bitmap.GetPixel(scanX, scanY); bool bIsMatching = colorMatch.IsMatching(testPx); if (bDebugMode) { Console.WriteLine(" [" + scanX + ", " + scanY + "] " + testPx + " => match:" + bIsMatching); } if (bIsMatching) { posHit = new Point(scanX, scanY); return(true); } } if (bDebugMode) { Console.WriteLine(" >> failed"); } posHit = new Point(posX + (traceLen * incX), posY + (traceLen * incY)); return(false); }
private void ScanSpecialAction(FastBitmapHSV bitmap, ScreenData screenData) { FastPixelHSV[] samples = FindSpecialActionButton(bitmap); if (samples != null) { for (int idx = 0; idx < samples.Length; idx++) { bool hasMatch = matchSpecialReload.IsMatching(samples[idx]); if (hasMatch) { screenData.specialAction = ESpecialAction.Reload; break; } } } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanSpecialAction: {1}", ScannerName, screenData.specialAction); } if (DebugLevel >= EDebugLevel.Verbose) { if (samples != null) { for (int idx = 0; idx < samples.Length; idx++) { Console.WriteLine(">> bigButton[{0}]: {1}", idx, samples[idx]); } } } }
public static List <Point> TraceSpansH(FastBitmapHSV bitmap, Rectangle box, FastPixelMatch colorMatch, int minSize, bool bDebugMode = false) { List <Point> result = new List <Point>(); int lastX = -1; bool bHasMatch = false; for (int IdxX = box.Left; IdxX <= box.Right; IdxX++) { bHasMatch = false; for (int IdxY = box.Top; IdxY <= box.Bottom; IdxY++) { FastPixelHSV testPx = bitmap.GetPixel(IdxX, IdxY); bHasMatch = colorMatch.IsMatching(testPx); if (bHasMatch) { if (bDebugMode) { Console.WriteLine("[" + IdxX + ", " + IdxY + "] " + testPx + " => match!"); } break; } } if (lastX == -1 && bHasMatch) { lastX = IdxX; } else if (lastX >= 0 && !bHasMatch) { int spanSize = IdxX - lastX; if (spanSize > minSize) { if (bDebugMode) { Console.WriteLine(">> adding span: " + lastX + ", size:" + spanSize); } result.Add(new Point(lastX, spanSize)); } lastX = -1; } } if (lastX >= 0 && bHasMatch) { int spanSize = box.Right - lastX + 1; if (spanSize > minSize) { if (bDebugMode) { Console.WriteLine(">> adding span: " + lastX + ", size:" + spanSize); } result.Add(new Point(lastX, spanSize)); } } return(result); }
private void ScanBurstPosition(FastBitmapHSV bitmap, ScreenData screenData) { bool hasMarker = false; for (int idxY = 0; idxY < rectBurstArea.Height; idxY++) { for (int idxX = 0; idxX < rectBurstArea.Width; idxX++) { FastPixelHSV testPx = bitmap.GetPixel(rectBurstArea.X + idxX, rectBurstArea.Y + idxY); bool isMatch = matchBurstMarker.IsMatching(testPx); if (isMatch) { hasMarker = HasBurstMarker(bitmap, rectBurstArea.X + idxX, rectBurstArea.Y + idxY); if (hasMarker) { screenData.BurstState = EBurstState.Ready; screenData.BurstMarkerPctX = idxX * 1.0f / rectBurstArea.Width; screenData.BurstMarkerPctY = idxY * 1.0f / rectBurstArea.Height; cachedBurstPos = new Point(rectBurstArea.X + idxX, rectBurstArea.Y + idxY); DrawRectangle(bitmap, rectBurstArea.X + idxX - 15, rectBurstArea.Y + idxY - 15, 30, 30, 255); break; } } } if (hasMarker) { break; } } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanBurstPosition: {1}", ScannerName, screenData.BurstState); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(">> marker.X:{0:P2}, marker.Y:{1:P2}", screenData.BurstMarkerPctX, screenData.BurstMarkerPctY); } }
protected void ScanActionSlot(FastBitmapHSV bitmap, Rectangle bounds, ActionData actionData, int slotIdx) { for (int idxY = 0; idxY < rectActionAvail.Height; idxY++) { for (int idxX = 0; idxX < rectActionAvail.Width; idxX++) { FastPixelHSV testPx = bitmap.GetPixel(bounds.X + rectActionAvail.X + idxX, bounds.Y + rectActionAvail.Y + idxY); bool match = matchActionAvail.IsMatching(testPx); if (match) { actionData.isValid = true; break; } } } if (actionData.isValid) { float[] pixelInput = ExtractActionSlotWeaponData(bitmap, slotIdx); actionData.weaponClass = (EWeaponType)classifierWeapon.Calculate(pixelInput, out float dummyPct); actionData.element = ScanElementType(bitmap, bounds); actionData.hasBoost = HasElemBoost(bitmap, slotIdx); } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} Action[{1}]: valid:{2}, class:{3}, elem: {4}", ScannerName, slotIdx, actionData.isValid, actionData.weaponClass, actionData.element); } if (DebugLevel >= EDebugLevel.Verbose) { var minMono = 255; var maxMono = 0; for (int idxY = 0; idxY < rectActionAvail.Height; idxY++) { for (int idxX = 0; idxX < rectActionAvail.Width; idxX++) { FastPixelHSV testPx = bitmap.GetPixel(bounds.X + rectActionAvail.X + idxX, bounds.Y + rectActionAvail.Y + idxY); minMono = Math.Min(minMono, testPx.GetMonochrome()); maxMono = Math.Max(maxMono, testPx.GetMonochrome()); } } Console.WriteLine(">> avail M:{0}..{1} (x:{2},y:{3},w:{4},h:{5})", minMono, maxMono, bounds.X + rectActionAvail.X, bounds.Y + rectActionAvail.Y, rectActionAvail.Width, rectActionAvail.Height); } }
protected bool HasLifeforceMeter(FastBitmapHSV bitmap) { int numMatching = 0; int numChanges = 0; bool wasMatchingR = false; bool wasMatchingG = false; for (int idx = 0; idx < posLifeforceMeter.Length; idx++) { var testPx = bitmap.GetPixel(posLifeforceMeter[idx].X, posLifeforceMeter[idx].Y); var isMatchingR = matchLifeforceR.IsMatching(testPx); var isMatchingG = isMatchingR ? false : matchLifeforceG.IsMatching(testPx); numChanges += (idx > 0 && isMatchingR != wasMatchingR) ? 1 : 0; numChanges += (idx > 0 && isMatchingG != wasMatchingG) ? 1 : 0; numMatching += (isMatchingR || isMatchingG) ? 1 : 0; wasMatchingR = isMatchingR; wasMatchingG = isMatchingG; } bool hasMatch = (numMatching >= 5) && (numChanges < 4); if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} HasLifeforceMeter: {1}", ScannerName, hasMatch); } if (DebugLevel >= EDebugLevel.Verbose) { string debugDesc = " "; for (int idx = 0; idx < posLifeforceMeter.Length; idx++) { var testPx = bitmap.GetPixel(posLifeforceMeter[idx].X, posLifeforceMeter[idx].Y); if (idx > 0) { debugDesc += ", "; } debugDesc += "(" + testPx + ")"; } Console.WriteLine(debugDesc); Console.WriteLine(" filterGreen({0}), filterRed({1})", matchLifeforceG, matchLifeforceR); Console.WriteLine(" numMatching: {0}, numChanges: {1}", numMatching, numChanges); } return(hasMatch); }
public static float CountFillPct(FastBitmapHSV bitmap, Rectangle box, FastPixelMatch colorMatch) { int totalPixels = (box.Width + 1) * (box.Height + 1); int matchPixels = 0; for (int IdxY = box.Top; IdxY <= box.Bottom; IdxY++) { for (int IdxX = box.Left; IdxX <= box.Right; IdxX++) { FastPixelHSV testPx = bitmap.GetPixel(IdxX, IdxY); matchPixels += colorMatch.IsMatching(testPx) ? 1 : 0; } } return((float)matchPixels / totalPixels); }
private void ScanSpecialAction(FastBitmapHSV bitmap, ScreenData screenData) { FastPixelHSV[] samples = FindSpecialActionButton(bitmap); int numReload = 0; int numRevive = 0; int numShip = 0; if (samples != null) { for (int idx = 0; idx < samples.Length; idx++) { numReload += matchSpecialReload.IsMatching(samples[idx]) ? 1 : 0; numRevive += matchSpecialRevive.IsMatching(samples[idx]) ? 1 : 0; numShip += matchSpecialShip.IsMatching(samples[idx]) ? 1 : 0; } screenData.specialAction = (numReload > numRevive && numReload > numShip) ? ESpecialAction.Reload : (numRevive > numReload && numRevive > numShip) ? ESpecialAction.Revive : (numShip > numRevive && numShip > numReload) ? ESpecialAction.AttackShip : ESpecialAction.None; } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} Special: {1}", ScannerName, screenData.specialAction); } if (DebugLevel >= EDebugLevel.Verbose) { if (samples != null) { for (int idx = 0; idx < samples.Length; idx++) { Console.WriteLine(">> bigButton[{0}]: {1}", idx, samples[idx]); } } Console.WriteLine(">> numReload:{0} ({1}), numRevive:{2} ({3}), numShip:{4} ({5})", numReload, matchSpecialReload, numRevive, matchSpecialRevive, numShip, matchSpecialShip); } }
protected void ScanSummonSelector(FastBitmapHSV bitmap, ScreenDataBase screenData) { var avgPx = ScreenshotUtilities.GetAverageColor(bitmap, rectSummonSelectorA); var iconFillPct = ScreenshotUtilities.CountFillPct(bitmap, rectSummonSelectorB, matchSummonIcon); var isAvgMatching = matchSummonBack.IsMatching(avgPx); var isIconMatching = (iconFillPct > 0.10f) && (iconFillPct < 0.35f); screenData.hasSummonSelection = isAvgMatching && isIconMatching; if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanSummonSelector: {1}", ScannerName, screenData.hasSummonSelection); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(" avgPx: ({0}) vs ({1}) => {2}, fillIcon: {3} => {4}", avgPx, matchSummonBack, isAvgMatching, iconFillPct, isIconMatching); } }
public static List <int> TraceLineSegments(FastBitmapHSV bitmap, int posX, int posY, int incX, int incY, int traceLen, FastPixelMatch colorMatch, int minSegSize, int segLimit, bool bDebugMode = false) { FastPixelHSV[] streakBuffer = new FastPixelHSV[minSegSize]; int bufferIdx = 0; for (int Idx = 0; Idx < streakBuffer.Length; Idx++) { streakBuffer[Idx] = new FastPixelHSV(255, 255, 255); } List <int> result = new List <int>(); bool bWasMatch = false; if (bDebugMode) { Console.WriteLine("TraceLineSegments [" + posX + ", " + posY + "] -> [" + (posX + (incX * traceLen)) + ", " + (posY + (incY * traceLen)) + "]"); } for (int stepIdx = 0; stepIdx < traceLen; stepIdx++) { int scanX = posX + (stepIdx * incX); int scanY = posY + (stepIdx * incY); FastPixelHSV testPx = bitmap.GetPixel(scanX, scanY); streakBuffer[bufferIdx] = testPx; bufferIdx = (bufferIdx + 1) % minSegSize; bool bBufferMatching = true; for (int Idx = 0; Idx < streakBuffer.Length; Idx++) { bBufferMatching = bBufferMatching && colorMatch.IsMatching(streakBuffer[Idx]); } if (bDebugMode) { Console.WriteLine(" [" + scanX + ", " + scanY + "] " + testPx + " => match:" + colorMatch.IsMatching(testPx) + ", buffer:" + bBufferMatching); } if (bBufferMatching != bWasMatch) { bWasMatch = bBufferMatching; int segPos = bBufferMatching ? (incX != 0) ? (scanX - (incX * minSegSize)) : (scanY - (incY * minSegSize)) : (incX != 0) ? scanX : scanY; result.Add(segPos); if (bDebugMode) { Console.WriteLine(" >> mark segment:" + segPos); } if (result.Count >= segLimit && segLimit > 0) { break; } } } return(result); }
protected bool HasLogoMarkers(FastBitmapHSV bitmap) { foreach (var pos in posLogoWhite) { var isMatching = matchLogoWhite.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasLogoMarkers: failed WHITE => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoWhite); } return(false); } } foreach (var pos in posLogoBlack) { var isMatching = matchLogoBlack.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasLogoMarkers: failed BLACK => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoBlack); } return(false); } } foreach (var pos in posLogoBlue) { var isMatching = matchLogoBlue.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasLogoMarkers: failed BLUE => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoBlue); } return(false); } } foreach (var pos in posLogoRed) { var isMatching = matchLogoRed.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasLogoMarkers: failed RED => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLogoRed); } return(false); } } return(true); }
protected bool HasOkButtonArea(FastBitmapHSV bitmap, ScreenData screenData) { FastPixelHSV[] avgPx = new FastPixelHSV[rectButtonPos.Length]; for (int idx = 1; idx < avgPx.Length; idx++) { avgPx[idx] = ScreenshotUtilities.GetAverageColor(bitmap, rectButtonPos[idx]); var scanOb = new ActionData(); scanOb.buttonColor = matchAvgRed.IsMatching(avgPx[idx]) ? EButtonColor.Red : matchAvgWhite.IsMatching(avgPx[idx]) ? EButtonColor.White : matchAvgSpec.IsMatching(avgPx[idx]) ? EButtonColor.Spec : EButtonColor.Unknown; if (scanOb.buttonColor != EButtonColor.Unknown) { float[] values = ExtractButtonData(bitmap, idx); scanOb.buttonType = (EButtonType)classifierButtons.Calculate(values, out float DummyPct); switch (scanOb.buttonColor) { case EButtonColor.Red: scanOb.isDisabled = avgPx[idx].GetValue() < 40; break; case EButtonColor.White: scanOb.isDisabled = avgPx[idx].GetValue() < 70; break; default: break; } } screenData.actions[idx] = scanOb; } if (screenData.actions[(int)EButtonPos.CombatReportOk].buttonColor == EButtonColor.Red && screenData.actions[(int)EButtonPos.CombatReportOk].buttonType == EButtonType.Ok && screenData.actions[(int)EButtonPos.CombatReportRetry].buttonColor == EButtonColor.White && (screenData.actions[(int)EButtonPos.CombatReportRetry].buttonType == EButtonType.Retry || screenData.actions[(int)EButtonPos.CombatReportRetry].buttonType == EButtonType.Next)) { screenData.mode = EMessageType.CombatReport; } else if (screenData.actions[(int)EButtonPos.CombatStart].buttonColor == EButtonColor.Red && screenData.actions[(int)EButtonPos.CombatStart].buttonType == EButtonType.Start && screenData.actions[(int)EButtonPos.CombatDetails].buttonColor == EButtonColor.Spec && (screenData.actions[(int)EButtonPos.CombatDetails].buttonType == EButtonType.Details)) { screenData.mode = EMessageType.CombatStart; } else if (screenData.actions[(int)EButtonPos.Center].buttonColor == EButtonColor.Red && screenData.actions[(int)EButtonPos.Center].buttonType == EButtonType.Ok) { screenData.mode = EMessageType.Ok; } else if (screenData.actions[(int)EButtonPos.CenterTwoLeft].buttonColor == EButtonColor.White && screenData.actions[(int)EButtonPos.CenterTwoLeft].buttonType == EButtonType.Cancel && screenData.actions[(int)EButtonPos.CenterTwoRight].buttonColor == EButtonColor.Red && screenData.actions[(int)EButtonPos.CenterTwoRight].buttonType == EButtonType.Ok) { screenData.mode = EMessageType.OkCancel; } else if (screenData.actions[(int)EButtonPos.Center].buttonColor == EButtonColor.White && screenData.actions[(int)EButtonPos.Center].buttonType == EButtonType.Close) { screenData.mode = EMessageType.Close; } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} Mode: {1}", ScannerName, screenData.mode); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(" filterRed:({0}), filterWhite:({1}), filterSpec({2})", matchAvgRed, matchAvgWhite, matchAvgSpec); for (int idx = 1; idx < avgPx.Length; idx++) { Console.WriteLine(" [{0}]:({1}), color:{2}, class:{3}", (EButtonPos)idx, avgPx[idx], screenData.actions[idx].buttonColor, screenData.actions[idx].buttonType); } } return(screenData.mode != EMessageType.Unknown); }
public static Point TraceBoundsH(FastBitmapHSV bitmap, Rectangle box, FastPixelMatch colorMatch, int maxGapSize, bool bDebugMode = false) { int boxCenter = (box.Right + box.Left) / 2; int minX = -1; int gapStart = -1; bool bPrevMatch = false; for (int IdxX = box.Left; IdxX < boxCenter; IdxX++) { bool bHasMatch = false; for (int IdxY = box.Top; IdxY <= box.Bottom; IdxY++) { FastPixelHSV testPx = bitmap.GetPixel(IdxX, IdxY); bHasMatch = colorMatch.IsMatching(testPx); if (bHasMatch) { if (bDebugMode) { Console.WriteLine("[" + IdxX + ", " + IdxY + "] " + testPx + " => match!"); } break; } } if (bHasMatch) { int gapSize = IdxX - gapStart; if ((gapSize > maxGapSize && gapStart > 0) || (minX < 0)) { minX = IdxX; gapStart = -1; } if (bDebugMode) { Console.WriteLine(">> gapSize:" + gapSize + ", gapStart:" + gapStart + ", bPrevMatch:" + bPrevMatch + " => minX:" + minX); } } else { if (bPrevMatch) { gapStart = IdxX; if (bDebugMode) { Console.WriteLine(">> gapStart:" + gapStart); } } } bPrevMatch = bHasMatch; } if (minX >= 0) { int maxX = -1; gapStart = -1; bPrevMatch = false; for (int IdxX = box.Right; IdxX > boxCenter; IdxX--) { bool bHasMatch = false; for (int IdxY = box.Top; IdxY <= box.Bottom; IdxY++) { FastPixelHSV testPx = bitmap.GetPixel(IdxX, IdxY); bHasMatch = colorMatch.IsMatching(testPx); if (bHasMatch) { if (bDebugMode) { Console.WriteLine("[" + IdxX + ", " + IdxY + "] " + testPx + " => match!"); } break; } } if (bHasMatch) { int gapSize = gapStart - IdxX; if ((gapSize > maxGapSize && gapStart > 0) || (maxX < 0)) { maxX = IdxX; gapStart = -1; } if (bDebugMode) { Console.WriteLine(">> gapSize:" + gapSize + ", gapStart:" + gapStart + ", bPrevMatch:" + bPrevMatch + " => maxX:" + maxX); } } else { if (bPrevMatch) { gapStart = IdxX; if (bDebugMode) { Console.WriteLine(">> gapStart:" + gapStart); } } } bPrevMatch = bHasMatch; } if (maxX > minX) { return(new Point(minX, maxX - minX)); } else { if (bDebugMode) { Console.WriteLine(">> TraceBoundsH: no match on right side!"); } } } else { if (bDebugMode) { Console.WriteLine(">> TraceBoundsH: no match on left side!"); } } return(new Point()); }
protected bool HasElemBoostMarker(FastBitmapHSV bitmap, int posX, int posY, int slotIdx) { // samplesIn: hue: 20 +- 30, higher Y = lower hue, first 3 (center column) can be a super bright wildcard // samplesOut: similar hue, low V (dark) FastPixelHSV[] samplesIn = new FastPixelHSV[posBoostIn.Length]; int numHueDec = 0; int numWildCards = 0; int numMatching = 0; for (int idx = 0; idx < samplesIn.Length; idx++) { samplesIn[idx] = bitmap.GetPixel(posX + posBoostIn[idx].X, posY + posBoostIn[idx].Y); bool isMatching = matchBoostIn.IsMatching(samplesIn[idx]); numMatching += isMatching ? 1 : 0; if ((idx > 0) && (posBoostIn[idx - 1].Y < posBoostIn[idx].Y)) { numHueDec += (samplesIn[idx - 1].GetHue() >= samplesIn[idx].GetHue()) ? 1 : 0; } if (idx < 3 && !isMatching) { numWildCards += matchBoostInW.IsMatching(samplesIn[idx]) ? 1 : 0; } } bool matchIn = ((numMatching + numWildCards) == samplesIn.Length) && (numHueDec == 3) && (numWildCards < 2); FastPixelHSV[] samplesOut = new FastPixelHSV[posBoostOut.Length]; bool matchOut = true; for (int idx = 0; idx < samplesOut.Length; idx++) { samplesOut[idx] = bitmap.GetPixel(posX + posBoostOut[idx].X, posY + posBoostOut[idx].Y); matchOut = matchOut && matchBoostOut.IsMatching(samplesOut[idx]); } var showLogs = //(slotIdx == 2) && (posY == 501); //((slotIdx == 1) || (slotIdx == 3)) && (matchIn && matchOut); false; if (DebugLevel >= EDebugLevel.Verbose && showLogs) { Console.WriteLine("HasElemBoostMarker[{0}], Y:{1}, In.HueDec:{2}, matchIn:{3}, matchOut:{4} => {5}", slotIdx, posY, numHueDec, matchIn, matchOut, matchIn && matchOut); string desc = ""; for (int idx = 0; idx < samplesIn.Length; idx++) { if (idx > 0) { desc += ", "; } desc += string.Format("({0},{1} = {2}):{3}", posX + posBoostIn[idx].X, posY + posBoostIn[idx].Y, samplesIn[idx], matchBoostIn.IsMatching(samplesIn[idx]) ? "Yes" : matchBoostInW.IsMatching(samplesIn[idx]) ? "Maybe" : "No"); } Console.WriteLine(" IN({0}): {1}", matchBoostIn, desc); desc = ""; for (int idx = 0; idx < samplesOut.Length; idx++) { if (idx > 0) { desc += ", "; } desc += string.Format("({0},{1} = {2}):{3}", posX + posBoostOut[idx].X, posY + posBoostOut[idx].Y, samplesOut[idx], matchBoostOut.IsMatching(samplesOut[idx])); } Console.WriteLine(" OUT({0}): {1}", matchBoostOut, desc); } return(matchIn && matchOut); }
public static bool CreateFloodFillBitmap(FastBitmapHSV srcBitmap, Point floodOrigin, Size floodExtent, FastPixelMatch colorMatch, out FastBitmapHSV floodBitmap, out Rectangle floodBounds, bool bDebugMode = false) { List <Point> floodPoints = new List <Point>(); int minX = floodOrigin.X; int maxX = floodOrigin.X; int minY = floodOrigin.Y; int maxY = floodOrigin.Y; Rectangle boundRect = new Rectangle(floodOrigin.X - floodExtent.Width, floodOrigin.Y - floodExtent.Height, floodExtent.Width * 2, floodExtent.Height * 2); Stack <Point> openList = new Stack <Point>(); openList.Push(floodOrigin); while (openList.Count > 0) { Point testPoint = openList.Pop(); if (floodPoints.Contains(testPoint)) { continue; } FastPixelHSV testPx = srcBitmap.GetPixel(testPoint.X, testPoint.Y); if (bDebugMode) { Console.WriteLine("[" + testPoint.X + ", " + testPoint.Y + "] " + testPx + ", match:" + colorMatch.IsMatching(testPx) + ", inBounds:" + boundRect.Contains(testPoint)); } if (colorMatch.IsMatching(testPx) && boundRect.Contains(testPoint)) { floodPoints.Add(testPoint); minX = Math.Min(minX, testPoint.X); maxX = Math.Max(maxX, testPoint.X); minY = Math.Min(minY, testPoint.Y); maxY = Math.Max(maxY, testPoint.Y); openList.Push(new Point(testPoint.X - 1, testPoint.Y)); openList.Push(new Point(testPoint.X + 1, testPoint.Y)); openList.Push(new Point(testPoint.X, testPoint.Y - 1)); openList.Push(new Point(testPoint.X, testPoint.Y + 1)); openList.Push(new Point(testPoint.X - 1, testPoint.Y - 1)); openList.Push(new Point(testPoint.X + 1, testPoint.Y - 1)); openList.Push(new Point(testPoint.X - 1, testPoint.Y + 1)); openList.Push(new Point(testPoint.X + 1, testPoint.Y + 1)); } } floodBounds = new Rectangle(minX, minY, maxX - minX + 1, maxY - minY + 1); if (floodPoints.Count > 0) { floodBitmap = new FastBitmapHSV(floodBounds.Width, floodBounds.Height); int numPx = floodBounds.Width * floodBounds.Height; for (int Idx = 0; Idx < numPx; Idx++) { floodBitmap.SetPixel(Idx, new FastPixelHSV(false)); } foreach (Point p in floodPoints) { int Idx = (p.X - minX) + ((p.Y - minY) * floodBounds.Width); floodBitmap.SetPixel(Idx, new FastPixelHSV(true)); } } else { floodBitmap = null; } return(floodBitmap != null); }
protected bool HasTimerMarkers(FastBitmapHSV bitmap) { foreach (var pos in posLabelI) { var isMatching = matchLabelI.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasTimerMarkers: failed LabelI => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLabelI); } return(false); } } foreach (var pos in posLabelO) { var isMatching = matchLabelO.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasTimerMarkers: failed LabelO => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchLabelO); } return(false); } } foreach (var pos in posTimeI) { var isMatching = matchTimerI.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasTimerMarkers: failed TimerI => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchTimerI); } return(false); } } foreach (var pos in posTimeO) { var isMatching = matchTimerO.IsMatching(bitmap.GetPixel(pos.X, pos.Y)); if (!isMatching) { if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine("{0} HasTimerMarkers: failed TimerO => ({1},{2}) = ({3}) vs ({4})", ScannerName, pos.X, pos.Y, bitmap.GetPixel(pos.X, pos.Y), matchTimerO); } return(false); } } return(true); }
protected bool HasPurifyPlate(FastBitmapHSV bitmap) { var hasMatch = true; for (int idx = 0; idx < posPurifyPlateI.Length; idx++) { var testPx = bitmap.GetPixel(posPurifyPlateI[idx].X, posPurifyPlateI[idx].Y); var isMatch = matchPlateShiny.IsMatching(testPx); if (!isMatch) { hasMatch = false; break; } } for (int idx = 0; idx < posPurifyPlateO.Length; idx++) { var testPx = bitmap.GetPixel(posPurifyPlateO[idx].X, posPurifyPlateO[idx].Y); var isMatch = matchPlateBack.IsMatching(testPx); if (!isMatch) { hasMatch = false; break; } } var rectSample0 = bitmap.GetPixel(rectPurifyPlate.X, rectPurifyPlate.Y); int maxHDiff = 0; int maxMDiff = 0; for (int idx = 1; idx < rectPurifyPlate.Width; idx++) { var testPx = bitmap.GetPixel(rectPurifyPlate.X + idx, rectPurifyPlate.Y); int hDiff = Math.Abs(testPx.GetHue() - rectSample0.GetHue()); int mDiff = Math.Abs(testPx.GetMonochrome() - rectSample0.GetMonochrome()); if (maxHDiff < hDiff) { maxHDiff = hDiff; } if (maxMDiff < mDiff) { maxMDiff = mDiff; } } if (maxHDiff > 35 || maxMDiff > 25) { hasMatch = false; } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} HasPurifyPlate: {1}", ScannerName, hasMatch); } if (DebugLevel >= EDebugLevel.Verbose) { string debugDesc = " in: "; for (int idx = 0; idx < posPurifyPlateI.Length; idx++) { var testPx = bitmap.GetPixel(posPurifyPlateI[idx].X, posPurifyPlateI[idx].Y); if (idx > 0) { debugDesc += ", "; } debugDesc += "(" + testPx + ")"; } Console.WriteLine(debugDesc); debugDesc = " out: "; for (int idx = 0; idx < posPurifyPlateO.Length; idx++) { var testPx = bitmap.GetPixel(posPurifyPlateO[idx].X, posPurifyPlateO[idx].Y); if (idx > 0) { debugDesc += ", "; } debugDesc += "(" + testPx + ")"; } Console.WriteLine(debugDesc); Console.WriteLine(" filterIn({0}), filterOut({1})", matchPlateShiny, matchPlateBack); Console.WriteLine(" maxHDiff:{0}, maxMDiff:{1}", maxHDiff, maxMDiff); } return(hasMatch); }