diff --git a/AdventureBackpacks/AdventureBackpacks.cs b/AdventureBackpacks/AdventureBackpacks.cs index 6c0f1a8..dfd93fc 100644 --- a/AdventureBackpacks/AdventureBackpacks.cs +++ b/AdventureBackpacks/AdventureBackpacks.cs @@ -28,7 +28,7 @@ public class AdventureBackpacks : BaseUnityPlugin, IPluginInfo //Module Constants private const string _pluginId = "vapok.mods.adventurebackpacks"; private const string _displayName = "Adventure Backpacks"; - private const string _version = "1.6.26"; + private const string _version = "1.6.27"; //Interface Properties public string PluginId => _pluginId; diff --git a/AdventureBackpacks/Components/BackpackComponent.cs b/AdventureBackpacks/Components/BackpackComponent.cs index a8da656..db69122 100644 --- a/AdventureBackpacks/Components/BackpackComponent.cs +++ b/AdventureBackpacks/Components/BackpackComponent.cs @@ -28,6 +28,15 @@ public Inventory GetInventory() return _backpackInventory; } + public void UpdateContainerSizing(Container backpackContainer) + { + var inventory = GetInventory(); + backpackContainer.m_inventory = inventory; + backpackContainer.m_width = inventory.m_width; + backpackContainer.m_height = inventory.m_height; + backpackContainer.m_bkg = Item.m_shared.m_icons[0]; + } + public string Serialize() { _log.Debug($"[Serialize()] Starting.."); diff --git a/AdventureBackpacks/Extensions/PlayerExtensions.cs b/AdventureBackpacks/Extensions/PlayerExtensions.cs index 20eaf0a..4c8695e 100644 --- a/AdventureBackpacks/Extensions/PlayerExtensions.cs +++ b/AdventureBackpacks/Extensions/PlayerExtensions.cs @@ -18,6 +18,20 @@ public static bool IsBackpackEquipped(this Player player) return player.m_shoulderItem.IsBackpack(); } + public static bool IsThisBackpackEquipped(this Player player, ItemDrop.ItemData itemData ) + { + if (player == null || player.GetInventory() == null) + return false; + + if (player.m_shoulderItem == null) + return false; + + if (!player.m_shoulderItem.IsBackpack()) + return false; + + return player.m_shoulderItem.Equals(itemData); + } + public static BackpackComponent GetEquippedBackpack(this Player player) { if (player == null || player.GetInventory() == null) diff --git a/AdventureBackpacks/Patches/Humanoid.cs b/AdventureBackpacks/Patches/Humanoid.cs index 70f2df7..969f31d 100644 --- a/AdventureBackpacks/Patches/Humanoid.cs +++ b/AdventureBackpacks/Patches/Humanoid.cs @@ -140,14 +140,8 @@ static void Postfix(ItemDrop.ItemData __0, bool __result) InventoryGuiPatches.BackpackEquipped = true; var backpackContainer = player.gameObject.GetComponent<Container>(); - var backpack = item.Data().GetOrCreate<BackpackComponent>(); - - var inventory = backpack.GetInventory(); - backpackContainer.m_inventory = inventory; - backpackContainer.m_width = inventory.m_width; - backpackContainer.m_height = inventory.m_height; - backpackContainer.m_bkg = backpack.Item.m_shared.m_icons[0]; + backpack.UpdateContainerSizing(backpackContainer); } } } diff --git a/AdventureBackpacks/Patches/InventoryGui.cs b/AdventureBackpacks/Patches/InventoryGui.cs index 08bcf7f..7521efe 100644 --- a/AdventureBackpacks/Patches/InventoryGui.cs +++ b/AdventureBackpacks/Patches/InventoryGui.cs @@ -26,11 +26,23 @@ static class InventoryGuiDoCraftingPrefix [UsedImplicitly] static void Postfix(InventoryGui __instance) { + if ( Player.m_localPlayer == null) + return; + var player = Player.m_localPlayer; + if (__instance.m_craftUpgradeItem != null && __instance.m_craftUpgradeItem.IsBackpack()) { var backpack = __instance.m_craftUpgradeItem.Data().Get<BackpackComponent>(); + if (backpack == null) + return; + + var backpackContainer = player.gameObject.GetComponent<Container>(); backpack?.Load(); - Player.m_localPlayer.UpdateEquipmentStatusEffects(); + + if (player.IsThisBackpackEquipped(backpack.Item)) + backpack?.UpdateContainerSizing(backpackContainer); + + player.UpdateEquipmentStatusEffects(); } } } @@ -447,6 +459,7 @@ CodeInstruction FindInstructionWithLabel(List<CodeInstruction> codeInstructions, AdventureBackpacks.Log.Warning($" patchedShowBackpackMethod {patchedShowBackpackMethod}"); AdventureBackpacks.Log.Warning($" patchedDetectInputHideMethod {patchedDetectInputHideMethod}"); AdventureBackpacks.Log.Warning($" patchedDetectInputShowMethod {patchedDetectInputShowMethod}"); + AdventureBackpacks.Log.Error($"Please inform Mod Author."); Thread.Sleep(5000); } } diff --git a/AdventureBackpacks/Properties/AssemblyInfo.cs b/AdventureBackpacks/Properties/AssemblyInfo.cs index e01566e..8f35b0e 100644 --- a/AdventureBackpacks/Properties/AssemblyInfo.cs +++ b/AdventureBackpacks/Properties/AssemblyInfo.cs @@ -31,5 +31,5 @@ // You can specify all the values or you can default the Build and Revision Numbers // by using the '*' as shown below: // [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("1.6.26.0")] -[assembly: AssemblyFileVersion("1.6.26.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.6.27.0")] +[assembly: AssemblyFileVersion("1.6.27.0")] \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e86c0..a5f3e44 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +# 1.6.27 - Bug Fix +* Fixed: In a rare case, when a bag is upgraded, and then you die before unequipping your bag, it can potentially lose the contents of the backpack. + * This is fixed in this version. + # 1.6.26 - Hotfix to address Critical Crashing Bug * Turns out adding a container on Players, make them interactable which crashes the player object. * Disabled the interaction function on containers when the container is Player(Clone) @@ -9,6 +13,9 @@ * Craft From Containers needs 1 update in order to work (They need to not check for Piece component) * Fixes a Compatibility issue with Valheim+ Where Transpilers were fighting for attention. +<details> +<summary><b>Changelog History</b> (<i>click to expand</i>)</summary> + # 1.6.24 - Updates and Compatibilities * Fixing a Player Load error on Startup when wearing a backpack. @@ -268,4 +275,6 @@ * This is a full refactor and completely re-writen version of JotunnBackpacks. * Adventure Backpacks will seamlessly convert Jotunn Backpacks into new Adventure Backpacks. * As such, Jotunn Backpacks is incompatible with Adventure Backpacks - * Utilizing the same Prefab Name, to get technical. \ No newline at end of file + * Utilizing the same Prefab Name, to get technical. + +</details> \ No newline at end of file diff --git a/manifest.json b/manifest.json index 8aa8dbe..ea64d7b 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "AdventureBackpacks", - "version_number": "1.6.26", + "version_number": "1.6.27", "website_url": "https://github.com/Vapok/AdventureBackpacks", "description": "A Valheim Mod to add a catalogue of Adventuring Backpacks to the Game. These packs will grow and become more useful as the game progresses.", "dependencies": [