diff --git a/BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj b/BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj index d22da44..ba697d1 100644 --- a/BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj +++ b/BTD6 Mod Manager.Lib/BTD6 Mod Manager.Lib.csproj @@ -35,7 +35,7 @@ False - ..\BTD6 Mod Manager.wpf\bin\Debug\MelonLoader.ModHandler.dll + F:\Program Files (x86)\Steam\steamapps\common\BloonsTD6\MelonLoader\MelonLoader.ModHandler.dll ..\BTD6 Mod Manager.wpf\packages\WindowsAPICodePack-Core.1.1.1\lib\Microsoft.WindowsAPICodePack.dll diff --git a/BTD6 Mod Manager.Lib/MelonMods/MelonMod_Handler.cs b/BTD6 Mod Manager.Lib/MelonMods/MelonMod_Handler.cs index fdc26b5..394e468 100644 --- a/BTD6 Mod Manager.Lib/MelonMods/MelonMod_Handler.cs +++ b/BTD6 Mod Manager.Lib/MelonMods/MelonMod_Handler.cs @@ -58,8 +58,18 @@ public static System.Reflection.Assembly GetMod(int index) /// /// FilePath to the file you want to get MelonModInfo from /// - 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; + } + } + /// /// Get the MelonInfo of the mod with the provided Assembly diff --git a/BTD6 Mod Manager.wpf/BTD6 Mod Manager.csproj b/BTD6 Mod Manager.wpf/BTD6 Mod Manager.csproj index d1c56fd..73ca3a3 100644 --- a/BTD6 Mod Manager.wpf/BTD6 Mod Manager.csproj +++ b/BTD6 Mod Manager.wpf/BTD6 Mod Manager.csproj @@ -63,6 +63,7 @@ packages\DotNetZip.1.13.8\lib\net40\DotNetZip.dll + packages\Microsoft.WindowsAPICodePack-Core.1.1.0.2\lib\Microsoft.WindowsAPICodePack.dll diff --git a/BTD6 Mod Manager.wpf/Launcher.cs b/BTD6 Mod Manager.wpf/Launcher.cs index c5b75ec..50a06a8 100644 --- a/BTD6 Mod Manager.wpf/Launcher.cs +++ b/BTD6 Mod Manager.wpf/Launcher.cs @@ -1,12 +1,13 @@ 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 { @@ -14,14 +15,45 @@ 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; } } } diff --git a/BTD6 Mod Manager.wpf/MainWindow.xaml.cs b/BTD6 Mod Manager.wpf/MainWindow.xaml.cs index 2980341..ee3ea6f 100644 --- a/BTD6 Mod Manager.wpf/MainWindow.xaml.cs +++ b/BTD6 Mod Manager.wpf/MainWindow.xaml.cs @@ -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); @@ -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(); @@ -175,6 +177,7 @@ private void Launch_Button_Click(object sender, RoutedEventArgs e) return; } + Launcher.Launch(); } diff --git a/BTD6 Mod Manager.wpf/Properties/AssemblyInfo.cs b/BTD6 Mod Manager.wpf/Properties/AssemblyInfo.cs index 56e22c1..e066ae3 100644 --- a/BTD6 Mod Manager.wpf/Properties/AssemblyInfo.cs +++ b/BTD6 Mod Manager.wpf/Properties/AssemblyInfo.cs @@ -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")] diff --git a/BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs b/BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs index 34848e3..1780620 100644 --- a/BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs +++ b/BTD6 Mod Manager.wpf/UserControls/ModItem_UserControl.xaml.cs @@ -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 @@ -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;*/ } } diff --git a/BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs b/BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs index f485ce9..9d87609 100644 --- a/BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs +++ b/BTD6 Mod Manager.wpf/UserControls/Mods_UserControl.xaml.cs @@ -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 @@ -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; @@ -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) @@ -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 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|", "");