Decompiled source of Infected v1.4.0

Infected.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.UI;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace Infected;

internal static class Antidote
{
	private const int PropsLayer = 6;

	private const int ScanNodeLayer = 22;

	private const float InjectRange = 3f;

	private const int SampleRate = 44100;

	internal static Item ItemType;

	private static bool templateApplied;

	private static bool spawnedToday;

	private static AudioClip injectClip;

	internal static void Register()
	{
		//IL_0055: 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)
		GameObject val = NetworkPrefabs.CreateNetworkPrefab("InfectedAntidote");
		val.layer = 6;
		val.tag = "PhysicsProp";
		ItemType = ScriptableObject.CreateInstance<Item>();
		((Object)ItemType).name = "InfectedAntidote";
		ItemType.spawnPrefab = val;
		ApplyOwnSettings();
		BoxCollider val2 = val.AddComponent<BoxCollider>();
		((Collider)val2).isTrigger = true;
		val2.center = Vector3.zero;
		val2.size = new Vector3(0.12f, 0.36f, 0.12f);
		AudioSource val3 = val.AddComponent<AudioSource>();
		val3.playOnAwake = false;
		val3.spatialBlend = 1f;
		val3.rolloffMode = (AudioRolloffMode)1;
		val3.maxDistance = 15f;
		MeshRenderer mainObjectRenderer = AntidoteModel.Build(val.transform);
		AddScanNode(val.transform);
		AntidoteItem antidoteItem = val.AddComponent<AntidoteItem>();
		((GrabbableObject)antidoteItem).itemProperties = ItemType;
		((GrabbableObject)antidoteItem).grabbable = true;
		((GrabbableObject)antidoteItem).grabbableToEnemies = true;
		((GrabbableObject)antidoteItem).mainObjectRenderer = mainObjectRenderer;
		Items.RegisterItem(ItemType);
	}

	private static void AddScanNode(Transform parent)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_002f: 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)
		GameObject val = new GameObject("ScanNode");
		val.layer = 22;
		val.transform.SetParent(parent, false);
		BoxCollider val2 = val.AddComponent<BoxCollider>();
		((Collider)val2).isTrigger = true;
		val2.size = Vector3.one * 0.4f;
		ScanNodeProperties val3 = val.AddComponent<ScanNodeProperties>();
		val3.headerText = "Antidote";
		val3.subText = "Cures the infection";
		val3.nodeType = 0;
		val3.minRange = 1;
		val3.maxRange = 13;
		val3.requiresLineOfSight = true;
		val3.creatureScanID = -1;
	}

	internal static void ApplyTemplate()
	{
		if (templateApplied || (Object)(object)StartOfRound.Instance == (Object)null || (Object)(object)StartOfRound.Instance.allItemsList == (Object)null)
		{
			return;
		}
		Item val = null;
		string[] array = new string[2] { "TZP-Inhalant", "Flashlight" };
		foreach (string name in array)
		{
			List<Item> itemsList = StartOfRound.Instance.allItemsList.itemsList;
			Predicate<Item> match = (Item item) => (Object)(object)item != (Object)null && item.itemName == name;
			val = itemsList.Find(match);
			if ((Object)(object)val != (Object)null)
			{
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			val = StartOfRound.Instance.allItemsList.itemsList.Find((Item item) => (Object)(object)item != (Object)null && !item.isScrap && (Object)(object)item != (Object)(object)ItemType);
		}
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		templateApplied = true;
		FieldInfo[] fields = typeof(Item).GetFields(BindingFlags.Instance | BindingFlags.Public);
		foreach (FieldInfo fieldInfo in fields)
		{
			if (fieldInfo.Name != "itemId" && fieldInfo.Name != "spawnPrefab")
			{
				fieldInfo.SetValue(ItemType, fieldInfo.GetValue(val));
			}
		}
		ApplyOwnSettings();
	}

	private static void ApplyOwnSettings()
	{
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		ItemType.itemName = "Antidote";
		ItemType.isScrap = false;
		ItemType.creditsWorth = 0;
		ItemType.minValue = 0;
		ItemType.maxValue = 0;
		ItemType.weight = 1.02f;
		ItemType.toolTips = new string[1] { "Inject : [LMB]" };
		ItemType.twoHanded = false;
		ItemType.twoHandedAnimation = false;
		ItemType.holdButtonUse = false;
		ItemType.requiresBattery = false;
		ItemType.automaticallySetUsingPower = false;
		ItemType.syncUseFunction = false;
		ItemType.syncGrabFunction = false;
		ItemType.syncDiscardFunction = false;
		ItemType.syncInteractLRFunction = false;
		ItemType.saveItemVariable = false;
		ItemType.isDefensiveWeapon = false;
		ItemType.isConductiveMetal = false;
		ItemType.canBeGrabbedBeforeGameStart = true;
		ItemType.itemSpawnsOnGround = false;
		ItemType.useAnim = "";
		ItemType.meshVariants = (Mesh[])(object)new Mesh[0];
		ItemType.materialVariants = (Material[])(object)new Material[0];
		ItemType.spawnPositionTypes = new List<ItemGroup>();
		ItemType.restingRotation = new Vector3(0f, 0f, 90f);
		ItemType.verticalOffset = 0.05f;
	}

	internal static void Tick()
	{
		//IL_00c3: 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)
		if (!Net.IsHost || spawnedToday)
		{
			return;
		}
		StartOfRound instance = StartOfRound.Instance;
		TimeOfDay instance2 = TimeOfDay.Instance;
		if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance2 == (Object)null) && !instance.inShipPhase && instance.shipHasLanded && !instance.shipIsLeaving && !((Object)(object)instance.currentLevel == (Object)null) && instance.currentLevel.spawnEnemiesAndScrap && instance2.numberOfHours > 0)
		{
			float num = (Plugin.AntidoteSpawnHour.Value - 6f) / (float)instance2.numberOfHours;
			if (!(instance2.normalizedTimeOfDay < num) && FindSpawnPoint(out var position))
			{
				spawnedToday = true;
				Transform val = (((Object)(object)RoundManager.Instance != (Object)null) ? RoundManager.Instance.spawnedScrapContainer : null);
				GameObject val2 = Object.Instantiate<GameObject>(ItemType.spawnPrefab, position, Quaternion.Euler(ItemType.restingRotation), val);
				AntidoteItem component = val2.GetComponent<AntidoteItem>();
				((GrabbableObject)component).fallTime = 0f;
				((GrabbableObject)component).isInFactory = true;
				val2.GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}

	private static bool FindSpawnPoint(out Vector3 position)
	{
		//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_0030: 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_00c4: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		List<Vector3> list = new List<Vector3>();
		RandomScrapSpawn[] array = Object.FindObjectsOfType<RandomScrapSpawn>();
		foreach (RandomScrapSpawn val in array)
		{
			if (!val.spawnUsed)
			{
				list.Add(((Component)val).transform.position);
			}
		}
		if (list.Count == 0 && (Object)(object)RoundManager.Instance != (Object)null && RoundManager.Instance.insideAINodes != null)
		{
			GameObject[] insideAINodes = RoundManager.Instance.insideAINodes;
			foreach (GameObject val2 in insideAINodes)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					list.Add(val2.transform.position);
				}
			}
		}
		if (list.Count == 0)
		{
			return false;
		}
		position = list[Random.Range(0, list.Count)] + Vector3.up * 0.3f;
		return true;
	}

	internal static void OnRoundEnded()
	{
		spawnedToday = false;
	}

	internal static void OnSpawned(AntidoteItem item)
	{
		StartOfRound instance = StartOfRound.Instance;
		if (Plugin.AnnounceAntidote.Value && !((Object)(object)instance == (Object)null) && !instance.inShipPhase && instance.shipHasLanded && !((GrabbableObject)item).isInShipRoom && !((GrabbableObject)item).isInElevator && !((Object)(object)HUDManager.Instance == (Object)null))
		{
			HUDManager.Instance.DisplayTip("Antidote delivered", "The Company has left one antidote somewhere in the facility.", false, false, "LC_Tip1");
		}
	}

	internal static PlayerControllerB TargetFor(PlayerControllerB holder)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)holder.gameplayCamera).transform;
		RaycastHit[] array = Physics.RaycastAll(transform.position, transform.forward, 3f, StartOfRound.Instance.playersMask, (QueryTriggerInteraction)2);
		PlayerControllerB val = null;
		float num = float.MaxValue;
		RaycastHit[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			RaycastHit val2 = array2[i];
			PlayerControllerB componentInParent = ((Component)((RaycastHit)(ref val2)).collider).GetComponentInParent<PlayerControllerB>();
			if ((Object)(object)componentInParent != (Object)null && (Object)(object)componentInParent != (Object)(object)holder && componentInParent.isPlayerControlled && !componentInParent.isPlayerDead && ((RaycastHit)(ref val2)).distance < num)
			{
				val = componentInParent;
				num = ((RaycastHit)(ref val2)).distance;
			}
		}
		if (!((Object)(object)val != (Object)null))
		{
			return holder;
		}
		return val;
	}

	internal static void PlayInject(PlayerControllerB holder)
	{
		if ((Object)(object)injectClip == (Object)null)
		{
			injectClip = MakeHiss();
		}
		if ((Object)(object)holder.movementAudio != (Object)null)
		{
			holder.movementAudio.PlayOneShot(injectClip, 0.8f);
		}
	}

	private static AudioClip MakeHiss()
	{
		int num = 15434;
		float[] array = new float[num];
		Random random = new Random(7);
		float num2 = 0f;
		for (int i = 0; i < num; i++)
		{
			float num3 = (float)i / (float)num;
			float num4 = Mathf.Min(1f, num3 * 20f) * Mathf.Pow(1f - num3, 2f);
			float num5 = (float)(random.NextDouble() * 2.0 - 1.0);
			num2 = Mathf.Lerp(num2, num5, 0.6f);
			array[i] = num2 * num4 * 0.5f;
		}
		AudioClip val = AudioClip.Create("AntidoteHiss", num, 1, 44100, false);
		val.SetData(array, 0);
		return val;
	}
}
internal class AntidoteItem : GrabbableObject
{
	public override void Start()
	{
		((GrabbableObject)this).Start();
		Antidote.OnSpawned(this);
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		PlayerControllerB playerHeldBy = base.playerHeldBy;
		if (buttonDown && !((Object)(object)playerHeldBy == (Object)null) && ((NetworkBehaviour)this).IsOwner && !((Object)(object)playerHeldBy != (Object)(object)Infection.LocalPlayer))
		{
			PlayerControllerB val = Antidote.TargetFor(playerHeldBy);
			Antidote.PlayInject(playerHeldBy);
			if ((Object)(object)val != (Object)(object)playerHeldBy && (Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.DisplayTip("Antidote used", "You injected " + val.playerUsername + ".", false, false, "LC_Tip1");
			}
			Infection.RequestAntidote(val);
			playerHeldBy.DespawnHeldObject();
		}
	}
}
internal static class AntidoteModel
{
	private const int PropsLayer = 6;

	internal static MeshRenderer Build(Transform parent)
	{
		//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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_00b6: 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_00ed: 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_0123: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		//IL_018f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_020f: Unknown result type (might be due to invalid IL or missing references)
		Material mat = Mat(new Color(0.85f, 0.9f, 0.9f), Color.black, 0.9f);
		Material mat2 = Mat(new Color(0.35f, 1f, 0.3f), new Color(0.6f, 2.2f, 0.4f), 0.6f);
		Material mat3 = Mat(new Color(0.7f, 0.72f, 0.75f), Color.black, 0.8f);
		Material mat4 = Mat(new Color(0.12f, 0.12f, 0.12f), Color.black, 0.2f);
		MeshRenderer result = Part(parent, "Barrel", (PrimitiveType)2, mat, new Vector3(0f, 0f, 0f), new Vector3(0.05f, 0.1f, 0.05f));
		Part(parent, "Serum", (PrimitiveType)2, mat2, new Vector3(0f, -0.015f, 0f), new Vector3(0.042f, 0.08f, 0.042f));
		Part(parent, "Flange", (PrimitiveType)2, mat3, new Vector3(0f, 0.1f, 0f), new Vector3(0.1f, 0.005f, 0.03f));
		Part(parent, "Plunger", (PrimitiveType)2, mat3, new Vector3(0f, 0.13f, 0f), new Vector3(0.012f, 0.04f, 0.012f));
		Part(parent, "Thumb", (PrimitiveType)2, mat4, new Vector3(0f, 0.17f, 0f), new Vector3(0.045f, 0.006f, 0.045f));
		Part(parent, "Hub", (PrimitiveType)2, mat3, new Vector3(0f, -0.11f, 0f), new Vector3(0.022f, 0.012f, 0.022f));
		Part(parent, "Needle", (PrimitiveType)2, mat3, new Vector3(0f, -0.16f, 0f), new Vector3(0.004f, 0.04f, 0.004f));
		return result;
	}

	private static Material Mat(Color color, Color emission, float smoothness)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Expected O, but got Unknown
		//IL_0041: 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_0073: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find("HDRP/Lit");
		Material val2;
		if ((Object)(object)val != (Object)null)
		{
			val2 = new Material(val);
		}
		else
		{
			GameObject val3 = GameObject.CreatePrimitive((PrimitiveType)3);
			val2 = new Material(val3.GetComponent<Renderer>().sharedMaterial);
			Object.Destroy((Object)(object)val3);
		}
		val2.SetColor("_BaseColor", color);
		val2.SetColor("_Color", color);
		val2.SetFloat("_Smoothness", smoothness);
		if (((Color)(ref emission)).maxColorComponent > 0f)
		{
			val2.SetColor("_EmissiveColor", emission);
			val2.SetFloat("_EmissiveExposureWeight", 0f);
			val2.EnableKeyword("_EMISSION");
		}
		return val2;
	}

	private static MeshRenderer Part(Transform parent, string name, PrimitiveType type, Material mat, Vector3 localPosition, Vector3 localScale)
	{
		//IL_0000: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive(type);
		Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
		((Object)val).name = name;
		val.layer = 6;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		val.transform.localScale = localScale;
		MeshRenderer component = val.GetComponent<MeshRenderer>();
		((Renderer)component).sharedMaterial = mat;
		return component;
	}
}
internal static class Infection
{
	private const string BittenMessage = "Infected.Bitten";

	private const string StateMessage = "Infected.State";

	private const string PurgeMessage = "Infected.Purge";

	private const string AntidoteUseMessage = "Infected.AntidoteUse";

	private const string AntidoteResultMessage = "Infected.AntidoteResult";

	private const int CompanyLevelId = 3;

	internal static bool LocalInfected;

	private static readonly HashSet<ulong> infected = new HashSet<ulong>();

	private static bool spreadDoneThisTrip;

	private static bool purgeSentThisLanding;

	internal static PlayerControllerB LocalPlayer
	{
		get
		{
			if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
			{
				return null;
			}
			return GameNetworkManager.Instance.localPlayerController;
		}
	}

	private static bool IsHost => Net.IsHost;

	internal static void RegisterMessages()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		Net.Handle("Infected.Bitten", new HandleNamedMessageDelegate(OnBittenReceived));
		Net.Handle("Infected.State", new HandleNamedMessageDelegate(OnStateReceived));
		Net.Handle("Infected.Purge", new HandleNamedMessageDelegate(OnPurgeReceived));
		Net.Handle("Infected.AntidoteUse", new HandleNamedMessageDelegate(OnAntidoteUseReceived));
		Net.Handle("Infected.AntidoteResult", new HandleNamedMessageDelegate(OnAntidoteResultReceived));
	}

	internal static void Reset()
	{
		LocalInfected = false;
		infected.Clear();
		spreadDoneThisTrip = false;
		purgeSentThisLanding = false;
	}

	internal static void OnLocalBitten()
	{
		PlayerControllerB localPlayer = LocalPlayer;
		if ((Object)(object)localPlayer == (Object)null || localPlayer.isPlayerDead)
		{
			return;
		}
		SetLocal(value: true, fromBite: true);
		if (Net.IsConnected)
		{
			if (Net.IsHost)
			{
				infected.Add(localPlayer.actualClientId);
				return;
			}
			Net.Send("Infected.Bitten", 0uL, new byte[1] { 1 });
		}
	}

	private static void OnBittenReceived(ulong senderClientId, FastBufferReader reader)
	{
		if (IsHost)
		{
			PlayerControllerB val = FindPlayer(senderClientId);
			if ((Object)(object)val != (Object)null && !val.isPlayerDead)
			{
				infected.Add(senderClientId);
			}
		}
	}

	private static void OnStateReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (Net.FromHost(senderClientId))
		{
			byte[] array = Net.ReadAll(reader);
			if (array != null)
			{
				SetLocal(array[0] != 0, fromBite: false);
			}
		}
	}

	private static void OnPurgeReceived(ulong senderClientId, FastBufferReader reader)
	{
		if (Net.FromHost(senderClientId))
		{
			Symptoms.BeginPurge();
		}
	}

	internal static void RequestAntidote(PlayerControllerB target)
	{
		PlayerControllerB localPlayer = LocalPlayer;
		if (!((Object)(object)localPlayer == (Object)null) && Net.IsConnected)
		{
			if (Net.IsHost)
			{
				HostApplyAntidote(localPlayer.actualClientId, target.actualClientId);
			}
			else
			{
				Net.Send("Infected.AntidoteUse", 0uL, BitConverter.GetBytes(target.actualClientId));
			}
		}
	}

	private static void OnAntidoteUseReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		if (IsHost)
		{
			byte[] array = Net.ReadAll(reader);
			if (array != null && array.Length >= 8)
			{
				HostApplyAntidote(senderClientId, BitConverter.ToUInt64(array, 0));
			}
		}
	}

	private static void HostApplyAntidote(ulong injectorClientId, ulong targetClientId)
	{
		bool flag = infected.Remove(targetClientId);
		byte[] array = new byte[2]
		{
			(byte)(flag ? 1u : 0u),
			(byte)((injectorClientId != targetClientId) ? 1u : 0u)
		};
		if (targetClientId == NetworkManager.Singleton.LocalClientId)
		{
			ApplyAntidoteResult(array);
		}
		else
		{
			Net.Send("Infected.AntidoteResult", targetClientId, array);
		}
	}

	private static void OnAntidoteResultReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		if (Net.FromHost(senderClientId))
		{
			byte[] array = Net.ReadAll(reader);
			if (array != null && array.Length >= 2)
			{
				ApplyAntidoteResult(array);
			}
		}
	}

	private static void ApplyAntidoteResult(byte[] result)
	{
		bool flag = result[0] != 0;
		if (flag)
		{
			SetLocal(value: false, fromBite: false);
		}
		Symptoms.OnAntidote(flag, result[1] != 0);
	}

	private static void SetLocal(bool value, bool fromBite)
	{
		if (LocalInfected != value)
		{
			LocalInfected = value;
			Symptoms.OnInfectionChanged(value, fromBite);
		}
	}

	private static void HostInfect(ulong clientId)
	{
		infected.Add(clientId);
		if (clientId == NetworkManager.Singleton.LocalClientId)
		{
			SetLocal(value: true, fromBite: false);
			return;
		}
		Net.Send("Infected.State", clientId, new byte[1] { 1 });
	}

	internal static void Tick(PlayerControllerB local)
	{
		if (LocalInfected && local.isPlayerDead)
		{
			SetLocal(value: false, fromBite: false);
		}
		if (!IsHost || (Object)(object)StartOfRound.Instance == (Object)null)
		{
			return;
		}
		if (infected.Count > 0)
		{
			infected.RemoveWhere(delegate(ulong id)
			{
				PlayerControllerB val = FindPlayer(id);
				return (Object)(object)val == (Object)null || val.isPlayerDead;
			});
		}
		HostCheckCompanyPurge();
	}

	internal static void OnShipLanded()
	{
		spreadDoneThisTrip = false;
	}

	internal static void HostOnShipLeft()
	{
		if (!IsHost || spreadDoneThisTrip || !Plugin.SpreadOnTakeoff.Value)
		{
			return;
		}
		spreadDoneThisTrip = true;
		bool flag = false;
		List<PlayerControllerB> list = new List<PlayerControllerB>();
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (!((Object)(object)val == (Object)null) && val.isPlayerControlled && !val.isPlayerDead && (val.isInHangarShipRoom || val.isInElevator))
			{
				if (infected.Contains(val.actualClientId))
				{
					flag = true;
				}
				else
				{
					list.Add(val);
				}
			}
		}
		if (flag && list.Count != 0)
		{
			HostInfect(list[Random.Range(0, list.Count)].actualClientId);
		}
	}

	private static void HostCheckCompanyPurge()
	{
		StartOfRound instance = StartOfRound.Instance;
		if (!instance.shipHasLanded || instance.inShipPhase)
		{
			purgeSentThisLanding = false;
		}
		else if (!purgeSentThisLanding && Plugin.CompanyPurge.Value && AtCompany(instance.currentLevel) && infected.Count != 0)
		{
			purgeSentThisLanding = true;
			Net.SendToClients("Infected.Purge", new byte[1] { 1 });
			Symptoms.BeginPurge();
		}
	}

	private static bool AtCompany(SelectableLevel level)
	{
		if ((Object)(object)level != (Object)null)
		{
			if (level.levelID != 3)
			{
				return level.sceneName == "CompanyBuilding";
			}
			return true;
		}
		return false;
	}

	private static PlayerControllerB FindPlayer(ulong clientId)
	{
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if ((Object)(object)val != (Object)null && val.isPlayerControlled && val.actualClientId == clientId)
			{
				return val;
			}
		}
		return null;
	}
}
internal static class Net
{
	private static readonly Dictionary<string, HandleNamedMessageDelegate> handlers = new Dictionary<string, HandleNamedMessageDelegate>();

	private static CustomMessagingManager registeredWith;

	internal static bool IsHost
	{
		get
		{
			if ((Object)(object)NetworkManager.Singleton != (Object)null)
			{
				return NetworkManager.Singleton.IsServer;
			}
			return false;
		}
	}

	internal static bool IsConnected
	{
		get
		{
			if ((Object)(object)NetworkManager.Singleton != (Object)null)
			{
				return NetworkManager.Singleton.IsListening;
			}
			return false;
		}
	}

	internal static void Handle(string message, HandleNamedMessageDelegate handler)
	{
		handlers[message] = handler;
	}

	internal static void OnLobbyStarted()
	{
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null || singleton.CustomMessagingManager == registeredWith)
		{
			return;
		}
		registeredWith = singleton.CustomMessagingManager;
		foreach (KeyValuePair<string, HandleNamedMessageDelegate> handler in handlers)
		{
			registeredWith.RegisterNamedMessageHandler(handler.Key, handler.Value);
		}
	}

	internal static void OnLobbyEnded()
	{
		if (registeredWith == null)
		{
			return;
		}
		try
		{
			foreach (string key in handlers.Keys)
			{
				registeredWith.UnregisterNamedMessageHandler(key);
			}
		}
		catch (Exception)
		{
		}
		registeredWith = null;
	}

	internal static bool FromHost(ulong senderClientId)
	{
		return senderClientId == 0;
	}

	internal static void Send(string message, ulong clientId, byte[] payload, NetworkDelivery delivery)
	{
		//IL_0024: 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)
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(payload.Length, (Allocator)2, -1);
		try
		{
			((FastBufferWriter)(ref val)).WriteBytesSafe(payload, payload.Length, 0);
			NetworkManager.Singleton.CustomMessagingManager.SendNamedMessage(message, clientId, val, delivery);
		}
		finally
		{
			((FastBufferWriter)(ref val)).Dispose();
		}
	}

	internal static void Send(string message, ulong clientId, byte[] payload)
	{
		Send(message, clientId, payload, (NetworkDelivery)3);
	}

	internal static void SendToClients(string message, byte[] payload, NetworkDelivery delivery)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
		{
			return;
		}
		foreach (ulong connectedClientsId in singleton.ConnectedClientsIds)
		{
			if (connectedClientsId != singleton.LocalClientId)
			{
				Send(message, connectedClientsId, payload, delivery);
			}
		}
	}

	internal static void SendToClients(string message, byte[] payload)
	{
		SendToClients(message, payload, (NetworkDelivery)3);
	}

	internal static byte[] ReadAll(FastBufferReader reader)
	{
		int num = ((FastBufferReader)(ref reader)).Length - ((FastBufferReader)(ref reader)).Position;
		if (num <= 0)
		{
			return null;
		}
		byte[] result = new byte[num];
		((FastBufferReader)(ref reader)).ReadBytesSafe(ref result, num, 0);
		return result;
	}
}
[HarmonyPatch(typeof(StartOfRound))]
internal static class StartOfRoundPatches
{
	[HarmonyPatch("Start")]
	[HarmonyPostfix]
	private static void LobbyStarted()
	{
		Symptoms.Reset();
		Infection.Reset();
		Antidote.OnRoundEnded();
		Antidote.ApplyTemplate();
		Net.OnLobbyStarted();
	}

	[HarmonyPatch("OnDestroy")]
	[HarmonyPrefix]
	private static void LobbyEnded()
	{
		Rats.OnRoundEnded();
		Symptoms.Reset();
		Infection.Reset();
		Net.OnLobbyEnded();
	}

	[HarmonyPostfix]
	[HarmonyPatch("OnShipLandedMiscEvents")]
	private static void ShipLanded()
	{
		Infection.OnShipLanded();
	}

	[HarmonyPatch("ShipLeave")]
	[HarmonyPostfix]
	private static void ShipLeaving()
	{
		Rats.OnRoundEnded();
		Antidote.OnRoundEnded();
	}

	[HarmonyPrefix]
	[HarmonyPatch("ShipHasLeft")]
	private static void ShipHasLeft()
	{
		Infection.HostOnShipLeft();
	}
}
[HarmonyPatch(typeof(PlayerControllerB), "Update")]
internal static class PlayerUpdatePatch
{
	private static void Postfix(PlayerControllerB __instance)
	{
		if (((NetworkBehaviour)__instance).IsOwner && !((Object)(object)__instance != (Object)(object)Infection.LocalPlayer))
		{
			Infection.Tick(__instance);
			Symptoms.Tick(__instance);
			Rats.Tick();
			Antidote.Tick();
		}
	}
}
[BepInPlugin("axelc.infected", "Infected", "1.4.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "axelc.infected";

	public const string PluginName = "Infected";

	public const string Version = "1.4.0";

	internal static ManualLogSource Log;

	internal static ConfigEntry<int> RatsPerDay;

	internal static ConfigEntry<int> MaxRatsAtOnce;

	internal static ConfigEntry<float> RatIntervalMin;

	internal static ConfigEntry<float> RatIntervalMax;

	internal static ConfigEntry<float> RatDetectionRange;

	internal static ConfigEntry<int> MaxBitesPerDay;

	internal static ConfigEntry<float> InfectionChance;

	internal static ConfigEntry<int> BiteDamage;

	internal static ConfigEntry<float> TripIntervalMin;

	internal static ConfigEntry<float> TripIntervalMax;

	internal static ConfigEntry<float> TripDuration;

	internal static ConfigEntry<bool> DropItemOnTrip;

	internal static ConfigEntry<bool> SpreadOnTakeoff;

	internal static ConfigEntry<bool> CompanyPurge;

	internal static ConfigEntry<float> AntidoteSpawnHour;

	internal static ConfigEntry<bool> AnnounceAntidote;

	private void Awake()
	{
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		RatsPerDay = ((BaseUnityPlugin)this).Config.Bind<int>("Rats", "RatsPerDay", 4, "How many rats come for each player per day while they're inside the facility. The host runs the rats, so only the host's Rats settings matter (except BiteDamage, which is the bitten player's).");
		MaxRatsAtOnce = ((BaseUnityPlugin)this).Config.Bind<int>("Rats", "MaxAtOnce", 1, "Most rats that can be sent after one player at the same time.");
		RatIntervalMin = ((BaseUnityPlugin)this).Config.Bind<float>("Rats", "MinSecondsBetween", 40f, "Shortest wait between rats while a player is inside.");
		RatIntervalMax = ((BaseUnityPlugin)this).Config.Bind<float>("Rats", "MaxSecondsBetween", 110f, "Longest wait between rats while a player is inside.");
		RatDetectionRange = ((BaseUnityPlugin)this).Config.Bind<float>("Rats", "DetectionRange", 10f, "How close a rat has to be, with line of sight, before it starts chasing you.");
		MaxBitesPerDay = ((BaseUnityPlugin)this).Config.Bind<int>("Rats", "MaxBitesPerDay", 1, "How many bites the rats get per day across the whole crew. Once they're used up, the rats scatter and no more come until the next landing.");
		InfectionChance = ((BaseUnityPlugin)this).Config.Bind<float>("Rats", "InfectionChance", 0.4f, "Chance (0 to 1) that a bite infects. 0.4 = 40%. A bite always does damage either way.");
		BiteDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Rats", "BiteDamage", 2, "Damage a rat bite deals (players have 100 health).");
		TripIntervalMin = ((BaseUnityPlugin)this).Config.Bind<float>("Infection", "MinSecondsBetweenTrips", 30f, "Shortest wait between trips for an infected player.");
		TripIntervalMax = ((BaseUnityPlugin)this).Config.Bind<float>("Infection", "MaxSecondsBetweenTrips", 90f, "Longest wait between trips for an infected player.");
		TripDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Infection", "TripSeconds", 1.5f, "How long a trip leaves the infected player on their knees, unable to move.");
		DropItemOnTrip = ((BaseUnityPlugin)this).Config.Bind<bool>("Infection", "DropItemOnTrip", false, "Infected players drop whatever they're holding when they trip.");
		SpreadOnTakeoff = ((BaseUnityPlugin)this).Config.Bind<bool>("Infection", "SpreadOnTakeoff", true, "When the ship takes off with an infected player aboard, one random uninfected player aboard catches it. Only the host's setting matters.");
		CompanyPurge = ((BaseUnityPlugin)this).Config.Bind<bool>("Infection", "CompanyPurge", true, "If anyone alive is infected when the ship lands at the Company, the Company kills the whole crew. Only the host's setting matters.");
		AntidoteSpawnHour = ((BaseUnityPlugin)this).Config.Bind<float>("Antidote", "SpawnHour", 17f, "In-game hour (24-hour clock) after which the day's one antidote appears in the facility. 17 = 5 PM. Only the host's setting matters.");
		AnnounceAntidote = ((BaseUnityPlugin)this).Config.Bind<bool>("Antidote", "Announce", true, "Tell everyone when the antidote has been dropped in the facility (not where).");
		Infection.RegisterMessages();
		Rats.RegisterMessages();
		Antidote.Register();
		new Harmony("axelc.infected").PatchAll();
		Log.LogInfo((object)"Infected 1.4.0 loaded.");
	}
}
internal static class Rats
{
	private class SpawnTimer
	{
		internal float next = -1f;

		internal int spawned;
	}

	private const string SpawnMessage = "Infected.RatSpawn";

	private const string MoveMessage = "Infected.RatMove";

	private const string DespawnMessage = "Infected.RatDespawn";

	private const string BiteMessage = "Infected.RatBite";

	private const float BroadcastInterval = 0.1f;

	private static readonly Dictionary<int, Rat> rats = new Dictionary<int, Rat>();

	private static readonly Dictionary<ulong, SpawnTimer> timers = new Dictionary<ulong, SpawnTimer>();

	private static int nextId = 1;

	private static float nextBroadcast;

	private static int bitesToday;

	internal static bool BitesUsedUp => bitesToday >= Plugin.MaxBitesPerDay.Value;

	internal static void RegisterMessages()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Expected O, but got Unknown
		Net.Handle("Infected.RatSpawn", new HandleNamedMessageDelegate(OnSpawnReceived));
		Net.Handle("Infected.RatMove", new HandleNamedMessageDelegate(OnMoveReceived));
		Net.Handle("Infected.RatDespawn", new HandleNamedMessageDelegate(OnDespawnReceived));
		Net.Handle("Infected.RatBite", new HandleNamedMessageDelegate(OnBiteReceived));
	}

	internal static void Tick()
	{
		if (Net.IsHost)
		{
			HostSpawnTick();
			HostBroadcast();
		}
	}

	private static void HostSpawnTick()
	{
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		StartOfRound instance = StartOfRound.Instance;
		bool flag = (Object)(object)instance != (Object)null && !instance.inShipPhase && instance.shipHasLanded && !instance.shipIsLeaving;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		PlayerControllerB[] allPlayerScripts = instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if ((Object)(object)val == (Object)null || !val.isPlayerControlled)
			{
				continue;
			}
			if (!timers.TryGetValue(val.actualClientId, out var value))
			{
				value = new SpawnTimer();
				timers[val.actualClientId] = value;
			}
			if (!flag || !val.isInsideFactory || val.isPlayerDead || BitesUsedUp)
			{
				value.next = -1f;
			}
			else
			{
				if (value.spawned >= Plugin.RatsPerDay.Value)
				{
					continue;
				}
				if (value.next < 0f)
				{
					value.next = Time.time + NextInterval();
				}
				else if (!(Time.time < value.next) && CountSentAfter(val) < Plugin.MaxRatsAtOnce.Value)
				{
					if (FindHiddenSpawn(val, out var position))
					{
						HostSpawn(position, val);
						value.spawned++;
						value.next = Time.time + NextInterval();
					}
					else
					{
						value.next = Time.time + 5f;
					}
				}
			}
		}
	}

	private static float NextInterval()
	{
		float num = Mathf.Max(5f, Plugin.RatIntervalMin.Value);
		return Random.Range(num, Mathf.Max(num, Plugin.RatIntervalMax.Value));
	}

	private static int CountSentAfter(PlayerControllerB player)
	{
		int num = 0;
		foreach (Rat value in rats.Values)
		{
			if ((Object)(object)value != (Object)null && (Object)(object)value.Home == (Object)(object)player)
			{
				num++;
			}
		}
		return num;
	}

	private static void HostSpawn(Vector3 position, PlayerControllerB home)
	{
		//IL_000e: 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_0055: Unknown result type (might be due to invalid IL or missing references)
		int num = nextId++;
		Rat rat = RatModel.Build(position);
		rat.BeginHost(num, home);
		rats[num] = rat;
		MemoryStream memoryStream = new MemoryStream();
		BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
		binaryWriter.Write(num);
		WriteVector(binaryWriter, ((Component)rat).transform.position);
		binaryWriter.Write(((Component)rat).transform.eulerAngles.y);
		Net.SendToClients("Infected.RatSpawn", memoryStream.ToArray());
	}

	private static void HostBroadcast()
	{
		//IL_00bb: 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)
		if (Time.time < nextBroadcast || rats.Count == 0)
		{
			return;
		}
		nextBroadcast = Time.time + 0.1f;
		MemoryStream memoryStream = new MemoryStream();
		BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
		int num = 0;
		foreach (Rat value in rats.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				num++;
			}
		}
		binaryWriter.Write(num);
		foreach (Rat value2 in rats.Values)
		{
			if (!((Object)(object)value2 == (Object)null))
			{
				binaryWriter.Write(value2.Id);
				WriteVector(binaryWriter, ((Component)value2).transform.position);
				binaryWriter.Write(((Component)value2).transform.eulerAngles.y);
				binaryWriter.Write(value2.IsChasing);
			}
		}
		Net.SendToClients("Infected.RatMove", memoryStream.ToArray(), (NetworkDelivery)1);
	}

	internal static void HostDespawn(Rat rat)
	{
		rats.Remove(rat.Id);
		Object.Destroy((Object)(object)((Component)rat).gameObject);
		Net.SendToClients("Infected.RatDespawn", BitConverter.GetBytes(rat.Id));
	}

	internal static void HostBite(Rat rat, PlayerControllerB victim)
	{
		bitesToday++;
		if (BitesUsedUp)
		{
			foreach (Rat value in rats.Values)
			{
				if ((Object)(object)value != (Object)null && (Object)(object)value != (Object)(object)rat)
				{
					value.RunOff();
				}
			}
		}
		bool flag = Random.value < Mathf.Clamp01(Plugin.InfectionChance.Value);
		MemoryStream memoryStream = new MemoryStream();
		BinaryWriter binaryWriter = new BinaryWriter(memoryStream);
		binaryWriter.Write(rat.Id);
		binaryWriter.Write(victim.actualClientId);
		binaryWriter.Write(flag);
		Net.SendToClients("Infected.RatBite", memoryStream.ToArray());
		OnBite(rat.Id, victim.actualClientId, flag);
	}

	private static void OnBite(int ratId, ulong victimClientId, bool infects)
	{
		//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)
		if (rats.TryGetValue(ratId, out var value) && (Object)(object)value != (Object)null)
		{
			value.PlayBite();
		}
		PlayerControllerB localPlayer = Infection.LocalPlayer;
		if ((Object)(object)localPlayer == (Object)null || localPlayer.actualClientId != victimClientId || localPlayer.isPlayerDead)
		{
			return;
		}
		localPlayer.DamagePlayer(Mathf.Max(0, Plugin.BiteDamage.Value), true, true, (CauseOfDeath)6, 0, false, default(Vector3));
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			HUDManager.Instance.ShakeCamera((ScreenShakeType)0);
		}
		if (!localPlayer.isPlayerDead)
		{
			if (infects)
			{
				Infection.OnLocalBitten();
			}
			else if (!Infection.LocalInfected)
			{
				Symptoms.OnBittenClean();
			}
		}
	}

	private static void OnSpawnReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0001: 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_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		BinaryReader binaryReader = Open(senderClientId, reader);
		if (binaryReader == null)
		{
			return;
		}
		try
		{
			int num = binaryReader.ReadInt32();
			Vector3 position = ReadVector(binaryReader);
			float num2 = binaryReader.ReadSingle();
			if (!rats.ContainsKey(num))
			{
				Rat rat = RatModel.Build(position);
				((Component)rat).transform.rotation = Quaternion.Euler(0f, num2, 0f);
				rat.BeginPuppet(num);
				rats[num] = rat;
			}
		}
		catch (EndOfStreamException)
		{
		}
	}

	private static void OnMoveReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0001: 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_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		BinaryReader binaryReader = Open(senderClientId, reader);
		if (binaryReader == null)
		{
			return;
		}
		try
		{
			int num = binaryReader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				int key = binaryReader.ReadInt32();
				Vector3 position = ReadVector(binaryReader);
				float yaw = binaryReader.ReadSingle();
				bool isChasing = binaryReader.ReadBoolean();
				if (rats.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
				{
					value.ApplyNetState(position, yaw, isChasing);
				}
			}
		}
		catch (EndOfStreamException)
		{
		}
	}

	private static void OnDespawnReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		BinaryReader binaryReader = Open(senderClientId, reader);
		if (binaryReader == null)
		{
			return;
		}
		try
		{
			int key = binaryReader.ReadInt32();
			if (rats.TryGetValue(key, out var value))
			{
				rats.Remove(key);
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
		}
		catch (EndOfStreamException)
		{
		}
	}

	private static void OnBiteReceived(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		BinaryReader binaryReader = Open(senderClientId, reader);
		if (binaryReader == null)
		{
			return;
		}
		try
		{
			int ratId = binaryReader.ReadInt32();
			ulong victimClientId = binaryReader.ReadUInt64();
			bool infects = binaryReader.ReadBoolean();
			OnBite(ratId, victimClientId, infects);
		}
		catch (EndOfStreamException)
		{
		}
	}

	private static BinaryReader Open(ulong senderClientId, FastBufferReader reader)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		if (!Net.FromHost(senderClientId) || Net.IsHost)
		{
			return null;
		}
		byte[] array = Net.ReadAll(reader);
		if (array != null)
		{
			return new BinaryReader(new MemoryStream(array));
		}
		return null;
	}

	private static void WriteVector(BinaryWriter writer, Vector3 value)
	{
		writer.Write(value.x);
		writer.Write(value.y);
		writer.Write(value.z);
	}

	private static Vector3 ReadVector(BinaryReader reader)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		return new Vector3(reader.ReadSingle(), reader.ReadSingle(), reader.ReadSingle());
	}

	private static bool FindHiddenSpawn(PlayerControllerB player, out Vector3 position)
	{
		//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_0036: 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_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_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b1: 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_00b4: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		position = Vector3.zero;
		GameObject[] array = (((Object)(object)RoundManager.Instance != (Object)null) ? RoundManager.Instance.insideAINodes : null);
		if (array == null || array.Length == 0)
		{
			return false;
		}
		Vector3 val = ((Component)player).transform.position + Vector3.up * 1.6f;
		int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
		List<Vector3> list = new List<Vector3>();
		GameObject[] array2 = array;
		NavMeshHit val3 = default(NavMeshHit);
		foreach (GameObject val2 in array2)
		{
			if (!((Object)(object)val2 == (Object)null))
			{
				Vector3 position2 = val2.transform.position;
				float num = Vector3.Distance(position2, ((Component)player).transform.position);
				if (!(num < 10f) && !(num > 30f) && Physics.Linecast(val, position2 + Vector3.up * 0.3f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) && NavMesh.SamplePosition(position2, ref val3, 2f, -1))
				{
					list.Add(((NavMeshHit)(ref val3)).position);
				}
			}
		}
		if (list.Count == 0)
		{
			return false;
		}
		position = list[Random.Range(0, list.Count)];
		return true;
	}

	internal static Vector3? RandomNodeNear(Vector3 from, float minDistance, float maxDistance)
	{
		//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_0067: 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)
		GameObject[] array = (((Object)(object)RoundManager.Instance != (Object)null) ? RoundManager.Instance.insideAINodes : null);
		if (array == null || array.Length == 0)
		{
			return null;
		}
		NavMeshHit val2 = default(NavMeshHit);
		for (int i = 0; i < 12; i++)
		{
			GameObject val = array[Random.Range(0, array.Length)];
			if (!((Object)(object)val == (Object)null))
			{
				float num = Vector3.Distance(val.transform.position, from);
				if (num >= minDistance && num <= maxDistance && NavMesh.SamplePosition(val.transform.position, ref val2, 2f, -1))
				{
					return ((NavMeshHit)(ref val2)).position;
				}
			}
		}
		return null;
	}

	internal static void OnRoundEnded()
	{
		foreach (Rat value in rats.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}
		rats.Clear();
		timers.Clear();
		bitesToday = 0;
	}
}
internal class Rat : MonoBehaviour
{
	private enum State
	{
		Wander,
		Chase,
		Flee
	}

	private const float WanderSpeed = 2.5f;

	private const float ChaseSpeed = 7f;

	private const float FleeSpeed = 9f;

	private const float BiteRange = 1.1f;

	private const float GiveUpAfter = 5f;

	private const float HopSeconds = 0.25f;

	internal int Id;

	internal PlayerControllerB Home;

	private bool puppet;

	private NavMeshAgent agent;

	private AudioSource voice;

	private Transform body;

	private Transform[] tailSegments;

	private Transform[] legs;

	private State state;

	private PlayerControllerB chasing;

	private float lifetime;

	private float nextPath;

	private float nextSqueak;

	private float lastSawTarget;

	private float fleeUntil;

	private float hopStarted = -10f;

	private Vector3 netPosition;

	private float netYaw;

	private Vector3 lastPosition;

	private float speed;

	internal bool IsChasing => state == State.Chase;

	internal void Configure(Transform bodyPivot, Transform[] tail, Transform[] legPivots, AudioSource audio)
	{
		body = bodyPivot;
		tailSegments = tail;
		legs = legPivots;
		voice = audio;
	}

	internal void BeginHost(int id, PlayerControllerB home)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		Id = id;
		Home = home;
		state = State.Wander;
		lifetime = Random.Range(90f, 150f);
		nextSqueak = Time.time + Random.Range(0.5f, 2f);
		lastPosition = ((Component)this).transform.position;
		agent = ((Component)this).gameObject.AddComponent<NavMeshAgent>();
		agent.radius = 0.15f;
		agent.height = 0.3f;
		agent.baseOffset = 0f;
		agent.acceleration = 30f;
		agent.angularSpeed = 720f;
		agent.stoppingDistance = 0f;
		agent.autoBraking = false;
		agent.obstacleAvoidanceType = (ObstacleAvoidanceType)0;
		agent.Warp(((Component)this).transform.position);
		agent.speed = 2.5f;
	}

	internal void BeginPuppet(int id)
	{
		//IL_0037: 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_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		Id = id;
		puppet = true;
		state = State.Wander;
		nextSqueak = Time.time + Random.Range(0.5f, 2f);
		netPosition = ((Component)this).transform.position;
		netYaw = ((Component)this).transform.eulerAngles.y;
		lastPosition = ((Component)this).transform.position;
	}

	internal void ApplyNetState(Vector3 position, float yaw, bool isChasing)
	{
		//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)
		netPosition = position;
		netYaw = yaw;
		if (state != State.Flee)
		{
			state = (isChasing ? State.Chase : State.Wander);
		}
	}

	internal void PlayBite()
	{
		hopStarted = Time.time;
		Squeak(1f);
		if (puppet)
		{
			state = State.Flee;
		}
	}

	private void Update()
	{
		//IL_001f: 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_002f: 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_007c: Unknown result type (might be due to invalid IL or missing references)
		if (puppet)
		{
			FollowNetState();
		}
		else if (!Think())
		{
			return;
		}
		Vector3 val = ((Component)this).transform.position - lastPosition;
		float num = ((Vector3)(ref val)).magnitude / Mathf.Max(Time.deltaTime, 0.0001f);
		speed = Mathf.Lerp(speed, num, 1f - Mathf.Exp(-10f * Time.deltaTime));
		lastPosition = ((Component)this).transform.position;
		if (Time.time >= nextSqueak)
		{
			nextSqueak = Time.time + ((state == State.Chase) ? Random.Range(0.4f, 1.1f) : Random.Range(2.5f, 6f));
			Squeak((state == State.Chase) ? 1f : 0.7f);
		}
		Animate();
	}

	private void FollowNetState()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: 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_00ab: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = netPosition - ((Component)this).transform.position;
		if (((Vector3)(ref val)).sqrMagnitude > 25f)
		{
			((Component)this).transform.position = netPosition;
		}
		else
		{
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, netPosition, 1f - Mathf.Exp(-12f * Time.deltaTime));
		}
		((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.Euler(0f, netYaw, 0f), 1f - Mathf.Exp(-12f * Time.deltaTime));
	}

	private bool Think()
	{
		if ((Object)(object)agent == (Object)null || !agent.isOnNavMesh)
		{
			Rats.HostDespawn(this);
			return false;
		}
		lifetime -= Time.deltaTime;
		if (lifetime <= 0f && state != State.Chase)
		{
			Rats.HostDespawn(this);
			return false;
		}
		switch (state)
		{
		case State.Wander:
			Wander();
			break;
		case State.Chase:
			Chase();
			break;
		case State.Flee:
			if (Time.time >= fleeUntil)
			{
				Rats.HostDespawn(this);
				return false;
			}
			break;
		}
		return true;
	}

	private void Wander()
	{
		//IL_00b7: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		agent.speed = 2.5f;
		PlayerControllerB val = NearestVisiblePlayer();
		if ((Object)(object)val != (Object)null)
		{
			chasing = val;
			state = State.Chase;
			lastSawTarget = Time.time;
			Squeak(1f);
		}
		else if (Time.time >= nextPath || (!agent.pathPending && agent.remainingDistance < 0.5f))
		{
			nextPath = Time.time + Random.Range(6f, 12f);
			Vector3 val2 = (IsValidTarget(Home) ? ((Component)Home).transform.position : ((Component)this).transform.position);
			Vector3? val3 = Rats.RandomNodeNear(val2, 0f, 18f);
			if (!val3.HasValue)
			{
				val3 = Rats.RandomNodeNear(val2, 0f, 60f);
			}
			if (val3.HasValue)
			{
				agent.SetDestination(val3.Value);
			}
		}
	}

	private void Chase()
	{
		//IL_003b: 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_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_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		if (!IsValidTarget(chasing))
		{
			state = State.Wander;
			nextPath = 0f;
			return;
		}
		agent.speed = 7f;
		Vector3 val = ((Component)chasing).transform.position - ((Component)this).transform.position;
		if (Mathf.Abs(val.y) < 1.3f)
		{
			Vector2 val2 = new Vector2(val.x, val.z);
			if (((Vector2)(ref val2)).magnitude < 1.1f)
			{
				Bite(chasing);
				return;
			}
		}
		if (CanSee(chasing))
		{
			lastSawTarget = Time.time;
		}
		else if (Time.time - lastSawTarget > 5f)
		{
			state = State.Wander;
			nextPath = 0f;
			return;
		}
		if (Time.time >= nextPath)
		{
			nextPath = Time.time + 0.2f;
			agent.SetDestination(((Component)chasing).transform.position);
		}
	}

	private void Bite(PlayerControllerB victim)
	{
		if (Rats.BitesUsedUp)
		{
			RunOff();
			return;
		}
		RunOff();
		Rats.HostBite(this, victim);
	}

	internal void RunOff()
	{
		//IL_0053: 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 (state != State.Flee && !((Object)(object)agent == (Object)null) && agent.isOnNavMesh)
		{
			state = State.Flee;
			fleeUntil = Time.time + 4f;
			agent.speed = 9f;
			Vector3? val = Rats.RandomNodeNear(((Component)this).transform.position, 12f, 40f);
			if (val.HasValue)
			{
				agent.SetDestination(val.Value);
			}
		}
	}

	private PlayerControllerB NearestVisiblePlayer()
	{
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB result = null;
		float num = float.MaxValue;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (IsValidTarget(val))
			{
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
				if (num2 < num && CanSee(val))
				{
					num = num2;
					result = val;
				}
			}
		}
		return result;
	}

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

	private bool CanSee(PlayerControllerB player)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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_002b: 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_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 val = ((Component)player).transform.position + Vector3.up * 1.5f;
		if (Vector3.Distance(((Component)this).transform.position, val) > Plugin.RatDetectionRange.Value)
		{
			return false;
		}
		return !Physics.Linecast(((Component)this).transform.position + Vector3.up * 0.2f, val, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
	}

	private void Squeak(float volume)
	{
		if ((Object)(object)voice != (Object)null)
		{
			voice.pitch = Random.Range(0.9f, 1.15f);
			voice.PlayOneShot(RatModel.RandomSqueak(), volume);
		}
	}

	private void Animate()
	{
		//IL_009e: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		float num = Time.time * (6f + speed * 5f);
		float num2 = Mathf.Clamp01(speed / 2.5f);
		if ((Object)(object)body != (Object)null)
		{
			float num3 = ((Time.time - hopStarted < 0.25f) ? (Mathf.Sin((Time.time - hopStarted) / 0.25f * (float)Math.PI) * 0.25f) : 0f);
			body.localPosition = new Vector3(0f, Mathf.Abs(Mathf.Sin(num)) * 0.025f * num2 + num3, num3 * 0.5f);
		}
		if (legs != null)
		{
			for (int i = 0; i < legs.Length; i++)
			{
				float num4 = ((i == 0 || i == 3) ? 0f : ((float)Math.PI));
				legs[i].localRotation = Quaternion.Euler(Mathf.Sin(num + num4) * 45f * num2, 0f, 0f);
			}
		}
		if (tailSegments != null)
		{
			for (int j = 0; j < tailSegments.Length; j++)
			{
				tailSegments[j].localRotation = Quaternion.Euler(-4f, Mathf.Sin(Time.time * 7f - (float)j * 0.8f) * (10f + 12f * num2), 0f);
			}
		}
	}
}
internal static class RatModel
{
	private const int EnemyLayer = 19;

	private const int SampleRate = 44100;

	private static Shader litShader;

	private static readonly Dictionary<string, Material> materials = new Dictionary<string, Material>();

	private static AudioClip[] squeaks;

	internal static Rat Build(Vector3 position)
	{
		//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_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_004d: 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_0077: Expected O, but got Unknown
		//IL_0085: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: 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_0151: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0205: Unknown result type (might be due to invalid IL or missing references)
		//IL_0228: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0319: Unknown result type (might be due to invalid IL or missing references)
		//IL_0335: Unknown result type (might be due to invalid IL or missing references)
		//IL_033a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_038e: Unknown result type (might be due to invalid IL or missing references)
		//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_041e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0417: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_046e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0487: Unknown result type (might be due to invalid IL or missing references)
		Material material = GetMaterial(new Color(0.22f, 0.18f, 0.16f), Color.black);
		Material material2 = GetMaterial(new Color(0.75f, 0.45f, 0.45f), Color.black);
		Material material3 = GetMaterial(new Color(0.6f, 0f, 0f), new Color(4f, 0.1f, 0.05f));
		GameObject val = new GameObject("Infected Rat");
		val.layer = 19;
		val.transform.position = position;
		val.transform.rotation = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
		Transform val2 = Pivot(val.transform, "Body", Vector3.zero);
		Primitive(val2, "Torso", (PrimitiveType)0, material, new Vector3(0f, 0.12f, 0f), new Vector3(0.22f, 0.18f, 0.42f));
		Primitive(val2, "Haunch", (PrimitiveType)0, material, new Vector3(0f, 0.13f, -0.1f), new Vector3(0.25f, 0.21f, 0.25f));
		Primitive(val2, "Head", (PrimitiveType)0, material, new Vector3(0f, 0.15f, 0.23f), new Vector3(0.15f, 0.13f, 0.2f));
		Primitive(val2, "Snout", (PrimitiveType)0, material, new Vector3(0f, 0.13f, 0.33f), new Vector3(0.08f, 0.07f, 0.11f));
		Primitive(val2, "Nose", (PrimitiveType)0, material2, new Vector3(0f, 0.135f, 0.385f), Vector3.one * 0.03f);
		Primitive(val2, "EarL", (PrimitiveType)0, material2, new Vector3(-0.06f, 0.23f, 0.2f), new Vector3(0.08f, 0.08f, 0.02f));
		Primitive(val2, "EarR", (PrimitiveType)0, material2, new Vector3(0.06f, 0.23f, 0.2f), new Vector3(0.08f, 0.08f, 0.02f));
		Primitive(val2, "EyeL", (PrimitiveType)0, material3, new Vector3(-0.045f, 0.175f, 0.3f), Vector3.one * 0.03f);
		Primitive(val2, "EyeR", (PrimitiveType)0, material3, new Vector3(0.045f, 0.175f, 0.3f), Vector3.one * 0.03f);
		Transform[] array = (Transform[])(object)new Transform[4];
		Vector3[] array2 = (Vector3[])(object)new Vector3[4]
		{
			new Vector3(-0.08f, 0.07f, 0.13f),
			new Vector3(0.08f, 0.07f, 0.13f),
			new Vector3(-0.09f, 0.07f, -0.12f),
			new Vector3(0.09f, 0.07f, -0.12f)
		};
		for (int i = 0; i < array.Length; i++)
		{
			array[i] = Pivot(val2, "Leg" + i, array2[i]);
			Primitive(array[i], "Foot", (PrimitiveType)0, material2, new Vector3(0f, -0.045f, 0.01f), new Vector3(0.05f, 0.05f, 0.08f));
		}
		Transform[] array3 = (Transform[])(object)new Transform[5];
		Transform parent = Pivot(val2, "TailRoot", new Vector3(0f, 0.11f, -0.22f));
		for (int j = 0; j < array3.Length; j++)
		{
			array3[j] = Pivot(parent, "Tail" + j, (Vector3)((j == 0) ? Vector3.zero : new Vector3(0f, 0f, -0.11f)));
			float num = Mathf.Lerp(0.03f, 0.012f, (float)j / (float)(array3.Length - 1));
			Primitive(array3[j], "Segment", (PrimitiveType)2, material2, new Vector3(0f, 0f, -0.055f), new Vector3(num, 0.055f, num)).localRotation = Quaternion.Euler(90f, 0f, 0f);
			parent = array3[j];
		}
		AudioSource val3 = val.AddComponent<AudioSource>();
		val3.playOnAwake = false;
		val3.spatialBlend = 1f;
		val3.rolloffMode = (AudioRolloffMode)1;
		val3.minDistance = 1f;
		val3.maxDistance = 20f;
		val3.dopplerLevel = 0f;
		Rat rat = val.AddComponent<Rat>();
		rat.Configure(val2, array3, array, val3);
		return rat;
	}

	internal static AudioClip RandomSqueak()
	{
		if (squeaks == null)
		{
			squeaks = (AudioClip[])(object)new AudioClip[3]
			{
				MakeSqueak(3200f, 5200f, 0.13f, 1),
				MakeSqueak(3800f, 4600f, 0.09f, 2),
				MakeSqueak(4400f, 3000f, 0.18f, 1)
			};
		}
		return squeaks[Random.Range(0, squeaks.Length)];
	}

	private static AudioClip MakeSqueak(float startHz, float endHz, float chirpSeconds, int extraChirps)
	{
		int num = (int)(chirpSeconds * 44100f);
		int num2 = 2205;
		int num3 = num * (extraChirps + 1) + num2 * extraChirps;
		float[] array = new float[num3];
		for (int i = 0; i <= extraChirps; i++)
		{
			int num4 = i * (num + num2);
			float num5 = 0f;
			for (int j = 0; j < num; j++)
			{
				float num6 = (float)j / (float)num;
				float num7 = Mathf.Lerp(startHz, endHz, num6) + Mathf.Sin(num6 * 60f) * 250f;
				num5 += (float)Math.PI * 2f * num7 / 44100f;
				float num8 = Mathf.Sin(num6 * (float)Math.PI);
				array[num4 + j] = (Mathf.Sin(num5) * 0.8f + Mathf.Sin(num5 * 2f) * 0.2f) * num8 * 0.5f;
			}
		}
		AudioClip val = AudioClip.Create("RatSqueak", num3, 1, 44100, false);
		val.SetData(array, 0);
		return val;
	}

	private unsafe static Material GetMaterial(Color color, Color emission)
	{
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Expected O, but got Unknown
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_00b3: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
		string key = ((object)(*(Color*)(&color))/*cast due to .constrained prefix*/).ToString() + ((object)(*(Color*)(&emission))/*cast due to .constrained prefix*/).ToString();
		if (materials.TryGetValue(key, out var value) && (Object)(object)value != (Object)null)
		{
			return value;
		}
		if ((Object)(object)litShader == (Object)null)
		{
			litShader = Shader.Find("HDRP/Lit");
		}
		if ((Object)(object)litShader != (Object)null)
		{
			value = new Material(litShader);
		}
		else
		{
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)3);
			value = new Material(val.GetComponent<Renderer>().sharedMaterial);
			Object.Destroy((Object)(object)val);
		}
		((Object)value).name = "InfectedRat_" + materials.Count;
		value.SetColor("_BaseColor", color);
		value.SetColor("_Color", color);
		value.SetFloat("_Smoothness", 0.2f);
		if (((Color)(ref emission)).maxColorComponent > 0f)
		{
			value.SetColor("_EmissiveColor", emission);
			value.SetFloat("_EmissiveExposureWeight", 0f);
			value.EnableKeyword("_EMISSION");
		}
		materials[key] = value;
		return value;
	}

	private static Transform Pivot(Transform parent, string name, Vector3 localPosition)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.layer = 19;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		return val.transform;
	}

	private static Transform Primitive(Transform parent, string name, PrimitiveType type, Material mat, Vector3 localPosition, Vector3 localScale)
	{
		//IL_0000: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive(type);
		Object.DestroyImmediate((Object)(object)val.GetComponent<Collider>());
		((Object)val).name = name;
		val.layer = 19;
		val.transform.SetParent(parent, false);
		val.transform.localPosition = localPosition;
		val.transform.localScale = localScale;
		((Renderer)val.GetComponent<MeshRenderer>()).sharedMaterial = mat;
		return val.transform;
	}
}
internal static class Symptoms
{
	private const float PurgeDelay = 5f;

	private static readonly Color LabelColor = new Color(0.55f, 1f, 0.25f);

	private static float nextTripTime = -1f;

	private static float tripEndTime = -1f;

	private static bool tripFroze;

	private static bool tripCrouched;

	private static float purgeAt = -1f;

	private static TextMeshProUGUI label;

	internal static void Reset()
	{
		EndTrip(Infection.LocalPlayer);
		nextTripTime = -1f;
		purgeAt = -1f;
		if ((Object)(object)label != (Object)null)
		{
			Object.Destroy((Object)(object)((Component)label).gameObject);
		}
		label = null;
	}

	internal static void OnInfectionChanged(bool infected, bool fromBite)
	{
		nextTripTime = (infected ? (Time.time + NextTripInterval()) : (-1f));
		if (!infected)
		{
			EndTrip(Infection.LocalPlayer);
		}
		else if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			if (fromBite)
			{
				HUDManager.Instance.DisplayTip("You were bitten", "The wound is hot and swelling. You don't feel right.", true, false, "LC_Tip1");
			}
			else
			{
				HUDManager.Instance.DisplayTip("You feel feverish", "Someone on the ship was carrying something. Now you are too.", true, false, "LC_Tip1");
			}
		}
		UpdateLabel();
	}

	internal static void OnBittenClean()
	{
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			HUDManager.Instance.DisplayTip("You were bitten", "It stings, but the wound looks clean.", false, false, "LC_Tip1");
		}
	}

	internal static void OnAntidote(bool cured, bool byOther)
	{
		if (!((Object)(object)HUDManager.Instance == (Object)null))
		{
			if (cured)
			{
				HUDManager.Instance.DisplayTip("The fever breaks", "The antidote worked. You're no longer infected.", false, false, "LC_Tip1");
			}
			else if (byOther)
			{
				HUDManager.Instance.DisplayTip("Someone injected you", "A sharp prick in the arm. You don't feel any different.", false, false, "LC_Tip1");
			}
			else
			{
				HUDManager.Instance.DisplayTip("Nothing happens", "You weren't infected. The antidote is wasted.", false, false, "LC_Tip1");
			}
		}
	}

	internal static void Tick(PlayerControllerB player)
	{
		//IL_002b: 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_0040: 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)
		if (purgeAt > 0f && Time.time >= purgeAt)
		{
			purgeAt = -1f;
			if (!player.isPlayerDead)
			{
				player.KillPlayer(Vector3.up * 2f, true, (CauseOfDeath)13, 0, default(Vector3), false);
			}
		}
		if (tripEndTime > 0f && (Time.time >= tripEndTime || player.isPlayerDead))
		{
			EndTrip(player);
		}
		UpdateLabel();
		if (Infection.LocalInfected && !(nextTripTime < 0f) && !(Time.time < nextTripTime))
		{
			if (CanTrip(player))
			{
				Trip(player);
				nextTripTime = Time.time + NextTripInterval();
			}
			else
			{
				nextTripTime = Time.time + 2f;
			}
		}
	}

	private static float NextTripInterval()
	{
		float num = Mathf.Max(5f, Plugin.TripIntervalMin.Value);
		return Random.Range(num, Mathf.Max(num, Plugin.TripIntervalMax.Value));
	}

	private static bool CanTrip(PlayerControllerB player)
	{
		if (player.isPlayerControlled && !player.isPlayerDead && player.thisController.isGrounded && !player.inTerminalMenu && !player.isTypingChat && !player.inSpecialInteractAnimation && !player.isClimbingLadder && !player.disableMoveInput)
		{
			if (!((Object)(object)player.quickMenuManager == (Object)null))
			{
				return !player.quickMenuManager.isMenuOpen;
			}
			return true;
		}
		return false;
	}

	private static void Trip(PlayerControllerB player)
	{
		//IL_00b9: 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)
		tripFroze = true;
		player.disableMoveInput = true;
		tripCrouched = !player.isCrouching;
		if (tripCrouched)
		{
			player.Crouch(true);
		}
		player.sprintMeter = Mathf.Clamp01(player.sprintMeter - 0.3f);
		if ((Object)(object)player.movementAudio != (Object)null && (Object)(object)StartOfRound.Instance.playerHitGroundSoft != (Object)null)
		{
			player.movementAudio.PlayOneShot(StartOfRound.Instance.playerHitGroundSoft, 1f);
		}
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
		}
		if (Plugin.DropItemOnTrip.Value && (Object)(object)player.currentlyHeldObjectServer != (Object)null && !player.isGrabbingObjectAnimation)
		{
			player.DiscardHeldObject(false, (NetworkObject)null, default(Vector3), true);
		}
		tripEndTime = Time.time + Mathf.Max(0.3f, Plugin.TripDuration.Value);
	}

	private static void EndTrip(PlayerControllerB player)
	{
		if (tripEndTime < 0f)
		{
			return;
		}
		tripEndTime = -1f;
		if ((Object)(object)player != (Object)null)
		{
			if (tripFroze)
			{
				player.disableMoveInput = false;
			}
			if (tripCrouched && player.isCrouching && !player.isPlayerDead)
			{
				player.Crouch(false);
			}
		}
		tripFroze = false;
		tripCrouched = false;
	}

	internal static void BeginPurge()
	{
		if (!(purgeAt > 0f))
		{
			purgeAt = Time.time + 5f;
			if ((Object)(object)HUDManager.Instance != (Object)null)
			{
				HUDManager.Instance.DisplayTip("BIOHAZARD DETECTED", "The Company has detected an infection aboard your vessel. Sterilization will begin shortly.", true, false, "LC_Tip1");
				HUDManager.Instance.ShakeCamera((ScreenShakeType)2);
			}
		}
	}

	private static void UpdateLabel()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		bool localInfected = Infection.LocalInfected;
		if ((Object)(object)label == (Object)null)
		{
			if (!localInfected)
			{
				return;
			}
			label = CreateLabel();
			if ((Object)(object)label == (Object)null)
			{
				return;
			}
		}
		if (((Component)label).gameObject.activeSelf != localInfected)
		{
			((Component)label).gameObject.SetActive(localInfected);
		}
		if (localInfected)
		{
			Color labelColor = LabelColor;
			labelColor.a = 0.7f + 0.3f * Mathf.Sin(Time.time * 2.5f);
			((Graphic)label).color = labelColor;
		}
	}

	private static TextMeshProUGUI CreateLabel()
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Expected O, but got Unknown
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Expected O, but got Unknown
		//IL_00af: 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_00d9: 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)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_013c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_01c5: Unknown result type (might be due to invalid IL or missing references)
		HUDManager instance = HUDManager.Instance;
		if ((Object)(object)instance == (Object)null || (Object)(object)instance.selfRedCanvasGroup == (Object)null || (Object)(object)instance.weightCounter == (Object)null)
		{
			return null;
		}
		Transform transform = ((Component)instance.selfRedCanvasGroup).transform;
		RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
		if ((Object)(object)val == (Object)null || (Object)(object)((Transform)val).parent == (Object)null)
		{
			return null;
		}
		GameObject val2 = new GameObject("InfectedLabel", new Type[1] { typeof(RectTransform) });
		val2.layer = ((Component)val).gameObject.layer;
		RectTransform val3 = (RectTransform)val2.transform;
		((Transform)val3).SetParent(((Transform)val).parent, false);
		val3.anchorMin = new Vector2(0.5f, 0.5f);
		val3.anchorMax = new Vector2(0.5f, 0.5f);
		val3.pivot = new Vector2(0.5f, 1f);
		val3.sizeDelta = new Vector2(220f, 40f);
		Rect rect = val.rect;
		float x = ((Rect)(ref rect)).center.x;
		Rect rect2 = val.rect;
		Vector3 val4 = default(Vector3);
		((Vector3)(ref val4))..ctor(x, ((Rect)(ref rect2)).yMin, 0f);
		((Transform)val3).localPosition = ((Transform)val).localPosition + ((Transform)val).localRotation * Vector3.Scale(val4, ((Transform)val).localScale);
		((Transform)val3).localRotation = ((Transform)val).localRotation;
		((Transform)val3).localScale = Vector3.one;
		TextMeshProUGUI val5 = val2.AddComponent<TextMeshProUGUI>();
		((TMP_Text)val5).font = ((TMP_Text)instance.weightCounter).font;
		((TMP_Text)val5).fontSize = ((TMP_Text)instance.weightCounter).fontSize;
		((TMP_Text)val5).alignment = (TextAlignmentOptions)258;
		((TMP_Text)val5).enableWordWrapping = false;
		((TMP_Text)val5).overflowMode = (TextOverflowModes)0;
		((Graphic)val5).raycastTarget = false;
		((TMP_Text)val5).text = "INFECTED";
		((Graphic)val5).color = LabelColor;
		return val5;
	}
}