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

@ -14,17 +14,25 @@ namespace RacesOfValheim
// ─── Health malus ────────────────────────────────────────────────────
/// <summary>
/// The Dvergur is a small frame, and carries less health for it. The target is resolved
/// with AccessTools rather than named against a type, because GetMaxHealth may be declared
/// on Character or overridden on Player depending on the game version - AccessTools walks
/// up to whichever one actually runs, and the local-player guard makes either correct.
/// The Dvergur is a small frame, and carries less health for it.
///
/// The malus is taken off the food total rather than off Character.GetMaxHealth, which is
/// what the first attempt did and what produced the bug where the bar shrank but the
/// number stayed put and the border flashed. Patching the getter makes it lie to the rest
/// of the game: Character.SetMaxHealth is the only thing that clamps current health down
/// to the new maximum, and it never saw a lower number, so m_health stayed at 58. Worse,
/// Player.SetMaxHealth flashes the bar whenever the new maximum is above GetMaxHealth() -
/// against a getter that always read low, every food tick looked like a health *increase*
/// and re-triggered the flash.
///
/// GetTotalFoodValue is upstream of both: UpdateFood feeds its result straight into
/// SetMaxHealth, so Valheim does its own clamping and its own flash logic on an honest
/// number and bar, value and animation all agree.
/// </summary>
[HarmonyPatch]
public static class Dvergur_GetMaxHealth_Patch
[HarmonyPatch(typeof(Player), "GetTotalFoodValue")]
public static class Dvergur_GetTotalFoodValue_Patch
{
public static MethodBase TargetMethod() => AccessTools.Method(typeof(Player), "GetMaxHealth");
public static void Postfix(Character __instance, ref float __result)
public static void Postfix(Player __instance, ref float hp)
{
if (__instance == null || __instance != Player.m_localPlayer) return;
if (!DvergurRace.IsDvergur()) return;
@ -32,7 +40,26 @@ namespace RacesOfValheim
float malus = DvergurProgression.Current.HealthMalus;
if (malus <= 0f) return;
__result = Mathf.Max(DvergurConfig.MinMaxHealth, __result - malus);
hp = Mathf.Max(DvergurConfig.MinMaxHealth, hp - malus);
}
}
// ─── Scale ───────────────────────────────────────────────────────────
/// <summary>
/// Sizing runs off Player.Update, which is where the Trol does it and the only place it
/// holds: Trol's own postfix forces every non-Trol player's visual back to scale 1 on the
/// same frame, so a scale applied from anywhere else was simply overwritten. Being a
/// postfix on the same method puts the Dvergur on equal footing, and RaceScale keeps the
/// two from undoing each other.
/// </summary>
[HarmonyPatch(typeof(Player), "Update")]
public static class Dvergur_PlayerUpdate_Scale_Patch
{
public static void Postfix(Player __instance)
{
if (__instance == null) return;
DvergurVisuals.ApplyScale(__instance, DvergurVisuals.IsDvergurPlayer(__instance));
}
}
@ -290,7 +317,7 @@ namespace RacesOfValheim
Player player = __instance.GetComponent<Player>();
if (player == null) return;
DvergurVisuals.Apply(player);
DvergurVisuals.ApplyHood(player);
}
}
}