Decompiled source of ScaryFriendsPack v2.3.1

ScaryFriendsPack.dll

Decompiled 8 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.Security.Cryptography;
using System.Text;
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.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("ListenerTest")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ScaryFriendsPack")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ScaryFriendsPack")]
[assembly: AssemblyTitle("ScaryFriendsPack")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Listener
{
	internal class Blackout : MonoBehaviour
	{
		private const float FadeIn = 0.25f;

		private const float FadeOut = 1.5f;

		private static Blackout instance;

		private Image image;

		private PlayerControllerB slowed;

		private float start;

		private float duration;

		private float slowFor;

		private bool active;

		public static bool Active
		{
			get
			{
				if ((Object)(object)instance != (Object)null)
				{
					return instance.active;
				}
				return false;
			}
		}

		public static bool Slowing
		{
			get
			{
				if ((Object)(object)instance != (Object)null)
				{
					return (Object)(object)instance.slowed != (Object)null;
				}
				return false;
			}
		}

		public static void Trigger(PlayerControllerB player, float darkSeconds, float slowSeconds)
		{
			if ((Object)(object)instance == (Object)null)
			{
				Create();
			}
			instance.Begin(player, darkSeconds, slowSeconds);
		}

		private static void Create()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("ListenerBlackout");
			Object.DontDestroyOnLoad((Object)(object)val);
			Canvas obj = val.AddComponent<Canvas>();
			obj.renderMode = (RenderMode)0;
			obj.sortingOrder = 32000;
			Image val2 = new GameObject("Black").AddComponent<Image>();
			((Component)val2).transform.SetParent(val.transform, false);
			((Graphic)val2).color = Color.clear;
			((Graphic)val2).raycastTarget = false;
			((Graphic)val2).rectTransform.anchorMin = Vector2.zero;
			((Graphic)val2).rectTransform.anchorMax = Vector2.one;
			RectTransform rectTransform = ((Graphic)val2).rectTransform;
			Vector2 offsetMin = (((Graphic)val2).rectTransform.offsetMax = Vector2.zero);
			rectTransform.offsetMin = offsetMin;
			instance = val.AddComponent<Blackout>();
			instance.image = val2;
		}

		private void Begin(PlayerControllerB player, float darkSeconds, float slowSeconds)
		{
			if ((Object)(object)ListenerAssets.Catch != (Object)null && (Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.UIAudio.PlayOneShot(ListenerAssets.Catch, 0.9f);
			}
			start = (active ? (Time.time - 0.25f) : Time.time);
			duration = Mathf.Max(1.75f, darkSeconds);
			slowFor = slowSeconds;
			active = true;
			if ((Object)(object)slowed == (Object)null)
			{
				slowed = player;
				player.isMovementHindered = Mathf.Max(player.isMovementHindered, 0) + 1;
				player.hinderedMultiplier = Mathf.Max(player.hinderedMultiplier, 1f);
			}
		}

		private void Update()
		{
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			if (!active)
			{
				return;
			}
			float num = Time.time - start;
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			if (num >= duration || (Object)(object)val == (Object)null || val.isPlayerDead)
			{
				End((Object)(object)val != (Object)null && !val.isPlayerDead);
				return;
			}
			if (num >= slowFor)
			{
				StopSlow(revert: true);
			}
			float num2 = 0.92f + 0.05f * Mathf.PerlinNoise(num * 3f, 0f);
			float num3 = ((num < 0.25f) ? (num2 * num / 0.25f) : ((num > duration - 1.5f) ? (num2 * (duration - num) / 1.5f) : num2));
			((Graphic)image).color = new Color(0f, 0f, 0f, num3);
		}

		private void StopSlow(bool revert)
		{
			if ((Object)(object)slowed != (Object)null && revert)
			{
				slowed.isMovementHindered = Mathf.Max(slowed.isMovementHindered - 1, 0);
			}
			slowed = null;
		}

		private void End(bool revertSlow)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			active = false;
			((Graphic)image).color = Color.clear;
			StopSlow(revertSlow);
		}
	}
	internal class CompanionAI : EnemyAI
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnVictimMessage;
		}

		public const int Follow = 0;

		public const int Flee = 1;

		public const int Kill = 2;

		private const string VictimMessage = "scaryfriends.companion.victim";

		private const float ShineToScare = 3f;

		private const float KillFuse = 3.2f;

		private const float CloseEnough = 8f;

		public static int Alive;

		public CompanionBody body;

		public Collider scanCollider;

		public float FollowSeconds;

		private float localFollow;

		private float nextSound;

		private float litFor;

		private float stateEnteredAt;

		private float broadcastAt;

		private float lostVictimFor;

		private float lastTick;

		private float hostKillAfter = -1f;

		private int localState = -1;

		private bool fleeTargetChosen;

		private Vector3 lastPosition;

		private Vector3 velocity;

		private GameObject glow;

		private static readonly List<AudioClip> gameSounds = new List<AudioClip>();

		private static readonly float[] ShineHeights = new float[2] { 2.55f, 1.7f };

		internal static bool ForceFlashlightForTests;

		internal static bool ShowToVictimForTests;

		public int VictimId { get; private set; } = -1;

		public PlayerControllerB Victim
		{
			get
			{
				PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
				if (VictimId < 0 || VictimId >= allPlayerScripts.Length)
				{
					return null;
				}
				return allPlayerScripts[VictimId];
			}
		}

		private bool LocalIsVictim
		{
			get
			{
				if ((Object)(object)Victim != (Object)null)
				{
					return (Object)(object)Victim == (Object)(object)GameNetworkManager.Instance.localPlayerController;
				}
				return false;
			}
		}

		private float KillAfter
		{
			get
			{
				if (!((NetworkBehaviour)this).IsServer && !(hostKillAfter <= 0f))
				{
					return hostKillAfter;
				}
				return Plugin.CompanionKillAfter.Value;
			}
		}

		public override void Start()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Start();
			Alive++;
			base.removedPowerLevel = true;
			((NetworkBehaviour)this).NetworkObject.DontDestroyWithOwner = true;
			lastPosition = ((Component)this).transform.position;
			lastTick = Time.time;
			nextSound = Time.time + 3f;
			CollectGameSounds();
		}

		public override void OnDestroy()
		{
			((EnemyAI)this).OnDestroy();
			Alive--;
			if ((Object)(object)glow != (Object)null)
			{
				Object.Destroy((Object)(object)glow);
			}
		}

		public override void OnNetworkSpawn()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			((NetworkBehaviour)this).OnNetworkSpawn();
			CustomMessagingManager customMessagingManager = ((NetworkBehaviour)this).NetworkManager.CustomMessagingManager;
			object obj = <>O.<0>__OnVictimMessage;
			if (obj == null)
			{
				HandleNamedMessageDelegate val = OnVictimMessage;
				<>O.<0>__OnVictimMessage = val;
				obj = (object)val;
			}
			customMessagingManager.RegisterNamedMessageHandler("scaryfriends.companion.victim", (HandleNamedMessageDelegate)obj);
		}

		public override void DoAIInterval()
		{
			//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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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)
			if (base.currentBehaviourStateIndex != localState)
			{
				EnterStateLocally(base.currentBehaviourStateIndex);
			}
			float num = Mathf.Min(Time.time - lastTick, 0.5f);
			lastTick = Time.time;
			if (base.isEnemyDead || StartOfRound.Instance.allPlayersDead || base.stunNormalizedTimer > 0f)
			{
				base.agent.speed = 0f;
				((EnemyAI)this).DoAIInterval();
				return;
			}
			float num2 = Time.time - stateEnteredAt;
			switch (base.currentBehaviourStateIndex)
			{
			case 0:
			{
				KeepVictim(num);
				PlayerControllerB victim = Victim;
				if ((Object)(object)victim == (Object)null || !victim.isInsideFactory)
				{
					base.agent.speed = 0f;
					break;
				}
				Vector3 val = Behind(victim);
				float num3 = Vector3.Distance(((Component)this).transform.position, ((Component)victim).transform.position);
				if (num3 > 30f)
				{
					base.agent.Warp(val);
				}
				base.agent.speed = Mathf.Clamp(num3 * 1.6f, 1.5f, 10f);
				((EnemyAI)this).SetDestinationToPosition(val, false);
				if (num3 < 8f)
				{
					FollowSeconds += num;
				}
				if (FollowSeconds >= Plugin.CompanionKillAfter.Value)
				{
					((EnemyAI)this).SwitchToBehaviourState(2);
				}
				break;
			}
			case 1:
				base.agent.speed = ((num2 < 1.2f) ? 0f : 12f);
				if (num2 >= 1.2f && !fleeTargetChosen)
				{
					ChooseFleeTarget();
				}
				if (num2 > 7f)
				{
					Leave();
				}
				break;
			case 2:
				base.agent.speed = 0f;
				break;
			}
			((EnemyAI)this).DoAIInterval();
		}

		private static Vector3 Behind(PlayerControllerB v)
		{
			//IL_000d: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_003d: 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)
			//IL_004d: 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_005e: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			Vector3 navMeshPosition = instance.GetNavMeshPosition(((Component)v).transform.position - ((Component)v).transform.forward * 2.5f, instance.navHit, 3f, -1);
			if (!instance.GotNavMeshPositionResult)
			{
				return instance.GetNavMeshPosition(((Component)v).transform.position, instance.navHit, 3f, -1);
			}
			return navMeshPosition;
		}

		private void KeepVictim(float dt)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB victim = Victim;
			bool flag = (Object)(object)victim != (Object)null && victim.isPlayerControlled && !victim.isPlayerDead && !CompanionDirector.IsAwayHost(victim);
			lostVictimFor = ((flag && !victim.isInsideFactory) ? (lostVictimFor + dt) : 0f);
			if (!flag || lostVictimFor > 30f)
			{
				PlayerControllerB val = CompanionDirector.PickVictim();
				SetVictim(((Object)(object)val != (Object)null) ? ((int)val.playerClientId) : (-1));
				if ((Object)(object)val != (Object)null)
				{
					base.agent.Warp(Behind(val));
				}
			}
			if (Time.time > broadcastAt)
			{
				Broadcast();
			}
		}

		private void SetVictim(int id)
		{
			if (id != VictimId)
			{
				Plugin.Log.LogInfo((object)$"Companion follows player #{id}");
				VictimId = id;
				FollowSeconds = 0f;
				localFollow = 0f;
				Broadcast();
			}
		}

		private void Broadcast(bool sound = false)
		{
			//IL_0032: 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_004b: 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_0069: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			broadcastAt = Time.time + 2f;
			if (!((NetworkBehaviour)this).IsServer)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(17, (Allocator)2, -1);
			try
			{
				ulong networkObjectId = ((NetworkBehaviour)this).NetworkObjectId;
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				int victimId = VictimId;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref victimId, default(ForPrimitives));
				float value = Plugin.CompanionKillAfter.Value;
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref value, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref sound, default(ForPrimitives));
				((NetworkBehaviour)this).NetworkManager.CustomMessagingManager.SendNamedMessageToAll("scaryfriends.companion.victim", val, (NetworkDelivery)2);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnVictimMessage(ulong sender, FastBufferReader reader)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			ulong key = default(ulong);
			((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref key, default(ForPrimitives));
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			float num2 = default(float);
			((FastBufferReader)(ref reader)).ReadValueSafe<float>(ref num2, default(ForPrimitives));
			bool flag = default(bool);
			((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
			CompanionAI companionAI = default(CompanionAI);
			if (!NetworkManager.Singleton.IsServer && NetworkManager.Singleton.SpawnManager.SpawnedObjects.TryGetValue(key, out var value) && ((Component)value).TryGetComponent<CompanionAI>(ref companionAI))
			{
				companionAI.hostKillAfter = num2;
				if (companionAI.VictimId != num)
				{
					companionAI.VictimId = num;
					companionAI.localFollow = 0f;
				}
				if (flag)
				{
					companionAI.PlayGameSound();
				}
			}
		}

		private void ChooseFleeTarget()
		{
			fleeTargetChosen = true;
			ListenerAI.RunFar((EnemyAI)(object)this);
		}

		private void Leave()
		{
			if (((NetworkBehaviour)this).IsServer && ((NetworkBehaviour)this).NetworkObject.IsSpawned)
			{
				if (ControlCompanyCompat.Holds((EnemyAI)(object)this))
				{
					((EnemyAI)this).SwitchToBehaviourState(0);
					return;
				}
				CompanionDirector.ScheduleReturn();
				((NetworkBehaviour)this).NetworkObject.Despawn(true);
			}
		}

		public override void Update()
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0061: 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_0072: 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)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			((EnemyAI)this).Update();
			if (base.isEnemyDead)
			{
				return;
			}
			float num = Mathf.Max(Time.deltaTime, 0.0001f);
			Vector3 val = ((Component)this).transform.position - lastPosition;
			val.y = 0f;
			velocity = Vector3.Lerp(velocity, val / num, Mathf.Clamp01(8f * num));
			lastPosition = ((Component)this).transform.position;
			if (base.currentBehaviourStateIndex != localState)
			{
				EnterStateLocally(base.currentBehaviourStateIndex);
			}
			bool flag = LocalIsVictim && !ShowToVictimForTests;
			body.Hidden = flag;
			scanCollider.enabled = !flag;
			body.Speed = ((Vector3)(ref velocity)).magnitude;
			body.CoverEyes = ((base.currentBehaviourStateIndex == 1 && Time.time - stateEnteredAt < 1.4f) ? 1f : 0f);
			PlayerControllerB victim = Victim;
			bool flag2 = (Object)(object)victim != (Object)null && base.currentBehaviourStateIndex == 0;
			body.Lean = ((flag2 && body.Speed < 1.2f && Vector3.Distance(((Component)this).transform.position, ((Component)victim).transform.position) < 3.5f) ? 1f : 0f);
			body.LookAt = (flag2 ? new Vector3?(((Component)victim.gameplayCamera).transform.position) : ((Vector3?)null));
			if (base.currentBehaviourStateIndex == 0 && (Object)(object)Victim != (Object)null)
			{
				if (Time.time > nextSound)
				{
					PlayGameSound();
				}
				if (LocalIsVictim && !Victim.isPlayerDead)
				{
					if (Vector3.Distance(((Component)this).transform.position, ((Component)Victim).transform.position) < 8f)
					{
						localFollow += Time.deltaTime;
					}
					VictimFx.Deafen(localFollow / KillAfter);
				}
			}
			CheckShine();
		}

		private void EnterStateLocally(int state)
		{
			localState = state;
			stateEnteredAt = Time.time;
			fleeTargetChosen = false;
			Plugin.Log.LogInfo((object)$"companion state {state} victim=#{VictimId}");
			if (state == 2)
			{
				((MonoBehaviour)this).StartCoroutine(KillSequence());
			}
		}

		private void CheckShine()
		{
			//IL_0050: 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_0061: 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_0080: 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_008c: 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)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00ad: 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_00bc: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			bool flag = false;
			if (base.currentBehaviourStateIndex == 0 && (Object)(object)localPlayerController != (Object)null && !localPlayerController.isPlayerDead && !LocalIsVictim && FlashlightOn(localPlayerController))
			{
				Vector3 position = ((Component)localPlayerController.gameplayCamera).transform.position;
				Vector3 forward = ((Component)localPlayerController.gameplayCamera).transform.forward;
				float[] shineHeights = ShineHeights;
				foreach (float num in shineHeights)
				{
					Vector3 val = ((Component)this).transform.position + Vector3.up * num - position;
					if (((Vector3)(ref val)).magnitude < 18f && Vector3.Angle(forward, val) < 20f && !Physics.Linecast(position, position + val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
					{
						flag = true;
						break;
					}
				}
			}
			litFor = (flag ? (litFor + Time.deltaTime) : Mathf.Max(0f, litFor - Time.deltaTime));
			if (litFor >= 3f)
			{
				litFor = 0f;
				((EnemyAI)this).SwitchToBehaviourState(1);
			}
		}

		internal static bool FlashlightOn(PlayerControllerB p)
		{
			if (!ForceFlashlightForTests || !((Object)(object)p == (Object)(object)GameNetworkManager.Instance.localPlayerController))
			{
				GrabbableObject currentlyHeldObjectServer = p.currentlyHeldObjectServer;
				FlashlightItem val = (FlashlightItem)(object)((currentlyHeldObjectServer is FlashlightItem) ? currentlyHeldObjectServer : null);
				if (val == null || !((GrabbableObject)val).isBeingUsed)
				{
					if ((Object)(object)p.helmetLight != (Object)null && ((Behaviour)p.helmetLight).enabled)
					{
						GrabbableObject pocketedFlashlight = p.pocketedFlashlight;
						FlashlightItem val2 = (FlashlightItem)(object)((pocketedFlashlight is FlashlightItem) ? pocketedFlashlight : null);
						if (val2 != null)
						{
							return ((GrabbableObject)val2).isBeingUsed;
						}
					}
					return false;
				}
			}
			return true;
		}

		public override void HitEnemy(int force = 1, PlayerControllerB playerWhoHit = null, bool playHitSFX = false, int hitID = -1)
		{
			((EnemyAI)this).HitEnemy(force, playerWhoHit, playHitSFX, hitID);
			if ((((Object)(object)playerWhoHit != (Object)null) ? ((Object)(object)playerWhoHit == (Object)(object)GameNetworkManager.Instance.localPlayerController) : ((NetworkBehaviour)this).IsOwner) && base.currentBehaviourStateIndex == 0)
			{
				((EnemyAI)this).SwitchToBehaviourState(1);
			}
		}

		public void ControlledSound()
		{
			PlayGameSound();
			Broadcast(sound: true);
		}

		private void PlayGameSound()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			nextSound = Time.time + Random.Range(2.5f, 3.5f);
			AudioClip val = null;
			int num = 0;
			foreach (AudioClip gameSound in gameSounds)
			{
				if ((Object)(object)gameSound != (Object)null && (int)gameSound.loadState == 2 && Random.Range(0, ++num) == 0)
				{
					val = gameSound;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				base.creatureVoice.pitch = Random.Range(0.9f, 1.05f);
				base.creatureVoice.PlayOneShot(val, 1f);
			}
		}

		private static void CollectGameSounds()
		{
			gameSounds.Clear();
			StartOfRound instance = StartOfRound.Instance;
			Add(instance.creakOpenDoorMetal);
			Add(instance.shutDoorMetal);
			Add((IEnumerable<AudioClip>)(object)new AudioClip[3] { instance.playerJumpSFX, instance.playerHitGroundSoft, instance.playerHitGroundHard });
			Add(instance.bodyCollisionSFX);
			Add(instance.playerDragFootSFX);
			foreach (FootstepSurface item in instance.footstepSurfaces.Take(3))
			{
				Add(item.clips);
			}
			BreakerBox val = Object.FindObjectOfType<BreakerBox>();
			if ((Object)(object)val != (Object)null)
			{
				Add((IEnumerable<AudioClip>)(object)new AudioClip[1] { val.switchPowerSFX });
			}
			EnemyVent val2 = Object.FindObjectOfType<EnemyVent>();
			if ((Object)(object)val2 != (Object)null)
			{
				Add((IEnumerable<AudioClip>)(object)new AudioClip[1] { val2.ventCrawlSFX });
			}
			foreach (AnimatedObjectTrigger item2 in Object.FindObjectsOfType<AnimatedObjectTrigger>().Take(12))
			{
				Add(item2.boolTrueAudios);
				Add(item2.boolFalseAudios);
			}
			Add(from i in instance.allItemsList.itemsList.Where((Item i) => (Object)(object)i != (Object)null && (Object)(object)i.dropSFX != (Object)null).Take(12)
				select i.dropSFX);
			Plugin.Log.LogInfo((object)$"Companion borrowed {gameSounds.Count} sounds of the game");
			static void Add(IEnumerable<AudioClip> clips)
			{
				if (clips == null)
				{
					return;
				}
				foreach (AudioClip clip in clips)
				{
					if ((Object)(object)clip != (Object)null && !gameSounds.Contains(clip))
					{
						gameSounds.Add(clip);
					}
				}
			}
		}

		private IEnumerator KillSequence()
		{
			PlayerControllerB v = Victim;
			if ((Object)(object)v == (Object)null)
			{
				yield break;
			}
			bool mine = (Object)(object)v == (Object)(object)GameNetworkManager.Instance.localPlayerController;
			if (mine)
			{
				VictimFx.Finale(gameSounds.Where((AudioClip c) => (Object)(object)c != (Object)null && (int)c.loadState == 2).ToList(), 3.2f);
			}
			glow = VictimFx.Glow(((Component)v).transform);
			for (float t = 0f; t < 3.2f; t += Time.deltaTime)
			{
				VictimFx.SetGlow(glow, t / 3.2f);
				yield return null;
			}
			Vector3 val = ((Component)v).transform.position + Vector3.up;
			Object.Destroy((Object)(object)glow);
			Landmine.SpawnExplosion(val, true, 0f, 0f, 50, 0f, (GameObject)null, false);
			if (mine && !v.isPlayerDead)
			{
				v.KillPlayer(Vector3.up * 14f + Random.insideUnitSphere * 5f, true, (CauseOfDeath)3, 0, default(Vector3), false);
			}
			if (((NetworkBehaviour)this).IsServer)
			{
				SpawnFlashlight(val);
				yield return (object)new WaitForSeconds(1.5f);
				Leave();
			}
		}

		private static void SpawnFlashlight(Vector3 at)
		{
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: 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)
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			Item val = ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.itemName == "Flashlight")) ?? ((IEnumerable<Item>)itemsList).FirstOrDefault((Func<Item, bool>)((Item i) => (Object)(object)i != (Object)null && i.itemName.Contains("flashlight")));
			if (!((Object)(object)val == (Object)null) && !((Object)(object)val.spawnPrefab == (Object)null))
			{
				RoundManager instance = RoundManager.Instance;
				Vector3 navMeshPosition = instance.GetNavMeshPosition(at, instance.navHit, 3f, -1);
				Object.Instantiate<GameObject>(val.spawnPrefab, navMeshPosition + Vector3.up * 0.5f, Quaternion.identity, instance.spawnedScrapContainer).GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	internal class CompanionBody : MonoBehaviour
	{
		private enum Cell
		{
			Coat,
			Skin,
			Hair,
			Hat,
			Metal,
			Lens,
			Leather,
			Tie,
			Shirt,
			Band,
			Lapel,
			Trousers,
			Sole,
			Button,
			SkinShade
		}

		private class Shape
		{
			private readonly List<Vector3> verts = new List<Vector3>();

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

			private readonly List<Vector2> uvs = new List<Vector2>();

			private readonly List<int> tris = new List<int>();

			private static readonly Vector3[] Faces = (Vector3[])(object)new Vector3[6]
			{
				Vector3.forward,
				Vector3.back,
				Vector3.right,
				Vector3.left,
				Vector3.up,
				Vector3.down
			};

			private void Vertex(Matrix4x4 m, Matrix4x4 normalMatrix, Vector3 p, Vector3 n, Vector2 uv)
			{
				//IL_0008: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: 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_001d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				verts.Add(((Matrix4x4)(ref m)).MultiplyPoint3x4(p));
				List<Vector3> list = norms;
				Vector3 val = ((Matrix4x4)(ref normalMatrix)).MultiplyVector(n);
				list.Add(((Vector3)(ref val)).normalized);
				uvs.Add(uv);
			}

			private static Vector4 Fit(Vector4 r, float w, float h)
			{
				//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_0063: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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_0019: 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_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Unknown result type (might be due to invalid IL or missing references)
				if (!(r == Face))
				{
					return new Vector4(r.x, r.y, Mathf.Lerp(r.x, r.z, Mathf.Min(1f, w / 0.5f)), Mathf.Lerp(r.y, r.w, Mathf.Min(1f, h / 0.5f)));
				}
				return r;
			}

			private static float[] Steps(float half, float r)
			{
				return new float[8]
				{
					0f - half,
					0f - half + 0.423f * r,
					0f - half + 0.732f * r,
					0f - half + r,
					half - r,
					half - 0.732f * r,
					half - 0.423f * r,
					half
				};
			}

			public void RoundBox(Matrix4x4 m, Vector3 size, float r, Vector4 all, Vector4? front = null, Vector4? top = null, Vector4? back = null, Vector2? taper = null)
			{
				//IL_0000: 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_000b: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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_0019: Unknown result type (might be due to invalid IL or missing references)
				//IL_004b: 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_0050: 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_0058: 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_0061: 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_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: 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_009a: 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_00a1: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b3: 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_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_011f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0120: Unknown result type (might be due to invalid IL or missing references)
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_012f: Unknown result type (might be due to invalid IL or missing references)
				//IL_013d: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_014c: Unknown result type (might be due to invalid IL or missing references)
				//IL_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_00fe: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cd: 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_00de: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01be: 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_01c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0200: 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_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_021c: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0230: Unknown result type (might be due to invalid IL or missing references)
				//IL_0232: Unknown result type (might be due to invalid IL or missing references)
				//IL_0237: Unknown result type (might be due to invalid IL or missing references)
				//IL_023b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0240: Unknown result type (might be due to invalid IL or missing references)
				//IL_0242: Unknown result type (might be due to invalid IL or missing references)
				//IL_0244: Unknown result type (might be due to invalid IL or missing references)
				//IL_0247: Unknown result type (might be due to invalid IL or missing references)
				//IL_024c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0251: Unknown result type (might be due to invalid IL or missing references)
				//IL_0253: Unknown result type (might be due to invalid IL or missing references)
				//IL_0259: Unknown result type (might be due to invalid IL or missing references)
				//IL_025f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0266: Unknown result type (might be due to invalid IL or missing references)
				//IL_0272: Unknown result type (might be due to invalid IL or missing references)
				//IL_029c: Unknown result type (might be due to invalid IL or missing references)
				//IL_029d: Unknown result type (might be due to invalid IL or missing references)
				//IL_029e: 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_02a2: 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_02c3: 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_02e4: Unknown result type (might be due to invalid IL or missing references)
				Vector3 val = size / 2f;
				r = Mathf.Min(r, Mathf.Min(val.x, Mathf.Min(val.y, val.z)) * 0.999f);
				Vector2 val2 = (Vector2)(((??)taper) ?? Vector2.one);
				Matrix4x4 inverse = ((Matrix4x4)(ref m)).inverse;
				Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose;
				Vector3[] faces = Faces;
				Vector3 val7 = default(Vector3);
				foreach (Vector3 val3 in faces)
				{
					Vector3 val4 = ((val3.y != 0f) ? Vector3.forward : Vector3.up);
					Vector3 val5 = Vector3.Cross(val3, val4);
					Vector4 r2 = (Vector4)((!(val3 == Vector3.forward)) ? ((!(val3 == Vector3.up)) ? ((!(val3 == Vector3.back)) ? all : (((??)back) ?? all)) : (((??)top) ?? all)) : (((??)front) ?? all));
					float num = Mathf.Abs(Vector3.Dot(val, val5));
					float num2 = Mathf.Abs(Vector3.Dot(val, val4));
					float num3 = Mathf.Abs(Vector3.Dot(val, val3));
					r2 = Fit(r2, 2f * num, 2f * num2);
					float[] array = Steps(num, r);
					float[] array2 = Steps(num2, r);
					int count = verts.Count;
					float[] array3 = array2;
					foreach (float num4 in array3)
					{
						float[] array4 = array;
						foreach (float num5 in array4)
						{
							Vector3 val6 = val3 * num3 + val5 * num5 + val4 * num4;
							((Vector3)(ref val7))..ctor(Mathf.Clamp(val6.x, r - val.x, val.x - r), Mathf.Clamp(val6.y, r - val.y, val.y - r), Mathf.Clamp(val6.z, r - val.z, val.z - r));
							Vector3 val8 = val6 - val7;
							Vector3 normalized = ((Vector3)(ref val8)).normalized;
							Vector3 val9 = val7 + normalized * r;
							float num6 = Mathf.Lerp(val2.x, val2.y, (val9.y + val.y) / (2f * val.y));
							val9.x *= num6;
							val9.z *= num6;
							Vertex(m, transpose, val9, normalized, new Vector2(Mathf.Lerp(r2.x, r2.z, (num5 + num) / (2f * num)), Mathf.Lerp(r2.y, r2.w, (num4 + num2) / (2f * num2))));
						}
					}
					for (int l = 0; l < array2.Length - 1; l++)
					{
						for (int n = 0; n < array.Length - 1; n++)
						{
							int num7 = count + l * array.Length + n;
							int num8 = num7 + 1;
							int num9 = num7 + array.Length;
							int num10 = num9 + 1;
							tris.AddRange(new int[6] { num7, num9, num10, num7, num10, num8 });
						}
					}
				}
			}

			public void Tube(Matrix4x4 m, float r0, float r1, float length, int sides, Vector4 reg, float domeBottom = 0f, float domeTop = 0f, Func<Vector3, Vector3> warp = null)
			{
				//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_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_0153: Unknown result type (might be due to invalid IL or missing references)
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_0198: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_022c: Unknown result type (might be due to invalid IL or missing references)
				//IL_022d: Unknown result type (might be due to invalid IL or missing references)
				//IL_022e: 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)
				//IL_0250: Unknown result type (might be due to invalid IL or missing references)
				//IL_0257: Unknown result type (might be due to invalid IL or missing references)
				//IL_026a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0271: Unknown result type (might be due to invalid IL or missing references)
				//IL_0222: Unknown result type (might be due to invalid IL or missing references)
				//IL_0224: Unknown result type (might be due to invalid IL or missing references)
				//IL_0229: 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_0349: Unknown result type (might be due to invalid IL or missing references)
				//IL_034e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0350: Unknown result type (might be due to invalid IL or missing references)
				//IL_0366: Unknown result type (might be due to invalid IL or missing references)
				//IL_0367: Unknown result type (might be due to invalid IL or missing references)
				//IL_036c: Unknown result type (might be due to invalid IL or missing references)
				//IL_036e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0295: Unknown result type (might be due to invalid IL or missing references)
				Matrix4x4 inverse = ((Matrix4x4)(ref m)).inverse;
				Matrix4x4 transpose = ((Matrix4x4)(ref inverse)).transpose;
				float num = (0f - length) / 2f;
				float num2 = length / 2f;
				float item = (r0 - r1) / length;
				List<(float, float, float, float)> list = new List<(float, float, float, float)>();
				int num3 = 0;
				while (domeBottom > 0f && num3 < 3)
				{
					float num4 = MathF.PI / 2f * (float)num3 / 3f;
					list.Add((r0 * Mathf.Sin(num4), num - domeBottom * Mathf.Cos(num4), Mathf.Sin(num4) / r0, (0f - Mathf.Cos(num4)) / domeBottom));
					num3++;
				}
				list.Add((r0, num, 1f, item));
				list.Add((r1, num2, 1f, item));
				int num5 = 2;
				while (domeTop > 0f && num5 >= 0)
				{
					float num6 = MathF.PI / 2f * (float)num5 / 3f;
					list.Add((r1 * Mathf.Sin(num6), num2 + domeTop * Mathf.Cos(num6), Mathf.Sin(num6) / r1, Mathf.Cos(num6) / domeTop));
					num5--;
				}
				float num7 = 0f;
				float[] array = new float[list.Count];
				for (int i = 1; i < list.Count; i++)
				{
					num7 = (array[i] = num7 + Vector2.Distance(new Vector2(list[i].Item1, list[i].Item2), new Vector2(list[i - 1].Item1, list[i - 1].Item2)));
				}
				reg = Fit(reg, MathF.PI * 2f * Mathf.Max(r0, r1), num7);
				int count = verts.Count;
				Vector3 val = default(Vector3);
				for (int j = 0; j < list.Count; j++)
				{
					for (int k = 0; k <= sides; k++)
					{
						float num8 = (float)k * 2f * MathF.PI / (float)sides;
						float num9 = Mathf.Cos(num8);
						float num10 = Mathf.Sin(num8);
						(float, float, float, float) tuple = list[j];
						((Vector3)(ref val))..ctor(num9 * tuple.Item1, tuple.Item2, num10 * tuple.Item1);
						if (warp != null)
						{
							val = warp(val);
						}
						Vertex(m, transpose, val, new Vector3(num9 * tuple.Item3, tuple.Item4, num10 * tuple.Item3), new Vector2(Mathf.Lerp(reg.x, reg.z, (float)k / (float)sides), Mathf.Lerp(reg.y, reg.w, (num7 > 0f) ? (array[j] / num7) : 0f)));
					}
				}
				for (int l = 0; l < list.Count - 1; l++)
				{
					for (int n = 0; n < sides; n++)
					{
						int num11 = count + l * (sides + 1) + n;
						int num12 = num11 + 1;
						int num13 = num11 + sides + 1;
						int num14 = num13 + 1;
						tris.AddRange(new int[6] { num11, num13, num14, num11, num14, num12 });
					}
				}
				if (domeBottom <= 0f)
				{
					Cap(m, transpose, r0, num, sides, reg, Vector3.down, warp);
				}
				if (domeTop <= 0f)
				{
					Cap(m, transpose, r1, num2, sides, reg, Vector3.up, warp);
				}
			}

			private void Cap(Matrix4x4 m, Matrix4x4 nm, float r, float y, int sides, Vector4 reg, Vector3 normal, Func<Vector3, Vector3> warp)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Unknown result type (might be due to invalid IL or missing references)
				//IL_001e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0040: 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_004f: 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_007f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008b: 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_0090: 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_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_00da: 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_00d4: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor((reg.x + reg.z) / 2f, (reg.y + reg.w) / 2f);
				Vector2 val2 = new Vector2(reg.z - reg.x, reg.w - reg.y) / 2f;
				int count = verts.Count;
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(0f, y, 0f);
				Vertex(m, nm, warp?.Invoke(val3) ?? val3, normal, val);
				Vector3 val4 = default(Vector3);
				for (int i = 0; i <= sides; i++)
				{
					float num = (float)i * 2f * MathF.PI / (float)sides;
					((Vector3)(ref val4))..ctor(Mathf.Cos(num) * r, y, Mathf.Sin(num) * r);
					Vertex(m, nm, warp?.Invoke(val4) ?? val4, normal, val + Vector2.Scale(new Vector2(Mathf.Cos(num), Mathf.Sin(num)), val2));
				}
				for (int j = 0; j < sides; j++)
				{
					tris.AddRange((normal.y > 0f) ? new int[3]
					{
						count,
						count + 2 + j,
						count + 1 + j
					} : new int[3]
					{
						count,
						count + 1 + j,
						count + 2 + j
					});
				}
			}

			public Mesh ToMesh(string name)
			{
				//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_0017: Expected O, but got Unknown
				Mesh val = new Mesh
				{
					name = "Companion" + name
				};
				if (verts.Count > 65000)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.SetVertices(verts);
				val.SetNormals(norms);
				val.SetUVs(0, uvs);
				val.SetTriangles(tris, 0);
				val.RecalculateTangents();
				val.RecalculateBounds();
				((Object)val).hideFlags = (HideFlags)32;
				return val;
			}
		}

		private static readonly Vector4 Face = new Vector4(0f, 0.5f, 0.75f, 1f);

		private const float Tile = 0.5f;

		private static Material material;

		public Transform spine;

		public Transform hipL;

		public Transform hipR;

		public Transform kneeL;

		public Transform kneeR;

		public Transform shoulderL;

		public Transform shoulderR;

		public Transform elbowL;

		public Transform elbowR;

		public Transform neck;

		public Transform coatL;

		public Transform coatR;

		public Transform coatBack;

		public Transform trophyLamp;

		public List<Transform> trophies = new List<Transform>();

		public float Speed;

		public float CoverEyes;

		public float Lean;

		public Vector3? LookAt;

		public bool Hidden;

		private float phase;

		private float cover;

		private float lean;

		private Renderer[] renderers;

		private Light flicker;

		private readonly Dictionary<Transform, Shape> shapes = new Dictionary<Transform, Shape>();

		private static Vector4 Region(Cell c)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			int num = (int)c % 8;
			int num2 = (int)c / 8;
			float num3 = (float)(num * 128) + 4f;
			float num4 = (float)((num + 1) * 128) - 4f;
			float num5 = (float)(512 + num2 * 128) + 4f;
			float num6 = (float)(512 + (num2 + 1) * 128) - 4f;
			return new Vector4(num3 / 1024f, 1f - num6 / 1024f, num4 / 1024f, 1f - num5 / 1024f);
		}

		private Shape On(Transform joint)
		{
			if (!shapes.TryGetValue(joint, out var value))
			{
				return shapes[joint] = new Shape();
			}
			return value;
		}

		private static Matrix4x4 At(Vector3 pos, Vector3 euler = default(Vector3), Vector3? scale = null)
		{
			//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_0002: 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_0012: 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)
			return Matrix4x4.TRS(pos, Quaternion.Euler(euler), (Vector3)(((??)scale) ?? Vector3.one));
		}

		public static CompanionBody Build(GameObject root, int layer)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: 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_0033: 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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_0053: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_006b: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: 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_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_0460: Unknown result type (might be due to invalid IL or missing references)
			//IL_0466: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_049d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: 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_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_0554: Unknown result type (might be due to invalid IL or missing references)
			//IL_055b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_056d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0599: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0606: Unknown result type (might be due to invalid IL or missing references)
			//IL_0610: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: 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_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: 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_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0331: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0386: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_065c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0674: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_070c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0720: Unknown result type (might be due to invalid IL or missing references)
			//IL_072a: Unknown result type (might be due to invalid IL or missing references)
			//IL_076e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0775: Unknown result type (might be due to invalid IL or missing references)
			//IL_077b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0787: Unknown result type (might be due to invalid IL or missing references)
			//IL_079b: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0814: Unknown result type (might be due to invalid IL or missing references)
			//IL_0828: Unknown result type (might be due to invalid IL or missing references)
			//IL_0837: Unknown result type (might be due to invalid IL or missing references)
			//IL_084d: Unknown result type (might be due to invalid IL or missing references)
			//IL_086f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0876: Unknown result type (might be due to invalid IL or missing references)
			//IL_087c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0888: Unknown result type (might be due to invalid IL or missing references)
			//IL_089c: Unknown result type (might be due to invalid IL or missing references)
			//IL_08a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_08f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0913: Unknown result type (might be due to invalid IL or missing references)
			//IL_091d: Unknown result type (might be due to invalid IL or missing references)
			//IL_095d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0971: Unknown result type (might be due to invalid IL or missing references)
			//IL_0977: Unknown result type (might be due to invalid IL or missing references)
			//IL_0993: Unknown result type (might be due to invalid IL or missing references)
			//IL_09a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_09c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_09dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a05: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a0a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a20: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a25: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a3b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a40: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a56: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a5b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a71: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a76: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a89: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0abd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ac4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b33: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b3a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b40: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b4c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b62: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b84: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b8b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b9d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bb3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bdb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c03: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c54: Unknown result type (might be due to invalid IL or missing references)
			//IL_10fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_1129: Unknown result type (might be due to invalid IL or missing references)
			//IL_1130: Unknown result type (might be due to invalid IL or missing references)
			//IL_1136: Unknown result type (might be due to invalid IL or missing references)
			//IL_1142: Unknown result type (might be due to invalid IL or missing references)
			//IL_1158: Unknown result type (might be due to invalid IL or missing references)
			//IL_117a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1181: Unknown result type (might be due to invalid IL or missing references)
			//IL_1187: Unknown result type (might be due to invalid IL or missing references)
			//IL_1193: Unknown result type (might be due to invalid IL or missing references)
			//IL_11a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_11cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_11d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_11e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_11f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_1203: Unknown result type (might be due to invalid IL or missing references)
			//IL_1205: Unknown result type (might be due to invalid IL or missing references)
			//IL_120f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1216: Unknown result type (might be due to invalid IL or missing references)
			//IL_123d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1244: Unknown result type (might be due to invalid IL or missing references)
			//IL_124a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1256: Unknown result type (might be due to invalid IL or missing references)
			//IL_126a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1274: Unknown result type (might be due to invalid IL or missing references)
			//IL_12b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_12bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_12c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_12cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_12e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_12eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cbb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ce8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d2f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d36: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d3c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d5e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d85: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0da5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e14: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e1b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e2d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e72: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e7e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e94: Unknown result type (might be due to invalid IL or missing references)
			//IL_0eb6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ebd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ec3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ecf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ee5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f0f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f15: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f36: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f58: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f5f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f65: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f71: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f85: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1337: Unknown result type (might be due to invalid IL or missing references)
			//IL_133e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1344: Unknown result type (might be due to invalid IL or missing references)
			//IL_1350: Unknown result type (might be due to invalid IL or missing references)
			//IL_1364: Unknown result type (might be due to invalid IL or missing references)
			//IL_136e: Unknown result type (might be due to invalid IL or missing references)
			//IL_13c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_13e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_141b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1422: Unknown result type (might be due to invalid IL or missing references)
			//IL_1428: Unknown result type (might be due to invalid IL or missing references)
			//IL_142a: Unknown result type (might be due to invalid IL or missing references)
			//IL_1431: Unknown result type (might be due to invalid IL or missing references)
			//IL_1447: Unknown result type (might be due to invalid IL or missing references)
			//IL_1487: Unknown result type (might be due to invalid IL or missing references)
			//IL_148e: Unknown result type (might be due to invalid IL or missing references)
			//IL_1494: Unknown result type (might be due to invalid IL or missing references)
			//IL_1496: Unknown result type (might be due to invalid IL or missing references)
			//IL_149d: Unknown result type (might be due to invalid IL or missing references)
			//IL_14b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fe7: Unknown result type (might be due to invalid IL or missing references)
			//IL_1005: Unknown result type (might be due to invalid IL or missing references)
			//IL_1014: Unknown result type (might be due to invalid IL or missing references)
			//IL_1029: Unknown result type (might be due to invalid IL or missing references)
			//IL_105d: Unknown result type (might be due to invalid IL or missing references)
			//IL_1075: Unknown result type (might be due to invalid IL or missing references)
			//IL_1084: Unknown result type (might be due to invalid IL or missing references)
			//IL_1099: Unknown result type (might be due to invalid IL or missing references)
			//IL_14f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_14f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_14ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_1501: Unknown result type (might be due to invalid IL or missing references)
			//IL_1508: Unknown result type (might be due to invalid IL or missing references)
			//IL_151e: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Part(root.transform, "Model", Vector3.zero, layer);
			CompanionBody companionBody = ((Component)val).gameObject.AddComponent<CompanionBody>();
			Vector4 val2 = Region(Cell.Coat);
			Vector4 val3 = Region(Cell.Skin);
			Vector4 all = Region(Cell.SkinShade);
			Vector4 val4 = Region(Cell.Hair);
			Vector4 reg = Region(Cell.Hat);
			Vector4 val5 = Region(Cell.Metal);
			Vector4 reg2 = Region(Cell.Lens);
			Vector4 all2 = Region(Cell.Leather);
			Vector4 all3 = Region(Cell.Tie);
			Vector4 val6 = Region(Cell.Shirt);
			Vector4 reg3 = Region(Cell.Band);
			Vector4 all4 = Region(Cell.Lapel);
			Vector4 val7 = Region(Cell.Trousers);
			Vector4 all5 = Region(Cell.Sole);
			Vector4 reg4 = Region(Cell.Button);
			for (int i = -1; i <= 1; i += 2)
			{
				Transform val8 = Part(val, (i < 0) ? "HipL" : "HipR", new Vector3(0.08f * (float)i, 1.3f, 0f), layer);
				companionBody.On(val8).Tube(At(new Vector3(0f, -0.31f, 0f)), 0.042f, 0.05f, 0.62f, 10, val7, 0f, 0.03f);
				Transform joint = Part(val8, "Knee", new Vector3(0f, -0.62f, 0f), layer);
				Shape shape = companionBody.On(joint);
				shape.RoundBox(At(new Vector3(0f, 0f, 0.01f)), new Vector3(0.095f, 0.085f, 0.095f), 0.038f, val7);
				shape.Tube(At(new Vector3(0f, -0.31f, 0f)), 0.035f, 0.041f, 0.6f, 10, val7);
				shape.Tube(At(new Vector3(0f, -0.595f, 0f)), 0.043f, 0.039f, 0.035f, 10, val7);
				shape.RoundBox(At(new Vector3(0f, -0.645f, 0.06f)), new Vector3(0.1f, 0.075f, 0.26f), 0.032f, all2);
				shape.RoundBox(At(new Vector3(0f, -0.655f, 0.22f), new Vector3(-6f, 0f, 0f)), new Vector3(0.078f, 0.056f, 0.13f), 0.026f, all2);
				shape.RoundBox(At(new Vector3(0f, -0.686f, 0.1f)), new Vector3(0.104f, 0.022f, 0.36f), 0.009f, all5);
				if (i < 0)
				{
					companionBody.hipL = val8;
					companionBody.kneeL = joint;
				}
				else
				{
					companionBody.hipR = val8;
					companionBody.kneeR = joint;
				}
			}
			companionBody.spine = Part(val, "Spine", new Vector3(0f, 1.28f, 0f), layer);
			Shape shape2 = companionBody.On(companionBody.spine);
			Matrix4x4 m = At(new Vector3(0f, 0.45f, 0f));
			Vector3 size = new Vector3(0.32f, 0.9f, 0.2f);
			Vector2? taper = new Vector2(0.92f, 1.08f);
			shape2.RoundBox(m, size, 0.06f, val2, null, null, null, taper);
			shape2.RoundBox(At(new Vector3(0f, 0.7f, 0.096f)), new Vector3(0.12f, 0.3f, 0.012f), 0.005f, val6);
			Matrix4x4 m2 = At(new Vector3(0f, 0.62f, 0.104f));
			Vector3 size2 = new Vector3(0.052f, 0.4f, 0.012f);
			taper = new Vector2(1.25f, 0.75f);
			shape2.RoundBox(m2, size2, 0.005f, all3, null, null, null, taper);
			shape2.RoundBox(At(new Vector3(0f, 0.84f, 0.106f)), new Vector3(0.062f, 0.05f, 0.03f), 0.015f, all3);
			for (int j = -1; j <= 1; j += 2)
			{
				shape2.RoundBox(At(new Vector3(0.068f * (float)j, 0.66f, 0.102f), new Vector3(0f, 0f, -12f * (float)j)), new Vector3(0.075f, 0.38f, 0.016f), 0.007f, all4);
				shape2.RoundBox(At(new Vector3(0.12f * (float)j, 0.93f, -0.01f), new Vector3(0f, 0f, 16f * (float)j)), new Vector3(0.1f, 0.2f, 0.15f), 0.035f, all4);
				shape2.RoundBox(At(new Vector3(0.1f * (float)j, 0.17f, 0.1f)), new Vector3(0.1f, 0.036f, 0.02f), 0.008f, all4);
			}
			float[] array = new float[2] { 0.16f, 0.31f };
			foreach (float num in array)
			{
				shape2.Tube(At(new Vector3(0.045f, num, 0.101f), new Vector3(90f, 0f, 0f)), 0.012f, 0.012f, 0.008f, 10, reg4, 0f, 0.004f);
			}
			shape2.RoundBox(At(Vector3.zero), new Vector3(0.335f, 0.05f, 0.215f), 0.02f, all2);
			shape2.RoundBox(At(new Vector3(0f, 0f, 0.11f)), new Vector3(0.062f, 0.046f, 0.014f), 0.008f, val5);
			companionBody.coatL = companionBody.CoatTail(new Vector3(-0.078f, -0.01f, 0.096f), new Vector3(0.155f, 0.74f, 0.022f), layer, val2);
			companionBody.coatR = companionBody.CoatTail(new Vector3(0.078f, -0.01f, 0.096f), new Vector3(0.155f, 0.74f, 0.022f), layer, val2);
			companionBody.coatBack = companionBody.CoatTail(new Vector3(0f, -0.01f, -0.097f), new Vector3(0.32f, 0.74f, 0.022f), layer, val2);
			Vector3[] array2 = (Vector3[])(object)new Vector3[5]
			{
				new Vector3(0.17f, -0.02f, 0.06f),
				new Vector3(0.165f, -0.02f, -0.07f),
				new Vector3(-0.17f, -0.02f, 0.05f),
				new Vector3(-0.13f, -0.02f, -0.1f),
				new Vector3(0.05f, -0.02f, -0.115f)
			};
			foreach (Vector3 localPos in array2)
			{
				Transform val9 = Part(companionBody.spine, "Trophy", localPos, layer);
				Shape shape3 = companionBody.On(val9);
				shape3.RoundBox(At(new Vector3(0f, -0.03f, 0f)), new Vector3(0.016f, 0.06f, 0.016f), 0.006f, all2);
				shape3.Tube(At(new Vector3(0f, -0.145f, 0f)), 0.028f, 0.03f, 0.17f, 12, val5, 0f, 0.012f);
				shape3.Tube(At(new Vector3(0f, -0.245f, 0f)), 0.037f, 0.033f, 0.035f, 12, val5);
				shape3.Tube(At(new Vector3(0f, -0.264f, 0f)), 0.031f, 0.031f, 0.004f, 12, reg2);
				companionBody.trophies.Add(val9);
			}
			companionBody.trophyLamp = Part(companionBody.trophies[0], "Lamp", new Vector3(0f, -0.27f, 0f), layer);
			for (int l = -1; l <= 1; l += 2)
			{
				Transform val10 = Part(companionBody.spine, (l < 0) ? "ShoulderL" : "ShoulderR", new Vector3(0.2f * (float)l, 0.85f, 0f), layer);
				Shape shape4 = companionBody.On(val10);
				shape4.RoundBox(At(new Vector3(0f, 0.015f, 0f)), new Vector3(0.13f, 0.1f, 0.21f), 0.045f, val2);
				shape4.Tube(At(new Vector3(0f, -0.29f, 0f)), 0.04f, 0.05f, 0.58f, 10, val2);
				Transform joint2 = Part(val10, "Elbow", new Vector3(0f, -0.58f, 0f), layer);
				Shape shape5 = companionBody.On(joint2);
				shape5.RoundBox(At(Vector3.zero), new Vector3(0.09f, 0.075f, 0.09f), 0.036f, val2);
				shape5.Tube(At(new Vector3(0f, -0.24f, 0f)), 0.036f, 0.041f, 0.48f, 10, val2);
				shape5.Tube(At(new Vector3(0f, -0.47f, 0f)), 0.045f, 0.045f, 0.05f, 10, val2);
				shape5.Tube(At(new Vector3(0f, -0.505f, 0f)), 0.034f, 0.034f, 0.03f, 10, val6);
				shape5.Tube(At(new Vector3(0f, -0.53f, 0f)), 0.019f, 0.021f, 0.05f, 8, val3);
				shape5.RoundBox(At(new Vector3(0f, -0.6f, 0f)), new Vector3(0.08f, 0.1f, 0.03f), 0.013f, val3);
				for (int n = 0; n < 4; n++)
				{
					float num2 = -0.03f + (float)n * 0.02f;
					shape5.Tube(At(new Vector3(num2 * 1.2f, -0.725f, 0.004f), new Vector3(8f, 0f, ((float)n - 1.5f) * 4f)), 0.0062f, 0.0078f, 0.16f, 6, val3, 0.006f);
				}
				shape5.Tube(At(new Vector3(0.05f * (float)l, -0.6f, 0.01f), new Vector3(0f, 0f, 30f * (float)l)), 0.0072f, 0.0085f, 0.1f, 6, val3, 0.006f);
				if (l < 0)
				{
					companionBody.shoulderL = val10;
					companionBody.elbowL = joint2;
				}
				else
				{
					companionBody.shoulderR = val10;
					companionBody.elbowR = joint2;
				}
			}
			companionBody.neck = Part(companionBody.spine, "Neck", new Vector3(0f, 0.9f, 0f), layer);
			Shape shape6 = companionBody.On(companionBody.neck);
			shape6.Tube(At(new Vector3(0f, 0.06f, 0f)), 0.034f, 0.034f, 0.13f, 10, val3);
			shape6.Tube(At(new Vector3(0f, 0.02f, 0f)), 0.05f, 0.046f, 0.05f, 12, val6);
			shape6.RoundBox(At(new Vector3(0f, 0.37f, 0.04f)), new Vector3(0.75f, 0.5f, 0.55f), 0.09f, all, Face, val4, val4);
			shape6.RoundBox(At(new Vector3(0f, 0.53f, -0.01f)), new Vector3(0.77f, 0.2f, 0.52f), 0.08f, val4);
			shape6.RoundBox(At(new Vector3(0f, 0.6f, 0.295f)), new Vector3(0.74f, 0.06f, 0.06f), 0.025f, val4);
			for (int num3 = -1; num3 <= 1; num3 += 2)
			{
				shape6.RoundBox(At(new Vector3(0.385f * (float)num3, 0.36f, 0.07f)), new Vector3(0.04f, 0.13f, 0.09f), 0.018f, all);
			}
			Transform val11 = Part(companionBody.neck, "Hat", new Vector3(0.02f, 0.62f, 0.02f), layer);
			val11.localRotation = Quaternion.Euler(-4f, 0f, 8f);
			Shape shape7 = companionBody.On(val11);
			Vector3 value = default(Vector3);
			((Vector3)(ref value))..ctor(1f, 1f, 0.84f);
			shape7.Tube(At(new Vector3(0f, 0.011f, 0f), default(Vector3), value), 0.49f, 0.49f, 0.02f, 28, reg, 0f, 0f, (Vector3 p) => p + Vector3.up * (0.055f * Mathf.Pow(p.x / 0.49f, 2f) - 0.015f * Mathf.Pow(p.z / 0.49f, 2f)));
			shape7.Tube(At(new Vector3(0f, 0.12f, 0f), default(Vector3), value), 0.28f, 0.245f, 0.2f, 24, reg, 0f, 0.04f, (Vector3 p) => (!(p.y > 0.06f)) ? p : (p - Vector3.up * (0.05f * Mathf.Exp(0f - Mathf.Pow(p.x / 0.08f, 2f)) * Mathf.Clamp01((p.y - 0.06f) / 0.08f))));
			shape7.Tube(At(new Vector3(0f, 0.045f, 0f), default(Vector3), value), 0.284f, 0.279f, 0.046f, 24, reg3);
			foreach (KeyValuePair<Transform, Shape> shape8 in companionBody.shapes)
			{
				((Component)shape8.Key).gameObject.AddComponent<MeshFilter>().sharedMesh = shape8.Value.ToMesh(((Object)shape8.Key).name);
				((Component)shape8.Key).gameObject.AddComponent<MeshRenderer>();
			}
			companionBody.shapes.Clear();
			return companionBody;
		}

		private static Transform Part(Transform parent, string name, Vector3 localPos, int layer)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name)
			{
				layer = layer
			};
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			return val.transform;
		}

		private Transform CoatTail(Vector3 hinge, Vector3 size, int layer, Vector4 coat)
		{
			//IL_000b: 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_0031: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			Transform val = Part(spine, "CoatTail", hinge, layer);
			Shape shape = On(val);
			Matrix4x4 m = At(new Vector3(0f, (0f - size.y) / 2f, 0f));
			Vector2? taper = new Vector2(1.18f, 1f);
			shape.RoundBox(m, size, 0.01f, coat, null, null, null, taper);
			return val;
		}

		private void Start()
		{
			//IL_0089: 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 ((Object)(object)material == (Object)null)
			{
				material = ListenerVisuals.MakeMaterial((Texture)(object)ListenerAssets.CompanionAtlas, doubleSided: false);
				((Object)material).name = "CompanionBody";
			}
			renderers = ((Component)this).GetComponentsInChildren<Renderer>(true);
			Renderer[] array = renderers;
			foreach (Renderer obj in array)
			{
				obj.sharedMaterial = material;
				obj.shadowCastingMode = (ShadowCastingMode)1;
			}
			HDAdditionalLightData val = GameObjectExtension.AddHDLight(((Component)trophyLamp).gameObject, (HDLightTypeAndShape)3);
			((Component)val).transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
			val.color = new Color(1f, 0.9f, 0.7f);
			val.range = 7f;
			val.SetSpotAngle(70f, 0f);
			flicker = ((Component)val).GetComponent<Light>();
		}

		private void LateUpdate()
		{
			//IL_0160: 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_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_0309: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0394: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0423: Unknown result type (might be due to invalid IL or missing references)
			//IL_042a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0469: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_047e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_0538: Unknown result type (might be due to invalid IL or missing references)
			//IL_0553: Unknown result type (might be due to invalid IL or missing references)
			//IL_056e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0573: Unknown result type (might be due to invalid IL or missing references)
			//IL_057e: Unknown result type (might be due to invalid IL or missing references)
			//IL_058c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b7: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] array = renderers;
			for (int i = 0; i < array.Length; i++)
			{
				array[i].enabled = !Hidden;
			}
			if ((Object)(object)flicker != (Object)null)
			{
				((Behaviour)flicker).enabled = !Hidden;
				float num = Mathf.PerlinNoise(Time.time * 7f, 0.3f);
				HDAdditionalLightData val = default(HDAdditionalLightData);
				if (((Component)flicker).TryGetComponent<HDAdditionalLightData>(ref val))
				{
					val.intensity = ((num < 0.35f) ? 0f : (120f * num));
				}
			}
			float num2 = Mathf.Clamp01(Speed / 3f);
			phase += Time.deltaTime * Mathf.Lerp(2f, 9f, Mathf.Clamp01(Speed / 10f));
			cover = Mathf.MoveTowards(cover, CoverEyes, Time.deltaTime * 4f);
			lean = Mathf.MoveTowards(lean, Lean, Time.deltaTime * 1.5f);
			float num3 = Mathf.Sin(phase);
			float num4 = Mathf.Lerp(32f, 55f, Mathf.Clamp01(Speed / 10f)) * num2;
			hipL.localRotation = Quaternion.Euler(num3 * num4, 0f, 0f);
			hipR.localRotation = Quaternion.Euler((0f - num3) * num4, 0f, 0f);
			kneeL.localRotation = Quaternion.Euler(Mathf.Max(0f, Mathf.Sin(phase + 1.6f)) * 1.4f * num4, 0f, 0f);
			kneeR.localRotation = Quaternion.Euler(Mathf.Max(0f, Mathf.Sin(phase + 1.6f + MathF.PI)) * 1.4f * num4, 0f, 0f);
			coatL.localRotation = Quaternion.Euler(-6f + Mathf.Min(0f, (0f - num3) * num4) * 0.6f, 0f, -3f);
			coatR.localRotation = Quaternion.Euler(-6f + Mathf.Min(0f, num3 * num4) * 0.6f, 0f, 3f);
			coatBack.localRotation = Quaternion.Euler(6f + Mathf.Abs(num3) * 8f * num2, 0f, 0f);
			for (int j = 0; j < trophies.Count; j++)
			{
				trophies[j].localRotation = Quaternion.Euler(Mathf.Sin(phase + (float)j) * 18f * num2 + Mathf.Sin(Time.time * 1.3f + (float)j) * 3f, 0f, Mathf.Cos(phase * 0.5f + (float)j * 1.7f) * 10f * num2);
			}
			spine.localRotation = Quaternion.Euler(lean * 16f, 0f, 0f);
			Quaternion val2 = Quaternion.Euler(Mathf.Lerp(8f, 4f, cover) + Mathf.Abs(num3) * 4f * num2, 0f, Mathf.Lerp(14f, 0f, cover));
			neck.localRotation = val2;
			if (LookAt.HasValue && lean > 0f && cover < 0.5f)
			{
				Vector3 val3 = spine.InverseTransformPoint(LookAt.Value) - neck.localPosition;
				float num5 = Mathf.Clamp(Mathf.Atan2(val3.x, val3.z) * 57.29578f, -70f, 70f);
				float y = val3.y;
				Vector2 val4 = new Vector2(val3.x, val3.z);
				float num6 = Mathf.Clamp((0f - Mathf.Atan2(y, ((Vector2)(ref val4)).magnitude)) * 57.29578f, -10f, 45f);
				neck.localRotation = Quaternion.Slerp(val2, Quaternion.Euler(num6, num5, 10f), lean);
			}
			float num7 = Mathf.Sin(Time.time * 0.7f) * 4f;
			for (int k = -1; k <= 1; k += 2)
			{
				Transform val5 = ((k < 0) ? shoulderL : shoulderR);
				Transform val6 = ((k < 0) ? elbowL : elbowR);
				float num8 = ((k < 0) ? (0f - num3) : num3) * num4 * 0.6f + num7;
				val5.localRotation = Quaternion.Euler(num8 - lean * 10f, 0f, -4f * (float)k);
				val6.localRotation = Quaternion.Euler(-8f - 10f * num2 - lean * 20f, 0f, 0f);
				if (!(cover <= 0f))
				{
					val5.localRotation = Quaternion.Slerp(val5.localRotation, AimDown(val5, new Vector3(0.37f * (float)k, 2.03f, 0.56f)), cover);
					val6.localRotation = Quaternion.Slerp(val6.localRotation, AimDown(val6, new Vector3(0.09f * (float)k, 2.6f, 0.42f)), cover);
				}
			}
		}

		private Quaternion AimDown(Transform joint, Vector3 bodyPoint)
		{
			//IL_0006: 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_000d: 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_0017: 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_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_002e: 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_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0054: 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)
			Vector3 val = ((Component)this).transform.TransformPoint(bodyPoint) - joint.position;
			Quaternion val2 = Quaternion.FromToRotation(((Component)this).transform.rotation * Vector3.down, val) * ((Component)this).transform.rotation;
			return Quaternion.Inverse(joint.parent.rotation) * val2;
		}
	}
	internal class CompanionDirector : MonoBehaviour
	{
		internal static readonly Dictionary<ulong, float> litSeconds = new Dictionary<ulong, float>();

		private static float nextAppear = -1f;

		private static float nextTally;

		private static bool inRound;

		private void Update()
		{
			StartOfRound instance = StartOfRound.Instance;
			RoundManager instance2 = RoundManager.Instance;
			if (!((Object)(object)NetworkManager.Singleton != (Object)null) || !NetworkManager.Singleton.IsServer || (Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || !instance.shipHasLanded || instance.shipIsLeaving || !instance2.dungeonCompletedGenerating)
			{
				inRound = false;
				return;
			}
			if (!inRound)
			{
				inRound = true;
				litSeconds.Clear();
				nextAppear = Time.time + Plugin.CompanionAppearAfter.Value + Random.Range(0f, 60f);
			}
			if (Time.time >= nextTally)
			{
				nextTally = Time.time + 0.5f;
				PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
				foreach (PlayerControllerB val in allPlayerScripts)
				{
					if (val.isPlayerControlled && !val.isPlayerDead && CompanionAI.FlashlightOn(val))
					{
						litSeconds[val.playerClientId] = LitSeconds(val) + 0.5f;
					}
				}
			}
			if (Plugin.CompanionEnabled.Value && !(nextAppear < 0f) && !(Time.time < nextAppear) && CompanionAI.Alive <= 0)
			{
				if ((Object)(object)PickVictim() == (Object)null)
				{
					nextAppear = Time.time + 10f;
					return;
				}
				nextAppear = -1f;
				SpawnNow();
			}
		}

		private static float LitSeconds(PlayerControllerB p)
		{
			if (!litSeconds.TryGetValue(p.playerClientId, out var value))
			{
				return 0f;
			}
			return value;
		}

		public static PlayerControllerB PickVictim()
		{
			return StartOfRound.Instance.allPlayerScripts.Where((PlayerControllerB p) => p.isPlayerControlled && !p.isPlayerDead && p.isInsideFactory && !IsAwayHost(p)).OrderByDescending(LitSeconds).ThenBy((PlayerControllerB _) => Random.value)
				.FirstOrDefault();
		}

		public static bool IsAwayHost(PlayerControllerB p)
		{
			if ((Object)(object)p == (Object)(object)GameNetworkManager.Instance.localPlayerController)
			{
				return ListenerAI.LocalPlayerAway();
			}
			return false;
		}

		public static void SpawnNow()
		{
			//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)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			RoundManager instance = RoundManager.Instance;
			GameObject[] insideAINodes = instance.insideAINodes;
			if (i