Example #1
0
        private async void BtnExport_Click(object sender, RoutedEventArgs e)
        {
            var deck = Helper.MainWindow.DeckPickerList.SelectedDeck;

            if (deck == null)
            {
                return;
            }

            var result = await Helper.MainWindow.ShowMessageAsync("Export " + deck.Name + " to Hearthstone",
                                                                  "Please create a new, empty " + deck.Class +
                                                                  "-Deck in Hearthstone before continuing (leave the deck creation screen open).\nDo not move your mouse after clicking OK!",
                                                                  MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                var controller =
                    await Helper.MainWindow.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Helper.MainWindow.Topmost = false;
                await Task.Delay(500);

                await DeckExporter.Export(Helper.MainWindow.DeckPickerList.SelectedDeck);

                await controller.CloseAsync();
            }

            After_Click();
        }
Example #2
0
        private async void ExportDeck(Deck deck)
        {
            var message = "Please create a new, empty " + deck.Class +
                          "-Deck in Hearthstone before continuing (leave the deck creation screen open).\nDo not move your mouse after clicking OK!";

            if (deck.Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen"))
            {
                message += "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting";
            }

            var result = await this.ShowMessageAsync("Export " + deck.Name + " to Hearthstone",
                                                     message,
                                                     MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                var controller =
                    await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Topmost = false;
                await Task.Delay(500);

                await DeckExporter.Export(deck);

                await controller.CloseAsync();
            }
        }
        private async void ExportDeck(Deck deck)
        {
            var message =
                string.Format(
                    "1) create a new, empty {0}-Deck {1}.\n\n2) leave the deck creation screen open.\n\n3)do not move your mouse or type after clicking \"export\"",
                    deck.Class,
                    (Config.Instance.AutoClearDeck ? "(or open an existing one to be cleared automatically)" : ""));

            if (deck.Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen"))
            {
                message += "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting";
            }

            var settings = new MetroDialogSettings {
                AffirmativeButtonText = "export"
            };
            var result = await this.ShowMessageAsync("Export " + deck.Name + " to Hearthstone",
                                                     message,
                                                     MessageDialogStyle.AffirmativeAndNegative, settings);

            if (result == MessageDialogResult.Affirmative)
            {
                var controller =
                    await this.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Topmost = false;
                await Task.Delay(500);

                await DeckExporter.Export(deck);

                await controller.CloseAsync();
            }
        }
Example #4
0
        private async void BtnExport_Click(object sender, RoutedEventArgs e)
        {
            var deck = Helper.MainWindow.DeckPickerList.SelectedDeck;

            if (deck == null)
            {
                return;
            }

            var message = "Please create a new, empty " + deck.Class +
                          "-Deck in Hearthstone before continuing (leave the deck creation screen open).\nDo not move your mouse after clicking OK!";

            if (deck.Cards.Any(c => c.Name == "Stalagg" || c.Name == "Feugen"))
            {
                message += "\n\nIMPORTANT: If you own golden versions of Feugen or Stalagg please make sure to configure\nOptions > Other > Exporting";
            }

            var result = await Helper.MainWindow.ShowMessageAsync("Export " + deck.Name + " to Hearthstone",
                                                                  message,
                                                                  MessageDialogStyle.AffirmativeAndNegative);

            if (result == MessageDialogResult.Affirmative)
            {
                var controller =
                    await Helper.MainWindow.ShowProgressAsync("Creating Deck", "Please do not move your mouse or type.");

                Helper.MainWindow.Topmost = false;
                await Task.Delay(500);

                await DeckExporter.Export(Helper.MainWindow.DeckPickerList.SelectedDeck);

                await controller.CloseAsync();
            }

            After_Click();
        }
Example #5
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();
        }
		public MainWindow()
		{
			InitializeComponent();

			var version = Helper.CheckForUpdates(out _newVersion);
			if (version != null)
			{
				TxtblockVersion.Text = string.Format("Version: {0}.{1}.{2}", version.Major, version.Minor,
													 version.Build);
			}

			#region load config
			_config = new Config();
			_xmlManagerConfig = new XmlManager<Config> { Type = typeof(Config) };

			bool foundConfig = false;
			try
			{
				if (File.Exists("config.xml"))
				{
					_config = _xmlManagerConfig.Load("config.xml");
					foundConfig = true;
				}
				else if (File.Exists(_config.AppDataPath + @"\config.xml"))
				{
					_config = _xmlManagerConfig.Load(_config.AppDataPath + @"\config.xml");
					foundConfig = true;
				}
				else if (!Directory.Exists(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)))

				//save locally if appdata doesn't exist (when e.g. not on C)
				{
					_config.SaveInAppData = false;
				}

			}
			catch (Exception e)
			{
				MessageBox.Show(
					e.Message + "\n\n" + e.InnerException +
					"\n\n If you don't know how to fix this, please delete " + _config.ConfigPath,
					"Error loading config.xml");
				Application.Current.Shutdown();
			}
			_configPath = _config.ConfigPath;
			if (!foundConfig)
			{
				if (_config.HomeDir != string.Empty)
					Directory.CreateDirectory(_config.HomeDir);
				using (var sr = new StreamWriter(_config.ConfigPath, false))
				{
					sr.WriteLine("<Config></Config>");
				}
			}
			else
			{
				//check if config needs to be moved
				if (_config.SaveInAppData)
				{
					if (File.Exists("config.xml"))
					{
						Directory.CreateDirectory(_config.HomeDir);
						if (File.Exists(_config.ConfigPath))
						{
							//backup in case the file already exists
							File.Move(_configPath, _configPath + DateTime.Now.ToFileTime());
						}
						File.Move("config.xml", _config.ConfigPath);
						Logger.WriteLine("Moved config to appdata");
					}
				}
				else
				{
					if (File.Exists(_config.AppDataPath + @"\config.xml"))
					{
						if (File.Exists(_config.ConfigPath))
						{
							//backup in case the file already exists
							File.Move(_configPath, _configPath + DateTime.Now.ToFileTime());
						}
						File.Move(_config.AppDataPath + @"\config.xml", _config.ConfigPath);
						Logger.WriteLine("Moved config to local");
					}
				}
			}
			#endregion

			if (_config.SelectedTags.Count == 0)
				_config.SelectedTags.Add("All");

			_config.Debug = IS_DEBUG;

			if (_config.GenerateLog)
			{
				Directory.CreateDirectory("Logs");
				var listener = new TextWriterTraceListener(_config.LogFilePath);
				Trace.Listeners.Add(listener);
				Trace.AutoFlush = true;
			}

			#region find hearthstone dir
			if (string.IsNullOrEmpty(_config.HearthstoneDirectory) || !File.Exists(_config.HearthstoneDirectory + @"\Hearthstone.exe"))
			{
				using (var hsDirKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Hearthstone"))
				{
					if (hsDirKey != null)
					{
						var hsDir = (string)hsDirKey.GetValue("InstallLocation");

						//verify the installlocation actually is correct (possibly moved?)
						if (File.Exists(hsDir + @"\Hearthstone.exe"))
						{
							_config.HearthstoneDirectory = hsDir;
							WriteConfig();
							_foundHsDirectory = true;
						}
					}
				}
			}
			else
			{
				_foundHsDirectory = true;
			}

			if (_foundHsDirectory)
			{

				//check for log config and create if not existing
				try
				{
					//always overwrite is true by default. 
					if (!File.Exists(_logConfigPath))
					{
						_updatedLogConfig = true;
						File.Copy("Files/log.config", _logConfigPath, true);
						Logger.WriteLine(string.Format("Copied log.config to {0} (did not exist)", _configPath));
					}
					else
					{
						//update log.config if newer
						var localFile = new FileInfo(_logConfigPath);
						var file = new FileInfo("Files/log.config");
						if (file.LastWriteTime > localFile.LastWriteTime)
						{
							_updatedLogConfig = true;
							File.Copy("Files/log.config", _logConfigPath, true);
							Logger.WriteLine(string.Format("Copied log.config to {0} (file newer)", _configPath));
						}
						else if (_config.AlwaysOverwriteLogConfig)
						{
							File.Copy("Files/log.config", _logConfigPath, true);
							Logger.WriteLine(string.Format("Copied log.config to {0} (AlwaysOverwriteLogConfig)", _configPath));
						}
					}
				}
				catch (Exception e)
				{
					if (_updatedLogConfig)
					{
						MessageBox.Show(
							e.Message + "\n\n" + e.InnerException +
							"\n\n Please manually copy the log.config from the Files directory to \"%LocalAppData%/Blizzard/Hearthstone\".",
							"Error writing log.config");
						Application.Current.Shutdown();
					}
				}
			}
			#endregion

			string languageTag = _config.SelectedLanguage;
			//hearthstone, loads db etc - needs to be loaded before playerdecks, since cards are only saved as ids now
			_game = Helper.LanguageDict.ContainsValue(languageTag) ? new Game(languageTag) : new Game("enUS");
			_game.Reset();

			#region playerdecks
			_decksPath = _config.HomeDir + "PlayerDecks.xml";

			if (_config.SaveInAppData)
			{
				if (File.Exists("PlayerDecks.xml"))
				{
					if (File.Exists(_decksPath))
					{
						//backup in case the file already exists
						File.Move(_decksPath, _decksPath + DateTime.Now.ToFileTime());
					}
					File.Move("PlayerDecks.xml", _decksPath);
					Logger.WriteLine("Moved decks to appdata");
				}
			}
			else
			{
				var appDataPath = _config.AppDataPath + @"\PlayerDecks.xml";
				if (File.Exists(appDataPath))
				{
					if (File.Exists(_decksPath))
					{
						//backup in case the file already exists
						File.Move(_decksPath, _decksPath + DateTime.Now.ToFileTime());
					}
					File.Move(appDataPath, _decksPath);
					Logger.WriteLine("Moved decks to local");
				}
			}

			//load saved decks
			if (!File.Exists(_decksPath))
			{
				//avoid overwriting decks file with new releases.
				using (var sr = new StreamWriter(_decksPath, false))
				{
					sr.WriteLine("<Decks></Decks>");
				}
			}
			else
			{
				//the new playerdecks.xml wont work with versions below 0.2.19, make copy
				if (!File.Exists(_decksPath + ".old"))
				{
					File.Copy(_decksPath, _decksPath + ".old");
				}
			}

			_xmlManager = new XmlManager<Decks> { Type = typeof(Decks) };
			try
			{
				_deckList = _xmlManager.Load(_decksPath);
			}
			catch (Exception e)
			{
				MessageBox.Show(
					e.Message + "\n\n" + e.InnerException +
					"\n\n If you don't know how to fix this, please delete " + _decksPath + " (this will cause you to lose your decks).",
					"Error loading PlayerDecks.xml");
				Application.Current.Shutdown();
			}
			#endregion

			foreach (var deck in _deckList.DecksList)
			{
				DeckPickerList.AddDeck(deck);
			}
			DeckPickerList.SelectedDeckChanged += DeckPickerListOnSelectedDeckChanged;

			_notifyIcon = new System.Windows.Forms.NotifyIcon();
			_notifyIcon.Icon = new Icon(@"Images/HearthstoneDeckTracker.ico");
			_notifyIcon.MouseDoubleClick += NotifyIconOnMouseDoubleClick;
			_notifyIcon.Visible = false;

			_xmlManagerDeck = new XmlManager<Deck>();
			_xmlManagerDeck.Type = typeof(Deck);

			_newDeck = new Deck();
			ListViewNewDeck.ItemsSource = _newDeck.Cards;


			//create overlay
			_overlay = new OverlayWindow(_config, _game) { Topmost = true };
			if (_foundHsDirectory)
			{
				_overlay.Show();
			}
			_playerWindow = new PlayerWindow(_config, _game.IsUsingPremade ? _game.PlayerDeck : _game.PlayerDrawn);
			_opponentWindow = new OpponentWindow(_config, _game.OpponentCards);
			_timerWindow = new TimerWindow(_config);

			if (_config.WindowsOnStartup)
			{
				_playerWindow.Show();
				_opponentWindow.Show();
			}
			if (_config.TimerWindowOnStartup)
			{
				_timerWindow.Show();
			}
			if (!_deckList.AllTags.Contains("All"))
			{
				_deckList.AllTags.Add("All");
				WriteDecks();
			}
			if (!_deckList.AllTags.Contains("Arena"))
			{
				_deckList.AllTags.Add("Arena");
				WriteDecks();
			}
			if (!_deckList.AllTags.Contains("Constructed"))
			{
				_deckList.AllTags.Add("Constructed");
				WriteDecks();
			}

			ComboboxAccent.ItemsSource = ThemeManager.Accents;
			ComboboxTheme.ItemsSource = ThemeManager.AppThemes;
			ComboboxLanguages.ItemsSource = Helper.LanguageDict.Keys;

			ComboboxKeyPressGameStart.ItemsSource = EventKeys.Split(',');
			ComboboxKeyPressGameEnd.ItemsSource = EventKeys.Split(',');

			LoadConfig();

			_deckImporter = new DeckImporter(_game);
			_deckExporter = new DeckExporter(_config);

			//this has to happen before reader starts
			var lastDeck = _deckList.DecksList.FirstOrDefault(d => d.Name == _config.LastDeck);
			DeckPickerList.SelectDeck(lastDeck);

			//deck options flyout button events
			DeckOptionsFlyout.BtnDeleteDeck.Click += DeckOptionsFlyoutBtnDeleteDeck_Click;
			DeckOptionsFlyout.BtnExportHs.Click += DeckOptionsFlyoutBtnExportHs_Click;
			DeckOptionsFlyout.BtnNotes.Click += DeckOptionsFlyoutBtnNotes_Click;
			DeckOptionsFlyout.BtnScreenshot.Click += DeckOptionsFlyoutBtnScreenhot_Click;
			DeckOptionsFlyout.BtnCloneDeck.Click += DeckOptionsFlyoutCloneDeck_Click;
			DeckOptionsFlyout.BtnTags.Click += DeckOptionsFlyoutBtnTags_Click;
			DeckOptionsFlyout.BtnSaveToFile.Click += DeckOptionsFlyoutBtnSaveToFile_Click;
			DeckOptionsFlyout.BtnClipboard.Click += DeckOptionsFlyoutBtnClipboard_Click;

			DeckOptionsFlyout.DeckOptionsButtonClicked += CloseDeckOptionsFlyout;

			//deck import flyout button events
			DeckImportFlyout.BtnWeb.Click += DeckImportFlyoutBtnWebClick;
			DeckImportFlyout.BtnArenavalue.Click += DeckImportFlyoutBtnArenavalue_Click;
			DeckImportFlyout.BtnFile.Click += DeckImportFlyoutBtnFile_Click;
			DeckImportFlyout.BtnIdString.Click += DeckImportFlyoutBtnIdString_Click;

			DeckImportFlyout.DeckOptionsButtonClicked += CloseDeckImportFlyout;

			//log reader
			_logReader = new HsLogReader(_config.HearthstoneDirectory, _config.UpdateDelay);
			_logReader.CardMovement += LogReaderOnCardMovement;
			_logReader.GameStateChange += LogReaderOnGameStateChange;
			_logReader.Analyzing += LogReaderOnAnalyzing;
			_logReader.TurnStart += LogReaderOnTurnStart;
			_logReader.CardPosChange += LogReaderOnCardPosChange;
			_logReader.SecretPlayed += LogReaderOnSecretPlayed;

			_turnTimer = new TurnTimer(90);
			_turnTimer.TimerTick += TurnTimerOnTimerTick;

			TagControlFilter.HideStuffToCreateNewTag();
			TagControlNewDeck.OperationSwitch.Visibility = Visibility.Collapsed;
			TagControlMyDecks.OperationSwitch.Visibility = Visibility.Collapsed;

			TagControlNewDeck.NewTag += TagControlOnNewTag;
			TagControlNewDeck.SelectedTagsChanged += TagControlOnSelectedTagsChanged;
			TagControlNewDeck.DeleteTag += TagControlOnDeleteTag;
			TagControlMyDecks.NewTag += TagControlOnNewTag;
			TagControlMyDecks.SelectedTagsChanged += TagControlOnSelectedTagsChanged;
			TagControlMyDecks.DeleteTag += TagControlOnDeleteTag;
			TagControlFilter.SelectedTagsChanged += TagControlFilterOnSelectedTagsChanged;
			TagControlFilter.OperationChanged += TagControlFilterOnOperationChanged;


			UpdateDbListView();

			_doUpdate = _foundHsDirectory;
			UpdateOverlayAsync();

			_initialized = true;

			DeckPickerList.UpdateList();
			if (lastDeck != null)
			{
				DeckPickerList.SelectDeck(lastDeck);
				UpdateDeckList(lastDeck);
				UseDeck(lastDeck);
			}

			if (_foundHsDirectory)
			{
				_logReader.Start();
			}

			Helper.SortCardCollection(ListViewDeck.Items, _config.CardSortingClassFirst);

		}