Decompiled source of MetalItemVariants v0.1.4

BepInEx/plugins/MetalItemVariants.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dawn;
using Dawn.Internal;
using GameNetcodeStuff;
using HatLib.Tools;
using MetalItemVariants.MonoBehaviours;
using MetalItemVariants.NetcodePatcher;
using MetalItemVariants.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json.Linq;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MetalItemVariants")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.4.0")]
[assembly: AssemblyInformationalVersion("0.1.4")]
[assembly: AssemblyProduct("MetalItemVariants")]
[assembly: AssemblyTitle("MetalItemVariants")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.4.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MetalItemVariants
{
	internal class ConfigManager
	{
		internal const string DawnModGUID = "MrHat.MetalItemVariants";

		private static readonly DuskConfigInjector Configs = new DuskConfigInjector("MrHat.MetalItemVariants");

		internal static ConfigEntry<bool> DebugLogging { get; private set; } = null;

		internal ConfigManager()
		{
			DebugLogging = Configs.Bind<bool>("_Mod Internal Settings", "Debug Logs", false, "Enables debug logging");
		}
	}
	[BepInPlugin("MrHat.MetalItemVariants.Internals", "MetalItemVariants", "0.1.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "MrHat.MetalItemVariants.Internals";

		private const string modName = "MetalItemVariants";

		private const string modVersion = "0.1.4";

		internal static ManualLogSource mls;

		internal static Plugin instance;

		internal static ConfigManager Configs;

		internal const string DawnNamespace = "metalitemvariants";

		private void Awake()
		{
			instance = this;
			mls = Logger.CreateLogSource("MrHat.MetalItemVariants.Internals");
			InitialiseNetworkSerialisation();
			Configs = new ConfigManager();
			MetalGiftBox.EnableSaving();
			ItemSheenSeed.EnableSaving();
			DawnFindResource.OnFreeze<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, (Action)Utility.AssignResources);
			Log.Info("MetalItemVariants loaded");
		}

		private static void InitialiseNetworkSerialisation()
		{
			MethodInfo methodInfo = typeof(Plugin).Assembly.GetType("__GEN.NetworkVariableSerializationHelper")?.GetMethod("InitializeSerialization", BindingFlags.Static | BindingFlags.NonPublic);
			if (methodInfo == null)
			{
				Log.Fatal("Netcode serialization method was not found");
			}
			else
			{
				methodInfo.Invoke(null, null);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MetalItemVariants";

		public const string PLUGIN_NAME = "MetalItemVariants";

		public const string PLUGIN_VERSION = "0.1.4";
	}
}
namespace MetalItemVariants.Utils
{
	internal static class Log
	{
		public static void Debug(string message)
		{
			if (ConfigManager.DebugLogging.Value)
			{
				Write((LogLevel)32, message);
			}
		}

		public static void Info(string message)
		{
			Write((LogLevel)16, message);
		}

		public static void Warn(string message)
		{
			Write((LogLevel)4, message);
		}

		public static void Error(string message)
		{
			Write((LogLevel)2, message);
		}

		public static void Fatal(string message)
		{
			Write((LogLevel)1, message);
		}

		private static void Write(LogLevel logLevel, string message)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.mls != null)
			{
				Plugin.mls.Log(logLevel, (object)message);
			}
		}
	}
	internal static class Utility
	{
		internal static AudioClip OpenGiftAudio;

		internal static void AssignResources()
		{
			NamespacedKey<DawnItemInfo> val = NamespacedKey<DawnItemInfo>.Vanilla("gift");
			NamespacedKey<DawnItemInfo> sourceKey = NamespacedKey<DawnItemInfo>.Vanilla("big_bolt");
			NamespacedKey<DawnItemInfo> val2 = NamespacedKey<DawnItemInfo>.Vanilla("red_soda");
			NamespacedKey<DawnItemInfo> val3 = NamespacedKey<DawnItemInfo>.Vanilla("rubber_ducky");
			NamespacedKey<DawnItemInfo> val4 = NamespacedKey<DawnItemInfo>.Vanilla("cash_register");
			NamespacedKey<DawnItemInfo> val5 = NamespacedKey<DawnItemInfo>.Vanilla("cookie_pan");
			NamespacedKey<DawnItemInfo> val6 = NamespacedKey<DawnItemInfo>.Vanilla("egg_beater");
			NamespacedKey<DawnItemInfo> val7 = NamespacedKey<DawnItemInfo>.Vanilla("garbage_lid");
			NamespacedKey<DawnItemInfo> val8 = NamespacedKey<DawnItemInfo>.Vanilla("gold_bar");
			NamespacedKey<DawnItemInfo> val9 = NamespacedKey<DawnItemInfo>.Vanilla("golden_cup");
			NamespacedKey<DawnItemInfo> sourceKey2 = NamespacedKey<DawnItemInfo>.Vanilla("jar_of_pickles");
			NamespacedKey<DawnItemInfo> val10 = NamespacedKey<DawnItemInfo>.Vanilla("large_axle");
			NamespacedKey<DawnItemInfo> val11 = NamespacedKey<DawnItemInfo>.Vanilla("magnifying_glass");
			NamespacedKey<DawnItemInfo> val12 = NamespacedKey<DawnItemInfo>.Vanilla("metal_sheet");
			NamespacedKey<DawnItemInfo> val13 = NamespacedKey<DawnItemInfo>.Vanilla("proflashlight");
			NamespacedKey<DawnItemInfo> dropSourceKey = NamespacedKey<DawnItemInfo>.Vanilla("stop_sign");
			NamespacedKey<DawnItemInfo> val14 = NamespacedKey<DawnItemInfo>.Vanilla("vtype_engine");
			NamespacedKey<DawnItemInfo>[] array = new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_metal_sheet"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_metal_sheet"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_metal_sheet")
			};
			NamespacedKey<DawnItemInfo>[] array2 = new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_vtype_engine"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_vtype_engine"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_vtype_engine")
			};
			AudioClip val15 = default(AudioClip);
			if (DawnFindResource.Resolve<DawnItemInfo, AudioClip>((Registry<DawnItemInfo>)(object)LethalContent.Items, val, (Func<DawnItemInfo, AudioClip>)((DawnItemInfo info) => info.Item.spawnPrefab.GetComponent<GiftBoxItem>().openGiftAudio), "gift open audio", ref val15))
			{
				OpenGiftAudio = val15;
				AudioTools.Load(val15);
				Log.Debug("Found gift open audio " + ((Object)OpenGiftAudio).name);
			}
			else
			{
				Log.Error("Gift open audio source missing");
			}
			GrabbableObject[] array3 = Resources.FindObjectsOfTypeAll<GrabbableObject>();
			AssignItemMeshes(array3, sourceKey, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_bolt"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_bolt"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_bolt")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val4, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cash_register"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cash_register"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_cash_register")
			}, new string[3] { "CashRegister", "CashRegisterAnim/Crank", "CashRegisterAnim/Drawer" });
			AssignItemMeshes(array3, val5, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cookie_mold"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cookie_mold"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_cookie_mold")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val6, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_egg_beater"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_egg_beater"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_egg_beater")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val9, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cup"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cup"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "true_gold_cup")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val7, new NamespacedKey<DawnItemInfo>[1] { NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_garbage_lid") }, new string[1] { string.Empty });
			AssignItemMeshes(array3, val, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_gift"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_gift"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_gift")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val8, new NamespacedKey<DawnItemInfo>[2]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_bar"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_bar")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, sourceKey2, new NamespacedKey<DawnItemInfo>[1] { NamespacedKey<DawnItemInfo>.From("metalitemvariants", "radiant_golden_jar_of_pickles") }, new string[2]
			{
				string.Empty,
				"Pickles.001"
			});
			AssignItemMeshes(array3, val10, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_large_axle"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_large_axle"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_large_axle")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val11, new NamespacedKey<DawnItemInfo>[3]
			{
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_magnifying_glass"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_magnifying_glass"),
				NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_magnifying_glass")
			}, new string[1] { string.Empty });
			AssignItemMeshes(array3, val12, array, new string[1] { string.Empty });
			AssignItemMeshes(array3, val13, new NamespacedKey<DawnItemInfo>[1] { NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_flashlight") }, new string[1] { "Mesh" });
			AssignItemMeshes(array3, val3, new NamespacedKey<DawnItemInfo>[1] { NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_ducky") }, new string[1] { string.Empty });
			AssignItemMeshes(array3, val14, array2, new string[1] { string.Empty });
			Mesh[] array4 = default(Mesh[]);
			if (DawnFindResource.Resolve<DawnItemInfo, Mesh[]>((Registry<DawnItemInfo>)(object)LethalContent.Items, val12, (Func<DawnItemInfo, Mesh[]>)((DawnItemInfo info) => info.Item.meshVariants), "metal sheet mesh variants", ref array4))
			{
				Log.Debug("Found metal sheet mesh variants " + string.Join(", ", array4.Select((Mesh mesh) => ((Object)mesh).name)));
				NamespacedKey<DawnItemInfo>[] array5 = array;
				DawnItemInfo val17 = default(DawnItemInfo);
				foreach (NamespacedKey<DawnItemInfo> val16 in array5)
				{
					if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, val16, ref val17))
					{
						Log.Error($"Metal sheet mesh variant target missing: {val16}");
						continue;
					}
					val17.Item.meshVariants = array4;
					Log.Debug($"Assigned metal sheet mesh variants to {val16}");
				}
			}
			else
			{
				Log.Error("Metal sheet mesh variant source missing");
			}
			DawnItemInfo val18 = default(DawnItemInfo);
			if (DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, val14, ref val18))
			{
				Material[] sharedMaterials = ((Renderer)val18.Item.spawnPrefab.GetComponent<MeshRenderer>()).sharedMaterials;
				NamespacedKey<DawnItemInfo>[] array6 = array2;
				DawnItemInfo val20 = default(DawnItemInfo);
				foreach (NamespacedKey<DawnItemInfo> val19 in array6)
				{
					if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, val19, ref val20))
					{
						continue;
					}
					GrabbableObject[] array7 = array3;
					foreach (GrabbableObject val21 in array7)
					{
						if (!((Object)(object)val21.itemProperties != (Object)(object)val20.Item))
						{
							MeshRenderer component = ((Component)val21).GetComponent<MeshRenderer>();
							Material[] sharedMaterials2 = ((Renderer)component).sharedMaterials;
							sharedMaterials2[1] = sharedMaterials[1];
							sharedMaterials2[5] = sharedMaterials[5];
							((Renderer)component).sharedMaterials = sharedMaterials2;
						}
					}
				}
			}
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_bolt"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_bolt"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_bolt"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cash_register"), val4, val4, null, val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cash_register"), val4, val4, null, val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_cash_register"), val4, val4, null, val4);
			AssignNoisemakerAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cash_register"), val4);
			AssignNoisemakerAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cash_register"), val4);
			AssignNoisemakerAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_cash_register"), val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cookie_mold"), val5, val5, null, val5);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cookie_mold"), val5, val5, null, val5);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_cookie_mold"), val5, val5, null, val5);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_egg_beater"), val6, val6, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_egg_beater"), val6, val6, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_egg_beater"), val6, val6, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_cup"), null, val9, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_cup"), null, val9, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "true_gold_cup"), null, val9, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_garbage_lid"), null, val7, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_gift"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_gift"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_gift"), val2, val2, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_ducky"), val3, val2, null, null, val3);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_bar"), val8, val8, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_bar"), val8, val8, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "radiant_golden_jar_of_pickles"), val2, dropSourceKey, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_large_axle"), val10, val10, null, val10);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_large_axle"), val10, val10, null, val10);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_large_axle"), val10, val10, null, val10);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_magnifying_glass"), val11, val11, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_magnifying_glass"), val11, val11, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_magnifying_glass"), val11, val11, null, null);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_metal_sheet"), null, val12, null, val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_metal_sheet"), null, val12, null, val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_metal_sheet"), null, val12, null, val4);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_flashlight"), val13, val2, val13, null);
			AssignFlashlightAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "golden_flashlight"), val13);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "bronze_vtype_engine"), val14, val14, null, val14);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "silver_vtype_engine"), val14, val14, null, val14);
			AssignItemAudio(NamespacedKey<DawnItemInfo>.From("metalitemvariants", "gold_vtype_engine"), val14, val14, null, val14);
		}

		private static void AssignItemMeshes(GrabbableObject[] resourceItems, NamespacedKey<DawnItemInfo> sourceKey, NamespacedKey<DawnItemInfo>[] targetKeys, string[] meshPaths)
		{
			DawnItemInfo val = default(DawnItemInfo);
			if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, sourceKey, ref val))
			{
				Log.Error($"Mesh source item missing: {sourceKey}");
				return;
			}
			Mesh[] array = (Mesh[])(object)new Mesh[meshPaths.Length];
			for (int i = 0; i < meshPaths.Length; i++)
			{
				Transform val2 = ((meshPaths[i].Length == 0) ? val.Item.spawnPrefab.transform : val.Item.spawnPrefab.transform.Find(meshPaths[i]));
				array[i] = ((Component)val2).GetComponent<MeshFilter>().sharedMesh;
			}
			Log.Debug(string.Format("Found meshes {0} for {1}", string.Join(", ", array.Select((Mesh mesh) => ((Object)mesh).name)), sourceKey));
			DawnItemInfo val4 = default(DawnItemInfo);
			foreach (NamespacedKey<DawnItemInfo> val3 in targetKeys)
			{
				if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, val3, ref val4))
				{
					Log.Error($"Mesh target item missing: {val3}");
					continue;
				}
				bool flag = false;
				foreach (GrabbableObject val5 in resourceItems)
				{
					if (!((Object)(object)val5.itemProperties != (Object)(object)val4.Item))
					{
						for (int num3 = 0; num3 < meshPaths.Length; num3++)
						{
							Transform val6 = ((meshPaths[num3].Length == 0) ? ((Component)val5).transform : ((Component)val5).transform.Find(meshPaths[num3]));
							((Component)val6).GetComponent<MeshFilter>().sharedMesh = array[num3];
						}
						flag = true;
					}
				}
				if (flag)
				{
					Log.Debug($"Assigned meshes from {sourceKey} to {val3}");
				}
				else
				{
					Log.Error($"Mesh target prefab missing: {val3}");
				}
			}
		}

		private static void AssignItemAudio(NamespacedKey<DawnItemInfo> targetKey, NamespacedKey<DawnItemInfo>? grabSourceKey, NamespacedKey<DawnItemInfo>? dropSourceKey, NamespacedKey<DawnItemInfo>? pocketSourceKey, NamespacedKey<DawnItemInfo>? clinkSourceKey, NamespacedKey<DawnItemInfo>? throwSourceKey = null)
		{
			DawnItemInfo val = default(DawnItemInfo);
			if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, targetKey, ref val))
			{
				Log.Error($"Audio target item missing: {targetKey}");
				return;
			}
			AudioClip grabSFX = default(AudioClip);
			if (grabSourceKey != null && DawnFindResource.Resolve<DawnItemInfo, AudioClip>((Registry<DawnItemInfo>)(object)LethalContent.Items, grabSourceKey, (Func<DawnItemInfo, AudioClip>)((DawnItemInfo info) => info.Item.grabSFX), $"grab SFX for {targetKey}", ref grabSFX))
			{
				val.Item.grabSFX = grabSFX;
				Log.Debug($"Assigned grab SFX {((Object)val.Item.grabSFX).name} to {targetKey}");
			}
			AudioClip dropSFX = default(AudioClip);
			if (dropSourceKey != null && DawnFindResource.Resolve<DawnItemInfo, AudioClip>((Registry<DawnItemInfo>)(object)LethalContent.Items, dropSourceKey, (Func<DawnItemInfo, AudioClip>)((DawnItemInfo info) => info.Item.dropSFX), $"drop SFX for {targetKey}", ref dropSFX))
			{
				val.Item.dropSFX = dropSFX;
				Log.Debug($"Assigned drop SFX {((Object)val.Item.dropSFX).name} to {targetKey}");
			}
			AudioClip pocketSFX = default(AudioClip);
			if (pocketSourceKey != null && DawnFindResource.Resolve<DawnItemInfo, AudioClip>((Registry<DawnItemInfo>)(object)LethalContent.Items, pocketSourceKey, (Func<DawnItemInfo, AudioClip>)((DawnItemInfo info) => info.Item.pocketSFX), $"pocket SFX for {targetKey}", ref pocketSFX))
			{
				val.Item.pocketSFX = pocketSFX;
				Log.Debug($"Assigned pocket SFX {((Object)val.Item.pocketSFX).name} to {targetKey}");
			}
			AudioClip throwSFX = default(AudioClip);
			if (throwSourceKey != null && DawnFindResource.Resolve<DawnItemInfo, AudioClip>((Registry<DawnItemInfo>)(object)LethalContent.Items, throwSourceKey, (Func<DawnItemInfo, AudioClip>)((DawnItemInfo info) => info.Item.grabSFX), $"throw SFX for {targetKey}", ref throwSFX))
			{
				val.Item.throwSFX = throwSFX;
				Log.Debug($"Assigned throw SFX {((Object)val.Item.throwSFX).name} to {targetKey}");
			}
			AudioClip[] array = default(AudioClip[]);
			if (clinkSourceKey != null && DawnFindResource.Resolve<DawnItemInfo, AudioClip[]>((Registry<DawnItemInfo>)(object)LethalContent.Items, clinkSourceKey, (Func<DawnItemInfo, AudioClip[]>)delegate(DawnItemInfo info)
			{
				AudioClip[] clinkAudios = info.Item.clinkAudios;
				return (clinkAudios == null || clinkAudios.Length == 0) ? null : info.Item.clinkAudios;
			}, $"clink audios for {targetKey}", ref array))
			{
				val.Item.clinkAudios = array;
				Log.Debug(string.Format("Assigned clink audios {0} to {1}", string.Join(", ", array.Select((AudioClip clip) => ((Object)clip).name)), targetKey));
			}
		}

		private static void AssignNoisemakerAudio(NamespacedKey<DawnItemInfo> targetKey, NamespacedKey<DawnItemInfo> sourceKey)
		{
			NoisemakerProp val = default(NoisemakerProp);
			AudioClip[] noiseSFX = default(AudioClip[]);
			if (!DawnFindResource.Resolve<DawnItemInfo, NoisemakerProp>((Registry<DawnItemInfo>)(object)LethalContent.Items, targetKey, (Func<DawnItemInfo, NoisemakerProp>)((DawnItemInfo info) => info.Item.spawnPrefab.GetComponent<NoisemakerProp>()), $"NoisemakerProp target for {targetKey}", ref val))
			{
				Log.Error($"NoisemakerProp audio target item missing: {targetKey}");
			}
			else if (DawnFindResource.Resolve<DawnItemInfo, AudioClip[]>((Registry<DawnItemInfo>)(object)LethalContent.Items, sourceKey, (Func<DawnItemInfo, AudioClip[]>)((DawnItemInfo info) => info.Item.spawnPrefab.GetComponent<NoisemakerProp>().noiseSFX), $"NoisemakerProp source noise SFX for {targetKey}", ref noiseSFX))
			{
				val.noiseSFX = noiseSFX;
				Log.Debug(string.Format("Assigned NoisemakerProp noise SFX {0} to {1}", string.Join(", ", val.noiseSFX.Select((AudioClip clip) => ((Object)clip).name)), targetKey));
			}
		}

		private static void AssignFlashlightAudio(NamespacedKey<DawnItemInfo> targetKey, NamespacedKey<DawnItemInfo> sourceKey)
		{
			FlashlightItem val = default(FlashlightItem);
			if (!DawnFindResource.Resolve<DawnItemInfo, FlashlightItem>((Registry<DawnItemInfo>)(object)LethalContent.Items, targetKey, (Func<DawnItemInfo, FlashlightItem>)((DawnItemInfo info) => info.Item.spawnPrefab.GetComponent<FlashlightItem>()), $"FlashlightItem target for {targetKey}", ref val))
			{
				Log.Error($"FlashlightItem audio target item missing: {targetKey}");
			}
			else
			{
				FlashlightItem val2 = default(FlashlightItem);
				if (!DawnFindResource.Resolve<DawnItemInfo, FlashlightItem>((Registry<DawnItemInfo>)(object)LethalContent.Items, sourceKey, (Func<DawnItemInfo, FlashlightItem>)((DawnItemInfo info) => info.Item.spawnPrefab.GetComponent<FlashlightItem>()), $"FlashlightItem source for {targetKey}", ref val2))
				{
					return;
				}
				if (val2.flashlightClips == null)
				{
					Log.Error($"FlashlightItem clips source field missing for {targetKey}");
					return;
				}
				val.flashlightClips = val2.flashlightClips;
				val.outOfBatteriesClip = val2.outOfBatteriesClip;
				val.flashlightFlicker = val2.flashlightFlicker;
				Log.Debug(string.Format("Assigned flashlight clips {0} to {1}", string.Join(", ", val.flashlightClips.Select((AudioClip clip) => ((Object)clip).name)), targetKey));
				Log.Debug($"Assigned flashlight out of batteries clip {((Object)val.outOfBatteriesClip).name} to {targetKey}");
				Log.Debug($"Assigned flashlight flicker clip {((Object)val.flashlightFlicker).name} to {targetKey}");
			}
		}
	}
}
namespace MetalItemVariants.MonoBehaviours
{
	public class GoldenDucky : GrabbableObject
	{
		private Quaternion throwStartRotation;

		private Quaternion throwRestingRotation;

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (buttonDown && ((NetworkBehaviour)this).IsOwner && !((Object)(object)base.playerHeldBy == (Object)null))
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(((Component)base.playerHeldBy.gameplayCamera).transform.position, ((Component)base.playerHeldBy.gameplayCamera).transform.forward);
				RaycastHit val3 = default(RaycastHit);
				Vector3 val2 = (Physics.Raycast(val, ref val3, 6f, 268437761, (QueryTriggerInteraction)1) ? ((Ray)(ref val)).GetPoint(((RaycastHit)(ref val3)).distance - 0.05f) : ((Ray)(ref val)).GetPoint(4f));
				((Ray)(ref val))..ctor(val2, Vector3.down);
				val2 = (Physics.Raycast(val, ref val3, 30f, 268437761, (QueryTriggerInteraction)1) ? (((RaycastHit)(ref val3)).point + Vector3.up * 0.05f) : ((Ray)(ref val)).GetPoint(30f));
				base.playerHeldBy.DiscardHeldObject(true, (NetworkObject)null, val2, true);
			}
		}

		public override void FallWithCurve()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = base.targetFloorPosition - base.startFallingPosition;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude < 4f)
			{
				((GrabbableObject)this).FallWithCurve();
				return;
			}
			float num = Vector3.Distance(base.startFallingPosition, base.targetFloorPosition);
			float num2 = Mathf.Clamp01(base.fallTime);
			if (base.fallTime == 0f)
			{
				throwStartRotation = ((Component)this).transform.rotation;
				throwRestingRotation = Quaternion.Euler(base.itemProperties.restingRotation.x, (base.floorYRot == -1) ? ((Component)this).transform.eulerAngles.y : ((float)(base.floorYRot + base.itemProperties.floorYOffset) + 90f), base.itemProperties.restingRotation.z);
			}
			Vector3 localPosition = Vector3.Lerp(base.startFallingPosition, base.targetFloorPosition, num2);
			localPosition.y += Mathf.Sin(num2 * MathF.PI) * Mathf.Min(((Vector3)(ref val)).magnitude * 0.18f, 0.65f);
			((Component)this).transform.localPosition = localPosition;
			Quaternion val2 = throwStartRotation * Quaternion.Euler(num2 * 270f, 0f, 0f);
			float num3 = Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.72f, 1f, num2));
			((Component)this).transform.rotation = Quaternion.Slerp(val2, throwRestingRotation, num3);
			base.fallTime += Mathf.Abs(Time.deltaTime * 6f / Mathf.Max(num, 1f));
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			((GrabbableObject)this).__initializeRpcs();
		}

		protected internal override string __getTypeName()
		{
			return "GoldenDucky";
		}
	}
	public class ItemSheenSeed : NetworkBehaviour
	{
		private static readonly int SheenSeedProperty = Shader.PropertyToID("_SheenSeed");

		private static readonly string SheenSeedSaveKey = ((object)NamespacedKey.From("metalitemvariants", "sheen_seed")).ToString();

		private readonly NetworkVariable<float> sheenSeed = new NetworkVariable<float>(0f, (NetworkVariableReadPermission)0, (NetworkVariableWritePermission)0);

		private float? loadedSeed;

		internal static void EnableSaving()
		{
			DawnItemSaveEvents.OnCollectExtraSaveData += SaveSeed;
			DawnItemSaveEvents.OnLoadExtraSaveData += LoadSeed;
		}

		private static void SaveSeed(GrabbableObject item, JObject extraData)
		{
			ItemSheenSeed itemSheenSeed = default(ItemSheenSeed);
			if (((Component)item).TryGetComponent<ItemSheenSeed>(ref itemSheenSeed))
			{
				extraData[SheenSeedSaveKey] = JToken.op_Implicit(itemSheenSeed.sheenSeed.Value);
			}
		}

		private static void LoadSeed(GrabbableObject item, JObject extraData)
		{
			ItemSheenSeed itemSheenSeed = default(ItemSheenSeed);
			if (!((Component)item).TryGetComponent<ItemSheenSeed>(ref itemSheenSeed))
			{
				return;
			}
			JToken obj = extraData[SheenSeedSaveKey];
			float? num = ((obj != null) ? new float?(obj.ToObject<float>()) : ((float?)null));
			if (num.HasValue)
			{
				float valueOrDefault = num.GetValueOrDefault();
				itemSheenSeed.loadedSeed = valueOrDefault;
				if (((NetworkBehaviour)itemSheenSeed).IsSpawned && ((NetworkBehaviour)itemSheenSeed).IsServer)
				{
					itemSheenSeed.sheenSeed.Value = valueOrDefault;
				}
			}
		}

		public override void OnNetworkSpawn()
		{
			NetworkVariable<float> obj = sheenSeed;
			obj.OnValueChanged = (OnValueChangedDelegate<float>)(object)Delegate.Combine((Delegate?)(object)obj.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<float>(UpdateSheenMaterials));
			if (((NetworkBehaviour)this).IsServer)
			{
				sheenSeed.Value = loadedSeed ?? Random.Range(0f, 1000f);
			}
			UpdateSheenMaterials(0f, sheenSeed.Value);
		}

		public override void OnNetworkDespawn()
		{
			NetworkVariable<float> obj = sheenSeed;
			obj.OnValueChanged = (OnValueChangedDelegate<float>)(object)Delegate.Remove((Delegate?)(object)obj.OnValueChanged, (Delegate?)(object)new OnValueChangedDelegate<float>(UpdateSheenMaterials));
		}

		private void UpdateSheenMaterials(float _, float currentSeed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			MaterialPropertyBlock val = new MaterialPropertyBlock();
			Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (sharedMaterials[j].HasProperty(SheenSeedProperty))
					{
						val.Clear();
						val2.GetPropertyBlock(val, j);
						val.SetFloat(SheenSeedProperty, currentSeed);
						val2.SetPropertyBlock(val, j);
					}
				}
			}
		}

		protected override void __initializeVariables()
		{
			if (sheenSeed == null)
			{
				throw new Exception("ItemSheenSeed.sheenSeed cannot be null. All NetworkVariableBase instances must be initialized.");
			}
			((NetworkVariableBase)sheenSeed).Initialize((NetworkBehaviour)(object)this);
			((NetworkBehaviour)this).__nameNetworkVariable((NetworkVariableBase)(object)sheenSeed, "sheenSeed");
			base.NetworkVariableFields.Add((NetworkVariableBase)(object)sheenSeed);
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			((NetworkBehaviour)this).__initializeRpcs();
		}

		protected internal override string __getTypeName()
		{
			return "ItemSheenSeed";
		}
	}
	public class MetalGiftBox : GrabbableObject
	{
		private static readonly string GiftSelectionSaveKey = ((object)NamespacedKey.From("metalitemvariants", "gift_selection")).ToString();

		public ParticleSystem PoofParticle;

		public AudioSource presentAudio;

		public AudioClip openGiftAudio;

		[SerializeField]
		private string[] possibleItemKeys;

		[SerializeField]
		private string minimumValueBonusConfigKey;

		[SerializeField]
		private string maximumValueBonusConfigKey;

		private PlayerControllerB? previousHolder;

		private bool hasOpened;

		private int itemIndex = -1;

		private int selectedScrapValue;

		private int minimumValueBonus;

		private int maximumValueBonus;

		private bool hasNoItem;

		internal static void EnableSaving()
		{
			DawnItemSaveEvents.OnCollectExtraSaveData += SaveItemSelection;
			DawnItemSaveEvents.OnLoadExtraSaveData += LoadItemSelection;
		}

		private static void SaveItemSelection(GrabbableObject item, JObject extraData)
		{
			if (item is MetalGiftBox metalGiftBox && metalGiftBox.GetItem(out Item _))
			{
				extraData[GiftSelectionSaveKey] = JToken.op_Implicit(metalGiftBox.possibleItemKeys[metalGiftBox.itemIndex]);
			}
		}

		private static void LoadItemSelection(GrabbableObject item, JObject extraData)
		{
			if (item is MetalGiftBox metalGiftBox)
			{
				JToken obj = extraData[GiftSelectionSaveKey];
				string text = ((obj != null) ? obj.ToObject<string>() : null);
				if (text != null)
				{
					metalGiftBox.LoadSelection(text);
				}
			}
		}

		public override void Start()
		{
			((GrabbableObject)this).Start();
			minimumValueBonus = DuskConfigInjector.Read<int>("MrHat.MetalItemVariants", minimumValueBonusConfigKey);
			maximumValueBonus = DuskConfigInjector.Read<int>("MrHat.MetalItemVariants", maximumValueBonusConfigKey);
			openGiftAudio = Utility.OpenGiftAudio;
			if (((NetworkBehaviour)this).IsServer)
			{
				CoroutineTools.NextFrame((MonoBehaviour)(object)this, (Action)InitialiseSelection);
			}
		}

		public override void EquipItem()
		{
			((GrabbableObject)this).EquipItem();
			previousHolder = base.playerHeldBy;
		}

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!hasNoItem && buttonDown && !((Object)(object)base.playerHeldBy == (Object)null) && !hasOpened)
			{
				hasOpened = true;
				base.playerHeldBy.activatingItem = true;
				OpenBoxRpc();
			}
		}

		public override void PocketItem()
		{
			((GrabbableObject)this).PocketItem();
			if ((Object)(object)base.playerHeldBy != (Object)null)
			{
				base.playerHeldBy.activatingItem = false;
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		private void OpenBoxRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				RpcAttributeParams val = new RpcAttributeParams
				{
					RequireOwnership = false
				};
				RpcParams val3 = default(RpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendRpc(3293125562u, val3, val, (SendTo)2, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendRpc(ref val2, 3293125562u, val3, val, (SendTo)2, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			if (!GetItem(out Item item) || (Object)(object)item.spawnPrefab == (Object)null)
			{
				Plugin.mls.LogError((object)"MetalGiftBox could not find the selected item");
				EndOpenRpc();
				return;
			}
			Vector3 val4 = ((Component)this).transform.position + Vector3.up * 0.25f;
			Transform val5 = ((((Object)(object)previousHolder != (Object)null && previousHolder.isInElevator) || StartOfRound.Instance.inShipPhase) ? StartOfRound.Instance.elevatorTransform : null);
			GrabbableObject val6 = default(GrabbableObject);
			NetworkObject val7 = default(NetworkObject);
			if (!PrefabSpawns.Grabbable(item, val4, Quaternion.identity, ref val6, ref val7, val5))
			{
				EndOpenRpc();
				return;
			}
			val6.SetScrapValue(selectedScrapValue);
			GrabbablePlacement.DropFrom(val6, val4, val6.GetItemFloorPosition(((Component)this).transform.position));
			((MonoBehaviour)this).StartCoroutine(ResetSpawnedItemFallState(val6));
			ApplyShipDropState(val6);
			val7.Spawn(false);
			SyncSpawnedItemRpc(NetworkObjectReference.op_Implicit(val7), selectedScrapValue, val4);
			EndOpenRpc();
		}

		private void InitialiseSelection()
		{
			if (possibleItemKeys != null && possibleItemKeys.Length != 0 && itemIndex < 0 && GetRandomItem(out Item item))
			{
				Log.Debug("MetalGiftBox rolled random item: " + item.itemName + " (" + possibleItemKeys[itemIndex] + ")");
				selectedScrapValue = RollScrapValue(item);
			}
		}

		private void LoadSelection(string selectedItemKey)
		{
			itemIndex = Array.IndexOf(possibleItemKeys, selectedItemKey);
			if (GetItem(out Item item))
			{
				hasNoItem = false;
				Log.Debug("MetalGiftBox loaded item: " + item.itemName + " (" + selectedItemKey + ")");
				selectedScrapValue = RollScrapValue(item);
			}
			else
			{
				Log.Warn("MetalGiftBox could not find saved item key '" + selectedItemKey + "'. Is item disabled in config? Rerolling...");
				itemIndex = -1;
				hasNoItem = false;
				InitialiseSelection();
			}
		}

		private bool GetRandomItem([NotNullWhen(true)] out Item? item)
		{
			item = null;
			if (possibleItemKeys == null || possibleItemKeys.Length == 0)
			{
				return false;
			}
			int num = possibleItemKeys.Length;
			bool[] array = new bool[possibleItemKeys.Length];
			while (num > 0)
			{
				int num2 = Random.Range(0, possibleItemKeys.Length);
				while (array[num2])
				{
					num2 = Random.Range(0, possibleItemKeys.Length);
				}
				array[num2] = true;
				num--;
				itemIndex = num2;
				if (GetItem(out item))
				{
					hasNoItem = false;
					return true;
				}
				Log.Warn("MetalGiftBox could not find item key '" + possibleItemKeys[num2] + "', is item disabled in config? Rerolling...");
			}
			Log.Error("MetalGiftBox could not find any item keys, are all metal variant items disabled in config?");
			itemIndex = -1;
			hasNoItem = true;
			return false;
		}

		private IEnumerator ResetSpawnedItemFallState(GrabbableObject spawnedItem)
		{
			yield return (object)new WaitForEndOfFrame();
			spawnedItem.reachedFloorTarget = false;
			spawnedItem.hasHitGround = false;
			spawnedItem.fallTime = 0f;
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		private void EndOpenRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				RpcAttributeParams val = default(RpcAttributeParams);
				RpcParams val3 = default(RpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendRpc(3275437139u, val3, val, (SendTo)7, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendRpc(ref val2, 3275437139u, val3, val, (SendTo)7, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			PoofParticle.Play();
			if ((Object)(object)presentAudio != (Object)null && (Object)(object)openGiftAudio != (Object)null && AudioTools.PlayOneShot(presentAudio, openGiftAudio))
			{
				WalkieTalkie.TransmitOneShotAudio(presentAudio, openGiftAudio, 1f);
				RoundManager.Instance.PlayAudibleNoise(((Component)presentAudio).transform.position, 8f, 0.5f, 0, base.isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
			if ((Object)(object)base.playerHeldBy != (Object)null)
			{
				base.playerHeldBy.activatingItem = false;
				((GrabbableObject)this).DestroyObjectInHand(base.playerHeldBy);
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				float num = (Object.op_Implicit((Object)(object)openGiftAudio) ? openGiftAudio.length : 0f);
				if (num <= 0f)
				{
					DespawnGift();
				}
				else
				{
					CoroutineTools.Delay((MonoBehaviour)(object)this, num, (Action)DespawnGift);
				}
			}
		}

		private void DespawnGift()
		{
			if (((NetworkBehaviour)this).NetworkObject.IsSpawned)
			{
				((NetworkBehaviour)this).NetworkObject.Despawn(true);
			}
		}

		[Rpc(/*Could not decode attribute arguments.*/)]
		private void SyncSpawnedItemRpc(NetworkObjectReference netObjectRef, int scrapValue, Vector3 spawnPosition)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				RpcAttributeParams val = default(RpcAttributeParams);
				RpcParams val3 = default(RpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendRpc(3654392344u, val3, val, (SendTo)7, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref netObjectRef, default(ForNetworkSerializable));
				BytePacker.WriteValueBitPacked(val2, scrapValue);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref spawnPosition);
				((NetworkBehaviour)this).__endSendRpc(ref val2, 3654392344u, val3, val, (SendTo)7, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1)
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			int scrapValue2 = scrapValue;
			Vector3 spawnPosition2 = spawnPosition;
			if (!((NetworkBehaviour)this).IsServer)
			{
				NetworkRefs.WhenReady<GrabbableObject>((MonoBehaviour)(object)this, netObjectRef, (Action<GrabbableObject>)delegate(GrabbableObject spawnedItem)
				{
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					ApplySpawnedItemOnClient(spawnedItem, scrapValue2, spawnPosition2);
				}, 8f, 1);
			}
		}

		private void ApplySpawnedItemOnClient(GrabbableObject spawnedItem, int scrapValue, Vector3 spawnPosition)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			instance.totalScrapValueInLevel -= (float)scrapValue;
			RoundManager instance2 = RoundManager.Instance;
			instance2.totalScrapValueInLevel += (float)spawnedItem.scrapValue;
			spawnedItem.SetScrapValue(scrapValue);
			((Component)spawnedItem).transform.SetParent((((Object)(object)previousHolder != (Object)null && previousHolder.isInElevator) || StartOfRound.Instance.inShipPhase) ? StartOfRound.Instance.elevatorTransform : null, true);
			GrabbablePlacement.DropFrom(spawnedItem, spawnPosition, spawnedItem.GetItemFloorPosition(spawnPosition));
			ApplyShipDropState(spawnedItem);
		}

		private void ApplyShipDropState(GrabbableObject spawnedItem)
		{
			if ((Object)(object)previousHolder != (Object)null && previousHolder.isInHangarShipRoom)
			{
				previousHolder.SetItemInElevator(true, true, spawnedItem);
			}
		}

		private bool GetItem([NotNullWhen(true)] out Item? item)
		{
			item = null;
			if (possibleItemKeys == null || itemIndex < 0 || itemIndex >= possibleItemKeys.Length || string.IsNullOrWhiteSpace(possibleItemKeys[itemIndex]))
			{
				return false;
			}
			NamespacedKey<DawnItemInfo> val = NamespacedKey<DawnItemInfo>.From("metalitemvariants", possibleItemKeys[itemIndex]);
			DawnItemInfo val2 = default(DawnItemInfo);
			if (!DawnFindResource.Resolve<DawnItemInfo>((Registry<DawnItemInfo>)(object)LethalContent.Items, val, ref val2))
			{
				return false;
			}
			item = val2.Item;
			return (Object)(object)item != (Object)null;
		}

		private int RollScrapValue(Item item)
		{
			int num = item.minValue + minimumValueBonus;
			int num2 = item.maxValue + maximumValueBonus;
			if (num2 <= num)
			{
				num2 = num + 1;
			}
			return (int)((float)Random.Range(num, num2) * RoundManager.Instance.scrapValueMultiplier);
		}

		protected override void __initializeVariables()
		{
			((GrabbableObject)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(3293125562u, new RpcReceiveHandler(__rpc_handler_3293125562), "OpenBoxRpc");
			((NetworkBehaviour)this).__registerRpc(3275437139u, new RpcReceiveHandler(__rpc_handler_3275437139), "EndOpenRpc");
			((NetworkBehaviour)this).__registerRpc(3654392344u, new RpcReceiveHandler(__rpc_handler_3654392344), "SyncSpawnedItemRpc");
			((GrabbableObject)this).__initializeRpcs();
		}

		private static void __rpc_handler_3293125562(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MetalGiftBox)(object)target).OpenBoxRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3275437139(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MetalGiftBox)(object)target).EndOpenRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3654392344(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				NetworkObjectReference netObjectRef = default(NetworkObjectReference);
				((FastBufferReader)(ref reader)).ReadValueSafe<NetworkObjectReference>(ref netObjectRef, default(ForNetworkSerializable));
				int scrapValue = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref scrapValue);
				Vector3 spawnPosition = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref spawnPosition);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((MetalGiftBox)(object)target).SyncSpawnedItemRpc(netObjectRef, scrapValue, spawnPosition);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "MetalGiftBox";
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
			NetworkVariableSerializationTypes.InitializeSerializer_UnmanagedByMemcpy<float>();
			NetworkVariableSerializationTypes.InitializeEqualityChecker_UnmanagedIEquatable<float>();
		}
	}
}
namespace MetalItemVariants.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}