Decompiled source of Demogorgon Enemy v0.0.0

DemogorgonEnemy.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Empress.KittyCurse;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DemogorgonEnemy")]
[assembly: AssemblyTitle("DemogorgonEnemy")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace Empress.ZoraStare
{
	public class ZoraEventRouter : MonoBehaviourPunCallbacks, IOnEventCallback
	{
		public enum Ev : byte
		{
			Spawn = 41,
			Pose,
			Despawn,
			SpawnRoll
		}

		private static bool _callbackHooked;

		private static GameObject _active;

		private static ZoraStareController _ctrl;

		private static GameObject _prefab;

		internal static void SetPrefab(GameObject prefab)
		{
			_prefab = prefab;
		}

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

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

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

		public override void OnLeftRoom()
		{
			if (_callbackHooked)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbackHooked = false;
			}
			LocalDespawn();
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode m)
		{
			LocalDespawn();
			if (PhotonNetwork.InRoom)
			{
				EnsureCallbackHooked();
			}
		}

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

		internal static void BroadcastSpawnRoll(bool passed, float chance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0047: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				object[] array = new object[2] { passed, chance };
				PhotonNetwork.RaiseEvent((byte)44, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)1
				}, SendOptions.SendReliable);
			}
		}

		internal static void BroadcastSpawn(Vector3 pos, Quaternion rot, int visionMask)
		{
			//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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0059: Expected O, but got Unknown
			CreateLocal(pos, rot, visionMask);
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				object[] array = new object[3] { pos, rot, visionMask };
				PhotonNetwork.RaiseEvent((byte)41, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}

		internal static void BroadcastPose(Vector3 pos, Quaternion rot)
		{
			//IL_0021: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: 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_004b: Expected O, but got Unknown
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				object[] array = new object[2] { pos, rot };
				PhotonNetwork.RaiseEvent((byte)42, (object)array, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendUnreliable);
			}
		}

		internal static void BroadcastDespawn()
		{
			//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_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_0034: Expected O, but got Unknown
			LocalDespawn();
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				PhotonNetwork.RaiseEvent((byte)43, (object)null, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				}, SendOptions.SendReliable);
			}
		}

		private static void CreateLocal(Vector3 pos, Quaternion rot, int visionMask)
		{
			//IL_0024: 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_0045: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_active) && !((Object)(object)_prefab == (Object)null))
			{
				NavMeshHit val = default(NavMeshHit);
				if (NavMesh.SamplePosition(pos, ref val, 4f, -1))
				{
					pos = ((NavMeshHit)(ref val)).position;
				}
				_active = Object.Instantiate<GameObject>(_prefab, pos, rot);
				((Object)_active).name = "ZoraStare_Ender";
				NavMeshAgent component = _active.GetComponent<NavMeshAgent>();
				if (Object.op_Implicit((Object)(object)component) && ((Behaviour)component).enabled)
				{
					component.Warp(pos);
					component.stoppingDistance = 1.5f;
					component.speed = 3.5f;
					component.acceleration = 8f;
					component.angularSpeed = 360f;
					component.autoBraking = true;
				}
				_ctrl = _active.GetComponent<ZoraStareController>();
				if (Object.op_Implicit((Object)(object)_ctrl))
				{
					_ctrl.Setup(LayerMask.op_Implicit(visionMask));
				}
			}
		}

		private static void LocalDespawn()
		{
			if (Object.op_Implicit((Object)(object)_active))
			{
				Object.Destroy((Object)(object)_active);
			}
			_active = null;
			_ctrl = null;
		}

		public void OnEvent(EventData e)
		{
			//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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_00d9: 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)
			try
			{
				switch ((Ev)e.Code)
				{
				case Ev.Spawn:
					if (!KittyManager.IsAuthority() && e.CustomData is object[] array2 && array2.Length >= 3)
					{
						Vector3 pos = (Vector3)array2[0];
						Quaternion rot = (Quaternion)array2[1];
						int visionMask = (int)array2[2];
						CreateLocal(pos, rot, visionMask);
					}
					break;
				case Ev.Pose:
					if (!KittyManager.IsAuthority() && !((Object)(object)_ctrl == (Object)null) && e.CustomData is object[] array && array.Length >= 2)
					{
						_ctrl.ApplyNetworkPose((Vector3)array[0], (Quaternion)array[1]);
					}
					break;
				case Ev.Despawn:
					LocalDespawn();
					break;
				case Ev.SpawnRoll:
					break;
				}
			}
			catch
			{
			}
		}
	}
	public class ZoraStareAudio : MonoBehaviour
	{
		private AudioSource _source;

		private ManualLogSource _log;

		private void Awake()
		{
			_log = ZoraStarePlugin.Log;
			_source = ((Component)this).GetComponent<AudioSource>();
			if (!Object.op_Implicit((Object)(object)_source))
			{
				_source = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_source.spatialBlend = 1f;
			_source.rolloffMode = (AudioRolloffMode)1;
			_source.minDistance = 1f;
			_source.maxDistance = 18f;
			_source.volume = 1f;
			_source.loop = false;
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(IdleLoop());
		}

		private IEnumerator IdleLoop()
		{
			while (true)
			{
				yield return (object)new WaitForSeconds(Random.Range(5f, 12f));
				if (ZoraStarePlugin.IdleClips != null && ZoraStarePlugin.IdleClips.Count > 0)
				{
					AudioClip clip = ZoraStarePlugin.IdleClips[Random.Range(0, ZoraStarePlugin.IdleClips.Count)];
					if (Object.op_Implicit((Object)(object)_source) && Object.op_Implicit((Object)(object)clip))
					{
						_source.PlayOneShot(clip);
					}
				}
			}
		}

		public void PlayAttack()
		{
			if (ZoraStarePlugin.AttackClips != null && ZoraStarePlugin.AttackClips.Count > 0)
			{
				AudioClip val = ZoraStarePlugin.AttackClips[Random.Range(0, ZoraStarePlugin.AttackClips.Count)];
				if (Object.op_Implicit((Object)(object)_source) && Object.op_Implicit((Object)(object)val))
				{
					_source.PlayOneShot(val);
				}
			}
		}

		public void PlayStep()
		{
			if (ZoraStarePlugin.WalkClips != null && ZoraStarePlugin.WalkClips.Count > 0)
			{
				AudioClip val = ZoraStarePlugin.WalkClips[Random.Range(0, ZoraStarePlugin.WalkClips.Count)];
				if (Object.op_Implicit((Object)(object)_source) && Object.op_Implicit((Object)(object)val))
				{
					_source.PlayOneShot(val);
				}
			}
		}
	}
	[RequireComponent(typeof(NavMeshAgent))]
	[DisallowMultipleComponent]
	public class ZoraStareController : MonoBehaviour
	{
		private NavMeshAgent _agent;

		private PlayerAvatar _target;

		private LayerMask _visionMask;

		private float _poseSendTimer;

		private const float PoseSendInterval = 0.2f;

		private Vector3 _netPos;

		private Quaternion _netRot;

		private bool _hasNetPose;

		private const float PoseSnapDist = 5f;

		private const float PoseLerpRate = 10f;

		private const float LookDotThreshold = 0.96f;

		private const float KillRadius = 1.5f;

		private const float MoveSpeed = 3.5f;

		private bool _exploding;

		private Animator _anim;

		private Vector3 _lastAnimPos;

		private bool _targetLocked;

		private bool _isAttacking;

		private ZoraStareAudio _audio;

		private float _walkTimer;

		private const float WalkInterval = 0.45f;

		private float _idleTimer;

		public void Setup(LayerMask visionMask)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			_visionMask = visionMask;
		}

		private void Awake()
		{
			//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)
			_agent = ((Component)this).GetComponent<NavMeshAgent>();
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.stoppingDistance = 1.5f;
				_agent.speed = 3.5f;
			}
			_anim = ((Component)this).GetComponent<Animator>();
			_lastAnimPos = ((Component)this).transform.position;
			_audio = ((Component)this).GetComponent<ZoraStareAudio>();
		}

		private void Start()
		{
			if (!KittyManager.IsAuthority() && Object.op_Implicit((Object)(object)_agent) && ((Behaviour)_agent).enabled)
			{
				((Behaviour)_agent).enabled = false;
			}
		}

		private void Update()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			if (KittyManager.IsAuthority())
			{
				HostTick();
				if (KittyManager.CanStreamPose())
				{
					_poseSendTimer += Time.deltaTime;
					if (_poseSendTimer >= 0.2f)
					{
						_poseSendTimer = 0f;
						ZoraEventRouter.BroadcastPose(((Component)this).transform.position, ((Component)this).transform.rotation);
					}
				}
			}
			else
			{
				ClientTick();
			}
			if (!Object.op_Implicit((Object)(object)_anim))
			{
				return;
			}
			bool flag = false;
			Vector3 val;
			if (_isAttacking || _exploding)
			{
				flag = false;
			}
			else if (_idleTimer > 0f)
			{
				flag = false;
			}
			else if (KittyManager.IsAuthority())
			{
				if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
				{
					int num;
					if (!_agent.isStopped)
					{
						val = _agent.velocity;
						num = ((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? 1 : 0);
					}
					else
					{
						num = 0;
					}
					flag = (byte)num != 0;
				}
			}
			else
			{
				val = ((Component)this).transform.position - _lastAnimPos;
				flag = ((Vector3)(ref val)).sqrMagnitude > 0.001f;
			}
			if (!((Behaviour)_anim).enabled)
			{
				((Behaviour)_anim).enabled = true;
			}
			_anim.SetBool("isWalking", flag);
			if (flag)
			{
				_walkTimer += Time.deltaTime;
				if (_walkTimer >= 0.45f)
				{
					_walkTimer = 0f;
					if (Object.op_Implicit((Object)(object)_audio))
					{
						_audio.PlayStep();
					}
				}
			}
			else
			{
				_walkTimer = 0f;
			}
			_lastAnimPos = ((Component)this).transform.position;
		}

		private void HostTick()
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: 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)
			if (_exploding || _isAttacking)
			{
				return;
			}
			IReadOnlyList<PlayerAvatar> readOnlyList = KittyManager.AllPlayersCached();
			bool flag = false;
			for (int i = 0; i < readOnlyList.Count; i++)
			{
				PlayerAvatar val = readOnlyList[i];
				if (Object.op_Implicit((Object)(object)val) && PlayerLookingAtMe(val))
				{
					flag = true;
				}
			}
			if ((Object)(object)_target == (Object)null)
			{
				Wander();
				LookForPlayer();
			}
			if ((Object)(object)_target != (Object)null)
			{
				_idleTimer = 0f;
				Vector3 position = ((Component)_target).transform.position;
				Vector3 val2 = position - ((Component)this).transform.position;
				val2.y = 0f;
				if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f)
				{
					Quaternion val3 = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
					((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val3, Time.deltaTime * 6f);
				}
			}
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				if (flag)
				{
					_agent.isStopped = true;
				}
				else if ((Object)(object)_target != (Object)null)
				{
					_agent.isStopped = false;
					_agent.speed = 3.5f;
					_agent.acceleration = 8f;
					_agent.angularSpeed = 360f;
					_agent.SetDestination(((Component)_target).transform.position);
				}
			}
			if ((Object)(object)_target != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)_target).transform.position) <= 1.55f && !flag)
			{
				((MonoBehaviour)this).StartCoroutine(AttackRoutine());
			}
		}

		private void Wander()
		{
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh)
			{
				return;
			}
			if (_idleTimer > 0f)
			{
				_idleTimer -= Time.deltaTime;
				if (!_agent.isStopped)
				{
					_agent.isStopped = true;
				}
			}
			else
			{
				if (_agent.pathPending || (_agent.hasPath && !(_agent.remainingDistance < 0.75f)))
				{
					return;
				}
				if (_agent.hasPath)
				{
					_agent.ResetPath();
					_idleTimer = Random.Range(3f, 8f);
					_agent.isStopped = true;
					return;
				}
				Vector3 val = Random.insideUnitSphere * 15f;
				val += ((Component)this).transform.position;
				NavMeshHit val2 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val, ref val2, 15f, -1))
				{
					_agent.SetDestination(((NavMeshHit)(ref val2)).position);
					_agent.isStopped = false;
				}
			}
		}

		private void LookForPlayer()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			IReadOnlyList<PlayerAvatar> readOnlyList = KittyManager.AllPlayersCached();
			RaycastHit val3 = default(RaycastHit);
			for (int i = 0; i < readOnlyList.Count; i++)
			{
				PlayerAvatar val = readOnlyList[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					Vector3 val2 = ((Component)val).transform.position - ((Component)this).transform.position;
					if (Physics.Raycast(((Component)this).transform.position + Vector3.up, ((Vector3)(ref val2)).normalized, ref val3, 30f, LayerMask.op_Implicit(_visionMask)) && (Object)(object)((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<PlayerAvatar>() == (Object)(object)val)
					{
						_target = val;
						_targetLocked = true;
						break;
					}
				}
			}
		}

		private IEnumerator AttackRoutine()
		{
			_isAttacking = true;
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.isStopped = true;
			}
			float mult = Random.Range(2f, 3f);
			if (Object.op_Implicit((Object)(object)_anim))
			{
				_anim.speed = mult;
				_anim.SetBool("attack", true);
			}
			if (Object.op_Implicit((Object)(object)_audio))
			{
				_audio.PlayAttack();
			}
			yield return (object)new WaitForSeconds(3.037f / mult);
			if ((Object)(object)_target != (Object)null && Vector3.Distance(((Component)this).transform.position, ((Component)_target).transform.position) <= 2.5f)
			{
				TryKill(_target);
				if (Object.op_Implicit((Object)(object)_anim))
				{
					_anim.speed = 1f;
				}
				((MonoBehaviour)this).StartCoroutine(SpinAndExplode());
			}
			else
			{
				_isAttacking = false;
				if (Object.op_Implicit((Object)(object)_anim))
				{
					_anim.speed = 1f;
					_anim.SetBool("attack", false);
				}
			}
		}

		private bool PlayerLookingAtMe(PlayerAvatar player)
		{
			//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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			Transform val = null;
			try
			{
				val = (((Object)(object)player.PlayerVisionTarget != (Object)null) ? player.PlayerVisionTarget.VisionTransform : null);
			}
			catch
			{
			}
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)player).transform;
			}
			Vector3 val2 = ((Component)this).transform.position + Vector3.up * 1f - val.position;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude <= 0.0001f)
			{
				return true;
			}
			val2 /= magnitude;
			float num = Vector3.Dot(val.forward, val2);
			if (num < 0.96f)
			{
				return false;
			}
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Linecast(val.position, ((Component)this).transform.position + Vector3.up * 1f, ref val3, LayerMask.op_Implicit(_visionMask)))
			{
				PlayerAvatar componentInParent = ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<PlayerAvatar>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent == (Object)(object)player)
				{
					return true;
				}
				return false;
			}
			return true;
		}

		private IEnumerator SpinAndExplode()
		{
			if (!_exploding)
			{
				_exploding = true;
				if (Object.op_Implicit((Object)(object)_agent))
				{
					_agent.isStopped = true;
				}
				float t = 0f;
				float spin = 0f;
				while (t < 2f)
				{
					spin += 720f * Time.deltaTime;
					((Component)this).transform.Rotate(Vector3.up, spin * Time.deltaTime, (Space)0);
					t += Time.deltaTime;
					yield return null;
				}
				ZoraEventRouter.BroadcastDespawn();
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		private void DoExplosion()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			IReadOnlyList<PlayerAvatar> readOnlyList = KittyManager.AllPlayersCached();
			float num = 6f;
			for (int i = 0; i < readOnlyList.Count; i++)
			{
				PlayerAvatar val = readOnlyList[i];
				if (Object.op_Implicit((Object)(object)val) && Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position) <= num)
				{
					TryKill(val);
				}
			}
		}

		private void TryKill(PlayerAvatar player)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)player == (Object)null)
				{
					return;
				}
				if ((Object)(object)player.playerHealth != (Object)null)
				{
					player.playerHealth.HurtOther(999, ((Component)player).transform.position, true, -1);
					return;
				}
				PlayerHealth playerHealth = player.playerHealth;
				if (playerHealth != null)
				{
					playerHealth.Hurt(999, true, -1);
				}
			}
			catch
			{
			}
		}

		public void ApplyNetworkPose(Vector3 pos, Quaternion rot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			_netPos = pos;
			_netRot = rot;
			_hasNetPose = true;
		}

		private void ClientTick()
		{
			//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_005b: 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_0071: 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_009e: 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)
			if (_hasNetPose)
			{
				if (Vector3.Distance(((Component)this).transform.position, _netPos) > 5f)
				{
					((Component)this).transform.SetPositionAndRotation(_netPos, _netRot);
					return;
				}
				((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, _netPos, Time.deltaTime * 10f);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, _netRot, Time.deltaTime * 10f);
			}
		}
	}
	[BepInPlugin("empress.repo.demogorgonex", "DemoGorgonEX", "1.1.8")]
	public class ZoraStarePlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ZoraStareController), "TryKill")]
		private static class Patch_Zora_TryKill
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				_spawnKillAchieved = true;
			}
		}

		public const string PluginGuid = "empress.repo.demogorgonex";

		public const string PluginName = "DemoGorgonEX";

		public const string PluginVersion = "1.1.8";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		private static AssetBundle _bundle;

		private static GameObject _enderPrefab;

		public static List<AudioClip> IdleClips = new List<AudioClip>();

		public static List<AudioClip> AttackClips = new List<AudioClip>();

		public static List<AudioClip> WalkClips = new List<AudioClip>();

		internal static ConfigEntry<float> SpawnChance;

		private bool _spawnRoutineRunning;

		private bool _spawnedThisScene;

		private static bool _spawnKillAchieved;

		public static LayerMask VisionMask = LayerMask.op_Implicit(-1);

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"!!! ZORA PLUGIN AWAKE !!!");
			_harmony = new Harmony("empress.repo.demogorgonex");
			_harmony.PatchAll(typeof(ZoraStarePlugin).Assembly);
			SpawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawn", "SpawnChance", 0.05f, new ConfigDescription("Chance [0..1] that Zora spawns per playable level.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			LoadBundle();
			GameObject val = new GameObject("ZoraStare_RouterHost");
			Object.DontDestroyOnLoad((Object)(object)val);
			((Object)val).hideFlags = (HideFlags)52;
			ZoraEventRouter zoraEventRouter = val.AddComponent<ZoraEventRouter>();
			ZoraEventRouter.SetPrefab(_enderPrefab);
			SceneManager.sceneLoaded += OnSceneLoaded;
		}

		private void Start()
		{
			((MonoBehaviour)this).StartCoroutine(LoadExternalAudio());
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		private void OnSceneLoaded(Scene s, LoadSceneMode m)
		{
			_spawnRoutineRunning = false;
			_spawnedThisScene = false;
			((MonoBehaviour)this).StopAllCoroutines();
			if (AttackClips.Count == 0)
			{
				((MonoBehaviour)this).StartCoroutine(LoadExternalAudio());
			}
			if (PhotonNetwork.InRoom || !PhotonNetwork.IsConnected)
			{
				((MonoBehaviour)this).StartCoroutine(WaitLevelThenSpawn());
			}
		}

		private IEnumerator LoadExternalAudio()
		{
			Log.LogInfo((object)"[Skript was here] === STARTING AUDIO LOAD (Sync Check) ===");
			string myDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			if (string.IsNullOrEmpty(myDir))
			{
				myDir = Paths.PluginPath;
			}
			Log.LogInfo((object)("[Skript was here] Scanning folder: " + myDir));
			IdleClips.Clear();
			AttackClips.Clear();
			WalkClips.Clear();
			string[] extensions = new string[3] { ".mp3", ".wav", ".ogg" };
			string[] files = (from f in Directory.GetFiles(myDir, "*.*", SearchOption.TopDirectoryOnly)
				where extensions.Contains(Path.GetExtension(f).ToLowerInvariant())
				select f).ToArray();
			if (files.Length == 0)
			{
				Log.LogError((object)"[Skript was here] 0 AUDIO FILES FOUND! Make sure .mp3 files are next to the .dll");
				yield break;
			}
			Log.LogInfo((object)$"[Skript was here] Found {files.Length} files. Starting web requests...");
			string[] array = files;
			foreach (string f2 in array)
			{
				string fileName = Path.GetFileNameWithoutExtension(f2).ToLowerInvariant();
				string extension = Path.GetExtension(f2).ToLowerInvariant();
				AudioType type = (AudioType)0;
				switch (extension)
				{
				case ".mp3":
					type = (AudioType)13;
					break;
				case ".wav":
					type = (AudioType)20;
					break;
				case ".ogg":
					type = (AudioType)14;
					break;
				}
				string url = "file:///" + f2.Replace("\\", "/");
				UnityWebRequest uwr = UnityWebRequestMultimedia.GetAudioClip(url, type);
				try
				{
					yield return uwr.SendWebRequest();
					if ((int)uwr.result == 1)
					{
						AudioClip clip = DownloadHandlerAudioClip.GetContent(uwr);
						((Object)clip).name = fileName;
						if (fileName.Contains("idle"))
						{
							IdleClips.Add(clip);
							Log.LogInfo((object)("[Skript was here] + IDLE: " + fileName));
						}
						else if (fileName.Contains("attack"))
						{
							AttackClips.Add(clip);
							Log.LogInfo((object)("[Skript was here] + ATTACK: " + fileName));
						}
						else if (fileName.Contains("walk") || fileName.Contains("step"))
						{
							WalkClips.Add(clip);
							Log.LogInfo((object)("[Skript was here] + WALK: " + fileName));
						}
					}
					else
					{
						Log.LogError((object)("[Skript was here] FAILED " + fileName + ": " + uwr.error));
					}
				}
				finally
				{
					((IDisposable)uwr)?.Dispose();
				}
			}
			Log.LogInfo((object)$"[Skript was here] === DONE === Idles: {IdleClips.Count}, Attacks: {AttackClips.Count}, Walks: {WalkClips.Count}");
		}

		private IEnumerator WaitLevelThenSpawn()
		{
			if (_spawnRoutineRunning || _spawnedThisScene)
			{
				yield break;
			}
			_spawnRoutineRunning = true;
			float t = 0f;
			while (BlockedMenuOrHub())
			{
				if (t >= 30f)
				{
					_spawnRoutineRunning = false;
					yield break;
				}
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			t = 0f;
			if (!PhotonNetwork.InRoom && PhotonNetwork.IsConnected)
			{
				_spawnRoutineRunning = false;
				yield break;
			}
			while ((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated)
			{
				if (t >= 30f)
				{
					_spawnRoutineRunning = false;
					yield break;
				}
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			t = 0f;
			while (!NavMeshReady())
			{
				if (t >= 30f)
				{
					_spawnRoutineRunning = false;
					yield break;
				}
				t += Time.unscaledDeltaTime;
				yield return null;
			}
			if (!KittyManager.IsAuthority())
			{
				_spawnRoutineRunning = false;
				yield break;
			}
			if ((Object)(object)_enderPrefab == (Object)null)
			{
				_spawnRoutineRunning = false;
				yield break;
			}
			float chance = Mathf.Clamp01(SpawnChance?.Value ?? 1f);
			bool pass = Random.value <= chance;
			if (PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady)
			{
				ZoraEventRouter.BroadcastSpawnRoll(pass, chance);
			}
			if (!pass)
			{
				_spawnRoutineRunning = false;
				_spawnedThisScene = false;
				yield break;
			}
			Transform tSpawn = PickRandomSpawnPoint();
			Vector3 pos = tSpawn.position + Vector3.up * 0.2f;
			Quaternion rot = tSpawn.rotation;
			ZoraEventRouter.BroadcastSpawn(pos, rot, ((LayerMask)(ref VisionMask)).value);
			_spawnKillAchieved = false;
			((MonoBehaviour)this).StartCoroutine(DespawnIfNoKill(180f));
			_spawnedThisScene = true;
			_spawnRoutineRunning = false;
		}

		private IEnumerator DespawnIfNoKill(float seconds)
		{
			float end = Time.time + seconds;
			while (Time.time < end)
			{
				if (_spawnKillAchieved)
				{
					yield break;
				}
				yield return null;
			}
			if (KittyManager.IsAuthority())
			{
				ZoraEventRouter.BroadcastDespawn();
			}
		}

		private static bool BlockedMenuOrHub()
		{
			try
			{
				RunManager instance = RunManager.instance;
				Level val = instance?.levelCurrent;
				if ((Object)(object)instance == (Object)null || (Object)(object)val == (Object)null)
				{
					return true;
				}
				string text = SafeLower(val.NarrativeName);
				string text2 = SafeLower(val.ResourcePath);
				if (text.Contains("lobby menu") || text2.Contains("lobby menu"))
				{
					return true;
				}
				if (text.Contains("main menu") || text2.Contains("main menu"))
				{
					return true;
				}
				if (text.Contains("splash screen") || text.Contains("splash"))
				{
					return true;
				}
				if (text.Contains("shop") || text2.Contains("shop") || text2.Contains("store"))
				{
					return true;
				}
				if (text.Contains("lobby") || text2.Contains("lobby"))
				{
					return true;
				}
				if (text.Contains("arena") || text2.Contains("arena"))
				{
					return true;
				}
				if (text2.Contains("/menu/"))
				{
					return true;
				}
				return false;
			}
			catch
			{
				return true;
			}
		}

		private static string SafeLower(string s)
		{
			return (s ?? string.Empty).Trim().ToLowerInvariant();
		}

		private static bool NavMeshReady()
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: 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)
			NavMeshTriangulation val = NavMesh.CalculateTriangulation();
			return val.vertices != null && val.vertices.Length != 0 && val.indices != null && val.indices.Length != 0;
		}

		private static Transform PickRandomSpawnPoint()
		{
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Expected O, but got Unknown
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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)
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance != (Object)null && instance.Generated && instance.LevelPathPoints != null && instance.LevelPathPoints.Count > 0)
			{
				List<Transform> list = new List<Transform>(instance.LevelPathPoints.Count);
				for (int i = 0; i < instance.LevelPathPoints.Count; i++)
				{
					LevelPoint val = instance.LevelPathPoints[i];
					if (!((Object)(object)val == (Object)null))
					{
						list.Add(((Component)val).transform);
					}
				}
				if ((Object)(object)instance.LevelPathTruck != (Object)null)
				{
					Vector3 position = ((Component)instance.LevelPathTruck).transform.position;
					for (int j = 1; j < list.Count; j++)
					{
						Transform val2 = list[j];
						float num = Vector3.Distance(position, val2.position);
						int num2 = j - 1;
						while (num2 >= 0 && Vector3.Distance(position, list[num2].position) > num)
						{
							list[num2 + 1] = list[num2];
							num2--;
						}
						list[num2 + 1] = val2;
					}
					int num3 = Mathf.Min(3, list.Count);
					int num4 = 0;
					for (int k = num3; k < list.Count; k++)
					{
						if (Vector3.Distance(position, list[k].position) > 6f)
						{
							list[num4++] = list[k];
						}
					}
					if (num4 > 0)
					{
						list.RemoveRange(num4, list.Count - num4);
					}
				}
				if (list.Count > 0)
				{
					return list[Random.Range(0, list.Count)];
				}
			}
			SpawnPoint[] array = Object.FindObjectsOfType<SpawnPoint>();
			if (array == null || array.Length == 0)
			{
				GameObject val3 = new GameObject("ZoraStare_SpawnFallback");
				val3.transform.position = Vector3.up;
				return val3.transform;
			}
			return ((Component)array[Random.Range(0, array.Length)]).transform;
		}

		private void LoadBundle()
		{
			if ((Object)(object)_bundle != (Object)null)
			{
				return;
			}
			try
			{
				string text = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
				if (string.IsNullOrEmpty(text))
				{
					text = Paths.PluginPath;
				}
				string[] array = Directory.GetFiles(text, "demogordo", SearchOption.TopDirectoryOnly).Concat(Directory.GetFiles(text, "demogordo.*", SearchOption.TopDirectoryOnly)).ToArray();
				string[] array2 = array;
				foreach (string text2 in array2)
				{
					try
					{
						_bundle = AssetBundle.LoadFromFile(text2);
						if (!Object.op_Implicit((Object)(object)_bundle))
						{
							continue;
						}
						_enderPrefab = _bundle.LoadAsset<GameObject>("DemogorgonPrefab");
						if (Object.op_Implicit((Object)(object)_enderPrefab))
						{
							if (!Object.op_Implicit((Object)(object)_enderPrefab.GetComponent<NavMeshAgent>()))
							{
								_enderPrefab.AddComponent<NavMeshAgent>();
							}
							if (!Object.op_Implicit((Object)(object)_enderPrefab.GetComponent<ZoraStareController>()))
							{
								_enderPrefab.AddComponent<ZoraStareController>();
							}
							if (!Object.op_Implicit((Object)(object)_enderPrefab.GetComponent<ZoraStareAudio>()))
							{
								_enderPrefab.AddComponent<ZoraStareAudio>();
							}
							Log.LogInfo((object)("Loaded AssetBundle at " + text2 + " with ender prefab."));
							return;
						}
					}
					catch (Exception ex)
					{
						Log.LogWarning((object)("Failed to load bundle at " + text2 + ": " + ex.Message));
					}
				}
				Log.LogWarning((object)"No 'demogordo' AssetBundle found beside the plugin .dll.");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"LoadBundle failed: {arg}");
			}
		}
	}
}
namespace Empress.KittyCurse
{
	[RequireComponent(typeof(NavMeshAgent))]
	[DisallowMultipleComponent]
	public class KittyCatController : MonoBehaviour
	{
		private enum State
		{
			Patrol,
			Pursue,
			Ask,
			KillAll
		}

		private NavMeshAgent _agent;

		private Animator _anim;

		private AudioSource _voice;

		private AudioSource _music;

		private AudioClip[] _voiceClips;

		private AudioClip _musicClip;

		private float _voiceVol = 1f;

		private float _musicVol = 0.5f;

		private float _patrolRadius;

		private float _engageDistance;

		private LayerMask _visionMask;

		private float _askGrace;

		private float _askInterval;

		private Transform[] _levelPoints;

		private Transform _truckPoint;

		private Transform _currentPatrolTarget;

		private float _idleUntil;

		private bool _movingToPatrol;

		private float _repathTimer;

		private Vector3 _lastPos;

		private float _stuckTimer;

		private PlayerAvatar _target;

		private State _state = State.Patrol;

		private float _scanTimer;

		private float _poseSendTimer;

		private const float PoseSendInterval = 0.2f;

		private Vector3 _netPos;

		private Quaternion _netRot;

		private bool _hasNetPose;

		private const float PoseSnapDist = 5f;

		private const float PoseLerpRate = 10f;

		private float _postGiftCooldownUntil;

		private bool _hasCatIdleTrigger;

		private bool _hasWalkBool;

		private Vector3 _animLastPos;

		private float _killRepathTimer;

		private static readonly List<PlayerAvatar> _victimsTmp = new List<PlayerAvatar>(8);

		public void Setup(float patrolRadius, float engageDistance, LayerMask visionMask, float askGrace, float askInterval)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			_patrolRadius = patrolRadius;
			_engageDistance = engageDistance;
			_visionMask = visionMask;
			_askGrace = Mathf.Max(10f, askGrace);
			_askInterval = Mathf.Max(_askGrace, askInterval);
		}

		public void AssignAudio(AudioClip[] voices, AudioClip music, float voiceVol, float musicVol)
		{
			_voiceClips = voices ?? Array.Empty<AudioClip>();
			_musicClip = music;
			_voiceVol = Mathf.Clamp01(voiceVol);
			_musicVol = Mathf.Clamp01(musicVol);
		}

		public void ApplyNetworkPose(Vector3 pos, Quaternion rot)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_000a: Unknown result type (might be due to invalid IL or missing references)
			_netPos = pos;
			_netRot = rot;
			_hasNetPose = true;
		}

		private void Awake()
		{
			_agent = ((Component)this).GetComponent<NavMeshAgent>();
			_anim = ((Component)this).GetComponent<Animator>();
			_voice = ((Component)this).GetComponent<AudioSource>() ?? ((Component)this).gameObject.AddComponent<AudioSource>();
			_voice.playOnAwake = false;
			_voice.loop = false;
			_voice.spatialBlend = 1f;
			_voice.dopplerLevel = 0f;
			_voice.rolloffMode = (AudioRolloffMode)0;
			_voice.minDistance = 8f;
			_voice.maxDistance = 18f;
			_music = ((Component)this).gameObject.AddComponent<AudioSource>();
			_music.playOnAwake = false;
			_music.loop = true;
			_music.spatialBlend = 1f;
			_music.dopplerLevel = 0f;
			_music.rolloffMode = (AudioRolloffMode)0;
			_music.minDistance = 12f;
			_music.maxDistance = 30f;
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.stoppingDistance = 1.5f;
			}
		}

		private void OnEnable()
		{
			KittyManager.Register(this);
		}

		private void OnDisable()
		{
			KittyManager.Unregister(this);
		}

		private void Start()
		{
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Invalid comparison between Unknown and I4
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Invalid comparison between Unknown and I4
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance != (Object)null && instance.Generated)
			{
				_truckPoint = (Object.op_Implicit((Object)(object)instance.LevelPathTruck) ? ((Component)instance.LevelPathTruck).transform : null);
				if (instance.LevelPathPoints != null)
				{
					_levelPoints = (from p in instance.LevelPathPoints
						where (Object)(object)p != (Object)null
						select ((Component)p).transform).ToArray();
				}
			}
			_idleUntil = Time.time + Random.Range(10f, 30f);
			_lastPos = ((Component)this).transform.position;
			_animLastPos = ((Component)this).transform.position;
			if ((Object)(object)_anim != (Object)null)
			{
				for (int i = 0; i < _anim.parameterCount; i++)
				{
					AnimatorControllerParameter parameter = _anim.GetParameter(i);
					if (parameter.name == "catidle" && (int)parameter.type == 9)
					{
						_hasCatIdleTrigger = true;
					}
					if (parameter.name == "Walk" && (int)parameter.type == 4)
					{
						_hasWalkBool = true;
					}
				}
			}
			if (!KittyManager.IsAuthority() && Object.op_Implicit((Object)(object)_agent) && ((Behaviour)_agent).enabled)
			{
				((Behaviour)_agent).enabled = false;
			}
		}

		private void Update()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: 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)
			if (KittyManager.IsAuthority())
			{
				HostTick();
				if (KittyManager.CanStreamPose())
				{
					_poseSendTimer += Time.deltaTime;
					if (_poseSendTimer >= 0.2f)
					{
						_poseSendTimer = 0f;
						KittyEventRouter.BroadcastPose(((Component)this).transform.position, ((Component)this).transform.rotation);
					}
				}
			}
			else
			{
				ClientTick();
			}
			if (!Object.op_Implicit((Object)(object)_anim) || !_hasWalkBool)
			{
				return;
			}
			bool flag = false;
			Vector3 val;
			if (KittyManager.IsAuthority())
			{
				if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
				{
					int num;
					if (!_agent.isStopped)
					{
						val = _agent.velocity;
						num = ((((Vector3)(ref val)).sqrMagnitude > 0.0001f) ? 1 : 0);
					}
					else
					{
						num = 0;
					}
					flag = (byte)num != 0;
				}
			}
			else
			{
				val = ((Component)this).transform.position - _animLastPos;
				flag = ((Vector3)(ref val)).sqrMagnitude > 0.0001f;
			}
			_anim.SetBool("Walk", flag);
			_animLastPos = ((Component)this).transform.position;
		}

		private void HostTick()
		{
			_scanTimer -= Time.deltaTime;
			if (_scanTimer <= 0f)
			{
				_scanTimer = 0.33f;
				ScanForTargets();
			}
			switch (_state)
			{
			case State.Patrol:
				PatrolTick();
				break;
			case State.Pursue:
				PursueTick();
				break;
			case State.Ask:
				break;
			case State.KillAll:
				KillAllTick();
				break;
			}
		}

		private void ScanForTargets()
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _postGiftCooldownUntil || _state == State.Ask || _state == State.KillAll)
			{
				return;
			}
			IReadOnlyList<PlayerAvatar> readOnlyList = KittyManager.AllPlayersCached();
			PlayerAvatar val = null;
			float num = float.PositiveInfinity;
			for (int i = 0; i < readOnlyList.Count; i++)
			{
				PlayerAvatar val2 = readOnlyList[i];
				if (Object.op_Implicit((Object)(object)val2))
				{
					float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val2).transform.position);
					if (num2 <= _engageDistance && num2 < num && HasLineOfSight(val2))
					{
						val = val2;
						num = num2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				_target = val;
				_state = State.Pursue;
			}
		}

		private void PursueTick()
		{
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_target == (Object)null)
			{
				_state = State.Patrol;
			}
			else if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				_agent.isStopped = false;
				_repathTimer -= Time.deltaTime;
				if (_repathTimer <= 0f)
				{
					_repathTimer = 0.15f;
					_agent.SetDestination(((Component)_target).transform.position);
				}
				if (Vector3.Distance(((Component)this).transform.position, ((Component)_target).transform.position) <= 4f)
				{
					((MonoBehaviour)this).StartCoroutine(AskSequence(_target));
				}
			}
		}

		private IEnumerator AskSequence(PlayerAvatar player)
		{
			if (_state == State.Ask)
			{
				yield break;
			}
			_state = State.Ask;
			IdleAnim();
			for (int i = 0; i < 3; i++)
			{
				if (KittyManager.IsAuthority())
				{
					KittyEventRouter.BroadcastVoice(Mathf.Clamp(i, 0, 2));
				}
				float t = 0f;
				while (t < _askGrace)
				{
					if (GiftSatisfied(player))
					{
						OnGiftAccepted();
						yield break;
					}
					t += Time.deltaTime;
					yield return null;
				}
				if (i >= 2)
				{
					continue;
				}
				float end = Time.time + _askInterval;
				while (Time.time < end)
				{
					if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
					{
						_agent.isStopped = false;
						_agent.speed = 4.2f;
						_repathTimer -= Time.deltaTime;
						if (_repathTimer <= 0f)
						{
							_repathTimer = 0.2f;
							_agent.SetDestination(((Component)player).transform.position);
						}
					}
					if (GiftSatisfied(player))
					{
						OnGiftAccepted();
						yield break;
					}
					yield return null;
				}
				IdleAnim();
			}
			if (!KittyManager.IsAuthority())
			{
				yield break;
			}
			float t2 = 0f;
			while (t2 < _askGrace)
			{
				if (GiftSatisfied(player))
				{
					OnGiftAccepted();
					yield break;
				}
				t2 += Time.deltaTime;
				yield return null;
			}
			StartKillEveryoneMode();
		}

		private void IdleAnim()
		{
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.isStopped = true;
			}
			if (Object.op_Implicit((Object)(object)_anim) && _hasCatIdleTrigger)
			{
				_anim.SetTrigger("catidle");
			}
			if (Object.op_Implicit((Object)(object)_anim) && _hasWalkBool)
			{
				_anim.SetBool("Walk", false);
			}
		}

		private bool GiftSatisfied(PlayerAvatar player)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			if (KittyManager.IsAuthority())
			{
				return KittyManager.AnyRecentDropNear(((Component)this).transform.position, _askGrace, 6f);
			}
			return false;
		}

		private void OnGiftAccepted()
		{
			_target = null;
			_state = State.Patrol;
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.speed = 3.5f;
				_agent.isStopped = false;
			}
			_postGiftCooldownUntil = Time.time + 15f;
			((MonoBehaviour)this).StartCoroutine(WanderOffAndDie());
		}

		private IEnumerator WanderOffAndDie()
		{
			Vector3 best = ((Component)this).transform.position;
			float bestScore = float.NegativeInfinity;
			IReadOnlyList<PlayerAvatar> players = KittyManager.AllPlayersCached();
			NavMeshHit hit = default(NavMeshHit);
			for (int i = 0; i < 16; i++)
			{
				Vector3 cand = ((Component)this).transform.position + Random.insideUnitSphere * 45f;
				if (NavMesh.SamplePosition(cand, ref hit, 6f, -1))
				{
					float score = 0f;
					for (int p = 0; p < players.Count; p++)
					{
						PlayerAvatar av = players[p];
						if (Object.op_Implicit((Object)(object)av))
						{
							score += Vector3.Distance(((NavMeshHit)(ref hit)).position, ((Component)av).transform.position);
						}
					}
					if (score > bestScore)
					{
						bestScore = score;
						best = ((NavMeshHit)(ref hit)).position;
					}
				}
				hit = default(NavMeshHit);
			}
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				_agent.isStopped = false;
				_agent.speed = 3.8f;
				_agent.SetDestination(best);
			}
			float end = Time.time + 10f;
			while (Time.time < end)
			{
				yield return null;
			}
			ToggleMusicLocal(on: false);
			KittyEventRouter.BroadcastDespawn();
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private bool HasLineOfSight(PlayerAvatar player)
		{
			//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_002d: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			Vector3 val = ((Component)this).transform.position + Vector3.up * 1.2f;
			Transform val2 = null;
			try
			{
				val2 = (((Object)(object)player.PlayerVisionTarget != (Object)null) ? player.PlayerVisionTarget.VisionTransform : null);
			}
			catch
			{
			}
			Vector3 val3 = (((Object)(object)val2 != (Object)null) ? val2.position : ((Component)player).transform.position);
			RaycastHit val4 = default(RaycastHit);
			if (Physics.Linecast(val, val3, ref val4, LayerMask.op_Implicit(_visionMask)))
			{
				return (Object)(object)((Component)((RaycastHit)(ref val4)).collider).GetComponentInParent<PlayerAvatar>() == (Object)(object)player;
			}
			return true;
		}

		private void PatrolTick()
		{
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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)
			if (!Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh)
			{
				return;
			}
			if (_movingToPatrol)
			{
				if (!_agent.pathPending && _agent.remainingDistance <= 0.5f)
				{
					_movingToPatrol = false;
					_idleUntil = Time.time + Random.Range(10f, 30f);
					_agent.isStopped = true;
					return;
				}
				Vector3 val = ((Component)this).transform.position - _lastPos;
				float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
				_stuckTimer = ((sqrMagnitude < 0.0004f) ? (_stuckTimer + Time.deltaTime) : 0f);
				_lastPos = ((Component)this).transform.position;
				if (_stuckTimer > 2f)
				{
					_stuckTimer = 0f;
					ForceNextPatrolDestination();
				}
			}
			else if (Time.time < _idleUntil)
			{
				if (!_agent.isStopped)
				{
					_agent.isStopped = true;
				}
			}
			else
			{
				ForceNextPatrolDestination();
			}
		}

		private void ForceNextPatrolDestination()
		{
			//IL_00a8: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: 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_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)
			_agent.isStopped = false;
			_currentPatrolTarget = ChooseNextLevelPoint();
			if ((Object)(object)_currentPatrolTarget != (Object)null)
			{
				Vector3 position = _currentPatrolTarget.position;
				NavMeshHit val = default(NavMeshHit);
				if (NavMesh.SamplePosition(position, ref val, 3f, -1))
				{
					position = ((NavMeshHit)(ref val)).position;
				}
				if (_agent.isOnNavMesh)
				{
					_agent.SetDestination(position);
				}
				else
				{
					_agent.Warp(position);
				}
				_movingToPatrol = true;
				_lastPos = ((Component)this).transform.position;
				_stuckTimer = 0f;
				return;
			}
			Vector3 val2 = Random.insideUnitSphere * _patrolRadius + ((Component)this).transform.position;
			NavMeshHit val3 = default(NavMeshHit);
			if (NavMesh.SamplePosition(val2, ref val3, _patrolRadius, -1))
			{
				if (_agent.isOnNavMesh)
				{
					_agent.SetDestination(((NavMeshHit)(ref val3)).position);
				}
				else
				{
					_agent.Warp(((NavMeshHit)(ref val3)).position);
				}
			}
			_movingToPatrol = true;
			_lastPos = ((Component)this).transform.position;
			_stuckTimer = 0f;
		}

		private Transform ChooseNextLevelPoint()
		{
			//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_006a: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			if (_levelPoints == null || _levelPoints.Length == 0)
			{
				return null;
			}
			Vector3 position = ((Component)this).transform.position;
			Transform val = null;
			float num = float.NegativeInfinity;
			for (int i = 0; i < _levelPoints.Length; i++)
			{
				Transform val2 = _levelPoints[i];
				if ((Object)(object)val2 == (Object)null || ((Object)(object)_truckPoint != (Object)null && Vector3.Distance(val2.position, _truckPoint.position) <= 6f))
				{
					continue;
				}
				float num2 = Vector3.Distance(val2.position, position);
				if (!(num2 <= 12f))
				{
					float num3 = num2;
					if (num3 > num)
					{
						num = num3;
						val = val2;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			return _levelPoints[Random.Range(0, _levelPoints.Length)];
		}

		private void TryKill(PlayerAvatar player)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)player == (Object)null)
				{
					return;
				}
				if ((Object)(object)player.playerHealth != (Object)null)
				{
					player.playerHealth.HurtOther(999, ((Component)player).transform.position, true, -1);
					return;
				}
				PlayerHealth playerHealth = player.playerHealth;
				if (playerHealth != null)
				{
					playerHealth.Hurt(999, true, -1);
				}
			}
			catch
			{
			}
		}

		private void StartKillEveryoneMode()
		{
			_state = State.KillAll;
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.isStopped = false;
				_agent.speed = 9f;
				_agent.acceleration = 20f;
				_agent.angularSpeed = 720f;
			}
			if (KittyManager.IsAuthority())
			{
				KittyEventRouter.BroadcastMusic(on: true);
			}
		}

		private void KillAllTick()
		{
			//IL_00d8: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh)
			{
				return;
			}
			_victimsTmp.Clear();
			IReadOnlyList<PlayerAvatar> readOnlyList = KittyManager.AllPlayersCached();
			for (int i = 0; i < readOnlyList.Count; i++)
			{
				PlayerAvatar val = readOnlyList[i];
				if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.playerHealth) && ((Component)val.playerHealth).gameObject.activeInHierarchy)
				{
					_victimsTmp.Add(val);
				}
			}
			if (_victimsTmp.Count == 0)
			{
				return;
			}
			PlayerAvatar val2 = null;
			float num = float.PositiveInfinity;
			for (int j = 0; j < _victimsTmp.Count; j++)
			{
				PlayerAvatar val3 = _victimsTmp[j];
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val3).transform.position);
				if (num2 < num)
				{
					num = num2;
					val2 = val3;
				}
			}
			if ((Object)(object)val2 != (Object)null)
			{
				_agent.isStopped = false;
				_killRepathTimer -= Time.deltaTime;
				if (_killRepathTimer <= 0f)
				{
					_killRepathTimer = 0.12f;
					_agent.SetDestination(((Component)val2).transform.position);
				}
				if (num <= 3.2f && KittyManager.IsAuthority())
				{
					TryKill(val2);
				}
			}
		}

		internal void PlayVoiceLocal(int index)
		{
			if (!((Object)(object)_voice == (Object)null) && _voiceClips != null && _voiceClips.Length != 0)
			{
				int num = Mathf.Clamp(index, 0, _voiceClips.Length - 1);
				AudioClip val = _voiceClips[num];
				if (Object.op_Implicit((Object)(object)val))
				{
					_voice.volume = _voiceVol;
					_voice.PlayOneShot(val);
				}
			}
		}

		internal void ToggleMusicLocal(bool on)
		{
			if ((Object)(object)_music == (Object)null || (Object)(object)_musicClip == (Object)null)
			{
				return;
			}
			if (on)
			{
				if ((Object)(object)_music.clip != (Object)(object)_musicClip)
				{
					_music.clip = _musicClip;
				}
				_music.volume = _musicVol;
				if (!_music.isPlaying)
				{
					_music.Play();
				}
			}
			else if (_music.isPlaying)
			{
				_music.Stop();
			}
		}

		private void ClientTick()
		{
			//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_005b: 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_0071: 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_009e: 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)
			if (_hasNetPose)
			{
				if (Vector3.Distance(((Component)this).transform.position, _netPos) > 5f)
				{
					((Component)this).transform.SetPositionAndRotation(_netPos, _netRot);
					return;
				}
				((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, _netPos, Time.deltaTime * 10f);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, _netRot, Time.deltaTime * 10f);
			}
		}
	}
	public static class KittyEventRouter
	{
		public static void BroadcastPose(Vector3 pos, Quaternion rot)
		{
		}

		public static void BroadcastDespawn()
		{
		}

		public static void BroadcastMusic(bool on)
		{
		}

		public static void BroadcastVoice(int index)
		{
		}
	}
	public static class KittyManager
	{
		private struct DropRec
		{
			public float t;

			public Vector3 pos;
		}

		private static readonly List<KittyCatController> _cats = new List<KittyCatController>();

		private static readonly Dictionary<int, (float t, Vector3 pos)> _playerDrop = new Dictionary<int, (float, Vector3)>();

		private static readonly DropRec[] _recentDrops = new DropRec[16];

		private static int _recentDropsHead;

		private static readonly List<PlayerAvatar> _playersCache = new List<PlayerAvatar>(8);

		private static float _playersNextRefresh;

		private const float PlayersRefreshInterval = 1f;

		public static void Register(KittyCatController c)
		{
			if ((Object)(object)c != (Object)null && !_cats.Contains(c))
			{
				_cats.Add(c);
			}
		}

		public static void Unregister(KittyCatController c)
		{
			if ((Object)(object)c != (Object)null)
			{
				_cats.Remove(c);
			}
		}

		public static bool IsAuthority()
		{
			return !GameManager.Multiplayer() || PhotonNetwork.IsMasterClient;
		}

		public static bool CanStreamPose()
		{
			return PhotonNetwork.InRoom && PhotonNetwork.IsConnectedAndReady && IsAuthority();
		}

		public static bool AnyCatNear(Vector3 where, float withinMeters)
		{
			//IL_0021: 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)
			for (int i = 0; i < _cats.Count; i++)
			{
				KittyCatController kittyCatController = _cats[i];
				if (Object.op_Implicit((Object)(object)kittyCatController) && Vector3.Distance(where, ((Component)kittyCatController).transform.position) <= withinMeters)
				{
					return true;
				}
			}
			return false;
		}

		public static void NoteValuableDropped(PlayerAvatar avatar, Vector3 where)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)avatar))
			{
				_playerDrop[((Object)avatar).GetInstanceID()] = (Time.time, where);
			}
		}

		public static void NoteValuableDroppedNet(Vector3 where, float time)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			int num = _recentDropsHead++ & (_recentDrops.Length - 1);
			_recentDrops[num].t = time;
			_recentDrops[num].pos = where;
		}

		public static bool AnyRecentDropNear(Vector3 where, float withinSeconds, float withinMeters)
		{
			//IL_003c: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			float time = Time.time;
			float num = withinMeters * withinMeters;
			for (int i = 0; i < _recentDrops.Length; i++)
			{
				float num2 = time - _recentDrops[i].t;
				if (num2 > 0f && num2 <= withinSeconds)
				{
					Vector3 val = where - _recentDrops[i].pos;
					if (((Vector3)(ref val)).sqrMagnitude <= num)
					{
						return true;
					}
				}
			}
			return false;
		}

		public static bool PlayerDroppedValuableNear(PlayerAvatar avatar, Vector3 where, float withinSeconds, float withinMeters)
		{
			//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)
			if (!Object.op_Implicit((Object)(object)avatar))
			{
				return false;
			}
			if (_playerDrop.TryGetValue(((Object)avatar).GetInstanceID(), out (float, Vector3) value) && Time.time - value.Item1 <= withinSeconds)
			{
				return Vector3.Distance(value.Item2, where) <= withinMeters;
			}
			return false;
		}

		public static IReadOnlyList<PlayerAvatar> AllPlayersCached()
		{
			if (Time.unscaledTime >= _playersNextRefresh)
			{
				_playersCache.Clear();
				PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
				if (array != null)
				{
					foreach (PlayerAvatar val in array)
					{
						if (Object.op_Implicit((Object)(object)val))
						{
							_playersCache.Add(val);
						}
					}
				}
				_playersNextRefresh = Time.unscaledTime + 1f;
			}
			return _playersCache;
		}
	}
}