Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
# Conflicts:
#	ModHelperData.cs
  • Loading branch information
doombubbles committed Oct 14, 2023
2 parents e9ad382 + 7e4f82b commit beaf0f9
Show file tree
Hide file tree
Showing 17 changed files with 671 additions and 142 deletions.
Binary file modified Icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 2 additions & 1 deletion LATEST.md
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
- Fixed for BTD6 v38.1
- Fixed for BTD6 v39.0
- Added functionality for creating additional tiers for tower upgrade paths, see updated readme for more details
8 changes: 4 additions & 4 deletions ModHelperData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ namespace PathsPlusPlus;

internal static class ModHelperData
{
public const string WorksOnVersion = "38.1";
public const string Version = "1.0.2";
public const string WorksOnVersion = "39.0";
public const string Version = "1.1.0";
public const string Name = "Paths++";

public const string Description = "A helper mod allowing additional upgrade paths to be made for towers.\n\n" +
"Toggle 'Balanced Mode' to switch from being still only able get up to 5 upgrades in any one path and 2 in another, " +
public const string Description = "A helper mod allowing additional upgrade paths and tiers to be made for towers.\n\n" +
"Toggle 'Balanced Mode' to switch from being still only able get up to max upgrades in any one path and 2 in another, " +
"vs getting all vanilla upgrades you normally can as well as any/all available Paths++ upgrades.\n\n" +
"Toggling off Balanced Mode can also function well with Ultimate Crosspathing (assuming the Mod Creators were keeping it in mind while coding).";

Expand Down
29 changes: 2 additions & 27 deletions Patches/GamePatches.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ internal static class UnityToSimulation_UpgradeTower_Impl
[HarmonyPrefix]
private static bool Prefix(UnityToSimulation __instance, ObjectId id, int pathIndex, int callbackId, int inputId)
{
if (pathIndex < 3 || current == null) return true;
if (current == null || !PathsPlusPlusMod.UpgradesById.ContainsKey(current.name)) return true;

var action = __instance.UnregisterCallback(callbackId, inputId);
var towerManager = __instance.simulation.towerManager;
Expand Down Expand Up @@ -75,7 +75,7 @@ private static bool Prefix(UnityToSimulation __instance, ObjectId id, int pathIn
}

[HarmonyPatch(typeof(TowerSelectionMenu), nameof(TowerSelectionMenu.UpgradeTower), typeof(UpgradeModel), typeof(int),
typeof(float))]
typeof(float), typeof(double))]
internal static class TowerSelectionMenu_UpgradeTower
{
[HarmonyPrefix]
Expand All @@ -84,29 +84,4 @@ private static void Prefix(UpgradeModel upgrade)
UnityToSimulation_UpgradeTower_Impl.current = upgrade;
UnityToSimulation_UpgradeTower_Impl.cash = InGame.instance.GetCash();
}
}

/// <summary>
/// If a path uses a TowerCreateTowerModel, don't let multiple towers spawn due to upgrading thet tower
/// </summary>
[HarmonyPatch(typeof(TowerCreateTower), nameof(TowerCreateTower.OnDestroy))]
internal static class TowerCreateTower_OnDestroy
{
[HarmonyPrefix]
private static void Prefix(TowerCreateTower __instance)
{
if (__instance.towerAdded && !__instance.tower.IsDestroyed)
{
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);
}
}
}
}
71 changes: 65 additions & 6 deletions Patches/PreventPatches.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
using BTD_Mod_Helper.Extensions;
using HarmonyLib;
using Il2CppAssets.Scripts.Models.Towers.Upgrades;
using Il2CppAssets.Scripts.Simulation.Input;
using Il2CppAssets.Scripts.Simulation.Objects;
using Il2CppAssets.Scripts.Simulation.Towers;
using Il2CppAssets.Scripts.Simulation.Towers.Behaviors;
using Il2CppAssets.Scripts.Unity.Bridge;
using Il2CppAssets.Scripts.Unity.UI_New.InGame.TowerSelectionMenu;
using Il2CppAssets.Scripts.Unity.UI_New.Upgrade;

namespace PathsPlusPlus.Patches;

Expand All @@ -16,17 +19,23 @@ private static bool Prefix(TowerSelectionMenu __instance, int path, ref bool __r
{
if (!PathsPlusPlusMod.BalancedMode)
{
if (path < 3) return true;

__result = false;
return false;
}

var tower = __instance.selectedTower.tower;
var tiers = tower.GetAllTiers();
tiers[path]++;

__result = !PathsPlusPlusMod.ValidTiers(tiers);
if (PathPlusPlus.TryGetPath(tower.towerModel.baseId, path, out var pathPlusPlus))
{
tiers[path]++;
__result = !pathPlusPlus.ValidTiers(tiers.ToArray());
}
else
{
__result = !PathPlusPlus.DefaultValidTiers(tiers.ToArray());
}

return false;
}
}
Expand Down Expand Up @@ -63,8 +72,6 @@ internal static class TowerToSimulation_GetMaxTierForPath
[HarmonyPrefix]
private static bool Prefix(TowerToSimulation __instance, int path, ref int __result)
{
if (path < 3) return true;

__result = PathPlusPlus.TryGetPath(__instance.Def.baseId, path, out var pathPlusPlus)
? pathPlusPlus.UpgradeCount
: 5;
Expand Down Expand Up @@ -131,4 +138,56 @@ internal static class Tower_AddMutator
[HarmonyPrefix]
private static bool Prefix(Tower __instance, BehaviorMutator mutator) =>
!(__instance.towerModel.isSubTower && PathsPlusPlusMod.PathsById.ContainsKey(mutator.id));
}

[HarmonyPatch(typeof(UpgradeModel), nameof(UpgradeModel.IsParagon), MethodType.Getter)]
internal static class UpgradeModel_IsParagon
{
[HarmonyPrefix]
private static bool Prefix(UpgradeModel __instance, ref bool __result)
{
if (PathsPlusPlusMod.UpgradesById.ContainsKey(__instance.name))
{
__result = false;
return false;
}

return true;
}
}

[HarmonyPatch(typeof(UpgradeObject), nameof(UpgradeObject.PostSimUpgrade))]
internal static class UpgradeObject_PostSimUpgrade
{
[HarmonyPrefix]
private static bool Prefix(UpgradeObject __instance)
{
return __instance.isActiveAndEnabled;
}
}

[HarmonyPatch(typeof(BeastHandlerUpgradeLock), nameof(BeastHandlerUpgradeLock.IsUpgradeBlocked))]
internal static class BeastHandlerUpgradeLock_IsUpgradeBlocked
{
[HarmonyPrefix]
private static bool Prefix(BeastHandlerUpgradeLock __instance, int path, ref bool __result)
{
if (path >= 3)
{
__result = false;
return false;
}

return true;
}
}

[HarmonyPatch(typeof(UpgradeDetails), nameof(UpgradeDetails.OnPointerExit))]
internal static class UpgradeDetails_OnPointerExit
{
[HarmonyPostfix]
private static void Postfix(UpgradeDetails __instance)
{

}
}
Loading

0 comments on commit beaf0f9

Please sign in to comment.