diff --git a/BTD Mod Helper Core/Api/ModOptions/ModSettingsHandler.cs b/BTD Mod Helper Core/Api/ModOptions/ModSettingsHandler.cs index d17ae2088..1dc0b3335 100644 --- a/BTD Mod Helper Core/Api/ModOptions/ModSettingsHandler.cs +++ b/BTD Mod Helper Core/Api/ModOptions/ModSettingsHandler.cs @@ -46,6 +46,7 @@ internal static void InitializeModSettings(string modSettingsDir) var fileName = $"{modSettingsDir}\\{mod.Info.Name}.json"; if (!File.Exists(fileName)) { + MelonLogger.Msg("saving new file"); SaveModSettings(mod, modSettingsDir); } } diff --git a/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs b/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs index b5de518f7..074055e79 100644 --- a/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs +++ b/BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs @@ -23,6 +23,8 @@ internal static class ModTowerHandler internal static readonly Dictionary Tower2DScales = new Dictionary(); + internal static readonly Dictionary ModTowersCache = new Dictionary(); + internal static void LoadTowers(List modTowers) { foreach (var modTower in modTowers) @@ -239,6 +241,7 @@ internal static void AddTower(ModTower modTower) try { Game.instance.model.AddTowerToGame(towerModel); + ModTowersCache[towerModel.name] = modTower; } catch (Exception e) { diff --git a/BTD Mod Helper Core/Extensions/BloonsModExt.cs b/BTD Mod Helper Core/Extensions/BloonsModExt.cs index 45de94616..680070b1b 100644 --- a/BTD Mod Helper Core/Extensions/BloonsModExt.cs +++ b/BTD Mod Helper Core/Extensions/BloonsModExt.cs @@ -58,7 +58,7 @@ public static string GetModSettingsDir(this BloonsMod bloonsMod) /// public static string GetModSettingsDir(this BloonsMod bloonsMod, bool createIfNotExists = true) { - var path = Path.Combine(bloonsMod.GetModSettingsDir(), "Mod Settings"); + var path = bloonsMod.GetModSettingsDir(); if (createIfNotExists) Directory.CreateDirectory(path); return path; } diff --git a/BTD Mod Helper Core/Extensions/ModelExtensions/TowerModelExt.cs b/BTD Mod Helper Core/Extensions/ModelExtensions/TowerModelExt.cs index 8c9addc27..1e44c64a9 100644 --- a/BTD Mod Helper Core/Extensions/ModelExtensions/TowerModelExt.cs +++ b/BTD Mod Helper Core/Extensions/ModelExtensions/TowerModelExt.cs @@ -11,6 +11,7 @@ using Assets.Scripts.Unity.Display; using BTD_Mod_Helper.Api; using BTD_Mod_Helper.Api.Display; +using BTD_Mod_Helper.Api.Towers; #if BloonsTD6 using Assets.Scripts.Models.Towers.Projectiles; using Assets.Scripts.Models.Towers.Weapons; @@ -217,5 +218,27 @@ public static void ApplyDisplay(this TowerModel towerModel) where T : ModDisp { ModContent.GetInstance().Apply(towerModel); } + + /// + /// Gets the ModTower associated with this TowerModel + ///
+ /// If there is no associated ModTower, returns null + ///
+ /// + public static ModTower GetModTower(this TowerModel towerModel) + { + return ModTowerHandler.ModTowersCache.TryGetValue(towerModel.name, out var modTower) ? modTower : null; + } + + /// + /// Gets the specific ModTower associated with this TowerModel + ///
+ /// If there is no associated ModTower, returns null + ///
+ /// + public static T GetModTower(this TowerModel towerModel) where T : ModTower + { + return (T) GetModTower(towerModel); + } } } \ No newline at end of file diff --git a/BTD Mod Helper Core/ModHelperData.cs b/BTD Mod Helper Core/ModHelperData.cs index 870c09fdf..ca1426db6 100644 --- a/BTD Mod Helper Core/ModHelperData.cs +++ b/BTD Mod Helper Core/ModHelperData.cs @@ -2,7 +2,7 @@ { public static class ModHelperData { - public const string currentVersion = "2.0.0"; + public const string currentVersion = "2.0.1"; } } diff --git a/BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj b/BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj index e89533dc6..5ece5314a 100644 --- a/BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj +++ b/BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj @@ -236,6 +236,8 @@ + + diff --git a/BloonsTD6 Mod Helper/Extensions/InGameExt.cs b/BloonsTD6 Mod Helper/Extensions/InGameExt.cs index 15e74d5e3..1eb1bafee 100644 --- a/BloonsTD6 Mod Helper/Extensions/InGameExt.cs +++ b/BloonsTD6 Mod Helper/Extensions/InGameExt.cs @@ -79,6 +79,7 @@ public static double GetCash(this InGame inGame) public static void AddCash(this InGame inGame, double amount) { inGame.GetCashManager().cash.Value += amount; + InGame.instance.bridge.OnCashChangedSim(); } /// @@ -88,6 +89,7 @@ public static void AddCash(this InGame inGame, double amount) public static void SetCash(this InGame inGame, double amount) { inGame.GetCashManager().cash.Value = amount; + InGame.instance.bridge.OnCashChangedSim(); } /// diff --git a/BloonsTD6 Mod Helper/Patches/Bloons/Bloon_Damage - Copy.cs b/BloonsTD6 Mod Helper/Patches/Bloons/Bloon_Damage - Copy.cs index 3aa8bf44c..6956addf2 100644 --- a/BloonsTD6 Mod Helper/Patches/Bloons/Bloon_Damage - Copy.cs +++ b/BloonsTD6 Mod Helper/Patches/Bloons/Bloon_Damage - Copy.cs @@ -12,7 +12,7 @@ namespace BTD_Mod_Helper.Patches.Bloons internal class Bloon_Damage { - [HarmonyPostfix] + /*[HarmonyPostfix] internal static void Postfix(Bloon __instance, float totalAmount, Projectile projectile, bool distributeToChildren, bool overrideDistributeBlocker, bool createEffect, Tower tower, BloonProperties immuneBloonProperties, bool canDestroyProjectile, bool ignoreNonTargetable, @@ -25,6 +25,6 @@ internal static void Postfix(Bloon __instance, float totalAmount, Projectile pro immuneBloonProperties, canDestroyProjectile, ignoreNonTargetable, blockSpawnChildren); }); - } + }*/ } } \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/Patches/UpgradeScreen_PopulatePath.cs b/BloonsTD6 Mod Helper/Patches/UpgradeScreen_PopulatePath.cs new file mode 100644 index 000000000..703a93c91 --- /dev/null +++ b/BloonsTD6 Mod Helper/Patches/UpgradeScreen_PopulatePath.cs @@ -0,0 +1,42 @@ +using Assets.Scripts.Models.Towers; +using Assets.Scripts.Models.Towers.Behaviors.Abilities; +using Assets.Scripts.Unity; +using Assets.Scripts.Unity.UI_New.Upgrade; +using BTD_Mod_Helper.Extensions; +using Harmony; +using Il2CppSystem.Collections.Generic; +using MelonLoader; +using UnhollowerBaseLib; +using UnityEngine; + +namespace BTD_Mod_Helper.Patches +{ + [HarmonyPatch(typeof(UpgradeScreen), nameof(UpgradeScreen.PopulatePath))] + internal class UpgradeScreen_PopulatePath + { + [HarmonyPostfix] + internal static void Postfix(UpgradeScreen __instance, TowerModel tower, int pathIndex, Il2CppReferenceArray pathUpgrades) + { + var modTower = tower.GetModTower(); + if (modTower != null) + { + var portrait = modTower.GetSpriteReference(modTower.Portrait); + var maxPathTier = modTower.tierMaxes[pathIndex]; + var emptyAbilities = new List().Cast>(); + var upgradeModel = Game.instance.model.GetUpgrade("Faster Throwing"); // random real upgrade to internally use + for (var i = maxPathTier; i < 5; i++) + { + var upgradeDetails = pathUpgrades[i]; + upgradeDetails.SetUpgrade(tower.baseId, upgradeModel, emptyAbilities, pathIndex, portrait); + upgradeDetails.gameObject.SetActive(false); + + var array = new[] {0, 0, 0}; + array[pathIndex] = i + 1; + + var arrow = __instance.transform.GetComponentFromChildrenByName($"Arrow{array.Printed()}"); + arrow.gameObject.Hide(); + } + } + } + } +} \ No newline at end of file diff --git a/BloonsTD6 Mod Helper/Patches/UpgradeScreen_UpdateUi.cs b/BloonsTD6 Mod Helper/Patches/UpgradeScreen_UpdateUi.cs new file mode 100644 index 000000000..a11446355 --- /dev/null +++ b/BloonsTD6 Mod Helper/Patches/UpgradeScreen_UpdateUi.cs @@ -0,0 +1,31 @@ +using Assets.Scripts.Unity.UI_New.Upgrade; +using BTD_Mod_Helper.Extensions; +using Harmony; +using MelonLoader; +using UnityEngine; + +namespace BTD_Mod_Helper.Patches +{ + [HarmonyPatch(typeof(UpgradeScreen), nameof(UpgradeScreen.UpdateUi))] + internal class UpgradeScreen_UpdateUi + { + [HarmonyPrefix] + internal static void Prefix(UpgradeScreen __instance) + { + var bgArrows = __instance.GetComponentFromChildrenByName("BGArrows"); + foreach (var arrow in bgArrows.GetComponentsInChildren()) + { + arrow.gameObject.Show(); + } + } + + [HarmonyPostfix] + internal static void Postfix(UpgradeScreen __instance) + { + if (!__instance.selectedDetails.gameObject.active) + { + __instance.SelectUpgrade(__instance.path2Upgrades[0]); + } + } + } +} \ No newline at end of file