diff --git a/JotunnModStub/RaceInput.cs b/JotunnModStub/RaceInput.cs index 4ec970b..2622a5d 100644 --- a/JotunnModStub/RaceInput.cs +++ b/JotunnModStub/RaceInput.cs @@ -15,13 +15,16 @@ namespace RacesOfValheim /// (InventoryGui covers the backpack and chests alike), so mirror that instead of maintaining /// a parallel list of GUI checks that would drift as the game changes. /// - /// ONE GUI THAT TakeInput DOES NOT COVER: the hammer's piece selection panel. Read off the IL, + /// TWO GUIS THAT TakeInput DOES NOT COVER. The first is the hammer's piece selection panel. Read off the IL, /// TakeInput tests Chat, Console, TextInput, StoreGui, InventoryGui, Menu, TextViewer, the map, /// free-fly and the barber - and nothing else. Vanilla does not need it there because build /// input is handled separately in UpdatePlacement, but a mod ability reading the device /// directly does: Skadi's cold spell is bound to middle mouse and kept casting while the build /// menu was open. Hud.IsPieceSelectionVisible is static, public and null-safe on its own /// instance, so it costs one call and no reflection. + /// + /// The second is the radial menu, and it is handled in AttackDown rather than here - see + /// RadialOpen for why the difference matters. /// public static class RaceInput { @@ -77,8 +80,18 @@ namespace RacesOfValheim /// public static bool IsDownIgnoringHeldKeys(this KeyboardShortcut shortcut) { + // The queued press is taken FIRST and without any gate, because that is the radial menu + // firing this very ability - see Press(). Everything below is the device being read raw. if (ConsumePress(shortcut)) return true; if (shortcut.MainKey == KeyCode.None) return false; + + // A keybind that sits on a mouse button is the radial's own click as far as the device is + // concerned, so the wheel closes this door too. AttackDown covers the forms' attacks; + // this covers abilities bound to a button instead - Skadi's cold spell is on middle + // mouse, and middle-clicking an entry in the wheel used to cast it. Keys at the keyboard + // are left alone: nothing about the wheel makes pressing K ambiguous. + if (RadialOpen && IsMouseButton(shortcut.MainKey)) return false; + if (!Input.GetKeyDown(shortcut.MainKey)) return false; foreach (KeyCode modifier in shortcut.Modifiers) @@ -143,15 +156,55 @@ namespace RacesOfValheim /// public static bool AttackDown(int mouseButton) { + if (RadialOpen) return false; return Input.GetMouseButtonDown(mouseButton) || PadAttackDown(mouseButton); } /// Held-down counterpart of . public static bool AttackHeld(int mouseButton) { + if (RadialOpen) return false; return Input.GetMouseButton(mouseButton) || PadAttackHeld(mouseButton); } + /// + /// Whether the radial menu is up, which is a third GUI TakeInput knows nothing about. + /// + /// Clicking an entry in the wheel was also swinging the transformed form's attack: the click + /// picks the entry AND is read here as a raw mouse button. Vanilla attacks are untouched by + /// this because they go through ZInput, which the radial already blocks - only input read + /// straight off the device gets through, which is all of ours. + /// + /// CHECKED HERE AND NOT IN , deliberately. The radial fires an ability by + /// queueing its keybind through Press(), and the ability's own reader picks that up inside an + /// Allowed gate - so blocking Allowed while the wheel is open would risk the wheel swallowing + /// the very abilities it exists to trigger. The queued press does survive, since it holds for + /// PressWindow rather than a single frame, but there is no reason to lean on that when only + /// the mouse reads are the problem. Keybinds pressed at the keyboard while the wheel is open + /// are left alone for the same reason. + /// + private static bool IsMouseButton(KeyCode key) + { + return key >= KeyCode.Mouse0 && key <= KeyCode.Mouse6; + } + + private static bool RadialOpen + { + get + { + try + { + return Hud.InRadial(); + } + catch + { + // Fail open, like the TakeInput path above: a game update that moves this must + // cost the fix, not every attack in every form. + return false; + } + } + } + /// The gamepad half of alone, for attacks whose mouse /// side is a rebindable KeyboardShortcut rather than a fixed button. public static bool PadAttackDown(int mouseButton)