Decompiled source of Odd Company v0.10.1

BepInEx/plugins/OddCompany/OddCompany.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using GameNetcodeStuff;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyFileVersion("0.10.1.0")]
[assembly: AssemblyVersion("0.10.1.0")]
namespace OddCompany;

public static class Balance
{
	public const int Protocol = 10;

	public const float PliggaWindup = 0.8f;

	public const float BlackoutChaseSpeed = 5.2f;

	public const float BlackoutLungeSpeed = 11f;

	public const float BlackoutWindup = 0.6f;

	public const float BlackoutLungeTime = 0.85f;

	public static readonly string[] Names = new string[7] { "pligga", "Hushloom", "Backstitch", "Tollbud", "Foldback", "The Last Passenger", "The Blackout" };

	public static readonly string[] Advice = new string[7] { "Nine-metre tongue sweep! Retreat, circle behind or use cover; spit obscures your visor.", "Sprinting charges its shriek. Crouch before the pulse or leave its ten-metre radius.", "Crouch across cyan stitches. Walking also triggers snares; the hunter follows.", "Stand still for two seconds at the OUTER edge of its six-metre ring to earn a short pass.", "It races along your footsteps only 2.5 seconds behind. Keep moving; do not double back.", "Do not stare. Its mark returns at takeoff. The curse is fatal.", "Sidestep its rasping lunge or use solid cover. If grabbed, steady six heartbeats; crew can hit it twice to rescue you." };

	public static int Damage(int health, int requested, bool gentle)
	{
		return Math.Max(0, Math.Min(requested, gentle ? (health - 20) : health));
	}

	public static bool InTongue(float forward, float sideways, float height)
	{
		if (forward >= 0f && forward <= 9f && Math.Abs(sideways) <= 1.1f)
		{
			return Math.Abs(height) < 2f;
		}
		return false;
	}

	public static bool InSweep(float forward, float sideways, float height, float previous, float current)
	{
		double num = Math.Atan2(sideways, forward) * 180.0 / Math.PI;
		if (forward >= 0f && forward * forward + sideways * sideways <= 81f && Math.Abs(height) < 2f && num >= (double)(-50f + 100f * previous - 7f))
		{
			return num <= (double)(-50f + 100f * current + 7f);
		}
		return false;
	}

	public static bool PassengerRoll(double roll, float chance, int spawned, bool alreadySpawned)
	{
		if (!alreadySpawned && chance > 0f)
		{
			if (!(roll < (double)chance))
			{
				return spawned >= 2;
			}
			return true;
		}
		return false;
	}

	public static int Toughness(int kind)
	{
		if (kind != 0 && kind != 3 && kind != 6)
		{
			return 6;
		}
		return 8;
	}

	public static int CorpseTier(int kind)
	{
		switch (kind)
		{
		default:
			return 1;
		case 0:
		case 3:
			return 2;
		case 5:
		case 6:
			return 3;
		}
	}

	public static bool CanCommitDeath(bool host, bool dead)
	{
		if (host)
		{
			return !dead;
		}
		return false;
	}

	public static bool BlackoutCanGrab(float distance, bool clear, bool eligible)
	{
		if (eligible && clear)
		{
			return distance <= 1.8f;
		}
		return false;
	}

	public static bool CanSpawn(float distance, bool visible, bool pathComplete)
	{
		if (distance >= 14f && distance <= 65f && !visible)
		{
			return pathComplete;
		}
		return false;
	}

	public static float RemainingStamina(float current, float drain)
	{
		return Math.Min(current, Math.Max(0.15f, current - drain));
	}

	public static bool OutsideRoll(double roll, float chance)
	{
		return roll < (double)chance;
	}

	public static bool ZoneMatches(bool insideFactory, bool outside)
	{
		return insideFactory != outside;
	}

	public static bool CanMark(float distance, float angle, bool clear, bool looking, bool sameZone)
	{
		if (distance <= 22f && angle <= 65f && clear && looking)
		{
			return sameZone;
		}
		return false;
	}
}
public sealed class HeartbeatRules
{
	public const float Lead = 2f;

	public const float Interval = 0.85f;

	public const float Window = 0.18f;

	public int Hits;

	public int Mistakes;

	public int Beat;

	public float NextBeat => 2f + (float)Beat * 0.85f;

	public bool Done
	{
		get
		{
			if (Hits < 6)
			{
				return Mistakes >= 3;
			}
			return true;
		}
	}

	public bool Won => Hits >= 6;

	public bool Tap(float elapsed)
	{
		if (Done)
		{
			return false;
		}
		bool flag = Math.Abs(elapsed - NextBeat) <= 0.18f;
		if (flag)
		{
			Hits++;
		}
		else
		{
			Mistakes++;
		}
		Beat++;
		return flag;
	}

	public void Advance(float elapsed)
	{
		while (!Done && elapsed > NextBeat + 0.18f)
		{
			Mistakes++;
			Beat++;
		}
	}

	public static bool ValidResult(int hits, int mistakes, float elapsed)
	{
		if (hits < 0 || mistakes < 0 || hits > 6 || mistakes > 3 || hits == 6 == (mistakes == 3))
		{
			return false;
		}
		if (hits >= 6)
		{
			return elapsed >= 6.07f;
		}
		return true;
	}

	public static bool PlayVictory(int stage, bool won, float elapsed)
	{
		if (stage == 3 && won && elapsed >= 0f)
		{
			return elapsed < 2f;
		}
		return false;
	}
}
public sealed class SightingGate
{
	private readonly bool[] seen = new bool[Balance.Names.Length];

	private float nextAllowed;

	public void Reset()
	{
		Array.Clear(seen, 0, seen.Length);
		nextAllowed = 0f;
	}

	public static bool Visible(float distance, bool inView, bool clearLine, bool eligible)
	{
		if (eligible && distance <= 12f && inView)
		{
			return clearLine;
		}
		return false;
	}

	public bool Consume(int kind, float now, bool attack, bool enabled)
	{
		if (kind < 0 || kind >= seen.Length || seen[kind])
		{
			return false;
		}
		seen[kind] = true;
		if (!enabled || attack || now < nextAllowed)
		{
			return false;
		}
		nextAllowed = now + 45f;
		return true;
	}
}
public static class CurseRules
{
	public const float GazeSeconds = 0.6f;

	public const float VisionSeconds = 3.5f;

	public const float SnapSeconds = 2.4f;

	public const float FinishSeconds = 6f;

	public static int Next(int stage, float elapsed, bool leaving, bool victimAlive)
	{
		if ((stage == 1 || stage == 2) && !victimAlive)
		{
			return 4;
		}
		if ((stage == 1 || stage == 2) && leaving)
		{
			return 3;
		}
		if (stage == 1 && elapsed >= 3.5f)
		{
			return 2;
		}
		if (stage == 3 && elapsed >= 6f)
		{
			return 4;
		}
		return stage;
	}

	public static bool ShouldKill(int stage, float elapsed, bool localVictim, bool alreadyKilled)
	{
		if (stage == 3 && elapsed >= 2.4f && elapsed < 6f && localVictim)
		{
			return !alreadyKilled;
		}
		return false;
	}
}
[BepInPlugin("local.oddcompany.five", "Odd Company", "0.10.1")]
public sealed class Plugin : BaseUnityPlugin
{
	private const string Channel = "OddCompany.v1";

	internal static Plugin Instance;

	private readonly Dictionary<int, Creature> creatures = new Dictionary<int, Creature>();

	private readonly Dictionary<ulong, float> peers = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, Signal> signals = new Dictionary<ulong, Signal>();

	private readonly Dictionary<ulong, float> hurtUntil = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, float> hitUntil = new Dictionary<ulong, float>();

	private ConfigEntry<bool> enabledMod;

	private ConfigEntry<bool> gentle;

	private ConfigEntry<bool> testMode;

	private ConfigEntry<bool> hints;

	private ConfigEntry<int> maxAlive;

	private ConfigEntry<int> maxPerDay;

	private ConfigEntry<int> testKind;

	private ConfigEntry<float> spawnDelay;

	private ConfigEntry<float> spawnInterval;

	private ConfigEntry<float> spawnChance;

	private ConfigEntry<float> outsideChance;

	private ConfigEntry<float> passengerChance;

	private ConfigEntry<float> curseShake;

	private ConfigEntry<float> curseFlicker;

	private ConfigEntry<float> curseDistortion;

	private bool? pendingOutside;

	private bool passengerSpawned;

	private int pendingKind = -1;

	private CombatEffects combat;

	internal PassengerCurse Curse;

	internal HeartbeatGrab Grab;

	private ConfigEntry<float> ambienceVolume;

	private ConfigEntry<float> warningVolume;

	private ConfigEntry<bool> sightingScares;

	private ConfigEntry<float> sightingVolume;

	internal readonly SightingGate Sightings = new SightingGate();

	private ConfigEntry<bool>[] enabledKinds = new ConfigEntry<bool>[Balance.Names.Length];

	private NetworkManager network;

	private CustomMessagingManager messages;

	private bool active;

	private bool acknowledged;

	private bool warnedPeers;

	private float nextSend;

	private float nextSpawn;

	private float activeSince;

	private float localHurtUntil;

	private int spawned;

	private int nextId = 1;

	private int sequence;

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

	private Random random = new Random();

	internal Texture2D Face;

	internal AudioClip[,] Sounds = new AudioClip[Balance.Names.Length, 5];

	internal AudioClip[] CurseSounds = (AudioClip[])(object)new AudioClip[3];

	private readonly HashSet<int> shownHints = new HashSet<int>();

	internal float CurseShake => curseShake.Value;

	internal float CurseFlicker => curseFlicker.Value;

	internal float CurseDistortion => curseDistortion.Value;

	internal bool SightingScares => sightingScares.Value;

	internal float SightingVolume => sightingVolume.Value;

	internal float AmbienceVolume => ambienceVolume.Value;

	internal float WarningVolume => warningVolume.Value;

	internal bool Host
	{
		get
		{
			if ((Object)(object)network != (Object)null)
			{
				return network.IsServer;
			}
			return false;
		}
	}

	internal bool Gentle => gentle.Value;

	internal IEnumerable<Creature> Creatures => creatures.Values;

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

	internal static int WallMask
	{
		get
		{
			if (!((Object)(object)StartOfRound.Instance != (Object)null))
			{
				return LayerMask.GetMask(new string[3] { "Default", "Room", "Colliders" });
			}
			return StartOfRound.Instance.collidersAndRoomMask;
		}
	}

	private void Awake()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Expected O, but got Unknown
		//IL_00df: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Expected O, but got Unknown
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Expected O, but got Unknown
		//IL_015d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Expected O, but got Unknown
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Expected O, but got Unknown
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Expected O, but got Unknown
		//IL_028a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Expected O, but got Unknown
		//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d3: Expected O, but got Unknown
		//IL_0308: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Expected O, but got Unknown
		//IL_0368: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Expected O, but got Unknown
		//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_03b1: Expected O, but got Unknown
		//IL_0407: Unknown result type (might be due to invalid IL or missing references)
		//IL_0411: Expected O, but got Unknown
		//IL_0463: Unknown result type (might be due to invalid IL or missing references)
		//IL_046d: Expected O, but got Unknown
		//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0500: Expected O, but got Unknown
		Instance = this;
		enabledMod = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Host: enable added encounters.");
		gentle = ((BaseUnityPlugin)this).Config.Bind<bool>("Balance", "GentleDamage", false, "Host: optional mercy mode stops normal attacks at 20 HP. Default false: monsters can kill. Passenger curse is always fatal.");
		maxAlive = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxAlive", 1, new ConfigDescription("Host: simultaneous added monsters.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), new object[0]));
		maxPerDay = ((BaseUnityPlugin)this).Config.Bind<int>("Spawning", "MaxPerDay", 3, new ConfigDescription("Host: encounter limit per moon landing.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 12), new object[0]));
		spawnDelay = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "FirstSpawnDelay", 75f, new ConfigDescription("Host: seconds after landing.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(10f, 600f), new object[0]));
		spawnInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpawnInterval", 75f, new ConfigDescription("Host: seconds between spawn attempts.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(15f, 600f), new object[0]));
		spawnChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "SpawnChance", 0.65f, new ConfigDescription("Host: probability per attempt.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		outsideChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "OutdoorChance", 0.2f, new ConfigDescription("Host: chance each new encounter is assigned outdoors. Failed placement keeps its roll until a suitable player/point is available.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		passengerChance = ((BaseUnityPlugin)this).Config.Bind<float>("Spawning", "LastPassengerChance", 0.6f, new ConfigDescription("Host: encounter selection chance; guaranteed selection by encounter three if enabled and chance > 0. At most once per landing; valid placement still required.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		ConfigEntry<int> val = ((BaseUnityPlugin)this).Config.Bind<int>("Balance", "BalanceRevision", 0, "Internal one-time balance migration marker.");
		if (val.Value < 5)
		{
			gentle.Value = false;
			if (Mathf.Abs(passengerChance.Value - 0.12f) < 0.001f)
			{
				passengerChance.Value = 0.6f;
			}
			val.Value = 5;
			((BaseUnityPlugin)this).Config.Save();
		}
		curseShake = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "CurseShake", 0.7f, new ConfigDescription("Local: curse tremor intensity; zero disables camera shake.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		curseFlicker = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "CurseFlicker", 0.75f, new ConfigDescription("Local: curse light flicker depth; zero disables flickering.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		curseDistortion = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "CurseDistortion", 0.65f, new ConfigDescription("Local: temporary listener audio distortion; zero disables filtering.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		hints = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowHints", true, "Local: show each creature's counter once per landing.");
		ambienceVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "EncounterVolume", 0.45f, new ConfigDescription("Local: spatial creature soundscape volume. Zero disables ambience, not attack warnings.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		warningVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "WarningVolume", 0.75f, new ConfigDescription("Local: distinctive warning and attack sound volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		sightingScares = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "FirstSightingScares", true, "Local: short sting on first clear sight of each species per landing. Shared 45-second cooldown; no camera effects.");
		sightingVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "SightingVolume", 0.55f, new ConfigDescription("Local: first-sighting sting volume.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		testMode = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "TestMode", false, "Host: first encounter after 15 seconds; cycles all enabled monsters, one at a time. Use a disposable LAN save.");
		testKind = ((BaseUnityPlugin)this).Config.Bind<int>("Testing", "FirstMonster", 0, new ConfigDescription("Host: 0 pligga, 1 Hushloom, 2 Backstitch, 3 Tollbud, 4 Foldback, 5 The Last Passenger, 6 The Blackout.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, Balance.Names.Length - 1), new object[0]));
		for (int i = 0; i < Balance.Names.Length; i++)
		{
			enabledKinds[i] = ((BaseUnityPlugin)this).Config.Bind<bool>("Monsters", Balance.Names[i], true, "Host: allow this monster to spawn.");
		}
		using (Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream("OddCompany.Pligga.png"))
		{
			if (stream != null)
			{
				byte[] array = new byte[stream.Length];
				int num;
				for (int j = 0; j < array.Length; j += num)
				{
					if ((num = stream.Read(array, j, array.Length - j)) <= 0)
					{
						break;
					}
				}
				Face = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(Face, array);
			}
		}
		for (int k = 0; k < Balance.Names.Length; k++)
		{
			for (int l = 0; l < 5; l++)
			{
				float[] array2 = HorrorAudio.Render(k, l);
				AudioClip val2 = AudioClip.Create("OddCompany_" + k + "_" + l, array2.Length, 1, 22050, false);
				val2.SetData(array2, 0);
				Sounds[k, l] = val2;
			}
		}
		for (int m = 0; m < 3; m++)
		{
			float[] array3 = HorrorAudio.RenderCurse(m);
			CurseSounds[m] = AudioClip.Create("LastPassenger_Event_" + m, array3.Length, 1, 22050, false);
			CurseSounds[m].SetData(array3, 0);
		}
		Curse = ((Component)this).gameObject.AddComponent<PassengerCurse>();
		Grab = ((Component)this).gameObject.AddComponent<HeartbeatGrab>();
		combat = ((Component)this).gameObject.AddComponent<CombatEffects>();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Odd Company 0.10.1 loaded. Seven Blender-authored skinned models. All players need this version.");
	}

	private void Update()
	{
		//IL_0073: Unknown result type (might be due to invalid IL or missing references)
		//IL_007d: Expected O, but got Unknown
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton != (Object)(object)network || ((Object)(object)network != (Object)null && !network.IsListening))
		{
			Unbind();
			if ((Object)(object)singleton != (Object)null && singleton.IsListening && singleton.CustomMessagingManager != null)
			{
				network = singleton;
				messages = singleton.CustomMessagingManager;
				messages.RegisterNamedMessageHandler("OddCompany.v1", new HandleNamedMessageDelegate(Receive));
				nextSend = 0f;
			}
		}
		if ((Object)(object)network == (Object)null)
		{
			return;
		}
		StartOfRound instance = StartOfRound.Instance;
		if (!((Object)(object)instance != (Object)null) || !instance.shipHasLanded || instance.inShipPhase || instance.allPlayersDead)
		{
			if (active)
			{
				Clear();
			}
			active = false;
		}
		else if (!active)
		{
			active = true;
			activeSince = Time.time;
			nextSpawn = Time.time + (testMode.Value ? 15f : spawnDelay.Value);
			spawned = 0;
			shownHints.Clear();
			Sightings.Reset();
			bag.Clear();
			pendingOutside = null;
			pendingKind = -1;
			passengerSpawned = false;
			if (Host)
			{
				Curse.Reset();
			}
			random = new Random(instance.randomMapSeed ^ 0x3084B);
		}
		if (!(Time.time >= nextSend))
		{
			return;
		}
		nextSend = Time.time + 0.2f;
		if (Host)
		{
			RecordSignal(network.LocalClientId, LocalSignal());
			if (active)
			{
				HostTick();
			}
			Grab.HostTick(active && enabledMod.Value && AllPeersReady());
			Curse.HostTick(enabledMod.Value && AllPeersReady());
			BroadcastSnapshot();
		}
		else
		{
			Send(new Packet
			{
				op = 1,
				version = 10,
				signal = LocalSignal()
			}, 0uL);
		}
	}

	private Signal LocalSignal()
	{
		//IL_006d: 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_007f: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayer = LocalPlayer;
		Signal signal = new Signal();
		signal.sprint = (Object)(object)localPlayer != (Object)null && localPlayer.isSprinting;
		signal.sellBodies = SellBodiesBridge.Available;
		signal.crouch = (Object)(object)localPlayer != (Object)null && localPlayer.isCrouching;
		signal.witness = WitnessInView(localPlayer);
		signal.look = (((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer.gameplayCamera != (Object)null) ? ((Component)localPlayer.gameplayCamera).transform.forward : Vector3.forward);
		return signal;
	}

	private int WitnessInView(PlayerControllerB player, int kind = 5)
	{
		//IL_006c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		if (!Eligible(player) || (Object)(object)player.gameplayCamera == (Object)null)
		{
			return 0;
		}
		foreach (Creature value in creatures.Values)
		{
			if (!((Object)(object)value == (Object)null) && !value.Dead && value.Kind == kind && value.EligibleFor(player))
			{
				Vector3 val = ((Component)value).transform.position + Vector3.up * ((kind == 5) ? 2.2f : 1.8f);
				Vector3 val2 = player.gameplayCamera.WorldToViewportPoint(val);
				if (val2.z > 0f && val2.x > 0.04f && val2.x < 0.96f && val2.y > 0.04f && val2.y < 0.96f && Vector3.Distance(val, ((Component)player.gameplayCamera).transform.position) <= (float)((kind == 5) ? 22 : 26) && ClearLine(((Component)player.gameplayCamera).transform.position, val))
				{
					return value.Id;
				}
			}
		}
		return 0;
	}

	internal Signal GetSignal(PlayerControllerB player)
	{
		//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)
		if (signals.TryGetValue(player.actualClientId, out var value) && Time.time - value.received < 1.5f)
		{
			return value;
		}
		Signal signal = new Signal();
		signal.look = ((Component)player).transform.forward;
		return signal;
	}

	private void RecordSignal(ulong sender, Signal value)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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)
		if (value != null && Finite(value.look.x) && Finite(value.look.y) && Finite(value.look.z))
		{
			value.look = ((((Vector3)(ref value.look)).sqrMagnitude > 0.01f) ? ((Vector3)(ref value.look)).normalized : Vector3.forward);
			value.received = Time.time;
			signals[sender] = value;
		}
	}

	private static bool Finite(float value)
	{
		if (!float.IsNaN(value))
		{
			return !float.IsInfinity(value);
		}
		return false;
	}

	private void Receive(ulong sender, FastBufferReader reader)
	{
		try
		{
			if (((FastBufferReader)(ref reader)).Length > 24000)
			{
				return;
			}
			string text = default(string);
			((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
			Packet packet = JsonUtility.FromJson<Packet>(text);
			if (packet == null || packet.version != 10)
			{
				return;
			}
			if (Host)
			{
				if (sender != network.LocalClientId)
				{
					if (packet.op == 1)
					{
						peers[sender] = Time.time;
						RecordSignal(sender, packet.signal);
					}
					else if (packet.op == 4)
					{
						HostHit(sender, packet.id);
					}
					else if (packet.op == 5)
					{
						Grab.Message(sender, packet);
					}
				}
			}
			else if (sender == 0)
			{
				if (packet.op == 2)
				{
					acknowledged = true;
					ApplySnapshot(packet);
				}
				else if (packet.op == 3)
				{
					ApplyEffect(packet);
				}
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Ignored invalid Odd Company packet: " + ex.Message));
		}
	}

	private unsafe void Send(Packet packet, ulong client)
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		if (messages == null || (Object)(object)network == (Object)null || !network.IsListening)
		{
			return;
		}
		packet.version = 10;
		string text = JsonUtility.ToJson((object)packet);
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(text.Length * 4 + 64, (Allocator)2, -1);
		try
		{
			((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
			messages.SendNamedMessage("OddCompany.v1", client, val, (NetworkDelivery)4);
		}
		finally
		{
			((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
		}
	}

	private bool AllPeersReady()
	{
		foreach (ulong connectedClientsId in network.ConnectedClientsIds)
		{
			if (connectedClientsId != network.LocalClientId)
			{
				if (!peers.TryGetValue(connectedClientsId, out var value) || Time.time - value > 6f)
				{
					return false;
				}
				if (SellBodiesBridge.Available && (!signals.TryGetValue(connectedClientsId, out var value2) || !value2.sellBodies))
				{
					return false;
				}
			}
		}
		return true;
	}

	private void HostTick()
	{
		if (!enabledMod.Value || !AllPeersReady())
		{
			Clear();
			if (!warnedPeers && enabledMod.Value && Time.time - activeSince > 12f)
			{
				warnedPeers = true;
				Tip("Odd Company paused", "Everyone needs Odd Company 0.10.1, plus SellBodiesFixed if the host uses it. Waiting for matching clients.");
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Missing client handshake: added monsters paused.");
			}
			return;
		}
		warnedPeers = false;
		foreach (Creature item in new List<Creature>(creatures.Values))
		{
			if ((Object)(object)item == (Object)null)
			{
				if ((Object)(object)item != (Object)null)
				{
					Remove(item.Id);
				}
			}
			else
			{
				item.Tick();
			}
		}
		int num = (testMode.Value ? 1 : maxAlive.Value);
		int num2 = (testMode.Value ? Balance.Names.Length : maxPerDay.Value);
		int num3 = 0;
		foreach (Creature value in creatures.Values)
		{
			if ((Object)(object)value != (Object)null && !value.Dead)
			{
				num3++;
			}
		}
		if (num3 < num && spawned < num2 && !(Time.time < nextSpawn))
		{
			nextSpawn = Time.time + (testMode.Value ? 8f : spawnInterval.Value);
			if (testMode.Value || !(random.NextDouble() > (double)spawnChance.Value))
			{
				TrySpawn();
			}
		}
	}

	private void TrySpawn()
	{
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0184: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Expected O, but got Unknown
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_029c: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a2: Invalid comparison between Unknown and I4
		//IL_02ec: 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_02fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_0261: Unknown result type (might be due to invalid IL or missing references)
		//IL_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_0390: Unknown result type (might be due to invalid IL or missing references)
		if (pendingKind < 0)
		{
			pendingKind = PickKind();
		}
		if (pendingKind < 0)
		{
			return;
		}
		if (!pendingOutside.HasValue)
		{
			pendingOutside = Balance.OutsideRoll(random.NextDouble(), outsideChance.Value);
		}
		bool value = pendingOutside.Value;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		List<PlayerControllerB> list = new List<PlayerControllerB>();
		PlayerControllerB[] array = allPlayerScripts;
		foreach (PlayerControllerB val in array)
		{
			if (Eligible(val) && Balance.ZoneMatches(val.isInsideFactory, value))
			{
				list.Add(val);
			}
		}
		if (list.Count == 0 && !value)
		{
			return;
		}
		Vector3 val2 = ((list.Count > 0) ? ((Component)list[random.Next(list.Count)]).transform.position : StartOfRound.Instance.groundOutsideShipSpawnPosition.position);
		NavMeshHit val3 = default(NavMeshHit);
		if (!NavMesh.SamplePosition(val2, ref val3, 4f, -1))
		{
			return;
		}
		val2 = ((NavMeshHit)(ref val3)).position;
		GameObject[] array2 = (value ? RoundManager.Instance.outsideAINodes : RoundManager.Instance.insideAINodes);
		if (array2 == null || array2.Length == 0)
		{
			return;
		}
		NavMeshHit val5 = default(NavMeshHit);
		for (int j = 0; j < 45; j++)
		{
			GameObject val4 = array2[random.Next(array2.Length)];
			if ((Object)(object)val4 == (Object)null)
			{
				continue;
			}
			Vector3 position = val4.transform.position;
			if (!NavMesh.SamplePosition(position, ref val5, 2f, -1))
			{
				continue;
			}
			position = ((NavMeshHit)(ref val5)).position;
			if (value && Vector3.Distance(position, StartOfRound.Instance.elevatorTransform.position) < 20f)
			{
				continue;
			}
			float num = ((list.Count == 0) ? Vector3.Distance(position, val2) : float.MaxValue);
			bool visible = false;
			foreach (PlayerControllerB item in list)
			{
				num = Mathf.Min(num, Vector3.Distance(position, ((Component)item).transform.position));
				if (CanSee(item, position + Vector3.up))
				{
					visible = true;
				}
			}
			if (value)
			{
				PlayerControllerB[] array3 = allPlayerScripts;
				foreach (PlayerControllerB val6 in array3)
				{
					if ((Object)(object)val6 != (Object)null && val6.isPlayerControlled && !val6.isPlayerDead && !val6.isInsideFactory && CanSee(val6, position + Vector3.up))
					{
						visible = true;
					}
				}
			}
			NavMeshPath val7 = new NavMeshPath();
			bool pathComplete = NavMesh.CalculatePath(position, val2, -1, val7) && (int)val7.status == 0;
			if (Balance.CanSpawn(num, visible, pathComplete) && (pendingKind != 5 || !(num > 32f)))
			{
				int num2 = pendingKind;
				Creature creature = Create(nextId++, num2, position, value);
				creature.Home = position;
				if (num2 == 5)
				{
					passengerSpawned = true;
				}
				pendingOutside = null;
				pendingKind = -1;
				spawned++;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Spawned " + Balance.Names[num2] + " (" + creature.Id + ") " + (value ? "outside" : "inside") + " at " + position));
				if (testMode.Value)
				{
					Tip("Test encounter: " + Balance.Names[num2], Balance.Advice[num2] + (value ? " Look outside away from the ship." : " Look deeper inside."));
				}
				break;
			}
		}
	}

	private int PickKind()
	{
		if (testMode.Value)
		{
			for (int i = 0; i < Balance.Names.Length; i++)
			{
				int num = (testKind.Value + spawned + i) % Balance.Names.Length;
				if (enabledKinds[num].Value)
				{
					return num;
				}
			}
			return -1;
		}
		if (enabledKinds[5].Value && Balance.PassengerRoll(random.NextDouble(), passengerChance.Value, spawned, passengerSpawned))
		{
			return 5;
		}
		if (bag.Count == 0)
		{
			for (int j = 0; j < Balance.Names.Length; j++)
			{
				if (j != 5 && enabledKinds[j].Value)
				{
					bag.Add(j);
				}
			}
		}
		if (bag.Count == 0)
		{
			return -1;
		}
		int index = random.Next(bag.Count);
		int result = bag[index];
		bag.RemoveAt(index);
		return result;
	}

	private Creature Create(int id, int kind, Vector3 point, bool outside)
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("OddCompany_" + Balance.Names[kind]);
		val.transform.position = point;
		Creature creature = val.AddComponent<Creature>();
		creature.Initialize(id, kind, Host, outside);
		creatures.Add(id, creature);
		return creature;
	}

	internal void Remove(int id)
	{
		if (Host && (Object)(object)Grab != (Object)null)
		{
			Grab.Removed(id);
		}
		if (creatures.TryGetValue(id, out var value))
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
			creatures.Remove(id);
		}
	}

	internal void Killed(Creature creature)
	{
		if (!((Object)(object)creature == (Object)null) && Balance.CanCommitDeath(Host, creature.Dead))
		{
			creature.Die();
			Grab.Removed(creature.Id);
			Curse.CancelFor(creature.Id);
			if (SellBodiesBridge.Drop(creature))
			{
				Remove(creature.Id);
			}
		}
	}

	private void Clear()
	{
		if ((Object)(object)Grab != (Object)null)
		{
			Grab.Reset();
		}
		if ((Object)(object)combat != (Object)null)
		{
			combat.Reset();
		}
		foreach (Creature value in creatures.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}
		creatures.Clear();
		hurtUntil.Clear();
		hitUntil.Clear();
	}

	private void BroadcastSnapshot()
	{
		List<CreatureState> list = new List<CreatureState>();
		foreach (Creature value in creatures.Values)
		{
			if ((Object)(object)value != (Object)null)
			{
				list.Add(value.State());
			}
		}
		Packet packet = new Packet();
		packet.op = 2;
		packet.serial = ++sequence;
		packet.monsters = list.ToArray();
		packet.curse = Curse.Snapshot();
		packet.grab = Grab.Snapshot();
		Packet packet2 = packet;
		foreach (ulong connectedClientsId in network.ConnectedClientsIds)
		{
			if (connectedClientsId != network.LocalClientId && peers.ContainsKey(connectedClientsId))
			{
				Send(packet2, connectedClientsId);
			}
		}
	}

	private void ApplySnapshot(Packet packet)
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		if (packet.serial <= sequence || packet.monsters == null || packet.monsters.Length > 12)
		{
			return;
		}
		sequence = packet.serial;
		if (packet.curse != null)
		{
			Curse.Apply(packet.curse);
		}
		if (packet.grab != null)
		{
			Grab.Apply(packet.grab);
		}
		HashSet<int> hashSet = new HashSet<int>();
		CreatureState[] monsters = packet.monsters;
		foreach (CreatureState creatureState in monsters)
		{
			if (creatureState.kind >= 0 && creatureState.kind < Balance.Names.Length)
			{
				if (!creatures.TryGetValue(creatureState.id, out var value))
				{
					value = Create(creatureState.id, creatureState.kind, creatureState.position, creatureState.outside);
				}
				value.Apply(creatureState);
				hashSet.Add(creatureState.id);
			}
		}
		foreach (int item in new List<int>(creatures.Keys))
		{
			if (!hashSet.Contains(item))
			{
				Remove(item);
			}
		}
	}

	internal bool Hurt(PlayerControllerB player, int damage, float stamina, int kind)
	{
		if (!Host || !Eligible(player))
		{
			return false;
		}
		if (hurtUntil.TryGetValue(player.actualClientId, out var value) && Time.time < value)
		{
			return false;
		}
		hurtUntil[player.actualClientId] = Time.time + 1.5f;
		Packet packet = new Packet();
		packet.op = 3;
		packet.damage = damage;
		packet.stamina = stamina;
		packet.gentle = gentle.Value;
		packet.kind = kind;
		Packet packet2 = packet;
		if (player.actualClientId == network.LocalClientId)
		{
			ApplyEffect(packet2);
		}
		else
		{
			Send(packet2, player.actualClientId);
		}
		return true;
	}

	private void ApplyEffect(Packet packet)
	{
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayer = LocalPlayer;
		if (active && Eligible(localPlayer) && !(Time.time < localHurtUntil))
		{
			localHurtUntil = Time.time + 1.35f;
			int num = Balance.Damage(localPlayer.health, Mathf.Clamp(packet.damage, 0, 65), packet.gentle);
			if (num > 0)
			{
				localPlayer.DamagePlayer(num, true, true, (CauseOfDeath)6, 0, false, Vector3.zero);
			}
			localPlayer.sprintMeter = Balance.RemainingStamina(localPlayer.sprintMeter, Mathf.Clamp(packet.stamina, 0f, 0.5f));
			if (!localPlayer.isPlayerDead)
			{
				combat.Apply(packet.kind);
			}
		}
	}

	internal void RequestHit(int id, PlayerControllerB player)
	{
		if (!((Object)(object)player == (Object)null) && !((Object)(object)player != (Object)(object)LocalPlayer))
		{
			if (Host)
			{
				HostHit(network.LocalClientId, id);
			}
			else if (acknowledged)
			{
				Send(new Packet
				{
					op = 4,
					id = id
				}, 0uL);
			}
		}
	}

	internal void GrabMessage(int session, int action, int beats, int mistakes)
	{
		if (!((Object)(object)network == (Object)null))
		{
			Packet packet = new Packet();
			packet.op = 5;
			packet.id = session;
			packet.grabAction = action;
			packet.beats = beats;
			packet.mistakes = mistakes;
			Packet packet2 = packet;
			if (Host)
			{
				Grab.Message(network.LocalClientId, packet2);
			}
			else
			{
				Send(packet2, 0uL);
			}
		}
	}

	private void HostHit(ulong sender, int id)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		if (!active || !creatures.TryGetValue(id, out var value) || value.Dead || Grab.IsVictim(sender))
		{
			return;
		}
		PlayerControllerB val = null;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val2 in allPlayerScripts)
		{
			if ((Object)(object)val2 != (Object)null && val2.actualClientId == sender)
			{
				val = val2;
				break;
			}
		}
		if (Eligible(val) && !(Vector3.Distance(((Component)val).transform.position, ((Component)value).transform.position) > 4.5f) && ClearLine(((Component)val).transform.position + Vector3.up, ((Component)value).transform.position + Vector3.up) && (val.currentlyHeldObjectServer is Shovel || val.currentlyHeldObjectServer is KnifeItem || val.currentlyHeldObject is Shovel || val.currentlyHeldObject is KnifeItem) && (!hitUntil.TryGetValue(sender, out var value2) || !(Time.time < value2)))
		{
			hitUntil[sender] = Time.time + 0.65f;
			value.TakeHit(sender);
		}
	}

	internal static bool Eligible(PlayerControllerB player)
	{
		if ((Object)(object)player != (Object)null && player.isPlayerControlled && !player.isPlayerDead && !player.isInHangarShipRoom && !player.inSpecialInteractAnimation)
		{
			return !player.isClimbingLadder;
		}
		return false;
	}

	internal static bool ClearLine(Vector3 from, Vector3 to)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		return !Physics.Linecast(from, to, WallMask, (QueryTriggerInteraction)1);
	}

	internal bool CanSee(PlayerControllerB player, Vector3 point)
	{
		//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_0027: 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_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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)
		Vector3 val = ((Component)player).transform.position + Vector3.up * 1.5f;
		if (Vector3.Angle(GetSignal(player).look, point - val) < 75f)
		{
			return ClearLine(val, point);
		}
		return false;
	}

	internal void EncounterHint(int kind, Vector3 point)
	{
		//IL_002f: 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_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)
		//IL_0051: 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_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayer = LocalPlayer;
		if (hints.Value && !shownHints.Contains(kind) && Eligible(localPlayer) && !(Vector3.Distance(((Component)localPlayer).transform.position, point) > 12f) && ClearLine(((Component)localPlayer).transform.position + Vector3.up, point + Vector3.up))
		{
			shownHints.Add(kind);
			Tip(Balance.Names[kind], Balance.Advice[kind]);
		}
	}

	private static void Tip(string title, string body)
	{
		if ((Object)(object)HUDManager.Instance != (Object)null)
		{
			HUDManager.Instance.DisplayTip(title, body, false, false, "OddCompany");
		}
	}

	private void Unbind()
	{
		if (messages != null)
		{
			messages.UnregisterNamedMessageHandler("OddCompany.v1");
		}
		messages = null;
		network = null;
		acknowledged = false;
		active = false;
		peers.Clear();
		signals.Clear();
		shownHints.Clear();
		sequence = 0;
		localHurtUntil = 0f;
		Sightings.Reset();
		if ((Object)(object)Curse != (Object)null)
		{
			Curse.Reset();
		}
		if ((Object)(object)combat != (Object)null)
		{
			combat.Reset();
		}
		Clear();
	}

	private void OnDestroy()
	{
		Unbind();
		if ((Object)(object)Face != (Object)null)
		{
			Object.Destroy((Object)(object)Face);
		}
		AudioClip[,] sounds = Sounds;
		foreach (AudioClip val in sounds)
		{
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}
		AudioClip[] curseSounds = CurseSounds;
		foreach (AudioClip val2 in curseSounds)
		{
			if ((Object)(object)val2 != (Object)null)
			{
				Object.Destroy((Object)(object)val2);
			}
		}
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}
}
[Serializable]
public sealed class Signal
{
	public bool sprint;

	public bool crouch;

	public bool sellBodies;

	public int witness;

	public Vector3 look;

	[NonSerialized]
	public float received;
}
[Serializable]
public sealed class Packet
{
	public int op;

	public int version;

	public int serial;

	public int id;

	public int kind;

	public int damage;

	public int grabAction;

	public int beats;

	public int mistakes;

	public float stamina;

	public bool gentle;

	public Signal signal;

	public CreatureState[] monsters;

	public CurseState curse;

	public GrabState grab;
}
[Serializable]
public sealed class CreatureState
{
	public int id;

	public int kind;

	public int phase;

	public int cue;

	public int mood;

	public int cueRole;

	public bool outside;

	public bool dead;

	public Vector3 position;

	public Vector3 aim;

	public float yaw;

	public float charge;

	public Vector3[] marks;
}
public sealed class Creature : MonoBehaviour, IHittable
{
	private struct Mark
	{
		public Vector3 point;

		public float time;

		public Mark(Vector3 position, float when)
		{
			//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)
			point = position;
			time = when;
		}
	}

	public int Id;

	public int Kind;

	public float Born;

	public Vector3 Home;

	public bool Outside;

	public bool Dead;

	private readonly Dictionary<ulong, float> gaze = new Dictionary<ulong, float>();

	private bool host;

	private NavMeshAgent agent;

	private Visuals visual;

	private CreatureState remote;

	private int phase;

	private int cue;

	private int mood;

	private int cueRole = 1;

	private int health = 3;

	private float deadline;

	private float cooldown;

	private float charge;

	private float nextMark;

	private float nextRoam;

	private float stunnedUntil;

	private float alertUntil;

	private float staggerReady;

	private readonly HashSet<ulong> swept = new HashSet<ulong>();

	private Vector3 aim;

	private Vector3 roam;

	private readonly List<Mark> marks = new List<Mark>();

	private readonly Queue<Mark> footsteps = new Queue<Mark>();

	private readonly Dictionary<ulong, float> stillness = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, float> passes = new Dictionary<ulong, float>();

	private readonly Dictionary<ulong, Vector3> lastPosition = new Dictionary<ulong, Vector3>();

	private ulong trailOwner = ulong.MaxValue;

	private Vector3 previousTrail;

	private float trailTick;

	private ulong blackoutTarget = ulong.MaxValue;

	private float blackoutMemory;

	private Vector3 blackoutLastSeen;

	public int Mood => mood;

	public void Initialize(int id, int kind, bool isHost, bool outside)
	{
		//IL_002f: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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)
		Outside = outside;
		Id = id;
		Kind = kind;
		host = isHost;
		Born = Time.time;
		Home = ((Component)this).transform.position;
		health = Balance.Toughness(kind);
		aim = ((Component)this).transform.position + ((Component)this).transform.forward * 5f;
		int num = LayerMask.NameToLayer("Enemies");
		((Component)this).gameObject.layer = ((num >= 0) ? num : 19);
		CapsuleCollider val = ((Component)this).gameObject.AddComponent<CapsuleCollider>();
		((Collider)val).isTrigger = false;
		val.center = Vector3.up;
		val.height = 2f;
		val.radius = 0.65f;
		if (kind == 0)
		{
			val.center = Vector3.up * 1.3f;
			val.height = 2.6f;
			val.radius = 0.85f;
		}
		visual = new Visuals(((Component)this).transform, kind);
		if (host)
		{
			agent = ((Component)this).gameObject.AddComponent<NavMeshAgent>();
			agent.radius = 0.35f;
			agent.height = 1.8f;
			agent.speed = 1.5f;
			agent.angularSpeed = 180f;
			agent.acceleration = 6f;
			agent.stoppingDistance = 0.5f;
			if (kind == 6)
			{
				agent.acceleration = 40f;
			}
			agent.autoTraverseOffMeshLink = false;
			nextMark = Time.time + 5f;
		}
	}

	private void Update()
	{
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0192: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: 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)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: 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_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: 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)
		if ((Object)(object)Plugin.Instance == (Object)null)
		{
			return;
		}
		if (Dead)
		{
			visual.Corpse();
			return;
		}
		if (!host && remote != null)
		{
			((Component)this).transform.position = Vector3.Lerp(((Component)this).transform.position, remote.position, 1f - Mathf.Exp(-12f * Time.deltaTime));
			((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.Euler(0f, remote.yaw, 0f), 1f - Mathf.Exp(-12f * Time.deltaTime));
		}
		if (host && (Object)(object)agent != (Object)null && agent.isOnNavMesh)
		{
			Vector3 desiredVelocity = agent.desiredVelocity;
			if (((Vector3)(ref desiredVelocity)).sqrMagnitude > 0.01f)
			{
				Vector3 val = ((Component)this).transform.position + Vector3.up;
				Vector3 desiredVelocity2 = agent.desiredVelocity;
				if (!Plugin.ClearLine(val, val + ((Vector3)(ref desiredVelocity2)).normalized * 0.85f))
				{
					agent.isStopped = true;
				}
			}
		}
		visual.Animate(phase, mood, charge, aim, Points(), Time.time - Born);
		Plugin.Instance.EncounterHint(Kind, ((Component)this).transform.position);
	}

	public CreatureState State()
	{
		//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_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		CreatureState creatureState = new CreatureState();
		creatureState.id = Id;
		creatureState.kind = Kind;
		creatureState.position = ((Component)this).transform.position;
		creatureState.yaw = ((Component)this).transform.eulerAngles.y;
		creatureState.phase = phase;
		creatureState.cue = cue;
		creatureState.mood = mood;
		creatureState.cueRole = cueRole;
		creatureState.outside = Outside;
		creatureState.dead = Dead;
		creatureState.charge = charge;
		creatureState.aim = aim;
		creatureState.marks = Points();
		return creatureState;
	}

	public void Apply(CreatureState state)
	{
		//IL_000f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		if (state.dead)
		{
			((Component)this).transform.position = state.position;
			((Component)this).transform.rotation = Quaternion.Euler(0f, state.yaw, 0f);
			Die();
			return;
		}
		if (state.cue > cue)
		{
			visual.Sound(state.cueRole);
		}
		cue = state.cue;
		phase = state.phase;
		mood = state.mood;
		cueRole = state.cueRole;
		charge = state.charge;
		aim = state.aim;
		remote = state;
		marks.Clear();
		if (state.marks != null)
		{
			for (int i = 0; i < Mathf.Min(12, state.marks.Length); i++)
			{
				marks.Add(new Mark(state.marks[i], Time.time));
			}
		}
	}

	private Vector3[] Points()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		Vector3[] array = (Vector3[])(object)new Vector3[marks.Count];
		for (int i = 0; i < marks.Count; i++)
		{
			ref Vector3 reference = ref array[i];
			reference = marks[i].point;
		}
		return array;
	}

	private void Cue(int role = 1)
	{
		cue++;
		cueRole = role;
		visual.Sound(role);
	}

	private void Stop()
	{
		if ((Object)(object)agent != (Object)null && agent.isOnNavMesh)
		{
			agent.isStopped = true;
		}
	}

	private void Move(Vector3 destination, float speed)
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: 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)
		if (Outside && (Object)(object)StartOfRound.Instance != (Object)null && Vector3.Distance(destination, StartOfRound.Instance.elevatorTransform.position) < 12f)
		{
			Stop();
		}
		else if (!((Object)(object)agent == (Object)null) && agent.isOnNavMesh)
		{
			NavMeshHit val = default(NavMeshHit);
			if (!NavMesh.SamplePosition(destination, ref val, 2f, -1))
			{
				Stop();
				return;
			}
			agent.isStopped = false;
			agent.speed = speed;
			agent.SetDestination(((NavMeshHit)(ref val)).position);
		}
	}

	private void Roam()
	{
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		mood = 0;
		if (Time.time >= nextRoam || Vector3.Distance(((Component)this).transform.position, roam) < 1.5f)
		{
			nextRoam = Time.time + 9f;
			GameObject[] array = (((Object)(object)RoundManager.Instance == (Object)null) ? null : (Outside ? RoundManager.Instance.outsideAINodes : RoundManager.Instance.insideAINodes));
			roam = Home;
			if (array != null && array.Length > 0)
			{
				for (int i = 0; i < 10; i++)
				{
					GameObject val = array[Random.Range(0, array.Length)];
					if ((Object)(object)val != (Object)null && Vector3.Distance(val.transform.position, ((Component)this).transform.position) < 22f)
					{
						roam = val.transform.position;
						break;
					}
				}
			}
		}
		Move(roam, 1.2f);
	}

	private PlayerControllerB Nearest(float range, bool requireSight)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB result = null;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (EligibleFor(val))
			{
				float num = Vector3.Distance(((Component)this).transform.position, ((Component)val).transform.position);
				if (!(num >= range) && (!requireSight || Sees(val)))
				{
					range = num;
					result = val;
				}
			}
		}
		return result;
	}

	private bool Sees(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_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: 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)
		return Plugin.ClearLine(((Component)this).transform.position + Vector3.up, ((Component)player).transform.position + Vector3.up);
	}

	public bool EligibleFor(PlayerControllerB player)
	{
		if (Plugin.Eligible(player))
		{
			return Balance.ZoneMatches(player.isInsideFactory, Outside);
		}
		return false;
	}

	private float Distance(PlayerControllerB player)
	{
		//IL_0006: 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)
		return Vector3.Distance(((Component)this).transform.position, ((Component)player).transform.position);
	}

	private void Face(Vector3 point)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0032: 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)
		Vector3 val = point - ((Component)this).transform.position;
		val.y = 0f;
		if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
		{
			((Component)this).transform.rotation = Quaternion.LookRotation(val);
		}
	}

	public void Tick()
	{
		if (Dead || !host || (Object)(object)agent == (Object)null || !agent.isOnNavMesh)
		{
			return;
		}
		mood = 0;
		if (Kind == 5)
		{
			Passenger();
			return;
		}
		if (Time.time - Born < 6f || Time.time < stunnedUntil)
		{
			mood = 4;
			Stop();
			return;
		}
		switch (Kind)
		{
		case 0:
			Pligga();
			break;
		case 1:
			Hushloom();
			break;
		case 2:
			Backstitch();
			break;
		case 3:
			Tollbud();
			break;
		case 4:
			Foldback();
			break;
		case 6:
			Blackout();
			break;
		case 5:
			break;
		}
	}

	private void Pligga()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00db: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: 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)
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_029b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_0144: Unknown result type (might be due to invalid IL or missing references)
		//IL_014f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0154: Unknown result type (might be due to invalid IL or missing references)
		//IL_0159: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: 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_0163: 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)
		if (phase == 1)
		{
			mood = 2;
			Stop();
			Face(aim);
			charge = 1f - Mathf.Clamp01((deadline - Time.time) / 0.8f);
			if (Time.time < deadline)
			{
				return;
			}
			phase = 2;
			mood = 3;
			deadline = Time.time + 1f;
			charge = 0f;
			swept.Clear();
			Cue(2);
		}
		if (phase == 2)
		{
			mood = 3;
			Stop();
			float previous = charge;
			charge = 1f - Mathf.Clamp01(deadline - Time.time);
			Vector3 val = aim - ((Component)this).transform.position;
			val.y = 0f;
			((Vector3)(ref val)).Normalize();
			Vector3 val2 = Vector3.Cross(Vector3.up, val);
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val3 in allPlayerScripts)
			{
				if (EligibleFor(val3) && !swept.Contains(val3.actualClientId))
				{
					Vector3 val4 = ((Component)val3).transform.position - ((Component)this).transform.position;
					if (Balance.InSweep(Vector3.Dot(val4, val), Vector3.Dot(val4, val2), val4.y, previous, charge) && Sees(val3) && Plugin.Instance.Hurt(val3, 35, 0.3f, Kind))
					{
						swept.Add(val3.actualClientId);
					}
				}
			}
			if (Time.time < deadline)
			{
				return;
			}
			phase = 0;
			charge = 0f;
			cooldown = Time.time + 3.5f;
		}
		PlayerControllerB val5 = Nearest(26f, requireSight: true);
		if ((Object)(object)val5 == (Object)null)
		{
			Roam();
			return;
		}
		mood = 1;
		if (Distance(val5) < 9f && Time.time >= cooldown)
		{
			aim = ((Component)val5).transform.position;
			phase = 1;
			mood = 2;
			deadline = Time.time + 0.8f;
			Stop();
			Face(aim);
			Cue();
		}
		else if (Distance(val5) > 3f)
		{
			Move(((Component)val5).transform.position, 2.8f);
		}
		else
		{
			Stop();
		}
	}

	private void Hushloom()
	{
		//IL_01de: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB val = null;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val2 in allPlayerScripts)
		{
			if (EligibleFor(val2) && Distance(val2) < 18f && Sees(val2) && Plugin.Instance.GetSignal(val2).sprint)
			{
				val = val2;
				break;
			}
		}
		if (phase == 1)
		{
			mood = 2;
			Stop();
			if (Time.time < deadline)
			{
				return;
			}
			PlayerControllerB[] allPlayerScripts2 = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB player in allPlayerScripts2)
			{
				if (EligibleFor(player) && Distance(player) < 10f && Sees(player) && !Plugin.Instance.GetSignal(player).crouch)
				{
					Plugin.Instance.Hurt(player, 30, 0.4f, Kind);
				}
			}
			phase = 2;
			mood = 3;
			deadline = Time.time + 0.6f;
			Cue(2);
			return;
		}
		if (phase == 2)
		{
			mood = 3;
			if (Time.time < deadline)
			{
				return;
			}
			phase = 0;
			charge = 0f;
			cooldown = Time.time + 3f;
		}
		charge = Mathf.Clamp01(charge + (((Object)(object)val == (Object)null) ? (-0.025f) : 0.25f));
		if (charge >= 1f && Time.time >= cooldown)
		{
			phase = 1;
			mood = 2;
			deadline = Time.time + 2f;
			Stop();
			Cue();
		}
		else if ((Object)(object)val != (Object)null)
		{
			mood = 1;
			Move(((Component)val).transform.position, 3.5f);
		}
		else
		{
			mood = 0;
			Roam();
		}
	}

	private void Backstitch()
	{
		//IL_003c: 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_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01db: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		Roam();
		PlayerControllerB val = Nearest(16f, requireSight: true);
		if ((Object)(object)val != (Object)null && !Plugin.Instance.GetSignal(val).crouch)
		{
			mood = 1;
			Move(((Component)val).transform.position, 3.2f);
		}
		for (int num = marks.Count - 1; num >= 0; num--)
		{
			if (Time.time - marks[num].time > 20f)
			{
				marks.RemoveAt(num);
			}
		}
		if (Time.time >= nextMark)
		{
			nextMark = Time.time + 1.2f;
			if (marks.Count == 0 || Vector3.Distance(marks[marks.Count - 1].point, ((Component)this).transform.position) > 1f)
			{
				marks.Add(new Mark(((Component)this).transform.position, Time.time));
				Cue(2);
				if (marks.Count > 8)
				{
					marks.RemoveAt(0);
				}
			}
		}
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val2 in allPlayerScripts)
		{
			if (!EligibleFor(val2) || Plugin.Instance.GetSignal(val2).crouch)
			{
				continue;
			}
			foreach (Mark mark in marks)
			{
				if (Time.time - mark.time > 1.5f && Vector3.Distance(((Component)val2).transform.position, mark.point) < 1.5f && Plugin.ClearLine(mark.point + Vector3.up * 0.5f, ((Component)val2).transform.position + Vector3.up))
				{
					alertUntil = Time.time + 3f;
					if (Plugin.Instance.Hurt(val2, 22, 0.35f, Kind))
					{
						Cue(2);
					}
					break;
				}
			}
		}
		phase = ((marks.Count > 0) ? 1 : 0);
		if (Time.time < alertUntil)
		{
			mood = 1;
		}
	}

	private void Tollbud()
	{
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB val = Nearest(9f, requireSight: true);
		if ((Object)(object)val == (Object)null)
		{
			phase = 0;
			charge = 0f;
			stillness.Clear();
			if (Vector3.Distance(((Component)this).transform.position, Home) > 0.8f)
			{
				Move(Home, 1f);
			}
			else
			{
				Stop();
			}
			return;
		}
		Stop();
		Face(((Component)val).transform.position);
		mood = 2;
		bool flag = true;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val2 in allPlayerScripts)
		{
			if (!EligibleFor(val2) || Distance(val2) > 9f || !Sees(val2))
			{
				continue;
			}
			ulong actualClientId = val2.actualClientId;
			Vector3 value;
			bool flag2 = lastPosition.TryGetValue(actualClientId, out value);
			lastPosition[actualClientId] = ((Component)val2).transform.position;
			if (!passes.TryGetValue(actualClientId, out var value2) || !(Time.time < value2))
			{
				flag = false;
				stillness.TryGetValue(actualClientId, out var value3);
				value3 = ((flag2 && Vector3.Distance(value, ((Component)val2).transform.position) < 0.12f) ? (value3 + 0.2f) : 0f);
				stillness[actualClientId] = value3;
				if (value3 >= 2f)
				{
					passes[actualClientId] = Time.time + 10f;
					stillness[actualClientId] = 0f;
				}
				else if (phase == 1 && Time.time >= deadline && Distance(val2) < 6f)
				{
					Plugin.Instance.Hurt(val2, 40, 0.4f, Kind);
				}
			}
		}
		if (flag)
		{
			phase = 2;
			mood = 0;
			charge = 0f;
			return;
		}
		if (phase != 1)
		{
			phase = 1;
			deadline = Time.time + 3f;
			Cue();
		}
		charge = 1f - Mathf.Clamp01((deadline - Time.time) / 3f);
		if (Time.time >= deadline)
		{
			mood = 3;
			deadline = Time.time + 3f;
			Cue(2);
		}
	}

	private void Foldback()
	{
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0232: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB val = null;
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val2 in allPlayerScripts)
		{
			if (EligibleFor(val2) && val2.actualClientId == trailOwner && Distance(val2) < 40f && Time.time < alertUntil)
			{
				val = val2;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Nearest(30f, requireSight: true);
		}
		if ((Object)(object)val != (Object)null && Sees(val))
		{
			alertUntil = Time.time + 8f;
		}
		if ((Object)(object)val == (Object)null)
		{
			footsteps.Clear();
			marks.Clear();
			trailOwner = ulong.MaxValue;
			phase = 0;
			Roam();
			return;
		}
		mood = 1;
		if (val.actualClientId != trailOwner)
		{
			footsteps.Clear();
			marks.Clear();
			trailOwner = val.actualClientId;
			previousTrail = ((Component)val).transform.position;
			phase = 0;
			cooldown = Time.time + 3f;
			Cue();
		}
		if (Time.time >= trailTick)
		{
			trailTick = Time.time + 0.2f;
			footsteps.Enqueue(new Mark(((Component)val).transform.position, Time.time));
			while (footsteps.Count > 20)
			{
				footsteps.Dequeue();
			}
		}
		if (footsteps.Count > 0 && Time.time - footsteps.Peek().time >= 2.5f)
		{
			Mark mark = footsteps.Dequeue();
			if (Vector3.Distance(previousTrail, mark.point) > 10f)
			{
				footsteps.Clear();
				marks.Clear();
				phase = 0;
				mood = 0;
				cooldown = Time.time + 7f;
				Stop();
				return;
			}
			previousTrail = mark.point;
			aim = mark.point;
			Move(aim, 5f);
			phase = 1;
		}
		else if (phase == 0)
		{
			Stop();
		}
		marks.Clear();
		int num = 0;
		foreach (Mark footstep in footsteps)
		{
			if (num++ % 2 == 0 && marks.Count < 6)
			{
				marks.Add(footstep);
			}
		}
		charge = Mathf.Clamp01((Time.time - Born) / 7f);
		if (phase != 1 || !(Time.time >= cooldown))
		{
			return;
		}
		PlayerControllerB[] allPlayerScripts2 = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB player in allPlayerScripts2)
		{
			if (EligibleFor(player) && Distance(player) < 1.7f && Sees(player) && Plugin.Instance.Hurt(player, 35, 0.3f, Kind))
			{
				mood = 3;
				Cue(2);
			}
		}
	}

	private void Blackout()
	{
		//IL_0063: 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_0135: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0234: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_025c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		//IL_039b: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_030b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0312: Unknown result type (might be due to invalid IL or missing references)
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0333: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Unknown result type (might be due to invalid IL or missing references)
		if (Plugin.Instance.Grab.Holds(Id))
		{
			phase = 3;
			mood = 3;
			Stop();
			return;
		}
		if (Time.time < cooldown)
		{
			phase = 0;
			mood = 0;
			Stop();
			return;
		}
		if (phase == 2)
		{
			mood = 3;
			Move(aim, 11f);
			PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
			foreach (PlayerControllerB val in allPlayerScripts)
			{
				if (EligibleFor(val) && Balance.BlackoutCanGrab(Distance(val), Sees(val), eligible: true) && Vector3.Angle(((Component)this).transform.forward, ((Component)val).transform.position - ((Component)this).transform.position) < 65f && Plugin.Instance.Grab.Begin(Id, val))
				{
					phase = 3;
					Stop();
					Cue(2);
					return;
				}
			}
			if (Time.time >= deadline || Vector3.Distance(((Component)this).transform.position, aim) < 0.6f)
			{
				phase = 0;
				charge = 0f;
				cooldown = Time.time + 1.6f;
				Stop();
			}
			return;
		}
		PlayerControllerB val2 = null;
		PlayerControllerB[] allPlayerScripts2 = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val3 in allPlayerScripts2)
		{
			if (EligibleFor(val3) && val3.actualClientId == blackoutTarget && Distance(val3) < 34f && Time.time < blackoutMemory)
			{
				val2 = val3;
				break;
			}
		}
		if ((Object)(object)val2 == (Object)null)
		{
			val2 = Nearest(34f, requireSight: true);
		}
		if ((Object)(object)val2 == (Object)null)
		{
			phase = 0;
			charge = 0f;
			Roam();
			return;
		}
		bool flag = Sees(val2);
		if (flag)
		{
			blackoutTarget = val2.actualClientId;
			blackoutMemory = Time.time + 6f;
			blackoutLastSeen = ((Component)val2).transform.position;
		}
		if (!flag)
		{
			phase = 0;
			charge = 0f;
			mood = 1;
			Move(blackoutLastSeen, 5.2f);
		}
		else if (phase == 1)
		{
			mood = 2;
			Stop();
			charge = 1f - Mathf.Clamp01((deadline - Time.time) / 0.6f);
			if (charge < 0.5f)
			{
				aim = ((Component)val2).transform.position;
				Face(aim);
			}
			if (!(Time.time < deadline))
			{
				Vector3 val4 = aim - ((Component)this).transform.position;
				val4.y = 0f;
				aim = ((Component)this).transform.position + ((Vector3)(ref val4)).normalized * Mathf.Min(9f, ((Vector3)(ref val4)).magnitude + 3.5f);
				phase = 2;
				mood = 3;
				deadline = Time.time + 0.85f;
				Cue(2);
			}
		}
		else
		{
			mood = 1;
			Move(((Component)val2).transform.position, 5.2f);
			if (Distance(val2) <= 5f)
			{
				aim = ((Component)val2).transform.position;
				phase = 1;
				mood = 2;
				charge = 0f;
				deadline = Time.time + 0.6f;
				Stop();
				Face(aim);
				Cue();
			}
		}
	}

	public void ReleasedGrab()
	{
		phase = 0;
		charge = 0f;
		cooldown = Time.time + 8f;
		stunnedUntil = Time.time + 2f;
		Stop();
	}

	private void Passenger()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0076: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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)
		Stop();
		if (Plugin.Instance.Curse.Marked)
		{
			mood = 2;
			return;
		}
		PlayerControllerB[] allPlayerScripts = StartOfRound.Instance.allPlayerScripts;
		foreach (PlayerControllerB val in allPlayerScripts)
		{
			if (!((Object)(object)val == (Object)null))
			{
				Signal signal = Plugin.Instance.GetSignal(val);
				Vector3 val2 = ((Component)this).transform.position + Vector3.up * 2.2f - (((Component)val).transform.position + Vector3.up * 1.5f);
				bool flag = Balance.CanMark(((Vector3)(ref val2)).magnitude, Vector3.Angle(signal.look, val2), Sees(val), signal.witness == Id, EligibleFor(val));
				gaze.TryGetValue(val.actualClientId, out var value);
				value = (flag ? (value + 0.2f) : 0f);
				gaze[val.actualClientId] = value;
				if (flag)
				{
					Face(((Component)val).transform.position);
					mood = 1;
				}
				if (value >= 0.6f && Plugin.Instance.Curse.Mark(val, Id))
				{
					mood = 2;
					Cue();
					break;
				}
			}
		}
	}

	public bool Hit(int force, Vector3 hitDirection, PlayerControllerB playerWhoHit, bool playHitSFX, int hitID)
	{
		if (!Dead && (Object)(object)Plugin.Instance != (Object)null && force > 0)
		{
			Plugin.Instance.RequestHit(Id, playerWhoHit);
		}
		return true;
	}

	public void TakeHit(ulong attacker)
	{
		if (!Dead)
		{
			bool flag = Kind == 6 && Plugin.Instance.Grab.Holds(Id);
			if (flag)
			{
				Plugin.Instance.Grab.Rescue(Id, attacker);
			}
			health--;
			if (!flag && Time.time >= staggerReady)
			{
				staggerReady = Time.time + 3f;
				stunnedUntil = Time.time + 0.65f;
				phase = 0;
				charge = 0f;
				cooldown = Time.time + 1f;
				mood = 4;
				Stop();
				Cue(2);
			}
			if (health <= 0)
			{
				Plugin.Instance.Killed(this);
			}
		}
	}

	public void Die()
	{
		if (!Dead)
		{
			Dead = true;
			Stop();
			if ((Object)(object)agent != (Object)null)
			{
				((Behaviour)agent).enabled = false;
			}
			Collider[] componentsInChildren = ((Component)this).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				val.enabled = false;
			}
			visual.Corpse();
		}
	}

	private void OnDestroy()
	{
		if (visual != null)
		{
			visual.Dispose();
		}
	}
}
public sealed class Visuals
{
	private readonly Transform root;

	private readonly Transform body;

	private readonly int kind;

	private readonly List<Material> materials = new List<Material>();

	private readonly List<Mesh> meshes = new List<Mesh>();

	private readonly List<Transform> limbs = new List<Transform>();

	private readonly List<Quaternion> restRotations = new List<Quaternion>();

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

	private readonly List<LineRenderer> marks = new List<LineRenderer>();

	private readonly AudioSource sound;

	private readonly AudioSource ambience;

	private readonly AudioSource pursuit;

	private readonly AudioSource sighting;

	private readonly AudioLowPassFilter soundFilter;

	private readonly AudioLowPassFilter ambienceFilter;

	private readonly AudioLowPassFilter pursuitFilter;

	private float nextOcclusion;

	private float occlusion = 1f;

	private float mix;

	private float chaseMix;

	private float sightTime;

	private float gait;

	private float speed;

	private float strikeAt = -10f;

	private Vector3 lastPosition;

	private Quaternion headRest;

	private Vector3 headScale;

	private readonly Material main;

	private readonly Material bright;

	private readonly Material dark;

	private LineRenderer ring;

	private LineRenderer tongue;

	private LineRenderer guide;

	private Transform head;

	private RefinedModel refined;

	private static readonly Color[] Colors = (Color[])(object)new Color[7]
	{
		new Color(0.39f, 0.31f, 0.27f),
		new Color(0.29f, 0.28f, 0.25f),
		new Color(0.25f, 0.3f, 0.27f),
		new Color(0.33f, 0.25f, 0.15f),
		new Color(0.47f, 0.46f, 0.38f),
		new Color(0.32f, 0.045f, 0.04f),
		new Color(0.12f, 0.13f, 0.12f)
	};

	private readonly Transform[] blackoutArms = (Transform[])(object)new Transform[2];

	private readonly Transform[] blackoutElbows = (Transform[])(object)new Transform[2];

	private readonly Transform[] blackoutHips = (Transform[])(object)new Transform[2];

	private readonly Transform[] blackoutKnees = (Transform[])(object)new Transform[2];

	private Transform blackoutJaw;

	public Visuals(Transform parent, int creatureKind)
	{
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0188: Unknown result type (might be due to invalid IL or missing references)
		//IL_018d: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0311: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_056c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0573: Expected O, but got Unknown
		//IL_058d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0597: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
		root = parent;
		kind = creatureKind;
		body = new GameObject("Body").transform;
		body.SetParent(root, false);
		main = Material(Colors[kind], glow: false);
		Color[] array = (Color[])(object)new Color[7]
		{
			new Color(0.43f, 0.17f, 0.14f),
			new Color(0.4f, 0.37f, 0.49f),
			new Color(0.25f, 0.53f, 0.48f),
			new Color(0.65f, 0.42f, 0.16f),
			new Color(0.54f, 0.55f, 0.39f),
			new Color(0.29f, 0.025f, 0.022f),
			new Color(0.65f, 0.64f, 0.51f)
		};
		bright = Material(array[kind], glow: true);
		dark = Material(new Color(0.045f, 0.047f, 0.043f), glow: false);
		switch (kind)
		{
		case 0:
			BuildPligga();
			break;
		case 1:
			BuildHushloom();
			break;
		case 2:
			BuildBackstitch();
			break;
		case 3:
			BuildTollbud();
			break;
		case 4:
			BuildFoldback();
			break;
		case 5:
			BuildPassenger();
			break;
		case 6:
			BuildBlackout();
			break;
		}
		if (kind == 0 || kind == 4 || kind == 5)
		{
			RigHead();
		}
		if (kind == 0)
		{
			body.localScale = new Vector3(1.3f, 1.25f, 1.3f);
		}
		headRest = head.localRotation;
		headScale = head.localScale;
		lastPosition = root.position;
		foreach (Transform limb in limbs)
		{
			restRotations.Add(limb.localRotation);
			restPositions.Add(limb.localPosition);
		}
		Renderer[] componentsInChildren = ((Component)body).GetComponentsInChildren<Renderer>();
		refined = RefinedModel.TryCreate(body, kind);
		if (refined != null)
		{
			Renderer[] array2 = componentsInChildren;
			foreach (Renderer val in array2)
			{
				val.enabled = false;
			}
		}
		ring = Line("Warning ring", bright, 0.045f, loop: true);
		tongue = Line("Tongue", main, 0.13f, loop: false);
		guide = Line("Trail guide", bright, 0.028f, loop: false);
		for (int j = 0; j < 8; j++)
		{
			marks.Add(Line("Trail " + j, bright, 0.04f, loop: true));
		}
		sound = Audio("Warning voice", loop: false);
		ambience = Audio("Encounter bed", loop: true);
		pursuit = Audio("Pursuit bed", loop: true);
		sighting = Audio("First sighting", loop: false);
		sighting.spatialBlend = 0f;
		sighting.priority = 100;
		soundFilter = ((Component)sound).gameObject.AddComponent<AudioLowPassFilter>();
		ambienceFilter = ((Component)ambience).gameObject.AddComponent<AudioLowPassFilter>();
		pursuitFilter = ((Component)pursuit).gameObject.AddComponent<AudioLowPassFilter>();
		soundFilter.lowpassResonanceQ = (ambienceFilter.lowpassResonanceQ = 1f);
		ambience.clip = Plugin.Instance.Sounds[kind, 0];
		ambience.volume = 0f;
		ambience.Play();
		pursuit.clip = Plugin.Instance.Sounds[kind, 3];
		pursuit.volume = 0f;
		pursuit.Play();
		GameObject val2 = new GameObject("ScanNode");
		val2.transform.SetParent(root, false);
		val2.transform.localPosition = Vector3.up * 1.2f;
		int num2 = LayerMask.NameToLayer("ScanNode");
		val2.layer = ((num2 >= 0) ? num2 : 22);
		BoxCollider val3 = val2.AddComponent<BoxCollider>();
		((Collider)val3).isTrigger = true;
		val3.size = Vector3.one;
		ScanNodeProperties val4 = val2.AddComponent<ScanNodeProperties>();
		val4.headerText = Balance.Names[kind];
		val4.subText = Balance.Advice[kind];
		val4.minRange = 0;
		val4.maxRange = 18;
		val4.requiresLineOfSight = true;
		val4.nodeType = 1;
		val4.creatureScanID = -1;
	}

	private Material Material(Color color, bool glow)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: 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_00c2: Unknown result type (might be due to invalid IL or missing references)
		Shader val = Shader.Find(glow ? "HDRP/Unlit" : "HDRP/Lit");
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("HDRP/Unlit");
		}
		if ((Object)(object)val == (Object)null)
		{
			val = Shader.Find("Unlit/Color");
		}
		Material val2 = new Material(val);
		if (val2.HasProperty("_BaseColor"))
		{
			val2.SetColor("_BaseColor", color);
		}
		if (val2.HasProperty("_UnlitColor"))
		{
			val2.SetColor("_UnlitColor", color);
		}
		if (val2.HasProperty("_Color"))
		{
			val2.SetColor("_Color", color);
		}
		if (val2.HasProperty("_Smoothness"))
		{
			val2.SetFloat("_Smoothness", 0.08f);
		}
		if (val2.HasProperty("_EmissiveColor"))
		{
			val2.SetColor("_EmissiveColor", glow ? color : Color.black);
		}
		val2.enableInstancing = true;
		materials.Add(val2);
		return val2;
	}

	private void RigHead()
	{
		//IL_0005: 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)
		Transform transform = new GameObject("Head pivot").transform;
		transform.SetParent(body, false);
		transform.localPosition = head.localPosition;
		for (int num = body.childCount - 1; num >= 0; num--)
		{
			Transform child = body.GetChild(num);
			if ((Object)(object)child == (Object)(object)head || ((Object)child).name == "Photo face" || ((Object)child).name == "Mask seam" || ((Object)child).name == "Tongue tip" || ((Object)child).name == "Eye slit" || ((Object)child).name.StartsWith("Passenger face") || ((Object)child).name.StartsWith("Maw"))
			{
				child.SetParent(transform, true);
			}
		}
		head = transform;
	}

	private Transform Shape(string name, PrimitiveType type, Vector3 position, Vector3 scale, Material material)
	{
		//IL_0000: 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_0032: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = GameObject.CreatePrimitive(type);
		((Object)val).name = name;
		val.transform.SetParent(body, false);
		val.transform.localPosition = position;
		val.transform.localScale = scale;
		Collider component = val.GetComponent<Collider>();
		component.enabled = false;
		Object.Destroy((Object)(object)component);
		val.GetComponent<Renderer>().sharedMaterial = material;
		return val.transform;
	}

	private Transform Bone(string name, Vector3 from, Vector3 to, float width, Material material)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0004: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: 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_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = (from + to) * 0.5f;
		Vector3 val = to - from;
		Transform val2 = Shape(name, (PrimitiveType)2, position, new Vector3(width, ((Vector3)(ref val)).magnitude * 0.5f, width), material);
		val2.localRotation = Quaternion.FromToRotation(Vector3.up, to - from);
		return val2;
	}

	private Transform Sheet(string name, Vector3[] vertices, Material material)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		Mesh val = new Mesh();
		((Object)val).name = name;
		Vector3[] array = (Vector3[])(object)new Vector3[vertices.Length * 2];
		Array.Copy(vertices, 0, array, 0, vertices.Length);
		Array.Copy(vertices, 0, array, vertices.Length, vertices.Length);
		int[] array2 = new int[(vertices.Length - 2) * 6];
		for (int i = 0; i < vertices.Length - 2; i++)
		{
			int num = i * 6;
			array2[num] = 0;
			array2[num + 1] = i + 1;
			array2[num + 2] = i + 2;
			array2[num + 3] = vertices.Length;
			array2[num + 4] = vertices.Length + i + 2;
			array2[num + 5] = vertices.Length + i + 1;
		}
		val.vertices = array;
		val.triangles = array2;
		val.RecalculateNormals();
		val.RecalculateBounds();
		meshes.Add(val);
		GameObject val2 = new GameObject(name);
		val2.transform.SetParent(body, false);
		val2.AddComponent<MeshFilter>().sharedMesh = val;
		((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = material;
		return val2.transform;
	}

	private AudioSource Audio(string name, bool loop)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(name);
		val.transform.SetParent(root, false);
		val.transform.localPosition = Vector3.up;
		AudioSource val2 = val.AddComponent<AudioSource>();
		val2.playOnAwake = false;
		val2.spatialBlend = 1f;
		val2.rolloffMode = (AudioRolloffMode)1;
		val2.minDistance = 2f;
		val2.maxDistance = (loop ? 21 : 24);
		val2.dopplerLevel = 0f;
		val2.loop = loop;
		val2.volume = 0f;
		val2.priority = (loop ? 180 : 80);
		PlayerControllerB localPlayer = Plugin.LocalPlayer;
		if ((Object)(object)localPlayer != (Object)null && (Object)(object)localPlayer.movementAudio != (Object)null)
		{
			val2.outputAudioMixerGroup = localPlayer.movementAudio.outputAudioMixerGroup;
		}
		return val2;
	}

	private void MixAudio(int mood, float charge)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayer = Plugin.LocalPlayer;
		bool flag = Plugin.Eligible(localPlayer);
		if (Time.time >= nextOcclusion)
		{
			nextOcclusion = Time.time + 0.2f;
			occlusion = ((flag && !Plugin.ClearLine(root.position + Vector3.up, ((Component)localPlayer).transform.position + Vector3.up)) ? 0.28f : 1f);
		}
		float num = (flag ? 1 : 0);
		if (flag)
		{
			float num2 = Vector3.Distance(root.position, ((Component)localPlayer).transform.position);
			foreach (Creature creature in Plugin.Instance.Creatures)
			{
				if ((Object)(object)creature != (Object)null && (Object)(object)((Component)creature).transform != (Object)(object)root && Vector3.Distance(((Component)creature).transform.position, ((Component)localPlayer).transform.position) + 1f < num2)
				{
					num *= 0.35f;
					break;
				}
			}
			if (num2 > 24f)
			{
				num = 0f;
			}
		}
		mix = Mathf.MoveTowards(mix, num, Time.deltaTime * 0.8f);
		chaseMix = Mathf.MoveTowards(chaseMix, (float)((mood >= 1 && mood <= 3) ? 1 : 0), Time.deltaTime * 1.5f);
		float num3 = mix * Plugin.Instance.AmbienceVolume * occlusion;
		float num4 = (sound.isPlaying ? 0.4f : 1f);
		ambience.volume = num3 * (1f - chaseMix) * num4;
		pursuit.volume = num3 * chaseMix * num4;
		sound.volume = (flag ? (Plugin.Instance.WarningVolume * Mathf.Max(0.5f, occlusion)) : 0f);
		float num5 = ((occlusion < 0.5f) ? 1200 : 16000);
		ambienceFilter.cutoffFrequency = Mathf.Lerp(ambienceFilter.cutoffFrequency, num5, Time.deltaTime * 6f);
		pursuitFilter.cutoffFrequency = Mathf.Lerp(pursuitFilter.cutoffFrequency, num5, Time.deltaTime * 6f);
		soundFilter.cutoffFrequency = Mathf.Lerp(soundFilter.cutoffFrequency, (float)((occlusion < 0.5f) ? 2400 : 18000), Time.deltaTime * 6f);
		if (!flag)
		{
			sighting.Stop();
		}
	}

	private void CheckSighting(int mood)
	{
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0051: 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_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		PlayerControllerB localPlayer = Plugin.LocalPlayer;
		if (!Plugin.Eligible(localPlayer) || (Object)(object)localPlayer.gameplayCamera == (Object)null)
		{
			sightTime = 0f;
			return;
		}
		Camera gameplayCamera = localPlayer.gameplayCamera;
		Vector3 val = root.position + Vector3.up * 1.35f;
		Vector3 val2 = gameplayCamera.WorldToViewportPoint(val);
		bool inView = val2.z > 0f && val2.x > 0.12f && val2.x < 0.88f && val2.y > 0.08f && val2.y < 0.92f;
		bool flag = SightingGate.Visible(Vector3.Distance(((Component)gameplayCamera).transform.position, val), inView, Plugin.ClearLine(((Component)gameplayCamera).transform.position, val), eligible: true);
		sightTime = (flag ? (sightTime + Time.d