fix(dvergur): correct the health malus, body scale and hood

Health: the malus was taken off Character.GetMaxHealth, which only made the
getter lie. Character.SetMaxHealth is the one thing that clamps current health
to the new maximum and it never saw a lower number, so the bar shrank while the
value stayed where it was. Player.SetMaxHealth also flashes the bar whenever the
new maximum is above GetMaxHealth(), so against a getter that always read low
every food tick looked like an increase and re-triggered the flash. Taking the
malus off Player.GetTotalFoodValue instead puts it upstream of both, and leaves
Valheim to do its own clamping on an honest number.

Scale: applied from the plugin MonoBehaviour, it was overwritten on the same
frame by Trol's Player.Update postfix, which forced every non-Trol player back
to scale 1. Sizing now happens in a postfix on that same method, the way the
Trol does it, and RaceScale records which races size themselves so they stop
undoing each other. This also fixes the Furling, which was losing the same race.

Hood: the Dverger Circlet is a metal band, not the hood, and instantiating a
skinned mesh leaves its bones pointing at the source prefab so it renders
nowhere. The headgear is now lifted off the Dvergr NPC and rebound to the
player's own bones by name, as the Skeleton does for whole bodies.

Skin is tinted to a dvergr grey, saved and restored through the same
OriginalSkinColor keys the other tinted races use.

Adds a dumpdverger console command: prefab contents live in the asset bundles
and cannot be read outside a running game, so this is how the hood mesh and the
per-star LevelEffects colours get identified.
This commit is contained in:
kanym 2026-08-02 22:58:11 +02:00
commit 79a54fb533
8 changed files with 388 additions and 118 deletions

View file

@ -38,6 +38,7 @@ namespace RacesOfValheim
CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());
CommandManager.Instance.AddConsoleCommand(new IncreaseProgressionCommand());
CommandManager.Instance.AddConsoleCommand(new ResetProgressionCommand());
CommandManager.Instance.AddConsoleCommand(new DumpDvergerCommand());
}
/// <summary>
@ -592,8 +593,9 @@ namespace RacesOfValheim
Player.m_localPlayer.GetSEMan().AddStatusEffect(DvergurConfig.StatsSE.GetStableHashCode(), true);
// The Dvergur keeps its own skin - only the silhouette and the hood change, so
// UpdateVisuals is enough and UpdateColors has nothing to do here.
// Saves the original skin first, so ResetRace can hand it back.
DvergurVisuals.ApplySkinColor(Player.m_localPlayer);
VisEquipment visEq = Player.m_localPlayer.GetComponent<VisEquipment>();
if (visEq != null)
{
@ -690,6 +692,13 @@ 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);
}
// Check for Race Selection
if (!__instance.m_customData.ContainsKey("Race"))
{
@ -768,6 +777,82 @@ namespace RacesOfValheim
}
}
/// <summary>
/// Dumps the Dvergr NPC prefab: its transform tree, every renderer on it, and its per-star
/// LevelEffects colours. Prefab contents live in the asset bundles and cannot be read outside
/// a running game, so this is how the hood mesh and the star tints get identified.
/// </summary>
public class DumpDvergerCommand : ConsoleCommand
{
public override string Name => "dumpdverger";
public override string Help => "[DEBUG] Logs the Dverger prefab hierarchy, renderers and star colours";
public override void Run(string[] args)
{
string prefabName = args.Length > 0 ? args[0] : DvergurConfig.DvergerPrefabName;
GameObject prefab = Jotunn.Managers.PrefabManager.Cache.GetPrefab<GameObject>(prefabName);
if (prefab == null)
{
Console.instance.Print($"Prefab '{prefabName}' not found.");
return;
}
Jotunn.Logger.LogInfo($"=== {prefabName} HIERARCHY ===");
DumpTransform(prefab.transform, "");
Jotunn.Logger.LogInfo($"=== {prefabName} RENDERERS ===");
foreach (Renderer renderer in prefab.GetComponentsInChildren<Renderer>(true))
{
Jotunn.Logger.LogInfo($" {renderer.gameObject.name} ({renderer.GetType().Name}) path={GetPath(renderer.transform)}");
}
LevelEffects levelEffects = prefab.GetComponentInChildren<LevelEffects>(true);
if (levelEffects != null && levelEffects.m_levelSetups != null)
{
Jotunn.Logger.LogInfo($"=== {prefabName} LEVEL SETUPS (index 0 = 1 star) ===");
for (int i = 0; i < levelEffects.m_levelSetups.Count; i++)
{
var setup = levelEffects.m_levelSetups[i];
if (setup == null) continue;
Jotunn.Logger.LogInfo(
$" [{i}] scale={setup.m_scale} hue={setup.m_hue} sat={setup.m_saturation} val={setup.m_value} " +
$"emissive={setup.m_setEmissiveColor}:{setup.m_emissiveColor}");
}
}
else
{
Jotunn.Logger.LogInfo($"{prefabName} has no LevelEffects.");
}
Console.instance.Print($"Dumped '{prefabName}' to the BepInEx log.");
}
private static void DumpTransform(Transform t, string indent)
{
if (t == null) return;
System.Text.StringBuilder components = new System.Text.StringBuilder();
foreach (Component c in t.GetComponents<Component>())
{
if (c != null) components.Append(c.GetType().Name).Append(" ");
}
Jotunn.Logger.LogInfo($"{indent}{t.name} [{components}]");
for (int i = 0; i < t.childCount; i++) DumpTransform(t.GetChild(i), indent + " ");
}
private static string GetPath(Transform t)
{
string path = t.name;
while (t.parent != null)
{
t = t.parent;
path = t.name + "/" + path;
}
return path;
}
}
public class ResetProgressionCommand : ConsoleCommand
{
public override string Name => "resetprogression";