Browse Source

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

tags/v1.6.0
NorbiPeti 2 years ago
parent
commit
4eeec67ac4
6 changed files with 47 additions and 22 deletions
  1. +1
    -0
      TBMM/Configuration.cs
  2. +5
    -7
      TBMM/MainForm.cs
  3. +7
    -1
      TBMM/MainPatcher.cs
  4. +14
    -10
      TBMM/MainUtils.cs
  5. +18
    -4
      TBMM/SettingsForm.Designer.cs
  6. +2
    -0
      TBMM/SettingsForm.cs

+ 1
- 0
TBMM/Configuration.cs View File

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

public static Configuration Load()
{


+ 5
- 7
TBMM/MainForm.cs View File

@@ -23,7 +23,7 @@ namespace TBMM
public Configuration Configuration { get; }

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 tbmm = new ModInfo { Author = "NorbiPeti", Name = "TBMM" };
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.
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.
Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
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.
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, launch the game without mods through its own launcher.

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.

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.
You may also want to verify the game's files in the launcher.
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.
";

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)
{
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 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",


+ 7
- 1
TBMM/MainPatcher.cs View File

@@ -12,7 +12,9 @@ namespace TBMM
{
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()
{
@@ -29,10 +31,13 @@ namespace TBMM
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}";
if (Configuration.KeepPatched)
status.Text += "\nUnpatch on exit disabled";
playbtn.Text = play;
}
if (GetExe() == null)
{
patched = false;
SetStatusText(GameState.NotFound, false);
return GameState.NotFound;
}
@@ -78,6 +83,7 @@ namespace TBMM

var patchedState = GetPatchedState();
var finalState = gameIsRunning ? GameState.InGame : patchedState;
patched = patchedState == GameState.Patched;
SetStatusText(finalState, patchedState == GameState.Patched);
return finalState;
}


+ 14
- 10
TBMM/MainUtils.cs View File

@@ -93,7 +93,7 @@ namespace TBMM
throw new NullReferenceException("Game process is null");
process.EnableRaisingEvents = true;
process.Exited += HandleGameExit;
_gameProcess = process;
_gameProcess = (process, true);
patched = CheckIfPatched(); // Set in-game status
}

@@ -109,8 +109,8 @@ namespace TBMM

private void HandleGameExit(object sender, EventArgs e)
{
_gameProcess = null;
if (InvokeMethod(CheckIfPatched) != GameState.Patched)
_gameProcess = (null, false);
if (InvokeMethod(CheckIfPatched) != GameState.Patched || Configuration.KeepPatched)
return;
InvokeMethod(() => ExecutePatcher(false)).Exited += (_, _) =>
{
@@ -124,11 +124,11 @@ namespace TBMM
};
}

private Process _gameProcess;
private (Process Process, bool ExitHandlerAdded) _gameProcess = (null, false);

private bool CheckIfGameIsRunning()
{
switch (_gameProcess)
switch (_gameProcess.Process)
{
case { HasExited: false }:
return true;
@@ -137,17 +137,21 @@ namespace TBMM
HandleGameExit(null, EventArgs.Empty);
return false;
default:
_gameProcess = Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault();
if (_gameProcess == null) return false;
if (_gameProcess.HasExited)
if (_gameProcess.Process?.HasExited ?? true)
_gameProcess = (Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault(), false);

if (_gameProcess.Process == null) return false;
if (_gameProcess.Process.HasExited)
{
HandleGameExit(null, EventArgs.Empty);
return false;
}
else
{
_gameProcess.Exited += HandleGameExit;
_gameProcess.EnableRaisingEvents = true;
if (_gameProcess.ExitHandlerAdded) return true;
_gameProcess.Process.Exited += HandleGameExit;
_gameProcess.Process.EnableRaisingEvents = true;
_gameProcess.ExitHandlerAdded = true;
return true;
}
}


+ 18
- 4
TBMM/SettingsForm.Designer.cs View File

@@ -34,12 +34,13 @@
this.browsebtn = new System.Windows.Forms.Button();
this.savebtn = new System.Windows.Forms.Button();
this.cancelbtn = new System.Windows.Forms.Button();
this.keepPatched = new System.Windows.Forms.CheckBox();
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238)));
this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.label1.Location = new System.Drawing.Point(12, 15);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(116, 20);
@@ -68,7 +69,7 @@
//
this.savebtn.DialogResult = System.Windows.Forms.DialogResult.OK;
this.savebtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.savebtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0)))));
this.savebtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.savebtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.savebtn.Location = new System.Drawing.Point(270, 113);
this.savebtn.Name = "savebtn";
@@ -82,7 +83,7 @@
//
this.cancelbtn.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.cancelbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0)))));
this.cancelbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.cancelbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.cancelbtn.Location = new System.Drawing.Point(352, 113);
this.cancelbtn.Name = "cancelbtn";
@@ -92,6 +93,16 @@
this.cancelbtn.UseVisualStyleBackColor = true;
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
//
this.AcceptButton = this.savebtn;
@@ -100,6 +111,7 @@
this.BackColor = System.Drawing.Color.Black;
this.CancelButton = this.cancelbtn;
this.ClientSize = new System.Drawing.Size(439, 148);
this.Controls.Add(this.keepPatched);
this.Controls.Add(this.cancelbtn);
this.Controls.Add(this.savebtn);
this.Controls.Add(this.browsebtn);
@@ -107,7 +119,7 @@
this.Controls.Add(this.label1);
this.ForeColor = System.Drawing.Color.Lime;
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon")));
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimizeBox = false;
this.Name = "SettingsForm";
@@ -120,6 +132,8 @@
this.PerformLayout();
}

private System.Windows.Forms.CheckBox keepPatched;

#endregion

private System.Windows.Forms.Label label1;


+ 2
- 0
TBMM/SettingsForm.cs View File

@@ -16,6 +16,7 @@ namespace TBMM
{
mainForm = (MainForm) Owner;
gamelocation.Text = mainForm.Configuration.GamePath;
keepPatched.Checked = mainForm.Configuration.KeepPatched;
}

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


Loading…
Cancel
Save