Techblox Mod Manager / Launcher
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

184 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) || GetExe() == null)
  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 UpdateAPI();
  71. await PatchStartGame(); //It will call EndWork();
  72. }
  73. private void settingsbtn_Click(object sender, EventArgs e)
  74. {
  75. if (settingsbtn.ForeColor == Color.Green) return; //Disabled
  76. var sf = new SettingsForm();
  77. sf.ShowDialog(this);
  78. }
  79. private void modlist_SelectedIndexChanged(object sender, EventArgs e)
  80. {
  81. if (working) return;
  82. modinfobox.Clear();
  83. switch (modlist.SelectedItems.Count)
  84. {
  85. case 0:
  86. modinfobox.Text = defaultInfo;
  87. UpdateButton(installbtn, false);
  88. UpdateButton(uninstallbtn, false);
  89. break;
  90. case 1:
  91. default:
  92. installbtn.Text = "Install mod";
  93. UpdateButton(installbtn, false);
  94. UpdateButton(uninstallbtn, false);
  95. bool install = false, update = false;
  96. foreach (ListViewItem item in modlist.SelectedItems)
  97. {
  98. var mod = mods[item.Name];
  99. if (modlist.SelectedItems.Count == 1)
  100. {
  101. bool up = mod.Updatable;
  102. modinfobox.Text = ((up ? "New version available! " + mod.UpdateDetails + "\n\n"
  103. : "") + mod.Description).Replace("\n", Environment.NewLine);
  104. if(up)
  105. {
  106. modinfobox.Select(0, "New version available!".Length);
  107. modinfobox.SelectionColor = Color.Aqua;
  108. modinfobox.DeselectAll();
  109. modinfobox.SelectionColor = modinfobox.ForeColor;
  110. }
  111. }
  112. else
  113. modinfobox.Text = modlist.SelectedItems.Count + " mods selected";
  114. if (mod.DownloadURL != null && !(mod.LatestVersion <= mod.Version))
  115. {
  116. UpdateButton(installbtn, true);
  117. if (mod.Version != null)
  118. update = true;
  119. else
  120. install = true;
  121. }
  122. if (mod.Version != null)
  123. UpdateButton(uninstallbtn, true);
  124. }
  125. if (install && update)
  126. installbtn.Text = "Install and update mod";
  127. else if (update)
  128. installbtn.Text = "Update mod";
  129. else
  130. installbtn.Text = "Install mod";
  131. break;
  132. }
  133. }
  134. private async void installbtn_Click(object sender, EventArgs e)
  135. {
  136. if (installbtn.ForeColor == Color.Green) return; //Disabled
  137. if (!BeginWork()) return;
  138. foreach (ListViewItem item in modlist.SelectedItems)
  139. {
  140. var mod = mods[item.Name];
  141. if (item.Group.Name == "installed" && (mod.DownloadURL == null || mod.LatestVersion <= mod.Version)) continue;
  142. await InstallMod(mod);
  143. }
  144. EndWork();
  145. }
  146. private void uninstallbtn_Click(object sender, EventArgs e)
  147. {
  148. if (uninstallbtn.ForeColor == Color.Green) return; //Disabled
  149. foreach (ListViewItem item in modlist.SelectedItems)
  150. {
  151. if (item.Group.Name != "installed") continue;
  152. UninstallMod(mods[item.Name]);
  153. }
  154. EndWork(); //Update button states
  155. }
  156. private void findlog_Click(object sender, EventArgs e)
  157. {
  158. if (Environment.OSVersion.Platform == PlatformID.Win32NT)
  159. {
  160. Process.Start("explorer.exe", $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{GetExe().Replace(".exe", "")}\Player.log");
  161. }
  162. }
  163. private void unpatched_CheckedChanged(object sender, EventArgs e)
  164. {
  165. CheckIfPatched();
  166. }
  167. }
  168. }