From edc7fd33b7ee1aa567ddc4c84cd888a1efb2f0b4 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 17 Oct 2026 16:11:16 +0200 Subject: [PATCH 1/3] debug: F8 dumps the build ghost and the placement ray (temporary) --- JotunnModStub/PlacementGhostDebug.cs | 70 ++++++++++++++++++++++++++++ JotunnModStub/RacesOfValheim.cs | 2 + 2 files changed, 72 insertions(+) create mode 100644 JotunnModStub/PlacementGhostDebug.cs diff --git a/JotunnModStub/PlacementGhostDebug.cs b/JotunnModStub/PlacementGhostDebug.cs new file mode 100644 index 0000000..17fd667 --- /dev/null +++ b/JotunnModStub/PlacementGhostDebug.cs @@ -0,0 +1,70 @@ +using System.Text; +using HarmonyLib; +using UnityEngine; + +namespace RacesOfValheim +{ + /// + /// TEMPORARY DEBUG. F8 dumps the build ghost in hand and what the placement ray hits, to the + /// console and the BepInEx log - for the Trol War Totem, whose ghost stays invisible where every + /// other station's now shows. Remove once that is fixed. + /// + public class PlacementGhostDebug : MonoBehaviour + { + private void Update() + { + if (!Input.GetKeyDown(KeyCode.F8)) return; + + Player player = Player.m_localPlayer; + if (player == null) return; + + var sb = new StringBuilder(); + GameObject ghost = Traverse.Create(player).Field("m_placementGhost").Value; + sb.AppendLine($"[GhostDebug] status={Traverse.Create(player).Field("m_placementStatus").GetValue()} ghost={(ghost != null ? ghost.name : "none")}"); + + Camera cam = GameCamera.instance != null ? GameCamera.instance.GetComponent() : null; + if (GameCamera.instance != null && Physics.Raycast(GameCamera.instance.transform.position, GameCamera.instance.transform.forward, out RaycastHit hit, 50f)) + { + sb.AppendLine($"[GhostDebug] ray hit '{hit.collider.name}' layer={LayerMask.LayerToName(hit.collider.gameObject.layer)} " + + $"dist={hit.distance:0.0} heightmap={(hit.collider.GetComponent() != null)} rigidbody={(hit.collider.attachedRigidbody != null)}"); + } + + if (ghost != null) + { + sb.AppendLine($"[GhostDebug] ghost active={ghost.activeInHierarchy} pos={ghost.transform.position} scale={ghost.transform.lossyScale} " + + $"layer={LayerMask.LayerToName(ghost.layer)} cameraMask has ghost layer={(cam != null && (cam.cullingMask & (1 << ghost.layer)) != 0)}"); + + foreach (LODGroup lod in ghost.GetComponentsInChildren(true)) + { + sb.AppendLine($"[GhostDebug] LODGroup on '{lod.name}' enabled={lod.enabled} active={lod.gameObject.activeInHierarchy} lods={lod.lodCount}"); + } + + foreach (Renderer r in ghost.GetComponentsInChildren(true)) + { + Material m = r.sharedMaterial; + sb.AppendLine($"[GhostDebug] renderer '{PathOf(r.transform, ghost.transform)}' {r.GetType().Name} enabled={r.enabled} " + + $"forceOff={r.forceRenderingOff} active={r.gameObject.activeInHierarchy} visible={r.isVisible} " + + $"layer={LayerMask.LayerToName(r.gameObject.layer)} bounds={r.bounds.size} " + + $"shader={(m != null && m.shader != null ? m.shader.name : "none")}"); + } + } + + string text = sb.ToString(); + Jotunn.Logger.LogInfo(text); + if (Console.instance != null) + { + foreach (string line in text.Split('\n')) + { + if (!string.IsNullOrWhiteSpace(line)) Console.instance.Print(line.TrimEnd()); + } + } + } + + private static string PathOf(Transform t, Transform root) + { + string path = t.name; + for (Transform p = t.parent; p != null && p != root; p = p.parent) path = p.name + "/" + path; + return path; + } + } +} diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index e6f8289..6bb439d 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -69,6 +69,8 @@ namespace RacesOfValheim // Not a race: a perk two races share (Skadi and Trol build inside troll caves), so it // gets its own component rather than living inside either one's Update. gameObject.AddComponent(); + // TEMPORARY DEBUG: F8 dumps the build ghost (Trol War Totem ghost investigation). + gameObject.AddComponent(); PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets; CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand()); CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand()); From e1bd3b66e16e6fc4d2782ac0dda7ea5aa50a555b Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 17 Oct 2026 16:19:03 +0200 Subject: [PATCH 2/3] fix(trol): War Totem ghost invisible everywhere The totem borrowed its look from the GoblinTotem item, whose root holds a ParticleSystem while the mesh sits in its attach child. Player.SetupPlacementGhost switches off every GameObject with a ParticleSystem, so it took the root and the mesh with it: the F8 dump showed TotemModel/model/attach/model active=False on the ghost. The Yagluth head (TrophyGoblinKing) is built the same way. Both now borrow the item's attach child, which is the mesh itself. ModelBorrow switches the copy on, since an item's attach is stored inactive in its prefab. --- JotunnModStub/ModelBorrow.cs | 5 +++++ JotunnModStub/Trol/TrolTotem.cs | 19 +++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/JotunnModStub/ModelBorrow.cs b/JotunnModStub/ModelBorrow.cs index b064361..20b2ded 100644 --- a/JotunnModStub/ModelBorrow.cs +++ b/JotunnModStub/ModelBorrow.cs @@ -89,6 +89,11 @@ namespace RacesOfValheim copy.transform.localRotation = localRotation; copy.transform.localScale = Vector3.one; + // An item's "attach" child is stored switched off in its prefab (VisEquipment turns it on + // when it is worn), so a copy of one comes out switched off too. The holder above is still + // inactive, so turning the copy on wakes nothing. + if (!copy.activeSelf) copy.SetActive(true); + // Everything that is not a Renderer or a Transform. Order matters for the same reason it did // on the Aswid's lights: behaviours first, then the things they hold references to. foreach (MonoBehaviour behaviour in copy.GetComponentsInChildren(true)) diff --git a/JotunnModStub/Trol/TrolTotem.cs b/JotunnModStub/Trol/TrolTotem.cs index 5bd38f8..f3d567f 100644 --- a/JotunnModStub/Trol/TrolTotem.cs +++ b/JotunnModStub/Trol/TrolTotem.cs @@ -239,7 +239,7 @@ namespace RacesOfValheim // The look the player asked for: the totem itself, not a log with a head on it. Grounded on // its own base, so Vector3.zero really is "standing on the spot the hammer picked". - GameObject totemModel = ModelBorrow.Attach(prefab.transform, "TotemModel", "GoblinTotem", + GameObject totemModel = ModelBorrow.Attach(prefab.transform, "TotemModel", ItemMesh("GoblinTotem"), Vector3.zero, Quaternion.identity, TotemHeight, "Trol"); TrolTotemBehaviour totem = prefab.AddComponent(); @@ -293,7 +293,7 @@ namespace RacesOfValheim Jotunn.Logger.LogInfo($"[Trol] Totem crown measured at {crown:0.##} m; the king's head is " + $"{HeadSize} m across and sunk {HeadSize * HeadSink:0.##} m into it."); - totem.m_yagluthHead = ModelBorrow.Attach(prefab.transform, "TotemHeadYagluth", YagluthHead, + totem.m_yagluthHead = ModelBorrow.Attach(prefab.transform, "TotemHeadYagluth", ItemMesh(YagluthHead), new Vector3(0f, crown - HeadSize * HeadSink, 0f), HeadTilt, HeadSize, "Trol"); totem.m_yagluthHead.SetActive(false); @@ -329,6 +329,21 @@ namespace RacesOfValheim })); } + /// + /// The part of an item that IS the item: its "attach" child, which holds the mesh, rather than + /// the whole prefab. GoblinTotem carries a ParticleSystem on its root, and + /// Player.SetupPlacementGhost switches off every GameObject that has one - taking the root and, + /// with it, the mesh underneath. That is why the War Totem showed no ghost anywhere while every + /// other station did. TrophyGoblinKing is built the same way. Falls back to the whole prefab + /// for an item without an attach. + /// + private static GameObject ItemMesh(string itemPrefab) + { + GameObject source = PrefabManager.Cache.GetPrefab(itemPrefab); + Transform attach = source != null ? source.transform.Find("attach") : null; + return attach != null ? attach.gameObject : source; + } + public static void EnsureKnown(Player player) { if (player == null) return; From 0cc10b437e41642f6e6f35de1009ee8ada314dd5 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 17 Oct 2026 16:21:50 +0200 Subject: [PATCH 3/3] Revert "debug: F8 dumps the build ghost and the placement ray (temporary)" This reverts commit edc7fd33b7ee1aa567ddc4c84cd888a1efb2f0b4. --- JotunnModStub/PlacementGhostDebug.cs | 70 ---------------------------- JotunnModStub/RacesOfValheim.cs | 2 - 2 files changed, 72 deletions(-) delete mode 100644 JotunnModStub/PlacementGhostDebug.cs diff --git a/JotunnModStub/PlacementGhostDebug.cs b/JotunnModStub/PlacementGhostDebug.cs deleted file mode 100644 index 17fd667..0000000 --- a/JotunnModStub/PlacementGhostDebug.cs +++ /dev/null @@ -1,70 +0,0 @@ -using System.Text; -using HarmonyLib; -using UnityEngine; - -namespace RacesOfValheim -{ - /// - /// TEMPORARY DEBUG. F8 dumps the build ghost in hand and what the placement ray hits, to the - /// console and the BepInEx log - for the Trol War Totem, whose ghost stays invisible where every - /// other station's now shows. Remove once that is fixed. - /// - public class PlacementGhostDebug : MonoBehaviour - { - private void Update() - { - if (!Input.GetKeyDown(KeyCode.F8)) return; - - Player player = Player.m_localPlayer; - if (player == null) return; - - var sb = new StringBuilder(); - GameObject ghost = Traverse.Create(player).Field("m_placementGhost").Value; - sb.AppendLine($"[GhostDebug] status={Traverse.Create(player).Field("m_placementStatus").GetValue()} ghost={(ghost != null ? ghost.name : "none")}"); - - Camera cam = GameCamera.instance != null ? GameCamera.instance.GetComponent() : null; - if (GameCamera.instance != null && Physics.Raycast(GameCamera.instance.transform.position, GameCamera.instance.transform.forward, out RaycastHit hit, 50f)) - { - sb.AppendLine($"[GhostDebug] ray hit '{hit.collider.name}' layer={LayerMask.LayerToName(hit.collider.gameObject.layer)} " + - $"dist={hit.distance:0.0} heightmap={(hit.collider.GetComponent() != null)} rigidbody={(hit.collider.attachedRigidbody != null)}"); - } - - if (ghost != null) - { - sb.AppendLine($"[GhostDebug] ghost active={ghost.activeInHierarchy} pos={ghost.transform.position} scale={ghost.transform.lossyScale} " + - $"layer={LayerMask.LayerToName(ghost.layer)} cameraMask has ghost layer={(cam != null && (cam.cullingMask & (1 << ghost.layer)) != 0)}"); - - foreach (LODGroup lod in ghost.GetComponentsInChildren(true)) - { - sb.AppendLine($"[GhostDebug] LODGroup on '{lod.name}' enabled={lod.enabled} active={lod.gameObject.activeInHierarchy} lods={lod.lodCount}"); - } - - foreach (Renderer r in ghost.GetComponentsInChildren(true)) - { - Material m = r.sharedMaterial; - sb.AppendLine($"[GhostDebug] renderer '{PathOf(r.transform, ghost.transform)}' {r.GetType().Name} enabled={r.enabled} " + - $"forceOff={r.forceRenderingOff} active={r.gameObject.activeInHierarchy} visible={r.isVisible} " + - $"layer={LayerMask.LayerToName(r.gameObject.layer)} bounds={r.bounds.size} " + - $"shader={(m != null && m.shader != null ? m.shader.name : "none")}"); - } - } - - string text = sb.ToString(); - Jotunn.Logger.LogInfo(text); - if (Console.instance != null) - { - foreach (string line in text.Split('\n')) - { - if (!string.IsNullOrWhiteSpace(line)) Console.instance.Print(line.TrimEnd()); - } - } - } - - private static string PathOf(Transform t, Transform root) - { - string path = t.name; - for (Transform p = t.parent; p != null && p != root; p = p.parent) path = p.name + "/" + path; - return path; - } - } -} diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index 6bb439d..e6f8289 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -69,8 +69,6 @@ namespace RacesOfValheim // Not a race: a perk two races share (Skadi and Trol build inside troll caves), so it // gets its own component rather than living inside either one's Update. gameObject.AddComponent(); - // TEMPORARY DEBUG: F8 dumps the build ghost (Trol War Totem ghost investigation). - gameObject.AddComponent(); PrefabManager.OnVanillaPrefabsAvailable += CreateAllModAssets; CommandManager.Instance.AddConsoleCommand(new ResetRaceCommand()); CommandManager.Instance.AddConsoleCommand(new CheckProgressionCommand());