Skip to content

Commit

Permalink
Merge pull request #3 from Vapok/vapok/r1.0.1
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
Vapok authored Feb 8, 2023
2 parents a6afb46 + 55fbdc5 commit 9a2f041
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 28 deletions.
2 changes: 1 addition & 1 deletion FastItemTransfer/FastItemTransfer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions FastItemTransfer/FastItemTransfer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,13 @@
<HintPath>..\..\References\BepInEx\5.4.1901\BepInEx\core\0Harmony.dll</HintPath>
</Reference>
<Reference Include="assembly_guiutils">
<HintPath>..\..\References\Valheim\0.212.9\assembly_guiutils_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.213.4\assembly_guiutils_publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_utils">
<HintPath>..\..\References\Valheim\0.212.9\assembly_utils_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.213.4\assembly_utils_publicized.dll</HintPath>
</Reference>
<Reference Include="assembly_valheim">
<HintPath>..\..\References\Valheim\0.212.9\assembly_valheim_publicized.dll</HintPath>
<HintPath>..\..\References\Valheim\0.213.4\assembly_valheim_publicized.dll</HintPath>
</Reference>
<Reference Include="BepInEx">
<HintPath>..\..\References\BepInEx\5.4.1901\BepInEx\core\BepInEx.dll</HintPath>
Expand Down
71 changes: 50 additions & 21 deletions FastItemTransfer/Features/QuickTransfer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using BepInEx.Bootstrap;
using System;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using FastItemTransfer.Configuration;
using HarmonyLib;
Expand All @@ -8,17 +9,23 @@

namespace FastItemTransfer.Features;

public class QuickTransfer
public static class QuickTransfer
{
public static bool FeatureInitialized = false;
public static ConfigEntry<bool> EnableQuickTransfer { get; private set;}

private static InventoryGui _inventoryGuiInstance;
private static Inventory _fromInventory;
private static Inventory _toInventory;

private static bool _processingRightClick = false;

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.",
Expand All @@ -27,53 +34,75 @@ 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;
}
}

}
4 changes: 2 additions & 2 deletions FastItemTransfer/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.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]
5 changes: 5 additions & 0 deletions PATCHNOTES.md
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -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": [
Expand Down

0 comments on commit 9a2f041

Please sign in to comment.