From edc7fd33b7ee1aa567ddc4c84cd888a1efb2f0b4 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 17 Oct 2026 16:11:16 +0200 Subject: [PATCH] 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());