diff --git a/JotunnModStub/Sverm/SvermPatches.cs b/JotunnModStub/Sverm/SvermPatches.cs
index f662304..692a992 100644
--- a/JotunnModStub/Sverm/SvermPatches.cs
+++ b/JotunnModStub/Sverm/SvermPatches.cs
@@ -280,7 +280,13 @@ namespace RacesOfValheim
SvermVisuals.ApplyClaws(__instance); // cleanup of the retired cosmetic path
SvermVisuals.ApplySpines(__instance);
SvermVisuals.ApplyGlideMotes(__instance);
- if (isSverm) SvermVisuals.ApplyCarapace(__instance);
+
+ // Unconditional, like the four above it: ApplyCarapace takes the carapace OFF
+ // whoever is no longer a Sverm, and it cannot do that from behind an
+ // `if (isSverm)`. That gate is why the chitin stayed on after a race change
+ // until the player happened to equip something. For anyone who never wore it
+ // this returns on the first line.
+ SvermVisuals.ApplyCarapace(__instance);
// Issues the claws if they are missing and puts them back in hand whenever
// both hands are free. On the same throttle rather than every frame: it is a
diff --git a/JotunnModStub/Sverm/SvermVisuals.cs b/JotunnModStub/Sverm/SvermVisuals.cs
index 2c51174..9462e5d 100644
--- a/JotunnModStub/Sverm/SvermVisuals.cs
+++ b/JotunnModStub/Sverm/SvermVisuals.cs
@@ -643,6 +643,14 @@ namespace RacesOfValheim
/// Called from the UpdateVisuals postfix rather than once at spawn, because Valheim
/// rebuilds these instances on every equipment change and hands back plain white models.
///
+ ///
+ /// Worn by a player whose three armour slots are currently showing carapace rather than
+ /// whatever they actually have equipped. A marker component rather than a static set of
+ /// players: it dies with the GameObject, so a player who logs out or is destroyed cannot
+ /// leave an entry behind.
+ ///
+ private class CarapaceMark : MonoBehaviour { }
+
public static void ApplyCarapace(Player player)
{
if (player == null) return;
@@ -650,7 +658,29 @@ namespace RacesOfValheim
VisEquipment visEq = player.GetComponent();
if (visEq == null) return;
- if (!IsSvermPlayer(player)) return;
+ if (!IsSvermPlayer(player))
+ {
+ // TAKING IT OFF IS THIS METHOD'S JOB TOO, and for a long time it was nobody's:
+ // this returned here and the only caller was itself behind an `if (isSverm)`, so
+ // the three slots kept showing carapace after the player had stopped being one.
+ // The visuals are a plain override written with SetChestItem and friends, so
+ // nothing in the game corrects them on its own - which is why equipping anything
+ // appeared to "fix" it. That was Valheim's own refresh writing the real gear back
+ // over ours, and until it happened the player wore chitin they no longer had.
+ //
+ // Every other cosmetic in this file already removes itself from whoever is not a
+ // Sverm (ApplyEyes, ApplyClaws, ApplySpines all do); the carapace was the one that
+ // did not.
+ CarapaceMark mark = player.GetComponent();
+ if (mark != null)
+ {
+ Object.Destroy(mark);
+ RestoreEquipmentVisuals(player, visEq);
+ }
+ return;
+ }
+
+ if (player.GetComponent() == null) player.gameObject.AddComponent();
visEq.SetChestItem(SvermConfig.CarapaceChestVisual);
visEq.SetLegItem(SvermConfig.CarapaceLegsVisual);
@@ -663,6 +693,33 @@ namespace RacesOfValheim
TintInstances(Traverse.Create(visEq).Field("m_helmetItemInstance").GetValue(), state);
}
+ ///
+ /// 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
+ /// 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.
+ ///
+ /// Read through Traverse because the equipment fields are not public in the shipped
+ /// assembly, which is the same reason SvermClawSlot reads m_rightItem that way.
+ ///
+ 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"));
+ }
+
+ /// The prefab name VisEquipment wants for an equipped slot, or "" when it is empty.
+ private static string EquippedVisualName(Player player, string field)
+ {
+ ItemDrop.ItemData item = Traverse.Create((Humanoid)player).Field(field).Value;
+ if (item == null || item.m_dropPrefab == null) return "";
+ return item.m_dropPrefab.name;
+ }
+
private static void TintInstances(object value, int state)
{
if (value is GameObject single)