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/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(); }