Skip to content

Commit

Permalink
Support for MHW:I Ver.15.11.00
Browse files Browse the repository at this point in the history
  • Loading branch information
dragonyue0417 committed Jan 6, 2021
1 parent ddfc80e commit f9c39a0
Show file tree
Hide file tree
Showing 8 changed files with 155 additions and 30 deletions.
114 changes: 92 additions & 22 deletions SmartHunter/Core/MemoryUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,6 +22,7 @@ enum State
DownloadingUpdates,
Restarting,
WaitingForProcess,
StartMHW,
ProcessFound,
FastPatternScanning,
PatternScanning,
Expand All @@ -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; }

Expand Down Expand Up @@ -73,7 +77,7 @@ void CreateStateMachine()
Log.WriteLine("Searching for updates (You can disable this feature in file 'Config.json')!");
}),
new StateMachine<State>.Transition(
State.WaitingForProcess,
State.StartMHW,
() => !ConfigHelper.Main.Values.Overlay.MonsterWidget.UseNetworkServer && !ConfigHelper.Main.Values.AutomaticallyCheckAndDownloadUpdates,
() =>
{
Expand Down Expand Up @@ -131,7 +135,7 @@ void CreateStateMachine()
new StateMachine<State>.Transition[]
{
new StateMachine<State>.Transition(
State.WaitingForProcess,
State.StartMHW,
() => !ConfigHelper.Main.Values.Overlay.MonsterWidget.UseNetworkServer && !updater.CheckForUpdates(),
() =>
{
Expand Down Expand Up @@ -203,7 +207,7 @@ void CreateStateMachine()
Log.WriteLine("Successfully downloaded all files!");
}),
new StateMachine<State>.Transition(
State.WaitingForProcess,
State.StartMHW,
() => !updater.DownloadUpdates(),
() =>
{
Expand Down Expand Up @@ -239,43 +243,63 @@ void CreateStateMachine()
new StateMachine<State>.Transition[]
{
new StateMachine<State>.Transition(
State.WaitingForProcess,
State.StartMHW,
() => ServerManager.Instance.IsServerOline != 0,
() =>
{
Initialize();
})
}));

m_StateMachine.Add(State.WaitingForProcess, new StateMachine<State>.StateData(
m_StateMachine.Add(State.StartMHW, new StateMachine<State>.StateData(
null,
new StateMachine<State>.Transition[]
{
new StateMachine<State>.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<State>.StateData(
null,
new StateMachine<State>.Transition[]
{
new StateMachine<State>.Transition(
State.ProcessFound,
() =>
{
return CheckProcess();
},
null)
}));


m_StateMachine.Add(State.ProcessFound, new StateMachine<State>.StateData(
null,
new StateMachine<State>.Transition[]
Expand Down Expand Up @@ -431,7 +455,32 @@ private void Initialize(bool processExited = false)
m_MemoryScans = new List<ThreadedMemoryScan>();

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");
Expand Down Expand Up @@ -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;
}
}
}
6 changes: 6 additions & 0 deletions SmartHunter/Game/Config/LocalizationConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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"},
Expand Down
3 changes: 3 additions & 0 deletions SmartHunter/Game/Config/MainConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
8 changes: 4 additions & 4 deletions SmartHunter/Game/Config/MemoryConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand Down
25 changes: 23 additions & 2 deletions SmartHunter/Game/Data/ViewModels/SettingsViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +25,7 @@ public static SettingsViewModel Instance
}
}

public List<Setting> Settings { get; }
public IList<Setting> Settings { get; }

private void restartSmartHunter()
{
Expand Down Expand Up @@ -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;
Expand Down
24 changes: 24 additions & 0 deletions SmartHunter/Game/MhwMemoryUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(); };
Expand Down
5 changes: 3 additions & 2 deletions SmartHunter/SmartHunter.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
<LangVersion>latest</LangVersion>
<AssemblyTitle>SmartHunter</AssemblyTitle>
<Deterministic>false</Deterministic>
<AssemblyVersion>2020.12.04.00</AssemblyVersion>
<FileVersion>2020.12.04.00</FileVersion>
<AssemblyVersion>2021.01.06.00</AssemblyVersion>
<FileVersion>2021.01.06.00</FileVersion>
<OutputPath>bin\$(Configuration)</OutputPath>
<UseWPF>true</UseWPF>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
Expand Down Expand Up @@ -41,6 +41,7 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xaml" />
<Reference Include="WindowsBase" />
<Reference Include="PresentationCore" />
Expand Down
Binary file modified SmartHunter/bin/Debug/SmartHunter.exe
Binary file not shown.

0 comments on commit f9c39a0

Please sign in to comment.