diff --git a/NewHorizons/Main.cs b/NewHorizons/Main.cs index 0174b754..970c514f 100644 --- a/NewHorizons/Main.cs +++ b/NewHorizons/Main.cs @@ -47,7 +47,8 @@ namespace NewHorizons public static bool IsSystemReady { get; private set; } public static float FurthestOrbit { get; set; } = 50000f; - public string CurrentStarSystem { get { return Instance._currentStarSystem; } } + public string DefaultStarSystem => SystemDict.Keys.Contains(_defaultSystemOverride) ? _defaultSystemOverride : _defaultStarSystem; + public string CurrentStarSystem => _currentStarSystem; public bool IsWarpingFromShip { get; private set; } = false; public bool IsWarpingFromVessel { get; private set; } = false; public bool WearingSuit { get; private set; } = false; @@ -227,6 +228,12 @@ namespace NewHorizons { Logger.LogVerbose($"Scene Loaded: {scene.name} {mode}"); + if (!SystemDict.ContainsKey(_currentStarSystem) || !BodyDict.ContainsKey(_currentStarSystem)) + { + Logger.LogError($"System \"{_currentStarSystem}\" does not exist!"); + _currentStarSystem = DefaultStarSystem; + } + // Set time loop stuff if its enabled and if we're warping to a new place if (IsChangingStarSystem && (SystemDict[_currentStarSystem].Config.enableTimeLoop || _currentStarSystem == "SolarSystem") && SecondsLeftInLoop > 0f) { diff --git a/NewHorizons/Patches/ShipLogPatches.cs b/NewHorizons/Patches/ShipLogPatches.cs index 306b53a9..7901dc87 100644 --- a/NewHorizons/Patches/ShipLogPatches.cs +++ b/NewHorizons/Patches/ShipLogPatches.cs @@ -21,8 +21,17 @@ namespace NewHorizons.Patches { RumorModeBuilder.Init(); ShipLogHandler.Init(); - Logger.Log($"Beginning Ship Log Generation For: {Main.Instance.CurrentStarSystem}"); - if (Main.Instance.CurrentStarSystem != "SolarSystem") + + var currentStarSystem = Main.Instance.CurrentStarSystem; + + if (!Main.SystemDict.ContainsKey(currentStarSystem) || !Main.BodyDict.ContainsKey(currentStarSystem)) + { + currentStarSystem = Main.Instance.DefaultStarSystem; + } + + Logger.Log($"Beginning Ship Log Generation For: {currentStarSystem}"); + + if (currentStarSystem != "SolarSystem") { __instance._shipLogXmlAssets = new TextAsset[] { }; foreach (ShipLogEntryLocation logEntryLocation in GameObject.FindObjectsOfType()) @@ -31,13 +40,13 @@ namespace NewHorizons.Patches } } - var curiosities = Main.SystemDict[Main.Instance.CurrentStarSystem].Config.curiosities; + var curiosities = Main.SystemDict[currentStarSystem].Config.curiosities; if (curiosities != null) { RumorModeBuilder.AddCuriosityColors(curiosities); } - foreach (NewHorizonsBody body in Main.BodyDict[Main.Instance.CurrentStarSystem]) + foreach (NewHorizonsBody body in Main.BodyDict[currentStarSystem]) { if (body.Config.ShipLog?.xmlFile != null) {