From d61b40216ce836cbc6cd498873c11c76c427847d Mon Sep 17 00:00:00 2001 From: Soar Qin Date: Sat, 26 Apr 2025 01:58:50 +0800 Subject: [PATCH] CheatEnabler: minor changes --- CheatEnabler/Patches/FactoryPatch.cs | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/CheatEnabler/Patches/FactoryPatch.cs b/CheatEnabler/Patches/FactoryPatch.cs index b58b706..5ca122a 100644 --- a/CheatEnabler/Patches/FactoryPatch.cs +++ b/CheatEnabler/Patches/FactoryPatch.cs @@ -176,6 +176,7 @@ public class FactoryPatch : PatchImpl factory.BeginFlattenTerrain(); factory.cargoTraffic._batch_buffer_no_refresh = true; PlanetFactory.batchBuild = true; + CargoTrafficPatch.DisableRefreshBatchesBuffers = true; for (var i = factory.prebuildCursor - 1; i > 0; i--) { ref var pb = ref prebuilds[i]; @@ -190,11 +191,6 @@ public class FactoryPatch : PatchImpl anyBuilt = true; } PlanetFactory.batchBuild = false; - if (anyBelt) - { - factory.cargoTraffic.RefreshBeltBatchesBuffers(); - factory.cargoTraffic.RefreshPathBatchesBuffers(); - } factory.cargoTraffic._batch_buffer_no_refresh = false; factory.EndFlattenTerrain(); CargoTrafficPatch.IsBatchBuilding = false; @@ -216,6 +212,12 @@ public class FactoryPatch : PatchImpl _alterBeltRendererIds.Clear(); _alterPathRendererIds.Clear(); _refreshPathUVIds.Clear(); + CargoTrafficPatch.DisableRefreshBatchesBuffers = false; + if (anyBelt) + { + factory.cargoTraffic.RefreshBeltBatchesBuffers(); + factory.cargoTraffic.RefreshPathBatchesBuffers(); + } if (anyBuilt) { factory.planet.physics?.raycastLogic?.NotifyBatchObjectRemove(); @@ -237,7 +239,9 @@ public class FactoryPatch : PatchImpl private class CargoTrafficPatch : PatchImpl { public static bool IsBatchBuilding; + public static bool DisableRefreshBatchesBuffers; [HarmonyPrefix] + [HarmonyPriority(Priority.First)] [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterBeltRenderer))] private static bool CargoTraffic_AlterBeltRenderer_Prefix(int beltId) { @@ -247,6 +251,7 @@ public class FactoryPatch : PatchImpl } [HarmonyPrefix] + [HarmonyPriority(Priority.First)] [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.AlterPathRenderer))] private static bool CargoTraffic_AlterPathRenderer_Prefix(int pathId) { @@ -256,6 +261,7 @@ public class FactoryPatch : PatchImpl } [HarmonyPrefix] + [HarmonyPriority(Priority.First)] [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathUV))] private static bool CargoTraffic_RefreshPathUV_Prefix(int pathId) { @@ -263,6 +269,15 @@ public class FactoryPatch : PatchImpl _refreshPathUVIds.Add(pathId); return false; } + + [HarmonyPrefix] + [HarmonyPriority(Priority.First)] + [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshBeltBatchesBuffers))] + [HarmonyPatch(typeof(CargoTraffic), nameof(CargoTraffic.RefreshPathBatchesBuffers))] + private static bool CargoTraffic_RefreshBeltBatchesBuffers_Prefix() + { + return !DisableRefreshBatchesBuffers; + } } [HarmonyPostfix]