From 99ec4134beb049bfbafb2da1808e18364226d0d7 Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 29 Oct 2026 01:50:33 +0100 Subject: [PATCH] fix(trenta): the Muspell no longer swings the weapon in hand The Muspell was the one form without the attack blocks every other form has. Each stomp and spike also started the hidden human's attack, and the Elder clone's CharacterAnimEvent fired a held bow or crossbow through OnAttackTrigger, several shots a swing. StartAttack, PlayerAttackInput and OnAttackTrigger are shut while the Muspell is up, and the guard is cleared after SetControls, since the spike sits on Right Mouse, which is also Block. --- JotunnModStub/Trenta/TrentaMuspell.cs | 44 +++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/JotunnModStub/Trenta/TrentaMuspell.cs b/JotunnModStub/Trenta/TrentaMuspell.cs index d3af9ef..473ced8 100644 --- a/JotunnModStub/Trenta/TrentaMuspell.cs +++ b/JotunnModStub/Trenta/TrentaMuspell.cs @@ -498,4 +498,48 @@ namespace RacesOfValheim target.Damage(hitData); } } + + /// + /// The hidden human does not fight under the Muspell. Every other form already had these + /// (see Fenrir's BlockPlayerLogicAttackPatch); the Muspell had none, so each stomp and spike + /// also swung the weapon in hand, and the Elder clone's own CharacterAnimEvent fired the held + /// bow or crossbow through OnAttackTrigger on top of that: a tester's bow shot several times a + /// swing. Right Mouse is the spike and the Block button at once, so the guard is cleared too, + /// as BlockPlayerGuardPatch does it. + /// + internal static class TrentaMuspellAttackBlock + { + private static bool LocalInForm(Character character) => + TrentaMuspell.IsTransformed && character != null && character == Player.m_localPlayer; + + [HarmonyPatch(typeof(Humanoid), nameof(Humanoid.StartAttack))] + public static class Trenta_MuspellBlockNativeAttack_Patch + { + public static bool Prefix(Humanoid __instance) => !LocalInForm(__instance); + } + + [HarmonyPatch(typeof(Player), "PlayerAttackInput")] + public static class Trenta_MuspellBlockAttackInput_Patch + { + public static bool Prefix(Player __instance) => !LocalInForm(__instance); + } + + [HarmonyPatch(typeof(Humanoid), nameof(Humanoid.OnAttackTrigger))] + public static class Trenta_MuspellBlockAttackTrigger_Patch + { + public static bool Prefix(Humanoid __instance) => !LocalInForm(__instance); + } + + [HarmonyPatch(typeof(Player), nameof(Player.SetControls))] + public static class Trenta_MuspellBlockGuard_Patch + { + private static readonly AccessTools.FieldRef Blocking = + AccessTools.FieldRefAccess("m_blocking"); + + public static void Postfix(Player __instance) + { + if (LocalInForm(__instance)) Blocking(__instance) = false; + } + } + } }