Decompiled source of MetalItemVariants v0.0.7

BepInEx/plugins/MetalItemVariants.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dawn;
using Dusk;
using GameNetcodeStuff;
using MetalItemVariants.NetcodePatcher;
using MetalItemVariants.Utils;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MetalItemVariants
{
	internal class ConfigManager
	{
		internal static ConfigEntry<bool> DebugLogging { get; private set; }

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

		internal const string modName = "MetalItemVariants";

		internal const string modVersion = "0.0.7";

		internal const string DawnNamespace = "metalitemvariants";

		internal static ManualLogSource mls { get; private set; }

		internal static Plugin Instance { get; private set; }

		internal static ConfigManager Configs { get; private set; }

		private void Awake()
		{
			Instance = this;
			mls = Logger.CreateLogSource("MrHat.MetalItemVariants.Internals");
			Configs = new ConfigManager();
		}

		internal static void LogDebug(object message)
		{
			if (ConfigManager.DebugLogging.Value)
			{
				mls.LogDebug(message);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MetalItemVariants";

		public const string PLUGIN_NAME = "MetalItemVariants";

		public const string PLUGIN_VERSION = "0.0.7";
	}
}
namespace MetalItemVariants.Utils
{
	internal static class DuskConfigParser
	{
		private const string Guid = "MrHat.MetalItemVariants";

		private static DuskMod GetMod()
		{
			return ((IEnumerable<DuskMod>)DuskMod.AllMods).FirstOrDefault((Func<DuskMod, bool>)((DuskMod item) => item.Plugin.GUID == "MrHat.MetalItemVariants"));
		}

		internal static bool TryGet<T>(string key, out T value)
		{
			DuskMod mod = GetMod();
			if (mod != null)
			{
				ConfigEntryBase val = ((IEnumerable<ConfigEntryBase>)mod.ConfigEntries).FirstOrDefault((Func<ConfigEntryBase, bool>)((ConfigEntryBase item) => item.Definition.Key == key));
				if (val is ConfigEntry<T> val2)
				{
					value = val2.Value;
					return true;
				}
			}
			value = default(T);
			return false;
		}

		internal static ConfigEntry<T> Bind<T>(string section, string key, T defaultValue, string description)
		{
			DuskMod mod = GetMod();
			if (mod == null)
			{
				return null;
			}
			ConfigContext val = mod.ConfigManager.CreateConfigSection(section);
			try
			{
				return val.Bind<T>(key, description, defaultValue);
			}
			finally
			{
				((IDisposable)val)?.Dispose();
			}
		}
	}
}
namespace MetalItemVariants.MonoBehaviours
{
	public class MetalGiftBox : GrabbableObject
	{
		[CompilerGenerated]
		private sealed class <InitialiseSelectionNextFrame>d__22 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MetalGiftBox <>4__this;

			private Item <selectedItem>5__1;

			private Item <savedItem>5__2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<selectedItem>5__1 = null;
				<savedItem>5__2 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (!<>4__this.HasSpawnPool())
					{
						return false;
					}
					if (<>4__this.hasLoadedSelectionFromSave)
					{
						<>4__this.selectedItemIndex = <>4__this.loadedSelectedIndex;
						if (<>4__this.TryGetSelectedItem(out <savedItem>5__2))
						{
							<>4__this.hasNoResolvedItem = false;
							Plugin.LogDebug("MetalGiftBox loaded saved item: " + <savedItem>5__2.itemName + " (" + <>4__this.possibleSpawnKeys[<>4__this.selectedItemIndex] + ")");
							<>4__this.selectedScrapValue = <>4__this.RollScrapValue(<savedItem>5__2);
							return false;
						}
						Plugin.mls.LogWarning((object)("MetalGiftBox could not resolve saved item key '" + <>4__this.possibleSpawnKeys[<>4__this.selectedItemIndex] + "'. Is item disabled in config? Rerolling..."));
						<savedItem>5__2 = null;
					}
					if (!<>4__this.TrySelectRandomResolvedItem(out <selectedItem>5__1))
					{
						return false;
					}
					Plugin.LogDebug("MetalGiftBox rolled random item: " + <selectedItem>5__1.itemName + " (" + <>4__this.possibleSpawnKeys[<>4__this.selectedItemIndex] + ")");
					<>4__this.selectedScrapValue = <>4__this.RollScrapValue(<selectedItem>5__1);
					return false;
				}
			}

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

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

		[CompilerGenerated]
		private sealed class <ResetSpawnedItemFallStateNextFrame>d__24 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public GrabbableObject spawnedItem;

			public MetalGiftBox <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					spawnedItem.reachedFloorTarget = false;
					spawnedItem.hasHitGround = false;
					spawnedItem.fallTime = 0f;
					return false;
				}
			}

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

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

		[CompilerGenerated]
		private sealed class <ResolveSpawnedItemOnClient>d__27 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public NetworkObjectReference netObjectRef;

			public int scrapValue;

			public Vector3 spawnPosition;

			public MetalGiftBox <>4__this;

			private NetworkObject <spawnedNetworkObject>5__1;

			private float <startTime>5__2;

			private GrabbableObject <spawnedItem>5__3;

			private Transform <spawnParent>5__4;

			private Vector3 <floorPosition>5__5;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<spawnedNetworkObject>5__1 = null;
				<spawnedItem>5__3 = null;
				<spawnParent>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0159: Unknown result type (might be due to invalid IL or missing references)
				//IL_015e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0163: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Expected O, but got Unknown
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ae: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<spawnedNetworkObject>5__1 = null;
					<startTime>5__2 = Time.realtimeSinceStartup;
					goto IL_0062;
				case 1:
					<>1__state = -1;
					goto IL_0062;
				case 2:
					{
						<>1__state = -1;
						<spawnedItem>5__3 = ((Component)<spawnedNetworkObject>5__1).GetComponent<GrabbableObject>();
						if ((Object)(object)<spawnedItem>5__3 == (Object)null)
						{
							return false;
						}
						RoundManager instance = RoundManager.Instance;
						instance.totalScrapValueInLevel -= (float)scrapValue;
						RoundManager instance2 = RoundManager.Instance;
						instance2.totalScrapValueInLevel += (float)<spawnedItem>5__3.scrapValue;
						<spawnedItem>5__3.SetScrapValue(scrapValue);
						<spawnParent>5__4 = <>4__this.GetSpawnParent();
						((Component)<spawnedItem>5__3).transform.SetParent(<spawnParent>5__4, true);
						<floorPosition>5__5 = <spawnedItem>5__3.GetItemFloorPosition(spawnPosition);
						if ((Object)(object)((Component)<spawnedItem>5__3).transform.parent != (Object)null)
						{
							<spawnedItem>5__3.targetFloorPosition = ((Component)<spawnedItem>5__3).transform.parent.InverseTransformPoint(<floorPosition>5__5);
							spawnPosition = ((Component)<spawnedItem>5__3).transform.parent.InverseTransformPoint(spawnPosition);
						}
						else
						{
							<spawnedItem>5__3.targetFloorPosition = <floorPosition>5__5;
						}
						<spawnedItem>5__3.startFallingPosition = spawnPosition;
						<spawnedItem>5__3.fallTime = 0f;
						<spawnedItem>5__3.hasHitGround = false;
						<spawnedItem>5__3.reachedFloorTarget = false;
						<>4__this.ApplyShipDropState(<spawnedItem>5__3);
						return false;
					}
					IL_0062:
					if (Time.realtimeSinceStartup - <startTime>5__2 < 8f && !((NetworkObjectReference)(ref netObjectRef)).TryGet(ref <spawnedNetworkObject>5__1, (NetworkManager)null))
					{
						<>2__current = (object)new WaitForSeconds(0.03f);
						<>1__state = 1;
						return true;
					}
					if ((Object)(object)<spawnedNetworkObject>5__1 == (Object)null)
					{
						return false;
					}
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 2;
					return true;
				}
			}

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

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

		public ParticleSystem PoofParticle;

		public AudioSource presentAudio;

		public AudioClip openGiftAudio;

		[SerializeField]
		private string[] possibleSpawnKeys;

		[SerializeField]
		private string minimumValueBonusConfigKey;

		[SerializeField]
		private string maximumValueBonusConfigKey;

		private PlayerControllerB previousHolder;

		private bool hasOpened;

		private bool hasLoadedSelectionFromSave;

		private int loadedSelectedIndex = -1;

		private int selectedItemIndex = -1;

		private int selectedScrapValue;

		private int minimumValueBonus;

		private int maximumValueBonus;

		private bool hasNoResolvedItem;

		public override void Start()
		{
			((GrabbableObject)this).Start();
			DuskConfigParser.TryGet<int>(minimumValueBonusConfigKey, out minimumValueBonus);
			DuskConfigParser.TryGet<int>(maximumValueBonusConfigKey, out maximumValueBonus);
			if (((NetworkBehaviour)this).IsServer)
			{
				((MonoBehaviour)this).StartCoroutine(InitialiseSelectionNextFrame());
			}
		}

		public override void LoadItemSaveData(int saveData)
		{
			((GrabbableObject)this).LoadItemSaveData(saveData);
			if (HasSpawnPool())
			{
				loadedSelectedIndex = Mathf.Clamp(saveData, 0, possibleSpawnKeys.Length - 1);
				hasLoadedSelectionFromSave = true;
			}
		}

		public override int GetItemDataToSave()
		{
			((GrabbableObject)this).GetItemDataToSave();
			if (selectedItemIndex < 0)
			{
				return 0;
			}
			return selectedItemIndex;
		}

		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 (!hasNoResolvedItem && buttonDown && !((Object)(object)base.playerHeldBy == (Object)null) && !hasOpened)
			{
				hasOpened = true;
				base.playerHeldBy.activatingItem = true;
				OpenBoxServerRpc();
			}
		}

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

		[ServerRpc(RequireOwnership = false)]
		private void OpenBoxServerRpc()
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: 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 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2474130236u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2474130236u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 || (!networkManager.IsServer && !networkManager.IsHost))
			{
				return;
			}
			((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
			if (!TryGetSelectedItem(out var item) || (Object)(object)item.spawnPrefab == (Object)null)
			{
				Plugin.mls.LogError((object)"MetalGiftBox could not resolve its selected item.");
				FinishOpenClientRpc();
				return;
			}
			Vector3 val3 = ((Component)this).transform.position + Vector3.up * 0.25f;
			Transform spawnParent = GetSpawnParent();
			GameObject val4 = Object.Instantiate<GameObject>(item.spawnPrefab, val3, Quaternion.identity, spawnParent);
			GrabbableObject component = val4.GetComponent<GrabbableObject>();
			NetworkObject component2 = val4.GetComponent<NetworkObject>();
			if ((Object)(object)component == (Object)null || (Object)(object)component2 == (Object)null)
			{
				Plugin.mls.LogError((object)"MetalGiftBox (somehow) spawned an object without GrabbableObject or NetworkObject.");
				Object.Destroy((Object)(object)val4);
				FinishOpenClientRpc();
				return;
			}
			component.startFallingPosition = val3;
			component.targetFloorPosition = component.GetItemFloorPosition(((Component)this).transform.position);
			component.SetScrapValue(selectedScrapValue);
			((MonoBehaviour)this).StartCoroutine(ResetSpawnedItemFallStateNextFrame(component));
			ApplyShipDropState(component);
			component2.Spawn(false);
			SyncSpawnedItemClientRpc(NetworkObjectReference.op_Implicit(component2), selectedScrapValue, val3);
			FinishOpenClientRpc();
		}

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

		private bool TrySelectRandomResolvedItem(out Item item)
		{
			item = null;
			if (!HasSpawnPool())
			{
				return false;
			}
			int num = possibleSpawnKeys.Length;
			bool[] array = new bool[possibleSpawnKeys.Length];
			while (num > 0)
			{
				int num2 = Random.Range(0, possibleSpawnKeys.Length);
				while (array[num2])
				{
					num2 = Random.Range(0, possibleSpawnKeys.Length);
				}
				array[num2] = true;
				num--;
				selectedItemIndex = num2;
				if (TryGetSelectedItem(out item))
				{
					hasNoResolvedItem = false;
					return true;
				}
				Plugin.mls.LogWarning((object)("MetalGiftBox could not resolve item key '" + possibleSpawnKeys[num2] + "'. Is item disabled in config? Rerolling..."));
			}
			Plugin.mls.LogError((object)"MetalGiftBox could not resolve any configured item keys.");
			selectedItemIndex = -1;
			hasNoResolvedItem = true;
			return false;
		}

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

		[ClientRpc]
		private void FinishOpenClientRpc()
		{
			//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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1248329090u, val, (RpcDelivery)0);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1248329090u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				PlayOpenEffects();
				if ((Object)(object)base.playerHeldBy != (Object)null)
				{
					base.playerHeldBy.activatingItem = false;
					((GrabbableObject)this).DestroyObjectInHand(base.playerHeldBy);
				}
			}
		}

		[ClientRpc]
		private void SyncSpawnedItemClientRpc(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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(1172852060u, val, (RpcDelivery)0);
				((FastBufferWriter)(ref val2)).WriteValueSafe<NetworkObjectReference>(ref netObjectRef, default(ForNetworkSerializable));
				BytePacker.WriteValueBitPacked(val2, scrapValue);
				((FastBufferWriter)(ref val2)).WriteValueSafe(ref spawnPosition);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 1172852060u, val, (RpcDelivery)0);
			}
			if ((int)((NetworkBehaviour)this).__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				((NetworkBehaviour)this).__rpc_exec_stage = (__RpcExecStage)0;
				if (!((NetworkBehaviour)this).IsServer)
				{
					((MonoBehaviour)this).StartCoroutine(ResolveSpawnedItemOnClient(netObjectRef, scrapValue, spawnPosition));
				}
			}
		}

		[IteratorStateMachine(typeof(<ResolveSpawnedItemOnClient>d__27))]
		private IEnumerator ResolveSpawnedItemOnClient(NetworkObjectReference netObjectRef, int scrapValue, Vector3 spawnPosition)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ResolveSpawnedItemOnClient>d__27(0)
			{
				<>4__this = this,
				netObjectRef = netObjectRef,
				scrapValue = scrapValue,
				spawnPosition = spawnPosition
			};
		}

		private void PlayOpenEffects()
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			ParticleSystem poofParticle = PoofParticle;
			if (poofParticle != null)
			{
				poofParticle.Play();
			}
			if ((Object)(object)presentAudio != (Object)null && (Object)(object)openGiftAudio != (Object)null)
			{
				presentAudio.PlayOneShot(openGiftAudio);
				WalkieTalkie.TransmitOneShotAudio(presentAudio, openGiftAudio, 1f);
				RoundManager.Instance.PlayAudibleNoise(((Component)presentAudio).transform.position, 8f, 0.5f, 0, base.isInShipRoom && StartOfRound.Instance.hangarDoorsClosed, 0);
			}
		}

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

		private Transform GetSpawnParent()
		{
			if (((Object)(object)previousHolder != (Object)null && previousHolder.isInElevator) || StartOfRound.Instance.inShipPhase)
			{
				return StartOfRound.Instance.elevatorTransform;
			}
			return null;
		}

		private bool HasSpawnPool()
		{
			return possibleSpawnKeys != null && possibleSpawnKeys.Length != 0;
		}

		private bool TryGetSelectedItem(out Item item)
		{
			item = null;
			if (!HasSpawnPool())
			{
				return false;
			}
			if (selectedItemIndex < 0 || selectedItemIndex >= possibleSpawnKeys.Length)
			{
				return false;
			}
			return TryResolveItem(possibleSpawnKeys[selectedItemIndex], out item);
		}

		private bool TryResolveItem(string key, out Item item)
		{
			item = null;
			if (string.IsNullOrWhiteSpace(key))
			{
				return false;
			}
			NamespacedKey obj = NamespacedKey.From("metalitemvariants", key);
			foreach (KeyValuePair<NamespacedKey<DawnItemInfo>, DawnItemInfo> item2 in (Registry<DawnItemInfo>)(object)LethalContent.Items)
			{
				if (!((object)item2.Key).Equals((object?)obj))
				{
					continue;
				}
				item = item2.Value.Item;
				return (Object)(object)item != (Object)null;
			}
			return false;
		}

		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(2474130236u, new RpcReceiveHandler(__rpc_handler_2474130236), "OpenBoxServerRpc");
			((NetworkBehaviour)this).__registerRpc(1248329090u, new RpcReceiveHandler(__rpc_handler_1248329090), "FinishOpenClientRpc");
			((NetworkBehaviour)this).__registerRpc(1172852060u, new RpcReceiveHandler(__rpc_handler_1172852060), "SyncSpawnedItemClientRpc");
			((GrabbableObject)this).__initializeRpcs();
		}

		private static void __rpc_handler_2474130236(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).OpenBoxServerRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1248329090(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).FinishOpenClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1172852060(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).SyncSpawnedItemClientRpc(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()
		{
		}
	}
}
namespace MetalItemVariants.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}