Skip to content

Commit

Permalink
Merge pull request #116 from Vapok/vapok/r1.6.27
Browse files Browse the repository at this point in the history
Fixing the backpack container bug and release 1.6.27
  • Loading branch information
Vapok authored Sep 29, 2023
2 parents bc6a53b + 1813466 commit e1d46fd
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 13 deletions.
2 changes: 1 addition & 1 deletion AdventureBackpacks/AdventureBackpacks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
9 changes: 9 additions & 0 deletions AdventureBackpacks/Components/BackpackComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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..");
Expand Down
14 changes: 14 additions & 0 deletions AdventureBackpacks/Extensions/PlayerExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 1 addition & 7 deletions AdventureBackpacks/Patches/Humanoid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
}
Expand Down
15 changes: 14 additions & 1 deletion AdventureBackpacks/Patches/InventoryGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
Expand Down Expand Up @@ -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);
}
}
Expand Down
4 changes: 2 additions & 2 deletions AdventureBackpacks/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
[assembly: AssemblyVersion("1.6.27.0")]
[assembly: AssemblyFileVersion("1.6.27.0")]
11 changes: 10 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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.

Expand Down Expand Up @@ -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.
* Utilizing the same Prefab Name, to get technical.

</details>
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit e1d46fd

Please sign in to comment.