Skip to content

Commit

Permalink
1.12.4 (#642)
Browse files Browse the repository at this point in the history
## Bug fixes
- Fixes dying on spawn in Evacuation
- Fixes the player seeing objects loading out when changing star system
- Fixes a NRE on reload without the Stranger
- No longer get burned by the sun when spawning in (for real this time)

This time without introducing a bug that breaks systems with only a
single planet!
  • Loading branch information
xen-42 committed Jul 17, 2023
2 parents 97af3b7 + aa9aa8c commit 6557286
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 20 deletions.
5 changes: 4 additions & 1 deletion NewHorizons/Builder/General/AstroObjectBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using NewHorizons.Components;
using NewHorizons.Components.Orbital;
using NewHorizons.External.Configs;
using NewHorizons.Utility.OWML;
Expand Down Expand Up @@ -61,7 +62,9 @@ public static NHAstroObject Make(GameObject body, AstroObject primaryBody, Plane
Delay.RunWhen(
() => Locator._centerOfTheUniverse != null,
() => Locator._centerOfTheUniverse._staticReferenceFrame = astroObject.GetComponent<OWRigidbody>()
);
);

PreserveActiveCenterOfTheUniverse.Apply(astroObject.gameObject);
}

return astroObject;
Expand Down
3 changes: 3 additions & 0 deletions NewHorizons/Builder/General/SpawnPointBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ public static SpawnPoint Make(GameObject planetGO, SpawnModule module, OWRigidbo
ship.GetRequiredComponent<MatchInitialMotion>().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)
Expand Down
2 changes: 1 addition & 1 deletion NewHorizons/Builder/Orbital/InitialMotionBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private static void SetInitialMotion(InitialMotion initialMotion, AstroObject pr
}
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.");
}
}

Expand Down
26 changes: 26 additions & 0 deletions NewHorizons/Components/PreserveActiveCenterOfTheUniverse.cs
Original file line number Diff line number Diff line change
@@ -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<PreserveActiveCenterOfTheUniverse>()._centerOfTheUniverse = center;
}

public void Update()
{
if (!_centerOfTheUniverse.activeInHierarchy)
{
NHLogger.LogWarning("Center of the universe cannot be inactive.");
_centerOfTheUniverse.SetActive(true);
}
}
}
}
4 changes: 3 additions & 1 deletion NewHorizons/Components/Stars/SunLightEffectsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public static void AddStar(StarController star)

public static void RemoveStar(StarController star)
{
if (Instance == null) return;

NHLogger.LogVerbose($"Removing star from list: {star?.gameObject?.name}");
if (Instance._stars.Contains(star))
{
Expand All @@ -74,7 +76,7 @@ public static void AddStarLight(Light light)

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);
}
Expand Down
18 changes: 4 additions & 14 deletions NewHorizons/Handlers/PlanetCreationHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,20 +245,10 @@ public static bool LoadBody(NewHorizonsBody body, bool defaultPrimaryToSun = fal
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<NHAstroObject>();

Expand Down
5 changes: 3 additions & 2 deletions NewHorizons/Handlers/PlanetDestructionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,18 +54,19 @@ public static void RemoveStockPlanets()

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);
if (ao != null) Delay.FireInNUpdates(() => RemoveBody(ao, false), 2);
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);
}

Expand Down
21 changes: 21 additions & 0 deletions NewHorizons/Patches/PlayerPatches/PlayerHazardDetectorPatches.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
}
2 changes: 1 addition & 1 deletion NewHorizons/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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" ],
Expand Down

0 comments on commit 6557286

Please sign in to comment.