-
Notifications
You must be signed in to change notification settings - Fork 181
/
Patches.cs
101 lines (92 loc) · 3.69 KB
/
Patches.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using HarmonyLib;
using Il2CppAssets.Scripts.Models.Towers;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors.Attack;
namespace UltimateCrosspathing
{
[HarmonyPatch(typeof(UpgradeObject), nameof(UpgradeObject.CheckBlockedPath))]
internal class UpgradeObject_CheckBlockedPath
{
[HarmonyPostfix]
internal static void Postfix(UpgradeObject __instance, ref int __result, ref bool __runOriginal)
{
if (__instance.tts == null || !LoadInfo.ShouldWork(__instance.tts.Def.baseId) || !__runOriginal) return;
var tier = __instance.tier;
var tiers = __instance.tts.Def.tiers;
var sum = tiers.Sum();
var remainingTiers = Settings.MaxTiers - sum;
__result = tier + remainingTiers;
if (__result > 5)
{
__result = 5;
}
}
}
[HarmonyPatch(typeof(TowerSelectionMenu), nameof(TowerSelectionMenu.IsUpgradePathClosed))]
internal class TowerSelectionMenu_IsUpgradePathClosed
{
[HarmonyPostfix]
internal static void Postfix(TowerSelectionMenu __instance, int path, ref bool __result, ref bool __runOriginal)
{
if (__instance.selectedTower == null || !__runOriginal) return;
var towerModel = __instance.selectedTower.Def;
var blockBeastHandler = towerModel.baseId == TowerType.BeastHandler &&
towerModel.tiers.Count(t => t > 0) >= 2 &&
towerModel.tiers[path] == 0;
if (LoadInfo.ShouldWork(towerModel.baseId) && !blockBeastHandler)
{
__result &= towerModel.tiers.Sum() >= Settings.MaxTiers;
}
}
}
/// <summary>
/// Fix v38.1 inlining of TowerSelectionMenu.IsUpgradePathClosed method
/// </summary>
[HarmonyPatch(typeof(UpgradeObject), nameof(UpgradeObject.UpdateVisuals))]
internal static class UpgradeObject_UpdateVisuals
{
[HarmonyPrefix]
private static bool Prefix(UpgradeObject __instance, int path, bool upgradeClicked)
{
if (__instance.towerSelectionMenu.IsUpgradePathClosed(path))
{
__instance.upgradeButton.SetUpgradeModel(null);
}
__instance.CheckLocked();
var maxTier = __instance.CheckBlockedPath();
var maxTierRestricted = __instance.CheckRestrictedPath();
__instance.SetTier(__instance.tier, maxTier, maxTierRestricted);
__instance.currentUpgrade.UpdateVisuals();
__instance.upgradeButton.UpdateVisuals(path, upgradeClicked);
return false;
}
}
[HarmonyPatch(typeof(Bank), nameof(Bank.Cash), MethodType.Setter)]
internal class Bank_Cash
{
[HarmonyPostfix]
internal static void Postfix(Bank __instance)
{
if (__instance.bankModel.autoCollect && __instance.Cash >= __instance.bankModel.capacity)
{
__instance.Collect();
}
}
}
/// <summary>
/// Fix bug where previous target suppliers that were since destroyed would sometimes still stick around
/// </summary>
[HarmonyPatch(typeof(Attack), nameof(Attack.UpdateActiveTargetSupplier))]
internal static class Attack_UpdateActiveTargetSupplier
{
[HarmonyPrefix]
internal static void Prefix(Attack __instance)
{
if (__instance.activeTargetSupplier is {IsDestroyed: true})
{
__instance.activeTargetSupplier = null;
}
}
}
}