Ejemplo n.º 1
0
        public static async Task <Bitmap> CaptureHearthstoneAsync(Point point, int width, int height, IntPtr wndHandle = default(IntPtr),
                                                                  bool requireInForeground = true, bool?altScreenCapture = null)
        {
            if (wndHandle == default(IntPtr))
            {
                wndHandle = User32.GetHearthstoneWindow();
            }

            if (requireInForeground && !User32.IsHearthstoneInForeground())
            {
                return(null);
            }

            try
            {
                if (altScreenCapture ?? Config.Instance.AlternativeScreenCapture)
                {
                    return(await Task.Run(() => CaptureWindow(wndHandle, point, width, height)));
                }
                return(await Task.Run(() => CaptureScreen(wndHandle, point, width, height)));
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error capturing hearthstone: " + ex, "Helper");
                return(null);
            }
        }
Ejemplo n.º 2
0
        public static Bitmap CaptureHearthstone(Point point, int width, int height, IntPtr wndHandle = default(IntPtr),
                                                bool requireInForeground = true)
        {
            if (wndHandle == default(IntPtr))
            {
                wndHandle = User32.GetHearthstoneWindow();
            }

            User32.ClientToScreen(wndHandle, ref point);
            if (requireInForeground && !User32.IsHearthstoneInForeground())
            {
                return(null);
            }

            try
            {
                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);
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error capturing hearthstone: " + ex, "Helper");
                return(null);
            }
        }
Ejemplo n.º 3
0
 private async void BtnUnlockOverlay_Click(object sender, RoutedEventArgs e)
 {
     if (User32.GetHearthstoneWindow() == IntPtr.Zero)
     {
         return;
     }
     BtnUnlockOverlay.Content = await Helper.MainWindow.Overlay.UnlockUI() ? "Lock" : "Unlock";
 }
Ejemplo n.º 4
0
        public static async Task StartHearthstoneAsync()
        {
            if (User32.GetHearthstoneWindow() != IntPtr.Zero)
            {
                return;
            }
            Core.MainWindow.BtnStartHearthstone.IsEnabled = false;
            var useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone");

            Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Enabled = false;
            try
            {
                var bnetProc = Process.GetProcessesByName("Battle.net").FirstOrDefault();
                if (bnetProc == null)
                {
                    Process.Start("battlenet://");

                    var foundBnetWindow = false;
                    Core.MainWindow.TextBlockBtnStartHearthstone.Text = "STARTING LAUNCHER...";
                    for (var i = 0; i < 40; i++)
                    {
                        bnetProc = Process.GetProcessesByName("Battle.net").FirstOrDefault();
                        if (bnetProc != null && bnetProc.MainWindowHandle != IntPtr.Zero)
                        {
                            foundBnetWindow = true;
                            break;
                        }
                        await Task.Delay(500);
                    }
                    Core.MainWindow.TextBlockBtnStartHearthstone.Text = "START LAUNCHER / HEARTHSTONE";
                    if (!foundBnetWindow)
                    {
                        Core.MainWindow.ShowMessageAsync("Problem starting Battle.net launcher",
                                                         "Starting the Battle.net launcher failed or was too slow. Please try again once it started or run Hearthstone manually.").Forget();
                        Core.MainWindow.BtnStartHearthstone.IsEnabled = true;
                        return;
                    }
                }
                await Task.Delay(2000);                 //just to make sure

                Process.Start("battlenet://WTCG");
            }
            catch (Exception ex)
            {
                Log.Error(ex);
            }

            Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Enabled = true;
            Core.MainWindow.BtnStartHearthstone.IsEnabled = true;
        }
Ejemplo n.º 5
0
        public static async Task StartHearthstoneAsync()
        {
            if (User32.GetHearthstoneWindow() != IntPtr.Zero)
            {
                return;
            }
            Core.MainWindow.BtnStartHearthstone.IsEnabled = false;
            int useNoDeckMenuItem = Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems.IndexOfKey("startHearthstone");

            Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Enabled = false;
            try
            {
                var bnetProc = Process.GetProcessesByName("Battle.net").FirstOrDefault();
                if (bnetProc == null)
                {
                    Process.Start("battlenet://");

                    var foundBnetWindow = false;
                    Core.MainWindow.TextBlockBtnStartHearthstone.Text = "STARTING LAUNCHER...";
                    for (int i = 0; i < 20; i++)
                    {
                        bnetProc = Process.GetProcessesByName("Battle.net").FirstOrDefault();
                        if (bnetProc != null && bnetProc.MainWindowHandle != IntPtr.Zero)
                        {
                            foundBnetWindow = true;
                            break;
                        }
                        await Task.Delay(500);
                    }
                    Core.MainWindow.TextBlockBtnStartHearthstone.Text = "START LAUNCHER / HEARTHSTONE";
                    if (!foundBnetWindow)
                    {
                        Core.MainWindow.ShowMessageAsync("Error starting battle.net launcher", "Could not find or start the battle.net launcher.");
                        Core.MainWindow.BtnStartHearthstone.IsEnabled = true;
                        return;
                    }
                }
                await Task.Delay(2000); //just to make sure

                Process.Start("battlenet://WTCG");
            }
            catch (Exception ex)
            {
                Logger.WriteLine("Error starting launcher/hearthstone: " + ex);
            }

            Core.TrayIcon.NotifyIcon.ContextMenu.MenuItems[useNoDeckMenuItem].Enabled = true;
            Core.MainWindow.BtnStartHearthstone.IsEnabled = true;
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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;
        }
Ejemplo n.º 8
0
        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;
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
        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
            {
            }
        }
        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;
        }
Ejemplo n.º 13
0
        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();
            }
        }
Ejemplo n.º 14
0
        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;
        }