Techblox Mod Manager / Launcher
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

265 wiersze
11KB

  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. foreach (ListViewItem item in modlist.SelectedItems)
  102. {
  103. var mod = mods[item.Name];
  104. if (modlist.SelectedItems.Count == 1)
  105. {
  106. bool up = mod.Updatable;
  107. modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n"
  108. : "") + mod.Description).Replace("\n", Environment.NewLine);
  109. if(up)
  110. {
  111. modinfobox.Select(0, "New version available!".Length);
  112. modinfobox.SelectionColor = Color.Aqua;
  113. modinfobox.DeselectAll();
  114. modinfobox.SelectionColor = modinfobox.ForeColor;
  115. }
  116. }
  117. else
  118. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  119. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  120. {
  121. UpdateButton(installbtn, true);
  122. if (mod.Version != null)
  123. update = true;
  124. else
  125. install = true;
  126. }
  127. if (mod.Version != null)
  128. UpdateButton(uninstallbtn, true);
  129. }
  130. if (install && update)
  131. installbtn.Text = "Install and update mod";
  132. else if (update)
  133. installbtn.Text = "Update mod";
  134. else
  135. installbtn.Text = "Install mod";
  136. break;
  137. }
  138. if (unpatched.Checked)
  139. { //Don't allow (un)installing mods if mods are disabled
  140. UpdateButton(installbtn, false);
  141. UpdateButton(uninstallbtn, false);
  142. modlist.Enabled = false;
  143. }
  144. else
  145. modlist.Enabled = true;
  146. }
  147. private async void installbtn_Click(object sender, EventArgs e)
  148. {
  149. if (installbtn.ForeColor == Color.Green) return; //Disabled
  150. if (!BeginWork()) return;
  151. foreach (ListViewItem item in modlist.SelectedItems)
  152. {
  153. var mod = mods[item.Name];
  154. if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
  155. await InstallMod(mod);
  156. }
  157. EndWork();
  158. }
  159. private void uninstallbtn_Click(object sender, EventArgs e)
  160. {
  161. if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
  162. foreach (ListViewItem item in modlist.SelectedItems)
  163. {
  164. if (item.Group.Name != "installed") continue;
  165. UninstallMod(mods[item.Name]);
  166. }
  167. EndWork(); //Update button states
  168. }
  169. private void findlog_Click(object sender, EventArgs e)
  170. {
  171. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  172. {
  173. if (CheckNoExe(out string exe))
  174. return;
  175. Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(".exe", "")}\Player.log");
  176. }
  177. }
  178. private void unpatched_CheckedChanged(object sender, EventArgs e)
  179. { //Not using the patcher's revert option because sometimes it restores the wrong files - the game can be patched without mods
  180. if (CheckNoExe())
  181. return;
  182. CheckIfPatched();
  183. modlist_SelectedIndexChanged(modlist, null);
  184. string plugins = GamePath("\\Plugins");
  185. string disabled = GamePath("\\Plugins_Disabled");
  186. DeleteEmptyPluginsDir(out bool pexists, out bool dexists);
  187. if (unpatched.Checked)
  188. {
  189. if (pexists)
  190. {
  191. if (dexists)
  192. Directory.Delete(disabled, true); //Resolving conflicts would be complicated so delete the other mods - this shouldn't happen normally
  193. Directory.Move(plugins, disabled);
  194. }
  195. }
  196. else
  197. {
  198. if (dexists)
  199. {
  200. if (pexists)
  201. Directory.Delete(plugins, true);
  202. Directory.Move(disabled, plugins);
  203. }
  204. }
  205. }
  206. private void DeleteEmptyPluginsDir(out bool pexists, out bool dexists)
  207. {
  208. string plugins = GamePath("\\Plugins");
  209. string disabled = GamePath("\\Plugins_Disabled");
  210. pexists = Directory.Exists(plugins);
  211. dexists = Directory.Exists(disabled);
  212. if (pexists && !Directory.EnumerateFiles(plugins).Any())
  213. {
  214. Directory.Delete(plugins);
  215. pexists = false;
  216. }
  217. if (dexists && !Directory.EnumerateFiles(disabled).Any())
  218. {
  219. Directory.Delete(disabled);
  220. dexists = false;
  221. }
  222. }
  223. private async void refreshbtn_Click(object sender, EventArgs e)
  224. {
  225. CheckIfPatched(); //Set from placeholder
  226. lastGameUpdateTime = GetLastGameUpdateTime();
  227. var mods = GetInstalledMods();
  228. await GetAvailableMods();
  229. CheckUninstalledMods(mods);
  230. CheckIfPatched(); //Check after getting the available mods to show GCIPA updates
  231. }
  232. private void validatebtn_Click(object sender, EventArgs e)
  233. {
  234. if (CheckNoExe())
  235. return;
  236. 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)
  237. return;
  238. string exe = GetExe();
  239. File.Delete(GamePath($@"\{exe.Replace(".exe", "")}_Data\Managed\IllusionInjector.dll")); //Used to check if game is patched
  240. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  241. Process.Start("steam://validate/1078000/");
  242. else
  243. Process.Start("xdg-open", "steam://validate/1078000/");
  244. }
  245. }
  246. }