Techblox Mod Manager / Launcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

183 lines
7.3KB

  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 Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
  24. private string defaultInfo = @"
  25. Gamecraft Mod Manager
  26. If you click on a mod it will show some info about it. The install instructions there are for manual installs.
  27. To get started, click on a mod and select Install mod. Most mods need GamecraftModdingAPI as well.
  28. Then, simply click Play. This will first download and run the patcher (GCIPA) if needed.
  29. If all goes well, after some time a modded Gamecraft should launch.
  30. 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.
  31. Until updated versions are released, use the ""Run unpatched"" checkbox at the bottom to launch the game without mods.
  32. 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.
  33. However, make sure to click Play each time you want to switch between modded and unmodded.
  34. Disclaimer:
  35. 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.
  36. If you encounter an issue while the game is patched, report it to us. If you think it's an issue with the game, test again with the unpatched option checked before reporting to Freejam.
  37. ";
  38. private void Form1_Load(object sender, EventArgs e)
  39. {
  40. if (Settings.Default.NeedsUpdate)
  41. {
  42. Settings.Default.Upgrade();
  43. Settings.Default.NeedsUpdate = false;
  44. Settings.Default.Save();
  45. }
  46. modlist.Items.Clear();
  47. UpdateButton(installbtn, false);
  48. modinfobox.Text = defaultInfo;
  49. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  50. {
  51. Settings.Default.GamePath = GetGameFolder();
  52. if (string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  53. Settings.Default.GamePath = SelectGameFolder();
  54. else
  55. MessageBox.Show("Found game at " + Settings.Default.GamePath);
  56. Settings.Default.Save();
  57. }
  58. if(string.IsNullOrWhiteSpace(Settings.Default.GamePath))
  59. {
  60. status.Text = "Status: Game not found";
  61. return;
  62. }
  63. CheckIfPatched();
  64. GetInstalledMods();
  65. GetAvailableMods();
  66. }
  67. private async void playbtn_Click(object sender, EventArgs e)
  68. {
  69. if (playbtn.ForeColor == Color.Green) return; //Disabled
  70. await PatchStartGame(); //It will call EndWork();
  71. }
  72. private void settingsbtn_Click(object sender, EventArgs e)
  73. {
  74. if (settingsbtn.ForeColor == Color.Green) return; //Disabled
  75. var sf = new SettingsForm();
  76. sf.ShowDialog(this);
  77. }
  78. private void modlist_SelectedIndexChanged(object sender, EventArgs e)
  79. {
  80. if (working) return;
  81. modinfobox.Clear();
  82. switch (modlist.SelectedItems.Count)
  83. {
  84. case 0:
  85. modinfobox.Text = defaultInfo;
  86. UpdateButton(installbtn, false);
  87. UpdateButton(uninstallbtn, false);
  88. break;
  89. case 1:
  90. default:
  91. installbtn.Text = "Install mod";
  92. UpdateButton(installbtn, false);
  93. UpdateButton(uninstallbtn, false);
  94. bool install = false, update = false;
  95. foreach (ListViewItem item in modlist.SelectedItems)
  96. {
  97. var mod = mods[item.Name];
  98. if (modlist.SelectedItems.Count == 1)
  99. {
  100. bool up = mod.Version != null && mod.Version < mod.LatestVersion;
  101. modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n"
  102. : "") + mod.Description).Replace("\n", Environment.NewLine);
  103. if(up)
  104. {
  105. modinfobox.Select(0, "New version available!".Length);
  106. modinfobox.SelectionColor = Color.Aqua;
  107. modinfobox.DeselectAll();
  108. modinfobox.SelectionColor = modinfobox.ForeColor;
  109. }
  110. }
  111. else
  112. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  113. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  114. {
  115. UpdateButton(installbtn, true);
  116. if (mod.Version != null)
  117. update = true;
  118. else
  119. install = true;
  120. }
  121. if (mod.Version != null)
  122. UpdateButton(uninstallbtn, true);
  123. }
  124. if (install && update)
  125. installbtn.Text = "Install and update mod";
  126. else if (update)
  127. installbtn.Text = "Update mod";
  128. else
  129. installbtn.Text = "Install mod";
  130. break;
  131. }
  132. }
  133. private async void installbtn_Click(object sender, EventArgs e)
  134. {
  135. if (installbtn.ForeColor == Color.Green) return; //Disabled
  136. if (!BeginWork()) return;
  137. foreach (ListViewItem item in modlist.SelectedItems)
  138. {
  139. var mod = mods[item.Name];
  140. if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
  141. await InstallMod(mod);
  142. }
  143. EndWork();
  144. }
  145. private void uninstallbtn_Click(object sender, EventArgs e)
  146. {
  147. if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
  148. foreach (ListViewItem item in modlist.SelectedItems)
  149. {
  150. if (item.Group.Name != "installed") continue;
  151. UninstallMod(mods[item.Name]);
  152. }
  153. EndWork(); //Update button states
  154. }
  155. private void findlog_Click(object sender, EventArgs e)
  156. {
  157. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  158. {
  159. Process.Start("explorer.exe", "/select,"+Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"Low\Freejam\Gamecraft\Player.log");
  160. }
  161. }
  162. private void unpatched_CheckedChanged(object sender, EventArgs e)
  163. {
  164. CheckIfPatched();
  165. }
  166. }
  167. }