From e636ad6e19ccb4cc3bb3bafeedfe43a146ad58cb Mon Sep 17 00:00:00 2001 From: devbeni Date: Sat, 13 Dec 2025 20:57:23 +0100 Subject: [PATCH] asd --- Main.cs | 51 ++++++++++++++++++++--------- Packets/Lobby/SaveTransferPacket.cs | 8 +++++ 2 files changed, 44 insertions(+), 15 deletions(-) diff --git a/Main.cs b/Main.cs index 3f2040e..03d6b24 100644 --- a/Main.cs +++ b/Main.cs @@ -1269,20 +1269,38 @@ namespace KCM public class SpeedControlUISetSpeedHook { private static long lastTime = 0; + private static long lastClientBlockLogTime = 0; - public static bool Prefix(ref bool __state) + public static bool Prefix(int idx, ref bool __state) { __state = false; - if (KCClient.client.IsConnected) - { - bool calledFromPacket = false; - try { calledFromPacket = PacketHandler.IsHandlingPacket; } catch { } + if (!KCClient.client.IsConnected) + return true; - if (!calledFromPacket) + bool calledFromPacket = false; + try { calledFromPacket = PacketHandler.IsHandlingPacket; } catch { } + + // In multiplayer, keep time control authoritative to the host to avoid clients pausing/stalling the simulation. + if (!KCServer.IsRunning) + { + if (calledFromPacket) + return true; + + long now = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + if ((now - lastClientBlockLogTime) >= 2000) { - if ((DateTimeOffset.Now.ToUnixTimeMilliseconds() - lastTime) >= 250) // Set speed spam fix / hack - __state = true; + lastClientBlockLogTime = now; + Main.helper.Log("Blocked SpeedControlUI.SetSpeed on non-host client: " + idx); } + + return false; + } + + if (!calledFromPacket) + { + long now = DateTimeOffset.Now.ToUnixTimeMilliseconds(); + if ((now - lastTime) >= 250) // Set speed spam fix / hack + __state = true; } return true; @@ -1463,18 +1481,13 @@ namespace KCM public static bool Prefix(ref string __result) { Main.helper.Log("Get save dir"); - if (KCClient.client.IsConnected) + if (KCServer.IsRunning) { - if (KCServer.IsRunning) - { - - } __result = Application.persistentDataPath + "/Saves/Multiplayer"; - return false; } - __result = Application.persistentDataPath + "/Saves"; ; + __result = Application.persistentDataPath + "/Saves"; return true; } } @@ -1554,6 +1567,14 @@ namespace KCM Main.SetMultiplayerSaveLoadInProgress(false); } + try + { + RunPostLoadRebuild("LoadAtPath (multiplayer)"); + } + catch + { + } + Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent()); } diff --git a/Packets/Lobby/SaveTransferPacket.cs b/Packets/Lobby/SaveTransferPacket.cs index d3e1374..0bd1eb9 100644 --- a/Packets/Lobby/SaveTransferPacket.cs +++ b/Packets/Lobby/SaveTransferPacket.cs @@ -117,6 +117,14 @@ namespace KCM.Packets.Lobby { Main.SetMultiplayerSaveLoadInProgress(false); } + + try + { + RunPostLoadRebuild("Save transfer complete"); + } + catch + { + } Broadcast.OnLoadedEvent.Broadcast(new OnLoadedEvent()); try