2020-06-15 19:11:05 +00:00
using GCMM.Properties ;
2020-06-15 21:17:49 +00:00
using Newtonsoft.Json.Linq ;
2020-06-15 19:11:05 +00:00
using System ;
2020-06-16 17:22:29 +00:00
using System.Collections.Generic ;
2020-06-15 21:17:49 +00:00
using System.Diagnostics ;
2020-06-15 19:11:05 +00:00
using System.Drawing ;
using System.IO ;
2020-06-15 21:17:49 +00:00
using System.IO.Compression ;
2020-06-15 19:11:05 +00:00
using System.Linq ;
2020-06-15 21:17:49 +00:00
using System.Net ;
using System.Reflection ;
2020-06-15 19:11:05 +00:00
using System.Text.RegularExpressions ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
namespace GCMM
{
public partial class MainForm : Form
{
public MainForm ( )
{
InitializeComponent ( ) ;
}
2020-08-23 21:38:10 +00:00
private readonly Dictionary < string , ModInfo > mods = new Dictionary < string , ModInfo > ( ) ;
private readonly ModInfo gcipa = new ModInfo { Author = "modtainers" , Name = "GCIPA" } ;
2020-10-03 13:41:31 +00:00
private readonly ModInfo gcmm = new ModInfo { Author = "NorbiPeti" , Name = "GCMM" } ;
2020-12-31 17:05:38 +00:00
private DateTime lastGameUpdateTime ;
2021-01-20 17:31:34 +00:00
private string steamPath ;
2020-08-23 21:38:10 +00:00
private const string defaultInfo = @ "
2021-05-15 00:21:05 +00:00
Techblox Mod Manager
2020-06-17 21:56:18 +00:00
2020-08-18 14:02:57 +00:00
If you click on a mod it will show some info about it . The install instructions there are usually for manual installs .
2021-05-15 00:21:05 +00:00
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 Steam but if you didn ' t then you must use the Play button .
This will first download and run the patcher ( GCIPA ) if needed . If all goes well , after some time a modded Techblox should launch .
2020-06-17 21:56:18 +00:00
2021-05-15 00:21:05 +00:00
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 .
2020-08-18 14:02:57 +00:00
Until updated versions are released , use the "" Disable mods "" checkbox at the bottom to launch the game without mods .
2021-01-20 21:41:21 +00:00
If you enabled auto - patching you will get a warning about this .
2020-06-17 21:56:18 +00:00
2021-05-15 00:21:05 +00:00
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 "" .
2020-06-17 21:56:18 +00:00
Disclaimer :
2021-05-15 00:21:05 +00:00
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 .
2020-06-17 21:56:18 +00:00
2020-08-18 14:02:57 +00:00
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 .
2021-01-20 21:41:21 +00:00
You may also want to verify the game ' s files by clicking on the Validate game button .
2020-06-17 21:56:18 +00:00
";
2020-06-16 17:22:29 +00:00
2021-01-19 23:49:11 +00:00
private async void Form1_Load ( object sender , EventArgs e )
{
2021-01-20 23:59:16 +00:00
if ( mods . Values . All ( mod = > mod . LatestVersion = = null ) ) //Not (fully) loaded yet
await LoadEverything ( true ) ;
2021-01-19 23:49:11 +00:00
}
2021-01-20 23:59:16 +00:00
public async Task LoadEverything ( bool evenMods )
2020-06-15 19:11:05 +00:00
{
2020-06-18 18:05:14 +00:00
if ( Settings . Default . NeedsUpdate )
{
Settings . Default . Upgrade ( ) ;
Settings . Default . NeedsUpdate = false ;
Settings . Default . Save ( ) ;
}
2020-06-15 19:11:05 +00:00
modlist . Items . Clear ( ) ;
2021-01-19 23:49:11 +00:00
mods . Clear ( ) ; //This method may get called twice when ran from the command line
2020-06-15 19:11:05 +00:00
UpdateButton ( installbtn , false ) ;
2020-06-17 21:56:18 +00:00
modinfobox . Text = defaultInfo ;
2021-01-20 21:41:21 +00:00
var ( steamPath , user ) = GetSteamLocationAndUser ( ) ;
2021-01-20 17:31:34 +00:00
if ( steamPath ! = null )
this . steamPath = steamPath ;
else
{
MessageBox . Show ( "Steam not found! If you have Steam installed, please report this to ExMods.\n\nThe Steam install is checked to autodetect where the game is installed and to optionally configure auto-patching." , "Steam not found" ) ;
status . Text = "Status: Steam not found" ;
return ;
}
if ( Settings . Default . SteamUserID = = 0 & & Settings . Default . AutoLaunch )
{
if ( MessageBox . Show ( "Do you want GCMM to change the game's launch settings so it can ensure the game is patched?\n\n" +
"If you say yes, GCMM will do a quick check before the game is launched and patches if necessary. " +
2021-05-15 00:21:05 +00:00
"This way you (hopefully) won't see crashes after a Techblox update.\n\n" +
"Note that this also means that if you (re)move GCMM without disabling this in the settings then you won't be able to launch Techblox until you change the launch options in Steam." ,
2021-01-20 17:31:34 +00:00
"GCMM auto-patching" , MessageBoxButtons . YesNo ) = = DialogResult . Yes )
DetectConfigLocationAndAutoStart ( steamPath , ref user ) ;
else
Settings . Default . AutoLaunch = false ;
Settings . Default . Save ( ) ;
}
2020-07-17 18:57:46 +00:00
if ( string . IsNullOrWhiteSpace ( Settings . Default . GamePath ) | | GetExe ( ) = = null )
2020-06-15 19:11:05 +00:00
{
Settings . Default . GamePath = GetGameFolder ( ) ;
if ( string . IsNullOrWhiteSpace ( Settings . Default . GamePath ) )
Settings . Default . GamePath = SelectGameFolder ( ) ;
else
MessageBox . Show ( "Found game at " + Settings . Default . GamePath ) ;
Settings . Default . Save ( ) ;
}
2020-06-15 21:17:49 +00:00
if ( string . IsNullOrWhiteSpace ( Settings . Default . GamePath ) )
{
status . Text = "Status: Game not found" ;
return ;
}
2020-08-18 14:02:57 +00:00
DeleteEmptyPluginsDir ( out bool pexists , out bool dexists ) ;
if ( ! pexists & & dexists )
unpatched . Checked = true ; //It will call the event but that won't do anything
2021-01-20 23:59:16 +00:00
await RefreshEverything ( evenMods ) ;
2020-06-15 19:11:05 +00:00
}
2020-06-18 16:28:07 +00:00
private async void playbtn_Click ( object sender , EventArgs e )
2020-06-15 21:17:49 +00:00
{
if ( playbtn . ForeColor = = Color . Green ) return ; //Disabled
2020-07-18 20:25:52 +00:00
await UpdateAPI ( ) ;
2020-06-18 16:28:07 +00:00
await PatchStartGame ( ) ; //It will call EndWork();
2020-06-15 19:11:05 +00:00
}
private void settingsbtn_Click ( object sender , EventArgs e )
{
2020-06-15 21:17:49 +00:00
if ( settingsbtn . ForeColor = = Color . Green ) return ; //Disabled
2020-06-15 19:11:05 +00:00
var sf = new SettingsForm ( ) ;
sf . ShowDialog ( this ) ;
}
2020-06-16 13:45:04 +00:00
private void modlist_SelectedIndexChanged ( object sender , EventArgs e )
{
2020-06-17 13:08:22 +00:00
if ( working ) return ;
2020-06-18 16:28:07 +00:00
modinfobox . Clear ( ) ;
2020-06-17 13:08:22 +00:00
switch ( modlist . SelectedItems . Count )
{
case 0 :
2020-06-17 21:56:18 +00:00
modinfobox . Text = defaultInfo ;
2020-06-17 13:08:22 +00:00
UpdateButton ( installbtn , false ) ;
UpdateButton ( uninstallbtn , false ) ;
break ;
case 1 :
default :
installbtn . Text = "Install mod" ;
UpdateButton ( installbtn , false ) ;
UpdateButton ( uninstallbtn , false ) ;
2020-06-17 21:56:18 +00:00
bool install = false , update = false ;
2021-01-01 23:12:52 +00:00
Action < string , Color > addText = ( txt , color ) = >
{
int start = modinfobox . Text . Length ;
modinfobox . AppendText ( txt + Environment . NewLine + Environment . NewLine ) ;
modinfobox . Select ( start , txt . Length ) ;
modinfobox . SelectionColor = color ;
modinfobox . DeselectAll ( ) ;
modinfobox . SelectionColor = modinfobox . ForeColor ;
} ;
2020-06-17 13:08:22 +00:00
foreach ( ListViewItem item in modlist . SelectedItems )
{
var mod = mods [ item . Name ] ;
if ( modlist . SelectedItems . Count = = 1 )
2020-06-17 21:56:18 +00:00
{
2021-01-01 23:12:52 +00:00
if ( mod . Updatable )
addText ( "New version available! " + mod . UpdateDetails , Color . Aqua ) ;
if ( mod . LastUpdated < lastGameUpdateTime )
addText ( "Outdated mod! It may not work properly on the latest version of the game." , Color . DarkOrange ) ;
if ( mod . Description ! = null )
modinfobox . AppendText ( mod . Description . Replace ( "\n" , Environment . NewLine ) ) ;
2020-06-17 21:56:18 +00:00
}
2020-06-17 13:08:22 +00:00
else
modinfobox . Text = modlist . SelectedItems . Count + " mods selected" ;
if ( mod . DownloadURL ! = null & & ! ( mod . LatestVersion < = mod . Version ) )
{
UpdateButton ( installbtn , true ) ;
if ( mod . Version ! = null )
2020-06-17 21:56:18 +00:00
update = true ;
2020-06-17 13:08:22 +00:00
else
2020-06-17 21:56:18 +00:00
install = true ;
2020-06-17 13:08:22 +00:00
}
if ( mod . Version ! = null )
UpdateButton ( uninstallbtn , true ) ;
}
2020-06-17 21:56:18 +00:00
if ( install & & update )
installbtn . Text = "Install and update mod" ;
else if ( update )
installbtn . Text = "Update mod" ;
else
installbtn . Text = "Install mod" ;
2020-06-17 13:08:22 +00:00
break ;
}
2020-08-18 14:02:57 +00:00
if ( unpatched . Checked )
{ //Don't allow (un)installing mods if mods are disabled
UpdateButton ( installbtn , false ) ;
UpdateButton ( uninstallbtn , false ) ;
modlist . Enabled = false ;
}
else
modlist . Enabled = true ;
2020-06-17 13:08:22 +00:00
}
2020-06-16 13:45:04 +00:00
2020-06-17 13:08:22 +00:00
private async void installbtn_Click ( object sender , EventArgs e )
{
if ( installbtn . ForeColor = = Color . Green ) return ; //Disabled
if ( ! BeginWork ( ) ) return ;
foreach ( ListViewItem item in modlist . SelectedItems )
{
2020-06-17 21:56:18 +00:00
var mod = mods [ item . Name ] ;
if ( item . Group . Name = = "installed" & & ( mod . DownloadURL = = null | | mod . LatestVersion < = mod . Version ) ) continue ;
await InstallMod ( mod ) ;
2020-06-17 13:08:22 +00:00
}
EndWork ( ) ;
2020-06-16 13:45:04 +00:00
}
2020-06-17 16:31:20 +00:00
private void uninstallbtn_Click ( object sender , EventArgs e )
{
if ( uninstallbtn . ForeColor = = Color . Green ) return ; //Disabled
foreach ( ListViewItem item in modlist . SelectedItems )
{
if ( item . Group . Name ! = "installed" ) continue ;
UninstallMod ( mods [ item . Name ] ) ;
}
EndWork ( ) ; //Update button states
}
2020-06-17 21:56:18 +00:00
private void findlog_Click ( object sender , EventArgs e )
{
if ( Environment . OSVersion . Platform = = PlatformID . Win32NT )
{
2020-08-18 18:56:19 +00:00
if ( CheckNoExe ( out string exe ) )
return ;
Process . Start ( "explorer.exe" , $@"/select,{Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)}Low\Freejam\{exe.Replace(" . exe ", " ")}\Player.log" ) ;
2020-06-17 21:56:18 +00:00
}
}
private void unpatched_CheckedChanged ( object sender , EventArgs e )
2020-08-18 14:02:57 +00:00
{ //Not using the patcher's revert option because sometimes it restores the wrong files - the game can be patched without mods
2020-08-18 18:56:19 +00:00
if ( CheckNoExe ( ) )
return ;
2020-06-17 21:56:18 +00:00
CheckIfPatched ( ) ;
2020-08-18 14:02:57 +00:00
modlist_SelectedIndexChanged ( modlist , null ) ;
string plugins = GamePath ( "\\Plugins" ) ;
string disabled = GamePath ( "\\Plugins_Disabled" ) ;
DeleteEmptyPluginsDir ( out bool pexists , out bool dexists ) ;
if ( unpatched . Checked )
{
if ( pexists )
{
if ( dexists )
Directory . Delete ( disabled , true ) ; //Resolving conflicts would be complicated so delete the other mods - this shouldn't happen normally
Directory . Move ( plugins , disabled ) ;
}
}
else
{
if ( dexists )
{
if ( pexists )
Directory . Delete ( plugins , true ) ;
Directory . Move ( disabled , plugins ) ;
}
}
}
private void DeleteEmptyPluginsDir ( out bool pexists , out bool dexists )
{
string plugins = GamePath ( "\\Plugins" ) ;
string disabled = GamePath ( "\\Plugins_Disabled" ) ;
pexists = Directory . Exists ( plugins ) ;
dexists = Directory . Exists ( disabled ) ;
if ( pexists & & ! Directory . EnumerateFiles ( plugins ) . Any ( ) )
{
Directory . Delete ( plugins ) ;
pexists = false ;
}
if ( dexists & & ! Directory . EnumerateFiles ( disabled ) . Any ( ) )
{
Directory . Delete ( disabled ) ;
dexists = false ;
}
2020-06-17 21:56:18 +00:00
}
2020-08-18 18:56:19 +00:00
2020-08-23 21:38:10 +00:00
private async void refreshbtn_Click ( object sender , EventArgs e )
2021-01-19 23:49:11 +00:00
{
2021-01-20 23:59:16 +00:00
await RefreshEverything ( true ) ;
2021-01-19 23:49:11 +00:00
}
2021-01-20 23:59:16 +00:00
private async Task RefreshEverything ( bool evenMods )
2020-08-18 18:56:19 +00:00
{
2020-08-23 21:38:10 +00:00
CheckIfPatched ( ) ; //Set from placeholder
2021-01-01 03:45:51 +00:00
lastGameUpdateTime = await GetLastGameUpdateTime ( ) ;
2020-08-18 18:56:19 +00:00
var mods = GetInstalledMods ( ) ;
2021-01-20 23:59:16 +00:00
if ( evenMods )
await GetAvailableMods ( ) ;
2020-08-18 18:56:19 +00:00
CheckUninstalledMods ( mods ) ;
2020-08-23 21:38:10 +00:00
CheckIfPatched ( ) ; //Check after getting the available mods to show GCIPA updates
2020-08-18 18:56:19 +00:00
}
2020-08-18 19:32:03 +00:00
private void validatebtn_Click ( object sender , EventArgs e )
{
if ( CheckNoExe ( ) )
return ;
2021-01-20 23:59:16 +00:00
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 if auto-patching isn't enabled then 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 )
2020-08-18 19:32:03 +00:00
return ;
2020-10-03 11:32:53 +00:00
string exe = GetExe ( ) ;
File . Delete ( GamePath ( $@"\{exe.Replace(" . exe ", " ")}_Data\Managed\IllusionInjector.dll" ) ) ; //Used to check if game is patched
2020-08-18 19:32:03 +00:00
if ( Environment . OSVersion . Platform = = PlatformID . Win32NT )
Process . Start ( "steam://validate/1078000/" ) ;
else
Process . Start ( "xdg-open" , "steam://validate/1078000/" ) ;
}
2021-01-19 23:49:11 +00:00
private void MainForm_Shown ( object sender , EventArgs e )
{
Focus ( ) ;
}
2020-06-15 19:11:05 +00:00
}
}