diff --git a/NewHorizons/Builder/General/PlanetDestroyer.cs b/NewHorizons/Builder/General/PlanetDestroyer.cs index 0d3dd61a..b2eab533 100644 --- a/NewHorizons/Builder/General/PlanetDestroyer.cs +++ b/NewHorizons/Builder/General/PlanetDestroyer.cs @@ -43,14 +43,14 @@ namespace NewHorizons.Builder.General foreach(var name in _solarSystemBodies) { var ao = AstroObjectLocator.GetAstroObject(name); - if (ao != null) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveBody(ao)); + if (ao != null) Main.Instance.ModHelper.Events.Unity.FireOnNextUpdate(() => RemoveBody(ao, false)); } // Bring the sun back because why not Main.Instance.ModHelper.Events.Unity.FireInNUpdates(() => { if (Locator.GetAstroObject(AstroObject.Name.Sun).gameObject.activeInHierarchy) { sunVolumes.SetActive(true); } }, 2); } - public static void RemoveBody(AstroObject ao, List toDestroy = null) + public static void RemoveBody(AstroObject ao, bool delete = false, List toDestroy = null) { Logger.Log($"Removing {ao.name}"); @@ -67,7 +67,9 @@ namespace NewHorizons.Builder.General toDestroy.Add(ao); if (ao.GetAstroObjectName() == AstroObject.Name.BrittleHollow) - RemoveBody(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole), toDestroy); + { + RemoveBody(AstroObjectLocator.GetAstroObject(AstroObject.Name.WhiteHole), delete, toDestroy); + } // Check if any other objects depend on it and remove them too var aoArray = AstroObjectLocator.GetAllAstroObjects(); @@ -81,7 +83,7 @@ namespace NewHorizons.Builder.General if (ao.Equals(obj.GetPrimaryBody())) { AstroObjectLocator.RemoveAstroObject(obj); - RemoveBody(obj, toDestroy); + RemoveBody(obj, delete, toDestroy); } } @@ -90,57 +92,61 @@ namespace NewHorizons.Builder.General if (ao.GetAstroObjectName() == AstroObject.Name.CaveTwin || ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) { if (ao.GetAstroObjectName() == AstroObject.Name.TowerTwin) - GameObject.Find("TimeLoopRing_Body").SetActive(false); - var focalBody = GameObject.Find("FocalBody"); - if (focalBody != null) focalBody.SetActive(false); + { + DisableBody(GameObject.Find("TimeLoopRing_Body"), delete); + } + DisableBody(GameObject.Find("FocalBody"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.MapSatellite) { - var msb = GameObject.Find("MapSatellite_Body"); - if (msb != null) msb.SetActive(false); + DisableBody(GameObject.Find("MapSatellite_Body"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.ProbeCannon) { - GameObject.Find("NomaiProbe_Body").SetActive(false); - GameObject.Find("CannonMuzzle_Body").SetActive(false); - GameObject.Find("FakeCannonMuzzle_Body (1)").SetActive(false); - GameObject.Find("CannonBarrel_Body").SetActive(false); - GameObject.Find("FakeCannonBarrel_Body (1)").SetActive(false); - GameObject.Find("Debris_Body (1)").SetActive(false); + DisableBody(GameObject.Find("NomaiProbe_Body"), delete); + DisableBody(GameObject.Find("CannonMuzzle_Body"), delete); + DisableBody(GameObject.Find("FakeCannonMuzzle_Body (1)"), delete); + DisableBody(GameObject.Find("CannonBarrel_Body"), delete); + DisableBody(GameObject.Find("FakeCannonBarrel_Body (1)"), delete); + DisableBody(GameObject.Find("Debris_Body (1)"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.SunStation) { - GameObject.Find("SS_Debris_Body").SetActive(false); + DisableBody(GameObject.Find("SS_Debris_Body"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.GiantsDeep) { - GameObject.Find("BrambleIsland_Body").SetActive(false); - GameObject.Find("GabbroIsland_Body").SetActive(false); - GameObject.Find("QuantumIsland_Body").SetActive(false); - GameObject.Find("StatueIsland_Body").SetActive(false); - GameObject.Find("ConstructionYardIsland_Body").SetActive(false); - GameObject.Find("GabbroShip_Body").SetActive(false); + DisableBody(GameObject.Find("BrambleIsland_Body"), delete); + DisableBody(GameObject.Find("GabbroIsland_Body"), delete); + DisableBody(GameObject.Find("QuantumIsland_Body"), delete); + DisableBody(GameObject.Find("StatueIsland_Body"), delete); + DisableBody(GameObject.Find("ConstructionYardIsland_Body"), delete); + DisableBody(GameObject.Find("GabbroShip_Body"), delete); + foreach (var jelly in GameObject.FindObjectsOfType()) { - jelly.gameObject.SetActive(false); + DisableBody(jelly.gameObject, delete); } } else if (ao.GetAstroObjectName() == AstroObject.Name.WhiteHole) { - GameObject.Find("WhiteholeStation_Body").SetActive(false); - GameObject.Find("WhiteholeStationSuperstructure_Body").SetActive(false); + DisableBody(GameObject.Find("WhiteholeStation_Body"), delete); + DisableBody(GameObject.Find("WhiteholeStationSuperstructure_Body"), delete); } else if (ao.GetAstroObjectName() == AstroObject.Name.TimberHearth) { - GameObject.Find("MiningRig_Body").SetActive(false); + // Always just fucking kill this one to stop THE WARP BUG!!! + DisableBody(GameObject.Find("StreamingGroup_TH"), true); + + DisableBody(GameObject.Find("MiningRig_Body"), delete); foreach (var obj in GameObject.FindObjectsOfType()) { - GameObject.Destroy(obj); + DisableBody(obj.gameObject, true); } foreach (var obj in GameObject.FindObjectsOfType()) { - GameObject.Destroy(obj); + DisableBody(obj.gameObject, true); } } else if (ao.GetAstroObjectName() == AstroObject.Name.Sun) @@ -172,8 +178,8 @@ namespace NewHorizons.Builder.General } else if (ao.GetAstroObjectName() == AstroObject.Name.DreamWorld) { - GameObject.Find("BackRaft_Body").SetActive(false); - GameObject.Find("SealRaft_Body").SetActive(false); + DisableBody(GameObject.Find("BackRaft_Body"), delete); + DisableBody(GameObject.Find("SealRaft_Body"), delete); } } catch(Exception e) @@ -186,14 +192,13 @@ namespace NewHorizons.Builder.General { if (p.GetValue("_originalBody") == ao.gameObject) { - p.gameObject.SetActive(false); + DisableBody(p.gameObject, true); break; } } RemoveProxy(ao.name.Replace("_Body", "")); - // For TH we wait until the player is fully loaded in - Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => ao.transform.root.gameObject.SetActive(false)); + Main.Instance.ModHelper.Events.Unity.RunWhen(() => Main.IsSystemReady, () => DisableBody(ao.gameObject, delete)); foreach (ProxyBody proxy in GameObject.FindObjectsOfType()) { @@ -209,7 +214,14 @@ namespace NewHorizons.Builder.General public static void RemoveDistantProxyClones() { GameObject.Destroy(GameObject.FindObjectOfType().gameObject); + } + private static void DisableBody(GameObject go, bool delete) + { + if (go == null) return; + + if (delete) GameObject.Destroy(go); + else go.SetActive(false); } private static void RemoveProxy(string name)