From 71e1e09c75c600f248353cf7f2061b7e70d73d99 Mon Sep 17 00:00:00 2001 From: b3ni15 Date: Mon, 15 Dec 2025 09:27:05 +0100 Subject: [PATCH] feat: Enhance building removal logic to ensure correct player job list modifications and add fallback for Remove method --- .../Game/GameBuilding/BuildingRemovePacket.cs | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/Packets/Game/GameBuilding/BuildingRemovePacket.cs b/Packets/Game/GameBuilding/BuildingRemovePacket.cs index 53738e2..388032e 100644 --- a/Packets/Game/GameBuilding/BuildingRemovePacket.cs +++ b/Packets/Game/GameBuilding/BuildingRemovePacket.cs @@ -1,4 +1,6 @@ using System; +using System.Reflection; +using UnityEngine; namespace KCM.Packets.Game.GameBuilding { @@ -44,7 +46,7 @@ namespace KCM.Packets.Game.GameBuilding isProcessingPacket = true; // Set Player.inst to the correct player for this building - // This ensures Remove() modifies the correct player's job lists + // This ensures the removal modifies the correct player's job lists Player originalPlayer = Player.inst; Player correctPlayer = Main.GetPlayerByBuilding(building); if (correctPlayer != null) @@ -52,7 +54,19 @@ namespace KCM.Packets.Game.GameBuilding Player.inst = correctPlayer; } - building.Remove(); + // Use reflection to call the Remove method from the game assembly + MethodInfo removeMethod = typeof(Building).GetMethod("Remove", BindingFlags.Public | BindingFlags.Instance); + if (removeMethod != null) + { + removeMethod.Invoke(building, null); + } + else + { + // Fallback: destroy the building GameObject directly + Main.helper.Log("Remove method not found, using Destroy fallback"); + building.destroyedWhileInPlay = true; + UnityEngine.Object.Destroy(building.gameObject); + } // Restore original Player.inst Player.inst = originalPlayer;