From 8f477dd3be5c1c47f890be04334404b6dad2ee17 Mon Sep 17 00:00:00 2001 From: kanym Date: Sat, 26 Sep 2026 18:29:34 +0200 Subject: [PATCH] fix(aswid): Eclipse brings the night instead of dying on its first line The coroutine set EnvMan's two debug-time fields the wrong way round and asked for 0.5, which is noon. Handing a bool to the float field threw, so the cast stopped right after the announcement and IsEclipseActive stayed true, and every later press returned without a word. The fields are now set directly, to midnight, and a finally frees the ability if anything in there throws again. Co-Authored-By: Claude Opus 5.5 --- JotunnModStub/Aswid/AswidRace.cs | 35 +++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index b1f1cd2..b3612bc 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -887,23 +887,34 @@ namespace RacesOfValheim yield return null; } - // Force night client-side - if (EnvMan.instance != null) + // Force night client-side. EnvMan's switch is the bool m_debugTimeOfDay and the time it + // pins is the float m_debugTime, a day fraction where 0 is midnight and 0.5 is noon. + // These two used to be written the other way round: handing a bool to the float threw, + // the coroutine died right after "An Eclipse descends...", and IsEclipseActive stayed + // true for the rest of the session, so every later press returned without a word. + // Public fields both, so no Traverse to get the names wrong through. + try { - HarmonyLib.Traverse.Create(EnvMan.instance).Field("m_debugTime").SetValue(true); - HarmonyLib.Traverse.Create(EnvMan.instance).Field("m_debugTimeOfDay").SetValue(0.5f); // Midnight + if (EnvMan.instance != null) + { + EnvMan.instance.m_debugTime = 0f; + EnvMan.instance.m_debugTimeOfDay = true; + } + + yield return new WaitForSeconds(AswidConfig.EclipseDuration.Value); + } + finally + { + // In a finally so that a throw in here can never again leave the ability locked. + // Unity does not dispose a coroutine it stops, so this does not cover that case. + if (EnvMan.instance != null) EnvMan.instance.m_debugTimeOfDay = false; + IsEclipseActive = false; } - yield return new WaitForSeconds(AswidConfig.EclipseDuration.Value); - - // Revert to server time - if (EnvMan.instance != null) + if (Player.m_localPlayer != null) { - HarmonyLib.Traverse.Create(EnvMan.instance).Field("m_debugTime").SetValue(false); + Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The Eclipse has ended."); } - - IsEclipseActive = false; - Player.m_localPlayer.Message(MessageHud.MessageType.Center, "The Eclipse has ended."); } private float damageTickTimer = 0f;