Decompiled source of Funee v1.0.3

FuneePlugin.dll

Decompiled 9 months ago
using System;
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 System.Text;
using BepInEx;
using BepInEx.Logging;
using FuneePlugin.NetcodePatcher;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[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 = "")]
[assembly: AssemblyCompany("FuneePlugin")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Plugin that does the Funee")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FuneePlugin")]
[assembly: AssemblyTitle("FuneePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
namespace FuneePlugin
{
	[BepInPlugin("Kakerdoker.Funee", "Funee", "1.0.3")]
	public class Main : BaseUnityPlugin
	{
		private const string modGUID = "Kakerdoker.Funee";

		private readonly Harmony harmony = new Harmony("Kakerdoker.Funee");

		public static Main instance;

		private void Awake()
		{
			UnityNetcodePatch();
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			harmony.PatchAll(typeof(NetworkPatch));
			harmony.PatchAll(typeof(EnemyAIPatch));
			harmony.PatchAll(typeof(StartOfRoundPatch));
			harmony.PatchAll(typeof(JesterAIPatch));
			harmony.PatchAll(typeof(FlashlightItemPatch));
			harmony.PatchAll(typeof(HoarderBugAIPatch));
			harmony.PatchAll(typeof(CentipedeAIPatch));
			harmony.PatchAll(typeof(BaboonBirdAIPatch));
			MyLogger.Debug("Funee plugin is done patching.");
		}

		private static void UnityNetcodePatch()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			Type[] array = types;
			foreach (Type type in array)
			{
				MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				MethodInfo[] array2 = methods;
				foreach (MethodInfo methodInfo in array2)
				{
					object[] customAttributes = methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false);
					if (customAttributes.Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}
	}
	internal class MyLogger
	{
		public static ManualLogSource mls = Logger.CreateLogSource("Kakerdoker.Funi");

		public static void Debug(string message)
		{
			mls.LogInfo((object)message);
		}

		public static void Error(string message)
		{
			mls.LogError((object)message);
		}
	}
	internal static class NetworkPatch
	{
		public static GameObject networkPrefab;

		public static GameObject networker;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager), "Start")]
		public static void AddPrefabPatch()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			AssetBundle val = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "networkbundle"));
			networkPrefab = (GameObject)val.LoadAsset("FuneeNetworkHandler");
			networkPrefab.AddComponent<UnfortunatePlayerNetworkHandler>();
			NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound), "Awake")]
		private static void PatchAwake()
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)networkPrefab != (Object)null && (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer))
			{
				if ((Object)(object)networker != (Object)null)
				{
					Object.Destroy((Object)(object)networker);
				}
				networker = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
				networker.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	public class UnfortunatePlayerNetworkHandler : NetworkBehaviour
	{
		public static UnfortunatePlayerNetworkHandler Instance { get; private set; }

		public override void OnNetworkSpawn()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				UnfortunatePlayerNetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		[ClientRpc]
		public void ClearSteamIDListClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3533927864u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3533927864u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					UnfortunatePlayer.steamIds.Clear();
				}
			}
		}

		[ClientRpc]
		public void AddSteamIDToListClientRpc(ulong steamID)
		{
			//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)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3877653611u, val, (RpcDelivery)0);
					BytePacker.WriteValueBitPacked(val2, steamID);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3877653611u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					UnfortunatePlayer.steamIds.Add(steamID);
				}
			}
		}

		[ClientRpc]
		public void InitializeClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3068828466u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3068828466u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					UnfortunatePlayer.SetPlayersFromSteamIDs();
					UnfortunatePlayer.LogPlayers();
				}
			}
		}

		[ClientRpc]
		public void SetHostAsUnfortunatePlyerClientRpc()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_007c: 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 != 2 && (networkManager.IsServer || networkManager.IsHost))
				{
					ClientRpcParams val = default(ClientRpcParams);
					FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(3037262534u, val, (RpcDelivery)0);
					((NetworkBehaviour)this).__endSendClientRpc(ref val2, 3037262534u, val, (RpcDelivery)0);
				}
				if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && !NetworkManager.Singleton.IsHost && !NetworkManager.Singleton.IsServer)
				{
					UnfortunatePlayer.players = new List<PlayerControllerB> { StartOfRound.Instance.allPlayerScripts[0] };
					UnfortunatePlayer.LogPlayers();
				}
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_UnfortunatePlayerNetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(3533927864u, new RpcReceiveHandler(__rpc_handler_3533927864));
			NetworkManager.__rpc_func_table.Add(3877653611u, new RpcReceiveHandler(__rpc_handler_3877653611));
			NetworkManager.__rpc_func_table.Add(3068828466u, new RpcReceiveHandler(__rpc_handler_3068828466));
			NetworkManager.__rpc_func_table.Add(3037262534u, new RpcReceiveHandler(__rpc_handler_3037262534));
		}

		private static void __rpc_handler_3533927864(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((UnfortunatePlayerNetworkHandler)(object)target).ClearSteamIDListClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3877653611(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)
			{
				ulong steamID = default(ulong);
				ByteUnpacker.ReadValueBitPacked(reader, ref steamID);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((UnfortunatePlayerNetworkHandler)(object)target).AddSteamIDToListClientRpc(steamID);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3068828466(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((UnfortunatePlayerNetworkHandler)(object)target).InitializeClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_3037262534(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((UnfortunatePlayerNetworkHandler)(object)target).SetHostAsUnfortunatePlyerClientRpc();
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "UnfortunatePlayerNetworkHandler";
		}
	}
	[HarmonyPatch(typeof(BaboonBirdAI))]
	internal static class BaboonBirdAIPatch
	{
		private static bool isLockedOnUnfortunate;

		private static PlayerControllerB unfortunatePlayer;

		[HarmonyPostfix]
		[HarmonyPatch("DoAIInterval")]
		private static void DoAIIntervalPatch(ref BaboonBirdAI __instance, ref PlayerControllerB ___targetPlayer, ref int ___aggressiveMode, ref float ___fightTimer, ref float ___timeSinceFighting)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)unfortunatePlayer == (Object)null || !isLockedOnUnfortunate)
			{
				return;
			}
			if (unfortunatePlayer.isPlayerDead || unfortunatePlayer.isInsideFactory)
			{
				isLockedOnUnfortunate = false;
				unfortunatePlayer = null;
				return;
			}
			if (___aggressiveMode != 2)
			{
				___aggressiveMode = 2;
				__instance.SetAggressiveModeServerRpc(2);
			}
			___targetPlayer = unfortunatePlayer;
			___fightTimer = 15f;
			___timeSinceFighting = 15f;
			((EnemyAI)__instance).SetDestinationToPosition(((Component)unfortunatePlayer).transform.position, false);
		}

		[HarmonyPostfix]
		[HarmonyPatch("SetAggressiveModeServerRpc")]
		private static void SetAggressiveModeServerRpcPatch(ref BaboonBirdAI __instance, ref int mode)
		{
			if (mode != 2)
			{
				return;
			}
			Threat focusedThreat = __instance.focusedThreat;
			object obj;
			if (focusedThreat == null)
			{
				obj = null;
			}
			else
			{
				IVisibleThreat threatScript = focusedThreat.threatScript;
				obj = ((threatScript != null) ? threatScript.GetThreatTransform() : null);
			}
			Transform threatTransform = (Transform)obj;
			if (!((Object)(object)threatTransform == (Object)null))
			{
				PlayerControllerB val = UnfortunatePlayer.players.Find((PlayerControllerB p) => (Object)(object)((Component)p).transform == (Object)(object)threatTransform);
				if ((Object)(object)val != (Object)null)
				{
					unfortunatePlayer = val;
					isLockedOnUnfortunate = true;
				}
			}
		}
	}
	[HarmonyPatch(typeof(CentipedeAI))]
	internal static class CentipedeAIPatch
	{
		private static bool IsRayhitOnAnyUnfortunatePlayer(RaycastHit rayHit)
		{
			foreach (PlayerControllerB player in UnfortunatePlayer.players)
			{
				if ((Object)(object)((RaycastHit)(ref rayHit)).transform == (Object)(object)((Component)player).transform)
				{
					return true;
				}
			}
			return false;
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref CentipedeAI __instance, ref int ___currentBehaviourStateIndex, ref bool ___clingingToCeiling, ref bool ___clingingToPlayer, ref bool ___triggeredFall)
		{
			//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_0056: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			if (___clingingToCeiling && ___currentBehaviourStateIndex == 1)
			{
				Ray val = default(Ray);
				((Ray)(ref val))..ctor(((Component)__instance).transform.position, Vector3.down);
				RaycastHit rayHit = default(RaycastHit);
				if (Physics.SphereCast(val, 5f, ref rayHit, 60f, StartOfRound.Instance.playersMask) && !___clingingToPlayer && !Physics.Linecast(((RaycastHit)(ref rayHit)).transform.position, ((Component)__instance).transform.position, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1) && !___triggeredFall && IsRayhitOnAnyUnfortunatePlayer(rayHit))
				{
					___triggeredFall = true;
					__instance.TriggerCentipedeFallServerRpc(NetworkManager.Singleton.LocalClientId);
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch2(ref CentipedeAI __instance)
		{
			if (UnfortunatePlayer.players.Contains(((EnemyAI)__instance).targetPlayer))
			{
				((EnemyAI)__instance).agent.speed = 10f;
			}
		}
	}
	internal static class DebugPatches
	{
		private static float timeOfNextUpdate;

		private const float secondsForUpdate = 1f;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(BaboonBirdAI))]
		[HarmonyPatch("Update")]
		private static void BaboonUpdatePatch(ref BaboonBirdAI __instance, ref int ___aggressiveMode, ref float ___fightTimer, ref float ___fearLevel)
		{
			if (timeOfNextUpdate < Time.time)
			{
				timeOfNextUpdate = Time.time + 1f;
				MyLogger.Debug($"aggressiveMode: {___aggressiveMode} | currentBehaviourStateIndex: {((EnemyAI)__instance).currentBehaviourStateIndex} | focusedThreatIsInView: {__instance.focusedThreatIsInView} | fightTimer: {___fightTimer} | fearLevel: {___fearLevel}");
			}
		}
	}
	[HarmonyPatch(typeof(EnemyAI))]
	internal static class EnemyAIPatch
	{
		[HarmonyPatch("CheckLineOfSightForPlayer")]
		[HarmonyPostfix]
		private static void CheckLineOfSightForPlayerPatch(ref int range, ref Transform ___eye, ref PlayerControllerB __result)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (UnfortunatePlayer.players.Count == 0)
			{
				return;
			}
			range *= 10;
			foreach (PlayerControllerB player in UnfortunatePlayer.players)
			{
				if (!((Object)(object)player == (Object)null) && !player.isPlayerDead)
				{
					Vector3 position = ((Component)player.gameplayCamera).transform.position;
					if (Vector3.Distance(position, ___eye.position) < (float)range && !Physics.Linecast(___eye.position, position, StartOfRound.Instance.collidersAndRoomMaskAndDefault))
					{
						__result = player;
						break;
					}
				}
			}
		}

		[HarmonyPatch("TargetClosestPlayer")]
		[HarmonyPostfix]
		private static void TargetClosestPlayerPatch(ref float bufferDistance, ref float ___mostOptimalDistance, ref PlayerControllerB ___targetPlayer, ref EnemyAI __instance, ref bool __result)
		{
			//IL_003e: 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_0084: 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)
			foreach (PlayerControllerB player in UnfortunatePlayer.players)
			{
				if (!((Object)(object)player == (Object)null) && !player.isPlayerDead)
				{
					___mostOptimalDistance = Vector3.Distance(((Component)__instance).transform.position, ((Component)player).transform.position);
					if (__instance.PlayerIsTargetable(player, false, false) && (Object)(object)player != (Object)null && bufferDistance > 0f && (Object)(object)player != (Object)null && Mathf.Abs(___mostOptimalDistance - Vector3.Distance(((Component)__instance).transform.position, ((Component)player).transform.position)) < bufferDistance)
					{
						___targetPlayer = player;
						__result = (Object)(object)___targetPlayer != (Object)null;
						break;
					}
				}
			}
		}

		[HarmonyPatch("GetClosestPlayer")]
		[HarmonyPostfix]
		private static void GetClosestPlayerPatch(ref PlayerControllerB __result, ref EnemyAI __instance, ref float ___tempDist, ref float ___mostOptimalDistance, ref bool requireLineOfSight, ref bool cannotBeInShip, ref bool cannotBeNearShip)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: 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)
			if (UnfortunatePlayer.players.Count == 0)
			{
				return;
			}
			___mostOptimalDistance = Vector3.Distance(((Component)__instance).transform.position, ((Component)UnfortunatePlayer.players[0]).transform.position);
			foreach (PlayerControllerB player in UnfortunatePlayer.players)
			{
				if ((Object)(object)player == (Object)null || player.isPlayerDead || !__instance.PlayerIsTargetable(player, cannotBeInShip, false))
				{
					continue;
				}
				if (cannotBeNearShip)
				{
					if (player.isInElevator)
					{
						continue;
					}
					bool flag = false;
					for (int i = 0; i < RoundManager.Instance.spawnDenialPoints.Length; i++)
					{
						if (Vector3.Distance(RoundManager.Instance.spawnDenialPoints[i].transform.position, ((Component)player).transform.position) < 10f)
						{
							flag = true;
							break;
						}
					}
					if (flag)
					{
						continue;
					}
				}
				if (!requireLineOfSight || !Physics.Linecast(((Component)__instance).transform.position, ((Component)player).transform.position, 256))
				{
					___tempDist = Vector3.Distance(((Component)__instance).transform.position, ((Component)player).transform.position);
					if (___tempDist < ___mostOptimalDistance)
					{
						___mostOptimalDistance = ___tempDist;
						__result = player;
						break;
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(FlashlightItem))]
	internal static class FlashlightItemPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePatch(ref FlashlightItem __instance, ref Light ___flashlightBulb)
		{
			if (UnfortunatePlayer.players.Contains(((GrabbableObject)__instance).playerHeldBy))
			{
				Light obj = ___flashlightBulb;
				obj.intensity *= 0.7f;
			}
		}
	}
	[HarmonyPatch(typeof(FlowermanAI))]
	internal static class FlowermanAIPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("AddToAngerMeter")]
		private static void AddToAngerPatch(ref float amountToAdd, ref PlayerControllerB ___targetPlayer)
		{
			if (UnfortunatePlayer.players.Contains(___targetPlayer))
			{
				amountToAdd *= 30f;
			}
		}
	}
	[HarmonyPatch(typeof(HoarderBugAI))]
	internal static class HoarderBugAIPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("DetectAndLookAtPlayers")]
		private static void DetectAndLookAtPlayersPatch(ref PlayerControllerB ___watchingPlayer, ref PlayerControllerB ___angryAtPlayer, ref float ___angryTimer, ref EnemyAI __instance)
		{
			if (UnfortunatePlayer.players.Contains(___watchingPlayer))
			{
				__instance.SwitchToBehaviourState(2);
				___angryAtPlayer = ___watchingPlayer;
				if (___angryTimer < 1f)
				{
					___angryTimer = 1f;
				}
			}
		}
	}
	[HarmonyPatch(typeof(JesterAI))]
	internal static class JesterAIPatch
	{
		private static float initialBeginCrankingTimer;

		private static float initialPopUpTimer;

		[HarmonyPrefix]
		[HarmonyPatch("Update")]
		private static void UpdatePrePatch(ref float ___beginCrankingTimer, ref float ___popUpTimer)
		{
			initialBeginCrankingTimer = ___beginCrankingTimer;
			initialPopUpTimer = ___popUpTimer;
		}

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		private static void UpdatePostPatch(ref float ___beginCrankingTimer, ref float ___popUpTimer, ref PlayerControllerB ___targetPlayer)
		{
			if (UnfortunatePlayer.players.Contains(___targetPlayer))
			{
				float num = initialBeginCrankingTimer - ___beginCrankingTimer;
				float num2 = initialPopUpTimer - ___popUpTimer;
				___beginCrankingTimer -= num;
				___popUpTimer -= num2;
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	internal static class StartOfRoundPatch
	{
		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		private static void StartGamePatch()
		{
			UnfortunatePlayer.Synchronize();
		}
	}
	public static class UnfortunatePlayer
	{
		public static List<PlayerControllerB> players;

		public static List<ulong> steamIds = new List<ulong>();

		private const string steamIDPath = "players.txt";

		public static void Synchronize()
		{
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				if (StartOfRound.Instance.allPlayerScripts[0].playerSteamId == 0)
				{
					SynchronizeLAN();
				}
				else
				{
					SynchronizeNormal();
				}
			}
		}

		private static void SynchronizeLAN()
		{
			players = new List<PlayerControllerB> { StartOfRound.Instance.allPlayerScripts[0] };
			UnfortunatePlayerNetworkHandler.Instance.SetHostAsUnfortunatePlyerClientRpc();
			LogPlayers();
		}

		private static void SynchronizeNormal()
		{
			HostInit();
			ClientInit();
		}

		private static void ClientInit()
		{
			UnfortunatePlayerNetworkHandler.Instance.ClearSteamIDListClientRpc();
			foreach (PlayerControllerB player in players)
			{
				UnfortunatePlayerNetworkHandler.Instance.AddSteamIDToListClientRpc(player.playerSteamId);
			}
			UnfortunatePlayerNetworkHandler.Instance.InitializeClientRpc();
		}

		private static void HostInit()
		{
			CreateStandardFileIfDoesntExist("players.txt");
			steamIds = GetSteamIDsFromFile("players.txt");
			players = GetUnfortunatePlayers(steamIds);
			IfThereAreNoUnfortunatePlayersMakeOnePersonInLobbyUnfortunate();
			LogPlayers();
		}

		public static void SetPlayersFromSteamIDs()
		{
			players = GetUnfortunatePlayers(steamIds);
		}

		public static void LogPlayers()
		{
			foreach (PlayerControllerB player in players)
			{
				MyLogger.Debug(player.playerUsername);
			}
		}

		private static void IfThereAreNoUnfortunatePlayersMakeOnePersonInLobbyUnfortunate()
		{
			if (players.Count == 0)
			{
				PlayerControllerB randomPlayer = GetRandomPlayer();
				players = new List<PlayerControllerB> { randomPlayer };
				MakeStandardFile();
				AppendNewIDInFile(randomPlayer.playerSteamId);
			}
		}

		private static PlayerControllerB GetRandomPlayer()
		{
			int num = 0;
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (val.isPlayerControlled)
				{
					num++;
				}
			}
			Random random = new Random();
			int num2 = random.Next(0, num);
			PlayerControllerB[] allPlayerScripts2 = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val2 in allPlayerScripts2)
			{
				if (num2 == 0)
				{
					return val2;
				}
				if (val2.isPlayerControlled)
				{
					num2--;
				}
			}
			MyLogger.Error("Randomly chosen player index wasn't found inside StartOfRound.Instance.allPlayerScripts");
			return StartOfRound.Instance.allPlayerScripts[0];
		}

		private static List<PlayerControllerB> GetUnfortunatePlayers(List<ulong> steamIds)
		{
			List<PlayerControllerB> list = new List<PlayerControllerB>();
			GameObject[] allPlayerObjects = StartOfRound.Instance.allPlayerObjects;
			foreach (GameObject val in allPlayerObjects)
			{
				PlayerControllerB component = val.GetComponent<PlayerControllerB>();
				if (steamIds.Contains(component.playerSteamId))
				{
					list.Add(component);
				}
			}
			return list;
		}

		private static void MakeStandardFile()
		{
			using FileStream fileStream = File.Open("players.txt", FileMode.Create);
			byte[] bytes = new UTF8Encoding(encoderShouldEmitUTF8Identifier: true).GetBytes("76561198194556193\n76561198068333834\n");
			fileStream.Write(bytes, 0, bytes.Length);
		}

		private static void AppendNewIDInFile(ulong steamId)
		{
			using StreamWriter streamWriter = new StreamWriter("players.txt", append: true);
			streamWriter.WriteLine(steamId + "\n");
		}

		private static void CreateStandardFileIfDoesntExist(string path)
		{
			if (!File.Exists(path))
			{
				MakeStandardFile();
			}
		}

		private static List<ulong> GetSteamIDsFromFile(string path)
		{
			List<ulong> list = new List<ulong>();
			foreach (string item in File.ReadLines(path))
			{
				if (ulong.TryParse(item, out var result) && item.Length == 17)
				{
					list.Add(result);
				}
			}
			return list;
		}
	}
}
namespace FuneePlugin.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}