コード例 #1
0
        private static bool CheckForGolden(IntPtr wndHandle, Point point)
        {
            const int   width = 50, height = 50, targetHue = 43;
            const float targetSat = 0.38f;
            var         avgHue    = 0.0f;
            var         avgSat    = 0.0f;
            var         capture   = Helper.CaptureHearthstone(point, width, height, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            var validPixels = 0;

            for (var i = 0; i < width; i++)
            {
                for (var j = 0; j < height; j++)
                {
                    var pixel = capture.GetPixel(i, j);

                    //ignore sparkle
                    if (pixel.GetSaturation() > 0.05)
                    {
                        avgHue += pixel.GetHue();
                        avgSat += pixel.GetSaturation();
                        validPixels++;
                    }
                }
            }
            avgHue /= validPixels;
            avgSat /= validPixels;

            return(avgHue <= targetHue && avgSat <= targetSat);
        }
コード例 #2
0
        private static bool CheckForCardsInDeck(IntPtr wndHandle, int width, int height, double ratio)
        {
            var capture = Helper.CaptureHearthstone(new Point((int)GetXPos(Config.Instance.ExportClearX, width, ratio), (int)(Config.Instance.ExportClearCheckYFixed * height)), 1,
                                                    1, wndHandle);

            return(ColorDistance(capture.GetPixel(0, 0), Color.FromArgb(255, 56, 45, 69), 5));
        }
コード例 #3
0
        private static bool CardHasLock(IntPtr wndHandle, int posX, int posY)
        {
            const int    width         = 55;
            const int    height        = 30;
            const double maxBrightness = 5.0 / 11.0;

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), width, height, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Brightness < maxBrightness);
        }
コード例 #4
0
        private static bool CardExists(IntPtr wndHandle, int posX, int posY)
        {
            const int    width  = 40;
            const int    height = 40;
            const double minHue = 90;

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), width, height, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Hue > minHue);
        }
コード例 #5
0
        private static bool CardExists(IntPtr wndHandle, int posX, int posY, int width, int height)
        {
            const double scale  = 0.037;            // 40px @ height = 1080
            const double minHue = 90;

            int size = (int)Math.Round(height * scale);

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), size, size, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Hue > minHue);
        }
コード例 #6
0
        // checks the zero crystal, to see if it is selected
        private static bool IsZeroCrystalSelected(IntPtr wndHandle, double ratio, int width, int height)
        {
            const int    cWidth        = 22;
            const int    cHeight       = 22;
            const double minBrightness = 0.55;

            int posX = (int)GetXPos(Config.Instance.ExportZeroSquareX, width, ratio);
            int posY = (int)(Config.Instance.ExportZeroSquareY * height);

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), cWidth, cHeight, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Brightness > minBrightness);
        }
コード例 #7
0
        private static bool CardHasLock(IntPtr wndHandle, int posX, int posY, int width, int height)
        {
            // setting this as a "width" value relative to height, maybe not best solution?
            const double xScale        = 0.051;      // 55px @ height = 1080
            const double yScale        = 0.0278;     // 30px @ height = 1080
            const double maxBrightness = 5.0 / 11.0;

            int lockWidth  = (int)Math.Round(height * xScale);
            int lockHeight = (int)Math.Round(height * yScale);

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), lockWidth, lockHeight, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Brightness < maxBrightness);
        }
コード例 #8
0
        private static bool IsZeroCrystalSelected(IntPtr wndHandle, double ratio, int width, int height)
        {
            const double scale         = 0.020;     // 22px @ height = 1080
            const double minBrightness = 0.55;

            int size = (int)Math.Round(height * scale);

            int posX = (int)GetXPos(Config.Instance.ExportZeroSquareX, width, ratio);
            int posY = (int)(Config.Instance.ExportZeroSquareY * height);

            var capture = Helper.CaptureHearthstone(new Point(posX, posY), size, size, wndHandle);

            if (capture == null)
            {
                return(false);
            }

            return(GetAverageHueAndBrightness(capture).Brightness > minBrightness);
        }
コード例 #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();
        }