Skip to content

Commit

Permalink
v2.0.1 Bug Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Jul 2, 2021
1 parent 45c583b commit 764d8f8
Show file tree
Hide file tree
Showing 10 changed files with 108 additions and 4 deletions.
1 change: 1 addition & 0 deletions BTD Mod Helper Core/Api/ModOptions/ModSettingsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
3 changes: 3 additions & 0 deletions BTD Mod Helper Core/Api/Towers/ModTowerHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ internal static class ModTowerHandler

internal static readonly Dictionary<string, float> Tower2DScales = new Dictionary<string, float>();

internal static readonly Dictionary<string, ModTower> ModTowersCache = new Dictionary<string, ModTower>();

internal static void LoadTowers(List<ModTower> modTowers)
{
foreach (var modTower in modTowers)
Expand Down Expand Up @@ -239,6 +241,7 @@ internal static void AddTower(ModTower modTower)
try
{
Game.instance.model.AddTowerToGame(towerModel);
ModTowersCache[towerModel.name] = modTower;
}
catch (Exception e)
{
Expand Down
2 changes: 1 addition & 1 deletion BTD Mod Helper Core/Extensions/BloonsModExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static string GetModSettingsDir(this BloonsMod bloonsMod)
/// <returns></returns>
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;
}
Expand Down
23 changes: 23 additions & 0 deletions BTD Mod Helper Core/Extensions/ModelExtensions/TowerModelExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -217,5 +218,27 @@ public static void ApplyDisplay<T>(this TowerModel towerModel) where T : ModDisp
{
ModContent.GetInstance<T>().Apply(towerModel);
}

/// <summary>
/// Gets the ModTower associated with this TowerModel
/// <br/>
/// If there is no associated ModTower, returns null
/// </summary>
/// <returns></returns>
public static ModTower GetModTower(this TowerModel towerModel)
{
return ModTowerHandler.ModTowersCache.TryGetValue(towerModel.name, out var modTower) ? modTower : null;
}

/// <summary>
/// Gets the specific ModTower associated with this TowerModel
/// <br/>
/// If there is no associated ModTower, returns null
/// </summary>
/// <returns></returns>
public static T GetModTower<T>(this TowerModel towerModel) where T : ModTower
{
return (T) GetModTower(towerModel);
}
}
}
2 changes: 1 addition & 1 deletion BTD Mod Helper Core/ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
public static class ModHelperData
{
public const string currentVersion = "2.0.0";
public const string currentVersion = "2.0.1";

}
}
2 changes: 2 additions & 0 deletions BloonsTD6 Mod Helper/BloonsTD6 Mod Helper.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,8 @@
<Compile Include="Patches\Towers\Tower_SetSaveData.cs" />
<Compile Include="Patches\Towers\Tower_UnHighlight.cs" />
<Compile Include="Patches\Towers\Tower_UpdatedModel.cs" />
<Compile Include="Patches\UpgradeScreen_PopulatePath.cs" />
<Compile Include="Patches\UpgradeScreen_UpdateUi.cs" />
<Compile Include="Patches\Weapons\Attack_UpdatedModel.cs" />
<Compile Include="Patches\Weapons\Attack_Initialise.cs" />
<Compile Include="Patches\Weapons\Weapon_Initialise.cs" />
Expand Down
2 changes: 2 additions & 0 deletions BloonsTD6 Mod Helper/Extensions/InGameExt.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/// <summary>
Expand All @@ -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();
}

/// <summary>
Expand Down
4 changes: 2 additions & 2 deletions BloonsTD6 Mod Helper/Patches/Bloons/Bloon_Damage - Copy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -25,6 +25,6 @@ internal static void Postfix(Bloon __instance, float totalAmount, Projectile pro
immuneBloonProperties, canDestroyProjectile, ignoreNonTargetable,
blockSpawnChildren);
});
}
}*/
}
}
42 changes: 42 additions & 0 deletions BloonsTD6 Mod Helper/Patches/UpgradeScreen_PopulatePath.cs
Original file line number Diff line number Diff line change
@@ -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<UpgradeDetails> pathUpgrades)
{
var modTower = tower.GetModTower();
if (modTower != null)
{
var portrait = modTower.GetSpriteReference(modTower.Portrait);
var maxPathTier = modTower.tierMaxes[pathIndex];
var emptyAbilities = new List<AbilityModel>().Cast<ICollection<AbilityModel>>();
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<RectTransform>($"Arrow{array.Printed()}");
arrow.gameObject.Hide();
}
}
}
}
}
31 changes: 31 additions & 0 deletions BloonsTD6 Mod Helper/Patches/UpgradeScreen_UpdateUi.cs
Original file line number Diff line number Diff line change
@@ -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<RectTransform>("BGArrows");
foreach (var arrow in bgArrows.GetComponentsInChildren<CanvasRenderer>())
{
arrow.gameObject.Show();
}
}

[HarmonyPostfix]
internal static void Postfix(UpgradeScreen __instance)
{
if (!__instance.selectedDetails.gameObject.active)
{
__instance.SelectUpgrade(__instance.path2Upgrades[0]);
}
}
}
}

0 comments on commit 764d8f8

Please sign in to comment.