Decompiled source of LC GiftBox Config v1.2.0

plugins/LC_GiftBox_Config.dll

Decompiled 3 weeks 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.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using ILUtils;
using ILUtils.HarmonyXtensions;
using LCUtils;
using Microsoft.CodeAnalysis;
using StaticNetcodeLib;
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 gift boxes / presents, such as having store items / scrap / another present / nothing, weighting of item selection, spawn rates, etc.")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyInformationalVersion("1.2.0+58656a83e1f16f480cfefde1978bc70253ca2256")]
[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.2.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;
		}
	}
}
internal static class BepPluginInfo
{
	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.2.0";
}
namespace LC_GiftBox_Config
{
	[BepInPlugin("com.github.decibillyjoel.lc_giftbox_config", "DBJ.LC_GiftBox_Config", "1.2.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.github.decibillyjoel.lc_giftbox_config";

		public const string PLUGIN_NAME = "LC_GiftBox_Config";

		public const string PLUGIN_VERSION = "1.2.0";

		public const string PLUGIN_TS_TEAM = "DBJ";

		public static ManualLogSource PluginLogger = null;

		public static ConfigEntry<bool> giftboxMechanicsDisabled = null;

		public static ConfigEntry<bool> giftboxDupeSoundsBugFixDisabled = null;

		public static ConfigEntry<bool> giftboxToolScrapValueBugfixDisabled = null;

		public static ConfigEntry<int> giftboxEggsplosionChance = null;

		public static ConfigEntry<int> positionRNGInfluence = 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<bool> scrapRarityCanBeZero = 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> giftboxValueAdditionChance = null;

		public static ConfigEntry<int> giftboxValueAdditionMin = null;

		public static ConfigEntry<int> giftboxValueAdditionMax = null;

		public static ConfigEntry<int> giftboxValueMultiplierChance = null;

		public static ConfigEntry<int> giftboxValueMultiplierMin = null;

		public static ConfigEntry<int> giftboxValueMultiplierMax = null;

		public static ConfigEntry<int> giftboxRarityAdditionChance = null;

		public static ConfigEntry<int> giftboxRarityAdditionMin = null;

		public static ConfigEntry<int> giftboxRarityAdditionMax = null;

		public static ConfigEntry<int> giftboxRarityMultiplierChance = null;

		public static ConfigEntry<int> giftboxRarityMultiplierMin = null;

		public static ConfigEntry<int> giftboxRarityMultiplierMax = null;

		public static ConfigEntry<int> giftboxSpawnChance = null;

		public static ConfigEntry<int> giftboxSpawnMin = null;

		public static ConfigEntry<int> giftboxSpawnMax = null;

		public static ConfigEntry<int> storeItemPriceMin = null;

		public static ConfigEntry<int> storeItemPriceMax = null;

		public static ConfigEntry<int> storeItemPriceInfluence = null;

		public static ConfigEntry<bool> storeItemMustBeBuyable = 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 ValidateMinMaxOrder(ConfigEntry<int> minEntry, ConfigEntry<int> maxEntry)
		{
			if (minEntry.Value > maxEntry.Value)
			{
				Log((LogLevel)4, "|" + ((ConfigEntryBase)minEntry).Definition.Key + "| is greater than |" + ((ConfigEntryBase)maxEntry).Definition.Key + "! Swapping values...");
				int value = maxEntry.Value;
				int value2 = minEntry.Value;
				minEntry.Value = value;
				maxEntry.Value = value2;
			}
		}

		private void ValidateConfigAndApplyPatches()
		{
			Log((LogLevel)32, "Validating config...");
			((BaseUnityPlugin)this).Config.SettingChanged -= ScheduleValidateConfigAndApplyPatches;
			if (spawnStoreItemChance.Value == 0 && spawnScrapChance.Value == 0 && spawnGiftBoxChance.Value == 0 && spawnNothingChance.Value == 0 && doNothingChance.Value == 0)
			{
				Log((LogLevel)4, "All [" + ((ConfigEntryBase)doNothingChance).Definition.Section + "] config weights are 0! This will cause the gift box to always be unmodified! Please set at least one of the weights to a non-zero value!");
			}
			ValidateMinMaxOrder(scrapValueMin, scrapValueMax);
			ValidateMinMaxOrder(scrapRarityMin, scrapRarityMax);
			ValidateMinMaxOrder(scrapValueAdditionMin, scrapValueAdditionMax);
			ValidateMinMaxOrder(scrapValueMultiplierMin, scrapValueMultiplierMax);
			ValidateMinMaxOrder(storeItemPriceMin, storeItemPriceMax);
			ValidateMinMaxOrder(giftboxRarityAdditionMin, giftboxRarityAdditionMax);
			ValidateMinMaxOrder(giftboxRarityMultiplierMin, giftboxRarityMultiplierMax);
			ValidateMinMaxOrder(giftboxValueAdditionMin, giftboxValueAdditionMax);
			ValidateMinMaxOrder(giftboxValueMultiplierMin, giftboxValueMultiplierMax);
			ValidateMinMaxOrder(giftboxSpawnMin, giftboxSpawnMax);
			if (!scrapRarityCanBeZero.Value)
			{
				scrapRarityMin.Value = Math.Max(scrapRarityMin.Value, 1);
				scrapRarityMax.Value = Math.Max(scrapRarityMax.Value, 1);
			}
			((BaseUnityPlugin)this).Config.SettingChanged += ScheduleValidateConfigAndApplyPatches;
			Log((LogLevel)32, "Unpatching...");
			harmony.UnpatchSelf();
			Log((LogLevel)32, "Patching...");
			try
			{
				harmony.PatchAll();
			}
			catch (Exception arg)
			{
				Log((LogLevel)2, $"Patching failed! Unpatching! Exception:\n{arg}");
				harmony.UnpatchSelf();
			}
			Log((LogLevel)32, "Finished config validation and patching!");
		}

		private void ScheduleValidateConfigAndApplyPatches(object? eventSender = null, SettingChangedEventArgs? eventArgs = null)
		{
			Log((LogLevel)32, "Scheduling config validation...");
			string text = "ValidateConfigAndApplyPatches";
			((MonoBehaviour)this).CancelInvoke(text);
			((MonoBehaviour)this).Invoke(text, 0.33f);
		}

		private void Awake()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Expected O, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Expected O, but got Unknown
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Expected O, but got Unknown
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Expected O, but got Unknown
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e4: Expected O, but got Unknown
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Expected O, but got Unknown
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Expected O, but got Unknown
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Expected O, but got Unknown
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Expected O, but got Unknown
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Expected O, but got Unknown
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0447: Expected O, but got Unknown
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: Expected O, but got Unknown
			//IL_04bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Expected O, but got Unknown
			//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Expected O, but got Unknown
			//IL_0536: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Expected O, but got Unknown
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Expected O, but got Unknown
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ba: Expected O, but got Unknown
			//IL_05f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fb: Expected O, but got Unknown
			//IL_0632: Unknown result type (might be due to invalid IL or missing references)
			//IL_063c: Expected O, but got Unknown
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0676: Expected O, but got Unknown
			//IL_06a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Expected O, but got Unknown
			//IL_06e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Expected O, but got Unknown
			//IL_0723: Unknown result type (might be due to invalid IL or missing references)
			//IL_072d: Expected O, but got Unknown
			//IL_0764: Unknown result type (might be due to invalid IL or missing references)
			//IL_076e: Expected O, but got Unknown
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_07af: Expected O, but got Unknown
			//IL_07df: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e9: Expected O, but got Unknown
			//IL_081c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0826: Expected O, but got Unknown
			//IL_085c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0866: Expected O, but got Unknown
			//IL_0896: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a0: Expected O, but got Unknown
			//IL_08cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d9: Expected O, but got Unknown
			//IL_0908: Unknown result type (might be due to invalid IL or missing references)
			//IL_0912: Expected O, but got Unknown
			//IL_0942: Unknown result type (might be due to invalid IL or missing references)
			//IL_094c: Expected O, but got Unknown
			//IL_097c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0986: Expected O, but got Unknown
			//IL_09ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_09b8: Expected O, but got Unknown
			//IL_09e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ea: Expected O, but got Unknown
			//IL_0a12: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a1c: Expected O, but got Unknown
			PluginLogger = ((BaseUnityPlugin)this).Logger;
			Log("[v1.2.0] Loading...");
			spawnStoreItemChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Item Type", "Store Item Chance (Selection Weight)", 50, new ConfigDescription("The selection weight of a gift box containing a store item.     \n0 = will not happen    \nLarger selection weight = more likely to happen    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			spawnScrapChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Item Type", "Scrap Item Chance (Selection Weight)", 30, new ConfigDescription("The selection weight of a gift box containing a scrap item.     \n0 = will not happen    \nLarger selection weight = more likely to happen    \n    \n[Vanilla Value: 100]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			spawnGiftBoxChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Item Type", "Gift Box Chance (Selection Weight)", 5, new ConfigDescription("The selection weight of a gift box containing another gift box.     \n0 = will not happen    \nLarger selection weight = more likely to happen    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			spawnNothingChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Item Type", "Empty Chance (Selection Weight)", 15, new ConfigDescription("The selection weight of a gift box being empty.     \n0 = will not happen    \nLarger selection weight = more likely to happen    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			doNothingChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Item Type", "Unmodified Chance (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.     \n0 = will not happen    \nLarger 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>())), false, (Assembly)null);
			scrapValueMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Scrap Value Minimum", 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>())), false, (Assembly)null);
			scrapValueMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Scrap Value Maximum", 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>())), false, (Assembly)null);
			scrapValueInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Scrap Value Influence (%)", -50, new ConfigDescription("How much influence a scrap item's value has over its selection weight.     \n0 = scrap item's value does not influence its selection weight    \nLarger influence percentage = high-value scrap items are more likely than low-value scrap items    \nNegative 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 / 10    \n0 = 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>())), false, (Assembly)null);
			scrapRarityMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Spawn Weight Minimum", 1, new ConfigDescription("The minimum spawn weight required for a scrap item to be selected by the gift box    \n    \n[Vanilla Value: 1]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, int.MaxValue), Array.Empty<object>())), false, (Assembly)null);
			scrapRarityMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Spawn Weight Maximum", 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>())), false, (Assembly)null);
			scrapRarityInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Item", "Spawn Weight Influence (%)", 50, new ConfigDescription("How much influence a scrap item's spawn weight within the current level has over its selection weight.     \n0 = scrap item's spawn weight does not influence its selection weight    \nLarger influence percentage = common scrap items are more likely than rare scrap items    \nNegative 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 / 10    \n0 = 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>())), false, (Assembly)null);
			scrapRarityCanBeZero = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Contained Scrap Item", "Spawn Weight Can Be Zero", false, new ConfigDescription("If true, scrap items with a spawn weight of 0 will be selectable by the gift box, i.e. if its scrap value causes it to be selected. (If this is set to false, Spawn Weight Minimum and Maximum will be adjusted to be no less than 1)    \n    \n[Vanilla Value: false]", (AcceptableValueBase)null, Array.Empty<object>())), false, (Assembly)null);
			storeItemPriceMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Store Item", "Price Minimum", 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>())), false, (Assembly)null);
			storeItemPriceMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Store Item", "Price Maximum", 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>())), false, (Assembly)null);
			storeItemPriceInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Store Item", "Price Influence (%)", -100, new ConfigDescription("How much influence a store item's price has over its selection weight.     \n0 = store item's price does not influence its selection weight    \nLarger influence percentage = expensive store items are more likely than cheap store items    \nNegative 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 / 10    \n0 = 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>())), false, (Assembly)null);
			storeItemMustBeBuyable = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Contained Store Item", "Must Be Buyable", true, new ConfigDescription("If true, only store items that are accessible through the terminal will be selectable by the gift box    \n    \n[Vanilla Value: N/A]", (AcceptableValueBase)null, Array.Empty<object>())), false, (Assembly)null);
			scrapValueIsGiftBoxChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Inherit Gift Box Value Chance (%)", 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>())), false, (Assembly)null);
			scrapValueAdditionChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Addition Chance (%)", 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>())), false, (Assembly)null);
			scrapValueAdditionMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Addition Minimum", 30, new ConfigDescription("The minimum possible value of the addition applied to the selected scrap item's scrap value    \n    \n[Vanilla Value: 25]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			scrapValueAdditionMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Addition Maximum", 40, new ConfigDescription("The maximum possible value of the addition applied to the selected scrap item's scrap value    \n    \n[Vanilla Value: 35]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			scrapValueMultiplierChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Multiplier Chance (%)", 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>())), false, (Assembly)null);
			scrapValueMultiplierMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Multiplier Minimum (%)", 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>())), false, (Assembly)null);
			scrapValueMultiplierMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Contained Scrap Value", "Multiplier Maximum (%)", 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>())), false, (Assembly)null);
			giftboxValueAdditionChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Addition Chance (%)", 100, new ConfigDescription("The likelihood (% chance) of the gift box receiving an addition to its scrap value    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxValueAdditionMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Addition Minimum", 30, new ConfigDescription("The minimum possible value of the addition applied to the gift box's scrap value    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxValueAdditionMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Addition Maximum", 40, new ConfigDescription("The maximum possible value of the addition applied to the gift box's scrap value    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxValueMultiplierChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Multiplier Chance (%)", 35, new ConfigDescription("The likelihood (% chance) of the gift box receiving a multiplier to its scrap value    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxValueMultiplierMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Multiplier Minimum (%)", 120, new ConfigDescription("The minimum possible value of the multiplier applied to the gift box's scrap value    \n    \n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxValueMultiplierMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Scrap Value", "Multiplier Maximum (%)", 150, new ConfigDescription("The maximum possible value of the multiplier applied to the gift box's scrap value    \n    \n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityAdditionChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Addition Chance (%)", 25, new ConfigDescription("The likelihood (% chance) of gift boxes receiving an addition to their spawn weight within the current level    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityAdditionMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Addition Minimum", 10, new ConfigDescription("The minimum possible value of the addition applied to gift boxes' spawn weight within the current level    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityAdditionMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Addition Maximum", 15, new ConfigDescription("The maximum possible value of the addition applied to gift boxes' spawn weight within the current level    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(-1000, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityMultiplierChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Multiplier Chance (%)", 25, new ConfigDescription("The likelihood (% chance) of gift boxes receiving a multiplier to their spawn weight within the current level    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityMultiplierMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Multiplier Minimum", 120, new ConfigDescription("The minimum possible value of the multiplier applied to gift boxes' spawn weight within the current level    \n    \n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxRarityMultiplierMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Weight", "Multiplier Maximum", 150, new ConfigDescription("The maximum possible value of the multiplier applied to gift boxes' spawn weight within the current level    \n    \n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>())), false, (Assembly)null);
			giftboxSpawnChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Anomaly", "Anomalous Spawning Chance (%)", 65, new ConfigDescription("The likelihood (% chance) of gift boxes anomalously spawning in the current level, separate from the level's natural scrap pool mechanics    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxSpawnMin = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Anomaly", "Minimum Gift Boxes", 2, new ConfigDescription("The minimum possible number of gift boxes to be anomalously spawned    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxSpawnMax = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Spawn Anomaly", "Maximum Gift Boxes", 5, new ConfigDescription("The maximum possible number of gift boxes to be anomalously spawned    \n    \n[Vanilla Value: 0]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxEggsplosionChance = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Behaviors", "Empty Gift Box Eggsplosion Chance (%)", 100, new ConfigDescription("The likelihood (% chance) of an empty gift box non-harmfully eggsploding (it won't harm you, but it may attract enemies who will)    \n    \n[Vanilla Value: 0%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			positionRNGInfluence = LethalConfigNicerizer.Nicerize<int>(((BaseUnityPlugin)this).Config.Bind<int>("Gift Box Behaviors", "Position-Based Randomness Influence (%)", 50, new ConfigDescription("How much influence position-based randomness has over all gift box randomness mechanics. Lowering this value increases the randomness felt between gift boxes in the same position; increasing this value decreases the randomness felt between gift boxes in the same position    \n    \n[Vanilla Value: 100%]", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>())), false, (Assembly)null);
			giftboxMechanicsDisabled = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Compatibility / Debugging", "Disable All Mod Mechanics", false, new ConfigDescription("WARNING: May cause unexpected game behaviors, desyncs, or loss / corruption of mod-related save data! Do not use this setting unless you know what you're doing!    \n    \nToggle this setting to disable the modded gift box mechanics", (AcceptableValueBase)null, Array.Empty<object>())), false, (Assembly)null);
			giftboxDupeSoundsBugFixDisabled = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Compatibility / Debugging", "Disable Gift Box Duplicate Sounds Bugfix", false, new ConfigDescription("Toggle this setting to disable the gift box duplicate sounds bugfix", (AcceptableValueBase)null, Array.Empty<object>())), false, (Assembly)null);
			giftboxToolScrapValueBugfixDisabled = LethalConfigNicerizer.Nicerize<bool>(((BaseUnityPlugin)this).Config.Bind<bool>("Compatibility / Debugging", "Disable Gift Box Setting Tool Scrap Value Bugfix", false, new ConfigDescription("Toggle this setting to disable the bugfix for the gift box setting a tool's scrap value", (AcceptableValueBase)null, Array.Empty<object>())), false, (Assembly)null);
			MigrateOldEntries(("Gift Box - Gift Box Value", "Chance for the gift box to receive scrap value addition (%)", (ConfigEntryBase)(object)giftboxValueAdditionChance), ("Gift Box - Gift Box Value", "Minimum gift box value addition", (ConfigEntryBase)(object)giftboxValueAdditionMin), ("Gift Box - Gift Box Value", "Maximum gift box value addition", (ConfigEntryBase)(object)giftboxValueAdditionMax), ("Gift Box - Gift Box Value", "Chance for gift box to receive scrap value multiplier (%)", (ConfigEntryBase)(object)giftboxValueMultiplierChance), ("Gift Box - Gift Box Value", "Minimum gift box value multiplier (%)", (ConfigEntryBase)(object)giftboxValueMultiplierMin), ("Gift Box - Gift Box Value", "Maximum gift box value multiplier (%)", (ConfigEntryBase)(object)giftboxValueMultiplierMax), ("Gift Box - Gift Box Natural Spawn Chance", "Chance for gift boxes to receive spawn weight addition (%)", (ConfigEntryBase)(object)giftboxRarityAdditionChance), ("Gift Box - Gift Box Natural Spawn Chance", "Minimum gift box spawn weight addition", (ConfigEntryBase)(object)giftboxRarityAdditionMin), ("Gift Box - Gift Box Natural Spawn Chance", "Maximum gift box spawn weight addition", (ConfigEntryBase)(object)giftboxRarityAdditionMax), ("Gift Box - Gift Box Natural Spawn Chance", "Chance for gift boxes to receive spawn weight multiplier (%)", (ConfigEntryBase)(object)giftboxRarityMultiplierChance), ("Gift Box - Gift Box Natural Spawn Chance", "Minimum gift box spawn weight multiplier (%)", (ConfigEntryBase)(object)giftboxRarityMultiplierMin), ("Gift Box - Gift Box Natural Spawn Chance", "Maximum gift box spawn weight multiplier (%)", (ConfigEntryBase)(object)giftboxRarityMultiplierMax), ("Gift Box - Gift Box Anomalous Spawning", "Chance for gift boxes to anomalously spawn (%)", (ConfigEntryBase)(object)giftboxSpawnChance), ("Gift Box - Gift Box Anomalous Spawning", "Minimum number of anomalously spawned gift boxes", (ConfigEntryBase)(object)giftboxSpawnMin), ("Gift Box - Gift Box Anomalous Spawning", "Maximum number of anomalously spawned gift boxes", (ConfigEntryBase)(object)giftboxSpawnMax), ("Gift Box - Behavior Selection", "Chance to select a store item (Selection Weight)", (ConfigEntryBase)(object)spawnStoreItemChance), ("Gift Box - Behavior Selection", "Chance to select a scrap item (Selection Weight)", (ConfigEntryBase)(object)spawnScrapChance), ("Gift Box - Behavior Selection", "Chance to select another gift box (Selection Weight)", (ConfigEntryBase)(object)spawnGiftBoxChance), ("Gift Box - Behavior Selection", "Chance to select no item (Selection Weight)", (ConfigEntryBase)(object)spawnNothingChance), ("Gift Box - Behavior Selection", "Chance to leave gift box unmodified (Selection Weight)", (ConfigEntryBase)(object)doNothingChance), ("Gift Box - Scrap Selection", "Minimum selectable scrap value", (ConfigEntryBase)(object)scrapValueMin), ("Gift Box - Scrap Selection", "Maximum selectable scrap value", (ConfigEntryBase)(object)scrapValueMax), ("Gift Box - Scrap Selection", "Scrap value influence percentage (%)", (ConfigEntryBase)(object)scrapValueInfluence), ("Gift Box - Scrap Selection", "Minimum selectable scrap spawn weight", (ConfigEntryBase)(object)scrapRarityMin), ("Gift Box - Scrap Selection", "Maximum selectable scrap spawn weight", (ConfigEntryBase)(object)scrapRarityMax), ("Gift Box - Scrap Selection", "Scrap spawn weight influence percentage (%)", (ConfigEntryBase)(object)scrapRarityInfluence), ("Gift Box - Scrap Item Value", "Chance for scrap item to inherit gift box value (%)", (ConfigEntryBase)(object)scrapValueIsGiftBoxChance), ("Gift Box - Scrap Item Value", "Chance for scrap item to receive scrap value addition (%)", (ConfigEntryBase)(object)scrapValueAdditionChance), ("Gift Box - Scrap Item Value", "Minimum scrap item value addition", (ConfigEntryBase)(object)scrapValueAdditionMin), ("Gift Box - Scrap Item Value", "Maximum scrap item value addition", (ConfigEntryBase)(object)scrapValueAdditionMax), ("Gift Box - Scrap Item Value", "Chance for scrap item to receive scrap value multiplier (%)", (ConfigEntryBase)(object)scrapValueMultiplierChance), ("Gift Box - Scrap Item Value", "Minimum scrap item value multiplier (%)", (ConfigEntryBase)(object)scrapValueMultiplierMin), ("Gift Box - Scrap Item Value", "Maximum scrap item value multiplier (%)", (ConfigEntryBase)(object)scrapValueMultiplierMax), ("Gift Box - Store Item Selection", "Minimum selectable store item price", (ConfigEntryBase)(object)storeItemPriceMin), ("Gift Box - Store Item Selection", "Maximum selectable store item price", (ConfigEntryBase)(object)storeItemPriceMax), ("Gift Box - Store Item Selection", "Store item price influence percentage (%)", (ConfigEntryBase)(object)storeItemPriceInfluence), ("Gift Box Behaviors", "Disable All Mod Mechanics", (ConfigEntryBase)(object)giftboxMechanicsDisabled), ("Gift Box Behaviors", "Disable Gift Box Duplicate Sounds Bugfix", (ConfigEntryBase)(object)giftboxDupeSoundsBugFixDisabled), ("Gift Box Behaviors", "Disable Gift Box Setting Tool Scrap Value Bugfix", (ConfigEntryBase)(object)giftboxToolScrapValueBugfixDisabled));
			ValidateConfigAndApplyPatches();
			Log("[v1.2.0] Finished loading!");
		}

		private void MigrateOldEntries(params (string oldSection, string oldKey, ConfigEntryBase newEntry)[] migrations)
		{
			Dictionary<ConfigDefinition, string> orphanedEntries = (Dictionary<ConfigDefinition, string>)(AccessTools.DeclaredPropertyGetter(typeof(ConfigFile), "OrphanedEntries")?.Invoke(((BaseUnityPlugin)this).Config, Array.Empty<object>()));
			if (orphanedEntries == null)
			{
				Log((LogLevel)4, "Unable to retrieve orphaned entries!");
				return;
			}
			int migrationsPerformed = 0;
			CollectionExtensions.Do<(string, string, ConfigEntryBase)>((IEnumerable<(string, string, ConfigEntryBase)>)migrations, (Action<(string, string, ConfigEntryBase)>)delegate((string oldSection, string oldKey, ConfigEntryBase newEntry) migration)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				ConfigDefinition val = new ConfigDefinition(migration.oldSection, migration.oldKey);
				if (orphanedEntries.TryGetValue(val, out string value))
				{
					migration.newEntry.SetSerializedValue(value);
					migrationsPerformed++;
					Log($"[{migrationsPerformed} Migrated [{val.Section}].[{val.Key}] to [{migration.newEntry.Definition.Section}].[{migration.newEntry.Definition.Key}]");
					orphanedEntries.Remove(val);
				}
			});
			if (migrationsPerformed != 0)
			{
				Log($"Successfully migrated {migrationsPerformed} orphan entries! Saving to file...");
				((BaseUnityPlugin)this).Config.Save();
				Log("Migrations saved to file!");
			}
		}
	}
}
namespace LC_GiftBox_Config.Patches.GiftBoxItemPatches
{
	[StaticNetcode]
	[HarmonyPatch(typeof(GiftBoxItem))]
	public static class GiftBoxItemPatch
	{
		public class GiftBoxModdedParams
		{
			[ES3Serializable]
			public bool CanEggsplode;

			[ES3Serializable]
			public bool ScrapHasGiftBoxValue;

			[ES3Serializable]
			public int ScrapValue;

			[ES3Serializable]
			public int NestedScrapId = -1;
		}

		public class GiftBoxModdedBehavior : MonoBehaviour
		{
			public GiftBoxModdedParams Params;

			public GiftBoxModdedBehavior()
			{
				Params = new GiftBoxModdedParams();
			}

			public GiftBoxModdedBehavior(GiftBoxModdedParams _Params)
			{
				Params = _Params;
			}

			public static implicit operator GiftBoxModdedParams?(GiftBoxModdedBehavior? component)
			{
				return component?.Params;
			}
		}

		public const int GIFTBOX_ITEM_ID = 152767;

		public static Item? _GIFTBOX_ITEM = null;

		public static GameObject? _EGGSPLOSION = null;

		public static AudioClip? _EGGPOP = null;

		public static List<int> giftboxBehaviors = new List<int>(5) { 0, 0, 0, 0, 0 };

		public const int DO_NOTHING = 0;

		public const int SPAWN_STORE_ITEM = 1;

		public const int SPAWN_SCRAP = 2;

		public const int SPAWN_GIFTBOX = 3;

		public const int SPAWN_NOTHING = 4;

		public static GiftBoxModdedParams? parentGiftboxParams = null;

		public static Terminal? _terminal = null;

		public static Item[] _terminalBuyableItemsList = Array.Empty<Item>();

		public static CompatibleNoun[] _terminalItemNouns = Array.Empty<CompatibleNoun>();

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

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

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

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

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

		public static Item GIFTBOX_ITEM => _GIFTBOX_ITEM ?? (_GIFTBOX_ITEM = StartOfRound.Instance.allItemsList.itemsList.ToList().First((Item item) => item.itemId == 152767));

		public static GameObject EGGSPLOSION => _EGGSPLOSION ?? (_EGGSPLOSION = Resources.FindObjectsOfTypeAll<GameObject>().First((GameObject obj) => ((Object)obj).name == "EasterEggExplosionParticle"));

		public static AudioClip? EGGPOP => _EGGPOP ?? (_EGGPOP = Resources.FindObjectsOfTypeAll<AudioClip>().First((AudioClip clip) => ((Object)clip).name == "EasterEggPop"));

		public static List<Item> filteredStoreItems
		{
			get
			{
				if ((Object)(object)_terminal == (Object)null || !((Behaviour)_terminal).isActiveAndEnabled)
				{
					_terminal = Object.FindAnyObjectByType<Terminal>();
					_terminalBuyableItemsList = Array.Empty<Item>();
					_terminalItemNouns = Array.Empty<CompatibleNoun>();
				}
				if (_terminalBuyableItemsList != _terminal?.buyableItemsList || _terminalItemNouns != ((IEnumerable<TerminalKeyword>)_terminal?.terminalNodes?.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => ((Object)keyword).name == "Buy"))?.compatibleNouns)
				{
					_terminalBuyableItemsList = _terminal?.buyableItemsList ?? Array.Empty<Item>();
					_terminalItemNouns = ((IEnumerable<TerminalKeyword>)_terminal?.terminalNodes?.allKeywords).FirstOrDefault((Func<TerminalKeyword, bool>)((TerminalKeyword keyword) => ((Object)keyword).name == "Buy"))?.compatibleNouns ?? Array.Empty<CompatibleNoun>();
					_filteredStoreItems.Clear();
				}
				if (_filteredStoreItems.Count == 0)
				{
					_filteredStoreItems = _terminalBuyableItemsList.Where((Item item, int index) => item.creditsWorth >= Plugin.storeItemPriceMin.Value && item.creditsWorth <= Plugin.storeItemPriceMax.Value && (!Plugin.storeItemMustBeBuyable.Value || _terminalItemNouns.Any((CompatibleNoun noun) => noun.result.buyItemIndex == index))).ToList();
					Plugin.Log((LogLevel)32, "Filtered Store Items: " + string.Join(", ", _filteredStoreItems.Select((Item item) => item.itemName)));
				}
				return _filteredStoreItems;
			}
			set
			{
				if (value == null)
				{
					_filteredStoreItems.Clear();
				}
				else
				{
					_filteredStoreItems = value;
				}
			}
		}

		public 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;
				}
			}
		}

		public 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;
				}
			}
		}

		public 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;
				}
			}
		}

		[HarmonyPatch("GetItemDataToSave")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> GetItemDataToSave(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIndex((int?)val.Instructions.Count, 0, 0, 1, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionExtensions.LoadsConstant(code, 0L)), (int?)null, 0, true, "Not found!");
			val.OverwriteIL(CodeInstructionPolyfills.LoadConstant(int.MaxValue), (int?)null, true, true, "Out of bounds!");
			return val.Instructions;
		}

		public static bool OverrideLoadItemSaveData(GiftBoxItem giftbox, int saveData)
		{
			GiftBoxModdedParams giftBoxModdedParams = ((Component)giftbox).GetComponent<GiftBoxModdedBehavior>();
			if (giftBoxModdedParams == null)
			{
				return false;
			}
			giftbox.objectInPresentItem = ((saveData == int.MaxValue) ? null : StartOfRound.Instance.allItemsList.itemsList.ElementAtOrDefault(saveData));
			giftbox.objectInPresent = giftbox.objectInPresentItem?.spawnPrefab;
			giftbox.objectInPresentValue = giftBoxModdedParams.ScrapValue;
			giftbox.loadedItemFromSave = true;
			return true;
		}

		[HarmonyPatch("LoadItemSaveData")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> LoadItemSaveData(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GrabbableObject), "LoadItemSaveData", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] Call GrabbableObject.LoadItemSaveData() not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			Label label = val.DeclareLabel();
			val.InsertIL(new List<CodeInstruction>(4)
			{
				CodeInstructionPolyfills.LoadArgument(0, false),
				CodeInstructionPolyfills.LoadArgument(1, false),
				CodeInstructionPolyfills.Call(typeof(GiftBoxItemPatch), "OverrideLoadItemSaveData", (Type[])null, (Type[])null),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresField(code, typeof(GiftBoxItem), "loadedItemFromSave")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] Store field GrabbableObject.loadedItemFromSave not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), new Label[1] { label }), (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		public static bool InitGiftboxModdedBehavior(GiftBoxItem giftbox, ref Random giftboxBehaviorSeed, ref Random valueSeed)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			BlendedRandom val = new BlendedRandom(giftboxBehaviorSeed, (Random)null, (double)Plugin.positionRNGInfluence.Value / 100.0);
			int randomWeightedIndex = Probability.GetRandomWeightedIndex(giftboxBehaviors, (Random)(object)val);
			if (randomWeightedIndex == 0)
			{
				return false;
			}
			giftboxBehaviorSeed = (Random)(object)val;
			valueSeed = (Random)new BlendedRandom(valueSeed, (Random)null, (double)Plugin.positionRNGInfluence.Value / 100.0);
			GiftBoxModdedParams @params = ((Component)giftbox).gameObject.AddComponent<GiftBoxModdedBehavior>().Params;
			@params.CanEggsplode = giftboxBehaviorSeed.Next(0, 100) < Plugin.giftboxEggsplosionChance.Value;
			List<int> list = giftboxBehaviors.ToList();
			list[0] = 0;
			while (list.Sum() > 0)
			{
				Item val2;
				switch (randomWeightedIndex)
				{
				case 4:
					return true;
				case 1:
				{
					int randomWeightedIndex3 = Probability.GetRandomWeightedIndex(filteredStoreItemWeights, giftboxBehaviorSeed);
					Item val3 = filteredStoreItems.ElementAtOrDefault(randomWeightedIndex3);
					if (!((Object)(object)val3 == (Object)null))
					{
						giftbox.objectInPresentItem = val3;
						giftbox.objectInPresent = val3.spawnPrefab;
						return true;
					}
					break;
				}
				case 3:
					if (parentGiftboxParams != null)
					{
						@params.NestedScrapId = parentGiftboxParams.NestedScrapId;
					}
					else
					{
						int randomWeightedIndex2 = Probability.GetRandomWeightedIndex(filteredScrapItemWeights, giftboxBehaviorSeed);
						Item nestedScrapItem = filteredScrapItems.ElementAtOrDefault(randomWeightedIndex2)?.spawnableItem;
						if ((Object)(object)nestedScrapItem != (Object)null)
						{
							@params.NestedScrapId = StartOfRound.Instance.allItemsList.itemsList.FindIndex((Item item) => (Object)(object)item == (Object)(object)nestedScrapItem);
						}
					}
					goto case 2;
				case 2:
					if (randomWeightedIndex == 3)
					{
						val2 = ((GrabbableObject)giftbox).itemProperties;
					}
					else
					{
						GiftBoxModdedParams? giftBoxModdedParams = parentGiftboxParams;
						if (giftBoxModdedParams != null)
						{
							_ = giftBoxModdedParams.NestedScrapId;
							if (true)
							{
								val2 = StartOfRound.Instance.allItemsList.itemsList.ElementAtOrDefault(parentGiftboxParams.NestedScrapId);
								goto IL_01f5;
							}
						}
						int index = parentGiftboxParams?.NestedScrapId ?? Probability.GetRandomWeightedIndex(filteredScrapItemWeights, giftboxBehaviorSeed);
						val2 = filteredScrapItems.ElementAtOrDefault(index)?.spawnableItem;
					}
					goto IL_01f5;
				default:
					{
						throw new Exception("[Patches.GiftBoxItemPatches.GiftBoxItemPatch.InitGiftboxModdedBehavior] Giftbox Behavior selection failed due to invalid index! This should never happen!");
					}
					IL_01f5:
					if (!((Object)(object)val2 == (Object)null))
					{
						giftbox.objectInPresentItem = val2;
						giftbox.objectInPresent = val2.spawnPrefab;
						giftbox.objectInPresentValue = valueSeed.Next(giftbox.objectInPresentItem.minValue, giftbox.objectInPresentItem.maxValue);
						giftbox.objectInPresentValue = (int)((float)giftbox.objectInPresentValue * RoundManager.Instance.scrapValueMultiplier);
						if (valueSeed.Next(0, 100) < Plugin.scrapValueAdditionChance.Value)
						{
							giftbox.objectInPresentValue += valueSeed.Next(Plugin.scrapValueAdditionMin.Value, Plugin.scrapValueAdditionMax.Value + 1);
						}
						if (valueSeed.Next(0, 100) < Plugin.scrapValueMultiplierChance.Value)
						{
							giftbox.objectInPresentValue = valueSeed.Next((giftbox.objectInPresentValue * Plugin.scrapValueMultiplierMin.Value + 50) / 100, (giftbox.objectInPresentValue * Plugin.scrapValueMultiplierMax.Value + 50) / 100 + 1);
						}
						if (valueSeed.Next(0, 100) < Plugin.scrapValueIsGiftBoxChance.Value)
						{
							@params.ScrapHasGiftBoxValue = true;
						}
						return true;
					}
					break;
				}
				list[randomWeightedIndex] = 0;
				randomWeightedIndex = Probability.GetRandomWeightedIndex(list, giftboxBehaviorSeed);
			}
			return true;
		}

		[HarmonyPatch("Start")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> Start(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: 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;
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsProperty(code, typeof(NetworkBehaviour), "IsServer")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.Start] Property NetworkBehaviour.IsServer not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(new List<CodeInstruction>(6)
			{
				CodeInstructionPolyfills.LoadArgument(0, false),
				CodeInstructionPolyfills.LoadLocal(0, true),
				CodeInstructionPolyfills.LoadLocal(1, true),
				CodeInstructionPolyfills.Call(typeof(GiftBoxItemPatch), "InitGiftboxModdedBehavior", (Type[])null, (Type[])null),
				new CodeInstruction(OpCodes.Not, (object)null),
				new CodeInstruction(OpCodes.And, (object)null)
			}, (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		public static void NestedGiftboxFun(GiftBoxItem giftbox, GrabbableObject? spawnedObj)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)spawnedObj == (Object)null) && spawnedObj.itemProperties.itemId == 152767)
			{
				((Component)spawnedObj).transform.localScale = ((Component)giftbox).transform.localScale * 0.925f;
				((Object)spawnedObj).name = "Nested " + ((Object)giftbox).name;
				ScanNodeProperties componentInChildren = ((Component)giftbox).GetComponentInChildren<ScanNodeProperties>();
				ScanNodeProperties componentInChildren2 = ((Component)spawnedObj).GetComponentInChildren<ScanNodeProperties>();
				if ((Object)(object)componentInChildren != (Object)null && (Object)(object)componentInChildren2 != (Object)null)
				{
					componentInChildren2.headerText = "Nested " + componentInChildren.headerText;
				}
				else
				{
					Plugin.Log((LogLevel)4, "Failed to prepare nested giftbox scan node :(");
				}
			}
		}

		public static bool OverrideOpenGiftBox(GiftBoxItem giftbox)
		{
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			GiftBoxModdedParams giftBoxModdedParams = ((Component)giftbox).GetComponent<GiftBoxModdedBehavior>();
			if (giftBoxModdedParams == null)
			{
				return false;
			}
			if (giftBoxModdedParams.ScrapHasGiftBoxValue)
			{
				giftbox.objectInPresentValue = ((GrabbableObject)giftbox).scrapValue;
			}
			parentGiftboxParams = giftBoxModdedParams;
			GrabbableObject val = SpawnGiftItem(giftbox);
			parentGiftboxParams = null;
			NestedGiftboxFun(giftbox, val);
			if ((Object)(object)val == (Object)null && giftBoxModdedParams.CanEggsplode)
			{
				EggsplosionClientRpc(NetworkObjectReference.op_Implicit(((Component)giftbox).gameObject));
			}
			return true;
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		public static GrabbableObject? SpawnGiftItem(GiftBoxItem giftbox)
		{
			Transpiler(null, null, null);
			return null;
			static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Expected O, but got Unknown
				//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f2: Expected O, but got Unknown
				//IL_0202: Unknown result type (might be due to invalid IL or missing references)
				//IL_021a: Expected O, but got Unknown
				//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ae: Expected O, but got Unknown
				ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
				val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 0)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] Store Local 0 (gameObject) not found");
				val.GotoIL(ILPatterns.NextEmptyStack(0), (int?)null, 1, true, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] OpCodes.Ldnull not found");
				val.RemoveIL((int?)0, (int?)val.CurrentIndex, true, false, false, "Out of bounds!");
				Func<CodeInstruction, bool> obj = (CodeInstruction code) => CodeInstructionPolyfills.LoadsString(code, "Error: There is no object in gift box!");
				int? num = null;
				val.GotoIL(obj, num, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] \"no object\" error message not found");
				num = 1 + val.FindIL(ILPatterns.NextEmptyStack(0), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] Call Debug.LogError(object) not found");
				val.RemoveIL((int?)null, num, true, true, true, "Out of bounds!");
				val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GrabbableObject), "SetScrapValue", new Type[1] { typeof(int) }, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] Call GrabbableObject.SetScrapValue(int) not found");
				num = null;
				val.GotoIndex(num, 1, 0, 1, "Out of bounds!");
				num = val.FindIL(ILPatterns.NextEmptyStack(0), (int?)null, 0, true, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.SpawnGiftItem] 1st Load Local 4 (component) not found");
				List<CodeInstruction> collection = val.RemoveIL((int?)null, num, true, false, false, "Out of bounds!");
				Label label = val.DeclareLabel();
				List<CodeInstruction> list = new List<CodeInstruction>();
				list.Add(CodeInstructionPolyfills.LoadLocal(4, false));
				list.Add(CodeInstructionPolyfills.LoadField(typeof(GrabbableObject), "itemProperties", false));
				list.Add(CodeInstructionPolyfills.LoadField(typeof(Item), "isScrap", false));
				list.Add(new CodeInstruction(OpCodes.Brfalse, (object)label));
				list.AddRange(collection);
				list.Add(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), new Label[1] { label }));
				List<CodeInstruction> list2 = val.InsertIL(list, (int?)null, true, true, true, "Out of bounds!");
				val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GiftBoxItem), "OpenGiftBoxClientRpc", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc_DuplicateSoundsBugfix] Call GiftBoxItem.OpenGiftBoxClientRpc not found!");
				val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
				val.InsertIL(new List<CodeInstruction>(2)
				{
					CodeInstructionPolyfills.LoadLocal(4, false),
					new CodeInstruction(OpCodes.Ret, (object)null)
				}, (int?)null, true, false, false, "Out of bounds!");
				val.GotoIndex((int?)val.Instructions.Count, 0, 0, 1, "Out of bounds!");
				val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => code.opcode == OpCodes.Ret), (int?)null, 0, true, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc_DuplicateSoundsBugfix] Final return not found!");
				val.InsertIL(CodeInstructionPolyfills.LoadNull(), (int?)null, true, true, true, "Out of bounds!");
				return val.Instructions;
			}
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> OpenGiftBoxServerRpc(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 0)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] Store Local 0 (gameObject) not found");
			val.GotoIL(ILPatterns.NextEmptyStack(0), (int?)null, 1, true, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] Beginning of Store Local 0 (gameObject) not found");
			Label label = val.DeclareLabel();
			val.InsertIL(new List<CodeInstruction>(3)
			{
				CodeInstructionPolyfills.LoadArgument(0, false),
				CodeInstructionPolyfills.Call(typeof(GiftBoxItemPatch), "OverrideOpenGiftBox", (Type[])null, (Type[])null),
				new CodeInstruction(OpCodes.Brtrue, (object)label)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GiftBoxItem), "OpenGiftBoxNoPresentClientRpc", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc] Call GiftBoxItem.OpenGiftBoxNoPresentClientRpc not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), new Label[1] { label }), (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		[ClientRpc]
		public static void EggsplosionClientRpc(NetworkObjectReference giftboxNGO)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			GameObject obj = NetworkObjectReference.op_Implicit(giftboxNGO);
			GiftBoxItem val = ((obj != null) ? obj.GetComponent<GiftBoxItem>() : null);
			if (!((Object)(object)val == (Object)null))
			{
				if ((Object)(object)EGGSPLOSION != (Object)null)
				{
					Transform val2 = (((GrabbableObject)val).isInElevator ? StartOfRound.Instance.elevatorTransform : RoundManager.Instance.mapPropsContainer.transform);
					Object.Instantiate<GameObject>(EGGSPLOSION, ((Component)val).transform.position, Quaternion.identity, val2);
				}
				else
				{
					Plugin.Log((LogLevel)4, "EGGSPLOSION VFX not found!");
				}
				if ((Object)(object)EGGPOP != (Object)null)
				{
					val.presentAudio.PlayOneShot(EGGPOP, 0.67f);
					WalkieTalkie.TransmitOneShotAudio(val.presentAudio, EGGPOP, 0.67f);
					RoundManager.Instance.PlayAudibleNoise(((Component)val.presentAudio).transform.position, 15f, 0.67f, 1, ((GrabbableObject)val).isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0);
				}
				else
				{
					Plugin.Log((LogLevel)4, "EGGSPLOSION SFX not found!");
				}
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> waitForGiftPresentToSpawnOnClient(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresField(code, typeof(GrabbableObject), "reachedFloorTarget")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.waitForGiftPresentToSpawnOnClient] Store Field GrabbableObject.reachedFloorTarget not found");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(new List<CodeInstruction>(3)
			{
				CodeInstructionPolyfills.LoadLocal(1, false),
				CodeInstructionPolyfills.LoadLocal(2, false),
				CodeInstructionPolyfills.Call(typeof(GiftBoxItemPatch), "NestedGiftboxFun", (Type[])null, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		[HarmonyPatch("OpenGiftBoxServerRpc")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> OpenGiftBoxServerRpc_DuplicateSoundsBugfix(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			if (Plugin.giftboxDupeSoundsBugFixDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GiftBoxItem), "OpenGiftBoxClientRpc", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc_DuplicateSoundsBugfix] Call GiftBoxItem.OpenGiftBoxClientRpc not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			Label label = val.DeclareLabel();
			val.InsertIL(new CodeInstruction(OpCodes.Br, (object)label), (int?)null, true, false, false, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GiftBoxItem), "OpenGiftBoxNoPresentClientRpc", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.OpenGiftBoxServerRpc_DuplicateSoundsBugfix] Call GiftBoxItem.OpenGiftBoxNoPresentClientRpc not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), new Label[1] { label }), (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		public static IEnumerable<CodeInstruction> waitForGiftPresentToSpawnOnClient_ToolBugfix(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Expected O, but got Unknown
			if (Plugin.giftboxToolScrapValueBugfixDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresField(code, typeof(RoundManager), "totalScrapValueInLevel")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.waitForGiftPresentToSpawnOnClient_ToolBugfix] Store Field RoundManager.totalScrapValueInLevel not found");
			int? num = null;
			val.GotoIndex(num, 1, 0, 1, "Out of bounds!");
			Label label = val.DeclareLabel();
			List<CodeInstruction> list = new List<CodeInstruction>
			{
				CodeInstructionPolyfills.LoadLocal(2, false),
				CodeInstructionPolyfills.LoadField(typeof(GrabbableObject), "itemProperties", false),
				CodeInstructionPolyfills.LoadField(typeof(Item), "isScrap", false),
				new CodeInstruction(OpCodes.Brfalse, (object)label)
			};
			num = 1 + val.FindIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.Calls(code, typeof(GrabbableObject), "SetScrapValue", (Type[])null, (Type[])null)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.GiftBoxItemPatch.waitForGiftPresentToSpawnOnClient_ToolBugfix] Call GrabbableObject.SetScrapValue not found");
			list.AddRange(val.RemoveIL((int?)null, num, true, false, false, "Out of bounds!"));
			list.Add(CodeInstructionExtensions.WithLabels(new CodeInstruction(OpCodes.Nop, (object)null), new Label[1] { label }));
			val.InsertIL(list, (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal static class RoundManagerPatch
	{
		internal static void AnomalouslySpawnGiftBoxes(RoundManager roundmanager, List<Item> ScrapToSpawn, int spawnOneItemIndex, List<SpawnableItemWithRarity> spawnableScrap)
		{
			if (spawnOneItemIndex == -1 || spawnableScrap[spawnOneItemIndex].spawnableItem.itemId == 152767)
			{
				Random anomalyRandom = roundmanager.AnomalyRandom;
				if (anomalyRandom.Next(0, 100) < Plugin.giftboxSpawnChance.Value)
				{
					int count = anomalyRandom.Next(Plugin.giftboxSpawnMin.Value, Plugin.giftboxSpawnMax.Value + 1);
					ScrapToSpawn.AddRange(Enumerable.Repeat<Item>(GiftBoxItemPatch.GIFTBOX_ITEM, count).ToList());
				}
			}
		}

		internal static void AdjustGiftBoxSpawnWeight(RoundManager roundmanager, int[] weights, List<SpawnableItemWithRarity> spawnableScrap)
		{
			Random anomalyRandom = roundmanager.AnomalyRandom;
			if (weights.Length != spawnableScrap.Count)
			{
				Plugin.Log((LogLevel)2, "[LC_GiftBox_Config.Patches.RoundManagerPatch.AdjustGiftBoxSpawnWeight] weights length does not match spawnableScrap length! Wonkiness may occur!");
			}
			for (int i = 0; i < Math.Min(spawnableScrap.Count, weights.Length); i++)
			{
				if (spawnableScrap[i].spawnableItem.itemId == 152767)
				{
					if (anomalyRandom.Next(0, 100) < Plugin.giftboxRarityAdditionChance.Value)
					{
						weights[i] += anomalyRandom.Next(Plugin.giftboxRarityAdditionMin.Value, Plugin.giftboxRarityAdditionMax.Value + 1);
					}
					if (anomalyRandom.Next(0, 100) < Plugin.giftboxRarityMultiplierChance.Value)
					{
						weights[i] = anomalyRandom.Next((weights[i] * Plugin.giftboxRarityMultiplierMin.Value + 50) / 100, (weights[i] * Plugin.giftboxRarityMultiplierMax.Value + 50) / 100 + 1);
					}
				}
			}
		}

		internal static void AdjustGiftBoxValue(RoundManager roundmanager, GrabbableObject component, List<int> scrapValues)
		{
			if (component.itemProperties.itemId == 152767)
			{
				Random anomalyRandom = roundmanager.AnomalyRandom;
				if (anomalyRandom.Next(0, 100) < Plugin.giftboxValueAdditionChance.Value)
				{
					scrapValues[scrapValues.Count - 1] += anomalyRandom.Next(Plugin.giftboxValueAdditionMin.Value, Plugin.giftboxValueAdditionMax.Value + 1);
				}
				if (anomalyRandom.Next(0, 100) < Plugin.giftboxValueMultiplierChance.Value)
				{
					scrapValues[scrapValues.Count - 1] = anomalyRandom.Next((scrapValues[scrapValues.Count - 1] * Plugin.giftboxValueMultiplierMin.Value + 50) / 100, (scrapValues[scrapValues.Count - 1] * Plugin.giftboxValueMultiplierMax.Value + 50) / 100 + 1);
				}
			}
		}

		[HarmonyPatch("SpawnScrapInLevel")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> SpawnScrapInLevel(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper stepper = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			stepper.GotoIL((Func<CodeInstruction, int, bool>)((CodeInstruction code, int index) => CodeInstructionPolyfills.StoresLocal(code, 15) && index > 0 && CodeInstructionExtensions.LoadsConstant(stepper.Instructions[index - 1], 0L)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] For loop initialization (int j = 0;) not found");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => code.opcode.FlowControl == FlowControl.Branch), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] For loop branch to control statement (j < this.currentLevel.spawnableScrap.Count;) not found");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => code.labels.Contains((Label)stepper.CurrentOperand)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] For loop control statement (j < this.currentLevel.spawnableScrap.Count;) not found");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsProperty(code, typeof(List<SpawnableItemWithRarity>), "Count")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Load Property List.Count (this.currentLevel.spawnableScrap.Count) not found");
			List<CodeInstruction> list = (from code in stepper.GetIL((int?)stepper.FindIL(ILPatterns.NextEmptyStack(-1), (int?)null, 0, true, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Spawnable Scrap List (this.currentLevel.spawnableScrap) not found)"), (int?)null, "Out of bounds!")
				select code.Clone()).ToList();
			stepper.GotoIndex((int?)0, 0, 0, 1, "Out of bounds!");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresField(code, stepper.GetLocal(0, "No such local variable!").LocalType, "ScrapToSpawn")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Store Field compilerClosureObj.ScrapToSpawn not found");
			stepper.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			ILStepper obj = stepper;
			List<CodeInstruction> list2 = new List<CodeInstruction>();
			list2.Add(CodeInstructionPolyfills.LoadArgument(0, false));
			list2.Add(CodeInstructionPolyfills.LoadLocal(0, false));
			list2.Add(CodeInstructionPolyfills.LoadField(stepper.GetLocal(0, "No such local variable!").LocalType, "ScrapToSpawn", false));
			list2.Add(CodeInstructionPolyfills.LoadLocal(2, false));
			list2.AddRange(list);
			list2.Add(CodeInstructionPolyfills.Call(typeof(RoundManagerPatch), "AnomalouslySpawnGiftBoxes", (Type[])null, (Type[])null));
			obj.InsertIL(list2, (int?)null, true, true, true, "Out of bounds!");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 6)), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Store Local 6 (weights) not found");
			stepper.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			ILStepper obj2 = stepper;
			CodeInstruction item = CodeInstructionPolyfills.LoadArgument(0, false);
			CodeInstruction item2 = CodeInstructionPolyfills.LoadLocal(6, false);
			list2 = list;
			List<CodeInstruction> list3 = new List<CodeInstruction>(3 + list2.Count);
			list3.Add(item);
			list3.Add(item2);
			list3.AddRange(list2);
			list3.Add(CodeInstructionPolyfills.Call(typeof(RoundManagerPatch), "AdjustGiftBoxSpawnWeight", (Type[])null, (Type[])null));
			obj2.InsertIL(list3, (int?)null, true, true, true, "Out of bounds!");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresField(code, typeof(GrabbableObject), "scrapValue")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Store field GrabbableObject.scrapValue not found");
			stepper.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 4)), (int?)null, 0, true, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Store Local 4 (num4) not found");
			stepper.GotoIL(ILPatterns.NextEmptyStack(0), (int?)null, 1, true, "[Patches.GiftBoxItemPatches.RoundManagerPatch.SpawnScrapInLevel] Load Local 4 (num4) not found");
			stepper.InsertIL(new List<CodeInstruction>(4)
			{
				CodeInstructionPolyfills.LoadArgument(0, false),
				CodeInstructionPolyfills.LoadLocal(18, false),
				CodeInstructionPolyfills.LoadLocal(3, false),
				CodeInstructionPolyfills.Call(typeof(RoundManagerPatch), "AdjustGiftBoxValue", (Type[])null, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			return stepper.Instructions;
		}
	}
	[HarmonyPatch]
	internal static class SaveFilePatch
	{
		internal static readonly string GiftBoxModdedParamsSaveKey = Plugin.harmony.Id + ".giftboxModdedParamsDict";

		internal static Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams> GetGiftBoxModdedParamsDict()
		{
			Plugin.Log($"ES3 Key exists: {ES3.KeyExists(GiftBoxModdedParamsSaveKey, GameNetworkManager.Instance.currentSaveFileName)}");
			if (!ES3.KeyExists(GiftBoxModdedParamsSaveKey, GameNetworkManager.Instance.currentSaveFileName))
			{
				return new Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>();
			}
			CollectionExtensions.Do<KeyValuePair<int, GiftBoxItemPatch.GiftBoxModdedParams>>((IEnumerable<KeyValuePair<int, GiftBoxItemPatch.GiftBoxModdedParams>>)ES3.Load<Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>>(GiftBoxModdedParamsSaveKey, GameNetworkManager.Instance.currentSaveFileName), (Action<KeyValuePair<int, GiftBoxItemPatch.GiftBoxModdedParams>>)delegate(KeyValuePair<int, GiftBoxItemPatch.GiftBoxModdedParams> keypair)
			{
				Plugin.Log($"\t{keypair.Key} {keypair.Value}");
			});
			return ES3.Load<Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>>(GiftBoxModdedParamsSaveKey, GameNetworkManager.Instance.currentSaveFileName);
		}

		internal static void LoadGiftBoxModdedParams(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams> dict, int index, GrabbableObject grabbable)
		{
			Plugin.Log($"Dict Key [{index}] exists: {dict.ContainsKey(index)}");
			if (dict.ContainsKey(index))
			{
				Plugin.Log($"\t[{index}] {dict[index]}");
				((Component)grabbable).gameObject.AddComponent<GiftBoxItemPatch.GiftBoxModdedBehavior>().Params = dict[index];
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "LoadShipGrabbableItems")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> LoadShipGrabbableItems(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsString(code, "Ship grabbable items list loaded. Count: {0}")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.SaveFilePatch.LoadShipGrabbableItems] String \"Ship grabbable items list loaded. Count: {0}\" not found");
			val.GotoIL(ILPatterns.NextEmptyStack(0), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.SaveFilePatch.LoadShipGrabbableItems] Call Debug.Log not found");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			LocalVariableInfo localVariableInfo = val.DeclareLocal(typeof(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>), false);
			val.InsertIL(new List<CodeInstruction>(2)
			{
				CodeInstructionPolyfills.Call(typeof(SaveFilePatch), "GetGiftBoxModdedParamsDict", (Type[])null, (Type[])null),
				CodeInstructionPolyfills.StoreLocal(localVariableInfo)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 0)), (int?)null, 0, false, "Not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			val.InsertIL(new List<CodeInstruction>(4)
			{
				CodeInstructionPolyfills.LoadLocal(localVariableInfo, false),
				CodeInstructionPolyfills.LoadLocal(9, false),
				CodeInstructionPolyfills.LoadLocal(0, false),
				CodeInstructionPolyfills.Call(typeof(SaveFilePatch), "LoadGiftBoxModdedParams", (Type[])null, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}

		internal static void SetGiftBoxModdedParamsInDict(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams> dict, int index, GrabbableObject grabbable)
		{
			GiftBoxItemPatch.GiftBoxModdedParams giftBoxModdedParams = ((Component)grabbable).GetComponent<GiftBoxItemPatch.GiftBoxModdedBehavior>();
			if (giftBoxModdedParams != null)
			{
				dict.Add(index, giftBoxModdedParams);
			}
		}

		internal static void SaveGiftBoxModdedParamsDict(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams> dict)
		{
			ES3.Save<Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>>(GiftBoxModdedParamsSaveKey, dict, GameNetworkManager.Instance.currentSaveFileName);
		}

		[HarmonyPatch(typeof(GameNetworkManager), "SaveItemsInShip")]
		[HarmonyPriority(int.MinValue)]
		[HarmonyTranspiler]
		internal static IEnumerable<CodeInstruction> SaveItemsInShip(IEnumerable<CodeInstruction> methodIL, ILGenerator methodGenerator, MethodBase methodBase)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Expected O, but got Unknown
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Expected O, but got Unknown
			if (Plugin.giftboxMechanicsDisabled.Value)
			{
				return methodIL;
			}
			ILStepper val = new ILStepper(methodIL, methodGenerator, methodBase, 0);
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsString(code, "shipGrabbableItemIDs")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.SaveFilePatch.SaveItemsInShip] String \"shipGrabbableItemIDs\" not found");
			val.InsertIL(new List<CodeInstruction>(4)
			{
				CodeInstructionPolyfills.LoadString(GiftBoxModdedParamsSaveKey),
				CodeInstructionPolyfills.LoadArgument(0, false),
				CodeInstructionPolyfills.LoadField(typeof(GameNetworkManager), "currentSaveFileName", false),
				CodeInstructionPolyfills.Call(typeof(ES3), "DeleteKey", new Type[2]
				{
					typeof(string),
					typeof(string)
				}, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.StoresLocal(code, 4)), (int?)null, 0, false, "Not found!");
			val.GotoIndex((int?)null, 1, 0, 1, "Out of bounds!");
			LocalVariableInfo localVariableInfo = val.DeclareLocal(typeof(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>), false);
			val.InsertIL(new List<CodeInstruction>(2)
			{
				CodeInstructionPolyfills.CallConstructor(typeof(Dictionary<int, GiftBoxItemPatch.GiftBoxModdedParams>), (Type[])null, false),
				CodeInstructionPolyfills.StoreLocal(localVariableInfo)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsString(code, "Saved data for item type: {0} - {1}")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.SaveFilePatch.SaveItemsInShip] String \"Saved data for item type: {0} - {1}\" not found");
			val.InsertIL(new List<CodeInstruction>(9)
			{
				CodeInstructionPolyfills.LoadLocal(localVariableInfo, false),
				CodeInstructionPolyfills.LoadLocal(1, false),
				CodeInstructionPolyfills.LoadProperty(typeof(List<int>), "Count"),
				CodeInstructionPolyfills.LoadConstant(1),
				new CodeInstruction(OpCodes.Sub, (object)null),
				CodeInstructionPolyfills.LoadLocal(0, false),
				CodeInstructionPolyfills.LoadLocal(6, false),
				new CodeInstruction(OpCodes.Ldelem_Ref, (object)null),
				CodeInstructionPolyfills.Call(typeof(SaveFilePatch), "SetGiftBoxModdedParamsInDict", (Type[])null, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			val.GotoIL((Func<CodeInstruction, bool>)((CodeInstruction code) => CodeInstructionPolyfills.LoadsString(code, "shipGrabbableItemPos")), (int?)null, 0, false, "[Patches.GiftBoxItemPatches.SaveFilePatch.SaveItemsInShip] String \"shipGrabbableItemPos\" not found");
			val.InsertIL(new List<CodeInstruction>(2)
			{
				CodeInstructionPolyfills.LoadLocal(localVariableInfo, false),
				CodeInstructionPolyfills.Call(typeof(SaveFilePatch), "SaveGiftBoxModdedParamsDict", (Type[])null, (Type[])null)
			}, (int?)null, true, true, true, "Out of bounds!");
			return val.Instructions;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}