Read game version from the game, begin renaming to TBMM everywhere

This commit is contained in:
Norbi Peti 2021-06-16 01:25:48 +02:00
parent adfe43f1a3
commit 43db83717f
18 changed files with 62 additions and 46 deletions

View file

@ -1,4 +1,4 @@
namespace GCMM namespace TBMM
{ {
public enum AutoPatchingState public enum AutoPatchingState
{ {

View file

@ -1,7 +1,7 @@
using System.IO; using System.IO;
using Newtonsoft.Json; using Newtonsoft.Json;
namespace GCMM namespace TBMM
{ {
public class Configuration public class Configuration
{ {

View file

@ -1,4 +1,4 @@
namespace GCMM namespace TBMM
{ {
partial class CustomMessageBox partial class CustomMessageBox
{ {

View file

@ -1,6 +1,6 @@
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
public partial class CustomMessageBox : Form public partial class CustomMessageBox : Form
{ {

View file

@ -1,6 +1,6 @@
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
public static class DialogUtils public static class DialogUtils
{ {

View file

@ -6,7 +6,7 @@
<UseWindowsForms>true</UseWindowsForms> <UseWindowsForms>true</UseWindowsForms>
<SignAssembly>false</SignAssembly> <SignAssembly>false</SignAssembly>
<ApplicationIcon>favicon.ico</ApplicationIcon> <ApplicationIcon>favicon.ico</ApplicationIcon>
<Version>1.4.0</Version> <Version>1.5.0</Version>
<Authors>NorbiPeti</Authors> <Authors>NorbiPeti</Authors>
<Company>ExMods</Company> <Company>ExMods</Company>
<Description>A mod manager for Techblox. It automatically downloads and runs GCIPA and allows the user to install mods.</Description> <Description>A mod manager for Techblox. It automatically downloads and runs GCIPA and allows the user to install mods.</Description>
@ -33,9 +33,6 @@
<ItemGroup> <ItemGroup>
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
<Reference Include="System.Windows.Forms" /> <Reference Include="System.Windows.Forms" />
<Reference Include="UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null">
<HintPath>..\..\ref\TechbloxPreview_Data\Managed\UnityEngine.CoreModule.dll</HintPath>
</Reference>
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>

View file

@ -8,7 +8,7 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace GCMM { namespace TBMM {
using System; using System;
@ -39,7 +39,7 @@ namespace GCMM {
internal static global::System.Resources.ResourceManager ResourceManager { internal static global::System.Resources.ResourceManager ResourceManager {
get { get {
if (object.ReferenceEquals(resourceMan, null)) { if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("GCMM.Localization", typeof(Localization).Assembly); global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("TBMM.Localization", typeof(Localization).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;

View file

@ -1,4 +1,4 @@
namespace GCMM namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {

View file

@ -9,14 +9,14 @@ using System.Resources;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
public partial class MainForm : Form public partial class MainForm : Form
{ {
public MainForm() public MainForm()
{ {
InitializeComponent(); InitializeComponent();
resources = new ResourceManager("GCMM.Localization", Assembly.GetExecutingAssembly()); resources = new ResourceManager("TBMM.Localization", Assembly.GetExecutingAssembly());
Configuration = Configuration.Load(); Configuration = Configuration.Load();
} }
@ -25,21 +25,19 @@ namespace GCMM
private readonly ResourceManager resources; private readonly ResourceManager resources;
private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>(); private readonly Dictionary<string, ModInfo> mods = new Dictionary<string, ModInfo>();
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" }; private readonly ModInfo gcipa = new ModInfo { Author = "modtainers", Name = "GCIPA" };
private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti", Name = "GCMM" }; private readonly ModInfo tbmm = new ModInfo { Author = "NorbiPeti", Name = "TBMM" };
private DateTime lastGameUpdateTime; private DateTime lastGameUpdateTime;
private const string defaultInfo = @" private const string defaultInfo = @"
Techblox Mod Manager Techblox Mod Manager
If you click on a mod it will show some info about it. The install instructions there are usually for manual installs. If you click on a mod it will show some info about it. The install instructions there are usually for manual installs.
To get started, click on a mod and select Install mod. Most mods need TechbloxModdingAPI as well so it'll be installed. To get started, click on a mod and select Install mod. Most mods need TechbloxModdingAPI as well so it'll be installed.
Then launch Techblox: if you enabled auto-patching then you can use the launcher but if you didn't then you must use the Play button. Then launch Techblox by clicking on the Play button below. Mods are only loaded if you start the game from here.
This will first download and run the patcher (GCIPA) if needed. If all goes well, after some time a modded Techblox should launch. This will first download and run the patcher (GCIPA) if needed. If all goes well, after some time a modded Techblox should launch.
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. 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.
Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods. Until updated versions are released, use the ""Disable mods"" checkbox at the bottom to launch the game without mods.
If you enabled auto-patching you will get a warning about this. If you launch the game through the launcher after an update and encounter an error, either repair the game or launch it through the mod manager.
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"" or the game may not function properly.
Disclaimer: Disclaimer:
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. 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.
@ -130,8 +128,8 @@ You may also want to verify the game's files in the launcher.
{ {
if (mod.Updatable) if (mod.Updatable)
addText("New version available! " + mod.UpdateDetails, Color.Aqua); addText("New version available! " + mod.UpdateDetails, Color.Aqua);
if (mod.LastUpdated < lastGameUpdateTime) if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime)
addText("Outdated mod! It may not work properly on the latest version of the game.", Color.DarkOrange); addText("Outdated mod! It may not work properly on the current version of the game.", Color.DarkOrange);
if (mod.Description != null) if (mod.Description != null)
modinfobox.AppendText(mod.Description.Replace("\n", Environment.NewLine)); modinfobox.AppendText(mod.Description.Replace("\n", Environment.NewLine));
} }

View file

@ -7,7 +7,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {

View file

@ -11,7 +11,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {
@ -53,11 +53,11 @@ namespace GCMM
} }
try try
{ {
string mmpath = "GCMM.exe"; string mmpath = "TBMM.exe";
if (File.Exists(mmpath)) if (File.Exists(mmpath))
{ {
var an = AssemblyName.GetAssemblyName(mmpath); var an = AssemblyName.GetAssemblyName(mmpath);
gcmm.Version = an.Version; tbmm.Version = an.Version;
} }
} }
catch (BadImageFormatException) catch (BadImageFormatException)
@ -79,20 +79,21 @@ namespace GCMM
var mod = new ModInfo var mod = new ModInfo
{ {
Author = sp[0].Trim(), Author = sp[0].Trim(),
Name = sp[1].Trim() Name = sp[1].Trim(),
LastUpdated = sp.Length > 2 ? DateTime.Parse(sp[2].Trim()) : default
}; };
if (await FetchModInfo(mod, preview, true)) //If it's actually a mod if (await FetchModInfo(mod, preview, true)) //If it's actually a mod
AddUpdateModInList(mod); AddUpdateModInList(mod);
} }
} }
if (gcmm.LatestVersion == null) //Only check once if (tbmm.LatestVersion == null) //Only check once
{ {
await FetchModInfo(gcipa, preview, false); await FetchModInfo(gcipa, preview, false);
await FetchModInfo(gcmm, preview, false); await FetchModInfo(tbmm, preview, false);
if (gcmm.Updatable) if (tbmm.Updatable)
if (MessageBox.Show("There is a GCMM update available! Do you want to download it now? If yes, extract it over this installation.\n\n" + gcmm.UpdateDetails, "Mod Manager update", MessageBoxButtons.YesNo) if (MessageBox.Show("There is a TBMM update available! Do you want to download it now? If yes, extract it over this installation.\n\n" + tbmm.UpdateDetails, "Mod Manager update", MessageBoxButtons.YesNo)
== DialogResult.Yes) == DialogResult.Yes)
Process.Start(gcmm.DownloadURL); Process.Start(tbmm.DownloadURL);
} }
} }
@ -134,7 +135,9 @@ namespace GCMM
}); });
mod.DownloadURL = asset?["browser_download_url"]?.ToString(); mod.DownloadURL = asset?["browser_download_url"]?.ToString();
mod.LastUpdated = (DateTime)release["published_at"]; var lastUpdated = (DateTime)release["published_at"];
if (mod.LastUpdated < lastUpdated)
mod.LastUpdated = lastUpdated; //If there's a newer release than the last known working date
var ver = verstr.Split('.').Select(str => int.Parse(str)).ToArray(); var ver = verstr.Split('.').Select(str => int.Parse(str)).ToArray();
int getver(byte i) => ver.Length > i ? ver[i] : 0; //By default it sets values not present to -1, but we need them to be 0 int getver(byte i) => ver.Length > i ? ver[i] : 0; //By default it sets values not present to -1, but we need them to be 0
@ -189,7 +192,7 @@ namespace GCMM
if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion)
item.ForeColor = Color.Blue; item.ForeColor = Color.Blue;
else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime) else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime)
item.ForeColor = Color.DarkOrange; item.ForeColor = Color.OrangeRed;
else else
item.ForeColor = modlist.ForeColor; item.ForeColor = modlist.ForeColor;
} }

View file

@ -7,7 +7,7 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {
@ -103,7 +103,7 @@ namespace GCMM
await Task.Delay(500); //The EnsureShown() call should download info about GCIPA await Task.Delay(500); //The EnsureShown() call should download info about GCIPA
if (gcipa.DownloadURL == null) if (gcipa.DownloadURL == null)
{ {
MessageBox.Show("Could not get information about GCIPA in time. Please run GCMM manually."); MessageBox.Show("Could not get information about GCIPA in time. Please run TBMM manually.");
return retOpenedWindowShouldStay; return retOpenedWindowShouldStay;
} }
using (WebClient client = GetClient()) using (WebClient client = GetClient())

View file

@ -7,9 +7,8 @@ using System.Net;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
using Microsoft.Win32; using Microsoft.Win32;
using Application = UnityEngine.Application;
namespace GCMM namespace TBMM
{ {
partial class MainForm partial class MainForm
{ {
@ -100,9 +99,9 @@ namespace GCMM
{ {
if (!unpatched.Checked && MessageBox.Show("If the game updated just now, some mods may be incompatible or they may work just fine." + if (!unpatched.Checked && MessageBox.Show("If the game updated just now, some mods may be incompatible or they may work just fine." +
" Do you want to try running with mods?" + " Do you want to try running with mods?" +
"\n\nClick Yes to start the game with mods (after a small update or if you just installed GCMM)" + "\n\nClick Yes to start the game with mods (after a small update or if you just installed TBMM)" +
"\nClick No to disable mods before starting the game (after a major update)" + "\nClick No to disable mods before starting the game (after a major update)" +
"\n\nYou can always enable/disable mods by launching GCMM.", "\n\nYou can always enable/disable mods by launching TBMM.",
"Possible incompatibility warning", MessageBoxButtons.YesNo) == DialogResult.No) "Possible incompatibility warning", MessageBoxButtons.YesNo) == DialogResult.No)
unpatched.Checked = true; unpatched.Checked = true;
} }
@ -114,7 +113,7 @@ namespace GCMM
return; return;
if (MessageBox.Show("Mod update(s) available!\n\n" if (MessageBox.Show("Mod update(s) available!\n\n"
+ updatable.Select(mod => mod.Name + " " + mod.LatestVersion).Aggregate((a, b) => a + "\n") + updatable.Select(mod => mod.Name + " " + mod.LatestVersion).Aggregate((a, b) => a + "\n")
+ "\n\nDo you want to update them now? You can also update later by opening GCMM.", + "\n\nDo you want to update them now? You can also update later by opening TBMM.",
"Update(s) available", MessageBoxButtons.YesNo) == DialogResult.No) "Update(s) available", MessageBoxButtons.YesNo) == DialogResult.No)
return; return;
foreach (var mod in updatable) foreach (var mod in updatable)
@ -196,7 +195,26 @@ namespace GCMM
public DateTime GetGameVersionAsDate() public DateTime GetGameVersionAsDate()
{ {
return Convert.ToDateTime(Application.version); if (Configuration.GamePath == null) return default;
using var fs = File.OpenRead(GamePath("\\TechbloxPreview_Data\\globalgamemanagers"));
using var sr = new StreamReader(fs);
char[] data = new char[512];
while(!sr.EndOfStream)
{
Array.Copy(data, 256, data, 0, 256);
int read = sr.ReadBlock(data, 256, 256);
for (int i = 0; i < data.Length - 11; i++)
{
if (data[i] == '2')
{
string date = new string(data, i, 11);
if (date.StartsWith("202") && DateTime.TryParse(date, out var ret))
return ret;
}
}
}
return default;
} }
} }
} }

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace GCMM namespace TBMM
{ {
public class ModInfo public class ModInfo
{ {

View file

@ -4,7 +4,7 @@ using System.Linq;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
static class Program static class Program
{ {

View file

@ -1,4 +1,4 @@
namespace GCMM namespace TBMM
{ {
partial class SettingsForm partial class SettingsForm
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Windows.Forms; using System.Windows.Forms;
namespace GCMM namespace TBMM
{ {
public partial class SettingsForm : Form public partial class SettingsForm : Form
{ {

View file

@ -6,7 +6,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace GCMM namespace TBMM
{ {
public static class ZipArchiveExtensions public static class ZipArchiveExtensions
{ //https://stackoverflow.com/a/14795752/2703239 { //https://stackoverflow.com/a/14795752/2703239