From e0b1b736c3a95653c725536ea38d44e34c7d42a1 Mon Sep 17 00:00:00 2001 From: devbeni Date: Sun, 14 Dec 2025 00:27:17 +0100 Subject: [PATCH] pls :( 2 --- Main.cs | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/Main.cs b/Main.cs index f9ed6ea..e371bb1 100644 --- a/Main.cs +++ b/Main.cs @@ -58,6 +58,7 @@ namespace KCM private static readonly Dictionary lastTeamIdLookupLogMs = new Dictionary(); private static int resetInProgress = 0; private static int multiplayerSaveLoadInProgress = 0; + private static int worldReadyRebuildDone = 0; public static bool IsMultiplayerSaveLoadInProgress { @@ -94,6 +95,7 @@ namespace KCM try { LobbyManager.loadingSave = false; } catch { } try { SetMultiplayerSaveLoadInProgress(false); } catch { } + try { Interlocked.Exchange(ref worldReadyRebuildDone, 0); } catch { } try { @@ -160,6 +162,28 @@ namespace KCM } } + private static int GetLoadTickDelayOrMinusOne(object instance) + { + if (instance == null) + return -1; + + try + { + FieldInfo loadTickDelayField = instance.GetType().GetField("loadTickDelay", BindingFlags.Instance | BindingFlags.NonPublic); + if (loadTickDelayField == null) + return -1; + + object v = loadTickDelayField.GetValue(instance); + if (v is int) + return (int)v; + } + catch + { + } + + return -1; + } + public static void RunPostLoadRebuild(string reason) { try @@ -318,6 +342,33 @@ namespace KCM private void FixedUpdate() { + try + { + if (KCClient.client != null && + KCClient.client.IsConnected && + Volatile.Read(ref worldReadyRebuildDone) == 0 && + World.inst != null && + Player.inst != null && + VillagerSystem.inst != null) + { + if (Interlocked.Exchange(ref worldReadyRebuildDone, 1) == 0) + { + Main.helper.Log("AutoRebuild: world ready; running post-load rebuild"); + RunPostLoadRebuild("auto:world-ready"); + Main.helper.Log( + "AutoRebuild: timeScale=" + Time.timeScale + + " loadTickDelay(Player/Unit/Job/Villager)=" + + GetLoadTickDelayOrMinusOne(Player.inst) + "/" + + GetLoadTickDelayOrMinusOne(UnitSystem.inst) + "/" + + GetLoadTickDelayOrMinusOne(JobSystem.inst) + "/" + + GetLoadTickDelayOrMinusOne(VillagerSystem.inst)); + } + } + } + catch + { + } + // send batched building placement info /*if (PlaceHook.QueuedBuildings.Count > 0 && (FixedUpdateInterval % 25 == 0)) {