From 95dcf3c1e64d166cf62b4028d5d1ad0122152753 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 31 Jul 2026 11:24:30 +0200 Subject: [PATCH 1/5] Fix build portability: add BepInEx NuGet feed and de-hardcode package paths BepInEx.Core isn't on nuget.org (only on nuget.bepinex.dev), so restore failed on machines without it configured globally. PackageThunderstore also pointed at a contributor's personal desktop path; it now outputs to a repo-local dist/ folder and uses the checked-in Package/icon.png. Co-Authored-By: Claude Sonnet 5 --- JotunnModStub/RacesOfValheim.csproj | 12 ++++++++---- NuGet.Config | 7 +++++++ 2 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 NuGet.Config diff --git a/JotunnModStub/RacesOfValheim.csproj b/JotunnModStub/RacesOfValheim.csproj index 7122411..6029e4c 100644 --- a/JotunnModStub/RacesOfValheim.csproj +++ b/JotunnModStub/RacesOfValheim.csproj @@ -93,11 +93,15 @@ - + + + $(SolutionDir)dist\ + + - - - + + + diff --git a/NuGet.Config b/NuGet.Config new file mode 100644 index 0000000..d5f366b --- /dev/null +++ b/NuGet.Config @@ -0,0 +1,7 @@ + + + + + + + From 00b1b4e9ed126fd54fda21346f21d7b058379f16 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 31 Jul 2026 13:04:30 +0200 Subject: [PATCH 2/5] Fix Skadi resetrace, cold spell VFX, and Freezing-to-Cold conversion - resetrace never cleaned up SE_SkadiStats/SE_SkadiCooldown, so Skadi's Aura and its frost buffs stuck around after switching race. - Cold Spell projectile spawned near the feet (0.4m) and used the unarmed kick animation; now spawns at chest height and uses the galdr_cast (raised-arms) trigger instead. - Freezing-to-Cold silently did nothing from tier 1 onward: Skadi's passive Frost damage resistance made Valheim's own environmental check skip Cold/Freezing entirely before our conversion patch ever ran. Added a scoped patch that neutralizes just that environmental check for the local Skadi player, plus a guard against Valheim's own Cold-removal call flickering the converted status off every other frame, plus an explicit cleanup of any real Freezing left over from before the conversion kicked in. Co-Authored-By: Claude Sonnet 5 --- JotunnModStub/RacesOfValheim.cs | 2 + JotunnModStub/Skadi/SkadiPatches.cs | 71 +++++++++++++++++++++++++++++ JotunnModStub/Skadi/SkadiRace.cs | 17 +++---- 3 files changed, 82 insertions(+), 8 deletions(-) diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 079e3b1..9b99d9f 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -600,6 +600,8 @@ namespace RacesOfValheim Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode()); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode()); Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode()); + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode()); + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode()); ZNetView nview = Player.m_localPlayer.GetComponent(); if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_Race", "Human"); diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 3b35c9a..e79121c 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -98,6 +98,10 @@ namespace RacesOfValheim if (rules.FreezingToCold) { + // Strip any real Freezing that may already be active (e.g. applied + // before this tier's conversion kicked in) so it can't linger + // alongside the converted Cold status. + __instance.RemoveStatusEffect("Freezing".GetStableHashCode(), true); nameHash = "Cold".GetStableHashCode(); } } @@ -106,6 +110,73 @@ namespace RacesOfValheim } } + // SE_SkadiStats grants a "Resistant" (or higher) Frost damage modifier from tier 1 onward, + // exactly like drinking a Frost Resistance potion. Valheim's own Player.UpdateEnvStatusEffects + // checks that same Frost damage modifier before deciding whether to apply Cold/Freezing at + // all, and skips both entirely once the character is Frost-resistant. That means real Mountain + // exposure (which applies Freezing, not Cold, per vanilla rules) never even reaches + // SkadiSEManPatch above from tier 1 onward, so the tier 2 "Freezing to Cold" conversion never + // gets a chance to run. These two patches scope out just that one environmental check: while + // Player.UpdateEnvStatusEffects is running for the local Skadi player, GetDamageModifiers is + // reported as Normal for Frost, so vanilla always attempts to apply the real status and + // SkadiSEManPatch's per-tier logic (block/convert/allow) is what actually decides the outcome. + // Frost damage resistance from hits (SkadiDamagePatch) is untouched by this. + [HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")] + public static class SkadiEnvCheckScope + { + public static bool Active = false; + + public static void Prefix(Player __instance) + { + Active = __instance == Player.m_localPlayer && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi(); + } + + public static void Postfix() + { + Active = false; + } + } + + [HarmonyPatch(typeof(Character), "GetDamageModifiers")] + public static class SkadiEnvFrostModifierPatch + { + public static void Postfix(Character __instance, ref HitData.DamageModifiers __result) + { + if (SkadiEnvCheckScope.Active && __instance == Player.m_localPlayer) + { + __result.m_frost = HitData.DamageModifier.Normal; + } + } + } + + // Valheim's Player.UpdateEnvStatusEffects always tries RemoveStatusEffect(Cold, quiet:true) + // as the first step of applying Freezing. Since SkadiSEManPatch redirects Freezing into Cold, + // that removal would strip our converted Cold status every other frame (a permanent + // add/remove flicker that cancels the buff out). Blocking just this "quiet" removal for the + // FreezingToCold player forces Valheim to always fall through to AddStatusEffect(Freezing,...), + // which SkadiSEManPatch converts to a stable, non-resetting Cold re-application instead. + [HarmonyPatch(typeof(SEMan), "RemoveStatusEffect", new System.Type[] { typeof(int), typeof(bool) })] + public static class SkadiColdRemovalGuardPatch + { + public static bool Prefix(SEMan __instance, int nameHash, bool quiet, ref bool __result) + { + if (quiet && nameHash == "Cold".GetStableHashCode()) + { + Character character = Traverse.Create(__instance).Field("m_character").Value; + if (character == Player.m_localPlayer && SkadiRace.Instance != null && SkadiRace.Instance.IsSkadi()) + { + var rules = SkadiProgression.GetRules(BossProgressionManager.GetCurrentProgressionState()); + if (rules.FreezingToCold && !rules.ImmuneToFreezing) + { + __result = false; + return false; + } + } + } + return true; + } + } + [HarmonyPatch(typeof(Character), "ApplyDamage")] public static class SkadiDamagePatch { diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index ca23977..4d5d5bd 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -230,7 +230,7 @@ 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 (Kick) + // Middle Mouse Button to cast if (Input.GetMouseButtonDown(2)) { float cooldown = rules.ImprovedColdSpell ? 2.0f : 1.5f; @@ -246,10 +246,11 @@ namespace RacesOfValheim lastSpellTime = Time.time; var zanim = HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_zanim").Value; - if (zanim != null) + if (zanim != null) { - // Forcing secondary attack trigger, which is kick when unarmed - zanim.SetTrigger("secondary"); + // Raised-arms Galdr cast gesture instead of the unarmed kick, so the cast + // reads as a spell instead of a leg swing near the ground. + zanim.SetTrigger("galdr_cast"); } StartCoroutine(ColdSpellKickCoroutine(rules)); @@ -258,7 +259,7 @@ namespace RacesOfValheim private IEnumerator ColdSpellKickCoroutine(SkadiProgression.FormRules rules) { - // Wait for the kick animation to reach the extension point + // Wait for the cast animation to reach the release point yield return new WaitForSeconds(0.4f); if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) yield break; @@ -287,16 +288,16 @@ namespace RacesOfValheim { if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) break; - // Spawn from the foot (low position, forward) + // Spawn from chest height, forward Vector3 lookDir = Player.m_localPlayer.GetLookDir(); - + // Add a small spread for the improved blast if (rules.ImprovedColdSpell && i > 0) { lookDir = Quaternion.Euler(UnityEngine.Random.Range(-5f, 5f), UnityEngine.Random.Range(-5f, 5f), 0f) * lookDir; } - Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 0.4f + lookDir * 0.6f; + Vector3 spawnPos = Player.m_localPlayer.transform.position + Vector3.up * 1.4f + lookDir * 0.6f; GameObject projInstance = Instantiate(projPrefab, spawnPos, Quaternion.LookRotation(lookDir)); From cccabe16ef167af70c9d8225453e6dc7017befec Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 31 Jul 2026 16:25:06 +0200 Subject: [PATCH 3/5] Rework Skadi dragon flight, enforce form duration, surface timers in HUD Flight ran on the debug-fly noclip, so it ignored aim entirely and needed Space/Ctrl for height. It now uses Character's native flying-creature movement with the camera's full look direction fed in each frame: - Aim steers, including climb and dive; W powers forward, releasing it holds level briefly and then settles into a glide instead of coasting along the aim vector (which let you climb forever without input). - The body actually turns now. m_flyTurnSpeed sat at Character's 12 deg/s default because the Player prefab was never set up to fly, so a quarter turn took over seven seconds and read as no rotation at all. - Touching down no longer slides you forward forever. Zeroing the fly speeds stops the character without fighting the AddForce UpdateFlying queues, which had caused frame-to-frame jitter and TAA ghosting. DurationMinutes was never wired to anything, so timed forms never expired and their cooldown, which only starts on reversion, was unreachable in practice. Timed forms now drop on their own, and both the remaining time and the cooldown show up beside the minimap as a Moder trophy icon. Attack capability was snapshotted when the form was entered, so reaching the Bonemass tier while already transformed left the drake unarmed until the player reverted and transformed again; it is re-read live now. --- JotunnModStub/Skadi/DrakeFormBehavior.cs | 49 ++++++++++++--- JotunnModStub/Skadi/SkadiPatches.cs | 73 +++++++++++++++++++++++ JotunnModStub/Skadi/SkadiRace.cs | 69 ++++++++++++++++++--- JotunnModStub/Skadi/SkadiStatusEffects.cs | 6 ++ README.md | 19 +++--- 5 files changed, 194 insertions(+), 22 deletions(-) diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index 53a4122..75a6a6e 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -6,11 +6,21 @@ namespace RacesOfValheim { public class DrakeFormBehavior : MonoBehaviour { + // Single active instance, read by SkadiDirectedFlightPatch to feed a + // look-direction-based m_moveDir into Character.UpdateFlying every frame. + public static DrakeFormBehavior Active { get; private set; } + private Animator anim; private bool isFlying = false; private bool isLanding = false; private float lastAttackTime = 0f; - + + public bool IsFlying => isFlying; + + // Time.time of the last powered/grounded moment. SkadiDirectedFlightPatch holds the form + // level for a short window past this before letting it start sinking. + public float LastPoweredTime; + private SkadiProgression.FormRules formRules; public void Initialize(SkadiProgression.FormRules rules) @@ -18,15 +28,37 @@ namespace RacesOfValheim this.formRules = rules; } + // formRules is a snapshot taken when the form was entered, so a progression change while + // still transformed (defeating a boss, or the increaseprogression debug command) wouldn't + // grant the attack until the player reverted and transformed again. Re-read the rules for + // the form we're currently in so the unlock applies as soon as the tier is reached. + private bool CanAttackNow() + { + if (formRules == null) return false; + + int state = BossProgressionManager.GetCurrentProgressionState(); + SkadiProgression.FormRules live = null; + + switch (formRules.Form) + { + case SkadiProgression.FormType.Drake: live = SkadiProgression.GetGKeyRules(state); break; + case SkadiProgression.FormType.Moder: live = SkadiProgression.GetHKeyRules(state); break; + case SkadiProgression.FormType.SkeletonDragon: live = SkadiProgression.GetJKeyRules(state); break; + } + + return live != null && live.Form == formRules.Form && live.CanAttackInForm; + } + private const float ATTACK_COST = 20f; private const float ATTACK_COOLDOWN = 3f; private void Start() { + Active = this; anim = GetComponentInChildren(); if (Player.m_localPlayer != null) { - HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false); + HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false); } } @@ -40,20 +72,22 @@ namespace RacesOfValheim if (!isFlying && !isLanding) { isFlying = true; - HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true); + LastPoweredTime = Time.time; + HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true); } else if (isFlying && !isLanding) { isLanding = true; isFlying = false; - HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false); + HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false); } else if (isLanding) { // Cancel landing, resume flight isLanding = false; isFlying = true; - HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(true); + LastPoweredTime = Time.time; + HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(true); } } @@ -88,7 +122,7 @@ namespace RacesOfValheim } // Handle Attack - if (formRules != null && formRules.CanAttackInForm) + if (CanAttackNow()) { if (Input.GetMouseButtonDown(0)) { @@ -345,9 +379,10 @@ namespace RacesOfValheim private void OnDestroy() { + if (Active == this) Active = null; if (Player.m_localPlayer != null) { - HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_debugFly").SetValue(false); + HarmonyLib.Traverse.Create(Player.m_localPlayer).Field("m_flying").SetValue(false); } } } diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index e79121c..7675048 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -200,6 +200,79 @@ namespace RacesOfValheim + // DrakeFormBehavior flips the player into Character's native flying-creature movement + // (m_flying = true) instead of the old debug-fly noclip, which lets us feed it a full 3D + // move direction. Character.UpdateFlying normally reads whatever m_moveDir the vanilla input + // pipeline last wrote (ground-plane WASD relative to camera yaw only); this patch overwrites + // it every frame with the camera's actual look direction (pitch included) so the player always + // glides toward wherever the mouse is aiming, with W adding a speed boost (m_run) on top of the + // base glide speed instead of being required just to move. + [HarmonyPatch(typeof(Character), "UpdateFlying")] + public static class SkadiDirectedFlightPatch + { + private const float TURN_SPEED = 120f; + private const float GLIDE_SPEED = 5f; + private const float BOOST_SPEED = 12f; + private const float HOVER_SECONDS = 2f; + // Tangent of the unpowered descent angle: 0.4 sinks at roughly 22 degrees below level. + private const float DESCENT_SLOPE = 0.4f; + + public static void Prefix(Character __instance) + { + if (__instance != Player.m_localPlayer) return; + + DrakeFormBehavior form = DrakeFormBehavior.Active; + if (form == null || !form.IsFlying) return; + + var traverse = Traverse.Create(__instance); + Vector3 lookDir = Player.m_localPlayer.GetLookDir(); + bool boost = Input.GetKey(KeyCode.W); + bool onGround = __instance.IsOnGround(); + + traverse.Field("m_run").SetValue(boost); + traverse.Field("m_flyFastSpeed").SetValue(BOOST_SPEED); + + // UpdateFlying rotates the body toward m_moveDir on its own, but at m_flyTurnSpeed, + // which sits at Character's 12 deg/s default because the Player prefab was never set + // up as a flying creature - a 90 degree turn would take over seven seconds, so the + // model reads as not turning at all. Give it a speed that suits a flying mount. + traverse.Field("m_flyTurnSpeed").SetValue(TURN_SPEED); + + // Powered flight and ground contact both refresh the hover window. + if (boost || onGround) form.LastPoweredTime = Time.time; + + Vector3 moveDir = lookDir; + float coastSpeed; + + if (onGround || Time.time - form.LastPoweredTime < HOVER_SECONDS) + { + // Holding station: on the ground this keeps a touchdown from sliding the player + // forward forever, and in the air it gives the beat of level flight before the + // form starts to sink. m_moveDir stays full length so the body still turns to + // face the camera, and zeroing the speed (rather than the rigidbody velocity) + // avoids fighting the AddForce UpdateFlying queues, which caused visible jitter. + coastSpeed = 0f; + } + else + { + // Unpowered flight is a glide, not a hover with a joystick: drift along the + // heading the camera faces while losing height, so aiming at the sky without + // holding W no longer climbs. + Vector3 heading = new Vector3(lookDir.x, 0f, lookDir.z); + if (heading.sqrMagnitude < 0.0001f) + { + heading = __instance.transform.forward; + heading.y = 0f; + } + moveDir = (heading.normalized + Vector3.down * DESCENT_SLOPE).normalized; + coastSpeed = GLIDE_SPEED; + } + + traverse.Field("m_moveDir").SetValue(moveDir); + traverse.Field("m_flySlowSpeed").SetValue(coastSpeed); + } + } + [HarmonyPatch(typeof(Humanoid), "StartAttack")] public static class SkadiAttackPatch { diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 4d5d5bd..071dac5 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -11,6 +11,7 @@ namespace RacesOfValheim public static SkadiRace Instance; public static SE_SkadiStats skadiCurseSE; public static SE_FormCooldown skadiCdSE; + public static SE_SkadiForm skadiFormSE; private float auraTimer = 0f; private float lastSpellTime = 0f; @@ -18,6 +19,8 @@ namespace RacesOfValheim private bool isTransformed = false; private bool isTransformingSequence = false; private SkadiProgression.FormRules activeRules = null; + // Time.time at which a timed form drops; 0 means the current form has no time limit. + private float formExpireTime = 0f; private float lastAuraTime = 0f; private GameObject frostAuraVFX = null; @@ -47,18 +50,33 @@ namespace RacesOfValheim ItemManager.Instance.AddStatusEffect(skadiStats); skadiCurseSE = skadiStats.StatusEffect as SE_SkadiStats; + // Timed forms and their cooldown are Moder's, so they carry her trophy rather than the + // drake one used for the passive blessing. + Sprite dragonIcon = GetTrophyIcon("TrophyDragonQueen") ?? GetTrophyIcon("TrophyHatchling"); + skadiCdSE = ScriptableObject.CreateInstance(); skadiCdSE.name = "SE_SkadiCooldown"; skadiCdSE.m_name = "Dragon Form Cooldown"; - if (drakeTrophy != null) - { - ItemDrop trophyDrop = drakeTrophy.GetComponent(); - if (trophyDrop != null && trophyDrop.m_itemData.m_shared.m_icons.Length > 0) - { - skadiCdSE.m_icon = trophyDrop.m_itemData.m_shared.m_icons[0]; - } - } + skadiCdSE.m_icon = dragonIcon; ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiCdSE, fixReference: false)); + + skadiFormSE = ScriptableObject.CreateInstance(); + skadiFormSE.name = "SE_SkadiForm"; + skadiFormSE.m_name = "Dragon Form"; + skadiFormSE.m_tooltip = "Your dragon shape holds for a while longer."; + skadiFormSE.m_icon = dragonIcon; + ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(skadiFormSE, fixReference: false)); + } + + private static Sprite GetTrophyIcon(string prefabName) + { + GameObject trophy = PrefabManager.Cache.GetPrefab(prefabName)?.gameObject; + ItemDrop drop = trophy != null ? trophy.GetComponent() : null; + if (drop != null && drop.m_itemData.m_shared.m_icons.Length > 0) + { + return drop.m_itemData.m_shared.m_icons[0]; + } + return null; } @@ -139,6 +157,16 @@ namespace RacesOfValheim if (isTransformingSequence) return; + // Forms with a DurationMinutes budget drop on their own once it runs out, which is + // also what starts their cooldown - without this the timed tiers never expired. + if (isTransformed && formExpireTime > 0f && Time.time >= formExpireTime) + { + formExpireTime = 0f; + Player.m_localPlayer.Message(MessageHud.MessageType.Center, "Your dragon form fades."); + StartCoroutine(RevertToHumanRoutine()); + 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; } @@ -589,10 +617,33 @@ namespace RacesOfValheim else if (prefabName == "Fader") Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You are Fader!"); isTransformed = true; + StartFormTimer(rules); } } } + // Drives both the expiry check in Update and the HUD icon: the status effect exists purely + // so Valheim draws Moder's trophy with its own countdown next to the minimap. + private void StartFormTimer(SkadiProgression.FormRules rules) + { + int hash = "SE_SkadiForm".GetStableHashCode(); + SEMan seman = Player.m_localPlayer.GetSEMan(); + seman.RemoveStatusEffect(hash, true); + + if (rules.DurationMinutes <= 0f) + { + formExpireTime = 0f; + return; + } + + float seconds = rules.DurationMinutes * 60f; + formExpireTime = Time.time + seconds; + + seman.AddStatusEffect(hash, true); + StatusEffect se = seman.GetStatusEffect(hash); + if (se != null) se.m_ttl = seconds; + } + private void ExecuteReversion() { Transform playerVisual = Player.m_localPlayer.transform.Find("Visual"); @@ -615,6 +666,8 @@ namespace RacesOfValheim } isTransformed = false; + formExpireTime = 0f; + Player.m_localPlayer.GetSEMan().RemoveStatusEffect("SE_SkadiForm".GetStableHashCode(), true); Player.m_localPlayer.Message(MessageHud.MessageType.Center, "You returned to human form."); if (activeRules != null && activeRules.CooldownMinutes > 0) diff --git a/JotunnModStub/Skadi/SkadiStatusEffects.cs b/JotunnModStub/Skadi/SkadiStatusEffects.cs index 536e8de..b6517af 100644 --- a/JotunnModStub/Skadi/SkadiStatusEffects.cs +++ b/JotunnModStub/Skadi/SkadiStatusEffects.cs @@ -4,6 +4,12 @@ using UnityEngine; namespace RacesOfValheim { + // Timed dragon forms. m_ttl is set when the form is entered, which is all Valheim needs to + // render the countdown: StatusEffect.GetIconText() prints the remaining time by itself. + public class SE_SkadiForm : StatusEffect + { + } + public class SE_SkadiStats : SE_Stats { public override void Setup(Character character) diff --git a/README.md b/README.md index 3132ba0..813b42e 100644 --- a/README.md +++ b/README.md @@ -81,13 +81,18 @@ This mod currently introduces 6 custom races: ### Skadi Progression - **Base (No Bosses)**: Immune to Cold, Bonus Frost Damage, 50% Frost Resistance. -- **Eikthyr**: +20% Eitr Regen, Freezing to Cold, Cold Spell. -- **The Elder**: Drake Form (Cannot attack). -- **Bonemass**: Drake Form (Can attack). -- **Moder**: Moder Form (1 min duration, 10 min cooldown). -- **Yagluth**: Improved Cold Spell. Moder Form (1 min duration, 5 min cooldown). -- **The Queen**: Moder Form (Unlimited duration, no cooldown). -- **Fader**: Skeleton Dragon Form. +- **Eikthyr**: +20% Eitr Regen, Freezing to Cold, Cold Spell (Middle Mouse). +- **The Elder**: Drake Form ('G' Key) (Cannot attack). +- **Bonemass**: Drake Form ('G' Key) (Can attack). +- **Moder**: Moder Form ('H' Key) (1 min duration, 10 min cooldown). +- **Yagluth**: Improved Cold Spell. Moder Form ('H' Key) (1 min duration, 5 min cooldown). +- **The Queen**: Moder Form ('H' Key) (Unlimited duration, no cooldown). +- **Fader**: Skeleton Dragon Form ('J' Key). + +While transformed, Right Mouse toggles flight. You glide toward wherever you are aiming; hold W +to power forward and climb. Let go and the form holds level for a couple of seconds before +settling into a gentle descent. Timed forms show their remaining seconds, and their cooldown, +as a Moder trophy icon beside the minimap. ### Skeleton Progression - **Base (No Bosses)**: +50 Max Health. Undead Diet (Cannot eat mortal food, no stamina bar). From 16275d6abc03e107b72b7b7b2f322de8e384942e Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 1 Aug 2026 13:24:44 +0200 Subject: [PATCH 4/5] Stop remote clients spawning a dragon model every frame The multiplayer visual sync named each spawned model "
_multiplayer" but searched for an existing one called "SkadiBody_Form", a name nothing is ever assigned. The lookup therefore missed every time, and since VisEquipment.UpdateVisuals runs each frame off CustomUpdate, observers instantiated a fresh dragon roughly sixty times a second for as long as the Skadi player stayed transformed. The transformed player saw nothing wrong, because owners return early, and the pile only got cleaned up in the reverted-to-human branch, so the lag never let up on its own. Look the model up by the name actually assigned. The scan also destroys any surplus "_multiplayer" children it walks past, so clients that have already accumulated a pile clear it on the first frame after updating instead of needing to rejoin. --- JotunnModStub/Skadi/SkadiPatches.cs | 82 ++++++++++++++++------------- 1 file changed, 44 insertions(+), 38 deletions(-) diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index 7675048..fc1976f 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -28,52 +28,58 @@ namespace RacesOfValheim [HarmonyPatch(typeof(VisEquipment), "UpdateVisuals")] public static class Skadi_MultiplayerVisuals_Patch { + private const string FormSuffix = "_multiplayer"; + public static void Postfix(VisEquipment __instance) { if (!__instance.m_isPlayer) return; Player player = __instance.GetComponent(); if (player == null || player.IsOwner()) return; // Only process remote players - - ZNetView nview = player.GetComponent(); - if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Skadi") - { - string formName = nview.GetZDO().GetString("RacesOfValheim_SkadiForm", ""); - - Transform playerVisual = player.transform.Find("Visual"); - Transform formBody = player.transform.Find("SkadiBody_Form"); - - if (!string.IsNullOrEmpty(formName)) { - if (formBody != null && formBody.gameObject.name != formName + "_multiplayer") { - UnityEngine.Object.Destroy(formBody.gameObject); - formBody = null; - } - if (formBody == null) { - GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(formName); - if (prefab != null) { - Transform visual = prefab.transform.Find("Visual"); - if (visual != null) { - GameObject formInstance = UnityEngine.Object.Instantiate(visual.gameObject, player.transform); - formInstance.name = formName + "_multiplayer"; - if (formName == "Hatchling") formInstance.transform.localPosition = new Vector3(0f, -1.0f, 0f); - else formInstance.transform.localPosition = Vector3.zero; - formInstance.transform.localRotation = Quaternion.identity; - } - } - } - if (playerVisual != null) playerVisual.gameObject.SetActive(false); - } else { - if (formBody != null) UnityEngine.Object.Destroy(formBody.gameObject); - - // Fader form has a different name? "SkadiBody_Form" was used earlier, we just find all children and destroy them if they have "_multiplayer" - foreach (Transform child in player.transform) { - if (child.name.EndsWith("_multiplayer")) { - UnityEngine.Object.Destroy(child.gameObject); - } - } - if (playerVisual != null) playerVisual.gameObject.SetActive(true); + ZNetView nview = player.GetComponent(); + if (nview == null || !nview.IsValid()) return; + if (nview.GetZDO().GetString("RacesOfValheim_Race", "Human") != "Skadi") return; + + string formName = nview.GetZDO().GetString("RacesOfValheim_SkadiForm", ""); + Transform playerVisual = player.transform.Find("Visual"); + string wanted = formName + FormSuffix; + + // VisEquipment.UpdateVisuals runs every frame off CustomUpdate, so the spawned model + // has to be found again by the exact name it was given. This used to search for + // "SkadiBody_Form" - a name nothing is ever assigned - so the lookup missed every + // time and a fresh dragon was instantiated each frame. Remote players watched the + // models pile up on the spot and their client degraded until the Skadi player + // reverted; the transformed player saw nothing, since owners return above. + // Anything left over from that, or from a previous form, is cleaned up here too. + Transform formBody = null; + foreach (Transform child in player.transform) + { + if (!child.name.EndsWith(FormSuffix)) continue; + + if (formBody == null && child.name == wanted) formBody = child; + else UnityEngine.Object.Destroy(child.gameObject); + } + + if (string.IsNullOrEmpty(formName)) + { + if (playerVisual != null) playerVisual.gameObject.SetActive(true); + return; + } + + if (formBody == null) + { + GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab(formName); + Transform visual = prefab != null ? prefab.transform.Find("Visual") : null; + if (visual != null) + { + GameObject formInstance = UnityEngine.Object.Instantiate(visual.gameObject, player.transform); + formInstance.name = wanted; + formInstance.transform.localPosition = formName == "Hatchling" ? new Vector3(0f, -1.0f, 0f) : Vector3.zero; + formInstance.transform.localRotation = Quaternion.identity; } } + + if (playerVisual != null) playerVisual.gameObject.SetActive(false); } } From bca47beda6524422c096fe6bd90264e9fd94fbfe Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 1 Aug 2026 13:25:02 +0200 Subject: [PATCH 5/5] Ignore race ability input while a GUI has focus UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons kept firing with the map, the inventory, a chest, the chat or a menu open - clicking an item in a container also swung the transformed attack. Route that input through Player.TakeInput, which is what Valheim runs its own controls through and already reports false for those states (InventoryGui covers the backpack and chests alike). Aswid's transform keys were the only place already doing this; the shared helper replaces that one-off and covers Skadi's cold spell, form keys, flight toggle, form attacks and flight boost, Fenrir's form keys and the attacks of all four form behaviors, Trol's rock throw and true form, and Aswid's devour toggle. Cultist fire is a held button, so it is gated per read rather than around the block: opening a GUI mid-stream now falls through to StopFire() instead of leaving the flames running. --- JotunnModStub/Aswid/AswidPatches.cs | 2 +- JotunnModStub/Aswid/AswidRace.cs | 3 +- JotunnModStub/Fenrir/FenrirBehaviors.cs | 18 +++++++----- JotunnModStub/Fenrir/FenrirRace.cs | 2 ++ JotunnModStub/RaceInput.cs | 36 ++++++++++++++++++++++++ JotunnModStub/Skadi/DrakeFormBehavior.cs | 4 +-- JotunnModStub/Skadi/SkadiPatches.cs | 2 +- JotunnModStub/Skadi/SkadiRace.cs | 5 +++- JotunnModStub/Trol/TrolRace.cs | 15 ++++++---- 9 files changed, 67 insertions(+), 20 deletions(-) create mode 100644 JotunnModStub/RaceInput.cs diff --git a/JotunnModStub/Aswid/AswidPatches.cs b/JotunnModStub/Aswid/AswidPatches.cs index 19e26df..bc8becb 100644 --- a/JotunnModStub/Aswid/AswidPatches.cs +++ b/JotunnModStub/Aswid/AswidPatches.cs @@ -506,7 +506,7 @@ namespace RacesOfValheim ZNetView nview = __instance.GetComponent(); if (nview != null && nview.IsValid() && nview.GetZDO().GetString("RacesOfValheim_Race", "Human") == "Aswid") { - if (__instance == Player.m_localPlayer && Input.GetKeyDown(KeyCode.I)) + if (__instance == Player.m_localPlayer && RaceInput.Allowed && Input.GetKeyDown(KeyCode.I)) { 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 124b63e..62fc547 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -515,8 +515,7 @@ namespace RacesOfValheim int state = BossProgressionManager.GetCurrentProgressionState(); - bool takeInput = HarmonyLib.Traverse.Create(Player.m_localPlayer).Method("TakeInput").GetValue(); - if (takeInput) + if (RaceInput.Allowed) { if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(AswidProgression.GetGKeyRules(state)); return; } if (Input.GetKeyDown(KeyCode.H)) { TryToggleMistForm(); return; } diff --git a/JotunnModStub/Fenrir/FenrirBehaviors.cs b/JotunnModStub/Fenrir/FenrirBehaviors.cs index 7954de1..e2628aa 100644 --- a/JotunnModStub/Fenrir/FenrirBehaviors.cs +++ b/JotunnModStub/Fenrir/FenrirBehaviors.cs @@ -56,7 +56,7 @@ namespace RacesOfValheim fenrirAnim.SetFloat("sideway_speed", playerAnim.GetFloat("sideway_speed")); } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetKeyDown(KeyCode.O)) { @@ -311,8 +311,12 @@ namespace RacesOfValheim if (isGrounded) { + // Gated per-read rather than around the block, so opening a GUI mid-stream + // still falls through to StopFire() instead of leaving the flames running. + bool canAct = RaceInput.Allowed; + // Fire attack on Right Click - if (Input.GetMouseButton(1)) + if (canAct && Input.GetMouseButton(1)) { if (Player.m_localPlayer.GetEitr() > 0) { @@ -335,18 +339,18 @@ namespace RacesOfValheim StopFire(); } - if (Input.GetKeyDown(KeyCode.O)) + if (canAct && Input.GetKeyDown(KeyCode.O)) { StartCoroutine(HowlRoutine()); } // Attacks on Left Click - if (Input.GetMouseButtonDown(0) && !isShootingFire) + if (canAct && Input.GetMouseButtonDown(0) && !isShootingFire) { StartCoroutine(ClawRoutine()); // Single claw } // Double claw on Middle Click - else if (Input.GetMouseButtonDown(2) && !isShootingFire) + else if (canAct && Input.GetMouseButtonDown(2) && !isShootingFire) { StartCoroutine(DoubleClawRoutine()); } @@ -671,7 +675,7 @@ namespace RacesOfValheim } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetMouseButtonDown(0)) // Left Click { @@ -844,7 +848,7 @@ namespace RacesOfValheim } } - if (isGrounded) + if (isGrounded && RaceInput.Allowed) { if (Input.GetMouseButtonDown(0)) // Left Click { diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index 3768190..5adc796 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -143,6 +143,8 @@ namespace RacesOfValheim { } } + if (!RaceInput.Allowed) return; + int state = BossProgressionManager.GetCurrentProgressionState(); if (Input.GetKeyDown(KeyCode.G)) { TryTransformWithRules(FenrirProgression.GetGKeyRules(state)); return; } diff --git a/JotunnModStub/RaceInput.cs b/JotunnModStub/RaceInput.cs new file mode 100644 index 0000000..4c92a55 --- /dev/null +++ b/JotunnModStub/RaceInput.cs @@ -0,0 +1,36 @@ +using System.Reflection; +using HarmonyLib; + +namespace RacesOfValheim +{ + /// + /// Gate for race ability input. + /// + /// UnityEngine.Input reads the device directly, so abilities bound to keys or mouse buttons + /// kept firing while the map, the inventory, a chest, the chat or a menu had focus - dragging + /// an item inside a container also swung the transformed attack, for instance. Valheim runs + /// its own controls through Player.TakeInput, which reports false for exactly those states + /// (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. + /// + public static class RaceInput + { + // Not public on Player, hence the reflection; resolved once rather than per frame. + private static readonly MethodInfo TakeInputMethod = AccessTools.Method(typeof(Player), "TakeInput"); + + public static bool Allowed + { + get + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + // Fail open: if a game update ever renames the method, abilities stay usable + // rather than silently going dead. + if (TakeInputMethod == null) return true; + + return (bool)TakeInputMethod.Invoke(player, null); + } + } + } +} diff --git a/JotunnModStub/Skadi/DrakeFormBehavior.cs b/JotunnModStub/Skadi/DrakeFormBehavior.cs index 75a6a6e..62941b0 100644 --- a/JotunnModStub/Skadi/DrakeFormBehavior.cs +++ b/JotunnModStub/Skadi/DrakeFormBehavior.cs @@ -67,7 +67,7 @@ namespace RacesOfValheim if (Player.m_localPlayer == null || Player.m_localPlayer.IsDead()) return; // Handle Flight Toggle (RMB) - Disabled for Fader - if (Input.GetMouseButtonDown(1) && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) + if (RaceInput.Allowed && Input.GetMouseButtonDown(1) && formRules != null && formRules.Form != SkadiProgression.FormType.SkeletonDragon) { if (!isFlying && !isLanding) { @@ -122,7 +122,7 @@ namespace RacesOfValheim } // Handle Attack - if (CanAttackNow()) + if (CanAttackNow() && RaceInput.Allowed) { if (Input.GetMouseButtonDown(0)) { diff --git a/JotunnModStub/Skadi/SkadiPatches.cs b/JotunnModStub/Skadi/SkadiPatches.cs index fc1976f..e38a81e 100644 --- a/JotunnModStub/Skadi/SkadiPatches.cs +++ b/JotunnModStub/Skadi/SkadiPatches.cs @@ -232,7 +232,7 @@ namespace RacesOfValheim var traverse = Traverse.Create(__instance); Vector3 lookDir = Player.m_localPlayer.GetLookDir(); - bool boost = Input.GetKey(KeyCode.W); + bool boost = RaceInput.Allowed && Input.GetKey(KeyCode.W); bool onGround = __instance.IsOnGround(); traverse.Field("m_run").SetValue(boost); diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 071dac5..1b45633 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -150,7 +150,7 @@ namespace RacesOfValheim } } - if (rules.ColdSpell) + if (rules.ColdSpell && RaceInput.Allowed) { HandleColdSpell(rules); } @@ -167,6 +167,9 @@ namespace RacesOfValheim return; } + // Form keys and the debug dump are ability input: they stay inert while a GUI has focus. + 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; } diff --git a/JotunnModStub/Trol/TrolRace.cs b/JotunnModStub/Trol/TrolRace.cs index ee82086..5b7eb15 100644 --- a/JotunnModStub/Trol/TrolRace.cs +++ b/JotunnModStub/Trol/TrolRace.cs @@ -119,14 +119,17 @@ namespace RacesOfValheim { if (!IsTrol()) return; - if (Input.GetKeyDown(KeyCode.G)) + if (RaceInput.Allowed) { - TryThrowRock(); - } + if (Input.GetKeyDown(KeyCode.G)) + { + TryThrowRock(); + } - if (Input.GetKeyDown(KeyCode.H)) - { - TryTrueForm(); + if (Input.GetKeyDown(KeyCode.H)) + { + TryTrueForm(); + } } // Check log durability