From 7a400e2046fb7b05e8db1ae2e9cf85cd586e4f54 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 11:48:37 -0400 Subject: [PATCH 01/11] throw error better when planet null --- NewHorizons/Handlers/PlanetCreationHandler.cs | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 8a9129cf..98d55efa 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -245,20 +245,10 @@ namespace NewHorizons.Handlers try { NHLogger.Log($"Creating [{body.Config.name}]"); - var planetObject = GenerateBody(body, defaultPrimaryToSun); - try - { - planetObject?.SetActive(true); - } - catch (Exception e) - { - NHLogger.LogError($"Error when activating new planet [{body.Config.name}] - {e}"); - } - if (planetObject == null) - { - body.UnloadCache(); - return false; - } + var planetObject = GenerateBody(body, defaultPrimaryToSun) + ?? throw new NullReferenceException("Something went wrong when generating the body but no errors were logged."); + + planetObject.SetActive(true); var ao = planetObject.GetComponent(); From f8fa30eb664482ec18fe1963d3d369ffc720c4b0 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 12:59:58 -0400 Subject: [PATCH 02/11] Improve an error message --- NewHorizons/Builder/Orbital/InitialMotionBuilder.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs b/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs index 71fae84a..c6405bd9 100644 --- a/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs +++ b/NewHorizons/Builder/Orbital/InitialMotionBuilder.cs @@ -80,7 +80,7 @@ namespace NewHorizons.Builder.Orbital } else { - NHLogger.LogError($"No primary gravity or focal point for {primaryBody}"); + NHLogger.LogError($"Trying to put {secondaryBody.name} around {primaryBody.name} but found no primary gravity or focal point."); } } From 3887dde13e8277cf2e820aa25f457312ea4b6170 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 13:00:14 -0400 Subject: [PATCH 03/11] I can't see why it's being disabled but it should never happen so --- NewHorizons/Builder/General/AstroObjectBuilder.cs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index aec97f75..dfa81e3c 100644 --- a/NewHorizons/Builder/General/AstroObjectBuilder.cs +++ b/NewHorizons/Builder/General/AstroObjectBuilder.cs @@ -60,11 +60,24 @@ namespace NewHorizons.Builder.General Delay.RunWhen( () => Locator._centerOfTheUniverse != null, - () => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent() + () => { + Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent(); + } ); + + NeverDeactivateCenterOfTheUniverse(astroObject.gameObject); } return astroObject; } + + private static void NeverDeactivateCenterOfTheUniverse(GameObject centerOfTheUniverse) + { + NHLogger.LogVerbose("Center of the universe cannot be inactive."); + centerOfTheUniverse.SetActive(true); + Delay.RunWhen(() => !centerOfTheUniverse.activeInHierarchy, () => { + NeverDeactivateCenterOfTheUniverse(centerOfTheUniverse); + }); + } } } From 44b6df04d2aee2a2478ef33262bb49bff78dc62c Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 13:05:41 -0400 Subject: [PATCH 04/11] Update manifest.json --- NewHorizons/manifest.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NewHorizons/manifest.json b/NewHorizons/manifest.json index 2e669fbc..2ab0644b 100644 --- a/NewHorizons/manifest.json +++ b/NewHorizons/manifest.json @@ -4,7 +4,7 @@ "author": "xen, Bwc9876, clay, MegaPiggy, John, Trifid, Hawkbar, Book", "name": "New Horizons", "uniqueName": "xen.NewHorizons", - "version": "1.12.3", + "version": "1.12.4", "owmlVersion": "2.9.3", "dependencies": [ "JohnCorby.VanillaFix", "_nebula.MenuFramework", "xen.CommonCameraUtility", "dgarro.CustomShipLogModes" ], "conflicts": [ "Raicuparta.QuantumSpaceBuddies", "PacificEngine.OW_CommonResources" ], From cffc0632694e11669944e368f75113a445f1e581 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 13:38:33 -0400 Subject: [PATCH 05/11] Use a component instead of silly delay --- .../Builder/General/AstroObjectBuilder.cs | 18 +++---------- .../PreserveActiveCenterOfTheUniverse.cs | 26 +++++++++++++++++++ 2 files changed, 30 insertions(+), 14 deletions(-) create mode 100644 NewHorizons/Components/PreserveActiveCenterOfTheUniverse.cs diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index dfa81e3c..8278d056 100644 --- a/NewHorizons/Builder/General/AstroObjectBuilder.cs +++ b/NewHorizons/Builder/General/AstroObjectBuilder.cs @@ -1,3 +1,4 @@ +using NewHorizons.Components; using NewHorizons.Components.Orbital; using NewHorizons.External.Configs; using NewHorizons.Utility.OWML; @@ -60,24 +61,13 @@ namespace NewHorizons.Builder.General Delay.RunWhen( () => Locator._centerOfTheUniverse != null, - () => { - Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent(); - } - ); + () => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent() + ); - NeverDeactivateCenterOfTheUniverse(astroObject.gameObject); + PreserveActiveCenterOfTheUniverse.Apply(astroObject.gameObject); } return astroObject; } - - private static void NeverDeactivateCenterOfTheUniverse(GameObject centerOfTheUniverse) - { - NHLogger.LogVerbose("Center of the universe cannot be inactive."); - centerOfTheUniverse.SetActive(true); - Delay.RunWhen(() => !centerOfTheUniverse.activeInHierarchy, () => { - NeverDeactivateCenterOfTheUniverse(centerOfTheUniverse); - }); - } } } diff --git a/NewHorizons/Components/PreserveActiveCenterOfTheUniverse.cs b/NewHorizons/Components/PreserveActiveCenterOfTheUniverse.cs new file mode 100644 index 00000000..0e8cd3c0 --- /dev/null +++ b/NewHorizons/Components/PreserveActiveCenterOfTheUniverse.cs @@ -0,0 +1,26 @@ +using NewHorizons.Utility.OWML; +using UnityEngine; + +namespace NewHorizons.Components +{ + // Prevents the center of the universe being deactivated + public class PreserveActiveCenterOfTheUniverse : MonoBehaviour + { + private GameObject _centerOfTheUniverse; + + public static void Apply(GameObject center) + { + var go = new GameObject(nameof(PreserveActiveCenterOfTheUniverse)); + go.AddComponent()._centerOfTheUniverse = center; + } + + public void Update() + { + if (!_centerOfTheUniverse.activeInHierarchy) + { + NHLogger.LogWarning("Center of the universe cannot be inactive."); + _centerOfTheUniverse.SetActive(true); + } + } + } +} From 09ddb2f78008d3a2f6ad704c7b11afa4d1f2e4c5 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 14:04:52 -0400 Subject: [PATCH 06/11] Make sure ship is activated --- NewHorizons/Builder/General/SpawnPointBuilder.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/NewHorizons/Builder/General/SpawnPointBuilder.cs b/NewHorizons/Builder/General/SpawnPointBuilder.cs index a4a12f74..4ae1084b 100644 --- a/NewHorizons/Builder/General/SpawnPointBuilder.cs +++ b/NewHorizons/Builder/General/SpawnPointBuilder.cs @@ -65,6 +65,9 @@ namespace NewHorizons.Builder.General ship.GetRequiredComponent().SetBodyToMatch(owRigidBody); } spawnGO.SetActive(true); + + // Ship doesn't get activated sometimes + Delay.RunWhen(() => Main.IsSystemReady, () => ship.gameObject.SetActive(true)); } if ((Main.Instance.IsWarpingFromVessel || (!Main.Instance.IsWarpingFromShip && (module.playerSpawn?.startWithSuit ?? false))) && !suitUpQueued) From be9df727565364f85e9a6b5d53d06c2e45651d17 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 14:05:15 -0400 Subject: [PATCH 07/11] Remove stock planets immediately since we use SearchUtility anyway --- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 ++-- NewHorizons/Handlers/PlanetDestructionHandler.cs | 9 +-------- 2 files changed, 3 insertions(+), 10 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 8a9129cf..73d814a5 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -32,6 +32,8 @@ namespace NewHorizons.Handlers public static void Init(List bodies) { + if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveStockPlanets(); + Main.FurthestOrbit = 30000; _existingBodyDict = new(); @@ -135,8 +137,6 @@ namespace NewHorizons.Handlers SingularityBuilder.PairAllSingularities(); // Events.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies); - - if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveStockPlanets(); } public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 4a752848..304881a7 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -54,19 +54,12 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { - // Stop the sun from killing the player - var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); - sunVolumes.SetActive(false); - foreach (var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); - if (ao != null) Delay.FireInNUpdates(() => RemoveBody(ao, false), 2); + if (ao != null) RemoveBody(ao, false); else NHLogger.LogError($"Couldn't find [{name}]"); } - - // Bring the sun back because why not - Delay.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3); } public static void RemoveEyeOfTheUniverse() From 25b3c422eee3176edc709bbf1fdbda71b14ffcd2 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 14:16:28 -0400 Subject: [PATCH 08/11] Fix player burning when spawning --- .../PlayerHazardDetectorPatches.cs | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 NewHorizons/Patches/PlayerPatches/PlayerHazardDetectorPatches.cs diff --git a/NewHorizons/Patches/PlayerPatches/PlayerHazardDetectorPatches.cs b/NewHorizons/Patches/PlayerPatches/PlayerHazardDetectorPatches.cs new file mode 100644 index 00000000..032f8f9b --- /dev/null +++ b/NewHorizons/Patches/PlayerPatches/PlayerHazardDetectorPatches.cs @@ -0,0 +1,21 @@ +using HarmonyLib; +using NewHorizons.Utility.OWML; + +namespace NewHorizons.Patches.PlayerPatches +{ + [HarmonyPatch(typeof(HazardDetector))] + public static class PlayerHazardDetectorPatches + { + [HarmonyPostfix] + [HarmonyPatch(nameof(HazardDetector.Awake))] + public static void HazardDetector_Awake(HazardDetector __instance) + { + // Prevent the player detector from being hurt while the solar system is being set up + if (__instance._isPlayerDetector && !Main.IsSystemReady) + { + __instance.enabled = false; + Delay.RunWhen(() => Main.IsSystemReady, () => __instance.enabled = true); + } + } + } +} From c8f0d9c753ead86aa2f78cab3279548f9973fa54 Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 14:58:41 -0400 Subject: [PATCH 09/11] Fix some NREs with the sun --- NewHorizons/Components/Stars/SunLightEffectsController.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/NewHorizons/Components/Stars/SunLightEffectsController.cs b/NewHorizons/Components/Stars/SunLightEffectsController.cs index 904bdf6a..22bde0f2 100644 --- a/NewHorizons/Components/Stars/SunLightEffectsController.cs +++ b/NewHorizons/Components/Stars/SunLightEffectsController.cs @@ -49,6 +49,8 @@ namespace NewHorizons.Components.Stars public static void RemoveStar(StarController star) { + if (Instance == null) return; + NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}"); if (Instance._stars.Contains(star)) { @@ -74,7 +76,7 @@ namespace NewHorizons.Components.Stars public static void RemoveStarLight(Light light) { - if (light != null && Instance._lights.Contains(light)) + if (Instance != null && light != null && Instance._lights.Contains(light)) { Instance._lights.Remove(light); } From db3785f2f43af3a1f97a652e581aa9741281f8ba Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 16:37:56 -0400 Subject: [PATCH 10/11] Revert "Remove stock planets immediately since we use SearchUtility anyway" This reverts commit be9df727565364f85e9a6b5d53d06c2e45651d17. --- NewHorizons/Handlers/PlanetCreationHandler.cs | 4 ++-- NewHorizons/Handlers/PlanetDestructionHandler.cs | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/NewHorizons/Handlers/PlanetCreationHandler.cs b/NewHorizons/Handlers/PlanetCreationHandler.cs index 0379a982..98d55efa 100644 --- a/NewHorizons/Handlers/PlanetCreationHandler.cs +++ b/NewHorizons/Handlers/PlanetCreationHandler.cs @@ -32,8 +32,6 @@ namespace NewHorizons.Handlers public static void Init(List bodies) { - if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveStockPlanets(); - Main.FurthestOrbit = 30000; _existingBodyDict = new(); @@ -137,6 +135,8 @@ namespace NewHorizons.Handlers SingularityBuilder.PairAllSingularities(); // Events.FireOnNextUpdate(PlanetDestroyer.RemoveAllProxies); + + if (Main.SystemDict[Main.Instance.CurrentStarSystem].Config.destroyStockPlanets) PlanetDestructionHandler.RemoveStockPlanets(); } public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = false) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 304881a7..4a752848 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -54,12 +54,19 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { + // Stop the sun from killing the player + var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); + sunVolumes.SetActive(false); + foreach (var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); - if (ao != null) RemoveBody(ao, false); + if (ao != null) Delay.FireInNUpdates(() => RemoveBody(ao, false), 2); else NHLogger.LogError($"Couldn't find [{name}]"); } + + // Bring the sun back because why not + Delay.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3); } public static void RemoveEyeOfTheUniverse() From aa9aa8c9c61ad6b848d72f79257cc41c781e856d Mon Sep 17 00:00:00 2001 From: Nick Date: Sun, 16 Jul 2023 18:12:25 -0400 Subject: [PATCH 11/11] Comments --- NewHorizons/Handlers/PlanetDestructionHandler.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/NewHorizons/Handlers/PlanetDestructionHandler.cs b/NewHorizons/Handlers/PlanetDestructionHandler.cs index 4a752848..a5f7add7 100644 --- a/NewHorizons/Handlers/PlanetDestructionHandler.cs +++ b/NewHorizons/Handlers/PlanetDestructionHandler.cs @@ -54,10 +54,11 @@ namespace NewHorizons.Handlers public static void RemoveSolarSystem() { - // Stop the sun from killing the player + // Stop the sun from killing the player if they spawn at the center of the solar system var sunVolumes = SearchUtilities.Find("Sun_Body/Sector_SUN/Volumes_SUN"); sunVolumes.SetActive(false); + // Random shit breaks if we don't wait idk why foreach (var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); @@ -65,7 +66,7 @@ namespace NewHorizons.Handlers else NHLogger.LogError($"Couldn't find [{name}]"); } - // Bring the sun back because why not + // Bring the sun back Delay.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 3); }