Decompiled source of DropJustEnough v1.0.2

DropJustEnough.dll

Decompiled 12 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("DropJustEnough")]
[assembly: AssemblyDescription("Fork of DeekyJay's DropJustEnough mod")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("DropJustEnough")]
[assembly: AssemblyCopyright("Copyright ©2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b88fb0e4-bdb0-494a-b2f9-38c9f0d32e23")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace DropJustEnough
{
	[BepInPlugin("io.gimrall.plugins.dropjustenough", "DropJustEnough", "1.0.2.0")]
	[BepInProcess("valheim.exe")]
	public class DropJustEnoughPlugin : BaseUnityPlugin
	{
		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("io.gimrall.plugins.dropjustenough").PatchAll();
		}
	}
}
namespace DropJustEnough.GameClasses
{
	[HarmonyPatch(typeof(InventoryGrid), "OnLeftClick")]
	public static class InventoryGrid_Patch_OnLeftClick_DropJustEnoughItems
	{
		private static bool Prefix(ref InventoryGrid __instance, ref Inventory ___m_inventory, UIInputHandler clickHandler)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Vector2i buttonPos = __instance.GetButtonPos(((Component)clickHandler).gameObject);
			ItemData itemAt = ___m_inventory.GetItemAt(buttonPos.x, buttonPos.y);
			if (Input.GetKey((KeyCode)308) || Input.GetKey((KeyCode)307))
			{
				return !DropJustEnoughItems(___m_inventory, itemAt);
			}
			return true;
		}

		private static bool DropJustEnoughItems(Inventory inventory, ItemData item)
		{
			float totalWeight = inventory.GetTotalWeight();
			float weight = item.GetWeight(item.m_stack);
			float num = weight / (float)item.m_stack;
			float maxCarryWeight = Player.m_localPlayer.GetMaxCarryWeight();
			float num2 = totalWeight - maxCarryWeight;
			if (totalWeight < maxCarryWeight)
			{
				return false;
			}
			int num3 = ((weight > num2) ? ((int)Math.Ceiling(num2 / num)) : item.m_stack);
			return ((Humanoid)Player.m_localPlayer).DropItem(inventory, item, num3);
		}
	}
}