Decompiled source of LC GiftBox Config v1.0.3

plugins/LC_GiftBox_Config.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LC_GiftBox_Config.libs.ILTools;
using LC_GiftBox_Config.libs.LethalConfigNicerizer;
using LC_GiftBox_Config.libs.Probability;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyCompany("DBJ")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Configure how the gift box filters and spawns scrap items + store items, and modifies their scrap values")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+f6c2fb05bda16495707aecc5165287699ab61fe3")]
[assembly: AssemblyProduct("LC_GiftBox_Config")]
[assembly: AssemblyTitle("com.github.decibillyjoel.lc_giftbox_config")]
[assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/DecibillyJoel/LC_GiftBox_Config")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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;
		}
	}
}
internal static class LCMPluginInfo
{
	public const string PLUGIN_GUID = "com.github.decibillyjoel.lc_giftbox_config";

	public const string PLUGIN_NAME = "LC_GiftBox_Config";

	public const string PLUGIN_TS_TEAM = "DBJ";

	public const string PLUGIN_VERSION = "1.0.3";
}
namespace LC_GiftBox_Config
{
	[BepInPlugin("com.github.decibillyjoel.lc_giftbox_config", "DBJ.LC_GiftBox_Config", "1.0.3")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static ManualLogSource PluginLogger = null;

		public static ConfigEntry<bool> giftBoxMechanicsDisabled = null;

		public static ConfigEntry<int> spawnStoreItemChance = null;

		public static ConfigEntry<int> spawnScrapChance = null;

		public static ConfigEntry<int> spawnGiftBoxChance = null;

		public static ConfigEntry<int> spawnNothingChance = null;

		public static ConfigEntry<int> doNothingChance = null;

		public static ConfigEntry<int> scrapValueMin = null;

		public static ConfigEntry<int> scrapValueMax = null;

		public static ConfigEntry<int> scrapValueInfluence = null;

		public static ConfigEntry<int> scrapRarityMin = null;

		public static ConfigEntry<int> scrapRarityMax = null;

		public static ConfigEntry<int> scrapRarityInfluence = null;

		public static ConfigEntry<int> scrapValueIsGiftBoxChance = null;

		public static ConfigEntry<int> scrapValueAdditionChance = null;

		public static ConfigEntry<int> scrapValueAdditionMin = null;

		public static ConfigEntry<int> scrapValueAdditionMax = null;

		public static ConfigEntry<int> scrapValueMultiplierChance = null;

		public static ConfigEntry<int> scrapValueMultiplierMin = null;

		public static ConfigEntry<int> scrapValueMultiplierMax = null;

		public static ConfigEntry<int> storeItemPriceMin = null;

		public static ConfigEntry<int> storeItemPriceMax = null;

		public static ConfigEntry<int> storeItemPriceInfluence = null;

		internal static readonly Harmony harmony = new Harmony("DBJ.LC_GiftBox_Config");

		public static void Log(LogLevel logLevel, string logMessage)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			PluginLogger.Log(logLevel, (object)(logMessage ?? ""));
		}

		public static void Log(string logMessage)
		{
			Log((LogLevel)16, logMessage);
		}

		private void ValidateConfigAndApplyPatches(object? eventSender = null, SettingChangedEventArgs? eventArgs = null)
		{
			Log((LogLevel)32, "Validating config...");
			((BaseUnityPlugin)this).Config.SettingChanged -= ValidateConfigAndApplyPatches;
			if (spawnStoreItemChance.Value == 0 && spawnScrapChance.Value == 0 && spawnGiftBoxChance.Value == 0 && spawnNothingChance.Value == 0 && doNothingChance.Value == 0)
			{
				Log((LogLevel)2, "All [" + ((ConfigEntryBase)spawnScrapChance).Definition.Section + "] config weights are 0! Setting |" + ((ConfigEntryBase)giftBoxMechanicsDisabled).Definition.Key + "| to true...");
				giftBoxMechanicsDisabled.Value = true;
			}
			if (scrapValueMin.Value > scrapValueMax.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)scrapValueMin).Definition.Key + "| is greater than |" + ((ConfigEntryBase)scrapValueMax).Definition.Key + "! Swapping values...");
				ConfigEntry<int> val = scrapValueMin;
				ConfigEntry<int> obj = scrapValueMax;
				int value = scrapValueMax.Value;
				int value2 = scrapValueMin.Value;
				val.Value = value;
				obj.Value = value2;
			}
			if (scrapRarityMin.Value > scrapRarityMax.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)scrapRarityMin).Definition.Key + "| is greater than |" + ((ConfigEntryBase)scrapRarityMax).Definition.Key + "! Swapping values...");
				ConfigEntry<int> val = scrapRarityMin;
				ConfigEntry<int> obj2 = scrapRarityMax;
				int value2 = scrapRarityMax.Value;
				int value = scrapRarityMin.Value;
				val.Value = value2;
				obj2.Value = value;
			}
			if (scrapValueAdditionMin.Value > scrapValueAdditionMax.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)scrapValueAdditionMin).Definition.Key + "| is greater than |" + ((ConfigEntryBase)scrapValueAdditionMax).Definition.Key + "! Swapping values...");
				ConfigEntry<int> val = scrapValueAdditionMin;
				ConfigEntry<int> obj3 = scrapValueAdditionMax;
				int value = scrapValueAdditionMax.Value;
				int value2 = scrapValueAdditionMin.Value;
				val.Value = value;
				obj3.Value = value2;
			}
			if (scrapValueMultiplierMin.Value > scrapValueMultiplierMax.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)scrapValueMultiplierMin).Definition.Key + "| is greater than |" + ((ConfigEntryBase)scrapValueMultiplierMax).Definition.Key + "! Swapping values...");
				ConfigEntry<int> val = scrapValueMultiplierMin;
				ConfigEntry<int> obj4 = scrapValueMultiplierMax;
				int value2 = scrapValueMultiplierMax.Value;
				int value = scrapValueMultiplierMin.Value;
				val.Value = value2;
				obj4.Value = value;
			}
			if (storeItemPriceMin.Value > storeItemPriceMax.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)storeItemPriceMin).Definition.Key + "| is greater than |" + ((ConfigEntryBase)storeItemPriceMax).Definition.Key + "! Swapping values...");
				ConfigEntry<int> val = storeItemPriceMin;
				ConfigEntry<int> obj5 = storeItemPriceMax;
				int value = storeItemPriceMax.Value;
				int value2 = storeItemPriceMin.Value;
				val.Value = value;
				obj5.Value = value2;
			}
			((BaseUnityPlugin)this).Config.SettingChanged += ValidateConfigAndApplyPatches;
			Log((LogLevel)32, "Unpatching...");
			harmony.UnpatchSelf();
			Log((LogLevel)32, "Patching...");
			harmony.PatchAll();
			Log((LogLevel)32, "Finished config validation and patching!");
		}

		private void Awake()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Expected O, but got Unknown
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Expected O, but got Unknown
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Expected O, but got Unknown
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Expected O, but got Unknown
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Expected O, but got Unknown
			//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d8: Expected O, but got Unknown
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Expected O, but got Unknown
			//IL_0340: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Expected O, but got Unknown
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Expected O, but got Unknown
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Expected O, but got Unknown
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Expected O, but got Unknown
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Expected O, but got Unknown
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Expected O, but got Unknown
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Expected O, but got Unknown
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f8: Expected O, but got Unknown
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Expected O, but got Unknown
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			Log("[v1.0.3] Loading...");
			giftBoxMechanicsDisabled = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Gift Box - Toggle", "Disable modded mechanics", false, new ConfigDescription("Toggle this setting to disable the modded gift box mechanics", (AcceptableValueBase)null, Array.Empty<object>())));
			spawnStoreItemChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Behavior Selection", "Chance to select a store item (Selection Weight)", 60, new ConfigDescription("The selection weight of a gift box containing a store item. 0 = will not happen, larger selection weight = more likely to happen\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			spawnScrapChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Behavior Selection", "Chance to select a scrap item (Selection Weight)", 35, new ConfigDescription("The selection weight of a gift box containing a scrap item. 0 = will not happen, larger selection weight = more likely to happen\n\n[Vanilla Value: 100]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			spawnGiftBoxChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Behavior Selection", "Chance to select another gift box (Selection Weight)", 1, new ConfigDescription("The selection weight of a gift box containing another gift box. 0 = will not happen, larger selection weight = more likely to happen\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			spawnNothingChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Behavior Selection", "Chance to select no item (Selection Weight)", 4, new ConfigDescription("The selection weight of a gift box being empty. 0 = will not happen, larger selection weight = more likely to happen\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			doNothingChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Behavior Selection", "Chance to leave gift box unmodified (Selection Weight)", 0, new ConfigDescription("The selection weight of a gift box not being modified by this mod, i.e. so another gift box mod's effects can function instead. 0 = will not happen, larger selection weight = more likely to happen\n\nIf you do not have any other gift box mods that function by transpiling OpenGiftBoxServerRpc(), I recommend leaving this value at 0. Otherwise, I recommend setting their probability values to 100% and this probability value to the weight you'd like to assign to the other mod, so that whenever this mod selects this hands-off behavior, the other mod's functionality will have a 100% chance to occur rather than simply using vanilla behavior", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			scrapValueMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Minimum selectable scrap value", 0, new ConfigDescription("The minimum value required for a scrap item to be selected by the gift box\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			scrapValueMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Maximum selectable scrap value", int.MaxValue, new ConfigDescription("The maximum value required for a scrap item to be selected by the gift box\n\n[Vanilla Value: infinity]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			scrapValueInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Scrap value influence percentage (%)", -50, new ConfigDescription("How much influence a scrap item's value has over its selection weight. 0 = scrap item's value does not influence its selection weight, larger influence percentage = high-value scrap items are more likely than low-value scrap items, negative influence percentage = high-value scrap items are less likely than low-value scrap items\n\nEach selectable scrap item is given a selection weight equal to their scrap value raised to the power of this percentage (i.e. 100% = 100 / 100 = 1, so the exponent is 1). e.g. if this percentage is set to 200%, a scrap item with a value of 2 has a selection weight of 4 (2 ^ 200% = 2 ^ 2 = 4), which is four times the selection weight of a scrap item with a value of 1 and therefore a selection weight of 1 (1 ^ 200% = 1 ^ 2 = 1). If this value is negative, then the selection weights are inverted - e.g. -100% results in a scrap item with a value of 2 receiving a selection weight of 0.5 (2 ^ -100% = 2 ^ -1 = 1 / (2 ^ 1) = 1 / 2 = 0.5)\n\n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())));
			scrapRarityMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Minimum selectable scrap spawn weight", 0, new ConfigDescription("The minimum spawn weight required for a scrap item to be selected by the gift box\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			scrapRarityMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Maximum selectable scrap spawn weight", int.MaxValue, new ConfigDescription("The maximum value required for a scrap item to be selected by the gift box\n\n[Vanilla Value: infinity]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			scrapRarityInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Selection", "Scrap spawn weight influence percentage (%)", 50, new ConfigDescription("How much influence a scrap item's spawn weight within the current level has over its selection weight. 0 = scrap item's spawn weight does not influence its selection weight, larger influence percentage = common scrap items are more likely than rare scrap items, negative influence percentage = common scrap items are less likely than rare scrap items\n\nEach selectable scrap item is given a selection weight equal to their spawn weight raised to the power of this percentage (i.e. 100% = 100 / 100 = 1, so the exponent is 1). e.g. if this percentage is set to 200%, a scrap item with a spawn weight of 2 has a selection weight of 4 (2 ^ 200% = 2 ^ 2 = 4), which is four times the selection weight of a scrap item with a spawn weight of 1 and therefore a selection weight of 1 (1 ^ 200% = 1 ^ 2 = 1). If this value is negative, then the selection weights are inverted - e.g. -100% results in a scrap item with a spawn weight of 2 receiving a selection weight of 0.5 (2 ^ -100% = 2 ^ -1 = 1 / (2 ^ 1) = 1 / 2 = 0.5)\n\n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())));
			scrapValueIsGiftBoxChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Chance for scrap item to inherit gift box value (%)", 15, new ConfigDescription("The likelihood (% chance) of the selected scrap item having the same scrap value as the gift box itself\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())));
			scrapValueAdditionChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Chance for scrap item to receive scrap value addition (%)", 100, new ConfigDescription("The likelihood (% chance) of the selected scrap item receiving an addition to its scrap value (if the scrap item inherits the gift box's scrap value, this addition will not be applied)\n\n[Vanilla Value: 100]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())));
			scrapValueAdditionMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Minimum scrap item value addition", 30, new ConfigDescription("The minimum possible value of the multiplier applied to the selected scrap item's scrap value\n\n[Vanilla Value: 25]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())));
			scrapValueAdditionMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Maximum scrap item value addition", 60, new ConfigDescription("The maximum possible value of the multiplier applied to the selected scrap item's scrap value\n\n[Vanilla Value: 35]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())));
			scrapValueMultiplierChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Chance for scrap item to receive scrap value multiplier (%)", 35, new ConfigDescription("The likelihood (% chance) of the selected scrap item receiving a multiplier to its scrap value (if the scrap item inherits the gift box's scrap value, this multiplier will not be applied)\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())));
			scrapValueMultiplierMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Minimum scrap item value multiplier (%)", 120, new ConfigDescription("The minimum possible value of the multiplier applied to the selected scrap item's scrap value\n\n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			scrapValueMultiplierMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Scrap Item Value", "Maximum scrap item value multiplier (%)", 150, new ConfigDescription("The maximum possible value of the multiplier applied to the selected scrap item's scrap value\n\n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())));
			storeItemPriceMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Store Item Selection", "Minimum selectable store item price", 0, new ConfigDescription("The minimum store item price required for an item to be selected by the gift box\n\n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			storeItemPriceMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Store Item Selection", "Maximum selectable store item price", int.MaxValue, new ConfigDescription("The maximum store item price required for an item to be selected by the gift box\n\n[Vanilla Value: infinity]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())));
			storeItemPriceInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box - Store Item Selection", "Store item price influence percentage (%)", -100, new ConfigDescription("How much influence a store item's price has over its selection weight. 0 = store item's price does not influence its selection weight, larger influence percentage = expensive store items are more likely than cheap store items, negative influence percentage = expensive store items are less likely than cheap store items\n\nEach selectable store item is given a selection weight equal to their store price raised to the power of this percentage (i.e. 100% = 100 / 100 = 1, so the exponent is 1). e.g. if this percentage is set to 200%, a store item with a price of 2 has a selection weight of 4 (2 ^ 200% = 2 ^ 2 = 4), which is four times the selection weight of a store item with a price of 1 and therefore a selection weight of 1 (1 ^ 200% = 1 ^ 2 = 1). If this value is negative, then the selection weights are inverted - e.g. -100% results in a store item with a price of 2 receiving a selection weight of 0.5 (2 ^ -100% = 2 ^ -1 = 1 / (2 ^ 1) = 1 / 2 = 0.5)\n\n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())));
			ValidateConfigAndApplyPatches();
			Log("[v1.0.3] Finished loading!");
		}
	}
}
namespace LC_GiftBox_Config.Patches.GiftBoxItemPatches.GiftBoxItemPatches
{
	[HarmonyPatch(typeof(GiftBoxItem))]
	internal static class GiftBoxItemPatch
	{
		internal static List<int> giftboxBehaviors = new List<int>(5) { 0, 0, 0, 0, 0 };

		private const int DO_NOTHING = 0;

		private const int SPAWN_STORE_ITEM = 1;

		private const int SPAWN_SCRAP = 2;

		private const int SPAWN_GIFTBOX = 3;

		private const int SPAWN_NOTHING = 4;

		private const int IGNORE_ITEM_VALUE = -1;

		private const int USE_GIFTBOX_VALUE = -2;

		internal static Terminal _terminal = null;

		internal static Item[] _terminalBuyableItemsList = null;

		internal static List<Item> _filteredStoreItems = new List<Item>();

		internal static List<double> _filteredStoreItemWeights = new List<double>();

		private const int GIFTBOX_ITEM_ID = 152767;

		internal static List<SpawnableItemWithRarity> _currentLevelSpawnableScrap = new List<SpawnableItemWithRarity>();

		internal static List<SpawnableItemWithRarity> _filteredScrapItems = new List<SpawnableItemWithRarity>();

		internal static List<double> _filteredScrapItemWeights = new List<double>();

		internal static List<Item> filteredStoreItems
		{
			get
			{
				if ((Object)(object)_terminal == (Object)null || !((Behaviour)_terminal).isActiveAndEnabled)
				{
					_terminal = Object.FindAnyObjectByType<Terminal>();
					_terminalBuyableItemsList = null;
				}
				if (_terminalBuyableItemsList != _terminal.buyableItemsList)
				{
					_terminalBuyableItemsList = _terminal.buyableItemsList;
					_filteredStoreItems.Clear();
				}
				if (_filteredStoreItems.Count == 0)
				{
					_filteredStoreItems = _terminalBuyableItemsList.Where((Item item) => item.creditsWorth >= Plugin.storeItemPriceMin.Value && item.creditsWorth <= Plugin.storeItemPriceMax.Value).ToList();
				}
				return _filteredStoreItems;
			}
			set
			{
				if (value == null)
				{
					_filteredStoreItems.Clear();
				}
				else
				{
					_filteredStoreItems = value;
				}
			}
		}

		internal static List<double> filteredStoreItemWeights
		{
			get
			{
				_ = filteredStoreItems;
				if (_filteredStoreItemWeights.Count == 0)
				{
					_filteredStoreItemWeights = _filteredStoreItems.Select((Item item) => Math.Pow(item.creditsWorth, (double)Plugin.scrapValueInfluence.Value / 100.0)).ToList();
				}
				return _filteredStoreItemWeights;
			}
			set
			{
				if (value == null)
				{
					_filteredStoreItemWeights.Clear();
				}
				else
				{
					_filteredStoreItemWeights = value;
				}
			}
		}

		internal static List<SpawnableItemWithRarity> filteredScrapItems
		{
			get
			{
				if (_currentLevelSpawnableScrap != RoundManager.Instance.currentLevel.spawnableScrap)
				{
					_currentLevelSpawnableScrap = RoundManager.Instance.currentLevel.spawnableScrap;
					_filteredScrapItems.Clear();
					_filteredScrapItemWeights.Clear();
				}
				if (_filteredScrapItems.Count == 0)
				{
					_filteredScrapItems = _currentLevelSpawnableScrap.Where((SpawnableItemWithRarity item) => item.spawnableItem.itemId != 152767 && item.spawnableItem.minValue >= Plugin.scrapValueMin.Value && item.spawnableItem.maxValue <= Plugin.scrapValueMax.Value && item.rarity >= Plugin.scrapRarityMin.Value && item.rarity <= Plugin.scrapRarityMax.Value).ToList();
				}
				return _filteredScrapItems;
			}
			set
			{
				if (value == null)
				{
					_filteredScrapItems.Clear();
				}
				else
				{
					_filteredScrapItems = value;
				}
			}
		}

		internal static List<double> filteredScrapItemWeights
		{
			get
			{
				_ = filteredScrapItems;
				if (_filteredScrapItemWeights.Count == 0)
				{
					_filteredScrapItemWeights = _filteredScrapItems.Select((SpawnableItemWithRarity item) => Math.Pow((double)(item.spawnableItem.minValue + item.spawnableItem.maxValue) / 2.0, (double)Plugin.scrapValueInfluence.Value / 100.0) + Math.Pow(item.rarity, (double)Plugin.scrapRarityInfluence.Value / 100.0)).ToList();
				}
				return _filteredScrapItemWeights;
			}
			set
			{
				if (value == null)
				{
					_filteredScrapItemWeights.Clear();
				}
				else
				{
					_filteredScrapItemWeights = value;
				}
			}
		}

		internal static bool InsertObjectInPresentAndScrapValue(GiftBoxItem giftbox, Random giftboxBehaviorSeed, Random valueBehaviorSeed)
		{
			int randomWeightedIndex = Probability.GetRandomWeightedIndex(giftboxBehaviors, giftboxBehaviorSeed);
			giftbox.objectInPresentValue = -1;
			switch (randomWeightedIndex)
			{
			case 0:
				return false;
			case 1:
			{
				int randomWeightedIndex3 = Probability.GetRandomWeightedIndex(filteredStoreItemWeights, giftboxBehaviorSeed);
				if (randomWeightedIndex3 != -1)
				{
					giftbox.objectInPresentItem = filteredStoreItems[randomWeightedIndex3];
					giftbox.objectInPresent = giftbox.objectInPresentItem.spawnPrefab;
				}
				break;
			}
			case 3:
				giftbox.objectInPresentItem = ((GrabbableObject)giftbox).itemProperties;
				giftbox.objectInPresent = ((GrabbableObject)giftbox).itemProperties.spawnPrefab;
				goto case 2;
			case 2:
				if (randomWeightedIndex == 2)
				{
					int randomWeightedIndex2 = Probability.GetRandomWeightedIndex(filteredScrapItemWeights, giftboxBehaviorSeed);
					if (randomWeightedIndex2 == -1)
					{
						break;
					}
					giftbox.objectInPresentItem = filteredScrapItems[randomWeightedIndex2].spawnableItem;
					giftbox.objectInPresent = giftbox.objectInPresentItem.spawnPrefab;
				}
				giftbox.objectInPresentValue = valueBehaviorSeed.Next(giftbox.objectInPresentItem.minValue, giftbox.objectInPresentItem.maxValue);
				if (valueBehaviorSeed.Next(0, 100) < Plugin.scrapValueIsGiftBoxChance.Value)
				{
					giftbox.objectInPresentValue = -2;
					break;
				}
				if (valueBehaviorSeed.Next(0, 100) < Plugin.scrapValueAdditionChance.Value)
				{
					giftbox.objectInPresentValue += valueBehaviorSeed.Next(Plugin.scrapValueAdditionMin.Value, Plugin.scrapValueAdditionMax.Value + 1);
				}
				if (valueBehaviorSeed.Next(0, 100) < Plugin.scrapValueMultiplierChance.Value)
				{
					giftbox.objectInPresentValue = (int)((double)giftbox.objectInPresentValue * ((double)Plugin.scrapValueMultiplierMin.Value + (double)(Plugin.scrapValueMultiplierMax.Value - Plugin.scrapValueMultiplierMin.Value) * valueBehaviorSeed.NextDouble()) / 100.0);
				}
				giftbox.objectInPresentValue = -Math.Max(0, (int)((float)giftbox.objectInPresentValue * RoundManager.Instance.scrapValueMultiplier)) - 100;
				break;
			default:
				throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.InsertObjectInPresentAndScrapValue] Giftbox Behavior selection failed! This should never happen!");
			case 4:
				break;
			}
			return true;
		}

		[HarmonyPatch("Start")]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> Start(IEnumerable<CodeInstruction> methodIL)
		{
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Expected O, but got Unknown
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Expected O, but got Unknown
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Expected O, but got Unknown
			if (Plugin.giftBoxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			filteredStoreItems = null;
			filteredScrapItems = null;
			giftboxBehaviors[0] = Plugin.doNothingChance.Value;
			giftboxBehaviors[1] = Plugin.spawnStoreItemChance.Value;
			giftboxBehaviors[2] = Plugin.spawnScrapChance.Value;
			giftboxBehaviors[3] = Plugin.spawnGiftBoxChance.Value;
			giftboxBehaviors[4] = Plugin.spawnNothingChance.Value;
			List<CodeInstruction> codes = new List<CodeInstruction>(methodIL);
			int index = 0;
			MethodInfo findValue = typeof(NetworkBehaviour).GetMethod("get_IsServer", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] NetworkBehaviour.get_IsServer() MethodInfo not accessible");
			ILTools.FindCodeInstruction(ref index, ref codes, findValue, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] method_get_IsServer not found");
			ILTools.FindCodeInstruction(ref index, ref codes, OpCodes.Brfalse, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] OpCodes.Brfalse not found");
			MethodInfo methodInfo = typeof(GiftBoxItemPatch).GetMethod("InsertObjectInPresentAndScrapValue", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] GiftBoxItemPatch.InsertObjectInPresentAndScrapValue() MethodInfo not accessible");
			codes.Insert(index++, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			codes.Insert(index++, new CodeInstruction(OpCodes.Ldloc_0, (object)null));
			codes.Insert(index++, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
			codes.Insert(index++, new CodeInstruction(OpCodes.Call, (object)methodInfo));
			codes.Insert(index++, new CodeInstruction(OpCodes.Not, (object)null));
			codes.Insert(index++, new CodeInstruction(OpCodes.And, (object)null));
			return codes.AsEnumerable();
		}

		internal static bool OverrideOpenGiftBox(GiftBoxItem giftbox)
		{
			if (giftbox.objectInPresentValue >= 0)
			{
				return false;
			}
			switch (giftbox.objectInPresentValue)
			{
			case -2:
				giftbox.objectInPresentValue = ((GrabbableObject)giftbox).scrapValue;
				break;
			default:
				giftbox.objectInPresentValue = -(giftbox.objectInPresentValue + 100);
				break;
			case -1:
				break;
			}
			SpawnGiftItem(giftbox);
			return true;
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		internal static void SpawnGiftItem(GiftBoxItem giftbox)
		{
			Transpiler(null, null);
			static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> methodIL, ILGenerator generator)
			{
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d0: Expected O, but got Unknown
				//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e6: Expected O, but got Unknown
				//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0101: Expected O, but got Unknown
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Expected O, but got Unknown
				if (Plugin.giftBoxMechanicsDisabled.Value)
				{
					return methodIL;
				}
				List<CodeInstruction> codes = new List<CodeInstruction>(methodIL);
				int index = 0;
				MethodInfo findValue = typeof(Vector3).GetMethod("get_zero", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] Vector3.get_zero() MethodInfo not accessible");
				ILTools.FindCodeInstruction(ref index, ref codes, findValue, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] method_get_zero not found");
				ILTools.FindCodeInstruction(ref index, ref codes, OpCodes.Ldnull, reverse: true, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] OpCodes.Ldnull not found");
				codes.RemoveRange(0, index);
				index = 0;
				ILTools.FindCodeInstruction(ref index, ref codes, "Error: There is no object in gift box!", reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] \"no object\" error message not found");
				codes.RemoveRange(index, 2);
				ILTools.FindCodeInstruction(ref index, ref codes, 1, instructionIsStore: true, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] Store Local 1 (num) not found");
				ILTools.FindCodeInstruction(ref index, ref codes, 4, instructionIsStore: false, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] 1st Load Local 4 (component) not found");
				Label label = generator.DefineLabel();
				codes.Insert(index++, new CodeInstruction(OpCodes.Ldloc_1, (object)null));
				codes.Insert(index++, new CodeInstruction(OpCodes.Ldc_I4_0, (object)null));
				codes.Insert(index++, new CodeInstruction(OpCodes.Blt, (object)label));
				index++;
				ILTools.FindCodeInstruction(ref index, ref codes, 4, instructionIsStore: false, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] 2nd Load Local 4 (component) not found");
				codes.Insert(index, new CodeInstruction(OpCodes.Nop, (object)null));
				codes[index].labels.Add(label);
				return codes;
			}
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> OpenGiftBoxServerRpc(IEnumerable<CodeInstruction> methodIL, ILGenerator generator)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Expected O, but got Unknown
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			if (Plugin.giftBoxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			List<CodeInstruction> codes = new List<CodeInstruction>(methodIL);
			int index = 0;
			FieldInfo fieldInfo = typeof(NetworkBehaviour).GetField("__rpc_exec_stage", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] NetworkBehaviour.__rpc_exec_stage FieldInfo not accessible");
			ILTools.FindCodeInstruction(ref index, ref codes, fieldInfo, instructionIsStore: false, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] 1st field___rpc_exec_stage not found");
			index++;
			ILTools.FindCodeInstruction(ref index, ref codes, fieldInfo, instructionIsStore: false, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] 2nd field___rpc_exec_stage not found");
			ILTools.FindCodeInstruction(ref index, ref codes, OpCodes.Nop, reverse: false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] OpCodes.Nop not found");
			index++;
			Label label = generator.DefineLabel();
			MethodInfo methodInfo = typeof(GiftBoxItemPatch).GetMethod("OverrideOpenGiftBox", BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic) ?? throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] GiftBoxItemPatch.OverrideOpenGiftBox() MethodInfo not accessible");
			codes.Insert(index++, new CodeInstruction(OpCodes.Ldarg_0, (object)null));
			codes.Insert(index++, new CodeInstruction(OpCodes.Call, (object)methodInfo));
			codes.Insert(index++, new CodeInstruction(OpCodes.Brfalse, (object)label));
			codes.Insert(index++, new CodeInstruction(OpCodes.Ret, (object)null));
			codes.Insert(index, new CodeInstruction(OpCodes.Nop, (object)null));
			codes[index].labels.Add(label);
			return codes.AsEnumerable();
		}
	}
}
namespace LC_GiftBox_Config.libs.ReflectionsAccess
{
	public static class ReflectionsAccess
	{
		public static object CallMethod(this object methodHolder, string methodName, params object[] args)
		{
			MethodInfo methodInfo = methodHolder.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new ArgumentException($"[libs.ReflectionsAccess.CallMethod] Couldn't call nonpublic method {methodHolder}.{methodName}");
			Plugin.Log((LogLevel)32, $"[libs.ReflectionsAccess.CallMethod] Calling nonpublic method {methodHolder}.{methodName}");
			return methodInfo.Invoke(methodHolder, args);
		}

		public static T GetFieldValue<T>(object fieldHolder, string fieldName)
		{
			FieldInfo fieldInfo = fieldHolder.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new ArgumentException($"[libs.ReflectionsAccess.GetFieldValue] Field {fieldHolder}.{fieldName} not found!");
			T val = (T)fieldInfo.GetValue(fieldHolder);
			Plugin.Log((LogLevel)32, $"[libs.ReflectionsAccess.GetFieldValue] Field {fieldHolder}.{fieldName} found, returning {val}");
			return val;
		}

		public static void SetFieldValue(object fieldHolder, string fieldName, object fieldValue)
		{
			FieldInfo fieldInfo = fieldHolder.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.NonPublic) ?? throw new ArgumentException($"[libs.ReflectionsAccess.SetFieldValue] Field {fieldHolder}.{fieldName} not found!");
			Plugin.Log((LogLevel)32, $"[libs.ReflectionsAccess.SetFieldValue] Field {fieldHolder}.{fieldName} found, assigning to {fieldValue}");
			fieldInfo.SetValue(fieldHolder, fieldValue);
		}
	}
}
namespace LC_GiftBox_Config.libs.Probability
{
	public static class Probability
	{
		public static int GetRandomWeightedIndex(List<double> weights, Random? randomSeed = null)
		{
			if (weights == null || weights.Count == 0)
			{
				Plugin.Log((LogLevel)4, "[libs.Probability.GetRandomWeightedIndex] Could not get random weighted index; list is empty or null.");
				return -1;
			}
			if (weights.Any((double weight) => weight < 0.0))
			{
				Plugin.Log((LogLevel)4, "[libs.Probability.GetRandomWeightedIndex] Could not get random weighted index; list contains negative weights.");
				return -1;
			}
			if (randomSeed == null)
			{
				randomSeed = new Random();
			}
			double num = weights.Sum();
			if (num <= 0.0)
			{
				return randomSeed.Next(0, weights.Count);
			}
			double randomValue = randomSeed.NextDouble() * weights.Sum();
			double accumulatedValue = 0.0;
			return weights.FindIndex((double weight) => (accumulatedValue += weight) >= randomValue);
		}

		public static int GetRandomWeightedIndex(List<int> weights, Random? randomSeed = null)
		{
			if (weights == null || weights.Count == 0)
			{
				Plugin.Log((LogLevel)4, "[libs.Probability.GetRandomWeightedIndex] Could not get random weighted index; list is empty or null.");
				return -1;
			}
			if (weights.Any((int weight) => weight < 0))
			{
				Plugin.Log((LogLevel)4, "[libs.Probability.GetRandomWeightedIndex] Could not get random weighted index; list contains negative weights.");
				return -1;
			}
			if (randomSeed == null)
			{
				randomSeed = new Random();
			}
			int num = weights.Sum();
			if (num <= 0)
			{
				return randomSeed.Next(0, weights.Count);
			}
			int randomValue = randomSeed.Next(0, num);
			int accumulatedValue = 0;
			return weights.FindIndex((int weight) => (accumulatedValue += weight) >= randomValue);
		}
	}
}
namespace LC_GiftBox_Config.libs.LethalConfigNicerizer
{
	internal static class LethalConfigNicerizer
	{
		internal const string LethalConfig_GUID = "ainavt.lc.lethalconfig";

		internal static bool CanHasNicerizationPlease => Chainloader.PluginInfos.ContainsKey("ainavt.lc.lethalconfig");

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static ConfigEntry<T> Nicerize<T>(ConfigEntry<T> entry, bool restartRequired = false)
		{
			if (entry is ConfigEntry<int>)
			{
				if (CanHasNicerizationPlease)
				{
					AddConfigItem(entry as ConfigEntry<int>, restartRequired);
				}
			}
			else if (entry is ConfigEntry<float>)
			{
				if (CanHasNicerizationPlease)
				{
					AddConfigItem(entry as ConfigEntry<float>, restartRequired);
				}
			}
			else if (entry is ConfigEntry<bool>)
			{
				if (CanHasNicerizationPlease)
				{
					AddConfigItem(entry as ConfigEntry<bool>, restartRequired);
				}
			}
			else if (entry is ConfigEntry<string>)
			{
				if (CanHasNicerizationPlease)
				{
					AddConfigItem(entry as ConfigEntry<string>, restartRequired);
				}
			}
			else
			{
				if (!(entry is ConfigEntry<Enum>))
				{
					throw new ArgumentException($"[libs.LethalConfigNicerizer.Nicerize] Cannot Nicerize ConfigEntry<{typeof(T)}>!");
				}
				if (CanHasNicerizationPlease)
				{
					AddConfigItem(entry as ConfigEntry<Enum>, restartRequired);
				}
			}
			return entry;
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<int> entry, bool restartRequired = false)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (((ConfigEntryBase)entry).Description.AcceptableValues != null)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new IntSliderConfigItem(entry, restartRequired));
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new IntInputFieldConfigItem(entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<float> entry, bool restartRequired = false)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (((ConfigEntryBase)entry).Description.AcceptableValues != null)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatSliderConfigItem(entry, restartRequired));
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new FloatInputFieldConfigItem(entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<bool> entry, bool restartRequired = false)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(entry, restartRequired));
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<string> entry, bool restartRequired = false)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (((ConfigEntryBase)entry).Description.AcceptableValues != null)
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextDropDownConfigItem(entry, restartRequired));
			}
			else
			{
				LethalConfigManager.AddConfigItem((BaseConfigItem)new TextInputFieldConfigItem(entry, restartRequired));
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.NoOptimization)]
		internal static void AddConfigItem(ConfigEntry<Enum> entry, bool restartRequired = false)
		{
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)new EnumDropDownConfigItem<Enum>(entry, restartRequired));
		}
	}
}
namespace LC_GiftBox_Config.libs.ILTools
{
	public static class ILTools
	{
		private static readonly OpCode[] ArgumentedLoadLocalCodeInstructions = new OpCode[2]
		{
			OpCodes.Ldloc,
			OpCodes.Ldloc_S
		};

		private static readonly OpCode[] ArgumentedStoreLocalCodeInstructions = new OpCode[2]
		{
			OpCodes.Stloc,
			OpCodes.Stloc_S
		};

		private static readonly OpCode[] ArgumentedIntegerCodeInstructions = new OpCode[3]
		{
			OpCodes.Ldc_I4,
			OpCodes.Ldc_I4_S,
			OpCodes.Ldc_I8
		};

		private static readonly OpCode[] ArgumentedFloatCodeInstructions = new OpCode[2]
		{
			OpCodes.Ldc_R4,
			OpCodes.Ldc_R8
		};

		public static bool FindCodeInstruction(ref int index, ref List<CodeInstruction> codes, object findValue, bool reverse = false, string? errorMessage = "Not found")
		{
			index = Math.Clamp(index, 0, codes.Count);
			while (index >= 0 && index < codes.Count)
			{
				if (CheckCodeInstruction(codes[index], findValue))
				{
					return true;
				}
				index += ((!reverse) ? 1 : (-1));
			}
			if (errorMessage != null)
			{
				throw new Exception($"[libs.ILTools.FindCodeInstruction] [{findValue}] | {errorMessage}");
			}
			return false;
		}

		public static bool FindCodeInstruction(ref int index, ref List<CodeInstruction> codes, short localIndex, bool instructionIsStore = false, bool reverse = false, string? errorMessage = "Not found")
		{
			index = Math.Clamp(index, 0, codes.Count);
			while (index >= 0 && index < codes.Count)
			{
				if (CheckCodeInstruction(codes[index], localIndex, instructionIsStore))
				{
					return true;
				}
				index += ((!reverse) ? 1 : (-1));
			}
			if (errorMessage != null)
			{
				throw new Exception($"[libs.ILTools.FindCodeInstruction] {{{localIndex}, {instructionIsStore}}}] | {errorMessage}");
			}
			return false;
		}

		public static bool FindCodeInstruction(ref int index, ref List<CodeInstruction> codes, FieldInfo fieldInfo, bool instructionIsStore = false, bool reverse = false, string? errorMessage = "Not found")
		{
			index = Math.Clamp(index, 0, codes.Count);
			while (index >= 0 && index < codes.Count)
			{
				if (CheckCodeInstruction(codes[index], fieldInfo, instructionIsStore))
				{
					return true;
				}
				index += ((!reverse) ? 1 : (-1));
			}
			if (errorMessage != null)
			{
				throw new Exception($"[libs.ILTools.FindCodeInstruction] {{{fieldInfo}, {instructionIsStore}}}] | {errorMessage}");
			}
			return false;
		}

		private static bool CheckCodeInstruction(CodeInstruction code, int localIndex, bool instructionIsStore)
		{
			if (!instructionIsStore)
			{
				bool result;
				if (ArgumentedLoadLocalCodeInstructions.Contains(code.opcode))
				{
					LocalBuilder obj = code.operand as LocalBuilder;
					result = obj != null && obj.LocalIndex == localIndex;
				}
				else
				{
					result = localIndex switch
					{
						0 => code.opcode == OpCodes.Ldloc_0, 
						1 => code.opcode == OpCodes.Ldloc_1, 
						2 => code.opcode == OpCodes.Ldloc_2, 
						3 => code.opcode == OpCodes.Ldloc_3, 
						_ => false, 
					};
				}
				return result;
			}
			bool result2;
			if (ArgumentedStoreLocalCodeInstructions.Contains(code.opcode))
			{
				LocalBuilder obj2 = code.operand as LocalBuilder;
				result2 = obj2 != null && obj2.LocalIndex == localIndex;
			}
			else
			{
				result2 = localIndex switch
				{
					0 => code.opcode == OpCodes.Stloc_0, 
					1 => code.opcode == OpCodes.Stloc_1, 
					2 => code.opcode == OpCodes.Stloc_2, 
					3 => code.opcode == OpCodes.Stloc_3, 
					_ => false, 
				};
			}
			return result2;
		}

		private static bool CheckCodeInstruction(CodeInstruction code, FieldInfo fieldInfo, bool instructionIsStore)
		{
			if (!instructionIsStore)
			{
				return (code.opcode == OpCodes.Ldfld || code.opcode == OpCodes.Ldsfld) && (FieldInfo)code.operand == fieldInfo;
			}
			return (code.opcode == OpCodes.Stfld || code.opcode == OpCodes.Stsfld) && (FieldInfo)code.operand == fieldInfo;
		}

		private static bool CheckCodeInstruction(CodeInstruction code, object findValue)
		{
			if (findValue == null)
			{
				throw new ArgumentNullException("CheckCodeInstruction(code, findValue) findValue should not be null; use CheckCodeInstruction(code, OpCodes.Ldnull) if searching for null");
			}
			if (findValue is byte || findValue is sbyte || findValue is short || findValue is ushort || findValue is int || findValue is uint || findValue is long || findValue is ulong)
			{
				return CheckIntegerCodeInstruction(code, findValue);
			}
			if (findValue is float || findValue is double || findValue is decimal)
			{
				return CheckFloatCodeInstruction(code, findValue);
			}
			if (findValue is string)
			{
				if (code.opcode == OpCodes.Ldstr)
				{
					return code.operand.Equals(findValue);
				}
				return false;
			}
			if (findValue is MethodInfo)
			{
				if (code.opcode == OpCodes.Call || code.opcode == OpCodes.Callvirt)
				{
					return code.operand == findValue;
				}
				return false;
			}
			if (findValue is OpCode)
			{
				return code.opcode == (OpCode)findValue;
			}
			if (findValue is FieldInfo)
			{
				throw new ArgumentException("CheckCodeInstruction(code, findValue) findValue should not be FieldInfo; use CheckCodeInstruction(code, fieldInfo, instructionIsStore) instead");
			}
			return false;
		}

		private static bool CheckIntegerCodeInstruction(CodeInstruction code, object findValue)
		{
			if (ArgumentedIntegerCodeInstructions.Contains(code.opcode))
			{
				return code.operand == findValue;
			}
			if (findValue is ulong num && num > 8)
			{
				return false;
			}
			long num2 = (long)findValue;
			long num3 = num2 - -1;
			if ((ulong)num3 <= 9uL)
			{
				switch (num3)
				{
				case 1L:
					return code.opcode == OpCodes.Ldc_I4_0;
				case 2L:
					return code.opcode == OpCodes.Ldc_I4_1;
				case 3L:
					return code.opcode == OpCodes.Ldc_I4_2;
				case 4L:
					return code.opcode == OpCodes.Ldc_I4_3;
				case 5L:
					return code.opcode == OpCodes.Ldc_I4_4;
				case 6L:
					return code.opcode == OpCodes.Ldc_I4_5;
				case 7L:
					return code.opcode == OpCodes.Ldc_I4_6;
				case 8L:
					return code.opcode == OpCodes.Ldc_I4_7;
				case 9L:
					return code.opcode == OpCodes.Ldc_I4_8;
				case 0L:
					return code.opcode == OpCodes.Ldc_I4_M1;
				}
			}
			return false;
		}

		private static bool CheckFloatCodeInstruction(CodeInstruction code, object findValue)
		{
			if (ArgumentedFloatCodeInstructions.Contains(code.opcode))
			{
				return code.operand == findValue;
			}
			return false;
		}
	}
}