Skip to content

Commit

Permalink
Fixing the backpack container bug and release 1.6.27
Browse files Browse the repository at this point in the history
  • Loading branch information
Vapok committed Sep 29, 2023
1 parent fadca72 commit 1813466
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 16 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
8 changes: 6 additions & 2 deletions AdventureBackpacks/AdventureBackpacks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
<Reference Include="UnityEngine">
<HintPath>..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.dll</HintPath>
Expand All @@ -78,8 +79,11 @@
<Reference Include="UnityEngine.UI">
<HintPath>..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.UI.dll</HintPath>
</Reference>
<Reference Include="Vapok.Common">
<HintPath>..\..\References\Vapok.Common\Vapok.Common.dll</HintPath>
<Reference Include="Vapok.Valheim.Common, Version=0.217.14.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Vapok.Valheim.Common.1.3.21714\lib\net462\Vapok.Valheim.Common.dll</HintPath>
</Reference>
<Reference Include="YamlDotNet, Version=12.0.0.0, Culture=neutral, PublicKeyToken=ec19458f3c15af5e, processorArchitecture=MSIL">
<HintPath>..\packages\YamlDotNet.12.3.1\lib\net45\YamlDotNet.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
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
4 changes: 3 additions & 1 deletion AdventureBackpacks/ILRepack.targets
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
<Target Name="ILRepacker" AfterTargets="Build">
<ItemGroup>
<InputAssemblies Include="$(TargetPath)" />
<InputAssemblies Include="$(OutputPath)\Vapok.Common.dll" />
<InputAssemblies Include="$(OutputPath)\Vapok.Valheim.Common.dll" />
<InputAssemblies Include="$(OutputPath)\YamlDotNet.dll" />
<InputAssemblies Include="$(OutputPath)\ServerSync.dll" />
<LibraryPath Include="$(OutputPath)" />
</ItemGroup>
<ILRepack Parallel="true" DebugInfo="true" Internalize="true" InputAssemblies="@(InputAssemblies)" OutputFile="$(TargetPath)" TargetKind="SameAsPrimaryAssembly" LibraryPath="@(LibraryPath)" />
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")]
2 changes: 2 additions & 0 deletions AdventureBackpacks/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net462" />
<package id="Vapok.Valheim.Common" version="1.3.21714" targetFramework="net462" />
<package id="YamlDotNet" version="12.3.1" targetFramework="net462" />
</packages>
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 1813466

Please sign in to comment.