Decompiled source of JackSkellington v1.0.2

BepInEx/plugins/JLeonL-JackSkellington/JackSkellington.dll

Decompiled 19 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("JackSkellington")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("JackSkellington")]
[assembly: AssemblyTitle("JackSkellington")]
[assembly: AssemblyVersion("1.0.2.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 JackSkellington
{
	internal sealed class JackActor
	{
		private readonly string StateMessage;

		private readonly string RequestMessage;

		private readonly int id;

		private readonly JackWorld world;

		private float scale;

		private bool enabled;

		private JackSkinView view;

		private double nextDoor;

		private ScanNodeProperties scan;

		private int syncAttempts;

		private const int Walls = 134217985;

		private GameObject root;

		private NavMeshAgent agent;

		private CapsuleCollider body;

		private AudioSource voice;

		private AudioSource scare;

		private AudioSource steps;

		private NetworkManager registered;

		private JackBehaviour mind;

		private Random random;

		private readonly List<Vector3> waypoints = new List<Vector3>();

		private readonly NavMeshPath path = new NavMeshPath();

		private JackState state;

		private int target = -1;

		private uint sequence;

		private uint cancelledSequence = uint.MaxValue;

		private double since;

		private double clock;

		private double lastPacket = -1.0;

		private double nextSend;

		private double nextThink;

		private double nextPath;

		private double nextSync;

		private Vector3 receivedPosition;

		private Vector3 lastPosition;

		private Vector3 lastSeenPosition;

		private Quaternion receivedRotation;

		private bool hasSnapshot;

		private PlayerControllerB held;

		private bool oldMove;

		private bool oldLook;

		private bool oldSpecial;

		private float grabDeadline;

		private float grabY;

		private float lastHitRequest;

		private Vector3 lastHeldPosition;

		private Quaternion oldCamera;

		private uint heldSequence = uint.MaxValue;

		private double nextStep;

		private uint presentedSequence = uint.MaxValue;

		private float Height => 2.8f * scale;

		private float GrabDistance => 0.65f + 0.8f * scale;

		internal string Status
		{
			get
			{
				if (!((Object)(object)root == (Object)null))
				{
					return "variant=" + id + " enabled=" + enabled + " state=" + state.ToString() + " target=" + target + " sequence=" + sequence + " authority=" + (Host ? "host" : "client") + " nav=" + ((Object)(object)agent != (Object)null && agent.isOnNavMesh);
				}
				return "not spawned";
			}
		}

		private bool Host
		{
			get
			{
				if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.IsListening)
				{
					return NetworkManager.Singleton.IsServer;
				}
				return true;
			}
		}

		private PlayerControllerB Local
		{
			get
			{
				if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
				{
					return null;
				}
				return GameNetworkManager.Instance.localPlayerController;
			}
		}

		internal bool IsHolding(PlayerControllerB player)
		{
			if ((Object)(object)held != (Object)null)
			{
				return (Object)(object)held == (Object)(object)player;
			}
			return false;
		}

		private PlayerControllerB Player(int index)
		{
			PlayerControllerB[] array = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.allPlayerScripts : null);
			if (array == null || index < 0 || index >= array.Length)
			{
				return null;
			}
			return array[index];
		}

		private bool Valid(PlayerControllerB p)
		{
			if ((Object)(object)p != (Object)null && p.isPlayerControlled && !p.isPlayerDead)
			{
				return p.isInsideFactory;
			}
			return false;
		}

		internal JackActor(int id, JackWorld world, float scale)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			this.id = id;
			this.world = world;
			this.scale = scale;
			StateMessage = "JLeonL.JackSkellington.State." + id;
			RequestMessage = "JLeonL.JackSkellington.Request." + id;
		}

		internal bool TargetsGrab(PlayerControllerB p)
		{
			if (state == JackState.Grab)
			{
				return (Object)(object)Player(target) == (Object)(object)p;
			}
			return false;
		}

		internal void BeginVisit(bool spawn)
		{
			//IL_0049: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_0188: 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_0249: 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_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: 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_03fc: Unknown result type (might be due to invalid IL or missing references)
			enabled = Host && spawn;
			random = new Random(world.Seed ^ 0x68AC913 ^ (id * 1777));
			Vector3[] array = world.Waypoints;
			NavMeshHit val2 = default(NavMeshHit);
			foreach (Vector3 val in array)
			{
				if (NavMesh.SamplePosition(val, ref val2, 1f, world.AreaMask) && Mathf.Abs(((NavMeshHit)(ref val2)).position.y - val.y) < 0.6f)
				{
					waypoints.Add(((NavMeshHit)(ref val2)).position);
				}
			}
			if (waypoints.Count == 0)
			{
				JackPlugin.Log.LogWarning((object)("JACK_NO_NAVIGATION " + id));
				return;
			}
			Vector3[] array2 = (from p in waypoints
				where Vector3.Distance(p, world.PreferredSpawn) > (float)((id == 0) ? 18 : 32)
				orderby Vector3.Distance(p, world.PreferredSpawn)
				select p).ToArray();
			Vector3 val3 = ((array2.Length != 0) ? array2[Math.Min(id * 3, array2.Length - 1)] : waypoints[random.Next(waypoints.Count)]);
			root = new GameObject((id == 0) ? "JackSkellington" : "PumpkinKing");
			root.transform.SetParent(world.Root, true);
			root.transform.position = val3;
			root.layer = 19;
			root.tag = "Enemy";
			view = JackSkins.Create(root.transform, id, scale);
			if (view == null)
			{
				Object.Destroy((Object)(object)root);
				root = null;
				return;
			}
			root.AddComponent<JackHitbox>().Actor = this;
			body = root.AddComponent<CapsuleCollider>();
			body.radius = 0.32f * scale;
			body.height = Height;
			body.center = Vector3.up * (Height * 0.5f);
			Rigidbody obj = root.AddComponent<Rigidbody>();
			obj.isKinematic = true;
			obj.useGravity = false;
			scan = JackScanNodes.Configure(root.transform, "JackScanNode", Vector3.up * (2.25f * scale), (id == 0) ? "Jack Skellington" : "Pumpkin King", 1, inside: true, 45);
			voice = Source("ChaseVoice", 0.47f, 3f, 24f);
			voice.loop = true;
			scare = Source("Scare", 0.6f, 2f, 18f);
			steps = Source("Footsteps", 0.24f, 2f, 14f);
			if (Host)
			{
				mind = new JackBehaviour();
				hasSnapshot = true;
				if (enabled)
				{
					agent = root.AddComponent<NavMeshAgent>();
					agent.radius = 0.35f * scale;
					agent.height = Height;
					agent.speed = 1.65f;
					agent.areaMask = world.AreaMask;
					agent.acceleration = 12f;
					agent.angularSpeed = 240f;
					agent.stoppingDistance = 1.45f * scale;
					agent.autoTraverseOffMeshLink = false;
					agent.obstacleAvoidanceType = (ObstacleAvoidanceType)1;
					agent.Warp(val3);
				}
			}
			receivedPosition = (lastPosition = val3);
			receivedRotation = root.transform.rotation;
			root.SetActive(enabled);
			Register();
			JackPlugin.Log.LogInfo((object)("JACK_READY variant=" + id + " enabled=" + enabled + " host=" + Host + " height=" + 2.8f * scale + " world=" + world.Key));
		}

		private AudioSource Source(string name, float volume, float min, float max)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(root.transform, false);
			val.transform.localPosition = Vector3.up * (1.9f * scale);
			AudioSource obj = val.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.dopplerLevel = 0f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = min;
			obj.maxDistance = max;
			obj.volume = volume;
			obj.priority = 90;
			return obj;
		}

		private void Register()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null && !((Object)(object)registered == (Object)(object)singleton))
			{
				Unregister();
				registered = singleton;
				singleton.CustomMessagingManager.RegisterNamedMessageHandler(StateMessage, new HandleNamedMessageDelegate(Receive));
				singleton.CustomMessagingManager.RegisterNamedMessageHandler(RequestMessage, new HandleNamedMessageDelegate(Request));
			}
		}

		private void Unregister()
		{
			if ((Object)(object)registered != (Object)null && registered.CustomMessagingManager != null)
			{
				registered.CustomMessagingManager.UnregisterNamedMessageHandler(StateMessage);
				registered.CustomMessagingManager.UnregisterNamedMessageHandler(RequestMessage);
			}
			registered = null;
		}

		internal void Tick()
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			if (JackDirector.World != world)
			{
				EndVisit();
				return;
			}
			Register();
			NetworkManager singleton = NetworkManager.Singleton;
			double num;
			if (!((Object)(object)singleton != (Object)null) || !singleton.IsListening)
			{
				num = Time.time;
			}
			else
			{
				NetworkTime serverTime = singleton.ServerTime;
				num = ((NetworkTime)(ref serverTime)).Time;
			}
			clock = num;
			if (Host && mind != null)
			{
				if (enabled && clock >= nextThink)
				{
					nextThink = clock + 0.16;
					Think();
					state = mind.State;
					target = mind.Target;
					since = mind.Since;
					sequence = mind.Sequence;
				}
				if ((Object)(object)agent != (Object)null && agent.isOnNavMesh)
				{
					agent.isStopped = state == JackState.Grab;
					if (state == JackState.Grab && Valid(Player(target)))
					{
						Vector3 val = ((Component)Player(target)).transform.position - root.transform.position;
						val.y = 0f;
						if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
						{
							root.transform.rotation = Quaternion.RotateTowards(root.transform.rotation, Quaternion.LookRotation(val), Time.deltaTime * 240f);
						}
					}
					agent.speed = ((state == JackState.Roam) ? 1.65f : ((state == JackState.Retreat) ? 4.5f : 4f));
					if (clock >= nextPath && state != JackState.Grab)
					{
						nextPath = clock + ((state == JackState.Chase) ? 0.55 : 2.0);
						Navigate();
					}
				}
				if (clock >= nextSend)
				{
					nextSend = clock + (enabled ? 0.1 : 5.0);
					Send();
				}
			}
			else
			{
				if (clock >= nextSync && !hasSnapshot)
				{
					nextSync = clock + (double)Math.Min(30, 1 + syncAttempts++ * 2);
					SendRequest(0);
				}
				if (hasSnapshot)
				{
					root.transform.position = Vector3.Lerp(root.transform.position, receivedPosition, 1f - Mathf.Exp(-18f * Time.deltaTime));
					root.transform.rotation = Quaternion.Slerp(root.transform.rotation, receivedRotation, 1f - Mathf.Exp(-18f * Time.deltaTime));
				}
			}
			if (!enabled)
			{
				ReleaseLocal();
				voice.Stop();
				return;
			}
			if (!Host && hasSnapshot && clock - lastPacket > 1.5)
			{
				ReleaseLocal();
				voice.Stop();
				return;
			}
			Vector3 val2 = root.transform.position - lastPosition;
			bool moving = ((Vector3)(ref val2)).sqrMagnitude > 1E-06f;
			lastPosition = root.transform.position;
			view.Animate(state, clock - since, clock, moving);
			Presentation(moving);
		}

		private bool Visible(PlayerControllerB p, float range)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			if (!Valid(p) || Vector3.Distance(root.transform.position, ((Component)p).transform.position) > range)
			{
				return false;
			}
			Vector3 val = (((Object)(object)p.gameplayCamera != (Object)null) ? ((Component)p.gameplayCamera).transform.position : (((Component)p).transform.position + Vector3.up * 1.6f));
			return !Physics.Linecast(root.transform.position + Vector3.up * Mathf.Min(2.2f, 1.8f * scale), val, 134217985, (QueryTriggerInteraction)1);
		}

		private void Think()
		{
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			int num = mind.Target;
			PlayerControllerB val = Player(num);
			if (mind.State == JackState.Roam)
			{
				num = -1;
				float range = 22f;
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				for (int i = 0; i < allPlayerScripts.Length; i++)
				{
					if (Visible(allPlayerScripts[i], range))
					{
						range = Vector3.Distance(root.transform.position, ((Component)allPlayerScripts[i]).transform.position);
						num = i;
					}
				}
				val = Player(num);
			}
			if (!Valid(val))
			{
				num = -1;
			}
			bool flag = Visible(val, 26f);
			if (flag)
			{
				lastSeenPosition = ((Component)val).transform.position;
			}
			bool flag2 = Valid(val) && Vector3.Distance(root.transform.position, ((Component)val).transform.position) < 2.65f * scale;
			bool safe = flag2 && SafeGrab(val);
			JackState num2 = mind.State;
			int index = mind.Target;
			mind.Step(clock, num, flag, flag2, safe);
			if (num2 == JackState.Grab && mind.State != JackState.Grab)
			{
				JackDirector.Released(Player(index), clock);
			}
			if (num2 != mind.State)
			{
				if ((Object)(object)agent != (Object)null && agent.isOnNavMesh)
				{
					agent.ResetPath();
				}
				nextPath = 0.0;
				nextSend = 0.0;
				JackPlugin.Log.LogInfo((object)("CIRCUS_JACK_STATE " + mind.State.ToString() + " target=" + mind.Target + " sequence=" + mind.Sequence));
			}
		}

		private bool SafeGround(Vector3 p, bool connectors = false)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (!connectors)
			{
				return world.Flat(p);
			}
			return world.Route(p);
		}

		private bool SafeGrab(PlayerControllerB p)
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_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_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			if (!Valid(p) || !JackDirector.CanHold(p, this) || p.isClimbingLadder || p.inSpecialInteractAnimation || p.inTerminalMenu || (Object)(object)p.inAnimationWithEnemy != (Object)null || (world.Blocked != null && world.Blocked(p)))
			{
				return false;
			}
			if (Mathf.Abs(((Component)p).transform.position.y - root.transform.position.y) > 0.3f || !SafeGround(((Component)p).transform.position) || !SafeGround(root.transform.position))
			{
				return false;
			}
			Vector3[] arrivals = world.Arrivals;
			for (int i = 0; i < arrivals.Length; i++)
			{
				if (Vector3.Distance(arrivals[i], ((Component)p).transform.position) < 5f)
				{
					return false;
				}
			}
			if ((Object)(object)p == (Object)(object)Local && (Object)(object)p.thisController != (Object)null && !p.thisController.isGrounded)
			{
				return false;
			}
			Vector3 val = ((Component)p).transform.position - root.transform.position;
			val.y = 0f;
			return ClearFloorSegment(((Component)p).transform.position, root.transform.position + ((Vector3)(ref val)).normalized * GrabDistance);
		}

		private bool ClearFloorSegment(Vector3 a, Vector3 b)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			if (Physics.Linecast(a + Vector3.up * 0.6f, b + Vector3.up * 0.6f, 134217985, (QueryTriggerInteraction)1))
			{
				return false;
			}
			RaycastHit val2 = default(RaycastHit);
			for (int i = 0; i <= 6; i++)
			{
				Vector3 val = Vector3.Lerp(a, b, (float)i / 6f);
				if (!SafeGround(val) || !Physics.Raycast(val + Vector3.up * 0.35f, Vector3.down, ref val2, 0.7f, 134217985, (QueryTriggerInteraction)1) || Mathf.Abs(((RaycastHit)(ref val2)).point.y - a.y) > 0.18f)
				{
					return false;
				}
			}
			return true;
		}

		private bool SetRoute(Vector3 goal)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			NavMeshHit val = default(NavMeshHit);
			if (!NavMesh.SamplePosition(goal, ref val, 1f, -1) || Mathf.Abs(((NavMeshHit)(ref val)).position.y - goal.y) > 0.8f)
			{
				return false;
			}
			if (!agent.CalculatePath(((NavMeshHit)(ref val)).position, path) || (int)path.status != 0)
			{
				return false;
			}
			Vector3[] corners = path.corners;
			for (int i = 1; i < corners.Length; i++)
			{
				int num = Mathf.CeilToInt(Vector3.Distance(corners[i - 1], corners[i]) / 0.8f);
				for (int j = 0; j <= num; j++)
				{
					if (!SafeGround(Vector3.Lerp(corners[i - 1], corners[i], (float)j / (float)Math.Max(1, num)), connectors: true))
					{
						return false;
					}
				}
			}
			return agent.SetPath(path);
		}

		private void Navigate()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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)
			if (state == JackState.Chase)
			{
				if (!SetRoute(lastSeenPosition))
				{
					agent.ResetPath();
				}
				return;
			}
			OpenNearbyDoors();
			if (agent.hasPath && agent.remainingDistance > 2f)
			{
				return;
			}
			PlayerControllerB val = StartOfRound.Instance.allPlayerScripts.Where(Valid).OrderBy(delegate(PlayerControllerB p)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val3 = ((Component)p).transform.position - root.transform.position;
				return ((Vector3)(ref val3)).sqrMagnitude;
			}).FirstOrDefault();
			for (int num = 0; num < 18; num++)
			{
				Vector3 val2 = waypoints[random.Next(waypoints.Count)];
				float num2 = Vector3.Distance(root.transform.position, val2);
				if (!(num2 < 12f) && !(num2 > 105f) && (!((Object)(object)val != (Object)null) || state != JackState.Roam || num >= 12 || !(Vector3.Distance(val2, ((Component)val).transform.position) > 35f)) && (!((Object)(object)val != (Object)null) || state != JackState.Retreat || !(Vector3.Distance(val2, ((Component)val).transform.position) < 18f)) && SetRoute(val2))
				{
					return;
				}
			}
			agent.ResetPath();
		}

		private void OpenNearbyDoors()
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!world.Generic || clock < nextDoor)
			{
				return;
			}
			nextDoor = clock + 0.5;
			DoorLock[] doors = world.Doors;
			foreach (DoorLock val in doors)
			{
				if (!((Object)(object)val == (Object)null) && ((NetworkBehaviour)val).IsSpawned && !val.isLocked && !(Vector3.Distance(((Component)val).transform.position, root.transform.position) > 2.7f))
				{
					AnimatedObjectTrigger component = ((Component)val).GetComponent<AnimatedObjectTrigger>();
					if ((Object)(object)component != (Object)null && !component.boolValue)
					{
						component.TriggerAnimationNonPlayer(false, true, false);
						val.OpenDoorAsEnemyServerRpc();
					}
				}
			}
		}

		private void Presentation(bool moving)
		{
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB local = Local;
			bool flag = Valid(local);
			double num = clock - since;
			if ((Object)(object)voice.clip != (Object)(object)JackAudio.Chase)
			{
				voice.clip = JackAudio.Chase;
			}
			if (flag && state == JackState.Chase && (Object)(object)voice.clip != (Object)null)
			{
				if (!voice.isPlaying)
				{
					voice.Play();
				}
			}
			else if (voice.isPlaying)
			{
				voice.Stop();
			}
			if (flag && moving && state != JackState.Grab && clock >= nextStep)
			{
				nextStep = clock + ((state == JackState.Roam) ? 0.62 : 0.34);
				if ((Object)(object)JackAudio.Step != (Object)null)
				{
					steps.PlayOneShot(JackAudio.Step);
				}
			}
			if (flag && state == JackState.Chase && (Object)(object)Player(target) == (Object)(object)local && Visible(local, 16f))
			{
				local.IncreaseFearLevelOverTime(0.45f, 0.85f);
			}
			if (state == JackState.Grab && sequence != presentedSequence)
			{
				presentedSequence = sequence;
				if (flag && (Object)(object)JackAudio.Scare != (Object)null)
				{
					scare.PlayOneShot(JackAudio.Scare);
				}
				if (flag && (Object)(object)Player(target) == (Object)(object)local && num < 2.8 && SafeGrab(local))
				{
					held = local;
					heldSequence = sequence;
					oldMove = local.disableMoveInput;
					oldLook = local.disableLookInput;
					oldSpecial = local.inSpecialInteractAnimation;
					grabY = ((Component)local).transform.position.y;
					lastHeldPosition = ((Component)local).transform.position;
					grabDeadline = Time.unscaledTime + 3.2f;
					oldCamera = (((Object)(object)local.gameplayCamera != (Object)null) ? ((Component)local.gameplayCamera).transform.localRotation : Quaternion.identity);
					local.disableMoveInput = true;
					local.disableLookInput = true;
					local.inSpecialInteractAnimation = true;
					local.JumpToFearLevel(1f, true);
					if ((Object)(object)HUDManager.Instance != (Object)null)
					{
						HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
					}
				}
				else if (flag && (Object)(object)Player(target) == (Object)(object)local)
				{
					CancelGrab();
				}
			}
			if ((Object)(object)held != (Object)null && (state != JackState.Grab || sequence != heldSequence || (Object)(object)Player(target) != (Object)(object)held || !Valid(held) || Time.unscaledTime > grabDeadline || num >= 2.8))
			{
				ReleaseLocal();
			}
		}

		internal void MoveHeld(PlayerControllerB p)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: 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_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: 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_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: 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_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: 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_0329: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHolding(p))
			{
				return;
			}
			if (!((Object)(object)root == (Object)null) && JackDirector.World == world && Valid(p) && state == JackState.Grab && !(Time.unscaledTime > grabDeadline) && !((Object)(object)p.thisController == (Object)null) && ((Collider)p.thisController).enabled)
			{
				Vector3 val = ((Component)p).transform.position - lastHeldPosition;
				if (!(((Vector3)(ref val)).sqrMagnitude > 1f) && (world.Blocked == null || !world.Blocked(p)))
				{
					Vector3 val2 = ((Component)p).transform.position - root.transform.position;
					val2.y = 0f;
					Vector3 val3 = root.transform.position + ((Vector3)(ref val2)).normalized * Mathf.Min(GrabDistance, ((Vector3)(ref val2)).magnitude);
					val3.y = grabY;
					Vector3 position = ((Component)p).transform.position;
					position.y = grabY;
					Vector3 val4 = Vector3.MoveTowards(position, val3, Time.deltaTime * 1.7f);
					Vector3 facePosition = view.FacePosition;
					float num = (((Object)(object)p.gameplayCamera != (Object)null) ? Mathf.Max(0.1f, ((Component)p.gameplayCamera).transform.position.y - ((Component)p).transform.position.y) : 1.6f);
					float num2 = Mathf.Clamp(facePosition.y - grabY - num, 0f, Height);
					float num3 = Mathf.Clamp01((float)((clock - since - 2.15) / 0.55));
					num2 *= 1f - num3 * num3 * (3f - 2f * num3);
					val4.y = Mathf.MoveTowards(((Component)p).transform.position.y, grabY + num2, Time.deltaTime * ((num3 > 0f) ? Mathf.Max(6f, Height * 3f) : 6f));
					Vector3 b = val4;
					b.y = grabY;
					if (!ClearFloorSegment(position, b) || !ClearBodyMove(p, val4))
					{
						CancelGrab();
						return;
					}
					p.ResetFallGravity();
					p.thisController.Move(val4 - ((Component)p).transform.position);
					lastHeldPosition = ((Component)p).transform.position;
					if ((Object)(object)p.gameplayCamera != (Object)null)
					{
						Vector3 val5 = facePosition - ((Component)p.gameplayCamera).transform.position;
						if (((Vector3)(ref val5)).sqrMagnitude > 0.01f)
						{
							((Component)p.gameplayCamera).transform.rotation = Quaternion.Slerp(((Component)p.gameplayCamera).transform.rotation, Quaternion.LookRotation(val5), 1f - Mathf.Exp(-14f * Time.deltaTime));
						}
					}
					return;
				}
			}
			CancelGrab();
		}

		private bool ClearBodyMove(PlayerControllerB p, Vector3 next)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			CharacterController thisController = p.thisController;
			Vector3 val = next - ((Component)p).transform.position;
			if (((Vector3)(ref val)).sqrMagnitude < 1E-06f)
			{
				return true;
			}
			float num = Mathf.Max(0f, thisController.height * 0.5f - thisController.radius);
			Vector3 val2 = ((Component)thisController).transform.TransformPoint(thisController.center - Vector3.up * num);
			Vector3 val3 = ((Component)thisController).transform.TransformPoint(thisController.center + Vector3.up * num);
			float num2 = Mathf.Max(0.01f, Mathf.Max(Vector3.Distance(((Component)thisController).transform.position, ((Component)thisController).transform.TransformPoint(Vector3.right * thisController.radius)), Vector3.Distance(((Component)thisController).transform.position, ((Component)thisController).transform.TransformPoint(Vector3.forward * thisController.radius))) - 0.025f);
			return !Physics.CapsuleCast(val2, val3, num2, ((Vector3)(ref val)).normalized, ((Vector3)(ref val)).magnitude, 134217985, (QueryTriggerInteraction)1);
		}

		private void CancelGrab()
		{
			ReleaseLocal();
			if (cancelledSequence != sequence)
			{
				cancelledSequence = sequence;
				if (Host && mind != null)
				{
					JackDirector.Released(Player(mind.Target), clock);
					mind.Release(clock);
					nextThink = (nextPath = (nextSend = 0.0));
				}
				else
				{
					SendRequest(2);
				}
			}
		}

		private void ReleaseLocal()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)held != (Object)null)
			{
				Vector3 position = ((Component)held).transform.position;
				position.y = grabY;
				if ((Object)(object)held == (Object)(object)Local && Valid(held) && (Object)(object)held.thisController != (Object)null && ((Collider)held.thisController).enabled && ((Component)held).transform.position.y > grabY + 0.01f)
				{
					Vector3 val = ((Component)held).transform.position - lastHeldPosition;
					RaycastHit val2 = default(RaycastHit);
					if (((Vector3)(ref val)).sqrMagnitude < 0.25f && SafeGround(position) && Physics.Raycast(position + Vector3.up * 0.35f, Vector3.down, ref val2, 0.7f, 134217985, (QueryTriggerInteraction)1) && Mathf.Abs(((RaycastHit)(ref val2)).point.y - grabY) < 0.18f)
					{
						held.thisController.Move(position - ((Component)held).transform.position);
					}
				}
				held.disableMoveInput = oldMove;
				held.disableLookInput = oldLook;
				held.inSpecialInteractAnimation = oldSpecial;
				held.ResetFallGravity();
				if ((Object)(object)held.gameplayCamera != (Object)null)
				{
					((Component)held.gameplayCamera).transform.localRotation = oldCamera;
				}
			}
			held = null;
			heldSequence = uint.MaxValue;
		}

		internal bool Hit(int force, PlayerControllerB hitter)
		{
			if (force <= 0 || !enabled || !Valid(hitter) || (Object)(object)root == (Object)null)
			{
				return false;
			}
			if (Host)
			{
				Provoke(hitter);
			}
			else if ((Object)(object)hitter == (Object)(object)Local && Time.unscaledTime - lastHitRequest > 0.3f)
			{
				lastHitRequest = Time.unscaledTime;
				SendRequest(1);
			}
			return true;
		}

		private void Provoke(PlayerControllerB hitter)
		{
			//IL_0054: 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)
			if (enabled && mind != null && Valid(hitter) && Visible(hitter, 6f))
			{
				int num = Array.IndexOf(StartOfRound.Instance.allPlayerScripts, hitter);
				if (mind.Provoke(clock, num))
				{
					lastSeenPosition = ((Component)hitter).transform.position;
					nextThink = (nextPath = (nextSend = 0.0));
				}
			}
		}

		private unsafe void SendRequest(byte kind)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)registered == (Object)null || !registered.IsListening || world == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref world.Seed, default(ForPrimitives));
				int keyHash = world.KeyHash;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref keyHash, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref kind, default(ForPrimitives));
				registered.CustomMessagingManager.SendNamedMessage(RequestMessage, 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void Request(ulong sender, FastBufferReader reader)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			if (!Host || (Object)(object)root == (Object)null || mind == null || world == null || JackDirector.World != world || ((FastBufferReader)(ref reader)).Length < 9)
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int num2 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			byte b = default(byte);
			((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			if (num != world.Seed || num2 != world.KeyHash)
			{
				return;
			}
			if (b == 0)
			{
				Send(sender);
				return;
			}
			PlayerControllerB val = ((IEnumerable<PlayerControllerB>)StartOfRound.Instance.allPlayerScripts).FirstOrDefault((Func<PlayerControllerB, bool>)((PlayerControllerB x) => (Object)(object)x != (Object)null && x.actualClientId == sender && Valid(x)));
			if (!((Object)(object)val == (Object)null))
			{
				if (b == 1)
				{
					Provoke(val);
				}
				if (b == 2 && mind.State == JackState.Grab && (Object)(object)Player(mind.Target) == (Object)(object)val)
				{
					JackDirector.Released(val, clock);
					mind.Release(clock);
					nextThink = (nextPath = (nextSend = 0.0));
				}
			}
		}

		private unsafe void Send(ulong? client = null)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0190: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)registered == (Object)null || !registered.IsListening || (Object)(object)root == (Object)null || mind == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(96, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref world.Seed, default(ForPrimitives));
				int keyHash = world.KeyHash;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref keyHash, default(ForPrimitives));
				byte b = (enabled ? ((byte)1) : ((byte)0));
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref scale, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<double>(ref clock, default(ForPrimitives));
				keyHash = (int)mind.State;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref keyHash, default(ForPrimitives));
				keyHash = mind.Target;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref keyHash, default(ForPrimitives));
				double num = mind.Since;
				((FastBufferWriter)(ref val)).WriteValueSafe<double>(ref num, default(ForPrimitives));
				uint num2 = mind.Sequence;
				((FastBufferWriter)(ref val)).WriteValueSafe<uint>(ref num2, default(ForPrimitives));
				Vector3 position = root.transform.position;
				((FastBufferWriter)(ref val)).WriteValueSafe(ref position);
				Quaternion rotation = root.transform.rotation;
				((FastBufferWriter)(ref val)).WriteValueSafe(ref rotation);
				if (client.HasValue)
				{
					registered.CustomMessagingManager.SendNamedMessage(StateMessage, client.Value, val, (NetworkDelivery)3);
				}
				else
				{
					registered.CustomMessagingManager.SendNamedMessageToAll(StateMessage, val, (NetworkDelivery)3);
				}
			}
			finally
			{
				((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
			}
		}

		private void Receive(ulong sender, FastBufferReader reader)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: 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_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: 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_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0286: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: 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_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0329: Unknown result type (might be due to invalid IL or missing references)
			if (Host || sender != 0L || (Object)(object)root == (Object)null || JackDirector.World != world || world == null || ((FastBufferReader)(ref reader)).Length < 69)
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			int num2 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num2, default(ForPrimitives));
			byte b = default(byte);
			((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			float num3 = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num3, default(ForPrimitives));
			double num4 = default(double);
			((FastBufferReader)(ref reader)).ReadValueSafe<double>(ref num4, default(ForPrimitives));
			int num5 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num5, default(ForPrimitives));
			int num6 = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num6, default(ForPrimitives));
			double num7 = default(double);
			((FastBufferReader)(ref reader)).ReadValueSafe<double>(ref num7, default(ForPrimitives));
			uint num8 = default(uint);
			((FastBufferReader)(ref reader)).ReadValueSafe<uint>(ref num8, default(ForPrimitives));
			Vector3 pos = default(Vector3);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref pos);
			Quaternion val = default(Quaternion);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref val);
			if (num != world.Seed || num2 != world.KeyHash || b > 1 || !float.IsFinite(num3) || num3 < 0.6f || num3 > 2f || num5 < 0 || num5 > 3 || double.IsNaN(num4) || double.IsInfinity(num4) || num4 <= lastPacket || num7 > num4 || double.IsNaN(num7) || double.IsInfinity(num7) || !float.IsFinite(pos.x) || !float.IsFinite(pos.y) || !float.IsFinite(pos.z) || !waypoints.Any(delegate(Vector3 p)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val2 = p - pos;
				return ((Vector3)(ref val2)).sqrMagnitude < 48400f;
			}))
			{
				return;
			}
			float num9 = val.x * val.x + val.y * val.y + val.z * val.z + val.w * val.w;
			if (float.IsFinite(num9) && !(num9 < 0.9f) && !(num9 > 1.1f) && num6 >= -1 && num6 < StartOfRound.Instance.allPlayerScripts.Length)
			{
				enabled = b == 1;
				scale = num3;
				view.SetScale(num3);
				body.radius = 0.32f * num3;
				body.height = Height;
				body.center = Vector3.up * (Height * 0.5f);
				((Component)scan).transform.localPosition = Vector3.up * (2.25f * num3);
				root.SetActive(enabled);
				state = (JackState)num5;
				target = num6;
				since = num7;
				sequence = num8;
				receivedPosition = pos;
				receivedRotation = val;
				lastPacket = num4;
				if (!hasSnapshot)
				{
					root.transform.SetPositionAndRotation(pos, val);
				}
				hasSnapshot = true;
			}
		}

		internal void EndVisit()
		{
			ReleaseLocal();
			Unregister();
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			root = null;
			agent = null;
			body = null;
			voice = null;
			scare = null;
			steps = null;
			mind = null;
			waypoints.Clear();
			state = JackState.Roam;
			target = -1;
			sequence = 0u;
			since = 0.0;
			clock = 0.0;
			lastPacket = -1.0;
			nextSend = (nextThink = (nextPath = (nextSync = (nextStep = 0.0))));
			hasSnapshot = false;
			presentedSequence = (cancelledSequence = uint.MaxValue);
		}
	}
	public sealed class JackHitbox : MonoBehaviour, IHittable
	{
		internal JackActor Actor;

		public bool Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			if (Actor != null)
			{
				return Actor.Hit(force, playerWhoHit);
			}
			return false;
		}
	}
	internal static class JackAudio
	{
		internal static AudioClip Chase;

		internal static AudioClip Scare;

		internal static AudioClip Step;

		internal static void Initialize(MonoBehaviour runtime, string directory)
		{
			string text = Path.Combine(directory, "audio", "jack-26-38.wav");
			runtime.StartCoroutine(Load(File.Exists(text) ? text : Path.Combine(directory, "audio", "effects", "jack-chase.wav"), delegate(AudioClip c)
			{
				Chase = c;
			}));
			runtime.StartCoroutine(Load(Path.Combine(directory, "audio", "effects", "jack-scare.wav"), delegate(AudioClip c)
			{
				Scare = c;
			}));
			runtime.StartCoroutine(Load(Path.Combine(directory, "audio", "effects", "jack-step.wav"), delegate(AudioClip c)
			{
				Step = c;
			}));
		}

		private static IEnumerator Load(string file, Action<AudioClip> receive)
		{
			if (!File.Exists(file))
			{
				JackPlugin.Log.LogWarning((object)("CIRCUS_JACK_AUDIO_MISSING " + Path.GetFileName(file)));
				yield break;
			}
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(new Uri(file).AbsoluteUri, (AudioType)20);
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result == 1)
				{
					receive(DownloadHandlerAudioClip.GetContent(request));
				}
				else
				{
					JackPlugin.Log.LogWarning((object)("CIRCUS_JACK_AUDIO_FAILED " + request.error));
				}
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		internal static void Dispose()
		{
			AudioClip[] array = (AudioClip[])(object)new AudioClip[3] { Chase, Scare, Step };
			foreach (AudioClip val in array)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
			}
			Chase = (Scare = (Step = null));
		}
	}
	[HarmonyPatch(typeof(HUDManager), "AssignNewNodes")]
	internal static class JackScanner
	{
		private static readonly Action<HUDManager, ScanNodeProperties, int, PlayerControllerB> attempt = AccessTools.MethodDelegate<Action<HUDManager, ScanNodeProperties, int, PlayerControllerB>>(AccessTools.Method(typeof(HUDManager), "AttemptScanNode", (Type[])null, (Type[])null), (object)null, true);

		[HarmonyPostfix]
		private static void Postfix(HUDManager __instance, PlayerControllerB playerScript)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			if (JackDirector.World == null || (Object)(object)playerScript == (Object)null || playerScript.isPlayerDead || (Object)(object)playerScript.gameplayCamera == (Object)null)
			{
				return;
			}
			foreach (JackScanTarget target in JackScanNodes.Targets)
			{
				if ((Object)(object)target == (Object)null || (Object)(object)target.Node == (Object)null || !((Behaviour)target.Node).isActiveAndEnabled || target.Inside != playerScript.isInsideFactory)
				{
					continue;
				}
				ScanNodeProperties node = target.Node;
				Vector3 val = ((Component)node).transform.position - ((Component)playerScript).transform.position;
				if (!(((Vector3)(ref val)).sqrMagnitude >= (float)(node.maxRange * node.maxRange)))
				{
					Vector3 val2 = playerScript.gameplayCamera.WorldToViewportPoint(((Component)node).transform.position);
					if (!(val2.z <= 0f) && !(val2.x < 0f) && !(val2.x > 1f) && !(val2.y < 0f) && !(val2.y > 1f))
					{
						attempt(__instance, node, 0, playerScript);
					}
				}
			}
		}
	}
	internal static class JackScanNodes
	{
		internal const string MobHeader = "Surprise surprise, not a monster";

		internal const int MobRange = 45;

		internal const int DoorRange = 60;

		internal static readonly List<JackScanTarget> Targets = new List<JackScanTarget>();

		internal static ScanNodeProperties Configure(Transform parent, string name, Vector3 position, string header, int type, bool inside, int range)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			Transform val = parent.Find(name);
			if ((Object)(object)val == (Object)null)
			{
				val = new GameObject(name).transform;
				val.SetParent(parent, false);
			}
			val.localPosition = position;
			val.localRotation = Quaternion.identity;
			val.localScale = Vector3.one;
			int num = LayerMask.NameToLayer("ScanNode");
			((Component)val).gameObject.layer = ((num >= 0) ? num : 22);
			ScanNodeProperties val2 = ((Component)val).GetComponent<ScanNodeProperties>() ?? ((Component)val).gameObject.AddComponent<ScanNodeProperties>();
			((Behaviour)val2).enabled = true;
			val2.headerText = header;
			val2.subText = "";
			val2.nodeType = type;
			val2.creatureScanID = -1;
			val2.scrapValue = 0;
			val2.minRange = 0;
			val2.maxRange = range;
			val2.requiresLineOfSight = true;
			SphereCollider obj = ((Component)val).GetComponent<SphereCollider>() ?? ((Component)val).gameObject.AddComponent<SphereCollider>();
			((Collider)obj).enabled = true;
			((Collider)obj).isTrigger = true;
			obj.radius = 0.45f;
			obj.center = Vector3.zero;
			Rigidbody obj2 = ((Component)val).GetComponent<Rigidbody>() ?? ((Component)val).gameObject.AddComponent<Rigidbody>();
			obj2.isKinematic = true;
			obj2.useGravity = false;
			JackScanTarget jackScanTarget = ((Component)val).GetComponent<JackScanTarget>() ?? ((Component)val).gameObject.AddComponent<JackScanTarget>();
			jackScanTarget.Node = val2;
			jackScanTarget.Inside = inside;
			if (!Targets.Contains(jackScanTarget))
			{
				Targets.Add(jackScanTarget);
			}
			return val2;
		}

		internal static void Forget(JackScanTarget target)
		{
			Targets.Remove(target);
		}

		internal static void EndVisit()
		{
			Targets.Clear();
		}
	}
	public sealed class JackScanTarget : MonoBehaviour
	{
		internal ScanNodeProperties Node;

		internal bool Inside;

		private void OnDestroy()
		{
			JackScanNodes.Forget(this);
		}
	}
	internal sealed class JackSkinView
	{
		internal Transform Root;

		internal Transform[] Bones;

		internal GameObject OriginalHead;

		internal GameObject Normal;

		internal GameObject Scare;

		internal CharacterAssetData Data;

		private int lastClip = -1;

		private float nextTick;

		internal Vector3 FacePosition => Bones[5].TransformPoint(new Vector3(0f, 0.08f, -0.13f));

		internal void SetScale(float scale)
		{
			//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)
			Root.localScale = Vector3.one * scale;
		}

		internal void Animate(JackState state, double elapsed, double clock, bool moving)
		{
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: 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)
			bool flag = state == JackState.Grab;
			if ((Object)(object)OriginalHead != (Object)null)
			{
				OriginalHead.SetActive(!flag);
			}
			if ((Object)(object)Normal != (Object)null)
			{
				Normal.SetActive(!flag);
			}
			Scare.SetActive(flag);
			int num = (flag ? 3 : ((!moving) ? 1 : ((state == JackState.Chase || state == JackState.Retreat) ? 2 : 0)));
			if (!(Time.unscaledTime < nextTick) || num != lastClip)
			{
				nextTick = Time.unscaledTime + 1f / 30f;
				lastClip = num;
				CharacterClipData characterClipData = Data.Clips[num];
				double num2 = (flag ? Math.Max(0.0, Math.Min((double)characterClipData.Duration - 0.001, elapsed)) : clock);
				int num3 = 3 + Bones.Length * 4;
				double num4 = (num2 % (double)characterClipData.Duration + (double)characterClipData.Duration) % (double)characterClipData.Duration / (double)characterClipData.Duration * (double)(characterClipData.Frames - 1);
				int num5 = (int)num4;
				int num6 = num5 * num3;
				int num7 = Math.Min(num5 + 1, characterClipData.Frames - 1) * num3;
				float num8 = (float)(num4 - (double)num5);
				Bones[0].localPosition = JackSkins.V(Data.LocalPositions[0]) + Vector3.Lerp(JackSkins.V(characterClipData.Samples, num6), JackSkins.V(characterClipData.Samples, num7), num8);
				for (int i = 0; i < Bones.Length; i++)
				{
					Bones[i].localRotation = Quaternion.Slerp(JackSkins.Q(characterClipData.Samples, num6 + 3 + i * 4), JackSkins.Q(characterClipData.Samples, num7 + 3 + i * 4), num8);
				}
			}
		}
	}
	internal static class JackSkins
	{
		private sealed class Head
		{
			public Mesh[] Meshes;

			public Material[] Materials;

			public HeadAssetData Data;
		}

		private static string folder;

		private static CharacterAssetData data;

		private static Mesh[] bodies;

		private static Mesh[] heads;

		private static Material[] materials;

		private static readonly Dictionary<string, Head> alternatives = new Dictionary<string, Head>();

		private static readonly List<Texture2D> textures = new List<Texture2D>();

		internal static void Initialize(string directory)
		{
			folder = Path.Combine(directory, "characters");
		}

		internal static Vector3 V(float[] a, int o = 0)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(a[o], a[o + 1], a[o + 2]);
		}

		internal static Quaternion Q(float[] a, int o)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(a[o], a[o + 1], a[o + 2], a[o + 3]);
		}

		private static Material Material(Color color, Color emission, string name)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Expected O, but got Unknown
			Shader obj = Shader.Find("HDRP/Lit");
			if ((Object)(object)obj == (Object)null)
			{
				throw new InvalidOperationException("HDRP/Lit not loaded yet");
			}
			Material val = new Material(obj)
			{
				name = name
			};
			val.SetColor("_BaseColor", color);
			val.SetFloat("_Metallic", 0f);
			val.SetFloat("_Smoothness", 0.18f);
			val.SetFloat("_DoubleSidedEnable", 1f);
			val.SetFloat("_CullMode", 0f);
			val.SetFloat("_CullModeForward", 0f);
			val.SetVector("_DoubleSidedConstants", new Vector4(1f, 1f, -1f, 0f));
			val.EnableKeyword("_DOUBLESIDED_ON");
			val.SetColor("_EmissiveColor", emission);
			val.SetFloat("_UseEmissiveIntensity", 0f);
			return val;
		}

		private static Texture2D Texture(string name, bool normal)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			if (string.IsNullOrEmpty(name))
			{
				return null;
			}
			if (Path.GetFileName(name) != name)
			{
				throw new InvalidDataException("Unsafe texture path");
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, normal)
			{
				name = name,
				filterMode = (FilterMode)2,
				anisoLevel = 2
			};
			if (!ImageConversion.LoadImage(val, File.ReadAllBytes(Path.Combine(folder, name)), false))
			{
				throw new InvalidDataException(name);
			}
			if (!normal)
			{
				val.Compress(true);
			}
			val.Apply(true, true);
			textures.Add(val);
			return val;
		}

		private static void Load()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: 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_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0419: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d4: 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_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Expected O, but got Unknown
			if (data != null)
			{
				return;
			}
			CharacterAssetData characterAssetData = CharacterAssetData.Read(Path.Combine(folder, "jack.cskin"));
			Material[] array = (Material[])(object)new Material[characterAssetData.Materials.Length];
			for (int i = 0; i < array.Length; i++)
			{
				CharacterMaterialData characterMaterialData = characterAssetData.Materials[i];
				Material val = Material(new Color(characterMaterialData.Color[0] * 0.88f, characterMaterialData.Color[1] * 0.88f, characterMaterialData.Color[2] * 0.88f, 1f), Color.black, "Jack_" + characterMaterialData.Name);
				Texture2D val2 = Texture(characterMaterialData.Albedo, normal: false);
				if ((Object)(object)val2 != (Object)null)
				{
					val.SetTexture("_BaseColorMap", (Texture)(object)val2);
				}
				Texture2D val3 = Texture(characterMaterialData.Normal, normal: true);
				if ((Object)(object)val3 != (Object)null)
				{
					val.SetTexture("_NormalMap", (Texture)(object)val3);
					val.SetFloat("_NormalScale", 0.7f);
					val.EnableKeyword("_NORMALMAP_TANGENT_SPACE");
				}
				array[i] = val;
			}
			Mesh[] array2 = (Mesh[])(object)new Mesh[characterAssetData.Lods.Length];
			Mesh[] array3 = (Mesh[])(object)new Mesh[characterAssetData.Lods.Length];
			for (int j = 0; j < characterAssetData.Lods.Length; j++)
			{
				CharacterMeshData characterMeshData = characterAssetData.Lods[j];
				int num = characterMeshData.Vertices.Length / 8;
				Vector3[] v = (Vector3[])(object)new Vector3[num];
				Vector3[] n = (Vector3[])(object)new Vector3[num];
				Vector2[] uv = (Vector2[])(object)new Vector2[num];
				BoneWeight[] w = (BoneWeight[])(object)new BoneWeight[num];
				for (int k = 0; k < num; k++)
				{
					v[k] = V(characterMeshData.Vertices, k * 8);
					n[k] = V(characterMeshData.Vertices, k * 8 + 3);
					uv[k] = new Vector2(characterMeshData.Vertices[k * 8 + 6], characterMeshData.Vertices[k * 8 + 7]);
					int num2 = k * 4;
					BoneWeight[] array4 = w;
					int num3 = k;
					BoneWeight val4 = default(BoneWeight);
					((BoneWeight)(ref val4)).boneIndex0 = characterMeshData.Bones[num2];
					((BoneWeight)(ref val4)).boneIndex1 = characterMeshData.Bones[num2 + 1];
					((BoneWeight)(ref val4)).boneIndex2 = characterMeshData.Bones[num2 + 2];
					((BoneWeight)(ref val4)).boneIndex3 = characterMeshData.Bones[num2 + 3];
					((BoneWeight)(ref val4)).weight0 = characterMeshData.Weights[num2];
					((BoneWeight)(ref val4)).weight1 = characterMeshData.Weights[num2 + 1];
					((BoneWeight)(ref val4)).weight2 = characterMeshData.Weights[num2 + 2];
					((BoneWeight)(ref val4)).weight3 = characterMeshData.Weights[num2 + 3];
					array4[num3] = val4;
				}
				SkinPartition skinPartition = SkinPartition.Split(characterAssetData, j);
				Matrix4x4[] bind = characterAssetData.BindPositions.Select((float[] p) => Matrix4x4.Translate(-V(p))).ToArray();
				array2[j] = Build("JackBodyLOD" + j, skinPartition.Body);
				array3[j] = Build("JackOriginalHeadLOD" + j, skinPartition.Head);
				Mesh Build(string name, int[][] indices)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0005: 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_0014: Expected O, but got Unknown
					Mesh val6 = new Mesh
					{
						name = name,
						indexFormat = (IndexFormat)1
					};
					val6.vertices = v;
					val6.normals = n;
					val6.uv = uv;
					val6.boneWeights = w;
					val6.bindposes = bind;
					val6.subMeshCount = indices.Length;
					for (int l = 0; l < indices.Length; l++)
					{
						val6.SetTriangles(indices[l], l);
					}
					val6.RecalculateTangents();
					val6.RecalculateBounds();
					return val6;
				}
			}
			string[] array5 = new string[3] { "jack_scare", "pumpkin", "pumpkin_scare" };
			foreach (string text in array5)
			{
				HeadAssetData headAssetData = HeadAssetData.Read(Path.Combine(folder, text + ".jhead"));
				Head head = new Head
				{
					Data = headAssetData,
					Materials = (Material[])(object)new Material[headAssetData.Materials.Length],
					Meshes = (Mesh[])(object)new Mesh[headAssetData.Lods.Length]
				};
				for (int num5 = 0; num5 < headAssetData.Materials.Length; num5++)
				{
					HeadMaterialData headMaterialData = headAssetData.Materials[num5];
					head.Materials[num5] = Material(new Color(headMaterialData.Color[0], headMaterialData.Color[1], headMaterialData.Color[2], headMaterialData.Color[3]), new Color(headMaterialData.Emission[0], headMaterialData.Emission[1], headMaterialData.Emission[2]), text + "Material" + num5);
				}
				for (int num6 = 0; num6 < headAssetData.Lods.Length; num6++)
				{
					HeadMeshData headMeshData = headAssetData.Lods[num6];
					int num7 = headMeshData.Vertices.Length / 6;
					Vector3[] array6 = (Vector3[])(object)new Vector3[num7];
					Vector3[] array7 = (Vector3[])(object)new Vector3[num7];
					for (int num8 = 0; num8 < num7; num8++)
					{
						array6[num8] = V(headMeshData.Vertices, num8 * 6);
						array7[num8] = V(headMeshData.Vertices, num8 * 6 + 3);
					}
					Mesh val5 = new Mesh
					{
						name = text + "LOD" + num6,
						indexFormat = (IndexFormat)1
					};
					val5.vertices = array6;
					val5.normals = array7;
					val5.subMeshCount = headMeshData.Indices.Length;
					for (int num9 = 0; num9 < headMeshData.Indices.Length; num9++)
					{
						val5.SetTriangles(headMeshData.Indices[num9], num9);
					}
					val5.RecalculateBounds();
					head.Meshes[num6] = val5;
				}
				alternatives.Add(text, head);
			}
			data = characterAssetData;
			materials = array;
			bodies = array2;
			heads = array3;
			JackPlugin.Log.LogInfo((object)("JACK_SKINS_READY joints=" + characterAssetData.Parents.Length + " headVariants=3 originalHeadPartitioned=True"));
		}

		internal static JackSkinView Create(Transform parent, int variant, float scale)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			//IL_00df: 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_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Load();
				Transform transform = new GameObject("JackArticulatedVisual").transform;
				transform.SetParent(parent, false);
				transform.localRotation = Quaternion.Euler(0f, 180f, 0f);
				transform.localScale = Vector3.one * scale;
				JackSkinView view = new JackSkinView
				{
					Root = transform,
					Data = data,
					Bones = (Transform[])(object)new Transform[data.Parents.Length]
				};
				for (int i = 0; i < view.Bones.Length; i++)
				{
					Transform transform2 = new GameObject(data.BoneNames[i]).transform;
					transform2.SetParent((data.Parents[i] < 0) ? transform : view.Bones[data.Parents[i]], false);
					transform2.localPosition = V(data.LocalPositions[i]);
					view.Bones[i] = transform2;
				}
				GameObject val = new GameObject("OriginalSkull");
				val.transform.SetParent(transform, false);
				LOD[] array = (LOD[])(object)new LOD[bodies.Length];
				float[] levels = new float[3] { 0.15f, 0.055f, 0.008f };
				int l;
				for (l = 0; l < bodies.Length; l++)
				{
					SkinnedMeshRenderer val2 = Renderer(bodies[l], transform);
					SkinnedMeshRenderer val3 = Renderer(heads[l], val.transform);
					array[l] = new LOD(levels[l], (Renderer[])(object)new Renderer[2]
					{
						(Renderer)val2,
						(Renderer)val3
					});
				}
				LODGroup obj = ((Component)transform).gameObject.AddComponent<LODGroup>();
				obj.SetLODs(array);
				obj.size = 3.4f;
				obj.localReferencePoint = Vector3.up;
				if (variant == 0)
				{
					view.OriginalHead = val;
				}
				else
				{
					val.SetActive(false);
				}
				if (variant == 1)
				{
					view.Normal = Alternative("pumpkin");
				}
				view.Scare = Alternative((variant == 0) ? "jack_scare" : "pumpkin_scare");
				view.Animate(JackState.Roam, 0.0, 0.0, moving: false);
				return view;
				GameObject Alternative(string key)
				{
					//IL_0018: Unknown result type (might be due to invalid IL or missing references)
					//IL_001e: Expected O, but got Unknown
					//IL_0063: Unknown result type (might be due to invalid IL or missing references)
					//IL_0068: Unknown result type (might be due to invalid IL or missing references)
					//IL_007a: Unknown result type (might be due to invalid IL or missing references)
					//IL_0138: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
					//IL_0104: Unknown result type (might be due to invalid IL or missing references)
					Head a = alternatives[key];
					GameObject val4 = new GameObject(key);
					val4.transform.SetParent(view.Bones[5], false);
					LOD[] array2 = (LOD[])(object)new LOD[a.Meshes.Length];
					for (int j = 0; j < a.Meshes.Length; j++)
					{
						GameObject val5 = new GameObject(key + "LOD" + j);
						val5.transform.SetParent(val4.transform, false);
						val5.AddComponent<MeshFilter>().sharedMesh = a.Meshes[j];
						MeshRenderer val6 = val5.AddComponent<MeshRenderer>();
						((Renderer)val6).sharedMaterials = a.Data.Lods[j].Materials.Select((int num) => a.Materials[num]).ToArray();
						((Renderer)val6).shadowCastingMode = (ShadowCastingMode)0;
						array2[j] = new LOD(levels[j], (Renderer[])(object)new Renderer[1] { (Renderer)val6 });
					}
					LODGroup obj2 = val4.AddComponent<LODGroup>();
					obj2.SetLODs(array2);
					obj2.size = 1f;
					obj2.localReferencePoint = Vector3.zero;
					return val4;
				}
				SkinnedMeshRenderer Renderer(Mesh mesh, Transform p)
				{
					//IL_0006: Unknown result type (might be due to invalid IL or missing references)
					//IL_000b: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
					GameObject val4 = new GameObject(((Object)mesh).name);
					val4.transform.SetParent(p, false);
					SkinnedMeshRenderer obj2 = val4.AddComponent<SkinnedMeshRenderer>();
					obj2.sharedMesh = mesh;
					obj2.bones = view.Bones;
					obj2.rootBone = view.Bones[0];
					obj2.quality = (SkinQuality)4;
					((Renderer)obj2).sharedMaterials = data.Lods[l].Materials.Select((int num) => materials[num]).ToArray();
					((Renderer)obj2).localBounds = new Bounds(new Vector3(0f, 1.4f, 0f), new Vector3(6f, 6f, 6f));
					((Renderer)obj2).shadowCastingMode = (ShadowCastingMode)0;
					((Renderer)obj2).receiveShadows = true;
					return obj2;
				}
			}
			catch (Exception ex)
			{
				JackPlugin.Log.LogError((object)("JACK_SKIN_FAILED " + ex));
				return null;
			}
		}

		internal static void Dispose()
		{
			if (bodies != null)
			{
				foreach (Mesh item in bodies.Concat(heads))
				{
					Object.Destroy((Object)(object)item);
				}
			}
			if (materials != null)
			{
				Material[] array = materials;
				for (int i = 0; i < array.Length; i++)
				{
					Object.Destroy((Object)(object)array[i]);
				}
			}
			foreach (Head value in alternatives.Values)
			{
				Mesh[] meshes = value.Meshes;
				for (int i = 0; i < meshes.Length; i++)
				{
					Object.Destroy((Object)(object)meshes[i]);
				}
				Material[] array = value.Materials;
				for (int i = 0; i < array.Length; i++)
				{
					Object.Destroy((Object)(object)array[i]);
				}
			}
			alternatives.Clear();
			foreach (Texture2D texture in textures)
			{
				Object.Destroy((Object)(object)texture);
			}
			textures.Clear();
			data = null;
			bodies = (heads = null);
			materials = null;
		}
	}
	public sealed class JackWorld
	{
		public string Key;

		public int Seed;

		public int AreaMask = -1;

		public Transform Root;

		public Vector3[] Waypoints;

		public Vector3[] Arrivals;

		public Vector3 PreferredSpawn;

		public Func<Vector3, bool> Flat;

		public Func<Vector3, bool> Route;

		public Func<PlayerControllerB, bool> Blocked;

		internal DoorLock[] Doors = Array.Empty<DoorLock>();

		internal bool Generic;

		public int KeyHash
		{
			get
			{
				uint num = 2166136261u;
				string text = Key ?? "";
				foreach (char c in text)
				{
					num = (num ^ c) * 16777619;
				}
				return (int)num;
			}
		}
	}
	public static class WorldBridge
	{
		public static string Status
		{
			get
			{
				if (JackDirector.World != null)
				{
					return string.Join("; ", JackDirector.Actors.Select((JackActor a) => a.Status));
				}
				return "inactive";
			}
		}

		public static void Register(string key, int seed, Transform root, Vector3[] waypoints, Vector3 preferredSpawn, Vector3[] arrivals, Func<Vector3, bool> flat, Func<Vector3, bool> route, Func<PlayerControllerB, bool> blocked, int areaMask)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)root == (Object)null) && waypoints != null && waypoints.Length != 0 && flat != null && route != null && (JackDirector.World == null || !((Object)(object)JackDirector.World.Root == (Object)(object)root) || JackDirector.World.Seed != seed))
			{
				JackDirector.Begin(new JackWorld
				{
					Key = key,
					Seed = seed,
					Root = root,
					Waypoints = waypoints,
					PreferredSpawn = preferredSpawn,
					Arrivals = (arrivals ?? Array.Empty<Vector3>()),
					Flat = flat,
					Route = route,
					Blocked = blocked,
					AreaMask = areaMask
				});
			}
		}

		public static bool IsHolding(PlayerControllerB player)
		{
			return JackDirector.IsHolding(player);
		}

		public static void Unregister(Transform root)
		{
			if (JackDirector.World != null && (Object)(object)JackDirector.World.Root == (Object)(object)root)
			{
				JackDirector.EndVisit();
			}
		}
	}
	internal static class JackDirector
	{
		internal static JackWorld World;

		internal static readonly List<JackActor> Actors = new List<JackActor>();

		private static readonly Dictionary<ulong, double> recovery = new Dictionary<ulong, double>();

		private static float nextDiscovery;

		private static bool landed;

		internal static bool Host
		{
			get
			{
				if (!((Object)(object)NetworkManager.Singleton == (Object)null) && NetworkManager.Singleton.IsListening)
				{
					return NetworkManager.Singleton.IsServer;
				}
				return true;
			}
		}

		internal static bool CanHold(PlayerControllerB player, JackActor requester)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			double num;
			if (!((Object)(object)NetworkManager.Singleton != (Object)null) || !NetworkManager.Singleton.IsListening)
			{
				num = Time.time;
			}
			else
			{
				NetworkTime serverTime = NetworkManager.Singleton.ServerTime;
				num = ((NetworkTime)(ref serverTime)).Time;
			}
			double num2 = num;
			if (!recovery.TryGetValue(player.actualClientId, out var value) || num2 >= value)
			{
				return !Actors.Any((JackActor a) => a != requester && a.TargetsGrab(player));
			}
			return false;
		}

		internal static void Released(PlayerControllerB player, double now)
		{
			if ((Object)(object)player != (Object)null)
			{
				recovery[player.actualClientId] = now + 30.0;
			}
		}

		internal static bool IsHolding(PlayerControllerB player)
		{
			return Actors.Any((JackActor a) => a.IsHolding(player));
		}

		internal static void MoveHeld(PlayerControllerB player)
		{
			foreach (JackActor actor in Actors)
			{
				actor.MoveHeld(player);
			}
		}

		internal static void Begin(JackWorld world)
		{
			EndVisit();
			World = world;
			landed = false;
			Random random = new Random(world.Seed ^ 0x68AC913);
			for (int i = 0; i < 2; i++)
			{
				bool num = ((i == 0) ? JackPlugin.EnableJack.Value : JackPlugin.EnablePumpkin.Value);
				int num2 = ((i == 0) ? JackPlugin.JackChance.Value : JackPlugin.PumpkinChance.Value);
				bool spawn = num && random.Next(100) < num2;
				JackActor jackActor = new JackActor(i, world, JackPlugin.Scale.Value);
				Actors.Add(jackActor);
				jackActor.BeginVisit(spawn);
			}
			JackPlugin.Log.LogInfo((object)("JACK_WORLD key=" + world.Key + " seed=" + world.Seed + " host=" + Host + " maxPerVariant=1"));
		}

		internal static void Tick()
		{
			//IL_0237: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_031a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Expected O, but got Unknown
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			List<Vector3> points;
			float height;
			if (World != null)
			{
				if (!((Object)(object)World.Root == (Object)null) && !((Object)(object)instance == (Object)null) && instance.randomMapSeed == World.Seed && (!landed || !instance.inShipPhase))
				{
					landed |= instance.shipHasLanded;
					{
						foreach (JackActor actor in Actors)
						{
							actor.Tick();
						}
						return;
					}
				}
				EndVisit();
			}
			else
			{
				if (Time.unscaledTime < nextDiscovery)
				{
					return;
				}
				nextDiscovery = Time.unscaledTime + 1f;
				if ((Object)(object)instance == (Object)null || !instance.shipHasLanded || instance.inShipPhase || (Object)(object)instance.currentLevel == (Object)null || (Object)(object)RoundManager.Instance == (Object)null || RoundManager.Instance.dungeonIsGenerating || instance.currentLevel.PlanetName == "77 Circus Labyrinth")
				{
					return;
				}
				string name = instance.currentLevel.PlanetName ?? "";
				string[] source = (from x in JackPlugin.Moons.Value.Split(',')
					select x.Trim()).ToArray();
				if (Host && !source.Contains("*") && !source.Any((string x) => string.Equals(x, name, StringComparison.OrdinalIgnoreCase) || string.Equals(x, Regex.Replace(name, "^\\d+\\s*", ""), StringComparison.OrdinalIgnoreCase)))
				{
					return;
				}
				GameObject[] insideAINodes = RoundManager.Instance.insideAINodes;
				if (insideAINodes == null || insideAINodes.Length == 0)
				{
					return;
				}
				Vector3[] array = (from n in insideAINodes
					where (Object)(object)n != (Object)null
					select n.transform.position).ToArray();
				if (array.Length == 0)
				{
					return;
				}
				points = new List<Vector3>();
				height = 2.8f * (Host ? JackPlugin.Scale.Value : 0.6f);
				Vector3[] array2 = array;
				foreach (Vector3 p in array2)
				{
					Add(p);
				}
				NavMeshTriangulation val = NavMesh.CalculateTriangulation();
				int num2 = Math.Max(1, val.vertices.Length / 1200);
				for (int num3 = 0; num3 < val.vertices.Length; num3 += num2)
				{
					if (points.Count >= 384)
					{
						break;
					}
					Vector3 p2 = val.vertices[num3];
					if (array.Any(delegate(Vector3 a)
					{
						//IL_0000: Unknown result type (might be due to invalid IL or missing references)
						//IL_001e: Unknown result type (might be due to invalid IL or missing references)
						//IL_0020: Unknown result type (might be due to invalid IL or missing references)
						//IL_0025: Unknown result type (might be due to invalid IL or missing references)
						//IL_002a: Unknown result type (might be due to invalid IL or missing references)
						if (Mathf.Abs(a.y - p2.y) < 1.3f)
						{
							Vector3 val3 = a - p2;
							return ((Vector3)(ref val3)).sqrMagnitude < 625f;
						}
						return false;
					}))
					{
						Add(p2);
					}
				}
				if (points.Count < 2)
				{
					JackPlugin.Log.LogInfo((object)("JACK_NO_TALL_INTERIOR_POINTS moon=" + name));
					nextDiscovery = Time.unscaledTime + 30f;
					return;
				}
				GameObject val2 = new GameObject("JackSkellington_InteriorVisit");
				SceneManager.MoveGameObjectToScene(val2, insideAINodes.First((GameObject n) => (Object)(object)n != (Object)null).scene);
				Vector3[] arrivals = (from e in Object.FindObjectsOfType<EntranceTeleport>()
					where !e.isEntranceToBuilding && (Object)(object)e.entrancePoint != (Object)null
					select e.entrancePoint.position).ToArray();
				Begin(new JackWorld
				{
					Key = name,
					Seed = instance.randomMapSeed,
					Root = val2.transform,
					Waypoints = points.ToArray(),
					PreferredSpawn = points[0],
					Arrivals = arrivals,
					Flat = Flat,
					Route = Route,
					Generic = true,
					Doors = Object.FindObjectsOfType<DoorLock>()
				});
			}
			void Add(Vector3 val3)
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				NavMeshHit hit = default(NavMeshHit);
				if (NavMesh.SamplePosition(val3, ref hit, 1.5f, -1) && !(Mathf.Abs(((NavMeshHit)(ref hit)).position.y - val3.y) > 1.2f) && HasRoom(((NavMeshHit)(ref hit)).position, height) && !points.Any(delegate(Vector3 q)
				{
					//IL_0000: Unknown result type (might be due to invalid IL or missing references)
					//IL_0007: Unknown result type (might be due to invalid IL or missing references)
					//IL_000c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0011: Unknown result type (might be due to invalid IL or missing references)
					Vector3 val4 = q - ((NavMeshHit)(ref hit)).position;
					return ((Vector3)(ref val4)).sqrMagnitude < 16f;
				}))
				{
					points.Add(((NavMeshHit)(ref hit)).position);
				}
			}
			static bool Flat(Vector3 val3)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0015: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				RaycastHit val4 = default(RaycastHit);
				NavMeshHit val5 = default(NavMeshHit);
				if (Physics.Raycast(val3 + Vector3.up * 0.35f, Vector3.down, ref val4, 0.7f, 257, (QueryTriggerInteraction)1) && Mathf.Abs(((RaycastHit)(ref val4)).point.y - val3.y) < 0.25f && NavMesh.SamplePosition(val3, ref val5, 0.6f, -1))
				{
					return Mathf.Abs(((NavMeshHit)(ref val5)).position.y - val3.y) < 0.3f;
				}
				return false;
			}
			bool Route(Vector3 val3)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_000e: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: 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)