Decompiled source of BotFriends v3.6.0

BotFriends.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Empress BotFriends")]
[assembly: AssemblyFileVersion("1.1.3.0")]
[assembly: AssemblyInformationalVersion("1.1.3+4247eae4b81cc1423970370465980f9d0841d4e8")]
[assembly: AssemblyProduct("Empress BotFriends")]
[assembly: AssemblyTitle("BotFriends")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : 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]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Empress.StupidBots
{
	internal sealed class EmpressBotAvatarVisual : MonoBehaviour
	{
		private const float DefaultSpeed = 4.2f;

		private const int MaxRandomCosmetics = 4;

		private static readonly string[] HiddenVisualNameParts = new string[7] { "grab", "grabb", "holder", "suction", "vacuum", "tool", "cart" };

		private static readonly string[] PreferredVisibleLayers = new string[2] { "PlayerVisuals", "Default" };

		private static readonly CosmeticType[] RandomCosmeticTypes;

		private static readonly FieldRef<PlayerAvatar, PlayerCosmetics> PlayerAvatarCosmeticsRef;

		private static readonly FieldRef<PlayerAvatarVisuals, PlayerCosmetics> VisualsPlayerCosmeticsRef;

		private static readonly FieldRef<PlayerCosmetics, PlayerAvatarVisuals> PlayerCosmeticsVisualsRef;

		private static readonly FieldRef<PlayerCosmetics, List<CosmeticParent>> CosmeticParentsRef;

		private static readonly FieldRef<CosmeticParent, CosmeticType> CosmeticParentTypeRef;

		private static readonly FieldRef<CosmeticParent, PlayerSpringImpulse> CosmeticParentSpringImpulseRef;

		private static readonly FieldRef<CosmeticParent, Transform> CosmeticParentParentRef;

		private static readonly FieldRef<CosmeticParent, bool> CosmeticParentResetTransformRef;

		private static readonly FieldRef<CosmeticParent, List<Transform>> BaseMeshParentsRef;

		private static readonly FieldRef<CosmeticParent, List<Transform>> BaseMeshesRef;

		private static readonly FieldRef<PlayerCosmetics, bool> FirstSetupRef;

		private static readonly FieldRef<PlayerCosmetics, bool> FirstSetupCoroutineRef;

		private static readonly FieldRef<MetaManager, List<CosmeticAsset>> CosmeticAssetsRef;

		private static readonly FieldRef<CosmeticAsset, CosmeticType> CosmeticAssetTypeRef;

		private static readonly FieldRef<CosmeticAsset, PrefabRef> CosmeticAssetPrefabRef;

		private static readonly MethodInfo InstantiateCosmeticMethod;

		private NavMeshAgent? _agent;

		private Animator[] _animators = Array.Empty<Animator>();

		private Vector3 _lastPosition;

		private float _fallbackSpeed = 4.2f;

		internal void Init(NavMeshAgent? agent, float fallbackSpeed)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			_agent = agent;
			_fallbackSpeed = Mathf.Max(0.1f, fallbackSpeed);
			_animators = ((Component)this).GetComponentsInChildren<Animator>(true);
			_lastPosition = ((Component)this).transform.position;
			for (int i = 0; i < _animators.Length; i++)
			{
				Animator val = _animators[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					((Behaviour)val).enabled = true;
					val.applyRootMotion = false;
					val.speed = 1f;
					val.cullingMode = (AnimatorCullingMode)0;
				}
			}
		}

		private void LateUpdate()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: 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_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Invalid comparison between Unknown and I4
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Invalid comparison between Unknown and I4
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			if (_animators == null || _animators.Length == 0)
			{
				return;
			}
			Vector3 val = ((Time.deltaTime > 0.0001f) ? ((((Component)this).transform.position - _lastPosition) / Time.deltaTime) : Vector3.zero);
			_lastPosition = ((Component)this).transform.position;
			if (Object.op_Implicit((Object)(object)_agent) && ((Behaviour)_agent).enabled && _agent.isOnNavMesh)
			{
				Vector3 velocity = _agent.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude > ((Vector3)(ref val)).sqrMagnitude)
				{
					val = _agent.velocity;
				}
			}
			Vector3 val2 = val;
			val2.y = 0f;
			float magnitude = ((Vector3)(ref val2)).magnitude;
			bool flag = magnitude > 0.08f;
			float num = (Object.op_Implicit((Object)(object)_agent) ? Mathf.Max(1.5f, _agent.speed) : Mathf.Max(1.5f, _fallbackSpeed));
			float num2 = Mathf.Clamp01(magnitude / num);
			Vector3 val3 = ((Component)this).transform.InverseTransformDirection(val2);
			for (int i = 0; i < _animators.Length; i++)
			{
				Animator val4 = _animators[i];
				if (!Object.op_Implicit((Object)(object)val4))
				{
					continue;
				}
				AnimatorControllerParameter[] parameters = val4.parameters;
				foreach (AnimatorControllerParameter val5 in parameters)
				{
					string text = val5.name.ToLowerInvariant();
					AnimatorControllerParameterType type = val5.type;
					if ((int)type != 1)
					{
						if ((int)type == 4)
						{
							if (text.Contains("moving") || text.Contains("move") || text.Contains("walk") || text.Contains("run"))
							{
								val4.SetBool(val5.nameHash, flag);
							}
							else if (text.Contains("ground"))
							{
								val4.SetBool(val5.nameHash, true);
							}
						}
					}
					else if (text.Contains("horizontal") || text.Contains("strafe"))
					{
						val4.SetFloat(val5.nameHash, val3.x);
					}
					else if (text.Contains("vertical") || text.Contains("forward"))
					{
						val4.SetFloat(val5.nameHash, val3.z);
					}
					else if (text.Contains("speed") || text.Contains("move") || text.Contains("velocity"))
					{
						val4.SetFloat(val5.nameHash, num2);
					}
				}
			}
		}

		internal static bool TryAttach(GameObject root, PlayerAvatar? player, Color accent, NavMeshAgent? agent, float fallbackSpeed)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)root) || !Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			GameObject val = ResolveAvatarVisualRoot(player);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			PlayerCosmetics sourceCosmetics = ResolvePlayerCosmetics(player, val);
			GameObject val2;
			try
			{
				val2 = Object.Instantiate<GameObject>(val, root.transform, false);
			}
			catch
			{
				return false;
			}
			((Object)val2).name = "AvatarBody";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			PrepareClone(val2, val, sourceCosmetics);
			TintClone(val2, accent);
			val2.AddComponent<EmpressBotAvatarVisual>().Init(agent, fallbackSpeed);
			return CountVisibleRenderers(val2) > 0;
		}

		private static GameObject? ResolveAvatarVisualRoot(PlayerAvatar player)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return null;
			}
			try
			{
				if (Object.op_Implicit((Object)(object)player.playerAvatarVisuals))
				{
					return ((Component)player.playerAvatarVisuals).gameObject;
				}
			}
			catch
			{
			}
			try
			{
				FieldInfo fieldInfo = AccessTools.Field(((object)player).GetType(), "playerAvatarVisuals");
				if (fieldInfo != null)
				{
					object? value = fieldInfo.GetValue(player);
					Component val = (Component)((value is Component) ? value : null);
					if (Object.op_Implicit((Object)(object)val))
					{
						return val.gameObject;
					}
				}
			}
			catch
			{
			}
			try
			{
				PropertyInfo propertyInfo = AccessTools.Property(((object)player).GetType(), "playerAvatarVisuals");
				if (propertyInfo != null)
				{
					object? value2 = propertyInfo.GetValue(player, null);
					Component val2 = (Component)((value2 is Component) ? value2 : null);
					if (Object.op_Implicit((Object)(object)val2))
					{
						return val2.gameObject;
					}
				}
			}
			catch
			{
			}
			try
			{
				PlayerAvatarVisuals componentInChildren = ((Component)player).GetComponentInChildren<PlayerAvatarVisuals>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					return ((Component)componentInChildren).gameObject;
				}
			}
			catch
			{
			}
			return null;
		}

		private static PlayerCosmetics? ResolvePlayerCosmetics(PlayerAvatar player, GameObject visualRoot)
		{
			if (!Object.op_Implicit((Object)(object)player))
			{
				return null;
			}
			try
			{
				PlayerCosmetics val = PlayerAvatarCosmeticsRef.Invoke(player);
				if (Object.op_Implicit((Object)(object)val))
				{
					return val;
				}
			}
			catch
			{
			}
			try
			{
				PlayerAvatarVisuals component = visualRoot.GetComponent<PlayerAvatarVisuals>();
				if (Object.op_Implicit((Object)(object)component))
				{
					PlayerCosmetics val2 = VisualsPlayerCosmeticsRef.Invoke(component);
					if (Object.op_Implicit((Object)(object)val2))
					{
						return val2;
					}
				}
			}
			catch
			{
			}
			try
			{
				PlayerCosmetics componentInChildren = ((Component)player).GetComponentInChildren<PlayerCosmetics>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					return componentInChildren;
				}
			}
			catch
			{
			}
			return null;
		}

		private static void PrepareClone(GameObject clone, GameObject sourceRoot, PlayerCosmetics? sourceCosmetics)
		{
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			MonoBehaviour[] componentsInChildren = clone.GetComponentsInChildren<MonoBehaviour>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren[i]))
				{
					componentsInChildren[i].StopAllCoroutines();
					((Behaviour)componentsInChildren[i]).enabled = false;
				}
			}
			clone.SetActive(true);
			int layer = ResolveVisibleLayer();
			EnsureCloneCosmetics(clone, sourceRoot, sourceCosmetics);
			PreventVanillaCosmeticSetup(clone);
			StripEquippedCosmetics(clone);
			RestoreBaseAvatarMeshes(clone);
			RandomizeCloneCosmetics(clone);
			Transform[] componentsInChildren2 = clone.GetComponentsInChildren<Transform>(true);
			for (int j = 0; j < componentsInChildren2.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren2[j]))
				{
					((Component)componentsInChildren2[j]).gameObject.layer = layer;
				}
			}
			HideNamedVisuals(clone);
			DisableCloneLights(clone);
			Renderer[] componentsInChildren3 = clone.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren3)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				if (ShouldHide(((Object)((Component)val).gameObject).name))
				{
					val.enabled = false;
					continue;
				}
				val.enabled = true;
				((Component)val).gameObject.layer = layer;
				val.shadowCastingMode = (ShadowCastingMode)1;
				val.receiveShadows = true;
				SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
				if (val2 != null)
				{
					val2.updateWhenOffscreen = true;
				}
			}
			Animator[] componentsInChildren4 = clone.GetComponentsInChildren<Animator>(true);
			foreach (Animator val3 in componentsInChildren4)
			{
				if (Object.op_Implicit((Object)(object)val3))
				{
					((Behaviour)val3).enabled = true;
					val3.applyRootMotion = false;
					val3.speed = 1f;
					val3.cullingMode = (AnimatorCullingMode)0;
				}
			}
			Collider[] componentsInChildren5 = clone.GetComponentsInChildren<Collider>(true);
			for (int m = 0; m < componentsInChildren5.Length; m++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren5[m]))
				{
					componentsInChildren5[m].enabled = false;
				}
			}
			Rigidbody[] componentsInChildren6 = clone.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val4 in componentsInChildren6)
			{
				if (Object.op_Implicit((Object)(object)val4))
				{
					val4.isKinematic = true;
					val4.detectCollisions = false;
					val4.useGravity = false;
				}
			}
			AudioSource[] componentsInChildren7 = clone.GetComponentsInChildren<AudioSource>(true);
			for (int num = 0; num < componentsInChildren7.Length; num++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren7[num]))
				{
					((Behaviour)componentsInChildren7[num]).enabled = false;
				}
			}
			ParticleSystem[] componentsInChildren8 = clone.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem val5 in componentsInChildren8)
			{
				if (Object.op_Implicit((Object)(object)val5))
				{
					EmissionModule emission = val5.emission;
					((EmissionModule)(ref emission)).enabled = false;
					val5.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
			TextMesh[] componentsInChildren9 = clone.GetComponentsInChildren<TextMesh>(true);
			for (int num3 = 0; num3 < componentsInChildren9.Length; num3++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren9[num3]))
				{
					((Component)componentsInChildren9[num3]).gameObject.SetActive(false);
				}
			}
		}

		private static void RandomizeCloneCosmetics(GameObject clone)
		{
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)MetaManager.instance) || InstantiateCosmeticMethod == null)
			{
				return;
			}
			PlayerCosmetics val = ((IEnumerable<PlayerCosmetics>)clone.GetComponentsInChildren<PlayerCosmetics>(true)).FirstOrDefault((Func<PlayerCosmetics, bool>)((PlayerCosmetics component) => Object.op_Implicit((Object)(object)component)));
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			HashSet<CosmeticType> supportedCosmeticTypes = GetSupportedCosmeticTypes(val);
			if (supportedCosmeticTypes.Count == 0)
			{
				return;
			}
			List<CosmeticAsset> list = null;
			try
			{
				list = CosmeticAssetsRef.Invoke(MetaManager.instance);
			}
			catch
			{
			}
			if (list == null || list.Count == 0)
			{
				return;
			}
			Dictionary<CosmeticType, List<CosmeticAsset>> dictionary = new Dictionary<CosmeticType, List<CosmeticAsset>>();
			for (int i = 0; i < list.Count; i++)
			{
				CosmeticAsset val2 = list[i];
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				CosmeticType val3;
				try
				{
					val3 = CosmeticAssetTypeRef.Invoke(val2);
				}
				catch
				{
					continue;
				}
				PrefabRef val4;
				try
				{
					val4 = CosmeticAssetPrefabRef.Invoke(val2);
				}
				catch
				{
					continue;
				}
				if (supportedCosmeticTypes.Contains(val3) && RandomCosmeticTypes.Contains(val3) && val4 != null && val4.IsValid())
				{
					if (!dictionary.TryGetValue(val3, out var value))
					{
						value = (dictionary[val3] = new List<CosmeticAsset>());
					}
					value.Add(val2);
				}
			}
			List<CosmeticType> list3 = dictionary.Keys.OrderBy((CosmeticType _) => Random.value).ToList();
			int num = Mathf.Min(4, list3.Count);
			for (int j = 0; j < num; j++)
			{
				List<CosmeticAsset> list4 = dictionary[list3[j]];
				if (list4.Count == 0)
				{
					continue;
				}
				CosmeticAsset val5 = list4[Random.Range(0, list4.Count)];
				try
				{
					object? obj4 = InstantiateCosmeticMethod.Invoke(val, new object[1] { val5 });
					GameObject val6 = (GameObject)((obj4 is GameObject) ? obj4 : null);
					if (Object.op_Implicit((Object)(object)val6))
					{
						val6.SetActive(true);
					}
				}
				catch
				{
				}
			}
		}

		private static void EnsureCloneCosmetics(GameObject clone, GameObject sourceRoot, PlayerCosmetics? sourceCosmetics)
		{
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Expected O, but got Unknown
			if (!Object.op_Implicit((Object)(object)sourceCosmetics))
			{
				return;
			}
			PlayerCosmetics val = clone.GetComponentInChildren<PlayerCosmetics>(true);
			if (!Object.op_Implicit((Object)(object)val))
			{
				val = clone.AddComponent<PlayerCosmetics>();
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			try
			{
				((MonoBehaviour)val).StopAllCoroutines();
			}
			catch
			{
			}
			try
			{
				FirstSetupRef.Invoke(val) = false;
			}
			catch
			{
			}
			try
			{
				FirstSetupCoroutineRef.Invoke(val) = true;
			}
			catch
			{
			}
			PlayerAvatarVisuals component = clone.GetComponent<PlayerAvatarVisuals>();
			if (Object.op_Implicit((Object)(object)component))
			{
				try
				{
					PlayerCosmeticsVisualsRef.Invoke(val) = component;
				}
				catch
				{
				}
				try
				{
					VisualsPlayerCosmeticsRef.Invoke(component) = val;
				}
				catch
				{
				}
			}
			List<CosmeticParent> list = null;
			try
			{
				list = CosmeticParentsRef.Invoke(sourceCosmetics);
			}
			catch
			{
			}
			if (list == null || list.Count == 0)
			{
				return;
			}
			List<CosmeticParent> list2 = new List<CosmeticParent>();
			for (int i = 0; i < list.Count; i++)
			{
				CosmeticParent val2 = list[i];
				if (val2 == null)
				{
					continue;
				}
				Transform val3 = null;
				List<Transform> list3 = new List<Transform>();
				List<Transform> list4 = new List<Transform>();
				try
				{
					val3 = MapCloneTransform(CosmeticParentParentRef.Invoke(val2), sourceRoot.transform, clone.transform);
				}
				catch
				{
				}
				try
				{
					list3 = MapCloneTransforms(BaseMeshParentsRef.Invoke(val2), sourceRoot.transform, clone.transform);
				}
				catch
				{
				}
				try
				{
					list4 = MapCloneTransforms(BaseMeshesRef.Invoke(val2), sourceRoot.transform, clone.transform);
				}
				catch
				{
				}
				if (Object.op_Implicit((Object)(object)val3) && list3.Count != 0)
				{
					CosmeticParent val4 = new CosmeticParent();
					try
					{
						CosmeticParentTypeRef.Invoke(val4) = CosmeticParentTypeRef.Invoke(val2);
					}
					catch
					{
						continue;
					}
					try
					{
						CosmeticParentSpringImpulseRef.Invoke(val4) = null;
					}
					catch
					{
					}
					try
					{
						CosmeticParentParentRef.Invoke(val4) = val3;
					}
					catch
					{
					}
					try
					{
						CosmeticParentResetTransformRef.Invoke(val4) = CosmeticParentResetTransformRef.Invoke(val2);
					}
					catch
					{
					}
					try
					{
						BaseMeshParentsRef.Invoke(val4) = list3;
					}
					catch
					{
					}
					try
					{
						BaseMeshesRef.Invoke(val4) = list4;
					}
					catch
					{
					}
					list2.Add(val4);
				}
			}
			if (list2.Count <= 0)
			{
				return;
			}
			try
			{
				CosmeticParentsRef.Invoke(val) = list2;
			}
			catch
			{
			}
		}

		private static HashSet<CosmeticType> GetSupportedCosmeticTypes(PlayerCosmetics playerCosmetics)
		{
			HashSet<CosmeticType> hashSet = new HashSet<CosmeticType>();
			List<CosmeticParent> list = null;
			try
			{
				list = CosmeticParentsRef.Invoke(playerCosmetics);
			}
			catch
			{
			}
			if (list == null)
			{
				return hashSet;
			}
			for (int i = 0; i < list.Count; i++)
			{
				CosmeticParent val = list[i];
				if (val == null)
				{
					continue;
				}
				Transform val2 = null;
				try
				{
					val2 = CosmeticParentParentRef.Invoke(val);
				}
				catch
				{
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					try
					{
						hashSet.Add(CosmeticParentTypeRef.Invoke(val));
					}
					catch
					{
					}
				}
			}
			return hashSet;
		}

		private static List<Transform> MapCloneTransforms(List<Transform>? sourceTransforms, Transform sourceRoot, Transform cloneRoot)
		{
			List<Transform> list = new List<Transform>();
			if (sourceTransforms == null)
			{
				return list;
			}
			for (int i = 0; i < sourceTransforms.Count; i++)
			{
				Transform val = MapCloneTransform(sourceTransforms[i], sourceRoot, cloneRoot);
				if (Object.op_Implicit((Object)(object)val))
				{
					list.Add(val);
				}
			}
			return list;
		}

		private static Transform? MapCloneTransform(Transform? source, Transform sourceRoot, Transform cloneRoot)
		{
			if (!Object.op_Implicit((Object)(object)source))
			{
				return null;
			}
			if ((Object)(object)source == (Object)(object)sourceRoot)
			{
				return cloneRoot;
			}
			if (!source.IsChildOf(sourceRoot))
			{
				return null;
			}
			List<int> list = new List<int>();
			Transform val = source;
			while (Object.op_Implicit((Object)(object)val) && (Object)(object)val != (Object)(object)sourceRoot)
			{
				list.Add(val.GetSiblingIndex());
				val = val.parent;
			}
			Transform val2 = cloneRoot;
			for (int num = list.Count - 1; num >= 0; num--)
			{
				int num2 = list[num];
				if (num2 < 0 || num2 >= val2.childCount)
				{
					return null;
				}
				val2 = val2.GetChild(num2);
			}
			return val2;
		}

		private static void PreventVanillaCosmeticSetup(GameObject clone)
		{
			PlayerCosmetics[] componentsInChildren = clone.GetComponentsInChildren<PlayerCosmetics>(true);
			foreach (PlayerCosmetics val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					try
					{
						((MonoBehaviour)val).StopAllCoroutines();
					}
					catch
					{
					}
					try
					{
						FirstSetupRef.Invoke(val) = false;
					}
					catch
					{
					}
					try
					{
						FirstSetupCoroutineRef.Invoke(val) = true;
					}
					catch
					{
					}
				}
			}
		}

		private static void StripEquippedCosmetics(GameObject clone)
		{
			Cosmetic[] componentsInChildren = clone.GetComponentsInChildren<Cosmetic>(true);
			foreach (Cosmetic val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && !((Object)(object)((Component)val).gameObject == (Object)(object)clone))
				{
					((Component)val).gameObject.SetActive(false);
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}

		private static void RestoreBaseAvatarMeshes(GameObject clone)
		{
			PlayerCosmetics[] componentsInChildren = clone.GetComponentsInChildren<PlayerCosmetics>(true);
			foreach (PlayerCosmetics val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				List<CosmeticParent> list = null;
				try
				{
					list = CosmeticParentsRef.Invoke(val);
				}
				catch
				{
				}
				if (list == null)
				{
					continue;
				}
				for (int j = 0; j < list.Count; j++)
				{
					CosmeticParent val2 = list[j];
					if (val2 != null)
					{
						List<Transform> transforms = null;
						List<Transform> transforms2 = null;
						try
						{
							transforms = BaseMeshParentsRef.Invoke(val2);
						}
						catch
						{
						}
						try
						{
							transforms2 = BaseMeshesRef.Invoke(val2);
						}
						catch
						{
						}
						SetBaseMeshesActive(transforms, active: true);
						SetBaseMeshesActive(transforms2, active: true);
					}
				}
			}
		}

		private static void SetBaseMeshesActive(List<Transform>? transforms, bool active)
		{
			if (transforms == null)
			{
				return;
			}
			for (int i = 0; i < transforms.Count; i++)
			{
				Transform val = transforms[i];
				if (Object.op_Implicit((Object)(object)val))
				{
					((Component)val).gameObject.SetActive(active);
				}
			}
		}

		private static void DisableCloneLights(GameObject clone)
		{
			Light[] componentsInChildren = clone.GetComponentsInChildren<Light>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)componentsInChildren[i]))
				{
					((Behaviour)componentsInChildren[i]).enabled = false;
				}
			}
		}

		private static void HideNamedVisuals(GameObject clone)
		{
			Transform[] componentsInChildren = clone.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && ShouldHide(((Object)((Component)val).gameObject).name))
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		private static bool ShouldHide(string name)
		{
			if (string.IsNullOrWhiteSpace(name))
			{
				return false;
			}
			string text = name.ToLowerInvariant();
			for (int i = 0; i < HiddenVisualNameParts.Length; i++)
			{
				if (text.Contains(HiddenVisualNameParts[i]))
				{
					return true;
				}
			}
			return false;
		}

		private static void TintClone(GameObject clone, Color accent)
		{
			//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_007f: 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_00aa: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Renderer[] componentsInChildren = clone.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val) || Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<Cosmetic>()))
				{
					continue;
				}
				Material[] materials;
				try
				{
					materials = val.materials;
				}
				catch
				{
					continue;
				}
				foreach (Material val2 in materials)
				{
					if (Object.op_Implicit((Object)(object)val2))
					{
						if (val2.HasProperty("_Color"))
						{
							val2.SetColor("_Color", Color.Lerp(val2.GetColor("_Color"), accent, 0.72f));
						}
						if (val2.HasProperty("_BaseColor"))
						{
							val2.SetColor("_BaseColor", Color.Lerp(val2.GetColor("_BaseColor"), accent, 0.72f));
						}
						if (val2.HasProperty("_EmissionColor"))
						{
							val2.EnableKeyword("_EMISSION");
							val2.SetColor("_EmissionColor", accent * 0.5f);
						}
					}
				}
			}
		}

		private static int CountVisibleRenderers(GameObject clone)
		{
			int num = 0;
			Renderer[] componentsInChildren = clone.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && val.enabled && ((Component)val).gameObject.activeInHierarchy)
				{
					num++;
				}
			}
			return num;
		}

		private static int ResolveVisibleLayer()
		{
			for (int i = 0; i < PreferredVisibleLayers.Length; i++)
			{
				int num = LayerMask.NameToLayer(PreferredVisibleLayers[i]);
				if (num >= 0)
				{
					return num;
				}
			}
			return 0;
		}

		static EmpressBotAvatarVisual()
		{
			CosmeticType[] array = new CosmeticType[11];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			RandomCosmeticTypes = (CosmeticType[])(object)array;
			PlayerAvatarCosmeticsRef = AccessTools.FieldRefAccess<PlayerAvatar, PlayerCosmetics>("playerCosmetics");
			VisualsPlayerCosmeticsRef = AccessTools.FieldRefAccess<PlayerAvatarVisuals, PlayerCosmetics>("playerCosmetics");
			PlayerCosmeticsVisualsRef = AccessTools.FieldRefAccess<PlayerCosmetics, PlayerAvatarVisuals>("playerAvatarVisuals");
			CosmeticParentsRef = AccessTools.FieldRefAccess<PlayerCosmetics, List<CosmeticParent>>("cosmeticParents");
			CosmeticParentTypeRef = AccessTools.FieldRefAccess<CosmeticParent, CosmeticType>("cosmeticType");
			CosmeticParentSpringImpulseRef = AccessTools.FieldRefAccess<CosmeticParent, PlayerSpringImpulse>("springImpulse");
			CosmeticParentParentRef = AccessTools.FieldRefAccess<CosmeticParent, Transform>("parent");
			CosmeticParentResetTransformRef = AccessTools.FieldRefAccess<CosmeticParent, bool>("resetTransform");
			BaseMeshParentsRef = AccessTools.FieldRefAccess<CosmeticParent, List<Transform>>("baseMeshParents");
			BaseMeshesRef = AccessTools.FieldRefAccess<CosmeticParent, List<Transform>>("baseMeshes");
			FirstSetupRef = AccessTools.FieldRefAccess<PlayerCosmetics, bool>("firstSetup");
			FirstSetupCoroutineRef = AccessTools.FieldRefAccess<PlayerCosmetics, bool>("firstSetupCoroutine");
			CosmeticAssetsRef = AccessTools.FieldRefAccess<MetaManager, List<CosmeticAsset>>("cosmeticAssets");
			CosmeticAssetTypeRef = AccessTools.FieldRefAccess<CosmeticAsset, CosmeticType>("type");
			CosmeticAssetPrefabRef = AccessTools.FieldRefAccess<CosmeticAsset, PrefabRef>("prefab");
			InstantiateCosmeticMethod = AccessTools.Method(typeof(PlayerCosmetics), "InstantiateCosmetic", new Type[1] { typeof(CosmeticAsset) }, (Type[])null);
		}
	}
	internal class BotChatterAgent : MonoBehaviour
	{
		public enum BotState
		{
			Idle,
			Moving,
			Carrying,
			Ragdoll
		}

		private NavMeshAgent _agent;

		private Rigidbody _rb;

		private AudioSource _src;

		private readonly List<PhysGrabObject> _buf = new List<PhysGrabObject>();

		private float _lastLocalSpeak;

		private bool _lastCarrying;

		private string _lastCarriedName;

		public BotState State { get; private set; }

		public bool IsCarrying { get; private set; }

		public string CarriedLabel { get; private set; }

		private void Awake()
		{
			_agent = ((Component)this).GetComponent<NavMeshAgent>();
			_rb = ((Component)this).GetComponent<Rigidbody>();
			_src = ((Component)this).GetComponent<AudioSource>();
			if (!Object.op_Implicit((Object)(object)_src))
			{
				_src = ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			_src.spatialBlend = 1f;
			_src.rolloffMode = (AudioRolloffMode)0;
			_src.minDistance = 2f;
			_src.maxDistance = 18f;
		}

		private void OnEnable()
		{
			BotChatterManager.Register(this);
		}

		private void OnDisable()
		{
			BotChatterManager.Unregister(this);
		}

		private void Update()
		{
			UpdateState();
		}

		private void UpdateState()
		{
			//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)
			bool flag = false;
			if (Object.op_Implicit((Object)(object)_agent) && ((Behaviour)_agent).enabled)
			{
				Vector3 velocity = _agent.velocity;
				flag = ((Vector3)(ref velocity)).sqrMagnitude > 0.04f;
			}
			bool flag2 = false;
			if (Object.op_Implicit((Object)(object)_rb))
			{
				flag2 = !_rb.isKinematic && !((Behaviour)_agent).enabled;
			}
			DetectCarry(out bool carrying, out string label);
			IsCarrying = carrying;
			CarriedLabel = label;
			if (flag2)
			{
				State = BotState.Ragdoll;
			}
			else if (carrying)
			{
				State = BotState.Carrying;
			}
			else if (flag)
			{
				State = BotState.Moving;
			}
			else
			{
				State = BotState.Idle;
			}
		}

		private void DetectCarry(out bool carrying, out string label)
		{
			//IL_005c: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			carrying = false;
			label = "";
			_buf.Clear();
			((Component)this).GetComponentsInChildren<PhysGrabObject>(true, _buf);
			PhysGrabObject val = null;
			float num = float.PositiveInfinity;
			for (int i = 0; i < _buf.Count; i++)
			{
				PhysGrabObject val2 = _buf[i];
				if (!Object.op_Implicit((Object)(object)val2))
				{
					continue;
				}
				Transform transform = ((Component)val2).transform;
				if (!((Object)(object)transform == (Object)(object)((Component)this).transform))
				{
					Vector3 val3 = transform.position - ((Component)this).transform.position;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						val = val2;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				carrying = true;
				label = ((Object)((Component)val).gameObject).name;
			}
		}

		internal void PlayClip(DecTalkSynth.Clip clip, float volume)
		{
			if (Object.op_Implicit((Object)(object)_src))
			{
				AudioClip val = AudioClip.Create("BotChat", clip.Samples.Length / clip.Channels, clip.Channels, clip.SampleRate, false);
				val.SetData(clip.Samples, 0);
				_src.Stop();
				_src.clip = val;
				_src.loop = false;
				_src.volume = Mathf.Clamp01(volume);
				_src.Play();
			}
		}

		internal bool TickLocal(float now, bool canSpeak)
		{
			if (!canSpeak)
			{
				return false;
			}
			if (now < _lastLocalSpeak)
			{
				return false;
			}
			bool flag = false;
			if (IsCarrying && !_lastCarrying)
			{
				flag = true;
			}
			_lastCarrying = IsCarrying;
			if (!flag)
			{
				return false;
			}
			string text = (IsCarrying ? "Moving with package." : "Moving.");
			if (EmpressBotFriendsChatterPlugin.UseDECtalk.Value)
			{
				DecTalkSynth.Enqueue(this, text);
				_lastLocalSpeak = now + EmpressBotFriendsChatterPlugin.SelfCooldown.Value;
				return true;
			}
			return false;
		}
	}
	internal enum BotPersonalityType
	{
		Clumsy,
		Fast,
		Slow,
		Aggressive,
		Coward,
		Curious,
		Guardian,
		Jittery,
		Pacifist,
		Trickster
	}
	internal class BotPersonality : MonoBehaviour
	{
		public BotPersonalityType Type { get; private set; }

		public float SpeedMultiplier { get; private set; } = 1f;


		public bool AllowValuables { get; private set; } = true;


		public bool AllowWeapons { get; private set; } = true;


		public float AimConeDegrees { get; private set; } = 6f;


		public Vector2 FireInterval { get; private set; } = new Vector2(0.9f, 1.6f);


		public float ToyingChance { get; private set; }

		public float DropChanceOnShoot { get; private set; }

		public void InitRandom(int seed)
		{
			Random random = new Random(seed);
			BotPersonalityType[] array = (BotPersonalityType[])Enum.GetValues(typeof(BotPersonalityType));
			Type = array[random.Next(array.Length)];
			ApplyDefaults(Type);
		}

		public void ApplyDefaults(BotPersonalityType t)
		{
			//IL_0036: 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_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: 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)
			Type = t;
			SpeedMultiplier = 1f;
			AllowValuables = true;
			AllowWeapons = true;
			AimConeDegrees = 6f;
			FireInterval = new Vector2(0.9f, 1.6f);
			ToyingChance = 0f;
			DropChanceOnShoot = 0f;
			switch (t)
			{
			case BotPersonalityType.Clumsy:
				SpeedMultiplier = 0.95f;
				AimConeDegrees = 10f;
				DropChanceOnShoot = 0.12f;
				break;
			case BotPersonalityType.Fast:
				SpeedMultiplier = 1.25f;
				AimConeDegrees = 7f;
				FireInterval = new Vector2(0.6f, 1f);
				break;
			case BotPersonalityType.Slow:
				SpeedMultiplier = 0.7f;
				AimConeDegrees = 8f;
				FireInterval = new Vector2(1.2f, 2f);
				break;
			case BotPersonalityType.Aggressive:
				SpeedMultiplier = 1.1f;
				AimConeDegrees = 5f;
				FireInterval = new Vector2(0.35f, 0.75f);
				break;
			case BotPersonalityType.Coward:
				SpeedMultiplier = 1f;
				AimConeDegrees = 12f;
				FireInterval = new Vector2(1.5f, 2.2f);
				AllowValuables = false;
				break;
			case BotPersonalityType.Curious:
				SpeedMultiplier = 1f;
				AimConeDegrees = 9f;
				FireInterval = new Vector2(0.8f, 1.6f);
				ToyingChance = 0.25f;
				break;
			case BotPersonalityType.Guardian:
				SpeedMultiplier = 0.95f;
				AimConeDegrees = 4f;
				FireInterval = new Vector2(0.55f, 1.1f);
				break;
			case BotPersonalityType.Jittery:
				SpeedMultiplier = 1.1f;
				AimConeDegrees = 14f;
				FireInterval = new Vector2(0.25f, 0.6f);
				break;
			case BotPersonalityType.Pacifist:
				SpeedMultiplier = 1f;
				AllowWeapons = false;
				break;
			case BotPersonalityType.Trickster:
				SpeedMultiplier = 1f;
				AimConeDegrees = 18f;
				FireInterval = new Vector2(0.4f, 1.2f);
				ToyingChance = 0.5f;
				break;
			}
		}
	}
	internal class BotRagdoll : MonoBehaviour
	{
		private bool _feature;

		private float _thresholdSqr;

		private float _recover;

		private Rigidbody _rb;

		private NavMeshAgent _agent;

		private StupidBotBrain _brain;

		private StupidBotCarrier _carrier;

		private bool _active;

		private bool _carrierPrevEnabled;

		private float _timer;

		internal void Init(NavMeshAgent agent, StupidBotBrain brain, StupidBotCarrier carrier, Rigidbody rb, bool enabled, float threshold, float recover)
		{
			_agent = agent;
			_brain = brain;
			_carrier = carrier;
			_rb = rb;
			_feature = enabled;
			_thresholdSqr = Mathf.Max(0.01f, threshold * threshold);
			_recover = Mathf.Max(0.5f, recover);
		}

		private void OnCollisionEnter(Collision c)
		{
			//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)
			if (_feature && !_active)
			{
				Vector3 relativeVelocity = c.relativeVelocity;
				if (((Vector3)(ref relativeVelocity)).sqrMagnitude >= _thresholdSqr)
				{
					Activate();
				}
			}
		}

		private void Activate()
		{
			_active = true;
			_timer = 0f;
			if (Object.op_Implicit((Object)(object)_carrier))
			{
				_carrierPrevEnabled = ((Behaviour)_carrier).enabled;
				((Behaviour)_carrier).enabled = false;
			}
			if (Object.op_Implicit((Object)(object)_agent))
			{
				((Behaviour)_agent).enabled = false;
			}
			if (Object.op_Implicit((Object)(object)_brain))
			{
				_brain.SetExternalControl(on: true);
			}
			if (Object.op_Implicit((Object)(object)_rb))
			{
				_rb.isKinematic = false;
			}
		}

		private void Deactivate()
		{
			//IL_001a: 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)
			_active = false;
			if (Object.op_Implicit((Object)(object)_rb))
			{
				_rb.velocity = Vector3.zero;
				_rb.angularVelocity = Vector3.zero;
				_rb.isKinematic = true;
			}
			if (Object.op_Implicit((Object)(object)_agent))
			{
				((MonoBehaviour)this).StartCoroutine(EnableAgent());
				return;
			}
			if (Object.op_Implicit((Object)(object)_brain))
			{
				_brain.SetExternalControl(on: false);
			}
			if (Object.op_Implicit((Object)(object)_carrier) && _carrierPrevEnabled)
			{
				((Behaviour)_carrier).enabled = true;
			}
		}

		private IEnumerator EnableAgent()
		{
			yield return null;
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.Warp(((Component)this).transform.position);
			}
			if (Object.op_Implicit((Object)(object)_agent))
			{
				((Behaviour)_agent).enabled = true;
			}
			if (Object.op_Implicit((Object)(object)_brain))
			{
				_brain.SetExternalControl(on: false);
			}
			if (Object.op_Implicit((Object)(object)_carrier) && _carrierPrevEnabled)
			{
				((Behaviour)_carrier).enabled = true;
			}
		}

		private void Update()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			if (!_feature || !_active)
			{
				return;
			}
			_timer += Time.deltaTime;
			if (!(_timer < _recover) && Object.op_Implicit((Object)(object)_rb))
			{
				Vector3 velocity = _rb.velocity;
				if (((Vector3)(ref velocity)).sqrMagnitude < 0.16f)
				{
					Deactivate();
				}
			}
		}

		internal void SetEnabled(bool on)
		{
			_feature = on;
		}

		internal void Reconfigure(float threshold, float recover)
		{
			_thresholdSqr = Mathf.Max(0.01f, threshold * threshold);
			_recover = Mathf.Max(0.5f, recover);
		}
	}
	internal static class BotUtils
	{
		private static readonly Dictionary<int, StupidBotCarrier> Claims = new Dictionary<int, StupidBotCarrier>();

		private static readonly Dictionary<int, float> IgnoreUntil = new Dictionary<int, float>();

		internal static List<PhysGrabObject> FindNearbyValuables(Vector3 position, float range)
		{
			//IL_0007: 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_0011: Unknown result type (might be due to invalid IL or missing references)
			List<PhysGrabObject> list = new List<PhysGrabObject>();
			try
			{
				List<PhysGrabObject> list2 = SemiFunc.PhysGrabObjectGetAllWithinRange(range, position, true, default(LayerMask), (PhysGrabObject)null);
				for (int i = 0; i < list2.Count; i++)
				{
					PhysGrabObject val = list2[i];
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)((Component)val).GetComponent<ValuableObject>()))
					{
						list.Add(val);
					}
				}
			}
			catch
			{
			}
			return list;
		}

		internal static bool TryClaim(PhysGrabObject pgo, StupidBotCarrier owner)
		{
			if (!Object.op_Implicit((Object)(object)pgo))
			{
				return false;
			}
			int instanceID = ((Object)pgo).GetInstanceID();
			if (IsIgnored(pgo))
			{
				return false;
			}
			if (Claims.TryGetValue(instanceID, out StupidBotCarrier value) && Object.op_Implicit((Object)(object)value) && (Object)(object)value != (Object)(object)owner)
			{
				return false;
			}
			Claims[instanceID] = owner;
			return true;
		}

		internal static void ReleaseClaim(PhysGrabObject pgo, StupidBotCarrier owner)
		{
			if (Object.op_Implicit((Object)(object)pgo))
			{
				int instanceID = ((Object)pgo).GetInstanceID();
				if (Claims.TryGetValue(instanceID, out StupidBotCarrier value) && (Object)(object)value == (Object)(object)owner)
				{
					Claims.Remove(instanceID);
				}
			}
		}

		internal static bool IsClaimedByOther(PhysGrabObject pgo, StupidBotCarrier owner)
		{
			if (!Object.op_Implicit((Object)(object)pgo))
			{
				return false;
			}
			int instanceID = ((Object)pgo).GetInstanceID();
			if (!Claims.TryGetValue(instanceID, out StupidBotCarrier value))
			{
				return false;
			}
			if (Object.op_Implicit((Object)(object)value))
			{
				return (Object)(object)value != (Object)(object)owner;
			}
			return false;
		}

		internal static void IgnoreFor(PhysGrabObject pgo, float seconds)
		{
			if (Object.op_Implicit((Object)(object)pgo))
			{
				int instanceID = ((Object)pgo).GetInstanceID();
				IgnoreUntil[instanceID] = Time.time + Mathf.Max(0f, seconds);
				Claims.Remove(instanceID);
			}
		}

		internal static bool IsIgnored(PhysGrabObject pgo)
		{
			if (!Object.op_Implicit((Object)(object)pgo))
			{
				return false;
			}
			int instanceID = ((Object)pgo).GetInstanceID();
			if (!IgnoreUntil.TryGetValue(instanceID, out var value))
			{
				return false;
			}
			return value > Time.time;
		}

		internal static Vector3 WithY(this Vector3 v, float y)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			v.y = y;
			return v;
		}
	}
	internal class BotWeaponUser : MonoBehaviour
	{
		internal struct Cfg
		{
			public float SearchRadius;
		}

		private static readonly Dictionary<int, BotWeaponUser> Claims = new Dictionary<int, BotWeaponUser>();

		private static readonly Dictionary<int, float> EmptyUntil = new Dictionary<int, float>();

		private Cfg _cfg;

		private NavMeshAgent _agent;

		private Transform _hold;

		private StupidBotBrain _brain;

		private BotPersonality _persona;

		private ItemGun _gun;

		private PhysGrabObject _pgo;

		private Rigidbody _rb;

		private Collider[] _myCols;

		private readonly List<Collider> _gunCols = new List<Collider>();

		private float _retargetTimer;

		private float _fireTimer;

		private float _toyTimer;

		private bool _busy;

		private bool _subscribed;

		internal void Init(Cfg cfg, NavMeshAgent agent, Transform hold, StupidBotBrain brain, BotPersonality persona)
		{
			_cfg = cfg;
			_agent = agent;
			_hold = hold;
			_brain = brain;
			_persona = persona;
			_myCols = ((Component)this).GetComponentsInChildren<Collider>(true);
			_retargetTimer = Random.Range(0.2f, 0.8f);
			_fireTimer = Random.Range(0.4f, 1f);
			_toyTimer = Random.Range(1.5f, 3.5f);
		}

		private void OnDisable()
		{
			Drop(immediate: true);
		}

		private void Update()
		{
			//IL_00a6: 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_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if ((Object.op_Implicit((Object)(object)_persona) && !_persona.AllowWeapons) || _busy)
			{
				return;
			}
			if (Object.op_Implicit((Object)(object)_gun))
			{
				EnsureHeldTransform();
				_brain.SetExternalControl(on: true);
				AimAndShoot();
				return;
			}
			_retargetTimer -= Time.deltaTime;
			if (_retargetTimer > 0f)
			{
				return;
			}
			_retargetTimer = Random.Range(0.9f, 1.6f);
			ItemGun val = FindNearestGun();
			if (!Object.op_Implicit((Object)(object)val) || !TryClaim(val))
			{
				return;
			}
			_busy = true;
			Vector3 position = ((Component)val).transform.position;
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				NavMeshHit val2 = default(NavMeshHit);
				if (NavMesh.SamplePosition(position, ref val2, 2.5f, -1))
				{
					_agent.SetDestination(((NavMeshHit)(ref val2)).position);
				}
				else
				{
					_agent.SetDestination(position);
				}
				_agent.stoppingDistance = 0.35f;
			}
			((MonoBehaviour)this).StartCoroutine(ApproachAndPick(val));
		}

		private IEnumerator ApproachAndPick(ItemGun target)
		{
			float giveUp = 8f;
			_pgo = (Object.op_Implicit((Object)(object)target) ? ((Component)target).GetComponent<PhysGrabObject>() : null);
			while (giveUp > 0f && Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				giveUp -= Time.deltaTime;
				if (!IsValidTarget(target) || Vector3.Distance(((Component)this).transform.position, ((Component)target).transform.position) <= 1.8f)
				{
					break;
				}
				yield return null;
			}
			if (!Object.op_Implicit((Object)(object)target) || !Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh || !IsValidTarget(target))
			{
				if (Object.op_Implicit((Object)(object)target))
				{
					Release(target);
				}
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			_gun = target;
			_pgo = ((Component)target).GetComponent<PhysGrabObject>();
			_rb = (Object.op_Implicit((Object)(object)_pgo) ? _pgo.rb : null) ?? ((Component)target).GetComponent<Rigidbody>();
			try
			{
				Transform transform = ((Component)target).transform;
				transform.SetParent(_hold, false);
				transform.localPosition = Vector3.zero;
				transform.localRotation = Quaternion.identity;
				if (Object.op_Implicit((Object)(object)_rb))
				{
					_rb.velocity = Vector3.zero;
					_rb.angularVelocity = Vector3.zero;
					_rb.isKinematic = true;
				}
			}
			catch
			{
			}
			SetCarryCollisionIgnore(ignore: true);
			HookGunEvents(_gun, on: true);
			_brain.SetExternalControl(on: true);
			_busy = false;
		}

		private void AimAndShoot()
		{
			//IL_002d: 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_003e: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			_toyTimer -= Time.deltaTime;
			_fireTimer -= Time.deltaTime;
			Vector3 aimPos;
			Transform val = FindEnemyConstrained(out aimPos);
			Vector3 val2 = aimPos - _hold.position;
			Vector3 normalized = ((Vector3)(ref val2)).normalized;
			if (((Vector3)(ref normalized)).sqrMagnitude > 0.0001f)
			{
				_hold.rotation = Quaternion.Slerp(_hold.rotation, Quaternion.LookRotation(normalized, Vector3.up), Time.deltaTime * 10f);
			}
			if (Object.op_Implicit((Object)(object)_persona) && _persona.ToyingChance > 0f && _toyTimer <= 0f)
			{
				_toyTimer = Random.Range(1.5f, 3.5f);
				if (Random.value < _persona.ToyingChance && Object.op_Implicit((Object)(object)_pgo))
				{
					ItemToggle val3 = (Object.op_Implicit((Object)(object)_gun) ? ((Component)_gun).GetComponent<ItemToggle>() : null);
					if (Object.op_Implicit((Object)(object)val3))
					{
						val3.ToggleItem(!val3.toggleState, -1);
					}
				}
			}
			if (_fireTimer <= 0f)
			{
				_fireTimer = (Object.op_Implicit((Object)(object)_persona) ? Random.Range(_persona.FireInterval.x, _persona.FireInterval.y) : Random.Range(0.8f, 1.6f));
				if (Object.op_Implicit((Object)(object)val))
				{
					_gun.Shoot();
				}
				if (Object.op_Implicit((Object)(object)_persona) && _persona.DropChanceOnShoot > 0f && Random.value < _persona.DropChanceOnShoot)
				{
					Drop(immediate: false);
				}
			}
		}

		private void EnsureHeldTransform()
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_gun))
			{
				Transform transform = ((Component)_gun).transform;
				if ((Object)(object)transform.parent != (Object)(object)_hold)
				{
					transform.SetParent(_hold, false);
				}
				if (transform.localPosition != Vector3.zero)
				{
					transform.localPosition = Vector3.zero;
				}
				if (transform.localRotation != Quaternion.identity)
				{
					transform.localRotation = Quaternion.identity;
				}
				if (Object.op_Implicit((Object)(object)_rb) && !_rb.isKinematic)
				{
					_rb.velocity = Vector3.zero;
					_rb.angularVelocity = Vector3.zero;
					_rb.isKinematic = true;
				}
			}
		}

		private void Drop(bool immediate)
		{
			//IL_0054: 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)
			if (!Object.op_Implicit((Object)(object)_gun))
			{
				return;
			}
			try
			{
				HookGunEvents(_gun, on: false);
				SetCarryCollisionIgnore(ignore: false);
				((Component)_gun).transform.SetParent((Transform)null, true);
				if (Object.op_Implicit((Object)(object)_rb))
				{
					_rb.isKinematic = false;
					_rb.velocity = Vector3.zero;
					_rb.angularVelocity = Vector3.zero;
				}
			}
			catch
			{
			}
			Release(_gun);
			_gun = null;
			_pgo = null;
			_rb = null;
			_brain.SetExternalControl(on: false);
		}

		private bool IsValidTarget(ItemGun g)
		{
			if (!Object.op_Implicit((Object)(object)g))
			{
				return false;
			}
			int instanceID = ((Object)g).GetInstanceID();
			if (EmptyUntil.TryGetValue(instanceID, out var value) && value > Time.time)
			{
				return false;
			}
			PhysGrabObject component = ((Component)g).GetComponent<PhysGrabObject>();
			if (!Object.op_Implicit((Object)(object)component))
			{
				return false;
			}
			if (SemiFunc.PhysGrabObjectIsGrabbed(component))
			{
				return false;
			}
			return true;
		}

		private ItemGun FindNearestGun()
		{
			//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_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			ItemGun result = null;
			float num = float.PositiveInfinity;
			ItemGun[] array = Object.FindObjectsOfType<ItemGun>();
			Vector3 position = ((Component)this).transform.position;
			float num2 = _cfg.SearchRadius * _cfg.SearchRadius;
			foreach (ItemGun val in array)
			{
				if (Object.op_Implicit((Object)(object)val) && IsValidTarget(val) && !IsLikelyInsideExtractor(((Component)val).transform) && (!Claims.TryGetValue(((Object)val).GetInstanceID(), out BotWeaponUser value) || !Object.op_Implicit((Object)(object)value) || !((Object)(object)value != (Object)(object)this)))
				{
					Vector3 val2 = ((Component)val).transform.position - position;
					float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
					if (!(sqrMagnitude > num2) && sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = val;
					}
				}
			}
			return result;
		}

		private Transform FindEnemyConstrained(out Vector3 aimPos)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_00e4: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: 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_00fc: 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_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			aimPos = ((Component)this).transform.position + ((Component)this).transform.forward * 6f;
			Enemy[] array = Object.FindObjectsOfType<Enemy>();
			Transform result = null;
			float num = float.PositiveInfinity;
			Vector3 val = (Object.op_Implicit((Object)(object)_hold) ? _hold.position : (((Component)this).transform.position + Vector3.up * 1.5f));
			float num2 = Mathf.Cos((Object.op_Implicit((Object)(object)_persona) ? Mathf.Max(1f, _persona.AimConeDegrees) : 8f) * (MathF.PI / 180f));
			RaycastHit val5 = default(RaycastHit);
			foreach (Enemy val2 in array)
			{
				if (!Object.op_Implicit((Object)(object)val2) || !((Component)val2).gameObject.activeInHierarchy)
				{
					continue;
				}
				Transform transform = ((Component)val2).transform;
				Vector3 val3 = transform.position + Vector3.up * 0.6f;
				Vector3 val4 = val3 - val;
				float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
				if (!(sqrMagnitude > 900f))
				{
					Vector3 normalized = ((Vector3)(ref val4)).normalized;
					if (!(Vector3.Dot(((Component)this).transform.forward, normalized) < num2) && (!Physics.Raycast(val, normalized, ref val5, Mathf.Sqrt(sqrMagnitude), -1, (QueryTriggerInteraction)1) || (Object.op_Implicit((Object)(object)((RaycastHit)(ref val5)).collider) && Object.op_Implicit((Object)(object)((Component)((RaycastHit)(ref val5)).collider).GetComponentInParent<Enemy>()))) && sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = transform;
						aimPos = val3;
					}
				}
			}
			return result;
		}

		private bool IsLikelyInsideExtractor(Transform t)
		{
			//IL_0001: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			ExtractionPoint val = SemiFunc.ExtractionPointGetNearest(t.position);
			if (!Object.op_Implicit((Object)(object)val))
			{
				return false;
			}
			return Vector3.Distance(t.position, ((Component)val).transform.position) <= 1.25f;
		}

		private void SetCarryCollisionIgnore(bool ignore)
		{
			if (!Object.op_Implicit((Object)(object)_gun))
			{
				return;
			}
			_gunCols.Clear();
			((Component)_gun).GetComponentsInChildren<Collider>(true, _gunCols);
			if (_myCols == null || _myCols.Length == 0)
			{
				_myCols = ((Component)this).GetComponentsInChildren<Collider>(true);
			}
			for (int i = 0; i < _myCols.Length; i++)
			{
				Collider val = _myCols[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				for (int j = 0; j < _gunCols.Count; j++)
				{
					Collider val2 = _gunCols[j];
					if (Object.op_Implicit((Object)(object)val2))
					{
						Physics.IgnoreCollision(val, val2, ignore);
					}
				}
			}
		}

		private void HookGunEvents(ItemGun g, bool on)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (Object.op_Implicit((Object)(object)g) && _subscribed != on)
			{
				_subscribed = on;
				if (on)
				{
					g.onStateOutOfAmmoStart.AddListener(new UnityAction(OnGunOutOfAmmoStart));
				}
				else
				{
					g.onStateOutOfAmmoStart.RemoveListener(new UnityAction(OnGunOutOfAmmoStart));
				}
			}
		}

		private void OnGunOutOfAmmoStart()
		{
			if (Object.op_Implicit((Object)(object)_gun))
			{
				int instanceID = ((Object)_gun).GetInstanceID();
				EmptyUntil[instanceID] = Time.time + 25f;
			}
			Drop(immediate: false);
		}

		private bool TryClaim(ItemGun g)
		{
			if (!Object.op_Implicit((Object)(object)g))
			{
				return false;
			}
			int instanceID = ((Object)g).GetInstanceID();
			if (Claims.TryGetValue(instanceID, out BotWeaponUser value) && Object.op_Implicit((Object)(object)value) && (Object)(object)value != (Object)(object)this)
			{
				return false;
			}
			Claims[instanceID] = this;
			return true;
		}

		private void Release(ItemGun g)
		{
			if (Object.op_Implicit((Object)(object)g))
			{
				int instanceID = ((Object)g).GetInstanceID();
				if (Claims.TryGetValue(instanceID, out BotWeaponUser value) && (Object)(object)value == (Object)(object)this)
				{
					Claims.Remove(instanceID);
				}
			}
		}
	}
	internal static class DecTalkSynth
	{
		internal struct Clip
		{
			public float[] Samples;

			public int Channels;

			public int SampleRate;
		}

		private struct Job
		{
			public BotChatterAgent Agent;

			public string Text;
		}

		private struct Ready
		{
			public BotChatterAgent Agent;

			public Clip Clip;
		}

		private static class Wav
		{
			internal static bool TryLoad(string path, out float[] data, out int channels, out int sampleRate)
			{
				data = Array.Empty<float>();
				channels = 0;
				sampleRate = 0;
				using FileStream input = File.OpenRead(path);
				using BinaryReader binaryReader = new BinaryReader(input);
				if (new string(binaryReader.ReadChars(4)) != "RIFF")
				{
					return false;
				}
				binaryReader.ReadInt32();
				if (new string(binaryReader.ReadChars(4)) != "WAVE")
				{
					return false;
				}
				short num = 1;
				short num2 = 16;
				bool flag = false;
				while (binaryReader.BaseStream.Position < binaryReader.BaseStream.Length)
				{
					string text = new string(binaryReader.ReadChars(4));
					int num3 = binaryReader.ReadInt32();
					if (text == "fmt ")
					{
						flag = true;
						num = binaryReader.ReadInt16();
						channels = binaryReader.ReadInt16();
						sampleRate = binaryReader.ReadInt32();
						binaryReader.ReadInt32();
						binaryReader.ReadInt16();
						num2 = binaryReader.ReadInt16();
						int num4 = num3 - 16;
						if (num4 > 0)
						{
							binaryReader.ReadBytes(num4);
						}
						continue;
					}
					if (text == "data")
					{
						if (!flag)
						{
							return false;
						}
						byte[] array = binaryReader.ReadBytes(num3);
						if (num != 1)
						{
							return false;
						}
						switch (num2)
						{
						case 16:
						{
							int num6 = array.Length / 2;
							float[] array3 = new float[num6];
							int num7 = 0;
							int num8 = 0;
							while (num7 < num6)
							{
								short num9 = (short)(array[num8] | (array[num8 + 1] << 8));
								array3[num7] = (float)num9 / 32768f;
								num7++;
								num8 += 2;
							}
							data = array3;
							return true;
						}
						case 8:
						{
							int num5 = array.Length;
							float[] array2 = new float[num5];
							for (int i = 0; i < num5; i++)
							{
								array2[i] = (float)(array[i] - 128) / 128f;
							}
							data = array2;
							return true;
						}
						default:
							return false;
						}
					}
					binaryReader.ReadBytes(num3);
				}
				return false;
			}

			internal static float[] ResampleLinear(float[] interleaved, int channels, int srcRate, int dstRate)
			{
				if (srcRate == dstRate)
				{
					return interleaved;
				}
				int num = interleaved.Length / channels;
				double num2 = (double)dstRate / (double)srcRate;
				int num3 = Mathf.Max(1, (int)Math.Round((double)num * num2));
				float[] array = new float[num3 * channels];
				for (int i = 0; i < channels; i++)
				{
					for (int j = 0; j < num3; j++)
					{
						double num4 = (double)j / num2;
						int num5 = (int)Math.Floor(num4);
						int num6 = Math.Min(num - 1, num5 + 1);
						double num7 = num4 - (double)num5;
						float num8 = interleaved[num5 * channels + i];
						float num9 = interleaved[num6 * channels + i];
						array[j * channels + i] = (float)((double)num8 + (double)(num9 - num8) * num7);
					}
				}
				return array;
			}
		}

		private static string _exe;

		private static string _voice;

		private static int _rate;

		private static string _dict;

		private static readonly ConcurrentQueue<Job> _jobs = new ConcurrentQueue<Job>();

		private static readonly ConcurrentQueue<Ready> _ready = new ConcurrentQueue<Ready>();

		private static readonly Dictionary<string, Clip> _cache = new Dictionary<string, Clip>(64);

		private static readonly LinkedList<string> _lru = new LinkedList<string>();

		private static Thread _worker;

		private static volatile bool _run;

		internal static void Configure(string exe, string voice, int sampleRate, string dictionaryPath)
		{
			_exe = ResolvePath(exe);
			_voice = (string.IsNullOrWhiteSpace(voice) ? "Paul" : voice.Trim());
			_rate = Mathf.Clamp(sampleRate, 8000, 48000);
			_dict = (string.IsNullOrWhiteSpace(dictionaryPath) ? "" : ResolvePath(dictionaryPath.Trim()));
			StartWorker();
		}

		internal static void Enqueue(BotChatterAgent who, string text)
		{
			if (!((Object)(object)who == (Object)null) && !string.IsNullOrWhiteSpace(text))
			{
				_jobs.Enqueue(new Job
				{
					Agent = who,
					Text = text
				});
				StartWorker();
			}
		}

		internal static bool TryDequeueReady(out BotChatterAgent who, out Clip clip)
		{
			who = null;
			clip = default(Clip);
			if (_ready.TryDequeue(out var result))
			{
				who = result.Agent;
				clip = result.Clip;
				return true;
			}
			return false;
		}

		internal static bool TrySynthesize(string text, out Clip clip)
		{
			clip = default(Clip);
			if (!TrySynthesizeInternal(text, out clip))
			{
				return false;
			}
			return true;
		}

		private static void StartWorker()
		{
			if (_worker == null || !_worker.IsAlive)
			{
				_run = true;
				_worker = new Thread(WorkerLoop)
				{
					IsBackground = true,
					Name = "DecTalkSynthWorker"
				};
				_worker.Start();
			}
		}

		private static void WorkerLoop()
		{
			while (_run)
			{
				Clip clip;
				if (!_jobs.TryDequeue(out var result))
				{
					Thread.Sleep(1);
				}
				else if (!((Object)(object)result.Agent == (Object)null) && TrySynthesizeInternal(result.Text, out clip))
				{
					_ready.Enqueue(new Ready
					{
						Agent = result.Agent,
						Clip = clip
					});
				}
			}
		}

		private static bool TrySynthesizeInternal(string text, out Clip clip)
		{
			clip = default(Clip);
			if (string.IsNullOrEmpty(_exe) || !File.Exists(_exe))
			{
				return false;
			}
			if (TryGetCache(text, out clip))
			{
				return true;
			}
			try
			{
				string text2 = "[:name " + _voice + "] " + text;
				string text3 = Path.GetDirectoryName(_exe) ?? Directory.GetCurrentDirectory();
				string text4 = Path.Combine(text3, "out");
				Directory.CreateDirectory(text4);
				string text5 = DateTime.UtcNow.Ticks.ToString("x");
				string text6 = Path.Combine(text4, "dt_" + text5 + ".wav");
				string text7 = "";
				if (!string.IsNullOrEmpty(_dict) && File.Exists(_dict))
				{
					text7 = "-d \"" + _dict + "\" ";
				}
				ProcessStartInfo processStartInfo = new ProcessStartInfo();
				processStartInfo.FileName = _exe;
				processStartInfo.Arguments = "-w \"" + text6 + "\" " + text7 + "\"" + text2 + "\"";
				processStartInfo.WorkingDirectory = text3;
				processStartInfo.CreateNoWindow = true;
				processStartInfo.UseShellExecute = false;
				processStartInfo.RedirectStandardOutput = true;
				processStartInfo.RedirectStandardError = true;
				using (Process process = Process.Start(processStartInfo))
				{
					process?.WaitForExit(15000);
				}
				if (!File.Exists(text6))
				{
					return false;
				}
				if (!Wav.TryLoad(text6, out float[] data, out int channels, out int sampleRate))
				{
					return false;
				}
				if (sampleRate != _rate)
				{
					data = Wav.ResampleLinear(data, channels, sampleRate, _rate);
					sampleRate = _rate;
				}
				clip = new Clip
				{
					Samples = data,
					Channels = channels,
					SampleRate = sampleRate
				};
				try
				{
					File.Delete(text6);
				}
				catch
				{
				}
				PutCache(text, clip);
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static bool TryGetCache(string text, out Clip clip)
		{
			if (_cache.TryGetValue(text, out clip))
			{
				LinkedListNode<string> linkedListNode = _lru.Find(text);
				if (linkedListNode != null)
				{
					_lru.Remove(linkedListNode);
					_lru.AddFirst(linkedListNode);
				}
				return true;
			}
			return false;
		}

		private static void PutCache(string text, Clip clip)
		{
			if (_cache.ContainsKey(text))
			{
				return;
			}
			_cache[text] = clip;
			_lru.AddFirst(text);
			if (_lru.Count > 64)
			{
				LinkedListNode<string> last = _lru.Last;
				if (last != null)
				{
					_cache.Remove(last.Value);
					_lru.RemoveLast();
				}
			}
		}

		private static string ResolvePath(string p)
		{
			if (Path.IsPathRooted(p))
			{
				return p;
			}
			string location = Assembly.GetExecutingAssembly().Location;
			return Path.GetFullPath(Path.Combine(string.IsNullOrEmpty(location) ? Directory.GetCurrentDirectory() : (Path.GetDirectoryName(location) ?? Directory.GetCurrentDirectory()), p));
		}
	}
	internal class StupidBotBrain : MonoBehaviour
	{
		internal struct Config
		{
			public bool FollowPlayer;

			public float WanderRadius;

			public float Speed;
		}

		private const float FollowOrbitRadius = 12f;

		private Config _cfg;

		private NavMeshAgent? _agent;

		private Transform? _player;

		private Vector3 _homePos;

		private float _retargetTimer;

		private float _emoteTimer;

		private Vector3 _lastPos;

		private float _stuckTimer;

		private bool _hopping;

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

		private bool _haveGlobal;

		internal bool ExternalControl { get; private set; }

		internal void SetExternalControl(bool on)
		{
			ExternalControl = on;
		}

		internal void Init(Config cfg)
		{
			_cfg = cfg;
		}

		private void Start()
		{
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0032: Unknown result type (might be due to invalid IL or missing references)
			_agent = ((Component)this).GetComponent<NavMeshAgent>();
			if (Object.op_Implicit((Object)(object)_agent))
			{
				if (!_agent.isOnNavMesh)
				{
					TryPlaceOnNavMesh(_agent, ((Component)this).transform.position);
				}
				_agent.isStopped = false;
				_agent.updateRotation = true;
				_agent.autoBraking = true;
			}
			_homePos = ((Component)this).transform.position;
			TryGetPlayer(out _player);
			_retargetTimer = Random.Range(0.25f, 1.25f);
			_emoteTimer = Random.Range(2.5f, 7.5f);
			_lastPos = ((Component)this).transform.position;
			BuildGlobalTargets();
		}

		private void Update()
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Invalid comparison between Unknown and I4
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: 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_0284: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)_agent) && ((Behaviour)_agent).enabled)
			{
				_agent.speed = _cfg.Speed;
			}
			if ((Object)(object)_player == (Object)null)
			{
				TryGetPlayer(out _player);
			}
			if (ExternalControl)
			{
				return;
			}
			_retargetTimer -= Time.deltaTime;
			bool flag = false;
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				bool num = !_agent.hasPath || (int)_agent.pathStatus > 0;
				bool flag2 = _agent.hasPath && !_agent.pathPending && _agent.remainingDistance <= _agent.stoppingDistance + 0.1f;
				if (num || flag2 || _retargetTimer <= 0f)
				{
					flag = true;
				}
			}
			else if (_retargetTimer <= 0f)
			{
				flag = true;
			}
			if (flag)
			{
				_retargetTimer = Random.Range(1.6f, 3.2f);
				PickNextDestination();
			}
			_emoteTimer -= Time.deltaTime;
			if (_emoteTimer <= 0f)
			{
				_emoteTimer = Random.Range(4f, 10f);
				TryHop();
			}
			Vector3 val;
			if (Object.op_Implicit((Object)(object)_agent) && _agent.hasPath)
			{
				val = _agent.velocity;
				if (((Vector3)(ref val)).sqrMagnitude > 0.01f)
				{
					val = _agent.velocity;
					Vector3 normalized = ((Vector3)(ref val)).normalized;
					if (((Vector3)(ref normalized)).sqrMagnitude > 0.001f)
					{
						Quaternion val2 = Quaternion.LookRotation(normalized, Vector3.up);
						((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, Time.deltaTime * 5f);
					}
				}
			}
			val = ((Component)this).transform.position - _lastPos;
			float sqrMagnitude = ((Vector3)(ref val)).sqrMagnitude;
			_stuckTimer = ((sqrMagnitude < 0.0009f) ? (_stuckTimer + Time.deltaTime) : 0f);
			_lastPos = ((Component)this).transform.position;
			if (_stuckTimer > 1.5f && Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				_stuckTimer = 0f;
				_agent.ResetPath();
				_agent.Warp(((Component)this).transform.position);
			}
		}

		private void PickNextDestination()
		{
			//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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: 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_00c2: 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_0021: 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_004d: 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_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: 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_0107: 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)
			Vector3 homePos = _homePos;
			if (_cfg.FollowPlayer && Object.op_Implicit((Object)(object)_player))
			{
				Vector3 val = Random.insideUnitSphere;
				val.y = 0f;
				if (((Vector3)(ref val)).sqrMagnitude < 0.0001f)
				{
					val = Vector3.forward;
				}
				homePos = _player.position + ((Vector3)(ref val)).normalized * Random.Range(2.5f, 12f);
			}
			else if (_haveGlobal)
			{
				int index = Random.Range(0, _globalTargets.Count);
				homePos = _globalTargets[index];
			}
			else
			{
				homePos = _homePos + Random.insideUnitSphere.WithY(0f) * 25f;
			}
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				NavMeshHit val2 = default(NavMeshHit);
				if (NavMesh.SamplePosition(homePos, ref val2, 3f, -1))
				{
					_agent.SetDestination(((NavMeshHit)(ref val2)).position);
				}
				else
				{
					_agent.SetDestination(homePos);
				}
				return;
			}
			Vector3 val3 = homePos - ((Component)this).transform.position;
			val3.y = 0f;
			float num = Mathf.Min(_cfg.Speed * 0.5f * Time.deltaTime, ((Vector3)(ref val3)).magnitude);
			if (num > 0f)
			{
				Transform transform = ((Component)this).transform;
				transform.position += ((Vector3)(ref val3)).normalized * num;
			}
		}

		private void TryHop()
		{
			if (!((Object)(object)_agent == (Object)null) && !_hopping)
			{
				((MonoBehaviour)this).StartCoroutine(HopCR());
			}
		}

		private IEnumerator HopCR()
		{
			_hopping = true;
			float start = _agent.baseOffset;
			float peak = start + 0.6f;
			float t2 = 0f;
			float up = 0.15f;
			while (t2 < up)
			{
				t2 += Time.deltaTime;
				_agent.baseOffset = Mathf.Lerp(start, peak, t2 / up);
				yield return null;
			}
			t2 = 0f;
			float down = 0.2f;
			while (t2 < down)
			{
				t2 += Time.deltaTime;
				_agent.baseOffset = Mathf.Lerp(peak, start, t2 / down);
				yield return null;
			}
			_agent.baseOffset = start;
			_hopping = false;
		}

		private static bool TryGetPlayer(out Transform? player)
		{
			player = null;
			try
			{
				if (Object.op_Implicit((Object)(object)PlayerController.instance))
				{
					player = ((Component)PlayerController.instance).transform;
					return true;
				}
			}
			catch
			{
			}
			try
			{
				PlayerAvatar[] array = Object.FindObjectsOfType<PlayerAvatar>();
				if (array != null && array.Length != 0)
				{
					player = ((Component)array[0]).transform;
					return true;
				}
			}
			catch
			{
			}
			return false;
		}

		private static bool TryPlaceOnNavMesh(NavMeshAgent agent, Vector3 desired)
		{
			//IL_0000: 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_0013: Unknown result type (might be due to invalid IL or missing references)
			NavMeshHit val = default(NavMeshHit);
			if (NavMesh.SamplePosition(desired, ref val, 6f, -1))
			{
				return agent.Warp(((NavMeshHit)(ref val)).position);
			}
			return agent.Warp(desired);
		}

		private void BuildGlobalTargets()
		{
			//IL_008d: 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_00cd: 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_0064: Unknown result type (might be due to invalid IL or missing references)
			_globalTargets.Clear();
			try
			{
				if (Object.op_Implicit((Object)(object)LevelGenerator.Instance) && LevelGenerator.Instance.LevelPathPoints != null)
				{
					List<LevelPoint> levelPathPoints = LevelGenerator.Instance.LevelPathPoints;
					NavMeshHit val2 = default(NavMeshHit);
					for (int i = 0; i < levelPathPoints.Count; i++)
					{
						LevelPoint val = levelPathPoints[i];
						if (Object.op_Implicit((Object)(object)val) && NavMesh.SamplePosition(((Component)val).transform.position, ref val2, 3f, -1))
						{
							_globalTargets.Add(((NavMeshHit)(ref val2)).position);
						}
					}
				}
			}
			catch
			{
			}
			if (_globalTargets.Count == 0)
			{
				try
				{
					Vector3[] vertices = NavMesh.CalculateTriangulation().vertices;
					int num = Mathf.Max(1, vertices.Length / 64);
					NavMeshHit val3 = default(NavMeshHit);
					for (int j = 0; j < vertices.Length; j += num)
					{
						if (NavMesh.SamplePosition(vertices[j], ref val3, 3f, -1))
						{
							_globalTargets.Add(((NavMeshHit)(ref val3)).position);
						}
					}
				}
				catch
				{
				}
			}
			_haveGlobal = _globalTargets.Count > 0;
		}
	}
	internal class StupidBotCarrier : MonoBehaviour
	{
		internal struct Cfg
		{
			public float SearchRadius;

			public float ExtractorStopDistance;

			public float GentleDropTime;
		}

		private Cfg _cfg;

		private NavMeshAgent _agent;

		private Transform _hold;

		private StupidBotBrain _brain;

		private int _lastActivateId;

		private float _lastActivateTime;

		private Vector3 _truckDestination;

		private bool _truckCached;

		private PhysGrabObject _carried;

		private Rigidbody _carriedRB;

		private bool _busy;

		private bool _dropping;

		private float _retargetTimer;

		private float _savedStopDist;

		private Collider[] _myCols;

		private readonly List<Collider> _carriedCols = new List<Collider>();

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

		private float _activationGraceUntil;

		private float _carryTimer;

		private bool _isJumping;

		private float _jumpCD;

		private readonly Collider[] _overlap = (Collider[])(object)new Collider[32];

		private void OnDisable()
		{
			if (Object.op_Implicit((Object)(object)_carried))
			{
				ForceDrop(immediate: true);
			}
		}

		internal void Init(Cfg cfg, NavMeshAgent agent, Transform holdPoint, StupidBotBrain brain)
		{
			_myCols = ((Component)this).GetComponentsInChildren<Collider>(true);
			_cfg = cfg;
			_agent = agent;
			_hold = holdPoint;
			_brain = brain;
			_retargetTimer = Random.Range(0.25f, 0.75f);
			_activationGraceUntil = 0f;
			_carryTimer = 0f;
			_isJumping = false;
			_jumpCD = 0f;
		}

		private void Update()
		{
			//IL_01e9: 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_0183: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0301: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: 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)
			if (Object.op_Implicit((Object)(object)_carried))
			{
				_brain.SetExternalControl(on: true);
				_carryTimer += Time.deltaTime;
				ExtractionPoint targetEP = null;
				if (TryResolveDeliveryTarget(out Vector3 goal, out targetEP))
				{
					if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
					{
						if (!_agent.hasPath || Vector3.SqrMagnitude(_agent.destination - goal) > 0.25f)
						{
							_agent.SetDestination(goal);
						}
						_agent.stoppingDistance = Mathf.Clamp(_cfg.ExtractorStopDistance * 0.5f, 0.2f, 1f);
					}
					float num = Vector3.Distance(((Component)this).transform.position, goal);
					if (!_dropping && num <= Mathf.Max(0.5f, _cfg.ExtractorStopDistance + 0.25f))
					{
						if (IsDeliveryDropAllowed(targetEP) || Time.time < _activationGraceUntil || _carryTimer > 12f)
						{
							_dropping = true;
							((MonoBehaviour)this).StartCoroutine(DropGently());
						}
						else if (Object.op_Implicit((Object)(object)targetEP))
						{
							TryActivateExtraction(targetEP);
						}
					}
				}
				if (Object.op_Implicit((Object)(object)_carried) && !_dropping)
				{
					Transform transform = ((Component)_carried).transform;
					if ((Object)(object)transform.parent != (Object)(object)_hold)
					{
						transform.SetParent(_hold, false);
					}
					transform.localPosition = Vector3.zero;
					transform.localRotation = Quaternion.identity;
				}
				return;
			}
			_carryTimer = 0f;
			if (_busy)
			{
				return;
			}
			_retargetTimer -= Time.deltaTime;
			if (_retargetTimer > 0f)
			{
				return;
			}
			_retargetTimer = Random.Range(0.9f, 1.4f);
			List<PhysGrabObject> list = BotUtils.FindNearbyValuables(((Component)this).transform.position, _cfg.SearchRadius);
			PhysGrabObject val = null;
			float num2 = float.PositiveInfinity;
			foreach (PhysGrabObject item in list)
			{
				if (Object.op_Implicit((Object)(object)item) && !SemiFunc.PhysGrabObjectIsGrabbed(item) && Object.op_Implicit((Object)(object)((Component)item).GetComponent<ValuableObject>()) && !_ignoreIds.Contains(((Object)item).GetInstanceID()) && !BotUtils.IsIgnored(item) && !BotUtils.IsClaimedByOther(item, this) && !IsLikelyInsideExtractor(((Component)item).transform))
				{
					float num3 = Vector3.SqrMagnitude(((Component)item).transform.position - ((Component)this).transform.position);
					if (num3 < num2)
					{
						num2 = num3;
						val = item;
					}
				}
			}
			if (!Object.op_Implicit((Object)(object)val) || !BotUtils.TryClaim(val, this))
			{
				return;
			}
			_brain.SetExternalControl(on: true);
			_busy = true;
			if (Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				Vector3 position = ((Component)val).transform.position;
				NavMeshHit val2 = default(NavMeshHit);
				if (NavMesh.SamplePosition(position, ref val2, 2.5f, -1))
				{
					_agent.SetDestination(((NavMeshHit)(ref val2)).position);
				}
				else
				{
					_agent.SetDestination(position);
				}
			}
			((MonoBehaviour)this).StartCoroutine(ApproachAndPick(val));
		}

		private IEnumerator ApproachAndPick(PhysGrabObject target)
		{
			float stoppingDistance = 0.15f;
			float prevStop = (Object.op_Implicit((Object)(object)_agent) ? _agent.stoppingDistance : 0f);
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.stoppingDistance = stoppingDistance;
			}
			float giveUp = 10f;
			while (giveUp > 0f && Object.op_Implicit((Object)(object)target) && Object.op_Implicit((Object)(object)_agent) && _agent.isOnNavMesh)
			{
				giveUp -= Time.deltaTime;
				if (BotUtils.IsClaimedByOther(target, this))
				{
					BotUtils.ReleaseClaim(target, this);
					break;
				}
				if (CanReachByHold(target) || CanTouchTarget(target))
				{
					break;
				}
				TryJumpAssist(target);
				yield return null;
			}
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_agent.stoppingDistance = prevStop;
			}
			if (!Object.op_Implicit((Object)(object)target))
			{
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			if (!Object.op_Implicit((Object)(object)_agent) || !_agent.isOnNavMesh)
			{
				BotUtils.ReleaseClaim(target, this);
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			if (SemiFunc.PhysGrabObjectIsGrabbed(target))
			{
				BotUtils.ReleaseClaim(target, this);
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			if (!CanReachByHold(target) && !CanTouchTarget(target))
			{
				BotUtils.ReleaseClaim(target, this);
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			bool flag = false;
			Vector3 val = (Object.op_Implicit((Object)(object)_hold) ? _hold.position : (((Component)this).transform.position + Vector3.up * 1.5f));
			Vector3 val2 = ((Component)target).transform.position + Vector3.up * 0.1f;
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Linecast(val, val2, ref val3, -1, (QueryTriggerInteraction)1))
			{
				Transform transform = ((RaycastHit)(ref val3)).transform;
				if (Object.op_Implicit((Object)(object)transform) && (Object)(object)transform != (Object)(object)((Component)target).transform && !transform.IsChildOf(((Component)target).transform))
				{
					flag = true;
				}
			}
			if (flag && (CanReachByHold(target) || CanTouchTarget(target)))
			{
				flag = false;
			}
			if (flag)
			{
				BotUtils.ReleaseClaim(target, this);
				_busy = false;
				_brain.SetExternalControl(on: false);
				yield break;
			}
			if (Object.op_Implicit((Object)(object)target.rb) && !target.rb.isKinematic && (CanReachByHold(target) || CanTouchTarget(target)))
			{
				Vector3 val4 = (((Component)target).transform.position - ((Component)this).transform.position).WithY(0f);
				Vector3 val5 = ((Vector3)(ref val4)).normalized;
				if (((Vector3)(ref val5)).sqrMagnitude < 0.0001f)
				{
					val5 = ((Component)this).transform.forward;
				}
				try
				{
					target.rb.AddForce(val5 * 1.25f + Vector3.down * 2f, (ForceMode)1);
				}
				catch
				{
				}
				yield return (object)new WaitForSeconds(0.05f);
			}
			DetachExternalLinks(target);
			_carried = target;
			_carriedRB = target.rb;
			try
			{
				((Component)_carried).transform.SetParent((Transform)null, true);
				if (Object.op_Implicit((Object)(object)_carriedRB))
				{
					_carriedRB.velocity = Vector3.zero;
					_carriedRB.angularVelocity = Vector3.zero;
					_carriedRB.isKinematic = true;
				}
				target.OverrideKnockOutOfGrabDisable(2f);
			}
			catch
			{
			}
			SetCarryCollisionIgnore(ignore: true);
			if (Object.op_Implicit((Object)(object)_agent))
			{
				_savedStopDist = _agent.stoppingDistance;
			}
			_carryTimer = 0f;
		}

		private bool CanReachByHold(PhysGrabObject target)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Object.op_Implicit((Object)(object)_hold) ? _hold.position : (((Component)this).transform.position + Vector3.up * 1.5f));
			float num = float.PositiveInfinity;
			float num2 = float.PositiveInfinity;
			_carriedCols.Clear();
			((Component)target).GetComponentsInChildren<Collider>(true, _carriedCols);
			for (int i = 0; i < _carriedCols.Count; i++)
			{
				Collider val2 = _carriedCols[i];
				if (Object.op_Implicit((Object)(object)val2))
				{
					Vector3 val3 = val2.ClosestPoint(val);
					float num3 = Vector3.Distance(val, val3);
					if (num3 < num)
					{
						num = num3;
					}
					float num4 = Mathf.Abs(val3.y - val.y);
					if (num4 < num2)
					{
						num2 = num4;
					}
				}
			}
			if (float.IsInfinity(num))
			{
				num = Vector3.Distance(val, ((Component)target).transform.position);
				num2 = Mathf.Abs(((Component)target).transform.position.y - val.y);
			}
			Vector3 position = ((Component)this).transform.position;
			position.y = 0f;
			Vector3 position2 = ((Component)target).transform.position;
			position2.y = 0f;
			float num5 = Vector3.Distance(position, position2);
			if (num <= 1.5f && num5 <= 2.2f)
			{
				return true;
			}
			if (num5 <= 2.5f && num2 <= 2.2f)
			{
				return true;
			}
			return false;
		}

		private bool CanTouchTarget(PhysGrabObject target)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			int num = Physics.OverlapSphereNonAlloc(Object.op_Implicit((Object)(object)_hold) ? _hold.position : (((Component)this).transform.position + Vector3.up * 1.5f), 0.5f, _overlap, -1, (QueryTriggerInteraction)2);
			for (int i = 0; i < num; i++)
			{
				Collider obj = _overlap[i];
				Transform val = ((obj != null) ? ((Component)obj).transform : null);
				if (Object.op_Implicit((Object)(object)val) && ((Object)(object)val == (Object)(object)((Component)target).transform || val.IsChildOf(((Component)target).transform)))
				{
					return true;
				}
			}
			return false;
		}

		private void DetachExternalLinks(PhysGrabObject target)
		{
			try
			{
				Joint[] componentsInChildren = ((Component)target).GetComponentsInChildren<Joint>(true);
				foreach (Joint val in componentsInChildren)
				{
					if (!Object.op_Implicit((Object)(object)val))
					{
						continue;
					}
					Rigidbody connectedBody = val.connectedBody;
					if (Object.op_Implicit((Object)(object)connectedBody))
					{
						Transform transform = ((Component)connectedBody).transform;
						if (Object.op_Implicit((Object)(object)transform) && !transform.IsChildOf(((Component)target).transform) && (Object)(object)transform != (Object)(object)((Component)target).transform)
						{
							DisableJoint(val);
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				((Component)target).transform.SetParent((Transform)null, true);
			}
			catch
			{
			}
		}

		private IEnumerator DropGently()
		{
			if (!Object.op_Implicit((Object)(object)_carried))
			{
				_dropping = false;
				yield break;
			}
			Transform tform = ((Component)_carried).transform;
			try
			{
				tform.SetParent((Transform)null, true);
			}
			catch
			{
			}
			Vector3 start = tform.position;
			ExtractionPoint val = SemiFunc.ExtractionPointGetNearest(((Component)this).transform.position);
			Vector3 val2;
			Vector3 val3;
			if (!Ob