public static async void GameScreenshot() { var handle = User32.GetHearthstoneWindow(); if (handle == IntPtr.Zero) { return; } var rect = User32.GetHearthstoneRect(false); var bmp = await ScreenCapture.CaptureHearthstoneAsync(new Point(0, 0), rect.Width, rect.Height, handle, false, true); if (bmp == null) { Log.Error("There was an error capturing hearthstone."); return; } using (var mem = new MemoryStream()) { var encoder = new PngBitmapEncoder(); bmp.Save(mem, ImageFormat.Png); encoder.Frames.Add(BitmapFrame.Create(mem)); await Core.MainWindow.SaveOrUploadScreenshot(encoder, "Hearthstone " + DateTime.Now.ToString("MM-dd-yy hh-mm-ss")); } Core.MainWindow.ActivateWindow(); }
public async Task Squelch() { if (!User32.IsHearthstoneInForeground()) { Squelched = false; return; } var hearthstoneWindow = User32.GetHearthstoneWindow(); if (hearthstoneWindow == IntPtr.Zero) { return; } var HsRect = User32.GetHearthstoneRect(true); var Ratio = 4.0 / 3.0 / ((double)HsRect.Width / HsRect.Height); var opponentHeroPosition = new Point((int)Helper.GetScaledXPos(0.5, HsRect.Width, Ratio), (int)(0.17 * HsRect.Height)); var squelchBubblePosition = new Point((int)Helper.GetScaledXPos(0.4, HsRect.Width, Ratio), (int)(0.1 * HsRect.Height)); // setting this as a "width" value relative to height, maybe not best solution? const double xScale = 0.051; // 55px @ height = 1080 const double yScale = 0.025; // 27px @ height = 1080 const double minBrightness = 0.67; var lockWidth = (int)Math.Round(HsRect.Height * xScale); var lockHeight = (int)Math.Round(HsRect.Height * yScale); var squelchBubbleVisible = false; // Limit amount of tries (in case a game mode does not support squelching your opponent or else) const int maxTries = 4; var timesTried = 0; var previousMousePosition = User32.GetMousePos(); do { if (!ShouldTrySquelch) { Squelched = false; return; } await MouseHelpers.ClickOnPoint(hearthstoneWindow, opponentHeroPosition, false); await Task.Delay(TimeSpan.FromMilliseconds(Config.Instance.OverlayMouseOverTriggerDelay)); var capture = await ScreenCapture.CaptureHearthstoneAsync(squelchBubblePosition, lockWidth, lockHeight, hearthstoneWindow); squelchBubbleVisible = CalculateAverageLightness(capture) > minBrightness; if (!squelchBubbleVisible) { await Task.Delay(TimeSpan.FromMilliseconds(Config.Instance.OverlayMouseOverTriggerDelay)); ++timesTried; } } while (!squelchBubbleVisible && timesTried <= maxTries); await MouseHelpers.ClickOnPoint(hearthstoneWindow, squelchBubblePosition, true); MouseHelpers.SetCursorPosition(previousMousePosition); }
public async Task <Bitmap> GameScreenshot(bool alt = true) { var rect = GameRectangle(true); Common.Log.Debug($"Tracker: Capturing screenshot"); return(await ScreenCapture.CaptureHearthstoneAsync( new Point(0, 0), rect.Width, rect.Height, altScreenCapture : alt)); }
public static async Task <bool> IsDeckEmpty(IntPtr wndHandle, int width, int height, double ratio) { var capture = await ScreenCapture.CaptureHearthstoneAsync( new Point((int)Helper.GetScaledXPos(Config.Instance.ExportClearX, width, ratio), (int)(Config.Instance.ExportClearCheckYFixed *height)), 1, 1, wndHandle); return(capture != null && ColorDistance(capture.GetPixel(0, 0), Color.FromArgb(255, 56, 45, 69), 5)); }
private static async Task <Bitmap> CaptureScreenShot(bool alt) { var rect = Helper.GetHearthstoneRect(true); Log.Info($"Rectangle ({rect.X}, {rect.Y}, {rect.Width}, {rect.Height})"); Log.Info($"Calling screen capture"); return(await ScreenCapture.CaptureHearthstoneAsync( new Point(0, 0), rect.Width, rect.Height, altScreenCapture : alt)); }
public static async Task <bool> CardExists(IntPtr wndHandle, int posX, int posY, int width, int height) { const double scale = 0.037; // 40px @ height = 1080 const double minHue = 90; var size = (int)Math.Round(height * scale); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(posX, posY), size, size, wndHandle); if (capture == null) { return(false); } return(HueAndBrightness.GetAverage(capture).Hue > minHue); }
public async Task Squelch() { if (!User32.IsHearthstoneInForeground()) { Squelched = false; return; } IntPtr hearthstoneWindow = User32.GetHearthstoneWindow(); var HsRect = User32.GetHearthstoneRect(false); var Ratio = (4.0 / 3.0) / ((double)HsRect.Width / HsRect.Height); Point opponentHeroPosition = new Point((int)Helper.GetScaledXPos(0.5, HsRect.Width, Ratio), (int)(0.17 * HsRect.Height)); Point squelchBubblePosition = new Point((int)Helper.GetScaledXPos(0.4, HsRect.Width, Ratio), (int)(0.1 * HsRect.Height)); // setting this as a "width" value relative to height, maybe not best solution? const double xScale = 0.051; // 55px @ height = 1080 const double yScale = 0.025; // 27px @ height = 1080 const double minBrightness = 0.67; var lockWidth = (int)Math.Round(HsRect.Height * xScale); var lockHeight = (int)Math.Round(HsRect.Height * yScale); bool squelchBubbleVisible = false; do { if (!PluginRunning || !GameInProgress) { Squelched = false; return; } await MouseHelpers.ClickOnPoint(hearthstoneWindow, opponentHeroPosition, false); await Task.Delay(TimeSpan.FromMilliseconds(DeckExportDelay * 4)); var capture = await ScreenCapture.CaptureHearthstoneAsync(squelchBubblePosition, lockWidth, lockHeight, hearthstoneWindow); squelchBubbleVisible = HueAndBrightness.GetAverage(capture).Brightness > minBrightness; if (!squelchBubbleVisible) { await Task.Delay(TimeSpan.FromSeconds(0.5)); } } while (!squelchBubbleVisible); await MouseHelpers.ClickOnPoint(hearthstoneWindow, squelchBubblePosition, true); }
public static async Task <bool> IsZeroCrystalSelected(IntPtr wndHandle, double ratio, int width, int height) { const double scale = 0.020; // 22px @ height = 1080 const double minBrightness = 0.55; var size = (int)Math.Round(height * scale); var posX = (int)Helper.GetScaledXPos(Config.Instance.ExportZeroSquareX, width, ratio); var posY = (int)(Config.Instance.ExportZeroSquareY * height); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(posX, posY), size, size, wndHandle); if (capture == null) { return(false); } return(HueAndBrightness.GetAverage(capture).Brightness > minBrightness); }
public static async Task <bool> CardHasLock(IntPtr wndHandle, int posX, int posY, int width, int height) { // setting this as a "width" value relative to height, maybe not best solution? const double xScale = 0.051; // 55px @ height = 1080 const double yScale = 0.0278; // 30px @ height = 1080 const double maxBrightness = 5.0 / 11.0; // ReSharper disable once SuggestVarOrType_BuiltInTypes var lockWidth = (int)Math.Round(height * xScale); var lockHeight = (int)Math.Round(height * yScale); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(posX, posY), lockWidth, lockHeight, wndHandle); if (capture == null) { return(false); } return(HueAndBrightness.GetAverage(capture).Brightness < maxBrightness); }
public static async Task <bool> FriendsListOpen() { //wait for friendslist to open/close await Task.Delay(300); var rect = User32.GetHearthstoneRect(false); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(0, (int)(rect.Height * 0.85)), (int)(rect.Width * 0.1), (int)(rect.Height * 0.15)); if (capture == null) { return(false); } for (var y = 0; y < capture.Height; y++) { for (var x = 0; x < capture.Width; x++) { if (!IsYellowPixel(capture.GetPixel(x, y))) { continue; } var foundFriendsList = true; //check for a straight yellow line (left side of add button) for (var i = 0; i < 5; i++) { if (x + i >= capture.Width || !IsYellowPixel(capture.GetPixel(x + i, y))) { foundFriendsList = false; } } if (foundFriendsList) { return(true); } } } return(false); }
public async Task GetCardCounts(Deck deck) { var hsHandle = User32.GetHearthstoneWindow(); if (!User32.IsHearthstoneInForeground()) { //restore window and bring to foreground User32.ShowWindow(hsHandle, User32.SwRestore); User32.SetForegroundWindow(hsHandle); //wait it to actually be in foreground, else the rect might be wrong await Task.Delay(500); } if (!User32.IsHearthstoneInForeground()) { Log.Error("Can't find Hearthstone window."); return; } await Task.Delay(1000); Core.Overlay.ForceHidden = true; Core.Overlay.UpdatePosition(); const double xScale = 0.013; const double yScale = 0.017; const int targetHue = 53; const int hueMargin = 3; const int numVisibleCards = 21; var hsRect = User32.GetHearthstoneRect(false); var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); var posX = (int)Helper.GetScaledXPos(0.92, hsRect.Width, ratio); var startY = 71.0 / 768.0 * hsRect.Height; var strideY = 29.0 / 768.0 * hsRect.Height; var width = (int)Math.Round(hsRect.Width * xScale); var height = (int)Math.Round(hsRect.Height * yScale); for (var i = 0; i < Math.Min(numVisibleCards, deck.Cards.Count); i++) { var posY = (int)(startY + strideY * i); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(posX, posY), width, height, hsHandle); if (capture == null) { continue; } var yellowPixels = 0; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var pixel = capture.GetPixel(x, y); if (Math.Abs(pixel.GetHue() - targetHue) < hueMargin) { yellowPixels++; } } } //Console.WriteLine(yellowPixels + " of " + width * height + " - " + yellowPixels / (double)(width * height)); //capture.Save("arenadeckimages/" + i + ".png"); var yellowPixelRatio = yellowPixels / (double)(width * height); if (yellowPixelRatio > 0.25 && yellowPixelRatio < 50) { deck.Cards[i].Count = 2; } } if (deck.Cards.Count > numVisibleCards) { const int scrollClicksPerCard = 4; const int scrollDistance = 120; var clientPoint = new Point(posX, (int)startY); var previousPos = System.Windows.Forms.Cursor.Position; User32.ClientToScreen(hsHandle, ref clientPoint); System.Windows.Forms.Cursor.Position = new Point(clientPoint.X, clientPoint.Y); for (var j = 0; j < scrollClicksPerCard * (deck.Cards.Count - numVisibleCards); j++) { User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, -scrollDistance, UIntPtr.Zero); await Task.Delay(30); } System.Windows.Forms.Cursor.Position = previousPos; await Task.Delay(100); var remainingCards = deck.Cards.Count - numVisibleCards; startY = 76.0 / 768.0 * hsRect.Height + (numVisibleCards - remainingCards) * strideY; for (var i = 0; i < remainingCards; i++) { var posY = (int)(startY + strideY * i); var capture = await ScreenCapture.CaptureHearthstoneAsync(new Point(posX, posY), width, height, hsHandle); if (capture == null) { continue; } var yellowPixels = 0; for (var x = 0; x < width; x++) { for (var y = 0; y < height; y++) { var pixel = capture.GetPixel(x, y); if (Math.Abs(pixel.GetHue() - targetHue) < hueMargin) { yellowPixels++; } } } var yellowPixelRatio = yellowPixels / (double)(width * height); if (yellowPixelRatio > 0.25 && yellowPixelRatio < 50) { deck.Cards[numVisibleCards + i].Count = 2; } } System.Windows.Forms.Cursor.Position = new Point(clientPoint.X, clientPoint.Y); for (var j = 0; j < scrollClicksPerCard * (deck.Cards.Count - 21); j++) { User32.mouse_event((uint)User32.MouseEventFlags.Wheel, 0, 0, scrollDistance, UIntPtr.Zero); await Task.Delay(30); } System.Windows.Forms.Cursor.Position = previousPos; } Core.Overlay.ForceHidden = false; Core.Overlay.UpdatePosition(); ActivateWindow(); }
public static async Task <Bitmap> CaptureHearthstoneAsync(Point point, int width, int height, IntPtr wndHandle = default(IntPtr), bool requireInForeground = true, bool?altScreenCapture = null) => await ScreenCapture.CaptureHearthstoneAsync(point, width, height, wndHandle, requireInForeground, altScreenCapture);
private static async Task <Bitmap> CaptureScreenShot() { var rect = Helper.GetHearthstoneRect(true); return(await ScreenCapture.CaptureHearthstoneAsync(new Point(0, 0), rect.Width, rect.Height, altScreenCapture : true)); }