diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index 07166f1..c3d0dff 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -529,7 +529,7 @@ namespace RacesOfValheim ZNetView nview = __instance.GetComponent(); if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid") { - if (__instance == Player.m_localPlayer && RaceInput.Allowed && AswidConfig.ToggleDevourKey.Value.IsDown()) + if (__instance == Player.m_localPlayer && RaceInput.Allowed && AswidConfig.ToggleDevourKey.Value.IsDownIgnoringHeldKeys()) { AswidRace.DevourEnabled = !AswidRace.DevourEnabled; string msg = AswidRace.DevourEnabled ? "Devour Ability: ENABLED" : "Devour Ability: DISABLED"; diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index d9cc23f..9293dd4 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -387,14 +387,14 @@ namespace RacesOfValheim if (RaceInput.Allowed) { - if (AswidConfig.BatFormKey.Value.IsDown()) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; } - if (AswidConfig.MistFormKey.Value.IsDown()) { TryToggleMistForm(); return; } - if (AswidConfig.EclipseKey.Value.IsDown()) + if (AswidConfig.BatFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; } + if (AswidConfig.MistFormKey.Value.IsDownIgnoringHeldKeys()) { TryToggleMistForm(); return; } + if (AswidConfig.EclipseKey.Value.IsDownIgnoringHeldKeys()) { TryCastEclipse(state); return; } - if (AswidConfig.TameKey.Value.IsDown()) + if (AswidConfig.TameKey.Value.IsDownIgnoringHeldKeys()) { TryTameHoverObject(state); return; diff --git a/JotunnModStub/Dvergar/DvergarAbilities.cs b/JotunnModStub/Dvergar/DvergarAbilities.cs index b0f0dc4..11cc807 100644 --- a/JotunnModStub/Dvergar/DvergarAbilities.cs +++ b/JotunnModStub/Dvergar/DvergarAbilities.cs @@ -26,12 +26,12 @@ namespace RacesOfValheim DvergarProgression.DvergarRules rules = DvergarProgression.GetRules(state); - if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDown()) + if (rules.RunicPing && DvergarConfigManagement.RunicPingKey.Value.IsDownIgnoringHeldKeys()) { TryRunicPing(player); } - if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDown()) + if (rules.RunicOvercharge && DvergarConfigManagement.RunicOverchargeKey.Value.IsDownIgnoringHeldKeys()) { TryRunicOvercharge(player); } diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index 615a4a3..86045ff 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -58,7 +58,7 @@ namespace RacesOfValheim } if (isGrounded && RaceInput.Allowed) { - if (FenrirConfig.HowlKey.Value.IsDown()) + if (FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys()) { StartCoroutine(HowlRoutine()); } @@ -339,7 +339,7 @@ namespace RacesOfValheim StopFire(); } - if (canAct && FenrirConfig.HowlKey.Value.IsDown()) + if (canAct && FenrirConfig.HowlKey.Value.IsDownIgnoringHeldKeys()) { StartCoroutine(HowlRoutine()); } diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index b37968d..5cfe73f 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -152,9 +152,9 @@ namespace RacesOfValheim { int state = BossProgressionManager.GetCurrentProgressionState(); - if (FenrirConfig.WolfFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; } - if (FenrirConfig.FenrirFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetHKeyRules(state)); return; } - if (FenrirConfig.CultistFormKey.Value.IsDown()) { TryTransformWithRules(FenrirProgression.GetJKeyRules(state)); return; } + if (FenrirConfig.WolfFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; } + if (FenrirConfig.FenrirFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetHKeyRules(state)); return; } + if (FenrirConfig.CultistFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(FenrirProgression.GetJKeyRules(state)); return; } } private void TryTransformWithRules(FenrirProgression.FormRules rules) diff --git a/JotunnModStub/RaceInput.cs b/JotunnModStub/RaceInput.cs index 1fbba32..04f8f08 100644 --- a/JotunnModStub/RaceInput.cs +++ b/JotunnModStub/RaceInput.cs @@ -1,4 +1,5 @@ using System.Reflection; +using BepInEx.Configuration; using HarmonyLib; using UnityEngine; @@ -48,6 +49,45 @@ namespace RacesOfValheim { SuppressGuardianPowerUntil = Time.time + seconds; } + + /// + /// What KeyboardShortcut.IsDown() should have been for a game key. + /// + /// BepInEx's own IsDown() ends in a check that no key outside the shortcut is being held + /// (ModifierKeyTest -> _modifierBlockKeyCodes.All(c => !GetKey(c) || allKeys.Contains(c))), + /// which is right for a config-menu hotkey and completely wrong for a game ability: it + /// only exempts the mouse buttons, so holding W - or any other movement key - silently + /// killed every bound ability in the mod, in every race, including the ones bound to mouse + /// buttons. Vanilla attacks kept working because they go through ZInput instead, which is + /// what made it look like the abilities specifically had broken. + /// + /// This keeps the part that matters (main key down, every modifier held) and drops the + /// blocking rule, so an ability fires while the player is moving. + /// + public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut) + { + if (shortcut.MainKey == KeyCode.None) return false; + if (!Input.GetKeyDown(shortcut.MainKey)) return false; + + foreach (KeyCode modifier in shortcut.Modifiers) + { + if (!Input.GetKey(modifier)) return false; + } + return true; + } + + /// Held-down counterpart of . + public static bool IsPressedIgnoringHeldKeys(this KeyboardShortcut shortcut) + { + if (shortcut.MainKey == KeyCode.None) return false; + if (!Input.GetKey(shortcut.MainKey)) return false; + + foreach (KeyCode modifier in shortcut.Modifiers) + { + if (!Input.GetKey(modifier)) return false; + } + return true; + } } [HarmonyPatch(typeof(Player), "ActivateGuardianPower")] diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index b325194..74ff020 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -20,6 +20,19 @@ namespace RacesOfValheim // Read by RacesVisualController on other clients so they can keep this character airborne. public const string FlyingKey = "RacesOfValheim_SkadiFlying"; + /// + /// Time.time until which a breath is still streaming. Read by SkadiReverseFacingPatch to + /// hold the body on the aim for the duration. + /// + /// A deadline rather than a bool on purpose: the attack coroutine has several early exits + /// (a missing prefab, not enough stamina) and can be cut short outright when the form is + /// destroyed mid-breath, so a flag would leak set and pin the body forever. A timestamp + /// cannot leak - it expires on its own however the coroutine ends. + /// + private static float breathingUntil = -1f; + + public static bool IsBreathing => Time.time < breathingUntil; + private void SetFlying(bool value) { HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(value); @@ -85,18 +98,41 @@ namespace RacesOfValheim { Active = this; anim = GetComponentInChildren(); + if (Player.m_localPlayer != null) { SetFlying(false); } } + /// + /// Animator.SetTrigger on a name the controller does not have is silently ignored by Unity, + /// so a wrong trigger looks exactly like "the animation did not play" with nothing in the + /// log. Check before setting, while the form's real trigger names are still being pinned + /// down against the live prefabs. + /// + private void SetAttackTrigger(string trigger) + { + if (anim == null) return; + + foreach (AnimatorControllerParameter p in anim.parameters) + { + if (p.type == AnimatorControllerParameterType.Trigger && p.name == trigger) + { + anim.SetTrigger(trigger); + return; + } + } + + Jotunn.Logger.LogWarning($"[SkadiFormDebug] {formRules?.Form}: no trigger named '{trigger}' on this animator."); + } + private void Update() { if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; // Handle Flight Toggle (Right Mouse by default, rebindable) - Disabled for Fader - if (RaceInput.Allowed && SkadiConfig.FlightToggleKey.Value.IsDown() && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) + if (RaceInput.Allowed && SkadiConfig.FlightToggleKey.Value.IsDownIgnoringHeldKeys() && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) { if (!isFlying && !isLanding) { @@ -155,21 +191,21 @@ namespace RacesOfValheim // as it did when these were raw mouse-button checks. if (CanAttackNow() && RaceInput.Allowed) { - if (SkadiConfig.PrimaryAttackKey.Value.IsDown()) + if (SkadiConfig.PrimaryAttackKey.Value.IsDownIgnoringHeldKeys()) { if (HasAttackForButton(0) && Time.time - lastAttackTime >= ATTACK_COOLDOWN) { StartCoroutine(PerformAttackCoroutine(0)); } } - else if (SkadiConfig.BreathAttackKey.Value.IsDown()) + else if (SkadiConfig.BreathAttackKey.Value.IsDownIgnoringHeldKeys()) { if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) { StartCoroutine(PerformAttackCoroutine(2)); } } - else if (SkadiConfig.SpinAttackKey.Value.IsDown() && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // Fader Spin + else if (SkadiConfig.SpinAttackKey.Value.IsDownIgnoringHeldKeys() && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // Fader Spin { if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) { @@ -291,7 +327,19 @@ namespace RacesOfValheim } if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; - if (anim != null) anim.SetTrigger(attackTrigger); + + // Committed for the same reason as Fader's below: a 16- or 20-projectile volley + // lasts long enough for the camera to swing away from where the animation is + // still breathing. + // Grounded, the same as Fader's below: the head is held on the aim and the breath + // comes out of it. In the air the flight patch already steers the body, so this + // stays out of its way and the volley simply follows the same muzzle. + if (!isMelee && !isFlying && !isLanding) + { + breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f; + } + + SetAttackTrigger(attackTrigger); yield return new WaitForSeconds(projDelay); @@ -311,9 +359,9 @@ namespace RacesOfValheim float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel; for (int i = 0; i < projCount; i++) { - Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 3.0f; - Vector3 targetDir = Player.m_localPlayer.GetLookDir(); - + Vector3 targetDir = Player.m_localPlayer.transform.forward; + Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + targetDir * 3.0f; + if (projCount > 1) { Vector3 right = Vector3.Cross(Vector3.up, targetDir); @@ -377,7 +425,26 @@ namespace RacesOfValheim } if (!isMelee && !TrySpendVolleyStamina(projCount)) yield break; - if (anim != null) anim.SetTrigger(attackTrigger); + + // A breath is a stream, not a shot: 60 shards at 0.05 s each runs for about three + // seconds. Reading GetLookDir() fresh inside that loop let the ice track the + // crosshair live while the model's own breath VFX - baked into the animation, and + // so always leaving the muzzle - stayed with the body, which only turns at + // m_turnSpeed. Sweep the camera mid-breath and the two ended up pointing opposite + // ways. The direction is committed here instead, and the body is turned onto it. + // The breath follows the muzzle rather than a direction captured when the key went + // down. The model's own breath VFX is part of the animation and always leaves the + // mouth, so any direction the projectiles keep on their own drifts away from it - + // locking it at the press just swapped which of the two lagged. Pinning the body + // to the aim for the duration (breathingUntil, read by SkadiReverseFacingPatch) + // lets the mouse steer the head, and the projectiles below simply come out of + // wherever it has turned to, so ice and VFX cannot separate. + if (!isMelee) + { + breathingUntil = Time.time + projDelay + projCount * 0.05f + 0.5f; + } + + SetAttackTrigger(attackTrigger); yield return new WaitForSeconds(projDelay); @@ -397,8 +464,8 @@ namespace RacesOfValheim float vel = staffDrop.m_itemData.m_shared.m_attack.m_projectileVel; for (int i = 0; i < projCount; i++) { - Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + Player.m_localPlayer.GetLookDir() * 4.0f; - Vector3 targetDir = Player.m_localPlayer.GetLookDir(); + Vector3 targetDir = Player.m_localPlayer.transform.forward; + Vector3 spawnPos = Player.m_localPlayer.GetEyePoint() + targetDir * 4.0f; if (projCount > 1) { diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 7e1c3cd..6eba5d9 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -444,6 +444,19 @@ namespace RacesOfValheim public static bool Prefix(Player __instance, ref bool __result) { if (__instance != Player.m_localPlayer) return true; + + // A breath in progress holds the body on the aim, whether the player is moving or not. + // Character.UpdateRotation only steers by m_lookYaw when AlwaysRotateCamera() is true + // or the player is standing still - otherwise it faces m_moveDir. So running or + // strafing mid-breath turned the model (and the muzzle VFX baked into its animation) + // towards the run while our projectiles kept going where the player aimed, which is + // how the ice and the poison ended up pointing different ways. + if (DrakeFormBehavior.IsBreathing && DrakeFormBehavior.Active != null) + { + __result = true; + return false; + } + if (!SkadiDirectedFlightPatch.Reversing) return true; DrakeFormBehavior form = DrakeFormBehavior.Active; @@ -473,7 +486,7 @@ namespace RacesOfValheim // the live button state (via the configured shortcut, so a rebind stays in sync) // rather than a flag set during our Update, so it does not depend on whether // PlayerController's FixedUpdate happens to run first. - if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressed() && + if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressedIgnoringHeldKeys() && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi()) { var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()); diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 75e2602..15d08bf 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -244,9 +244,9 @@ namespace RacesOfValheim if (!RaceInput.Allowed) return; int state = BossProgressionManager.GetCurrentProgressionState(); - if (SkadiConfig.DrakeFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; } - if (SkadiConfig.ModerFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; } - if (SkadiConfig.FaderFormKey.Value.IsDown()) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; } + if (SkadiConfig.DrakeFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; } + if (SkadiConfig.ModerFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; } + if (SkadiConfig.FaderFormKey.Value.IsDownIgnoringHeldKeys()) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; } // Debug Dump if (Input.GetKeyDown(KeyCode.F8)) @@ -336,7 +336,7 @@ namespace RacesOfValheim if (isTransformed) return; // Do not cast human spell while in dragon form // Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey. - if (SkadiConfig.ColdSpellKey.Value.IsDown()) + if (SkadiConfig.ColdSpellKey.Value.IsDownIgnoringHeldKeys()) { // The improved cast is a burst rather than a rapid-fire, so it waits longer. float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN; diff --git a/JotunnModStub/Trenta/TrentaAbilities.cs b/JotunnModStub/Trenta/TrentaAbilities.cs index 1dceaf9..8e8e3c9 100644 --- a/JotunnModStub/Trenta/TrentaAbilities.cs +++ b/JotunnModStub/Trenta/TrentaAbilities.cs @@ -23,17 +23,17 @@ namespace RacesOfValheim // Player.TakeInput, so nothing fires while a map, chest or chat window has focus. if (!RaceInput.Allowed) return; - if (state >= TrentaConfig.PurpleRainUnlockState && TrentaConfigManagement.PurpleRainKey.Value.IsDown()) + if (state >= TrentaConfig.PurpleRainUnlockState && TrentaConfigManagement.PurpleRainKey.Value.IsDownIgnoringHeldKeys()) { TryPurpleRain(player); } - if (state >= TrentaConfig.PortalUnlockState && TrentaConfigManagement.PortalKey.Value.IsDown()) + if (state >= TrentaConfig.PortalUnlockState && TrentaConfigManagement.PortalKey.Value.IsDownIgnoringHeldKeys()) { TryOpenPortal(player); } - if (state >= TrentaConfig.MuspellUnlockState && TrentaConfigManagement.MuspellKey.Value.IsDown()) + if (state >= TrentaConfig.MuspellUnlockState && TrentaConfigManagement.MuspellKey.Value.IsDownIgnoringHeldKeys()) { TrentaMuspell.Toggle(player); } diff --git a/JotunnModStub/Trol/TrolRace.cs b/JotunnModStub/Trol/TrolRace.cs index ec5376e..0a50712 100644 --- a/JotunnModStub/Trol/TrolRace.cs +++ b/JotunnModStub/Trol/TrolRace.cs @@ -125,17 +125,17 @@ namespace RacesOfValheim if (RaceInput.Allowed) { - if (TrolConfig.ThrowRockKey.Value.IsDown()) + if (TrolConfig.ThrowRockKey.Value.IsDownIgnoringHeldKeys()) { TryThrowRock(); } - if (TrolConfig.TrueFormKey.Value.IsDown()) + if (TrolConfig.TrueFormKey.Value.IsDownIgnoringHeldKeys()) { TryTrueForm(); } - if (TrolConfig.GrabLogKey.Value.IsDown()) + if (TrolConfig.GrabLogKey.Value.IsDownIgnoringHeldKeys()) { TryGrabLog(); }