Decompiled source of ImprovedShop v1.0.0

ImprovedShop.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ImprovedShop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ImprovedShop")]
[assembly: AssemblyTitle("ImprovedShop")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[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 ImprovedShop
{
	internal static class GameAccess
	{
		private static readonly FieldRef<PlayerAvatar, bool> avatarDisabled = Ref<PlayerAvatar, bool>("isDisabled");

		private static readonly FieldRef<PlayerAvatar, PlayerDeathHead> avatarDeathHead = Ref<PlayerAvatar, PlayerDeathHead>("playerDeathHead");

		private static readonly FieldRef<PlayerDeathHead, PhysGrabObject> headPhysics = Ref<PlayerDeathHead, PhysGrabObject>("physGrabObject");

		private static readonly FieldRef<PlayerDeathHead, bool> headTriggered = Ref<PlayerDeathHead, bool>("triggered");

		private static readonly FieldRef<PlayerHealth, int> maxHealth = Ref<PlayerHealth, int>("maxHealth");

		private static readonly FieldRef<RunManager, bool> restarting = Ref<RunManager, bool>("restarting");

		private static readonly FieldRef<PhysGrabObject, PlayerAvatar> lastPlayerGrabbing = Ref<PhysGrabObject, PlayerAvatar>("lastPlayerGrabbing");

		private static readonly FieldRef<ShopManager, List<ItemAttributes>> shoppingList = Ref<ShopManager, List<ItemAttributes>>("shoppingList");

		private static readonly FieldRef<ItemAttributes, string> instanceName = Ref<ItemAttributes, string>("instanceName");

		private static readonly FieldRef<ItemUpgrade, bool> upgradeDone = Ref<ItemUpgrade, bool>("upgradeDone");

		private static readonly FieldRef<ItemEquippable, bool> isEquipped = Ref<ItemEquippable, bool>("isEquipped");

		private static readonly FieldRef<PhysGrabber, LayerMask> grabMask = Ref<PhysGrabber, LayerMask>("mask");

		internal static bool RespawnSupported
		{
			get
			{
				if (avatarDisabled != null && avatarDeathHead != null && headPhysics != null)
				{
					return headTriggered != null;
				}
				return false;
			}
		}

		internal static int GrabLayers(PhysGrabber grabber)
		{
			if (!((Object)(object)grabber != (Object)null) || grabMask == null)
			{
				return -1;
			}
			return ((LayerMask)(ref grabMask.Invoke(grabber))).value;
		}

		internal static bool IsDisabled(PlayerAvatar avatar)
		{
			if ((Object)(object)avatar != (Object)null && avatarDisabled != null)
			{
				return avatarDisabled.Invoke(avatar);
			}
			return false;
		}

		internal static PlayerDeathHead DeathHead(PlayerAvatar avatar)
		{
			if (!((Object)(object)avatar != (Object)null) || avatarDeathHead == null)
			{
				return null;
			}
			return avatarDeathHead.Invoke(avatar);
		}

		internal static PhysGrabObject HeadPhysics(PlayerDeathHead head)
		{
			if (!((Object)(object)head != (Object)null) || headPhysics == null)
			{
				return null;
			}
			return headPhysics.Invoke(head);
		}

		internal static bool HeadTriggered(PlayerDeathHead head)
		{
			if ((Object)(object)head != (Object)null && headTriggered != null)
			{
				return headTriggered.Invoke(head);
			}
			return false;
		}

		internal static int MaxHealth(PlayerHealth health)
		{
			if (!((Object)(object)health != (Object)null) || maxHealth == null)
			{
				return 100;
			}
			return maxHealth.Invoke(health);
		}

		internal static bool IsRestarting(RunManager manager)
		{
			if ((Object)(object)manager != (Object)null && restarting != null)
			{
				return restarting.Invoke(manager);
			}
			return false;
		}

		internal static PlayerAvatar LastHolder(PhysGrabObject item)
		{
			if (!((Object)(object)item != (Object)null) || lastPlayerGrabbing == null)
			{
				return null;
			}
			return lastPlayerGrabbing.Invoke(item);
		}

		internal static List<ItemAttributes> ShoppingList(ShopManager shop)
		{
			if (!((Object)(object)shop != (Object)null) || shoppingList == null)
			{
				return null;
			}
			return shoppingList.Invoke(shop);
		}

		internal static string InstanceName(ItemAttributes item)
		{
			if (!((Object)(object)item != (Object)null) || instanceName == null)
			{
				return null;
			}
			return instanceName.Invoke(item);
		}

		internal static bool UpgradeDone(ItemUpgrade upgrade)
		{
			if ((Object)(object)upgrade != (Object)null && upgradeDone != null)
			{
				return upgradeDone.Invoke(upgrade);
			}
			return false;
		}

		internal static bool IsEquipped(ItemEquippable item)
		{
			if ((Object)(object)item != (Object)null && isEquipped != null)
			{
				return isEquipped.Invoke(item);
			}
			return false;
		}

		private static FieldRef<T, F> Ref<T, F>(string name) where T : class
		{
			try
			{
				return AccessTools.FieldRefAccess<T, F>(name);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Couldn't find " + typeof(T).Name + "." + name + " (game update?). The feature that needs it is turned off. " + ex.Message));
				return null;
			}
		}
	}
	internal static class Net
	{
		internal const string Tag = "ImprovedShop";

		internal const byte RespawnRequest = 186;

		internal const byte RespawnStart = 187;

		internal const byte RespawnFinish = 188;

		internal const byte RespawnDenied = 189;

		internal const byte OwnerSet = 190;

		internal const byte OwnerCleared = 191;

		internal static void ToHost(byte code, params object[] data)
		{
			//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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			Send(code, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)2
			}, data);
		}

		internal static void ToAll(byte code, params object[] data)
		{
			//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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			Send(code, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)1
			}, data);
		}

		internal static void ToOthers(byte code, params object[] data)
		{
			//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)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			Send(code, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)0
			}, data);
		}

		internal static void ToPlayer(int actorNumber, byte code, params object[] data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			RaiseEventOptions val = new RaiseEventOptions();
			val.TargetActors = new int[1] { actorNumber };
			Send(code, val, data);
		}

		internal static void Send(byte code, RaiseEventOptions options, object[] data)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			object[] array = new object[data.Length + 1];
			array[0] = "ImprovedShop";
			data.CopyTo(array, 1);
			PhotonNetwork.RaiseEvent(code, (object)array, options, SendOptions.SendReliable);
		}

		internal static object[] Read(EventData photonEvent)
		{
			if (!(photonEvent.CustomData is object[] array) || array.Length == 0 || !(array[0] is string text) || text != "ImprovedShop")
			{
				return null;
			}
			object[] array2 = new object[array.Length - 1];
			Array.Copy(array, 1, array2, 0, array2.Length);
			return array2;
		}

		internal static bool FromHost(EventData photonEvent)
		{
			if (PhotonNetwork.MasterClient != null)
			{
				return photonEvent.Sender == PhotonNetwork.MasterClient.ActorNumber;
			}
			return false;
		}
	}
	internal static class Ownership
	{
		private sealed class Owner
		{
			public string SteamId;

			public string Name;

			public bool PickedUp;

			public int BoughtInLevel;
		}

		private sealed class Claim
		{
			public int ViewId;

			public string InstanceName;

			public string SteamId;

			public string Name;

			public bool GrabLocked;

			public bool UseLocked;

			public Owner Owner;

			public float OwnerMissingSince = -1f;
		}

		private const float OwnerGoneSeconds = 20f;

		private const float HostCheckInterval = 0.25f;

		private const float TagRange = 10f;

		private const float GrabHintRange = 5f;

		private static readonly float[] ResendDelays = new float[2] { 4f, 12f };

		private static readonly Dictionary<string, Owner> owners = new Dictionary<string, Owner>();

		private static readonly Dictionary<string, Queue<Owner>> waiting = new Dictionary<string, Queue<Owner>>();

		private static HashSet<string> previousLevelNames = new HashSet<string>();

		private static HashSet<string> nextLevelNames = new HashSet<string>();

		private static readonly Dictionary<string, Owner> levelItems = new Dictionary<string, Owner>();

		private static readonly Dictionary<string, int> levelViews = new Dictionary<string, int>();

		private static LevelGenerator levelToken;

		private static int levelCount;

		private static LevelGenerator claimsSentFor;

		private static List<KeyValuePair<string, PlayerAvatar>> checkout;

		private static readonly Dictionary<int, PlayerAvatar> shopHolders = new Dictionary<int, PlayerAvatar>();

		private static readonly HashSet<int> seenActors = new HashSet<int>();

		private static readonly List<KeyValuePair<int, float>> resends = new List<KeyValuePair<int, float>>();

		private static float nextHostCheck;

		private static readonly Dictionary<int, Claim> claims = new Dictionary<int, Claim>();

		private static float nextGrabHint;

		private static GUIStyle tagStyle;

		private static GUIStyle tagShadowStyle;

		private static int tagFontSize;

		private static float nextRefusalLog;

		private static bool HostActive
		{
			get
			{
				if (PhotonNetwork.IsMasterClient && (Object)(object)GameManager.instance != (Object)null && GameManager.Multiplayer())
				{
					return Plugin.OwnershipEnabled.Value;
				}
				return false;
			}
		}

		private static bool InPlayLevel
		{
			get
			{
				if (!SemiFunc.RunIsShop() && !SemiFunc.RunIsArena())
				{
					if (!SemiFunc.RunIsLobby())
					{
						return SemiFunc.RunIsLevel();
					}
					return true;
				}
				return false;
			}
		}

		private static bool LevelReady
		{
			get
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Invalid comparison between Unknown and I4
				if ((Object)(object)RunManager.instance != (Object)null && !GameAccess.IsRestarting(RunManager.instance) && (Object)(object)GameDirector.instance != (Object)null)
				{
					return (int)GameDirector.instance.currentState == 2;
				}
				return false;
			}
		}

		internal static void Tick()
		{
			if ((Object)(object)GameManager.instance == (Object)null || !GameManager.Multiplayer() || !PhotonNetwork.InRoom)
			{
				ResetAll();
				return;
			}
			if (PhotonNetwork.IsMasterClient && Time.unscaledTime >= nextHostCheck)
			{
				nextHostCheck = Time.unscaledTime + 0.25f;
				HostTick();
			}
			LockTick();
		}

		internal static void OnSceneLoaded()
		{
			if (claims.Count > 0)
			{
				Plugin.Log.LogDebug((object)$"Buyer owns it: scene loaded, forgetting {claims.Count} claim(s) from the last level.");
			}
			claims.Clear();
			shopHolders.Clear();
		}

		private static void ResetAll()
		{
			if (owners.Count != 0 || waiting.Count != 0 || claims.Count != 0 || seenActors.Count != 0 || levelItems.Count != 0 || previousLevelNames.Count != 0 || nextLevelNames.Count != 0 || shopHolders.Count != 0)
			{
				shopHolders.Clear();
				owners.Clear();
				waiting.Clear();
				previousLevelNames.Clear();
				nextLevelNames.Clear();
				levelItems.Clear();
				levelViews.Clear();
				levelToken = null;
				claimsSentFor = null;
				checkout = null;
				seenActors.Clear();
				resends.Clear();
				claims.Clear();
			}
		}

		internal static void ResetRun()
		{
			if (PhotonNetwork.IsMasterClient)
			{
				ClearClaimsForEveryone();
			}
			shopHolders.Clear();
			owners.Clear();
			waiting.Clear();
			previousLevelNames.Clear();
			nextLevelNames.Clear();
			levelItems.Clear();
			levelViews.Clear();
			levelToken = null;
			claims.Clear();
		}

		internal static void CheckoutStarting(bool firstOnly)
		{
			checkout = null;
			if (!HostActive || (Object)(object)ShopManager.instance == (Object)null)
			{
				return;
			}
			List<ItemAttributes> list = GameAccess.ShoppingList(ShopManager.instance);
			if (list == null)
			{
				return;
			}
			checkout = new List<KeyValuePair<string, PlayerAvatar>>();
			int num = (firstOnly ? Mathf.Min(1, list.Count) : list.Count);
			for (int i = 0; i < num; i++)
			{
				ItemAttributes val = list[i];
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.item == (Object)null))
				{
					checkout.Add(new KeyValuePair<string, PlayerAvatar>(((Object)val.item).name, LastHolderInShop(((Component)val).GetComponent<PhysGrabObject>())));
				}
			}
		}

		internal static void ItemGrabbed(PhysGrabObject item, int grabberViewId)
		{
			if (HostActive && !((Object)(object)item == (Object)null) && SemiFunc.RunIsShop())
			{
				PhotonView component = ((Component)item).GetComponent<PhotonView>();
				PhotonView val = PhotonView.Find(grabberViewId);
				PhysGrabber val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabber>() : null);
				if ((Object)(object)component != (Object)null && (Object)(object)val2 != (Object)null && (Object)(object)val2.playerAvatar != (Object)null)
				{
					shopHolders[component.ViewID] = val2.playerAvatar;
				}
			}
		}

		private static PlayerAvatar LastHolderInShop(PhysGrabObject item)
		{
			PlayerAvatar val = GameAccess.LastHolder(item);
			if ((Object)(object)val != (Object)null || (Object)(object)item == (Object)null)
			{
				return val;
			}
			PhotonView component = ((Component)item).GetComponent<PhotonView>();
			if ((Object)(object)component != (Object)null && shopHolders.TryGetValue(component.ViewID, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			return null;
		}

		internal static void CheckoutDone()
		{
			checkout = null;
		}

		internal static void ItemBought(string itemName)
		{
			if (checkout == null || string.IsNullOrEmpty(itemName))
			{
				return;
			}
			int num = checkout.FindIndex((KeyValuePair<string, PlayerAvatar> entry) => entry.Key == itemName);
			if (num < 0)
			{
				return;
			}
			PlayerAvatar value = checkout[num].Value;
			checkout.RemoveAt(num);
			if ((Object)(object)value == (Object)null || !Ownable(itemName))
			{
				return;
			}
			string text = SemiFunc.PlayerGetSteamID(value);
			if (!string.IsNullOrEmpty(text))
			{
				if (!waiting.TryGetValue(itemName, out var value2))
				{
					value2 = new Queue<Owner>();
					waiting[itemName] = value2;
				}
				value2.Enqueue(new Owner
				{
					SteamId = text,
					Name = PlayerName(value),
					BoughtInLevel = levelCount
				});
				Plugin.Log.LogInfo((object)(PlayerName(value) + " bought " + DisplayName(itemName) + "."));
			}
		}

		private static bool Ownable(string itemName)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Invalid comparison between Unknown and I4
			if ((Object)(object)StatsManager.instance == (Object)null || !StatsManager.instance.itemDictionary.TryGetValue(itemName, out var value) || (Object)(object)value == (Object)null)
			{
				return false;
			}
			if ((int)value.itemType != 2)
			{
				return (int)value.itemType != 5;
			}
			return false;
		}

		internal static void ItemNamed(string name, int viewId)
		{
			if (!HostActive || string.IsNullOrEmpty(name) || viewId <= 0 || !InPlayLevel)
			{
				return;
			}
			if (GameAccess.IsRestarting(RunManager.instance))
			{
				Plugin.Log.LogDebug((object)$"Buyer owns it: ignored {name} (view {viewId}), named while the level is changing.");
				return;
			}
			StartLevelIfNew();
			string text = ItemNameOf(name);
			Owner value = null;
			if (previousLevelNames.Contains(name))
			{
				owners.TryGetValue(name, out value);
			}
			else
			{
				owners.Remove(name);
				if (waiting.TryGetValue(text, out var value2) && value2.Count > 0)
				{
					value = value2.Dequeue();
					owners[name] = value;
				}
			}
			levelItems[name] = value;
			levelViews[name] = viewId;
			nextLevelNames.Add(name);
			Plugin.Log.LogDebug((object)string.Format("Buyer owns it: {0} (view {1}) appeared; {2}, owner {3}.", name, viewId, previousLevelNames.Contains(name) ? "was here last level" : "new", (value != null) ? value.Name : "none"));
			if (value != null)
			{
				AddClaim(viewId, name, value);
				Plugin.Log.LogInfo((object)(DisplayName(text) + " belongs to " + value.Name + " until they pick it up."));
			}
		}

		private static void StartLevelIfNew()
		{
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance == (Object)(object)levelToken)
			{
				return;
			}
			levelToken = instance;
			levelCount++;
			previousLevelNames = nextLevelNames;
			nextLevelNames = new HashSet<string>();
			levelItems.Clear();
			levelViews.Clear();
			foreach (Queue<Owner> value in waiting.Values)
			{
				while (value.Count > 0 && value.Peek().BoughtInLevel < levelCount - 1)
				{
					value.Dequeue();
				}
			}
		}

		private static void AddClaim(int viewId, string name, Owner owner)
		{
			PhotonView val = PhotonView.Find(viewId);
			if (!((Object)(object)val == (Object)null))
			{
				bool flag = (Object)(object)((Component)val).GetComponent<ItemUpgrade>() != (Object)null;
				Claim claim = new Claim
				{
					ViewId = viewId,
					InstanceName = name,
					SteamId = owner.SteamId,
					Name = owner.Name,
					GrabLocked = !owner.PickedUp,
					UseLocked = (flag && Plugin.LockUpgrades.Value),
					Owner = owner
				};
				if (claim.GrabLocked || claim.UseLocked)
				{
					claims[viewId] = claim;
					SendClaim(claim, -1);
				}
			}
		}

		private static void SendClaim(Claim claim, int actor)
		{
			object[] data = new object[6] { claim.ViewId, claim.InstanceName, claim.SteamId, claim.Name, claim.GrabLocked, claim.UseLocked };
			if (actor >= 0)
			{
				Net.ToPlayer(actor, 190, data);
			}
			else
			{
				Net.ToOthers(190, data);
			}
		}

		private static void RemoveClaim(int viewId)
		{
			if (claims.Remove(viewId))
			{
				Net.ToOthers(191, viewId);
			}
		}

		private static void ClearClaimsForEveryone()
		{
			foreach (int item in new List<int>(claims.Keys))
			{
				RemoveClaim(item);
			}
		}

		internal static void ItemRemoved(string instanceName)
		{
			if (PhotonNetwork.IsMasterClient && !string.IsNullOrEmpty(instanceName))
			{
				owners.Remove(instanceName);
				levelItems.Remove(instanceName);
				nextLevelNames.Remove(instanceName);
			}
		}

		internal static void UpgradeUsed(ItemUpgrade upgrade)
		{
			if (PhotonNetwork.IsMasterClient && !((Object)(object)upgrade == (Object)null))
			{
				PhotonView component = ((Component)upgrade).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					RemoveClaim(component.ViewID);
				}
				string text = GameAccess.InstanceName(((Component)upgrade).GetComponent<ItemAttributes>());
				if (!string.IsNullOrEmpty(text) && levelItems.Remove(text))
				{
					RepackForNextLevel(ItemNameOf(text));
				}
			}
		}

		private static void RepackForNextLevel(string itemName)
		{
			if ((Object)(object)StatsManager.instance == (Object)null)
			{
				return;
			}
			List<string> list = new List<string>();
			foreach (string key in StatsManager.instance.item.Keys)
			{
				if (key.Contains("/") && ItemNameOf(key) == itemName)
				{
					list.Add(key);
				}
			}
			List<Owner> list2 = new List<Owner>();
			foreach (string item in list)
			{
				if (levelItems.TryGetValue(item, out var value))
				{
					list2.Add(value);
				}
			}
			foreach (string item2 in list)
			{
				owners.Remove(item2);
				nextLevelNames.Remove(item2);
			}
			for (int i = 0; i < list2.Count && i < list.Count; i++)
			{
				nextLevelNames.Add(list[i]);
				if (list2[i] != null)
				{
					owners[list[i]] = list2[i];
				}
			}
		}

		private static void HostTick()
		{
			if (!Plugin.OwnershipEnabled.Value)
			{
				if (claims.Count > 0)
				{
					ClearClaimsForEveryone();
				}
				return;
			}
			ResendToNewPlayers();
			if (LevelReady && InPlayLevel)
			{
				RestoreClaims();
				ResendWhenLevelReady();
			}
			if (claims.Count == 0 || !LevelReady)
			{
				return;
			}
			List<int> list = new List<int>();
			List<Claim> list2 = new List<Claim>();
			List<Owner> list3 = new List<Owner>();
			foreach (Claim value in claims.Values)
			{
				PhotonView val = PhotonView.Find(value.ViewId);
				PhysGrabObject val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabObject>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					list.Add(value.ViewId);
					Plugin.Log.LogInfo((object)(value.Name + "'s " + DisplayName(ItemNameOf(value.InstanceName)) + " is gone (used up or destroyed)."));
					continue;
				}
				PlayerAvatar val3 = SemiFunc.PlayerAvatarGetFromSteamID(value.SteamId);
				if ((Object)(object)val3 == (Object)null)
				{
					if (value.OwnerMissingSince < 0f)
					{
						value.OwnerMissingSince = Time.time;
					}
					else if (Time.time - value.OwnerMissingSince > 20f && !list3.Contains(value.Owner))
					{
						list3.Add(value.Owner);
					}
					continue;
				}
				value.OwnerMissingSince = -1f;
				if (!value.GrabLocked)
				{
					continue;
				}
				if (IsHeldBy(val2, val3))
				{
					list2.Add(value);
					continue;
				}
				ItemEquippable component = ((Component)val).GetComponent<ItemEquippable>();
				if ((Object)(object)component != (Object)null && GameAccess.IsEquipped(component))
				{
					PlayerAvatar ownerPlayerAvatar = component.GetOwnerPlayerAvatar();
					if ((Object)(object)ownerPlayerAvatar == (Object)(object)val3)
					{
						list2.Add(value);
						continue;
					}
					list.Add(value.ViewId);
					Forget(value.Owner);
					Plugin.Log.LogWarning((object)(value.Name + "'s " + DisplayName(ItemNameOf(value.InstanceName)) + " was already in " + PlayerName(ownerPlayerAvatar) + "'s inventory, so it's no longer locked."));
				}
			}
			foreach (int item in list)
			{
				RemoveClaim(item);
			}
			foreach (Claim item2 in list2)
			{
				OwnerPickedUp(item2);
			}
			foreach (Owner item3 in list3)
			{
				OwnerLeft(item3);
			}
		}

		private static void RestoreClaims()
		{
			List<KeyValuePair<string, Owner>> list = null;
			foreach (KeyValuePair<string, Owner> levelItem in levelItems)
			{
				if (levelItem.Value != null && levelViews.TryGetValue(levelItem.Key, out var value) && !claims.ContainsKey(value))
				{
					PhotonView val = PhotonView.Find(value);
					ItemAttributes val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ItemAttributes>() : null);
					if (!((Object)(object)val2 == (Object)null) && !(GameAccess.InstanceName(val2) != levelItem.Key))
					{
						(list ?? (list = new List<KeyValuePair<string, Owner>>())).Add(levelItem);
					}
				}
			}
			if (list == null)
			{
				return;
			}
			foreach (KeyValuePair<string, Owner> item in list)
			{
				AddClaim(levelViews[item.Key], item.Key, item.Value);
				Plugin.Log.LogInfo((object)("Restored " + item.Value.Name + "'s claim on " + DisplayName(ItemNameOf(item.Key)) + " (it had gone missing)."));
			}
		}

		private static void ResendWhenLevelReady()
		{
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance == (Object)(object)claimsSentFor)
			{
				return;
			}
			claimsSentFor = instance;
			Player[] playerListOthers = PhotonNetwork.PlayerListOthers;
			foreach (Player val in playerListOthers)
			{
				float[] resendDelays = ResendDelays;
				foreach (float num in resendDelays)
				{
					resends.Add(new KeyValuePair<int, float>(val.ActorNumber, Time.unscaledTime + num));
				}
			}
		}

		private static bool IsHeldBy(PhysGrabObject physics, PlayerAvatar avatar)
		{
			foreach (PhysGrabber item in physics.playerGrabbing)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.playerAvatar == (Object)(object)avatar)
				{
					return true;
				}
			}
			return false;
		}

		private static void OwnerPickedUp(Claim claim)
		{
			if (claims.ContainsKey(claim.ViewId))
			{
				claim.Owner.PickedUp = true;
				if (claim.UseLocked)
				{
					claim.GrabLocked = false;
					SendClaim(claim, -1);
				}
				else
				{
					RemoveClaim(claim.ViewId);
					Forget(claim.Owner);
				}
				Plugin.Log.LogInfo((object)(claim.Name + " picked up their " + DisplayName(ItemNameOf(claim.InstanceName)) + "."));
			}
		}

		private static void OwnerLeft(Owner owner)
		{
			foreach (Claim item in new List<Claim>(claims.Values))
			{
				if (item.Owner == owner || item.SteamId == owner.SteamId)
				{
					RemoveClaim(item.ViewId);
				}
			}
			foreach (KeyValuePair<string, Owner> item2 in new List<KeyValuePair<string, Owner>>(owners))
			{
				if (item2.Value.SteamId == owner.SteamId)
				{
					Forget(item2.Value);
				}
			}
			foreach (Queue<Owner> value in waiting.Values)
			{
				List<Owner> list = new List<Owner>(value);
				list.RemoveAll((Owner o) => o.SteamId == owner.SteamId);
				value.Clear();
				list.ForEach(value.Enqueue);
			}
			Plugin.Log.LogInfo((object)(owner.Name + " left, so the items they bought are free for anyone now."));
		}

		private static void Forget(Owner owner)
		{
			foreach (KeyValuePair<string, Owner> item in new List<KeyValuePair<string, Owner>>(owners))
			{
				if (item.Value == owner)
				{
					owners.Remove(item.Key);
				}
			}
			foreach (KeyValuePair<string, Owner> item2 in new List<KeyValuePair<string, Owner>>(levelItems))
			{
				if (item2.Value == owner)
				{
					levelItems[item2.Key] = null;
				}
			}
		}

		private static void ResendToNewPlayers()
		{
			Player[] playerListOthers = PhotonNetwork.PlayerListOthers;
			foreach (Player val in playerListOthers)
			{
				if (seenActors.Add(val.ActorNumber))
				{
					float[] resendDelays = ResendDelays;
					foreach (float num in resendDelays)
					{
						resends.Add(new KeyValuePair<int, float>(val.ActorNumber, Time.unscaledTime + num));
					}
				}
			}
			for (int num2 = resends.Count - 1; num2 >= 0; num2--)
			{
				if (!(Time.unscaledTime < resends[num2].Value))
				{
					int key = resends[num2].Key;
					resends.RemoveAt(num2);
					if (PhotonNetwork.CurrentRoom == null || PhotonNetwork.CurrentRoom.GetPlayer(key, false) == null)
					{
						seenActors.Remove(key);
					}
					else
					{
						foreach (Claim value in claims.Values)
						{
							SendClaim(value, key);
						}
					}
				}
			}
		}

		internal static bool AllowGrab(PhysGrabObject item, int grabberViewId)
		{
			if (claims.Count == 0 || !PhotonNetwork.IsMasterClient || (Object)(object)item == (Object)null)
			{
				return true;
			}
			PhotonView component = ((Component)item).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null || !claims.TryGetValue(component.ViewID, out var value) || !value.GrabLocked)
			{
				return true;
			}
			PhotonView val = PhotonView.Find(grabberViewId);
			PhysGrabber val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<PhysGrabber>() : null);
			PlayerAvatar val3 = (((Object)(object)val2 != (Object)null) ? val2.playerAvatar : null);
			bool flag = (Object)(object)val3 != (Object)null && SemiFunc.PlayerGetSteamID(val3) == value.SteamId;
			if (!flag && Time.unscaledTime >= nextRefusalLog)
			{
				nextRefusalLog = Time.unscaledTime + 2f;
				Plugin.Log.LogDebug((object)("Buyer owns it: stopped " + (((Object)(object)val3 != (Object)null) ? PlayerName(val3) : "someone") + " picking up " + value.Name + "'s " + DisplayName(ItemNameOf(value.InstanceName)) + "."));
			}
			return flag;
		}

		internal static void OnEvent(EventData photonEvent)
		{
			byte code = photonEvent.Code;
			if ((code != 190 && code != 191) || PhotonNetwork.IsMasterClient || !Net.FromHost(photonEvent))
			{
				return;
			}
			object[] array = Net.Read(photonEvent);
			if (array == null || array.Length < 1 || !(array[0] is int num))
			{
				return;
			}
			if (code == 191)
			{
				if (claims.TryGetValue(num, out var value))
				{
					claims.Remove(num);
					Plugin.Log.LogDebug((object)$"Buyer owns it: host unlocked {value.Name}'s {DisplayName(ItemNameOf(value.InstanceName))} (view {num}).");
				}
			}
			else if (array.Length >= 6 && array[1] is string text && array[2] is string text2 && array[3] is string text3 && array[4] is bool flag && array[5] is bool flag2)
			{
				Claim claim = new Claim
				{
					ViewId = num,
					InstanceName = text,
					SteamId = text2,
					Name = text3,
					GrabLocked = flag,
					UseLocked = flag2
				};
				Claim value2;
				bool num2 = !claims.TryGetValue(num, out value2) || value2.InstanceName != text || value2.SteamId != text2 || value2.GrabLocked != flag || value2.UseLocked != flag2;
				claims[num] = claim;
				if (num2)
				{
					string text4 = (flag ? "locked until they pick it up" : (flag2 ? "only they can use it" : "not locked"));
					string text5 = (((Object)(object)Resolve(claim) != (Object)null) ? "" : " (no matching item here yet)");
					Plugin.Log.LogDebug((object)$"Buyer owns it: host says {text} (view {num}) is {text3}'s, {text4}{text5}.");
				}
			}
		}

		private static PhysGrabObject Resolve(Claim claim)
		{
			PhotonView val = PhotonView.Find(claim.ViewId);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			ItemAttributes component = ((Component)val).GetComponent<ItemAttributes>();
			if ((Object)(object)component == (Object)null)
			{
				return null;
			}
			string text = GameAccess.InstanceName(component);
			if (!string.IsNullOrEmpty(text) && text != claim.InstanceName)
			{
				return null;
			}
			return ((Component)val).GetComponent<PhysGrabObject>();
		}

		private static void LockTick()
		{
			if (claims.Count == 0)
			{
				return;
			}
			string text = LocalSteamId();
			foreach (Claim value in claims.Values)
			{
				if (value.GrabLocked && !(value.SteamId == text))
				{
					PhysGrabObject val = Resolve(value);
					if ((Object)(object)val != (Object)null)
					{
						val.OverrideGrabDisable(0.25f);
					}
				}
			}
			GrabHint(text);
		}

		private static void GrabHint(string me)
		{
			//IL_0033: 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_0087: 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)
			if (Time.unscaledTime < nextGrabHint || !SemiFunc.InputDown((InputKey)10) || !SemiFunc.NoTextInputsActive())
			{
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return;
			}
			RaycastHit[] array = Physics.RaycastAll(((Component)main).transform.position, ((Component)main).transform.forward, 5f, GameAccess.GrabLayers(PhysGrabber.instance), (QueryTriggerInteraction)1);
			Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
			RaycastHit[] array2 = array;
			for (int num = 0; num < array2.Length; num++)
			{
				RaycastHit val = array2[num];
				if (!((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerController>() != (Object)null) && !((Object)(object)((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PlayerAvatar>() != (Object)null))
				{
					PhysGrabObject componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent<PhysGrabObject>();
					PhotonView val2 = (((Object)(object)componentInParent != (Object)null) ? ((Component)componentInParent).GetComponent<PhotonView>() : null);
					if ((Object)(object)val2 != (Object)null && claims.TryGetValue(val2.ViewID, out var value) && value.GrabLocked && value.SteamId != me && (Object)(object)Resolve(value) == (Object)(object)componentInParent)
					{
						nextGrabHint = Time.unscaledTime + 2f;
						Respawn.ShowMessage("That's " + value.Name + "'s. Only they can pick it up until they've grabbed it once.");
						Plugin.Log.LogInfo((object)("You tried to pick up " + value.Name + "'s " + DisplayName(ItemNameOf(value.InstanceName)) + "; it's locked to them."));
					}
					break;
				}
			}
		}

		internal static bool AllowToggle(ItemToggle toggle, bool turningOn, int playerViewId, bool localPress)
		{
			if (!turningOn || claims.Count == 0 || (Object)(object)toggle == (Object)null)
			{
				return true;
			}
			PhotonView component = ((Component)toggle).GetComponent<PhotonView>();
			if ((Object)(object)component == (Object)null || !claims.TryGetValue(component.ViewID, out var value) || !value.UseLocked || (Object)(object)Resolve(value) == (Object)null)
			{
				return true;
			}
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(playerViewId);
			if ((Object)(object)val != (Object)null && SemiFunc.PlayerGetSteamID(val) == value.SteamId)
			{
				return true;
			}
			if (localPress)
			{
				Respawn.ShowMessage("This upgrade is " + value.Name + "'s. Only they can use it.");
				Plugin.Log.LogInfo((object)("You tried to use " + value.Name + "'s " + DisplayName(ItemNameOf(value.InstanceName)) + "; only they can."));
			}
			return false;
		}

		internal static int LocalAvatarViewId()
		{
			PlayerAvatar val = LocalAvatar();
			if (!((Object)(object)val != (Object)null) || !((Object)(object)val.photonView != (Object)null))
			{
				return -1;
			}
			return val.photonView.ViewID;
		}

		private static PlayerAvatar LocalAvatar()
		{
			if (!((Object)(object)PlayerController.instance != (Object)null))
			{
				return null;
			}
			return PlayerController.instance.playerAvatarScript;
		}

		private static string LocalSteamId()
		{
			PlayerAvatar val = LocalAvatar();
			if (!((Object)(object)val != (Object)null))
			{
				return null;
			}
			return SemiFunc.PlayerGetSteamID(val);
		}

		internal static void DrawTags()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//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_0073: 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_0086: Expected O, but got Unknown
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Expected O, but got Unknown
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: 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_00f9: 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)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7 || !Plugin.ShowOwnerTags.Value || claims.Count == 0)
			{
				return;
			}
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return;
			}
			int num = Mathf.Clamp(Screen.height / 45, 12, 30);
			if (tagStyle == null || tagFontSize != num)
			{
				tagFontSize = num;
				tagStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = num,
					alignment = (TextAnchor)4,
					fontStyle = (FontStyle)1
				};
				tagShadowStyle = new GUIStyle(tagStyle);
			}
			string text = LocalSteamId();
			Color color = GUI.color;
			Vector2 val4 = default(Vector2);
			Rect val5 = default(Rect);
			foreach (Claim value in claims.Values)
			{
				PhysGrabObject val = Resolve(value);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Vector3 val2 = val.centerPoint + Vector3.up * 0.4f;
				float num2 = Vector3.Distance(((Component)main).transform.position, val2);
				if (!(num2 > 10f))
				{
					Vector3 val3 = main.WorldToViewportPoint(val2);
					if (!(val3.z <= 0f) && !(val3.x < 0f) && !(val3.x > 1f) && !(val3.y < 0f) && !(val3.y > 1f))
					{
						bool flag = value.SteamId == text;
						string text2 = ((!flag) ? (value.GrabLocked ? (value.Name + "'s") : (value.Name + "'s upgrade")) : (value.GrabLocked ? "Yours" : "Your upgrade"));
						float num3 = Mathf.Clamp01((10f - num2) / 3f);
						((Vector2)(ref val4))..ctor(val3.x * (float)Screen.width, (1f - val3.y) * (float)Screen.height);
						((Rect)(ref val5))..ctor(val4.x - 200f, val4.y - (float)num, 400f, (float)num * 2f);
						tagShadowStyle.normal.textColor = new Color(0f, 0f, 0f, 0.85f * num3);
						GUI.Label(new Rect(((Rect)(ref val5)).x + 2f, ((Rect)(ref val5)).y + 2f, ((Rect)(ref val5)).width, ((Rect)(ref val5)).height), text2, tagShadowStyle);
						tagStyle.normal.textColor = (flag ? new Color(0.55f, 1f, 0.6f, num3) : new Color(1f, 0.75f, 0.35f, num3));
						GUI.Label(val5, text2, tagStyle);
					}
				}
			}
			GUI.color = color;
		}

		private static string ItemNameOf(string instanceName)
		{
			int num = instanceName.IndexOf('/');
			if (num < 0)
			{
				return instanceName;
			}
			return instanceName.Substring(0, num);
		}

		private static string DisplayName(string itemName)
		{
			if ((Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.itemDictionary.TryGetValue(itemName, out var value) && (Object)(object)value != (Object)null && !string.IsNullOrEmpty(value.itemName))
			{
				return value.itemName;
			}
			return itemName;
		}

		private static string PlayerName(PlayerAvatar avatar)
		{
			if (!((Object)(object)avatar != (Object)null) || !((Object)(object)avatar.photonView != (Object)null) || avatar.photonView.Owner == null)
			{
				return "Someone";
			}
			return avatar.photonView.Owner.NickName;
		}
	}
	[HarmonyPatch]
	internal static class OwnershipPurchasePatches
	{
		[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInShopList")]
		[HarmonyPrefix]
		private static void CheckoutOneStarting()
		{
			Safe(delegate
			{
				Ownership.CheckoutStarting(firstOnly: true);
			});
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyTheFirstPhysObjectsInShopList")]
		[HarmonyPostfix]
		private static void CheckoutOneDone()
		{
			Ownership.CheckoutDone();
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInShoppingList")]
		[HarmonyPrefix]
		private static void CheckoutAllStarting()
		{
			Safe(delegate
			{
				Ownership.CheckoutStarting(firstOnly: false);
			});
		}

		[HarmonyPatch(typeof(ExtractionPoint), "DestroyAllPhysObjectsInShoppingList")]
		[HarmonyPostfix]
		private static void CheckoutAllDone()
		{
			Ownership.CheckoutDone();
		}

		[HarmonyPatch(typeof(StatsManager), "ItemPurchase")]
		[HarmonyPrefix]
		private static void Bought(string itemName)
		{
			Safe(delegate
			{
				Ownership.ItemBought(itemName);
			});
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabPlayerAddRPC")]
		[HarmonyPostfix]
		private static void Grabbed(PhysGrabObject __instance, int photonViewID)
		{
			Safe(delegate
			{
				Ownership.ItemGrabbed(__instance, photonViewID);
			});
		}

		internal static void Safe(Action action)
		{
			try
			{
				action();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Buyer owns it: {arg}");
			}
		}
	}
	[HarmonyPatch]
	internal static class OwnershipLockPatches
	{
		[HarmonyPatch(typeof(PunManager), "SetItemNameLOGIC")]
		[HarmonyPostfix]
		private static void ItemNamed(string _name, int photonViewID)
		{
			OwnershipPurchasePatches.Safe(delegate
			{
				Ownership.ItemNamed(_name, photonViewID);
			});
		}

		[HarmonyPatch(typeof(StatsManager), "ItemRemove")]
		[HarmonyPostfix]
		private static void ItemRemoved(string instanceName)
		{
			OwnershipPurchasePatches.Safe(delegate
			{
				Ownership.ItemRemoved(instanceName);
			});
		}

		[HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")]
		[HarmonyPrefix]
		private static void UpgradeStarting(ItemUpgrade __instance, out bool __state)
		{
			__state = GameAccess.UpgradeDone(__instance);
		}

		[HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")]
		[HarmonyPostfix]
		private static void UpgradeDone(ItemUpgrade __instance, bool __state)
		{
			if (!__state && GameAccess.UpgradeDone(__instance))
			{
				OwnershipPurchasePatches.Safe(delegate
				{
					Ownership.UpgradeUsed(__instance);
				});
			}
		}

		[HarmonyPatch(typeof(RunManager), "ResetProgress")]
		[HarmonyPostfix]
		private static void RunReset()
		{
			OwnershipPurchasePatches.Safe(Ownership.ResetRun);
		}

		[HarmonyPatch(typeof(PhysGrabObject), "GrabStartedRPC")]
		[HarmonyPrefix]
		private static bool GrabStarting(PhysGrabObject __instance, int playerPhotonID)
		{
			try
			{
				return Ownership.AllowGrab(__instance, playerPhotonID);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Buyer owns it (grab): {arg}");
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemToggle), "ToggleItem")]
		[HarmonyPrefix]
		private static bool TogglePressed(ItemToggle __instance, bool toggle, int player)
		{
			try
			{
				bool localPress = player != -1 && player == Ownership.LocalAvatarViewId();
				return Ownership.AllowToggle(__instance, toggle, player, localPress);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Buyer owns it (use): {arg}");
				return true;
			}
		}

		[HarmonyPatch(typeof(ItemToggle), "ToggleItemLogic")]
		[HarmonyPrefix]
		private static bool ToggleApplying(ItemToggle __instance, bool toggle, int player)
		{
			try
			{
				return Ownership.AllowToggle(__instance, toggle, player, localPress: false);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Buyer owns it (use): {arg}");
				return true;
			}
		}
	}
	[BepInPlugin("ImprovedShop", "ImprovedShop", "1.0.0")]
	public sealed class Plugin : BaseUnityPlugin
	{
		public const string Guid = "ImprovedShop";

		public const string Name = "ImprovedShop";

		public const string Version = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> RespawnEnabled;

		internal static ConfigEntry<KeyCode> RespawnKey;

		internal static ConfigEntry<float> RespawnSeconds;

		internal static ConfigEntry<bool> RespawnInShop;

		internal static ConfigEntry<bool> RespawnInTruck;

		internal static ConfigEntry<int> RespawnHealthPercent;

		internal static ConfigEntry<float> RespawnProtectionSeconds;

		internal static ConfigEntry<bool> OwnershipEnabled;

		internal static ConfigEntry<bool> LockUpgrades;

		internal static ConfigEntry<bool> ShowOwnerTags;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_003a: Expected O, but got Unknown
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_004a: 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)
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			Harmony val = new Harmony("ImprovedShop");
			PatchClass(val, typeof(OwnershipPurchasePatches));
			PatchClass(val, typeof(OwnershipLockPatches));
			GameObject val2 = new GameObject("ImprovedShop");
			Object.DontDestroyOnLoad((Object)val2);
			((Object)val2).hideFlags = (HideFlags)61;
			val2.AddComponent<ImprovedShopController>();
			Log.LogInfo((object)("ImprovedShop 1.0.0 loaded. Respawn " + (RespawnEnabled.Value ? $"on ({RespawnKey.Value}, {RespawnSeconds.Value:0.#}s)" : "off") + ", buyer owns items " + (OwnershipEnabled.Value ? "on" : "off") + "."));
		}

		private static void PatchClass(Harmony harmony, Type patchClass)
		{
			try
			{
				harmony.CreateClassProcessor(patchClass).Patch();
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Couldn't apply {patchClass.Name} (a game update may have changed the code it patches): {arg}");
			}
		}

		private void BindConfig()
		{
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Expected O, but got Unknown
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Expected O, but got Unknown
			RespawnEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Respawn", "Enabled", true, "Let dead players respawn in the shop and the truck. The host's setting decides.");
			RespawnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Respawn", "Key", (KeyCode)114, "Key to press while dead to respawn. Your own setting.");
			RespawnSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Respawn", "Seconds", 5f, new ConfigDescription("How long the respawn takes: the head floats up, then the body comes back. The host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 15f), Array.Empty<object>()));
			RespawnInShop = ((BaseUnityPlugin)this).Config.Bind<bool>("Respawn", "In Shop", true, "Allow respawning in the shop. The host's setting decides.");
			RespawnInTruck = ((BaseUnityPlugin)this).Config.Bind<bool>("Respawn", "In Truck", true, "Allow respawning in the truck between levels. The host's setting decides.");
			RespawnHealthPercent = ((BaseUnityPlugin)this).Config.Bind<int>("Respawn", "Health Percent", 100, new ConfigDescription("Health after respawning, as a percent of max health. The host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
			RespawnProtectionSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Respawn", "Protection Seconds", 3f, new ConfigDescription("Seconds a respawned player can't be hurt, so nobody can kill them again right away. The host's setting decides.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 10f), Array.Empty<object>()));
			OwnershipEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Buyer Owns It", "Enabled", true, "Items bought in the shop belong to whoever put them in the checkout. In the truck, only that player can pick them up until they've grabbed them once, and only they can use an upgrade. The host's setting decides.");
			LockUpgrades = ((BaseUnityPlugin)this).Config.Bind<bool>("Buyer Owns It", "Upgrades Stay With Buyer", true, "Only the buyer can use an upgrade they bought, even after they've picked it up. Turn off to let players hand upgrades to each other. The host's setting decides.");
			ShowOwnerTags = ((BaseUnityPlugin)this).Config.Bind<bool>("Buyer Owns It", "Show Name Tags", true, "Show the owner's name above items that are still waiting for them. Your own setting.");
		}
	}
	internal sealed class ImprovedShopController : MonoBehaviour
	{
		internal static ImprovedShopController Instance;

		private void Awake()
		{
			Instance = this;
			PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void OnDestroy()
		{
			PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
			SceneManager.sceneLoaded -= OnSceneLoaded;
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			Ownership.OnSceneLoaded();
		}

		private void OnEvent(EventData photonEvent)
		{
			try
			{
				Respawn.OnEvent(photonEvent);
				Ownership.OnEvent(photonEvent);
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Network message error: {arg}");
			}
		}

		private void Update()
		{
			try
			{
				Respawn.Tick();
				Ownership.Tick();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Update error: {arg}");
			}
		}

		private void OnGUI()
		{
			try
			{
				Respawn.DrawPrompt();
				Ownership.DrawTags();
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Screen text error: {arg}");
			}
		}
	}
	internal static class Respawn
	{
		private sealed class Sequence
		{
			public PlayerAvatar Avatar;

			public int ViewId;

			public float StartTime;

			public float Duration;
		}

		private sealed class Glow
		{
			public PlayerAvatar Avatar;

			public GameObject Root;

			public Light Light;

			public ParticleSystem Swirl;

			public float StartTime;

			public float Duration;

			public bool Finishing;

			public float FinishTime;
		}

		private const float RiseHeight = 1.2f;

		private const float MinDeadSecondsBeforePrompt = 1f;

		private const float AnswerTimeout = 3f;

		private static readonly Dictionary<int, Sequence> sequences = new Dictionary<int, Sequence>();

		private static readonly Dictionary<int, Glow> glows = new Dictionary<int, Glow>();

		private static float deadSince = -1f;

		private static float requestedAt = -1f;

		private static float countdownStart = -1f;

		private static float countdownLength;

		private static string message;

		private static float messageUntil;

		private static GUIStyle promptStyle;

		private static GUIStyle shadowStyle;

		private static int styledFontSize;

		private static bool InShopOrTruck
		{
			get
			{
				if (!SemiFunc.RunIsShop())
				{
					return SemiFunc.RunIsLobby();
				}
				return true;
			}
		}

		private static bool HostAllowsHere
		{
			get
			{
				if (!SemiFunc.RunIsShop() || !Plugin.RespawnInShop.Value)
				{
					if (SemiFunc.RunIsLobby())
					{
						return Plugin.RespawnInTruck.Value;
					}
					return false;
				}
				return true;
			}
		}

		private static bool LevelReady
		{
			get
			{
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Invalid comparison between Unknown and I4
				if ((Object)(object)RunManager.instance != (Object)null && !GameAccess.IsRestarting(RunManager.instance) && (Object)(object)GameDirector.instance != (Object)null)
				{
					return (int)GameDirector.instance.currentState == 2;
				}
				return false;
			}
		}

		private static PlayerAvatar LocalAvatar
		{
			get
			{
				if (!((Object)(object)PlayerController.instance != (Object)null))
				{
					return null;
				}
				return PlayerController.instance.playerAvatarScript;
			}
		}

		internal static bool IsDead(PlayerAvatar avatar)
		{
			PlayerDeathHead val = GameAccess.DeathHead(avatar);
			if (GameAccess.IsDisabled(avatar) && (Object)(object)val != (Object)null)
			{
				return GameAccess.HeadTriggered(val);
			}
			return false;
		}

		internal static void Tick()
		{
			if (!GameAccess.RespawnSupported || (Object)(object)GameManager.instance == (Object)null || !GameManager.Multiplayer() || !PhotonNetwork.InRoom)
			{
				ClearAll();
				return;
			}
			LocalTick();
			if (PhotonNetwork.IsMasterClient)
			{
				HostTick();
			}
			GlowTick();
		}

		private static void ClearAll()
		{
			sequences.Clear();
			foreach (Glow value in glows.Values)
			{
				if ((Object)(object)value.Root != (Object)null)
				{
					Object.Destroy((Object)(object)value.Root);
				}
			}
			glows.Clear();
			deadSince = -1f;
			requestedAt = -1f;
			countdownStart = -1f;
		}

		private static void LocalTick()
		{
			//IL_00e8: 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)
			PlayerAvatar localAvatar = LocalAvatar;
			if ((Object)(object)localAvatar == (Object)null || !IsDead(localAvatar) || !InShopOrTruck)
			{
				deadSince = -1f;
				requestedAt = -1f;
				countdownStart = -1f;
				return;
			}
			if (deadSince < 0f)
			{
				deadSince = Time.unscaledTime;
			}
			if (requestedAt >= 0f && countdownStart < 0f && Time.unscaledTime - requestedAt > 3f)
			{
				requestedAt = -1f;
				ShowMessage("No answer from the host. The host needs ImprovedShop for respawning.");
				Plugin.Log.LogWarning((object)"Respawn: no answer from the host (does the host have ImprovedShop?).");
			}
			if (Plugin.RespawnEnabled.Value && Time.unscaledTime - deadSince >= 1f && requestedAt < 0f && countdownStart < 0f && LevelReady && Input.GetKeyDown(Plugin.RespawnKey.Value) && SemiFunc.NoTextInputsActive())
			{
				requestedAt = Time.unscaledTime;
				int viewID = localAvatar.photonView.ViewID;
				if (PhotonNetwork.IsMasterClient)
				{
					HandleRequest(viewID, PhotonNetwork.LocalPlayer.ActorNumber);
					return;
				}
				Plugin.Log.LogInfo((object)$"Respawn: you pressed {Plugin.RespawnKey.Value}; asking the host.");
				Net.ToHost(186, viewID);
			}
		}

		internal static void ShowMessage(string text)
		{
			message = text;
			messageUntil = Time.unscaledTime + 4f;
		}

		private static void HandleRequest(int viewId, int senderActor)
		{
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			string text = null;
			if (!Plugin.RespawnEnabled.Value)
			{
				text = "The host has respawning turned off.";
			}
			else if (!HostAllowsHere)
			{
				text = (InShopOrTruck ? "The host has respawning turned off here." : "You can only respawn in the shop or the truck.");
			}
			else if (!LevelReady)
			{
				text = "Wait until everyone has loaded in.";
			}
			else if ((Object)(object)val == (Object)null || (Object)(object)val.photonView == (Object)null || val.photonView.OwnerActorNr != senderActor)
			{
				text = "The host couldn't find your player.";
			}
			else
			{
				if (sequences.ContainsKey(viewId))
				{
					return;
				}
				if (!IsDead(val))
				{
					text = "You're already back.";
				}
			}
			if (text != null)
			{
				Plugin.Log.LogInfo((object)("Respawn: refused " + (((Object)(object)val != (Object)null) ? Name(val) : $"player {senderActor}") + ": " + text));
				if (senderActor == PhotonNetwork.LocalPlayer.ActorNumber)
				{
					requestedAt = -1f;
					ShowMessage(text);
				}
				else
				{
					Net.ToPlayer(senderActor, 189, viewId, text);
				}
			}
			else
			{
				StartSequence(val, viewId);
			}
		}

		private static void StartSequence(PlayerAvatar avatar, int viewId)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: 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_0063: 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)
			PhysGrabObject val = GameAccess.HeadPhysics(GameAccess.DeathHead(avatar));
			if (!((Object)(object)val == (Object)null))
			{
				TruckSafetySpawnPoint instance = TruckSafetySpawnPoint.instance;
				if ((Object)(object)instance != (Object)null && val.centerPoint.y < ((Component)instance).transform.position.y - 25f)
				{
					val.Teleport(((Component)instance).transform.position + Vector3.up * 0.5f, Quaternion.identity);
				}
				float value = Plugin.RespawnSeconds.Value;
				sequences[viewId] = new Sequence
				{
					Avatar = avatar,
					ViewId = viewId,
					StartTime = Time.time,
					Duration = value
				};
				Net.ToAll(187, viewId, value);
				Plugin.Log.LogInfo((object)$"{Name(avatar)} is respawning ({value:0.#}s).");
			}
		}

		private static void HostTick()
		{
			if (sequences.Count == 0)
			{
				return;
			}
			if (!LevelReady || !InShopOrTruck)
			{
				sequences.Clear();
				return;
			}
			List<int> list = new List<int>();
			foreach (Sequence value in sequences.Values)
			{
				PlayerAvatar avatar = value.Avatar;
				PhysGrabObject val = GameAccess.HeadPhysics(GameAccess.DeathHead(avatar));
				if ((Object)(object)avatar == (Object)null || (Object)(object)val == (Object)null || !IsDead(avatar))
				{
					list.Add(value.ViewId);
					Net.ToAll(188, value.ViewId, 0f, false);
					continue;
				}
				float num = Mathf.Clamp01((Time.time - value.StartTime) / value.Duration);
				FloatHead(val, num, value.Duration);
				if (num >= 1f)
				{
					list.Add(value.ViewId);
					Finish(value);
				}
			}
			foreach (int item in list)
			{
				sequences.Remove(item);
			}
		}

		private static void FloatHead(PhysGrabObject head, float t, float duration)
		{
			//IL_0084: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			head.OverrideZeroGravity(0.2f);
			head.OverrideGrabDisable(0.2f);
			head.OverrideIndestructible(0.2f);
			head.OverrideDrag(4f, 0.2f);
			head.OverrideAngularDrag(2f, 0.2f);
			Rigidbody rb = head.rb;
			if (!((Object)(object)rb == (Object)null) && !rb.isKinematic)
			{
				float num = (SomethingAbove(head, rb) ? 0f : (1.2f / duration * Mathf.SmoothStep(0.4f, 1.4f, t)));
				rb.linearVelocity = Vector3.up * num;
				rb.angularVelocity = new Vector3(0f, Mathf.Lerp(0.5f, 4f, t), 0f);
			}
		}

		private static bool SomethingAbove(PhysGrabObject head, Rigidbody body)
		{
			//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)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit[] array = Physics.RaycastAll(head.centerPoint, Vector3.up, 0.45f, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < array.Length; i++)
			{
				RaycastHit val = array[i];
				if ((Object)(object)((RaycastHit)(ref val)).rigidbody != (Object)(object)body)
				{
					return true;
				}
			}
			return false;
		}

		private static void Finish(Sequence sequence)
		{
			PlayerAvatar avatar = sequence.Avatar;
			avatar.Revive(false);
			int num = GameAccess.MaxHealth(avatar.playerHealth);
			int num2 = Mathf.Max(1, Mathf.RoundToInt((float)(num * Plugin.RespawnHealthPercent.Value) / 100f));
			if (num2 > 1)
			{
				avatar.playerHealth.HealOther(num2 - 1, true);
			}
			Net.ToAll(188, sequence.ViewId, Plugin.RespawnProtectionSeconds.Value, true);
			Plugin.Log.LogInfo((object)$"{Name(avatar)} respawned with {num2} health.");
		}

		internal static void OnEvent(EventData photonEvent)
		{
			byte code = photonEvent.Code;
			if (code < 186 || code > 189)
			{
				return;
			}
			object[] array = Net.Read(photonEvent);
			if (array == null || array.Length < 1 || !(array[0] is int viewId))
			{
				return;
			}
			switch (code)
			{
			case 186:
				if (PhotonNetwork.IsMasterClient)
				{
					HandleRequest(viewId, photonEvent.Sender);
				}
				break;
			case 187:
				if (!Net.FromHost(photonEvent) || array.Length < 2 || !(array[1] is float num))
				{
					break;
				}
				StartGlow(viewId, num);
				if (IsLocalView(viewId))
				{
					countdownStart = Time.unscaledTime;
					countdownLength = num;
					if (!PhotonNetwork.IsMasterClient)
					{
						Plugin.Log.LogInfo((object)$"Respawn: the host is bringing you back ({num:0.#}s).");
					}
				}
				break;
			case 188:
				if (!Net.FromHost(photonEvent) || array.Length < 3 || !(array[1] is float num2) || !(array[2] is bool flag))
				{
					break;
				}
				FinishGlow(viewId, flag);
				if (flag && num2 > 0f && (Object)(object)ImprovedShopController.Instance != (Object)null)
				{
					((MonoBehaviour)ImprovedShopController.Instance).StartCoroutine(Protect(viewId, num2));
				}
				if (IsLocalView(viewId))
				{
					requestedAt = -1f;
					countdownStart = -1f;
					if (!PhotonNetwork.IsMasterClient)
					{
						Plugin.Log.LogInfo((object)(flag ? $"Respawn: you're back ({num2:0.#}s of protection)." : "Respawn: cancelled (you were already revived, or the level changed)."));
					}
				}
				break;
			case 189:
				if (Net.FromHost(photonEvent) && IsLocalView(viewId) && array.Length >= 2 && array[1] is string text)
				{
					requestedAt = -1f;
					ShowMessage(text);
					Plugin.Log.LogInfo((object)("Respawn: the host said no: " + text));
				}
				break;
			}
		}

		private static bool IsLocalView(int viewId)
		{
			PlayerAvatar localAvatar = LocalAvatar;
			if ((Object)(object)localAvatar != (Object)null && (Object)(object)localAvatar.photonView != (Object)null)
			{
				return localAvatar.photonView.ViewID == viewId;
			}
			return false;
		}

		private static IEnumerator Protect(int viewId, float seconds)
		{
			yield return null;
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			if ((Object)(object)val != (Object)null && (Object)(object)val.playerHealth != (Object)null)
			{
				val.playerHealth.InvincibleSet(seconds);
			}
		}

		private static void StartGlow(int viewId, float duration)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0052: 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_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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)
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			PlayerDeathHead val2 = GameAccess.DeathHead(val);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			if (glows.TryGetValue(viewId, out var value) && (Object)(object)value.Root != (Object)null)
			{
				Object.Destroy((Object)(object)value.Root);
			}
			GameObject val3 = new GameObject("ImprovedShop Respawn Glow");
			val3.transform.position = HeadCenter(val2);
			Light val4 = val3.AddComponent<Light>();
			val4.type = (LightType)2;
			val4.color = new Color(0.45f, 1f, 0.75f);
			val4.range = 3f;
			val4.intensity = 0f;
			ParticleSystem val5 = null;
			if ((Object)(object)val.playerReviveEffects != (Object)null && (Object)(object)val.playerReviveEffects.swirlParticle != (Object)null)
			{
				GameObject obj = Object.Instantiate<GameObject>(((Component)val.playerReviveEffects.swirlParticle).gameObject, val3.transform);
				obj.transform.localPosition = Vector3.zero;
				obj.SetActive(true);
				val5 = obj.GetComponent<ParticleSystem>();
				if ((Object)(object)val5 != (Object)null)
				{
					MainModule main = val5.main;
					((MainModule)(ref main)).loop = true;
					val5.Play(true);
				}
			}
			glows[viewId] = new Glow
			{
				Avatar = val,
				Root = val3,
				Light = val4,
				Swirl = val5,
				StartTime = Time.unscaledTime,
				Duration = duration
			};
		}

		private static void FinishGlow(int viewId, bool revived)
		{
			if (!glows.TryGetValue(viewId, out var value) || (Object)(object)value.Root == (Object)null)
			{
				glows.Remove(viewId);
				return;
			}
			value.Finishing = true;
			value.FinishTime = Time.unscaledTime;
			if ((Object)(object)value.Swirl != (Object)null)
			{
				value.Swirl.Stop(true, (ParticleSystemStopBehavior)1);
			}
			if (revived && (Object)(object)value.Light != (Object)null)
			{
				value.Light.intensity = 8f;
			}
		}

		private static void GlowTick()
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			if (glows.Count == 0)
			{
				return;
			}
			List<int> list = new List<int>();
			foreach (KeyValuePair<int, Glow> glow in glows)
			{
				Glow value = glow.Value;
				if ((Object)(object)value.Root == (Object)null)
				{
					list.Add(glow.Key);
					continue;
				}
				if (value.Finishing)
				{
					float num = (Time.unscaledTime - value.FinishTime) / 0.6f;
					if ((Object)(object)value.Light != (Object)null)
					{
						value.Light.intensity = Mathf.Lerp(8f, 0f, num);
					}
					if (num >= 2.5f)
					{
						Object.Destroy((Object)(object)value.Root);
						list.Add(glow.Key);
					}
					continue;
				}
				PlayerDeathHead val = GameAccess.DeathHead(value.Avatar);
				if ((Object)(object)val != (Object)null && GameAccess.HeadTriggered(val))
				{
					value.Root.transform.position = HeadCenter(val);
				}
				float num2 = Mathf.Clamp01((Time.unscaledTime - value.StartTime) / value.Duration);
				float num3 = 0.8f + 0.2f * Mathf.Sin(Time.unscaledTime * (6f + 10f * num2));
				if ((Object)(object)value.Light != (Object)null)
				{
					value.Light.intensity = Mathf.Lerp(0.6f, 4f, num2) * num3;
				}
				if (Time.unscaledTime - value.StartTime > value.Duration + 5f)
				{
					FinishGlow(glow.Key, revived: false);
				}
			}
			foreach (int item in list)
			{
				glows.Remove(item);
			}
		}

		private static Vector3 HeadCenter(PlayerDeathHead head)
		{
			//IL_001d: 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)
			PhysGrabObject val = GameAccess.HeadPhysics(head);
			if (!((Object)(object)val != (Object)null))
			{
				return ((Component)head).transform.position;
			}
			return val.centerPoint;
		}

		private static string Name(PlayerAvatar avatar)
		{
			if (!((Object)(object)avatar != (Object)null) || !((Object)(object)avatar.photonView != (Object)null) || avatar.photonView.Owner == null)
			{
				return "A player";
			}
			return avatar.photonView.Owner.NickName;
		}

		internal static void DrawPrompt()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Invalid comparison between Unknown and I4
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Expected O, but got Unknown
			//IL_016e: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			if ((int)Event.current.type != 7)
			{
				return;
			}
			string text = null;
			if (message != null && Time.unscaledTime < messageUntil)
			{
				text = message;
			}
			else if (deadSince >= 0f)
			{
				if (countdownStart >= 0f)
				{
					int num = Mathf.Max(1, Mathf.CeilToInt(countdownLength - (Time.unscaledTime - countdownStart)));
					text = $"Respawning in {num}...";
				}
				else if (requestedAt >= 0f)
				{
					text = "Respawning...";
				}
				else if (Plugin.RespawnEnabled.Value && Time.unscaledTime - deadSince >= 1f)
				{
					text = $"Press <b>[{Plugin.RespawnKey.Value}]</b> to respawn";
				}
			}
			if (text != null)
			{
				int num2 = Mathf.Clamp(Screen.height / 28, 14, 44);
				if (promptStyle == null || styledFontSize != num2)
				{
					styledFontSize = num2;
					promptStyle = new GUIStyle(GUI.skin.label)
					{
						fontSize = num2,
						alignment = (TextAnchor)4,
						richText = true
					};
					promptStyle.normal.textColor = new Color(0.55f, 1f, 0.75f);
					shadowStyle = new GUIStyle(promptStyle);
					shadowStyle.normal.textColor = new Color(0f, 0f, 0f, 0.85f);
				}
				Rect val = default(Rect);
				((Rect)(ref val))..ctor(0f, (float)Screen.height * 0.62f, (float)Screen.width, (float)num2 * 2f);
				string text2 = text.Replace("<b>", "").Replace("</b>", "");
				GUI.Label(new Rect(((Rect)(ref val)).x + 2f, ((Rect)(ref val)).y + 2f, ((Rect)(ref val)).width, ((Rect)(ref val)).height), text2, shadowStyle);
				GUI.Label(val, text, promptStyle);
			}
		}
	}
}