From 7708599ff9a5cbff956e81eb7f05edd81c029c87 Mon Sep 17 00:00:00 2001 From: kanym Date: Thu, 6 Aug 2026 13:08:05 +0200 Subject: [PATCH] feat(skadi): add rebindable keybinds for abilities and special attacks Adds a Skadi - Keybinds config section (bound first, ahead of the other Skadi sections) covering every ability/attack trigger: dragon primary attack, cold spell cast, breath attack, Fader spin, flight toggle, and the three transform keys (Drake/Moder/Fader). Defaults match the previous fixed inputs exactly. SkadiAttackPatch's kick-suppression check now reads the configured Cold Spell key instead of a hardcoded Middle Mouse, so it stays correct if that key is rebound. Entries within Keybinds carry an explicit Order (via the new ConfigurationManagerAttributes shim, per CONFIGURATION-MANAGER-HOWTO.md) so they list as attack -> cast -> breath -> spin -> flight -> the three transform keys, rather than alphabetically. --- .../ConfigurationManagerAttributes.cs | 37 ++++++++++++ JotunnModStub/Skadi/DrakeFormBehavior.cs | 14 +++-- JotunnModStub/Skadi/SkadiConfig.cs | 58 +++++++++++++++++-- JotunnModStub/Skadi/SkadiPatches.cs | 11 ++-- JotunnModStub/Skadi/SkadiRace.cs | 10 ++-- 5 files changed, 108 insertions(+), 22 deletions(-) create mode 100644 JotunnModStub/ConfigurationManagerAttributes.cs diff --git a/JotunnModStub/ConfigurationManagerAttributes.cs b/JotunnModStub/ConfigurationManagerAttributes.cs new file mode 100644 index 0000000..9b18654 --- /dev/null +++ b/JotunnModStub/ConfigurationManagerAttributes.cs @@ -0,0 +1,37 @@ +using System; +using BepInEx.Configuration; + +namespace RacesOfValheim +{ + /// + /// Duck-typed by Configuration Manager (matched by field name via reflection, not by type), + /// so nothing here needs a reference to ConfigurationManager.dll and the mod works with or + /// without that plugin installed - see CONFIGURATION-MANAGER-HOWTO.md, "Overriding default + /// Configuration Manager behavior". Kept internal, not public, so this shape can never collide + /// with another mod's copy of the same trick. + /// + /// Only the fields RacesOfValheim actually sets (Order, CustomDrawer, HideDefaultButton, + /// ReadOnly) need to be correct; the rest of Configuration Manager's documented set is kept + /// alongside them so future config additions do not need a second copy of this file. + /// + internal sealed class ConfigurationManagerAttributes + { + // Most of these are read by Configuration Manager itself via reflection and are never + // assigned from our own code, which is exactly what CS0649 is warning about here. +#pragma warning disable 0649 + public Action CustomDrawer; + public bool? Browsable; + public string Category; + public object DefaultValue; + public bool? HideDefaultButton; + public bool? HideSettingName; + public string Description; + public string DispName; + public int? Order; + public bool? ReadOnly; + public bool? IsAdvanced; + public Func ObjToStr; + public Func StrToObj; +#pragma warning restore 0649 + } +} diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index 099fd33..b325194 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -95,8 +95,8 @@ namespace RacesOfValheim { if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; - // Handle Flight Toggle (RMB) - Disabled for Fader - if (RaceInput.Allowed && Input.GetMouseButtonDown(1) && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) + // 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 (!isFlying && !isLanding) { @@ -150,24 +150,26 @@ namespace RacesOfValheim anim.SetFloat("forward_speed", speed); } - // Handle Attack + // Handle Attack - each trigger is a rebindable SkadiConfig keybind; the button id + // passed into PerformAttackCoroutine (0/1/2) still selects which attack runs, exactly + // as it did when these were raw mouse-button checks. if (CanAttackNow() && RaceInput.Allowed) { - if (Input.GetMouseButtonDown(0)) + if (SkadiConfig.PrimaryAttackKey.Value.IsDown()) { if (HasAttackForButton(0) && Time.time - lastAttackTime >= ATTACK_COOLDOWN) { StartCoroutine(PerformAttackCoroutine(0)); } } - else if (Input.GetMouseButtonDown(2)) // MMB + else if (SkadiConfig.BreathAttackKey.Value.IsDown()) { if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) { StartCoroutine(PerformAttackCoroutine(2)); } } - else if (Input.GetMouseButtonDown(1) && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // RMB for Fader Spin + else if (SkadiConfig.SpinAttackKey.Value.IsDown() && formRules.Form == SkadiProgression.FormType.SkeletonDragon) // Fader Spin { if (Time.time - lastAttackTime >= ATTACK_COOLDOWN) { diff --git a/JotunnModStub/Skadi/SkadiConfig.cs b/JotunnModStub/Skadi/SkadiConfig.cs index 2b3fcfc..0f79d67 100644 --- a/JotunnModStub/Skadi/SkadiConfig.cs +++ b/JotunnModStub/Skadi/SkadiConfig.cs @@ -1,19 +1,37 @@ +using UnityEngine; using BepInEx.Configuration; namespace RacesOfValheim { /// - /// Every tunable number behind Skadi's abilities and special attacks, bound as BepInEx - /// ConfigEntry so they show up in Configuration Manager without touching code - see + /// Every tunable number and keybind behind Skadi's abilities and special attacks, bound as + /// BepInEx ConfigEntry so they show up in Configuration Manager without touching code - see /// CONFIGURATION-MANAGER-HOWTO.md. Bound once, from RacesOfValheim.Awake(). /// - /// Grouped to match the three places a Skadi actually gets these numbers from: the human - /// form's Cold Spell and passive frost aura/damage, the three dragon forms' melee and ranged - /// attacks, and directed flight. + /// One section per sub-group (rather than everything under one "Skadi" section) so each shows + /// up as its own entry in Configuration Manager's category list - collapsing them into a + /// single section made that list disappear. Keybinds is bound first, before its section + /// otherwise sorts alphabetically among the rest, since it is the group most worth reaching + /// quickly; within it every entry carries an explicit Order (Configuration Manager otherwise + /// sorts a section's own entries alphabetically) so it reads attack -> cast -> breath -> spin + /// -> flight -> the three transform keys, the order abilities actually chain in a fight, + /// rather than alphabetically. /// public static class SkadiConfig { - // ─── Cold Spell (human form, Middle Mouse) ───────────────────────────── + // ─── Keybinds ────────────────────────────────────────────────────────── + // Defaults match today's fixed inputs exactly, so nobody's controls change until they + // open Configuration Manager (or the .cfg) and rebind one on purpose. + public static ConfigEntry PrimaryAttackKey; + public static ConfigEntry ColdSpellKey; + public static ConfigEntry BreathAttackKey; + public static ConfigEntry SpinAttackKey; + public static ConfigEntry FlightToggleKey; + public static ConfigEntry DrakeFormKey; + public static ConfigEntry ModerFormKey; + public static ConfigEntry FaderFormKey; + + // ─── Cold Spell (human form) ───────────────────────────────────────── public static ConfigEntry SpellStaminaCost; public static ConfigEntry SpellCooldown; public static ConfigEntry ImprovedSpellCooldown; @@ -57,6 +75,29 @@ namespace RacesOfValheim public static void Bind(ConfigFile config) { + // Bound first, and ahead of everything else in the file, in case Configuration + // Manager's category list preserves bind order rather than sorting sections + // alphabetically - either way, the keybinds themselves still land in the requested + // order via the explicit Order below, which is guaranteed. + const string keybinds = "Skadi - Keybinds"; + int keyOrder = 8; + PrimaryAttackKey = config.Bind(keybinds, "Dragon Primary Attack", new KeyboardShortcut(KeyCode.Mouse0), + KeyDesc("Bite/claw attack in any dragon form.", keyOrder--)); + ColdSpellKey = config.Bind(keybinds, "Cold Spell Cast", new KeyboardShortcut(KeyCode.Mouse2), + KeyDesc("Casts the Cold Spell in human form, tier 1+.", keyOrder--)); + BreathAttackKey = config.Bind(keybinds, "Dragon Breath Attack", new KeyboardShortcut(KeyCode.Mouse2), + KeyDesc("Ranged breath/barrage attack in Moder and Skeleton Dragon form.", keyOrder--)); + SpinAttackKey = config.Bind(keybinds, "Fader Spin Attack", new KeyboardShortcut(KeyCode.Mouse1), + KeyDesc("360-degree spin attack, Skeleton Dragon form only.", keyOrder--)); + FlightToggleKey = config.Bind(keybinds, "Flight Toggle", new KeyboardShortcut(KeyCode.Mouse1), + KeyDesc("Takes off or lands while in Drake or Moder form.", keyOrder--)); + DrakeFormKey = config.Bind(keybinds, "Drake Form", new KeyboardShortcut(KeyCode.G), + KeyDesc("Transform into (or revert from) the Drake, tier 3+.", keyOrder--)); + ModerFormKey = config.Bind(keybinds, "Moder Form", new KeyboardShortcut(KeyCode.H), + KeyDesc("Transform into (or revert from) Moder, tier 5+.", keyOrder--)); + FaderFormKey = config.Bind(keybinds, "Fader Form", new KeyboardShortcut(KeyCode.J), + KeyDesc("Transform into (or revert from) the Skeleton Dragon, tier 8.", keyOrder--)); + const string spell = "Skadi - Cold Spell"; SpellStaminaCost = config.Bind(spell, "Stamina Cost", 20f, new ConfigDescription("Stamina spent per cast.", new AcceptableValueRange(0f, 100f))); @@ -129,5 +170,10 @@ namespace RacesOfValheim FlightSprintStaminaPerSecond = config.Bind(flight, "Sprint Stamina Per Second", 15f, new ConfigDescription("Stamina drained per second while the sprint speed is actually granted.", new AcceptableValueRange(0f, 60f))); } + + private static ConfigDescription KeyDesc(string description, int order) + { + return new ConfigDescription(description, null, new ConfigurationManagerAttributes { Order = order }); + } } } diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 571bf07..7e1c3cd 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -467,12 +467,13 @@ namespace RacesOfValheim } // Valheim binds its own SecondaryAttack action to Middle Mouse, the same button the - // Cold Spell casts on, so pressing it also swung the unarmed secondary - the kick that - // kept showing up alongside the cast no matter which animation trigger we used. For a - // Skadi who has the spell, Middle Mouse belongs to the spell. Keyed off the live button - // state rather than a flag set during our Update, so it does not depend on whether + // Cold Spell casts on by default, so pressing it also swung the unarmed secondary - + // the kick that kept showing up alongside the cast no matter which animation trigger + // we used. For a Skadi who has the spell, that button belongs to the spell. Keyed off + // 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 && Input.GetMouseButton(2) && + if (secondaryAttack && SkadiConfig.ColdSpellKey.Value.IsPressed() && 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 9c45f28..f5cf719 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -221,9 +221,9 @@ namespace RacesOfValheim if (!RaceInput.Allowed) return; int state = BossProgressionManager.GetCurrentProgressionState(); - if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(SkadiProgression.GetGKeyRules(state)); return; } - if (Input.GetKeyDown(KeyCode.H)) { TryTransformWithRules(SkadiProgression.GetHKeyRules(state)); return; } - if (Input.GetKeyDown(KeyCode.J)) { TryTransformWithRules(SkadiProgression.GetJKeyRules(state)); return; } + 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; } // Debug Dump if (Input.GetKeyDown(KeyCode.F8)) @@ -311,8 +311,8 @@ namespace RacesOfValheim if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; if (isTransformed) return; // Do not cast human spell while in dragon form - // Middle Mouse Button to cast - if (Input.GetMouseButtonDown(2)) + // Middle Mouse Button to cast, by default - rebindable via SkadiConfig.ColdSpellKey. + if (SkadiConfig.ColdSpellKey.Value.IsDown()) { // The improved cast is a burst rather than a rapid-fire, so it waits longer. float cooldown = rules.ImprovedColdSpell ? IMPROVED_SPELL_COOLDOWN : SPELL_COOLDOWN;