Techblox Mod Manager / Launcher
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

270 satır
12KB

  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 const string defaultInfo = @"
  28. Gamecraft Mod Manager
  29. If you click on a mod it will show some info about it. The install instructions there are usually for manual installs.
  30. To get started, click on a mod and select Install mod. Most mods need GamecraftModdingAPI as well.
  31. Then, simply click Play. This will first download and run the patcher (GCIPA) if needed.
  32. If all goes well, after some time a modded Gamecraft should launch.
  33. 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.
  34. Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
  35. 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.
  36. However, you need to run it and click ""Patch & Play"" each time there's a Gamecraft update.
  37. Disclaimer:
  38. 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.
  39. 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.
  40. 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.
  41. ";
  42. private void Form1_Load(object sender, EventArgs e)
  43. {
  44. if (Settings.Default.NeedsUpdate)
  45. {
  46. Settings.Default.Upgrade();
  47. Settings.Default.NeedsUpdate = false;
  48. Settings.Default.Save();
  49. }
  50. modlist.Items.Clear();
  51. UpdateButton(installbtn, false);
  52. modinfobox.Text = defaultInfo;
  53. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath) || GetExe() == null)
  54. {
  55. Settings.Default.GamePath = GetGameFolder();
  56. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  57. Settings.Default.GamePath = SelectGameFolder();
  58. else
  59. MessageBox.Show("Found game at " + Settings.Default.GamePath);
  60. Settings.Default.Save();
  61. }
  62. if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  63. {
  64. status.Text = "Status: Game not found";
  65. return;
  66. }
  67. DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
  68. if (!pexists && dexists)
  69. unpatched.Checked = true; //It will call the event but that won't do anything
  70. refreshbtn_Click(refreshbtn, null);
  71. }
  72. private async void playbtn_Click(object sender, EventArgs e)
  73. {
  74. if (playbtn.ForeColor == Color.Green) return; //Disabled
  75. await UpdateAPI();
  76. await PatchStartGame(); //It will call EndWork();
  77. }
  78. private void settingsbtn_Click(object sender, EventArgs e)
  79. {
  80. if (settingsbtn.ForeColor == Color.Green) return; //Disabled
  81. var sf = new SettingsForm();
  82. sf.ShowDialog(this);
  83. }
  84. private void modlist_SelectedIndexChanged(object sender, EventArgs e)
  85. {
  86. if (working) return;
  87. modinfobox.Clear();
  88. switch (modlist.SelectedItems.Count)
  89. {
  90. case 0:
  91. modinfobox.Text = defaultInfo;
  92. UpdateButton(installbtn, false);
  93. UpdateButton(uninstallbtn, false);
  94. break;
  95. case 1:
  96. default:
  97. installbtn.Text = "Install mod";
  98. UpdateButton(installbtn, false);
  99. UpdateButton(uninstallbtn, false);
  100. bool install = false, update = false;
  101. Action<string, Color> addText = (txt, color) =>
  102. {
  103. int start = modinfobox.Text.Length;
  104. modinfobox.AppendText(txt + Environment.NewLine + Environment.NewLine);
  105. modinfobox.Select(start, txt.Length);
  106. modinfobox.SelectionColor = color;
  107. modinfobox.DeselectAll();
  108. modinfobox.SelectionColor = modinfobox.ForeColor;
  109. };
  110. foreach (ListViewItem item in modlist.SelectedItems)
  111. {
  112. var mod = mods[item.Name];
  113. if (modlist.SelectedItems.Count == 1)
  114. {
  115. if (mod.Updatable)
  116. addText("New version available! " + mod.UpdateDetails, Color.Aqua);
  117. if (mod.LastUpdated < lastGameUpdateTime)
  118. addText("Outdated mod! It may not work properly on the latest version of the game.", Color.DarkOrange);
  119. if (mod.Description != null)
  120. modinfobox.AppendText(mod.Description.Replace("\n", Environment.NewLine));
  121. }
  122. else
  123. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  124. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  125. {
  126. UpdateButton(installbtn, true);
  127. if (mod.Version != null)
  128. update = true;
  129. else
  130. install = true;
  131. }
  132. if (mod.Version != null)
  133. UpdateButton(uninstallbtn, true);
  134. }
  135. if (install && update)
  136. installbtn.Text = "Install and update mod";
  137. else if (update)
  138. installbtn.Text = "Update mod";
  139. else
  140. installbtn.Text = "Install mod";
  141. break;
  142. }
  143. if (unpatched.Checked)
  144. { //Don't allow (un)installing mods if mods are disabled
  145. UpdateButton(installbtn, false);
  146. UpdateButton(uninstallbtn, false);
  147. modlist.Enabled = false;
  148. }
  149. else
  150. modlist.Enabled = true;
  151. }
  152. private async void installbtn_Click(object sender, EventArgs e)
  153. {
  154. if (installbtn.ForeColor == Color.Green) return; //Disabled
  155. if (!BeginWork()) return;
  156. foreach (ListViewItem item in modlist.SelectedItems)
  157. {
  158. var mod = mods[item.Name];
  159. if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
  160. await InstallMod(mod);
  161. }
  162. EndWork();
  163. }
  164. private void uninstallbtn_Click(object sender, EventArgs e)
  165. {
  166. if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
  167. foreach (ListViewItem item in modlist.SelectedItems)
  168. {
  169. if (item.Group.Name != "installed") continue;
  170. UninstallMod(mods[item.Name]);
  171. }
  172. EndWork(); //Update button states
  173. }
  174. private void findlog_Click(object sender, EventArgs e)
  175. {
  176. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  177. {
  178. if (CheckNoExe(out string exe))
  179. return;
  180. Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(".exe", "")}\Player.log");
  181. }
  182. }
  183. private void unpatched_CheckedChanged(object sender, EventArgs e)
  184. { //Not using the patcher's revert option because sometimes it restores the wrong files - the game can be patched without mods
  185. if (CheckNoExe())
  186. return;
  187. CheckIfPatched();
  188. modlist_SelectedIndexChanged(modlist, null);
  189. string plugins = GamePath("\\Plugins");
  190. string disabled = GamePath("\\Plugins_Disabled");
  191. DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
  192. if (unpatched.Checked)
  193. {
  194. if (pexists)
  195. {
  196. if (dexists)
  197. Directory.Delete(disabled, true); //Resolving conflicts would be complicated so delete the other mods - this shouldn't happen normally
  198. Directory.Move(plugins, disabled);
  199. }
  200. }
  201. else
  202. {
  203. if (dexists)
  204. {
  205. if (pexists)
  206. Directory.Delete(plugins, true);
  207. Directory.Move(disabled, plugins);
  208. }
  209. }
  210. }
  211. private void DeleteEmptyPluginsDir(out bool pexists, out bool dexists)
  212. {
  213. string plugins = GamePath("\\Plugins");
  214. string disabled = GamePath("\\Plugins_Disabled");
  215. pexists = Directory.Exists(plugins);
  216. dexists = Directory.Exists(disabled);
  217. if (pexists && !Directory.EnumerateFiles(plugins).Any())
  218. {
  219. Directory.Delete(plugins);
  220. pexists = false;
  221. }
  222. if (dexists && !Directory.EnumerateFiles(disabled).Any())
  223. {
  224. Directory.Delete(disabled);
  225. dexists = false;
  226. }
  227. }
  228. private async void refreshbtn_Click(object sender, EventArgs e)
  229. {
  230. CheckIfPatched(); //Set from placeholder
  231. lastGameUpdateTime = await GetLastGameUpdateTime();
  232. var mods = GetInstalledMods();
  233. await GetAvailableMods();
  234. CheckUninstalledMods(mods);
  235. CheckIfPatched(); //Check after getting the available mods to show GCIPA updates
  236. }
  237. private void validatebtn_Click(object sender, EventArgs e)
  238. {
  239. if (CheckNoExe())
  240. return;
  241. if (MessageBox.Show("Validating the game's files is useful if the game doesn't start even without mods. Make sure to click Refresh once Steam finished verifying the game. The Steam window that shows the progress might open in the background. Note that you will need to patch the game again using the Play button in order to use mods.\n\nContinue?", "Verify game files", MessageBoxButtons.OKCancel) == DialogResult.Cancel)
  242. return;
  243. string exe = GetExe();
  244. File.Delete(GamePath($@"\{exe.Replace(".exe", "")}_Data\Managed\IllusionInjector.dll")); //Used to check if game is patched
  245. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  246. Process.Start("steam://validate/1078000/");
  247. else
  248. Process.Start("xdg-open", "steam://validate/1078000/");
  249. }
  250. }
  251. }