Decompiled source of LinkStatue v1.2.4

LinkStatue.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 FallingStaticObject;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyTemplate;
using LinkStatue;
using LinkStatue.NetcodePatcher;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[module: NetcodePatchedAssembly]
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 FallingStaticObject
{
	internal class FallingObject : MonoBehaviour
	{
		public Vector3 targetFloorPosition;

		private float fallTime;

		public float verticalOffset;

		private Vector3 startFallingPosition;

		public void Start()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			startFallingPosition = ((Component)this).transform.position;
			FallToGround();
		}

		public void Update()
		{
			if (fallTime < 1f)
			{
				FallWithCurve();
			}
		}

		public void FallToGround(bool randomizePosition = false)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003a: 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_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_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			fallTime = 0f;
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(((Component)this).transform.position, Vector3.down, ref val, 80f, 268437760, (QueryTriggerInteraction)1))
			{
				targetFloorPosition = ((RaycastHit)(ref val)).point + verticalOffset * Vector3.up;
				if ((Object)(object)((Component)this).transform.parent != (Object)null)
				{
					targetFloorPosition = ((Component)this).transform.parent.InverseTransformPoint(targetFloorPosition);
				}
			}
			else
			{
				targetFloorPosition = ((Component)this).transform.localPosition;
			}
			if (randomizePosition)
			{
				targetFloorPosition += new Vector3(Random.Range(-0.5f, 0.5f), 0f, Random.Range(-0.5f, 0.5f));
			}
		}

		public virtual void FallWithCurve()
		{
			//IL_005a: 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_007a: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			float num = startFallingPosition.y - targetFloorPosition.y;
			if (num > 5f)
			{
				((Component)this).transform.localPosition = Vector3.Lerp(startFallingPosition, targetFloorPosition, StartOfRound.Instance.objectFallToGroundCurveNoBounce.Evaluate(fallTime));
			}
			else
			{
				((Component)this).transform.localPosition = Vector3.Lerp(startFallingPosition, targetFloorPosition, StartOfRound.Instance.objectFallToGroundCurve.Evaluate(fallTime));
			}
			fallTime += Mathf.Abs(Time.deltaTime * 6f / num);
		}
	}
}
namespace LinkStatue
{
	[HarmonyPatch(typeof(Shovel))]
	internal class ShovelPatch
	{
		[HarmonyPatch("HitShovel")]
		[HarmonyPostfix]
		public static void HitShovelPatch(Shovel __instance)
		{
			//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)
			if (!(Traverse.Create((object)__instance).Field("objectsHitByShovelList").GetValue() is List<RaycastHit> list))
			{
				return;
			}
			for (int i = 0; i < list.Count; i++)
			{
				RaycastHit val = list[i];
				Plugin.TTLogger.LogMessage((object)((Object)((RaycastHit)(ref val)).transform).name);
				LinkStatueAI component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<LinkStatueAI>();
				if ((Object)(object)component != (Object)null)
				{
					object value = Traverse.Create((object)__instance).Field("previousPlayerHeldBy").GetValue();
					PlayerControllerB thePlayer = (PlayerControllerB)((value is PlayerControllerB) ? value : null);
					component.StartKillingPlayer(thePlayer);
					RoundManager.PlayRandomClip(__instance.shovelAudio, __instance.hitSFX, true, 1f, 0, 1000);
					__instance.HitShovelServerRpc(-1);
				}
			}
		}
	}
	internal class LinkStatueAI : NetworkBehaviour
	{
		private bool _hasBeenSeen;

		private PlayerControllerB _lastPersonSeen;

		private int _counterOfTimesSeen;

		private int _numOfEyesOnMe;

		private float _timeSeen;

		public float teleportDelay = 20f;

		public float teleportDelayRange = 10f;

		private float _teleTrueTime;

		private int _defaultSpawnDistance = 100;

		public float tooLonelyTimeDelay = 180f;

		private float _tooLonelyTime;

		public bool haunting;

		private AudioSource LinkVoice;

		private AudioClip LaughSmall;

		private AudioClip LaughLong;

		private AudioClip KillingLaugh;

		private AudioClip KillingSound;

		private AudioClip KillingMusic;

		public void Start()
		{
			//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_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			Plugin.TTLogger.LogInfo((object)("Statue Start: IsServer=" + ((NetworkBehaviour)this).IsServer + " IsSpawned=" + ((NetworkBehaviour)this).IsSpawned + " pos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString()));
			_tooLonelyTime = Time.time + tooLonelyTimeDelay;
			((MonoBehaviour)this).InvokeRepeating("CheckSitesSlow", 0f, 2f);
			LinkVoice = ((Component)this).GetComponent<AudioSource>();
			LaughSmall = Plugin.appAssets.LoadAsset<AudioClip>("Zelda-Laugh-Short");
			LaughLong = Plugin.appAssets.LoadAsset<AudioClip>("Zelda-Laugh-Long");
			KillingLaugh = Plugin.appAssets.LoadAsset<AudioClip>("Happy-Mask-Laugh");
			KillingSound = Plugin.appAssets.LoadAsset<AudioClip>("SkullKid-Scream");
			KillingMusic = Plugin.appAssets.LoadAsset<AudioClip>("SongOfHealing");
			Vector3 position = GameObject.Find("LevelGenerationRoot").transform.position;
			if (Plugin.DebugMode.Value)
			{
				_defaultSpawnDistance = 10;
				position = GameObject.Find("StartRoom(Clone)").transform.position;
			}
			((Component)this).transform.position = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(position, (float)_defaultSpawnDistance, default(NavMeshHit));
			LinkVoice.minDistance = 10f;
			LinkVoice.maxDistance = 30f;
			LinkVoice.spatialBlend = 1f;
			LinkVoice.rolloffMode = (AudioRolloffMode)1;
		}

		public void CheckSitesSlow()
		{
			if (!((NetworkBehaviour)this).IsServer || _hasBeenSeen)
			{
				return;
			}
			PlayerControllerB[] lineOfSightOfAny = GetLineOfSightOfAny(45f, 30);
			_numOfEyesOnMe = lineOfSightOfAny.Length;
			if (_numOfEyesOnMe > 0 && !_hasBeenSeen)
			{
				_hasBeenSeen = true;
				_timeSeen = Time.time;
				_teleTrueTime = Random.Range(teleportDelay - teleportDelayRange, teleportDelay + teleportDelayRange);
				if ((Object)(object)_lastPersonSeen == (Object)(object)lineOfSightOfAny[0])
				{
					_counterOfTimesSeen++;
				}
				else
				{
					_lastPersonSeen = lineOfSightOfAny[0];
					_counterOfTimesSeen = 1;
				}
				Plugin.Dbg("Statue seen by " + lineOfSightOfAny[0].playerUsername + ": sighting " + _counterOfTimesSeen + "/" + Plugin.NumberOfTimesSeenToHaunt.Value + ", teleport in " + _teleTrueTime + "s");
				if (_counterOfTimesSeen >= Plugin.NumberOfTimesSeenToHaunt.Value)
				{
					Plugin.Dbg("Haunt threshold reached, haunting " + _lastPersonSeen.playerUsername);
					StartKillingPlayer(_lastPersonSeen);
				}
			}
		}

		public void Update()
		{
			if (!((NetworkBehaviour)this).IsServer || haunting)
			{
				return;
			}
			if (_hasBeenSeen && Time.time > _timeSeen + _teleTrueTime)
			{
				_numOfEyesOnMe = GetLineOfSightOfAny(45f, 30).Length;
				if (_numOfEyesOnMe > 0)
				{
					_timeSeen = Time.time;
				}
				else
				{
					_tooLonelyTime = Time.time + tooLonelyTimeDelay;
					_hasBeenSeen = false;
					MoveStatueSpot();
				}
			}
			if (Time.time > _tooLonelyTime)
			{
				_numOfEyesOnMe = GetLineOfSightOfAny(45f, 30).Length;
				if (_numOfEyesOnMe == 0)
				{
					_tooLonelyTime = Time.time + tooLonelyTimeDelay;
					_hasBeenSeen = false;
					MoveStatueSpot();
					_lastPersonSeen = null;
				}
			}
		}

		public override void OnDestroy()
		{
			((MonoBehaviour)this).CancelInvoke();
			((NetworkBehaviour)this).OnDestroy();
		}

		public unsafe void MoveStatueSpot()
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: 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_006d: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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_008f: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = GameObject.Find("LevelGenerationRoot").transform.position;
			float num = _defaultSpawnDistance;
			if (Plugin.DebugMode.Value)
			{
				position = GameObject.Find("StartRoom(Clone)").transform.position;
			}
			if ((Object)(object)_lastPersonSeen != (Object)null)
			{
				position = _lastPersonSeen.thisPlayerBody.position;
				num = Plugin.RadiusOfCloseTeleport.Value;
			}
			position = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(position, num, default(NavMeshHit));
			string[] obj = new string[7] { "Teleporting statue to ", null, null, null, null, null, null };
			Vector3 val = position;
			obj[1] = ((object)(*(Vector3*)(&val))/*cast due to .constrained prefix*/).ToString();
			obj[2] = " (radius ";
			obj[3] = num.ToString();
			obj[4] = ", following ";
			obj[5] = (((Object)(object)_lastPersonSeen != (Object)null) ? _lastPersonSeen.playerUsername : "nobody");
			obj[6] = ")";
			Plugin.Dbg(string.Concat(obj));
			MoveStatueSpotServerRpc(position);
		}

		[ServerRpc(RequireOwnership = false)]
		public void MoveStatueSpotServerRpc(Vector3 newSpot)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_00ce: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val2 = default(ServerRpcParams);
				FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(718832639u, val2, (RpcDelivery)0);
				((FastBufferWriter)(ref val)).WriteValueSafe(ref newSpot);
				((NetworkBehaviour)this).__endSendServerRpc(ref val, 718832639u, val2, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				base.__rpc_exec_stage = (__RpcExecStage)0;
				Plugin.Dbg("MoveStatueSpotServerRpc received (IsServer=" + ((NetworkBehaviour)this).IsServer + ")");
				if (((NetworkBehaviour)this).IsServer)
				{
					MoveStatueSpotClientRpc(newSpot);
				}
			}
		}

		[ClientRpc]
		public void MoveStatueSpotClientRpc(Vector3 newSpot)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val2 = default(ClientRpcParams);
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(2186059455u, val2, (RpcDelivery)0);
					((FastBufferWriter)(ref val)).WriteValueSafe(ref newSpot);
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 2186059455u, val2, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					Plugin.Dbg("MoveStatueSpotClientRpc received, starting teleport");
					((MonoBehaviour)this).StartCoroutine(MoveStatueSpotCoroutine(newSpot));
				}
			}
		}

		[ServerRpc(RequireOwnership = false)]
		public void StartKillingPlayerServerRpc(int thePlayer)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_0089: 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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					ServerRpcParams val2 = default(ServerRpcParams);
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendServerRpc(1540599700u, val2, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val, thePlayer);
					((NetworkBehaviour)this).__endSendServerRpc(ref val, 1540599700u, val2, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					StartKillingPlayerClientRpc(thePlayer);
				}
			}
		}

		[ClientRpc]
		public void StartKillingPlayerClientRpc(int thePlayer)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Invalid comparison between Unknown and I4
			//IL_005f: 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_006d: 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_0089: 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_00fe: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 1 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val2 = default(ClientRpcParams);
					FastBufferWriter val = ((NetworkBehaviour)this).__beginSendClientRpc(3420559006u, val2, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val, thePlayer);
					((NetworkBehaviour)this).__endSendClientRpc(ref val, 3420559006u, val2, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsClient || networkManager.IsHost))
				{
					base.__rpc_exec_stage = (__RpcExecStage)0;
					Plugin.Dbg("Haunt RPC received for player index " + thePlayer);
					((Component)this).transform.localScale = new Vector3(0f, 0f, 0f);
					((MonoBehaviour)this).StartCoroutine(StartKillingPlayerCoroutine(thePlayer));
				}
			}
		}

		public IEnumerator MoveStatueSpotCoroutine(Vector3 newSpot)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			((Component)this).transform.localScale = new Vector3(0f, 0f, 0f);
			Plugin.Dbg("Teleport laugh at " + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString() + ", player distance " + Vector3.Distance(((Component)this).transform.position, ((Component)StartOfRound.Instance.localPlayerController).transform.position));
			PlaySound(Random.Range(0, 2));
			yield return (object)new WaitUntil((Func<bool>)(() => !LinkVoice.isPlaying));
			((Component)this).transform.position = newSpot;
			((Component)this).transform.rotation = Quaternion.Euler(new Vector3(((Component)this).transform.eulerAngles.x, RoundManager.Instance.YRotationThatFacesTheFarthestFromPosition(newSpot, 25f, 6), ((Component)this).transform.eulerAngles.z));
			((Component)this).transform.localScale = new Vector3(2f, 2f, 2f);
		}

		public void InstantMoveStatue(Vector3 newPos)
		{
			//IL_0015: 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_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_0039: 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)
			((Component)this).transform.localScale = new Vector3(0f, 0f, 0f);
			((Component)this).transform.position = RoundManager.Instance.GetRandomNavMeshPositionInRadiusSpherical(newPos, 3f, default(NavMeshHit));
			((Component)this).transform.localScale = new Vector3(2f, 2f, 2f);
		}

		public void StartKillingPlayer(PlayerControllerB thePlayer)
		{
			if ((Object)(object)thePlayer == (Object)null)
			{
				Plugin.TTLogger.LogError((object)"StartKillingPlayer called with no player");
				return;
			}
			Plugin.Dbg("StartKillingPlayer for " + thePlayer.playerUsername);
			int thePlayer2 = Array.FindIndex(StartOfRound.Instance.allPlayerScripts, (PlayerControllerB player) => player.playerClientId == thePlayer.playerClientId);
			StartKillingPlayerServerRpc(thePlayer2);
		}

		public IEnumerator StartKillingPlayerCoroutine(int thePlayerIndex)
		{
			PlayerControllerB thePlayer = StartOfRound.Instance.allPlayerScripts[thePlayerIndex];
			haunting = true;
			Plugin.Dbg("Haunt started on " + thePlayer.playerUsername + ", killing in about 55s");
			PlaySound(Random.Range(0, 2));
			yield return (object)new WaitForSeconds(20f);
			float interval = 6f;
			for (int j = 0; j < 5; j++)
			{
				if ((Object)(object)StartOfRound.Instance.localPlayerController == (Object)(object)thePlayer)
				{
					thePlayer.statusEffectAudio.PlayOneShot(KillingLaugh);
				}
				yield return (object)new WaitForSeconds(interval);
				interval -= 0.5f;
			}
			thePlayer.statusEffectAudio.PlayOneShot(KillingMusic);
			for (int j = 0; j < 5; j++)
			{
				if ((Object)(object)StartOfRound.Instance.localPlayerController == (Object)(object)thePlayer)
				{
					thePlayer.statusEffectAudio.PlayOneShot(KillingLaugh);
				}
				yield return (object)new WaitForSeconds(2f);
			}
			Plugin.Dbg("Haunt finished, killing " + thePlayer.playerUsername);
			try
			{
				thePlayer.KillPlayer(Vector3.zero, true, (CauseOfDeath)5, 1, default(Vector3), false);
			}
			catch (Exception ex)
			{
				Plugin.TTLogger.LogError((object)("KillPlayer failed: " + ex));
			}
			InstantMoveStatue(((Component)thePlayer).transform.position);
			((Component)this).transform.localScale = new Vector3(2f, 2f, 2f);
			PlaySound(2);
			haunting = false;
			_hasBeenSeen = false;
			_tooLonelyTime = Time.time + tooLonelyTimeDelay;
		}

		public void PlaySound(int clipID)
		{
			switch (clipID)
			{
			case 0:
				LinkVoice.PlayOneShot(LaughSmall, 1f);
				break;
			case 1:
				LinkVoice.PlayOneShot(LaughLong, 1f);
				break;
			case 2:
				LinkVoice.PlayOneShot(KillingSound, 1f);
				break;
			}
		}

		public PlayerControllerB[] GetLineOfSightOfAny(float width = 45f, int range = 60)
		{
			//IL_002e: 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_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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0079: 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_0081: 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_008a: 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)
			List<PlayerControllerB> list = new List<PlayerControllerB>(4);
			for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
			{
				PlayerControllerB val = StartOfRound.Instance.allPlayerScripts[i];
				if (val.isPlayerDead)
				{
					continue;
				}
				Vector3 position = ((Component)val.gameplayCamera).transform.position;
				Vector3 position2 = ((Component)this).transform.Find("HeadPos").position;
				Transform transform = ((Component)val.gameplayCamera).transform;
				if (Vector3.Distance(position2, position) < (float)range && !Physics.Linecast(position2, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					Vector3 val2 = position - position2;
					if (Vector3.Angle(-transform.forward, val2) < width)
					{
						list.Add(val);
					}
				}
			}
			return list.ToArray();
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		protected override void __initializeRpcs()
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			((NetworkBehaviour)this).__registerRpc(718832639u, new RpcReceiveHandler(__rpc_handler_718832639), "MoveStatueSpotServerRpc");
			((NetworkBehaviour)this).__registerRpc(2186059455u, new RpcReceiveHandler(__rpc_handler_2186059455), "MoveStatueSpotClientRpc");
			((NetworkBehaviour)this).__registerRpc(1540599700u, new RpcReceiveHandler(__rpc_handler_1540599700), "StartKillingPlayerServerRpc");
			((NetworkBehaviour)this).__registerRpc(3420559006u, new RpcReceiveHandler(__rpc_handler_3420559006), "StartKillingPlayerClientRpc");
			((NetworkBehaviour)this).__initializeRpcs();
		}

		private static void __rpc_handler_718832639(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 newSpot = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref newSpot);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((LinkStatueAI)(object)target).MoveStatueSpotServerRpc(newSpot);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_2186059455(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0036: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				Vector3 newSpot = default(Vector3);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref newSpot);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((LinkStatueAI)(object)target).MoveStatueSpotClientRpc(newSpot);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_1540599700(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int thePlayer = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref thePlayer);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((LinkStatueAI)(object)target).StartKillingPlayerServerRpc(thePlayer);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3420559006(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0023: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				int thePlayer = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref thePlayer);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((LinkStatueAI)(object)target).StartKillingPlayerClientRpc(thePlayer);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "LinkStatueAI";
		}
	}
}
namespace LethalCompanyTemplate
{
	[BepInPlugin("LinkStatue", "LinkStatue", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony harmony = new Harmony("LinkStatue");

		public static string AppRoot = Path.Combine(Paths.PluginPath, "MadCows-LinkStatue");

		public static AssetBundle appAssets = null;

		public static GameObject LinkPrefab;

		public static Plugin _instance;

		public static ConfigEntry<float> SpawnChances;

		public static ConfigEntry<bool> DebugMode;

		public static ConfigEntry<int> NumberOfTimesSeenToHaunt;

		public static ConfigEntry<float> RadiusOfCloseTeleport;

		public static ManualLogSource TTLogger { get; set; }

		public static void Dbg(string msg)
		{
			if (DebugMode != null && DebugMode.Value)
			{
				TTLogger.LogInfo((object)("[debug] " + msg));
			}
		}

		public void Awake()
		{
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			_instance = this;
			SpawnChances = ((BaseUnityPlugin)this).Config.Bind<float>("Ganeral", "SpawnChanges", 0.5f, "The percentage chance of the statue spawning in a given round. 0.0 - 1.0");
			DebugMode = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DebugMode", false, "Puts the mod into Debug mode. this mode helps find the statue and puts out more log info. Devs only foo.");
			RadiusOfCloseTeleport = ((BaseUnityPlugin)this).Config.Bind<float>("General", "RadiusOfCloseTeleport", 20f, "Radius of how close the teleporting will be when following someone.");
			NumberOfTimesSeenToHaunt = ((BaseUnityPlugin)this).Config.Bind<int>("General", "NumberOfTimesSeenToHaunt", 4, "The number of times the statue can be seen before He wants to haunt.");
			TTLogger = Logger.CreateLogSource("Link Statue Mod");
			LoadBundle();
			if ((Object)(object)appAssets == (Object)null)
			{
				return;
			}
			TTLogger.LogInfo((object)("Plugin LinkStatue is loaded! SpawnChance=" + SpawnChances.Value + " DebugMode=" + DebugMode.Value + " SeenToHaunt=" + NumberOfTimesSeenToHaunt.Value + " TeleportRadius=" + RadiusOfCloseTeleport.Value));
			LinkPrefab = appAssets.LoadAsset<GameObject>("LinkStatue");
			LinkPrefab.AddComponent<FallingObject>();
			LinkPrefab.AddComponent<LinkStatueAI>();
			LinkPrefab.AddComponent<AudioSource>();
			((Object)LinkPrefab).name = "LINK_THE_HERO";
			LinkPrefab.transform.localScale = new Vector3(2f, 2f, 2f);
			LinkPrefab.layer = LayerMask.NameToLayer("Enemies");
			harmony.PatchAll(typeof(RoundManagerPatch));
			harmony.PatchAll(typeof(GameNetworkManagerPatch));
			harmony.PatchAll(typeof(ShovelPatch));
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			foreach (Type type in types)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						try
						{
							methodInfo.Invoke(null, null);
						}
						catch (Exception ex)
						{
							TTLogger.LogError((object)("Netcode init failed for " + type.Name + "." + methodInfo.Name + ": " + ex));
						}
					}
				}
			}
		}

		private void LoadBundle()
		{
			string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "linkstatuemodbundle");
			if (!File.Exists(path))
			{
				path = Path.Combine(AppRoot, "linkstatuemodbundle");
			}
			if (!File.Exists(path))
			{
				TTLogger.LogError((object)("Could not find linkstatuemodbundle next to the DLL or in " + AppRoot));
				return;
			}
			AssetBundle val = AssetBundle.LoadFromMemory(File.ReadAllBytes(path));
			if ((Object)(object)val != (Object)null)
			{
				TTLogger.LogInfo((object)"YES THE BUNDLE WAS LOADED!");
				appAssets = val;
			}
			else
			{
				TTLogger.LogError((object)"Failed to load the custom prefab.");
			}
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager))]
	public class GameNetworkManagerPatch
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPatch()
		{
			NetworkManager.Singleton.AddNetworkPrefab(Plugin.LinkPrefab);
		}
	}
	[HarmonyPatch(typeof(RoundManager))]
	internal class RoundManagerPatch
	{
		[HarmonyPatch("GeneratedFloorPostProcessing")]
		[HarmonyPrefix]
		private static void GeneratedFloorPostProcessingPatch(RoundManager __instance)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: 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)
			if (((NetworkBehaviour)__instance).IsServer)
			{
				float value = Random.value;
				if (value > Plugin.SpawnChances.Value)
				{
					Plugin.Dbg("Statue not spawned this round (roll " + value + " > chance " + Plugin.SpawnChances.Value + ")");
				}
				else
				{
					Plugin.Dbg("Spawning statue (roll " + value + ")");
					__instance.mapPropsContainer = GameObject.FindGameObjectWithTag("MapPropsContainer");
					Vector3 position = GameObject.Find("LevelGenerationRoot").transform.position;
					GameObject obj = Object.Instantiate<GameObject>(Plugin.LinkPrefab, position, Quaternion.identity);
					((Object)obj).name = "LINK_THE_HERO";
					obj.GetComponent<NetworkObject>().Spawn(false);
				}
			}
		}

		[HarmonyPatch("UnloadSceneObjectsEarly")]
		[HarmonyPrefix]
		private static void UnloadSceneObjectsEarlyPatch(RoundManager __instance)
		{
			GameObject val = GameObject.Find("LINK_THE_HERO");
			if (((NetworkBehaviour)__instance).IsServer && (Object)(object)val != (Object)null)
			{
				val.GetComponent<NetworkObject>().Despawn(true);
			}
		}
	}
}
namespace __GEN
{
	internal class NetworkVariableSerializationHelper
	{
		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeSerialization()
		{
		}
	}
}
namespace LinkStatue.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}