Decompiled source of ValuablesDropItems v0.3.1

ValuablesDropItems.dll

Decompiled a month ago
using System;
using System.Collections;
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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Kai")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+c3c0863ed661efe46afe401658d8bd4316c5569f")]
[assembly: AssemblyProduct("ValuablesDropItems")]
[assembly: AssemblyTitle("ValuablesDropItems")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 ValuableItemDrop
{
	public enum ItemConfigType
	{
		GroupedWeights,
		ItemWeights
	}
	public enum ItemSizeGroup
	{
		None,
		Small,
		Medium,
		Big
	}
	public enum DropKind
	{
		Item,
		Nothing,
		Trap
	}
	public enum TrapType
	{
		GrenadeExplosive,
		GrenadeDuctTaped,
		GrenadeHuman,
		GrenadeShockwave,
		GrenadeStun
	}
	public class DropEntry
	{
		public DropKind Kind;

		public Item? Item;

		public TrapType TrapType;

		public int Weight;

		public DropEntry(DropKind kind, int weight, Item? item = null, TrapType trapType = TrapType.GrenadeExplosive)
		{
			Kind = kind;
			Weight = weight;
			Item = item;
			TrapType = trapType;
		}
	}
	public class ItemGroupManager : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <BuildConfigDelayed>d__36 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public ItemGroupManager <>4__this;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <BuildConfigDelayed>d__36(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				int num = <>1__state;
				ItemGroupManager itemGroupManager = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null || StatsManager.instance.itemDictionary.Count == 0)
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				itemGroupManager.BuildConfig();
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private const int MinWeight = 0;

		private const int MaxWeight = 10;

		private const int MinChance = 0;

		private const int MaxChance = 100;

		private ConfigEntry<ItemConfigType> _configType;

		internal static ConfigEntry<float> SpawnHeightOffset;

		internal static ConfigEntry<bool> EnableDebugLog;

		internal static ConfigEntry<int> SmallRollChance;

		internal static ConfigEntry<int> MediumRollChance;

		internal static ConfigEntry<int> BigRollChance;

		private ConfigEntry<int> _smallEmptyWeight;

		private ConfigEntry<int> _mediumEmptyWeight;

		private ConfigEntry<int> _bigEmptyWeight;

		private ConfigEntry<int> _smallTrapWeight;

		private ConfigEntry<int> _mediumTrapWeight;

		private ConfigEntry<int> _bigTrapWeight;

		private readonly Dictionary<string, ConfigEntry<int>> _smallWeights = new Dictionary<string, ConfigEntry<int>>();

		private readonly Dictionary<string, ConfigEntry<int>> _mediumWeights = new Dictionary<string, ConfigEntry<int>>();

		private readonly Dictionary<string, ConfigEntry<int>> _bigWeights = new Dictionary<string, ConfigEntry<int>>();

		internal static ConfigEntry<int> TrapSpawnCount;

		internal static ConfigEntry<float> TrapSpreadForce;

		internal static ConfigEntry<bool> TrapInstantDetonate;

		private ConfigEntry<int> _trapExplosiveWeight;

		private ConfigEntry<int> _trapDuctWeight;

		private ConfigEntry<int> _trapHumanWeight;

		private ConfigEntry<int> _trapShockwaveWeight;

		private ConfigEntry<int> _trapStunWeight;

		private bool _built;

		public static ItemGroupManager Instance { get; private set; }

		private void Awake()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Expected O, but got Unknown
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Expected O, but got Unknown
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Expected O, but got Unknown
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0237: Expected O, but got Unknown
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Expected O, but got Unknown
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Expected O, but got Unknown
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)this);
				return;
			}
			Instance = this;
			_configType = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<ItemConfigType>("General", "ConfigType", ItemConfigType.GroupedWeights, "Config layout: GroupedWeights / ItemWeights");
			SpawnHeightOffset = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<float>("Drop", "SpawnHeightOffset", 0.5f, "Vertical spawn offset in meters. Increase this if dropped items clip into the ground.");
			SmallRollChance = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Drop", "SmallRollChance", 25, new ConfigDescription("Chance (0-100) to roll a drop when a Small valuable is destroyed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			MediumRollChance = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Drop", "MediumRollChance", 60, new ConfigDescription("Chance (0-100) to roll a drop when a Medium valuable is destroyed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			BigRollChance = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Drop", "BigRollChance", 100, new ConfigDescription("Chance (0-100) to roll a drop when a Big valuable is destroyed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			EnableDebugLog = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<bool>("Debug", "EnableDebugLog", false, "Enable debug logs for valuable drop processing.");
			TrapSpawnCount = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "SpawnCount", 4, new ConfigDescription("Number of trap items spawned at once", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			TrapInstantDetonate = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<bool>("Trap", "InstantDetonate", false, "If enabled, grenades spawned by traps explode immediately instead of activating normally.");
			_trapExplosiveWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "GrenadeExplosive", 5, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			_trapDuctWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "GrenadeDuctTaped", 2, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			_trapHumanWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "GrenadeHuman", 2, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			_trapShockwaveWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "GrenadeShockwave", 3, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			_trapStunWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "GrenadeStun", 3, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
			TrapSpreadForce = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<float>("Trap", "SpreadForce", 5f, "Force applied to trap items when spawned");
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(BuildConfigDelayed());
		}

		public static int GetRollChance(ItemSizeGroup group)
		{
			return group switch
			{
				ItemSizeGroup.Small => Mathf.Clamp(SmallRollChance?.Value ?? 100, 0, 100), 
				ItemSizeGroup.Medium => Mathf.Clamp(MediumRollChance?.Value ?? 100, 0, 100), 
				ItemSizeGroup.Big => Mathf.Clamp(BigRollChance?.Value ?? 100, 0, 100), 
				_ => 0, 
			};
		}

		public static bool ShouldRoll(ItemSizeGroup group)
		{
			int rollChance = GetRollChance(group);
			if (rollChance <= 0)
			{
				return false;
			}
			if (rollChance >= 100)
			{
				return true;
			}
			int num = Random.Range(0, 100);
			ValuablesDropItems.LogDebug($"[ValuableDrop] RollChance group={group}, chance={rollChance}, roll={num}");
			return num < rollChance;
		}

		[IteratorStateMachine(typeof(<BuildConfigDelayed>d__36))]
		private IEnumerator BuildConfigDelayed()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <BuildConfigDelayed>d__36(0)
			{
				<>4__this = this
			};
		}

		private void BuildConfig()
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Expected O, but got Unknown
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Expected O, but got Unknown
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Expected O, but got Unknown
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Expected O, but got Unknown
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Expected O, but got Unknown
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Expected O, but got Unknown
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Expected O, but got Unknown
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Expected O, but got Unknown
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Expected O, but got Unknown
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Expected O, but got Unknown
			//IL_0501: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Expected O, but got Unknown
			if (_built)
			{
				return;
			}
			_built = true;
			switch (_configType.Value)
			{
			case ItemConfigType.GroupedWeights:
				_smallEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Small", "Empty", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_mediumEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Medium", "Empty", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_bigEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Big", "Empty", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_smallTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Small", "Trap", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_mediumTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Medium", "Trap", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_bigTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Big", "Trap", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				break;
			case ItemConfigType.ItemWeights:
				_smallEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Empty", "Small", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_mediumEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Empty", "Medium", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_bigEmptyWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Empty", "Big", 0, new ConfigDescription("No drop weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_smallTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "Small", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_mediumTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "Medium", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				_bigTrapWeight = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Trap", "Big", 0, new ConfigDescription("Trap weight", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
				break;
			}
			IOrderedEnumerable<KeyValuePair<string, Item>> orderedEnumerable = from x in StatsManager.instance.itemDictionary
				orderby x.Value.itemType, x.Key
				select x;
			foreach (KeyValuePair<string, Item> item in orderedEnumerable)
			{
				string key = item.Key;
				string displayName = GetDisplayName(key);
				switch (_configType.Value)
				{
				case ItemConfigType.GroupedWeights:
					_smallWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Small", displayName, GetDefaultWeight(item.Value, ItemSizeGroup.Small), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					_mediumWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Medium", displayName, GetDefaultWeight(item.Value, ItemSizeGroup.Medium), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					_bigWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>("Big", displayName, GetDefaultWeight(item.Value, ItemSizeGroup.Big), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					break;
				case ItemConfigType.ItemWeights:
					_smallWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>(displayName, "Small", GetDefaultWeight(item.Value, ItemSizeGroup.Small), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					_mediumWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>(displayName, "Medium", GetDefaultWeight(item.Value, ItemSizeGroup.Medium), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					_bigWeights[key] = ((BaseUnityPlugin)ValuablesDropItems.Instance).Config.Bind<int>(displayName, "Big", GetDefaultWeight(item.Value, ItemSizeGroup.Big), new ConfigDescription("Weight 0-10 (0 = disabled)", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10), Array.Empty<object>()));
					break;
				}
			}
			ValuablesDropItems.Logger.LogInfo((object)$"Generated weighted item configs: {StatsManager.instance.itemDictionary.Count}");
		}

		private string GetDisplayName(string key)
		{
			if (key.StartsWith("ItemUpgrade"))
			{
				key = key.Substring("ItemUpgrade".Length);
			}
			else if (key.StartsWith("Item Upgrade"))
			{
				key = key.Substring("Item Upgrade".Length);
			}
			else if (key.StartsWith("Item"))
			{
				key = key.Substring("Item".Length);
			}
			return key.Replace(" ", "").Trim();
		}

		public int GetWeight(string itemKey, ItemSizeGroup group)
		{
			ConfigEntry<int> value = null;
			switch (group)
			{
			case ItemSizeGroup.Small:
				_smallWeights.TryGetValue(itemKey, out value);
				break;
			case ItemSizeGroup.Medium:
				_mediumWeights.TryGetValue(itemKey, out value);
				break;
			case ItemSizeGroup.Big:
				_bigWeights.TryGetValue(itemKey, out value);
				break;
			}
			if (value == null)
			{
				return 0;
			}
			return Mathf.Clamp(value.Value, 0, 10);
		}

		private int GetSpecialWeight(DropKind type, ItemSizeGroup group)
		{
			return Mathf.Clamp(type switch
			{
				DropKind.Nothing => group switch
				{
					ItemSizeGroup.Small => _smallEmptyWeight?.Value ?? 0, 
					ItemSizeGroup.Medium => _mediumEmptyWeight?.Value ?? 0, 
					ItemSizeGroup.Big => _bigEmptyWeight?.Value ?? 0, 
					_ => 0, 
				}, 
				DropKind.Trap => group switch
				{
					ItemSizeGroup.Small => _smallTrapWeight?.Value ?? 0, 
					ItemSizeGroup.Medium => _mediumTrapWeight?.Value ?? 0, 
					ItemSizeGroup.Big => _bigTrapWeight?.Value ?? 0, 
					_ => 0, 
				}, 
				_ => 0, 
			}, 0, 10);
		}

		public List<DropEntry> GetWeightedCandidates(ItemSizeGroup group)
		{
			List<DropEntry> list = new List<DropEntry>();
			if ((Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null)
			{
				return list;
			}
			int specialWeight = GetSpecialWeight(DropKind.Nothing, group);
			if (specialWeight > 0)
			{
				list.Add(new DropEntry(DropKind.Nothing, specialWeight));
			}
			int specialWeight2 = GetSpecialWeight(DropKind.Trap, group);
			if (specialWeight2 > 0)
			{
				if (_trapExplosiveWeight.Value > 0)
				{
					list.Add(new DropEntry(DropKind.Trap, _trapExplosiveWeight.Value));
				}
				if (_trapDuctWeight.Value > 0)
				{
					list.Add(new DropEntry(DropKind.Trap, _trapDuctWeight.Value, null, TrapType.GrenadeDuctTaped));
				}
				if (_trapHumanWeight.Value > 0)
				{
					list.Add(new DropEntry(DropKind.Trap, _trapHumanWeight.Value, null, TrapType.GrenadeHuman));
				}
				if (_trapShockwaveWeight.Value > 0)
				{
					list.Add(new DropEntry(DropKind.Trap, _trapShockwaveWeight.Value, null, TrapType.GrenadeShockwave));
				}
				if (_trapStunWeight.Value > 0)
				{
					list.Add(new DropEntry(DropKind.Trap, _trapStunWeight.Value, null, TrapType.GrenadeStun));
				}
			}
			foreach (KeyValuePair<string, Item> item in StatsManager.instance.itemDictionary)
			{
				string key = item.Key;
				Item value = item.Value;
				if (!((Object)(object)value == (Object)null) && !value.disabled && value.prefab != null && !string.IsNullOrEmpty(value.prefab.ResourcePath))
				{
					int weight = GetWeight(key, group);
					if (weight > 0)
					{
						list.Add(new DropEntry(DropKind.Item, weight, value));
					}
				}
			}
			return list;
		}

		public DropEntry? RollDrop(ItemSizeGroup group)
		{
			List<DropEntry> weightedCandidates = GetWeightedCandidates(group);
			if (weightedCandidates.Count == 0)
			{
				return null;
			}
			int num = 0;
			foreach (DropEntry item in weightedCandidates)
			{
				num += item.Weight;
			}
			if (num <= 0)
			{
				return null;
			}
			int num2 = Random.Range(0, num);
			ValuablesDropItems.LogDebug($"[ValuableDrop] RollDrop group={group}, total={num}, roll={num2}");
			foreach (DropEntry item2 in weightedCandidates)
			{
				ValuablesDropItems.LogDebug(string.Format("[ValuableDrop] Candidate kind={0}, item={1}, trap={2}, weight={3}", item2.Kind, ((Object)(object)item2.Item != (Object)null) ? ((Object)item2.Item).name : "null", item2.TrapType, item2.Weight));
				if (num2 < item2.Weight)
				{
					return item2;
				}
				num2 -= item2.Weight;
			}
			return weightedCandidates[weightedCandidates.Count - 1];
		}

		private int GetDefaultWeight(Item item, ItemSizeGroup group)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected I4, but got Unknown
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected I4, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Expected I4, but got Unknown
			if ((Object)(object)item == (Object)null)
			{
				return 0;
			}
			if (IsExcludedByDefault(item))
			{
				return 0;
			}
			switch (group)
			{
			case ItemSizeGroup.Small:
			{
				itemType itemType3 = item.itemType;
				return (int)itemType3 switch
				{
					7 => 5, 
					13 => 4, 
					8 => 3, 
					6 => 2, 
					9 => 2, 
					11 => 1, 
					10 => 1, 
					0 => 1, 
					1 => 1, 
					_ => 0, 
				};
			}
			case ItemSizeGroup.Medium:
			{
				itemType itemType2 = item.itemType;
				return (int)itemType2 switch
				{
					7 => 3, 
					13 => 3, 
					8 => 3, 
					6 => 4, 
					9 => 4, 
					11 => 3, 
					10 => 2, 
					0 => 2, 
					1 => 2, 
					_ => 0, 
				};
			}
			case ItemSizeGroup.Big:
			{
				itemType itemType = item.itemType;
				return (int)itemType switch
				{
					7 => 1, 
					13 => 2, 
					8 => 2, 
					6 => 3, 
					9 => 4, 
					11 => 3, 
					10 => 3, 
					0 => 4, 
					1 => 4, 
					_ => 0, 
				};
			}
			default:
				return 0;
			}
		}

		private bool IsExcludedByDefault(Item item)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: 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_001f: Expected I4, but got Unknown
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Invalid comparison between Unknown and I4
			itemType itemType = item.itemType;
			switch (itemType - 2)
			{
			default:
				if ((int)itemType != 12)
				{
					break;
				}
				return true;
			case 1:
				return true;
			case 0:
				return true;
			case 3:
				return true;
			case 2:
				break;
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector), "DestroyObject")]
	internal class ValuableDropPatch
	{
		public static class GrenadeTrap
		{
			[CompilerGenerated]
			private sealed class <SpawnDelayed>d__0 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public TrapType type;

				public Vector3 pos;

				public int count;

				private Item <item>5__2;

				private float <spawnHeight>5__3;

				private float <spreadForce>5__4;

				private int <i>5__5;

				private GameObject <go>5__6;

				private ItemGrenade <grenade>5__7;

				private PhotonView <pv>5__8;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <SpawnDelayed>d__0(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<item>5__2 = null;
					<go>5__6 = null;
					<grenade>5__7 = null;
					<pv>5__8 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_017c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0181: Unknown result type (might be due to invalid IL or missing references)
					//IL_0183: 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_01c1: 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_01d7: Unknown result type (might be due to invalid IL or missing references)
					//IL_0193: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ec: 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_012e: 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_0108: Unknown result type (might be due to invalid IL or missing references)
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
					{
						<>1__state = -1;
						if ((Object)(object)StatsManager.instance == (Object)null || StatsManager.instance.itemDictionary == null)
						{
							return false;
						}
						string key = type switch
						{
							TrapType.GrenadeExplosive => "Item Grenade Explosive", 
							TrapType.GrenadeDuctTaped => "Item Grenade Duct Taped", 
							TrapType.GrenadeHuman => "Item Grenade Human", 
							TrapType.GrenadeShockwave => "Item Grenade Shockwave", 
							TrapType.GrenadeStun => "Item Grenade Stun", 
							_ => "Item Grenade Explosive", 
						};
						if (!StatsManager.instance.itemDictionary.TryGetValue(key, out <item>5__2))
						{
							return false;
						}
						<spawnHeight>5__3 = 0.6f;
						<spreadForce>5__4 = ItemGroupManager.TrapSpreadForce.Value;
						<i>5__5 = 0;
						goto IL_02da;
					}
					case 1:
					{
						<>1__state = -1;
						Rigidbody component = <go>5__6.GetComponent<Rigidbody>();
						if ((Object)(object)component != (Object)null)
						{
							Vector3 onUnitSphere = Random.onUnitSphere;
							if (onUnitSphere.y < 0f)
							{
								onUnitSphere.y = 0f - onUnitSphere.y;
							}
							onUnitSphere.y += 0.5f;
							((Vector3)(ref onUnitSphere)).Normalize();
							component.velocity = onUnitSphere * <spreadForce>5__4;
							component.angularVelocity = Random.insideUnitSphere * 8f;
						}
						if (ItemGroupManager.TrapInstantDetonate.Value)
						{
							<grenade>5__7 = <go>5__6.GetComponent<ItemGrenade>();
							<pv>5__8 = <go>5__6.GetComponent<PhotonView>();
							if ((Object)(object)<grenade>5__7 != (Object)null)
							{
								<grenade>5__7.isSpawnedGrenade = true;
								<grenade>5__7.TickStart();
								<>2__current = null;
								<>1__state = 2;
								return true;
							}
							goto IL_0291;
						}
						ItemToggle component2 = <go>5__6.GetComponent<ItemToggle>();
						if ((Object)(object)component2 != (Object)null)
						{
							component2.ToggleItem(true, -1);
						}
						goto IL_02c1;
					}
					case 2:
						{
							<>1__state = -1;
							if (SemiFunc.IsMultiplayer() && (Object)(object)<pv>5__8 != (Object)null)
							{
								<pv>5__8.RPC("TickEndRPC", (RpcTarget)0, Array.Empty<object>());
							}
							else
							{
								UnityEvent onDetonate = <grenade>5__7.onDetonate;
								if (onDetonate != null)
								{
									onDetonate.Invoke();
								}
							}
							goto IL_0291;
						}
						IL_0291:
						<grenade>5__7 = null;
						<pv>5__8 = null;
						goto IL_02c1;
						IL_02da:
						if (<i>5__5 < count)
						{
							Vector3 val = pos + Vector3.up * <spawnHeight>5__3;
							if (SemiFunc.IsMultiplayer())
							{
								<go>5__6 = PhotonNetwork.InstantiateRoomObject(<item>5__2.prefab.ResourcePath, val, Quaternion.identity, (byte)0, (object[])null);
							}
							else
							{
								<go>5__6 = Object.Instantiate<GameObject>(<item>5__2.prefab.Prefab, val, Quaternion.identity);
							}
							if (!((Object)(object)<go>5__6 == (Object)null))
							{
								<>2__current = null;
								<>1__state = 1;
								return true;
							}
							goto IL_02c8;
						}
						return false;
						IL_02c8:
						<i>5__5++;
						goto IL_02da;
						IL_02c1:
						<go>5__6 = null;
						goto IL_02c8;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			[IteratorStateMachine(typeof(<SpawnDelayed>d__0))]
			public static IEnumerator SpawnDelayed(Vector3 pos, int count, TrapType type)
			{
				//IL_0007: 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)
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <SpawnDelayed>d__0(0)
				{
					pos = pos,
					count = count,
					type = type
				};
			}
		}

		private static void Postfix(PhysGrabObjectImpactDetector __instance, bool effects)
		{
			//IL_0059: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			ValuablesDropItems.LogDebug("[ValuableDrop] DestroyObject triggered");
			if (!SemiFunc.IsMasterClientOrSingleplayer() || !effects)
			{
				return;
			}
			ValuableObject component = ((Component)__instance).GetComponent<ValuableObject>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			if (ShouldSkipValuable(component))
			{
				ValuablesDropItems.LogDebug("[ValuableDrop] Skip: excluded valuable " + ((Object)((Component)component).gameObject).name);
			}
			else
			{
				if ((Object)(object)ItemGroupManager.Instance == (Object)null)
				{
					return;
				}
				ItemSizeGroup itemSizeGroup = ConvertVolumeType(component.volumeType);
				if (itemSizeGroup == ItemSizeGroup.None || !ItemGroupManager.ShouldRoll(itemSizeGroup))
				{
					return;
				}
				DropEntry dropEntry = ItemGroupManager.Instance.RollDrop(itemSizeGroup);
				if (dropEntry == null)
				{
					return;
				}
				switch (dropEntry.Kind)
				{
				case DropKind.Nothing:
					break;
				case DropKind.Trap:
					((MonoBehaviour)ItemGroupManager.Instance).StartCoroutine(GrenadeTrap.SpawnDelayed(((Component)component).transform.position, ItemGroupManager.TrapSpawnCount.Value, dropEntry.TrapType));
					break;
				case DropKind.Item:
					if (!((Object)(object)dropEntry.Item == (Object)null))
					{
						SpawnItem(dropEntry.Item, ((Component)component).transform.position);
					}
					break;
				}
			}
		}

		private static ItemSizeGroup ConvertVolumeType(Type volumeType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected I4, but got Unknown
			switch ((int)volumeType)
			{
			case 0:
			case 1:
				return ItemSizeGroup.Small;
			case 2:
				return ItemSizeGroup.Medium;
			case 3:
			case 4:
			case 5:
			case 6:
				return ItemSizeGroup.Big;
			default:
				return ItemSizeGroup.None;
			}
		}

		private static void SpawnItem(Item item, Vector3 pos)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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)
			float num = ((ItemGroupManager.SpawnHeightOffset != null) ? ItemGroupManager.SpawnHeightOffset.Value : 0.5f);
			Vector3 val = pos + Vector3.up * num;
			Quaternion identity = Quaternion.identity;
			GameObject val2 = ((!SemiFunc.IsMultiplayer()) ? Object.Instantiate<GameObject>(item.prefab.Prefab, val, identity) : PhotonNetwork.InstantiateRoomObject(item.prefab.ResourcePath, val, identity, (byte)0, (object[])null));
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			ItemAttributes component = val2.GetComponent<ItemAttributes>();
			if (!((Object)(object)component != (Object)null))
			{
				return;
			}
			component.item = item;
			if (!((Object)(object)PunManager.instance != (Object)null))
			{
				return;
			}
			int num2 = -1;
			if (SemiFunc.IsMultiplayer())
			{
				PhotonView component2 = ((Component)component).GetComponent<PhotonView>();
				if ((Object)(object)component2 != (Object)null)
				{
					num2 = component2.ViewID;
				}
			}
			PunManager.instance.SetItemName(((Object)item).name, component, num2);
		}

		private static bool ShouldSkipValuable(ValuableObject valuable)
		{
			if ((Object)(object)valuable == (Object)null)
			{
				return true;
			}
			string text = ((Object)valuable).name.ToLowerInvariant();
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			if (text.Contains("enemy valuable") || text.Contains("surplus"))
			{
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("Kai.ValuablesDropItems", "ValuablesDropItems", "2.0")]
	public class ValuablesDropItems : BaseUnityPlugin
	{
		internal static ValuablesDropItems Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			((Component)this).gameObject.AddComponent<ItemGroupManager>();
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void Patch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void Update()
		{
		}

		public static void LogDebug(string message)
		{
			if (ItemGroupManager.EnableDebugLog != null && ItemGroupManager.EnableDebugLog.Value)
			{
				Logger.LogInfo((object)message);
			}
		}
	}
}