diff --git a/JotunnModStub/Dvergar/DvergarConfig.cs b/JotunnModStub/Dvergar/DvergarConfig.cs index e891051..bed7c3d 100644 --- a/JotunnModStub/Dvergar/DvergarConfig.cs +++ b/JotunnModStub/Dvergar/DvergarConfig.cs @@ -62,6 +62,15 @@ namespace RacesOfValheim public const int OneStarState = 4; // Bonemass public const int TwoStarState = 8; // Fader + // Those offsets are authored against a dverger's own texture. Ours is a multiplier over + // the human skin, where white means "no tint at all" - so an offset that brightens and + // desaturates far enough lands on white and hands back an ordinary pink human. That is + // exactly what the two-star tier did. These bounds keep every tier recognisably the same + // colour, shifted rather than washed out. + public const float StarMinSaturation = 0.25f; + public const float StarMinValue = 0.20f; + public const float StarMaxValue = 0.85f; + // ─── Cosmetic hood ─────────────────────────────────────────────────── // The helmet slot itself stays free — whatever the player equips keeps all of its stats, // only the mesh is swapped. diff --git a/JotunnModStub/Dvergar/DvergarVisuals.cs b/JotunnModStub/Dvergar/DvergarVisuals.cs index 6015658..4247a81 100644 --- a/JotunnModStub/Dvergar/DvergarVisuals.cs +++ b/JotunnModStub/Dvergar/DvergarVisuals.cs @@ -127,23 +127,39 @@ namespace RacesOfValheim } cachedStarSetups = effects.m_levelSetups.ToArray(); - Jotunn.Logger.LogInfo( - $"[Dvergar] Star colours resolved: {cachedStarSetups.Length} setups from " + - $"'{DvergarConfig.DvergerPrefabName}'."); + + // The offsets themselves, so a tier that lands on the wrong colour can be tuned + // against the real numbers rather than by eye. + for (int i = 0; i < cachedStarSetups.Length; i++) + { + LevelEffects.LevelSetup setup = cachedStarSetups[i]; + Jotunn.Logger.LogInfo( + $"[Dvergar] Star {i + 1}: hue={setup.m_hue:F3} saturation={setup.m_saturation:F3} " + + $"value={setup.m_value:F3} emissive={(setup.m_setEmissiveColor ? setup.m_emissiveColor.ToString() : "none")} " + + $"-> skin {ShiftHsv(DvergarConfig.SkinColor, setup.m_hue, setup.m_saturation, setup.m_value)}"); + } + return cachedStarSetups; } /// - /// Applies an HSV offset the way the creature shader does - hue wraps, the other two - /// clamp - so the result is the same shift a starred dverger gets, on our colour. + /// Applies a star's HSV offset to our tint. Hue wraps the way the creature shader's does; + /// saturation and value are bounded rather than merely clamped to 0..1. + /// + /// The bounds are the whole trick. The shader applies these offsets to a dverger's own + /// texture, where a bright desaturated result is a pale dverger. Ours multiplies the human + /// skin texture, where the same result is *white* - and a white multiplier is no tint at + /// all, which is why the two-star Dvergar came out looking like an ordinary pink human. + /// Keeping saturation off the floor and value off the ceiling means every tier stays a + /// colour. /// private static Color ShiftHsv(Color color, float hue, float saturation, float value) { Color.RGBToHSV(color, out float h, out float s, out float v); h = Mathf.Repeat(h + hue, 1f); - s = Mathf.Clamp01(s + saturation); - v = Mathf.Clamp01(v + value); + s = Mathf.Clamp(s + saturation, DvergarConfig.StarMinSaturation, 1f); + v = Mathf.Clamp(v + value, DvergarConfig.StarMinValue, DvergarConfig.StarMaxValue); Color shifted = Color.HSVToRGB(h, s, v); shifted.a = color.a; diff --git a/JotunnModStub/Skeleton/SkeletonPatches.cs b/JotunnModStub/Skeleton/SkeletonPatches.cs index 40d9043..1fee96c 100644 --- a/JotunnModStub/Skeleton/SkeletonPatches.cs +++ b/JotunnModStub/Skeleton/SkeletonPatches.cs @@ -335,6 +335,7 @@ namespace RacesOfValheim HideItemInstances(__instance, "m_hairItemInstances"); HideItemInstances(__instance, "m_beardItemInstances"); + SetHelmetVisible(__instance, false); } } else @@ -358,10 +359,41 @@ namespace RacesOfValheim ShowItemInstances(__instance, "m_hairItemInstances"); ShowItemInstances(__instance, "m_beardItemInstances"); + SetHelmetVisible(__instance, true); } } } + /// + /// A helmet on a skull looks like a helmet floating in a skull, so the race hides it. + /// + /// SkeletonRace does this every frame in a world, but it only ever runs for the local + /// player - which is why the helmet came back on the main-menu preview once the body + /// swap started working there. Doing it here covers the menu, remote players and the + /// first frame after a race change, all of which reach this postfix and none of which + /// reach SkeletonRace. + /// + /// Scaled rather than deactivated, because Valheim re-enables the instance whenever it + /// refreshes visuals - the approach the Dvergar's hood already proved out. + /// + private static void SetHelmetVisible(VisEquipment visEq, bool visible) + { + GameObject helmet = Traverse.Create(visEq).Field("m_helmetItemInstance").Value; + if (helmet == null) return; + + Vector3 wanted = visible ? Vector3.one : Vector3.zero; + + // Only ever undo our own hiding: another race may legitimately be scaling this. + if (!visible && helmet.transform.localScale != Vector3.zero) + { + helmet.transform.localScale = wanted; + } + else if (visible && helmet.transform.localScale == Vector3.zero) + { + helmet.transform.localScale = wanted; + } + } + private static void HideItemInstances(VisEquipment visEq, string fieldName) { try