Moving mods instead of unpatching GC

No mods and a patched game is just as good as an unpatched game
This fixes some issues with the wrong backup being restored
This commit is contained in:
Norbi Peti 2020-08-18 16:02:57 +02:00
parent 706e9c5393
commit 678217b281
5 changed files with 75 additions and 16 deletions

View file

@ -196,17 +196,20 @@
// //
// unpatched // unpatched
// //
this.unpatched.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.unpatched.AutoSize = true; this.unpatched.AutoSize = true;
this.unpatched.Location = new System.Drawing.Point(12, 534); this.unpatched.Location = new System.Drawing.Point(12, 534);
this.unpatched.Name = "unpatched"; this.unpatched.Name = "unpatched";
this.unpatched.Size = new System.Drawing.Size(100, 17); this.unpatched.Size = new System.Drawing.Size(218, 17);
this.unpatched.TabIndex = 8; this.unpatched.TabIndex = 8;
this.unpatched.Text = "Run unpatched"; this.unpatched.Text = "Disable mods (check if game is crashing)";
this.unpatched.UseVisualStyleBackColor = true; this.unpatched.UseVisualStyleBackColor = true;
this.unpatched.CheckedChanged += new System.EventHandler(this.unpatched_CheckedChanged); 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.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;

View file

@ -26,21 +26,22 @@ namespace GCMM
private string defaultInfo = @" private string defaultInfo = @"
Gamecraft Mod Manager Gamecraft Mod Manager
If you click on a mod it will show some info about it. The install instructions there are for manual installs. If you click on a mod it will show some info about it. The install instructions there are usually for manual installs.
To get started, click on a mod and select Install mod. Most mods need GamecraftModdingAPI as well. To get started, click on a mod and select Install mod. Most mods need GamecraftModdingAPI as well.
Then, simply click Play. This will first download and run the patcher (GCIPA) if needed. Then, simply click Play. This will first download and run the patcher (GCIPA) if needed.
If all goes well, after some time a modded Gamecraft should launch. If all goes well, after some time a modded Gamecraft should launch.
After a Gamecraft update there's a good chance that mods will break. If this happens you may get errors when trying to start Gamecraft. After a Gamecraft update there's a good chance that mods will break. If this happens you may get errors when trying to start Gamecraft.
Until updated versions are released, use the ""Run unpatched"" checkbox at the bottom to launch the game without mods. Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
You don't have to use the mod manager to run the game each time, though it will tell you about mod updates when they come. You don't have to use the mod manager to run the game each time, though it will tell you about mod updates when they come.
However, make sure to click Play each time you want to switch between modded and unmodded. However, you need to run it and click ""Patch & Play"" each time there's a Gamecraft update.
Disclaimer: Disclaimer:
This mod manager and the mods in the list are made by the ExMods developers. We are not associated with Freejam or Gamecraft. Modify Gamecraft 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 Gamecraft. Modify Gamecraft at your own risk.
If you encounter an issue while the game is patched, report it to us. If you think it's an issue with the game, test again with the unpatched 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 with the ""Disable mods"" option checked before reporting to Freejam.
You may also want to verify the game's files by right clicking the game in Steam and choosing Properties, going to Local files and clicking Verify integrity of game files.
"; ";
private void Form1_Load(object sender, EventArgs e) private void Form1_Load(object sender, EventArgs e)
@ -68,6 +69,9 @@ If you encounter an issue while the game is patched, report it to us. If you thi
status.Text = "Status: Game not found"; status.Text = "Status: Game not found";
return; return;
} }
DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
if (!pexists && dexists)
unpatched.Checked = true; //It will call the event but that won't do anything
CheckIfPatched(); CheckIfPatched();
GetInstalledMods(); GetInstalledMods();
GetAvailableMods(); GetAvailableMods();
@ -141,6 +145,14 @@ If you encounter an issue while the game is patched, report it to us. If you thi
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,8 +188,48 @@ If you encounter an issue while the game is patched, report it to us. If you thi
} }
private void unpatched_CheckedChanged(object sender, EventArgs e) 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
CheckIfPatched(); 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)
{
string plugins = GamePath("\\Plugins");
string disabled = GamePath("\\Plugins_Disabled");
pexists = Directory.Exists(plugins);
dexists = Directory.Exists(disabled);
if (pexists && !Directory.EnumerateFiles(plugins).Any())
{
Directory.Delete(plugins);
pexists = false;
}
if (dexists && !Directory.EnumerateFiles(disabled).Any())
{
Directory.Delete(disabled);
dexists = false;
}
} }
} }
} }

View file

@ -130,7 +130,7 @@ namespace GCMM
File.Delete(file); File.Delete(file);
var parent = Directory.GetParent(file); var parent = Directory.GetParent(file);
if (!parent.EnumerateFiles().Any()) if (!parent.EnumerateFiles().Any())
parent.Delete(); parent.Delete(); //May delete the Plugins dir if empty
} }
} }
File.Delete(mod.Name + ".json"); File.Delete(mod.Name + ".json");

View file

@ -19,7 +19,12 @@ namespace GCMM
public void GetInstalledMods() public void GetInstalledMods()
{ {
foreach (var modPath in Directory.GetFiles(GamePath(@"\Plugins"), "*.dll")) bool disabled = false;
if (!Directory.Exists(GamePath("\\Plugins")))
if (Directory.Exists(GamePath("\\Plugins_Disabled")))
disabled = true;
else return;
foreach (var modPath in Directory.GetFiles(GamePath(disabled ? @"\Plugins_Disabled" : @"\Plugins"), "*.dll"))
{ {
try try
{ {

View file

@ -17,14 +17,14 @@ namespace GCMM
{ {
public bool? CheckIfPatched() public bool? CheckIfPatched()
{ {
string pnp = unpatched.Checked ? "Play" : "Patch && Play"; string pnp = "Patch && Play";
if (!File.Exists(GamePath(@"\IPA.exe"))) if (!File.Exists(GamePath(@"\IPA.exe")))
{ {
status.Text = "Status: Patcher missing\nClicking Play will install it"; status.Text = "Status: Patcher missing\nClicking Play will install it";
playbtn.Text = pnp; playbtn.Text = pnp;
return null; return null;
} }
string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it"); string nopatch = "Status: Unpatched\nClicking Play patches it";
string gc = GetExe().Replace(".exe", ""); string gc = GetExe().Replace(".exe", "");
string backups = GamePath(@"\IPA\Backups\" + gc); string backups = GamePath(@"\IPA\Backups\" + gc);
if (!Directory.Exists(backups)) if (!Directory.Exists(backups))
@ -48,8 +48,8 @@ namespace GCMM
playbtn.Text = pnp; playbtn.Text = pnp;
return false; return false;
} }
status.Text = "Status: Patched" + (unpatched.Checked ? "\nClicking Play unpatches it" : ""); status.Text = "Status: " + (unpatched.Checked ? "Mods disabled" : "Patched");
playbtn.Text = unpatched.Checked ? "Unpatch && Play" : "Play"; playbtn.Text = "Play" + (unpatched.Checked ? " unmodded" : "");
return true; return true;
} }
@ -82,10 +82,9 @@ namespace GCMM
EndWork(false); EndWork(false);
return; return;
} }
if (!status.Value ^ unpatched.Checked) if (!status.Value)
{ //TODO: Wine { //TODO: Wine
var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " " var psi = new ProcessStartInfo(GamePath(@"\IPA.exe"), GetExe() + " --nowait")
+ (unpatched.Checked ? "--revert " : "") + "--nowait")
{ {
UseShellExecute = false, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardError = true,