Add option to keep the game patched and don't ask on exit if not patched

This commit is contained in:
Norbi Peti 2022-03-20 18:23:23 +01:00
parent ae60c43cfe
commit 4eeec67ac4
6 changed files with 47 additions and 22 deletions

View file

@ -6,6 +6,7 @@ namespace TBMM
public class Configuration public class Configuration
{ {
public string GamePath { get; set; } public string GamePath { get; set; }
public bool KeepPatched { get; set; }
public static Configuration Load() public static Configuration Load()
{ {

View file

@ -23,7 +23,7 @@ namespace TBMM
public Configuration Configuration { get; } public Configuration Configuration { get; }
private readonly ResourceManager resources; private readonly ResourceManager resources;
private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>(); private readonly Dictionary<string, ModInfo> mods = new();
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" }; private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
private readonly ModInfo tbmm = new ModInfo { Author = "NorbiPeti", Name = "TBMM" }; private readonly ModInfo tbmm = new ModInfo { Author = "NorbiPeti", Name = "TBMM" };
private DateTime lastGameUpdateTime; private DateTime lastGameUpdateTime;
@ -35,15 +35,13 @@ To get started, click on a mod and select Install mod. Most mods need TechbloxMo
Then launch Techblox by clicking on the Play button below. Mods are only loaded if you start the game from here. Then launch Techblox by clicking on the Play button below. Mods are only loaded if you start the game from here.
This will first download and run the patcher (GCIPA) if needed. If all goes well, after some time a modded Techblox should launch. This will first download and run the patcher (GCIPA) if needed. If all goes well, after some time a modded Techblox should launch.
After a Techblox update there's a good chance that mods will break. If this happens you may get errors when trying to start Techblox. After a Techblox update there's a good chance that mods will break. If this happens you may get errors when trying to start Techblox through the mod manager.
Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods. Until updated versions are released, launch the game without mods through its own launcher.
If you launch the game through the launcher after an update and encounter an error, either repair the game or launch it through the mod manager.
Disclaimer: Disclaimer:
This mod manager and the mods in the list are made by the ExMods developers. We are not associated with Freejam or Techblox. Modify Techblox at your own risk. This mod manager and the mods in the list are made by the ExMods developers. We are not associated with Freejam or Techblox. Modify Techblox at your own risk.
If you encounter an issue while any mods are installed, report it to us. If you think it's an issue with the game, test again with the ""Disable mods"" option checked before reporting to Freejam. If you encounter an issue while any mods are installed, report it to us. If you think it's an issue with the game, test again by launching the game through the official launcher before reporting to Freejam.
You may also want to verify the game's files in the launcher.
"; ";
private async void Form1_Load(object sender, EventArgs e) private async void Form1_Load(object sender, EventArgs e)
@ -233,7 +231,7 @@ You may also want to verify the game's files in the launcher.
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{ {
if (e.Cancel) return; if (e.Cancel) return;
if (CheckIfPatched() != GameState.InGame) return; if (Configuration.KeepPatched || CheckIfPatched(out bool patched) != GameState.InGame || !patched) return;
if (MessageBox.Show("The game is still running. The mod manager needs to be running until the game closes to restore the game files." + if (MessageBox.Show("The game is still running. The mod manager needs to be running until the game closes to restore the game files." +
" If you proceed you won't be able to play online until you start the mod manager again.\n\n" + " If you proceed you won't be able to play online until you start the mod manager again.\n\n" +
"Are you sure you want TBMM to exit before the game does?", "Game still running", "Are you sure you want TBMM to exit before the game does?", "Game still running",

View file

@ -12,7 +12,9 @@ namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {
public GameState CheckIfPatched() public GameState CheckIfPatched() => CheckIfPatched(out _);
public GameState CheckIfPatched(out bool patched)
{ {
Dictionary<GameState, (string Status, string Extra, string Play)> statusTexts = new() Dictionary<GameState, (string Status, string Extra, string Play)> statusTexts = new()
{ {
@ -29,10 +31,13 @@ namespace TBMM
if (extra.Length == 0) extra = patched ? "Cannot join online mode" : "Online mode available"; if (extra.Length == 0) extra = patched ? "Cannot join online mode" : "Online mode available";
if (play.Length == 0) play = "Play modded"; if (play.Length == 0) play = "Play modded";
status.Text = $"Status: {statusText}\n{extra}"; status.Text = $"Status: {statusText}\n{extra}";
if (Configuration.KeepPatched)
status.Text += "\nUnpatch on exit disabled";
playbtn.Text = play; playbtn.Text = play;
} }
if (GetExe() == null) if (GetExe() == null)
{ {
patched = false;
SetStatusText(GameState.NotFound, false); SetStatusText(GameState.NotFound, false);
return GameState.NotFound; return GameState.NotFound;
} }
@ -78,6 +83,7 @@ namespace TBMM
var patchedState = GetPatchedState(); var patchedState = GetPatchedState();
var finalState = gameIsRunning ? GameState.InGame : patchedState; var finalState = gameIsRunning ? GameState.InGame : patchedState;
patched = patchedState == GameState.Patched;
SetStatusText(finalState, patchedState == GameState.Patched); SetStatusText(finalState, patchedState == GameState.Patched);
return finalState; return finalState;
} }

View file

@ -93,7 +93,7 @@ namespace TBMM
throw new NullReferenceException("Game process is null"); throw new NullReferenceException("Game process is null");
process.EnableRaisingEvents = true; process.EnableRaisingEvents = true;
process.Exited += HandleGameExit; process.Exited += HandleGameExit;
_gameProcess = process; _gameProcess = (process, true);
patched = CheckIfPatched(); // Set in-game status patched = CheckIfPatched(); // Set in-game status
} }
@ -109,8 +109,8 @@ namespace TBMM
private void HandleGameExit(object sender, EventArgs e) private void HandleGameExit(object sender, EventArgs e)
{ {
_gameProcess = null; _gameProcess = (null, false);
if (InvokeMethod(CheckIfPatched) != GameState.Patched) if (InvokeMethod(CheckIfPatched) != GameState.Patched || Configuration.KeepPatched)
return; return;
InvokeMethod(() => ExecutePatcher(false)).Exited += (_, _) => InvokeMethod(() => ExecutePatcher(false)).Exited += (_, _) =>
{ {
@ -124,11 +124,11 @@ namespace TBMM
}; };
} }
private Process _gameProcess; private (Process Process, bool ExitHandlerAdded) _gameProcess = (null, false);
private bool CheckIfGameIsRunning() private bool CheckIfGameIsRunning()
{ {
switch (_gameProcess) switch (_gameProcess.Process)
{ {
case { HasExited: false }: case { HasExited: false }:
return true; return true;
@ -137,17 +137,21 @@ namespace TBMM
HandleGameExit(null, EventArgs.Empty); HandleGameExit(null, EventArgs.Empty);
return false; return false;
default: default:
_gameProcess = Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(); if (_gameProcess.Process?.HasExited ?? true)
if (_gameProcess == null) return false; _gameProcess = (Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(), false);
if (_gameProcess.HasExited)
if (_gameProcess.Process == null) return false;
if (_gameProcess.Process.HasExited)
{ {
HandleGameExit(null, EventArgs.Empty); HandleGameExit(null, EventArgs.Empty);
return false; return false;
} }
else else
{ {
_gameProcess.Exited += HandleGameExit; if (_gameProcess.ExitHandlerAdded) return true;
_gameProcess.EnableRaisingEvents = true; _gameProcess.Process.Exited += HandleGameExit;
_gameProcess.Process.EnableRaisingEvents = true;
_gameProcess.ExitHandlerAdded = true;
return true; return true;
} }
} }

View file

@ -34,6 +34,7 @@
this.browsebtn = new System.Windows.Forms.Button(); this.browsebtn = new System.Windows.Forms.Button();
this.savebtn = new System.Windows.Forms.Button(); this.savebtn = new System.Windows.Forms.Button();
this.cancelbtn = new System.Windows.Forms.Button(); this.cancelbtn = new System.Windows.Forms.Button();
this.keepPatched = new System.Windows.Forms.CheckBox();
this.SuspendLayout(); this.SuspendLayout();
// //
// label1 // label1
@ -92,6 +93,16 @@
this.cancelbtn.UseVisualStyleBackColor = true; this.cancelbtn.UseVisualStyleBackColor = true;
this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click); this.cancelbtn.Click += new System.EventHandler(this.cancelbtn_Click);
// //
// keepPatched
//
this.keepPatched.AutoSize = true;
this.keepPatched.Location = new System.Drawing.Point(12, 61);
this.keepPatched.Name = "keepPatched";
this.keepPatched.Size = new System.Drawing.Size(330, 17);
this.keepPatched.TabIndex = 5;
this.keepPatched.Text = "Keep game patched (prevents online gameplay until unchecked)";
this.keepPatched.UseVisualStyleBackColor = true;
//
// SettingsForm // SettingsForm
// //
this.AcceptButton = this.savebtn; this.AcceptButton = this.savebtn;
@ -100,6 +111,7 @@
this.BackColor = System.Drawing.Color.Black; this.BackColor = System.Drawing.Color.Black;
this.CancelButton = this.cancelbtn; this.CancelButton = this.cancelbtn;
this.ClientSize = new System.Drawing.Size(439, 148); this.ClientSize = new System.Drawing.Size(439, 148);
this.Controls.Add(this.keepPatched);
this.Controls.Add(this.cancelbtn); this.Controls.Add(this.cancelbtn);
this.Controls.Add(this.savebtn); this.Controls.Add(this.savebtn);
this.Controls.Add(this.browsebtn); this.Controls.Add(this.browsebtn);
@ -120,6 +132,8 @@
this.PerformLayout(); this.PerformLayout();
} }
private System.Windows.Forms.CheckBox keepPatched;
#endregion #endregion
private System.Windows.Forms.Label label1; private System.Windows.Forms.Label label1;

View file

@ -16,6 +16,7 @@ namespace TBMM
{ {
mainForm = (MainForm) Owner; mainForm = (MainForm) Owner;
gamelocation.Text = mainForm.Configuration.GamePath; gamelocation.Text = mainForm.Configuration.GamePath;
keepPatched.Checked = mainForm.Configuration.KeepPatched;
} }
private void browsebtn_Click(object sender, EventArgs e) private void browsebtn_Click(object sender, EventArgs e)
@ -26,6 +27,7 @@ namespace TBMM
private void savebtn_Click(object sender, EventArgs e) private void savebtn_Click(object sender, EventArgs e)
{ {
mainForm.Configuration.GamePath = gamelocation.Text; mainForm.Configuration.GamePath = gamelocation.Text;
mainForm.Configuration.KeepPatched = keepPatched.Checked;
mainForm.Configuration.Save(); mainForm.Configuration.Save();
Close(); Close();
} }