From 4e208aa1f5add3decbd80c6ca998e3ac962c6cda Mon Sep 17 00:00:00 2001 From: doombubbles Date: Thu, 29 Sep 2022 20:40:07 -0700 Subject: [PATCH] Updated for MelonLoader 0.5.5 official release --- BloonsTD6 Mod Helper/BloonsTD6Mod.cs | 13 ----- BloonsTD6 Mod Helper/LATEST.md | 13 ++--- BloonsTD6 Mod Helper/MelonMain.cs | 21 +------- .../Patches/Main_GetInitialLoadTasks.cs | 2 +- .../LocalizationManger_LoadTableAsync.cs | 2 - Documentation/BTD_Mod_Helper.BloonsMod.md | 48 ++++++++++++------- Documentation/BTD_Mod_Helper.BloonsTD6Mod.md | 25 ---------- Shared/Api/Data/ModHelperData.cs | 2 +- Shared/Api/Helpers/MelonLoaderChecker.cs | 32 ------------- Shared/BloonsMod.cs | 13 +++-- Shared/ModHelper.cs | 2 +- Shared/Shared Project.projitems | 1 - 12 files changed, 47 insertions(+), 127 deletions(-) delete mode 100644 Shared/Api/Helpers/MelonLoaderChecker.cs diff --git a/BloonsTD6 Mod Helper/BloonsTD6Mod.cs b/BloonsTD6 Mod Helper/BloonsTD6Mod.cs index fefb4de0c..ff9f7c48c 100644 --- a/BloonsTD6 Mod Helper/BloonsTD6Mod.cs +++ b/BloonsTD6 Mod Helper/BloonsTD6Mod.cs @@ -32,19 +32,6 @@ namespace BTD_Mod_Helper; /// public abstract class BloonsTD6Mod : BloonsMod { - /// - /// Adds a TowerModel to the official list of TowerModels being used by the game - ///
- /// Equivalent to calling Game.instance.model.AddTowerToGame(...) - ///
- /// The new tower model - /// A TowerDetailsModel to go with it, if it'll be in the shop - [Obsolete("Just use Game.instance.model.AddTowerToGame")] - public static void AddTowerToGame(TowerModel newTowerModel, TowerDetailsModel towerDetailsModel = null) - { - Game.instance.model.AddTowerToGame(newTowerModel, towerDetailsModel!); - } - #region Networking Hooks /// diff --git a/BloonsTD6 Mod Helper/LATEST.md b/BloonsTD6 Mod Helper/LATEST.md index 73d14f74c..8d68a8594 100644 --- a/BloonsTD6 Mod Helper/LATEST.md +++ b/BloonsTD6 Mod Helper/LATEST.md @@ -1,10 +1,3 @@ -- Added the `SquareIcon` ModHelperData bool property to make the icon draw as constrained within panels rather than being allowed to slightly overflow -- Added an impossible to miss Popup for if you're not using a compatible MelonLoader version -- Added the ability to use a `` markdown comment in release messages to only include information beyond a certain point -- Added checkmark icons for Verified Modders in the Mod Browser -- Fixed issue where Double Cash mode was doubling cash generation it wasn't supposed to -- Fixed Round Set Changer setting -- Fixed sporadic issue with backing out of a Mod Settings menu -- Fixed `OnMenuClosed()` still happening if you pressed Escape too early for the menu to actually close -- Fixed monorepo mods using ZipName without DllName not showing up in the Mod Browser -- Internally switched from `.parent =` to `SetParent` calls to avoid flooding the MelonLoader debug log \ No newline at end of file +- Updated for the official MelonLoader v0.5.5 release + +Use this version of the mod alongside the MelonLoader 0.5.5 you get from the official installer, not the github actions / nightly builds that have been linked previously. \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/MelonMain.cs b/BloonsTD6 Mod Helper/MelonMain.cs index 99b5c9182..f3dd6ad79 100644 --- a/BloonsTD6 Mod Helper/MelonMain.cs +++ b/BloonsTD6 Mod Helper/MelonMain.cs @@ -1,11 +1,7 @@ using System; -using System.Diagnostics; -using System.IO; using System.Linq; using System.Threading.Tasks; using Assets.Scripts.Models.TowerSets.Mods; -using Assets.Scripts.Simulation; -using Assets.Scripts.Simulation.Towers; using Assets.Scripts.Unity; using Assets.Scripts.Unity.UI_New.InGame; using Assets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu; @@ -16,7 +12,6 @@ using BTD_Mod_Helper.Api.ModMenu; using BTD_Mod_Helper.Api.ModOptions; using BTD_Mod_Helper.Api.Towers; -using BTD_Mod_Helper.UI.Menus; using BTD_Mod_Helper.UI.Modded; using TaskScheduler = BTD_Mod_Helper.Api.TaskScheduler; @@ -28,7 +23,7 @@ namespace BTD_Mod_Helper; internal partial class MelonMain : BloonsTD6Mod { - public override void OnApplicationStart() + public override void OnInitialize() { ModContentInstances.SetInstance(GetType(), this); @@ -74,20 +69,6 @@ public override void OnApplicationStart() public override void OnUpdate() { - if (!MelonLoaderChecker.IsVersionNewEnough()) - { - if (PopupScreen.instance != null && !PopupScreen.instance.IsPopupActive()) - { - PopupScreen.instance.ShowPopup(PopupScreen.Placement.menuCenter, "Not On MelonLoader 0.5.5", - "Mod Helper failed to load. Not On MelonLoader 0.5.5. Click ok to be taken to a page with more information.", - new Action(() => - { - ProcessHelper.OpenURL("https://github.com/gurrenm3/BTD-Mod-Helper/wiki/Install-Guide"); - }), "Ok", null, "Cancel", Popup.TransitionAnim.Scale, instantClose: true); - } - return; - } - ModByteLoader.OnUpdate(); if (Game.instance is null) diff --git a/BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs b/BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs index 9a3f3be5f..8186900ba 100644 --- a/BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs +++ b/BloonsTD6 Mod Helper/Patches/Main_GetInitialLoadTasks.cs @@ -22,7 +22,7 @@ internal static class Main_GetInitialLoadTasks [HarmonyPostfix] private static void Postfix(ref SeriesTasks __result) { - if (ModHelper.FallbackToOldLoading || !MelonLoaderChecker.IsVersionNewEnough()) return; + if (ModHelper.FallbackToOldLoading) return; var tasks = __result.Tasks.Cast>().ToList(); var gameModelLoad = tasks.Last(); diff --git a/BloonsTD6 Mod Helper/Patches/Resources/LocalizationManger_LoadTableAsync.cs b/BloonsTD6 Mod Helper/Patches/Resources/LocalizationManger_LoadTableAsync.cs index 38ab8d59e..11e89cd37 100644 --- a/BloonsTD6 Mod Helper/Patches/Resources/LocalizationManger_LoadTableAsync.cs +++ b/BloonsTD6 Mod Helper/Patches/Resources/LocalizationManger_LoadTableAsync.cs @@ -12,8 +12,6 @@ internal static class LocalizationManger_LoadTableAsync [HarmonyPostfix] private static void Postfix(LocalizationManager._LoadTableAsync_d__45 __instance) { - if (!MelonLoaderChecker.IsVersionNewEnough()) return; - var result = __instance.__t__builder.Task.Result; if (result != null) { diff --git a/Documentation/BTD_Mod_Helper.BloonsMod.md b/Documentation/BTD_Mod_Helper.BloonsMod.md index 149d2eb28..00e1b03e7 100644 --- a/Documentation/BTD_Mod_Helper.BloonsMod.md +++ b/Documentation/BTD_Mod_Helper.BloonsMod.md @@ -194,14 +194,39 @@ Runs after the Melon has registered. This callback waits until MelonLoader has f public virtual void OnApplicationStart(); ``` + + +## BloonsMod.OnEarlyInitialize() Method + +Runs when the Melon is registered. Executed before the Melon's info is printed to the console. This callback should only be used a constructor for the Melon. + +```csharp +public virtual void OnEarlyInitialize(); +``` + +### Remarks +Please note that this callback may run before the Support Module is loaded. +
As a result, using unhollowed assemblies may not be possible yet and you would have to override instead.
+ + + +## BloonsMod.OnEarlyInitializeMelon() Method + +Runs when the Melon is registered. Executed before the Melon's info is printed to the console. This callback should only be used a constructor for the Melon. + +```csharp +public sealed override void OnEarlyInitializeMelon(); +``` + +### Remarks +Please note that this callback may run before the Support Module is loaded. +
As a result, using unhollowed assemblies may not be possible yet and you would have to override instead.
+ ## BloonsMod.OnInitialize() Method -Runs when the Melon is registered. Executed before the Melon's info is printed to the console. This callback should only be used a constructor for the Melon. - -Please note that this callback may run before the Support Module is loaded and before the Engine is fully initialized. -
As a result, using unhollowed assemblies and creating/getting UnityEngine Objects may not be possible and you would have to override instead.
+Runs after the Melon has registered. This callback waits until MelonLoader has fully initialized ([MelonLoader.MelonEvents.OnApplicationStart](https://docs.microsoft.com/en-us/dotnet/api/MelonLoader.MelonEvents.OnApplicationStart 'MelonLoader.MelonEvents.OnApplicationStart')). ```csharp public virtual void OnInitialize(); @@ -211,10 +236,7 @@ public virtual void OnInitialize(); ## BloonsMod.OnInitializeMelon() Method -Runs when the Melon is registered. Executed before the Melon's info is printed to the console. This callback should only be used a constructor for the Melon. - -Please note that this callback may run before the Support Module is loaded and before the Engine is fully initialized. -
As a result, using unhollowed assemblies and creating/getting UnityEngine Objects may not be possible and you would have to override instead.
+Runs after the Melon has registered. This callback waits until MelonLoader has fully initialized ([MelonLoader.MelonEvents.OnApplicationStart](https://docs.microsoft.com/en-us/dotnet/api/MelonLoader.MelonEvents.OnApplicationStart 'MelonLoader.MelonEvents.OnApplicationStart')). ```csharp public sealed override void OnInitializeMelon(); @@ -271,16 +293,6 @@ public virtual void OnKeyUp(UnityEngine.KeyCode keyCode); `keyCode` [UnityEngine.KeyCode](https://docs.microsoft.com/en-us/dotnet/api/UnityEngine.KeyCode 'UnityEngine.KeyCode') - - -## BloonsMod.OnLoaderInitialized() Method - -Runs after the Melon has registered. This callback waits until MelonLoader has fully initialized ([MelonLoader.MelonEvents.OnApplicationStart](https://docs.microsoft.com/en-us/dotnet/api/MelonLoader.MelonEvents.OnApplicationStart 'MelonLoader.MelonEvents.OnApplicationStart')). - -```csharp -public sealed override void OnLoaderInitialized(); -``` - ## BloonsMod.OnModOptionsOpened() Method diff --git a/Documentation/BTD_Mod_Helper.BloonsTD6Mod.md b/Documentation/BTD_Mod_Helper.BloonsTD6Mod.md index 381113de6..57237ca9b 100644 --- a/Documentation/BTD_Mod_Helper.BloonsTD6Mod.md +++ b/Documentation/BTD_Mod_Helper.BloonsTD6Mod.md @@ -36,31 +36,6 @@ public virtual bool ActOnMessage(NinjaKiwi.NKMulti.Message message); #### Returns [System.Boolean](https://docs.microsoft.com/en-us/dotnet/api/System.Boolean 'System.Boolean') - - -## BloonsTD6Mod.AddTowerToGame(TowerModel, TowerDetailsModel) Method - -Adds a TowerModel to the official list of TowerModels being used by the game -
-Equivalent to calling Game.instance.model.AddTowerToGame(...) - -```csharp -public static void AddTowerToGame(Assets.Scripts.Models.Towers.TowerModel newTowerModel, Assets.Scripts.Models.TowerSets.TowerDetailsModel towerDetailsModel=null); -``` -#### Parameters - - - -`newTowerModel` [Assets.Scripts.Models.Towers.TowerModel](https://docs.microsoft.com/en-us/dotnet/api/Assets.Scripts.Models.Towers.TowerModel 'Assets.Scripts.Models.Towers.TowerModel') - -The new tower model - - - -`towerDetailsModel` [Assets.Scripts.Models.TowerSets.TowerDetailsModel](https://docs.microsoft.com/en-us/dotnet/api/Assets.Scripts.Models.TowerSets.TowerDetailsModel 'Assets.Scripts.Models.TowerSets.TowerDetailsModel') - -A TowerDetailsModel to go with it, if it'll be in the shop - ## BloonsTD6Mod.OnAbilityCast(Ability) Method diff --git a/Shared/Api/Data/ModHelperData.cs b/Shared/Api/Data/ModHelperData.cs index 78804cbe4..4ae2bd9b0 100644 --- a/Shared/Api/Data/ModHelperData.cs +++ b/Shared/Api/Data/ModHelperData.cs @@ -237,7 +237,7 @@ public void SetVersion(string version) public static void LoadAll() { - foreach (var melonMod in ModHelper.Melons) + foreach (var melonMod in ModHelper.Melons.OrderBy(mod => mod.Priority)) { try { diff --git a/Shared/Api/Helpers/MelonLoaderChecker.cs b/Shared/Api/Helpers/MelonLoaderChecker.cs deleted file mode 100644 index 4416b82e5..000000000 --- a/Shared/Api/Helpers/MelonLoaderChecker.cs +++ /dev/null @@ -1,32 +0,0 @@ -using System; -namespace BTD_Mod_Helper.Api.Helpers; - -internal static class MelonLoaderChecker -{ - public static bool IsVersionNewEnough() - { - try - { - SaySomethingOnlyTheRealMelonLoaderWouldKnow(); - return true; - } - catch (Exception) - { - return false; - } - } - - private static void SaySomethingOnlyTheRealMelonLoaderWouldKnow() - { - try - { - // ReSharper disable once ReturnValueOfPureMethodIsNotUsed - MelonMod.RegisteredMelons.ToArray(); - } - catch (Exception) - { - // ignored - } - } - -} \ No newline at end of file diff --git a/Shared/BloonsMod.cs b/Shared/BloonsMod.cs index ec8abb0d9..ea5e38e1b 100644 --- a/Shared/BloonsMod.cs +++ b/Shared/BloonsMod.cs @@ -148,11 +148,12 @@ public sealed override void OnInitializeMelon() modHelperPatchAll = true; } + OnApplicationStart(); OnInitialize(); } /// - public sealed override void OnLoaderInitialized() + public sealed override void OnEarlyInitializeMelon() { if (modHelperPatchAll) { @@ -187,12 +188,18 @@ public sealed override void OnLoaderInitialized() } } - OnApplicationStart(); + OnEarlyInitialize(); } - /// + /// public new virtual void OnApplicationStart() { + + } + + /// + public virtual void OnEarlyInitialize() + { } /// diff --git a/Shared/ModHelper.cs b/Shared/ModHelper.cs index 7a1cabb70..293787525 100644 --- a/Shared/ModHelper.cs +++ b/Shared/ModHelper.cs @@ -17,7 +17,7 @@ public static class ModHelper #region ModHelperData for the Mod Helper internal const string Name = "BloonsTD6 Mod Helper"; - internal const string Version = "3.0.1"; + internal const string Version = "3.0.2"; internal const string RepoOwner = "gurrenm3"; internal const string RepoName = "BTD-Mod-Helper"; internal const string Description = "A powerful and easy to use API for modding BTD6. Also the mod that is allowing all of this UI to happen right now :P"; diff --git a/Shared/Shared Project.projitems b/Shared/Shared Project.projitems index 74491eeae..8463e730f 100644 --- a/Shared/Shared Project.projitems +++ b/Shared/Shared Project.projitems @@ -53,7 +53,6 @@ -