Skip to content

Commit

Permalink
New message popups and bugfix for btdapi mods
Browse files Browse the repository at this point in the history
Added more BTDApi Injector messages. Fixed bug with enable/disable btdapi mods. New message telling player to restart btd6 if they try enabling/disabling mods while game is open
  • Loading branch information
gurrenm3 committed Dec 25, 2020
1 parent 60d3bc9 commit aa5308a
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 41 deletions.
2 changes: 2 additions & 0 deletions BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj
Expand Up @@ -65,6 +65,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BgThread.cs" />
<Compile Include="BtdApi Handler.cs" />
<Compile Include="Game\GameInfo.cs" />
<Compile Include="Game\GameType.cs" />
<Compile Include="Game\SteamUtils.cs" />
Expand All @@ -88,5 +89,6 @@
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
34 changes: 34 additions & 0 deletions BTD6 Mod Manager.Lib/BtdApi Handler.cs
@@ -0,0 +1,34 @@
using System.Diagnostics;
using System.IO;
using System.Windows;

namespace BTD6_Mod_Manager.Lib
{
public class BtdApi_Handler
{
public static bool DoesInjectorExist(string modsDir)
{
const string disabledKey = ".disabled";
bool injectorExists = File.Exists($"{modsDir}\\BtdAPI_Injector.dll");
bool disabledInjectorExists = File.Exists($"{modsDir}\\BtdAPI_Injector.dll{disabledKey}");

return (injectorExists || disabledInjectorExists);
}

public static void AskDownloadInjector()
{
var result = MessageBox.Show("The Injector for BTD6 API mods was not found. It is required in order to use BTD6 API mods." +
" Do you want to download it?", "Download BTD6 API Injector?", MessageBoxButton.YesNo);

if (result == MessageBoxResult.Yes)
{
Process.Start("https://www.nexusmods.com/bloonstd6/mods/41?tab=description");
}
else
{
Logger.Log("You chose not to download the injector. You're BTD6 API mods won't work until you get it" +
". However, all other BTD6 mods will continue to work.", OutputType.Both);
}
}
}
}
1 change: 1 addition & 0 deletions BTD6 Mod Manager.wpf/SessionData.cs
Expand Up @@ -15,6 +15,7 @@ public class SessionData
public static string ModsDir { get { return GetModsDir(); } }

public static List<string> loadedMods = new List<string>();
public static bool ShownInjectorRequiredMessage = false;

private static string GetModsDir()
{
Expand Down
5 changes: 5 additions & 0 deletions BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs
Expand Up @@ -9,6 +9,7 @@
using BTD6_Mod_Manager.UserControls;
using BTD6_Mod_Manager.Windows;
using BTD6_Mod_Manager.Persistance;
using BTD6_Mod_Manager.Lib.Game;

namespace BTD6_Mod_Manager
{
Expand All @@ -31,6 +32,10 @@ private void CheckBox_Clicked(object sender, RoutedEventArgs e)
if (TempGuard.IsDoingWork(MainWindow.workType))
return;

bool isBtd6Running = SteamUtils.IsGameRunning(GameType.BTD6);
if (isBtd6Running)
Logger.Log("You need to restart BTD6 for your changes to take place", OutputType.Both);

CheckBox cb = (CheckBox)(sender);

if (cb.IsChecked == true)
Expand Down
62 changes: 21 additions & 41 deletions BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs
Expand Up @@ -6,9 +6,6 @@
using BTD6_Mod_Manager.Classes;
using BTD6_Mod_Manager.Lib;
using BTD6_Mod_Manager.Lib.Game;
using System.Linq;
using System.Threading;
using System.Diagnostics;
using BTD6_Mod_Manager.Persistance;

namespace BTD6_Mod_Manager.UserControls
Expand Down Expand Up @@ -74,12 +71,8 @@ public void PopulateMods(GameType game)
continue;
}
string modName = "";
if (File.Exists(mod))
modName = mod;
else
modName = mod + disabledKey;
string modName = (File.Exists(mod)) ? mod : mod + disabledKey;
TempList.Add(modName);
AddToSelectedModLB(modName);
}
Expand All @@ -106,7 +99,7 @@ public void RemoveFromSelectedLB(string modPath)
if (Settings.LoadedSettings.LastUsedMods.Contains(modFile.FullName))
Settings.LoadedSettings.LastUsedMods.Remove(modFile.FullName);

if (!modFile.FullName.Contains(".btd6mod") && !modFile.FullName.EndsWith(disabledKey))
if (!modFile.FullName.EndsWith(disabledKey))
{
string newPath = modFile.FullName + disabledKey;
if (File.Exists(newPath))
Expand Down Expand Up @@ -148,18 +141,30 @@ public void AddToSelectedModLB(string modPath)
}

SelectedMods_ListBox.SelectedIndex = SelectedMods_ListBox.Items.Count - 1;

bool isBtd6ApiMod = f.Extension == ".btd6mod";
bool injectorExists = BtdApi_Handler.DoesInjectorExist(SessionData.ModsDir);
bool shownInjectorNeededMsg = SessionData.ShownInjectorRequiredMessage;

bool showErrorMessage = (isBtd6ApiMod && !injectorExists && !shownInjectorNeededMsg);
if (showErrorMessage)
{
BtdApi_Handler.AskDownloadInjector();
SessionData.ShownInjectorRequiredMessage = true;
Settings.LoadedSettings.ShownBtdApiInjectorMessage = true;
}
}


public void AddItemToModsList(string modPath) => AddItemToModsList(new FileInfo(modPath));
public void AddItemToModsList(FileInfo modFile)
{
string modName = "";
string modName;
bool isBtdApiMod = modFile.FullName.Contains(".btd6mod");
bool isLastUsedMod = Settings.LoadedSettings.LastUsedMods.Contains(modFile.FullName);
bool isDisabled = modFile.FullName.EndsWith(disabledKey);

if (!isBtdApiMod && !isLastUsedMod && !isDisabled)
if (!isLastUsedMod && !isDisabled)
{
string newPath = modFile.FullName + disabledKey;
if (File.Exists(newPath))
Expand All @@ -174,22 +179,13 @@ public void AddItemToModsList(FileInfo modFile)
Logger.Log("One or more of your mods are BTD API mods. This means you need to use an injector to inject them into BTD6.", OutputType.Both);

string btd6ModsDir = SessionData.ModsDir;
if (!File.Exists(btd6ModsDir + "\\BtdAPI_Injector.dll") && !File.Exists(btd6ModsDir + "\\BtdAPI_Injector.dll.disabled"))
if (!BtdApi_Handler.DoesInjectorExist(SessionData.ModsDir))
{
var result = MessageBox.Show("The Injector for BTD6 API mods was not found. It is required in order to use BTD6 API mods." +
" Do you want to download it?", "Download BTD6 API Injector?", MessageBoxButton.YesNo);

if (result == MessageBoxResult.Yes)
{
Process.Start("https://www.nexusmods.com/bloonstd6/mods/41?tab=description");
}
else
{
Logger.Log("You chose not to download the injector. You're BTD6 API mods won't work until you get it" +
". However, all other BTD6 mods will continue to work.", OutputType.Both);
}
BtdApi_Handler.AskDownloadInjector();
}

Settings.LoadedSettings.ShownBtdApiInjectorMessage = true;
SessionData.ShownInjectorRequiredMessage = true;
}

modName = modFile.Name.Replace(disabledKey, "");
Expand All @@ -215,22 +211,6 @@ public void AddItemToModsList(FileInfo modFile)
private void ModsUserControl_Loaded(object sender, RoutedEventArgs e)
{
PopulateMods(SessionData.currentGame);

/*BgThread.AddToQueue(() =>
{
int lastFileCount = Directory.GetFiles(SessionData.ModsDir).Count();
while (true)
{
Thread.Sleep(1000);
var files = Directory.GetFiles(SessionData.ModsDir);
if (files.Count() == lastFileCount)
continue;
lastFileCount = files.Count();
OnRepopulateMods(new ModUcEventArgs());
}
});*/
}
private void ModsUserControl_SizeChanged(object sender, SizeChangedEventArgs e)
{
Expand Down

0 comments on commit aa5308a

Please sign in to comment.