diff --git a/NewHorizons/Builder/General/AstroObjectBuilder.cs b/NewHorizons/Builder/General/AstroObjectBuilder.cs index aec97f75..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; @@ -61,7 +62,9 @@ namespace NewHorizons.Builder.General Delay.RunWhen( () => Locator._centerOfTheUniverse != null, () => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent() - ); + ); + + PreserveActiveCenterOfTheUniverse.Apply(astroObject.gameObject); } return astroObject; 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) 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."); } } 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); + } + } + } +} 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); } 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(); 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); } 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); + } + } + } +} 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" ],