From bb1ca579247ab86cd1f8a7287518777bf0c40b0a Mon Sep 17 00:00:00 2001 From: kanym Date: Tue, 13 Oct 2026 20:00:03 +0200 Subject: [PATCH 1/3] chore(release): v1.5.10 - Skeleton body switch for player model mods New client-side option Skeleton - Visuals -> Body Model Enabled. Off, a Skeleton takes the human branch of the VisEquipment postfix: vanilla body on, no bone meshes, eye glow, jaw correction or skull flame, and the helmet is left alone. Requested by players using EnhancedValheimVRM, where the bones floated around the replacement model. README: New in block for v1.5.10, changelog entry (also the Russian fixes since 1.5.9), and a line under the Skeleton features. --- JotunnModStub/Package/manifest.json | 2 +- JotunnModStub/RacesOfValheim.cs | 2 +- JotunnModStub/Skeleton/SkeletonConfig.cs | 3 +++ JotunnModStub/Skeleton/SkeletonJawFix.cs | 5 +++-- JotunnModStub/Skeleton/SkeletonPatches.cs | 4 +++- JotunnModStub/Skeleton/SkeletonRace.cs | 12 ++++++++---- JotunnModStub/Skeleton/SkeletonVisuals.cs | 10 ++++++++++ JotunnModStub/ZdoVisualSync.cs | 9 ++++++--- README.md | 9 +++++++-- manifest.json | 2 +- 10 files changed, 43 insertions(+), 15 deletions(-) diff --git a/JotunnModStub/Package/manifest.json b/JotunnModStub/Package/manifest.json index 8b25e6f..47424f1 100644 --- a/JotunnModStub/Package/manifest.json +++ b/JotunnModStub/Package/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.", - "version_number": "1.5.9", + "version_number": "1.5.10", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333", diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index fe1cebb..6e826c6 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -15,7 +15,7 @@ namespace RacesOfValheim { public const string PluginGUID = "com.nandor.racesofvalheim"; public const string PluginName = "Races Of Valheim"; - public const string PluginVersion = "1.5.9"; + public const string PluginVersion = "1.5.10"; private readonly Harmony harmony = new Harmony(PluginGUID); diff --git a/JotunnModStub/Skeleton/SkeletonConfig.cs b/JotunnModStub/Skeleton/SkeletonConfig.cs index a31f1a9..c6b8ba6 100644 --- a/JotunnModStub/Skeleton/SkeletonConfig.cs +++ b/JotunnModStub/Skeleton/SkeletonConfig.cs @@ -41,6 +41,7 @@ namespace RacesOfValheim // ─── Visuals ─────────────────────────────────────────────────────────── public static ConfigEntry HeadFireVFXEnabled; + public static ConfigEntry BodyModelEnabled; public static void Bind(ConfigFile config) { @@ -71,6 +72,8 @@ namespace RacesOfValheim const string visuals = "Skeleton - Visuals"; HeadFireVFXEnabled = config.Bind(visuals, "Head Fire VFX Enabled", true, new ConfigDescription("Whether the burning-skull effect (worn from tier 5+) renders at all. A client-side preference: disabling it stops you from seeing it on yourself and on every other skeleton you look at, but does not change what other players see.")); + BodyModelEnabled = config.Bind(visuals, "Body Model Enabled", true, + new ConfigDescription("Whether Skeleton players wear the skeleton body. Turn it off if you use a player model mod (EnhancedValheimVRM and the like): Skeletons then keep the vanilla viking body, so the replacement model shows without bones clipping through it. Abilities are unchanged. Client-side, like the option above: it applies to every Skeleton you see, yourself included, and changes nothing for other players.")); } } } diff --git a/JotunnModStub/Skeleton/SkeletonJawFix.cs b/JotunnModStub/Skeleton/SkeletonJawFix.cs index 8f9860d..d96c8c5 100644 --- a/JotunnModStub/Skeleton/SkeletonJawFix.cs +++ b/JotunnModStub/Skeleton/SkeletonJawFix.cs @@ -62,10 +62,11 @@ namespace RacesOfValheim Transform jaw = ResolveJaw(); if (jaw == null || jaw.parent == null) return; - if (!SkeletonVisuals.IsSkeletonPlayer(m_player)) + if (!SkeletonVisuals.ShowsSkeletonBody(m_player)) { // Nothing rewrites this bone on its own, so a player who stops being a Skeleton - // would otherwise keep wearing the correction on their human face. + // (or switches the skeleton body off) would otherwise keep wearing the correction + // on their human face. if (m_applied) { jaw.localPosition = m_baseLocalPosition; diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 0937e37..461fa75 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -254,7 +254,9 @@ namespace RacesOfValheim // before it could find out it was looking at a Skeleton. string race = SkeletonVisuals.GetPlayerRace(p); - if (race == SkeletonVisuals.RaceId) + // With "Body Model Enabled" off a Skeleton takes the human branch below, the same + // as any other race, so the toggle also works live: the next refresh swaps back. + if (race == SkeletonVisuals.RaceId && SkeletonConfig.BodyModelEnabled.Value) { if (__instance.m_bodyModel != null) { diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index 78aebe6..1895ed5 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -323,9 +323,13 @@ namespace RacesOfValheim VisEquipment currentVis = Player.m_localPlayer.GetComponent(); if (currentVis != null) { - // Hide Helmets (Valheim uses singular GameObject for helmet) - var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field("m_helmetItemInstance").Value; - SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true); + // Hide Helmets (Valheim uses singular GameObject for helmet). Only over a skull: + // a viking body wears its helmet, and the VisEquipment postfix puts it back. + if (SkeletonConfig.BodyModelEnabled.Value) + { + var helmetObj = HarmonyLib.Traverse.Create(currentVis).Field("m_helmetItemInstance").Value; + SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true); + } // Scale Body Armor (Chest, Legs, Shoulder) by 5% string[] armorFields = { "m_chestItemInstances", "m_legItemInstances", "m_shoulderItemInstances" }; @@ -440,7 +444,7 @@ namespace RacesOfValheim } // Flames on the skull, worn with the fire-tier model and nothing else. - headFlame.Apply(Player.m_localPlayer, SkeletonConfig.HeadFireVFXEnabled.Value && SkeletonVisuals.GetModel(Player.m_localPlayer, state) == SkeletonProgression.FireModel); + headFlame.Apply(Player.m_localPlayer, SkeletonConfig.HeadFireVFXEnabled.Value && SkeletonConfig.BodyModelEnabled.Value && SkeletonVisuals.GetModel(Player.m_localPlayer, state) == SkeletonProgression.FireModel); if (rules.FireAura) { diff --git a/JotunnModStub/Skeleton/SkeletonVisuals.cs b/JotunnModStub/Skeleton/SkeletonVisuals.cs index 18ada8b..e91963c 100644 --- a/JotunnModStub/Skeleton/SkeletonVisuals.cs +++ b/JotunnModStub/Skeleton/SkeletonVisuals.cs @@ -49,6 +49,16 @@ namespace RacesOfValheim public static bool IsSkeletonPlayer(Player player) => GetPlayerRace(player) == RaceId; + /// + /// Whether this client draws the skeleton's bones on this player. False for every + /// non-Skeleton, and for every Skeleton when "Body Model Enabled" is off: model-replacement + /// mods (EnhancedValheimVRM and the like) hide the vanilla body and draw their own, so the + /// borrowed bones ended up floating around the replacement model. With the option off the + /// Skeleton keeps every ability and only looks like a plain viking. + /// + public static bool ShowsSkeletonBody(Player player) => + SkeletonConfig.BodyModelEnabled.Value && IsSkeletonPlayer(player); + /// /// Fully hides (or restores) one equipped item instance - a helmet, typically. /// diff --git a/JotunnModStub/ZdoVisualSync.cs b/JotunnModStub/ZdoVisualSync.cs index 0df6988..4f1326f 100644 --- a/JotunnModStub/ZdoVisualSync.cs +++ b/JotunnModStub/ZdoVisualSync.cs @@ -128,8 +128,11 @@ namespace RacesOfValheim vis.SetBeardItem(0); // Hide Helmet - var helmetObj = HarmonyLib.Traverse.Create(vis).Field("m_helmetItemInstance").Value; - SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true); + if (SkeletonConfig.BodyModelEnabled.Value) + { + var helmetObj = HarmonyLib.Traverse.Create(vis).Field("m_helmetItemInstance").Value; + SkeletonVisuals.SetEquipmentPieceHidden(helmetObj, true); + } // Scale Body Armor string[] armorFields = { "m_chestItemInstances", "m_legItemInstances", "m_shoulderItemInstances" }; @@ -165,7 +168,7 @@ namespace RacesOfValheim // The burning skull, grown locally for whoever we are looking at. The tier is on the // ZDO, so this client can work out for itself whether they should be alight. - m_skeletonHeadFlame.Apply(m_player, SkeletonConfig.HeadFireVFXEnabled.Value && SkeletonVisuals.GetModel(m_player, state) == SkeletonProgression.FireModel); + m_skeletonHeadFlame.Apply(m_player, SkeletonConfig.HeadFireVFXEnabled.Value && SkeletonConfig.BodyModelEnabled.Value && SkeletonVisuals.GetModel(m_player, state) == SkeletonProgression.FireModel); // Apply Scale Vector3 targetScale = rules.ScaleMultiplier; diff --git a/README.md b/README.md index 39865d8..741c132 100644 --- a/README.md +++ b/README.md @@ -15,9 +15,9 @@ Support the mod: [Patreon — NandorTheModder](https://www.patreon.com/c/NandorT --- -## New in v1.5.9 +## New in v1.5.10 -Skeletons can laugh: type /evillaugh. The Furling's fire bonus now covers crossbow bolts, and a crossbow in hand no longer fires on every attack while you are transformed. Full details in the [changelog](#v159). +Using a player model mod such as EnhancedValheimVRM? Turn off `Skeleton - Visuals` → `Body Model Enabled` and Skeletons keep the vanilla body, so no bones clip through your model. Full details in the [changelog](#v1510). --- @@ -30,6 +30,7 @@ Skeletons can laugh: type /evillaugh. The Furling's fire bonus now covers crossb - **Stamina-less Combat:** Skeletons use no stamina and do not have a stamina bar. - **Undead Diet:** Cannot eat normal food. Max health increases automatically as you defeat bosses to make up for lack of food buffs. - **Lit Sockets:** Your skull carries the eye lights of the creature your tier is built from, in that creature's own colour — so they change as the body does. +- **Body Model switch:** with a player model mod (EnhancedValheimVRM and the like), set `Skeleton - Visuals` → `Body Model Enabled` to off and Skeletons keep the vanilla body. Abilities stay the same. ### 2. Skadi ![Skadi1](https://wiki.aledanidev.ovh/assets/images/skadi1.gif) @@ -447,6 +448,10 @@ Both halves have an off switch under `Factions` in Configuration Manager: **Fact ## Changelog +### v1.5.10 +- **New - Skeleton body switch for player model mods:** with EnhancedValheimVRM or another model replacer, the skeleton's bones stayed on screen and floated around the new model. Set `Skeleton - Visuals` → `Body Model Enabled` to off and Skeletons keep the vanilla body: no bones, eye lights or skull flames, and the helmet shows. Abilities don't change. The setting is client-side, so it applies to every Skeleton you see and changes nothing for other players. The race strips hair and beard, so the vanilla body is bald, and the auto-resurrection still shows the skeleton for the few seconds it climbs out of the ground. Thanks to the players who reported it and tested the fix. +- **Fix - Russian translation:** corrections to several Russian texts, by Axibed. + ### v1.5.9 - **New - /evillaugh (Skeleton):** the Skeleton throws its head back, clacks its jaw, shakes its shoulders and punches both fists into the air for four seconds. Everyone nearby sees it. - **Change - Furling fire bolts:** the Wickerman's fire damage now also applies to crossbow bolts, not only to arrows. diff --git a/manifest.json b/manifest.json index 8b25e6f..47424f1 100644 --- a/manifest.json +++ b/manifest.json @@ -1,7 +1,7 @@ { "name": "RacesOfValheim", "description": "A Valheim mod that adds ten custom playable races (Aswid, Draugh, Dvergar, Fenrir, Furling, Skadi, Skeleton, Sverm, Trenta, Trol) each with unique abilities, traits, race stations and a deep boss-driven progression system.", - "version_number": "1.5.9", + "version_number": "1.5.10", "website_url": "", "dependencies": [ "denikson-BepInExPack_Valheim-5.4.2333", From 65b488b5dc841592dc75bbecd8a4dea62587d80f Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 14 Oct 2026 14:12:50 +0200 Subject: [PATCH 2/3] feat(trol): skin and hair colour pickers in Trol - Appearance Two Color entries, Skin Color and Hair Color (hair and beard), defaulting to the old peacock blue and golden blonde so no Trol changes on update. Each Trol publishes its choice on its own ZDO and every client paints that player with it; a Trol on an older build publishes nothing and shows the defaults. The menu preview, with no ZDO, reads the local config. The section is kept local by ConfigSync. README: New in block, Trol features line and a 1.5.10 changelog entry. --- JotunnModStub/ConfigSync.cs | 1 + JotunnModStub/Trol/TrolConfig.cs | 15 +++++++++++ JotunnModStub/Trol/TrolPatches.cs | 45 +++++++++++++++++++++++++------ README.md | 4 ++- 4 files changed, 56 insertions(+), 9 deletions(-) diff --git a/JotunnModStub/ConfigSync.cs b/JotunnModStub/ConfigSync.cs index fb38b9c..996168a 100644 --- a/JotunnModStub/ConfigSync.cs +++ b/JotunnModStub/ConfigSync.cs @@ -31,6 +31,7 @@ namespace RacesOfValheim "Skeleton - Visuals", "Sverm - Dorsal Spines", "Sverm - Emberform", + "Trol - Appearance", "War Vulture - Model", "War Vulture - Interface", }; diff --git a/JotunnModStub/Trol/TrolConfig.cs b/JotunnModStub/Trol/TrolConfig.cs index ffca8af..2a152ae 100644 --- a/JotunnModStub/Trol/TrolConfig.cs +++ b/JotunnModStub/Trol/TrolConfig.cs @@ -59,8 +59,23 @@ namespace RacesOfValheim // ─── Farming ─────────────────────────────────────────────────────────── public static ConfigEntry UnarmedFarmingDamageBonusPerState; + // ─── Appearance ──────────────────────────────────────────────────────── + public static ConfigEntry SkinColor; + public static ConfigEntry HairColor; + + // The colours every Trol wore before these became settings. Also what a Trol on an older + // build of the mod shows as, since that build publishes no colour of its own. + public static readonly Color DefaultSkinColor = new Color(0.1f, 0.6f, 0.7f, 1f); + public static readonly Color DefaultHairColor = new Color(0.9f, 0.8f, 0.4f, 1f); + public static void Bind(ConfigFile config) { + const string appearance = "Trol - Appearance"; + SkinColor = config.Bind(appearance, "Skin Color", DefaultSkinColor, + new ConfigDescription("Your Trol's skin. Other players see it too. The game multiplies it with the skin texture, so it comes out a little darker than the swatch. For the look of Valheim's own trolls try 7FA8C9.")); + HairColor = config.Bind(appearance, "Hair Color", DefaultHairColor, + new ConfigDescription("Your Trol's hair and beard. Other players see it too.")); + const string keybinds = "Trol - Keybinds"; ThrowRockKey = config.Bind(keybinds, "Throw Rock", new KeyboardShortcut(KeyCode.G), new ConfigDescription("Throws a rock (or the log you're holding), tier 3+.")); diff --git a/JotunnModStub/Trol/TrolPatches.cs b/JotunnModStub/Trol/TrolPatches.cs index 68007df..0d9f5c2 100644 --- a/JotunnModStub/Trol/TrolPatches.cs +++ b/JotunnModStub/Trol/TrolPatches.cs @@ -6,8 +6,23 @@ namespace RacesOfValheim [HarmonyPatch(typeof(VisEquipment), "UpdateColors")] public static class TrolSkinColorPatch { - // Golden blonde hair - private static readonly Color HairColor = new Color(0.9f, 0.8f, 0.4f, 1f); + // Each Trol picks their own colours in Trol - Appearance and publishes them here (see + // Trol_PlayerUpdate_Patch), so everyone sees the colours that player chose. Stored without + // alpha: _SkinColor ignores it. + public const string SkinColorKey = "RacesOfValheim_TrolSkinColor"; + public const string HairColorKey = "RacesOfValheim_TrolHairColor"; + + private static Vector3 ToVec3(Color c) => new Vector3(c.r, c.g, c.b); + private static Color ToColor(Vector3 v) => new Color(v.x, v.y, v.z, 1f); + + /// Puts the local player's chosen colours on their ZDO. Only the owner writes. + public static void Publish(ZDO zdo) + { + Vector3 skin = ToVec3(TrolConfig.SkinColor.Value); + Vector3 hair = ToVec3(TrolConfig.HairColor.Value); + if (zdo.GetVec3(SkinColorKey, Vector3.negativeInfinity) != skin) zdo.Set(SkinColorKey, skin); + if (zdo.GetVec3(HairColorKey, Vector3.negativeInfinity) != hair) zdo.Set(HairColorKey, hair); + } public static void Postfix(VisEquipment __instance) { @@ -28,25 +43,38 @@ namespace RacesOfValheim if (race != "Trol") return; - // Apply skin, hair, beard colors here... + // The colours this Trol published. A Trol on an older build publishes none and keeps the + // defaults; with no ZDO at all (the main-menu preview) it is the local player's own + // character, so the local settings are the right answer. + Color skinColor, hairColor; + if (nview != null && nview.IsValid()) + { + ZDO zdo = nview.GetZDO(); + skinColor = ToColor(zdo.GetVec3(SkinColorKey, ToVec3(TrolConfig.DefaultSkinColor))); + hairColor = ToColor(zdo.GetVec3(HairColorKey, ToVec3(TrolConfig.DefaultHairColor))); + } + else + { + skinColor = TrolConfig.SkinColor.Value; + hairColor = TrolConfig.HairColor.Value; + } + if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null) { - // Peacock blue (deep greenish-blue) - Color trolColor = new Color(0.1f, 0.6f, 0.7f, 1f); - __instance.m_bodyModel.material.SetColor("_SkinColor", trolColor); + __instance.m_bodyModel.material.SetColor("_SkinColor", skinColor); } // Hair var hairInst = Traverse.Create(__instance).Field("m_hairItemInstance").GetValue(); if (hairInst != null) foreach (var r in hairInst.GetComponentsInChildren()) - if (r.material != null) r.material.SetColor("_SkinColor", HairColor); + if (r.material != null) r.material.SetColor("_SkinColor", hairColor); // Beard var beardInst = Traverse.Create(__instance).Field("m_beardItemInstance").GetValue(); if (beardInst != null) foreach (var r in beardInst.GetComponentsInChildren()) - if (r.material != null) r.material.SetColor("_SkinColor", HairColor); + if (r.material != null) r.material.SetColor("_SkinColor", hairColor); } } @@ -128,6 +156,7 @@ namespace RacesOfValheim { nview.GetZDO().Set(StateKey, state); nview.GetZDO().Set(TrueFormKey, isTrueFormActive); + if (race == "Trol") TrolSkinColorPatch.Publish(nview.GetZDO()); } } else diff --git a/README.md b/README.md index 741c132..68d1e8d 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Support the mod: [Patreon — NandorTheModder](https://www.patreon.com/c/NandorT ## New in v1.5.10 -Using a player model mod such as EnhancedValheimVRM? Turn off `Skeleton - Visuals` → `Body Model Enabled` and Skeletons keep the vanilla body, so no bones clip through your model. Full details in the [changelog](#v1510). +Using a player model mod such as EnhancedValheimVRM? Turn off `Skeleton - Visuals` → `Body Model Enabled` and Skeletons keep the vanilla body, so no bones clip through your model. Trols can pick their own skin and hair colour under `Trol - Appearance`. Full details in the [changelog](#v1510). --- @@ -72,6 +72,7 @@ Using a player model mod such as EnhancedValheimVRM? Turn off `Skeleton - Visual - **Immense Strength:** Increased carry weight; armor scales up as you defeat bosses. - **Rock Throwing:** Hurl huge boulders at enemies. - **Tree Weaponry:** At higher tiers, True Form lets you rip logs and wield them as weapons or throw them. +- **Your Own Colours:** pick your skin and hair colour under `Trol - Appearance`. Other players see them too. ### 7. Draugh - **Born Dead, Buried Alive:** Undead warrior: resistant to physical/poison, weak to fire/spirit. @@ -450,6 +451,7 @@ Both halves have an off switch under `Factions` in Configuration Manager: **Fact ### v1.5.10 - **New - Skeleton body switch for player model mods:** with EnhancedValheimVRM or another model replacer, the skeleton's bones stayed on screen and floated around the new model. Set `Skeleton - Visuals` → `Body Model Enabled` to off and Skeletons keep the vanilla body: no bones, eye lights or skull flames, and the helmet shows. Abilities don't change. The setting is client-side, so it applies to every Skeleton you see and changes nothing for other players. The race strips hair and beard, so the vanilla body is bald, and the auto-resurrection still shows the skeleton for the few seconds it climbs out of the ground. Thanks to the players who reported it and tested the fix. +- **New - Trol skin and hair colour:** `Trol - Appearance` has a colour picker for the skin and one for the hair and beard. Each Trol picks their own and every player sees them. The defaults are the old peacock blue and golden blonde, so nobody's Trol changes after the update. For the blue-grey of Valheim's own trolls, try `7FA8C9`. A Trol on an older version of the mod shows the defaults to everyone else. Thanks to the player who suggested it. - **Fix - Russian translation:** corrections to several Russian texts, by Axibed. ### v1.5.9 From d5c2d58636ae37167642310ee6fea0fa1fb31aa3 Mon Sep 17 00:00:00 2001 From: kanym Date: Wed, 14 Oct 2026 16:40:27 +0200 Subject: [PATCH 3/3] fix(resetrace): drop every form and every mod status effect on reset ResetRace now undoes each race's form on the spot before it touches status effects: Aswid bat and mist, Fenrir, Skadi drake, Trol True Form, Trenta Muspell and Sverm Ravager. Each race gets a HardResetForReset that stops the form's coroutine, so a transform caught mid-gesture can't finish after the reset and a revert can't hand out its cooldown after the sweep. The hand-written status effect list is gone. The reset now removes everything the mod registers through Jotunn (ModRegistry), which covers the True Form and its cooldowns, Bat and Mist Form, the Skeleton resurrect cooldown and Skadi's ability cooldowns. It also puts the player and the Visual back to scale 1, clears the Sverm's static Ravager cooldown and the Trol's wasTrueFormActive flag, and prints what it removed to the console and the BepInEx log. --- JotunnModStub/Aswid/AswidRace.cs | 71 ++++++++++++++++++++++--- JotunnModStub/Fenrir/FenrirRace.cs | 58 ++++++++++++++++++-- JotunnModStub/RacesOfValheim.cs | 61 +++++++++++++++------ JotunnModStub/Skadi/SkadiRace.cs | 57 ++++++++++++++++++-- JotunnModStub/Sverm/SvermRavagerForm.cs | 34 +++++++++++- JotunnModStub/Trenta/TrentaMuspell.cs | 47 ++++++++++++++-- JotunnModStub/Trol/TrolRace.cs | 45 +++++++++++++++- 7 files changed, 336 insertions(+), 37 deletions(-) diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index e8bb4c7..b95daff 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -463,7 +463,7 @@ namespace RacesOfValheim if (EnvMan.instance != null && EnvMan.IsDay() && !isTransformingSequence && Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode())) { - StartCoroutine(RevertMistFormRoutine()); + RunFormRoutine(RevertMistFormRoutine()); } // Same rule for a night-only bat: a form the sun forbids cannot be kept through the @@ -474,7 +474,7 @@ namespace RacesOfValheim EnvMan.instance != null && EnvMan.IsDay()) { Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_aswid_morning_sun_drives_bat_back")); - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); } } @@ -565,7 +565,7 @@ namespace RacesOfValheim if (IsTransformed) { - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); return; } @@ -580,18 +580,73 @@ namespace RacesOfValheim return; } - StartCoroutine(TransformIntoBatRoutine(rules)); + RunFormRoutine(TransformIntoBatRoutine(rules)); + } + + // The one bat or mist routine in flight, if any. Kept so ResetRace can stop it: a + // TransformIntoBatRoutine left running through a reset finishes its 1.1s gesture and + // turns a freshly reset Human into a bat. + private Coroutine formRoutine; + + private void RunFormRoutine(System.Collections.IEnumerator routine) + { + formRoutine = StartCoroutine(routine); + } + + /// + /// Drops bat and mist form on the spot for ResetRace: no puff, no tween, nothing left + /// running. ForceRevert is no use there - it skips a form that is still mid-gesture, and + /// its coroutine would still be shrinking the body back after the reset has finished. + /// + /// True if there was a form to drop. + public bool HardResetForReset() + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + if (formRoutine != null) + { + StopCoroutine(formRoutine); + formRoutine = null; + } + + bool hadMist = mistTransformation != null || player.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()); + bool hadBat = IsTransformed || isTransformingSequence; + + // Also clears isTransformingSequence and puts the transform back to scale 1, which + // covers a reset caught halfway through the bat's shrink. + HardResetBatForm(); + + if (hadMist) + { + if (mistTransformation != null) + { + Destroy(mistTransformation); + mistTransformation = null; + } + + Transform playerVisual = player.transform.Find("Visual"); + PlayerVisualHider.Show(playerVisual, "aswid-reset-mist"); + if (playerVisual != null) playerVisual.localScale = Vector3.one; + + player.GetSEMan().RemoveStatusEffect("SE_MistForm".GetStableHashCode(), true); + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) nview.GetZDO().Set("Aswid_IsMistForm", false); + } + + isTransformingSequence = false; + return hadBat || hadMist; } public void ForceRevert() { if (IsTransformed && !isTransformingSequence) { - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); } if (Player.m_localPlayer != null && Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode()) && !isTransformingSequence) { - StartCoroutine(RevertMistFormRoutine()); + RunFormRoutine(RevertMistFormRoutine()); } } @@ -745,11 +800,11 @@ namespace RacesOfValheim if (Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_MistForm".GetStableHashCode())) { - StartCoroutine(RevertMistFormRoutine()); + RunFormRoutine(RevertMistFormRoutine()); } else { - StartCoroutine(TransformIntoMistRoutine()); + RunFormRoutine(TransformIntoMistRoutine()); } } diff --git a/JotunnModStub/Fenrir/FenrirRace.cs b/JotunnModStub/Fenrir/FenrirRace.cs index c1d7664..ee5cd5a 100644 --- a/JotunnModStub/Fenrir/FenrirRace.cs +++ b/JotunnModStub/Fenrir/FenrirRace.cs @@ -185,7 +185,7 @@ namespace RacesOfValheim { if (isTransformed) { - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); return; } @@ -213,7 +213,7 @@ namespace RacesOfValheim { } } - StartCoroutine(TransformIntoWolfRoutine(rules)); + RunFormRoutine(TransformIntoWolfRoutine(rules)); } /// @@ -256,11 +256,63 @@ namespace RacesOfValheim { return "$rov_msg_fenrir_formname_fenrir"; } + // The one transform or revert routine in flight, if any, so ResetRace can stop it. A + // revert left to finish on its own lands its cooldown after the reset has already swept + // the status effects, and the next Fenrir starts locked out. + private Coroutine formRoutine; + + private void RunFormRoutine(IEnumerator routine) + { + formRoutine = StartCoroutine(routine); + } + + /// + /// Drops whatever form is up, immediately, for ResetRace: no poof, no message, and no + /// cooldown - ExecuteReversion hands one out, which is right for a form running out and + /// wrong for a player leaving the race. + /// + /// True if there was a form to drop. + public bool HardResetForReset() + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + if (formRoutine != null) + { + StopCoroutine(formRoutine); + formRoutine = null; + } + + bool hadForm = isTransformed || isTransformingSequence || currentTransformation != null; + if (hadForm) + { + if (currentTransformation != null) Destroy(currentTransformation); + currentTransformation = null; + DestroyAllForms(); + + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_FenrirForm", ""); + + PlayerVisualHider.Show(player.transform.Find("Visual"), "fenrir-reset"); + + player.GetSEMan().RemoveStatusEffect("SE_FenrirForm".GetStableHashCode()); + player.GetSEMan().RemoveStatusEffect("SE_CultistForm".GetStableHashCode()); + player.GetSEMan().RemoveStatusEffect("SE_WolfForm".GetStableHashCode()); + } + + isTransformed = false; + isTransformingSequence = false; + activeRules = null; + revertMessage = null; + sunSicknessTimer = 0f; + return hadForm; + } + public void ForceRevert() { if (isTransformed && !isTransformingSequence) { - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); } } diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 6e826c6..e6f8289 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -4,6 +4,7 @@ using HarmonyLib; using Jotunn.Configs; using Jotunn.Entities; using Jotunn.Managers; +using Jotunn.Utils; using UnityEngine; using UnityEngine.UI; // Added for UI @@ -99,6 +100,20 @@ namespace RacesOfValheim Player player = Player.m_localPlayer; if (player == null) return; + // What the reset actually took off, printed at the end so it can be read in the console. + var removed = new System.Collections.Generic.List(); + + // Forms first, before any status effect goes. Taking a form's effect away without + // undoing the form leaves the body hidden (bat, mist, drake, wolf, Muspell, Ravager) + // or oversized (True Form), and several races only ever look at their form from an + // Update that returns early for anyone who is not of that race any more. + if (AswidRace.Instance != null && AswidRace.Instance.HardResetForReset()) removed.Add("form: Aswid bat/mist"); + if (FenrirRace.Instance != null && FenrirRace.Instance.HardResetForReset()) removed.Add("form: Fenrir"); + if (SkadiRace.Instance != null && SkadiRace.Instance.HardResetForReset()) removed.Add("form: Skadi drake"); + if (TrolRace.Instance != null && TrolRace.Instance.HardResetForReset()) removed.Add("form: Trol True Form"); + if (TrentaMuspell.HardResetForReset(player)) removed.Add("form: Trenta Muspell"); + if (SvermRavagerForm.HardResetForReset(player)) removed.Add("form: Sverm Ravager"); + RemovePermanentRaceEquipment(player); player.m_customData.Remove("Race"); @@ -120,21 +135,23 @@ namespace RacesOfValheim } } - player.GetSEMan().RemoveStatusEffect("SE_FenrirCurse".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect("SE_AswidStats".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect("SE_SkeletonStats".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect("SE_SkadiStats".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect("SE_SkadiCooldown".GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergarConfig.StatsSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergarConfig.OverchargeSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergarConfig.OverchargeCdSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(DvergarConfig.RunicPingCdSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(TrentaConfig.StatsSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(TrentaConfig.PurpleRainCdSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(TrentaConfig.PortalCdSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(SvermConfig.StatsSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(SvermConfig.RavagerSE.GetStableHashCode()); - player.GetSEMan().RemoveStatusEffect(SvermConfig.RavagerCdSE.GetStableHashCode()); + // Every status effect this mod registers, rather than a list kept by hand: the hand + // list was missing the True Form and both of its cooldowns, Bat and Mist Form, the + // Skeleton's resurrect cooldown and most of Skadi's, and the next effect anyone adds + // would have been missing too. The forms were dropped above, so taking their effects + // away here no longer leaves a body hidden or blown up. + SEMan seman = player.GetSEMan(); + foreach (CustomStatusEffect custom in ModRegistry.GetStatusEffects(PluginGUID)) + { + StatusEffect se = custom?.StatusEffect; + if (se == null) continue; + + int hash = se.name.GetStableHashCode(); + if (!seman.HaveStatusEffect(hash)) continue; + + seman.RemoveStatusEffect(hash, true); + removed.Add(se.name); + } // COLD, which is not one of ours at all - and that is exactly why it has to go. // @@ -161,9 +178,21 @@ namespace RacesOfValheim // Only after the ZDO above already says "Human" - see the class doc comment. RaceItemCleanup.PurgeForeignRaceItems(player); + // Normal size. The Trol, the Skeleton past Fader and the self-sizing races all scale + // either the player or its Visual, and each puts its own size back only from code that + // may not run again now the race has changed. The next race sets its own size anyway. + player.transform.localScale = Vector3.one; + GameObject visual = Traverse.Create(player).Field("m_visual").GetValue(); + if (visual != null) visual.transform.localScale = Vector3.one; + + string summary = removed.Count == 0 + ? "[ResetRace] Nothing race-specific was left on the player." + : "[ResetRace] Removed: " + string.Join(", ", removed); + Jotunn.Logger.LogInfo(summary); + if (Console.instance != null) Console.instance.Print(summary); + if (Instance != null) { - if (FenrirRace.Instance != null) FenrirRace.Instance.ForceRevert(); Instance.ShowRaceSelectionMenu(); } } diff --git a/JotunnModStub/Skadi/SkadiRace.cs b/JotunnModStub/Skadi/SkadiRace.cs index 573685d..27ea13e 100644 --- a/JotunnModStub/Skadi/SkadiRace.cs +++ b/JotunnModStub/Skadi/SkadiRace.cs @@ -247,7 +247,7 @@ namespace RacesOfValheim { formExpireTime = 0f; Player.m_localPlayer.Message(MessageHud.MessageType.Center, ModText.Get("rov_msg_skadi_dragon_form_fades")); - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); return; } @@ -687,7 +687,7 @@ namespace RacesOfValheim if (isTransformed) { - StartCoroutine(RevertToHumanRoutine()); + RunFormRoutine(RevertToHumanRoutine()); return; } @@ -707,7 +707,7 @@ namespace RacesOfValheim } activeRules = rules; - StartCoroutine(TransformRoutine(rules)); + RunFormRoutine(TransformRoutine(rules)); } private Vector3 GetFormScale(SkadiProgression.FormType form) @@ -914,6 +914,57 @@ namespace RacesOfValheim if (se != null) se.m_ttl = seconds; } + // The one transform or revert routine in flight, if any, so ResetRace can stop it. + private Coroutine formRoutine; + + private void RunFormRoutine(System.Collections.IEnumerator routine) + { + formRoutine = StartCoroutine(routine); + } + + /// + /// Drops the drake form on the spot for ResetRace. Update bails out on its first line for + /// anyone who is not a Skadi, so once the race changes nothing in this class ever looks at + /// the form again - a Skadi reset in drake form stayed a drake for good. No message and no + /// cooldown here, unlike ExecuteReversion. + /// + /// True if there was a form to drop. + public bool HardResetForReset() + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + if (formRoutine != null) + { + StopCoroutine(formRoutine); + formRoutine = null; + } + + bool hadForm = isTransformed || isTransformingSequence || currentTransformation != null; + if (hadForm) + { + if (currentTransformation != null) Destroy(currentTransformation); + currentTransformation = null; + foreach (var f in player.GetComponentsInChildren(true)) Destroy(f.gameObject); + + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) + { + nview.GetZDO().Set("Skadi_Form", ""); + nview.GetZDO().Set("RacesOfValheim_SkadiForm", ""); + } + + PlayerVisualHider.Show(player.transform.Find("Visual"), "skadi-reset"); + player.GetSEMan().RemoveStatusEffect("SE_SkadiForm".GetStableHashCode(), true); + } + + isTransformed = false; + isTransformingSequence = false; + formExpireTime = 0f; + activeRules = null; + return hadForm; + } + private void ExecuteReversion() { Transform playerVisual = Player.m_localPlayer.transform.Find("Visual"); diff --git a/JotunnModStub/Sverm/SvermRavagerForm.cs b/JotunnModStub/Sverm/SvermRavagerForm.cs index b0e6497..f41b7f0 100644 --- a/JotunnModStub/Sverm/SvermRavagerForm.cs +++ b/JotunnModStub/Sverm/SvermRavagerForm.cs @@ -177,7 +177,7 @@ namespace RacesOfValheim if (SvermRace.Instance != null) { - SvermRace.Instance.StartCoroutine(EnterRoutine(player)); + formRoutine = SvermRace.Instance.StartCoroutine(EnterRoutine(player)); } else { @@ -342,12 +342,42 @@ namespace RacesOfValheim } } + // The enter or exit routine in flight, if any, so ResetRace can stop it. An ExitRoutine + // left running finishes with Exit(spendCooldown: true), which puts the cooldown back on + // after the reset has swept it. + private static Coroutine formRoutine; + + /// + /// Drops Ravager Strain on the spot for ResetRace, and forgets its cooldown: nextAllowedAt + /// is a static the status effect sweep never touches, so without this a player who left + /// the Sverm and came back stayed locked out of the form with no timer in the HUD. + /// + /// True if there was a form to drop. + public static bool HardResetForReset(Player player) + { + if (player == null) return false; + + if (formRoutine != null && SvermRace.Instance != null) + { + SvermRace.Instance.StopCoroutine(formRoutine); + } + formRoutine = null; + + bool hadForm = IsActive || transforming || exiting || model != null; + if (IsActive || model != null) Exit(player, spendCooldown: false); + + transforming = false; + exiting = false; + nextAllowedAt = 0f; + return hadForm; + } + /// Kicks off the graceful exit (shrink, then Exit) if there is a host to run it on. private static void RunExit(Player player, bool spendCooldown, string message) { if (SvermRace.Instance != null) { - SvermRace.Instance.StartCoroutine(ExitRoutine(player, spendCooldown, message)); + formRoutine = SvermRace.Instance.StartCoroutine(ExitRoutine(player, spendCooldown, message)); } else { diff --git a/JotunnModStub/Trenta/TrentaMuspell.cs b/JotunnModStub/Trenta/TrentaMuspell.cs index 4499faf..d3af9ef 100644 --- a/JotunnModStub/Trenta/TrentaMuspell.cs +++ b/JotunnModStub/Trenta/TrentaMuspell.cs @@ -53,11 +53,11 @@ namespace RacesOfValheim if (IsTransformed) { - TrentaRace.Instance.StartCoroutine(RevertRoutine(player)); + formRoutine = TrentaRace.Instance.StartCoroutine(RevertRoutine(player)); } else { - TrentaRace.Instance.StartCoroutine(TransformRoutine(player)); + formRoutine = TrentaRace.Instance.StartCoroutine(TransformRoutine(player)); } } @@ -68,10 +68,51 @@ namespace RacesOfValheim { if (IsTransformed && !isTransformingSequence) { - TrentaRace.Instance.StartCoroutine(RevertRoutine(player)); + formRoutine = TrentaRace.Instance.StartCoroutine(RevertRoutine(player)); } } + // The one transform or revert routine in flight, if any, so ResetRace can stop it. + private static Coroutine formRoutine; + + /// + /// Drops the Muspell on the spot for ResetRace. ForceRevert would get there too, from + /// TrentaRace.Update, but a frame and a half-second tween later - after ResetRace has + /// already reopened the menu - and not at all if the reset lands mid-gesture. + /// + /// True if there was a form to drop. + public static bool HardResetForReset(Player player) + { + if (player == null) return false; + + if (formRoutine != null && TrentaRace.Instance != null) + { + TrentaRace.Instance.StopCoroutine(formRoutine); + } + formRoutine = null; + + bool hadForm = IsTransformed || isTransformingSequence || currentTransformation != null; + if (hadForm) + { + if (currentTransformation != null) Object.Destroy(currentTransformation); + currentTransformation = null; + + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) nview.GetZDO().Set("RacesOfValheim_MuspellForm", false); + + Transform playerVisual = player.transform.Find("Visual"); + if (playerVisual != null) + { + playerVisual.localScale = Vector3.one; + playerVisual.gameObject.SetActive(true); + } + } + + IsTransformed = false; + isTransformingSequence = false; + return hadForm; + } + /// /// Called by Purple Rain instead of its usual staff_summon trigger whenever Muspell is /// active - The Elder's own root-summon gesture, played on the transformation clone's diff --git a/JotunnModStub/Trol/TrolRace.cs b/JotunnModStub/Trol/TrolRace.cs index e1894ec..e2d26c4 100644 --- a/JotunnModStub/Trol/TrolRace.cs +++ b/JotunnModStub/Trol/TrolRace.cs @@ -206,11 +206,52 @@ namespace RacesOfValheim bool isTrueFormActive = Player.m_localPlayer.GetSEMan().HaveStatusEffect("SE_TrolTrueForm".GetStableHashCode()); if (wasTrueFormActive && !isTrueFormActive && !isTransforming) { - StartCoroutine(RevertTrueFormRoutine()); + RunFormRoutine(RevertTrueFormRoutine()); } wasTrueFormActive = isTrueFormActive; } + // The one grow or shrink routine in flight, if any, so ResetRace can stop it. + private Coroutine formRoutine; + + private void RunFormRoutine(System.Collections.IEnumerator routine) + { + formRoutine = StartCoroutine(routine); + } + + /// + /// Drops True Form on the spot for ResetRace. Update returns on its first line for anyone + /// who is not a Trol, so its auto-revert never saw the form end. wasTrueFormActive is the + /// part that would bite later: left true, the next time this player picks Trol the first + /// Update reads it as a form that just ran out and hands out a True Form cooldown. + /// + /// True if there was a form to drop. + public bool HardResetForReset() + { + Player player = Player.m_localPlayer; + if (player == null) return false; + + if (formRoutine != null) + { + StopCoroutine(formRoutine); + formRoutine = null; + } + + int trueFormHash = "SE_TrolTrueForm".GetStableHashCode(); + bool hadForm = isTransforming || wasTrueFormActive || player.GetSEMan().HaveStatusEffect(trueFormHash); + if (hadForm) + { + player.GetSEMan().RemoveStatusEffect(trueFormHash, true); + + ZNetView nview = player.GetComponent(); + if (nview != null && nview.IsValid()) nview.GetZDO().Set(Trol_PlayerUpdate_Patch.TrueFormKey, false); + } + + isTransforming = false; + wasTrueFormActive = false; + return hadForm; + } + private void TryTrueForm() { if (BossProgressionManager.GetCurrentProgressionState() < 5) return; // Requires Moder @@ -239,7 +280,7 @@ namespace RacesOfValheim if (!isTransforming) { - StartCoroutine(TransformToTrueFormRoutine()); + RunFormRoutine(TransformToTrueFormRoutine()); } }