From 8d7f8e8c8aad806c704051d754583e81cc44394c Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sat, 19 Apr 2025 18:38:48 +0800 Subject: [PATCH] UXAssist: fix Night Light again --- UXAssist/Patches/FactoryPatch.cs | 49 ++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 21 deletions(-) diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index 9203598..87042e8 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -233,7 +233,6 @@ public class FactoryPatch : PatchImpl private static bool _mechaOnEarth; private static AnimationState _sail; private static Light _sunlight; - private static StarData _lastStar; protected override void OnEnable() { @@ -247,8 +246,8 @@ public class FactoryPatch : PatchImpl _sunlight.transform.localEulerAngles = new Vector3(0f, 180f); _sunlight = null; } - _lastStar = null; _sail = null; + _mechaOnEarth = false; _nightlightInitialized = false; } @@ -259,8 +258,8 @@ public class FactoryPatch : PatchImpl _sunlight.transform.localEulerAngles = new Vector3(0f, 180f); _sunlight = null; } - _lastStar = null; _sail = null; + _mechaOnEarth = false; _nightlightInitialized = false; } @@ -271,6 +270,20 @@ public class FactoryPatch : PatchImpl GameMain.mainPlayer.transform.right * NightLightAngleY.Value / 10f); } + [HarmonyPostfix] + [HarmonyPatch(typeof(GameData), nameof(GameData.ArriveStar))] + public static void GameData_ArriveStar_Postfix() + { + _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(GameData), nameof(GameData.LeaveStar))] + public static void GameData_LeaveStar_Prefix() + { + _sunlight = null; + } + [HarmonyPostfix] [HarmonyPatch(typeof(GameMain), nameof(GameMain.LateUpdate))] public static void GameMain_LateUpdate_Postfix(GameMain __instance) @@ -281,33 +294,27 @@ public class FactoryPatch : PatchImpl { if (!GameMain.mainPlayer.controller.model.gameObject.activeInHierarchy) return; if (_sail == null) _sail = GameMain.mainPlayer.animator.sails[GameMain.mainPlayer.animator.sailAnimIndex]; + _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; _nightlightInitialized = true; } var sailing = _sail && _sail.enabled; if (_mechaOnEarth) { - if (sailing) + if (!sailing) { - _mechaOnEarth = false; - if (!_sunlight) return; - _sunlight.transform.localEulerAngles = new Vector3(0f, 180f); - _sunlight = null; + UpdateSunlightAngle(); + return; } + _mechaOnEarth = false; + if (!_sunlight) return; + _sunlight.transform.localEulerAngles = new Vector3(0f, 180f); + _sunlight = null; + return; } - else - { - if (sailing) return; - var localStar = GameMain.localStar; - if (!_sunlight || _lastStar != localStar) - { - _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; - if (!_sunlight) return; - _lastStar = localStar; - } - _mechaOnEarth = true; - } - UpdateSunlightAngle(); + + if (sailing) return; + _mechaOnEarth = true; } [HarmonyTranspiler]