예제 #1
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();
		}
예제 #2
0
 public static Rectangle GetHearthstoneRect(bool dpiScaling) => User32.GetHearthstoneRect(dpiScaling);
예제 #3
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;
                        }
                    }
                    Overlay.UpdatePosition();

                    if (!Game.IsRunning)
                    {
                        Overlay.Update(true);
                        Windows.CapturableOverlay?.UpdateContentVisibility();
                    }

                    MainWindow.BtnStartHearthstone.Visibility = Visibility.Collapsed;
                    TrayIcon.MenuItemStartHearthstone.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();
                    Helper.ClearCachedHearthstoneBuild();
                    TurnTimer.Instance.Stop();

                    MainWindow.BtnStartHearthstone.Visibility = Visibility.Visible;
                    TrayIcon.MenuItemStartHearthstone.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;
        }
        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
            {
            }
        }
예제 #5
0
 public static Rectangle GetHearthstoneRect(bool dpiScaling)
 {
     return(User32.GetHearthstoneRect(dpiScaling));
 }