Skip to content

Commit

Permalink
Update patch for v41.1
Browse files Browse the repository at this point in the history
  • Loading branch information
doombubbles committed Feb 14, 2024
1 parent 1534a52 commit f5ce384
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 13 deletions.
4 changes: 2 additions & 2 deletions LATEST.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
- Fixed for BTD6 v40.0
- The `UpgradeCount` property no longer needs to be manually specified for Paths, it will be inferred if omitted
- Fixed for BTD6 v41.1
- The specific patch in question should now also be more resilient to game updates going forward
4 changes: 2 additions & 2 deletions ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ namespace PathsPlusPlus;

internal static class ModHelperData
{
public const string WorksOnVersion = "40.0";
public const string Version = "1.1.2";
public const string WorksOnVersion = "41.1";
public const string Version = "1.1.3";
public const string Name = "Paths++";

public const string Description = "A helper mod allowing additional upgrade paths and tiers to be made for towers.\n\n" +
Expand Down
29 changes: 20 additions & 9 deletions Patches/UiPatches.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using BTD_Mod_Helper;
using BTD_Mod_Helper.Api;
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
Expand All @@ -11,6 +13,7 @@
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using UnityEngine.EventSystems;
using Object = Il2CppSystem.Object;

namespace PathsPlusPlus.Patches;

Expand Down Expand Up @@ -295,26 +298,34 @@ private static bool Prefix(UpgradeObject __instance, ref int __result)
}
}

[HarmonyPatch(typeof(TowerSelectionMenu.__c__DisplayClass64_0),
nameof(TowerSelectionMenu.__c__DisplayClass64_0._UpgradeTower_b__0))]
internal static class TowerSelectionMenu_DisplayClass62_UpgradeTower
[HarmonyPatch]
internal static class TowerSelectionMenu_DisplayClass_UpgradeTower
{
private static IEnumerable<MethodBase> TargetMethods()
{
yield return typeof(TowerSelectionMenu)
.GetNestedTypes()
.SelectMany(type => type.GetMethods("_UpgradeTower_b__0"))
.Single(info => info.GetParameters().Any(param => param.Name == "isUpgraded"));
}

[HarmonyPrefix]
private static bool Prefix(TowerSelectionMenu.__c__DisplayClass64_0 __instance, bool isUpgraded)
private static bool Prefix(Object __instance, bool isUpgraded)
{
if (__instance.path < 3) return true;
var path = __instance.GetIl2CppType().GetField("path").GetValue(__instance).Unbox<int>();
if (path < 3) return true;

var menu = __instance.__4__this;
var menu = __instance.GetIl2CppType().GetField("<>4__this").GetValue(__instance).Cast<TowerSelectionMenu>();

var upgradeObject = menu.upgradeButtons[__instance.path];
var upgradeObject = menu.upgradeButtons[path];

if (!upgradeObject.isActiveAndEnabled) return false;

if (!isUpgraded)
{
upgradeObject.tier = menu.selectedTower.tower.GetTier(__instance.path);
upgradeObject.tier = menu.selectedTower.tower.GetTier(path);
upgradeObject.LoadUpgrades();
__instance.__4__this.UpdateUpgradeVisuals();
menu.UpdateUpgradeVisuals();
}

upgradeObject.PostSimUpgrade();
Expand Down

0 comments on commit f5ce384

Please sign in to comment.