From 9e088c02f04957bfded7858a789050cadda8451b Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 18 Jul 2020 22:25:52 +0200 Subject: [PATCH] Fixes, Patch & Play, automatically install API --- GCMM/MainForm.cs | 9 +++++---- GCMM/MainModInstaller.cs | 13 +++++++++++++ GCMM/MainPatcher.cs | 11 +++++++++-- GCMM/ModInfo.cs | 1 + README.md | 1 + 5 files changed, 29 insertions(+), 6 deletions(-) diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs index 19f08cc..541b8ce 100644 --- a/GCMM/MainForm.cs +++ b/GCMM/MainForm.cs @@ -76,6 +76,7 @@ If you encounter an issue while the game is patched, report it to us. If you thi private async void playbtn_Click(object sender, EventArgs e) { if (playbtn.ForeColor == Color.Green) return; //Disabled + await UpdateAPI(); await PatchStartGame(); //It will call EndWork(); } @@ -108,15 +109,15 @@ If you encounter an issue while the game is patched, report it to us. If you thi var mod = mods[item.Name]; if (modlist.SelectedItems.Count == 1) { - bool up = mod.Version != null && mod.Version < mod.LatestVersion; + bool up = mod.Updatable; modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n" : "") + mod.Description).Replace("\n", Environment.NewLine); if(up) { modinfobox.Select(0, "New version available!".Length); - //modinfobox.SelectionColor = Color.Aqua; - //modinfobox.DeselectAll(); - //modinfobox.SelectionColor = modinfobox.ForeColor; + modinfobox.SelectionColor = Color.Aqua; + modinfobox.DeselectAll(); + modinfobox.SelectionColor = modinfobox.ForeColor; } } else diff --git a/GCMM/MainModInstaller.cs b/GCMM/MainModInstaller.cs index 208b64d..760d518 100644 --- a/GCMM/MainModInstaller.cs +++ b/GCMM/MainModInstaller.cs @@ -21,6 +21,8 @@ namespace GCMM MessageBox.Show("Gamecraft not found. Set the correct path in Settings."); return; } + if (mod.Name != "GamecraftModdingAPI") + await UpdateAPI(); var tmp = Directory.CreateDirectory("temp"); var plugins = Directory.CreateDirectory(GamePath(@"\Plugins")); string tmppath = tmp.FullName + Path.DirectorySeparatorChar + mod.Name; @@ -135,5 +137,16 @@ namespace GCMM mod.Version = null; //Not installed AddUpdateModInList(mod); //Update list } + + public async Task UpdateAPI() + { + var gcmapi = mods["GamecraftModdingAPI"]; + if (!gcmapi.Installed || gcmapi.Updatable) + { + if (MessageBox.Show($"GamecraftModdingAPI will be {(gcmapi.Installed ? "updated" : "installed")} as most mods need it to work. You can uninstall it if you're sure you don't need it.", "API needed", MessageBoxButtons.OKCancel) + == DialogResult.OK) + await InstallMod(gcmapi); + } + } } } diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs index f6a8bec..18e8a1c 100644 --- a/GCMM/MainPatcher.cs +++ b/GCMM/MainPatcher.cs @@ -17,32 +17,39 @@ namespace GCMM { public bool? CheckIfPatched() { + string pnp = unpatched.Checked ? "Play" : "Patch && Play"; if (!File.Exists(GamePath(@"\IPA.exe"))) { status.Text = "Status: Patcher missing\nClicking Play will install it"; + playbtn.Text = pnp; return null; } string nopatch = "Status: Unpatched" + (unpatched.Checked ? "" : "\nClicking Play patches it"); - string backups = GamePath(@"\IPA\Backups\Gamecraft"); + string gc = GetExe().Replace(".exe", ""); + string backups = GamePath(@"\IPA\Backups\" + gc); if (!Directory.Exists(backups)) { status.Text = nopatch; + playbtn.Text = pnp; return false; } string backup = Directory.EnumerateDirectories(backups).OrderByDescending(s => s).FirstOrDefault(); if (backup == null) { status.Text = nopatch; + playbtn.Text = pnp; return false; } - if (File.GetLastWriteTime(GamePath(@"\Gamecraft_Data\Managed\Assembly-CSharp.dll")) + 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)) { status.Text = nopatch; + playbtn.Text = pnp; return false; } status.Text = "Status: Patched" + (unpatched.Checked ? "\nClicking Play unpatches it" : ""); + playbtn.Text = unpatched.Checked ? "Unpatch && Play" : "Play"; return true; } diff --git a/GCMM/ModInfo.cs b/GCMM/ModInfo.cs index 4a7650d..b682303 100644 --- a/GCMM/ModInfo.cs +++ b/GCMM/ModInfo.cs @@ -27,5 +27,6 @@ namespace GCMM public string DownloadURL { get; set; } public HashSet ModFiles { get; set; } public string UpdateDetails { get; set; } + public bool Updatable => Version != null && LatestVersion != null && Version < LatestVersion; } } diff --git a/README.md b/README.md index fff60bc..67aae61 100644 --- a/README.md +++ b/README.md @@ -7,6 +7,7 @@ A manager that handles everything needed to use mods for Gamecraft. * Download and run GCIPA if needed * List, install and uninstall mods * Keep track of files added by mods and remove them when the mod is uninstalled +* Preview support for the game and mods for it ## Mod requirements * For a mod to be listed, it needs to have a regular release (so not a prerelease) with exactly 1 recognised attached asset.