Decompiled source of CtrlClickToMoveItem v1.0.1

CtrlClickToMoveItem.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player.Inventory;
using UnityEngine.InputSystem;
using WildSkies.Gameplay.Items;
using WildSkies.Service;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("CtrlClickToMoveItem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("CtrlClickToMoveItem")]
[assembly: AssemblyTitle("CtrlClickToMoveItem")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CtrlClickToMoveItem
{
	[BepInPlugin("CtrlClickToMoveItem", "CtrlClickToMoveItem", "1.0.1")]
	public class Plugin : BasePlugin
	{
		internal static ManualLogSource Log;

		internal static Harmony harmonyInstance;

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("CtrlClickToMoveItem");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public override bool Unload()
		{
			Harmony obj = harmonyInstance;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			return true;
		}

		[HarmonyPatch(typeof(InventoryInput), "UpdateCurrentGridController")]
		[HarmonyPrefix]
		public static bool InventoryInput_UpdateCurrentGridController(InventoryInput __instance)
		{
			if (!__instance._holdTriggered && Keyboard.current.ctrlKey.isPressed && __instance._inputService.UIInput.UI.SplitStack.WasReleasedThisFrame())
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(InventoryInput), "UpdateCurrentGridController")]
		[HarmonyPostfix]
		public static void InventoryInput_UpdateCurrentGridController_Postfix(InventoryInput __instance)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Invalid comparison between Unknown and I4
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (__instance._playerInventoryService.InHandInventory.ItemInHand != null || __instance.CurrentActiveGridController.IsShowingSplitStack || __instance._holdTriggered || !Keyboard.current.ctrlKey.isPressed || !__instance._inputService.UIInput.UI.Click.WasReleasedThisFrame())
			{
				return;
			}
			DefaultInventory associatedInventory = ((GridControllerBase)__instance._inventoryPanel._storageGridController).AssociatedInventory;
			IPlayerInventoryService playerInventoryService = __instance._playerInventoryService;
			IInventoryItem val = default(IInventoryItem);
			if ((int)__instance._inventoryPanel._inventoryType != 4 || !__instance._currentActiveGridController._associatedInventory.ContainsItemOnGrid(__instance._currentActiveGridController._gridPosition, ref val))
			{
				return;
			}
			Nullable<ColorDataInfo> val2;
			try
			{
				val2 = val.ParentItem.Item.ItemColor;
			}
			catch
			{
				val2 = new Nullable<ColorDataInfo>();
			}
			InventoryItem val3 = InventoryItemFactory.CreateInventoryItem(val.ParentItem.Item.ItemDefinition, Math.Max(Keyboard.current.shiftKey.isPressed ? (val.StackCount / 2) : val.StackCount, 1), val.ParentItem.Item.CreatorName, val2, val.ParentItem.Item.ItemLevel);
			IInventoryItem val4 = default(IInventoryItem);
			if (((IEnumerable<DefaultInventory>)(object)new DefaultInventory[2] { playerInventoryService.DefaultPlayerInventory, playerInventoryService.BeltPlayerInventory }).Contains(__instance._currentActiveGridController.AssociatedInventory) && ((GridControllerBase)__instance._inventoryPanel._storageGridController).AssociatedInventory.TryDefaultAddItem(((Il2CppObjectBase)val3.ParentItem.Item).Cast<IItem>(), ref val4))
			{
				if (val.StackCount == val3.StackCount && playerInventoryService.ToolBarInventory.IsItemSlottedToToolbar(val))
				{
					playerInventoryService.ToolBarInventory.UnassignToolBarItem(val);
				}
				for (int i = 0; i < val3.StackCount; i++)
				{
					val.Use();
				}
				if (val.ParentItem.StackCount <= 0)
				{
					val.RemoveFromCurrentInventory(true);
				}
			}
			if (((Object)__instance._currentActiveGridController.AssociatedInventory).Equals((Object)(object)associatedInventory) && (playerInventoryService.DefaultPlayerInventory.TryDefaultAddItem(((Il2CppObjectBase)val3.ParentItem.Item).Cast<IItem>(), ref val4) || playerInventoryService.BeltPlayerInventory.TryDefaultAddItem(((Il2CppObjectBase)val3.ParentItem.Item).Cast<IItem>(), ref val4)))
			{
				for (int j = 0; j < val3.StackCount; j++)
				{
					val.Use();
				}
				if (val.ParentItem.StackCount <= 0)
				{
					val.RemoveFromCurrentInventory(true);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryInput), "HandleOverGridClickInputs")]
		[HarmonyPrefix]
		public static bool InventoryInput_HandleOverGridClickInputs(InventoryInput __instance)
		{
			if (!__instance._overAnyGrid)
			{
				return true;
			}
			if (!Keyboard.current.ctrlKey.isPressed || !__instance._inputService.UIInput.UI.Click.WasPressedThisFrame())
			{
				return true;
			}
			return false;
		}

		[HarmonyPatch(typeof(InventoryInput), "HandleHoldToActionInputs")]
		[HarmonyPrefix]
		public static void InventoryInput_HandleHoldToActionInputs(InventoryInput __instance)
		{
			if (Keyboard.current.ctrlKey.isPressed && __instance._inputService.UIInput.UI.Discard.IsPressed())
			{
				__instance._holdTimer = 1f;
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "CtrlClickToMoveItem";

		public const string PLUGIN_NAME = "CtrlClickToMoveItem";

		public const string PLUGIN_VERSION = "1.0.1";
	}
}