From f8284ca105855939016e632d4d5a2bd50c4716a6 Mon Sep 17 00:00:00 2001 From: doombubbles Date: Mon, 9 Oct 2023 20:56:47 -0700 Subject: [PATCH] Update for 39.0 --- .../Api/Helpers/FileIOHelper.cs | 5 ++- BloonsTD6 Mod Helper/Api/Towers/ModHero.cs | 2 +- BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs | 5 ++- .../SimulationExtensions/TowerExt.cs | 2 +- BloonsTD6 Mod Helper/LATEST.md | 4 ++ BloonsTD6 Mod Helper/MelonMain.cs | 1 + BloonsTD6 Mod Helper/ModHelper.cs | 2 +- .../Towers/TowerCreateTower_OnDestroy.cs | 13 +------ .../MenuManager_CloseCurrentMenuIfPossible.cs | 5 +-- .../Patches/UI/MenuManager_OpenMenu.cs | 2 +- .../UI/BTD6/EmbeddedBrowser.cs | 37 ------------------ .../UI/Modded/RoundSetChanger.cs | 39 +++++++++++++++++-- Shared/ModHelper.cs | 15 ------- 13 files changed, 56 insertions(+), 76 deletions(-) delete mode 100644 Shared/ModHelper.cs diff --git a/BloonsTD6 Mod Helper/Api/Helpers/FileIOHelper.cs b/BloonsTD6 Mod Helper/Api/Helpers/FileIOHelper.cs index e473ca81a..5d15eee2f 100644 --- a/BloonsTD6 Mod Helper/Api/Helpers/FileIOHelper.cs +++ b/BloonsTD6 Mod Helper/Api/Helpers/FileIOHelper.cs @@ -1,4 +1,5 @@ using Il2CppNewtonsoft.Json; +using Il2CppSystem; using Il2CppSystem.IO; using UnityEngine; using Directory = System.IO.Directory; @@ -34,8 +35,8 @@ public static void SaveObject(string fileName, Object data) var text = JsonConvert.SerializeObject(data, new JsonSerializerSettings { Formatting = Formatting.Indented, - ReferenceLoopHandling = ReferenceLoopHandling.Ignore, - TypeNameHandling = TypeNameHandling.Objects + TypeNameHandling = TypeNameHandling.Objects, + _referenceLoopHandling = new Nullable {value = ReferenceLoopHandling.Ignore} }); SaveFile(fileName, text); diff --git a/BloonsTD6 Mod Helper/Api/Towers/ModHero.cs b/BloonsTD6 Mod Helper/Api/Towers/ModHero.cs index ba482cd91..026b70940 100644 --- a/BloonsTD6 Mod Helper/Api/Towers/ModHero.cs +++ b/BloonsTD6 Mod Helper/Api/Towers/ModHero.cs @@ -203,7 +203,7 @@ internal override string TowerId(int[] tiers) /// Gets the font material for the default SkinData /// /// Existing hero skins by their skin/tower name - public virtual Material GetFontMaterial(Dictionary skinsByName) => + public virtual string GetFontMaterial(Dictionary skinsByName) => skinsByName.TryGetValue(NameStyle, out var dataForFont) ? dataForFont.fontMaterial : skinsByName[TowerType.Quincy].fontMaterial; diff --git a/BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs b/BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs index be2fb9b9b..3cd07136b 100644 --- a/BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs +++ b/BloonsTD6 Mod Helper/Api/UI/ModGameMenu.cs @@ -11,6 +11,7 @@ using Il2CppAssets.Scripts.Unity.UI_New.Coop; using Il2CppAssets.Scripts.Unity.UI_New.GameEvents; using Il2CppAssets.Scripts.Unity.UI_New.HeroInGame; +using Il2CppAssets.Scripts.Unity.UI_New.InGame.EditorMenus; using Il2CppAssets.Scripts.Unity.UI_New.LevelUp; using Il2CppAssets.Scripts.Unity.UI_New.Main.PowersSelect; using Il2CppAssets.Scripts.Unity.UI_New.Settings; @@ -38,7 +39,9 @@ public abstract class ModGameMenu : ModContent {typeof(GameEventsScreen), SceneNames.GameEventsUI}, {typeof(HeroInGameScreen), SceneNames.HeroInGameUI}, {typeof(LevelUpScreen), SceneNames.LevelUpUI}, - {typeof(ContentBrowser), SceneNames.ContentBrowser} + {typeof(ContentBrowser), SceneNames.ContentBrowser}, + {typeof(MapEditorScreen), SceneNames.MapEditorUI}, + {typeof(ChallengeEditorPlay), SceneNames.ChallengeEditorPlay} }; diff --git a/BloonsTD6 Mod Helper/Extensions/SimulationExtensions/TowerExt.cs b/BloonsTD6 Mod Helper/Extensions/SimulationExtensions/TowerExt.cs index 4e37c7419..7ac9c020d 100644 --- a/BloonsTD6 Mod Helper/Extensions/SimulationExtensions/TowerExt.cs +++ b/BloonsTD6 Mod Helper/Extensions/SimulationExtensions/TowerExt.cs @@ -80,5 +80,5 @@ public static IEnumerable GetTowersInRange(this Tower tower) /// /// public static MonkeyAnimationController GetMonkeyAnimController(this Tower tower) => - tower.GetUnityDisplayNode()?.monkeyAnimationController; + tower.GetUnityDisplayNode()?.animationController.TryCast(); } \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/LATEST.md b/BloonsTD6 Mod Helper/LATEST.md index d8b852172..3321b69be 100644 --- a/BloonsTD6 Mod Helper/LATEST.md +++ b/BloonsTD6 Mod Helper/LATEST.md @@ -1,3 +1,7 @@ +- Fixes for v39 + - Due to the new Community Button, the Round Set Changer button now only appears while selecting the dificulty/mode for a map + - Fixed ModHero font name material reference + - Fixed JSON settings - Added setting to toggle Mod Browser Populating on Startup - From my personal testing, this leads to ~1s faster startup on average, in exchange for waiting 5s - 10s when you first open the browser diff --git a/BloonsTD6 Mod Helper/MelonMain.cs b/BloonsTD6 Mod Helper/MelonMain.cs index fafddb1f3..c8c1a9596 100644 --- a/BloonsTD6 Mod Helper/MelonMain.cs +++ b/BloonsTD6 Mod Helper/MelonMain.cs @@ -83,6 +83,7 @@ public override void OnInitialize() public override void OnUpdate() { ModByteLoader.OnUpdate(); + RoundSetChanger.OnUpdate(); // InitialLoadTasks_MoveNext.Update(); if (Game.instance is null || InGame.instance is null) diff --git a/BloonsTD6 Mod Helper/ModHelper.cs b/BloonsTD6 Mod Helper/ModHelper.cs index a9f28ae0a..294eb9d3a 100644 --- a/BloonsTD6 Mod Helper/ModHelper.cs +++ b/BloonsTD6 Mod Helper/ModHelper.cs @@ -18,7 +18,7 @@ namespace BTD_Mod_Helper; public static class ModHelper { internal const string Name = "BloonsTD6 Mod Helper"; - internal const string Version = "3.1.14"; + internal const string Version = "3.1.15"; internal const string RepoOwner = "gurrenm3"; internal const string RepoName = "BTD-Mod-Helper"; internal const string Description = diff --git a/BloonsTD6 Mod Helper/Patches/Towers/TowerCreateTower_OnDestroy.cs b/BloonsTD6 Mod Helper/Patches/Towers/TowerCreateTower_OnDestroy.cs index afdd82478..321a50069 100644 --- a/BloonsTD6 Mod Helper/Patches/Towers/TowerCreateTower_OnDestroy.cs +++ b/BloonsTD6 Mod Helper/Patches/Towers/TowerCreateTower_OnDestroy.cs @@ -12,18 +12,9 @@ internal static class TowerCreateTower_OnDestroy [HarmonyPrefix] private static void Prefix(TowerCreateTower __instance) { - if (__instance.towerAdded && !__instance.tower.IsDestroyed) + if (__instance.tower is {IsDestroyed: false} && __instance.createdTower is {IsDestroyed: false}) { - var baseId = __instance.createTowerModel.towerModel.baseId; - var tower = __instance.Sim.towerManager - .GetChildTowers(__instance.tower) - .ToList() - .OrderBy(t => t.createdAt) - .FirstOrDefault(tower => tower.towerModel.baseId == baseId); - if (tower != null) - { - __instance.Sim.DestroyTower(tower, tower.owner); - } + __instance.Sim.DestroyTower(__instance.createdTower, __instance.createdTower.owner); } } } \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/Patches/UI/MenuManager_CloseCurrentMenuIfPossible.cs b/BloonsTD6 Mod Helper/Patches/UI/MenuManager_CloseCurrentMenuIfPossible.cs index 08dc1ccdd..555f7e8e1 100644 --- a/BloonsTD6 Mod Helper/Patches/UI/MenuManager_CloseCurrentMenuIfPossible.cs +++ b/BloonsTD6 Mod Helper/Patches/UI/MenuManager_CloseCurrentMenuIfPossible.cs @@ -5,7 +5,7 @@ using Il2CppAssets.Scripts.Unity.Menu; namespace BTD_Mod_Helper.Patches.UI; -[HarmonyPatch(typeof(MenuManager), nameof(MenuManager.CloseCurrentMenuIfPossible))] +[HarmonyPatch(typeof(MenuManager), nameof(MenuManager.CloseCurrentMenu))] internal static class MenuManager_CloseCurrentMenu { [HarmonyPrefix] @@ -26,7 +26,6 @@ private static void Postfix(MenuManager __instance, ref GameMenu __state) modGameMenu.OnMenuClosed(); } - RoundSetChanger.OnMenuChanged(__state.Exists()?.name ?? "", - __instance.menuStack.ToList().SkipLast(1).LastOrDefault()?.Item1 ?? ""); + // RoundSetChanger.OnMenuChanged(__state.Exists()?.name ?? "", __instance.menuStack.ToList().SkipLast(1).LastOrDefault()?.Item1 ?? ""); } } \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/Patches/UI/MenuManager_OpenMenu.cs b/BloonsTD6 Mod Helper/Patches/UI/MenuManager_OpenMenu.cs index be178fc76..391577301 100644 --- a/BloonsTD6 Mod Helper/Patches/UI/MenuManager_OpenMenu.cs +++ b/BloonsTD6 Mod Helper/Patches/UI/MenuManager_OpenMenu.cs @@ -8,6 +8,6 @@ internal static class MenuManager_OpenMenu [HarmonyPrefix] private static void Prefix(MenuManager __instance, string menuName) { - RoundSetChanger.OnMenuChanged(__instance.GetCurrentMenu().Exists()?.name ?? "", menuName); + // RoundSetChanger.OnMenuChanged(__instance.GetCurrentMenu().Exists()?.name ?? "", menuName); } } \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/UI/BTD6/EmbeddedBrowser.cs b/BloonsTD6 Mod Helper/UI/BTD6/EmbeddedBrowser.cs index de83ec088..ac5803b76 100644 --- a/BloonsTD6 Mod Helper/UI/BTD6/EmbeddedBrowser.cs +++ b/BloonsTD6 Mod Helper/UI/BTD6/EmbeddedBrowser.cs @@ -178,43 +178,6 @@ private static bool Prefix(HtmlSurface __instance, HTML_FileOpenDialog_t callbac #endregion*/ - /// - /// Implement JS alerts using Ok popups - /// - [HarmonyPatch(typeof(HtmlSurface), nameof(HtmlSurface.OnJSAlertAPI))] - internal static class HtmlSurface_OnJSAlertAPI - { - [HarmonyPrefix] - private static bool Prefix(HtmlSurface __instance, HTML_JSAlert_t callbackdata) - { - var nativeHtmlSurface = __instance.client.native.htmlSurface; - - PopupScreen.instance.SafelyQueue(screen => screen.ShowOkPopup(callbackdata.PchMessage, - new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, true)))); - return false; - } - } - - /// - /// Implement JS confirms using Ok/Cancel popups - /// - [HarmonyPatch(typeof(HtmlSurface), nameof(HtmlSurface.OnJSConfirmAPI))] - internal static class HtmlSurface_OnJSConfirmAPI - { - [HarmonyPrefix] - private static bool Prefix(HtmlSurface __instance, HTML_JSConfirm_t callbackdata) - { - var nativeHtmlSurface = __instance.client.native.htmlSurface; - - PopupScreen.instance.SafelyQueue(screen => - screen.ShowPopup(PopupScreen.Placement.menuCenter, "Confirm", callbackdata.PchMessage, - new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, true)), "Ok", - new Action(() => nativeHtmlSurface.JSDialogResponse(callbackdata.UnBrowserHandle, false)), "Cancel", - Popup.TransitionAnim.Scale)); - return false; - } - } - /// /// Allow mod files to be downloaded through the browser /// diff --git a/BloonsTD6 Mod Helper/UI/Modded/RoundSetChanger.cs b/BloonsTD6 Mod Helper/UI/Modded/RoundSetChanger.cs index 2f7d1f2a8..512c68527 100644 --- a/BloonsTD6 Mod Helper/UI/Modded/RoundSetChanger.cs +++ b/BloonsTD6 Mod Helper/UI/Modded/RoundSetChanger.cs @@ -5,8 +5,10 @@ using BTD_Mod_Helper.Api.Bloons; using BTD_Mod_Helper.Api.Components; using BTD_Mod_Helper.Api.Enums; +using Il2CppAssets.Scripts; using Il2CppAssets.Scripts.Unity.Menu; using Il2CppAssets.Scripts.Unity.UI_New; +using Il2CppAssets.Scripts.Unity.UI_New.InGame; using Il2CppAssets.Scripts.Unity.UI_New.Main.Facebook; using Il2CppAssets.Scripts.Unity.UI_New.Main.MapSelect; using UnityEngine; @@ -24,8 +26,8 @@ public static class RoundSetChanger // TODO make this internal, add alt way to g private static readonly string[] ShowOnMenus = { - "MapSelectUI", "DifficultySelectUI", "ModeSelectUI", - "MapSelectScreen", "DifficultySelectScreen", "ModeSelectScreen" + "DifficultySelectUI", "ModeSelectUI", + "DifficultySelectScreen", "ModeSelectScreen" }; private static ModHelperPanel buttonPanel; @@ -36,6 +38,8 @@ public static class RoundSetChanger // TODO make this internal, add alt way to g private static ModHelperPanel invisibleCancel; + private static bool lastShowing; + /// /// The round set override currently chosen, or null /// @@ -204,6 +208,7 @@ private static void Show() Init(); RevealButton(); optionsPanel.SetActive(false); + lastShowing = true; } private static void Hide() @@ -211,6 +216,7 @@ private static void Hide() Init(); HideButton(); HideOptions(); + lastShowing = false; } internal static void EnsureHidden() @@ -224,11 +230,38 @@ internal static void EnsureHidden() { optionsPanel.SetActive(false); } + + lastShowing = false; + } + + internal static void OnUpdate() + { + if (!MelonMain.ShowRoundsetChanger || MenuManager.instance == null) return; + + if (InGame.instance != null) + { + EnsureHidden(); + return; + } + + var shouldShow = ShowOnMenus.Contains(MenuManager.instance.GetCurrentMenuName()); + + if (shouldShow != lastShowing) + { + if (shouldShow) + { + Show(); + ModifyBlockClicks(); + } + else + { + Hide(); + } + } } internal static void OnMenuChanged(string currentMenu, string newMenu) { - if (!MelonMain.ShowRoundsetChanger) return; if (ShowOnMenus.Contains(newMenu)) { diff --git a/Shared/ModHelper.cs b/Shared/ModHelper.cs deleted file mode 100644 index 846873fc9..000000000 --- a/Shared/ModHelper.cs +++ /dev/null @@ -1,15 +0,0 @@ -namespace BTD_Mod_Helper; - -public static class ModHelper -{ - internal const string Name = "BloonsTD6 Mod Helper"; - internal const string Version = "3.1.10"; - 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"; - internal const string DllName = "Btd6ModHelper.dll"; - internal const string XmlName = "Btd6ModHelper.xml"; - internal const string Author = "Gurrenm4 and Doombubbles"; - internal const string Branch = "master"; -} \ No newline at end of file