public void UpdatePosition() { if (!User32.IsForegroundWindow("Hearthstone") && !_needToRefresh) { _needToRefresh = true; } else if (_needToRefresh && User32.IsForegroundWindow("Hearthstone")) { _needToRefresh = false; Update(true); } //hide the overlay depenting on options ShowOverlay(!( (_config.HideInBackground && !User32.IsForegroundWindow("Hearthstone")) || (_config.HideInMenu && _hearthstone.IsInMenu) || _config.HideOverlay)); var hsRect = new User32.Rect(); User32.GetWindowRect(User32.FindWindow(null, "Hearthstone"), ref hsRect); //hs window has height 0 if it just launched, screwing things up if the tracker is started before hs is. //this prevents that from happening. if (hsRect.bottom - hsRect.top == 0) { return; } SetRect(hsRect.top, hsRect.left, hsRect.right - hsRect.left, hsRect.bottom - hsRect.top); ReSizePosLists(); }
public void UpdatePosition() { //hide the overlay depenting on options ShowOverlay(!( (Config.Instance.HideInBackground && !User32.IsForegroundWindow("Hearthstone")) || (Config.Instance.HideInMenu && Game.IsInMenu) || Config.Instance.HideOverlay)); var hsRect = User32.GetHearthstoneRect(true); //hs window has height 0 if it just launched, screwing things up if the tracker is started before hs is. //this prevents that from happening. if (hsRect.Height == 0 || Visibility != Visibility.Visible) { return; } SetRect(hsRect.Top, hsRect.Left, hsRect.Width, hsRect.Height); ReSizePosLists(); try { UpdateCardTooltip(); } catch (Exception) { } }
private void MouseInputOnLmbDown(object sender, EventArgs eventArgs) { if (!User32.IsForegroundWindow("Hearthstone") || Visibility != Visibility.Visible) { return; } var pos = User32.GetMousePos(); _mousePos = new Point(pos.X, pos.Y); if (_uiMovable) { _lmbDown = true; foreach (var movableElement in _movableElements) { var relativePos = movableElement.Value.PointFromScreen(_mousePos); var panel = movableElement.Key as StackPanel; if (panel != null) { if (PointInsideControl(relativePos, movableElement.Value.ActualWidth, movableElement.Value.ActualHeight)) { if (Math.Abs(relativePos.X - movableElement.Value.ActualWidth) < 30 && Math.Abs(relativePos.Y - movableElement.Value.ActualHeight) < 30) { _resizeElement = true; } _selectedUIElement = movableElement.Key; return; } } var timer = movableElement.Key as HearthstoneTextBlock; if (timer != null) { if (PointInsideControl(relativePos, timer.ActualWidth, timer.ActualHeight)) { if (Math.Abs(relativePos.X - timer.ActualWidth) < 30 && Math.Abs(relativePos.Y - timer.ActualHeight) < 30) { _resizeElement = true; } _selectedUIElement = movableElement.Key; return; } } } } HideCardsWhenFriendsListOpen(PointFromScreen(_mousePos)); GrayOutSecrets(_mousePos); }
public void UpdatePosition() { //hide the overlay depenting on options EnableCanvas(!( (_config.HideInBackground && !User32.IsForegroundWindow("Hearthstone")) || (_config.HideInMenu && _hearthstone.IsInMenu) || _config.HideOverlay)); var hsRect = new User32.Rect(); User32.GetWindowRect(User32.FindWindow(null, "Hearthstone"), ref hsRect); SetRect(hsRect.top, hsRect.left, hsRect.right - hsRect.left, hsRect.bottom - hsRect.top); ReSizePosLists(); }
public static Bitmap CaptureHearthstone(Point point, int width, int height, IntPtr wndHandle = default(IntPtr)) { if (wndHandle == default(IntPtr)) { wndHandle = User32.GetHearthstoneWindow(); } User32.ClientToScreen(wndHandle, ref point); if (!User32.IsForegroundWindow("Hearthstone")) { return(null); } var bmp = new Bitmap(width, height, PixelFormat.Format32bppArgb); var graphics = Graphics.FromImage(bmp); graphics.CopyFromScreen(point.X, point.Y, 0, 0, new Size(width, height), CopyPixelOperation.SourceCopy); return(bmp); }
public static async Task Export(Deck deck) { if (deck == null) { return; } var hsHandle = User32.FindWindow("UnityWndClass", "Hearthstone"); if (!User32.IsForegroundWindow("Hearthstone")) { //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.IsForegroundWindow("Hearthstone")) { MessageBox.Show("Can't find Heartstone window."); return; } var hsRect = User32.GetHearthstoneRect(false); var bounds = Screen.FromHandle(hsHandle).Bounds; var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); if (Config.Instance.ExportSetDeckName) { await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle); } await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle); foreach (var card in deck.Cards) { await AddCardToDeck(card, ratio, hsRect.Width, hsRect.Height, hsHandle); } }
public void Export(Deck deck) { if (deck == null) { return; } var hsHandle = User32.FindWindow(null, "Hearthstone"); if (!User32.IsForegroundWindow("Hearthstone")) { //restore window and bring to foreground User32.ShowWindow(hsHandle, SwRestore); User32.SetForegroundWindow(hsHandle); //wait it to actually be in foreground, else the rect might be wrong Thread.Sleep(500); } if (!User32.IsForegroundWindow("Hearthstone")) { MessageBox.Show("Can't find Heartstone window."); return; } User32.Rect hsWindowRect = new User32.Rect(); User32.GetWindowRect(hsHandle, ref hsWindowRect); var height = (hsWindowRect.bottom - hsWindowRect.top); var width = (hsWindowRect.right - hsWindowRect.left); var bounds = Screen.FromHandle(hsHandle).Bounds; bool isFullscreen = bounds.Width == width && bounds.Height == height; foreach (var card in deck.Cards) { AddCardToDeck(card, width, height, hsHandle, isFullscreen); } }
private static async Task AddCardToDeck(Card card, double ratio, int width, int height, IntPtr hsHandle) { if (!User32.IsForegroundWindow("Hearthstone")) { Helper.MainWindow.ShowMessage("Exporting aborted", "Hearthstone window lost focus."); return; } var cardPosX = GetXPos(Config.Instance.ExportCard1X, width, ratio); var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, width, ratio)), (int)(Config.Instance.ExportSearchBoxY * height)); await ClickOnPoint(hsHandle, searchBoxPos); SendKeys.SendWait(FixCardName(card.LocalizedName).ToLowerInvariant()); SendKeys.SendWait("{ENTER}"); await Task.Delay(Config.Instance.DeckExportDelay * 2); var card2PosX = GetXPos(Config.Instance.ExportCard2X, width, ratio); var cardPosY = Config.Instance.ExportCardsY * height; for (var i = 0; i < card.Count; i++) { if (Config.Instance.PrioritizeGolden) { if (card.Count == 2) { await ClickOnPoint(hsHandle, new Point((int)card2PosX, (int)cardPosY)); } else if (CheckForGolden(hsHandle, new Point((int)card2PosX, (int)(cardPosY + height * 0.05)))) { await ClickOnPoint(hsHandle, new Point((int)card2PosX, (int)cardPosY)); } else { await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); } } else { await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); } } if (card.Count == 2) { //click again to make sure we get 2 cards if (Config.Instance.PrioritizeGolden) { await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); } else { await ClickOnPoint(hsHandle, new Point((int)card2PosX, (int)cardPosY)); } } // Clear search field now all cards have been entered await ClickOnPoint(hsHandle, searchBoxPos); SendKeys.SendWait("{DELETE}"); SendKeys.SendWait("{ENTER}"); }