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); }
public float[] ExtractButtonData(FastBitmapHSV bitmap, int slotIdx) { // scan area: 16x8 (rectButtonText scaled down) float[] values = new float[16 * 8]; for (int idx = 0; idx < values.Length; idx++) { values[idx] = 0.0f; } const int monoSteps = 16; const float monoScale = 1.0f / monoSteps; Point slotPos = rectButtonPos[slotIdx].Location; slotPos.X += rectButtonText.Location.X; slotPos.Y += rectButtonText.Location.Y; for (int idxY = 0; idxY < 16; idxY++) { for (int idxX = 0; idxX < 32; idxX++) { FastPixelHSV pixel = bitmap.GetPixel(slotPos.X + idxX, slotPos.Y + idxY); int monoV = pixel.GetMonochrome() / (256 / monoSteps); values[(idxX / 2) + ((idxY / 2) * 16)] += monoV * monoScale * 0.25f; } } return(values); }
private bool HasBurstMarker(FastBitmapHSV bitmap, int testX, int testY) { //bool wantsLogs = testX == 153 && testY == 112; for (int idx = 0; idx < posBurstMarkerI.Length; idx++) { FastPixelHSV testPx = bitmap.GetPixel(posBurstMarkerI[idx].X + testX, posBurstMarkerI[idx].Y + testY); bool isMatch = matchBurstMarker.IsMatching(testPx); //if (wantsLogs) Console.WriteLine("HasBurstMarker({0}, {1}) - inner[{2}]({3},{4}) = {5}", testX, testY, idx, posBurstMarkerI[idx].X + testX, posBurstMarkerI[idx].Y + testY, testPx); if (!isMatch) { return(false); } } for (int idx = 0; idx < posBurstMarkerO.Length; idx++) { FastPixelHSV testPx = bitmap.GetPixel(posBurstMarkerO[idx].X + testX, posBurstMarkerO[idx].Y + testY); bool isMatch = matchBurstMarker.IsMatching(testPx); //if (wantsLogs) Console.WriteLine("HasBurstMarker({0}, {1}) - outer[{2}]({3},{4}) = {5}", testX, testY, idx, posBurstMarkerO[idx].X + testX, posBurstMarkerO[idx].Y + testY, testPx); if (isMatch) { return(false); } } return(true); }
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); }
public static FastBitmapHSV ConvertToFastBitmap(Bitmap image, int forcedWidth = -1, int forcedHeight = -1) { int useWidth = (forcedWidth > 0) ? forcedWidth : image.Width; int useHeight = (forcedHeight > 0) ? forcedHeight : image.Height; FastBitmapHSV result = new FastBitmapHSV(useWidth, useHeight); unsafe { BitmapData bitmapData = image.LockBits(new Rectangle(0, 0, image.Width, image.Height), ImageLockMode.ReadOnly, image.PixelFormat); int bytesPerPixel = Image.GetPixelFormatSize(image.PixelFormat) / 8; int bytesPerRow = Math.Min(bitmapData.Width, result.Width) * bytesPerPixel; int convertHeight = Math.Min(bitmapData.Height, result.Height); for (int IdxY = 0; IdxY < convertHeight; IdxY++) { byte *pixels = (byte *)bitmapData.Scan0 + (IdxY * bitmapData.Stride); int IdxPixel = IdxY * result.Width; for (int IdxByte = 0; IdxByte < bytesPerRow; IdxByte += bytesPerPixel) { result.Pixels[IdxPixel] = new FastPixelHSV(pixels[IdxByte + 2], pixels[IdxByte + 1], pixels[IdxByte]); IdxPixel++; } } image.UnlockBits(bitmapData); } return(result); }
protected bool HasRewardChests(FastBitmapHSV bitmap) { GetAverageChestColor(bitmap, posChestG, out int avgHueG, out int avgSatG); GetAverageChestColor(bitmap, posChestS, out int avgHueS, out int avgSatS); GetAverageChestColor(bitmap, posChestB, out int avgHueB, out int avgSatB); bool hasGold = (avgHueG < 45) && (avgHueG > 25) && (avgSatG < 60) && (avgSatG > 40); bool hasSilver = (avgHueS < 45) && (avgHueS > 25) && (avgSatS < 30) && (avgSatS > -1); bool hasBronze = (avgHueB < 30) && (avgHueB > 5) && (avgSatB < 60) && (avgSatB > 30); bool hasMatch = hasGold && hasSilver && hasBronze; if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} HasRewardChests: {1}", ScannerName, hasMatch); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(" gold: avgH:{0} avgS:{1} -> {2}", avgHueG, avgSatG, hasGold); Console.WriteLine(" silver: avgH:{0} avgS:{1} -> {2}", avgHueS, avgSatS, hasSilver); Console.WriteLine(" bronze: avgH:{0} avgS:{1} -> {2}", avgHueB, avgSatB, hasBronze); } return(hasMatch); }
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 float[] ExtractDemonTypeData(FastBitmapHSV bitmap) { // scan area: 10x10 (rectActionIcon) float[] values = new float[10 * 10]; for (int idx = 0; idx < values.Length; idx++) { values[idx] = 0.0f; } const int monoSteps = 16; const float monoScale = 1.0f / monoSteps; for (int idxY = 0; idxY < 10; idxY++) { for (int idxX = 0; idxX < 10; idxX++) { FastPixelHSV pixel = bitmap.GetPixel(rectDemonType.X + idxX, rectDemonType.Y + idxY); int monoV = pixel.GetMonochrome() / (256 / monoSteps); values[idxX + (idxY * 10)] = monoV * monoScale; } } return(values); }
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); }
public float[] ExtractActionSlotWeaponData(FastBitmapHSV bitmap, int slotIdx) { // scan area: 10x10 (rectActionIcon) float[] values = new float[10 * 10]; for (int idx = 0; idx < values.Length; idx++) { values[idx] = 0.0f; } const int monoSteps = 16; const float monoScale = 1.0f / monoSteps; Point slotPos = rectActionSlots[slotIdx].Location; for (int idxY = 0; idxY < 10; idxY++) { for (int idxX = 0; idxX < 10; idxX++) { FastPixelHSV pixel = bitmap.GetPixel(slotPos.X + rectActionIcon.X + idxX, slotPos.Y + rectActionIcon.Y + idxY); int monoV = pixel.GetMonochrome() / (256 / monoSteps); values[idxX + (idxY * 10)] = monoV * monoScale; } } return(values); }
public override object Process(FastBitmapHSV bitmap) { scannerState = 1; var hasTextBox = HasChatBoxArea(bitmap); if (hasTextBox) { scannerState = 2; var hasPurifyPlate = HasPurifyPlate(bitmap); if (hasPurifyPlate) { scannerState = 3; var outputOb = new ScreenData(); ScanSP(bitmap, outputOb); ScanBurst(bitmap, outputOb); for (int idx = 0; idx < posActionSlots.Length; idx++) { ScanActionSlot(bitmap, posActionSlots[idx], outputOb, idx); } return(outputOb); } } return(null); }
public float[] ExtractHeaderPatternData(FastBitmapHSV bitmap, int patternIdx) { // scan area: 20x8 float[] values = new float[20 * 8]; for (int idx = 0; idx < values.Length; idx++) { values[idx] = 0.0f; } const int monoSteps = 16; const float monoScale = 1.0f / monoSteps; for (int idxY = 0; idxY < 8; idxY++) { for (int idxX = 0; idxX < 20; idxX++) { FastPixelHSV pixel = bitmap.GetPixel(posHeaderPattern[patternIdx].X + idxX, posHeaderPattern[patternIdx].Y + idxY); int monoV = pixel.GetMonochrome() / (256 / monoSteps); values[idxX + (idxY * 20)] = monoV * monoScale; } } return(values); }
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); }
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); } }
private void ScanBurst(FastBitmapHSV bitmap, ScreenData screenData) { float monoAcc = 0.0f; for (int idxY = 0; idxY < rectBurstActive.Height; idxY++) { for (int idxX = 0; idxX < rectBurstActive.Width; idxX++) { FastPixelHSV testPx = bitmap.GetPixel(rectBurstActive.X + idxX, rectBurstActive.Y + idxY); monoAcc += testPx.GetMonochrome(); } } float monoAvg = monoAcc / (rectBurstActive.Width * rectBurstActive.Height); float centerFillPct = 0; if (monoAvg < 15) { screenData.BurstState = EBurstState.Active; } else { centerFillPct = ScreenshotUtilities.CountFillPct(bitmap, rectBurstCenter, matchBurstCenter); if (centerFillPct > 0.75f) { screenData.BurstState = EBurstState.ReadyAndCenter; screenData.BurstMarkerPctX = 0.5f; screenData.BurstMarkerPctY = 0.5f; if (DebugLevel >= EDebugLevel.Verbose) { Rectangle box = GetSpecialActionBox((int)ESpecialBox.BurstCenter); DrawRectangle(bitmap, box.X, box.Y, box.Width, box.Height, 255); } } else { ScanBurstPosition(bitmap, screenData); if (DebugLevel >= EDebugLevel.Verbose && screenData.BurstState == EBurstState.Ready) { Rectangle box = GetSpecialActionBox((int)ESpecialBox.BurstReady); DrawRectangle(bitmap, box.X, box.Y, box.Width, box.Height, 255); } } } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanBurst: {1}", ScannerName, screenData.BurstState); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(">> monoAvg: {0}, centerFillPct: {1}", monoAvg, centerFillPct); } }
public static void SaveBitmapWithShapes(FastBitmapHSV bitmap, List <Rectangle> listBounds, string fileName) { if (File.Exists(fileName)) { File.Delete(fileName); } using (Bitmap bmp = CreateBitmapWithShapes(bitmap, listBounds)) { bmp.Save(fileName, ImageFormat.Png); } }
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 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); } }
public static FastBitmapHSV ConvertToFastBitmap(byte[] PixelsBGRA, int width, int height) { FastBitmapHSV result = new FastBitmapHSV(width, height); int numPx = width * height; for (int IdxPx = 0; IdxPx < numPx; IdxPx++) { int IdxByte = IdxPx * 4; result.Pixels[IdxPx] = new FastPixelHSV(PixelsBGRA[IdxByte + 2], PixelsBGRA[IdxByte + 1], PixelsBGRA[IdxByte]); } return(result); }
public override object Process(FastBitmapHSV bitmap) { scannerState = 1; var hasMsgBox = HasLogoMarkers(bitmap); if (hasMsgBox) { scannerState = 2; var outputOb = new ScreenData(); return(outputOb); } return(null); }
public override object Process(FastBitmapHSV bitmap) { scannerState = 1; var outputOb = new ScreenData(); var hasMsgBox = HasOkButtonArea(bitmap, outputOb); if (hasMsgBox) { scannerState = 2; return(outputOb); } return(null); }
public static void FindColorRange(FastBitmapHSV bitmap, Rectangle box, out int minMono, out int maxMono) { minMono = 255; maxMono = 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); minMono = Math.Min(minMono, testPx.Monochrome); maxMono = Math.Max(maxMono, testPx.Monochrome); } } }
protected void ScanBurst(FastBitmapHSV bitmap, ScreenData screenData) { var centerFillPct = ScreenshotUtilities.CountFillPct(bitmap, rectBurstCenter, matchBurstCenter); screenData.hasBurstInCenter = centerFillPct > 0.75f; if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} ScanBurst: {1}", ScannerName, screenData.hasBurstInCenter); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(">> centerFillPct: {0}", centerFillPct); } }
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); }
private void ScanDemonSummon(FastBitmapHSV bitmap, ScreenData screenData) { var hasCircle = false; float pctDemonL = 0, pctDemonR = 0; float[] values = ExtractDemonCounterData(bitmap, 0); int IsDemonL = classifierDemon.Calculate(values, out pctDemonL); int IsDemonR = 0; if (IsDemonL > 0) { values = ExtractDemonCounterData(bitmap, 1); IsDemonR = classifierDemon.Calculate(values, out pctDemonR); if (IsDemonR > 0) { hasCircle = true; } } if (hasCircle) { screenData.demonState = EDemonState.Active; values = ExtractDemonTypeData(bitmap); screenData.demonType = (EWeaponType)classifierWeapon.Calculate(values, out float dummyPctDT); } else { var hasPrep = HasMatchingSamples(bitmap, posDemonPrepI, 0, 0, matchDemonPrepI, "prepI") && HasMatchingSamples(bitmap, posDemonPrepO, 0, 0, matchDemonPrepO, "prepO"); if (hasPrep) { screenData.demonState = EDemonState.Preparing; } } if (DebugLevel >= EDebugLevel.Simple) { Console.WriteLine("{0} Demon: {1} {2}", ScannerName, screenData.demonState, hasCircle ? screenData.demonType.ToString() : ""); } if (DebugLevel >= EDebugLevel.Verbose) { Console.WriteLine(">> IsDemonL: {0} ({1:P2}), IsDemonR:{2} ({3:P2})", IsDemonL, pctDemonL, IsDemonR, pctDemonR); } }
protected void DrawRectangle(FastBitmapHSV bitmap, int posX, int posY, int width, int height, byte color, int border = 1) { FastPixelHSV pixelOb = new FastPixelHSV(color, color, color); for (int idxX = 0; idxX < width; idxX++) { bitmap.SetPixel(posX + idxX, posY - border, pixelOb); bitmap.SetPixel(posX + idxX, posY + height + border, pixelOb); } for (int idxY = 0; idxY < height; idxY++) { bitmap.SetPixel(posX - border, posY + idxY, pixelOb); bitmap.SetPixel(posX + width + border, posY + idxY, pixelOb); } }
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 bool HasElemBoost(FastBitmapHSV bitmap, int slotIdx) { int posX = rectActionSlots[slotIdx].X + rectBoostSearch.X; int posY = rectActionSlots[slotIdx].Y + rectBoostSearch.Y; for (int offsetY = 0; offsetY < rectBoostSearch.Height / 2; offsetY++) { bool hasMarker = HasElemBoostMarker(bitmap, posX, posY + offsetY, slotIdx); if (hasMarker) { return(true); } } return(false); }
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); }
protected void ScanStats(FastBitmapHSV bitmap, Point[] playerPos, ref StatData[] stats) { float dummyPct = 0.0f; for (int playerIdx = 0; playerIdx < playerPos.Length; playerIdx++) { var statBlock = new StatData(); float[] values = ExtractStatData(bitmap, playerPos, playerIdx, 0); statBlock.PAtk = classifierStats.Calculate(values, out dummyPct); statBlock.PAtkType = (EStatMode)classifierStats.CalculateType(values, out dummyPct); values = ExtractStatData(bitmap, playerPos, playerIdx, 1); statBlock.PDef = classifierStats.Calculate(values, out dummyPct); statBlock.PDefType = (EStatMode)classifierStats.CalculateType(values, out dummyPct); values = ExtractStatData(bitmap, playerPos, playerIdx, 2); statBlock.MAtk = classifierStats.Calculate(values, out dummyPct); statBlock.MAtkType = (EStatMode)classifierStats.CalculateType(values, out dummyPct); values = ExtractStatData(bitmap, playerPos, playerIdx, 3); statBlock.MDef = classifierStats.Calculate(values, out dummyPct); statBlock.MDefType = (EStatMode)classifierStats.CalculateType(values, out dummyPct); // 21 = no number, store as -1 if (statBlock.PAtk > 20) { statBlock.PAtk = -1; } if (statBlock.PDef > 20) { statBlock.PDef = -1; } if (statBlock.MAtk > 20) { statBlock.MAtk = -1; } if (statBlock.MDef > 20) { statBlock.MDef = -1; } stats[playerIdx] = statBlock; } }