From c4062407e15b1283eba4fe2b64b9f67cd5378a33 Mon Sep 17 00:00:00 2001 From: Arsenii Fomin Date: Tue, 26 Mar 2024 10:54:24 +0700 Subject: [PATCH 1/3] Adding default items on container first opening/destroy without opening --- EpicLoot/Container_Patch.cs | 50 +++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/EpicLoot/Container_Patch.cs b/EpicLoot/Container_Patch.cs index 4b7c5efa4..8a439dc9b 100644 --- a/EpicLoot/Container_Patch.cs +++ b/EpicLoot/Container_Patch.cs @@ -7,6 +7,17 @@ namespace EpicLoot [HarmonyPatch(typeof(Container), nameof(Container.AddDefaultItems))] public static class Container_AddDefaultItems_Patch { + // already created (on Awake call) default items should be removed first + public static void Prefix(Container __instance) + { + if (__instance == null || __instance.m_piece == null) + { + return; + } + + __instance.m_inventory.RemoveAll(); + } + public static void Postfix(Container __instance) { if (__instance == null || __instance.m_piece == null) @@ -28,4 +39,43 @@ public static void Postfix(Container __instance) } } } + + // Looks like there is no need to change this since all containers are not empty initially + // [HarmonyPatch(typeof(Container), nameof(Container.GetHoverText))] + + [HarmonyPatch(typeof(Container), nameof(Container.RPC_RequestOpen))] + public static class Container_RPC_RequestOpen_Patch + { + public static void Prefix(Container __instance, long uid, long playerID) + { + if (__instance == null || __instance.m_piece == null) + { + return; + } + + if (__instance.m_nview.IsOwner() && !__instance.m_nview.GetZDO().GetBool("EL_container_items_rolled".GetStableHashCode())) + { + __instance.AddDefaultItems(); + __instance.m_nview.GetZDO().Set("EL_container_items_rolled".GetStableHashCode(), value: true); + } + } + } + + [HarmonyPatch(typeof(Container), nameof(Container.OnDestroyed))] + public static class Container_OnDestroyed_Patch + { + public static void Prefix(Container __instance) + { + if (__instance == null || __instance.m_piece == null) + { + return; + } + + if (__instance.m_nview.IsOwner() && !__instance.m_nview.GetZDO().GetBool("EL_container_items_rolled".GetStableHashCode())) + { + __instance.AddDefaultItems(); + __instance.m_nview.GetZDO().Set("EL_container_items_rolled".GetStableHashCode(), value: true); + } + } + } } From f17c3454195fb3b18a4cf0ca7371c6cdec404038 Mon Sep 17 00:00:00 2001 From: Arsenii Fomin Date: Tue, 26 Mar 2024 21:30:14 +0700 Subject: [PATCH 2/3] Fix for legacy containers --- EpicLoot/Container_Patch.cs | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/EpicLoot/Container_Patch.cs b/EpicLoot/Container_Patch.cs index 8a439dc9b..1856517c6 100644 --- a/EpicLoot/Container_Patch.cs +++ b/EpicLoot/Container_Patch.cs @@ -55,7 +55,12 @@ public static void Prefix(Container __instance, long uid, long playerID) if (__instance.m_nview.IsOwner() && !__instance.m_nview.GetZDO().GetBool("EL_container_items_rolled".GetStableHashCode())) { - __instance.AddDefaultItems(); + var containerName = __instance.m_piece.name.Replace("(Clone)", "").Trim(); + var lootTables = LootRoller.GetLootTable(containerName); + if (lootTables != null && lootTables.Count > 0) + { + __instance.AddDefaultItems(); + } __instance.m_nview.GetZDO().Set("EL_container_items_rolled".GetStableHashCode(), value: true); } } @@ -73,7 +78,12 @@ public static void Prefix(Container __instance) if (__instance.m_nview.IsOwner() && !__instance.m_nview.GetZDO().GetBool("EL_container_items_rolled".GetStableHashCode())) { - __instance.AddDefaultItems(); + var containerName = __instance.m_piece.name.Replace("(Clone)", "").Trim(); + var lootTables = LootRoller.GetLootTable(containerName); + if (lootTables != null && lootTables.Count > 0) + { + __instance.AddDefaultItems(); + } __instance.m_nview.GetZDO().Set("EL_container_items_rolled".GetStableHashCode(), value: true); } } From bfed5ac8344c4d2cfe70f43979d2e274b2e91ef0 Mon Sep 17 00:00:00 2001 From: Arsenii Fomin Date: Tue, 26 Mar 2024 21:34:29 +0700 Subject: [PATCH 3/3] Hotfix --- EpicLoot/Container_Patch.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/EpicLoot/Container_Patch.cs b/EpicLoot/Container_Patch.cs index 1856517c6..fabb227a3 100644 --- a/EpicLoot/Container_Patch.cs +++ b/EpicLoot/Container_Patch.cs @@ -15,7 +15,12 @@ public static void Prefix(Container __instance) return; } - __instance.m_inventory.RemoveAll(); + var containerName = __instance.m_piece.name.Replace("(Clone)", "").Trim(); + var lootTables = LootRoller.GetLootTable(containerName); + if (lootTables != null && lootTables.Count > 0) + { + __instance.m_inventory.RemoveAll(); + } } public static void Postfix(Container __instance)