From 24b4fb4f8fa0392c8a44aefa734ff6d558f3583d Mon Sep 17 00:00:00 2001 From: Star Rauchenberger Date: Mon, 24 Feb 2025 15:26:02 -0500 Subject: Minor fixes/safety stuff --- GameState.cs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) (limited to 'GameState.cs') diff --git a/GameState.cs b/GameState.cs index 9280eb3..1f63018 100644 --- a/GameState.cs +++ b/GameState.cs @@ -10,12 +10,21 @@ namespace ManifoldGardenArchipelago { public static LevelSystems GetLevelSystems(Component component) { - return component.gameObject.scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent(); + return GetLevelSystems(component.gameObject.scene); } public static LevelSystems GetLevelSystems(Scene scene) { - return scene.GetRootGameObjects().Single((obj) => obj.name == "Level Systems").GetComponent(); + foreach (GameObject gameObject in scene.GetRootGameObjects()) + { + if (gameObject.name == "Level Systems") + { + return gameObject.GetComponent(); + } + } + + Plugin.Logger.LogWarning($"Could not find Level Systems for {scene.name}"); + return null; } public static SceneItemReference GetChainListenerSceneReference(Component component) @@ -30,6 +39,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for chain listener {component.name}"); throw new Exception("Shouldn't happen"); } @@ -45,6 +55,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for gameplay component {component.name}"); throw new Exception("Shouldn't happen"); } @@ -60,6 +71,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for button {arg.name}"); throw new Exception("Shouldn't happen"); } @@ -75,6 +87,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for pad {arg.name}"); throw new Exception("Shouldn't happen"); } @@ -90,6 +103,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for socket {arg.name}"); throw new Exception("Shouldn't happen"); } @@ -105,6 +119,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for sphere {arg.name}"); throw new Exception("Shouldn't happen"); } @@ -120,6 +135,7 @@ namespace ManifoldGardenArchipelago } } + Plugin.Logger.LogWarning($"Could not find SIR for waterwheel {arg.name}"); throw new Exception("Shouldn't happen"); } @@ -144,7 +160,7 @@ namespace ManifoldGardenArchipelago bool shouldOpen = (decision == Requirement.Decision.Yes); //Plugin.Logger.LogInfo($"{door.Key}: {door.Value} -> {shouldOpen}"); - if (SceneManager.GetSceneByName(door.Key.scene) is Scene doorScene && doorScene.isLoaded) + if (SceneManager.GetSceneByName(door.Key.scene) is Scene doorScene && doorScene.IsValid() && doorScene.isLoaded) { LevelSystems levelSystems = GetLevelSystems(doorScene); if (levelSystems.isActiveAndEnabled) @@ -174,7 +190,7 @@ namespace ManifoldGardenArchipelago bool shouldOpen = (decision == Requirement.Decision.Yes); //Plugin.Logger.LogInfo($"{smokeWall.Key}: {smokeWall.Value} -> {shouldOpen}"); - if (SceneManager.GetSceneByName(smokeWall.Key.scene) is Scene smokeScene && smokeScene.isLoaded) + if (SceneManager.GetSceneByName(smokeWall.Key.scene) is Scene smokeScene && smokeScene.IsValid() && smokeScene.isLoaded) { LevelSystems levelSystems = GetLevelSystems(smokeScene); if (levelSystems.isActiveAndEnabled) @@ -192,7 +208,7 @@ namespace ManifoldGardenArchipelago { if (worldGrow.Value.Check() == Requirement.Decision.Yes) { - if (SceneManager.GetSceneByName(worldGrow.Key.scene) is Scene gardenScene && gardenScene.isLoaded) + if (SceneManager.GetSceneByName(worldGrow.Key.scene) is Scene gardenScene && gardenScene.IsValid() && gardenScene.isLoaded) { LevelSystems levelSystems = GetLevelSystems(gardenScene); if (levelSystems.isActiveAndEnabled) @@ -217,7 +233,7 @@ namespace ManifoldGardenArchipelago bool shouldOpen = (decision == Requirement.Decision.Yes); - if (SceneManager.GetSceneByName(laser.Key.scene) is Scene laserScene && laserScene.isLoaded) + if (SceneManager.GetSceneByName(laser.Key.scene) is Scene laserScene && laserScene.IsValid() && laserScene.isLoaded) { LevelSystems levelSystems = GetLevelSystems(laserScene); if (levelSystems.isActiveAndEnabled) -- cgit 1.4.1