diff --git a/GCMM/MainForm.cs b/GCMM/MainForm.cs
index f454971..6508608 100644
--- a/GCMM/MainForm.cs
+++ b/GCMM/MainForm.cs
@@ -31,21 +31,21 @@ namespace GCMM
Gamecraft Mod Manager
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.
-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.
+To get started, click on a mod and select Install mod. Most mods need GamecraftModdingAPI as well so it'll be installed.
+Then launch Gamecraft: if you enabled auto-patching then you can use Steam but if you didn't then you must use the Play button.
+This will first download and run the patcher (GCIPA) if needed. 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.
Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
+If you enabled auto-patching you will get a warning about this.
-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, you need to run it and click ""Patch & Play"" each time there's a Gamecraft update.
+If you don't have auto-patching enabled then you will need to run the mod manager each time Gamecraft updates and click ""Patch & Play"".
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.
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.
+You may also want to verify the game's files by clicking on the Validate game button.
";
private async void Form1_Load(object sender, EventArgs e)
@@ -65,7 +65,7 @@ You may also want to verify the game's files by right clicking the game in Steam
mods.Clear(); //This method may get called twice when ran from the command line
UpdateButton(installbtn, false);
modinfobox.Text = defaultInfo;
- var (steamPath, user) = GetSteamLocationAndUser(); //TODO: If user is 0 then start Steam
+ var (steamPath, user) = GetSteamLocationAndUser();
if (steamPath != null)
this.steamPath = steamPath;
else
diff --git a/GCMM/MainPatcher.cs b/GCMM/MainPatcher.cs
index 62e3599..5fc8c03 100644
--- a/GCMM/MainPatcher.cs
+++ b/GCMM/MainPatcher.cs
@@ -78,6 +78,7 @@ namespace GCMM
{
Show();
retOpenedWindowShouldStay = stay;
+ TopMost = true; //It opens in the background otherwise - should be fine since it only shows for a couple seconds
}
}
var status = CheckIfPatched();
@@ -143,11 +144,18 @@ namespace GCMM
};
process.OutputDataReceived += onoutput;
process.ErrorDataReceived += onoutput;
- process.Exited += CheckStartGame; //target-typed conditional expression - C# 9.0
+ var (handler, task) = CheckStartGame(command);
+ process.Exited += handler;
+ await task;
}
break;
case GameState.Patched:
- CheckStartGame(command, null); //Command may be null but that's okay
+ {
+ //CheckStartGame(command)(null, null);
+ var (handler, task) = CheckStartGame(command);
+ handler(null, null);
+ await task;
+ }
break;
}
return retOpenedWindowShouldStay;
diff --git a/GCMM/MainUtils.cs b/GCMM/MainUtils.cs
index 51b3bc5..070ebaf 100644
--- a/GCMM/MainUtils.cs
+++ b/GCMM/MainUtils.cs
@@ -33,13 +33,13 @@ namespace GCMM
}
public string GetGameFolder()
- { //TODO
+ {
string libs;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
- libs = Settings.Default.SteamUserID + @"\steamapps\libraryfolders.vdf"; //TODO: Not the Steam folder anymore!
+ libs = steamPath + @"\steamapps\libraryfolders.vdf";
else
return null;
- foreach (var line in File.ReadAllLines(libs).Concat(new[] {@"C:\Program Files (x86)\Steam\"}))
+ foreach (var line in File.ReadAllLines(libs).Concat(new[] { "\t\"19\"\t\t\"" + steamPath + "\"" }))
{
var regex = new Regex("\\t\"\\d+\"\\t\\t\"(.+)\"");
var match = regex.Match(line);
@@ -60,7 +60,7 @@ namespace GCMM
var ofd = new OpenFileDialog();
ofd.Filter = "Gamecraft executable|Gamecraft.exe|Gamecraft Preview executable|GamecraftPreview.exe";
ofd.Title = "Game location";
- ofd.InitialDirectory = @"C:\Program Files (x86)\Steam\steamapps\common\"; //TODO
+ ofd.InitialDirectory = steamPath + @"\steamapps\common\";
ofd.CheckFileExists = true;
ofd.ShowDialog();
if (string.IsNullOrWhiteSpace(ofd.FileName))
@@ -81,8 +81,26 @@ namespace GCMM
return (null, 0);
}
- private bool UpdateOrGetSteamConfigToAutoStart(bool? autoLaunch)
+ ///
+ /// Does not return the current value if setting it is not possible because Steam is running.
+ ///
+ /// The value to set or null to keep as is
+ /// The current value, unless setting it while Steam is running
+ public bool UpdateOrGetSteamConfigToAutoStart(bool? autoLaunch)
{
+ string commandToUse = Application.ExecutablePath + " -start %command%";
+ if (autoLaunch.HasValue && Process.GetProcessesByName("steam").Length > 0)
+ { //Setting it while Steam is running
+ if (MessageBox.Show("Cannot set launch options while Steam is running." +
+ (autoLaunch.Value
+ ? " Do you want to do it manually? If so, it will be copied on your clipboard." +
+ " Right click the game, select Properties and paste it in the launch options field."
+ : " Do you want to do it manually?" +
+ " If so, right click the game, select Properties and remove the text from the launch options field."),
+ "Launch options in Steam", MessageBoxButtons.YesNo) == DialogResult.Yes && autoLaunch.Value)
+ Clipboard.SetText(commandToUse);
+ return false;
+ }
var regex = new Regex(@"(\t{6}""LaunchOptions""\t+"")(.*)("")");
string path = steamPath + @"\userdata\" + Settings.Default.SteamUserID + @"\config\localconfig.vdf";
var lines = File.ReadAllLines(path);
@@ -97,22 +115,28 @@ namespace GCMM
var match = regex.Match(lines[i]);
if (!match.Success)
continue;
+ ret = match.Groups[2].Value.Contains("GCMM.exe");
+ string enabledCommand = match.Groups[1].Value + commandToUse.Replace("\\", "\\\\") + match.Groups[3].Value;
if (autoLaunch.HasValue)
{
if (autoLaunch.Value)
- lines[i] = match.Groups[1].Value + Application.ExecutablePath + " -start %command%" + match.Groups[3].Value;
+ lines[i] = enabledCommand;
else
- lines[i] = match.Groups[1].Value + match.Groups[2].Value;
+ lines[i] = match.Groups[1].Value + match.Groups[3].Value;
+ File.WriteAllLines(path, lines);
+ }
+ else if (ret && lines[i] != enabledCommand) //GCMM got moved or something and it's only queried, not set
+ {
+ lines[i] = enabledCommand;
File.WriteAllLines(path, lines);
}
- ret = match.Groups[2].Value.Contains("GCMM.exe");
break;
}
}
return ret;
}
- private (string, int) GetSteamLocationAndUser()
+ public (string, int) GetSteamLocationAndUser()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT) return (null, 0);
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Valve\Steam\ActiveProcess"))
@@ -123,7 +147,7 @@ namespace GCMM
}
}
- private void DetectConfigLocationAndAutoStart(string steamPath, ref int user)
+ public void DetectConfigLocationAndAutoStart(string steamPath, ref int user)
{
string path = steamPath + @"\userdata";
if (user == 0)
@@ -155,28 +179,64 @@ namespace GCMM
Settings.Default.AutoLaunch = false;
}
- private void CheckStartGame(object sender, EventArgs e)
+ private (EventHandler, Task) CheckStartGame(string command)
{
- Action act = () =>
+ var tcs = new TaskCompletionSource