diff --git a/UXAssist/Functions/PlanetFunctions.cs b/UXAssist/Functions/PlanetFunctions.cs index f817964..29d9d5d 100644 --- a/UXAssist/Functions/PlanetFunctions.cs +++ b/UXAssist/Functions/PlanetFunctions.cs @@ -130,6 +130,20 @@ public static class PlanetFunctions planet.audio?.RemoveAudioData(ed.audioId); } + for (var id = factory.prebuildCursor - 1; id > 0; id--) + { + ref var pb = ref factory.prebuildPool[id]; + if (pb.id != id) continue; + if (pb.colliderId != 0) + { + planet.physics.RemoveLinkedColliderData(pb.colliderId); + } + if (pb.modelId != 0) + { + GameMain.gpuiManager.RemovePrebuildModel(pb.modelIndex, pb.modelId); + } + } + var hives = GameMain.spaceSector?.dfHives; if (hives != null) { @@ -202,7 +216,7 @@ public static class PlanetFunctions factory.PlanetReformRevert(); } - planet.UnloadFactory(); + GameMain.data.LeavePlanet(); var index = factory.index; var warningSystem = GameMain.data.warningSystem; var warningPool = warningSystem.warningPool; @@ -275,12 +289,7 @@ public static class PlanetFunctions factory.digitalSystem = new DigitalSystem(planet); //GameMain.data.statistics.production.CreateFactoryStat(index); - planet.LoadFactory(); - while (!planet.factoryLoaded) - { - PlanetModelingManager.Update(); - Thread.Sleep(0); - } + GameMain.data.ArrivePlanet(planet); } public static void BuildOrbitalCollectors() diff --git a/UXAssist/Patches/FactoryPatch.cs b/UXAssist/Patches/FactoryPatch.cs index d0bc6e0..c2a0871 100644 --- a/UXAssist/Patches/FactoryPatch.cs +++ b/UXAssist/Patches/FactoryPatch.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using System.Reflection; using System.Reflection.Emit; +using System.Runtime.CompilerServices; using BepInEx.Configuration; using CommonAPI.Systems; using HarmonyLib; @@ -310,25 +311,13 @@ public class FactoryPatch : PatchImpl _nightlightInitialized = false; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void UpdateSunlightAngle() { if (!_sunlight) return; - _sunlight.transform.rotation = Quaternion.LookRotation(-GameMain.mainPlayer.transform.up + GameMain.mainPlayer.transform.forward * NightLightAngleX.Value / 10f + - GameMain.mainPlayer.transform.right * NightLightAngleY.Value / 10f); - } - - [HarmonyPostfix] - [HarmonyPatch(typeof(GameData), nameof(GameData.ArriveStar))] - public static void GameData_ArriveStar_Postfix() - { - _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; - } - - [HarmonyPrefix] - [HarmonyPatch(typeof(GameData), nameof(GameData.LeaveStar))] - public static void GameData_LeaveStar_Prefix() - { - _sunlight = null; + _sunlight.transform.rotation = + Quaternion.LookRotation(-GameMain.mainPlayer.transform.up + GameMain.mainPlayer.transform.forward * NightLightAngleX.Value / 10f + + GameMain.mainPlayer.transform.right * NightLightAngleY.Value / 10f); } [HarmonyPostfix] @@ -341,7 +330,6 @@ public class FactoryPatch : PatchImpl { if (!GameMain.mainPlayer.controller.model.gameObject.activeInHierarchy) return; if (_sail == null) _sail = GameMain.mainPlayer.animator.sails[GameMain.mainPlayer.animator.sailAnimIndex]; - _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; _nightlightInitialized = true; } @@ -362,6 +350,10 @@ public class FactoryPatch : PatchImpl if (sailing) return; _mechaOnEarth = true; + if (_sunlight == null) + { + _sunlight = GameMain.universeSimulator?.LocalStarSimulator()?.sunLight; + } } [HarmonyTranspiler]