From 0668d59a9b11b543c9fb2a91caba1aa745dd4c12 Mon Sep 17 00:00:00 2001 From: kanym Date: Fri, 13 Nov 2026 17:07:45 +0100 Subject: [PATCH] feat(debug): Debug config section; debug key rebindable and off by default; Log Form Hits moved from Fenrir; dead Skeleton F8 helpers removed Requested by Dagaz. --- JotunnModStub/DebugConfig.cs | 32 +++++++++ JotunnModStub/Fenrir/FenrirConfig.cs | 7 -- JotunnModStub/Fenrir/FenrirFormShared.cs | 6 +- JotunnModStub/RaceMeleeReach.cs | 5 +- JotunnModStub/RacesOfValheim.cs | 2 + JotunnModStub/Skeleton/SkeletonRace.cs | 91 ------------------------ 6 files changed, 40 insertions(+), 103 deletions(-) create mode 100644 JotunnModStub/DebugConfig.cs diff --git a/JotunnModStub/DebugConfig.cs b/JotunnModStub/DebugConfig.cs new file mode 100644 index 0000000..ae763e0 --- /dev/null +++ b/JotunnModStub/DebugConfig.cs @@ -0,0 +1,32 @@ +using UnityEngine; +using BepInEx.Configuration; + +namespace RacesOfValheim +{ + /// + /// The mod-wide debug switches, in one "Debug" section rather than one per race. Bound last + /// from RacesOfValheim.Awake(), so Configuration Manager lists the section at the bottom. + /// + /// Every entry stays local (never synced from the server): ConfigSync leaves KeyboardShortcut + /// entries and any key containing "debug" alone, so keep "Debug" in the key names. + /// + public static class DebugConfig + { + public static ConfigEntry EnableDebugKey; + public static ConfigEntry DebugKey; + public static ConfigEntry LogFormHits; + + public static void Bind(ConfigFile config) + { + const string section = "Debug"; + EnableDebugKey = config.Bind(section, "Debug: Enable Debug Key", false, + new ConfigDescription("Turns on the debug key below. Leave it off unless you are sending a bug report.")); + DebugKey = config.Bind(section, "Debug Key", new KeyboardShortcut(KeyCode.F8), + new ConfigDescription("Toggles the melee reach readout (top left and log) and writes what the Alfar drones and the camera's target are doing to the log.")); + // Was "Fenrir - Debug" / "Debug: Log Form Hits" until v1.6.10. It covers the Skadi, + // Sverm and Trol forms too (FormMelee.LogHit), so it moved here. + LogFormHits = config.Bind(section, "Debug: Log Form Hits", false, + new ConfigDescription("Writes one log line per form claw, bite or swing: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage.")); + } + } +} diff --git a/JotunnModStub/Fenrir/FenrirConfig.cs b/JotunnModStub/Fenrir/FenrirConfig.cs index 78a2c48..2190a36 100644 --- a/JotunnModStub/Fenrir/FenrirConfig.cs +++ b/JotunnModStub/Fenrir/FenrirConfig.cs @@ -100,9 +100,6 @@ namespace RacesOfValheim public static ConfigEntry UlvAttackRadius; public static ConfigEntry UlvPushForce; - // ─── Debug ───────────────────────────────────────────────────────────── - public static ConfigEntry DebugFormHits; - // ─── Appearance (per player, never synced) ────────────────────────────── public static ConfigEntry ReadyMessage; public static ConfigEntry EyeGlow; @@ -268,10 +265,6 @@ namespace RacesOfValheim // Tried at 1.2 in game: the orange was too strong. 0.9 checked and kept. EyeReadyStrength = config.Bind(appearance, "Eye Ready Strength", 0.9f, new ConfigDescription("Glow at night while a form is ready.", new AcceptableValueRange(0f, 3f))); - - // "debug" in the key keeps it local - see ConfigSync. - DebugFormHits = config.Bind("Fenrir - Debug", "Debug: Log Form Hits", false, - new ConfigDescription("Writes one log line per claw or bite: what was in reach, what it hit, and why anything was skipped. For bug reports about attacks that do no damage.")); } /// diff --git a/JotunnModStub/Fenrir/FenrirFormShared.cs b/JotunnModStub/Fenrir/FenrirFormShared.cs index 656f761..bcd9c27 100644 --- a/JotunnModStub/Fenrir/FenrirFormShared.cs +++ b/JotunnModStub/Fenrir/FenrirFormShared.cs @@ -342,7 +342,7 @@ namespace RacesOfValheim /// public static void LogMiss(string form, Collider hit, string reason) { - if (!FenrirConfig.DebugFormHits.Value) return; + if (!DebugConfig.LogFormHits.Value) return; Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing skipped '{hit.name}' (layer {LayerMask.LayerToName(hit.gameObject.layer)}): {reason}."); } @@ -436,14 +436,14 @@ namespace RacesOfValheim public static void LogHit(string form, IDestructible target, float damage) { - if (!FenrirConfig.DebugFormHits.Value) return; + if (!DebugConfig.LogFormHits.Value) return; string name = target is MonoBehaviour behaviour && behaviour != null ? behaviour.name : target.ToString(); Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing hit '{name}' for {damage:0}."); } public static void LogSwing(string form, int candidates) { - if (!FenrirConfig.DebugFormHits.Value) return; + if (!DebugConfig.LogFormHits.Value) return; Jotunn.Logger.LogInfo($"[FenrirForm] {form} swing: {candidates} collider(s) in reach."); } } diff --git a/JotunnModStub/RaceMeleeReach.cs b/JotunnModStub/RaceMeleeReach.cs index 052a2ff..4bb0331 100644 --- a/JotunnModStub/RaceMeleeReach.cs +++ b/JotunnModStub/RaceMeleeReach.cs @@ -115,13 +115,14 @@ namespace RacesOfValheim } } - /// F8 turns the reach readout on and off. + /// The debug key (DebugConfig, F8 by default) turns the reach readout on and off. [HarmonyPatch(typeof(Player), "Update")] internal static class RaceMeleeReachDebugKey { private static void Postfix(Player __instance) { - if (__instance != Player.m_localPlayer || !Input.GetKeyDown(KeyCode.F8)) return; + if (__instance != Player.m_localPlayer || !DebugConfig.EnableDebugKey.Value) return; + if (!DebugConfig.DebugKey.Value.IsDownIgnoringHeldKeys()) return; RaceMeleeReach.DebugOn = !RaceMeleeReach.DebugOn; __instance.Message(MessageHud.MessageType.TopLeft, $"[RoV reach] debug {(RaceMeleeReach.DebugOn ? "on" : "off")}"); AlfarMiner.DebugReport(__instance); diff --git a/JotunnModStub/RacesOfValheim.cs b/JotunnModStub/RacesOfValheim.cs index de1ae6e..f9cb049 100644 --- a/JotunnModStub/RacesOfValheim.cs +++ b/JotunnModStub/RacesOfValheim.cs @@ -57,6 +57,8 @@ namespace RacesOfValheim // Not a race either: the faction truce and the faction merchants, which cut across // every race at once, so they bind last rather than inside the alphabetical run above. FactionsConfig.Bind(Config); + // The mod-wide debug switches, at the bottom of the list on purpose. + DebugConfig.Bind(Config); // After every Bind above: tags the gameplay entries for Jotunn's server-to-client sync. ConfigSync.Apply(Config); harmony.PatchAll(); diff --git a/JotunnModStub/Skeleton/SkeletonRace.cs b/JotunnModStub/Skeleton/SkeletonRace.cs index ab73c15..47b359e 100644 --- a/JotunnModStub/Skeleton/SkeletonRace.cs +++ b/JotunnModStub/Skeleton/SkeletonRace.cs @@ -252,97 +252,6 @@ namespace RacesOfValheim return bestCombo; } - private void DumpTransformHierarchy(Transform t, string indent) - { - if (t == null) return; - Jotunn.Logger.LogInfo(indent + t.name + " (Active: " + t.gameObject.activeSelf + ")"); - for(int i = 0; i < t.childCount; i++) - { - DumpTransformHierarchy(t.GetChild(i), indent + " "); - } - } - - /// - /// F8 debug: fires a ray from the camera and logs whatever it hits. Cosmetic pieces - /// (hair, beard, helmet) carry no collider, so this mostly confirms terrain/creature hits - /// - LogHeadCosmeticsState below is what actually answers "what is that floating chunk." - /// Kept anyway because it is the general-purpose "what am I looking at" tool for any other - /// bone or prefab placement question that comes up later. - /// - private void LogRaycastHit() - { - Camera cam = Camera.main; - if (cam == null) - { - Jotunn.Logger.LogInfo("[F8] No camera found for raycast."); - return; - } - - Ray ray = new Ray(cam.transform.position, cam.transform.forward); - if (Physics.Raycast(ray, out RaycastHit hit, 50f)) - { - Jotunn.Logger.LogInfo("--- F8 RAYCAST HIT ---"); - Jotunn.Logger.LogInfo($"Collider: '{hit.collider.gameObject.name}' at {hit.point:F2}, distance={hit.distance:F2}"); - Jotunn.Logger.LogInfo($"Full path: {GetFullPath(hit.collider.transform)}"); - Renderer renderer = hit.collider.GetComponentInParent(); - if (renderer != null) - { - Jotunn.Logger.LogInfo($"Nearest renderer: '{renderer.gameObject.name}' ({renderer.GetType().Name}), enabled={renderer.enabled}, scale={renderer.transform.lossyScale:F3}"); - } - Jotunn.Logger.LogInfo("----------------------"); - } - else - { - Jotunn.Logger.LogInfo("[F8] Raycast hit nothing within 50m (cosmetic pieces usually have no collider anyway)."); - } - } - - private static string GetFullPath(Transform t) - { - string path = t.name; - for (Transform parent = t.parent; parent != null; parent = parent.parent) - { - path = parent.name + "/" + path; - } - return path; - } - - /// - /// F8 debug: dumps the exact state of the three item slots this race hides (hair, beard, - /// helmet) - active flag, renderer enabled flag and scale for every renderer underneath. - /// This is the direct answer to "what is still visible and why": a chunk that survives - /// hiding will show up here as active=true, or as a renderer with enabled=true even while - /// its wrapper is scaled to zero (the skinned-mesh case scale alone cannot hide). - /// - private void LogHeadCosmeticsState() - { - if (Player.m_localPlayer == null) return; - VisEquipment vis = Player.m_localPlayer.GetComponent(); - if (vis == null) return; - - Jotunn.Logger.LogInfo("--- F8 SKELETON HEAD COSMETICS ---"); - DumpItemInstanceField(vis, "m_hairItemInstance"); - DumpItemInstanceField(vis, "m_beardItemInstance"); - DumpItemInstanceField(vis, "m_helmetItemInstance"); - Jotunn.Logger.LogInfo("----------------------------------"); - } - - private static void DumpItemInstanceField(VisEquipment vis, string fieldName) - { - GameObject go = HarmonyLib.Traverse.Create(vis).Field(fieldName).Value; - if (go == null) - { - Jotunn.Logger.LogInfo($"[F8] {fieldName}: null (nothing equipped/instantiated)."); - return; - } - - Jotunn.Logger.LogInfo($"[F8] {fieldName}: '{go.name}' active={go.activeSelf} scale={go.transform.localScale:F3}"); - foreach (Renderer r in go.GetComponentsInChildren(true)) - { - Jotunn.Logger.LogInfo($"[F8] renderer '{r.gameObject.name}' ({r.GetType().Name}) enabled={r.enabled}"); - } - } - private void Update() { if (Player.m_localPlayer == null) return;