Remove unpatched checkbox and handle the game's running status

- Disabling mod installs while the game is running
- Automatically detecting whether the game is running and unpatching if needed
This commit is contained in:
Norbi Peti 2022-02-20 22:53:19 +01:00
parent ae89291c55
commit 333e8d6040
4 changed files with 103 additions and 107 deletions

View file

@ -30,7 +30,7 @@
{ {
System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Installed", System.Windows.Forms.HorizontalAlignment.Center); System.Windows.Forms.ListViewGroup listViewGroup1 = new System.Windows.Forms.ListViewGroup("Installed", System.Windows.Forms.HorizontalAlignment.Center);
System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Available", System.Windows.Forms.HorizontalAlignment.Center); System.Windows.Forms.ListViewGroup listViewGroup2 = new System.Windows.Forms.ListViewGroup("Available", System.Windows.Forms.HorizontalAlignment.Center);
System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] {"Mod", "modtainers", "1.0", "2020.06.15. 2:01:43"}, -1); System.Windows.Forms.ListViewItem listViewItem1 = new System.Windows.Forms.ListViewItem(new string[] { "Mod", "modtainers", "1.0", "2020.06.15. 2:01:43" }, -1);
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm)); System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.modlist = new System.Windows.Forms.ListView(); this.modlist = new System.Windows.Forms.ListView();
this.modName = new System.Windows.Forms.ColumnHeader(); this.modName = new System.Windows.Forms.ColumnHeader();
@ -43,17 +43,16 @@
this.playbtn = new System.Windows.Forms.Button(); this.playbtn = new System.Windows.Forms.Button();
this.settingsbtn = new System.Windows.Forms.Button(); this.settingsbtn = new System.Windows.Forms.Button();
this.findlog = new System.Windows.Forms.Button(); this.findlog = new System.Windows.Forms.Button();
this.unpatched = new System.Windows.Forms.CheckBox();
this.modinfobox = new System.Windows.Forms.RichTextBox(); this.modinfobox = new System.Windows.Forms.RichTextBox();
this.refreshbtn = new System.Windows.Forms.Button(); this.refreshbtn = new System.Windows.Forms.Button();
this.SuspendLayout(); this.SuspendLayout();
// //
// modlist // modlist
// //
this.modlist.Anchor = ((System.Windows.Forms.AnchorStyles) ((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.modlist.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right)));
this.modlist.BackColor = System.Drawing.Color.FromArgb(((int) (((byte) (216)))), ((int) (((byte) (240)))), ((int) (((byte) (216))))); this.modlist.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(216)))), ((int)(((byte)(240)))), ((int)(((byte)(216)))));
this.modlist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.modlist.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.modlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {this.modName, this.modAuthor, this.modVersion, this.modTimestamp}); this.modlist.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] { this.modName, this.modAuthor, this.modVersion, this.modTimestamp });
this.modlist.ForeColor = System.Drawing.Color.Green; this.modlist.ForeColor = System.Drawing.Color.Green;
this.modlist.FullRowSelect = true; this.modlist.FullRowSelect = true;
listViewGroup1.Header = "Installed"; listViewGroup1.Header = "Installed";
@ -62,11 +61,11 @@
listViewGroup2.Header = "Available"; listViewGroup2.Header = "Available";
listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center; listViewGroup2.HeaderAlignment = System.Windows.Forms.HorizontalAlignment.Center;
listViewGroup2.Name = "available"; listViewGroup2.Name = "available";
this.modlist.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] {listViewGroup1, listViewGroup2}); this.modlist.Groups.AddRange(new System.Windows.Forms.ListViewGroup[] { listViewGroup1, listViewGroup2 });
this.modlist.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable; this.modlist.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.modlist.HideSelection = false; this.modlist.HideSelection = false;
listViewItem1.Group = listViewGroup1; listViewItem1.Group = listViewGroup1;
this.modlist.Items.AddRange(new System.Windows.Forms.ListViewItem[] {listViewItem1}); this.modlist.Items.AddRange(new System.Windows.Forms.ListViewItem[] { listViewItem1 });
this.modlist.Location = new System.Drawing.Point(12, 47); this.modlist.Location = new System.Drawing.Point(12, 47);
this.modlist.Name = "modlist"; this.modlist.Name = "modlist";
this.modlist.Size = new System.Drawing.Size(491, 433); this.modlist.Size = new System.Drawing.Size(491, 433);
@ -98,10 +97,10 @@
// //
// status // status
// //
this.status.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); this.status.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.status.AutoSize = true; this.status.AutoSize = true;
this.status.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.status.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.status.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.status.Font = new System.Drawing.Font("Microsoft Sans Serif", 12F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.status.ForeColor = System.Drawing.Color.Lime; this.status.ForeColor = System.Drawing.Color.Lime;
this.status.Location = new System.Drawing.Point(8, 487); this.status.Location = new System.Drawing.Point(8, 487);
this.status.Name = "status"; this.status.Name = "status";
@ -111,11 +110,11 @@
// //
// installbtn // installbtn
// //
this.installbtn.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.installbtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.installbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; this.installbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.installbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.installbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.installbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.installbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.installbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.installbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.installbtn.Location = new System.Drawing.Point(509, 12); this.installbtn.Location = new System.Drawing.Point(509, 12);
this.installbtn.Name = "installbtn"; this.installbtn.Name = "installbtn";
this.installbtn.Size = new System.Drawing.Size(263, 49); this.installbtn.Size = new System.Drawing.Size(263, 49);
@ -126,11 +125,11 @@
// //
// uninstallbtn // uninstallbtn
// //
this.uninstallbtn.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); this.uninstallbtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.uninstallbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Black; this.uninstallbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Black;
this.uninstallbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Black; this.uninstallbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.Black;
this.uninstallbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.uninstallbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.uninstallbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.uninstallbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 14.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.uninstallbtn.ForeColor = System.Drawing.Color.Green; this.uninstallbtn.ForeColor = System.Drawing.Color.Green;
this.uninstallbtn.Location = new System.Drawing.Point(509, 67); this.uninstallbtn.Location = new System.Drawing.Point(509, 67);
this.uninstallbtn.Name = "uninstallbtn"; this.uninstallbtn.Name = "uninstallbtn";
@ -144,9 +143,9 @@
// //
this.playbtn.Anchor = System.Windows.Forms.AnchorStyles.Bottom; this.playbtn.Anchor = System.Windows.Forms.AnchorStyles.Bottom;
this.playbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; this.playbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.playbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.playbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.playbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.playbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.playbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.playbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 20.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.playbtn.Location = new System.Drawing.Point(250, 487); this.playbtn.Location = new System.Drawing.Point(250, 487);
this.playbtn.Name = "playbtn"; this.playbtn.Name = "playbtn";
this.playbtn.Size = new System.Drawing.Size(300, 62); this.playbtn.Size = new System.Drawing.Size(300, 62);
@ -157,9 +156,9 @@
// //
// settingsbtn // settingsbtn
// //
this.settingsbtn.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.settingsbtn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.settingsbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; this.settingsbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.settingsbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.settingsbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.settingsbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.settingsbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.settingsbtn.Location = new System.Drawing.Point(667, 487); this.settingsbtn.Location = new System.Drawing.Point(667, 487);
this.settingsbtn.Name = "settingsbtn"; this.settingsbtn.Name = "settingsbtn";
@ -171,9 +170,9 @@
// //
// findlog // findlog
// //
this.findlog.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.findlog.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.findlog.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; this.findlog.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.findlog.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.findlog.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.findlog.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.findlog.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.findlog.Location = new System.Drawing.Point(666, 522); this.findlog.Location = new System.Drawing.Point(666, 522);
this.findlog.Name = "findlog"; this.findlog.Name = "findlog";
@ -183,21 +182,9 @@
this.findlog.UseVisualStyleBackColor = true; this.findlog.UseVisualStyleBackColor = true;
this.findlog.Click += new System.EventHandler(this.findlog_Click); this.findlog.Click += new System.EventHandler(this.findlog_Click);
// //
// unpatched
//
this.unpatched.Anchor = ((System.Windows.Forms.AnchorStyles) ((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.unpatched.AutoSize = true;
this.unpatched.Location = new System.Drawing.Point(12, 534);
this.unpatched.Name = "unpatched";
this.unpatched.Size = new System.Drawing.Size(218, 17);
this.unpatched.TabIndex = 8;
this.unpatched.Text = "Disable mods (check if game is crashing)";
this.unpatched.UseVisualStyleBackColor = true;
this.unpatched.CheckedChanged += new System.EventHandler(this.unpatched_CheckedChanged);
//
// modinfobox // modinfobox
// //
this.modinfobox.Anchor = ((System.Windows.Forms.AnchorStyles) (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right))); this.modinfobox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) | System.Windows.Forms.AnchorStyles.Right)));
this.modinfobox.BackColor = System.Drawing.Color.Black; this.modinfobox.BackColor = System.Drawing.Color.Black;
this.modinfobox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; this.modinfobox.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.modinfobox.ForeColor = System.Drawing.Color.Lime; this.modinfobox.ForeColor = System.Drawing.Color.Lime;
@ -211,9 +198,9 @@
// refreshbtn // refreshbtn
// //
this.refreshbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green; this.refreshbtn.FlatAppearance.MouseDownBackColor = System.Drawing.Color.Green;
this.refreshbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int) (((byte) (0)))), ((int) (((byte) (40)))), ((int) (((byte) (0))))); this.refreshbtn.FlatAppearance.MouseOverBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(0)))), ((int)(((byte)(40)))), ((int)(((byte)(0)))));
this.refreshbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat; this.refreshbtn.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.refreshbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte) (238))); this.refreshbtn.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(238)));
this.refreshbtn.Location = new System.Drawing.Point(12, 12); this.refreshbtn.Location = new System.Drawing.Point(12, 12);
this.refreshbtn.Name = "refreshbtn"; this.refreshbtn.Name = "refreshbtn";
this.refreshbtn.Size = new System.Drawing.Size(105, 29); this.refreshbtn.Size = new System.Drawing.Size(105, 29);
@ -230,7 +217,6 @@
this.ClientSize = new System.Drawing.Size(784, 561); this.ClientSize = new System.Drawing.Size(784, 561);
this.Controls.Add(this.refreshbtn); this.Controls.Add(this.refreshbtn);
this.Controls.Add(this.modinfobox); this.Controls.Add(this.modinfobox);
this.Controls.Add(this.unpatched);
this.Controls.Add(this.findlog); this.Controls.Add(this.findlog);
this.Controls.Add(this.settingsbtn); this.Controls.Add(this.settingsbtn);
this.Controls.Add(this.playbtn); this.Controls.Add(this.playbtn);
@ -239,7 +225,7 @@
this.Controls.Add(this.status); this.Controls.Add(this.status);
this.Controls.Add(this.modlist); this.Controls.Add(this.modlist);
this.ForeColor = System.Drawing.Color.Lime; this.ForeColor = System.Drawing.Color.Lime;
this.Icon = ((System.Drawing.Icon) (resources.GetObject("$this.Icon"))); this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.Name = "MainForm"; this.Name = "MainForm";
this.Text = "Techblox Mod Manager"; this.Text = "Techblox Mod Manager";
this.Load += new System.EventHandler(this.Form1_Load); this.Load += new System.EventHandler(this.Form1_Load);
@ -261,7 +247,6 @@
private System.Windows.Forms.Button settingsbtn; private System.Windows.Forms.Button settingsbtn;
private System.Windows.Forms.ColumnHeader modAuthor; private System.Windows.Forms.ColumnHeader modAuthor;
private System.Windows.Forms.Button findlog; private System.Windows.Forms.Button findlog;
private System.Windows.Forms.CheckBox unpatched;
private System.Windows.Forms.RichTextBox modinfobox; private System.Windows.Forms.RichTextBox modinfobox;
private System.Windows.Forms.Button refreshbtn; private System.Windows.Forms.Button refreshbtn;
} }

View file

@ -75,9 +75,7 @@ You may also want to verify the game's files in the launcher.
status.Text = resources.GetString("Status_Game_not_found"); status.Text = resources.GetString("Status_Game_not_found");
return; return;
} }
DeleteEmptyPluginsDir(out bool pexists, out bool dexists); DeleteEmptyPluginsDir(out _, out _);
if (!pexists && dexists)
unpatched.Checked = true; //It will call the event but that won't do anything
await RefreshEverything(evenMods); await RefreshEverything(evenMods);
} }
@ -156,14 +154,6 @@ You may also want to verify the game's files in the launcher.
installbtn.Text = "Install mod"; installbtn.Text = "Install mod";
break; break;
} }
if (unpatched.Checked)
{ //Don't allow (un)installing mods if mods are disabled
UpdateButton(installbtn, false);
UpdateButton(uninstallbtn, false);
modlist.Enabled = false;
}
else
modlist.Enabled = true;
} }
private async void installbtn_Click(object sender, EventArgs e) private async void installbtn_Click(object sender, EventArgs e)
@ -176,7 +166,7 @@ You may also want to verify the game's files in the launcher.
if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue; if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
await InstallMod(mod); await InstallMod(mod);
} }
EndWork(); EndWork(CheckIfPatched());
} }
private void uninstallbtn_Click(object sender, EventArgs e) private void uninstallbtn_Click(object sender, EventArgs e)
@ -187,7 +177,7 @@ You may also want to verify the game's files in the launcher.
if (item.Group.Name != "installed") continue; if (item.Group.Name != "installed") continue;
UninstallMod(mods[item.Name]); UninstallMod(mods[item.Name]);
} }
EndWork(); //Update button states EndWork(CheckIfPatched()); //Update button states
} }
private void findlog_Click(object sender, EventArgs e) private void findlog_Click(object sender, EventArgs e)
@ -199,35 +189,6 @@ You may also want to verify the game's files in the launcher.
Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(".exe", "")}\Player.log"); Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(".exe", "")}\Player.log");
} }
} }
private void unpatched_CheckedChanged(object sender, EventArgs e)
{ //Not using the patcher's revert option because sometimes it restores the wrong files - the game can be patched without mods
if (CheckNoExe())
return;
CheckIfPatched();
modlist_SelectedIndexChanged(modlist, null);
string plugins = GamePath("\\Plugins");
string disabled = GamePath("\\Plugins_Disabled");
DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
if (unpatched.Checked)
{
if (pexists)
{
if (dexists)
Directory.Delete(disabled, true); //Resolving conflicts would be complicated so delete the other mods - this shouldn't happen normally
Directory.Move(plugins, disabled);
}
}
else
{
if (dexists)
{
if (pexists)
Directory.Delete(plugins, true);
Directory.Move(disabled, plugins);
}
}
}
private void DeleteEmptyPluginsDir(out bool pexists, out bool dexists) private void DeleteEmptyPluginsDir(out bool pexists, out bool dexists)
{ {
@ -254,7 +215,8 @@ You may also want to verify the game's files in the launcher.
private async Task RefreshEverything(bool evenMods) private async Task RefreshEverything(bool evenMods)
{ {
CheckIfPatched(); //Set from placeholder if (CheckIfPatched() == GameState.Patched) //Set from placeholder
HandleGameExit(null, EventArgs.Empty);
lastGameUpdateTime = GetGameVersionAsDate(); lastGameUpdateTime = GetGameVersionAsDate();
var mods = GetInstalledMods(); var mods = GetInstalledMods();
if (evenMods) if (evenMods)

View file

@ -25,6 +25,20 @@ namespace TBMM
playbtn.Text = pnp; playbtn.Text = pnp;
return GameState.NoPatcher; return GameState.NoPatcher;
} }
if (CheckIfGameIsRunning())
{
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))) if (gcipa.Updatable && !(gcipa.Version == new Version(1, 0, 0, 0) && gcipa.LatestVersion == new Version(4, 0, 0, 0)))
{ {
status.Text = "Status: Patcher outdated\nClicking play will update it"; status.Text = "Status: Patcher outdated\nClicking play will update it";
@ -40,7 +54,7 @@ namespace TBMM
playbtn.Text = pnp; playbtn.Text = pnp;
return GameState.Unpatched; return GameState.Unpatched;
} }
string backup = Directory.EnumerateDirectories(backups).OrderByDescending(name => Directory.GetLastWriteTimeUtc(name)).FirstOrDefault(); string backup = Directory.EnumerateDirectories(backups).OrderByDescending(Directory.GetLastWriteTimeUtc).FirstOrDefault();
if (backup == null) if (backup == null)
{ {
status.Text = nopatch; status.Text = nopatch;
@ -56,8 +70,9 @@ namespace TBMM
playbtn.Text = pnp; playbtn.Text = pnp;
return GameState.Unpatched; return GameState.Unpatched;
} }
status.Text = "Status: " + (unpatched.Checked ? "Mods disabled" : "Patched");
playbtn.Text = "Play" + (unpatched.Checked ? " unmodded" : ""); status.Text = "Status: Patched";
playbtn.Text = "Play";
return GameState.Patched; return GameState.Patched;
} }
@ -82,7 +97,7 @@ namespace TBMM
{ {
case GameState.NotFound: case GameState.NotFound:
MessageBox.Show("Techblox not found! Set the correct path in Settings."); MessageBox.Show("Techblox not found! Set the correct path in Settings.");
EndWork(false); EndWork(status, false);
return retOpenedWindowShouldStay; return retOpenedWindowShouldStay;
case GameState.NoPatcher: case GameState.NoPatcher:
case GameState.OldPatcher: case GameState.OldPatcher:
@ -94,7 +109,7 @@ namespace TBMM
) + "\n\nIt will be downloaded from https://git.exmods.org/modtainers/GCIPA/releases and ran to patch the game. You can validate the game to restore the original game files or simply disable mods at any time.", ) + "\n\nIt will be downloaded from https://git.exmods.org/modtainers/GCIPA/releases and ran to patch the game. You can validate the game to restore the original game files or simply disable mods at any time.",
"Patcher download needed", MessageBoxButtons.OKCancel) == DialogResult.Cancel) "Patcher download needed", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
{ {
EndWork(); EndWork(status);
return retOpenedWindowShouldStay; return retOpenedWindowShouldStay;
} }
this.status.Text = "Status: Patching..."; this.status.Text = "Status: Patching...";
@ -124,7 +139,7 @@ namespace TBMM
{ {
case GameState.NoPatcher: //Make sure it actually worked case GameState.NoPatcher: //Make sure it actually worked
case GameState.OldPatcher: case GameState.OldPatcher:
EndWork(false); EndWork(status, false);
return retOpenedWindowShouldStay; return retOpenedWindowShouldStay;
case GameState.Unpatched: case GameState.Unpatched:
{ //TODO: Wine { //TODO: Wine
@ -177,7 +192,11 @@ namespace TBMM
NoPatcher, NoPatcher,
OldPatcher, OldPatcher,
Unpatched, Unpatched,
Patched Patched,
/// <summary>
/// Doesn't matter if patched, don't do anything if the game is running
/// </summary>
InGame
} }
} }
} }

View file

@ -72,13 +72,13 @@ namespace TBMM
status.Text = "Status: Patching failed"; status.Text = "Status: Patching failed";
return; return;
} }
if (CheckIfPatched() == GameState.Patched || unpatched.Checked)
var patched = CheckIfPatched();
if (patched == GameState.Patched)
{ {
Process process = null; Process process = null;
if (command != null) if (command != null)
{ {
if (sender is Process) //Patched just now
CheckCompatibilityAndDisableMods();
await CheckModUpdatesAsync(); await CheckModUpdatesAsync();
process = Process.Start(command); process = Process.Start(command);
} }
@ -93,9 +93,11 @@ 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;
patched = CheckIfPatched(); // Set in-game status
} }
EndWork(false); EndWork(patched, false);
tcs.SetResult(null); tcs.SetResult(null);
}; };
if (InvokeRequired) if (InvokeRequired)
@ -107,9 +109,12 @@ namespace TBMM
private void HandleGameExit(object sender, EventArgs e) private void HandleGameExit(object sender, EventArgs e)
{ {
ExecutePatcher(false).Exited += (o, args) => _gameProcess = null;
if (InvokeMethod(CheckIfPatched) != GameState.Patched)
return;
InvokeMethod(() => ExecutePatcher(false)).Exited += (o, args) =>
{ {
if (CheckIfPatched() == GameState.Patched) if (InvokeMethod(CheckIfPatched) == GameState.Patched)
{ {
MessageBox.Show("Failed to unpatch game, launching through the launcher will fail because of anticheat. " + MessageBox.Show("Failed to unpatch game, launching through the launcher will fail because of anticheat. " +
"Check the output in the panel on the right.\n\n" + "Check the output in the panel on the right.\n\n" +
@ -119,15 +124,33 @@ namespace TBMM
}; };
} }
private void CheckCompatibilityAndDisableMods() private Process _gameProcess;
private bool CheckIfGameIsRunning()
{ {
if (!unpatched.Checked && MessageBox.Show("If the game updated just now, some mods may be incompatible or they may work just fine." + switch (_gameProcess)
" Do you want to try running with mods?" + {
"\n\nClick Yes to start the game with mods (after a small update or if you just installed TBMM)" + case { HasExited: false }:
"\nClick No to disable mods before starting the game (after a major update)" + return true;
"\n\nYou can always enable/disable mods by launching TBMM.", case { HasExited: true }:
"Possible incompatibility warning", MessageBoxButtons.YesNo) == DialogResult.No) MessageBox.Show("Game has exited without handling... Please report.");
unpatched.Checked = true; HandleGameExit(null, EventArgs.Empty);
return false;
default:
_gameProcess = Process.GetProcessesByName(GetExe(withExtension: false)).FirstOrDefault();
if (_gameProcess == null) return false;
if (_gameProcess.HasExited)
{
HandleGameExit(null, EventArgs.Empty);
return false;
}
else
{
_gameProcess.Exited += HandleGameExit;
_gameProcess.EnableRaisingEvents = true;
return true;
}
}
} }
private async Task CheckModUpdatesAsync() private async Task CheckModUpdatesAsync()
@ -154,6 +177,14 @@ namespace TBMM
return client; return client;
} }
public T InvokeMethod<T>(Func<T> func)
{
if (InvokeRequired)
return (T)Invoke(func);
else
return func();
}
private bool working = false; private bool working = false;
/// <summary> /// <summary>
/// Some simple "locking", only allow one operation at a time /// Some simple "locking", only allow one operation at a time
@ -167,18 +198,17 @@ namespace TBMM
UpdateButton(installbtn, false); UpdateButton(installbtn, false);
UpdateButton(uninstallbtn, false); UpdateButton(uninstallbtn, false);
UpdateButton(settingsbtn, false); UpdateButton(settingsbtn, false);
unpatched.Enabled = false;
return true; return true;
} }
public void EndWork(bool desc = true) public void EndWork(GameState state, bool desc = true)
{ {
working = false; working = false;
UpdateButton(playbtn, true); if (state != GameState.InGame)
UpdateButton(playbtn, true);
UpdateButton(settingsbtn, true); UpdateButton(settingsbtn, true);
if (desc) if (desc)
modlist_SelectedIndexChanged(modlist, null); modlist_SelectedIndexChanged(modlist, null);
unpatched.Enabled = true;
} }
/// <summary> /// <summary>
@ -197,7 +227,7 @@ namespace TBMM
if (File.Exists(GamePath("\\Techblox.exe", path))) if (File.Exists(GamePath("\\Techblox.exe", path)))
return "Techblox" + (withExtension ? ".exe" : ""); return "Techblox" + (withExtension ? ".exe" : "");
if (File.Exists(GamePath("\\TechbloxPreview.exe", path))) if (File.Exists(GamePath("\\TechbloxPreview.exe", path)))
return "TechbloxPreview.exe" + (withExtension ? ".exe" : ""); return "TechbloxPreview" + (withExtension ? ".exe" : "");
return null; return null;
} }