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.IsHearthstoneInForeground()) { 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); }
private static async void UpdateOverlayAsync() { #if (!SQUIRREL) if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } #endif var hsForegroundChanged = false; var useNoDeckMenuItem = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone"); while (UpdateOverlay) { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Game.CurrentRegion = Helper.GetCurrentRegion(); if (Game.CurrentRegion != Region.UNKNOWN) { BackupManager.Run(); Game.MetaData.HearthstoneBuild = null; } } Overlay.UpdatePosition(); if (!Game.IsRunning) { Overlay.Update(true); Windows.CapturableOverlay?.UpdateContentVisibility(); } MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false; Game.IsRunning = true; Helper.GameWindowState = User32.GetHearthstoneWindowState(); Windows.CapturableOverlay?.Update(); if (User32.IsHearthstoneInForeground() && Helper.GameWindowState != WindowState.Minimized) { if (hsForegroundChanged) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? Windows.OpponentWindow.Topmost = true; Windows.PlayerWindow.Topmost = true; Windows.TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else if (!hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { Windows.PlayerWindow.Topmost = false; Windows.OpponentWindow.Topmost = false; Windows.TimerWindow.Topmost = false; } hsForegroundChanged = true; } } else if (Game.IsRunning) { Game.IsRunning = false; Overlay.ShowOverlay(false); if (Windows.CapturableOverlay != null) { Windows.CapturableOverlay.UpdateContentVisibility(); await Task.Delay(100); Windows.CapturableOverlay.ForcedWindowState = WindowState.Minimized; Windows.CapturableOverlay.WindowState = WindowState.Minimized; } Log.Info("Exited game"); Game.CurrentRegion = Region.UNKNOWN; Log.Info("Reset region"); await Reset(); Game.IsInMenu = true; Game.InvalidateMatchInfoCache(); Overlay.HideRestartRequiredWarning(); TurnTimer.Instance.Stop(); MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized && !User32.IsHearthstoneInForeground()) { NetDeck.CheckForClipboardImport(); } await Task.Delay(UpdateDelay); } CanShutdown = true; }
private static async void UpdateOverlayAsync() { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } var hsForegroundChanged = false; var useNoDeckMenuItem = TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone"); UpdateOverlay = Helper.HearthstoneDirExists; while (UpdateOverlay) { if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Game.CurrentRegion = Helper.GetCurrentRegion(); } Overlay.UpdatePosition(); if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (!Game.IsRunning) { Overlay.Update(true); } MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = false; Game.IsRunning = true; if (User32.IsHearthstoneInForeground()) { if (hsForegroundChanged) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? Windows.OpponentWindow.Topmost = true; Windows.PlayerWindow.Topmost = true; Windows.TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else if (!hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { Windows.PlayerWindow.Topmost = false; Windows.OpponentWindow.Topmost = false; Windows.TimerWindow.Topmost = false; } hsForegroundChanged = true; } } else { Overlay.ShowOverlay(false); if (Game.IsRunning) { //game was closed Logger.WriteLine("Exited game", "UpdateOverlayLoop"); Game.CurrentRegion = Region.UNKNOWN; Logger.WriteLine("Reset region", "UpdateOverlayLoop"); //HsLogReaderV2.Instance.ClearLog(); Game.Reset(); if (DeckList.Instance.ActiveDeck != null) { Game.SetPremadeDeck((Deck)DeckList.Instance.ActiveDeck.Clone()); } await LogReaderManager.Restart(); MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible; TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } Game.IsRunning = false; } if (Config.Instance.NetDeckClipboardCheck.HasValue && Config.Instance.NetDeckClipboardCheck.Value && Initialized && !User32.IsHearthstoneInForeground()) { NetDeck.CheckForClipboardImport(); } await Task.Delay(Config.Instance.UpdateDelay); } CanShutdown = true; }
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()) { MessageBox.Show("Can't find Hearthstone window."); Logger.WriteLine("Can't find Hearthstone window.", "ArenaImport"); return; } await Task.Delay(1000); Overlay.ForceHidden = true; 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)DeckExporter.GetXPos(0.92, hsRect.Width, ratio); var startY = 71.0 / 768.0 * hsRect.Height; var strideY = 29.0 / 768.0 * hsRect.Height; int width = (int)Math.Round(hsRect.Width * xScale); int 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 = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle); if (capture != null) { var yellowPixels = 0; for (int x = 0; x < width; x++) { for (int 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 System.Drawing.Point(posX, (int)startY); var previousPos = System.Windows.Forms.Cursor.Position; User32.ClientToScreen(hsHandle, ref clientPoint); System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y); for (int 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 (int i = 0; i < remainingCards; i++) { var posY = (int)(startY + strideY * i); var capture = Helper.CaptureHearthstone(new System.Drawing.Point(posX, posY), width, height, hsHandle); if (capture != null) { var yellowPixels = 0; for (int x = 0; x < width; x++) { for (int 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 + 21 + ".png"); var yellowPixelRatio = yellowPixels / (double)(width * height); if (yellowPixelRatio > 0.25 && yellowPixelRatio < 50) { deck.Cards[numVisibleCards + i].Count = 2; } } } System.Windows.Forms.Cursor.Position = new System.Drawing.Point(clientPoint.X, clientPoint.Y); for (int 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; } Overlay.ForceHidden = false; Overlay.UpdatePosition(); ActivateWindow(); }
public static async Task Export(Deck deck) { if (deck == null) { return; } 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()) { MessageBox.Show("Can't find Heartstone window."); return; } var hsRect = User32.GetHearthstoneRect(false); var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); string oldClipboardContent = null; try { oldClipboardContent = Clipboard.GetText(); } catch { } var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)), (int)(Config.Instance.ExportSearchBoxY * hsRect.Height)); var cardPosX = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio); var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio); var cardPosY = Config.Instance.ExportCardsY * 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, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsHandle); } // Clear search field now all cards have been entered await ClickOnPoint(hsHandle, searchBoxPos); SendKeys.SendWait("{DELETE}"); SendKeys.SendWait("{ENTER}"); try { if (oldClipboardContent != null) { Clipboard.SetText(oldClipboardContent); } } catch { } }
//returns the number of missing cards private static async Task <int> AddCardToDeck(Card card, Point searchBoxPos, double cardPosX, double card2PosX, double cardPosY, int height, int width, IntPtr hsHandle) { if (!User32.IsHearthstoneInForeground()) { Helper.MainWindow.ShowMessage("Exporting aborted", "Hearthstone window lost focus."); Logger.WriteLine("Exporting aborted, window lost focus", "DeckExporter"); return(-1); } await ClickOnPoint(hsHandle, searchBoxPos); var addArtist = new[] { "zhCN", "zhTW", "ruRU", "koKR" }.All(x => Config.Instance.SelectedLanguage != x); var fixedName = addArtist ? (card.LocalizedName + " " + card.Artist).ToLowerInvariant() : card.LocalizedName.ToLowerInvariant(); if (Config.Instance.ExportPasteClipboard) { Clipboard.SetText(fixedName); SendKeys.SendWait("^v"); } else { SendKeys.SendWait(fixedName); } SendKeys.SendWait("{ENTER}"); Logger.WriteLine("try to export card: " + card.Name, "DeckExporter", 1); await Task.Delay(Config.Instance.DeckExportDelay * 2); if (await CheckForSpecialCases(card, cardPosX + 50, card2PosX + 50, cardPosY + 50, hsHandle)) { return(0); } //Check if Card exist in collection if (CardExists(hsHandle, (int)cardPosX, (int)cardPosY)) { //move mouse over card if card is new TODO: currently does nothing /*var newCard = new Point((int)cardPosX, (int)cardPosY); * User32.ClientToScreen(hsHandle, ref newCard); * for(var i = 0; i < 3; i++) * Cursor.Position = new Point(newCard.X + i + 50, newCard.Y - i + 50);*/ //Check if a golden exist if (Config.Instance.PrioritizeGolden && CardExists(hsHandle, (int)card2PosX, (int)cardPosY)) { await ClickOnPoint(hsHandle, new Point((int)card2PosX + 50, (int)cardPosY + 50)); if (card.Count == 2) { await ClickOnPoint(hsHandle, new Point((int)card2PosX + 50, (int)cardPosY + 50)); await ClickOnPoint(hsHandle, new Point((int)cardPosX + 50, (int)cardPosY + 50)); } } else { await ClickOnPoint(hsHandle, new Point((int)cardPosX + 50, (int)cardPosY + 50)); if (card.Count == 2) { //Check if two card are not available await Task.Delay(100); if (CardHasLock(hsHandle, (int)(cardPosX + width * 0.048), (int)(cardPosY + height * 0.287))) { return(1); } await ClickOnPoint(hsHandle, new Point((int)cardPosX + 50, (int)cardPosY + 50)); } } } else { return(card.Count); } return(0); }
public static async Task Export(Deck deck) { if (deck == null) { return; } string Current_Clipboard = ""; try { if (Config.Instance.ExportPasteClipboard && Clipboard.ContainsText()) { Current_Clipboard = Clipboard.GetText(); } Logger.WriteLine(string.Format("Exporting " + deck.GetDeckInfo()), "DeckExporter"); 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()) { MessageBox.Show("Can't find Heartstone window."); Logger.WriteLine("Can't find Hearthstone window.", "DeckExporter"); return; } Logger.WriteLine("Waiting for " + Config.Instance.ExportStartDelay + " seconds before starting the export process", "DeckExporter"); await Task.Delay(Config.Instance.ExportStartDelay * 1000); var hsRect = User32.GetHearthstoneRect(false); var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)), (int)(Config.Instance.ExportSearchBoxY * hsRect.Height)); var cardPosX = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio); var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio); var cardPosY = Config.Instance.ExportCardsY * hsRect.Height; Helper.MainWindow.Overlay.ForceHidden = true; Helper.MainWindow.Overlay.UpdatePosition(); if (Config.Instance.AutoClearDeck) { await ClearDeck(hsRect.Width, hsRect.Height, hsHandle, ratio); } if (Config.Instance.ExportSetDeckName) { await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle); } await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle); Logger.WriteLine("Creating deck...", "DeckExporter"); deck.MissingCards.Clear(); foreach (var card in deck.Cards) { var missingCardsCount = await AddCardToDeck(card, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsRect.Width, hsHandle); if (missingCardsCount < 0) { return; } if (missingCardsCount > 0) { var missingCard = (Card)card.Clone(); missingCard.Count = missingCardsCount; deck.MissingCards.Add(missingCard); } } if (deck.MissingCards.Any()) { DeckList.Save(); } // Clear search field now all cards have been entered await ClickOnPoint(hsHandle, searchBoxPos); SendKeys.SendWait("{DELETE}"); SendKeys.SendWait("{ENTER}"); if (Config.Instance.ExportPasteClipboard) { Clipboard.Clear(); } Logger.WriteLine("Done creating deck.", "DeckExporter"); } catch (Exception e) { Logger.WriteLine("Error exporting deck: " + e, "DeckExporter"); } finally { Helper.MainWindow.Overlay.ForceHidden = false; Helper.MainWindow.Overlay.UpdatePosition(); if (Config.Instance.ExportPasteClipboard && Current_Clipboard != "") { Clipboard.SetText(Current_Clipboard); } } }
private async void UpdateOverlayAsync() { var hsForegroundChanged = false; while (_doUpdate) { if (User32.GetHearthstoneWindow() != IntPtr.Zero) { Overlay.UpdatePosition(); if (!_tempUpdateCheckDisabled && Config.Instance.CheckForUpdates) { if (!Game.IsRunning && (DateTime.Now - _lastUpdateCheck) > new TimeSpan(0, 10, 0)) { Version newVersion; var currentVersion = Helper.CheckForUpdates(out newVersion); if (currentVersion != null && newVersion != null) { ShowNewUpdateMessage(newVersion); } _lastUpdateCheck = DateTime.Now; } } Game.IsRunning = true; if (!User32.IsHearthstoneInForeground() && !hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { PlayerWindow.Topmost = false; OpponentWindow.Topmost = false; TimerWindow.Topmost = false; } hsForegroundChanged = true; } else if (hsForegroundChanged && User32.IsHearthstoneInForeground()) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? OpponentWindow.Topmost = true; PlayerWindow.Topmost = true; TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else { Overlay.ShowOverlay(false); if (Game.IsRunning) { //game was closed Logger.WriteLine("Exited game"); HsLogReader.Instance.ClearLog(); Game.Reset(); if (DeckPickerList.SelectedDeck != null) { Game.SetPremadeDeck((Deck)DeckPickerList.SelectedDeck.Clone()); } HsLogReader.Instance.Reset(true); if (Config.Instance.CloseWithHearthstone) { Close(); } } Game.IsRunning = false; } await Task.Delay(Config.Instance.UpdateDelay); } _canShowDown = true; }
private static async Task AddCardToDeck(Card card, Point searchBoxPos, double cardPosX, double card2PosX, double cardPosY, int height, IntPtr hsHandle) { if (!User32.IsHearthstoneInForeground()) { Helper.MainWindow.ShowMessage("Exporting aborted", "Hearthstone window lost focus."); Logger.WriteLine("Exporting aborted, window lost focus", "DeckExporter"); return; } await ClickOnPoint(hsHandle, searchBoxPos); var addArtist = new[] { "zhCN", "zhTW", "ruRU", "koKR" }.All(x => Config.Instance.SelectedLanguage != x); var fixedName = addArtist ? (card.LocalizedName + " " + card.Artist).ToLowerInvariant() : card.LocalizedName.ToLowerInvariant(); if (Config.Instance.ExportPasteClipboard) { Clipboard.SetText(fixedName); SendKeys.SendWait("^v"); } else { SendKeys.SendWait(fixedName); } SendKeys.SendWait("{ENTER}"); await Task.Delay(Config.Instance.DeckExportDelay * 2); if (await CheckForSpecialCases(card, cardPosX, card2PosX, cardPosY, hsHandle)) { return; } var golden = CheckForGolden(hsHandle, new Point((int)card2PosX, (int)(cardPosY + height * 0.05))); for (var i = 0; i < card.Count; i++) { if (Config.Instance.PrioritizeGolden && golden) { await ClickOnPoint(hsHandle, new Point((int)card2PosX, (int)cardPosY)); } else { await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); } } if (card.Count == 2 && golden) { //click again to make sure we get 2 cards if (Config.Instance.PrioritizeGolden) { await ClickOnPoint(hsHandle, new Point((int)cardPosX, (int)cardPosY)); } else { await ClickOnPoint(hsHandle, new Point((int)card2PosX, (int)cardPosY)); } } }
public static async Task Export(Deck deck) { if (deck == null) { return; } try { Logger.WriteLine(string.Format("Exporting " + deck.GetDeckInfo(), "DeckExporter")); 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()) { MessageBox.Show("Can't find Heartstone window."); Logger.WriteLine("Can't find Hearthstone window.", "DeckExporter"); return; } var hsRect = User32.GetHearthstoneRect(false); var ratio = (4.0 / 3.0) / ((double)hsRect.Width / hsRect.Height); string oldClipboardContent = null; try { oldClipboardContent = Clipboard.GetText(); } catch { } var searchBoxPos = new Point((int)(GetXPos(Config.Instance.ExportSearchBoxX, hsRect.Width, ratio)), (int)(Config.Instance.ExportSearchBoxY * hsRect.Height)); var cardPosX = GetXPos(Config.Instance.ExportCard1X, hsRect.Width, ratio); var card2PosX = GetXPos(Config.Instance.ExportCard2X, hsRect.Width, ratio); var cardPosY = Config.Instance.ExportCardsY * hsRect.Height; Helper.MainWindow.Overlay.ForceHidden = true; Helper.MainWindow.Overlay.UpdatePosition(); if (Config.Instance.AutoClearDeck) { await ClearDeck(hsRect.Width, hsRect.Height, hsHandle, ratio); } if (Config.Instance.ExportSetDeckName) { await SetDeckName(deck.Name, ratio, hsRect.Width, hsRect.Height, hsHandle); } await ClickAllCrystal(ratio, hsRect.Width, hsRect.Height, hsHandle); Logger.WriteLine("Creating deck...", "DeckExporter"); foreach (var card in deck.Cards) { await AddCardToDeck(card, searchBoxPos, cardPosX, card2PosX, cardPosY, hsRect.Height, hsHandle); } // Clear search field now all cards have been entered await ClickOnPoint(hsHandle, searchBoxPos); SendKeys.SendWait("{DELETE}"); SendKeys.SendWait("{ENTER}"); try { if (oldClipboardContent != null) { Clipboard.SetText(oldClipboardContent); } } catch { } Logger.WriteLine("Done creating deck.", "DeckExporter"); } catch (Exception e) { Logger.WriteLine("Error exporting deck: " + e.Message, "DeckExporter"); } finally { Helper.MainWindow.Overlay.ForceHidden = false; Helper.MainWindow.Overlay.UpdatePosition(); } }
private static async void UpdateOverlayAsync() { #if (!SQUIRREL) if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(true); } #endif var hsForegroundChanged = false; while (UpdateOverlay) { if (Config.Instance.CheckForUpdates) { Updater.CheckForUpdates(); } if (User32.GetHearthstoneWindow() != IntPtr.Zero) { if (Game.CurrentRegion == Region.UNKNOWN) { //game started Helper.VerifyHearthstonePath(); Game.CurrentRegion = await Helper.GetCurrentRegion(); if (Game.CurrentRegion != Region.UNKNOWN) { BackupManager.Run(); Game.MetaData.HearthstoneBuild = null; } Watchers.ExperienceWatcher.Run(); } Overlay.UpdatePosition(); if (!Game.IsRunning) { Overlay.Update(true); Windows.CapturableOverlay?.UpdateContentVisibility(); } TrayIcon.MenuItemStartHearthstone.Visible = false; Game.IsRunning = true; GameIsRunningChanged?.Invoke(true); Helper.GameWindowState = User32.GetHearthstoneWindowState(); Windows.CapturableOverlay?.Update(); if (User32.IsHearthstoneInForeground() && Helper.GameWindowState != WindowState.Minimized) { if (hsForegroundChanged) { Overlay.Update(true); if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { //if player topmost is set to true before opponent: //clicking on the playerwindow and back to hs causes the playerwindow to be behind hs. //other way around it works for both windows... what? Windows.OpponentWindow.Topmost = true; Windows.PlayerWindow.Topmost = true; Windows.TimerWindow.Topmost = true; } hsForegroundChanged = false; } } else if (!hsForegroundChanged) { if (Config.Instance.WindowsTopmostIfHsForeground && Config.Instance.WindowsTopmost) { Windows.PlayerWindow.Topmost = false; Windows.OpponentWindow.Topmost = false; Windows.TimerWindow.Topmost = false; } hsForegroundChanged = true; } } else if (Game.IsRunning) { Game.IsRunning = false; GameIsRunningChanged?.Invoke(false); Overlay.ShowOverlay(false); Watchers.Stop(); if (Windows.CapturableOverlay != null) { Windows.CapturableOverlay.UpdateContentVisibility(); await Task.Delay(100); Windows.CapturableOverlay.ForcedWindowState = WindowState.Minimized; Windows.CapturableOverlay.WindowState = WindowState.Minimized; } Log.Info("Exited game"); Game.CurrentRegion = Region.UNKNOWN; Log.Info("Reset region"); await Reset(); Game.IsInMenu = true; Game.InvalidateMatchInfoCache(); Overlay.HideRestartRequiredWarning(); Helper.ClearCachedHearthstoneBuild(); TurnTimer.Instance.Stop(); TrayIcon.MenuItemStartHearthstone.Visible = true; if (Config.Instance.CloseWithHearthstone) { MainWindow.Close(); } } await Task.Delay(UpdateDelay); } CanShutdown = true; }