From 3c0a9b84ef4d7374b4813efa48b36f312d4afd42 Mon Sep 17 00:00:00 2001 From: Pete Navarra Date: Wed, 8 Feb 2023 11:58:07 -0500 Subject: [PATCH 1/2] Redesigining how Fast Link works to ensure Compatibility This allows Auto Split Stack as well as Quick Stack Sort to work flawlessly. --- FastItemTransfer/FastItemTransfer.csproj | 6 +- FastItemTransfer/Features/QuickTransfer.cs | 64 ++++++++++++++++------ 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/FastItemTransfer/FastItemTransfer.csproj b/FastItemTransfer/FastItemTransfer.csproj index 8d79103..981e678 100644 --- a/FastItemTransfer/FastItemTransfer.csproj +++ b/FastItemTransfer/FastItemTransfer.csproj @@ -39,13 +39,13 @@ ..\..\References\BepInEx\5.4.1901\BepInEx\core\0Harmony.dll - ..\..\References\Valheim\0.212.9\assembly_guiutils_publicized.dll + ..\..\References\Valheim\0.213.4\assembly_guiutils_publicized.dll - ..\..\References\Valheim\0.212.9\assembly_utils_publicized.dll + ..\..\References\Valheim\0.213.4\assembly_utils_publicized.dll - ..\..\References\Valheim\0.212.9\assembly_valheim_publicized.dll + ..\..\References\Valheim\0.213.4\assembly_valheim_publicized.dll ..\..\References\BepInEx\5.4.1901\BepInEx\core\BepInEx.dll diff --git a/FastItemTransfer/Features/QuickTransfer.cs b/FastItemTransfer/Features/QuickTransfer.cs index 2023fa5..0ffd848 100644 --- a/FastItemTransfer/Features/QuickTransfer.cs +++ b/FastItemTransfer/Features/QuickTransfer.cs @@ -1,4 +1,5 @@ -using BepInEx.Bootstrap; +using System; +using BepInEx.Bootstrap; using BepInEx.Configuration; using FastItemTransfer.Configuration; using HarmonyLib; @@ -12,6 +13,12 @@ public class QuickTransfer { public static bool FeatureInitialized = false; public static ConfigEntry EnableQuickTransfer { get; private set;} + + private static InventoryGui _inventoryGuiInstance; + private static Inventory _fromInventory; + private static Inventory _toInventory; + + private static bool _processingRightClick = false; static QuickTransfer() { @@ -27,53 +34,74 @@ private static void RegisterConfiguraitonFile() } [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.OnRightClickItem))] + [HarmonyPriority(Priority.First)] static class OnRightClickItemPatch { - static bool Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item) + static void Prefix(InventoryGui __instance, InventoryGrid grid, ItemDrop.ItemData item) { if (!FeatureInitialized) - return true; + return; if (Player.m_localPlayer == null || __instance == null || item == null) - return false; + return; if (__instance.m_currentContainer == null || !__instance.IsContainerOpen() || !EnableQuickTransfer.Value) - return true; + return; if (Chainloader.PluginInfos.ContainsKey("blumaye.quicktransfer")) { FastItemTransfer.Log.Warning("blumaye.quicktransfer mod is enabled. Fast Item Transfer disabled."); - return true; + return; } if (item.m_equiped) - return true; + return; var containerInventory = __instance.m_currentContainer.GetInventory(); - var playerInventory = Player.m_localPlayer.GetInventory(); if (playerInventory == null || containerInventory == null || grid == null) - return true; - - Inventory fromInventory; - Inventory toInventory; + return; + _inventoryGuiInstance = __instance; + if (grid.m_inventory == containerInventory) { - fromInventory = containerInventory; - toInventory = playerInventory; + _fromInventory = containerInventory; + _toInventory = playerInventory; } else { - fromInventory = playerInventory; - toInventory = containerInventory; + _fromInventory = playerInventory; + _toInventory = containerInventory; } - toInventory.MoveItemToThis(fromInventory, item); - __instance.m_moveItemEffects.Create(__instance.transform.position, Quaternion.identity); + _processingRightClick = true; + } + + static void Finalizer(Exception __exception) + { + _processingRightClick = false; + _toInventory = null; + _fromInventory = null; + _inventoryGuiInstance = null; + } + } + + [HarmonyPatch(typeof(Humanoid), nameof(Humanoid.UseItem))] + [HarmonyPriority(Priority.First)] + static class UseItemPatch + { + static bool Prefix(ItemDrop.ItemData item) + { + if (!_processingRightClick) + return true; + + _toInventory.MoveItemToThis(_fromInventory, item); + _inventoryGuiInstance.m_moveItemEffects.Create(_inventoryGuiInstance.transform.position, Quaternion.identity); return false; } } + } \ No newline at end of file From 55fbdc5f8ee0b5884029787a59aa028528e7eb1c Mon Sep 17 00:00:00 2001 From: Pete Navarra Date: Wed, 8 Feb 2023 14:00:15 -0500 Subject: [PATCH 2/2] Release 1.0.1 --- FastItemTransfer/FastItemTransfer.cs | 2 +- FastItemTransfer/Features/QuickTransfer.cs | 7 ++++--- FastItemTransfer/Properties/AssemblyInfo.cs | 4 ++-- PATCHNOTES.md | 5 +++++ README.md | 6 ++++++ manifest.json | 2 +- 6 files changed, 19 insertions(+), 7 deletions(-) diff --git a/FastItemTransfer/FastItemTransfer.cs b/FastItemTransfer/FastItemTransfer.cs index e19c964..daf2447 100644 --- a/FastItemTransfer/FastItemTransfer.cs +++ b/FastItemTransfer/FastItemTransfer.cs @@ -19,7 +19,7 @@ public class FastItemTransfer : BaseUnityPlugin, IPluginInfo //Module Constants private const string _pluginId = "vapok.mods.fastitemtransfer"; private const string _displayName = "Fast Item Transfer"; - private const string _version = "1.0.0"; + private const string _version = "1.0.1"; //Interface Properties public string PluginId => _pluginId; diff --git a/FastItemTransfer/Features/QuickTransfer.cs b/FastItemTransfer/Features/QuickTransfer.cs index 0ffd848..2ccf6c2 100644 --- a/FastItemTransfer/Features/QuickTransfer.cs +++ b/FastItemTransfer/Features/QuickTransfer.cs @@ -9,7 +9,7 @@ namespace FastItemTransfer.Features; -public class QuickTransfer +public static class QuickTransfer { public static bool FeatureInitialized = false; public static ConfigEntry EnableQuickTransfer { get; private set;} @@ -22,10 +22,10 @@ public class QuickTransfer static QuickTransfer() { - ConfigRegistry.Waiter.StatusChanged += (_, _) => RegisterConfiguraitonFile(); + ConfigRegistry.Waiter.StatusChanged += (_, _) => RegisterConfigurationFile(); } - private static void RegisterConfiguraitonFile() + private static void RegisterConfigurationFile() { EnableQuickTransfer = ConfigSyncBase.UnsyncedConfig("Local Config", "Enable Quick Right Click Item Transfer", true, new ConfigDescription("When enabled, can move items to/from player inventory to container, by right clicking.", @@ -85,6 +85,7 @@ static void Finalizer(Exception __exception) _toInventory = null; _fromInventory = null; _inventoryGuiInstance = null; + } } diff --git a/FastItemTransfer/Properties/AssemblyInfo.cs b/FastItemTransfer/Properties/AssemblyInfo.cs index 7e648a3..dc0b591 100644 --- a/FastItemTransfer/Properties/AssemblyInfo.cs +++ b/FastItemTransfer/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.0.0.0")] -[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file +[assembly: AssemblyVersion("1.0.1.0")] +[assembly: AssemblyFileVersion("1.0.1.0")] \ No newline at end of file diff --git a/PATCHNOTES.md b/PATCHNOTES.md index 6d269d7..f3eb5ae 100644 --- a/PATCHNOTES.md +++ b/PATCHNOTES.md @@ -1,5 +1,10 @@ # Fast Item Transfer Patchnotes +# 1.0.1 - Module Compatibility +* Reworked Logic to make Fast Item Transfer friendly to other inventory mods. + * Adds Compatibility to **[Auto Split Stack](https://www.nexusmods.com/valheim/mods/76?tab=files&file_id=7184)**, as well as **[Quick Stack Sort](https://www.nexusmods.com/valheim/mods/2094?tab=description)** + * May add additional compatibility to other mods not tested. + # 1.0.0 - Initial Release * Provides Right Click functionality to move items between Player Inventory and Containers * Lightweight, minimal overhead QoL Module \ No newline at end of file diff --git a/README.md b/README.md index 73c42ea..2984678 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,12 @@ There is very little configuration. Simply enable or disable. * Adding Modifer's (CTRL/ALT/SHIFT) to add additional functionality. ### Current Patch Notes + +# 1.0.1 - Module Compatibility +* Reworked Logic to make Fast Item Transfer friendly to other inventory mods. + * Adds Compatibility to **[Auto Split Stack](https://www.nexusmods.com/valheim/mods/76?tab=files&file_id=7184)**, as well as **[Quick Stack Sort](https://www.nexusmods.com/valheim/mods/2094?tab=description)** + * May add additional compatibility to other mods not tested. + #### 1.0.0 - Initial Release * Provides Right Click functionality to move items between Player Inventory and Containers * Lightweight, minimal overhead QoL Module diff --git a/manifest.json b/manifest.json index 03486f8..2c098d4 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "FastItemTransfer", - "version_number": "1.0.0", + "version_number": "1.0.1", "website_url": "https://github.com/Vapok/FastItemTransfer", "description": "", "dependencies": [