diff --git a/AdventureBackpacks/AdventureBackpacks.cs b/AdventureBackpacks/AdventureBackpacks.cs index fdb988b..23027af 100644 --- a/AdventureBackpacks/AdventureBackpacks.cs +++ b/AdventureBackpacks/AdventureBackpacks.cs @@ -12,7 +12,6 @@ using HarmonyLib; using ItemManager; using JetBrains.Annotations; -using UnityEngine; using Vapok.Common.Abstractions; using Vapok.Common.Managers; using Vapok.Common.Managers.Configuration; @@ -29,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.12"; + private const string _version = "1.6.13"; //Interface Properties public string PluginId => _pluginId; @@ -98,16 +97,10 @@ private void Update() if (backpack != null) Backpacks.PerformYardSale(Player.m_localPlayer, backpack.Item); } - - if (!KeyPressTool.IgnoreKeyPresses(true) && (ConfigRegistry.HotKeyOpen.Value.IsDown() || ZInput.GetButtonDown(ConfigRegistry.HotKeyOpen.Value.Serialize()) ) && Player.m_localPlayer.CanOpenBackpack()) - { - ZInput.ResetButtonStatus(ConfigRegistry.HotKeyOpen.Value.Serialize()); - Player.m_localPlayer.OpenBackpack(); - } - if (ConfigRegistry.OutwardMode.Value && !KeyPressTool.IgnoreKeyPresses(true) && (ConfigRegistry.HotKeyDrop.Value.IsDown() || ZInput.GetButtonDown(ConfigRegistry.HotKeyDrop.Value.Serialize())) && Player.m_localPlayer.CanOpenBackpack()) + if ((ZInput.GetButton("Forward") || ZInput.GetButton("Backward") || ZInput.GetButton("Left") ||ZInput.GetButton("Right")) + && ZInput.GetKeyDown(ConfigRegistry.HotKeyDrop.Value.MainKey) && ConfigRegistry.OutwardMode.Value) { - ZInput.ResetButtonStatus(ConfigRegistry.HotKeyOpen.Value.Serialize()); Player.m_localPlayer.QuickDropBackpack(); } diff --git a/AdventureBackpacks/AdventureBackpacks.csproj b/AdventureBackpacks/AdventureBackpacks.csproj index 1eeea8c..b411111 100644 --- a/AdventureBackpacks/AdventureBackpacks.csproj +++ b/AdventureBackpacks/AdventureBackpacks.csproj @@ -36,38 +36,44 @@ - ..\..\References\BepInEx\5.4.2100\BepInEx\core\0Harmony.dll + ..\..\References\BepInEx\5.4.2101\BepInEx\core\0Harmony.dll - ..\..\References\Valheim\0.214.2\assembly_guiutils_publicized.dll + ..\..\References\Valheim\0.214.3\assembly_guiutils_publicized.dll - ..\..\References\Valheim\0.214.2\assembly_utils_publicized.dll + ..\..\References\Valheim\0.214.3\assembly_utils_publicized.dll - ..\..\References\Valheim\0.214.2\assembly_valheim_publicized.dll + ..\..\References\Valheim\0.214.3\assembly_valheim_publicized.dll - ..\..\References\BepInEx\5.4.2100\BepInEx\core\BepInEx.dll + ..\..\References\BepInEx\5.4.2101\BepInEx\core\BepInEx.dll - ..\..\References\BepInEx\5.4.2100\BepInEx\core\BepInEx.Harmony.dll + ..\..\References\BepInEx\5.4.2101\BepInEx\core\BepInEx.Harmony.dll - ..\..\References\BepInEx\5.4.2100\unstripped_corlib\UnityEngine.dll + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.dll - ..\..\References\BepInEx\5.4.2100\unstripped_corlib\UnityEngine.AnimationModule.dll + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.AnimationModule.dll - ..\..\References\BepInEx\5.4.2100\unstripped_corlib\UnityEngine.AssetBundleModule.dll + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.AssetBundleModule.dll - ..\..\References\BepInEx\5.4.2100\unstripped_corlib\UnityEngine.CoreModule.dll + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.CoreModule.dll + + + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.InputLegacyModule.dll + + + ..\..\References\BepInEx\5.4.2101\unstripped_corlib\UnityEngine.PhysicsModule.dll ..\..\References\Vapok.Common\Vapok.Common.dll diff --git a/AdventureBackpacks/Extensions/PlayerExtensions.cs b/AdventureBackpacks/Extensions/PlayerExtensions.cs index 8b43128..410943b 100644 --- a/AdventureBackpacks/Extensions/PlayerExtensions.cs +++ b/AdventureBackpacks/Extensions/PlayerExtensions.cs @@ -1,5 +1,6 @@ using AdventureBackpacks.Components; using AdventureBackpacks.Patches; +using UnityEngine; using Vapok.Common.Managers; namespace AdventureBackpacks.Extensions; @@ -38,7 +39,7 @@ public static bool CanOpenBackpack(this Player player) return IsBackpackEquipped(player); } - public static void OpenBackpack(this Player player, bool track = true) + public static void OpenBackpack(this Player player, InventoryGui instance) { if (player == null) return; @@ -56,8 +57,7 @@ public static void OpenBackpack(this Player player, bool track = true) backpackContainer.m_bkg = backpack.Item.m_shared.m_icons[0]; InventoryGuiPatches.BackpackIsOpen = true; - InventoryGuiPatches.BackpackIsOpening = track; - InventoryGui.instance.Show(backpackContainer); + instance.Show(backpackContainer); } public static void QuickDropBackpack(this Player player) @@ -97,7 +97,9 @@ public static void QuickDropBackpack(this Player player) player.m_inventory.RemoveItem(backpack.Item); // This drops a copy of the backpack itemDrop.itemData - var itemDrop = ItemDrop.DropItem(backpack.Item, 1, player.transform.position - player.transform.up - player.transform.up, player.transform.rotation); + var itemDrop = ItemDrop.DropItem(backpack.Item, 1, player.transform.position - player.transform.forward + player.transform.up, player.transform.rotation); + itemDrop.GetComponent().velocity = (Vector3.up - player.transform.forward) * 5f; + player.m_dropEffects.Create(player.transform.position, Quaternion.identity); itemDrop.Save(); if (swapItemActivated) diff --git a/AdventureBackpacks/Patches/InventoryGui.cs b/AdventureBackpacks/Patches/InventoryGui.cs index a714eb3..fd62b65 100644 --- a/AdventureBackpacks/Patches/InventoryGui.cs +++ b/AdventureBackpacks/Patches/InventoryGui.cs @@ -3,21 +3,22 @@ using System.Linq; using System.Reflection.Emit; using AdventureBackpacks.Assets; +using AdventureBackpacks.Assets.Factories; using AdventureBackpacks.Components; using AdventureBackpacks.Configuration; using AdventureBackpacks.Extensions; using HarmonyLib; +using JetBrains.Annotations; using UnityEngine; using Vapok.Common.Managers; -using Vapok.Common.Tools; namespace AdventureBackpacks.Patches; internal static class InventoryGuiPatches { public static bool BackpackIsOpen; - public static bool BackpackIsOpening; public static bool BackpackEquipped = false; + private static bool _showBackpack = false; [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.DoCrafting))] static class InventoryGuiDoCraftingPrefix @@ -67,30 +68,90 @@ static Exception Finalizer(Exception __exception, InventoryGrid grid, ItemDrop.I } } - public static void ShowBackpack(Player player) + public static void ShowBackpack(Player player, InventoryGui instance) { - if (ConfigRegistry.OpenWithInventory.Value && player.CanOpenBackpack()) - { - player.OpenBackpack(false); + if (_showBackpack) + { + _showBackpack = false; + player.OpenBackpack(instance); } } public static void HideBackpack(InventoryGui instance) { - if (ConfigRegistry.OpenWithInventory.Value) + if (BackpackIsOpen) { - if (BackpackIsOpen) + instance.CloseContainer(); + BackpackIsOpen = false; + + if (ConfigRegistry.CloseInventory.Value) + instance.Hide(); + } + } + + public static bool DetectInputToHide(KeyCode defaultKeyCode, Player player, InventoryGui instance) + { + var defaultInputDown = Input.GetKeyDown(defaultKeyCode); + var hotKeyDown = ConfigRegistry.HotKeyOpen.Value.IsDown(); + var hotKeyDownOnClose = ConfigRegistry.CloseInventory.Value && hotKeyDown; + var hotKeyDrop = ConfigRegistry.OutwardMode.Value && ConfigRegistry.HotKeyDrop.Value.IsDown(); + + if (hotKeyDown && !BackpackIsOpen && player.CanOpenBackpack()) + { + if (instance.m_currentContainer != null) { - instance.CloseContainer(); - BackpackIsOpen = false; - - if (ConfigRegistry.CloseInventory.Value) - instance.Hide(); + instance.m_currentContainer.SetInUse(false); + instance.m_currentContainer = null; } + player.OpenBackpack(instance); + return false; + } + + if (hotKeyDown && BackpackIsOpen && !hotKeyDownOnClose) + { + instance.CloseContainer(); + BackpackIsOpen = false; + return false; + } + + if (hotKeyDrop) + { + player.QuickDropBackpack(); } - } + return defaultInputDown || hotKeyDownOnClose || hotKeyDrop; + } + public static bool DetectInputToShow(string defaultKeyCode, Player player, InventoryGui instance) + { + var zInputDown = ZInput.GetButtonDown(defaultKeyCode); + var hotKeyDown = ConfigRegistry.HotKeyOpen.Value.IsDown(); + var hotKeyDrop = ConfigRegistry.OutwardMode.Value && ConfigRegistry.HotKeyDrop.Value.IsDown(); + + if (hotKeyDrop) + { + player.QuickDropBackpack(); + } + + if (hotKeyDown && !BackpackIsOpen && player.CanOpenBackpack()) + { + _showBackpack = true; + } + + if (zInputDown && ConfigRegistry.OpenWithInventory.Value && !BackpackIsOpen && player.CanOpenBackpack()) + { + _showBackpack = true; + } + + if (_showBackpack && !BackpackIsOpen) + { + if (instance.m_currentContainer != null) + instance.CloseContainer(); + } + + return zInputDown || hotKeyDown || _showBackpack; + } + [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.Update))] static class InventoryGuiUpdateTranspiler { @@ -109,6 +170,8 @@ CodeInstruction LogMessage(CodeInstruction instruction) var resetButtonStatus = AccessTools.DeclaredMethod(typeof(ZInput), nameof(ZInput.ResetButtonStatus)); var hideMethod = AccessTools.DeclaredMethod(typeof(InventoryGui), nameof(InventoryGui.Hide)); var showMethod = AccessTools.DeclaredMethod(typeof(InventoryGui), nameof(InventoryGui.Show)); + var inputKeyDown = AccessTools.DeclaredMethod(typeof(Input), nameof(Input.GetKeyDown), new []{typeof(KeyCode)}); + var zInputButtonDown = AccessTools.DeclaredMethod(typeof(ZInput), nameof(ZInput.GetButtonDown), new []{typeof(string)}); for (int i = 0; i < instrs.Count; ++i) { @@ -151,10 +214,58 @@ CodeInstruction LogMessage(CodeInstruction instruction) //Patch ldloc_1 this is localPlayer. yield return LogMessage(localPlayerInstruction); counter++; + + //InventoryGui Argument. + yield return LogMessage(new CodeInstruction(OpCodes.Ldarg_0)); + counter++; //Patch Call Method for Hiding. yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), nameof(ShowBackpack)))); counter++; + } else if (i > 6 && instrs[i].opcode == OpCodes.Call && instrs[i].operand.Equals(inputKeyDown) && instrs[i - 1].operand.Equals((sbyte)KeyCode.Escape) && instrs[i + 2].opcode == OpCodes.Ldstr && instrs[i + 2].operand.Equals("Use")) + { + //Add Inventory Open Key from Config + //Get Player + var ldLocInstruction = new CodeInstruction(OpCodes.Ldloc_1); + //Move Any Labels from the instruction position being patched to new instruction. + if (instrs[i].labels.Count > 0) + instrs[i].MoveLabelsTo(ldLocInstruction); + + //Patch Call Method for Detecting Key Press + yield return LogMessage(ldLocInstruction); + counter++; + + //InventoryGui Argument. + yield return LogMessage(new CodeInstruction(OpCodes.Ldarg_0)); + counter++; + + //Patch Call Method for Detect Hide. + yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), nameof(DetectInputToHide)))); + counter++; + + } else if (i > 6 && instrs[i].opcode == OpCodes.Call && instrs[i].operand.Equals(zInputButtonDown) + && instrs[i - 1].operand.Equals("Inventory") && instrs[i + 1].opcode == OpCodes.Brtrue + && instrs[i + 2].opcode == OpCodes.Ldstr && instrs[i + 2].operand.Equals("JoyButtonY")) + { + + //Add Inventory Open Key from Config + //Get Player + var ldLocInstruction = new CodeInstruction(OpCodes.Ldloc_1); + //Move Any Labels from the instruction position being patched to new instruction. + if (instrs[i].labels.Count > 0) + instrs[i].MoveLabelsTo(ldLocInstruction); + + //Patch Call Method for Detecting Key Press + yield return LogMessage(ldLocInstruction); + counter++; + + //InventoryGui Argument. + yield return LogMessage(new CodeInstruction(OpCodes.Ldarg_0)); + counter++; + + //Patch Call Method for Detect Show. + yield return LogMessage(new CodeInstruction(OpCodes.Call, AccessTools.DeclaredMethod(typeof(InventoryGuiPatches), nameof(DetectInputToShow)))); + counter++; } else { @@ -164,39 +275,4 @@ CodeInstruction LogMessage(CodeInstruction instruction) } } } - - - [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.Update))] - static class InventoryGuiUpdatePatch - { - static void Postfix(Animator ___m_animator, ref Container ___m_currentContainer) - { - if ( !ConfigRegistry.HotKeyOpen.Value.IsDown() || !ZInput.GetButtonDown(ConfigRegistry.HotKeyOpen.Value.Serialize()) || !Player.m_localPlayer || !___m_animator.GetBool("visible")) - return; - - ZInput.ResetButtonStatus(ConfigRegistry.HotKeyOpen.Value.Serialize()); - - if (BackpackIsOpening) - { - BackpackIsOpening = false; - return; - } - - if (BackpackIsOpen) - { - InventoryGui.instance.CloseContainer(); - BackpackIsOpen = false; - - if (ConfigRegistry.CloseInventory.Value) - InventoryGui.instance.Hide(); - - return; - } - - if (Player.m_localPlayer.CanOpenBackpack()) - { - Player.m_localPlayer.OpenBackpack(false); - } - } - } } \ No newline at end of file diff --git a/AdventureBackpacks/Properties/AssemblyInfo.cs b/AdventureBackpacks/Properties/AssemblyInfo.cs index 8899a0f..305bfa8 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.12.0")] -[assembly: AssemblyFileVersion("1.6.12.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.6.13.0")] +[assembly: AssemblyFileVersion("1.6.13.0")] \ No newline at end of file diff --git a/PATCHNOTES.md b/PATCHNOTES.md index ffb07a8..83e3aef 100644 --- a/PATCHNOTES.md +++ b/PATCHNOTES.md @@ -1,5 +1,13 @@ # Adventure Backpacks Patchnotes +# 1.6.13.0 - Refactor of Backpack Interaction Controls +* Enhanced and improved the mechanics behind how backpacks open. +* Fixed the backpack not closing when open. +* All Configuration settings for backpack controls have been validated. + * **Please double check your settings if interactions have changed for you** +* Community has verified controller support from previous version. +* Fixed an issue with bags falling through the floor when dropped with Outward Mode + # 1.6.12.0 - Redefining Keymappings and Open with Inventory Option * Adjusted Config Keymappings to allow for Gamepad, Mouse, or Keyboard to be set. * Untested Controller Support - I'm hoping this works, but it might not. Please provide feedback. diff --git a/manifest.json b/manifest.json index d76bdaa..114c0de 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "AdventureBackpacks", - "version_number": "1.6.12", + "version_number": "1.6.13", "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": [