Skip to content

Commit

Permalink
fix squadtactics hacks
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazingTwist committed Aug 18, 2021
1 parent 6fec6e7 commit cc9197e
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 9 deletions.
1 change: 1 addition & 0 deletions SoD_BaseMod/SoD_BaseMod.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="src\AsmFirstpass\KAUICursorManagerPatcher.cs" />
<Compile Include="src\asm\AbilityPatcher.cs" />
<Compile Include="src\asm\AvAvatarControllerPatcher.cs" />
<Compile Include="src\asm\CaAvatarCamPatcher.cs" />
<Compile Include="src\asm\CameraMovementPatcher.cs" />
Expand Down
1 change: 1 addition & 0 deletions SoD_BaseMod/src/SodBaseMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public void Awake() {
var harmony = new Harmony(pluginGuid);
harmony.PatchAll(GetType().Assembly);
CharacterPatcher.ApplyPatches(harmony);
AbilityPatcher.ApplyPatches(harmony);
}
}
}
56 changes: 56 additions & 0 deletions SoD_BaseMod/src/asm/AbilityPatcher.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using BepInEx.Logging;
using BTHarmonyUtils;
using BTHarmonyUtils.TranspilerUtils;
using HarmonyLib;
using JetBrains.Annotations;
using SoD_BaseMod.config;
using SquadTactics;

namespace SoD_BaseMod {
public static class AbilityPatcher {
private static readonly string loggerName = $"BT_{MethodBase.GetCurrentMethod().DeclaringType?.Name}";
private static ManualLogSource Logger => _logger ?? (_logger = BepInEx.Logging.Logger.CreateLogSource(loggerName));
private static ManualLogSource _logger;

public static void ApplyPatches(Harmony harmony) {
harmony.Patch(
original: PatcherUtils.FindIEnumeratorMoveNext(AccessTools.Method(typeof(Ability), nameof(Ability.Activate),
new[] { typeof(Character), typeof(Character) })),
transpiler: new HarmonyMethod(SymbolExtensions.GetMethodInfo(() => Activate_Transpiler(null)))
);
}

[UsedImplicitly]
private static int GetCooldown(int fallback) {
BTHackConfig hackConfig = BTDebugCamInputManager.GetConfigHolder().hackConfig;
if (hackConfig != null && hackConfig.squadTactics_infiniteActions) {
return 0;
}
return fallback;
}

[UsedImplicitly]
private static IEnumerable<CodeInstruction> Activate_Transpiler(IEnumerable<CodeInstruction> instructions) {
List<CodeInstruction> instructionList = instructions.ToList();

FieldInfo field_mCurrentCooldown = AccessTools.Field(typeof(Ability), "mCurrentCooldown");
MethodInfo patcherMethod_GetCooldown = SymbolExtensions.GetMethodInfo(() => GetCooldown(0));

CodeReplacementPatch patch = new CodeReplacementPatch(
expectedMatches: 1,
insertInstructionSequence: new List<CodeInstruction> {
new CodeInstruction(OpCodes.Call, patcherMethod_GetCooldown)
},
postfixInstructionSequence: new List<CodeInstruction> {
new CodeInstruction(OpCodes.Stfld, field_mCurrentCooldown)
}
);
patch.ApplySafe(instructionList, Logger);
return instructionList;
}
}
}
22 changes: 13 additions & 9 deletions SoD_BaseMod/src/asm/GameManagerPatcher.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using HarmonyLib;
using System.Linq;
using HarmonyLib;
using SoD_BaseMod.config;
using SquadTactics;

Expand All @@ -16,16 +17,19 @@ private static bool ProcessMouseUpPrefix(GameManager __instance, Node selectedNo
selectedNode._CharacterOnNode.TakeStatChange(SquadTactics.Stat.HEALTH, -10_000f);
return false;
}

return true;
}

if (hackConfig.squadTactics_infiniteRange) {
__instance.ShowCharacterMovementRange(true);
__instance.StartCoroutine(selectedNode._CharacterOnNode == null
? __instance._SelectedCharacter.DoMovement(selectedNode)
: __instance._SelectedCharacter.DoMovePlusAbility(selectedNode._CharacterOnNode));
return false;
[HarmonyPrefix, HarmonyPatch(methodName: nameof(GameManager.SelectCharacter), argumentTypes: new[] { typeof(Character) })]
private static void SelectCharacter_Prefix(GameManager __instance, Character character) {
BTHackConfig hackConfig = BTDebugCamInputManager.GetConfigHolder().hackConfig;
if (hackConfig != null && hackConfig.squadTactics_infiniteRange) {
foreach (StStat movementStat in __instance.pAllPlayerUnits.Select(playerUnit => playerUnit.pCharacterData._Stats._Movement)) {
movementStat._Limits.Max = 100;
movementStat.pCurrentValue = movementStat._Limits.Max;
}
}

return true;
}
}
}

0 comments on commit cc9197e

Please sign in to comment.