Ejemplo n.º 1
0
        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);
            }
        }
Ejemplo n.º 2
0
        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);
            }
        }
Ejemplo n.º 3
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.º 4
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);
                }
            }
        }
Ejemplo n.º 6
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();
            }
        }