mirror of
https://github.com/soarqin/DSP_Mods.git
synced 2026-11-19 17:05:20 +08:00
fix(cheatenabler): restore mecha and fleet invincibility
Patch the native mecha damage and shield consumers so an inlined Player.invincible getter cannot bypass protection. Replace the fleet damage matcher with target-type prefixes to cover both space paths. Synchronize the English and Chinese documentation without changing version 2.4.8.
This commit is contained in:
1 parent
2eae91fa18
commit
64a23e9772
3 files changed
+35
-20
No files matched your search
@@ -1,10 +1,11 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using System.Linq;
|
||||
using System.Reflection.Emit;
|
||||
using BepInEx.Configuration;
|
||||
using HarmonyLib;
|
||||
using UXAssist.Common;
|
||||
using UXAssist.Common.ModFeatures;
|
||||
using UXAssist.Common.Patching;
|
||||
|
||||
namespace CheatEnabler.Patches;
|
||||
|
||||
@@ -48,27 +49,37 @@ public static class CombatPatch
|
||||
);
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
// Harmony transpiler: SkillSystem_DamageObject_Transpiler
|
||||
// Target: SkillSystem.DamageGroundObjectByLocalCaster, SkillSystem.DamageGroundObjectByRemoteCaster, SkillSystem.DamageObject
|
||||
// Fallback: None — patch will fail loudly if the target method body changes.
|
||||
// Harmony transpiler: Mecha_Invincible_Transpiler
|
||||
// Target: Mecha.TakeDamage, Mecha.EnergyShieldResist (both overloads)
|
||||
// Fallback: Return original instructions if the invincibility check is not found.
|
||||
[HarmonyTranspiler]
|
||||
[HarmonyPatch(typeof(Mecha), nameof(Mecha.TakeDamage))]
|
||||
[HarmonyPatch(typeof(Mecha), nameof(Mecha.EnergyShieldResist), [typeof(int)], [ArgumentType.Ref])]
|
||||
[HarmonyPatch(typeof(Mecha), nameof(Mecha.EnergyShieldResist), [typeof(int), typeof(int)], [ArgumentType.Ref, ArgumentType.Out])]
|
||||
private static IEnumerable<CodeInstruction> Mecha_Invincible_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
|
||||
{
|
||||
// Repatch the consumers too: an already inlined getter bypasses its own Harmony patch.
|
||||
var original = instructions.ToList();
|
||||
var matcher = new CodeMatcher(original, generator);
|
||||
matcher.MatchForward(false, new CodeMatch(ci => ci.Calls(AccessTools.PropertyGetter(typeof(Player), nameof(Player.invincible)))));
|
||||
if (matcher.IsInvalid) return matcher.Finish(original, CheatEnabler.Logger, nameof(Mecha_Invincible_Transpiler));
|
||||
matcher.Set(OpCodes.Pop, null).Advance(1).Insert(new CodeInstruction(OpCodes.Ldc_I4_1));
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(SkillSystem), nameof(SkillSystem.DamageGroundObjectByLocalCaster))]
|
||||
[HarmonyPatch(typeof(SkillSystem), nameof(SkillSystem.DamageGroundObjectByRemoteCaster))]
|
||||
[HarmonyPatch(typeof(SkillSystem), nameof(SkillSystem.DamageObject))]
|
||||
private static IEnumerable<CodeInstruction> SkillSystem_DamageObject_Transpiler(IEnumerable<CodeInstruction> instructions, ILGenerator generator, MethodBase __originalMethod)
|
||||
private static void SkillSystem_DamageGroundObject_Prefix(ref int damage, ref SkillTargetLocal target)
|
||||
{
|
||||
var matcher = new CodeMatcher(instructions, generator);
|
||||
matcher.MatchForward(false,
|
||||
new CodeMatch(ci => ci.IsLdarg()),
|
||||
new CodeMatch(OpCodes.Ldfld, AccessTools.Field(typeof(SkillTargetLocal), nameof(SkillTargetLocal.type))),
|
||||
new CodeMatch(OpCodes.Ldc_I4_6),
|
||||
new CodeMatch(ci => ci.opcode == OpCodes.Bne_Un || ci.opcode == OpCodes.Bne_Un_S)
|
||||
);
|
||||
matcher.Repeat(m => m.Advance(4).InsertAndAdvance(
|
||||
new CodeInstruction(OpCodes.Ldc_I4_0),
|
||||
new CodeInstruction(OpCodes.Starg_S, __originalMethod.Name == "DamageObject" ? 1 : 2)
|
||||
));
|
||||
return matcher.InstructionEnumeration();
|
||||
if (target.type == ETargetType.Craft) damage = 0;
|
||||
}
|
||||
|
||||
[HarmonyPrefix]
|
||||
[HarmonyPatch(typeof(SkillSystem), nameof(SkillSystem.DamageObject))]
|
||||
private static void SkillSystem_DamageObject_Prefix(ref int damage, ref SkillTarget target)
|
||||
{
|
||||
if (target.type == ETargetType.Craft) damage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -95,4 +106,4 @@ public static class CombatPatch
|
||||
return matcher.InstructionEnumeration();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user