Decompiled source of Christmas Gifts v1.0.5

ChristmasGifts.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ChristmasGifts")]
[assembly: AssemblyTitle("ChristmasGifts")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TrickOrTreat
{
	[BepInPlugin("Omniscye.TrickOrTreat", "TrickOrTreat", "1.0")]
	public class TrickOrTreat : BaseUnityPlugin
	{
		internal static TrickOrTreat Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

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

		internal Harmony? Harmony { get; set; }

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

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

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

		private void Update()
		{
		}
	}
}
namespace Empress.TrickOrTreat
{
	internal static class EnemyErrorSilencer
	{
		private sealed class FilteringUnityLogHandler : ILogHandler
		{
			private readonly ILogHandler _inner;

			private readonly Func<LogType, string, string, Exception, bool> _predicate;

			public FilteringUnityLogHandler(ILogHandler inner, Func<LogType, string, string, Exception, bool> predicate)
			{
				_inner = inner;
				_predicate = predicate;
			}

			public void LogFormat(LogType logType, Object context, string format, params object[] args)
			{
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				string arg = SafeFormat(format, args);
				if (!_predicate(logType, arg, string.Empty, null))
				{
					_inner.LogFormat(logType, context, format, args);
				}
			}

			public void LogException(Exception exception, Object context)
			{
				if (!_predicate((LogType)4, exception?.Message, exception?.StackTrace, exception))
				{
					_inner.LogException(exception, context);
				}
			}

			private static string SafeFormat(string fmt, object[] args)
			{
				try
				{
					return (args == null || args.Length == 0) ? fmt : string.Format(fmt, args);
				}
				catch
				{
					return fmt;
				}
			}
		}

		private sealed class FilteringBepListener : ILogListener, IDisposable
		{
			private readonly ILogListener[] _inners;

			private readonly Func<LogLevel, object, bool> _predicate;

			public FilteringBepListener(ILogListener[] inners, Func<LogLevel, object, bool> predicate)
			{
				_inners = inners ?? Array.Empty<ILogListener>();
				_predicate = predicate;
			}

			public void LogEvent(object sender, LogEventArgs eventArgs)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				if (!_predicate(eventArgs.Level, eventArgs.Data))
				{
					for (int i = 0; i < _inners.Length; i++)
					{
						_inners[i].LogEvent(sender, eventArgs);
					}
				}
			}

			public void Dispose()
			{
				for (int i = 0; i < _inners.Length; i++)
				{
					((IDisposable)_inners[i]).Dispose();
				}
			}
		}

		internal static bool Enabled = true;

		private static readonly string[] DefaultTokens = new string[10] { "Enemy", "AI", "NavMesh", "VisionTrigger", "StateIdle", "StateChase", "OnCollision", "Update (", "REPOLib.Modules.Enemies", "SpawnEnemy" };

		private static bool _installed;

		private static ILogHandler _unityInner;

		private static ManualLogSource _log;

		internal static void Install(ManualLogSource logger, IEnumerable<string> extraTokens = null)
		{
			if (_installed)
			{
				return;
			}
			_installed = true;
			_log = logger;
			try
			{
				string[] tokens = ((extraTokens == null) ? DefaultTokens : DefaultTokens.Concat(extraTokens).ToArray());
				_unityInner = Debug.unityLogger.logHandler;
				Debug.unityLogger.logHandler = (ILogHandler)(object)new FilteringUnityLogHandler(_unityInner, (LogType type, string msg, string st, Exception ex) => ShouldDrop(type, msg, st, ex, tokens));
				ILogListener[] inners = Logger.Listeners.ToArray();
				Logger.Listeners.Clear();
				Logger.Listeners.Add((ILogListener)(object)new FilteringBepListener(inners, delegate(LogLevel level, object data)
				{
					//IL_0017: Unknown result type (might be due to invalid IL or missing references)
					//IL_0019: Unknown result type (might be due to invalid IL or missing references)
					//IL_001b: Invalid comparison between Unknown and I4
					if (!Enabled)
					{
						return false;
					}
					if ((level & 3) == 0)
					{
						return false;
					}
					string s = data?.ToString() ?? string.Empty;
					return tokens.Any((string t) => s.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0);
				}));
				ManualLogSource log = _log;
				if (log != null)
				{
					log.LogInfo((object)"[Silencer] Enemy-related error spam will be filtered.");
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = _log;
				if (log2 != null)
				{
					log2.LogWarning((object)("[Silencer] Failed to install: " + ex2.Message));
				}
			}
		}

		private static bool ShouldDrop(LogType type, string message, string stackTrace, Exception exception, string[] tokens)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			string message2 = message;
			string stackTrace2 = stackTrace;
			if (!Enabled)
			{
				return false;
			}
			if ((int)type != 0 && (int)type != 4)
			{
				return false;
			}
			if (!string.IsNullOrEmpty(message2) && tokens.Any((string t) => message2.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if (!string.IsNullOrEmpty(stackTrace2) && tokens.Any((string t) => stackTrace2.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0))
			{
				return true;
			}
			if (exception != null)
			{
				string es = exception.ToString();
				if (tokens.Any((string t) => es.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0))
				{
					return true;
				}
			}
			return false;
		}
	}
	[BepInPlugin("empress.repo.empresspresents", "Empress Presents (Press-E, Host-Synced)", "4.5.4")]
	public class TrickOrTreatPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "empress.repo.empresspresents";

		public const string PluginName = "Empress Presents (Press-E, Host-Synced)";

		public const string PluginVersion = "4.5.4";

		internal static TrickOrTreatPlugin Instance;

		internal static ManualLogSource LogSrc;

		internal static ConfigEntry<float> ExplosionChance;

		internal static ConfigEntry<int> MinSpawnItems;

		internal static ConfigEntry<int> MaxSpawnItems;

		internal static ConfigEntry<int> MinPresents;

		internal static ConfigEntry<int> MaxPresents;

		internal static ConfigEntry<bool> SkipStartRoom;

		private void Awake()
		{
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			Instance = this;
			LogSrc = ((BaseUnityPlugin)this).Logger;
			ExplosionChance = ((BaseUnityPlugin)this).Config.Bind<float>("Gameplay", "ExplosionChance", 0.2f, "Chance [0..1] to explode instead of spawn loot or enemies.");
			MinSpawnItems = ((BaseUnityPlugin)this).Config.Bind<int>("Gameplay", "MinSpawnItems", 1, "Minimum drops on treat (items + valuables).");
			MaxSpawnItems = ((BaseUnityPlugin)this).Config.Bind<int>("Gameplay", "MaxSpawnItems", 6, "Maximum drops on treat (items + valuables).");
			MinPresents = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MinPresents", 1, "Minimum presents per level.");
			MaxPresents = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxPresents", 3, "Maximum presents per level.");
			SkipStartRoom = ((BaseUnityPlugin)this).Config.Bind<bool>("Spawning", "SkipStartRoom", true, "Skip points closest to the truck.");
			GameObject val = new GameObject("Empress_Presents_Host");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)52;
			val.AddComponent<PresentEventRouter>();
		}

		internal static bool IsHostOrOffline()
		{
			return !PhotonNetwork.InRoom || PhotonNetwork.IsMasterClient;
		}

		internal static bool IsHost()
		{
			return PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient;
		}

		internal static bool IsOffline()
		{
			return !PhotonNetwork.InRoom;
		}

		internal static void HostSpawnPresents()
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				LevelGenerator instance = LevelGenerator.Instance;
				if ((Object)(object)instance == (Object)null || !instance.Generated)
				{
					return;
				}
				List<LevelPoint> list = ((instance.LevelPathPoints != null) ? instance.LevelPathPoints.Where((LevelPoint p) => (Object)(object)p != (Object)null).ToList() : new List<LevelPoint>());
				if (list.Count == 0)
				{
					return;
				}
				if (SkipStartRoom.Value && (Object)(object)instance.LevelPathTruck != (Object)null)
				{
					Vector3 truckPos = ((Component)instance.LevelPathTruck).transform.position;
					list = list.OrderBy((LevelPoint p) => Vector3.Distance(truckPos, ((Component)p).transform.position)).Skip(3).ToList();
					if (list.Count == 0)
					{
						list = instance.LevelPathPoints.Where((LevelPoint p) => (Object)(object)p != (Object)null).ToList();
					}
				}
				int num = Mathf.Clamp(MinPresents.Value, 0, 1000);
				int num2 = Mathf.Max(num, MaxPresents.Value);
				int num3 = Random.Range(num, num2 + 1);
				num3 = Mathf.Min(num3, list.Count);
				Random rng = new Random((int)(DateTime.UtcNow.Ticks & 0x7FFFFFF));
				List<LevelPoint> list2 = list.OrderBy((LevelPoint _) => rng.Next()).Take(num3).ToList();
				foreach (LevelPoint item in list2)
				{
					Vector3 val = ((Component)item).transform.position + Vector3.up * 0.25f;
					Quaternion rotation = ((Component)item).transform.rotation;
					string text = Guid.NewGuid().ToString("N");
					PresentEventRouter.CreateLocalPresent(text, val, rotation, announce: false);
					PresentEventRouter.Raise(PresentEventRouter.Ev.Create, new object[3] { text, val, rotation }, (ReceiverGroup)0);
				}
			}
			catch
			{
			}
		}

		internal static void HostResolveInteraction(string id, Vector3 at)
		{
			//IL_00ca: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			PresentEventRouter.Ev code = PresentEventRouter.Ev.TreatFX;
			try
			{
				if (Random.value < Mathf.Clamp01(ExplosionChance.Value))
				{
					code = PresentEventRouter.Ev.ExplodeFX;
					PresentEventRouter.PlayFXLocal(PresentEventRouter.Ev.ExplodeFX, at);
					return;
				}
				code = PresentEventRouter.Ev.TreatFX;
				PresentEventRouter.PlayFXLocal(PresentEventRouter.Ev.TreatFX, at);
				BuildMixedSpawnPayload(out Item[] items, out PrefabRef[] valuables, out int _);
				bool flag = false;
				if (items != null && items.Length != 0)
				{
					HostSpawnItems(items, at);
					flag = true;
				}
				if (valuables != null && valuables.Length != 0)
				{
					HostSpawnValuables(valuables, at);
					flag = true;
				}
				if (!flag)
				{
					code = PresentEventRouter.Ev.ExplodeFX;
					PresentEventRouter.PlayFXLocal(PresentEventRouter.Ev.ExplodeFX, at);
				}
			}
			catch (Exception arg)
			{
				LogSrc.LogError((object)$"[Presents] HostResolveInteraction fatal: {arg}");
			}
			finally
			{
				try
				{
					PresentEventRouter.Raise(code, at, (ReceiverGroup)0);
				}
				catch
				{
				}
				try
				{
					PresentEventRouter.LocalDestroy(id);
				}
				catch
				{
				}
				try
				{
					PresentEventRouter.Raise(PresentEventRouter.Ev.Destroy, id, (ReceiverGroup)0);
				}
				catch
				{
				}
			}
		}

		private static void BuildMixedSpawnPayload(out Item[] items, out PrefabRef[] valuables, out int count)
		{
			items = Array.Empty<Item>();
			valuables = Array.Empty<PrefabRef>();
			count = Random.Range(Mathf.Max(1, MinSpawnItems.Value), Mathf.Max(MinSpawnItems.Value, MaxSpawnItems.Value) + 1);
			if (count <= 0)
			{
				return;
			}
			List<Item> list = BuildItemPool();
			List<PrefabRef> list2 = BuildValuablePool();
			if (list.Count == 0 && list2.Count == 0)
			{
				return;
			}
			Random random = new Random((int)(DateTime.UtcNow.Ticks & 0x7FFFFFFF));
			List<Item> list3 = new List<Item>(count);
			List<PrefabRef> list4 = new List<PrefabRef>(count);
			for (int i = 0; i < count; i++)
			{
				bool flag = list.Count > 0;
				bool flag2 = list2.Count > 0;
				if (flag && flag2)
				{
					if (random.NextDouble() < 0.5)
					{
						list3.Add(list[random.Next(list.Count)]);
					}
					else
					{
						list4.Add(list2[random.Next(list2.Count)]);
					}
				}
				else if (flag)
				{
					list3.Add(list[random.Next(list.Count)]);
				}
				else
				{
					list4.Add(list2[random.Next(list2.Count)]);
				}
			}
			items = list3.ToArray();
			valuables = list4.ToArray();
		}

		private static List<Item> BuildItemPool()
		{
			try
			{
				List<Item> list = new List<Item>();
				ShopManager instance = ShopManager.instance;
				if ((Object)(object)instance != (Object)null)
				{
					if (instance.potentialItems != null)
					{
						list.AddRange(instance.potentialItems);
					}
					if (instance.potentialItemConsumables != null)
					{
						list.AddRange(instance.potentialItemConsumables);
					}
					if (instance.potentialItemUpgrades != null)
					{
						list.AddRange(instance.potentialItemUpgrades);
					}
				}
				if (list.Count == 0 && (Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemDictionary != null)
				{
					list.AddRange(StatsManager.instance.itemDictionary.Values);
				}
				return list.Where((Item i) => (Object)(object)i != (Object)null && i.prefab != null && i.prefab.IsValid()).Distinct().ToList();
			}
			catch
			{
				return new List<Item>();
			}
		}

		private static List<PrefabRef> BuildValuablePool()
		{
			try
			{
				List<PrefabRef> list = new List<PrefabRef>();
				LevelGenerator instance = LevelGenerator.Instance;
				if ((Object)(object)instance == (Object)null || (Object)(object)instance.Level == (Object)null || instance.Level.ValuablePresets == null)
				{
					return list;
				}
				foreach (LevelValuables valuablePreset in instance.Level.ValuablePresets)
				{
					if (!((Object)(object)valuablePreset == (Object)null))
					{
						if (valuablePreset.tiny != null)
						{
							list.AddRange(valuablePreset.tiny);
						}
						if (valuablePreset.small != null)
						{
							list.AddRange(valuablePreset.small);
						}
						if (valuablePreset.medium != null)
						{
							list.AddRange(valuablePreset.medium);
						}
						if (valuablePreset.big != null)
						{
							list.AddRange(valuablePreset.big);
						}
						if (valuablePreset.wide != null)
						{
							list.AddRange(valuablePreset.wide);
						}
						if (valuablePreset.tall != null)
						{
							list.AddRange(valuablePreset.tall);
						}
						if (valuablePreset.veryTall != null)
						{
							list.AddRange(valuablePreset.veryTall);
						}
					}
				}
				return list.Where((PrefabRef v) => v != null && v.IsValid() && ((Object)(object)v.Prefab != (Object)null || !string.IsNullOrEmpty(v.ResourcePath))).Distinct().ToList();
			}
			catch
			{
				return new List<PrefabRef>();
			}
		}

		private static void HostSpawnItems(Item[] items, Vector3 center)
		{
			//IL_007f: 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)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHostOrOffline() || items == null || items.Length == 0)
			{
				return;
			}
			Quaternion val = Quaternion.identity;
			try
			{
				if ((Object)(object)ShopManager.instance != (Object)null)
				{
					Transform itemRotateHelper = ShopManager.instance.itemRotateHelper;
					if ((Object)(object)itemRotateHelper != (Object)null)
					{
						((Component)itemRotateHelper).transform.parent = null;
						val = ((Component)itemRotateHelper).transform.rotation;
					}
				}
			}
			catch
			{
			}
			Vector3 val2 = center + Vector3.up * 0.35f;
			foreach (Item val3 in items)
			{
				try
				{
					if ((Object)(object)val3 == (Object)null || val3.prefab == null || !val3.prefab.IsValid())
					{
						continue;
					}
					string resourcePath = val3.prefab.ResourcePath;
					GameObject prefab = val3.prefab.Prefab;
					Vector3 val4 = val2 + Random.insideUnitSphere * 0.4f;
					if (IsHost())
					{
						PhotonNetwork.Instantiate(resourcePath, val4, val, (byte)0, (object[])null);
					}
					else
					{
						if (!IsOffline())
						{
							continue;
						}
						if ((Object)(object)prefab != (Object)null)
						{
							Object.Instantiate<GameObject>(prefab, val4, val);
							continue;
						}
						GameObject val5 = Resources.Load<GameObject>(resourcePath);
						if ((Object)(object)val5 != (Object)null)
						{
							Object.Instantiate<GameObject>(val5, val4, val);
						}
						continue;
					}
				}
				catch
				{
				}
			}
		}

		private static void HostSpawnValuables(PrefabRef[] valuables, Vector3 center)
		{
			//IL_007f: 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)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHostOrOffline() || valuables == null || valuables.Length == 0)
			{
				return;
			}
			Quaternion val = Quaternion.identity;
			try
			{
				if ((Object)(object)ShopManager.instance != (Object)null)
				{
					Transform itemRotateHelper = ShopManager.instance.itemRotateHelper;
					if ((Object)(object)itemRotateHelper != (Object)null)
					{
						((Component)itemRotateHelper).transform.parent = null;
						val = ((Component)itemRotateHelper).transform.rotation;
					}
				}
			}
			catch
			{
			}
			Vector3 val2 = center + Vector3.up * 0.35f;
			foreach (PrefabRef val3 in valuables)
			{
				try
				{
					if (val3 == null || !val3.IsValid())
					{
						continue;
					}
					string resourcePath = val3.ResourcePath;
					GameObject prefab = val3.Prefab;
					Vector3 val4 = val2 + Random.insideUnitSphere * 0.4f;
					if (IsHost())
					{
						PhotonNetwork.Instantiate(resourcePath, val4, val, (byte)0, (object[])null);
					}
					else
					{
						if (!IsOffline())
						{
							continue;
						}
						if ((Object)(object)prefab != (Object)null)
						{
							Object.Instantiate<GameObject>(prefab, val4, val);
							continue;
						}
						GameObject val5 = Resources.Load<GameObject>(resourcePath);
						if ((Object)(object)val5 != (Object)null)
						{
							Object.Instantiate<GameObject>(val5, val4, val);
						}
						continue;
					}
				}
				catch
				{
				}
			}
		}
	}
	public class PresentEventRouter : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		public enum Ev : byte
		{
			Create = 61,
			Interact,
			TreatFX,
			ExplodeFX,
			Destroy
		}

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

			private object <>2__current;

			public PresentEventRouter <>4__this;

			private float <t>5__1;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					_spawnRoutineRunning = true;
					<t>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated) && <t>5__1 < 20f)
				{
					<t>5__1 += Time.deltaTime;
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				if (TrickOrTreatPlugin.IsHostOrOffline() && !_spawnedThisScene)
				{
					TrickOrTreatPlugin.HostSpawnPresents();
					_spawnedThisScene = true;
				}
				_spawnRoutineRunning = false;
				return false;
			}

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

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

		private static readonly Dictionary<string, GameObject> Active = new Dictionary<string, GameObject>();

		private static bool _spawnRoutineRunning;

		private static bool _spawnedThisScene;

		private static string _loadedSceneName;

		private bool _callbackHooked;

		private void OnEnable()
		{
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			if (_callbackHooked)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
			}
			_callbackHooked = false;
		}

		public override void OnJoinedRoom()
		{
			EnsureCallbackHooked();
		}

		public override void OnLeftRoom()
		{
			if (_callbackHooked)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbackHooked = false;
			}
			_spawnRoutineRunning = false;
			_spawnedThisScene = false;
			Active.Clear();
		}

		private void EnsureCallbackHooked()
		{
			if (!_callbackHooked)
			{
				PhotonNetwork.AddCallbackTarget((object)this);
				_callbackHooked = true;
			}
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode m)
		{
			_loadedSceneName = ((Scene)(ref s)).name ?? string.Empty;
			_spawnRoutineRunning = false;
			_spawnedThisScene = false;
			Active.Clear();
			EnsureCallbackHooked();
			if (PhotonNetwork.InRoom)
			{
				TrySpawnIfRealLevel();
			}
		}

		private void TrySpawnIfRealLevel()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string text = ((Scene)(ref activeScene)).name ?? "";
			if (text.IndexOf("Lobby", StringComparison.OrdinalIgnoreCase) < 0 && (PhotonNetwork.InRoom || !PhotonNetwork.IsConnected) && !_spawnRoutineRunning && !_spawnedThisScene)
			{
				((MonoBehaviour)this).StartCoroutine(WaitLevelThenSpawn());
			}
		}

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

		internal static void PlayFXLocal(Ev code, Vector3 pos)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				switch (code)
				{
				case Ev.TreatFX:
					TrickPresent.SpawnExplosionPrefab(pos, 0.5f, 0, 0, 0f, disableSound: true, 0f);
					break;
				case Ev.ExplodeFX:
					TrickPresent.SpawnExplosionPrefab(pos, 1.2f, 75, 160, 4f, disableSound: false, 1f);
					break;
				}
			}
			catch
			{
			}
		}

		internal static void LocalDestroy(string id)
		{
			try
			{
				if (!string.IsNullOrEmpty(id))
				{
					if (Active.TryGetValue(id, out GameObject value) && (Object)(object)value != (Object)null)
					{
						Object.Destroy((Object)(object)value);
					}
					Active.Remove(id);
				}
			}
			catch
			{
			}
		}

		public static void Raise(Ev code, object payload, ReceiverGroup receivers)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			//IL_005e: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				PhotonNetwork.RaiseEvent((byte)code, payload, new RaiseEventOptions
				{
					Receivers = receivers
				}, SendOptions.SendReliable);
				return;
			}
			try
			{
				switch (code)
				{
				case Ev.TreatFX:
					TrickPresent.SpawnExplosionPrefab((Vector3)payload, 0.5f, 0, 0, 0f, disableSound: true, 0f);
					break;
				case Ev.ExplodeFX:
					TrickPresent.SpawnExplosionPrefab((Vector3)payload, 1.2f, 75, 160, 4f, disableSound: false, 1f);
					break;
				case Ev.Destroy:
				{
					string id2 = payload as string;
					LocalDestroy(id2);
					break;
				}
				case Ev.Create:
					if (payload is object[] array && array.Length >= 3)
					{
						string id = array[0] as string;
						Vector3 pos = (Vector3)array[1];
						Quaternion rot = (Quaternion)array[2];
						CreateLocalPresent(id, pos, rot, announce: false);
					}
					break;
				case Ev.Interact:
					break;
				}
			}
			catch
			{
			}
		}

		public static void CreateLocalPresent(string id, Vector3 pos, Quaternion rot, bool announce)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!Active.ContainsKey(id))
				{
					GameObject value = PresentPrefabBuilder.Build(id, pos, rot);
					Active[id] = value;
				}
			}
			catch
			{
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_00ef: 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_00f8: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00d5: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				switch ((Ev)photonEvent.Code)
				{
				case Ev.Create:
					if (photonEvent.CustomData is object[] array2 && array2.Length >= 3)
					{
						string id3 = array2[0] as string;
						Vector3 pos3 = (Vector3)array2[1];
						Quaternion rot = (Quaternion)array2[2];
						if (!TrickOrTreatPlugin.IsHost())
						{
							CreateLocalPresent(id3, pos3, rot, announce: true);
						}
					}
					break;
				case Ev.Interact:
					if (TrickOrTreatPlugin.IsHostOrOffline() && photonEvent.CustomData is object[] array && array.Length >= 2)
					{
						string id2 = array[0] as string;
						Vector3 at = (Vector3)array[1];
						TrickOrTreatPlugin.HostResolveInteraction(id2, at);
					}
					break;
				case Ev.TreatFX:
				{
					Vector3 pos2 = (Vector3)photonEvent.CustomData;
					PlayFXLocal(Ev.TreatFX, pos2);
					break;
				}
				case Ev.ExplodeFX:
				{
					Vector3 pos = (Vector3)photonEvent.CustomData;
					PlayFXLocal(Ev.ExplodeFX, pos);
					break;
				}
				case Ev.Destroy:
				{
					string id = photonEvent.CustomData as string;
					LocalDestroy(id);
					break;
				}
				}
			}
			catch
			{
			}
		}

		public static void RequestInteract(string id, Vector3 at)
		{
			//IL_0025: 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)
			if (TrickOrTreatPlugin.IsHostOrOffline())
			{
				TrickOrTreatPlugin.HostResolveInteraction(id, at);
				return;
			}
			Raise(Ev.Interact, new object[2] { id, at }, (ReceiverGroup)2);
		}
	}
	public static class PresentPrefabBuilder
	{
		public static GameObject Build(string id, Vector3 pos, Quaternion rot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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_0079: Expected O, but got Unknown
			//IL_007f: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: 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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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)
			Vector3 val = pos + Vector3.up * 0.5f;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, Vector3.down, ref val2, 2f, -1, (QueryTriggerInteraction)1))
			{
				val = ((RaycastHit)(ref val2)).point + Vector3.up * 0.05f;
				rot = Quaternion.FromToRotation(Vector3.up, ((RaycastHit)(ref val2)).normal) * rot;
			}
			GameObject val3 = new GameObject("EmpressPresent_" + id);
			val3.transform.position = val;
			val3.transform.rotation = rot;
			Rigidbody val4 = val3.AddComponent<Rigidbody>();
			val4.useGravity = false;
			val4.isKinematic = false;
			val4.collisionDetectionMode = (CollisionDetectionMode)0;
			val4.interpolation = (RigidbodyInterpolation)0;
			val4.constraints = (RigidbodyConstraints)126;
			GameObject val5 = new GameObject("InteractCollider");
			val5.transform.SetParent(val3.transform, false);
			BoxCollider val6 = val5.AddComponent<BoxCollider>();
			val6.size = new Vector3(0.45f, 0.35f, 0.45f);
			val6.center = new Vector3(0f, 0.175f, 0f);
			((Collider)val6).isTrigger = true;
			val3.AddComponent<PresentVisualBinder>();
			TrickPresent trickPresent = val3.AddComponent<TrickPresent>();
			trickPresent.Id = id;
			return val3;
		}
	}
	public class PresentVisualBinder : MonoBehaviour
	{
		private void Awake()
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = TrickAssetLoader.LoadTreatPrefab();
				if ((Object)(object)val != (Object)null)
				{
					GameObject val2 = Object.Instantiate<GameObject>(val, ((Component)this).transform.position, ((Component)this).transform.rotation);
					val2.transform.SetParent(((Component)this).transform, true);
				}
			}
			catch
			{
			}
		}
	}
	public class TrickPresent : MonoBehaviour
	{
		[CompilerGenerated]
		private sealed class <PlayAnimationThenDoLogic>d__17 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public TrickPresent <>4__this;

			private Animator <animator>5__1;

			private bool <droveBool>5__2;

			private bool <hasBool>5__3;

			private int <i>5__4;

			private AnimatorControllerParameter[] <ps>5__5;

			private int <i>5__6;

			private int <hash>5__7;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<animator>5__1 = null;
				<ps>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0201: Unknown result type (might be due to invalid IL or missing references)
				//IL_020b: Expected O, but got Unknown
				//IL_026b: 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: Invalid comparison between Unknown and I4
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<animator>5__1 = null;
					<droveBool>5__2 = false;
					try
					{
						<animator>5__1 = ((Component)<>4__this).GetComponentInChildren<Animator>(true);
						if ((Object)(object)<animator>5__1 != (Object)null)
						{
							<i>5__4 = 0;
							while (<i>5__4 < <animator>5__1.layerCount)
							{
								<animator>5__1.SetLayerWeight(<i>5__4, 1f);
								<i>5__4++;
							}
							<hasBool>5__3 = false;
							try
							{
								<ps>5__5 = <animator>5__1.parameters;
								<i>5__6 = 0;
								while (<i>5__6 < <ps>5__5.Length)
								{
									if ((int)<ps>5__5[<i>5__6].type == 4 && <ps>5__5[<i>5__6].name == "Present")
									{
										<hasBool>5__3 = true;
										break;
									}
									<i>5__6++;
								}
								<ps>5__5 = null;
							}
							catch
							{
							}
							if (<hasBool>5__3)
							{
								<animator>5__1.SetBool("Present", true);
								ManualLogSource logSrc = TrickOrTreatPlugin.LogSrc;
								if (logSrc != null)
								{
									logSrc.LogInfo((object)"[Presents] Animator bool 'Present' = true.");
								}
								<droveBool>5__2 = true;
							}
							else
							{
								<hash>5__7 = Animator.StringToHash("Open Present");
								if (<animator>5__1.HasState(0, <hash>5__7))
								{
									<animator>5__1.CrossFade(<hash>5__7, 0.05f, 0, 0f);
									ManualLogSource logSrc2 = TrickOrTreatPlugin.LogSrc;
									if (logSrc2 != null)
									{
										logSrc2.LogInfo((object)"[Presents] Animator state 'Open Present' crossfaded (bool 'Present' not found).");
									}
									<droveBool>5__2 = true;
								}
							}
							<animator>5__1.Update(0f);
						}
					}
					catch
					{
					}
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if (<droveBool>5__2 && (Object)(object)<animator>5__1 != (Object)null)
					{
						try
						{
							<animator>5__1.SetBool("Present", false);
						}
						catch
						{
						}
					}
					PresentEventRouter.RequestInteract(<>4__this.Id, ((Component)<>4__this).transform.position);
					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 <Start>d__15 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public TrickPresent <>4__this;

			private Animator <anim>5__1;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<anim>5__1 = 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;
					<>4__this._armed = true;
					try
					{
						<anim>5__1 = ((Component)<>4__this).GetComponentInChildren<Animator>(true);
						if ((Object)(object)<anim>5__1 != (Object)null)
						{
							<anim>5__1.cullingMode = (AnimatorCullingMode)0;
							<anim>5__1.updateMode = (AnimatorUpdateMode)0;
							<anim>5__1.Rebind();
							<anim>5__1.Update(0f);
						}
						<anim>5__1 = null;
					}
					catch
					{
					}
					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();
			}
		}

		public string Id;

		private bool _armed;

		private float _nextUse;

		private readonly float _cooldown = 0.6f;

		private readonly float _useRange = 2f;

		private const string AnimBool = "Present";

		private const string AnimStateName = "Open Present";

		private const float AnimDelaySeconds = 2f;

		private static FieldRef<ParticlePrefabExplosion, float> _fExplosionSize;

		private static FieldRef<ParticlePrefabExplosion, int> _fExplosionDamage;

		private static FieldRef<ParticlePrefabExplosion, int> _fExplosionDamageEnemy;

		private static bool _fieldRefsReady;

		private static bool _fieldRefsFailed;

		private static void EnsureFieldRefs()
		{
			if (_fieldRefsReady || _fieldRefsFailed)
			{
				return;
			}
			try
			{
				_fExplosionSize = AccessTools.FieldRefAccess<ParticlePrefabExplosion, float>("explosionSize");
				_fExplosionDamage = AccessTools.FieldRefAccess<ParticlePrefabExplosion, int>("explosionDamage");
				_fExplosionDamageEnemy = AccessTools.FieldRefAccess<ParticlePrefabExplosion, int>("explosionDamageEnemy");
				_fieldRefsReady = true;
			}
			catch
			{
				_fieldRefsFailed = true;
			}
		}

		private static void TrySetFieldReflect<T>(object target, string fieldName, T value)
		{
			if (target == null)
			{
				return;
			}
			try
			{
				FieldInfo field = target.GetType().GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && field.FieldType.IsAssignableFrom(typeof(T)))
				{
					field.SetValue(target, value);
				}
			}
			catch
			{
			}
		}

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

		private void Update()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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_0079: 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_0088: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			if (!_armed || string.IsNullOrEmpty(Id) || Time.time < _nextUse)
			{
				return;
			}
			PlayerController instance = PlayerController.instance;
			Vector3 position;
			if ((Object)(object)instance != (Object)null)
			{
				position = ((Component)instance).transform.position;
			}
			else
			{
				if (!((Object)(object)Camera.main != (Object)null))
				{
					return;
				}
				position = ((Component)Camera.main).transform.position;
			}
			float num = Vector3.Distance(position, ((Component)this).transform.position);
			if (num > _useRange)
			{
				return;
			}
			SemiFunc.UIFocusText("Press <color=yellow>E</color> to open", Color.white, Color.yellow, 3f);
			if (!SemiFunc.InputDown((InputKey)2))
			{
				return;
			}
			_nextUse = Time.time + _cooldown;
			_armed = false;
			try
			{
				Transform obj = ((Component)this).transform.Find("InteractCollider");
				Collider val = ((obj != null) ? ((Component)obj).GetComponent<Collider>() : null);
				if ((Object)(object)val != (Object)null)
				{
					val.enabled = false;
				}
			}
			catch
			{
			}
			((MonoBehaviour)this).StartCoroutine(PlayAnimationThenDoLogic());
		}

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

		public static bool SpawnExplosionPrefab(Vector3 pos, float size, int damage, int enemyDamage, float forceMulti, bool disableSound, float shakeMultiplier)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				GameObject val = Resources.Load<GameObject>("Effects/Part Prefab Explosion");
				if ((Object)(object)val == (Object)null)
				{
					return false;
				}
				GameObject val2 = Object.Instantiate<GameObject>(val, pos, Quaternion.identity);
				ParticlePrefabExplosion component = val2.GetComponent<ParticlePrefabExplosion>();
				if ((Object)(object)component != (Object)null)
				{
					EnsureFieldRefs();
					float num = Mathf.Max(0.01f, size);
					int num2 = Mathf.Max(0, damage);
					int num3 = Mathf.Max(0, enemyDamage);
					float forceMultiplier = Mathf.Max(0f, forceMulti);
					if (_fieldRefsReady)
					{
						try
						{
							_fExplosionSize.Invoke(component) = num;
							_fExplosionDamage.Invoke(component) = num2;
							_fExplosionDamageEnemy.Invoke(component) = num3;
						}
						catch
						{
							TrySetFieldReflect(component, "explosionSize", num);
							TrySetFieldReflect(component, "explosionDamage", num2);
							TrySetFieldReflect(component, "explosionDamageEnemy", num3);
						}
					}
					else
					{
						TrySetFieldReflect(component, "explosionSize", num);
						TrySetFieldReflect(component, "explosionDamage", num2);
						TrySetFieldReflect(component, "explosionDamageEnemy", num3);
					}
					component.forceMultiplier = forceMultiplier;
					if (disableSound)
					{
						try
						{
							AudioSource[] componentsInChildren = val2.GetComponentsInChildren<AudioSource>(true);
							foreach (AudioSource val3 in componentsInChildren)
							{
								val3.mute = true;
							}
						}
						catch
						{
						}
					}
				}
				return true;
			}
			catch
			{
				return false;
			}
		}
	}
	internal static class TrickAssetLoader
	{
		private static AssetBundle _bundle;

		private static GameObject _cachedTreat;

		public static GameObject LoadTreatPrefab()
		{
			try
			{
				if ((Object)(object)_cachedTreat != (Object)null)
				{
					return _cachedTreat;
				}
				if ((Object)(object)_bundle == (Object)null)
				{
					string directoryName = Path.GetDirectoryName(typeof(TrickOrTreatPlugin).Assembly.Location);
					string text = Path.Combine(directoryName, "trick");
					string text2 = Path.Combine(directoryName, "Empress", "trick");
					string text3 = (File.Exists(text) ? text : text2);
					if (!File.Exists(text3))
					{
						return null;
					}
					_bundle = AssetBundle.LoadFromFile(text3);
					if ((Object)(object)_bundle == (Object)null)
					{
						return null;
					}
				}
				_cachedTreat = _bundle.LoadAsset<GameObject>("treat");
				return _cachedTreat;
			}
			catch
			{
				return null;
			}
		}
	}
}