diff --git a/JotunnModStub/Dvergur/DvergurConfig.cs b/JotunnModStub/Dvergur/DvergurConfig.cs index dac8e68..af26423 100644 --- a/JotunnModStub/Dvergur/DvergurConfig.cs +++ b/JotunnModStub/Dvergur/DvergurConfig.cs @@ -33,12 +33,18 @@ namespace RacesOfValheim // Tuning knobs are static readonly rather than const throughout: a const folds at compile // time, which turns "is this perk switched off?" guards into dead code the moment a knob // is set to zero, and would bake the old value into any assembly built against this one. - public static readonly float VisualScale = 0.70f; // -30% versus a human + // Nudged up from the 0.70 the spec asked for: -30% read as too small next to a human once + // it was actually on screen. + public static readonly float VisualScale = 0.78f; // -22% versus a human // ─── Skin ──────────────────────────────────────────────────────────── - // Tint applied over the human skin texture, the same multiplicative m_skinColor the - // Furling and Trol use. Ashen grey with a blue cast, to read as one of the deep folk. - public static readonly Vector3 SkinColor = new Vector3(0.72f, 0.74f, 0.82f); + // Written straight onto the body material's _SkinColor by the UpdateColors postfix, which + // is the only thing that actually tints a player - see the comment on that patch. + // Ashen grey with a blue cast, to read as one of the deep folk. + public static readonly Color SkinColor = new Color(0.72f, 0.74f, 0.82f, 1f); + + // Dvergr are white-haired. The hood hides most of it, but the beard shows. + public static readonly Color HairColor = new Color(0.88f, 0.88f, 0.90f, 1f); // ─── Cosmetic hood ─────────────────────────────────────────────────── // The helmet slot itself stays free — whatever the player equips keeps all of its stats, diff --git a/JotunnModStub/Dvergur/DvergurPatches.cs b/JotunnModStub/Dvergur/DvergurPatches.cs index 250aae1..b54b3e5 100644 --- a/JotunnModStub/Dvergur/DvergurPatches.cs +++ b/JotunnModStub/Dvergur/DvergurPatches.cs @@ -300,6 +300,52 @@ namespace RacesOfValheim } } + // ─── Skin ──────────────────────────────────────────────────────────── + + /// + /// Tints the Dvergur ashen grey. + /// + /// The first attempt did this the way the race-selection menu appears to - VisEquipment's + /// SetSkinColor followed by UpdateColors - and nothing happened, because that pair is not + /// what actually colours a player. UpdateColors rebuilds the body material from Valheim's + /// own state on every refresh, so any tint has to be written *after* it runs. That is why + /// every race in this mod that visibly changes colour has a postfix here writing + /// _SkinColor onto the material directly, and why the SetSkinColor calls in the selection + /// menu are, on their own, decorative. + /// + /// No local-player check and no saved original: the race is read from the ZDO with a + /// m_customData fallback so the main-menu preview and the first spawn frame are covered + /// too, and the tint simply stops being applied once the player is no longer a Dvergur. + /// + [HarmonyPatch(typeof(VisEquipment), "UpdateColors")] + public static class Dvergur_VisEquipment_UpdateColors_Patch + { + public static void Postfix(VisEquipment __instance) + { + if (__instance == null || !__instance.m_isPlayer) return; + + Player player = __instance.GetComponent(); + if (player == null || !DvergurVisuals.IsDvergurPlayer(player)) return; + + if (__instance.m_bodyModel != null && __instance.m_bodyModel.material != null) + { + __instance.m_bodyModel.material.SetColor("_SkinColor", DvergurConfig.SkinColor); + } + + TintRenderers(Traverse.Create(__instance).Field("m_hairItemInstance").GetValue()); + TintRenderers(Traverse.Create(__instance).Field("m_beardItemInstance").GetValue()); + } + + private static void TintRenderers(GameObject instance) + { + if (instance == null) return; + foreach (Renderer renderer in instance.GetComponentsInChildren()) + { + if (renderer.material != null) renderer.material.SetColor("_SkinColor", DvergurConfig.HairColor); + } + } + } + // ─── Cosmetic hood ─────────────────────────────────────────────────── /// diff --git a/JotunnModStub/Dvergur/DvergurVisuals.cs b/JotunnModStub/Dvergur/DvergurVisuals.cs index 1742ae7..d5c05ec 100644 --- a/JotunnModStub/Dvergur/DvergurVisuals.cs +++ b/JotunnModStub/Dvergur/DvergurVisuals.cs @@ -78,40 +78,6 @@ namespace RacesOfValheim } } - // ─── Skin ──────────────────────────────────────────────────────────── - - /// - /// Tints the local player's skin, saving the original first so ResetRace can put it back. - /// Same save-then-tint dance the Furling, Trol and Draugh selections do. - /// - public static void ApplySkinColor(Player player) - { - if (player == null) return; - - VisEquipment visEq = player.GetComponent(); - if (visEq == null) return; - - if (!player.m_customData.ContainsKey("OriginalSkinColor_X")) - { - Vector3 current = Traverse.Create(visEq).Field("m_skinColor").GetValue(); - player.m_customData["OriginalSkinColor_X"] = current.x.ToString(); - player.m_customData["OriginalSkinColor_Y"] = current.y.ToString(); - player.m_customData["OriginalSkinColor_Z"] = current.z.ToString(); - } - - Traverse.Create(visEq).Method("SetSkinColor", DvergurConfig.SkinColor).GetValue(); - RefreshColors(visEq); - } - - public static void RefreshColors(VisEquipment visEq) - { - if (visEq == null) return; - visEq.GetType().GetMethod("UpdateColors", - System.Reflection.BindingFlags.Instance | - System.Reflection.BindingFlags.NonPublic | - System.Reflection.BindingFlags.Public)?.Invoke(visEq, null); - } - // ─── Hood ──────────────────────────────────────────────────────────── /// diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index ceb30bc..95be5b1 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -593,9 +593,8 @@ namespace RacesOfValheim Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergurConfig.StatsSE.GetStableHashCode(), true); - // Saves the original skin first, so ResetRace can hand it back. - DvergurVisuals.ApplySkinColor(Player.m_localPlayer); - + // No SetSkinColor here: the tint is written onto the material by the UpdateColors + // postfix in DvergurPatches, which keys off the race and so needs nothing saved. VisEquipment visEq = Player.m_localPlayer.GetComponent(); if (visEq != null) { @@ -692,12 +691,8 @@ namespace RacesOfValheim if (visEq != null) visEq.GetType().GetMethod("UpdateColors", System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public)?.Invoke(visEq, null); } - // Re-tinted rather than merely refreshed: the skin colour is the one piece of the - // Dvergur that is not rebuilt from the race id on its own. - if (__instance.m_customData.ContainsKey("Race") && __instance.m_customData["Race"] == DvergurConfig.RaceId) - { - DvergurVisuals.ApplySkinColor(__instance); - } + // The Dvergur needs no entry here: its tint is applied by the UpdateColors postfix + // every time Valheim refreshes the body, rather than being stored on the player. // Check for Race Selection if (!__instance.m_customData.ContainsKey("Race"))