Decompiled source of RockyCompanion v0.1.0

RockyCompanion.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RockyCompanion")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+be072e973c1ecf412ca3aca9ead818d1446a3c90")]
[assembly: AssemblyProduct("RockyCompanion")]
[assembly: AssemblyTitle("RockyCompanion")]
[assembly: AssemblyVersion("0.1.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RockyCompanion
{
	internal sealed class Senses
	{
		private static readonly HashSet<string> Ignore = new HashSet<string> { "DoublewingAI", "DocileLocustBeesAI" };

		private float _next;

		private float _lastDist = -1f;

		private EnemyAI _last;

		internal static int Count;

		internal static string LastWord;

		public void Update(Rocky rocky)
		{
			//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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Warnings.Value || Time.time < _next)
			{
				return;
			}
			_next = Time.time + 0.5f;
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)instance == (Object)null || instance.SpawnedEnemies == null)
			{
				return;
			}
			Vector3 position = ((Component)rocky).transform.position;
			bool flag = position.y < -80f;
			float num = Mathf.Max(4f, Plugin.WarningRadius.Value);
			EnemyAI val = null;
			float num2 = num;
			foreach (EnemyAI spawnedEnemy in instance.SpawnedEnemies)
			{
				if (!((Object)(object)spawnedEnemy == (Object)null) && !spawnedEnemy.isEnemyDead && !Ignore.Contains(((object)spawnedEnemy).GetType().Name) && ((Component)spawnedEnemy).transform.position.y < -80f == flag)
				{
					float num3 = Vector3.Distance(((Component)spawnedEnemy).transform.position, position);
					if (num3 < num2)
					{
						num2 = num3;
						val = spawnedEnemy;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				_last = null;
				return;
			}
			bool num4 = (Object)(object)val == (Object)(object)_last && _lastDist > 0f && num2 < _lastDist - 0.5f;
			_last = val;
			_lastDist = num2;
			string text = (Lethal(val) ? "danger" : ((num2 < 7f) ? "warn_near" : ((num2 < 12f) ? "warn_mid" : "warn_far")));
			float num5;
			switch (text)
			{
			default:
				num5 = 4f;
				break;
			case "warn_mid":
				num5 = 2.5f;
				break;
			case "danger":
			case "warn_near":
				num5 = 1.5f;
				break;
			}
			float num6 = num5;
			if (num4)
			{
				num6 *= 0.7f;
			}
			_next = Time.time + num6;
			Count++;
			LastWord = text;
			rocky.Speak(text, Random.Range(0, int.MaxValue), warning: true);
		}

		private static bool Lethal(EnemyAI ai)
		{
			switch (((object)ai).GetType().Name)
			{
			case "ForestGiantAI":
			case "RadMechAI":
			case "SandWormAI":
				return true;
			case "JesterAI":
				return ai.currentBehaviourStateIndex >= 1;
			case "NutcrackerEnemyAI":
				return ai.currentBehaviourStateIndex == 2;
			default:
				return false;
			}
		}
	}
	internal static class Fend
	{
		private static readonly Dictionary<string, float> Unkillable = new Dictionary<string, float>
		{
			["SpringManAI"] = 6f,
			["JesterAI"] = 4f,
			["BlobAI"] = 6f,
			["ForestGiantAI"] = 4f,
			["RadMechAI"] = 4f,
			["ClaySurgeonAI"] = 4f
		};

		private static float _nextShout;

		private static float _nextKillable;

		private static float _nextCheck;

		private static float _nextGhost;

		private static readonly HashSet<string> Warned = new HashSet<string>();

		private static readonly MethodInfo StopChasing = AccessTools.Method(typeof(DressGirlAI), "StopChasing", (Type[])null, (Type[])null);

		public static void Reset()
		{
			_nextShout = (_nextKillable = (_nextCheck = (_nextGhost = 0f)));
		}

		public static void HostUpdate(Rocky rocky)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _nextCheck)
			{
				return;
			}
			_nextCheck = Time.time + 0.25f;
			if (Time.time < _nextShout)
			{
				return;
			}
			RoundManager instance = RoundManager.Instance;
			StartOfRound instance2 = StartOfRound.Instance;
			if ((Object)(object)instance == (Object)null || (Object)(object)instance2 == (Object)null || instance.SpawnedEnemies == null)
			{
				return;
			}
			Vector3 me = ((Component)rocky).transform.position;
			List<PlayerControllerB> list = instance2.allPlayerScripts.Where((PlayerControllerB p) => (Object)(object)p != (Object)null && p.isPlayerControlled && !p.isPlayerDead && Vector3.Distance(((Component)p).transform.position, me) < 15f).ToList();
			if (list.Count == 0)
			{
				return;
			}
			HashSet<string> hashSet = null;
			foreach (EnemyAI ai in instance.SpawnedEnemies)
			{
				if ((Object)(object)ai == (Object)null || ai.isEnemyDead || (Object)(object)ai.enemyType == (Object)null)
				{
					continue;
				}
				float fromMe = Vector3.Distance(((Component)ai).transform.position, me);
				if (fromMe > 12f)
				{
					continue;
				}
				string cls = ((object)ai).GetType().Name;
				if (cls == "DressGirlAI")
				{
					continue;
				}
				float value;
				bool flag = !Unkillable.TryGetValue(cls, out value);
				if (flag)
				{
					hashSet = hashSet ?? new HashSet<string>(from s in Plugin.FendOffNames.Value.Split(',')
						select s.Trim() into s
						where s.Length > 0
						select s, StringComparer.OrdinalIgnoreCase);
					if (!hashSet.Contains(ai.enemyType.enemyName) && (!Plugin.FendOffKillable.Value || Time.time < _nextKillable))
					{
						continue;
					}
					value = 4f;
				}
				if (!ai.enemyType.canBeStunned)
				{
					if (Warned.Add(ai.enemyType.enemyName))
					{
						Plugin.Log.LogInfo((object)("Rocky: " + ai.enemyType.enemyName + " can't be stunned, so he won't shout at it."));
					}
				}
				else
				{
					if (ai.stunNormalizedTimer > 0f || ai.postStunInvincibilityTimer >= 0f || !list.Any((PlayerControllerB p) => Hunting(ai, cls, p) || (fromMe <= 8f && (Vector3.Distance(((Component)ai).transform.position, ((Component)p).transform.position) < 6f || ((Object)(object)ai.targetPlayer == (Object)(object)p && ai.movingTowardsTargetPlayer)))))
					{
						continue;
					}
					_nextShout = Time.time + Mathf.Max(3f, Plugin.FendCooldown.Value);
					if (flag)
					{
						_nextKillable = Time.time + 40f;
					}
					Plugin.Log.LogInfo((object)$"Rocky: shouts at {ai.enemyType.enemyName} ({value:0} s stun).");
					instance.PlayAudibleNoise(me, 25f, 0.8f, 0, false, 0);
					Net.Shout(((NetworkBehaviour)ai).NetworkObjectId, value);
					if (ai.stunNormalizedTimer <= 0f)
					{
						Plugin.Log.LogInfo((object)("Rocky: the stun on " + ai.enemyType.enemyName + " didn't take; he'll shout again."));
						_nextShout = Time.time + 0.5f;
						if (flag)
						{
							_nextKillable = 0f;
						}
					}
					break;
				}
			}
		}

		private static bool Hunting(EnemyAI ai, string cls, PlayerControllerB p)
		{
			//IL_000d: 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)
			int currentBehaviourStateIndex = ai.currentBehaviourStateIndex;
			float num = Vector3.Distance(((Component)ai).transform.position, ((Component)p).transform.position);
			switch (cls)
			{
			case "SpringManAI":
				if (currentBehaviourStateIndex == 1)
				{
					if (!((Object)(object)ai.targetPlayer == (Object)(object)p))
					{
						return num < 12f;
					}
					return true;
				}
				return false;
			case "JesterAI":
				if (currentBehaviourStateIndex >= 1)
				{
					return num < 15f;
				}
				return false;
			case "ForestGiantAI":
				if (!((Object)(object)ai.inSpecialAnimationWithPlayer == (Object)(object)p))
				{
					if (currentBehaviourStateIndex == 1)
					{
						return num < 15f;
					}
					return false;
				}
				return true;
			default:
				return false;
			}
		}

		public static void ApplyShout(ulong enemyId, float seconds)
		{
			Rocky.Instance?.Shout();
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.SpawnManager.SpawnedObjects.TryGetValue(enemyId, out var value))
			{
				return;
			}
			EnemyAI componentInChildren = ((Component)value).GetComponentInChildren<EnemyAI>();
			if (!((Object)(object)componentInChildren == (Object)null) && !componentInChildren.isEnemyDead)
			{
				componentInChildren.SetEnemyStunned(true, seconds, (PlayerControllerB)null);
				if (componentInChildren.stunNormalizedTimer <= 0f && !singleton.IsServer && (Object)(object)Rocky.Instance != (Object)null)
				{
					((MonoBehaviour)Rocky.Instance).StartCoroutine(StunSoon(componentInChildren, seconds));
				}
			}
		}

		private static IEnumerator StunSoon(EnemyAI ai, float seconds)
		{
			for (float t = 0f; t < 1f; t += Time.deltaTime)
			{
				yield return null;
				if ((Object)(object)ai == (Object)null || ai.isEnemyDead || ai.stunNormalizedTimer > 0f)
				{
					break;
				}
				if (ai.postStunInvincibilityTimer < 0f)
				{
					ai.SetEnemyStunned(true, seconds, (PlayerControllerB)null);
					break;
				}
			}
		}

		public static void LocalGhost(Rocky rocky)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _nextGhost || StopChasing == null)
			{
				return;
			}
			PlayerControllerB val = (((Object)(object)GameNetworkManager.Instance != (Object)null) ? GameNetworkManager.Instance.localPlayerController : null);
			RoundManager instance = RoundManager.Instance;
			if ((Object)(object)val == (Object)null || val.isPlayerDead || (Object)(object)instance == (Object)null || instance.SpawnedEnemies == null || Vector3.Distance(((Component)val).transform.position, ((Component)rocky).transform.position) > 10f)
			{
				return;
			}
			foreach (EnemyAI spawnedEnemy in instance.SpawnedEnemies)
			{
				DressGirlAI val2 = (DressGirlAI)(object)((spawnedEnemy is DressGirlAI) ? spawnedEnemy : null);
				if (val2 != null && !((Object)(object)val2.hauntingPlayer != (Object)(object)val) && ((EnemyAI)val2).currentBehaviourStateIndex == 1 && !(Vector3.Distance(((Component)val2).transform.position, ((Component)val).transform.position) > 12f))
				{
					_nextGhost = Time.time + Mathf.Max(3f, Plugin.FendCooldown.Value);
					Plugin.Log.LogInfo((object)"Rocky: shouts the Ghost Girl away.");
					rocky.Shout();
					StopChasing.Invoke(val2, null);
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB), "SetPlayerSanityLevel")]
	internal static class CompanyPatch
	{
		private static void Prefix(PlayerControllerB __instance, out float __state)
		{
			__state = __instance.insanityLevel;
		}

		private static void Postfix(PlayerControllerB __instance, float __state)
		{
			//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)
			if (!Plugin.Company.Value || !__instance.isPlayerAlone || __instance.insanitySpeedMultiplier <= 0f)
			{
				return;
			}
			Rocky instance = Rocky.Instance;
			if (!((Object)(object)instance == (Object)null) && instance.IsAwake && !(Vector3.Distance(((Component)instance).transform.position, ((Component)__instance).transform.position) > 10f))
			{
				StartOfRound instance2 = StartOfRound.Instance;
				if (!((Object)(object)instance2 == (Object)null) && !instance2.inShipPhase)
				{
					__instance.isPlayerAlone = false;
					__instance.insanitySpeedMultiplier = -1f;
					__instance.insanityLevel = Mathf.MoveTowards(__state, 0f, Time.deltaTime);
				}
			}
		}
	}
	internal static class Assets
	{
		internal static readonly Dictionary<string, List<AudioClip>> Chords = new Dictionary<string, List<AudioClip>>();

		private static readonly Random Rng = new Random();

		internal static GameObject Model { get; private set; }

		public static void Load()
		{
			try
			{
				using (Stream stream = Res("rocky_companion"))
				{
					AssetBundle val = ((stream != null) ? AssetBundle.LoadFromStream(stream) : null);
					if ((Object)(object)val == (Object)null)
					{
						Plugin.Log.LogError((object)"Rocky: the embedded bundle is missing.");
						return;
					}
					Model = val.LoadAsset<GameObject>("RockyModel");
				}
				string[] manifestResourceNames = Assembly.GetExecutingAssembly().GetManifestResourceNames();
				foreach (string text in manifestResourceNames)
				{
					if (!text.EndsWith(".wav"))
					{
						continue;
					}
					string text2 = text.Substring("RockyCompanion.".Length, text.Length - "RockyCompanion.".Length - 4);
					string key = text2.TrimEnd('0', '1', '2', '3', '4', '5', '6', '7', '8', '9').TrimEnd('_');
					AudioClip val2 = Wav.Load(Res(text2 + ".wav"), "Rocky_" + text2);
					if (!((Object)(object)val2 == (Object)null))
					{
						if (!Chords.TryGetValue(key, out var value))
						{
							value = (Chords[key] = new List<AudioClip>());
						}
						value.Add(val2);
					}
				}
				Plugin.Log.LogInfo((object)$"Rocky: assets loaded (model {(Object)(object)Model != (Object)null}, {Chords.Count} chord words).");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Rocky: assets failed to load: {arg}");
			}
		}

		internal static AudioClip Chord(string word, Random rnd = null)
		{
			if (!Chords.TryGetValue(word, out var value) || value.Count == 0)
			{
				return null;
			}
			return value[(rnd ?? Rng).Next(value.Count)];
		}

		private static Stream Res(string name)
		{
			return Assembly.GetExecutingAssembly().GetManifestResourceStream("RockyCompanion." + name);
		}
	}
	internal static class Wav
	{
		public static AudioClip Load(Stream s, string name)
		{
			if (s == null)
			{
				Plugin.Log.LogError((object)("Rocky: sound " + name + " is missing."));
				return null;
			}
			using (s)
			{
				using BinaryReader binaryReader = new BinaryReader(s);
				binaryReader.ReadBytes(12);
				int num = 1;
				int num2 = 44100;
				int num3 = 16;
				byte[] array = null;
				while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length - 8)
				{
					string text = Encoding.ASCII.GetString(binaryReader.ReadBytes(4));
					int num4 = binaryReader.ReadInt32();
					if (text == "fmt ")
					{
						binaryReader.ReadInt16();
						num = binaryReader.ReadInt16();
						num2 = binaryReader.ReadInt32();
						binaryReader.ReadInt32();
						binaryReader.ReadInt16();
						num3 = binaryReader.ReadInt16();
						if (num4 > 16)
						{
							binaryReader.ReadBytes(num4 - 16);
						}
					}
					else
					{
						if (text == "data")
						{
							array = binaryReader.ReadBytes(num4);
							break;
						}
						binaryReader.ReadBytes(num4);
					}
				}
				if (array == null || num3 != 16)
				{
					Plugin.Log.LogError((object)("Rocky: sound " + name + " isn't 16-bit PCM."));
					return null;
				}
				int num5 = array.Length / 2;
				float[] array2 = new float[num5];
				for (int i = 0; i < num5; i++)
				{
					array2[i] = (float)BitConverter.ToInt16(array, i * 2) / 32768f;
				}
				AudioClip obj = AudioClip.Create(name, num5 / num, num, num2, false);
				obj.SetData(array2, 0);
				return obj;
			}
		}
	}
	internal sealed class Legs
	{
		private sealed class Leg
		{
			public Transform Upper;

			public Transform Lower;

			public Vector3 HipB;

			public float L1;

			public float L2;

			public Quaternion UpperRestB;

			public Quaternion LowerRestB;

			public Quaternion Frame1RestB;

			public Quaternion Frame2RestB;

			public Vector3 RestR;

			public Vector3 Foot;

			public bool Stepping;

			public Vector3 From;

			public Vector3 To;

			public float T0;

			public float Dur;

			public float Lift;
		}

		private readonly Transform _root;

		private readonly Transform _body;

		private readonly Leg[] _legs;

		private readonly Vector3 _bodyUpB;

		private readonly Vector3 _bodyRestR;

		private readonly Quaternion _bodyRestRotR;

		private Vector3 _lastRootPos;

		private float _lastYaw;

		private Vector3 _vel;

		private float _yawRate;

		private float _bodyDrop;

		private bool _init;

		public float Crouch;

		public float Fold;

		public float Rear;

		public float Clearance { get; }

		public int Airborne { get; private set; }

		public Action<int, float> OnFootDown { get; set; }

		public Legs(Transform root, Transform body, Transform[] uppers, Transform[] lowers, Transform[] tips)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_00a4: 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_0126: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0158: 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_0161: 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)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: 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_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			_root = root;
			_body = body;
			Vector3 val = body.InverseTransformDirection(root.up);
			_bodyUpB = ((Vector3)(ref val)).normalized;
			_bodyRestR = root.InverseTransformPoint(body.position);
			_bodyRestRotR = Quaternion.Inverse(root.rotation) * body.rotation;
			float num = float.MaxValue;
			Renderer[] componentsInChildren = ((Component)body).GetComponentsInChildren<Renderer>();
			foreach (Renderer r in componentsInChildren)
			{
				if (!uppers.Any((Transform u) => ((Component)r).transform.IsChildOf(u)))
				{
					float num2 = num;
					Bounds bounds = r.bounds;
					num = Mathf.Min(num2, ((Bounds)(ref bounds)).min.y);
				}
			}
			Clearance = ((num < float.MaxValue) ? Mathf.Clamp(num - root.position.y, 0f, 0.4f) : 0.04f);
			_legs = new Leg[uppers.Length];
			for (int num3 = 0; num3 < uppers.Length; num3++)
			{
				Leg leg = new Leg
				{
					Upper = uppers[num3],
					Lower = lowers[num3]
				};
				Vector3 val2 = body.InverseTransformPoint(uppers[num3].position);
				Vector3 val3 = body.InverseTransformPoint(lowers[num3].position);
				Vector3 val4 = body.InverseTransformPoint(tips[num3].position);
				leg.HipB = val2;
				val = val3 - val2;
				leg.L1 = ((Vector3)(ref val)).magnitude;
				val = val4 - val3;
				leg.L2 = ((Vector3)(ref val)).magnitude;
				val = Vector3.Cross(val4 - val2, _bodyUpB);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				leg.Frame1RestB = Quaternion.LookRotation(val3 - val2, normalized);
				leg.Frame2RestB = Quaternion.LookRotation(val4 - val3, normalized);
				leg.UpperRestB = Quaternion.Inverse(body.rotation) * uppers[num3].rotation;
				leg.LowerRestB = Quaternion.Inverse(body.rotation) * lowers[num3].rotation;
				Vector3 val5 = root.InverseTransformPoint(tips[num3].position);
				leg.RestR = new Vector3(val5.x, 0f, val5.z);
				_legs[num3] = leg;
			}
		}

		private Vector3 RestWorld(Leg g, Vector3 rootPos, Quaternion rootRot)
		{
			//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)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			return Ground(rootPos + rootRot * g.RestR, rootPos.y);
		}

		private static Vector3 Ground(Vector3 p, float fallbackY)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			int num = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.collidersAndRoomMaskAndDefault : (-1));
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(new Vector3(p.x, fallbackY + 1.2f, p.z), Vector3.down, ref val, 2.6f, num, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref val)).point;
			}
			return new Vector3(p.x, fallbackY, p.z);
		}

		public void Reset()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_005b: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			Leg[] legs = _legs;
			foreach (Leg leg in legs)
			{
				leg.Stepping = false;
				leg.Foot = RestWorld(leg, _root.position, _root.rotation);
			}
			_lastRootPos = _root.position;
			_lastYaw = _root.eulerAngles.y;
			_vel = Vector3.zero;
			_yawRate = 0f;
			_init = true;
		}

		public void Update(float dt)
		{
			//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_0021: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: 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_01b5: 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_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_052a: Unknown result type (might be due to invalid IL or missing references)
			//IL_052f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_0556: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0561: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_044c: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02be: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0604: Unknown result type (might be due to invalid IL or missing references)
			//IL_0609: Unknown result type (might be due to invalid IL or missing references)
			//IL_060e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0613: Unknown result type (might be due to invalid IL or missing references)
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_0635: Unknown result type (might be due to invalid IL or missing references)
			//IL_063a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_065e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			//IL_0665: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			//IL_066c: Unknown result type (might be due to invalid IL or missing references)
			//IL_066e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0675: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_068f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0701: Unknown result type (might be due to invalid IL or missing references)
			//IL_073c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0741: Unknown result type (might be due to invalid IL or missing references)
			//IL_074d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0752: Unknown result type (might be due to invalid IL or missing references)
			//IL_0757: Unknown result type (might be due to invalid IL or missing references)
			//IL_075b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0760: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_0764: Unknown result type (might be due to invalid IL or missing references)
			//IL_076d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0772: Unknown result type (might be due to invalid IL or missing references)
			//IL_077d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0787: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_079e: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07be: Unknown result type (might be due to invalid IL or missing references)
			//IL_07c5: Unknown result type (might be due to invalid IL or missing references)
			if (dt <= 0f)
			{
				return;
			}
			Vector3 position = _root.position;
			float y = _root.eulerAngles.y;
			Vector3 val;
			if (_init)
			{
				val = position - _lastRootPos;
				if (!(((Vector3)(ref val)).sqrMagnitude > 9f))
				{
					goto IL_0056;
				}
			}
			Reset();
			goto IL_0056;
			IL_0056:
			Vector3 val2 = (position - _lastRootPos) / dt;
			val2.y = 0f;
			_vel = Vector3.Lerp(_vel, val2, 1f - Mathf.Exp((0f - dt) * 12f));
			_yawRate = Mathf.Lerp(_yawRate, Mathf.DeltaAngle(_lastYaw, y) / dt, 1f - Mathf.Exp((0f - dt) * 12f));
			_lastRootPos = position;
			_lastYaw = y;
			float time = Time.time;
			float magnitude = ((Vector3)(ref _vel)).magnitude;
			float num = 0.16f + 0.05f * Mathf.Min(magnitude, 6f);
			float num2 = Mathf.Max(0.11f, 0.24f - 0.025f * magnitude);
			float lift = 0.1f + 0.012f * magnitude;
			int num3 = 0;
			Leg[] legs = _legs;
			for (int i = 0; i < legs.Length; i++)
			{
				if (legs[i].Stepping)
				{
					num3++;
				}
			}
			int num4 = _legs.Length;
			int[] array = new int[num4];
			float[] err = new float[num4];
			for (int j = 0; j < num4; j++)
			{
				array[j] = j;
				float[] array2 = err;
				int num5 = j;
				val = Flat(_legs[j].Foot - RestWorld(_legs[j], position, _root.rotation));
				array2[num5] = ((Vector3)(ref val)).magnitude;
			}
			Array.Sort(array, (int a, int b) => err[b].CompareTo(err[a]));
			int[] array3 = array;
			foreach (int num6 in array3)
			{
				Leg leg = _legs[num6];
				if (!leg.Stepping && !(err[num6] < num) && num3 < 2 && !_legs[(num6 + 1) % num4].Stepping && !_legs[(num6 + num4 - 1) % num4].Stepping)
				{
					Quaternion rootRot = Quaternion.Euler(0f, y + _yawRate * num2, 0f) * Quaternion.Inverse(Quaternion.Euler(0f, y, 0f)) * _root.rotation;
					Vector3 val3 = RestWorld(leg, position + _vel * num2, rootRot);
					Vector3 val4 = ((magnitude > 0.05f) ? (((Vector3)(ref _vel)).normalized * Mathf.Min(0.75f * num, magnitude * 0.12f)) : Vector3.zero);
					leg.Stepping = true;
					leg.From = leg.Foot;
					leg.To = Ground(val3 + val4, val3.y);
					leg.T0 = time;
					leg.Dur = num2;
					leg.Lift = lift;
					num3++;
				}
			}
			Airborne = 0;
			legs = _legs;
			foreach (Leg leg2 in legs)
			{
				if (leg2.Stepping)
				{
					float num7 = Mathf.Clamp01((time - leg2.T0) / leg2.Dur);
					float num8 = num7 * num7 * (3f - 2f * num7);
					Vector3 foot = Vector3.Lerp(leg2.From, leg2.To, num8);
					foot.y += leg2.Lift * Mathf.Sin(MathF.PI * num7);
					if (num7 >= 1f)
					{
						leg2.Foot = leg2.To;
						leg2.Stepping = false;
						OnFootDown?.Invoke(Array.IndexOf(_legs, leg2), magnitude);
					}
					else
					{
						Airborne++;
						leg2.Foot = foot;
					}
				}
			}
			float num9 = 0.018f * (float)Airborne + Crouch;
			_bodyDrop = Mathf.Lerp(_bodyDrop, num9, 1f - Mathf.Exp((0f - dt) * 10f));
			float num10 = 0.008f * Mathf.Sin(time * 9f) * Mathf.Clamp01(magnitude) + 0.006f * Mathf.Sin(time * 1.7f);
			float num11 = 5f * Mathf.Min(1f, magnitude / 4.5f) - 18f * Rear;
			_body.position = _root.TransformPoint(_bodyRestR + Vector3.up * (num10 - _bodyDrop + 0.12f * Rear));
			_body.rotation = _root.rotation * Quaternion.AngleAxis(num11, Vector3.right) * _bodyRestRotR;
			if (Fold <= 0.001f)
			{
				legs = _legs;
				foreach (Leg leg3 in legs)
				{
					Solve(leg3, leg3.Foot, Vector3.zero);
				}
				return;
			}
			float num12 = Fold * Fold * (3f - 2f * Fold);
			legs = _legs;
			foreach (Leg leg4 in legs)
			{
				Vector3 val5 = _body.TransformPoint(leg4.HipB);
				Vector3 val6 = Flat(val5 - _body.position);
				if (((Vector3)(ref val6)).sqrMagnitude < 1E-06f)
				{
					val6 = Flat(val5 - _root.position);
				}
				val6 = ((((Vector3)(ref val6)).sqrMagnitude < 1E-06f) ? _root.forward : ((Vector3)(ref val6)).normalized);
				Vector3 val7 = Vector3.Cross(Vector3.up, val6);
				float y2 = Ground(val5 + val6 * 0.3f, _root.position.y).y;
				float num13 = Mathf.Max(0f, val5.y - y2 - 0.05f);
				float num14 = Mathf.Sqrt(Mathf.Max(leg4.L1 * leg4.L1 - num13 * num13, 0.09f * leg4.L1 * leg4.L1));
				Vector3 val8 = val5 + val6 * num14;
				val8.y = val5.y - Mathf.Sqrt(Mathf.Max(0f, leg4.L1 * leg4.L1 - num14 * num14));
				val = val7 * Mathf.Cos(0.4886922f) - val6 * Mathf.Sin(0.4886922f);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val9 = Ground(val8 + normalized * leg4.L2, _root.position.y);
				val9.y += 0.03f;
				Vector3 val10 = val8 - val5;
				Solve(leg4, Vector3.Lerp(leg4.Foot, val9, num12), ((Vector3)(ref val10)).normalized * num12);
			}
		}

		private static Vector3 Flat(Vector3 v)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			v.y = 0f;
			return v;
		}

		private void Solve(Leg g, Vector3 foot, Vector3 pole)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: 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_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_00ac: 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_00a3: 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_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: 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_0160: 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_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: 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_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: 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_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			Quaternion rotation = _body.rotation;
			Vector3 val = rotation * _bodyUpB;
			if (((Vector3)(ref pole)).sqrMagnitude > 1E-06f)
			{
				val = Vector3.Slerp(val, ((Vector3)(ref pole)).normalized, Mathf.Clamp01(((Vector3)(ref pole)).magnitude));
			}
			Vector3 val2 = _body.TransformPoint(g.HipB);
			Vector3 val3 = foot - val2;
			float num = Mathf.Clamp(((Vector3)(ref val3)).magnitude, Mathf.Abs(g.L1 - g.L2) + 0.001f, g.L1 + g.L2 - 0.001f);
			Vector3 val4 = ((((Vector3)(ref val3)).sqrMagnitude > 1E-08f) ? ((Vector3)(ref val3)).normalized : (-val));
			Vector3 val5 = val - Vector3.Dot(val, val4) * val4;
			Vector3 normalized = ((Vector3)(ref val5)).normalized;
			float num2 = Mathf.Acos(Mathf.Clamp((g.L1 * g.L1 + num * num - g.L2 * g.L2) / (2f * g.L1 * num), -1f, 1f));
			Vector3 val6 = val2 + val4 * (g.L1 * Mathf.Cos(num2)) + normalized * (g.L1 * Mathf.Sin(num2));
			Vector3 val7 = val2 + val4 * num;
			val5 = Vector3.Cross(val4, val);
			Vector3 normalized2 = ((Vector3)(ref val5)).normalized;
			Quaternion val8 = Quaternion.LookRotation(val6 - val2, normalized2);
			Quaternion val9 = Quaternion.LookRotation(val7 - val6, normalized2);
			g.Upper.rotation = val8 * Quaternion.Inverse(rotation * g.Frame1RestB) * (rotation * g.UpperRestB);
			g.Lower.rotation = val9 * Quaternion.Inverse(rotation * g.Frame2RestB) * (rotation * g.LowerRestB);
		}
	}
	internal static class Net
	{
		internal struct State
		{
			public byte Mode;

			public ulong Target;

			public bool InShip;

			public Vector3 Pos;

			public float Yaw;

			public ushort Warps;
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnState;

			public static HandleNamedMessageDelegate <1>__OnSay;

			public static HandleNamedMessageDelegate <2>__OnShout;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static HandleNamedMessageDelegate <>9__12_0;

			public static Action<FastBufferWriter> <>9__12_3;

			public static HandleNamedMessageDelegate <>9__12_1;

			public static HandleNamedMessageDelegate <>9__12_2;

			public static Func<ulong, bool> <>9__15_0;

			public static Func<ulong, bool> <>9__18_0;

			public static Func<ulong, bool> <>9__20_0;

			internal void <Register>b__12_0(ulong sender, FastBufferReader r)
			{
				Rocky.Instance?.HostInteract(sender);
			}

			internal void <Register>b__12_1(ulong sender, FastBufferReader r)
			{
				Send("DanielLC.Rocky.Config", sender, delegate(FastBufferWriter w)
				{
					//IL_0011: 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)
					int value = Plugin.Price.Value;
					((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref value, default(ForPrimitives));
				});
			}

			internal void <Register>b__12_3(FastBufferWriter w)
			{
				//IL_0011: 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)
				int value = Plugin.Price.Value;
				((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref value, default(ForPrimitives));
			}

			internal void <Register>b__12_2(ulong sender, FastBufferReader r)
			{
				//IL_0006: 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)
				int num = default(int);
				((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
				Store.ApplyPrice(num);
				Plugin.Log.LogInfo((object)$"Rocky: host price {num}.");
			}

			internal bool <SendState>b__15_0(ulong c)
			{
				return c != 0;
			}

			internal bool <Say>b__18_0(ulong c)
			{
				return c != 0;
			}

			internal bool <Shout>b__20_0(ulong c)
			{
				return c != 0;
			}
		}

		private const string MsgState = "DanielLC.Rocky.State";

		private const string MsgInteract = "DanielLC.Rocky.Interact";

		private const string MsgSay = "DanielLC.Rocky.Say";

		private const string MsgShout = "DanielLC.Rocky.Shout";

		private const string MsgConfigRequest = "DanielLC.Rocky.ConfigRequest";

		private const string MsgConfig = "DanielLC.Rocky.Config";

		private static readonly string[] All = new string[6] { "DanielLC.Rocky.State", "DanielLC.Rocky.Interact", "DanielLC.Rocky.Say", "DanielLC.Rocky.Shout", "DanielLC.Rocky.ConfigRequest", "DanielLC.Rocky.Config" };

		private static bool _registered;

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

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

		public static void Register()
		{
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Expected O, but got Unknown
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_007a: 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)
			//IL_0085: Expected O, but got Unknown
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (_registered || (Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null || !singleton.IsListening)
			{
				return;
			}
			CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
			if (singleton.IsServer)
			{
				object obj = <>c.<>9__12_0;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = delegate(ulong sender, FastBufferReader r)
					{
						Rocky.Instance?.HostInteract(sender);
					};
					<>c.<>9__12_0 = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.Interact", (HandleNamedMessageDelegate)obj);
				object obj2 = <>c.<>9__12_1;
				if (obj2 == null)
				{
					HandleNamedMessageDelegate val2 = delegate(ulong sender, FastBufferReader r)
					{
						Send("DanielLC.Rocky.Config", sender, delegate(FastBufferWriter w)
						{
							//IL_0011: 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)
							int value = Plugin.Price.Value;
							((FastBufferWriter)(ref w)).WriteValueSafe<int>(ref value, default(ForPrimitives));
						});
					};
					<>c.<>9__12_1 = val2;
					obj2 = (object)val2;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.ConfigRequest", (HandleNamedMessageDelegate)obj2);
			}
			else
			{
				object obj3 = <>O.<0>__OnState;
				if (obj3 == null)
				{
					HandleNamedMessageDelegate val3 = OnState;
					<>O.<0>__OnState = val3;
					obj3 = (object)val3;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.State", (HandleNamedMessageDelegate)obj3);
				object obj4 = <>O.<1>__OnSay;
				if (obj4 == null)
				{
					HandleNamedMessageDelegate val4 = OnSay;
					<>O.<1>__OnSay = val4;
					obj4 = (object)val4;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.Say", (HandleNamedMessageDelegate)obj4);
				object obj5 = <>O.<2>__OnShout;
				if (obj5 == null)
				{
					HandleNamedMessageDelegate val5 = OnShout;
					<>O.<2>__OnShout = val5;
					obj5 = (object)val5;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.Shout", (HandleNamedMessageDelegate)obj5);
				object obj6 = <>c.<>9__12_2;
				if (obj6 == null)
				{
					HandleNamedMessageDelegate val6 = delegate(ulong sender, FastBufferReader r)
					{
						//IL_0006: 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)
						int num = default(int);
						((FastBufferReader)(ref r)).ReadValueSafe<int>(ref num, default(ForPrimitives));
						Store.ApplyPrice(num);
						Plugin.Log.LogInfo((object)$"Rocky: host price {num}.");
					};
					<>c.<>9__12_2 = val6;
					obj6 = (object)val6;
				}
				customMessagingManager.RegisterNamedMessageHandler("DanielLC.Rocky.Config", (HandleNamedMessageDelegate)obj6);
				Send("DanielLC.Rocky.ConfigRequest", 0uL, null);
			}
			_registered = true;
		}

		public static void Unregister()
		{
			CustomMessagingManager val = (((Object)(object)NetworkManager.Singleton != (Object)null) ? NetworkManager.Singleton.CustomMessagingManager : null);
			if (val != null)
			{
				string[] all = All;
				foreach (string text in all)
				{
					try
					{
						val.UnregisterNamedMessageHandler(text);
					}
					catch (Exception)
					{
					}
				}
			}
			_registered = false;
		}

		public static void SendState(State s)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0095: 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_00ba: 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_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				return;
			}
			List<ulong> list = singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList();
			if (list.Count == 0)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref s.Mode, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref s.Target, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref s.InShip, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(ref s.Pos);
				((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref s.Yaw, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ushort>(ref s.Warps, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("DanielLC.Rocky.State", (IReadOnlyList<ulong>)list, val, (NetworkDelivery)1);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnState(ulong sender, FastBufferReader r)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			State lastState = default(State);
			((FastBufferReader)(ref r)).ReadValueSafe<byte>(ref lastState.Mode, default(ForPrimitives));
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref lastState.Target, default(ForPrimitives));
			((FastBufferReader)(ref r)).ReadValueSafe<bool>(ref lastState.InShip, default(ForPrimitives));
			((FastBufferReader)(ref r)).ReadValueSafe(ref lastState.Pos);
			((FastBufferReader)(ref r)).ReadValueSafe<float>(ref lastState.Yaw, default(ForPrimitives));
			((FastBufferReader)(ref r)).ReadValueSafe<ushort>(ref lastState.Warps, default(ForPrimitives));
			Rocky.LastState = lastState;
			Rocky.HasState = true;
		}

		public static void RequestInteract()
		{
			if (IsHost)
			{
				Rocky.Instance?.HostInteract(0uL);
			}
			else
			{
				Send("DanielLC.Rocky.Interact", 0uL, null);
			}
		}

		public static void Say(string word)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				return;
			}
			int seed = Random.Range(0, int.MaxValue);
			List<ulong> list = singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList();
			if (list.Count > 0)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, -1);
				try
				{
					((FastBufferWriter)(ref val)).WriteValueSafe(word, false);
					((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref seed, default(ForPrimitives));
					singleton.CustomMessagingManager.SendNamedMessage("DanielLC.Rocky.Say", (IReadOnlyList<ulong>)list, val, (NetworkDelivery)3);
				}
				finally
				{
					((FastBufferWriter)(ref val)).Dispose();
				}
			}
			Rocky.Instance?.Speak(word, seed);
		}

		private static void OnSay(ulong sender, FastBufferReader r)
		{
			//IL_0010: 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)
			string word = default(string);
			((FastBufferReader)(ref r)).ReadValueSafe(ref word, false);
			int seed = default(int);
			((FastBufferReader)(ref r)).ReadValueSafe<int>(ref seed, default(ForPrimitives));
			Rocky.Instance?.Speak(word, seed);
		}

		public static void Shout(ulong enemyId, float seconds)
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsServer)
			{
				return;
			}
			List<ulong> list = singleton.ConnectedClientsIds.Where((ulong c) => c != 0).ToList();
			if (list.Count > 0)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(32, (Allocator)2, -1);
				try
				{
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref enemyId, default(ForPrimitives));
					((FastBufferWriter)(ref val)).WriteValueSafe<float>(ref seconds, default(ForPrimitives));
					singleton.CustomMessagingManager.SendNamedMessage("DanielLC.Rocky.Shout", (IReadOnlyList<ulong>)list, val, (NetworkDelivery)3);
				}
				finally
				{
					((FastBufferWriter)(ref val)).Dispose();
				}
			}
			Fend.ApplyShout(enemyId, seconds);
		}

		private static void OnShout(ulong sender, FastBufferReader r)
		{
			//IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			ulong enemyId = default(ulong);
			((FastBufferReader)(ref r)).ReadValueSafe<ulong>(ref enemyId, default(ForPrimitives));
			float seconds = default(float);
			((FastBufferReader)(ref r)).ReadValueSafe<float>(ref seconds, default(ForPrimitives));
			Fend.ApplyShout(enemyId, seconds);
		}

		private static void Send(string name, ulong to, Action<FastBufferWriter> write)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
			{
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(64, (Allocator)2, 1024);
			try
			{
				write?.Invoke(val);
				singleton.CustomMessagingManager.SendNamedMessage(name, to, val, (NetworkDelivery)3);
			}
			finally
			{
				((FastBufferWriter)(ref val)).Dispose();
			}
		}
	}
	[HarmonyPatch]
	internal static class NetPatches
	{
		[HarmonyPatch(typeof(StartOfRound), "Start")]
		[HarmonyPostfix]
		private static void StartOfRoundStart()
		{
			Net.Register();
			if (Net.IsHost)
			{
				Store.ApplyPrice(Plugin.Price.Value);
			}
		}

		[HarmonyPatch(typeof(StartOfRound), "OnDestroy")]
		[HarmonyPrefix]
		private static void StartOfRoundDestroy()
		{
			Net.Unregister();
			Rocky.Despawn();
		}
	}
	public static class PluginInfo
	{
		public const string Guid = "daniel.lethalcompany.rockycompanion";

		public const string Name = "Rocky Companion";

		public const string Version = "0.1.0";
	}
	[BepInPlugin("daniel.lethalcompany.rockycompanion", "Rocky Companion", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<int> Price;

		internal static ConfigEntry<float> WalkSpeed;

		internal static ConfigEntry<float> RunSpeed;

		internal static ConfigEntry<float> FollowDistance;

		internal static ConfigEntry<float> CatchUpDistance;

		internal static ConfigEntry<float> Size;

		internal static ConfigEntry<float> FendCooldown;

		internal static ConfigEntry<bool> FendOffKillable;

		internal static ConfigEntry<string> FendOffNames;

		internal static ConfigEntry<bool> Warnings;

		internal static ConfigEntry<float> WarningRadius;

		internal static ConfigEntry<float> Volume;

		internal static ConfigEntry<bool> ThroughWalkie;

		internal static ConfigEntry<bool> Company;

		internal static ConfigEntry<bool> DebugKeys;

		private readonly Harmony _harmony = new Harmony("daniel.lethalcompany.rockycompanion");

		private void Awake()
		{
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Expected O, but got Unknown
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			Price = ((BaseUnityPlugin)this).Config.Bind<int>("Store (host)", "Price", 400, "Ship upgrade price in credits (Daniel, q_483a9582693d4ee9).");
			WalkSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Walk speed", 4.5f, "Metres per second while following.");
			RunSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Run speed", 7f, "Metres per second when he's more than 10 m behind.");
			FollowDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Follow distance", 3f, "He stops this far from the player he follows.");
			CatchUpDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Catch-up distance", 40f, "Further than this, or stuck, he warps to just behind the player.");
			Size = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Size", 0.75f, "Model scale (1 = the Blender model, 1.56 m tall). 0.75 is about a large dog next to a player.");
			FendCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (host)", "Fend-off cooldown", 25f, "Seconds between shouts at monsters you can't kill.");
			FendOffKillable = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocky (host)", "Fend off killable monsters", false, "Also shout at monsters you can kill (Bracken, Thumper, dogs and so on), with a 40 s cooldown. Off so he doesn't make them trivial.");
			FendOffNames = ((BaseUnityPlugin)this).Config.Bind<string>("Rocky (host)", "Extra monsters to fend off", "", "Comma-separated enemy names as the game shows them (for modded unkillable monsters).");
			Warnings = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocky (this player)", "Monster warnings", true, "He plays a warning chord when he hears a monster nearby.");
			WarningRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (this player)", "Warning radius", 18f, "How far he hears monsters, through walls (metres).");
			Volume = ((BaseUnityPlugin)this).Config.Bind<float>("Rocky (this player)", "Volume", 1f, "Volume of his chords (0 to 1).");
			ThroughWalkie = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocky (this player)", "Through walkie-talkie", true, "Crew with a walkie-talkie on hear his warnings too.");
			Company = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocky (this player)", "Counts as company", true, "Being within 10 m of him (awake) keeps you from going mad alone.");
			DebugKeys = ((BaseUnityPlugin)this).Config.Bind<bool>("Testing", "Debug keys", false, "Host only, not while typing. F3: unlock Rocky for free. F4: Rocky follows you (or stays, if he already follows you). F5: spawn a Coil-head 7 m ahead, to try the shout.");
			GameObject val = new GameObject("RockyCompanion.Runner");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<Runner>();
			Assets.Load();
			Store.Register();
			_harmony.PatchAll(typeof(Plugin).Assembly);
			DawnSaveFix.TryPatch(_harmony);
			Log.LogInfo((object)"Rocky Companion 0.1.0 loaded.");
		}
	}
	internal enum Mode : byte
	{
		Sleep,
		Idle,
		Follow,
		Stay,
		Mourn
	}
	internal sealed class Rocky : MonoBehaviour
	{
		public static Net.State LastState;

		public static bool HasState;

		private float _size;

		private Legs _legs;

		private AudioSource _voice;

		private AudioSource _loud;

		private InteractTrigger _trigger;

		private readonly Senses _senses = new Senses();

		private bool _inShip;

		private Vector3 _shipLocal;

		private float _shipYaw;

		private Vector3[] _path;

		private int _corner;

		private float _nextPath;

		private float _badPath;

		private float _stuck;

		private float _sideTime;

		private float _nextSend;

		private float _mournUntil;

		private float _nextSad;

		private float _nextHum;

		private bool _moving;

		private bool _noMesh;

		private bool _wasDifferentSide;

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

		private ulong _trailOf = ulong.MaxValue;

		private int _playerDoorId = -1;

		private ushort _warps;

		private Vector3 _lastPos;

		private ushort _seenWarps;

		private Vector3 _smoothVel;

		private float _rearUntil;

		private float _bumpUntil;

		private float _rear;

		private static List<EntranceTeleport> _doors;

		private static float _doorsAt = -100f;

		private static Vector3? _sleepLocal;

		public static Rocky Instance { get; private set; }

		public Mode Mode { get; private set; }

		public ulong Target { get; private set; }

		public bool IsAwake => Mode != Mode.Sleep;

		public static void Spawn()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Instance != (Object)null) && !((Object)(object)Assets.Model == (Object)null))
			{
				Instance = new GameObject("RockyCompanion.Rocky").AddComponent<Rocky>();
			}
		}

		public static void Despawn()
		{
			if ((Object)(object)Instance != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)Instance).gameObject);
			}
			Instance = null;
			HasState = false;
			_sleepLocal = null;
			Fend.Reset();
		}

		private void Start()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Expected O, but got Unknown
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Expected O, but got Unknown
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Expected O, but got Unknown
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Expected O, but got Unknown
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034f: Expected O, but got Unknown
			//IL_0355: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Expected O, but got Unknown
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036f: Expected O, but got Unknown
			//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			_size = Mathf.Clamp(Plugin.Size.Value, 0.3f, 2f);
			PlaceAtSleepSpot(instance);
			_lastPos = ((Component)this).transform.position;
			GameObject val = Object.Instantiate<GameObject>(Assets.Model, ((Component)this).transform);
			((Object)val).name = "Model";
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			val.transform.localScale = Vector3.one * _size;
			val.SetActive(true);
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				((Component)componentsInChildren[i]).gameObject.layer = 0;
			}
			Transform[] all = val.GetComponentsInChildren<Transform>(true);
			Transform val2 = Find("Body");
			Transform[] array = (from num2 in Enumerable.Range(0, 5)
				select Find("Upper" + num2)).ToArray();
			Transform[] array2 = (from num2 in Enumerable.Range(0, 5)
				select Find("Lower" + num2)).ToArray();
			Transform[] array3 = (from num2 in Enumerable.Range(0, 5)
				select Find("Tip" + num2)).ToArray();
			if ((Object)(object)val2 == (Object)null || array.Concat(array2).Concat(array3).Any((Transform t) => (Object)(object)t == (Object)null))
			{
				Plugin.Log.LogError((object)"Rocky: the model's rig is incomplete; his legs won't move.");
			}
			else
			{
				_legs = new Legs(((Component)this).transform, val2, array, array2, array3);
				_legs.Reset();
			}
			GameNetworkManager instance2 = GameNetworkManager.Instance;
			object obj;
			if (instance2 == null)
			{
				obj = null;
			}
			else
			{
				PlayerControllerB localPlayerController = instance2.localPlayerController;
				if (localPlayerController == null)
				{
					obj = null;
				}
				else
				{
					AudioSource movementAudio = localPlayerController.movementAudio;
					obj = ((movementAudio != null) ? movementAudio.outputAudioMixerGroup : null);
				}
			}
			AudioMixerGroup mixer = (AudioMixerGroup)obj;
			_voice = MakeSource(mixer, 28f);
			_loud = MakeSource(mixer, 45f);
			GameObject val3 = new GameObject("RockyInteract");
			val3.transform.SetParent(((Component)this).transform, false);
			int num = LayerMask.NameToLayer("InteractableObject");
			val3.layer = ((num >= 0) ? num : 9);
			val3.tag = "InteractTrigger";
			BoxCollider obj2 = val3.AddComponent<BoxCollider>();
			((Collider)obj2).isTrigger = true;
			obj2.center = new Vector3(0f, 0.75f * _size, 0f);
			obj2.size = new Vector3(1.1f, 0.8f, 1.1f) * _size;
			_trigger = val3.AddComponent<InteractTrigger>();
			_trigger.hoverTip = "Fist bump : [E]";
			_trigger.disabledHoverTip = "Asleep until you land";
			_trigger.interactable = false;
			_trigger.oneHandedItemAllowed = true;
			_trigger.twoHandedItemAllowed = true;
			_trigger.interactCooldown = true;
			_trigger.cooldownTime = 0.6f;
			_trigger.onInteract = new InteractEvent();
			_trigger.onInteractEarly = new InteractEvent();
			_trigger.onInteractEarlyOtherClients = new InteractEvent();
			_trigger.onStopInteract = new InteractEvent();
			_trigger.onCancelAnimation = new InteractEvent();
			_trigger.holdingInteractEvent = new InteractEventFloat();
			((UnityEvent<PlayerControllerB>)(object)_trigger.onInteract).AddListener((UnityAction<PlayerControllerB>)delegate(PlayerControllerB p)
			{
				if ((Object)(object)p != (Object)null && (Object)(object)p == (Object)(object)GameNetworkManager.Instance?.localPlayerController)
				{
					Net.RequestInteract();
				}
			});
			FindHoverIcon();
			Plugin.Log.LogInfo((object)string.Format("Rocky: spawned ({0}) at {1}.", Net.IsHost ? "host" : "client", ((Component)this).transform.position));
			Transform Find(string n)
			{
				return ((IEnumerable<Transform>)all).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == n));
			}
		}

		private AudioSource MakeSource(AudioMixerGroup mixer, float range)
		{
			AudioSource obj = ((Component)this).gameObject.AddComponent<AudioSource>();
			obj.playOnAwake = false;
			obj.spatialBlend = 1f;
			obj.rolloffMode = (AudioRolloffMode)1;
			obj.minDistance = 2f;
			obj.maxDistance = range;
			obj.dopplerLevel = 0f;
			obj.outputAudioMixerGroup = mixer;
			return obj;
		}

		private void FindHoverIcon()
		{
			if (!((Object)(object)_trigger == (Object)null) && !((Object)(object)_trigger.hoverIcon != (Object)null))
			{
				InteractTrigger val = ((IEnumerable<InteractTrigger>)Object.FindObjectsOfType<InteractTrigger>()).FirstOrDefault((Func<InteractTrigger, bool>)((InteractTrigger t) => (Object)(object)t != (Object)(object)_trigger && (Object)(object)t.hoverIcon != (Object)null));
				if ((Object)(object)val != (Object)null)
				{
					_trigger.hoverIcon = val.hoverIcon;
					_trigger.disabledHoverIcon = val.disabledHoverIcon;
				}
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
		}

		private void Update()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)instance.elevatorTransform == (Object)null))
			{
				float deltaTime = Time.deltaTime;
				if (Net.IsHost)
				{
					HostTick(instance, deltaTime);
				}
				else
				{
					ClientTick(instance);
				}
				if ((Object)(object)_trigger != (Object)null)
				{
					FindHoverIcon();
					PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
					_trigger.interactable = IsAwake;
					_trigger.hoverTip = (((Object)(object)val != (Object)null && Mode == Mode.Follow && Target == val.actualClientId) ? "Stay here : [E]" : "Fist bump : [E]");
				}
				bool flag = instance.shipHasLanded && !instance.inShipPhase;
				if (IsAwake && flag)
				{
					_senses.Update(this);
					Fend.LocalGhost(this);
				}
				if (Mode == Mode.Sleep && Time.time > _nextHum)
				{
					_nextHum = Time.time + Random.Range(7f, 11f);
					PlayLocal("sleep", Random.Range(0, int.MaxValue), 0.35f, walkie: false, _voice);
				}
			}
		}

		private void LateUpdate()
		{
			StartOfRound instance = StartOfRound.Instance;
			if (_legs != null && !((Object)(object)instance == (Object)null))
			{
				float num = ((Time.time < _rearUntil) ? 1f : ((Time.time < _bumpUntil) ? 0.4f : 0f));
				_rear = Mathf.MoveTowards(_rear, num, Time.deltaTime * ((num > _rear) ? 5f : 2f));
				_legs.Rear = _rear;
				bool flag = Mode == Mode.Sleep;
				_legs.Crouch = Mathf.MoveTowards(_legs.Crouch, flag ? Mathf.Max(0f, _legs.Clearance - 0.03f) : 0f, Time.deltaTime * (flag ? 0.35f : 0.9f));
				_legs.Fold = Mathf.MoveTowards(_legs.Fold, flag ? 1f : 0f, Time.deltaTime * (flag ? 0.6f : 1.6f));
				if (_inShip && (!instance.shipHasLanded || instance.shipIsLeaving))
				{
					_legs.Reset();
				}
				_legs.Update(Time.deltaTime);
			}
		}

		private void HostTick(StartOfRound sor, float dt)
		{
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: 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)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: 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_02e1: 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_0303: Unknown result type (might be due to invalid IL or missing references)
			Transform elevatorTransform = sor.elevatorTransform;
			bool flag = sor.shipHasLanded && !sor.shipIsLeaving && !sor.inShipPhase;
			if (sor.inShipPhase || sor.shipIsLeaving)
			{
				if (Mode != Mode.Sleep)
				{
					Mode = Mode.Sleep;
					_path = null;
					if (!_inShip || Vector3.Distance(((Component)this).transform.position, SleepWorld(sor)) > 1.5f)
					{
						PlaceAtSleepSpot(sor);
						_warps++;
						_legs?.Reset();
					}
					Net.Say("sleep");
				}
			}
			else if (flag && Mode == Mode.Sleep)
			{
				Mode = Mode.Idle;
				Net.Say("wake");
			}
			_moving = false;
			if (flag)
			{
				switch (Mode)
				{
				case Mode.Follow:
					Follow(sor, dt);
					break;
				case Mode.Mourn:
					Mourn(sor, dt);
					break;
				}
				Fend.HostUpdate(this);
			}
			if (_inShip && !flag)
			{
				((Component)this).transform.position = elevatorTransform.TransformPoint(_shipLocal);
				((Component)this).transform.rotation = Quaternion.Euler(0f, elevatorTransform.eulerAngles.y + _shipYaw, 0f);
			}
			else
			{
				int inShip;
				if ((Object)(object)sor.shipInnerRoomBounds != (Object)null)
				{
					Bounds bounds = sor.shipInnerRoomBounds.bounds;
					inShip = (((Bounds)(ref bounds)).Contains(((Component)this).transform.position + Vector3.up * 0.4f) ? 1 : 0);
				}
				else
				{
					inShip = 0;
				}
				_inShip = (byte)inShip != 0;
				_shipLocal = elevatorTransform.InverseTransformPoint(((Component)this).transform.position);
				_shipYaw = Mathf.DeltaAngle(elevatorTransform.eulerAngles.y, ((Component)this).transform.eulerAngles.y);
			}
			Vector3 val = Flat(((Component)this).transform.position - _lastPos);
			float num = ((Vector3)(ref val)).magnitude / Mathf.Max(dt, 0.0001f);
			_lastPos = ((Component)this).transform.position;
			if (_moving && num < 0.3f)
			{
				_stuck += dt;
			}
			else
			{
				_stuck = 0f;
			}
			if (_stuck > 4f && Mode == Mode.Follow)
			{
				PlayerControllerB val2 = PlayerById(sor, Target);
				if ((Object)(object)val2 != (Object)null)
				{
					Plugin.Log.LogInfo((object)"Rocky: stuck, warping to the player.");
					WarpBehind(val2);
				}
			}
			if (Time.time >= _nextSend)
			{
				_nextSend = Time.time + 0.1f;
				Net.SendState(new Net.State
				{
					Mode = (byte)Mode,
					Target = Target,
					InShip = _inShip,
					Pos = (_inShip ? _shipLocal : ((Component)this).transform.position),
					Yaw = (_inShip ? _shipYaw : ((Component)this).transform.eulerAngles.y),
					Warps = _warps
				});
			}
		}

		public void HostInteract(ulong sender)
		{
			StartOfRound instance = StartOfRound.Instance;
			PlayerControllerB val = (((Object)(object)instance != (Object)null) ? PlayerById(instance, sender) : null);
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && IsAwake)
			{
				if (Mode == Mode.Follow && Target == sender)
				{
					Mode = Mode.Stay;
					Net.Say("stay");
					Plugin.Log.LogInfo((object)("Rocky: stays (asked by " + val.playerUsername + ")."));
					return;
				}
				Mode = Mode.Follow;
				Target = sender;
				_path = null;
				_nextPath = 0f;
				Net.Say("bump");
				Plugin.Log.LogInfo((object)("Rocky: fist bump, now follows " + val.playerUsername + "."));
			}
		}

		private void Follow(StartOfRound sor, float dt)
		{
			//IL_00a3: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: 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_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f5: 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_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = PlayerById(sor, Target);
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !val.isPlayerControlled)
			{
				if ((Object)(object)val != (Object)null && val.isPlayerDead && (Object)(object)val.deadBody != (Object)null)
				{
					Mode = Mode.Mourn;
					_mournUntil = Time.time + 60f;
					_nextSad = 0f;
					Plugin.Log.LogInfo((object)("Rocky: " + val.playerUsername + " died; he goes to the body."));
				}
				else
				{
					NextTarget(sor);
				}
				return;
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 position2 = ((Component)val).transform.position;
			bool meInside = position.y < -80f;
			bool pInside = val.isInsideFactory;
			if (meInside != pInside)
			{
				if (!_wasDifferentSide)
				{
					_wasDifferentSide = true;
					_sideTime = 0f;
					EntranceTeleport val2 = NearestDoor(position2, !pInside);
					_playerDoorId = (((Object)(object)val2 != (Object)null) ? val2.entranceId : (-1));
				}
				_sideTime += dt;
				EntranceTeleport val3 = ((IEnumerable<EntranceTeleport>)Doors()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport d) => d.entranceId == _playerDoorId && d.isEntranceToBuilding == !meInside));
				EntranceTeleport val4 = ((IEnumerable<EntranceTeleport>)Doors()).FirstOrDefault((Func<EntranceTeleport, bool>)((EntranceTeleport d) => d.entranceId == _playerDoorId && d.isEntranceToBuilding == !pInside));
				float num = (((Object)(object)val3 != (Object)null) ? Vector3.Distance(position, val3.entrancePoint.position) : 0f);
				int num2;
				if (_path != null && _path.Length != 0)
				{
					Vector3 val5 = Flat(_path[_path.Length - 1] - position);
					num2 = ((((Vector3)(ref val5)).magnitude < 0.6f) ? 1 : 0);
				}
				else
				{
					num2 = 0;
				}
				bool flag = (byte)num2 != 0;
				if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || _sideTime > 6f || num < 2.5f || (num < 5f && flag))
				{
					if ((Object)(object)val4 != (Object)null)
					{
						WarpTo(val4.entrancePoint.position);
					}
					else
					{
						WarpBehind(val);
					}
					_wasDifferentSide = false;
				}
				else
				{
					MoveTowards(val3.entrancePoint.position, Plugin.RunSpeed.Value, dt, val);
				}
				return;
			}
			_wasDifferentSide = false;
			RecordTrail(val);
			float num3 = Vector3.Distance(position, position2);
			if (num3 > Mathf.Max(10f, Plugin.CatchUpDistance.Value))
			{
				WarpBehind(val);
				return;
			}
			float num4 = Mathf.Max(1.2f, Plugin.FollowDistance.Value);
			if (num3 < num4 || (num3 < num4 + 1f && _path == null))
			{
				_path = null;
				Face(position2, dt);
			}
			else
			{
				float speed = ((num3 > 10f) ? Plugin.RunSpeed.Value : Plugin.WalkSpeed.Value);
				MoveTowards(position2, speed, dt, val);
			}
		}

		private void Mourn(StartOfRound sor, float dt)
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0077: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = PlayerById(sor, Target);
			DeadBodyInfo val2 = (((Object)(object)val != (Object)null) ? val.deadBody : null);
			if ((Object)(object)val2 == (Object)null || Time.time > _mournUntil)
			{
				NextTarget(sor);
				return;
			}
			Vector3 position = ((Component)val2).transform.position;
			if (position.y < -80f != ((Component)this).transform.position.y < -80f || Vector3.Distance(position, ((Component)this).transform.position) > 40f)
			{
				WarpTo(position);
				return;
			}
			if (Vector3.Distance(position, ((Component)this).transform.position) > 1.8f)
			{
				MoveTowards(position, Plugin.WalkSpeed.Value, dt, null);
			}
			else
			{
				_path = null;
				Face(position, dt);
			}
			if (Time.time > _nextSad)
			{
				_nextSad = Time.time + 5f;
				Net.Say("sad");
			}
		}

		private void NextTarget(StartOfRound sor)
		{
			PlayerControllerB val = (from x in sor.allPlayerScripts
				where (Object)(object)x != (Object)null && x.isPlayerControlled && !x.isPlayerDead
				orderby Vector3.Distance(((Component)x).transform.position, ((Component)this).transform.position)
				select x).FirstOrDefault();
			_path = null;
			if ((Object)(object)val == (Object)null)
			{
				Mode = Mode.Idle;
				return;
			}
			Mode = Mode.Follow;
			Target = val.actualClientId;
			Plugin.Log.LogInfo((object)("Rocky: now follows " + val.playerUsername + "."));
		}

		private void MoveTowards(Vector3 goal, float speed, float dt, PlayerControllerB p)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: 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_00f0: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			_moving = true;
			if (Time.time >= _nextPath || _path == null)
			{
				_nextPath = Time.time + 0.25f;
				Repath(goal);
				if (_badPath > 1.5f && (Object)(object)p != (Object)null)
				{
					Plugin.Log.LogInfo((object)"Rocky: no path to the player, warping.");
					WarpBehind(p);
					return;
				}
			}
			Vector3 position = ((Component)this).transform.position;
			Vector3 val = goal;
			if (_path != null && !_noMesh)
			{
				while (_corner < _path.Length - 1)
				{
					Vector3 val2 = Flat(_path[_corner] - position);
					if (!(((Vector3)(ref val2)).magnitude < 0.35f))
					{
						break;
					}
					_corner++;
				}
				val = _path[Mathf.Min(_corner, _path.Length - 1)];
			}
			Vector3 val3 = Flat(val - position);
			if (!(((Vector3)(ref val3)).sqrMagnitude < 0.0001f))
			{
				Vector3 val4 = ((Vector3)(ref val3)).normalized * Mathf.Min(speed * dt, ((Vector3)(ref val3)).magnitude);
				Vector3 val5 = position + val4;
				float fallback = Mathf.Lerp(position.y, val.y, Mathf.Clamp01(((Vector3)(ref val4)).magnitude / Mathf.Max(((Vector3)(ref val3)).magnitude, 0.001f)));
				val5.y = GroundY(val5, fallback);
				((Component)this).transform.position = val5;
				Face(val5 + val3, dt, 300f);
			}
		}

		private void Repath(Vector3 goal)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unk