Decompiled source of Monster PvP v0.6.3

BepInEx/plugins/RepoPvp/RepoPvp.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("RepoPvp.Diagnostics")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RepoPvp")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.6.3.0")]
[assembly: AssemblyInformationalVersion("0.6.3+a3bd65b3944df2809e53be8ff99b301d1c8b8db1")]
[assembly: AssemblyProduct("RepoPvp")]
[assembly: AssemblyTitle("RepoPvp")]
[assembly: AssemblyVersion("0.6.3.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 RepoPvp
{
	internal sealed class AttackFollowUp : MonoBehaviour
	{
		private int actor;

		private int epoch;

		private int mob;

		private string readyState;

		private float expires;

		private float nextAttempt;

		internal static void Schedule(Monster monster, string ready)
		{
			Session current = Session.Current;
			Pilot pilot = (Object.op_Implicit((Object)(object)current) ? current.PilotFor((Component)(object)monster.Controller) : null);
			if (pilot != null)
			{
				AttackFollowUp obj = ((Component)monster.Controller).GetComponent<AttackFollowUp>() ?? ((Component)monster.Controller).gameObject.AddComponent<AttackFollowUp>();
				obj.actor = pilot.Actor;
				obj.epoch = pilot.Epoch;
				obj.mob = pilot.Mob;
				obj.readyState = ready;
				obj.expires = Time.unscaledTime + 10f;
				obj.nextAttempt = Time.unscaledTime + 0.1f;
			}
		}

		private void Update()
		{
			Session current = Session.Current;
			Pilot pilot = (Object.op_Implicit((Object)(object)current) ? current.Teams.Find(actor) : null);
			Monster monster = (Object.op_Implicit((Object)(object)current) ? current.MonsterFor(pilot) : null);
			if (!Object.op_Implicit((Object)(object)current) || !current.IsHost || !Session.Playing || pilot == null || pilot.Epoch != epoch || pilot.Mob != mob || monster == null || !monster.CanAttack || Time.unscaledTime >= expires)
			{
				Object.Destroy((Object)(object)this);
			}
			else
			{
				if ((!(monster.State == readyState) && (!(readyState == "Chase") || !(monster.State == "ChaseSlow"))) || Time.unscaledTime < nextAttempt)
				{
					return;
				}
				nextAttempt = Time.unscaledTime + 0.1f;
				try
				{
					if (NativeActions.TryPerform(monster, 0, pilot.Yaw, pilot.Pitch, out var _))
					{
						Object.Destroy((Object)(object)this);
					}
				}
				catch (Exception ex)
				{
					current.Owner.Error("Requested attack continuation failed for " + monster.Kind + ": " + ex);
					Object.Destroy((Object)(object)this);
				}
			}
		}

		private void OnDisable()
		{
			Object.Destroy((Object)(object)this);
		}
	}
	internal static class AttackRules
	{
		internal static bool AllowTransition(string kind, string current, string next, bool requested)
		{
			if (requested || ControlRules.AutomaticStance(kind))
			{
				return true;
			}
			switch (kind)
			{
			case "EnemyAnimal":
				if (next != "PlayerNotice")
				{
					if (!(next != "WreakHavoc"))
					{
						return current == "GoToPlayer";
					}
					return true;
				}
				return false;
			case "EnemyBang":
				if (next != "FuseDelay")
				{
					if (!(next != "Fuse"))
					{
						return current == "FuseDelay";
					}
					return true;
				}
				return false;
			case "EnemyBeamer":
				if (next != "AttackStart" && next != "MeleeStart" && (next != "Melee" || current == "MeleeStart"))
				{
					if (!(next != "Attack"))
					{
						return current == "AttackStart";
					}
					return true;
				}
				return false;
			case "EnemyBombThrower":
				if (next != "Attack")
				{
					return next != "Melee";
				}
				return false;
			case "EnemyBowtie":
				if (next != "PlayerNotice")
				{
					if (!(next != "Yell"))
					{
						return current == "PlayerNotice";
					}
					return true;
				}
				return false;
			case "EnemyCeilingEye":
				return next != "HasTarget";
			case "EnemyFloater":
				return next != "ChargeAttack";
			case "EnemyGnome":
				if (next != "NoticeDelay")
				{
					if (!(next != "AttackMove"))
					{
						switch (current)
						{
						case "Notice":
						case "MoveBack":
						case "Attack":
							break;
						default:
							goto IL_04c5;
						}
					}
					if (!(next != "Attack"))
					{
						switch (current)
						{
						default:
							return current == "MoveBack";
						case "AttackMove":
						case "MoveUnder":
						case "MoveOver":
							break;
						}
					}
					return true;
				}
				goto IL_04c5;
			case "EnemyHeadGrabber":
				if (next != "Attack" && (next != "GotoHead" || current == "GotoHeadOver" || current == "BackToNavmesh"))
				{
					if (!(next != "GrabHead") && !(current == "GotoHead"))
					{
						return current == "GotoHeadOver";
					}
					return true;
				}
				return false;
			case "EnemyHeartHugger":
				if (next != "LureStart")
				{
					return next != "ChompGasp";
				}
				return false;
			case "EnemyHidden":
				return next != "PlayerPickup";
			case "EnemyHunter":
				return next != "Aim";
			case "EnemyOogly":
				return next != "PlayerSpotted";
			case "EnemyShadow":
				if (next != "Slap")
				{
					return next != "StuckAttack";
				}
				return false;
			case "EnemySlowMouth":
				if (next != "Attack" && next != "Puke")
				{
					return next != "IdlePuke";
				}
				return false;
			case "EnemySlowWalker":
				if (next != "Attack" && next != "StuckAttack")
				{
					return next != "LookUnderAttack";
				}
				return false;
			case "EnemySpinny":
				return next != "WaitForRoulette";
			case "EnemyThinMan":
				return next != "Notice";
			case "EnemyTick":
				if (next != "Notice" && (next != "Tumble" || current == "Notice") && (next != "Bite" || current == "Notice" || current == "Tumble"))
				{
					if (!(next != "RideVehicle") && !(current == "Notice") && !(current == "Tumble"))
					{
						return current == "Bite";
					}
					return true;
				}
				return false;
			case "EnemyTricycle":
				if (next != "StateBeforeAttack" && next != "BellRing" && (next != "BellRing2" || current == "BellRing"))
				{
					if (!(next != "BellRing3"))
					{
						return current == "BellRing2";
					}
					return true;
				}
				return false;
			case "EnemyTumbler":
				return next != "Tell";
			case "EnemyUpscream":
				return next != "Attack";
			case "EnemyValuableThrower":
				return next != "Throw";
			default:
				{
					return true;
				}
				IL_04c5:
				return false;
			}
		}

		internal static string RecoveryState(string kind, string current, string next)
		{
			if (kind == "EnemyGnome" && current == "AttackDone" && next == "AttackMove")
			{
				return "Move";
			}
			if (kind == "EnemyTricycle" && current == "BellRing3" && next == "StateBeforeAttack")
			{
				return "Roam";
			}
			return null;
		}
	}
	internal static class Bindings
	{
		internal static bool Pressed(KeyboardShortcut shortcut)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			ButtonControl val = Control(((KeyboardShortcut)(ref shortcut)).MainKey);
			if (val == null || !val.wasPressedThisFrame)
			{
				return false;
			}
			foreach (KeyCode modifier in ((KeyboardShortcut)(ref shortcut)).Modifiers)
			{
				ButtonControl val2 = Control(modifier);
				if (val2 == null || !val2.isPressed)
				{
					return false;
				}
			}
			return true;
		}

		private unsafe static ButtonControl Control(KeyCode code)
		{
			//IL_0006: 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_0026: Expected I4, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Invalid comparison between Unknown and I4
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Expected I4, but got Unknown
			//IL_014a: 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)
			Mouse current = Mouse.current;
			switch (code - 323)
			{
			case 0:
				if (current == null)
				{
					return null;
				}
				return current.leftButton;
			case 1:
				if (current == null)
				{
					return null;
				}
				return current.rightButton;
			case 2:
				if (current == null)
				{
					return null;
				}
				return current.middleButton;
			case 3:
				if (current == null)
				{
					return null;
				}
				return current.backButton;
			case 4:
				if (current == null)
				{
					return null;
				}
				return current.forwardButton;
			default:
			{
				Keyboard current2 = Keyboard.current;
				if (current2 == null || (int)code == 0)
				{
					return null;
				}
				string text = ((object)(*(KeyCode*)(&code))/*cast due to .constrained prefix*/).ToString();
				if (text.StartsWith("Alpha", StringComparison.Ordinal))
				{
					text = "Digit" + text.Substring(5);
				}
				else if (text.StartsWith("Keypad", StringComparison.Ordinal))
				{
					text = "Numpad" + text.Substring(6);
				}
				if ((int)code != 13)
				{
					switch (code - 300)
					{
					case 6:
						text = "LeftCtrl";
						break;
					case 5:
						text = "RightCtrl";
						break;
					case 10:
					case 11:
						text = "LeftMeta";
						break;
					case 9:
					case 12:
						text = "RightMeta";
						break;
					case 0:
						text = "NumLock";
						break;
					case 1:
						text = "CapsLock";
						break;
					}
				}
				else
				{
					text = "Enter";
				}
				if (!Enum.TryParse<Key>(text, ignoreCase: true, out Key result) || (int)result == 0)
				{
					return null;
				}
				return (ButtonControl)(object)current2[result];
			}
			}
		}
	}
	internal enum BalloonState : byte
	{
		Ready,
		Cooldown,
		Busy,
		NoSpace,
		Placing,
		Syncing
	}
	internal sealed class BirthdayBalloons : MonoBehaviour
	{
		[HarmonyPatch(typeof(EnemyBirthdayBoy), "UpdateState")]
		private static class Placement
		{
			[HarmonyPrefix]
			private static bool Before(EnemyBirthdayBoy __instance, State __0, out bool __state)
			{
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Invalid comparison between Unknown and I4
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Invalid comparison between Unknown and I4
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Invalid comparison between Unknown and I4
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Invalid comparison between Unknown and I4
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Invalid comparison between Unknown and I4
				//IL_005e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0064: Invalid comparison between Unknown and I4
				Session current = Session.Current;
				bool flag = Object.op_Implicit((Object)(object)current) && current.IsHost && Session.Playing && current.OwnsController((Component)(object)__instance);
				__state = flag && (int)__instance.currentState == 4 && (int)__0 == 5;
				if (!flag || ManualAttacks.HasRequest((Component)(object)__instance))
				{
					return true;
				}
				if ((int)__0 == 3)
				{
					return false;
				}
				if ((int)__0 == 4 && (int)__instance.currentState != 4)
				{
					return (int)__instance.currentState == 3;
				}
				return true;
			}

			[HarmonyPostfix]
			private static void After(EnemyBirthdayBoy __instance, bool __state)
			{
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Invalid comparison between Unknown and I4
				if (__state && (int)__instance.currentState == 5)
				{
					(((Component)__instance).GetComponent<BirthdayBalloons>() ?? ((Component)__instance).gameObject.AddComponent<BirthdayBalloons>()).readyAt = Time.unscaledTime + 8f;
				}
			}
		}

		internal const float Recovery = 8f;

		private float readyAt;

		internal static BalloonState Read(Monster monster, out float seconds)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Invalid comparison between Unknown and I4
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			EnemyBirthdayBoy val = (EnemyBirthdayBoy)monster.Controller;
			BirthdayBalloons component = ((Component)val).GetComponent<BirthdayBalloons>();
			seconds = (Object.op_Implicit((Object)(object)component) ? Mathf.Max(0f, component.readyAt - Time.unscaledTime) : 0f);
			if ((int)val.currentState == 4)
			{
				return BalloonState.Placing;
			}
			if (seconds > 0f)
			{
				return BalloonState.Cooldown;
			}
			if (!monster.CanAttack || !Passive(val.currentState))
			{
				return BalloonState.Busy;
			}
			if (NativeActions.Call(val, "GetNonCollidingBalloonSpawnPoints") is List<int> list)
			{
				foreach (int item in list)
				{
					if (!(bool)NativeActions.Call(val, "NearbyDoor", val.balloonSpawnPoints[item].position))
					{
						return BalloonState.Ready;
					}
				}
			}
			return BalloonState.NoSpace;
		}

		internal static bool Place(Monster monster, out string message)
		{
			float seconds;
			BalloonState balloonState = Read(monster, out seconds);
			if (balloonState != BalloonState.Ready)
			{
				message = balloonState switch
				{
					BalloonState.NoSpace => "Move somewhere with space for balloons.", 
					BalloonState.Cooldown => "Balloons ready in " + Mathf.CeilToInt(seconds) + "s.", 
					_ => "Finish the current action before placing balloons.", 
				};
				return false;
			}
			NativeActions.Write(monster.Controller, "SkipStateImpulse", false);
			bool flag = NativeActions.SetState(monster, "PlaceBalloon");
			message = (flag ? "Placing balloons." : "Balloon placement is unavailable.");
			return flag;
		}

		private static bool Passive(State state)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Invalid comparison between Unknown and I4
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			if ((int)state != 2 && (int)state != 11 && (int)state != 9 && (int)state != 10)
			{
				return (int)state == 12;
			}
			return true;
		}

		private void OnDisable()
		{
			readyAt = 0f;
		}
	}
	internal static class ControlRules
	{
		internal const string Protocol = "repo-pvp/10";

		internal const float InputTimeout = 0.35f;

		internal const float EchoDuration = 2f;

		internal const float PulsePeriod = 2.5f;

		internal const float PulseDuration = 0.45f;

		internal const float PulseRadius = 8f;

		internal static float EchoRemaining(int now, int sent)
		{
			return Math.Max(0f, 2f - (float)Math.Max(0, now - sent) / 1000f);
		}

		internal static bool ClipPingSegment(float distanceSquared, float lengthSquared, float dot, out float start, out float end)
		{
			start = 0f;
			end = 1f;
			if (lengthSquared < 1E-07f)
			{
				return distanceSquared <= 64f;
			}
			float num = dot * dot - lengthSquared * (distanceSquared - 64f);
			if (num < 0f)
			{
				return false;
			}
			float num2 = (float)Math.Sqrt(num);
			start = Math.Max(0f, (0f - dot - num2) / lengthSquared);
			end = Math.Min(1f, (0f - dot + num2) / lengthSquared);
			return end > start;
		}

		internal static bool IsRetreat(string state)
		{
			if (state != null)
			{
				if (!state.StartsWith("Leave", StringComparison.Ordinal) && !state.StartsWith("Despawn", StringComparison.Ordinal) && !state.StartsWith("RunAway", StringComparison.Ordinal))
				{
					switch (state)
					{
					default:
						return state == "Death";
					case "TeleportOut":
					case "RiderPanic":
					case "Dead":
						break;
					}
				}
				return true;
			}
			return false;
		}

		internal static bool IsUnavailable(string state)
		{
			if (state != null && !IsRetreat(state) && !state.StartsWith("Spawn", StringComparison.Ordinal))
			{
				switch (state)
				{
				default:
					return state == "AppearAtLevelPoint";
				case "PopUpSpawn":
				case "TeleportIn":
				case "FindCeiling":
					break;
				}
			}
			return true;
		}

		internal static bool GroupRetreatComplete(string directorState, string memberState, float distance, bool destinationChanged)
		{
			if (directorState != null && directorState != "Leave")
			{
				if (!(directorState != "Idle" || destinationChanged))
				{
					if (memberState == "Idle" && Finite(distance) && distance >= 0f)
					{
						return distance <= 2.05f;
					}
					return false;
				}
				return true;
			}
			return false;
		}

		internal static bool GroupRetreatSuperseded(string directorState)
		{
			if (!string.IsNullOrEmpty(directorState) && directorState != "Leave")
			{
				return directorState != "Idle";
			}
			return false;
		}

		internal static bool AutomaticStance(string kind)
		{
			switch (kind)
			{
			default:
				return kind == "EnemyRobe";
			case "EnemyDuck":
			case "EnemyElsa":
			case "EnemyBirthdayBoy":
			case "EnemyRunner":
				return true;
			}
		}

		internal static bool SteeringStance(string kind, string state)
		{
			if ((!(kind == "EnemyDuck") || (!(state == "ChaseTowards") && !(state == "ChaseNavmesh"))) && (!(kind == "EnemyBirthdayBoy") || !(state == "Attack")) && (!(kind == "EnemyRunner") || !(state == "AttackPlayer")) && (!(kind == "EnemyRobe") || (!(state == "Attack") && !(state == "TargetPlayer"))))
			{
				if (kind == "EnemyValuableThrower")
				{
					return state == "TargetPlayer";
				}
				return false;
			}
			return true;
		}

		internal static bool CanSteer(string state)
		{
			switch (state)
			{
			default:
				return state == "ChaseSlow";
			case "Idle":
			case "Roam":
			case "RoamFast":
			case "RoamAggro":
			case "Investigate":
			case "InvestigateFast":
			case "InvestigateWalk":
			case "Sneak":
			case "IdleSmall":
			case "RoamSmall":
			case "InvestigateSmall":
			case "SeekPlayer":
			case "GoToPlayer":
			case "GotoPlayer":
			case "PlayerGoTo":
			case "GoToPlayerSmall":
			case "GoToPlayerBig":
			case "GoToTarget":
			case "MoveToPlayer":
			case "Move":
			case "Follow":
			case "Seek":
			case "Search":
			case "GoToPlayerAngry":
			case "Chase":
			case "CeilingRoam":
			case "Roaming":
				return true;
			}
		}

		internal static int Cycle(IReadOnlyList<int> available, int current, int direction)
		{
			if (available.Count == 0)
			{
				return 0;
			}
			int num = -1;
			for (int i = 0; i < available.Count; i++)
			{
				if (available[i] == current)
				{
					num = i;
					break;
				}
			}
			if (num < 0)
			{
				if (direction >= 0)
				{
					return available[0];
				}
				return available[available.Count - 1];
			}
			return available[(num + ((direction >= 0) ? 1 : (-1)) + available.Count) % available.Count];
		}

		internal static bool Finite(float f)
		{
			if (!float.IsNaN(f))
			{
				return !float.IsInfinity(f);
			}
			return false;
		}

		internal static bool ValidInput(float x, float y, float yaw, float pitch)
		{
			if (Finite(x) && Finite(y) && Finite(yaw) && Finite(pitch) && Math.Abs(x) <= 1.01f && Math.Abs(y) <= 1.01f && yaw >= 0f && yaw < 360f)
			{
				return Math.Abs(pitch) <= 80f;
			}
			return false;
		}

		internal static bool ValidAction(byte action, float yaw, float pitch)
		{
			if (action <= 1)
			{
				return ValidInput(0f, 0f, yaw, pitch);
			}
			return false;
		}

		internal static bool NewSequence(int incoming, int previous)
		{
			uint num = (uint)(incoming - previous);
			if (num != 0)
			{
				return num < 2147483648u;
			}
			return false;
		}
	}
	[HarmonyPatch]
	internal static class EquipmentPolicy
	{
		internal static bool Blocked(Item item)
		{
			if (Object.op_Implicit((Object)(object)item))
			{
				return ItemRules.Blocked(((object)Unsafe.As<itemType, itemType>(ref item.itemType)/*cast due to .constrained prefix*/).ToString(), ((Object)item).name, ((PrefabRef<GameObject>)(object)item.prefab)?.ResourcePath);
			}
			return false;
		}

		[HarmonyPatch(typeof(ShopManager), "GetAllItemsFromStatsManager")]
		[HarmonyPostfix]
		private static void Shop(ShopManager __instance)
		{
			Filter(__instance.potentialItems);
			Filter(__instance.potentialItemConsumables);
			Filter(__instance.potentialItemUpgrades);
			Filter(__instance.potentialItemHealthPacks);
			foreach (List<Item> value in __instance.potentialSecretItems.Values)
			{
				Filter(value);
			}
		}

		[HarmonyPatch(typeof(ItemManager), "GetPurchasedItems")]
		[HarmonyPostfix]
		private static void Truck(ItemManager __instance)
		{
			Filter(__instance.purchasedItems);
		}

		private static void Filter(List<Item> items)
		{
			items.RemoveAll(Blocked);
		}

		[HarmonyPatch(typeof(PunManager), "ItemSpawnApply")]
		[HarmonyPrefix]
		private static bool Spawn(object __0)
		{
			PrefabRef val = NativeActions.Read<PrefabRef>(__0, "prefab");
			if (val == null || !((PrefabRef<GameObject>)(object)val).IsValid())
			{
				return true;
			}
			GameObject prefab = ((PrefabRef<GameObject>)(object)val).Prefab;
			ItemAttributes val2 = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponentInChildren<ItemAttributes>(true) : null);
			if (Object.op_Implicit((Object)(object)val2))
			{
				return !Blocked(val2.item);
			}
			return true;
		}

		[HarmonyPatch(typeof(ItemAttributes), "Start")]
		[HarmonyPrefix]
		private static bool Existing(ItemAttributes __instance)
		{
			if (!Blocked(__instance.item))
			{
				return true;
			}
			((Component)__instance).gameObject.SetActive(false);
			if (SemiFunc.IsMasterClientOrSingleplayer() && Object.op_Implicit((Object)(object)Plugin.Instance))
			{
				((MonoBehaviour)Plugin.Instance).StartCoroutine(Remove(((Component)__instance).gameObject));
			}
			return false;
		}

		private static IEnumerator Remove(GameObject item)
		{
			yield return null;
			if (!Object.op_Implicit((Object)(object)item))
			{
				yield break;
			}
			PhotonView component = item.GetComponent<PhotonView>();
			if (PhotonNetwork.InRoom && Object.op_Implicit((Object)(object)component) && component.ViewID != 0)
			{
				if (PhotonNetwork.IsMasterClient)
				{
					PhotonNetwork.Destroy(((Component)component).gameObject);
				}
			}
			else
			{
				Object.Destroy((Object)(object)item);
			}
		}
	}
	internal static class ItemRules
	{
		internal static bool Blocked(string type, string asset, string prefab)
		{
			if (type == "grenade")
			{
				return false;
			}
			string text = (asset + " " + prefab).Replace(" ", "").Replace("_", "").Replace("-", "");
			if (type == "launcher" && text.IndexOf("staff", StringComparison.OrdinalIgnoreCase) >= 0)
			{
				return false;
			}
			if (type == "gun" || type == "launcher")
			{
				return true;
			}
			if (text.IndexOf("cartcannon", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("cartlaser", StringComparison.OrdinalIgnoreCase) < 0)
			{
				if (type == "melee" && text.IndexOf("hammer", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return text.IndexOf("inflatablehammer", StringComparison.OrdinalIgnoreCase) < 0;
				}
				return false;
			}
			return true;
		}
	}
	internal sealed class LobbyTeams : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__8_0;

			internal void <Start>b__8_0()
			{
				Session.Current?.ToggleRole();
			}
		}

		private MenuPageLobby page;

		private MenuButton choose;

		private TextMeshProUGUI choiceText;

		private TextMeshProUGUI capacity;

		private GameObject ownedRoot;

		private string previousChoice;

		private readonly Dictionary<MenuPlayerListed, TextMeshProUGUI> badges = new Dictionary<MenuPlayerListed, TextMeshProUGUI>();

		private static readonly Color MonsterInk = new Color(1f, 0.79f, 0.22f);

		private void Start()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Expected O, but got Unknown
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Expected O, but got Unknown
			page = ((Component)this).GetComponent<MenuPageLobby>();
			if (!Object.op_Implicit((Object)(object)page) || !Object.op_Implicit((Object)(object)page.customizeButton))
			{
				return;
			}
			GameObject val = (ownedRoot = new GameObject("Monster team choice", new Type[1] { typeof(RectTransform) }));
			val.SetActive(false);
			val.transform.SetParent(((Component)page.customizeButton).transform.parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			Vector2 val2 = (component.offsetMin = (component.offsetMax = Vector2.zero));
			GameObject val4 = Object.Instantiate<GameObject>(((Component)page.customizeButton).gameObject, val.transform, false);
			((Object)val4).name = "Monster PvP team button";
			choose = val4.GetComponent<MenuButton>();
			choose.buttonTextString = "TEAM: SURVIVOR";
			choose.holdLogic = false;
			choose.hasHold = false;
			choiceText = val4.GetComponentInChildren<TextMeshProUGUI>(true);
			((TMP_Text)choiceText).text = choose.buttonTextString;
			val4.GetComponent<RectTransform>().anchoredPosition = ((Component)page.customizeButton).GetComponent<RectTransform>().anchoredPosition + new Vector2(0f, 42f);
			Button component2 = val4.GetComponent<Button>();
			component2.onClick = new ButtonClickedEvent();
			ButtonClickedEvent onClick = component2.onClick;
			object obj = <>c.<>9__8_0;
			if (obj == null)
			{
				UnityAction val5 = delegate
				{
					Session.Current?.ToggleRole();
				};
				<>c.<>9__8_0 = val5;
				obj = (object)val5;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			capacity = Label(((Component)page.inviteButton).transform, "Monster slots", choiceText, 14);
			RectTransform rectTransform = ((TMP_Text)capacity).rectTransform;
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			rectTransform.anchorMax = val2;
			rectTransform.anchorMin = val2;
			rectTransform.pivot = new Vector2(0.5f, 0.5f);
			rectTransform.anchoredPosition = new Vector2(0f, 42f);
			rectTransform.sizeDelta = new Vector2(130f, 24f);
			((TMP_Text)capacity).alignment = (TextAlignmentOptions)514;
			((Graphic)capacity).color = MonsterInk;
			val.SetActive(true);
		}

		private void LateUpdate()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: 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_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			Session current = Session.Current;
			if (!Object.op_Implicit((Object)(object)current) || !Object.op_Implicit((Object)(object)page) || !Object.op_Implicit((Object)(object)choose))
			{
				return;
			}
			bool flag = current.HasRole(Session.LocalActor);
			string text = (flag ? "TEAM: MONSTER" : "TEAM: SURVIVOR");
			if (text != previousChoice || ((TMP_Text)choiceText).text != text)
			{
				previousChoice = text;
				((TMP_Text)choiceText).text = text;
				choose.buttonTextString = text;
				choose.ResizeToText();
			}
			bool flag2 = !current.CanChooseTeam || (!flag && current.Teams.Count >= current.MonsterCapacity);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			Vector3[] array2 = (Vector3[])(object)new Vector3[4];
			((Component)page.customizeButton).GetComponent<RectTransform>().GetWorldCorners(array);
			((Component)choose).GetComponent<RectTransform>().GetWorldCorners(array2);
			Transform transform = ((Component)choose).transform;
			transform.position += array[0] + ((Component)page.customizeButton).transform.TransformVector(new Vector3(0f, 42f, 0f)) - array2[0];
			NativeActions.Write(choose, "disabled", flag2);
			((TMP_Text)capacity).text = ((current.MonsterCapacity == 0) ? "PVP: 2+ PLAYERS" : ("MONSTERS " + current.Teams.Count + "/" + current.MonsterCapacity));
			MenuPlayerListed[] componentsInChildren = ((Component)page).GetComponentsInChildren<MenuPlayerListed>(true);
			Vector2 val3 = default(Vector2);
			foreach (MenuPlayerListed val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val.playerName))
				{
					continue;
				}
				Player val2 = NativeActions.Read<Player>(val, "playerPhoton");
				if (val2 != null)
				{
					if (!badges.TryGetValue(val, out var value) || !Object.op_Implicit((Object)(object)value))
					{
						value = Label(((TMP_Text)val.playerName).transform, "PvP team", val.playerName, 12);
						RectTransform rectTransform = ((TMP_Text)value).rectTransform;
						RectTransform rectTransform2 = ((TMP_Text)value).rectTransform;
						((Vector2)(ref val3))..ctor(1f, 0.5f);
						rectTransform2.anchorMax = val3;
						rectTransform.anchorMin = val3;
						((TMP_Text)value).rectTransform.pivot = new Vector2(0f, 0.5f);
						((TMP_Text)value).rectTransform.anchoredPosition = new Vector2(80f, 0f);
						((TMP_Text)value).rectTransform.sizeDelta = new Vector2(90f, 22f);
						((TMP_Text)value).alignment = (TextAlignmentOptions)4097;
						badges[val] = value;
					}
					bool flag3 = current.HasRole(val2.ActorNumber);
					((TMP_Text)value).text = (flag3 ? "MONSTER" : "SURVIVOR");
					((Graphic)value).color = (Color)(flag3 ? MonsterInk : new Color(0.78f, 0.8f, 0.75f));
				}
			}
			List<MenuPlayerListed> list = new List<MenuPlayerListed>();
			foreach (KeyValuePair<MenuPlayerListed, TextMeshProUGUI> badge in badges)
			{
				if (!Object.op_Implicit((Object)(object)badge.Key))
				{
					list.Add(badge.Key);
				}
			}
			foreach (MenuPlayerListed item in list)
			{
				badges.Remove(item);
			}
		}

		private static TextMeshProUGUI Label(Transform parent, string name, TextMeshProUGUI style, int size)
		{
			//IL_0014: 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_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)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			TextMeshProUGUI obj = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = ((TMP_Text)style).font;
			((TMP_Text)obj).fontSharedMaterial = ((TMP_Text)style).fontSharedMaterial;
			((TMP_Text)obj).fontSize = size;
			((TMP_Text)obj).fontStyle = (FontStyles)2;
			((TMP_Text)obj).textWrappingMode = (TextWrappingModes)0;
			((TMP_Text)obj).outlineColor = Color32.op_Implicit(Color.black);
			((TMP_Text)obj).outlineWidth = 0.17f;
			((Graphic)obj).raycastTarget = false;
			return obj;
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)capacity))
			{
				Object.Destroy((Object)(object)((Component)capacity).gameObject);
			}
			if (Object.op_Implicit((Object)(object)ownedRoot))
			{
				Object.Destroy((Object)(object)ownedRoot);
			}
		}
	}
	[HarmonyPatch]
	internal static class ManualAttacks
	{
		internal readonly struct Request : IDisposable
		{
			private readonly Component previous;

			internal Request(Component controller)
			{
				previous = requestedController;
				requestedController = controller;
			}

			public void Dispose()
			{
				requestedController = previous;
			}
		}

		[ThreadStatic]
		private static Component requestedController;

		internal static readonly Type[] Controllers = new Type[23]
		{
			typeof(EnemyAnimal),
			typeof(EnemyBang),
			typeof(EnemyBeamer),
			typeof(EnemyBombThrower),
			typeof(EnemyBowtie),
			typeof(EnemyCeilingEye),
			typeof(EnemyFloater),
			typeof(EnemyGnome),
			typeof(EnemyHeadGrabber),
			typeof(EnemyHeartHugger),
			typeof(EnemyHidden),
			typeof(EnemyHunter),
			typeof(EnemyOogly),
			typeof(EnemyShadow),
			typeof(EnemySlowMouth),
			typeof(EnemySlowWalker),
			typeof(EnemySpinny),
			typeof(EnemyThinMan),
			typeof(EnemyTick),
			typeof(EnemyTricycle),
			typeof(EnemyTumbler),
			typeof(EnemyUpscream),
			typeof(EnemyValuableThrower)
		};

		internal static bool HasRequest(Component component)
		{
			return (Object)(object)requestedController == (Object)(object)component;
		}

		private static Monster Controlled(Component component)
		{
			Session current = Session.Current;
			if (!Object.op_Implicit((Object)(object)current) || !current.IsHost || !Session.Playing)
			{
				return null;
			}
			Pilot pilot = current.PilotFor(component);
			if (pilot == null)
			{
				EnemyParent componentInParent = component.GetComponentInParent<EnemyParent>();
				if (Object.op_Implicit((Object)(object)componentInParent))
				{
					foreach (Pilot pilot2 in current.Teams.Pilots)
					{
						if ((Object)(object)current.MonsterFor(pilot2)?.Parent == (Object)(object)componentInParent)
						{
							pilot = pilot2;
							break;
						}
					}
				}
			}
			Monster monster = current.MonsterFor(pilot);
			if (monster == null || ControlRules.AutomaticStance(monster.Kind))
			{
				return null;
			}
			return monster;
		}

		internal static bool Requested(Component component)
		{
			Monster monster = Controlled(component);
			if (monster != null)
			{
				return (Object)(object)monster.Controller == (Object)(object)requestedController;
			}
			return true;
		}

		private static IEnumerable<MethodBase> TargetMethods()
		{
			Type[] controllers = Controllers;
			foreach (Type type in controllers)
			{
				MethodInfo methodInfo = null;
				string[] array = new string[3] { "UpdateState", "StateSet", "SetState" };
				foreach (string text in array)
				{
					foreach (MethodInfo declaredMethod in AccessTools.GetDeclaredMethods(type))
					{
						ParameterInfo[] parameters = declaredMethod.GetParameters();
						if (declaredMethod.Name == text && parameters.Length == 1 && parameters[0].ParameterType.IsEnum)
						{
							methodInfo = declaredMethod;
							break;
						}
					}
					if (methodInfo != null)
					{
						break;
					}
				}
				if (methodInfo == null)
				{
					throw new MissingMethodException(type.Name, "native state setter");
				}
				yield return methodInfo;
			}
		}

		[HarmonyPrefix]
		private static bool Transition(Component __instance, object __0)
		{
			Monster monster = Controlled(__instance);
			if (monster == null || AttackRules.AllowTransition(monster.Kind, monster.State, __0.ToString(), (Object)(object)monster.Controller == (Object)(object)requestedController))
			{
				return true;
			}
			string text = AttackRules.RecoveryState(monster.Kind, monster.State, __0.ToString());
			if (text != null)
			{
				NativeActions.SetState(monster, text);
			}
			return false;
		}
	}
	[HarmonyPatch]
	internal static class ManualAttackChecks
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			string[] array = new string[8] { "TongueAttackCheck", "TryStartDefensiveAttack", "BackKickApproachTry", "FrontPunchTry", "FrustratedPhysObjectAttackTry", "StuckPhysObjectAttackCheck", "SetStateTongueAttackTellPlayer", "SetStateTongueAttackTellPhysObject" };
			foreach (string text in array)
			{
				yield return AccessTools.Method(typeof(EnemySnatcher), text, (Type[])null, (Type[])null) ?? throw new MissingMethodException("EnemySnatcher", text);
			}
			array = new string[2] { "AttackSetLogic", "MeleeSetLogic" };
			foreach (string text2 in array)
			{
				yield return AccessTools.Method(typeof(EnemyBombThrower), text2, (Type[])null, (Type[])null);
			}
			yield return AccessTools.Method(typeof(EnemyHeadGrabber), "AttackSet", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(EnemyHeadGrabber), "NearbyHeadLogic", (Type[])null, (Type[])null);
		}

		[HarmonyPrefix]
		private static bool Check(Component __instance, ref bool __result)
		{
			if (ManualAttacks.Requested(__instance))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	[HarmonyPatch]
	internal static class ManualAttackPerception
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			foreach (Type type in new List<Type>(ManualAttacks.Controllers) { typeof(EnemySnatcher) })
			{
				string[] array = new string[3] { "OnVision", "OnVisionTrigger", "OnVisionTriggered" };
				foreach (string name in array)
				{
					MethodInfo methodInfo = AccessTools.GetDeclaredMethods(type).Find((MethodInfo candidate) => candidate.Name == name);
					if (type != typeof(EnemyValuableThrower) && methodInfo != null && methodInfo.ReturnType == typeof(void))
					{
						yield return methodInfo;
					}
				}
			}
		}

		[HarmonyPrefix]
		private static bool Perception(Component __instance)
		{
			return ManualAttacks.Requested(__instance);
		}
	}
	[HarmonyPatch]
	internal static class ManualAttackCallbacks
	{
		[HarmonyPatch(typeof(EnemyHeadAnimationSystem), "ChaseBiteTrigger")]
		[HarmonyPrefix]
		private static bool Headman(EnemyHeadAnimationSystem __instance)
		{
			return ManualAttacks.Requested((Component)(object)__instance);
		}

		[HarmonyPatch(typeof(EnemyHunter), "OnInvestigate")]
		[HarmonyPrefix]
		private static bool Huntsman(EnemyHunter __instance)
		{
			return ManualAttacks.Requested((Component)(object)__instance);
		}

		[HarmonyPatch(typeof(EnemySnatcher), "BackKickSenseTick")]
		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> KickSense(IEnumerable<CodeInstruction> instructions, ILGenerator generator)
		{
			FieldInfo timer = AccessTools.Field(typeof(EnemySnatcher), "backKickSenseTimer");
			bool guarded = false;
			foreach (CodeInstruction instruction in instructions)
			{
				yield return instruction;
				if (!guarded && !(instruction.opcode != OpCodes.Stfld) && object.Equals(instruction.operand, timer))
				{
					guarded = true;
					Label run = generator.DefineLabel();
					yield return new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					yield return new CodeInstruction(OpCodes.Call, (object)AccessTools.Method(typeof(ManualAttacks), "Requested", (Type[])null, (Type[])null));
					yield return new CodeInstruction(OpCodes.Brtrue, (object)run);
					yield return new CodeInstruction(OpCodes.Ret, (object)null);
					CodeInstruction val = new CodeInstruction(OpCodes.Nop, (object)null);
					((IList)AccessTools.Field(typeof(CodeInstruction), "labels").GetValue(val)).Add(run);
					yield return val;
				}
			}
			if (!guarded)
			{
				throw new InvalidOperationException("Unsupported Snatcher kick-sense timers");
			}
		}
	}
	internal sealed class Monster
	{
		internal readonly Enemy Enemy;

		internal readonly MonoBehaviour Controller;

		internal readonly FieldInfo StateField;

		internal readonly FieldInfo RotationField;

		internal readonly EnemyParent Parent;

		internal readonly EnemyVision Vision;

		internal readonly EnemyStateInvestigate Hearing;

		internal readonly EnemyNavMeshAgent Navigation;

		internal readonly NavMeshAgent Agent;

		internal readonly EnemyRigidbody Body;

		internal readonly int Id;

		internal readonly string Kind;

		internal readonly string Name;

		private static readonly Dictionary<Type, FieldInfo> StateFields = new Dictionary<Type, FieldInfo>();

		private static readonly Dictionary<Type, FieldInfo> RotationFields = new Dictionary<Type, FieldInfo>();

		private static readonly FieldInfo ForceLeaveField = AccessTools.Field(typeof(EnemyParent), "forceLeave");

		private static readonly FieldInfo SetupDoneField = AccessTools.Field(typeof(EnemyParent), "SetupDone");

		private static readonly FieldInfo FrozenField = AccessTools.Field(typeof(EnemyRigidbody), "frozen");

		private static readonly FieldInfo GrabbedField = AccessTools.Field(typeof(EnemyRigidbody), "grabbed");

		private static readonly FieldInfo BangDirector = AccessTools.Field(typeof(EnemyBangDirector), "instance");

		private static readonly FieldInfo GnomeDirector = AccessTools.Field(typeof(EnemyGnomeDirector), "instance");

		private static readonly FieldInfo HealthDead = AccessTools.Field(typeof(EnemyHealth), "dead");

		private static readonly FieldInfo HealthDying = AccessTools.Field(typeof(EnemyHealth), "deadImpulse");

		private object Director
		{
			get
			{
				if (!(Kind == "EnemyBang"))
				{
					if (!(Kind == "EnemyGnome"))
					{
						return null;
					}
					return GnomeDirector?.GetValue(null);
				}
				return BangDirector?.GetValue(null);
			}
		}

		internal bool GroupControlled
		{
			get
			{
				if (!(Kind == "EnemyBang"))
				{
					return Kind == "EnemyGnome";
				}
				return true;
			}
		}

		internal string GroupState
		{
			get
			{
				object director = Director;
				MonoBehaviour val = (MonoBehaviour)((director is MonoBehaviour) ? director : null);
				if (val == null || !Object.op_Implicit((Object)(object)val))
				{
					return null;
				}
				return AccessTools.Field(director.GetType(), "currentState")?.GetValue(director)?.ToString();
			}
		}

		internal bool RetreatRequested
		{
			get
			{
				bool flag = default(bool);
				int num;
				if (Object.op_Implicit((Object)(object)Parent))
				{
					object obj = ForceLeaveField?.GetValue(Parent);
					if (obj is bool)
					{
						flag = (bool)obj;
						num = 1;
					}
					else
					{
						num = 0;
					}
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag ? 1u : 0u)) == 0 && !(GroupState == "Leave"))
				{
					return SpeciesControls.RetreatRequested(this);
				}
				return true;
			}
		}

		internal string State
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Enemy))
				{
					if (!(StateField != null) || !Object.op_Implicit((Object)(object)Controller))
					{
						return ((object)Unsafe.As<EnemyState, EnemyState>(ref Enemy.CurrentState)/*cast due to .constrained prefix*/).ToString();
					}
					return StateField.GetValue(Controller)?.ToString();
				}
				return null;
			}
		}

		internal bool Blind => Kind == "EnemyHunter";

		internal bool Deaf
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Hearing))
				{
					return Hearing.rangeMultiplier <= 0f;
				}
				return true;
			}
		}

		internal bool Alive
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Enemy) && Object.op_Implicit((Object)(object)Parent) && (bool)SetupDoneField.GetValue(Parent) && Object.op_Implicit((Object)(object)Parent.EnableObject) && Parent.EnableObject.activeInHierarchy && ((Behaviour)Enemy).isActiveAndEnabled)
				{
					return !DeadHealth();
				}
				return false;
			}
		}

		internal bool Available
		{
			get
			{
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Invalid comparison between Unknown and I4
				if (Alive && SpawnLifecycle.Ready(Parent) && !RetreatRequested && (int)Enemy.CurrentState != 11)
				{
					return !ControlRules.IsUnavailable(State);
				}
				return false;
			}
		}

		internal bool Stationary
		{
			get
			{
				if (!(Kind == "EnemyCeilingEye") && !(Kind == "EnemyThinMan"))
				{
					return Kind == "EnemyHeartHugger";
				}
				return true;
			}
		}

		internal bool CanAct
		{
			get
			{
				if (Available && !Enemy.IsStunned() && Enemy.FreezeTimer <= 0f)
				{
					if (Object.op_Implicit((Object)(object)Body))
					{
						if (!(bool)FrozenField.GetValue(Body))
						{
							return !(bool)GrabbedField.GetValue(Body);
						}
						return false;
					}
					return true;
				}
				return false;
			}
		}

		internal bool CanAttack
		{
			get
			{
				if (!CanAct)
				{
					if (Kind == "EnemyTick" && Available && !Enemy.IsStunned() && Enemy.FreezeTimer <= 0f)
					{
						if (Object.op_Implicit((Object)(object)Body))
						{
							return !(bool)FrozenField.GetValue(Body);
						}
						return true;
					}
					return false;
				}
				return true;
			}
		}

		internal bool CanSteer
		{
			get
			{
				if (!Stationary && CanAct)
				{
					if (!ControlRules.CanSteer(State) && !ControlRules.SteeringStance(Kind, State))
					{
						if (Kind == "EnemyShadow")
						{
							return State == "ChooseTarget";
						}
						return false;
					}
					return true;
				}
				return false;
			}
		}

		internal Transform Eye
		{
			get
			{
				if (!Object.op_Implicit((Object)(object)Vision) || !Object.op_Implicit((Object)(object)Vision.VisionTransform))
				{
					if (!Object.op_Implicit((Object)(object)Enemy) || !Object.op_Implicit((Object)(object)Enemy.CenterTransform))
					{
						return ((Component)Enemy).transform;
					}
					return Enemy.CenterTransform;
				}
				return Vision.VisionTransform;
			}
		}

		private static FieldInfo OptionalField(Type type, string name, Dictionary<Type, FieldInfo> cache)
		{
			if (!cache.TryGetValue(type, out var value))
			{
				Type type2 = type;
				while (type2 != null && value == null)
				{
					value = type2.GetField(name, BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					type2 = type2.BaseType;
				}
				cache[type] = value;
			}
			return value;
		}

		internal bool TryGroupDestination(out Vector3 destination)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			List<Vector3> list = NativeActions.Read<List<Vector3>>(Director, "destinations");
			int num = NativeActions.Read(Controller, "directorIndex", -1);
			if (list != null && num >= 0 && num < list.Count)
			{
				destination = list[num];
				return true;
			}
			destination = default(Vector3);
			return false;
		}

		private bool DeadHealth()
		{
			EnemyHealth component = ((Component)Enemy).GetComponent<EnemyHealth>();
			if (Object.op_Implicit((Object)(object)component))
			{
				if (!(bool)HealthDead.GetValue(component))
				{
					return (bool)HealthDying.GetValue(component);
				}
				return true;
			}
			return false;
		}

		internal Monster(Enemy enemy)
		{
			Enemy = enemy;
			Parent = ((Component)enemy).GetComponentInParent<EnemyParent>();
			Body = (Object.op_Implicit((Object)(object)Parent) ? ((Component)Parent).GetComponentInChildren<EnemyRigidbody>(true) : null);
			Vision = ((Component)enemy).GetComponent<EnemyVision>();
			Hearing = ((Component)enemy).GetComponent<EnemyStateInvestigate>();
			Navigation = ((Component)enemy).GetComponent<EnemyNavMeshAgent>();
			Agent = ((Component)enemy).GetComponent<NavMeshAgent>();
			MonoBehaviour[] components = ((Component)enemy).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val in components)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					FieldInfo fieldInfo = OptionalField(((object)val).GetType(), "currentState", StateFields);
					if (!(fieldInfo == null) && fieldInfo.FieldType.IsEnum && ((object)val).GetType().Name.StartsWith("Enemy"))
					{
						Controller = val;
						StateField = fieldInfo;
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)Controller))
			{
				Controller = (MonoBehaviour)(object)((Component)enemy).GetComponentInChildren<EnemyHeadController>(true);
			}
			Kind = (Object.op_Implicit((Object)(object)Controller) ? ((object)Controller).GetType().Name : ((object)enemy).GetType().Name);
			RotationField = (Object.op_Implicit((Object)(object)Controller) ? OptionalField(((object)Controller).GetType(), "rotationTarget", RotationFields) : null);
			PhotonView component = ((Component)enemy).GetComponent<PhotonView>();
			Id = ((Object.op_Implicit((Object)(object)component) && component.ViewID != 0) ? component.ViewID : ((Object)enemy).GetInstanceID());
			Name = (Object.op_Implicit((Object)(object)Parent) ? Parent.enemyName : Kind);
		}

		internal void Steer(Vector2 input, float yaw, float delta)
		{
			//IL_0014: 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_001a: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			if (!CanSteer)
			{
				return;
			}
			Quaternion val = Quaternion.Euler(0f, yaw, 0f);
			Vector3 direction = val * new Vector3(input.x, 0f, input.y);
			MonoBehaviour controller = Controller;
			EnemyOogly val2 = (EnemyOogly)(object)((controller is EnemyOogly) ? controller : null);
			if (val2 != null && State == "CeilingRoam")
			{
				SpeciesControls.SteerOogly(val2, direction);
				return;
			}
			if (!Object.op_Implicit((Object)(object)Navigation) || !Object.op_Implicit((Object)(object)Agent) || !((Behaviour)Agent).enabled || !Agent.isOnNavMesh)
			{
				return;
			}
			Navigation.Stop(0f);
			if (((Vector3)(ref direction)).sqrMagnitude > 0.001f)
			{
				float num = Mathf.Max(0.5f, Agent.speed * 0.4f);
				Vector3 val3 = ((Component)Enemy).transform.position + ((Vector3)(ref direction)).normalized * num;
				NavMeshQueryFilter val4 = default(NavMeshQueryFilter);
				((NavMeshQueryFilter)(ref val4)).agentTypeID = Agent.agentTypeID;
				((NavMeshQueryFilter)(ref val4)).areaMask = Agent.areaMask;
				NavMeshQueryFilter val5 = val4;
				NavMeshHit val6 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val3, ref val6, 0.75f, val5))
				{
					MonoBehaviour controller2 = Controller;
					EnemySnatcher val7 = (EnemySnatcher)(object)((controller2 is EnemySnatcher) ? controller2 : null);
					if ((val7 != null && SpeciesControls.OnCeiling(val7)) || ControlRules.AutomaticStance(Kind) || Kind == "EnemyValuableThrower")
					{
						if (Agent.pathPending)
						{
							goto IL_01ef;
						}
						if (Agent.hasPath)
						{
							Vector3 val8 = Agent.destination - ((NavMeshHit)(ref val6)).position;
							if (!(((Vector3)(ref val8)).sqrMagnitude > 0.0625f))
							{
								goto IL_01ef;
							}
						}
					}
					Agent.SetDestination(((NavMeshHit)(ref val6)).position);
				}
				else
				{
					Agent.ResetPath();
				}
			}
			else
			{
				Agent.ResetPath();
			}
			goto IL_01ef;
			IL_01ef:
			((Component)Enemy).transform.rotation = val;
			if (RotationField?.FieldType == typeof(Quaternion))
			{
				RotationField.SetValue(Controller, val);
			}
		}

		internal static List<Monster> Find()
		{
			List<Monster> list = new List<Monster>();
			Enemy[] array = Object.FindObjectsByType<Enemy>((FindObjectsSortMode)0);
			for (int i = 0; i < array.Length; i++)
			{
				Monster monster = new Monster(array[i]);
				if (Object.op_Implicit((Object)(object)monster.Controller) && Object.op_Implicit((Object)(object)monster.Parent))
				{
					list.Add(monster);
				}
			}
			list.Sort((Monster a, Monster b) => a.Id.CompareTo(b.Id));
			return list;
		}
	}
	internal sealed class MonsterAudio : IDisposable
	{
		private static MonsterAudio current;

		private readonly Dictionary<AudioSource, bool> mutes = new Dictionary<AudioSource, bool>();

		private readonly Dictionary<AudioSource, bool> listenerOverrides = new Dictionary<AudioSource, bool>();

		private readonly HashSet<AudioSource> ambience = new HashSet<AudioSource>();

		private readonly List<AudioSource> expired = new List<AudioSource>();

		private AudioListenerFollow listener;

		private Transform previousPosition;

		private Transform previousRotation;

		private bool deaf;

		private bool volumeCaptured;

		private float listenerVolume;

		internal MonsterAudio()
		{
			current = this;
		}

		internal static void Classify(AudioSource source, bool ambient)
		{
			if (current == null)
			{
				return;
			}
			if (ambient)
			{
				current.ambience.Add(source);
				if (current.mutes.TryGetValue(source, out var value))
				{
					source.mute = value;
					current.mutes.Remove(source);
				}
			}
			else
			{
				current.ambience.Remove(source);
			}
			if (current.deaf)
			{
				current.Filter(source);
			}
		}

		private bool IsAmbience(AudioSource source)
		{
			if (!ambience.Contains(source) && !Object.op_Implicit((Object)(object)((Component)source).GetComponentInParent<AmbienceLoop>()) && !Object.op_Implicit((Object)(object)((Component)source).GetComponentInParent<AmbienceLoopOverride>()))
			{
				if (Object.op_Implicit((Object)(object)AmbienceLoop.instance))
				{
					return (Object)(object)AmbienceLoop.instance.source == (Object)(object)source;
				}
				return false;
			}
			return true;
		}

		private void Filter(AudioSource source)
		{
			if (!Object.op_Implicit((Object)(object)source))
			{
				return;
			}
			if (!listenerOverrides.ContainsKey(source))
			{
				listenerOverrides[source] = source.ignoreListenerVolume;
			}
			if (!(source.ignoreListenerVolume = IsAmbience(source)))
			{
				if (!mutes.ContainsKey(source))
				{
					mutes[source] = source.mute;
				}
				source.mute = true;
			}
		}

		internal void Tick(Transform camera, bool isDeaf)
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)listener != (Object)(object)AudioListenerFollow.instance)
			{
				RestoreListener();
				listener = AudioListenerFollow.instance;
				if (Object.op_Implicit((Object)(object)listener))
				{
					previousPosition = listener.TargetPositionTransform;
					previousRotation = listener.TargetRotationTransform;
				}
			}
			if (Object.op_Implicit((Object)(object)listener))
			{
				listener.TargetPositionTransform = camera;
				listener.TargetRotationTransform = camera;
				((Component)listener).transform.SetPositionAndRotation(camera.position, camera.rotation);
			}
			if (deaf && !isDeaf)
			{
				RestoreMutes();
			}
			deaf = isDeaf;
			if (deaf)
			{
				if (!volumeCaptured)
				{
					listenerVolume = AudioListener.volume;
					volumeCaptured = true;
				}
				AudioListener.volume = 0f;
				AudioSource[] array = Object.FindObjectsByType<AudioSource>((FindObjectsSortMode)0);
				foreach (AudioSource source in array)
				{
					Filter(source);
				}
			}
			expired.Clear();
			foreach (KeyValuePair<AudioSource, bool> mute in mutes)
			{
				if (!Object.op_Implicit((Object)(object)mute.Key))
				{
					expired.Add(mute.Key);
				}
			}
			foreach (AudioSource item in expired)
			{
				mutes.Remove(item);
			}
			expired.Clear();
			foreach (KeyValuePair<AudioSource, bool> listenerOverride in listenerOverrides)
			{
				if (!Object.op_Implicit((Object)(object)listenerOverride.Key))
				{
					expired.Add(listenerOverride.Key);
				}
			}
			foreach (AudioSource item2 in expired)
			{
				listenerOverrides.Remove(item2);
			}
			ambience.RemoveWhere((AudioSource val) => !Object.op_Implicit((Object)(object)val));
		}

		private void RestoreMutes()
		{
			foreach (KeyValuePair<AudioSource, bool> mute in mutes)
			{
				if (Object.op_Implicit((Object)(object)mute.Key))
				{
					mute.Key.mute = mute.Value;
				}
			}
			mutes.Clear();
			foreach (KeyValuePair<AudioSource, bool> listenerOverride in listenerOverrides)
			{
				if (Object.op_Implicit((Object)(object)listenerOverride.Key))
				{
					listenerOverride.Key.ignoreListenerVolume = listenerOverride.Value;
				}
			}
			listenerOverrides.Clear();
			if (volumeCaptured)
			{
				AudioListener.volume = listenerVolume;
			}
			volumeCaptured = false;
		}

		private void RestoreListener()
		{
			if (Object.op_Implicit((Object)(object)listener))
			{
				listener.TargetPositionTransform = previousPosition;
				listener.TargetRotationTransform = previousRotation;
			}
			listener = null;
		}

		internal void Restore()
		{
			RestoreMutes();
			RestoreListener();
			deaf = false;
			ambience.RemoveWhere((AudioSource source) => !Object.op_Implicit((Object)(object)source));
		}

		public void Dispose()
		{
			Restore();
			ambience.Clear();
			if (current == this)
			{
				current = null;
			}
		}
	}
	[HarmonyPatch]
	internal static class MonsterGaze
	{
		private static MethodBase TargetMethod()
		{
			return AccessTools.EnumeratorMoveNext((MethodBase)AccessTools.Method(typeof(EnemyOnScreen), "Logic", (Type[])null, (Type[])null));
		}

		internal static bool CanObserve(PlayerAvatar player)
		{
			if (Object.op_Implicit((Object)(object)player))
			{
				return !TeamBodies.IsMonster(player);
			}
			return false;
		}

		[HarmonyTranspiler]
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo objB = AccessTools.Field(typeof(PlayerAvatar), "instance");
			MethodInfo methodInfo = AccessTools.Method(typeof(Object), "op_Implicit", new Type[1] { typeof(Object) }, (Type[])null);
			MethodInfo operand = AccessTools.Method(typeof(MonsterGaze), "CanObserve", (Type[])null, (Type[])null);
			int num = 0;
			for (int i = 0; i + 1 < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldsfld && object.Equals(list[i].operand, objB) && CodeInstructionExtensions.Calls(list[i + 1], methodInfo))
				{
					list[i + 1].operand = operand;
					num++;
				}
			}
			if (num != 1)
			{
				throw new InvalidOperationException("Unsupported native EnemyOnScreen local gaze check: " + num);
			}
			return list;
		}
	}
	internal sealed class MonsterGhosts
	{
		private sealed class Skin
		{
			private readonly Renderer renderer;

			private readonly Material[] original;

			private readonly Material[] ghost;

			internal Skin(Renderer renderer)
			{
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b6: Expected O, but got Unknown
				this.renderer = renderer;
				original = renderer.sharedMaterials;
				ghost = (Material[])(object)new Material[original.Length];
				Shader val = Shader.Find("Legacy Shaders/Transparent/Diffuse");
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = Shader.Find("Standard");
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = Shader.Find("Sprites/Default");
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					val = Shader.Find("Hidden/Internal-Colored");
				}
				if (!Object.op_Implicit((Object)(object)val))
				{
					throw new InvalidOperationException("Missing ghost transparency shader.");
				}
				for (int i = 0; i < ghost.Length; i++)
				{
					ghost[i] = new Material(val)
					{
						name = "Monster team ghost",
						hideFlags = (HideFlags)61,
						renderQueue = 3000
					};
					if (((Object)val).name == "Standard")
					{
						ghost[i].SetFloat("_Mode", 2f);
						ghost[i].EnableKeyword("_ALPHABLEND_ON");
						ghost[i].SetOverrideTag("RenderType", "Transparent");
					}
					Material val2 = original[i];
					if (Object.op_Implicit((Object)(object)val2) && ghost[i].HasProperty("_MainTex"))
					{
						string[] array = new string[4] { "_MainTex", "_AlbedoTexture", "_BaseMap", "_BaseColorMap" };
						foreach (string text in array)
						{
							if (val2.HasProperty(text) && Object.op_Implicit((Object)(object)val2.GetTexture(text)))
							{
								ghost[i].SetTexture("_MainTex", val2.GetTexture(text));
								break;
							}
						}
					}
					ghost[i].SetInt("_SrcBlend", 5);
					ghost[i].SetInt("_DstBlend", 10);
					ghost[i].SetInt("_ZWrite", 0);
					ghost[i].SetInt("_ZTest", 4);
					ghost[i].SetInt("_Cull", 2);
				}
				renderer.sharedMaterials = ghost;
			}

			internal bool StillApplied()
			{
				if (!Object.op_Implicit((Object)(object)renderer))
				{
					return false;
				}
				Material[] sharedMaterials = renderer.sharedMaterials;
				if (sharedMaterials.Length != ghost.Length)
				{
					return false;
				}
				for (int i = 0; i < sharedMaterials.Length; i++)
				{
					if ((Object)(object)sharedMaterials[i] != (Object)(object)ghost[i])
					{
						return false;
					}
				}
				return true;
			}

			internal void Apply()
			{
				//IL_0085: 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_0078: 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_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < ghost.Length; i++)
				{
					Material val = original[i];
					Color color = (Color)((Object.op_Implicit((Object)(object)val) && val.HasProperty("_AlbedoColor")) ? val.GetColor("_AlbedoColor") : ((Object.op_Implicit((Object)(object)val) && val.HasProperty("_BaseColor")) ? val.GetColor("_BaseColor") : ((Object.op_Implicit((Object)(object)val) && val.HasProperty("_Color")) ? val.GetColor("_Color") : new Color(0.65f, 0.9f, 1f))));
					color.a = 0.38f;
					ghost[i].color = color;
				}
			}

			internal void Restore()
			{
				if (StillApplied())
				{
					renderer.sharedMaterials = original;
				}
				Material[] array = ghost;
				foreach (Material val in array)
				{
					if (Object.op_Implicit((Object)(object)val))
					{
						Object.Destroy((Object)(object)val);
					}
				}
			}
		}

		internal const float Opacity = 0.38f;

		private readonly Dictionary<Renderer, Skin> skins = new Dictionary<Renderer, Skin>();

		internal static bool BetweenRounds
		{
			get
			{
				if (Object.op_Implicit((Object)(object)RunManager.instance) && !SemiFunc.MenuLevel())
				{
					if (!Session.InArena && !SemiFunc.RunIsShop())
					{
						return SemiFunc.RunIsLobby();
					}
					return true;
				}
				return false;
			}
		}

		internal void Tick()
		{
			HashSet<Renderer> hashSet = new HashSet<Renderer>();
			if (BetweenRounds && Object.op_Implicit((Object)(object)GameDirector.instance))
			{
				foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
				{
					if (!TeamBodies.OnMonsterTeam(player) || !Object.op_Implicit((Object)(object)player.playerAvatarVisuals) || player.playerAvatarVisuals.isMenuAvatar)
					{
						continue;
					}
					Transform val = ((Component)player).transform;
					Transform parent = val.parent;
					if (Object.op_Implicit((Object)(object)parent) && ((Object)parent).name.StartsWith("PlayerAvatar", StringComparison.Ordinal) && ((Component)parent).GetComponentsInChildren<PlayerAvatar>(true).Length == 1)
					{
						val = parent;
					}
					Renderer[] componentsInChildren = ((Component)val).GetComponentsInChildren<Renderer>(true);
					foreach (Renderer val2 in componentsInChildren)
					{
						if ((val2 is MeshRenderer || val2 is SkinnedMeshRenderer) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<ItemEquippable>()) && !Object.op_Implicit((Object)(object)((Component)val2).GetComponentInParent<ItemAttributes>()))
						{
							hashSet.Add(val2);
						}
					}
				}
			}
			List<Renderer> list = new List<Renderer>();
			foreach (KeyValuePair<Renderer, Skin> skin in skins)
			{
				if (!Object.op_Implicit((Object)(object)skin.Key) || !hashSet.Contains(skin.Key))
				{
					skin.Value.Restore();
					list.Add(skin.Key);
				}
			}
			foreach (Renderer item in list)
			{
				skins.Remove(item);
			}
			foreach (Renderer item2 in hashSet)
			{
				if (skins.TryGetValue(item2, out var value) && !value.StillApplied())
				{
					value.Restore();
					skins.Remove(item2);
					value = null;
				}
				if (value == null)
				{
					value = new Skin(item2);
					skins.Add(item2, value);
				}
				value.Apply();
			}
		}

		internal void Restore()
		{
			foreach (Skin value in skins.Values)
			{
				value.Restore();
			}
			skins.Clear();
		}
	}
	internal sealed class MonsterHud : IDisposable
	{
		private readonly Session session;

		private GameObject root;

		private GameObject legend;

		private GameObject reticle;

		private GameObject laserReticle;

		private TextMeshProUGUI heading;

		private TextMeshProUGUI controls;

		private TextMeshProUGUI actions;

		private TextMeshProUGUI notice;

		private TextMeshProUGUI waiting;

		private TextMeshProUGUI chat;

		private static readonly Color Ink = new Color(1f, 0.82f, 0.33f);

		internal Canvas Canvas { get; private set; }

		internal MonsterHud(Session session)
		{
			this.session = session;
		}

		internal void Tick()
		{
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_030e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)root) && !Create())
			{
				return;
			}
			bool flag = session.IsLocalMonster && Session.Playing;
			bool flag2 = Session.MenuOpen();
			bool flag3 = Time.unscaledTime < session.NoticeUntil;
			((Behaviour)Canvas).enabled = !flag2 && (flag || flag3);
			Monster possessed = session.Possessed;
			legend.SetActive(flag && possessed != null);
			((Component)waiting).gameObject.SetActive(flag && possessed == null);
			reticle.SetActive(flag && possessed != null && possessed.Blind);
			laserReticle.SetActive(flag && possessed != null && possessed.Kind == "EnemyBeamer");
			((Component)notice).gameObject.SetActive(flag3);
			((TMP_Text)notice).text = session.Notice;
			((TMP_Text)waiting).text = "WAITING FOR A MONSTER";
			bool flag4 = flag && Object.op_Implicit((Object)(object)ChatManager.instance) && !ChatManager.instance.StateIsInactive();
			((Component)chat).gameObject.SetActive(flag4);
			if (flag4)
			{
				((TMP_Text)chat).text = (Object.op_Implicit((Object)(object)ChatManager.instance.chatText) ? ((TMP_Text)ChatManager.instance.chatText).text : "");
			}
			if (possessed != null)
			{
				((TMP_Text)heading).text = possessed.Name.ToUpperInvariant();
				((TMP_Text)controls).text = Key(((object)session.Owner.PreviousKey.Value/*cast due to .constrained prefix*/).ToString() + "/" + ((object)session.Owner.NextKey.Value/*cast due to .constrained prefix*/).ToString()) + " SWITCH" + ((!possessed.Stationary) ? ("   " + Key("WASD") + " MOVE") : ((possessed.Kind == "EnemyCeilingEye") ? "" : ("   " + Key(((object)session.Owner.SpecialKey.Value/*cast due to .constrained prefix*/).ToString()) + " RELOCATE")));
				string text = NativeActions.PrimaryHint(possessed.Kind);
				((TMP_Text)actions).text = ((text == null) ? "AUTO ATTACK" : (Key(((object)session.Owner.PrimaryKey.Value/*cast due to .constrained prefix*/).ToString()) + " " + text.ToUpperInvariant()));
				string text2 = NativeActions.SecondaryHint(possessed.Kind);
				if (text2 != null)
				{
					TextMeshProUGUI val = actions;
					((TMP_Text)val).text = ((TMP_Text)val).text + "\n" + Key(((object)session.Owner.SecondaryKey.Value/*cast due to .constrained prefix*/).ToString()) + " " + text2.ToUpperInvariant();
				}
				if (possessed.Kind == "EnemyBirthdayBoy")
				{
					TextMeshProUGUI obj = actions;
					((TMP_Text)obj).text = ((TMP_Text)obj).text + " " + session.BalloonLabel();
				}
			}
		}

		private static string Key(string key)
		{
			return "<color=#FFD465>[" + key.Replace("Mouse0", "LMB").Replace("Mouse1", "RMB").Replace(" + ", "+") + "]</color>";
		}

		private bool Create()
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_0119: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: 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_02c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0382: Unknown result type (might be due to invalid IL or missing references)
			//IL_0391: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Expected O, but got Unknown
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Unknown result type (might be due to invalid IL or missing references)
			//IL_042e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_046e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0483: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04da: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0531: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Expected O, but got Unknown
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0580: Unknown result type (might be due to invalid IL or missing references)
			//IL_0587: Unknown result type (might be due to invalid IL or missing references)
			//IL_0598: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI val = null;
			if (Object.op_Implicit((Object)(object)HUD.instance))
			{
				TextMeshProUGUI[] componentsInChildren = ((Component)HUD.instance).GetComponentsInChildren<TextMeshProUGUI>(true);
				foreach (TextMeshProUGUI val2 in componentsInChildren)
				{
					if (Object.op_Implicit((Object)(object)((TMP_Text)val2).font))
					{
						val = val2;
						break;
					}
				}
			}
			TMP_FontAsset val3 = (Object.op_Implicit((Object)(object)val) ? ((TMP_Text)val).font : TMP_Settings.defaultFontAsset);
			if (!Object.op_Implicit((Object)(object)val3))
			{
				TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
				foreach (TMP_FontAsset val4 in array)
				{
					if (Object.op_Implicit((Object)(object)val4))
					{
						val3 = val4;
						break;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val3))
			{
				return false;
			}
			root = new GameObject("Monster PvP HUD", new Type[3]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(CanvasScaler)
			});
			Canvas = root.GetComponent<Canvas>();
			Canvas.renderMode = (RenderMode)0;
			Canvas.sortingOrder = 32700;
			CanvasScaler component = root.GetComponent<CanvasScaler>();
			component.uiScaleMode = (ScaleMode)1;
			component.referenceResolution = new Vector2(1280f, 720f);
			component.matchWidthOrHeight = 0.5f;
			legend = new GameObject("Monster key legend", new Type[1] { typeof(RectTransform) });
			legend.transform.SetParent(root.transform, false);
			RectTransform component2 = legend.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			Vector2 offsetMin = (component2.offsetMax = Vector2.zero);
			component2.offsetMin = offsetMin;
			heading = Label(legend.transform, "Creature", val3, val, 20, Vector2.zero, new Vector2(24f, 112f), new Vector2(360f, 28f));
			((Graphic)heading).color = Ink;
			TextMeshProUGUI obj = heading;
			((TMP_Text)obj).fontStyle = (FontStyles)(((TMP_Text)obj).fontStyle | 3);
			controls = Label(legend.transform, "Movement", val3, val, 15, Vector2.zero, new Vector2(24f, 84f), new Vector2(360f, 22f));
			actions = Label(legend.transform, "Abilities", val3, val, 15, Vector2.zero, new Vector2(24f, 59f), new Vector2(360f, 44f));
			notice = Label(root.transform, "Notice", val3, val, 17, new Vector2(0.5f, 0f), new Vector2(0f, 72f), new Vector2(600f, 48f));
			((TMP_Text)notice).alignment = (TextAlignmentOptions)1026;
			((Graphic)notice).color = Ink;
			waiting = Label(root.transform, "Waiting", val3, val, 19, new Vector2(0.5f, 0f), new Vector2(0f, 70f), new Vector2(440f, 30f));
			((TMP_Text)waiting).alignment = (TextAlignmentOptions)514;
			((Graphic)waiting).color = Ink;
			chat = Label(root.transform, "Chat", val3, val, 18, new Vector2(0.5f, 0f), new Vector2(0f, 110f), new Vector2(680f, 42f));
			((TMP_Text)chat).alignment = (TextAlignmentOptions)1026;
			reticle = new GameObject("Huntsman crosshair", new Type[1] { typeof(RectTransform) });
			reticle.transform.SetParent(root.transform, false);
			RectTransform component3 = reticle.GetComponent<RectTransform>();
			Vector2 val5 = default(Vector2);
			((Vector2)(ref val5))..ctor(0.5f, 0.5f);
			component3.pivot = val5;
			offsetMin = (component3.anchorMax = val5);
			component3.anchorMin = offsetMin;
			component3.anchoredPosition = Vector2.zero;
			component3.sizeDelta = new Vector2(16f, 16f);
			Mark(new Vector2(-5f, 0f), new Vector2(3f, 1f));
			Mark(new Vector2(5f, 0f), new Vector2(3f, 1f));
			Mark(new Vector2(0f, -5f), new Vector2(1f, 3f));
			Mark(new Vector2(0f, 5f), new Vector2(1f, 3f));
			Mark(Vector2.zero, new Vector2(1.5f, 1.5f));
			laserReticle = new GameObject("Clown laser crosshair", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Outline)
			});
			laserReticle.transform.SetParent(root.transform, false);
			RectTransform component4 = laserReticle.GetComponent<RectTransform>();
			((Vector2)(ref val5))..ctor(0.5f, 0.5f);
			component4.pivot = val5;
			offsetMin = (component4.anchorMax = val5);
			component4.anchorMin = offsetMin;
			component4.sizeDelta = new Vector2(28f, 2f);
			((Graphic)laserReticle.GetComponent<Image>()).color = new Color(1f, 0.08f, 0.04f, 0.95f);
			((Graphic)laserReticle.GetComponent<Image>()).raycastTarget = false;
			((Shadow)laserReticle.GetComponent<Outline>()).effectColor = Color.black;
			((Shadow)laserReticle.GetComponent<Outline>()).effectDistance = new Vector2(1f, -1f);
			Transform[] componentsInChildren2 = root.GetComponentsInChildren<Transform>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				((Component)componentsInChildren2[i]).gameObject.layer = LayerMask.NameToLayer("UI");
			}
			return true;
		}

		private void Mark(Vector2 position, Vector2 size)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Aim mark", new Type[3]
			{
				typeof(RectTransform),
				typeof(Image),
				typeof(Outline)
			});
			val.transform.SetParent(reticle.transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component.pivot = val2;
			Vector2 anchorMin = (component.anchorMax = val2);
			component.anchorMin = anchorMin;
			component.anchoredPosition = position;
			component.sizeDelta = size;
			Image component2 = val.GetComponent<Image>();
			((Graphic)component2).color = new Color(0.88f, 0.96f, 0.93f, 0.9f);
			((Graphic)component2).raycastTarget = false;
			Outline component3 = val.GetComponent<Outline>();
			((Shadow)component3).effectColor = new Color(0f, 0f, 0f, 0.8f);
			((Shadow)component3).effectDistance = new Vector2(0.75f, -0.75f);
		}

		private static TextMeshProUGUI Label(Transform parent, string name, TMP_FontAsset font, TextMeshProUGUI style, int size, Vector2 anchor, Vector2 position, Vector2 dimensions)
		{
			//IL_0014: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_004a: 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_005c: 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)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			Vector2 anchorMin = (component.anchorMax = anchor);
			component.anchorMin = anchorMin;
			component.pivot = new Vector2(anchor.x, 1f);
			component.anchoredPosition = position;
			component.sizeDelta = dimensions;
			TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).font = font;
			if (Object.op_Implicit((Object)(object)style))
			{
				((TMP_Text)val3).fontSharedMaterial = ((TMP_Text)style).fontSharedMaterial;
			}
			((TMP_Text)val3).fontSize = size;
			((TMP_Text)val3).fontStyle = (FontStyles)2;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)257;
			((Graphic)val3).color = new Color(0.93f, 0.94f, 0.87f);
			((TMP_Text)val3).outlineColor = Color32.op_Implicit(Color.black);
			((TMP_Text)val3).outlineWidth = 0.17f;
			((Graphic)val3).raycastTarget = false;
			((TMP_Text)val3).richText = true;
			((TMP_Text)val3).textWrappingMode = (TextWrappingModes)1;
			return val3;
		}

		public void Dispose()
		{
			if (Object.op_Implicit((Object)(object)root))
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			Canvas = null;
		}
	}
	[HarmonyPatch]
	internal static class MonsterInteractionRules
	{
		private static bool MonsterActor(int actor)
		{
			if (Object.op_Implicit((Object)(object)Session.Current))
			{
				return Session.Current.HasRole(actor);
			}
			return false;
		}

		private static PlayerAvatar Avatar(int id)
		{
			if (id <= 0)
			{
				return PlayerAvatar.instance;
			}
			return SemiFunc.PlayerAvatarGetFromPhotonID(id);
		}

		private static bool MonsterId(int id)
		{
			return TeamBodies.OnMonsterTeam(Avatar(id));
		}

		private static bool PlayerUpgrade(ItemToggle toggle)
		{
			return Object.op_Implicit((Object)(object)((Component)toggle).GetComponent<ItemUpgrade>());
		}

		[HarmonyPatch(typeof(ItemToggle), "ToggleItem")]
		[HarmonyPrefix]
		private static bool ToggleRequest(ItemToggle __instance, bool __0, int __1)
		{
			if (__0 && PlayerUpgrade(__instance))
			{
				return !MonsterId(__1);
			}
			return true;
		}

		[HarmonyPatch(typeof(ItemToggle), "ToggleItemRPC")]
		[HarmonyPrefix]
		private static bool ToggleNetwork(ItemToggle __instance, bool __0, int __1, PhotonMessageInfo _info)
		{
			//IL_0013: 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)
			if (__0 && PlayerUpgrade(__instance))
			{
				if (!MonsterId(__1))
				{
					if (_info.Sender != null)
					{
						return !MonsterActor(_info.Sender.ActorNumber);
					}
					return true;
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(ItemToggle), "ToggleItemLogic")]
		[HarmonyPrefix]
		private static bool ToggleLogic(ItemToggle __instance, bool __0, int __1)
		{
			if (__0 && PlayerUpgrade(__instance))
			{
				return !MonsterId(__1);
			}
			return true;
		}

		[HarmonyPatch(typeof(ItemUpgrade), "PlayerUpgrade")]
		[HarmonyPrefix]
		private static bool Consume(ItemUpgrade __instance)
		{
			ItemToggle component = ((Component)__instance).GetComponent<ItemToggle>();
			if (Object.op_Implicit((Object)(object)component))
			{
				return !MonsterId(NativeActions.Read(component, "playerTogglePhotonID", -1));
			}
			return true;
		}

		internal static bool PurchaseButton(StaticGrabObject button)
		{
			if (Object.op_Implicit((Object)(object)button))
			{
				if (!Object.op_Implicit((Object)(object)((Component)button).GetComponentInParent<UpgradeStand>()) && !Object.op_Implicit((Object)(object)((Component)button).GetComponentInParent<CosmeticShopMachine>()))
				{
					if (Object.op_Implicit((Object)(object)((Component)button).GetComponentInParent<ExtractionPoint>()))
					{
						return SemiFunc.RunIsShop();
					}
					return false;
				}
				return true;
			}
			return false;
		}

		private static bool CanGrab(StaticGrabObject button, PhysGrabber player)
		{
			if (PurchaseButton(button) && Object.op_Implicit((Object)(object)player))
			{
				return !TeamBodies.OnMonsterTeam(player.playerAvatar);
			}
			return true;
		}

		private static PhysGrabber Grabber(int id)
		{
			PhotonView obj = PhotonView.Find(id);
			if (obj == null)
			{
				return null;
			}
			return ((Component)obj).GetComponent<PhysGrabber>();
		}

		[HarmonyPatch(typeof(StaticGrabObject), "GrabStarted")]
		[HarmonyPrefix]
		private static bool GrabStart(StaticGrabObject __instance, PhysGrabber __0)
		{
			return CanGrab(__instance, __0);
		}

		[HarmonyPatch(typeof(StaticGrabObject), "GrabStartedRPC")]
		[HarmonyPrefix]
		private static bool GrabStartNetwork(StaticGrabObject __instance, int __0, PhotonMessageInfo _info)
		{
			//IL_0016: 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)
			if (CanGrab(__instance, Grabber(__0)))
			{
				if (PurchaseButton(__instance) && _info.Sender != null)
				{
					return !MonsterActor(_info.Sender.ActorNumber);
				}
				return true;
			}
			return false;
		}

		[HarmonyPatch(typeof(StaticGrabObject), "GrabLink")]
		[HarmonyPrefix]
		private static bool GrabLink(StaticGrabObject __instance, int __0)
		{
			return CanGrab(__instance, Grabber(__0));
		}

		[HarmonyPatch(typeof(StaticGrabObject), "GrabLinkRPC")]
		[HarmonyPrefix]
		private static bool GrabLinkNetwork(StaticGrabObject __instance, int __0, PhotonMessageInfo _info)
		{
			//IL_0016: 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)
			if (CanGrab(__instance, Grabber(__0)))
			{
				if (PurchaseButton(__instance) && _info.Sender != null)
				{
					return !MonsterActor(_info.Sender.ActorNumber);
				}
				return true;
			}
			return false;
		}

		[HarmonyPatch(typeof(StaticGrabObject), "Update")]
		[HarmonyPrefix]
		private static void RemoveForbiddenGrabs(StaticGrabObject __instance)
		{
			if (!PurchaseButton(__instance))
			{
				return;
			}
			bool flag = false;
			for (int num = __instance.playerGrabbing.Count - 1; num >= 0; num--)
			{
				PhysGrabber val = __instance.playerGrabbing[num];
				if (!CanGrab(__instance, val))
				{
					__instance.playerGrabbing.RemoveAt(num);
					flag = true;
					if (Object.op_Implicit((Object)(object)val) && (Object)(object)val.playerAvatar == (Object)(object)PlayerAvatar.instance)
					{
						val.OverrideGrabRelease(-1, 0.2f);
					}
				}
			}
			if (flag && __instance.playerGrabbing.Count == 0)
			{
				__instance.grabbed = false;
			}
		}

		[HarmonyPatch(typeof(PhysGrabber), "StartGrabbingPhysObject")]
		[HarmonyPrefix]
		private static bool LocalGrab(PhysGrabber __instance, RaycastHit __0)
		{
			return CanGrab(Object.op_Implicit((Object)(object)((RaycastHit)(ref __0)).collider) ? ((Component)((RaycastHit)(ref __0)).collider).GetComponentInParent<StaticGrabObject>() : null, __instance);
		}

		[HarmonyPatch(typeof(CosmeticShopMachine), "Interact")]
		[HarmonyPrefix]
		private static bool CosmeticLocal()
		{
			return !TeamBodies.OnMonsterTeam(PlayerAvatar.instance);
		}

		[HarmonyPatch(typeof(CosmeticShopMachine), "InteractSet")]
		[HarmonyPrefix]
		private static bool CosmeticBuyer(PlayerAvatar __0)
		{
			return !TeamBodies.OnMonsterTeam(__0);
		}

		[HarmonyPatch(typeof(CosmeticShopMachine), "InteractClientRPC")]
		[HarmonyPrefix]
		private static bool CosmeticNetwork(PhotonMessageInfo _info)
		{
			//IL_0000: 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)
			if (_info.Sender != null)
			{
				return !MonsterActor(_info.Sender.ActorNumber);
			}
			return true;
		}
	}
	internal sealed class MonsterView : IDisposable
	{
		private readonly Session session;

		private readonly MonsterHud hud;

		private readonly MonsterAudio audio = new MonsterAudio();

		private readonly Dictionary<Camera, bool> cameras = new Dictionary<Camera, bool>();

		private GameObject root;

		private PlayerDeathHead wornHead;

		private readonly Dictionary<Renderer, bool> wornHeadRenderers = new Dictionary<Renderer, bool>();

		private readonly Dictionary<Renderer, bool> attachmentRenderers = new Dictionary<Renderer, bool>();

		private readonly HashSet<Renderer> attachmentGeometry = new HashSet<Renderer>();

		private readonly List<Renderer> releasedGeometry = new List<Renderer>();

		private Camera camera;

		private SphereCollider cameraProbe;

		private Camera sourceCamera;

		private int sourceMask;

		private CameraClearFlags sourceClearFlags;

		private Color sourceBackground;

		private Vector3 sourceLocalPosition;

		private Quaternion sourceLocalRotation;

		private bool menuBackdrop;

		private readonly Dictionary<Camera, bool> menuCameras = new Dictionary<Camera, bool>();

		private readonly Dictionary<Graphic, bool> menuGraphics = new Dictionary<Graphic, bool>();

		private OutlineScene outlines;

		private RoomVolumeCheck roomCheck;

		private RoomVolumeCheck savedRoomCheck;

		private PlayerAvatar roomOwner;

		private LightManager lights;

		private Transform savedLightTarget;

		private int viewedId;

		private readonly Dictionary<Renderer, bool> hidden = new Dictionary<Renderer, bool>();

		private readonly Dictionary<Animator, AnimatorCullingMode> animators = new Dictionary<Animator, AnimatorCullingMode>();

		private readonly Dictionary<SkinnedMeshRenderer, bool> skins = new Dictionary<SkinnedMeshRenderer, bool>();

		private readonly Dictionary<Canvas, bool> canvases = new Dictionary<Canvas, bool>();

		internal OutlineScene Outlines => outlines;

		internal MonsterView(Session session)
		{
			this.session = session;
			hud = new MonsterHud(session);
		}

		internal void Tick()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Invalid comparison between Unknown and I4
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Invalid comparison between Unknown and I4
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Invalid comparison between Unknown and I4
			//IL_08a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_067e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_0833: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Unknown result type (might be due to invalid IL or missing references)
			//IL_0842: Unknown result type (might be due to invalid IL or missing references)
			//IL_0847: Unknown result type (might be due to invalid IL or missing references)
			//IL_0854: Unknown result type (might be due to invalid IL or missing references)
			//IL_0871: Unknown result type (might be due to invalid IL or missing references)
			//IL_06df: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0805: Unknown result type (might be due to invalid IL or missing references)
			//IL_0825: Unknown result type (might be due to invalid IL or missing references)
			//IL_080e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0813: Unknown result type (might be due to invalid IL or missing references)
			//IL_0817: Unknown result type (might be due to invalid IL or missing references)
			//IL_0820: Unknown result type (might be due to invalid IL or missing references)
			if ((int)SystemInfo.graphicsDeviceType == 4)
			{
				Restore();
				return;
			}
			hud.Tick();
			if (!session.IsLocalMonster || !Session.Playing)
			{
				Restore();
				return;
			}
			if (!Object.op_Implicit((Object)(object)root))
			{
				root = new GameObject("Monster PvP Camera");
				root.SetActive(false);
				camera = root.AddComponent<Camera>();
				cameraProbe = root.AddComponent<SphereCollider>();
				((Collider)cameraProbe).enabled = false;
				((Collider)cameraProbe).isTrigger = true;
				Camera val = (sourceCamera = Camera.main);
				if (Object.op_Implicit((Object)(object)val))
				{
					camera.CopyFrom(val);
					sourceMask = val.cullingMask;
					sourceClearFlags = val.clearFlags;
					sourceBackground = val.backgroundColor;
					sourceLocalPosition = ((Component)val).transform.localPosition;
					sourceLocalRotation = ((Component)val).transform.localRotation;
				}
				((Component)camera).tag = "MainCamera";
				camera.targetTexture = null;
				camera.depth = 100f;
				camera.nearClipPlane = 0.06f;
				camera.fieldOfView = 80f;
				camera.clearFlags = (CameraClearFlags)2;
				camera.backgroundColor = Color.black;
				roomCheck = root.AddComponent<RoomVolumeCheck>();
				roomCheck.CurrentRooms = new List<RoomVolume>();
				roomCheck.CheckPosition = Vector3.zero;
				roomCheck.currentSize = Vector3.one * 0.2f;
				root.SetActive(true);
				outlines = new OutlineScene(camera);
			}
			bool flag = Session.MenuOpen();
			Camera[] array = Object.FindObjectsByType<Camera>(