1.0 compatibility

This commit is contained in:
Ferdinando 2026-09-10 18:05:24 +02:00
commit 6193b3ee2d
33 changed files with 712 additions and 49 deletions

View file

@ -682,9 +682,10 @@ namespace RacesOfValheim
if (player.GetComponent<CarapaceMark>() == null) player.gameObject.AddComponent<CarapaceMark>();
visEq.SetChestItem(SvermConfig.CarapaceChestVisual);
visEq.SetLegItem(SvermConfig.CarapaceLegsVisual);
visEq.SetHelmetItem(SvermConfig.CarapaceHelmetVisual);
// Since Valheim 1.0 these three take an item hash rather than a prefab name.
visEq.SetChestItem(VisualHash(SvermConfig.CarapaceChestVisual));
visEq.SetLegItem(VisualHash(SvermConfig.CarapaceLegsVisual));
visEq.SetHelmetItem(VisualHash(SvermConfig.CarapaceHelmetVisual));
int state = GetRenderState(player);
@ -697,7 +698,7 @@ namespace RacesOfValheim
/// Puts the three slots back to whatever the player actually has equipped.
///
/// The same three lines vanilla's own Humanoid.SetupVisEquipment writes - the item's drop
/// prefab name, or "" for an empty slot - rather than calling that method, because it also
/// prefab name hashed, or 0 when empty - rather than calling that method, because it also
/// rewrites the hands, the shoulders and the utility slot, and the Sverm never touched
/// those. Restoring only what was overridden cannot disturb another race's visuals or a
/// weapon that some other patch is mid-way through swapping.
@ -707,17 +708,25 @@ namespace RacesOfValheim
/// </summary>
private static void RestoreEquipmentVisuals(Player player, VisEquipment visEq)
{
visEq.SetChestItem(EquippedVisualName(player, "m_chestItem"));
visEq.SetLegItem(EquippedVisualName(player, "m_legItem"));
visEq.SetHelmetItem(EquippedVisualName(player, "m_helmetItem"));
visEq.SetChestItem(EquippedVisualHash(player, "m_chestItem"));
visEq.SetLegItem(EquippedVisualHash(player, "m_legItem"));
visEq.SetHelmetItem(EquippedVisualHash(player, "m_helmetItem"));
}
/// <summary>The prefab name VisEquipment wants for an equipped slot, or "" when it is empty.</summary>
private static string EquippedVisualName(Player player, string field)
/// <summary>
/// What VisEquipment has wanted since Valheim 1.0: an item hash instead of a prefab name.
/// 0 is the empty slot - the same value vanilla Humanoid.SetupVisEquipment passes for a
/// slot holding nothing.
/// </summary>
private static int VisualHash(string prefabName) =>
string.IsNullOrEmpty(prefabName) ? 0 : prefabName.GetStableHashCode();
/// <summary>The item hash VisEquipment wants for an equipped slot, or 0 when it is empty.</summary>
private static int EquippedVisualHash(Player player, string field)
{
ItemDrop.ItemData item = Traverse.Create((Humanoid)player).Field<ItemDrop.ItemData>(field).Value;
if (item == null || item.m_dropPrefab == null) return "";
return item.m_dropPrefab.name;
if (item == null || item.m_dropPrefab == null) return 0;
return VisualHash(item.m_dropPrefab.name);
}
private static void TintInstances(object value, int state)