Techblox Mod Manager / Launcher
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

314 řádky
14KB

  1. using GCMM.Properties;
  2. using Newtonsoft.Json.Linq;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Diagnostics;
  6. using System.Drawing;
  7. using System.IO;
  8. using System.IO.Compression;
  9. using System.Linq;
  10. using System.Net;
  11. using System.Reflection;
  12. using System.Text.RegularExpressions;
  13. using System.Threading.Tasks;
  14. using System.Windows.Forms;
  15. namespace GCMM
  16. {
  17. public partial class MainForm : Form
  18. {
  19. public MainForm()
  20. {
  21. InitializeComponent();
  22. }
  23. private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
  24. private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
  25. private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" };
  26. private DateTime lastGameUpdateTime;
  27. private string steamPath;
  28. private const string defaultInfo = @"
  29. Techblox Mod Manager
  30. If you click on a mod it will show some info about it. The install instructions there are usually for manual installs.
  31. To get started, click on a mod and select Install mod. Most mods need TechbloxModdingAPI as well so it'll be installed.
  32. Then launch Techblox: if you enabled auto-patching then you can use Steam but if you didn't then you must use the Play button.
  33. This will first download and run the patcher (GCIPA) if needed. If all goes well, after some time a modded Techblox should launch.
  34. 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.
  35. Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
  36. If you enabled auto-patching you will get a warning about this.
  37. If you don't have auto-patching enabled then you will need to run the mod manager each time Techblox updates and click ""Patch & Play"".
  38. Disclaimer:
  39. 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.
  40. 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.
  41. You may also want to verify the game's files by clicking on the Validate game button.
  42. ";
  43. private async void Form1_Load(object sender, EventArgs e)
  44. {
  45. if (mods.Values.All(mod => mod.LatestVersion == null)) //Not (fully) loaded yet
  46. await LoadEverything(true);
  47. }
  48. public async Task LoadEverything(bool evenMods)
  49. {
  50. if (Settings.Default.NeedsUpdate)
  51. {
  52. Settings.Default.Upgrade();
  53. Settings.Default.NeedsUpdate = false;
  54. Settings.Default.Save();
  55. }
  56. modlist.Items.Clear();
  57. mods.Clear(); //This method may get called twice when ran from the command line
  58. UpdateButton(installbtn, false);
  59. modinfobox.Text = defaultInfo;
  60. var (steamPath, user) = GetSteamLocationAndUser();
  61. if (steamPath != null)
  62. this.steamPath = steamPath;
  63. else
  64. {
  65. MessageBox.Show("Steam not found! If you have Steam installed, please report this to ExMods.\n\nThe Steam install is checked to autodetect where the game is installed and to optionally configure auto-patching.", "Steam not found");
  66. status.Text = "Status: Steam not found";
  67. return;
  68. }
  69. if (Settings.Default.SteamUserID == 0 && Settings.Default.AutoLaunch)
  70. {
  71. if (MessageBox.Show("Do you want GCMM to change the game's launch settings so it can ensure the game is patched?\n\n" +
  72. "If you say yes, GCMM will do a quick check before the game is launched and patches if necessary. " +
  73. "This way you (hopefully) won't see crashes after a Techblox update.\n\n" +
  74. "Note that this also means that if you (re)move GCMM without disabling this in the settings then you won't be able to launch Techblox until you change the launch options in Steam.",
  75. "GCMM auto-patching", MessageBoxButtons.YesNo) == DialogResult.Yes)
  76. DetectConfigLocationAndAutoStart(steamPath, ref user);
  77. else
  78. Settings.Default.AutoLaunch = false;
  79. Settings.Default.Save();
  80. }
  81. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
  82. {
  83. Settings.Default.GamePath = GetGameFolder();
  84. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  85. Settings.Default.GamePath = SelectGameFolder();
  86. else
  87. MessageBox.Show("Found game at " + Settings.Default.GamePath);
  88. Settings.Default.Save();
  89. }
  90. if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  91. {
  92. status.Text = "Status: Game not found";
  93. return;
  94. }
  95. DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
  96. if (!pexists && dexists)
  97. unpatched.Checked = true; //It will call the event but that won't do anything
  98. await RefreshEverything(evenMods);
  99. }
  100. private async void playbtn_Click(object sender, EventArgs e)
  101. {
  102. if (playbtn.ForeColor == Color.Green) return; //Disabled
  103. await UpdateAPI();
  104. await PatchStartGame(); //It will call EndWork();
  105. }
  106. private void settingsbtn_Click(object sender, EventArgs e)
  107. {
  108. if (settingsbtn.ForeColor == Color.Green) return; //Disabled
  109. var sf = new SettingsForm();
  110. sf.ShowDialog(this);
  111. }
  112. private void modlist_SelectedIndexChanged(object sender, EventArgs e)
  113. {
  114. if (working) return;
  115. modinfobox.Clear();
  116. switch (modlist.SelectedItems.Count)
  117. {
  118. case 0:
  119. modinfobox.Text = defaultInfo;
  120. UpdateButton(installbtn, false);
  121. UpdateButton(uninstallbtn, false);
  122. break;
  123. case 1:
  124. default:
  125. installbtn.Text = "Install mod";
  126. UpdateButton(installbtn, false);
  127. UpdateButton(uninstallbtn, false);
  128. bool install = false, update = false;
  129. Action<string, Color> addText = (txt, color) =>
  130. {
  131. int start = modinfobox.Text.Length;
  132. modinfobox.AppendText(txt + Environment.NewLine + Environment.NewLine);
  133. modinfobox.Select(start, txt.Length);
  134. modinfobox.SelectionColor = color;
  135. modinfobox.DeselectAll();
  136. modinfobox.SelectionColor = modinfobox.ForeColor;
  137. };
  138. foreach (ListViewItem item in modlist.SelectedItems)
  139. {
  140. var mod = mods[item.Name];
  141. if (modlist.SelectedItems.Count == 1)
  142. {
  143. if (mod.Updatable)
  144. addText("New version available! " + mod.UpdateDetails, Color.Aqua);
  145. if (mod.LastUpdated < lastGameUpdateTime)
  146. addText("Outdated mod! It may not work properly on the latest version of the game.", Color.DarkOrange);
  147. if (mod.Description != null)
  148. modinfobox.AppendText(mod.Description.Replace("\n", Environment.NewLine));
  149. }
  150. else
  151. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  152. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  153. {
  154. UpdateButton(installbtn, true);
  155. if (mod.Version != null)
  156. update = true;
  157. else
  158. install = true;
  159. }
  160. if (mod.Version != null)
  161. UpdateButton(uninstallbtn, true);
  162. }
  163. if (install && update)
  164. installbtn.Text = "Install and update mod";
  165. else if (update)
  166. installbtn.Text = "Update mod";
  167. else
  168. installbtn.Text = "Install mod";
  169. break;
  170. }
  171. if (unpatched.Checked)
  172. { //Don't allow (un)installing mods if mods are disabled
  173. UpdateButton(installbtn, false);
  174. UpdateButton(uninstallbtn, false);
  175. modlist.Enabled = false;
  176. }
  177. else
  178. modlist.Enabled = true;
  179. }
  180. private async void installbtn_Click(object sender, EventArgs e)
  181. {
  182. if (installbtn.ForeColor == Color.Green) return; //Disabled
  183. if (!BeginWork()) return;
  184. foreach (ListViewItem item in modlist.SelectedItems)
  185. {
  186. var mod = mods[item.Name];
  187. if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
  188. await InstallMod(mod);
  189. }
  190. EndWork();
  191. }
  192. private void uninstallbtn_Click(object sender, EventArgs e)
  193. {
  194. if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
  195. foreach (ListViewItem item in modlist.SelectedItems)
  196. {
  197. if (item.Group.Name != "installed") continue;
  198. UninstallMod(mods[item.Name]);
  199. }
  200. EndWork(); //Update button states
  201. }
  202. private void findlog_Click(object sender, EventArgs e)
  203. {
  204. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  205. {
  206. if (CheckNoExe(out string exe))
  207. return;
  208. Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(".exe", "")}\Player.log");
  209. }
  210. }
  211. private void unpatched_CheckedChanged(object sender, EventArgs e)
  212. { //Not using the patcher's revert option because sometimes it restores the wrong files - the game can be patched without mods
  213. if (CheckNoExe())
  214. return;
  215. CheckIfPatched();
  216. modlist_SelectedIndexChanged(modlist, null);
  217. string plugins = GamePath("\\Plugins");
  218. string disabled = GamePath("\\Plugins_Disabled");
  219. DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
  220. if (unpatched.Checked)
  221. {
  222. if (pexists)
  223. {
  224. if (dexists)
  225. Directory.Delete(disabled, true); //Resolving conflicts would be complicated so delete the other mods - this shouldn't happen normally
  226. Directory.Move(plugins, disabled);
  227. }
  228. }
  229. else
  230. {
  231. if (dexists)
  232. {
  233. if (pexists)
  234. Directory.Delete(plugins, true);
  235. Directory.Move(disabled, plugins);
  236. }
  237. }
  238. }
  239. private void DeleteEmptyPluginsDir(out bool pexists, out bool dexists)
  240. {
  241. string plugins = GamePath("\\Plugins");
  242. string disabled = GamePath("\\Plugins_Disabled");
  243. pexists = Directory.Exists(plugins);
  244. dexists = Directory.Exists(disabled);
  245. if (pexists && !Directory.EnumerateFiles(plugins).Any())
  246. {
  247. Directory.Delete(plugins);
  248. pexists = false;
  249. }
  250. if (dexists && !Directory.EnumerateFiles(disabled).Any())
  251. {
  252. Directory.Delete(disabled);
  253. dexists = false;
  254. }
  255. }
  256. private async void refreshbtn_Click(object sender, EventArgs e)
  257. {
  258. await RefreshEverything(true);
  259. }
  260. private async Task RefreshEverything(bool evenMods)
  261. {
  262. CheckIfPatched(); //Set from placeholder
  263. lastGameUpdateTime = await GetLastGameUpdateTime();
  264. var mods = GetInstalledMods();
  265. if (evenMods)
  266. await GetAvailableMods();
  267. CheckUninstalledMods(mods);
  268. CheckIfPatched(); //Check after getting the available mods to show GCIPA updates
  269. }
  270. private void validatebtn_Click(object sender, EventArgs e)
  271. {
  272. if (CheckNoExe())
  273. return;
  274. if (MessageBox.Show("Validating the game's files is useful if the game doesn't start even without mods." +
  275. " Make sure to click Refresh once Steam finished verifying the game." +
  276. " The Steam window that shows the progress might open in the background." +
  277. " Note that if auto-patching isn't enabled then you will need to patch the game again using the Play button in order to use mods." +
  278. "\n\nContinue?", "Verify game files", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  279. return;
  280. string exe = GetExe();
  281. File.Delete(GamePath($@"\{exe.Replace(".exe", "")}_Data\Managed\IllusionInjector.dll")); //Used to check if game is patched
  282. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  283. Process.Start("steam://validate/1078000/");
  284. else
  285. Process.Start("xdg-open", "steam://validate/1078000/");
  286. }
  287. private void MainForm_Shown(object sender, EventArgs e)
  288. {
  289. Focus();
  290. }
  291. }
  292. }