|
|
@@ -1,4 +1,5 @@ |
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Diagnostics; |
|
|
|
using System.IO.Compression; |
|
|
|
using System.IO; |
|
|
@@ -13,67 +14,72 @@ namespace TBMM |
|
|
|
{ |
|
|
|
public GameState CheckIfPatched() |
|
|
|
{ |
|
|
|
if (GetExe() == null) |
|
|
|
Dictionary<GameState, (string Status, string Extra, string Play)> statusTexts = new() |
|
|
|
{ |
|
|
|
status.Text = "Status: Game not found"; |
|
|
|
return GameState.NotFound; |
|
|
|
{ GameState.NotFound, ("Game not found", "Specify the game's location in settings", "") }, |
|
|
|
{ GameState.InGame, ("Game is running", "", "In-game") }, |
|
|
|
{ GameState.NoPatcher, ("Patcher missing", "Clicking Play will install it", "") }, |
|
|
|
{ GameState.OldPatcher, ("Patcher outdated", "nClicking play will update it", "") }, |
|
|
|
{ GameState.Unpatched, ("Unpatched", "", "") }, |
|
|
|
{ GameState.Patched, ("Patched", "", "")} |
|
|
|
}; |
|
|
|
void SetStatusText(GameState state, bool patched) |
|
|
|
{ |
|
|
|
var (statusText, extra, play) = statusTexts[state]; |
|
|
|
if (extra.Length == 0) extra = patched ? "Cannot join online mode" : "Online mode available"; |
|
|
|
if (play.Length == 0) play = "Play modded"; |
|
|
|
status.Text = $"Status: {statusText}\n{extra}"; |
|
|
|
playbtn.Text = play; |
|
|
|
} |
|
|
|
string pnp = "Play modded"; |
|
|
|
if (!File.Exists(GamePath(@"\IPA.exe"))) |
|
|
|
if (GetExe() == null) |
|
|
|
{ |
|
|
|
status.Text = "Status: Patcher missing\nClicking Play will install it"; |
|
|
|
playbtn.Text = pnp; |
|
|
|
return GameState.NoPatcher; |
|
|
|
SetStatusText(GameState.NotFound, false); |
|
|
|
return GameState.NotFound; |
|
|
|
} |
|
|
|
|
|
|
|
if (CheckIfGameIsRunning()) |
|
|
|
bool gameIsRunning = CheckIfGameIsRunning(); |
|
|
|
if (gameIsRunning) |
|
|
|
{ |
|
|
|
status.Text = "Status: Game is running"; |
|
|
|
playbtn.Text = "In-game"; |
|
|
|
UpdateButton(playbtn, false); //Don't allow (un)installing mods if game is running |
|
|
|
UpdateButton(installbtn, false); |
|
|
|
UpdateButton(uninstallbtn, false); |
|
|
|
modlist.Enabled = false; |
|
|
|
return GameState.InGame; |
|
|
|
} |
|
|
|
|
|
|
|
if (!working) UpdateButton(playbtn, true); |
|
|
|
modlist.Enabled = true; |
|
|
|
if (gcipa.Updatable && !(gcipa.Version == new Version(1, 0, 0, 0) && gcipa.LatestVersion == new Version(4, 0, 0, 0))) |
|
|
|
else |
|
|
|
{ |
|
|
|
status.Text = "Status: Patcher outdated\nClicking play will update it"; |
|
|
|
playbtn.Text = pnp; |
|
|
|
return GameState.OldPatcher; |
|
|
|
if (!working) UpdateButton(playbtn, true); |
|
|
|
modlist.Enabled = true; |
|
|
|
} |
|
|
|
string nopatch = "Status: Unpatched"; |
|
|
|
string gc = GetExe(withExtension: false); |
|
|
|
string backups = GamePath(@"\IPA\Backups\" + gc); |
|
|
|
if (!Directory.Exists(backups)) |
|
|
|
{ |
|
|
|
status.Text = nopatch; |
|
|
|
playbtn.Text = pnp; |
|
|
|
return GameState.Unpatched; |
|
|
|
} |
|
|
|
string backup = Directory.EnumerateDirectories(backups).OrderByDescending(Directory.GetLastWriteTimeUtc).FirstOrDefault(); |
|
|
|
if (backup == null) |
|
|
|
{ |
|
|
|
status.Text = nopatch; |
|
|
|
playbtn.Text = pnp; |
|
|
|
return GameState.Unpatched; |
|
|
|
} |
|
|
|
if (File.GetLastWriteTime(GamePath($@"\{gc}_Data\Managed\Assembly-CSharp.dll")) |
|
|
|
> //If the file was updated at least 2 minutes after patching |
|
|
|
Directory.GetLastWriteTime(backup).AddMinutes(2) |
|
|
|
|| !File.Exists(GamePath($@"\{gc}_Data\Managed\IllusionInjector.dll"))) |
|
|
|
|
|
|
|
GameState GetPatchedState() |
|
|
|
{ |
|
|
|
status.Text = nopatch; |
|
|
|
playbtn.Text = pnp; |
|
|
|
return GameState.Unpatched; |
|
|
|
if (!File.Exists(GamePath(@"\IPA.exe"))) |
|
|
|
return GameState.NoPatcher; |
|
|
|
|
|
|
|
if (gcipa.Updatable && !(gcipa.Version == new Version(1, 0, 0, 0) && |
|
|
|
gcipa.LatestVersion == new Version(4, 0, 0, 0)) |
|
|
|
&& !gameIsRunning) |
|
|
|
return GameState.OldPatcher; |
|
|
|
string gc = GetExe(withExtension: false); |
|
|
|
string backups = GamePath(@"\IPA\Backups\" + gc); |
|
|
|
if (!Directory.Exists(backups)) |
|
|
|
return GameState.Unpatched; |
|
|
|
string backup = Directory.EnumerateDirectories(backups) |
|
|
|
.OrderByDescending(Directory.GetLastWriteTimeUtc).FirstOrDefault(); |
|
|
|
if (backup == null) |
|
|
|
return GameState.Unpatched; |
|
|
|
if (File.GetLastWriteTime(GamePath($@"\{gc}_Data\Managed\Assembly-CSharp.dll")) |
|
|
|
> //If the file was updated at least 2 minutes after patching |
|
|
|
Directory.GetLastWriteTime(backup).AddMinutes(2) |
|
|
|
|| !File.Exists(GamePath($@"\{gc}_Data\Managed\IllusionInjector.dll"))) |
|
|
|
return GameState.Unpatched; |
|
|
|
return GameState.Patched; |
|
|
|
} |
|
|
|
|
|
|
|
status.Text = "Status: Patched"; |
|
|
|
playbtn.Text = "Play"; |
|
|
|
return GameState.Patched; |
|
|
|
var patchedState = GetPatchedState(); |
|
|
|
var finalState = gameIsRunning ? GameState.InGame : patchedState; |
|
|
|
SetStatusText(finalState, patchedState == GameState.Patched); |
|
|
|
return finalState; |
|
|
|
} |
|
|
|
|
|
|
|
public async Task<bool?> PatchStartGame(string command = null) |
|
|
|