Decompiled source of Avatar NPCs and Voice Lines v3.2.0

Mods/AvatarNPCs.dll

Decompiled 3 days ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net.Http;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.Notifications;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSLZ.Data;
using Il2CppSLZ.Marrow;
using Il2CppSLZ.Marrow.Audio;
using Il2CppSLZ.Marrow.Combat;
using Il2CppSLZ.Marrow.Interaction;
using Il2CppSLZ.Marrow.Warehouse;
using Il2CppSLZ.VRMK;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using LabFusion.MonoBehaviours;
using LabFusion.Network;
using LabFusion.Network.Serialization;
using LabFusion.Player;
using LabFusion.SDK.Modules;
using LabFusion.Utilities;
using MelonLoader;
using MelonLoader.Preferences;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using NpcVoiceMod;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: MelonInfo(typeof(Main), "Avatar NPCs & Voice Lines", "3.2.0", "Giovanni", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: MelonOptionalDependencies(new string[] { "LabFusion" })]
[assembly: SecurityPermission((SecurityAction)8, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : System.Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableAttribute : System.Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableContextAttribute : System.Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : System.Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace NpcVoiceMod
{
	public static class BotFactory
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass7_0
		{
			public bool loaded;

			public GameObject asset;

			internal void <SwapAvatar>b__0(GameObject g)
			{
				loaded = true;
				asset = g;
			}
		}

		[CompilerGenerated]
		private sealed class <SwapAvatar>d__7 : System.Collections.Generic.IEnumerator<object>, System.IDisposable, System.Collections.IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string barcode;

			public Action<bool> done;

			private <>c__DisplayClass7_0 <>8__1;

			public RigManager rm;

			private AvatarCrate <crate>5__2;

			private float <timeout>5__3;

			private Avatar <avatar>5__4;

			object System.Collections.Generic.IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object System.Collections.IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <SwapAvatar>d__7(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void System.IDisposable.Dispose()
			{
			}

			private bool MoveNext()
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Expected O, but got Unknown
				//IL_0232: Unknown result type (might be due to invalid IL or missing references)
				//IL_023c: Expected O, but got Unknown
				//IL_0161: 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)
				GameObject val;
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>8__1 = new <>c__DisplayClass7_0();
					<crate>5__2 = ((CrateReferenceT<AvatarCrate>)new AvatarCrateReference(barcode)).Crate;
					if ((Object)(object)<crate>5__2 == (Object)null)
					{
						done?.Invoke(false);
						return false;
					}
					<>8__1.loaded = false;
					<>8__1.asset = null;
					((CrateT<GameObject>)(object)<crate>5__2).LoadAsset(Action<GameObject>.op_Implicit((Action<GameObject>)delegate(GameObject g)
					{
						<>8__1.loaded = true;
						<>8__1.asset = g;
					}));
					<timeout>5__3 = Time.time + 15f;
					goto IL_00c8;
				case 1:
					<>1__state = -1;
					goto IL_00c8;
				case 2:
					{
						<>1__state = -1;
						break;
					}
					IL_00c8:
					if (!<>8__1.loaded && Time.time < <timeout>5__3)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					if ((Object)(object)rm == (Object)null || (Object)(object)<>8__1.asset == (Object)null)
					{
						done?.Invoke(false);
						return false;
					}
					val = Object.Instantiate<GameObject>(<>8__1.asset);
					val.SetActive(false);
					((Object)val).name = ((Object)<>8__1.asset).name;
					val.transform.parent = ((Component)rm).transform;
					val.transform.localPosition = Vector3.zero;
					val.transform.localRotation = Quaternion.identity;
					<avatar>5__4 = val.GetComponentInParent<Avatar>(true);
					if ((Object)(object)<avatar>5__4 == (Object)null)
					{
						<avatar>5__4 = val.GetComponentInChildren<Avatar>(true);
					}
					rm.SwapAvatar(<avatar>5__4);
					<timeout>5__3 = Time.time + 10f;
					break;
				}
				if ((Object)(object)rm != (Object)null && (Object)(object)rm.avatar != (Object)(object)<avatar>5__4 && Time.time < <timeout>5__3)
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				if ((Object)(object)rm == (Object)null)
				{
					return false;
				}
				rm._avatarCrate = new AvatarCrateReference(((Scannable)<crate>5__2).Barcode);
				try
				{
					Action onAvatarSwapped = rm.onAvatarSwapped;
					if (onAvatarSwapped != null)
					{
						onAvatarSwapped.Invoke();
					}
				}
				catch
				{
				}
				try
				{
					rm.onAvatarSwapped2?.Invoke(((Scannable)<crate>5__2).Barcode);
				}
				catch
				{
				}
				AddImpactProperties(rm);
				try
				{
					rm.physicsRig.headSfx.mouthSrc.mute = true;
				}
				catch
				{
				}
				done?.Invoke((Object)(object)rm.avatar == (Object)(object)<avatar>5__4);
				return false;
			}

			bool System.Collections.IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void System.Collections.IEnumerator.Reset()
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				throw new NotSupportedException();
			}
		}

		public const string BotName = "[RigManager (Avatar NPC)]";

		public static void CreateRig(Vector3 position, Quaternion rotation, Action<RigManager> onCreated)
		{
			//IL_0007: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			MarrowSettings runtimeInstance = MarrowSettings.RuntimeInstance;
			if ((Object)(object)runtimeInstance == (Object)null)
			{
				MelonLogger.Error("[Bot] MarrowSettings missing");
				return;
			}
			SpawnableCrate crate = ((CrateReferenceT<SpawnableCrate>)(object)runtimeInstance.DefaultPlayerRig).Crate;
			if ((Object)(object)crate == (Object)null)
			{
				MelonLogger.Error("[Bot] Default player rig crate missing");
				return;
			}
			((CrateT<GameObject>)(object)crate).LoadAsset(Action<GameObject>.op_Implicit((Action<GameObject>)delegate(GameObject asset)
			{
				//IL_0002: 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)
				try
				{
					OnRigLoaded(asset, position, rotation, onCreated);
				}
				catch (System.Exception ex)
				{
					MelonLogger.Error("[Bot] Rig creation failed: " + (object)ex);
				}
			}));
		}

		private static void OnRigLoaded(GameObject asset, Vector3 position, Quaternion rotation, Action<RigManager> onCreated)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			//IL_0055: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)asset == (Object)null)
			{
				MelonLogger.Error("[Bot] Rig asset is null");
				return;
			}
			GameObject val = new GameObject("NpcVoiceMod_Temp");
			val.SetActive(false);
			GameObject obj = Object.Instantiate<GameObject>(((Component)asset.GetComponentInChildren<RigManager>(true)).gameObject, val.transform);
			((Object)obj).name = "[RigManager (Avatar NPC)]";
			obj.SetActive(false);
			obj.transform.SetPositionAndRotation(position, Quaternion.Euler(0f, ((Quaternion)(ref rotation)).eulerAngles.y, 0f));
			RigManager component = obj.GetComponent<RigManager>();
			Setup(component);
			obj.transform.parent = null;
			Object.Destroy((Object)(object)val);
			obj.SetActive(true);
			SwapControllers(component);
			MelonLogger.Msg("[Bot] Player body created");
			onCreated?.Invoke(component);
		}

		private static void Setup(RigManager rm)
		{
			OpenControllerRig val = ((Il2CppObjectBase)rm.ControllerRig).TryCast<OpenControllerRig>();
			try
			{
				rm.physicsRig.marrowEntity.Tags.Tags.RemoveAll(Predicate<BoneTagReference>.op_Implicit((Func<BoneTagReference, bool>)((BoneTagReference t) => ((ScannableReference)t).Barcode.ID == "SLZ.Marrow.BoneTag.Player")));
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[Bot] tag: " + ex.Message);
			}
			if ((Object)(object)val != (Object)null)
			{
				System.Collections.Generic.IEnumerator<MarrowBody> enumerator = ((Component)val).GetComponentsInChildren<MarrowBody>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						Object.DestroyImmediate((Object)(object)enumerator.Current);
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
				System.Collections.Generic.IEnumerator<Tracker> enumerator2 = ((Component)val).GetComponentsInChildren<Tracker>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator2).MoveNext())
					{
						Object.DestroyImmediate((Object)(object)((Component)enumerator2.Current).gameObject);
					}
				}
				finally
				{
					((System.IDisposable)enumerator2)?.Dispose();
				}
				MarrowEntity component = ((Component)val).GetComponent<MarrowEntity>();
				if ((Object)(object)component != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component);
				}
			}
			Player_Health val2 = ((Il2CppObjectBase)rm.health).TryCast<Player_Health>();
			if ((Object)(object)val2 != (Object)null)
			{
				val2.reloadLevelOnDeath = false;
				((Health)val2).healthMode = (HealthMode)0;
				if ((Object)(object)val2.Vignetter != (Object)null)
				{
					GameObject val3 = Object.Instantiate<GameObject>(val2.Vignetter);
					SkinnedMeshRenderer component2 = val3.GetComponent<SkinnedMeshRenderer>();
					if ((Object)(object)component2 != (Object)null)
					{
						((Renderer)component2).enabled = false;
					}
					val3.SetActive(false);
					val2.Vignetter = val3;
				}
			}
			try
			{
				AudioSource mouthSrc = rm.physicsRig.headSfx.mouthSrc;
				mouthSrc.spatialBlend = 1f;
				mouthSrc.mute = true;
			}
			catch
			{
			}
			System.Collections.Generic.IEnumerator<Component> enumerator3;
			if ((Object)(object)val != (Object)null)
			{
				val.quickmenuEnabled = false;
				val._timeInput = false;
				rm.remapHeptaRig.doubleJump = false;
				Transform headset = val.headset;
				HashSet<string> obj2 = new HashSet<string>();
				obj2.Add("AudioListener");
				obj2.Add("CameraSettings");
				obj2.Add("StreamingController");
				obj2.Add("VolumetricRendering");
				obj2.Add("UniversalAdditionalCameraData");
				HashSet<string> val4 = obj2;
				enumerator3 = ((Component)headset).GetComponents<Component>().GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator3).MoveNext())
					{
						Component current = enumerator3.Current;
						if (!((Object)(object)current == (Object)null) && val4.Contains(((MemberInfo)((Object)current).GetIl2CppType()).Name))
						{
							try
							{
								Object.DestroyImmediate((Object)(object)current);
							}
							catch
							{
							}
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator3)?.Dispose();
				}
				Camera component3 = ((Component)headset).GetComponent<Camera>();
				if ((Object)(object)component3 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)component3);
				}
				val.cameras = new Il2CppReferenceArray<Camera>(0L);
				List<string> val5 = new List<string>();
				Transform[] array = (Transform[])(object)new Transform[3]
				{
					headset,
					((Component)rm.ControllerRig.leftController).transform,
					((Component)rm.ControllerRig.rightController).transform
				};
				foreach (Transform val6 in array)
				{
					enumerator3 = ((Component)val6).GetComponents<Component>().GetEnumerator();
					try
					{
						while (((System.Collections.IEnumerator)enumerator3).MoveNext())
						{
							Component current2 = enumerator3.Current;
							if ((Object)(object)current2 == (Object)null)
							{
								continue;
							}
							string name = ((MemberInfo)((Object)current2).GetIl2CppType()).Name;
							val5.Add(((Object)val6).name + ":" + name);
							if (!name.Contains("TrackedPoseDriver") && !name.Contains("PoseDriver") && !(name == "XRController") && !(name == "ActionBasedController"))
							{
								continue;
							}
							try
							{
								Behaviour val7 = ((Il2CppObjectBase)current2).TryCast<Behaviour>();
								if ((Object)(object)val7 != (Object)null)
								{
									val7.enabled = false;
								}
								Object.DestroyImmediate((Object)(object)current2);
							}
							catch
							{
							}
							MelonLogger.Msg("[Bot] removed tracking component " + name);
						}
					}
					finally
					{
						((System.IDisposable)enumerator3)?.Dispose();
					}
				}
				if (Settings.DebugLog.Value)
				{
					MelonLogger.Msg("[Bot] tracking parts: " + string.Join(", ", (System.Collections.Generic.IEnumerable<string>)val5));
				}
				val.onLastCameraUpdate = null;
				((Component)headset).tag = "Untagged";
			}
			DestroyByTypeName(((Component)rm).gameObject, "PlayerAvatarArt");
			DestroyByTypeName(((Component)rm).gameObject, "UIControllerInput");
			enumerator3 = ((Component)rm).GetComponentsInChildren<Component>(true).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator3).MoveNext())
				{
					Component current3 = enumerator3.Current;
					if (!((Object)(object)current3 == (Object)null) && ((MemberInfo)((Object)current3).GetIl2CppType()).Name == "InventoryAmmoReceiver")
					{
						Collider component4 = current3.GetComponent<Collider>();
						if ((Object)(object)component4 != (Object)null)
						{
							component4.enabled = false;
						}
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator3)?.Dispose();
			}
			try
			{
				Hand[] array2 = (Hand[])(object)new Hand[2]
				{
					rm.physicsRig.leftHand,
					rm.physicsRig.rightHand
				};
				for (int num = 0; num < array2.Length; num++)
				{
					PhysHand component5 = ((Component)array2[num]).GetComponent<PhysHand>();
					if ((Object)(object)component5 != (Object)null && (Object)(object)component5.inventoryPlug != (Object)null)
					{
						((Collider)component5.inventoryPlug).enabled = false;
						((Component)component5.inventoryPlug).gameObject.SetActive(false);
					}
				}
			}
			catch
			{
			}
			try
			{
				BaseController[] array3 = (BaseController[])(object)new BaseController[2]
				{
					rm.ControllerRig.leftController,
					rm.ControllerRig.rightController
				};
				for (int num = 0; num < array3.Length; num++)
				{
					Haptor component6 = ((Component)array3[num]).GetComponent<Haptor>();
					if ((Object)(object)component6 != (Object)null)
					{
						component6.hapticsAllowed = false;
						((Behaviour)component6).enabled = false;
					}
				}
			}
			catch
			{
			}
			AddImpactProperties(rm);
		}

		private static void SwapControllers(RigManager rm)
		{
			ControllerRig controllerRig = rm.ControllerRig;
			Haptor haptor = controllerRig.leftController.haptor;
			controllerRig.leftController = ((Component)controllerRig.leftController).gameObject.AddComponent<BaseController>();
			controllerRig.leftController.contRig = controllerRig;
			if ((Object)(object)haptor != (Object)null)
			{
				haptor.device_Controller = controllerRig.leftController;
			}
			controllerRig.leftController.handedness = (Handedness)1;
			Haptor haptor2 = controllerRig.rightController.haptor;
			controllerRig.rightController = ((Component)controllerRig.rightController).gameObject.AddComponent<BaseController>();
			controllerRig.rightController.contRig = controllerRig;
			if ((Object)(object)haptor2 != (Object)null)
			{
				haptor2.device_Controller = controllerRig.rightController;
			}
			controllerRig.rightController.handedness = (Handedness)2;
		}

		private static void AddImpactProperties(RigManager rm)
		{
			try
			{
				PhysicsRig physicsRig = rm.physicsRig;
				SurfaceData val = physicsRig._surfaceDataDefault;
				try
				{
					if ((Object)(object)rm.avatar != (Object)null && (Object)(object)rm.avatar.surfaceData != (Object)null)
					{
						val = rm.avatar.surfaceData;
					}
				}
				catch
				{
				}
				List<ImpactProperties> val2 = new List<ImpactProperties>();
				System.Collections.Generic.IEnumerator<Rigidbody> enumerator = ((Component)physicsRig).GetComponentsInChildren<Rigidbody>(true).GetEnumerator();
				try
				{
					while (((System.Collections.IEnumerator)enumerator).MoveNext())
					{
						Rigidbody current = enumerator.Current;
						GameObject gameObject = ((Component)current).gameObject;
						if (!((Object)(object)gameObject == (Object)(object)physicsRig.knee) && !((Object)(object)gameObject == (Object)(object)physicsRig.feet))
						{
							ImpactProperties val3 = ((Component)current).GetComponent<ImpactProperties>();
							if ((Object)(object)val3 == (Object)null)
							{
								val3 = gameObject.AddComponent<ImpactProperties>();
								val3.decalType = (DecalType)(-1);
							}
							val3.surfaceData = val;
							try
							{
								val3._cachedSurfaceData = val;
								val3._isSurfaceDataLoaded = true;
							}
							catch
							{
							}
							val2.Add(val3);
						}
					}
				}
				finally
				{
					((System.IDisposable)enumerator)?.Dispose();
				}
				physicsRig._impactProperties = new Il2CppReferenceArray<ImpactProperties>(val2.ToArray());
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[Bot] impact properties: " + ex.Message);
			}
		}

		private static void DestroyByTypeName(GameObject root, string typeName)
		{
			System.Collections.Generic.IEnumerator<Component> enumerator = root.GetComponentsInChildren<Component>(true).GetEnumerator();
			try
			{
				while (((System.Collections.IEnumerator)enumerator).MoveNext())
				{
					Component current = enumerator.Current;
					if (!((Object)(object)current == (Object)null) && ((MemberInfo)((Object)current).GetIl2CppType()).Name == typeName)
					{
						try
						{
							Object.DestroyImmediate((Object)(object)current);
						}
						catch
						{
						}
					}
				}
			}
			finally
			{
				((System.IDisposable)enumerator)?.Dispose();
			}
		}

		[IteratorStateMachine(typeof(<SwapAvatar>d__7))]
		public static System.Collections.IEnumerator SwapAvatar(RigManager rm, string barcode, Action<bool> done)
		{
			AvatarCrate crate = ((CrateReferenceT<AvatarCrate>)new AvatarCrateReference(barcode)).Crate;
			if ((Object)(object)crate == (Object)null)
			{
				done?.Invoke(false);
				yield break;
			}
			bool loaded = false;
			GameObject asset = null;
			((CrateT<GameObject>)(object)crate).LoadAsset(Action<GameObject>.op_Implicit((Action<GameObject>)delegate(GameObject g)
			{
				loaded = true;
				asset = g;
			}));
			float timeout = Time.time + 15f;
			while (!loaded && Time.time < timeout)
			{
				yield return null;
			}
			if ((Object)(object)rm == (Object)null || (Object)(object)asset == (Object)null)
			{
				done?.Invoke(false);
				yield break;
			}
			GameObject val = Object.Instantiate<GameObject>(asset);
			val.SetActive(false);
			((Object)val).name = ((Object)asset).name;
			val.transform.parent = ((Component)rm).transform;
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			Avatar avatar = val.GetComponentInParent<Avatar>(true);
			if ((Object)(object)avatar == (Object)null)
			{
				avatar = val.GetComponentInChildren<Avatar>(true);
			}
			rm.SwapAvatar(avatar);
			timeout = Time.time + 10f;
			while ((Object)(object)rm != (Object)null && (Object)(object)rm.avatar != (Object)(object)avatar && Time.time < timeout)
			{
				yield return null;
			}
			if ((Object)(object)rm == (Object)null)
			{
				yield break;
			}
			rm._avatarCrate = new AvatarCrateReference(((Scannable)crate).Barcode);
			try
			{
				Action onAvatarSwapped = rm.onAvatarSwapped;
				if (onAvatarSwapped != null)
				{
					onAvatarSwapped.Invoke();
				}
			}
			catch
			{
			}
			try
			{
				rm.onAvatarSwapped2?.Invoke(((Scannable)crate).Barcode);
			}
			catch
			{
			}
			AddImpactProperties(rm);
			try
			{
				rm.physicsRig.headSfx.mouthSrc.mute = true;
			}
			catch
			{
			}
			done?.Invoke((Object)(object)rm.avatar == (Object)(object)avatar);
		}
	}
	public enum NpcPreset
	{
		Shopkeeper,
		Pedestrian
	}
	public class BotNpc
	{
		private struct Ring
		{
			public float Y;

			public float X;

			public float Z;

			public float NegZ;
		}

		public RigManager Rig;

		public NpcPreset Preset;

		public string AvatarBarcode;

		public string AvatarTitle;

		public Vector3 Home;

		public bool Ready;

		public float Health = 1f;

		public bool Dead;

		public int ErrorCount;

		public int NetId;

		public byte Owner;

		public bool IsRemote;

		private Vector3? _talkTarget;

		private OpenControllerRig _ocr;

		private Transform _headset;

		private Transform _leftCtrl;

		private Transform _rightCtrl;

		private Transform _vrRoot;

		private BaseController _leftInput;

		private BaseController _rightInput;

		private Rigidbody _pelvis;

		private Transform _leftPhysHand;

		private Transform _rightPhysHand;

		private AudioSource _voice;

		private VoiceLine _lastLine;

		private VoiceLine _currentLine;

		private float _lineStart;

		private float _maxRigHealth = 1f;

		private float _eye = 1.65f;

		private Vector3? _moveTarget;

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

		private int _pathIndex;

		private float _nextRepath;

		private float _speed = 0.45f;

		private float _yaw;

		private Vector3 _moveDir;

		private float _moveSpeed;

		private float _steerOffset;

		private float _waitUntil;

		private float _stuckTimer;

		private Vector3 _lastPos;

		private float _cornerBestDist = 3.4028235E+38f;

		private float _cornerProgressTime;

		private Vector3? _lookAt;

		private GestureDef _gesture;

		private float _gestureUntil;

		private float _gestureStart;

		private float _gestureBlend;

		private Pose _lastGesturePose;

		private bool _hasLastGesturePose;

		private float _nextIdleAnim;

		private readonly List<string> _recentIdle = new List<string>();

		private float _followUntil;

		private float _stayUntil;

		private Vector3 _leftCorr;

		private Vector3 _rightCorr;

		private float _idleLookYaw;

		private float _nextIdleLook;

		private float _nod;

		private float _nextSmallTalk;

		private float _greetCooldown;

		private float _fearCooldown;

		private float _touchCooldown;

		private float _painCooldown;

		private float _nextTouchLine;

		private float _nextBeckon;

		private float _nextPassWave;

		private bool _playerWasNear;

		private float _fleeUntil;

		private float _surrenderUntil;

		private bool _surrendering;

		private readonly List<Ring> _torso = new List<Ring>();

		private float _headRX = 0.1f;

		private float _headRZ = 0.11f;

		private Vector3 _poseHeadPos = new Vector3(0f, 1.65f, 0f);

		private Vector3 _poseL;

		private Vector3 _poseR;

		private Quaternion _poseHeadRot = Quaternion.identity;

		private Quaternion _poseLR = Quaternion.identity;

		private Quaternion _poseRR = Quaternion.identity;

		private float _reactUntil;

		private bool _greeted;

		private float _awaySince = -1f;

		private float _attentionUntil;

		private bool _turningToPlayer;

		private float _lastLineEnd;

		private float _nextChat;

		private BotNpc _chatPartner;

		private float _chatUntil;

		private float _replyAt = -1f;

		private Transform _jaw;

		private Quaternion _jawRest;

		private bool _jawSearched;

		private float _remoteTouchSent;

		private readonly float[] _net = new float[28];

		private bool _hasNet;

		private Vector3 _netPelvis;

		private float _netYaw;

		private Vector2 _netStick;

		public float Yaw => _yaw;

		public Vector3 Feet => Rig.physicsRig.feet.transform.position;

		public Vector3 HeadPos => ((Rig)Rig.physicsRig).m_head.position;

		public bool IsTalking
		{
			get
			{
				if ((Object)(object)_voice != (Object)null)
				{
					return _voice.isPlaying;
				}
				return false;
			}
		}

		private bool GestureBusy
		{
			get
			{
				if (_gesture != null)
				{
					return Time.time < _gestureUntil;
				}
				return false;
			}
		}

		public bool IsListening => Time.time < _attentionUntil;

		public void Init(float yaw)
		{
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			_ocr = ((Il2CppObjectBase)Rig.ControllerRig).TryCast<OpenControllerRig>();
			_headset = _ocr.headset;
			_vrRoot = _ocr.vrRoot;
			_leftInput = Rig.ControllerRig.leftController;
			_rightInput = Rig.ControllerRig.rightController;
			_leftCtrl = ((Component)_leftInput).transform;
			_rightCtrl = ((Component)_rightInput).transform;
			_pelvis = ((Component)((Rig)Rig.physicsRig).m_pelvis).GetComponent<Rigidbody>();
			_leftPhysHand = ((Component)Rig.physicsRig.leftHand).transform;
			_rightPhysHand = ((Component)Rig.physicsRig.rightHand).transform;
			_yaw = yaw;
			try
			{
				_maxRigHealth = Mathf.Max(0.01f, Rig.health.max_Health);
			}
			catch
			{
			}
			GameObject val = new GameObject("NpcVoiceMod_Voice");
			val.transform.SetParent(((Rig)Rig.physicsRig).m_head, false);
			_voice = val.AddComponent<AudioSource>();
			_voice.spatialBlend = 1f;
			_voice.minDistance = 1.5f;
			_voice.maxDistance = 30f;
			_voice.playOnAwake = false;
			try
			{
				_voice.outputAudioMixerGroup = Audio3dManager.npcVocals;
			}
			catch
			{
			}
			_voice.pitch = Random.Range(0.96f, 1.04f);
			_nextSmallTalk = Time.time + Random.Range(4f, 9f);
			_greetCooldown = Time.time + 1.5f;
			_nextIdleAnim = Time.time + Random.Range(20f, 60f);
			_lastPos = Home;
		}

		private static float Sane(float v, float def)
		{
			if (!float.IsNaN(v) && !(v < 0.04f) && !(v > 1.2f))
			{
				return v;
			}
			return def;
		}

		private void ReadBodyShape()
		{
			_torso.Clear();
			float num = _eye / 1.65f;
			float num2 = _eye * 0.55f;
			float num3 = _eye * 0.78f;
			float num4 = 0.17f * num;
			float num5 = 0.11f * num;
			float num6 = 0.12f * num;
			float num7 = 0.14f * num;
			float num8 = 0.1f * num;
			float num9 = 0.09f * num;
			float num10 = 0.17f * num;
			float num11 = 0.12f * num;
			float num12 = 0.1f * num;
			try
			{
				Avatar avatar = Rig.avatar;
				if ((Object)(object)avatar != (Object)null)
				{
					num2 = Mathf.Clamp(avatar.pelvisHeight, _eye * 0.35f, _eye * 0.7f);
					num3 = Mathf.Clamp(avatar.chestHeight, num2 + 0.1f, _eye - 0.1f);
					num4 = Sane(avatar._hipsEllipseX, num4);
					num5 = Sane(avatar._hipsEllipseZ, num5);
					num6 = Sane(avatar._hipsEllipseNegZ, num6);
					num7 = Sane(avatar._waistEllipseX, num7);
					num8 = Sane(avatar._waistEllipseZ, num8);
					num9 = Sane(avatar._waistEllipseNegZ, num9);
					num10 = Sane(avatar._chestEllipseX, num10);
					num11 = Sane(avatar._chestEllipseZ, num11);
					num12 = Sane(avatar._chestEllipseNegZ, num12);
					_headRX = Sane(avatar._headEllipseX, _headRX);
					_headRZ = Sane(Mathf.Max(avatar._headEllipseZ, avatar._headEllipseNegZ), _headRZ);
				}
			}
			catch
			{
			}
			_torso.Add(new Ring
			{
				Y = num2 - 0.12f * num,
				X = num4,
				Z = num5,
				NegZ = num6
			});
			_torso.Add(new Ring
			{
				Y = num2,
				X = num4,
				Z = num5,
				NegZ = num6
			});
			_torso.Add(new Ring
			{
				Y = (num2 + num3) * 0.5f,
				X = num7,
				Z = num8,
				NegZ = num9
			});
			_torso.Add(new Ring
			{
				Y = num3,
				X = num10,
				Z = num11,
				NegZ = num12
			});
			_torso.Add(new Ring
			{
				Y = _eye - 0.18f * num,
				X = num10 * 1.15f,
				Z = num11 * 0.8f,
				NegZ = num12 * 0.8f
			});
			if (Settings.DebugLog.Value)
			{
				MelonLogger.Msg($"[Bot] {AvatarTitle} body: eye {_eye:0.00} pelvis {num2:0.00} chest {num3:0.00} chestX {num10:0.00} chestZ {num11:0.00}/{num12:0.00}");
			}
		}

		private Vector3 KeepOutOfBody(Vector3 p, Vector3 headOffset)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: 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_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_021f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: 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_00d5: 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)
			float x = headOffset.x;
			float num = headOffset.z * 0.5f;
			if (_torso.Count > 1 && p.y > _torso[0].Y && p.y < _torso[_torso.Count - 1].Y + 0.08f)
			{
				Ring ring = _torso[_torso.Count - 1];
				for (int i = 0; i + 1 < _torso.Count; i++)
				{
					if (p.y <= _torso[i + 1].Y)
					{
						float num2 = Mathf.InverseLerp(_torso[i].Y, _torso[i + 1].Y, p.y);
						ring = new Ring
						{
							X = Mathf.Lerp(_torso[i].X, _torso[i + 1].X, num2),
							Z = Mathf.Lerp(_torso[i].Z, _torso[i + 1].Z, num2),
							NegZ = Mathf.Lerp(_torso[i].NegZ, _torso[i + 1].NegZ, num2)
						};
						break;
					}
				}
				p = PushOutOfEllipse(p, x, num, ring.X + 0.075f, ((p.z >= num) ? ring.Z : ring.NegZ) + 0.075f);
			}
			float num3 = _eye + headOffset.y;
			if (Mathf.Abs(p.y - num3) < 0.14f)
			{
				p = PushOutOfEllipse(p, headOffset.x, headOffset.z, _headRX + 0.060000002f, _headRZ + 0.060000002f);
			}
			return p;
		}

		private static Vector3 PushOutOfEllipse(Vector3 p, float cx, float cz, float rx, float rz)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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)
			float num = p.x - cx;
			float num2 = p.z - cz;
			float num3 = num * num / (rx * rx) + num2 * num2 / (rz * rz);
			if (num3 >= 1f)
			{
				return p;
			}
			if (num3 < 1E-06f)
			{
				p.z = cz + rz;
				return p;
			}
			float num4 = 1f / Mathf.Sqrt(num3);
			p.x = cx + num * num4;
			p.z = cz + num2 * num4;
			return p;
		}

		public void OnAvatarReady()
		{
			//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_0059: 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)
			try
			{
				if ((Object)(object)Rig.avatar != (Object)null && Rig.avatar.eyeHeight > 0.2f)
				{
					_eye = Rig.avatar.eyeHeight;
				}
			}
			catch
			{
			}
			ReadBodyShape();
			_leftCorr = (_rightCorr = Vector3.zero);
			_jawSearched = false;
			_jaw = null;
		}

		public void OverrideTracking()
		{
			//IL_0068: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_0178: 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_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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: 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_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: 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_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0366: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: 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_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: 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)
			//IL_0329: 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_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_035e: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Rig == (Object)null || (Object)(object)_headset == (Object)null)
			{
				return;
			}
			float num = Mathf.Min(Time.deltaTime, 0.05f);
			Rig.remapHeptaRig.inWeight = 1f;
			if (IsRemote)
			{
				RemoteTracking(num);
				return;
			}
			_vrRoot.rotation = Quaternion.Euler(0f, _yaw, 0f);
			Body b = new Body
			{
				Eye = _eye,
				S = _eye / 1.65f
			};
			Pose pose = BasePose(b);
			UpdateGesturePose(b, ref pose, num);
			Quaternion val = Quaternion.identity;
			bool flag = _moveSpeed > 0.01f;
			Vector3? lookAt = _lookAt;
			if (lookAt.HasValue)
			{
				Vector3 val2 = Quaternion.Inverse(_vrRoot.rotation) * (lookAt.Value - HeadPos);
				if (((Vector3)(ref val2)).sqrMagnitude > 0.01f)
				{
					Quaternion val3 = Quaternion.LookRotation(((Vector3)(ref val2)).normalized, Vector3.up);
					Vector3 eulerAngles = ((Quaternion)(ref val3)).eulerAngles;
					val = Quaternion.Euler(Mathf.Clamp(Mathf.DeltaAngle(0f, eulerAngles.x), -30f, 30f), Mathf.Clamp(Mathf.DeltaAngle(0f, eulerAngles.y), -60f, 60f), 0f);
				}
			}
			else if (!flag)
			{
				val = Quaternion.Euler(0f, _idleLookYaw, 0f);
			}
			if (_nod > 0.001f)
			{
				pose.HeadEuler.x += Mathf.Sin(Time.time * 9f) * 9f * _nod;
			}
			val *= Quaternion.Euler(pose.HeadEuler);
			_poseHeadPos = new Vector3(0f, _eye, 0f) + pose.HeadOffset;
			_poseHeadRot = Quaternion.Slerp(_poseHeadRot, val, 1f - Mathf.Exp(-5f * num));
			_leftCorr = (_rightCorr = Vector3.zero);
			if (_torso.Count == 0)
			{
				ReadBodyShape();
			}
			pose.L = KeepOutOfBody(pose.L, pose.HeadOffset);
			pose.R = KeepOutOfBody(pose.R, pose.HeadOffset);
			_poseL = pose.L + _leftCorr;
			_poseR = pose.R + _rightCorr;
			_poseLR = pose.LR;
			_poseRR = pose.RR;
			ReapplyPose();
			Vector2 val4 = Vector2.zero;
			if (flag && !Dead)
			{
				float num2 = _yaw + _headset.localEulerAngles.y;
				Vector3 val5 = Quaternion.Euler(0f, 0f - (num2 + _steerOffset), 0f) * _moveDir;
				((Vector2)(ref val4))..ctor(val5.x, val5.z);
				if (((Vector2)(ref val4)).sqrMagnitude > 1f)
				{
					((Vector2)(ref val4)).Normalize();
				}
				val4 *= _moveSpeed;
			}
			_leftInput._thumbstickAxis = val4;
			_rightInput._thumbstickAxis = Vector2.zero;
		}

		private Vector3 CorrectHand(Vector3 corr, Vector3 target, Transform physHand, float dt)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: 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_0039: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)physHand == (Object)null)
			{
				return corr;
			}
			Vector3 val = _vrRoot.InverseTransformPoint(physHand.position);
			Vector3 val2 = target - val;
			if (((Vector3)(ref val2)).magnitude > 0.6f)
			{
				return corr * 0.98f;
			}
			float num = (GestureBusy ? 0.6f : 3f);
			corr += val2 * (num * dt);
			return Vector3.ClampMagnitude(corr, 0.3f);
		}

		public void ReapplyPose()
		{
			//IL_0025: 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_0047: 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_0069: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_headset == (Object)null))
			{
				_vrRoot.rotation = Quaternion.Euler(0f, _yaw, 0f);
				_headset.localPosition = _poseHeadPos;
				_headset.localRotation = _poseHeadRot;
				_leftCtrl.localPosition = _poseL;
				_rightCtrl.localPosition = _poseR;
				_leftCtrl.localRotation = _poseLR;
				_rightCtrl.localRotation = _poseRR;
			}
		}

		private Pose BasePose(Body b)
		{
			//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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Sin(Time.time * 1.6f) * 0.008f;
			float num2 = ((_moveSpeed > 0.01f) ? (Mathf.Sin(Time.time * 6.5f) * 0.12f * Mathf.Clamp01(_moveSpeed * 1.6f)) : 0f);
			return new Pose
			{
				L = new Vector3((0f - b.Side) * 1.05f, b.Hip + 0.04f * b.S + num, 0.17f * b.S + num2),
				R = new Vector3(b.Side * 1.05f, b.Hip + 0.04f * b.S + num, 0.17f * b.S - num2),
				LR = Quaternion.Euler(50f, -6f, 0f),
				RR = Quaternion.Euler(50f, 6f, 0f)
			};
		}

		private void UpdateGesturePose(Body b, ref Pose pose, float dt)
		{
			bool flag = _gesture != null && Time.time < _gestureUntil;
			_gestureBlend = Mathf.MoveTowards(_gestureBlend, flag ? 1f : 0f, dt / 0.35f);
			if (flag)
			{
				Pose p = pose;
				try
				{
					_gesture.Fn(Time.time - _gestureStart, b, ref p);
				}
				catch
				{
				}
				_lastGesturePose = p;
				_hasLastGesturePose = true;
			}
			else if (_gestureBlend <= 0f)
			{
				_gesture = null;
				_hasLastGesturePose = false;
			}
			if (_hasLastGesturePose && _gestureBlend > 0f)
			{
				Pose lastGesturePose = _lastGesturePose;
				float t = Mathf.SmoothStep(0f, 1f, _gestureBlend);
				pose = Pose.Lerp(pose, lastGesturePose, t);
			}
		}

		public void PlayGesture(string name, float duration = -1f)
		{
			GestureDef gestureDef = Gestures.Get(name);
			if (gestureDef != null && (!_surrendering || !(name != "HandsUp")))
			{
				if (_gesture != gestureDef || Time.time > _gestureUntil)
				{
					_gestureStart = Time.time;
				}
				_gesture = gestureDef;
				_gestureUntil = Time.time + ((duration > 0f) ? duration : gestureDef.Duration);
			}
		}

		private void TryIdleAnimation()
		{
			if (Time.time < _nextIdleAnim)
			{
				return;
			}
			if (GestureBusy || _moveSpeed > 0.01f || IsTalking || _surrendering)
			{
				_nextIdleAnim = Time.time + 3f;
				return;
			}
			_nextIdleAnim = Time.time + Random.Range(Settings.IdleAnimMin.Value, Settings.IdleAnimMax.Value);
			List<GestureDef> idle = Gestures.Idle;
			GestureDef gestureDef = null;
			for (int i = 0; i < 20; i++)
			{
				if (gestureDef != null)
				{
					break;
				}
				GestureDef gestureDef2 = idle[Random.Range(0, idle.Count)];
				if (!_recentIdle.Contains(gestureDef2.Name))
				{
					gestureDef = gestureDef2;
				}
			}
			if (gestureDef == null)
			{
				gestureDef = idle[Random.Range(0, idle.Count)];
			}
			_recentIdle.Add(gestureDef.Name);
			if (_recentIdle.Count > 15)
			{
				_recentIdle.RemoveAt(0);
			}
			if (Preset == NpcPreset.Pedestrian)
			{
				_waitUntil = Mathf.Max(_waitUntil, Time.time + gestureDef.Duration + 0.5f);
			}
			PlayGesture(gestureDef.Name);
			if (Settings.DebugLog.Value)
			{
				MelonLogger.Msg("[Anim] " + AvatarTitle + ": " + gestureDef.Name);
			}
		}

		public void Tick(Vector3 playerHead, bool playerHasGun, Vector3 gunFwd, Vector3 gunPos, Vector3 leftHand, Vector3 rightHand)
		{
			//IL_0020: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_00dd: 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)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: 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_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0402: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0457: Unknown result type (might be due to invalid IL or missing references)
			//IL_0452: Unknown result type (might be due to invalid IL or missing references)
			//IL_045c: Unknown result type (might be due to invalid IL or missing references)
			//IL_045f: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_0532: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05da: Unknown result type (might be due to invalid IL or missing references)
			//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: 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_05f4: 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)
			if (!Ready || (Object)(object)Rig == (Object)null)
			{
				return;
			}
			if (IsRemote)
			{
				RemoteTick(playerHead, leftHand, rightHand);
				return;
			}
			if (Dead)
			{
				_moveDir = Vector3.zero;
				_moveSpeed = 0f;
				_moveTarget = null;
				return;
			}
			Vector3 headPos = HeadPos;
			float num = Vector3.Distance(headPos, playerHead);
			_nod = Mathf.MoveTowards(_nod, (IsTalking && Preset == NpcPreset.Shopkeeper && !_surrendering) ? 1f : 0f, Time.deltaTime * 3f);
			Vector3 b = (headPos + _pelvis.position) * 0.5f;
			if (Time.time > _touchCooldown && (Near(leftHand, headPos, 0.32f) || Near(rightHand, headPos, 0.32f) || Near(leftHand, b, 0.3f) || Near(rightHand, b, 0.3f) || Near(leftHand, _pelvis.position, 0.3f) || Near(rightHand, _pelvis.position, 0.3f)))
			{
				OnTouched();
			}
			bool flag = false;
			Vector3 val;
			if (playerHasGun && num < 14f)
			{
				val = headPos - gunPos;
				flag = Vector3.Dot(gunFwd, ((Vector3)(ref val)).normalized) > 0.93f || num < 2.5f;
			}
			if (flag)
			{
				if (!_surrendering)
				{
					_surrendering = true;
					_fearCooldown = Time.time + Random.Range(4f, 7f);
					Say(VoiceCategory.Fear, "gun", interrupt: true);
				}
				_surrenderUntil = Time.time + 2.5f;
			}
			if (_surrendering && Time.time > _surrenderUntil)
			{
				_surrendering = false;
				_gestureUntil = 0f;
				_moveTarget = null;
				_waitUntil = Time.time + 1.5f;
			}
			if (_surrendering && Time.time > _fearCooldown)
			{
				_fearCooldown = Time.time + Random.Range(5f, 8f);
				Say(VoiceCategory.Fear, "still aimed at");
			}
			bool flag2 = num < Settings.GreetDistance.Value;
			if (num > 15f)
			{
				if (_awaySince < 0f)
				{
					_awaySince = Time.time;
				}
			}
			else
			{
				_awaySince = -1f;
			}
			float value = Settings.GreetAgainMinutes.Value;
			if (_greeted && value > 0f && _awaySince > 0f && Time.time - _awaySince > value * 60f)
			{
				_greeted = false;
			}
			if (flag2 && !_greeted && Time.time > _greetCooldown && !_surrendering)
			{
				_greeted = true;
				Say(VoiceCategory.Greeting, "walked up");
				PlayGesture("Wave");
				_nextSmallTalk = Time.time + Random.Range(5f, 9f);
			}
			_playerWasNear = flag2;
			if (num < Settings.TalkDistance.Value && Time.time > _nextSmallTalk && !IsTalking && !_surrendering)
			{
				_nextSmallTalk = Time.time + Random.Range(Settings.SmallTalkMin.Value, Settings.SmallTalkMax.Value);
				Say(VoiceCategory.SmallTalk, "small talk");
			}
			if (IsTalking && !GestureBusy && !_surrendering && _moveSpeed < 0.01f)
			{
				PlayGesture("Talk", 0.5f);
			}
			else if (!IsTalking && _gesture != null && _gesture.Name == "Talk")
			{
				_gestureUntil = 0f;
			}
			TryIdleAnimation();
			_moveDir = Vector3.zero;
			_moveSpeed = 0f;
			if (_surrendering)
			{
				Surrender(playerHead, num);
			}
			else if (Time.time < _reactUntil || IsListening)
			{
				Vector3 val2 = (Vector3)(((??)_talkTarget) ?? playerHead);
				FaceTowards(val2, 4f);
				_lookAt = val2;
			}
			else if (Time.time < _followUntil)
			{
				Follow(playerHead, num);
			}
			else if (Time.time < _stayUntil)
			{
				_moveTarget = null;
				_lookAt = ((num < 7f) ? new Vector3?(playerHead) : ((Vector3?)null));
				if (num < 5f)
				{
					FaceTowards(playerHead, 2f);
				}
			}
			else if (Time.time < _fleeUntil)
			{
				FollowPath();
			}
			else if (_chatPartner != null && num > Settings.TalkDistance.Value)
			{
				UpdateChat();
			}
			else
			{
				_chatPartner = null;
				if (Preset == NpcPreset.Shopkeeper)
				{
					ThinkShopkeeper(playerHead, num);
				}
				else
				{
					ThinkPedestrian(playerHead, num);
				}
			}
			if (!IsListening && Time.time > _reactUntil)
			{
				_talkTarget = null;
			}
			if (_chatPartner == null && !_talkTarget.HasValue && num < Settings.LookDistance.Value)
			{
				_lookAt = playerHead;
				if (_moveSpeed < 0.01f && !_surrendering)
				{
					float yaw = _yaw;
					val = Flat(playerHead - Feet);
					Quaternion val3 = Quaternion.LookRotation((((Vector3)(ref val)).sqrMagnitude > 0.01f) ? Flat(playerHead - Feet) : Vector3.forward);
					float num2 = Mathf.Abs(Mathf.DeltaAngle(yaw, ((Quaternion)(ref val3)).eulerAngles.y));
					if (num2 > 40f || _turningToPlayer)
					{
						_turningToPlayer = num2 > 5f;
						FaceTowards(playerHead, 2.5f);
					}
				}
			}
			UpdateIdleLook();
			CalibrateSteering();
		}

		private static bool Near(Vector3 a, Vector3 b, float r)
		{
			//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_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = a - b;
			return ((Vector3)(ref val)).sqrMagnitude < r * r;
		}

		public void React(string topic, string saidText, Vector3? speaker = null)
		{
			if (Dead || !Ready || IsRemote)
			{
				return;
			}
			_talkTarget = speaker;
			VoiceCategory cat = default(VoiceCategory);
			if (!System.Enum.TryParse<VoiceCategory>("Answer_" + topic, ref cat))
			{
				return;
			}
			string text;
			if (topic != null)
			{
				switch (topic.Length)
				{
				case 5:
					break;
				case 6:
					goto IL_00b0;
				case 4:
					goto IL_00d9;
				case 9:
					goto IL_017f;
				case 3:
					goto IL_01d3;
				case 7:
					goto IL_01e8;
				case 10:
					goto IL_01fd;
				case 8:
					goto IL_027b;
				default:
					goto IL_037d;
				}
				switch (topic[0])
				{
				case 'H':
					break;
				case 'S':
					goto IL_012b;
				case 'O':
					goto IL_0140;
				case 'P':
					goto IL_0155;
				case 'D':
					goto IL_016a;
				default:
					goto IL_037d;
				}
				if (topic == "Hello")
				{
					text = "Wave";
					goto IL_0380;
				}
			}
			goto IL_037d;
			IL_01fd:
			if (!(topic == "Compliment"))
			{
				goto IL_037d;
			}
			text = "RubNeck";
			goto IL_0380;
			IL_012b:
			if (!(topic == "Sorry"))
			{
				goto IL_037d;
			}
			text = "NodYes";
			goto IL_0380;
			IL_016a:
			if (!(topic == "Dance"))
			{
				goto IL_037d;
			}
			text = ((Random.value < 0.5f) ? "Dance" : "Salsa");
			goto IL_0380;
			IL_0140:
			if (!(topic == "Order"))
			{
				goto IL_037d;
			}
			text = "NodYes";
			goto IL_0380;
			IL_0155:
			if (!(topic == "Price"))
			{
				goto IL_037d;
			}
			text = "PalmUp";
			goto IL_0380;
			IL_01d3:
			if (!(topic == "Sad"))
			{
				goto IL_037d;
			}
			text = "Comfort";
			goto IL_0380;
			IL_01e8:
			if (!(topic == "Goodbye"))
			{
				goto IL_037d;
			}
			text = ((Random.value < 0.5f) ? "Wave" : "Wave2");
			goto IL_0380;
			IL_00d9:
			switch (topic[0])
			{
			case 'J':
				break;
			case 'N':
				goto IL_0227;
			case 'H':
				goto IL_023c;
			case 'L':
				goto IL_0251;
			case 'S':
				goto IL_0266;
			default:
				goto IL_037d;
			}
			if (!(topic == "Joke"))
			{
				goto IL_037d;
			}
			text = "Laugh";
			goto IL_0380;
			IL_023c:
			if (!(topic == "Help"))
			{
				goto IL_037d;
			}
			text = "PointFar";
			goto IL_0380;
			IL_00b0:
			char c = topic[0];
			if (c != 'H')
			{
				if (c != 'I')
				{
					if (c != 'T' || !(topic == "Thanks"))
					{
						goto IL_037d;
					}
					text = "Bow";
				}
				else
				{
					if (!(topic == "Insult"))
					{
						goto IL_037d;
					}
					text = "Angry";
				}
			}
			else
			{
				if (!(topic == "Hungry"))
				{
					goto IL_037d;
				}
				text = "PatBelly";
			}
			goto IL_0380;
			IL_037d:
			text = null;
			goto IL_0380;
			IL_0380:
			string text2 = text;
			if (topic == "HandsUp")
			{
				_surrendering = true;
				_surrenderUntil = Time.time + 5f;
				_fearCooldown = Time.time + 5f;
				if (!Say(cat, "you said: " + saidText, interrupt: true))
				{
					Say(VoiceCategory.Fear, "you said: " + saidText, interrupt: true);
				}
			}
			else if (!_surrendering)
			{
				if (topic == "FollowMe")
				{
					_followUntil = Time.time + 90f;
					_stayUntil = 0f;
				}
				if (topic == "Stay")
				{
					_stayUntil = Time.time + 90f;
					_followUntil = 0f;
					_moveTarget = null;
					_path.Clear();
				}
				if (topic == "Goodbye")
				{
					_followUntil = 0f;
				}
				float num = ((text2 != null) ? Gestures.Get(text2) : null)?.Duration ?? 2f;
				if (text2 != null)
				{
					PlayGesture(text2);
				}
				if (Say(cat, "you said: " + saidText, interrupt: true) && (Object)(object)_currentLine?.Clip != (Object)null)
				{
					num = Mathf.Max(num, _currentLine.Clip.length);
				}
				_reactUntil = Time.time + num + 0.3f;
				_attentionUntil = Mathf.Max(_attentionUntil, _reactUntil + 3f);
				_moveTarget = null;
				_path.Clear();
				if (Preset == NpcPreset.Pedestrian)
				{
					_waitUntil = Mathf.Max(_waitUntil, _reactUntil + 1f);
				}
				_nextSmallTalk = Time.time + num + Random.Range(6f, 10f);
				_greetCooldown = Mathf.Max(_greetCooldown, Time.time + 10f);
			}
			return;
			IL_0251:
			if (!(topic == "Love"))
			{
				goto IL_037d;
			}
			text = "Heart";
			goto IL_0380;
			IL_027b:
			if (!(topic == "FollowMe"))
			{
				goto IL_037d;
			}
			text = "NodYes";
			goto IL_0380;
			IL_0227:
			if (!(topic == "Name"))
			{
				goto IL_037d;
			}
			text = "PointSelf";
			goto IL_0380;
			IL_017f:
			if (!(topic == "HowAreYou"))
			{
				goto IL_037d;
			}
			text = ((Random.value < 0.5f) ? "ThumbsUp" : "Shrug");
			goto IL_0380;
			IL_0266:
			if (!(topic == "Stay"))
			{
				goto IL_037d;
			}
			text = "PalmUp";
			goto IL_0380;
		}

		private void Follow(Vector3 playerHead, float dist)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			_lookAt = playerHead;
			if (dist > 3f)
			{
				GoTo(GroundBelow(playerHead), (dist > 7f) ? 0.9f : 0.55f, 1f);
				FollowPath();
			}
			else if (dist < 2.2f)
			{
				_moveTarget = null;
				_path.Clear();
				FaceTowards(playerHead, 3f);
			}
			else
			{
				FollowPath();
			}
			if (Preset == NpcPreset.Shopkeeper)
			{
				Home = Feet;
			}
		}

		private void Surrender(Vector3 playerHead, float dist)
		{
			//IL_0011: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: 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)
			PlayGesture("HandsUp", 0.6f);
			_lookAt = playerHead;
			_moveTarget = null;
			_path.Clear();
			FaceTowards(playerHead, 5f);
			Vector3 val = Flat(Feet - playerHead);
			if (((Vector3)(ref val)).sqrMagnitude < 0.001f)
			{
				val = -Flat(Quaternion.Euler(0f, _yaw, 0f) * Vector3.forward);
			}
			((Vector3)(ref val)).Normalize();
			bool num = !Physics.Raycast(_pelvis.position, val, 0.9f, -1, (QueryTriggerInteraction)1);
			bool flag = dist > 9f;
			int num2;
			if (Preset == NpcPreset.Shopkeeper)
			{
				Vector3 val2 = Flat(Feet - Home);
				num2 = ((((Vector3)(ref val2)).magnitude > 2.5f) ? 1 : 0);
			}
			else
			{
				num2 = 0;
			}
			bool flag2 = (byte)num2 != 0;
			if (num && !flag && !flag2)
			{
				_moveDir = val;
				_moveSpeed = 0.28f;
			}
		}

		private void ThinkShopkeeper(Vector3 playerHead, float dist)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_006b: 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)
			Vector3 val = Flat(Feet - Home);
			if (((Vector3)(ref val)).magnitude > (_moveTarget.HasValue ? 0.6f : 1.3f))
			{
				GoTo(Home, 0.4f);
				FollowPath();
				return;
			}
			_moveTarget = null;
			if (dist < 7f)
			{
				FaceTowards(playerHead, 3f);
				_lookAt = playerHead;
				if (dist > Settings.GreetDistance.Value + 0.5f && Time.time > _nextBeckon && !IsTalking && !GestureBusy)
				{
					_nextBeckon = Time.time + Random.Range(12f, 20f);
					PlayGesture("Beckon");
				}
			}
			else
			{
				_lookAt = null;
			}
		}

		private void ThinkPedestrian(Vector3 playerHead, float dist)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			_lookAt = ((dist < 5f) ? new Vector3?(playerHead) : ((Vector3?)null));
			if (dist < 6f && dist > Settings.GreetDistance.Value && Time.time > _nextPassWave && !GestureBusy && Time.time > _greetCooldown)
			{
				_nextPassWave = Time.time + Random.Range(25f, 45f);
				if (Random.value < 0.5f)
				{
					PlayGesture((Random.value < 0.5f) ? "Wave" : "Wave2", 1.8f);
				}
			}
			if (!_moveTarget.HasValue && Time.time > _waitUntil && Sidewalk.TryTakeTurn())
			{
				Vector3? random = WanderPoints.GetRandom();
				Vector3? val = ((!random.HasValue || !(Random.value < 0.35f)) ? (Settings.AvoidRoads.Value ? Sidewalk.ChooseTarget(Feet, _yaw) : RandomNavPoint(Feet, 18f, 5f)) : random);
				if (val.HasValue)
				{
					GoTo(val.Value, 0.45f);
				}
				else
				{
					_waitUntil = Time.time + 2f;
				}
			}
			if (!_moveTarget.HasValue && dist < 4f)
			{
				FaceTowards(playerHead, 2f);
			}
			FollowPath();
		}

		private void GoTo(Vector3 target, float speed, float repathEvery = 4f)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Invalid comparison between Unknown and I4
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			_speed = speed;
			if (_moveTarget.HasValue && Vector3.Distance(_moveTarget.Value, target) < 0.5f && Time.time < _nextRepath)
			{
				return;
			}
			_moveTarget = target;
			_nextRepath = Time.time + repathEvery;
			_path.Clear();
			_pathIndex = 0;
			_cornerBestDist = 3.4028235E+38f;
			_cornerProgressTime = Time.time;
			_stuckTimer = 0f;
			bool flag = false;
			try
			{
				NavMeshPath val = new NavMeshPath();
				Vector3 val2 = Feet;
				Vector3 val3 = target;
				NavMeshHit val4 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val2, ref val4, 2f, -1))
				{
					val2 = ((NavMeshHit)(ref val4)).position;
				}
				NavMeshHit val5 = default(NavMeshHit);
				if (NavMesh.SamplePosition(val3, ref val5, 3f, -1))
				{
					val3 = ((NavMeshHit)(ref val5)).position;
				}
				flag = NavMesh.CalculatePath(val2, val3, -1, val) && (int)val.status != 2;
				if (flag)
				{
					Il2CppStructArray<Vector3> corners = val.corners;
					for (int i = 0; i < ((Il2CppArrayBase<Vector3>)(object)corners).Length; i++)
					{
						if (i == 0)
						{
							Vector3 val6 = Flat(((Il2CppArrayBase<Vector3>)(object)corners)[i] - Feet);
							if (((Vector3)(ref val6)).magnitude < 1f)
							{
								continue;
							}
						}
						_path.Add(((Il2CppArrayBase<Vector3>)(object)corners)[i]);
					}
				}
			}
			catch
			{
				flag = false;
			}
			if (!flag || _path.Count == 0)
			{
				_path.Add(target);
			}
		}

		private void FollowPath()
		{
			//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_00b9: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: 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_01a4: 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_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: 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_020b: 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_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: 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_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			if (!_moveTarget.HasValue || Time.time < _waitUntil)
			{
				return;
			}
			Vector3 feet = Feet;
			bool flag = _pathIndex >= _path.Count - 1;
			float num = (flag ? 0.7f : 1f);
			Vector3 val;
			while (_pathIndex < _path.Count)
			{
				val = Flat(_path[_pathIndex] - feet);
				if (!(((Vector3)(ref val)).magnitude < num))
				{
					break;
				}
				_pathIndex++;
				_cornerBestDist = 3.4028235E+38f;
				_cornerProgressTime = Time.time;
				flag = _pathIndex >= _path.Count - 1;
				num = (flag ? 0.7f : 1f);
			}
			if (_pathIndex >= _path.Count)
			{
				Arrived();
				return;
			}
			Vector3 val2 = Flat(_path[_pathIndex] - feet);
			float magnitude = ((Vector3)(ref val2)).magnitude;
			if (magnitude < _cornerBestDist - 0.15f)
			{
				_cornerBestDist = magnitude;
				_cornerProgressTime = Time.time;
			}
			else if (Time.time - _cornerProgressTime > 2.5f)
			{
				_pathIndex++;
				_cornerBestDist = 3.4028235E+38f;
				_cornerProgressTime = Time.time;
				if (_pathIndex >= _path.Count)
				{
					Arrived();
				}
				return;
			}
			val2 = (_moveDir = val2 / Mathf.Max(magnitude, 0.001f));
			_moveSpeed = (flag ? Mathf.Lerp(0.2f, _speed, Mathf.Clamp01(magnitude / 2f)) : _speed);
			Quaternion val3 = Quaternion.LookRotation(val2);
			float y = ((Quaternion)(ref val3)).eulerAngles.y;
			_yaw = Mathf.MoveTowardsAngle(_yaw, y, 180f * Time.deltaTime);
			val = Flat(feet - _lastPos);
			float magnitude2 = ((Vector3)(ref val)).magnitude;
			_lastPos = feet;
			if (magnitude2 < 0.15f * Time.deltaTime)
			{
				_stuckTimer += Time.deltaTime;
			}
			else
			{
				_stuckTimer = Mathf.Max(0f, _stuckTimer - Time.deltaTime);
			}
			if (_stuckTimer > 0.8f && (Object)(object)_pelvis != (Object)null)
			{
				_pelvis.AddForce(val2 * 8f * _moveSpeed, (ForceMode)5);
			}
			if (_stuckTimer > 4f)
			{
				_stuckTimer = 0f;
				_moveTarget = null;
				_path.Clear();
				_waitUntil = Time.time + 1f;
			}
		}

		private void Arrived()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			_moveTarget = null;
			_path.Clear();
			_moveDir = Vector3.zero;
			_moveSpeed = 0f;
			if (Preset == NpcPreset.Pedestrian)
			{
				_waitUntil = Time.time + Random.Range(3f, 10f);
			}
		}

		private void CalibrateSteering()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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)
			if ((Object)(object)_pelvis == (Object)null)
			{
				return;
			}
			Vector3 val = Flat(_pelvis.velocity);
			if (_moveSpeed > 0.25f && ((Vector3)(ref val)).magnitude > 0.5f && ((Vector3)(ref _moveDir)).sqrMagnitude > 0.5f)
			{
				float num = Vector3.SignedAngle(_moveDir, ((Vector3)(ref val)).normalized, Vector3.up);
				if (Mathf.Abs(num) < 100f)
				{
					_steerOffset = Mathf.Clamp(_steerOffset + num * 0.8f * Time.deltaTime, -60f, 60f);
				}
			}
			else
			{
				_steerOffset = Mathf.MoveTowards(_steerOffset, 0f, 2f * Time.deltaTime);
			}
		}

		private void UpdateIdleLook()
		{
			if (Time.time > _nextIdleLook)
			{
				_nextIdleLook = Time.time + Random.Range(2.5f, 6f);
				_idleLookYaw = ((Random.value < 0.4f) ? 0f : Random.Range(-45f, 45f));
			}
		}

		private void FaceTowards(Vector3 pos, float speed)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_002d: 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)
			Vector3 val = Flat(pos - Feet);
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
			{
				Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized);
				float y = ((Quaternion)(ref val2)).eulerAngles.y;
				_yaw = Mathf.MoveTowardsAngle(_yaw, y, speed * 60f * Time.deltaTime);
			}
		}

		private void Flee(Vector3 from, float seconds)
		{
			//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_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			_fleeUntil = Time.time + seconds;
			Vector3 val = Flat(Feet - from);
			if (((Vector3)(ref val)).sqrMagnitude < 0.01f)
			{
				val = Random.insideUnitSphere;
			}
			val.y = 0f;
			Vector3 val2 = Feet + ((Vector3)(ref val)).normalized * 14f;
			Vector3 target = (Vector3)(((??)RandomNavPoint(val2, 4f)) ?? val2);
			_waitUntil = 0f;
			GoTo(target, 1f);
		}

		private static Vector3? RandomNavPoint(Vector3 around, float radius, float minDist = 0f)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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_0028: 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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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_0022: 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_0045: 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)
			NavMeshHit val3 = default(NavMeshHit);
			for (int i = 0; i < 10; i++)
			{
				Vector2 val = Random.insideUnitCircle * radius;
				if (((Vector2)(ref val)).magnitude < minDist)
				{
					val = ((Vector2)(ref val)).normalized * minDist;
				}
				Vector3 val2 = around + new Vector3(val.x, 0f, val.y);
				try
				{
					if (NavMesh.SamplePosition(val2, ref val3, 3f, -1))
					{
						return ((NavMeshHit)(ref val3)).position;
					}
				}
				catch
				{
				}
			}
			Vector2 insideUnitCircle = Random.insideUnitCircle;
			Vector2 val4 = ((Vector2)(ref insideUnitCircle)).normalized * Mathf.Clamp(radius * 0.4f, minDist, 8f);
			return GroundBelow(around + new Vector3(val4.x, 1.5f, val4.y));
		}

		private static Vector3 GroundBelow(Vector3 p)
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_002c: Unknown result type (might be due to invalid IL or missing references)
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(p + Vector3.up * 0.5f, Vector3.down, ref val, 6f, -1, (QueryTriggerInteraction)1))
			{
				return ((RaycastHit)(ref val)).point;
			}
			return p;
		}

		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;
		}

		public void OnAttacked(Attack attack)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 origin = attack.origin;
			if (((Vector3)(ref origin)).sqrMagnitude < 0.01f && (Object)(object)Player.Head != (Object)null)
			{
				origin = Player.Head.position;
			}
			if (IsRemote)
			{
				Net.SendDamage(this, attack.damage, (byte)attack.attackType, origin);
			}
			else
			{
				ApplyDamage(attack.damage, (byte)attack.attackType, origin);
			}
		}

		public void ApplyDamage(float rawDamage, byte attackType, Vector3 origin)
		{
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			if (Dead || IsRemote)
			{
				return;
			}
			float num = Mathf.Max(0f, rawDamage) / _maxRigHealth / Mathf.Max(0.1f, Settings.Toughness.Value);
			Health -= num;
			MelonLogger.Msg($"[Bot] {AvatarTitle} hit: type {attackType} dmg {rawDamage:0.00} -> health {Mathf.Max(0f, Health) * 100f:0}%");
			if (Health <= 0f)
			{
				Die();
				return;
			}
			bool flag = num > 0.2f || attackType == 1;
			if (Time.time > _painCooldown || flag)
			{
				_painCooldown = Time.time + 0.6f;
				if (!flag || !Say(VoiceCategory.Hurt, "big hit", interrupt: true))
				{
					Say(VoiceCategory.Pain, "hit", interrupt: true);
				}
			}
			if (Preset == NpcPreset.Pedestrian && !_surrendering)
			{
				Flee(origin, 6f);
			}
		}

		public void Die()
		{
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (Dead)
			{
				return;
			}
			Dead = true;
			Health = 0f;
			_surrendering = false;
			_gesture = null;
			_gestureBlend = 0f;
			_hasLastGesturePose = false;
			MelonLogger.Msg("[Bot] " + AvatarTitle + " died");
			_moveTarget = null;
			_moveDir = Vector3.zero;
			_moveSpeed = 0f;
			try
			{
				_leftInput._thumbstickAxis = Vector2.zero;
			}
			catch
			{
			}
			Say(VoiceCategory.Death, "death", interrupt: true);
			try
			{
				Rig.physicsRig.ShutdownRig();
				Rig.physicsRig.RagdollRig();
			}
			catch (System.Exception ex)
			{
				MelonLogger.Warning("[Bot] ragdoll: " + ex.Message);
			}
		}

		public void Revive()
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			if (Dead && !((Object)(object)Rig == (Object)null))
			{
				try
				{
					Rig.physicsRig.TurnOnRig();
					Rig.physicsRig.UnRagdollRig();
				}
				catch (System.Exception ex)
				{
					MelonLogger.Warning("[Bot] revive: " + ex.Message);
				}
				Dead = false;
				Health = 1f;
				_moveTarget = null;
				_fleeUntil = 0f;
				_leftCorr = (_rightCorr = Vector3.zero);
				MelonLogger.Msg("[Bot] " + AvatarTitle + " revived");
			}
		}

		public void OnTouched()
		{
			OnTouched(null);
		}

		public void OnTouched(Vector3? toucherHead)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			_touchCooldown = Time.time + 1.5f;
			if (IsRemote)
			{
				if (Time.time > _remoteTouchSent)
				{
					_remoteTouchSent = Time.time + 2f;
					Net.SendTouched(this, ((Object)(object)Player.Head != (Object)null) ? Player.Head.position : HeadPos);
				}
			}
			else if (!Dead && Ready && !_surrendering)
			{
				if (toucherHead.HasValue)
				{
					_talkTarget = toucherHead;
				}
				bool isListening = IsListening;
				_attentionUntil = Time.time + Settings.ListenSeconds.Value;
				if (Settings.DebugLog.Value && !isListening)
				{
					MelonLogger.Msg("[Bot] " + AvatarTitle + " is listening to you");
				}
				if (!_greeted)
				{
					_greeted = true;
					Say(VoiceCategory.Greeting, "touched", interrupt: true);
					PlayGesture("Wave", 1.8f);
				}
				else if (!isListening && !GestureBusy)
				{
					PlayGesture("NodYes", 1.2f);
				}
			}
		}

		public void TeleportTo(Vector3 p)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_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_004f: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)Rig == (Object)null))
			{
				try
				{
					Rig.Teleport(p, true);
				}
				catch
				{
				}
				_moveTarget = null;
				_path.Clear();
				_lastPos = p;
				_leftCorr = (_rightCorr = Vector3.zero);
				if (Preset == NpcPreset.Shopkeeper)
				{
					Home = p;
				}
			}
		}

		public static void TryConversations(List<BotNpc> bots, Vector3 playerHead)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bots.Count; i++)
			{
				BotNpc botNpc = bots[i];
				if (!botNpc.CanChat(playerHead))
				{
					continue;
				}
				for (int j = i + 1; j < bots.Count; j++)
				{
					BotNpc botNpc2 = bots[j];
					if (botNpc2.CanChat(playerHead) && !(Vector3.Distance(botNpc.HeadPos, botNpc2.HeadPos) > 3.5f))
					{
						if (botNpc.Say(VoiceCategory.SmallTalk, "chat with " + botNpc2.AvatarTitle))
						{
							float num = (((Object)(object)botNpc._currentLine?.Clip != (Object)null) ? botNpc._currentLine.Clip.length : 2f);
							botNpc.StartChat(botNpc2, 0f);
							botNpc2.StartChat(botNpc, num + 0.4f);
						}
						return;
					}
				}
			}
		}

		private bool CanChat(Vector3 playerHead)
		{
			//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)
			if (Ready && !Dead && !IsRemote && (Object)(object)Rig != (Object)null && !_surrendering && Time.time > _nextChat && !IsTalking && !_moveTarget.HasValue && Time.time > _fleeUntil)
			{
				return Vector3.Distance(HeadPos, playerHead) > Settings.TalkDistance.Value;
			}
			return false;
		}

		private void StartChat(BotNpc partner, float replyDelay)
		{
			_chatPartner = partner;
			_chatUntil = Time.time + 12f;
			_nextChat = Time.time + Random.Range(14f, 30f);
			_replyAt = ((replyDelay > 0f) ? (Time.time + replyDelay) : (-1f));
			_waitUntil = Mathf.Max(_waitUntil, Time.time + 8f);
		}

		private void UpdateChat()
		{
			//IL_0045: 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)
			if (_chatPartner == null)
			{
				return;
			}
			if (Time.time > _chatUntil || (Object)(object)_chatPartner.Rig == (Object)null || _chatPartner.Dead)
			{
				_chatPartner = null;
				return;
			}
			FaceTowards(_chatPartner.HeadPos, 3f);
			_lookAt = _chatPartner.HeadPos;
			if (_replyAt > 0f && Time.time >= _replyAt)
			{
				_replyAt = -1f;
				Say(VoiceCategory.SmallTalk, "reply to " + _chatPartner.AvatarTitle);
			}
		}

		public bool Say(VoiceCategory cat, string reason, bool interrupt = false)
		{
			if ((Object)(object)_voice == (Object)null || IsRemote)
			{
				return false;
			}
			if (IsTalking && !interrupt)
			{
				return false;
			}
			if (!interrupt && Time.time < _lastLineEnd + Settings.LineGap.Value)
			{
				return false;
			}
			VoiceLine randomFor = VoiceLibrary.GetRandomFor(AvatarBarcode, AvatarTitle, cat, _lastLine);
			if (randomFor == null)
			{
				if (Settings.DebugLog.Value)
				{
					MelonLogger.Msg($"[Voice] {AvatarTitle}: no {cat} lines ({reason})");
				}
				return false;
			}
			_voice.Stop();
			_voice.clip = randomFor.Clip;
			_voice.volume = Settings.VoiceVolume.Value;
			_voice.Play();
			_lastLine = (_currentLine = randomFor);
			_lineStart = Time.time;
			_lastLineEnd = Time.time + (((Object)(object)randomFor.Clip != (Object)null) ? (randomFor.Clip.length / Mathf.Max(0.5f, _voice.pitch)) : 2f);
			Net.OnLocalSay(this, cat, randomFor);
			if (Settings.DebugLog.Value)
			{
				MelonLogger.Msg($"[Voice] {AvatarTitle}: {cat} '{randomFor.Name}' ({reason})");
			}
			return true;
		}

		public float MouthOpen()
		{
			if (_currentLine?.Envelope == null || !IsTalking)
			{
				return 0f;
			}
			int num = (int)((Time.time - _lineStart) / 0.05f);
			if (num < 0 || num >= _currentLine.Envelope.Length)
			{
				return 0f;
			}
			return _currentLine.Envelope[num];
		}

		public void ApplyJaw(float open)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			if (!_jawSearched)
			{
				_jawSearched = true;
				try
				{
					_jaw = Rig.avatar.animator.GetBoneTransform((HumanBodyBones)23);
				}
				catch
				{
				}
				if ((Object)(object)_jaw != (Object)null)
				{
					_jawRest = _jaw.localRotation;
				}
			}
			if (!((Object)(object)_jaw == (Object)null))
			{
				_jaw.localRotation = _jawRest * Quaternion.AngleAxis(open * 22f, Vector3.right);
			}
		}

		public void WriteNetPose(float[] f)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (((Object)(object)_pelvis != (Object)null) ? _pelvis.position : HeadPos);
			int num = 0;
			f[num++] = val.x;
			f[num++] = val.y;
			f[num++] = val.z;
			f[num++] = _yaw;
			f[num++] = _poseHeadPos.x;
			f[num++] = _poseHeadPos.y;
			f[num++] = _poseHeadPos.z;
			f[num++] = _poseHeadRot.x;
			f[num++] = _poseHeadRot.y;
			f[num++] = _poseHeadRot.z;
			f[num++] = _poseHeadRot.w;
			f[num++] = _poseL.x;
			f[num++] = _poseL.y;
			f[num++] = _poseL.z;
			f[num++] = _poseLR.x;
			f[num++] = _poseLR.y;
			f[num++] = _poseLR.z;
			f[num++] = _poseLR.w;
			f[num++] = _poseR.x;
			f[num++] = _poseR.y;
			f[num++] = _poseR.z;
			f[num++] = _poseRR.x;
			f[num++] = _poseRR.y;
			f[num++] = _poseRR.z;
			f[num++] = _poseRR.w;
			Vector2 val2 = (((Object)(object)_leftInput != (Object)null) ? _leftInput._thumbstickAxis : Vector2.zero);
			f[num++] = val2.x;
			f[num++] = val2.y;
			f[num++] = Feet.y;
		}

		public void ApplyNetPose(float[] f, bool dead)
		{
			//IL_0023: 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_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if (f != null && f.Length >= 28)
			{
				System.Array.Copy((System.Array)f, (System.Array)_net, 28);
				_netPelvis = new Vector3(f[0], f[1], f[2]);
				_netYaw = f[3];
				_netStick = new Vector2(f[25], f[26]);
				_hasNet = true;
				if (dead && !Dead)
				{
					DieLocal();
				}
				else if (!dead && Dead)
				{
					Revive();
				}
			}
		}

		private static Quaternion Q(float[] f, int i)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_003a: 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_0048: 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)
			//I