diff --git a/SmartHunter/Core/MemoryUpdater.cs b/SmartHunter/Core/MemoryUpdater.cs index 4b5a275..595b544 100644 --- a/SmartHunter/Core/MemoryUpdater.cs +++ b/SmartHunter/Core/MemoryUpdater.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.IO; +using System.IO.Compression; using System.Linq; using System.Reflection; using System.Windows; @@ -21,6 +22,7 @@ enum State DownloadingUpdates, Restarting, WaitingForProcess, + StartMHW, ProcessFound, FastPatternScanning, PatternScanning, @@ -36,10 +38,12 @@ enum State protected abstract string ProcessName { get; } protected abstract BytePattern[] Patterns { get; } - + protected virtual string UserDataPath { get { return @"C:\Program Files (x86)\Steam\userdata"; } } protected virtual int ThreadsPerScan { get { return 2; } } protected virtual int UpdatesPerSecond { get { return 20; } } protected virtual bool ShutdownWhenProcessExits { get { return false; } } + protected virtual bool BackupWhenProcessExits { get { return false; } } + protected virtual bool StartMHWWhenSmartHunterStart { get { return false; } } protected Process Process { get; private set; } @@ -73,7 +77,7 @@ void CreateStateMachine() Log.WriteLine("Searching for updates (You can disable this feature in file 'Config.json')!"); }), new StateMachine.Transition( - State.WaitingForProcess, + State.StartMHW, () => !ConfigHelper.Main.Values.Overlay.MonsterWidget.UseNetworkServer && !ConfigHelper.Main.Values.AutomaticallyCheckAndDownloadUpdates, () => { @@ -131,7 +135,7 @@ void CreateStateMachine() new StateMachine.Transition[] { new StateMachine.Transition( - State.WaitingForProcess, + State.StartMHW, () => !ConfigHelper.Main.Values.Overlay.MonsterWidget.UseNetworkServer && !updater.CheckForUpdates(), () => { @@ -203,7 +207,7 @@ void CreateStateMachine() Log.WriteLine("Successfully downloaded all files!"); }), new StateMachine.Transition( - State.WaitingForProcess, + State.StartMHW, () => !updater.DownloadUpdates(), () => { @@ -239,7 +243,7 @@ void CreateStateMachine() new StateMachine.Transition[] { new StateMachine.Transition( - State.WaitingForProcess, + State.StartMHW, () => ServerManager.Instance.IsServerOline != 0, () => { @@ -247,35 +251,55 @@ void CreateStateMachine() }) })); - m_StateMachine.Add(State.WaitingForProcess, new StateMachine.StateData( + m_StateMachine.Add(State.StartMHW, new StateMachine.StateData( null, new StateMachine.Transition[] { new StateMachine.Transition( - State.ProcessFound, + State.WaitingForProcess, () => { - var processes = Process.GetProcesses(); - foreach (var p in processes) + if(CheckProcess()) + return true; + if(!StartMHWWhenSmartHunterStart) { - try - { - if (p != null && p.ProcessName.Equals(ProcessName) && !p.HasExited) - { - Process = p; - return true; - } - } - catch + Log.WriteLine("Start MHW When SmartHunter Start = false"); + return true; + } + Log.WriteLine("Start MHW."); + try + { + Process.Start(new ProcessStartInfo { - // nothing here - } + FileName = "steam://run/582010", + Arguments = "", + UseShellExecute = true + }); + return true; + } + catch(Exception ex) + { + Log.WriteException(ex); + return false; } - return false; }, null) })); + m_StateMachine.Add(State.WaitingForProcess, new StateMachine.StateData( + null, + new StateMachine.Transition[] + { + new StateMachine.Transition( + State.ProcessFound, + () => + { + return CheckProcess(); + }, + null) + })); + + m_StateMachine.Add(State.ProcessFound, new StateMachine.StateData( null, new StateMachine.Transition[] @@ -431,7 +455,32 @@ private void Initialize(bool processExited = false) m_MemoryScans = new List(); OverlayViewModel.Instance.IsGameActive = false; - + if (processExited && BackupWhenProcessExits) + { + try + { + string zipPath = @"UserDataBackup\"; + string fileName = DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") + ".zip"; + string filepath = Path.Combine(zipPath, fileName); + if (!Directory.Exists(zipPath)) + Directory.CreateDirectory(zipPath); + if (File.Exists(filepath)) + File.Delete(filepath); + if (Directory.Exists(UserDataPath)) + { + ZipFile.CreateFromDirectory(UserDataPath, filepath); + Log.WriteLine("MonsterHunterWorld process exits. Start backup 'UserData'."); + } + else + { + Log.WriteLine("Backup fail 'UserData' path not exist."); + } + } + catch (Exception ex) + { + Log.WriteException(ex); + } + } if (processExited && ShutdownWhenProcessExits) { Log.WriteLine("Process exited. Shutting down"); @@ -466,5 +515,26 @@ protected void TryUpdateTimerInterval() m_DispatcherTimer.Interval = new TimeSpan(0, 0, 0, 0, targetMilliseconds); } } + + private bool CheckProcess() + { + var processes = Process.GetProcesses(); + foreach (var p in processes) + { + try + { + if (p != null && p.ProcessName.Equals(ProcessName) && !p.HasExited) + { + Process = p; + return true; + } + } + catch + { + // nothing here + } + } + return false; + } } } diff --git a/SmartHunter/Game/Config/LocalizationConfig.cs b/SmartHunter/Game/Config/LocalizationConfig.cs index b626074..c80381f 100644 --- a/SmartHunter/Game/Config/LocalizationConfig.cs +++ b/SmartHunter/Game/Config/LocalizationConfig.cs @@ -443,6 +443,12 @@ public class LocalizationConfig { "LOC_SETTING_RESTART_DESC", "This feature will work on the next open of Smarthunter. Would you like to reopen it now?"}, { "LOC_SETTING_SHUTDOWN_WHEN_PROCESS_EXIT", "Shutdown when process exits"}, { "LOC_SETTING_SHUTDOWN_WHEN_PROCESS_EXIT_DESC", "Shutdown SmartHunter as soon as MonsterHunterWorld is killed"}, + { "LOC_SETTING_START_MHW_WHEN_SMARTHUNTER_START", "Start MHW when smarthunter start."}, + { "LOC_SETTING_START_MHW_WHEN_SMARTHUNTER_START_DESC", "Start MHW when smarthunter start."}, + { "LOC_SETTING_USERADATA_PATH", "'UserData' path"}, + { "LOC_SETTING_USERADATA_PATH_DESC", "Select 'UserData' path"}, + { "LOC_SETTING_BACKUP_WHEN_PROCESS_EXIT", "Backup 'UserData' when 'MonsterHunterWorld process' exits"}, + { "LOC_SETTING_BACKUP_WHEN_PROCESS_EXIT_DESC", ""}, { "LOC_SETTING_AUTO_CHECK_AND_DOWNLOAD_UPDATES", "Automatically check and download updates"}, { "LOC_SETTING_AUTO_CHECK_AND_DOWNLOAD_UPDATES_DESC", "If enabled SmartHunter will automatically check and download new updates"}, { "LOC_SETTING_HIDE_WHEN_GAME_WINDOW_IS_INACTIVE", "Hide when game window is inactive"}, diff --git a/SmartHunter/Game/Config/MainConfig.cs b/SmartHunter/Game/Config/MainConfig.cs index a986182..fc989e0 100644 --- a/SmartHunter/Game/Config/MainConfig.cs +++ b/SmartHunter/Game/Config/MainConfig.cs @@ -13,10 +13,13 @@ public class MainConfig public string PlayerDataFileName = "PlayerData.json"; public string MemoryFileName = "Memory.json"; public string ServerUrl = "http://140.238.55.121/index.php"; + public string UserDataPath = @"C:\Program Files (x86)\Steam\userdata\"; public bool IgnoreHttpsErrors = true; public bool ShutdownWhenProcessExits = false; + public bool BackupWhenProcessExits = false; public bool AutomaticallyCheckAndDownloadUpdates = true; // TODO: Rimetti a true + public bool StartMHWWhenSmartHunterStart = false; public OverlayConfig Overlay = new OverlayConfig(); diff --git a/SmartHunter/Game/Config/MemoryConfig.cs b/SmartHunter/Game/Config/MemoryConfig.cs index 634d837..523df5f 100644 --- a/SmartHunter/Game/Config/MemoryConfig.cs +++ b/SmartHunter/Game/Config/MemoryConfig.cs @@ -17,13 +17,13 @@ public class MemoryConfig public BytePatternConfig CurrentWeaponPattern = new BytePatternConfig( "CurrentWeaponPattern", "48 8B 0D ?? ?? ?? ?? 4C 8D 45 ?? 48 8D 97 ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B D8 48 85 C0 ", - "1411A5D86" + "1411A5DD6" ); public BytePatternConfig PlayerDamagePattern = new BytePatternConfig( "PlayerDamagePattern", "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B D8 48 85 C0 75 04 33 C9", - "141A5EED7" + "141A5EF27" ); public BytePatternConfig PlayerNamePattern = new BytePatternConfig( @@ -41,13 +41,13 @@ public class MemoryConfig public BytePatternConfig PlayerBuffPattern = new BytePatternConfig( "PlayerBuffPattern", "48 8B 05 ?? ?? ?? ?? 41 8B 94 00 ?? ?? ?? ?? 89 57 ??", - "142245571" + "1422455C1" ); public BytePatternConfig SelectedMonsterPattern = new BytePatternConfig( "SelectedMonsterPattern", "48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B 0D ?? ?? ?? ?? E8 ?? ?? ?? ?? 48 8B 05 ?? ?? ?? ?? 83 A0 ?? ?? ?? ?? ?? C6 43 ?? ??", - "141A98242" + "141A98292" ); public BytePatternConfig LobbyStatusPattern = new BytePatternConfig( diff --git a/SmartHunter/Game/Data/ViewModels/SettingsViewModel.cs b/SmartHunter/Game/Data/ViewModels/SettingsViewModel.cs index d0aa38b..d4933f4 100644 --- a/SmartHunter/Game/Data/ViewModels/SettingsViewModel.cs +++ b/SmartHunter/Game/Data/ViewModels/SettingsViewModel.cs @@ -3,7 +3,6 @@ using System.Diagnostics; using System.Reflection; using System.Windows; -using System.Windows.Input; using SmartHunter.Core; using SmartHunter.Core.Data; using SmartHunter.Game.Helpers; @@ -26,7 +25,7 @@ public static SettingsViewModel Instance } } - public List Settings { get; } + public IList Settings { get; } private void restartSmartHunter() { @@ -58,11 +57,33 @@ public SettingsViewModel() } }))); + Settings.Add(new Setting(ConfigHelper.Main.Values.StartMHWWhenSmartHunterStart, GetString("LOC_SETTING_START_MHW_WHEN_SMARTHUNTER_START"), GetString("LOC_SETTING_START_MHW_WHEN_SMARTHUNTER_START_DESC"), new Command(_ => + { + ConfigHelper.Main.Values.StartMHWWhenSmartHunterStart = !ConfigHelper.Main.Values.StartMHWWhenSmartHunterStart; + ConfigHelper.Main.Save(); + }))); + Settings.Add(new Setting(ConfigHelper.Main.Values.ShutdownWhenProcessExits, GetString("LOC_SETTING_SHUTDOWN_WHEN_PROCESS_EXIT"), GetString("LOC_SETTING_SHUTDOWN_WHEN_PROCESS_EXIT_DESC"), new Command(_ => { ConfigHelper.Main.Values.ShutdownWhenProcessExits = !ConfigHelper.Main.Values.ShutdownWhenProcessExits; ConfigHelper.Main.Save(); }))); + + Settings.Add(new Setting(false, $"{GetString("LOC_SETTING_USERADATA_PATH")} '{ConfigHelper.Main.Values.UserDataPath}'", GetString("LOC_SETTING_USERADATA_PATH_DESC"), new Command(_ => + { + System.Windows.Forms.FolderBrowserDialog path = new System.Windows.Forms.FolderBrowserDialog(); + System.Windows.Forms.DialogResult result = path.ShowDialog(); + if (result == System.Windows.Forms.DialogResult.OK) + ConfigHelper.Main.Values.UserDataPath = path.SelectedPath; + ConfigHelper.Main.Save(); + }))); + + Settings.Add(new Setting(ConfigHelper.Main.Values.BackupWhenProcessExits, GetString("LOC_SETTING_BACKUP_WHEN_PROCESS_EXIT"), GetString("LOC_SETTING_BACKUP_WHEN_PROCESS_EXIT_DESC"), new Command(_ => + { + ConfigHelper.Main.Values.BackupWhenProcessExits = !ConfigHelper.Main.Values.BackupWhenProcessExits; + ConfigHelper.Main.Save(); + }))); + Settings.Add(new Setting(ConfigHelper.Main.Values.AutomaticallyCheckAndDownloadUpdates, GetString("LOC_SETTING_AUTO_CHECK_AND_DOWNLOAD_UPDATES"), GetString("LOC_SETTING_AUTO_CHECK_AND_DOWNLOAD_UPDATES_DESC"), new Command(_ => { ConfigHelper.Main.Values.AutomaticallyCheckAndDownloadUpdates = !ConfigHelper.Main.Values.AutomaticallyCheckAndDownloadUpdates; diff --git a/SmartHunter/Game/MhwMemoryUpdater.cs b/SmartHunter/Game/MhwMemoryUpdater.cs index ce1b28d..986690b 100644 --- a/SmartHunter/Game/MhwMemoryUpdater.cs +++ b/SmartHunter/Game/MhwMemoryUpdater.cs @@ -71,6 +71,30 @@ protected override bool ShutdownWhenProcessExits } } + protected override string UserDataPath + { + get + { + return ConfigHelper.Main.Values.UserDataPath; + } + } + + protected override bool BackupWhenProcessExits + { + get + { + return ConfigHelper.Main.Values.BackupWhenProcessExits; + } + } + + protected override bool StartMHWWhenSmartHunterStart + { + get + { + return ConfigHelper.Main.Values.StartMHWWhenSmartHunterStart; + } + } + public MhwMemoryUpdater() { ConfigHelper.Main.Loaded += (s, e) => { TryUpdateTimerInterval(); }; diff --git a/SmartHunter/SmartHunter.csproj b/SmartHunter/SmartHunter.csproj index b9708a9..f65c71e 100644 --- a/SmartHunter/SmartHunter.csproj +++ b/SmartHunter/SmartHunter.csproj @@ -9,8 +9,8 @@ latest SmartHunter false - 2020.12.04.00 - 2020.12.04.00 + 2021.01.06.00 + 2021.01.06.00 bin\$(Configuration) true false @@ -41,6 +41,7 @@ + diff --git a/SmartHunter/bin/Debug/SmartHunter.exe b/SmartHunter/bin/Debug/SmartHunter.exe index 7bedd6d..5f1882e 100644 Binary files a/SmartHunter/bin/Debug/SmartHunter.exe and b/SmartHunter/bin/Debug/SmartHunter.exe differ