public static void TestData(Type classTypeOfTheme) { var pathFile = GetThemePathFile(classTypeOfTheme); var readAllLines = File.ReadAllLines(pathFile); var tableSizeAverageColors = new TableSizeAverageColors[readAllLines.Length]; for (int i = 0; i < readAllLines.Length; i++) { var split = readAllLines[i].Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries); tableSizeAverageColors[i] = new TableSizeAverageColors { TableSize = new Size(int.Parse(split[0]), int.Parse(split[1])), ScanRectangle = new Rectangle(int.Parse(split[2]), int.Parse(split[3]), int.Parse(split[4]), int.Parse(split[5])), R = double.Parse(split[6]), G = double.Parse(split[7]), B = double.Parse(split[8]) }; } while (true) { var handles = WinApi.GetWindowHandlesByClassName("PokerStarsTableFrameClass"); if (!handles.Any()) continue; var handle = handles.First(); var wr = WinApi.GetWindowRectangle(handle); var cr = WinApi.GetClientRectangle(handle); var bmp = new Bmp(ScreenCapture.GetBitmapWindowClient(handle)); var closest = tableSizeAverageColors.FirstOrDefault(a => a.TableSize.Width == cr.Width && a.TableSize.Height == cr.Height); if (closest == null) continue; double r, g, b; Methods.AverageColor(bmp, closest.ScanRectangle, out r, out g, out b); Debug.WriteLine(string.Format("{0,-3:0.00} {1,-3:0.00} {2,-3:0.00}", Math.Abs(closest.R - r), Math.Abs(closest.G - g), Math.Abs(closest.B - b))); Console.WriteLine(string.Format("{0,-3:0.00} {1,-3:0.00} {2,-3:0.00}", Math.Abs(closest.R - r), Math.Abs(closest.G - g), Math.Abs(closest.B - b))); Thread.Sleep(1000); } }
public static void CheckButtonAndClick(Bmp bmp, PokerStarsButton button, IntPtr handle) { Rectangle rect = new Rectangle( (int)Math.Round(button.LocationX * bmp.Width), (int)Math.Round(button.LocationY * bmp.Height), (int)Math.Round(button.Width * bmp.Width), (int)Math.Round(button.Height * bmp.Height)); double r, g, b; AverageColor(bmp, rect, out r, out g, out b); //Debug.WriteLine(string.Format("{0:0.000} {1:0.000} {2:0.000}", r - button.AvgR, g - button.AvgG, b - button.AvgB)); return; if (CompareColors(r, g, b, button.AvgR, button.AvgG, button.AvgB, button.MaxDiffR, button.MaxDiffG, button.MaxDiffB)) { if (button.ButtonSecondaryCheck != null)// secondary check for some buggy themes { //CheckButtonAndClick(bmp, button.ButtonSecondaryCheck, handle); } else { LeftMouseClickRelativeScaled(handle, button.ClickX, button.ClickY, true); } } }
public static void CheckImBackButtonAndClick(Bmp bmp, PokerStarsThemeTable pokerStarsThemeTable, IntPtr handle) { var closest = pokerStarsThemeTable.ButtonImBackSource.FirstOrDefault(a => a.TableSize.Width == bmp.Width && a.TableSize.Height == bmp.Height); if (closest == null) return; double r, g, b; AverageColor(bmp, closest.ScanRectangle, out r, out g, out b); if (Math.Abs(Math.Abs(closest.R - Math.Round(r, 2))) < 0.001 && Math.Abs(Math.Abs(closest.G - Math.Round(g, 2))) < 0.001 && Math.Abs(Math.Abs(closest.B - Math.Round(b, 2))) < 0.001) { LeftMouseClick(handle, closest.ScanRectangle.X + closest.ScanRectangle.Width / 2, closest.ScanRectangle.Y + closest.ScanRectangle.Height / 2, true); } }
public void Start() { Stop(); _thread = new Thread(() => { try { int timer = 0; bool firstCycle = true; while (true) { lock (_tablesLock) { IntPtr[] handles = WinApi.GetWindowHandlesByClassName("PokerStarsTableFrameClass"); // tables // remove closed tables foreach (Table t in _tables.Where(o => !handles.Contains(o.Handle)).ToArray()) { t.Dispose(); _tables.Remove(t); } // update tables foreach (IntPtr handle in handles) { bool isNewTable = false; // find or craete new table Table table = _tables.FirstOrDefault(o => o.Handle == handle); if (table == null) { table = new Table(handle) { ClassName = "PokerStarsTableFrameClass" }; _tables.Add(table); isNewTable = true; } // update table table.Title = WinApi.GetWindowTitle(handle); table.RectangleWindows = WinApi.GetWindowRectangle(handle); table.RectangleClient = WinApi.GetClientRectangle(handle); table.EnsureHud(); // autotile List<Table> tablesWithoutNewTable = _tables.ToList(); tablesWithoutNewTable.Remove(table); if (isNewTable && !firstCycle) { App.TableTileManager.AddAutoTileTable(table); } } // controller if (Config.AutoclickImBack || Config.AutoclickTimebank) { timer += DELAY_MS; if (timer > 2000) { timer = 0; foreach (IntPtr handle in handles) { Bitmap bitmap = ScreenCapture.GetBitmapWindowClient(handle); if (bitmap != null) { Bmp bmp = new Bmp(bitmap); if (Config.AutoclickImBack) Methods.CheckImBackButtonAndClick(bmp, Config.PokerStarsThemeTable, handle); if (Config.AutoclickTimebank) Methods.CheckButtonAndClick(bmp, Config.PokerStarsThemeTable.ButtonTimebank, handle); } } } } // UI update if (ObserverTableManagerTableList != null) ObserverTableManagerTableList.UpdateView(_tables); if (ObserverTableManagerTableCount != null) ObserverTableManagerTableCount.SetTableCount(_tables.Count); } if (firstCycle) firstCycle = false; Thread.Sleep(DELAY_MS); } } #if (DEBUG) catch (ThreadInterruptedException) { } #else catch (Exception e) { if (!(e is ThreadInterruptedException)) { Methods.DisplayException(e, App.WindowMain, WindowStartupLocation.CenterOwner); } } #endif finally { lock (_tablesLock) { foreach (Table t in _tables) { t.Dispose(); } _tables.Clear(); } } }); _thread.Start(); }
public static void AverageColor(Bmp bmp, Rectangle r, out double avgRed, out double avgGreen, out double avgBlue) { long redSum = 0, greenSum = 0, blueSum = 0; for (int y = r.Y; y < r.Y + r.Height; y++) { for (int x = r.X; x < r.X + r.Width; x++) { redSum += bmp.GetPixelR(x, y); greenSum += bmp.GetPixelG(x, y); blueSum += bmp.GetPixelB(x, y); } } avgRed = (double)redSum / (r.Width * r.Height); avgGreen = (double)greenSum / (r.Width * r.Height); avgBlue = (double)blueSum / (r.Width * r.Height); }
private static Point FindBmp(Bmp bmpSource, Bmp bmpTarget, double matchAccuracy = 1.0, double colorAccuracy = 1.0, int xSourceStarting = 0, int ySourceStarting = 0) { int totalPixelsToCheck = bmpTarget.Width * bmpTarget.Height; int minPixelsToMatch = (int)Math.Round(totalPixelsToCheck * matchAccuracy); int maxPixelsToMismatch = (int)Math.Round(totalPixelsToCheck * (1.0 - matchAccuracy)); int maxColorError = (int)Math.Round(byte.MaxValue - (byte.MaxValue * colorAccuracy)); for (int ySource = xSourceStarting; ySource < bmpSource.Height; ySource++) { for (int xSource = ySourceStarting; xSource < bmpSource.Width; xSource++) { if (BmpSourceFitsBmpTarget(bmpSource, xSource, ySource, bmpTarget, minPixelsToMatch, maxPixelsToMismatch, maxColorError)) { return new Point(xSource, ySource); } } } return new Point(int.MinValue, int.MinValue); }
public Bmp ___CutRectangle(Rectangle rect) { Bmp bmpCut = new Bmp(rect.Width, rect.Height); for (int y = rect.Y; y < rect.Height; y++) { for (int x = rect.X; x < rect.Width; x++) { bmpCut.SetPixelA(x - rect.X, y - rect.Y, GetPixelA(x, y)); } } return bmpCut; }
public static Bitmap BmpToBitmap(Bmp bmp) { return BytesToBitmap_Unsafe(bmp.GetBytesBGRA(), bmp.Width, bmp.Height); }
public static Bmp ___CutBmp(Bmp bmp, Rectangle rect) { Bmp bmpCut; using (Bitmap bitmap = BmpToBitmap(bmp)) { using (Bitmap bitmapCut = CutBitmap(bitmap, rect)) { bmpCut = new Bmp(bitmapCut); } } return bmpCut; }
private Bmp GetBmpWindowWindowSngTournamentFilter() { Bmp bmpPokerStarsLobby; using (Bitmap bitmap = ScreenCapture.GetBitmapWindowClient(HandleWindowSngTournamentFilter)) { bmpPokerStarsLobby = new Bmp(bitmap); } return bmpPokerStarsLobby; }
public static Bmp[] BitmapArrayToBmpArray(Bitmap[] bitmaps) { if (bitmaps == null) return null; Bmp[] bmps = new Bmp[bitmaps.Length]; for (int i = 0; i < bitmaps.Length; i++) { bmps[i] = new Bmp(bitmaps[i]); } return bmps; }
private void CheckButton(Bmp bmp, IntPtr window, IntPtr button, bool isTextless) { Thread.Sleep(1000); Rectangle rectangleToCheck = WinApi.GetClientRectangleRelativeTo(button, window); rectangleToCheck = isTextless ? new Rectangle(rectangleToCheck.X + 2, rectangleToCheck.Y + 3, 10, 10) : new Rectangle(rectangleToCheck.X + 5, rectangleToCheck.Y + 4, 10, 10); double avgR, avgG, avgB; Methods.AverageColor(bmp, rectangleToCheck, out avgR, out avgG, out avgB); Debug.WriteLine(avgR + " " + avgG + " " + avgB); }
public SngRegistratorManager() { using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.main_lobby_on.png")) { _bmpMainLobbyOn = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.main_lobby_off.png")) { _bmpMainLobbyOff = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.main_lobby_off_hover.png")) { _bmpMainLobbyOffHover = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.main_lobby_pressed.png")) { _bmpMainLobbyPressed = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_on.png")) { _bmpSngOn = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_off.png")) { _bmpSngOff = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_off_hover.png")) { _bmpSngOffHover = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_off_pressed.png")) { _bmpSngOffPressed = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_all_on.png")) { _bmpSngAllOn = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_all_off.png")) { _bmpSngAllOff = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_all_off_hover.png")) { _bmpSngAllOffHover = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.sng_all_off_pressed.png")) { _bmpSngAllOffPressed = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.t_games_view_on.png")) { _bmpTransparentGamesViewOn = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.t_games_view_on_pressed.png")) { _bmpTransparentGamesViewOnPressed = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.t_games_view_off.png")) { _bmpTransparentGamesViewOff = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.t_games_view_off_hover.png")) { _bmpTransparentGamesViewOffHover = new Bmp(bitmap); } using (Bitmap bitmap = Methods.GetEmbeddedResourceBitmap("PsHandler.Images.SngRegistrator.t_games_view_off_pressed.png")) { _bmpTransparentGamesViewOffPressed = new Bmp(bitmap); } }
// private Bmp GetBmpWindowPokerStarsLobby() { Bmp bmpPokerStarsLobby; using (Bitmap bitmap = ScreenCapture.GetBitmapWindowClient(_handleWindowPokerStarsLobby)) { bmpPokerStarsLobby = new Bmp(bitmap); } return bmpPokerStarsLobby; }
public PokerStarsButton(Bmp bmp, double clickX, double clickY, double locationX, double locationY, double maxDiffR, double maxDiffG, double maxDiffB) { Bmp = bmp; double r, g, b; Methods.AverageColor(Bmp, new Rectangle(0, 0, Bmp.Width, Bmp.Height), out r, out g, out b); AvgR = r; AvgG = g; AvgB = b; ClickX = clickX / PokerStarsThemeTable.WIDTH_DEFAULT; ClickY = clickY / PokerStarsThemeTable.HEIGHT_DEFAULT; LocationX = locationX / PokerStarsThemeTable.WIDTH_DEFAULT; LocationY = locationY / PokerStarsThemeTable.HEIGHT_DEFAULT; Width = bmp.Width / PokerStarsThemeTable.WIDTH_DEFAULT; Height = bmp.Height / PokerStarsThemeTable.HEIGHT_DEFAULT; MaxDiffR = maxDiffR; MaxDiffG = maxDiffG; MaxDiffB = maxDiffB; }
public Bmp ToHighContrastClone() { double h, s, l; Bmp bmpHighContrast = new Bmp(Width, Height); for (int y = 0; y < Height; y++) { for (int x = 0; x < Width; x++) { if (GetPixelA(x, y) < byte.MaxValue / 2) { bmpHighContrast.SetPixelA(x, y, 0); bmpHighContrast.SetPixelR(x, y, 0); bmpHighContrast.SetPixelG(x, y, 0); bmpHighContrast.SetPixelB(x, y, 0); } else { RgbToHsl(GetPixelR(x, y), GetPixelG(x, y), GetPixelB(x, y), out h, out s, out l); if (l < 0.5) { bmpHighContrast.SetPixelA(x, y, 255); bmpHighContrast.SetPixelR(x, y, 0); bmpHighContrast.SetPixelG(x, y, 0); bmpHighContrast.SetPixelB(x, y, 0); } else { bmpHighContrast.SetPixelA(x, y, 255); bmpHighContrast.SetPixelR(x, y, 255); bmpHighContrast.SetPixelG(x, y, 255); bmpHighContrast.SetPixelB(x, y, 255); } } } } return bmpHighContrast; }
public static void Scrape(Type classTypeOfTheme) { var rectangleTheme = THEMES[classTypeOfTheme]; var pathFile = GetThemePathFile(classTypeOfTheme); Thread.Sleep(3000); var handle = WinApi.GetWindowHandlesByClassName("PokerStarsTableFrameClass").First(); var wr = WinApi.GetWindowRectangle(handle); WinApi.MoveWindow(handle, wr.Left, wr.Top, SMALLEST.Width + 8 + 8, SMALLEST.Height + 31 + 8, true); wr = WinApi.GetWindowRectangle(handle); Thread.Sleep(250); MouseOperations.SetCursorPosition(wr.Right - 4, wr.Top + 100); Thread.Sleep(250); MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftDown); var sb = new StringBuilder(); var sb2 = new StringBuilder(); sb2.AppendLine("#region Source"); sb2.AppendLine(); for (int i = 0; i <= BIGGEST.Width - SMALLEST.Width; i++) { MouseOperations.SetCursorPosition(wr.Right - 4 + i, wr.Top + 100); Thread.Sleep(200); var cr = WinApi.GetClientRectangle(handle); var bmp = new Bmp(ScreenCapture.GetBitmapWindowClient(handle)); var ratioWidth = (double)cr.Width / DEFAULT.Width; var ratioHeight = (double)cr.Height / DEFAULT.Height; var theme = rectangleTheme; var rectangle = new Rectangle( (int)Math.Round(theme.X * ratioWidth), (int)Math.Round(theme.Y * ratioHeight), (int)Math.Round(theme.Width * ratioWidth), (int)Math.Round(theme.Height * ratioHeight) ); double r, g, b; Methods.AverageColor(bmp, rectangle, out r, out g, out b); Debug.WriteLine(string.Format("{0} {1} {2} {3} {4} {5} {6,3:0.00} {7,3:0.00} {8,3:0.00}", cr.Width, cr.Height, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, r, g, b)); sb.AppendLine(string.Format("{0} {1} {2} {3} {4} {5} {6,3:0.00} {7,3:0.00} {8,3:0.00}", cr.Width, cr.Height, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, r, g, b)); sb2.AppendLine(string.Format("new TableSizeAverageColors {9} TableSize = new Size({0}, {1}), ScanRectangle = new Rectangle({2}, {3}, {4}, {5}), R = {6,3:0.00}, G = {7,3:0.00}, B = {8,3:0.00} {10},", cr.Width, cr.Height, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height, r, g, b, "{", "}")); } MouseOperations.MouseEvent(MouseOperations.MouseEventFlags.LeftUp); Thread.Sleep(250); sb2.AppendLine(); sb2.AppendLine("#endregion"); File.WriteAllText(pathFile, sb.ToString()); File.WriteAllText(pathFile + "CSFORMAT.txt", sb2.ToString()); }
private static bool BmpSourceFitsBmpTarget(Bmp bmpSource, int xSource, int ySource, Bmp bmpTarget, int minPixelsToMatch, int maxPixelsToMismatch, int maxColorError) { if (xSource + bmpTarget.Width > bmpSource.Width || ySource + bmpTarget.Height > bmpSource.Height) return false; int transparent = 0, pixelsMatched = 0, pixelsMismatched = 0; for (int yTarget = 0; yTarget < bmpTarget.Height; yTarget++) { for (int xTarget = 0; xTarget < bmpTarget.Width; xTarget++) { int colorSourceR = bmpSource.GetPixelR(xSource + xTarget, ySource + yTarget); int colorSourceG = bmpSource.GetPixelG(xSource + xTarget, ySource + yTarget); int colorSourceB = bmpSource.GetPixelB(xSource + xTarget, ySource + yTarget); int colorTargetA = bmpTarget.GetPixelA(xTarget, yTarget); int colorTargetR = bmpTarget.GetPixelR(xTarget, yTarget); int colorTargetG = bmpTarget.GetPixelG(xTarget, yTarget); int colorTargetB = bmpTarget.GetPixelB(xTarget, yTarget); if (colorTargetA == 0) { transparent++; } else if (colorSourceR - maxColorError <= colorTargetR && colorSourceR + maxColorError >= colorTargetR && colorSourceG - maxColorError <= colorTargetG && colorSourceG + maxColorError >= colorTargetG && colorSourceB - maxColorError <= colorTargetB && colorSourceB + maxColorError >= colorTargetB) { pixelsMatched++; } else { pixelsMismatched++; } if (pixelsMismatched > maxPixelsToMismatch) { return false; } if (pixelsMatched + transparent >= minPixelsToMatch) { return true; } } } return false; }