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 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); }