diff --git a/src/ShipInventoryUpdated/Patches/RoundManager_Patches.cs b/src/ShipInventoryUpdated/Patches/RoundManager_Patches.cs
new file mode 100644
index 0000000..077796d
--- /dev/null
+++ b/src/ShipInventoryUpdated/Patches/RoundManager_Patches.cs
@@ -0,0 +1,23 @@
+using HarmonyLib;
+using ShipInventoryUpdated.Helpers;
+using ShipInventoryUpdated.Scripts;
+
+// ReSharper disable InconsistentNaming
+
+namespace ShipInventoryUpdated.Patches;
+
+[HarmonyPatch(typeof(RoundManager))]
+internal class RoundManager_Patches
+{
+ [HarmonyPatch(nameof(RoundManager.DespawnPropsAtEndOfRound))]
+ [HarmonyPostfix]
+ private static void DespawnPropsAtEndOfRound_Postfix(RoundManager __instance)
+ {
+ if (!__instance.IsServer)
+ return;
+
+ var itemsToUpdate = Inventory.Items.Where(item => !item.PERSISTED_THROUGH_ROUNDS).ToArray();
+
+ Inventory.MarkPersisted(itemsToUpdate);
+ }
+}
\ No newline at end of file
diff --git a/src/ShipInventoryUpdated/Scripts/Inventory.cs b/src/ShipInventoryUpdated/Scripts/Inventory.cs
index e82869b..d9f504d 100644
--- a/src/ShipInventoryUpdated/Scripts/Inventory.cs
+++ b/src/ShipInventoryUpdated/Scripts/Inventory.cs
@@ -88,6 +88,20 @@ public static ItemData[] Items
}
}
+ ///
+ /// Marks the items as they persisted through rounds
+ ///
+ public static void MarkPersisted(ItemData[] items)
+ {
+ if (_instance == null)
+ {
+ Logger.Warn("Tried to modify items in the inventory, but no instance was defined.");
+ return;
+ }
+
+ _instance.MarkPersistedServerRpc(items);
+ }
+
#endregion
#region Unity
@@ -133,5 +147,22 @@ private void ClearServerRpc()
_storedItems.Clear();
}
+ [ServerRpc(RequireOwnership = false)]
+ private void MarkPersistedServerRpc(params ItemData[] items)
+ {
+ var newItems = new HashSet(items);
+
+ for (var i = 0; i < _storedItems.Count; i++)
+ {
+ var item = _storedItems[i];
+
+ if (!newItems.Contains(item))
+ continue;
+
+ item.PERSISTED_THROUGH_ROUNDS = true;
+ _storedItems[i] = item;
+ }
+ }
+
#endregion
}
diff --git a/src/ShipInventoryUpdated/ShipInventoryUpdated.cs b/src/ShipInventoryUpdated/ShipInventoryUpdated.cs
index 64b6bce..6acf4bb 100644
--- a/src/ShipInventoryUpdated/ShipInventoryUpdated.cs
+++ b/src/ShipInventoryUpdated/ShipInventoryUpdated.cs
@@ -74,6 +74,7 @@ private void Patch()
{
_harmony = new Harmony(MyPluginInfo.PLUGIN_GUID);
_harmony.PatchAll(typeof(Patches.GameNetworkManager_Patches));
+ _harmony.PatchAll(typeof(Patches.RoundManager_Patches));
_harmony.PatchAll(typeof(Patches.StartOfRound_Patches));
_harmony.PatchAll(typeof(Patches.Terminal_Patches));
}