Skip to content

Commit

Permalink
Added warning if user tries loading multiple of the same mod
Browse files Browse the repository at this point in the history
  • Loading branch information
gurrenm3 committed Dec 26, 2020
1 parent 5110701 commit a852561
Show file tree
Hide file tree
Showing 8 changed files with 70 additions and 35 deletions.
2 changes: 1 addition & 1 deletion BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj
Expand Up @@ -35,7 +35,7 @@
<ItemGroup>
<Reference Include="MelonLoader.ModHandler, Version=0.2.7.4, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\BTD6 Mod Manager.wpf\bin\Debug\MelonLoader.ModHandler.dll</HintPath>
<HintPath>F:\Program Files (x86)\Steam\steamapps\common\BloonsTD6\MelonLoader\MelonLoader.ModHandler.dll</HintPath>
</Reference>
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\BTD6 Mod Manager.wpf\packages\WindowsAPICodePack-Core.1.1.1\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
Expand Down
14 changes: 12 additions & 2 deletions BTD6 Mod Manager.Lib/MelonMods/MelonMod_Handler.cs
Expand Up @@ -58,8 +58,18 @@ public static System.Reflection.Assembly GetMod(int index)
/// </summary>
/// <param name="filePath">FilePath to the file you want to get MelonModInfo from</param>
/// <returns></returns>
public static MelonInfoAttribute GetModInfo(string filePath) =>
GetModInfo(System.Reflection.Assembly.LoadFrom(filePath));
public static MelonInfoAttribute GetModInfo(string filePath)
{
try
{
return GetModInfo(System.Reflection.Assembly.LoadFrom(filePath));
}
catch (Exception)
{
return null;
}
}


/// <summary>
/// Get the MelonInfo of the mod with the provided Assembly
Expand Down
1 change: 1 addition & 0 deletions BTD6 Mod Manager.wpf/BTD6 Mod Manager.csproj
Expand Up @@ -63,6 +63,7 @@
<Reference Include="DotNetZip, Version=1.13.8.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>packages\DotNetZip.1.13.8\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="MelonLoader.ModHandler, Version=0.2.7.4, Culture=neutral, PublicKeyToken=null" />
<Reference Include="Microsoft.WindowsAPICodePack, Version=1.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\Microsoft.WindowsAPICodePack-Core.1.1.0.2\lib\Microsoft.WindowsAPICodePack.dll</HintPath>
</Reference>
Expand Down
42 changes: 37 additions & 5 deletions BTD6 Mod Manager.wpf/Launcher.cs
@@ -1,27 +1,59 @@
using BTD6_Mod_Manager.Lib;
using BTD6_Mod_Manager.Lib.Game;
using BTD6_Mod_Manager.Lib.MelonMods;
using BTD6_Mod_Manager.Lib.Natives;
using Ionic.Zip;
using System;
using System.Diagnostics;
using System.IO;
using System.Threading;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media.Media3D;
using System.Linq;
using static BTD6_Mod_Manager.Lib.MelonMods.MelonMod_Handler;

namespace BTD6_Mod_Manager
{
class Launcher
{
public static void Launch()
{
if (!AreModsValid())
return;

var gameInfo = GameInfo.GetGame(SessionData.currentGame);

if (!Utility.IsProgramRunning(gameInfo.ProcName, out var btd6Proc))
Process.Start("steam://rungameid/" + gameInfo.SteamID);
else
{
Logger.Log("Please close BTD6 to continue...", OutputType.Both);
}

private static bool AreModsValid()
{
foreach (var mod in SessionData.loadedMods)
{
string filePath = mod;
if (IsFileZip(filePath))
continue;

var melonInfo = MelonMod_Handler.GetModInfo(filePath);
string melonModName = melonInfo.Name;

var similarMods = SessionData.loadedMods.Count(dupMod => GetModInfo(dupMod)?.Name == melonModName);
bool isDuplicate = (similarMods > 1);
if (!isDuplicate)
continue;

Logger.Log($"Error! You are trying to load {melonModName} twice. You need to disable one to continue.", OutputType.Both);
return false;
}

return true;
}

private static bool IsFileZip(string filePath)
{
FileInfo fileInfo = new FileInfo(filePath);
bool isZip = (fileInfo.Extension == ".zip" || fileInfo.Extension == ".rar" || fileInfo.Extension == ".7z");
return isZip;
}
}
}
13 changes: 8 additions & 5 deletions BTD6 Mod Manager.wpf/MainWindow.xaml.cs
Expand Up @@ -52,6 +52,8 @@ private void OnFinishedLoading()
UserData.MainSettingsDir = tdloaderDir;
UserData.UserDataFilePath = tdloaderDir + "\\userdata.json";

SessionData.loadedMods = Settings.LoadedSettings.LastUsedMods;

if (Settings.LoadedSettings.IsNewUser)
{
var diag = MessageBox.Show("Would you like to see a tutorial on how to use this mod manager?", "Open tutorial?", MessageBoxButton.YesNo);
Expand Down Expand Up @@ -129,11 +131,11 @@ private void ToolBar_Loaded(object sender, RoutedEventArgs e)
bool finishedLoading = false;
private void Main_Activated(object sender, EventArgs e)
{
if (finishedLoading == false)
{
finishedLoading = true;
OnFinishedLoading();
}
if (finishedLoading)
return;

OnFinishedLoading();
finishedLoading = true;
}

private void Main_Closing(object sender, CancelEventArgs e) => Settings.LoadedSettings.Save();
Expand Down Expand Up @@ -175,6 +177,7 @@ private void Launch_Button_Click(object sender, RoutedEventArgs e)
return;
}


Launcher.Launch();
}

Expand Down
4 changes: 2 additions & 2 deletions BTD6 Mod Manager.wpf/Properties/AssemblyInfo.cs
Expand Up @@ -49,5 +49,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("2.2.3")]
[assembly: AssemblyFileVersion("2.2.3")]
[assembly: AssemblyVersion("2.2.4")]
[assembly: AssemblyFileVersion("2.2.4")]
17 changes: 0 additions & 17 deletions BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs
Expand Up @@ -53,12 +53,6 @@ private void CheckBox_Clicked(object sender, RoutedEventArgs e)
Mods_UserControl.instance.AddToSelectedModLB(modPath);
if (modPath.EndsWith(Mods_UserControl.instance.disabledKey))
modPath = modPath.Replace(Mods_UserControl.instance.disabledKey, "");

/*Mods_UserControl.instance.SelectedMods_ListBox.Items.Add(modName);
Mods_UserControl.instance.SelectedMods_ListBox.SelectedIndex = Mods_UserControl.instance.SelectedMods_ListBox.Items.Count - 1;
Mods_UserControl.instance.modPaths.Add(modPath);
SessionData.LoadedMods.Add(modPath);
Settings.LoadedSettings.Save();*/
}
}
else
Expand All @@ -69,17 +63,6 @@ private void CheckBox_Clicked(object sender, RoutedEventArgs e)
Mods_UserControl.instance.RemoveFromSelectedLB(modPath);
if (!modPath.EndsWith(Mods_UserControl.instance.disabledKey))
modPath += Mods_UserControl.instance.disabledKey;

/*int selected = Mods_UserControl.instance.SelectedMods_ListBox.SelectedIndex;
Mods_UserControl.instance.SelectedMods_ListBox.Items.Remove(modName);
Mods_UserControl.instance.modPaths.Remove(modPath);
SessionData.LoadedMods.Remove(modPath);
Settings.LoadedSettings.Save();
if (selected == 0 && Mods_UserControl.instance.SelectedMods_ListBox.Items.Count >= 1)
Mods_UserControl.instance.SelectedMods_ListBox.SelectedIndex = selected;
else if (Mods_UserControl.instance.SelectedMods_ListBox.Items.Count > 1)
Mods_UserControl.instance.SelectedMods_ListBox.SelectedIndex = selected - 1;*/
}
}

Expand Down
12 changes: 9 additions & 3 deletions BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs
Expand Up @@ -6,6 +6,7 @@
using BTD6_Mod_Manager.Classes;
using BTD6_Mod_Manager.Lib;
using BTD6_Mod_Manager.Lib.Game;
using BTD6_Mod_Manager.Lib.MelonMods;
using BTD6_Mod_Manager.Persistance;

namespace BTD6_Mod_Manager.UserControls
Expand Down Expand Up @@ -99,6 +100,10 @@ public void RemoveFromSelectedLB(string modPath)
if (Settings.LoadedSettings.LastUsedMods.Contains(modFile.FullName))
Settings.LoadedSettings.LastUsedMods.Remove(modFile.FullName);

if (SessionData.loadedMods.Contains(modFile.FullName))
SessionData.loadedMods.Remove(modFile.FullName);


if (!modFile.FullName.EndsWith(disabledKey))
{
string newPath = modFile.FullName + disabledKey;
Expand Down Expand Up @@ -132,6 +137,9 @@ public void AddToSelectedModLB(string modPath)
Settings.LoadedSettings.Save();
}

if (!SessionData.loadedMods.Contains(f.FullName))
SessionData.loadedMods.Add(f.FullName);

SelectedMods_ListBox.Items.Add(f.Name);

foreach (var modItem in modItems)
Expand Down Expand Up @@ -232,12 +240,10 @@ private void AddMods_Button_Click(object sender, RoutedEventArgs e)
MainWindow.doingWork = true;
MainWindow.workType = "Adding mods";

//string allModTypes = "All Mod Types|*.jet;*.zip;*.rar;*.7z;*.btd6mod;*.dll;*.boo;*.chai";
string allModTypes = "All Mod Types|";
foreach (var item in fileExtensions)
{
allModTypes += "*" + item + ";";
}

allModTypes = allModTypes.TrimEnd(';');

List<string> mods = FileIO.BrowseForFiles("Browse for mods", "", allModTypes + "|Dll files (*.dll)|Jet files (*.jet)|*.jet|Zip files (*.zip)|*.zip|Rar files (*.rar)|*.rar|7z files (*.7z)|*.7z|BTD6API mods (*.btd6mod)|*.btd6mod|", "");
Expand Down

0 comments on commit a852561

Please sign in to comment.