Decompiled source of DropAllStack v1.0.1

BepInEx/plugins/DropAllStack.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using DropAllStack.Configuration;
using DropAllStack.Localization;
using DropAllStack.Utils;
using HarmonyLib;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DropAllStack")]
[assembly: AssemblyDescription("DropAllStack mod for Old Market Simulator by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("DropAllStack")]
[assembly: AssemblyCopyright("Copyright © 2025 Ice Box Studio")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("A9D8C2D1-9E43-4C2E-9B9A-0E7C5D7B2C11")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.1.0")]
[HarmonyPatch(typeof(PlayerInventory), "GiveItemServerRpc")]
public static class PlayerInventory_GiveItemServerRpc_PrefixPatch
{
	[HarmonyPrefix]
	public static void Prefix(ref int cost)
	{
		if (cost < 0)
		{
			cost = 0;
		}
	}
}
[HarmonyPatch(typeof(PlayerInventory), "HandleDrop")]
public static class PlayerInventory_HandleDrop_PrefixPatch
{
	private static InputAction holdStackAction;

	private static InputAction decreaseStackAction;

	private static InputAction increaseStackAction;

	private static InputAction toggleStackTargetAction;

	internal static bool holdPressed;

	static PlayerInventory_HandleDrop_PrefixPatch()
	{
		InitializeHotkeys();
	}

	private static void InitializeHotkeys()
	{
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Expected O, but got Unknown
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Expected O, but got Unknown
		string value = ConfigManager.HoldKey.Value;
		string value2 = ConfigManager.DecreaseKey.Value;
		string value3 = ConfigManager.IncreaseKey.Value;
		string value4 = ConfigManager.ToggleStackTargetKey.Value;
		holdStackAction = new InputAction("HoldStack", (InputActionType)1, "<Keyboard>/" + value, (string)null, (string)null, (string)null);
		decreaseStackAction = new InputAction("DecreaseStack", (InputActionType)1, "<Keyboard>/" + value2, (string)null, (string)null, (string)null);
		increaseStackAction = new InputAction("IncreaseStack", (InputActionType)1, "<Keyboard>/" + value3, (string)null, (string)null, (string)null);
		toggleStackTargetAction = new InputAction("ToggleStackTarget", (InputActionType)1, "<Keyboard>/" + value4, (string)null, (string)null, (string)null);
		holdStackAction.performed += delegate
		{
			holdPressed = true;
		};
		holdStackAction.canceled += delegate
		{
			holdPressed = false;
		};
		decreaseStackAction.performed += delegate
		{
			if (ConfigManager.EnableMod.Value && holdPressed)
			{
				ConfigManager.AdjustCurrentStackLayers(-1);
				UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText("hud.stack_layers_value", ConfigManager.CurrentStackLayers, Mathf.Min(8, ConfigManager.MaxStackLayers.Value)), true, 2f, false);
			}
		};
		increaseStackAction.performed += delegate
		{
			if (ConfigManager.EnableMod.Value && holdPressed)
			{
				ConfigManager.AdjustCurrentStackLayers(1);
				UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText("hud.stack_layers_value", ConfigManager.CurrentStackLayers, Mathf.Min(8, ConfigManager.MaxStackLayers.Value)), true, 2f, false);
			}
		};
		toggleStackTargetAction.performed += delegate
		{
			if (ConfigManager.EnableMod.Value && holdPressed)
			{
				ConfigManager.ToggleStackTargetMode();
				bool flag = ConfigManager.StackTargetMode.Value == "Player";
				UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText(flag ? "hud.stack_target_player" : "hud.stack_target_mouse"), true, 2f, false);
			}
		};
		holdStackAction.Enable();
		decreaseStackAction.Enable();
		increaseStackAction.Enable();
		toggleStackTargetAction.Enable();
	}

	[HarmonyPrefix]
	public static bool Prefix(PlayerInventory __instance)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0405: Unknown result type (might be due to invalid IL or missing references)
		//IL_040a: Unknown result type (might be due to invalid IL or missing references)
		//IL_040f: Unknown result type (might be due to invalid IL or missing references)
		//IL_041c: Unknown result type (might be due to invalid IL or missing references)
		//IL_045b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0472: Unknown result type (might be due to invalid IL or missing references)
		//IL_0477: Unknown result type (might be due to invalid IL or missing references)
		//IL_047c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0430: Unknown result type (might be due to invalid IL or missing references)
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0451: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_049a: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_04bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Unknown result type (might be due to invalid IL or missing references)
		//IL_025a: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_057b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0585: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02de: Unknown result type (might be due to invalid IL or missing references)
		//IL_055c: Unknown result type (might be due to invalid IL or missing references)
		//IL_055e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0735: Unknown result type (might be due to invalid IL or missing references)
		//IL_073a: Unknown result type (might be due to invalid IL or missing references)
		//IL_073c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0743: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_074e: Unknown result type (might be due to invalid IL or missing references)
		//IL_05df: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0313: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0221: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Unknown result type (might be due to invalid IL or missing references)
		//IL_022b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0764: Unknown result type (might be due to invalid IL or missing references)
		//IL_0776: Unknown result type (might be due to invalid IL or missing references)
		//IL_077b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0780: Unknown result type (might be due to invalid IL or missing references)
		//IL_0787: Unknown result type (might be due to invalid IL or missing references)
		//IL_078e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0790: Unknown result type (might be due to invalid IL or missing references)
		//IL_079b: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_07ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_032a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0341: Unknown result type (might be due to invalid IL or missing references)
		//IL_0346: Unknown result type (might be due to invalid IL or missing references)
		//IL_034b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0611: Unknown result type (might be due to invalid IL or missing references)
		//IL_0623: Unknown result type (might be due to invalid IL or missing references)
		//IL_0628: Unknown result type (might be due to invalid IL or missing references)
		//IL_062d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0634: Unknown result type (might be due to invalid IL or missing references)
		//IL_063b: Unknown result type (might be due to invalid IL or missing references)
		//IL_063d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0648: Unknown result type (might be due to invalid IL or missing references)
		//IL_064e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0655: Unknown result type (might be due to invalid IL or missing references)
		//IL_0673: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0701: Unknown result type (might be due to invalid IL or missing references)
		//IL_068e: Unknown result type (might be due to invalid IL or missing references)
		//IL_06b5: Unknown result type (might be due to invalid IL or missing references)
		if (!ConfigManager.EnableMod.Value)
		{
			return true;
		}
		if (!holdPressed)
		{
			return true;
		}
		PlayerActions player = InputManager.Instance.inputMaster.Player;
		if (!((PlayerActions)(ref player)).Drop.WasPerformedThisFrame())
		{
			return true;
		}
		InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
		if (currentInventorySlot.itemId == -1)
		{
			return false;
		}
		Camera main = Camera.main;
		Quaternion rotation = ((Component)main).transform.rotation;
		Quaternion val = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
		ItemSO itemById = GameManager.Instance.GetItemById(currentInventorySlot.itemId);
		Quaternion val2 = val * itemById.prefab.transform.rotation;
		BoundsInfo stackInfo = BoundsHelper.GetStackInfo(currentInventorySlot.itemId, itemById, val2);
		float height = stackInfo.Height;
		Vector3 val3 = ((Component)__instance).transform.position + new Vector3(0f, 0f - stackInfo.MinY, 0f);
		RaycastHit val4 = default(RaycastHit);
		if (!(ConfigManager.StackTargetMode.Value == "Mouse"))
		{
			val3 = ((!Physics.Raycast(((Component)__instance).transform.position + Vector3.up * 3f, Vector3.down, ref val4, 100f, LayerMask.op_Implicit(__instance.itemPlacementLayerMask), (QueryTriggerInteraction)1)) ? (((Component)__instance).transform.position + new Vector3(0f, 0f - stackInfo.MinY, 0f)) : (((RaycastHit)(ref val4)).point + new Vector3(0f, 0f - stackInfo.MinY, 0f)));
		}
		else
		{
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			bool flag4 = false;
			float num = Mathf.Max(1f, ConfigManager.StackMouseMaxDistance.Value);
			if (Mouse.current != null)
			{
				Vector2 val5 = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
				if (Physics.Raycast(main.ScreenPointToRay(Vector2.op_Implicit(val5)), ref val4, 100f, ~LayerMask.op_Implicit(__instance.blockIgnoredLayerMask), (QueryTriggerInteraction)2))
				{
					Collider collider = ((RaycastHit)(ref val4)).collider;
					bool flag5 = ((Component)collider).CompareTag("Water") || ((Object)(object)((Component)collider).transform.parent != (Object)null && ((Component)((Component)collider).transform.parent).CompareTag("Water"));
					bool flag6 = !ConfigManager.EnableSurfaceRestriction.Value || Vector3.Dot(((RaycastHit)(ref val4)).normal, Vector3.up) > 0.5f;
					if (!ConfigManager.EnableSurfaceRestriction.Value || (!flag5 && flag6))
					{
						if (Vector3.Distance(((Component)__instance).transform.position, ((RaycastHit)(ref val4)).point) <= num)
						{
							val3 = ((RaycastHit)(ref val4)).point + new Vector3(0f, 0f - stackInfo.MinY, 0f);
							flag = true;
						}
						else
						{
							flag4 = true;
						}
					}
					else if (flag5)
					{
						flag2 = true;
					}
					else
					{
						flag3 = true;
					}
				}
				else
				{
					flag3 = true;
				}
			}
			if (!flag)
			{
				if (Physics.Raycast(main.ViewportPointToRay(Vector3.one / 2f), ref val4, 100f, ~LayerMask.op_Implicit(__instance.blockIgnoredLayerMask), (QueryTriggerInteraction)2))
				{
					Collider collider2 = ((RaycastHit)(ref val4)).collider;
					bool flag7 = ((Component)collider2).CompareTag("Water") || ((Object)(object)((Component)collider2).transform.parent != (Object)null && ((Component)((Component)collider2).transform.parent).CompareTag("Water"));
					bool flag8 = !ConfigManager.EnableSurfaceRestriction.Value || Vector3.Dot(((RaycastHit)(ref val4)).normal, Vector3.up) > 0.5f;
					if (!ConfigManager.EnableSurfaceRestriction.Value || (!flag7 && flag8))
					{
						if (Vector3.Distance(((Component)__instance).transform.position, ((RaycastHit)(ref val4)).point) <= num)
						{
							val3 = ((RaycastHit)(ref val4)).point + new Vector3(0f, 0f - stackInfo.MinY, 0f);
							flag = true;
						}
						else
						{
							flag4 = true;
						}
					}
					else if (flag7)
					{
						flag2 = true;
					}
					else
					{
						flag3 = true;
					}
				}
				else
				{
					flag3 = true;
				}
			}
			if (!flag)
			{
				if (flag2)
				{
					UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText("hud.stack_mouse_on_water"), true, 2f, false);
				}
				else if (flag3)
				{
					UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText("hud.stack_mouse_invalid_surface"), true, 2f, false);
				}
				else if (flag4)
				{
					UIManager.Instance.ShowLocalNotification(LocalizationManager.Instance.GetLocalizedText("hud.stack_mouse_too_far"), true, 2f, false);
				}
				return false;
			}
		}
		int num2 = 0;
		int num3 = Mathf.Clamp(ConfigManager.CurrentStackLayers, 1, ConfigManager.MaxStackLayers.Value);
		RaycastHit val6 = default(RaycastHit);
		float num4 = 0.01f;
		RaycastHit[] array = Physics.RaycastAll(val3 + new Vector3(0f, 0.001f, 0f), Vector3.up, 100f, LayerMask.op_Implicit(__instance.itemObstacleLayerMask), (QueryTriggerInteraction)1);
		float num5 = float.MaxValue;
		bool flag9 = false;
		RaycastHit[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val7 = array2[i];
			if (((Component)((RaycastHit)(ref val7)).collider).gameObject.layer != LayerMask.NameToLayer("Player") && !((Component)((RaycastHit)(ref val7)).collider).transform.IsChildOf(((Component)__instance).transform) && !((Object)(object)((Component)((RaycastHit)(ref val7)).collider).transform == (Object)(object)((Component)__instance).transform) && ((RaycastHit)(ref val7)).distance < num5)
			{
				num5 = ((RaycastHit)(ref val7)).distance;
				val6 = val7;
				flag9 = true;
			}
		}
		if (flag9)
		{
			int num6 = Mathf.Max(0, Mathf.FloorToInt((((RaycastHit)(ref val6)).point.y - val3.y - num4) / height));
			num3 = Mathf.Min(num3, num6);
		}
		if (itemById.stackSize > 1)
		{
			for (int j = 0; j < __instance.slots.Count; j++)
			{
				InventorySlot val8 = __instance.slots[j];
				if (val8.itemId == currentInventorySlot.itemId && val8.amount > 0)
				{
					if (num2 >= num3)
					{
						break;
					}
					int num7 = num3 - num2;
					int num8 = Mathf.Min(val8.amount, num7);
					for (int k = 0; k < num8; k++)
					{
						Vector3 val9 = val3 + new Vector3(0f, height * (float)num2, 0f);
						GameManager.Instance.SpawnItemAtPositionServerRpc(val8.itemId, val9, val2, ConfigManager.EnablePhysicsOnStack.Value, Vector3.zero, 1, val8.cost, val8.dayCounter);
						num2++;
					}
					int num9 = val8.amount - num8;
					if (num9 <= 0)
					{
						__instance.slots[j] = new InventorySlot
						{
							itemId = -1L,
							amount = -1,
							cost = -1,
							dayCounter = -1
						};
					}
					else
					{
						__instance.slots[j] = new InventorySlot
						{
							itemId = val8.itemId,
							amount = num9,
							cost = val8.cost,
							dayCounter = val8.dayCounter
						};
					}
				}
			}
		}
		else
		{
			for (int l = 0; l < __instance.slots.Count; l++)
			{
				InventorySlot val10 = __instance.slots[l];
				if (val10.itemId == currentInventorySlot.itemId && val10.amount > 0)
				{
					if (num2 >= num3)
					{
						break;
					}
					Vector3 val11 = val3 + new Vector3(0f, height * (float)num2, 0f);
					GameManager.Instance.SpawnItemAtPositionServerRpc(val10.itemId, val11, val2, ConfigManager.EnablePhysicsOnStack.Value, Vector3.zero, val10.amount, val10.cost, val10.dayCounter);
					num2++;
					__instance.slots[l] = new InventorySlot
					{
						itemId = -1L,
						amount = -1,
						cost = -1,
						dayCounter = -1
					};
				}
			}
		}
		__instance.audioSource.PlayOneShot(__instance.dropSound, 0.2f);
		return false;
	}
}
[HarmonyPatch(typeof(PlayerInventory), "HandleThrow")]
public static class PlayerInventory_HandleThrow_PrefixPatch
{
	[HarmonyPrefix]
	public static bool Prefix(PlayerInventory __instance)
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0303: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_031a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_0325: Unknown result type (might be due to invalid IL or missing references)
		//IL_0327: Unknown result type (might be due to invalid IL or missing references)
		//IL_032f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_036c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01da: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_022a: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_029e: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		if (!ConfigManager.EnableMod.Value)
		{
			return true;
		}
		if (!PlayerInventory_HandleDrop_PrefixPatch.holdPressed)
		{
			return true;
		}
		PlayerActions player = InputManager.Instance.inputMaster.Player;
		if (!((PlayerActions)(ref player)).Throw.WasPerformedThisFrame())
		{
			return true;
		}
		InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
		if (currentInventorySlot.itemId == -1)
		{
			return false;
		}
		float num = 0.25f;
		Camera main = Camera.main;
		Vector3 val = ((Component)__instance).transform.position + new Vector3(((Component)main).transform.forward.x, 0f, ((Component)main).transform.forward.z) * num + new Vector3(0f, 1f, 0f);
		Quaternion rotation = ((Component)main).transform.rotation;
		Quaternion val2 = Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f);
		ItemSO itemById = GameManager.Instance.GetItemById(currentInventorySlot.itemId);
		Quaternion val3 = val2 * itemById.prefab.transform.rotation;
		Vector3 val4 = (((Component)main).transform.forward + new Vector3(0f, 1f, 0f)) * 3f + __instance.exampleCharacterSetup.kinematicCharacterMotor.BaseVelocity / 2f;
		int num2 = Mathf.Max(1, ConfigManager.ThrowAllLimit.Value);
		int num3 = 0;
		bool flag = GameManager.Instance.GetItemById(currentInventorySlot.itemId) is TreeSO;
		if (Chainloader.PluginInfos.ContainsKey("IceBoxStudio.BetterMarketPlus") && flag)
		{
			return true;
		}
		if (itemById.stackSize > 1)
		{
			for (int i = 0; i < __instance.slots.Count; i++)
			{
				InventorySlot val5 = __instance.slots[i];
				if (val5.itemId != currentInventorySlot.itemId || val5.amount <= 0)
				{
					continue;
				}
				int num4 = Mathf.Min(val5.amount, num2 - num3);
				for (int j = 0; j < num4; j++)
				{
					GameManager.Instance.SpawnItemAtPositionServerRpc(val5.itemId, val, val3, true, val4, 1, -1, val5.dayCounter);
					num3++;
					if (num3 >= num2)
					{
						break;
					}
				}
				int num5 = val5.amount - num4;
				if (num5 <= 0)
				{
					__instance.slots[i] = new InventorySlot
					{
						itemId = -1L,
						amount = -1,
						cost = -1,
						dayCounter = -1
					};
				}
				else
				{
					__instance.slots[i] = new InventorySlot
					{
						itemId = val5.itemId,
						amount = num5,
						cost = val5.cost,
						dayCounter = val5.dayCounter
					};
				}
				if (num3 >= num2)
				{
					break;
				}
			}
		}
		else
		{
			for (int k = 0; k < __instance.slots.Count; k++)
			{
				InventorySlot val6 = __instance.slots[k];
				if (val6.itemId == currentInventorySlot.itemId && val6.amount > 0)
				{
					GameManager.Instance.SpawnItemAtPositionServerRpc(val6.itemId, val, val3, true, val4, val6.amount, -1, val6.dayCounter);
					__instance.slots[k] = new InventorySlot
					{
						itemId = -1L,
						amount = -1,
						cost = -1,
						dayCounter = -1
					};
					num3++;
					if (num3 >= num2)
					{
						break;
					}
				}
			}
		}
		__instance.audioSource.PlayOneShot(__instance.throwSound, 0.1f);
		return false;
	}
}
internal static class GhostCollisionStore
{
	public static readonly HashSet<Item> GhostItems = new HashSet<Item>();

	public static readonly Dictionary<Item, Collider[]> ItemColliders = new Dictionary<Item, Collider[]>();
}
[HarmonyPatch(typeof(Item), "ServerSetupItem")]
public static class Item_ServerSetupItem_PostfixPatch
{
	[HarmonyPostfix]
	public static void Postfix(Item __instance, long itemId, bool enableRigidbodyOnSpawn, int amount, int cost, int dayCounter, bool onStand, float priceTagYRotation = 0f)
	{
		if (cost >= 0)
		{
			return;
		}
		Collider[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<Collider>(true);
		GhostCollisionStore.ItemColliders[__instance] = componentsInChildren;
		GhostCollisionStore.GhostItems.Add(__instance);
		foreach (Item ghostItem in GhostCollisionStore.GhostItems)
		{
			if (!((Object)(object)ghostItem != (Object)(object)__instance) || !GhostCollisionStore.ItemColliders.ContainsKey(ghostItem))
			{
				continue;
			}
			Collider[] array = GhostCollisionStore.ItemColliders[ghostItem];
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				for (int j = 0; j < array.Length; j++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null && (Object)(object)array[j] != (Object)null)
					{
						Physics.IgnoreCollision(componentsInChildren[i], array[j], true);
					}
				}
			}
		}
	}
}
[HarmonyPatch(typeof(Item), "OnNetworkDespawn")]
public static class Item_OnNetworkDespawn_PostfixPatch
{
	[HarmonyPostfix]
	public static void Postfix(Item __instance)
	{
		if (GhostCollisionStore.GhostItems.Contains(__instance) && GhostCollisionStore.ItemColliders.ContainsKey(__instance))
		{
			GhostCollisionStore.GhostItems.Remove(__instance);
			GhostCollisionStore.ItemColliders.Remove(__instance);
		}
	}
}
namespace DropAllStack
{
	[BepInPlugin("IceBoxStudio.DropAllStack", "DropAllStack", "1.0.1")]
	public class DropAllStack : BaseUnityPlugin
	{
		private static DropAllStack _instance;

		private Harmony _harmony;

		private bool patchesApplied;

		public static DropAllStack Instance => _instance;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			_instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Logger.LogInfo((object)"=============================================");
				Logger.LogInfo((object)("DropAllStack " + LocalizationManager.Instance.GetLocalizedText("plugin.initializing")));
				Logger.LogInfo((object)(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix") + "Ice Box Studio(https://steamcommunity.com/id/ibox666/)"));
				ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
				ApplyPatches();
				Logger.LogInfo((object)("DropAllStack " + LocalizationManager.Instance.GetLocalizedText("plugin.initialized")));
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("DropAllStack 初始化错误: " + ex.Message + "\n" + ex.StackTrace));
			}
		}

		private void ApplyPatches()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!patchesApplied)
			{
				try
				{
					_harmony = new Harmony("IceBoxStudio.DropAllStack");
					_harmony.PatchAll();
					patchesApplied = true;
					return;
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("DropAllStack 应用补丁错误: " + ex.Message + "\n" + ex.StackTrace));
					return;
				}
			}
			Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.DropAllStack";

		public const string PLUGIN_NAME = "DropAllStack";

		public const string PLUGIN_VERSION = "1.0.1";

		public const string PLUGIN_AUTHOR = "Ice Box Studio";

		public const string PLUGIN_DESCRIPTION = "按住快捷键可一键堆叠/丢弃背包中相同物品。";
	}
}
namespace DropAllStack.Utils
{
	public struct BoundsInfo
	{
		public float MinY;

		public float Height;
	}
	public static class BoundsHelper
	{
		private static Matrix4x4 AccumulateToRoot(Transform child, Transform root)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> list = new List<Transform>();
			Transform val = child;
			while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)root)
			{
				list.Add(val);
				val = val.parent;
			}
			Matrix4x4 val2 = Matrix4x4.identity;
			for (int num = list.Count - 1; num >= 0; num--)
			{
				Transform val3 = list[num];
				val2 *= Matrix4x4.TRS(val3.localPosition, val3.localRotation, val3.localScale);
			}
			return val2;
		}

		private static void SamplePoint(ref float minY, ref float maxY, Matrix4x4 worldMatrix, Vector3 localPoint)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Matrix4x4)(ref worldMatrix)).MultiplyPoint3x4(localPoint);
			if (val.y < minY)
			{
				minY = val.y;
			}
			if (val.y > maxY)
			{
				maxY = val.y;
			}
		}

		public static BoundsInfo GetStackInfo(long itemId, ItemSO itemSO, Quaternion worldRotation)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0363: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0369: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			BoundsInfo result;
			if ((Object)(object)itemSO == (Object)null)
			{
				result = default(BoundsInfo);
				result.MinY = 0f;
				result.Height = 0.01f;
				return result;
			}
			GameObject val = ((itemSO is BlockSO) ? GameManager.Instance.blockBox : itemSO.prefab);
			if ((Object)(object)val == (Object)null)
			{
				result = default(BoundsInfo);
				result.MinY = 0f;
				result.Height = 0.01f;
				return result;
			}
			float minY = float.PositiveInfinity;
			float maxY = float.NegativeInfinity;
			float minY2 = float.PositiveInfinity;
			float maxY2 = float.NegativeInfinity;
			Transform transform = val.transform;
			Matrix4x4 val2 = Matrix4x4.TRS(Vector3.zero, worldRotation, transform.lossyScale);
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer obj in componentsInChildren)
			{
				Matrix4x4 val3 = AccumulateToRoot(((Component)obj).transform, transform);
				Matrix4x4 worldMatrix = val2 * val3;
				Bounds localBounds = obj.localBounds;
				Vector3 center = ((Bounds)(ref localBounds)).center;
				Vector3 extents = ((Bounds)(ref localBounds)).extents;
				for (int j = -1; j <= 1; j += 2)
				{
					for (int k = -1; k <= 1; k += 2)
					{
						for (int l = -1; l <= 1; l += 2)
						{
							SamplePoint(ref minY, ref maxY, worldMatrix, new Vector3(center.x + (float)j * extents.x, center.y + (float)k * extents.y, center.z + (float)l * extents.z));
						}
					}
				}
			}
			BoxCollider[] componentsInChildren2 = val.GetComponentsInChildren<BoxCollider>(true);
			foreach (BoxCollider obj2 in componentsInChildren2)
			{
				Matrix4x4 val4 = AccumulateToRoot(((Component)obj2).transform, transform);
				Matrix4x4 worldMatrix2 = val2 * val4;
				Vector3 center2 = obj2.center;
				Vector3 val5 = obj2.size * 0.5f;
				for (int n = -1; n <= 1; n += 2)
				{
					for (int num = -1; num <= 1; num += 2)
					{
						for (int num2 = -1; num2 <= 1; num2 += 2)
						{
							SamplePoint(ref minY2, ref maxY2, worldMatrix2, new Vector3(center2.x + (float)n * val5.x, center2.y + (float)num * val5.y, center2.z + (float)num2 * val5.z));
						}
					}
				}
			}
			SphereCollider[] componentsInChildren3 = val.GetComponentsInChildren<SphereCollider>(true);
			foreach (SphereCollider obj3 in componentsInChildren3)
			{
				Matrix4x4 val6 = AccumulateToRoot(((Component)obj3).transform, transform);
				Matrix4x4 worldMatrix3 = val2 * val6;
				Vector3 center3 = obj3.center;
				float radius = obj3.radius;
				SamplePoint(ref minY2, ref maxY2, worldMatrix3, center3 + new Vector3(0f, radius, 0f));
				SamplePoint(ref minY2, ref maxY2, worldMatrix3, center3 + new Vector3(0f, 0f - radius, 0f));
			}
			CapsuleCollider[] componentsInChildren4 = val.GetComponentsInChildren<CapsuleCollider>(true);
			foreach (CapsuleCollider val7 in componentsInChildren4)
			{
				Matrix4x4 val8 = AccumulateToRoot(((Component)val7).transform, transform);
				Matrix4x4 worldMatrix4 = val2 * val8;
				Vector3 center4 = val7.center;
				float radius2 = val7.radius;
				float num5 = val7.height * 0.5f - radius2;
				Vector3 val9 = ((val7.direction != 0) ? ((val7.direction != 1) ? Vector3.forward : Vector3.up) : Vector3.right);
				SamplePoint(ref minY2, ref maxY2, worldMatrix4, center4 + val9 * num5 + new Vector3(0f, radius2, 0f));
				SamplePoint(ref minY2, ref maxY2, worldMatrix4, center4 - val9 * num5 + new Vector3(0f, 0f - radius2, 0f));
			}
			if (minY == float.PositiveInfinity || maxY == float.NegativeInfinity)
			{
				result = default(BoundsInfo);
				result.MinY = 0f;
				result.Height = 0.01f;
				return result;
			}
			int num6;
			float num7;
			if (minY2 != float.PositiveInfinity)
			{
				num6 = ((maxY2 != float.NegativeInfinity) ? 1 : 0);
				if (num6 != 0)
				{
					num7 = minY2;
					goto IL_0432;
				}
			}
			else
			{
				num6 = 0;
			}
			num7 = minY;
			goto IL_0432;
			IL_0432:
			float num8 = num7;
			float num9 = ((num6 != 0) ? maxY2 : maxY) - num8;
			if (float.IsNaN(num9) || float.IsInfinity(num9) || num9 <= 0f)
			{
				num9 = 0.01f;
			}
			float num10 = 0.003f;
			float height = Mathf.Max(0.005f, num9 - num10);
			result = default(BoundsInfo);
			result.MinY = num8;
			result.Height = height;
			return result;
		}

		public static float GetStackHeight(long itemId, ItemSO itemSO, Quaternion worldRotation)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			return GetStackInfo(itemId, itemSO, worldRotation).Height;
		}
	}
}
namespace DropAllStack.Localization
{
	public static class LocalizationHelper
	{
		private static readonly string[] DefaultTranslationLanguages = new string[3] { "zh", "zh-Hant", "en" };

		public static void InitializeLanguageFiles()
		{
			string text = Path.Combine(Paths.ConfigPath, "DropAllStack", "Localization");
			if (!Directory.Exists(text))
			{
				Directory.CreateDirectory(text);
			}
			string[] defaultTranslationLanguages = DefaultTranslationLanguages;
			foreach (string text2 in defaultTranslationLanguages)
			{
				string filePath = Path.Combine(text, text2 + ".json");
				EnsureLanguageFile(text2, filePath);
			}
		}

		private static void EnsureLanguageFile(string language, string filePath)
		{
			Dictionary<string, string> defaultTranslations = GetDefaultTranslations(language);
			if (File.Exists(filePath))
			{
				try
				{
					Dictionary<string, string> dictionary = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(filePath)) ?? new Dictionary<string, string>();
					bool flag = false;
					foreach (KeyValuePair<string, string> item in defaultTranslations)
					{
						if (!dictionary.ContainsKey(item.Key))
						{
							dictionary[item.Key] = item.Value;
							flag = true;
						}
						else if (dictionary[item.Key] != item.Value)
						{
							dictionary[item.Key] = item.Value;
							flag = true;
						}
					}
					foreach (string item2 in new List<string>(dictionary.Keys))
					{
						if (!defaultTranslations.ContainsKey(item2))
						{
							dictionary.Remove(item2);
							flag = true;
						}
					}
					if (flag)
					{
						string contents = JsonConvert.SerializeObject((object)dictionary, (Formatting)1);
						File.WriteAllText(filePath, contents);
					}
					return;
				}
				catch
				{
					CreateLanguageFile(filePath, defaultTranslations);
					return;
				}
			}
			CreateLanguageFile(filePath, defaultTranslations);
		}

		private static void CreateLanguageFile(string filePath, Dictionary<string, string> translations)
		{
			string contents = JsonConvert.SerializeObject((object)translations, (Formatting)1);
			File.WriteAllText(filePath, contents);
		}

		public static Dictionary<string, string> GetDefaultTranslations(string language)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			switch (language)
			{
			case "zh":
				dictionary.Add("plugin.initializing", "开始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "补丁已应用,跳过...");
				dictionary.Add("plugin.language_fallback", "不支持的语言 {0},使用英语作为备用。");
				dictionary.Add("config.enable_mod_desc", "是否启用本模组");
				dictionary.Add("config.hold_key_desc", "按住此键启用一键堆叠和丢弃功能");
				dictionary.Add("config.enable_physics_desc", "堆叠时启用物理(可能会滑落)");
				dictionary.Add("config.max_stack_layers_desc", "最大堆叠层数(最高为 8)");
				dictionary.Add("config.decrease_key_desc", "降低堆叠层数的快捷键");
				dictionary.Add("config.increase_key_desc", "增加堆叠层数的快捷键");
				dictionary.Add("config.throwall_limit_desc", "一键丢出上限");
				dictionary.Add("config.stack_target_mode_desc", "堆叠模式\n可填写:Player(玩家脚下)、Mouse(鼠标所指)");
				dictionary.Add("config.stack_mouse_max_distance_desc", "鼠标模式最大堆叠距离");
				dictionary.Add("config.toggle_stack_target_key_desc", "切换堆叠模式的快捷键");
				dictionary.Add("config.enable_surface_restriction_desc", "启用鼠标模式禁止堆叠位置(禁止水面、墙壁和天花板等)");
				dictionary.Add("hud.stack_layers_value", "堆叠层数:{0}/{1}。");
				dictionary.Add("hud.stack_target_player", "堆叠位置:玩家脚下位置。");
				dictionary.Add("hud.stack_target_mouse", "堆叠位置:鼠标所指位置。");
				dictionary.Add("hud.stack_mouse_on_water", "鼠标所指位置为水面,无法放置。");
				dictionary.Add("hud.stack_mouse_invalid_surface", "鼠标所指位置不可放置。");
				dictionary.Add("hud.stack_mouse_too_far", "鼠标所指位置超出最大距离,无法放置。");
				break;
			case "zh-Hant":
				dictionary.Add("plugin.initializing", "開始初始化...");
				dictionary.Add("plugin.author_prefix", "作者:");
				dictionary.Add("plugin.initialized", "初始化成功!");
				dictionary.Add("plugin.patches_skipped", "補丁已應用,跳過...");
				dictionary.Add("plugin.language_fallback", "不支持的語言 {0},使用英語作為備用。");
				dictionary.Add("config.enable_mod_desc", "是否啟用本模組");
				dictionary.Add("config.hold_key_desc", "按住此鍵啟用一键堆疊和丟棄功能");
				dictionary.Add("config.enable_physics_desc", "堆疊時啟用物理(可能會滑落)");
				dictionary.Add("config.max_stack_layers_desc", "最大堆疊層數(最高為 8)");
				dictionary.Add("config.decrease_key_desc", "降低堆疊層數的快捷鍵");
				dictionary.Add("config.increase_key_desc", "增加堆疊層數的快捷鍵");
				dictionary.Add("config.throwall_limit_desc", "一鍵丟出上限");
				dictionary.Add("config.stack_target_mode_desc", "堆疊模式\n可填寫:Player(玩家腳下)、Mouse(滑鼠所指)");
				dictionary.Add("config.stack_mouse_max_distance_desc", "滑鼠模式最大堆疊距離");
				dictionary.Add("config.toggle_stack_target_key_desc", "切換堆疊模式的快捷鍵");
				dictionary.Add("config.enable_surface_restriction_desc", "啟用滑鼠模式禁止堆疊位置(禁止水面、牆壁和天花板等)");
				dictionary.Add("hud.stack_layers_value", "堆疊層數:{0}/{1}。");
				dictionary.Add("hud.stack_target_player", "堆疊位置:玩家腳下位置。");
				dictionary.Add("hud.stack_target_mouse", "堆疊位置:滑鼠所指位置。");
				dictionary.Add("hud.stack_mouse_on_water", "滑鼠所指位置為水面,無法放置。");
				dictionary.Add("hud.stack_mouse_invalid_surface", "滑鼠所指位置不可放置。");
				dictionary.Add("hud.stack_mouse_too_far", "滑鼠所指位置超出最大距離,無法放置。");
				break;
			case "en":
				dictionary.Add("plugin.initializing", "is initializing...");
				dictionary.Add("plugin.author_prefix", "Author: ");
				dictionary.Add("plugin.initialized", "initialized successfully!");
				dictionary.Add("plugin.patches_skipped", "Patches already applied, skipping...");
				dictionary.Add("plugin.language_fallback", "Unsupported language {0}, using English as fallback.");
				dictionary.Add("config.enable_mod_desc", "Whether to enable this mod");
				dictionary.Add("config.hold_key_desc", "Hold this key to enable one-click stack and drop");
				dictionary.Add("config.enable_physics_desc", "Enable physics when stacking, may slide");
				dictionary.Add("config.max_stack_layers_desc", "Max stack layers (upper bound 8)");
				dictionary.Add("config.decrease_key_desc", "Hotkey to decrease stack layers");
				dictionary.Add("config.increase_key_desc", "Hotkey to increase stack layers");
				dictionary.Add("hud.stack_layers_value", "Stack layers: {0}/{1}");
				dictionary.Add("config.throwall_limit_desc", "One-click throw-all limit");
				dictionary.Add("config.stack_target_mode_desc", "Stack target mode\nAllowed values: Player (player feet), Mouse (mouse point)");
				dictionary.Add("config.stack_mouse_max_distance_desc", "Max stacking distance in mouse mode");
				dictionary.Add("config.toggle_stack_target_key_desc", "Hotkey to toggle stack mode");
				dictionary.Add("config.enable_surface_restriction_desc", "Enable mouse mode surface restriction (blocks water, walls, ceilings, etc.)");
				dictionary.Add("hud.stack_target_player", "Stack target: player feet");
				dictionary.Add("hud.stack_target_mouse", "Stack target: mouse point");
				dictionary.Add("hud.stack_mouse_on_water", "Mouse points to water, cannot place.");
				dictionary.Add("hud.stack_mouse_invalid_surface", "Invalid surface, cannot place.");
				dictionary.Add("hud.stack_mouse_too_far", "Mouse point too far, cannot place.");
				break;
			}
			return dictionary;
		}
	}
	public class LocalizationManager
	{
		private static LocalizationManager _instance;

		private Dictionary<string, Dictionary<string, string>> _localizations = new Dictionary<string, Dictionary<string, string>>();

		private string _currentLocale = "zh";

		public static readonly string[] SupportedLanguages = new string[12]
		{
			"zh", "zh-Hant", "en", "fr", "de", "ja", "ko", "pt", "ru", "es",
			"tr", "uk"
		};

		private static readonly string[] DefaultTranslationLanguages = new string[3] { "zh", "zh-Hant", "en" };

		public static LocalizationManager Instance => _instance ?? (_instance = new LocalizationManager());

		private LocalizationManager()
		{
			Initialize();
		}

		public void Initialize()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)LocalizationSettings.SelectedLocale != (Object)null)
			{
				LocaleIdentifier identifier = LocalizationSettings.SelectedLocale.Identifier;
				_currentLocale = ((LocaleIdentifier)(ref identifier)).Code;
			}
			LocalizationHelper.InitializeLanguageFiles();
			string path = Path.Combine(Paths.ConfigPath, "DropAllStack", "Localization");
			string[] supportedLanguages = SupportedLanguages;
			foreach (string text in supportedLanguages)
			{
				string filePath = Path.Combine(path, text + ".json");
				LoadLanguageFile(text, filePath);
			}
			LocalizationSettings.SelectedLocaleChanged += OnGameLanguageChanged;
		}

		private void OnGameLanguageChanged(Locale locale)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)locale != (Object)null)
			{
				LocaleIdentifier identifier = locale.Identifier;
				string code = ((LocaleIdentifier)(ref identifier)).Code;
				if (_localizations.ContainsKey(code))
				{
					_currentLocale = code;
					return;
				}
				_currentLocale = "en";
				DropAllStack.Logger.LogInfo((object)GetLocalizedText("plugin.language_fallback", code));
			}
		}

		private void LoadLanguageFile(string language, string filePath)
		{
			if (File.Exists(filePath))
			{
				try
				{
					Dictionary<string, string> value = JsonConvert.DeserializeObject<Dictionary<string, string>>(File.ReadAllText(filePath));
					_localizations[language] = value;
					return;
				}
				catch
				{
					if (Array.IndexOf(DefaultTranslationLanguages, language) >= 0)
					{
						_localizations[language] = GetDefaultTranslations(language);
					}
					return;
				}
			}
			if (Array.IndexOf(DefaultTranslationLanguages, language) >= 0)
			{
				_localizations[language] = GetDefaultTranslations(language);
			}
		}

		private Dictionary<string, string> GetDefaultTranslations(string language)
		{
			MethodInfo methodInfo = AccessTools.Method(typeof(LocalizationHelper), "GetDefaultTranslations", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				return methodInfo.Invoke(null, new object[1] { language }) as Dictionary<string, string>;
			}
			return new Dictionary<string, string>();
		}

		public string GetLocalizedText(string key, params object[] args)
		{
			if (string.IsNullOrEmpty(_currentLocale) || !_localizations.ContainsKey(_currentLocale))
			{
				_currentLocale = "en";
			}
			if (_localizations.ContainsKey(_currentLocale) && _localizations[_currentLocale].TryGetValue(key, out var value))
			{
				if (args.Length == 0)
				{
					return value;
				}
				return string.Format(value, args);
			}
			if (_currentLocale != "en" && _localizations.ContainsKey("en") && _localizations["en"].TryGetValue(key, out var value2))
			{
				if (args.Length == 0)
				{
					return value2;
				}
				return string.Format(value2, args);
			}
			if (_localizations.ContainsKey("zh") && _localizations["zh"].TryGetValue(key, out var value3))
			{
				if (args.Length == 0)
				{
					return value3;
				}
				return string.Format(value3, args);
			}
			return key;
		}
	}
}
namespace DropAllStack.Configuration
{
	public static class ConfigManager
	{
		public static ConfigEntry<bool> EnableMod { get; private set; }

		public static ConfigEntry<string> HoldKey { get; private set; }

		public static ConfigEntry<string> DecreaseKey { get; private set; }

		public static ConfigEntry<string> IncreaseKey { get; private set; }

		public static ConfigEntry<string> ToggleStackTargetKey { get; private set; }

		public static ConfigEntry<bool> EnablePhysicsOnStack { get; private set; }

		public static ConfigEntry<int> MaxStackLayers { get; private set; }

		public static int CurrentStackLayers { get; private set; }

		public static ConfigEntry<int> ThrowAllLimit { get; private set; }

		public static ConfigEntry<string> StackTargetMode { get; private set; }

		public static ConfigEntry<float> StackMouseMaxDistance { get; private set; }

		public static ConfigEntry<bool> EnableSurfaceRestriction { get; private set; }

		public static void Initialize(ConfigFile config)
		{
			EnableMod = config.Bind<bool>("General", "EnableMod", true, LocalizationManager.Instance.GetLocalizedText("config.enable_mod_desc"));
			HoldKey = config.Bind<string>("General", "HoldKey", "leftShift", LocalizationManager.Instance.GetLocalizedText("config.hold_key_desc"));
			EnablePhysicsOnStack = config.Bind<bool>("General", "EnablePhysicsOnStack", true, LocalizationManager.Instance.GetLocalizedText("config.enable_physics_desc"));
			DecreaseKey = config.Bind<string>("Stacking", "DecreaseKey", "minus", LocalizationManager.Instance.GetLocalizedText("config.decrease_key_desc"));
			IncreaseKey = config.Bind<string>("Stacking", "IncreaseKey", "equals", LocalizationManager.Instance.GetLocalizedText("config.increase_key_desc"));
			ToggleStackTargetKey = config.Bind<string>("Stacking", "ToggleStackTargetKey", "period", LocalizationManager.Instance.GetLocalizedText("config.toggle_stack_target_key_desc"));
			StackMouseMaxDistance = config.Bind<float>("Stacking", "StackMouseMaxDistance", 5f, LocalizationManager.Instance.GetLocalizedText("config.stack_mouse_max_distance_desc"));
			EnableSurfaceRestriction = config.Bind<bool>("Stacking", "EnableSurfaceRestriction", true, LocalizationManager.Instance.GetLocalizedText("config.enable_surface_restriction_desc"));
			StackTargetMode = config.Bind<string>("Stacking", "StackTargetMode", "Player", LocalizationManager.Instance.GetLocalizedText("config.stack_target_mode_desc"));
			if (StackTargetMode.Value != "Player" && StackTargetMode.Value != "Mouse")
			{
				StackTargetMode.Value = "Player";
			}
			if (StackMouseMaxDistance.Value < 1f)
			{
				StackMouseMaxDistance.Value = 1f;
			}
			MaxStackLayers = config.Bind<int>("Stacking", "MaxStackLayers", 8, LocalizationManager.Instance.GetLocalizedText("config.max_stack_layers_desc"));
			if (MaxStackLayers.Value > 8)
			{
				MaxStackLayers.Value = 8;
			}
			if (MaxStackLayers.Value < 1)
			{
				MaxStackLayers.Value = 1;
			}
			CurrentStackLayers = MaxStackLayers.Value;
			ThrowAllLimit = config.Bind<int>("Throw", "ThrowAllLimit", 30, LocalizationManager.Instance.GetLocalizedText("config.throwall_limit_desc"));
			if (ThrowAllLimit.Value < 1)
			{
				ThrowAllLimit.Value = 1;
			}
		}

		public static void AdjustCurrentStackLayers(int delta)
		{
			int num = ((MaxStackLayers != null) ? MaxStackLayers.Value : 8);
			CurrentStackLayers = Mathf.Clamp(CurrentStackLayers + delta, 1, Mathf.Min(8, num));
		}

		public static void ToggleStackTargetMode()
		{
			if (StackTargetMode != null)
			{
				StackTargetMode.Value = ((StackTargetMode.Value == "Player") ? "Mouse" : "Player");
			}
		}
	}
}