Decompiled source of RepoBots v0.21.1

plugins/RepoBots.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityEngine.Windows.Speech;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: InternalsVisibleTo("RepoBotsOpenTest")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("RepoBots")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoBots")]
[assembly: AssemblyTitle("RepoBots")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace RepoBots
{
	internal static class BotAI
	{
		private const string Url = "https://api.anthropic.com/v1/messages";

		private static int _inFlight;

		public static bool Enabled => !string.IsNullOrWhiteSpace(Plugin.AIApiKey.Value);

		public static void Reply(BotBrain bot, PlayerAvatar from, string message)
		{
			if (!Enabled || (Object)(object)BotManager.Runner == (Object)null)
			{
				bot.AnswerLater(0.3f, BotChat.Ask.Unknown, from, null);
			}
			else if (_inFlight < 2)
			{
				BotManager.Runner.StartCoroutine(Ask(bot, from, message));
			}
		}

		private static IEnumerator Ask(BotBrain bot, PlayerAvatar from, string message)
		{
			_inFlight++;
			string text = bot.AIBriefing(from);
			JObject val = new JObject
			{
				["model"] = JToken.op_Implicit(Plugin.AIModel.Value),
				["max_tokens"] = JToken.op_Implicit(120),
				["system"] = JToken.op_Implicit(text)
			};
			JArray val2 = new JArray();
			val2.Add((JToken)new JObject
			{
				["role"] = JToken.op_Implicit("user"),
				["content"] = JToken.op_Implicit(from.playerName + " says to you: \"" + message + "\"")
			});
			val["messages"] = (JToken)val2;
			JObject val3 = val;
			byte[] bytes = Encoding.UTF8.GetBytes(((JToken)val3).ToString((Formatting)0, Array.Empty<JsonConverter>()));
			UnityWebRequest req = new UnityWebRequest("https://api.anthropic.com/v1/messages", "POST");
			try
			{
				req.uploadHandler = (UploadHandler)new UploadHandlerRaw(bytes);
				req.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
				req.SetRequestHeader("content-type", "application/json");
				req.SetRequestHeader("x-api-key", Plugin.AIApiKey.Value.Trim());
				req.SetRequestHeader("anthropic-version", "2023-06-01");
				req.timeout = 12;
				yield return req.SendWebRequest();
				_inFlight--;
				if ((int)req.result != 1)
				{
					ManualLogSource log = Plugin.Log;
					object arg = req.responseCode;
					string error = req.error;
					DownloadHandler downloadHandler = req.downloadHandler;
					log.LogWarning((object)$"Claude reply failed ({arg}): {error} {Truncate((downloadHandler != null) ? downloadHandler.text : null, 300)}");
					bot.AnswerLater(0f, BotChat.Ask.Unknown, from, null);
					yield break;
				}
				string text2 = null;
				try
				{
					foreach (JToken item in (IEnumerable<JToken>)(((object)JObject.Parse(req.downloadHandler.text)["content"]) ?? ((object)new JArray())))
					{
						if ((string)item[(object)"type"] == "text")
						{
							text2 += (string)item[(object)"text"];
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Couldn't read Claude's reply: " + ex.Message));
				}
				if (string.IsNullOrWhiteSpace(text2))
				{
					yield break;
				}
				bot.FromAI(text2.Trim(), from);
			}
			finally
			{
				((IDisposable)req)?.Dispose();
			}
		}

		private static string Truncate(string s, int n)
		{
			if (s != null)
			{
				if (s.Length > n)
				{
					return s.Substring(0, n);
				}
				return s;
			}
			return "";
		}

		public static string TakeAction(ref string text)
		{
			Match match = Regex.Match(text, "\\[(FOLLOW|COME|WAIT|FREE|TRUCK|GRAB|BRING|CART|NONE)\\]", RegexOptions.IgnoreCase);
			text = Regex.Replace(text, "\\[[A-Z_]+\\]", "", RegexOptions.IgnoreCase).Trim();
			if (!match.Success)
			{
				return null;
			}
			return match.Groups[1].Value.ToUpperInvariant();
		}
	}
	internal class BotBrain
	{
		private enum OpenStep
		{
			Approach,
			Pull,
			Peek
		}

		internal class Box
		{
			public PhysGrabHinge Hinge;

			public PhysGrabObject Door;

			public string Kind;

			public Bounds Furniture;
		}

		private enum Job
		{
			Follow,
			Flee,
			Freeze,
			Hide,
			Revive,
			Haul,
			Cart,
			Activate,
			Explore,
			Truck,
			Assist,
			Escort,
			Guard,
			Order,
			Heal,
			Open,
			HangOut,
			Gnome,
			Use
		}

		private enum Carry
		{
			Approach,
			Hold,
			Deliver
		}

		private class Percept
		{
			public Vector3 Pos;

			public float SeenAt = -100f;

			public float HeardAt = -100f;
		}

		private enum CartGoal
		{
			Extraction,
			LootZone,
			OutOfExtraction
		}

		private class PersonMemory
		{
			public Vector3 Pos;

			public float Time = -100f;

			public bool SeenNow;
		}

		internal enum OrderKind
		{
			None,
			Follow,
			Come,
			Hold,
			GoTo,
			Truck
		}

		private class Pending
		{
			public float At;

			public string Text;

			public int Prio;

			public bool CanReply;

			public Action After;
		}

		private class Want
		{
			public string Item;

			public string Owner;
		}

		public static bool MuteReplies;

		private static readonly Regex BoxName = new Regex("chest|wardrobe|bookshel|cabinet|fridge|locker|safe|garbage bin|bin\\b|bajamaja|toilet", RegexOptions.IgnoreCase);

		private static readonly Regex NotBox = new Regex("door|stall|vent|hatch|hinges|garage car|helicopter|mount|painting|shelves \\(", RegexOptions.IgnoreCase);

		internal static readonly List<Box> Boxes = new List<Box>();

		private static readonly Dictionary<PhysGrabHinge, Box> BoxOf = new Dictionary<PhysGrabHinge, Box>();

		private static readonly Dictionary<Box, BotBrain> OpenClaims = new Dictionary<Box, BotBrain>();

		private static float _boxesAt;

		private static bool _boxesFound;

		private readonly HashSet<Box> _boxSeen = new HashSet<Box>();

		private readonly HashSet<Box> _boxDone = new HashSet<Box>();

		private readonly HashSet<Box> _boxSkip = new HashSet<Box>();

		private float _boxLookAt;

		private float _openCheckAt;

		private Box _openBox;

		private OpenStep _openStep;

		private bool _openAsked;

		private Vector3? _openSpot;

		private float _openSpotAt;

		private int _openSpotTries;

		private Vector3 _openLocal;

		private float _openSign = 1f;

		private float _openBest;

		private float _openProgressAt;

		private int _openFlips;

		private int _openRegrabs;

		private float _peekUntil;

		private int _peekBefore;

		private int _openSweep;

		private Vector3 _openSweepAt;

		private const float WalkSpeed = 3.2f;

		private const float SprintSpeed = 5.6f;

		private const float CarrySpeed = 2.2f;

		private const float CrouchSpeed = 1.6f;

		private const float CrawlSpeed = 0.9f;

		private const float Accel = 18f;

		private const float EyeHeight = 1.5f;

		private const float ReachDistance = 3.5f;

		private const float Radius = 0.32f;

		private const float BodyHeight = 1.7f;

		private const float StepHeight = 0.4f;

		private const float Skin = 0.03f;

		private const int Stand = 0;

		private const int Crouch = 1;

		private const int Crawl = 2;

		private static readonly HashSet<string> LooksUnder = new HashSet<string> { "EnemyRobe", "EnemyRunner", "EnemySlowWalker", "EnemyHead" };

		private static readonly HashSet<string> Deadly = new HashSet<string> { "EnemyRobe", "EnemyRunner", "EnemyHead", "EnemySlowWalker", "EnemyBeamer", "EnemyTumbler", "EnemyFloater" };

		private static readonly int GroundMask = LayerMask.GetMask(new string[3] { "Default", "NavmeshOnly", "PlayerOnlyCollision" });

		private static readonly int MoveMask = LayerMask.GetMask(new string[5] { "Default", "PhysGrabObject", "PhysGrabObjectCart", "PhysGrabObjectHinge", "StaticGrabObject" });

		private static readonly RaycastHit[] Hits = (RaycastHit[])(object)new RaycastHit[24];

		private static readonly Dictionary<PhysGrabObject, BotBrain> Claims = new Dictionary<PhysGrabObject, BotBrain>();

		private static readonly Dictionary<PhysGrabObject, float> Blacklist = new Dictionary<PhysGrabObject, float>();

		private static BotBrain _activator;

		private readonly BotInfo _bot;

		private readonly NavMeshPath _path = new NavMeshPath();

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

		private int _corner;

		private float _repathAt;

		private Vector3 _pathGoal;

		private Job _job;

		private Job _jobBeforeFreeze;

		private float _thinkAt;

		private float _jobStarted;

		private PlayerAvatar _leader;

		private bool _walking;

		private bool _sprinting;

		private readonly float _followDist;

		private readonly float _sideBias;

		private Threat _danger;

		private Vector3 _fleeTo;

		private float _fleeUntil;

		private bool _fleeRun;

		private float _freezeUntil;

		private bool _quiet;

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

		private Vector3 _hideSpot;

		private bool _hideUnder;

		private float _hideStarted;

		private float _hideCalmSince = -1f;

		private int _posture;

		private readonly Dictionary<EnemyParent, Percept> _known = new Dictionary<EnemyParent, Percept>();

		private readonly List<Threat> _knownList = new List<Threat>();

		private readonly HashSet<EnemyParent> _seenNow = new HashSet<EnemyParent>();

		private int _knownFrame = -1;

		private float _heardUpTo;

		private Vector3 _attention;

		private float _attentionNext;

		private float _listenUntil;

		private float _attentionUntil;

		private LevelPoint _explore;

		private float _exploreStarted;

		private float _scanAt;

		private float _scanYaw;

		private bool _wasTumbling;

		private float _tumbleStarted;

		private bool _tumbleOnPurpose;

		private float _nextDiveAt;

		private PhysGrabObject _target;

		private PlayerAvatar _reviveOf;

		private PhysGrabCart _cart;

		private PhysGrabCart _pushing;

		private Carry _carry;

		private float _carryProblemSince = -1f;

		private float _deliverStarted;

		private float _grabbedAt;

		private float _itemBlocked;

		private float _crampedCheckAt;

		private bool _itemCramped;

		private int _wedgedCount;

		private Vector3? _approachFrom;

		private ExtractionPoint _activateTarget;

		private Vector3 _progressPos;

		private float _progressAt;

		private float _blockedSince = -1f;

		private Vector3 _sidestep;

		private float _sidestepUntil;

		private bool _wasDisabled;

		private BotBody _body;

		private PhysGrabObject _bodyIgnoresHeld;

		private float _glanceAt;

		private float _glanceYaw;

		private float _seeAt;

		private float _tagAlongUntil;

		private float _tagAlongRollAt;

		private static readonly Dictionary<PhysGrabObject, int> Fails = new Dictionary<PhysGrabObject, int>();

		private static readonly Dictionary<PhysGrabObject, float> HumanHeldAt = new Dictionary<PhysGrabObject, float>();

		private ExtractionPoint _reviveEP;

		private static readonly Collider[] Overlaps = (Collider[])(object)new Collider[16];

		private static readonly Collider[] Nearby = (Collider[])(object)new Collider[64];

		private const float SightRange = 22f;

		private const float SightHalfAngle = 60f;

		private const float FeelRange = 3f;

		private const float RememberSeen = 5f;

		private const float RememberHeard = 4f;

		private float _escapeLogAt;

		private float _liftUntil;

		private float _snagSince = -1f;

		private float _snagGraceUntil;

		private Vector3 _avoidDir;

		private float _avoidUntil;

		private bool _pathFailed;

		private bool _pathPartial;

		private float _yawVel;

		private float _pitchVel;

		private float _tapPhase;

		private bool _jobWantsToMove;

		private float _cartApproachAt = -1f;

		private float _grabCrouchUntil;

		private float _carryLogAt;

		private float _helpAskedAt;

		private float _haulCheckAt;

		private Vector3 _haulCheckPos;

		private bool _haulMoved = true;

		private static BotBrain _driver;

		private static BotBrain _escort;

		private static readonly Dictionary<PhysGrabCart, float> HumanTouchedAt = new Dictionary<PhysGrabCart, float>();

		private CartGoal _cartGoal;

		private Vector3 _cartDest;

		private int _cartFan = -1;

		private float _cartDecideAt;

		private float _cartParkedAt = -100f;

		private bool _cartForPerson;

		private PhysGrabCart _escortCart;

		private bool _escortHaul;

		private float _cartStillSince = -1f;

		private float _escortLostAt = -1f;

		private bool _guarding;

		private float _cartThreatAt = -100f;

		private Vector3 _cartThreatPos;

		private Vector3? _guardSpot;

		private Vector3? _detour;

		private float _routeWaitSince = -1f;

		private bool _routeLogged;

		private static readonly int CartWallMask = LayerMask.GetMask(new string[2] { "Default", "StaticGrabObject" });

		private PhysGrabCart _cartMeasured;

		private Vector3 _cartHalf;

		private Vector3 _cartCenterLocal;

		private float _cartBackUntil;

		private Vector3 _cartBackTurn;

		private float _cartBlockedSince = -1f;

		private float _cartModeBadSince = -1f;

		private float _cartAimBadSince = -1f;

		private bool _cartAimLogged;

		private static readonly int HingeMask = LayerMask.GetMask(new string[1] { "PhysGrabObjectHinge" });

		private static readonly RaycastHit[] DoorHits = (RaycastHit[])(object)new RaycastHit[8];

		private Box _door;

		private bool _doorHolding;

		private Vector3 _doorLocal;

		private float _doorSign = 1f;

		private float _doorStarted;

		private float _doorBest;

		private float _doorProgressAt;

		private int _doorFlips;

		private float _doorCheckAt;

		private readonly Dictionary<PhysGrabHinge, float> _doorRest = new Dictionary<PhysGrabHinge, float>();

		private PhysGrabHinge _backDoor;

		private float _backUntil;

		private float _backPushAt;

		private float _backClearSince = -1f;

		private static readonly Dictionary<PhysGrabHinge, BotBrain> DoorClaims = new Dictionary<PhysGrabHinge, BotBrain>();

		private float _doorWaitUntil;

		private Vector3 _doorWaitFrom;

		private EnemyParent _gnome;

		private float _gnomeSlamAt;

		private bool _gnomeUp;

		private float _gnomeCheckAt;

		private Vector3? _hangSpot;

		private Vector3 _hangAnchor;

		private bool _hangAnchored;

		private float _hangMoveAt;

		private bool _hangMoving;

		private float _hangLookAt;

		private Vector3? _hangLook;

		private PlayerAvatar _hangWho;

		private static readonly Dictionary<PlayerAvatar, PlayerHealthGrab> NeckOf = new Dictionary<PlayerAvatar, PlayerHealthGrab>();

		private static float _necksAt;

		private readonly Dictionary<PlayerAvatar, float> _knowHurt = new Dictionary<PlayerAvatar, float>();

		private PlayerAvatar _healing;

		private int _healStartHp;

		private int _healTargetHp;

		private float _healProgressAt;

		private bool _healAsked;

		private float _healCheckAt;

		private Vector3? _sneakTo;

		private bool _sneakUnder;

		private Vector3 _hunterLastPos;

		private float _hunterLastAt;

		private Vector3 _hunterVel;

		private float _frozeAt;

		private Vector3 _zoneCenter;

		private float _zoneRadius;

		private float _zoneUntil;

		private float _escapeUntil;

		private Vector3 _escapeTo;

		private static readonly int RoomLayer = LayerMask.GetMask(new string[1] { "RoomVolume" });

		private static readonly Collider[] MapHits = (Collider[])(object)new Collider[8];

		private readonly Dictionary<RoomVolume, float> _rooms = new Dictionary<RoomVolume, float>();

		private float _mapLearnAt;

		private Vector3 _routeCheckedGoal = new Vector3(9999f, 9999f, 9999f);

		private bool _mapOut;

		private float _mapUntil;

		private float _mapNextAllowed;

		private float _mapIdleAt = -1f;

		private Action _mapAfter;

		private const float PeopleSightRange = 30f;

		private const float ShareRange = 15f;

		private const float ForgetPerson = 90f;

		private readonly Dictionary<PlayerAvatar, PersonMemory> _people = new Dictionary<PlayerAvatar, PersonMemory>();

		private readonly HashSet<ValuableObject> Seen = new HashSet<ValuableObject>();

		private readonly Dictionary<PhysGrabObject, Vector3> _thingPos = new Dictionary<PhysGrabObject, Vector3>();

		private readonly List<PhysGrabCart> Carts = new List<PhysGrabCart>();

		private readonly HashSet<LevelPoint> Visited = new HashSet<LevelPoint>();

		private float _memoryAt;

		private float _shareAt;

		private static readonly List<PhysGrabCart> AllCarts = new List<PhysGrabCart>();

		private static float _allCartsAt;

		private OrderKind _order;

		private PlayerAvatar _orderBy;

		private Vector3 _orderPos;

		private float _orderUntil;

		private bool _orderArrived;

		private PlayerAvatar _bringTo;

		private float _orderLostSince = -1f;

		private bool _orderMoving;

		private int _orderStuck;

		private static readonly string[] Okays = new string[6] { "On it.", "Okay.", "Got it.", "Sure thing.", "You got it.", "Will do." };

		private ItemAttributes _shopItem;

		private bool _shopPutBack;

		private float _shopCheckAt;

		private float _shopNothingLogAt;

		private static Object _shopVisit;

		private static int _shopVisitNo;

		private static float _shopSince;

		private static readonly List<ItemAttributes> ShopStock = new List<ItemAttributes>();

		private static float _stockAt;

		private static readonly Dictionary<ItemAttributes, BotBrain> ShopBought = new Dictionary<ItemAttributes, BotBrain>();

		private static readonly Dictionary<ItemAttributes, Vector3> ShelfSpot = new Dictionary<ItemAttributes, Vector3>();

		private static readonly List<Vector3> BadShelves = new List<Vector3>();

		private static readonly HashSet<PlayerAvatar> WentShopping = new HashSet<PlayerAvatar>();

		private static bool _budgetSaid;

		private static bool _doneSaid;

		private static bool _buttonSaid;

		private static float _overSaidAt;

		private static int _stopVisit = -1;

		private static int _wantVisit = -1;

		private static string _shopWant;

		private BotPersona _persona;

		private List<string> _voices;

		private SlangStyle _slang;

		private float _talkAt;

		private bool _greeted;

		private float _greetAt = -1f;

		private float _banterAt;

		private bool _deadLineSaid;

		private float _diedAt = -1f;

		private PhysGrabObject _heldTalk;

		private string _heldName;

		private float _heldValue;

		private readonly List<Pending> _pending = new List<Pending>();

		private static readonly Dictionary<string, float> TeamSaid = new Dictionary<string, float>();

		private static float _anyTalkAt;

		internal static readonly List<string> Conversation = new List<string>();

		private const int Chatter = 0;

		private const int Info = 1;

		private const int Urgent = 2;

		private const int Reply = 3;

		private string _typing;

		private string _typingPlain;

		private string _typingFix;

		private int _typingPrio;

		private float _typingDone;

		private bool _typingReply;

		private string _typingTopic;

		private Action _typingAfter;

		private string _deferred;

		private int _deferredPrio;

		private float _deferredAt;

		private bool _deferredReply;

		private string _deferredTopic;

		private Action _deferredAfter;

		private float _cps = -1f;

		private static readonly Dictionary<PlayerAvatar, bool> WasDead = new Dictionary<PlayerAvatar, bool>();

		private static readonly Dictionary<PlayerAvatar, int> LastHp = new Dictionary<PlayerAvatar, int>();

		private static int _extractionsSeen = -1;

		private static int _watchFrame = -1;

		private static readonly int RoomMask = LayerMask.GetMask(new string[1] { "RoomVolume" });

		private static readonly Collider[] RoomHits = (Collider[])(object)new Collider[8];

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

		private static readonly HashSet<string> Generic = new HashSet<string>
		{
			"n", "s", "e", "w", "start", "room", "module", "level", "normal", "passage",
			"dead end", "deadend", "extraction", "truck"
		};

		private static readonly Dictionary<PhysGrabObject, List<BotBrain>> Helpers = new Dictionary<PhysGrabObject, List<BotBrain>>();

		private PhysGrabObject _assist;

		private bool _slackerRun;

		private bool _screenMode;

		private float _screenStarted;

		private float _screenGrabbedAt;

		private float _screenNudgeAt;

		private bool _finalSeen;

		private static readonly List<Want> Wants = new List<Want>();

		private ItemAttributes _useItem;

		private float _useStarted;

		private float _usePressedAt;

		private float _useCheckAt;

		private string _useName;

		private string _useKey;

		private float BoxRange => Mathf.Lerp(8f, 16f, P.Greed);

		private bool NoWayThere
		{
			get
			{
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_0051: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				if (!_pathFailed)
				{
					if (_pathPartial && _corner >= _corners.Count - 1 && _corners.Count > 0)
					{
						Vector3 val = Flat(_corners[_corners.Count - 1] - _bot.Position);
						if (((Vector3)(ref val)).magnitude < 1.2f)
						{
							goto IL_006f;
						}
					}
					return false;
				}
				goto IL_006f;
				IL_006f:
				return !StraightOk(_bot.Position, _pathGoal);
			}
		}

		private bool OpeningDoor => _door != null;

		private bool HangingOutHere => SemiFunc.RunIsLobby();

		private float Generosity => Mathf.Clamp01(0.65f * P.Helpful + 0.35f * P.Brave);

		private int HealFloor => Mathf.RoundToInt(Mathf.Lerp(70f, 12f, Generosity));

		private int HealBudget => Mathf.RoundToInt(Mathf.Lerp(10f, 90f, Generosity) / 10f) * 10;

		private int MyHealth
		{
			get
			{
				if (!((Object)(object)_bot.Avatar != (Object)null) || !((Object)(object)_bot.Avatar.playerHealth != (Object)null))
				{
					return 0;
				}
				return _bot.Avatar.playerHealth.health;
			}
		}

		private bool CanSpare => MyHealth - 10 >= HealFloor;

		internal Collider BodyCollider
		{
			get
			{
				if (!((Object)(object)_body != (Object)null))
				{
					return null;
				}
				return (Collider)(object)_body.Col;
			}
		}

		private int HealthNow
		{
			get
			{
				if (!((Object)(object)_bot.Avatar != (Object)null) || !((Object)(object)_bot.Avatar.playerHealth != (Object)null))
				{
					return 100;
				}
				return _bot.Avatar.playerHealth.health;
			}
		}

		private float Nerve
		{
			get
			{
				if (HealthNow >= 30)
				{
					if (HealthNow >= 50)
					{
						return P.Brave;
					}
					return Mathf.Min(P.Brave, 0.4f);
				}
				return Mathf.Min(P.Brave, 0.05f);
			}
		}

		private float MemorySpan => Mathf.Lerp(150f, 420f, P.Careful);

		public bool Alive
		{
			get
			{
				if ((Object)(object)_bot.Avatar != (Object)null)
				{
					return !_bot.Avatar.isDisabled;
				}
				return false;
			}
		}

		public Vector3 Position => _bot.Position;

		public string Name => _bot.Name;

		public PlayerAvatar Self => _bot.Avatar;

		public OrderKind CurrentOrder => _order;

		public PlayerAvatar OrderedBy => _orderBy;

		private static bool ShopStopped => _stopVisit == _shopVisitNo;

		private static string ShopWant
		{
			get
			{
				if (_wantVisit != _shopVisitNo)
				{
					return null;
				}
				return _shopWant;
			}
		}

		internal static bool AnyBotPurchases => ShopBought.Count > 0;

		private static int Currency => SemiFunc.StatGetRunCurrency();

		private static int ZoneCost => SemiFunc.ShopGetTotalCost();

		private BotPersona P => _persona ?? (_persona = BotPersona.For(_bot.SteamId));

		private List<string> Voices => _voices ?? (_voices = MakeVoices());

		private SlangStyle Slang => _slang ?? (_slang = SlangStyle.For(_bot.SteamId, P));

		private bool Typing => _typing != null;

		private float CharsPerSecond
		{
			get
			{
				if (_cps < 0f)
				{
					uint num = 2166136261u;
					string text = _bot.Name + _bot.SteamId;
					foreach (char c in text)
					{
						num = (num ^ c) * 16777619;
					}
					num ^= num >> 15;
					num *= 739982445;
					num ^= num >> 12;
					float num2 = 3.5f + (float)(num % 1000) / 1000f * 7.5f;
					_cps = num2 * Mathf.Lerp(0.85f, 1.2f, P.Chatty) * Mathf.Lerp(1.1f, 0.9f, P.Careful);
					Plugin.Log.LogInfo((object)$"{_bot.Name} types {_cps:0.0} letters a second");
				}
				return _cps;
			}
		}

		public bool OnScreen => _screenMode;

		private float HeavyLimit => Plugin.MaxCarryMass.Value;

		public void SayAck(string text)
		{
			Say(text, 3);
		}

		public void AnswerLater(float delay, BotChat.Ask ask, PlayerAvatar asker, string subject)
		{
			HeardFrom(asker);
			string text = AnswerText(ask, asker, subject);
			if (text != null)
			{
				if (delay <= 0.05f)
				{
					Say(text, 3);
				}
				else
				{
					SayLater(delay, text, 3);
				}
			}
		}

		internal string AIBriefing(PlayerAvatar asker)
		{
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("You are " + _bot.Name + ", a crew member in the co-op horror game R.E.P.O.: little robots sent into creepy places to grab valuables and haul them to an extraction point while avoiding monsters. You're one of the crew, talking out loud with a text-to-speech voice to your teammate " + asker.playerName + ".");
			stringBuilder.AppendLine("Your personality: " + P.Describe() + ". Talk like that.");
			stringBuilder.AppendLine("Reply with ONE short spoken line, under 15 words. Casual, a bit funny, no emojis, no stage directions, no quotes, spell numbers as words.");
			stringBuilder.AppendLine("Only use the facts below. If you don't know something, say so; never make up where things are.");
			stringBuilder.AppendLine("If they're asking you to do something, end your reply with one tag: [FOLLOW] (follow them), [COME] (go to them), [WAIT] (stay where you are), [FREE] (go back to looting on your own), [TRUCK] (go to the truck), [GRAB] (pick up what they're looking at), [BRING] (bring them what they're looking at), [CART] (take charge of the cart). Otherwise no tag.");
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("What you know right now:");
			stringBuilder.AppendLine("- You are: " + DoingNow() + ".");
			PlayerAvatar avatar = _bot.Avatar;
			if ((Object)(object)avatar != (Object)null && (Object)(object)avatar.playerHealth != (Object)null)
			{
				stringBuilder.AppendLine($"- Your health: {avatar.playerHealth.health} of {avatar.playerHealth.maxHealth}.");
			}
			stringBuilder.AppendLine($"- You remember {_rooms.Count} rooms of this level.");
			stringBuilder.AppendLine("- This save so far: " + HistoryText() + ". Level " + Words((((Object)(object)RunManager.instance != (Object)null) ? RunManager.instance.levelsCompleted : 0) + 1) + " of the run.");
			string text = RoomName(_bot.Position);
			if (text != null)
			{
				stringBuilder.AppendLine("- You're in " + text + ".");
			}
			if ((Object)(object)asker != (Object)null && !asker.isDisabled)
			{
				stringBuilder.AppendLine("- " + asker.playerName + " is " + Where(((Component)asker).transform.position, forListener: false) + " (from you).");
			}
			List<Threat> list = KnownThreats();
			if (list.Count == 0)
			{
				stringBuilder.AppendLine("- No monsters seen or heard lately.");
			}
			foreach (Threat item in list)
			{
				stringBuilder.AppendLine("- A " + MonsterName(item.Kind) + " " + Where(item.Position, forListener: true, asker) + " (from " + asker.playerName + "'s view)" + (item.Aggressive ? ", and it's angry" : "") + ".");
			}
			string text2 = AnswerText(BotChat.Ask.Loot, asker, null);
			if (text2 != null)
			{
				stringBuilder.AppendLine("- Loot: " + text2);
			}
			string text3 = AnswerText(BotChat.Ask.Money, asker, null);
			if (!string.IsNullOrEmpty(text3))
			{
				stringBuilder.AppendLine("- Money: " + text3);
			}
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if ((Object)(object)player != (Object)null && (Object)(object)player != (Object)(object)avatar && player.isDisabled)
				{
					stringBuilder.AppendLine("- " + player.playerName + " is dead.");
				}
			}
			if (Conversation.Count > 0)
			{
				stringBuilder.AppendLine();
				stringBuilder.AppendLine("Recent chat:");
				foreach (string item2 in Conversation)
				{
					stringBuilder.AppendLine(item2);
				}
			}
			return stringBuilder.ToString();
		}

		internal void FromAI(string text, PlayerAvatar from)
		{
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			string text2 = BotAI.TakeAction(ref text);
			text = text.Trim('"', ' ');
			if (text.Length > 140)
			{
				text = text.Substring(0, 140);
			}
			text = Regex.Replace(text, "\\d+", (Match m) => (!int.TryParse(m.Value, out var result)) ? m.Value : Words(result));
			Plugin.Log.LogInfo((object)(_bot.Name + " (Claude) -> " + text + ((text2 != null) ? (" [" + text2 + "]") : "")));
			MuteReplies = true;
			try
			{
				if (text2 != null)
				{
					switch (text2.Length)
					{
					default:
						goto end_IL_00a7;
					case 4:
						switch (text2[2])
						{
						default:
							goto end_IL_00a7;
						case 'M':
							if (text2 == "COME")
							{
								OrderCome(from);
							}
							goto end_IL_00a7;
						case 'I':
							if (text2 == "WAIT")
							{
								OrderHold(from);
							}
							goto end_IL_00a7;
						case 'E':
							if (text2 == "FREE")
							{
								ClearOrder(say: false);
							}
							goto end_IL_00a7;
						case 'R':
							if (text2 == "CART")
							{
								PhysGrabCart val = BotCommands.NearestCart(_bot.Position);
								if ((Object)(object)val != (Object)null)
								{
									OrderCart(from, val, toPerson: false);
								}
							}
							goto end_IL_00a7;
						case 'A':
							if (text2 == "GRAB")
							{
								break;
							}
							goto end_IL_00a7;
						}
						break;
					case 5:
						switch (text2[0])
						{
						default:
							goto end_IL_00a7;
						case 'T':
							if (text2 == "TRUCK")
							{
								OrderTruck(from);
							}
							goto end_IL_00a7;
						case 'B':
							if (text2 == "BRING")
							{
								break;
							}
							goto end_IL_00a7;
						}
						break;
					case 6:
						if (text2 == "FOLLOW" && _order != OrderKind.Follow)
						{
							OrderFollow(from);
						}
						goto end_IL_00a7;
					}
					PhysGrabObject val2 = BotCommands.GazeObject(from);
					if ((Object)(object)val2 != (Object)null)
					{
						OrderGrab(from, val2, text2 == "BRING");
					}
				}
				end_IL_00a7:;
			}
			finally
			{
				MuteReplies = false;
			}
			Say(text, 3);
		}

		private static void ResetBoxStatics()
		{
			Boxes.Clear();
			BoxOf.Clear();
			OpenClaims.Clear();
			_boxesAt = 0f;
			_boxesFound = false;
		}

		internal static void FindBoxes()
		{
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			if (_boxesFound || Time.time < _boxesAt || !SemiFunc.RunIsLevel())
			{
				return;
			}
			_boxesAt = Time.time + 5f;
			if ((Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated)
			{
				return;
			}
			PhysGrabHinge[] array = Object.FindObjectsOfType<PhysGrabHinge>();
			foreach (PhysGrabHinge val in array)
			{
				if ((Object)(object)val == (Object)null || BoxOf.ContainsKey(val) || (Object)(object)val.physGrabObject == (Object)null)
				{
					continue;
				}
				Transform parent = ((Component)val).transform.parent;
				if ((Object)(object)parent == (Object)null)
				{
					continue;
				}
				string name = ((Object)parent).name;
				if (NotBox.IsMatch(name) || !BoxName.IsMatch(name))
				{
					continue;
				}
				Box box = new Box
				{
					Hinge = val,
					Door = val.physGrabObject,
					Kind = KindOf(name)
				};
				bool flag = false;
				Renderer[] componentsInChildren = ((Component)parent).GetComponentsInChildren<Renderer>();
				foreach (Renderer val2 in componentsInChildren)
				{
					if (!((Object)(object)val2 == (Object)null) && (val2 is MeshRenderer || val2 is SkinnedMeshRenderer) && val2.enabled)
					{
						if (!flag)
						{
							box.Furniture = val2.bounds;
						}
						else
						{
							((Bounds)(ref box.Furniture)).Encapsulate(val2.bounds);
						}
						flag = true;
					}
				}
				if (!flag)
				{
					box.Furniture = new Bounds(val.physGrabObject.centerPoint, Vector3.one);
				}
				Boxes.Add(box);
				BoxOf[val] = box;
			}
			_boxesFound = true;
			Plugin.Log.LogInfo((object)$"Found {Boxes.Count} things that open (chests, cabinets, wardrobes...)");
		}

		private static string KindOf(string name)
		{
			string text = name.ToLowerInvariant();
			if (text.Contains("chest"))
			{
				return "chest";
			}
			if (text.Contains("wardrobe"))
			{
				return "wardrobe";
			}
			if (text.Contains("bookshel"))
			{
				return "bookshelf";
			}
			if (text.Contains("fridge"))
			{
				return "fridge";
			}
			if (text.Contains("locker"))
			{
				return "locker";
			}
			if (text.Contains("safe"))
			{
				return "safe";
			}
			if (text.Contains("cabinet"))
			{
				return "cabinet";
			}
			if (text.Contains("garbage") || Regex.IsMatch(text, "(^| )bin( |$)"))
			{
				return "trash can";
			}
			if (text.Contains("bajamaja"))
			{
				return "porta potty";
			}
			if (text.Contains("toilet"))
			{
				return "toilet";
			}
			return "cabinet";
		}

		private static bool BoxGone(Box b)
		{
			if (b != null && !((Object)(object)b.Hinge == (Object)null) && !((Object)(object)b.Door == (Object)null) && !b.Hinge.broken && !b.Hinge.dead)
			{
				return (Object)(object)b.Hinge.joint == (Object)null;
			}
			return true;
		}

		internal static float OpenAngle(Box b)
		{
			if (!((Object)(object)b.Hinge.joint != (Object)null))
			{
				return 0f;
			}
			return Mathf.Abs(b.Hinge.joint.angle);
		}

		internal static float OpenTarget(Box b)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			JointLimits limits = b.Hinge.joint.limits;
			float num = (b.Hinge.joint.useLimits ? Mathf.Max(Mathf.Abs(((JointLimits)(ref limits)).min), Mathf.Abs(((JointLimits)(ref limits)).max)) : 180f);
			HingeAnchor(b, out var axis);
			if (Mathf.Abs(axis.y) < 0.5f)
			{
				return Mathf.Max(num - 8f, Mathf.Min(num, 95f));
			}
			return Mathf.Min(75f, num * 0.7f);
		}

		internal static bool IsLid(Box b)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			HingeAnchor(b, out var axis);
			return Mathf.Abs(axis.y) < 0.5f;
		}

		private static bool LooksOpen(Box b)
		{
			return OpenAngle(b) > 30f;
		}

		private void LookForBoxes()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _boxLookAt)
			{
				return;
			}
			_boxLookAt = Time.time + 0.8f;
			FindBoxes();
			if (Boxes.Count == 0)
			{
				return;
			}
			Vector3 val = Eye();
			foreach (Box box in Boxes)
			{
				if (BoxGone(box) || _boxDone.Contains(box))
				{
					continue;
				}
				Vector3 centerPoint = box.Door.centerPoint;
				Vector3 val2 = centerPoint - val;
				if (!(((Vector3)(ref val2)).sqrMagnitude > 196f) && InView(centerPoint, 65f, 2.5f) && ClearLine(val, centerPoint, box.Door, ((Component)box.Hinge).transform.parent))
				{
					_boxSeen.Add(box);
					if (LooksOpen(box) && (!OpenClaims.TryGetValue(box, out var value) || value == this))
					{
						_boxDone.Add(box);
					}
				}
			}
		}

		private bool WantsToOpen(Box b)
		{
			float num = (float)((Name.GetHashCode() * 31 + ((Object)b.Hinge).GetInstanceID()) & 0xFFFF) / 65535f;
			float num2 = 0.45f + 0.45f * P.Greed + 0.2f * P.Careful - 0.15f * P.Social;
			if (b.Kind == "toilet" || b.Kind == "porta potty")
			{
				num2 -= 0.35f;
			}
			return num < num2;
		}

		private bool TryStartOpen()
		{
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time < _openCheckAt || !SemiFunc.RunIsLevel() || Boxes.Count == 0)
			{
				return false;
			}
			_openCheckAt = Time.time + 1f;
			if (_bot.HeldView != 0 || _bot.HoldingStatic || InDanger() || TruckTime() || _slackerRun)
			{
				return false;
			}
			Box box = null;
			float num = float.MaxValue;
			float boxRange = BoxRange;
			foreach (Box item in _boxSeen)
			{
				if (BoxGone(item) || _boxDone.Contains(item) || _boxSkip.Contains(item) || (OpenClaims.TryGetValue(item, out var value) && value != this && value != null && value._openBox == item))
				{
					continue;
				}
				if (LooksOpen(item))
				{
					_boxDone.Add(item);
					continue;
				}
				Vector3 centerPoint = item.Door.centerPoint;
				float num2 = Vector3.Distance(centerPoint, _bot.Position);
				if (!(num2 > boxRange) && SafeSpot(centerPoint))
				{
					if (!WantsToOpen(item))
					{
						_boxSkip.Add(item);
					}
					else if (num2 < num)
					{
						num = num2;
						box = item;
					}
				}
			}
			if (box == null)
			{
				return false;
			}
			StartOpen(box, asked: false);
			if (box.Kind == "toilet" || box.Kind == "porta potty")
			{
				Say(Line("opentoilet", null, null, box.Kind), 0, "opentoilet:" + _bot.Name, 120f);
			}
			else if (Random.value < 0.3f)
			{
				Say(Line("openbox", null, null, box.Kind), 0, "openbox:" + _bot.Name, 40f);
			}
			return true;
		}

		private void StartOpen(Box b, bool asked)
		{
			DropJob("StartOpen", 235);
			_job = Job.Open;
			_openBox = b;
			_openStep = OpenStep.Approach;
			_openAsked = asked;
			_openSpot = null;
			_openSpotAt = 0f;
			_openSpotTries = 0;
			_openFlips = 0;
			_openRegrabs = 0;
			_jobStarted = Time.time;
			OpenClaims[b] = this;
			_corners.Clear();
			ResetProgress();
			Plugin.Log.LogInfo((object)(_bot.Name + " is going to open a " + b.Kind + " (" + ((Object)((Component)b.Hinge).transform.parent).name + ")"));
		}

		private void StopOpen()
		{
			Box openBox = _openBox;
			_openBox = null;
			if (openBox != null)
			{
				if (OpenClaims.TryGetValue(openBox, out var value) && value == this)
				{
					OpenClaims.Remove(openBox);
				}
				if (_bot.HeldView != 0 && (Object)(object)openBox.Door != (Object)null && (Object)(object)openBox.Door.photonView != (Object)null && _bot.HeldView == openBox.Door.photonView.ViewID)
				{
					BotGrab.Release(_bot);
				}
			}
		}

		private bool OpenStillGoing()
		{
			if (_openBox != null && !BoxGone(_openBox))
			{
				return Time.time - _jobStarted < 30f;
			}
			return false;
		}

		private void FinishOpen(bool looked)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			Box openBox = _openBox;
			if (openBox != null)
			{
				_boxDone.Add(openBox);
				if (looked)
				{
					foreach (BotBrain brain in BotManager.Brains)
					{
						if (brain != null && brain != this && brain.Alive && Vector3.Distance(brain.Position, openBox.Door.centerPoint) < 10f)
						{
							brain._boxDone.Add(openBox);
						}
					}
				}
			}
			StopOpen();
			DropJob("FinishOpen", 280);
			_thinkAt = 0f;
			if (_openSweep > 0 && looked)
			{
				_openSweep--;
				Box box = NextInSweep();
				if (box != null)
				{
					int openSweep = _openSweep;
					StartOpen(box, asked: true);
					_openSweep = openSweep;
				}
				else
				{
					_openSweep = 0;
					Say(Line("opensweepdone"), 1, "opensweepdone:" + _bot.Name, 20f);
				}
			}
		}

		private Box NextInSweep()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Box result = null;
			float num = float.MaxValue;
			foreach (Box box in Boxes)
			{
				if (!BoxGone(box) && !_boxDone.Contains(box) && !LooksOpen(box) && (!OpenClaims.TryGetValue(box, out var value) || value == this || value == null || value._openBox != box))
				{
					float num2 = Vector3.Distance(box.Door.centerPoint, _openSweepAt);
					if (num2 < 10f && num2 < num)
					{
						num = num2;
						result = box;
					}
				}
			}
			return result;
		}

		internal static Vector3 HingeAnchor(Box b, out Vector3 axis)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			HingeJoint joint = b.Hinge.joint;
			Vector3 val = ((Component)joint).transform.TransformDirection(((Joint)joint).axis);
			axis = ((Vector3)(ref val)).normalized;
			return ((Component)joint).transform.TransformPoint(((Joint)joint).anchor);
		}

		private static float FromAxis(Vector3 p, Vector3 anchor, Vector3 axis)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: 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)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = p - anchor;
			Vector3 val2 = val - axis * Vector3.Dot(val, axis);
			return ((Vector3)(ref val2)).magnitude;
		}

		private Vector3? FindOpenSpot(Box b)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: 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_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			Vector3 centerPoint = b.Door.centerPoint;
			Vector3 axis;
			Vector3 anchor = HingeAnchor(b, out axis);
			float num = FromAxis(centerPoint, anchor, axis) * 2f + 0.35f;
			Vector3? result = null;
			float num2 = float.MaxValue;
			NavMeshHit val2 = default(NavMeshHit);
			for (int i = 0; i < 16; i++)
			{
				Vector3 val = Quaternion.Euler(0f, (float)i * 22.5f, 0f) * Vector3.forward;
				float[] array = new float[3] { 1.3f, 1.9f, 2.6f };
				foreach (float num3 in array)
				{
					if (!NavMesh.SamplePosition(centerPoint + val * num3, ref val2, 1.2f, -1))
					{
						continue;
					}
					Vector3 position = ((NavMeshHit)(ref val2)).position;
					if ((Mathf.Abs(position.y - _bot.Position.y) > 3f && Mathf.Abs(position.y - centerPoint.y) > 2.5f) || FromAxis(new Vector3(position.x, centerPoint.y, position.z), anchor, axis) < num)
					{
						continue;
					}
					Vector3 val3 = position + Vector3.up * 1.5f;
					Vector3 val4 = centerPoint - val3;
					if (!(((Vector3)(ref val4)).magnitude > 3.1f) && BotGrab.GrabLine(_bot, val3, centerPoint, ((Component)b.Door).transform))
					{
						Vector3 val5 = Flat(centerPoint - ((Bounds)(ref b.Furniture)).center);
						float num4;
						if (!(((Vector3)(ref val5)).sqrMagnitude > 0.01f))
						{
							num4 = 0f;
						}
						else
						{
							val4 = Flat(position - centerPoint);
							num4 = Vector3.Dot(((Vector3)(ref val4)).normalized, ((Vector3)(ref val5)).normalized);
						}
						float num5 = num4;
						float num6 = Vector3.Distance(position, _bot.Position) - num5 * 1.5f;
						if (num6 < num2)
						{
							num2 = num6;
							result = position;
						}
					}
				}
			}
			return result;
		}

		private bool PickDoorPoint(Box b, Vector3 eye, out Vector3 point, out PhysGrabObjectCollider which)
		{
			//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_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: 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_00bf: 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_00c8: 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_00d4: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: 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_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: 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_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			point = Vector3.zero;
			which = null;
			Vector3 axis;
			Vector3 val = HingeAnchor(b, out axis);
			float num = float.MinValue;
			PhysGrabObjectCollider[] componentsInChildren = ((Component)b.Door).GetComponentsInChildren<PhysGrabObjectCollider>();
			foreach (PhysGrabObjectCollider val2 in componentsInChildren)
			{
				Collider component = ((Component)val2).GetComponent<Collider>();
				if ((Object)(object)component == (Object)null || !component.enabled || component.isTrigger)
				{
					continue;
				}
				Bounds bounds = component.bounds;
				Vector3 center = ((Bounds)(ref bounds)).center;
				Vector3 val3 = center - val;
				Vector3 val4 = val3 - axis * Vector3.Dot(val3, axis);
				Vector3 val5 = component.ClosestPoint(center + val4 * 0.7f);
				Vector3[] array = (Vector3[])(object)new Vector3[4]
				{
					val5,
					Vector3.Lerp(center, val5, 0.5f),
					component.ClosestPoint(eye),
					center
				};
				foreach (Vector3 val6 in array)
				{
					Vector3 val7 = val6 - eye;
					if (!(((Vector3)(ref val7)).magnitude > 3.5f) && BotGrab.GrabLine(_bot, eye, val6, ((Component)b.Door).transform))
					{
						float num2 = FromAxis(val6, val, axis);
						val7 = val6 - eye;
						float num3 = num2 - ((Vector3)(ref val7)).magnitude * 0.2f;
						if (num3 > num)
						{
							num = num3;
							point = val6;
							which = val2;
						}
					}
				}
			}
			return (Object)(object)which != (Object)null;
		}

		internal static float OpenDirection(Box b, Vector3 grab, Vector3 eye)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0077: 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_0080: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a9: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			HingeJoint joint = b.Hinge.joint;
			JointLimits limits = joint.limits;
			if (joint.useLimits && ((JointLimits)(ref limits)).max <= 1f && ((JointLimits)(ref limits)).min < -1f)
			{
				return -1f;
			}
			if (joint.useLimits && ((JointLimits)(ref limits)).min >= -1f && ((JointLimits)(ref limits)).max > 1f)
			{
				return 1f;
			}
			Vector3 axis;
			Vector3 val = HingeAnchor(b, out axis);
			Vector3 val2 = grab - val;
			Vector3 val3 = val + Quaternion.AngleAxis(30f, axis) * val2;
			Vector3 val4 = val + Quaternion.AngleAxis(-30f, axis) * val2;
			Vector3 val5 = val3 - eye;
			float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
			val5 = val4 - eye;
			if (!(sqrMagnitude <= ((Vector3)(ref val5)).sqrMagnitude))
			{
				return -1f;
			}
			return 1f;
		}

		private int SeenInside(Box b)
		{
			//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_004a: Unknown result type (might be due to invalid IL or missing references)
			Bounds furniture = b.Furniture;
			((Bounds)(ref furniture)).Expand(0.6f);
			int num = 0;
			foreach (ValuableObject item in Seen)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.physGrabObject != (Object)null && ((Bounds)(ref furniture)).Contains(item.physGrabObject.centerPoint))
				{
					num++;
				}
			}
			return num;
		}

		private ValuableObject FirstInside(Box b)
		{
			//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_0048: Unknown result type (might be due to invalid IL or missing references)
			Bounds furniture = b.Furniture;
			((Bounds)(ref furniture)).Expand(0.6f);
			foreach (ValuableObject item in Seen)
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item.physGrabObject != (Object)null && ((Bounds)(ref furniture)).Contains(item.physGrabObject.centerPoint))
				{
					return item;
				}
			}
			return null;
		}

		private Vector3 DoOpen(out Vector3? lookAt)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_048f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f4: 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)
			//IL_0509: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_051b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0520: Unknown result type (might be due to invalid IL or missing references)
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0523: Unknown result type (might be due to invalid IL or missing references)
			//IL_0525: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0560: Unknown result type (might be due to invalid IL or missing references)
			//IL_0565: Unknown result type (might be due to invalid IL or missing references)
			//IL_0567: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: 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_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0704: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0721: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0731: Unknown result type (might be due to invalid IL or missing references)
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0714: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_06de: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05af: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_042d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_043c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0441: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			lookAt = null;
			Box openBox = _openBox;
			if (BoxGone(openBox))
			{
				FinishOpen(looked: false);
				return Vector3.zero;
			}
			Vector3 val = Eye();
			Vector3 centerPoint = openBox.Door.centerPoint;
			float num = OpenAngle(openBox);
			float time = Time.time;
			if (_openStep == OpenStep.Peek)
			{
				lookAt = ((Bounds)(ref openBox.Furniture)).center;
				if (time < _peekUntil)
				{
					return Vector3.zero;
				}
				LookForValuablesNow();
				int num2 = SeenInside(openBox) - _peekBefore;
				Plugin.Log.LogInfo((object)(_bot.Name + " looked in the " + openBox.Kind + ": " + ((num2 > 0) ? (num2 + " things") : "empty")));
				BotSave.Add(_bot.SteamId, "opened");
				if (num2 > 0)
				{
					BotSave.Add(_bot.SteamId, "found");
				}
				if (num2 > 0)
				{
					ValuableObject obj = FirstInside(openBox);
					Say(Line("openfound", null, null, openBox.Kind), 1, "openfound:" + _bot.Name, 15f);
					if ((Object)(object)obj != (Object)null)
					{
						_thinkAt = 0f;
					}
				}
				else if (_openAsked || Random.value < 0.35f)
				{
					Say(Line("openempty", null, null, openBox.Kind), _openAsked ? 1 : 0, "openempty:" + _bot.Name, _openAsked ? 5f : 45f);
				}
				FinishOpen(looked: true);
				return Vector3.zero;
			}
			if (_openStep == OpenStep.Pull)
			{
				int num3 = (((Object)(object)openBox.Door.photonView != (Object)null) ? openBox.Door.photonView.ViewID : 0);
				if (_bot.HeldView != num3 || num3 == 0)
				{
					_openStep = OpenStep.Approach;
					_openRegrabs++;
					return Vector3.zero;
				}
				lookAt = ((Component)openBox.Door).transform.TransformPoint(_openLocal);
				if (num >= OpenTarget(openBox))
				{
					BeginPeek(openBox);
					return Vector3.zero;
				}
				if (num > _openBest + 3f)
				{
					_openBest = num;
					_openProgressAt = time;
				}
				else
				{
					if (time - _openProgressAt > 0.9f && num >= 45f && !IsLid(openBox))
					{
						BeginPeek(openBox);
						return Vector3.zero;
					}
					if (time - _openProgressAt > 0.9f)
					{
						_openSign = 0f - _openSign;
						_openFlips++;
						_openProgressAt = time;
						if (_openFlips > 3)
						{
							Plugin.Log.LogInfo((object)(_bot.Name + " couldn't get the " + openBox.Kind + " open"));
							BotGrab.Release(_bot);
							Say(Line("openstuck", null, null, openBox.Kind), _openAsked ? 1 : 0, "openstuck:" + _bot.Name);
							FinishOpen(looked: false);
							return Vector3.zero;
						}
					}
				}
				Vector3 axis;
				Vector3 anchor = HingeAnchor(openBox, out axis);
				float num4 = FromAxis(centerPoint, anchor, axis) * 2f + 0.2f;
				if (FromAxis(new Vector3(_bot.Position.x, centerPoint.y, _bot.Position.z), anchor, axis) < num4)
				{
					Vector3 val2 = Flat(_bot.Position - centerPoint);
					return ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val2)).normalized : (-Flat(Quaternion.Euler(0f, _bot.Yaw, 0f) * Vector3.forward))) * 1.2f;
				}
				return Vector3.zero;
			}
			lookAt = centerPoint;
			if (LooksOpen(openBox) && (!OpenClaims.TryGetValue(openBox, out var value) || value == this))
			{
				BeginPeek(openBox);
				return Vector3.zero;
			}
			if (time - _jobStarted > 20f || _openRegrabs > 3)
			{
				Plugin.Log.LogInfo((object)(_bot.Name + " gave up on the " + openBox.Kind));
				_boxSkip.Add(openBox);
				FinishOpen(looked: false);
				return Vector3.zero;
			}
			Vector3 val3 = centerPoint - val;
			if (((Vector3)(ref val3)).magnitude < 3.2f && PickDoorPoint(openBox, val, out var point, out var which))
			{
				Vector3 axis2;
				Vector3 anchor2 = HingeAnchor(openBox, out axis2);
				float num5 = FromAxis(centerPoint, anchor2, axis2) * 2f + 0.1f;
				if ((FromAxis(new Vector3(_bot.Position.x, centerPoint.y, _bot.Position.z), anchor2, axis2) >= num5 || _openSpotTries >= 2) && BotGrab.GrabAt(_bot, openBox.Door, point, which))
				{
					_openLocal = ((Component)openBox.Door).transform.InverseTransformPoint(point);
					_openSign = OpenDirection(openBox, point, val);
					_openBest = num;
					_openProgressAt = time;
					_openStep = OpenStep.Pull;
					Plugin.Log.LogInfo((object)(_bot.Name + " grabbed the " + openBox.Kind + " door"));
					return Vector3.zero;
				}
			}
			if (!_openSpot.HasValue || time - _openSpotAt > 4f)
			{
				_openSpot = FindOpenSpot(openBox);
				_openSpotAt = time;
				_openSpotTries++;
				if (!_openSpot.HasValue)
				{
					if (_openSpotTries > 2)
					{
						Plugin.Log.LogInfo((object)(_bot.Name + " can't get to the " + openBox.Kind));
						_boxSkip.Add(openBox);
						if (_openAsked)
						{
							Say(Line("cantreach"), 1);
						}
						FinishOpen(looked: false);
						return Vector3.zero;
					}
					return Steer(_bot.Position, centerPoint) * 3.2f;
				}
			}
			val3 = Flat(_openSpot.Value - _bot.Position);
			if (((Vector3)(ref val3)).magnitude < 0.35f)
			{
				return Vector3.zero;
			}
			return Steer(_bot.Position, _openSpot.Value) * 3.2f;
		}

		private void LookForValuablesNow()
		{
			_seeAt = 0f;
			LookForValuables();
		}

		private void BeginPeek(Box b)
		{
			_openStep = OpenStep.Peek;
			_peekUntil = Time.time + Mathf.Lerp(0.7f, 1.6f, P.Careful) * Random.Range(0.85f, 1.2f);
			_peekBefore = SeenInside(b);
		}

		private void OpenPuller()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: 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_009d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			Box openBox = _openBox;
			if (!BoxGone(openBox))
			{
				if (_openStep == OpenStep.Peek)
				{
					_bot.Puller = ((Component)openBox.Door).transform.TransformPoint(_openLocal);
				}
				else if (_openStep == OpenStep.Pull)
				{
					Vector3 axis;
					Vector3 val = HingeAnchor(openBox, out axis);
					Vector3 val2 = ((Component)openBox.Door).transform.TransformPoint(_openLocal);
					Vector3 val3 = val + Quaternion.AngleAxis(_openSign * 35f, axis) * (val2 - val);
					Vector3 val4 = Eye();
					_bot.Puller = val4 + Vector3.ClampMagnitude(val3 - val4, 4f);
				}
			}
		}

		public void OrderOpen(PlayerAvatar by, PhysGrabObject looked, bool all)
		{
			//IL_007e: 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_0083: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			if (!Alive)
			{
				return;
			}
			FindBoxes();
			HeardFrom(by);
			Box value = null;
			if ((Object)(object)looked != (Object)null)
			{
				PhysGrabHinge component = ((Component)looked).GetComponent<PhysGrabHinge>();
				if ((Object)(object)component != (Object)null && !BoxOf.TryGetValue(component, out value))
				{
					Say(Line("opendoor"), 3);
					return;
				}
			}
			Vector3 val = (((Object)(object)by != (Object)null) ? ((Component)by).transform.position : _bot.Position);
			if (value == null)
			{
				float num = float.MaxValue;
				Vector3 val2 = (((Object)(object)by != (Object)null) ? Flat(((Component)by).transform.forward) : Vector3.zero);
				foreach (Box box in Boxes)
				{
					if (BoxGone(box) || LooksOpen(box))
					{
						continue;
					}
					Vector3 centerPoint = box.Door.centerPoint;
					float num2 = Vector3.Distance(centerPoint, val);
					if (!(num2 > 10f))
					{
						Vector3 val3 = Flat(centerPoint - val);
						float num3 = num2 - Vector3.Dot(((Vector3)(ref val3)).normalized, val2) * 2f;
						if (num3 < num)
						{
							num = num3;
							value = box;
						}
					}
				}
			}
			if (value == null)
			{
				Say(Line("opennone"), 3);
				return;
			}
			ClearOrder(say: false);
			if (OpenClaims.TryGetValue(value, out var value2) && value2 != this && value2 != null && value2._openBox == value)
			{
				value2.DropJob("OrderOpen", 685);
			}
			_boxSeen.Add(value);
			_boxDone.Remove(value);
			_boxSkip.Remove(value);
			StartOpen(value, asked: true);
			_openSweep = (all ? 6 : 0);
			_openSweepAt = val;
			Say(Ack(Line(all ? "ackopenall" : "ackopen", null, null, value.Kind)), 3);
		}

		public BotBrain(BotInfo bot)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			_bot = bot;
			_followDist = 2.2f + (float)(bot.Index % 3) * 0.6f;
			_sideBias = ((bot.Index % 2 == 0) ? 1f : (-1f)) * (0.8f + 0.3f * (float)(bot.Index / 2));
			_progressPos = bot.Position;
			_progressAt = Time.time;
			_thinkAt = Time.time + 0.2f * (float)bot.Index;
			if (SemiFunc.RunIsLevel())
			{
				BotSave.Add(bot.SteamId, "levels");
			}
		}

		public static void ResetLevel()
		{
			Claims.Clear();
			Blacklist.Clear();
			HumanHeldAt.Clear();
			ResetMemoryStatics();
			Fails.Clear();
			ResetTeamStatics();
			ResetCartStatics();
			ResetTalkStatics();
			ResetBoxStatics();
			DoorClaims.Clear();
			_activator = null;
			BotThreats.ResetLevel();
			BotSenses.ResetLevel();
		}

		public void Forget()
		{
			DropJob("Forget", 173);
		}

		public void Shove(Vector3 force)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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)
			if ((Object)(object)_body != (Object)null && (Object)(object)_body.Rb != (Object)null && !_body.Rb.isKinematic)
			{
				_body.Rb.AddForce(force, (ForceMode)2);
				return;
			}
			BotInfo bot = _bot;
			bot.Velocity += force;
		}

		public void Tick(float dt)
		{
			//IL_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0335: Unknown result type (might be due to invalid IL or missing references)
			//IL_0351: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_037e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0395: Unknown result type (might be due to invalid IL or missing references)
			//IL_039a: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0431: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0437: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0489: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_0508: Unknown result type (might be due to invalid IL or missing references)
			//IL_050d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_056c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Unknown result type (might be due to invalid IL or missing references)
			//IL_053b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0540: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_054a: Unknown result type (might be due to invalid IL or missing references)
			//IL_057f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0585: Unknown result type (might be due to invalid IL or missing references)
			//IL_058a: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0718: Unknown result type (might be due to invalid IL or missing references)
			//IL_071d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0722: Unknown result type (might be due to invalid IL or missing references)
			//IL_0724: Unknown result type (might be due to invalid IL or missing references)
			//IL_0726: Unknown result type (might be due to invalid IL or missing references)
			//IL_072e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0733: Unknown result type (might be due to invalid IL or missing references)
			//IL_073b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Unknown result type (might be due to invalid IL or missing references)
			//IL_0748: Unknown result type (might be due to invalid IL or missing references)
			//IL_074d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0752: Unknown result type (might be due to invalid IL or missing references)
			//IL_0755: Unknown result type (might be due to invalid IL or missing references)
			//IL_0757: Unknown result type (might be due to invalid IL or missing references)
			//IL_0759: Unknown result type (might be due to invalid IL or missing references)
			//IL_075e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0760: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_0764: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_0779: Unknown result type (might be due to invalid IL or missing references)
			//IL_077e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0780: Unknown result type (might be due to invalid IL or missing references)
			//IL_0787: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_078f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0790: Unknown result type (might be due to invalid IL or missing references)
			//IL_079d: Unknown result type (might be due to invalid IL or missing references)
			//IL_079f: Unknown result type (might be due to invalid IL or missing references)
			//IL_07aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0625: Unknown result type (might be due to invalid IL or missing references)
			//IL_0649: Unknown result type (might be due to invalid IL or missing references)
			//IL_0605: Unknown result type (might be due to invalid IL or missing references)
			//IL_060c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0611: Unknown result type (might be due to invalid IL or missing references)
			//IL_0669: Unknown result type (might be due to invalid IL or missing references)
			//IL_066e: Unknown result type (might be due to invalid IL or missing references)
			//IL_067b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0680: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_0688: Unknown result type (might be due to invalid IL or missing references)
			//IL_0689: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_09e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_09de: Unknown result type (might be due to invalid IL or missing references)
			//IL_08fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0904: Unknown result type (might be due to invalid IL or missing references)
			//IL_0915: Unknown result type (might be due to invalid IL or missing references)
			//IL_0917: Unknown result type (might be due to invalid IL or missing references)
			//IL_091c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0933: Unknown result type (might be due to invalid IL or missing references)
			//IL_093a: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar avatar = _bot.Avatar;
			if ((Object)(object)avatar == (Object)null)
			{
				return;
			}
			TalkTick();
			if (avatar.isDisabled || avatar.deadSet)
			{
				if (!_wasDisabled)
				{
					BotSave.Add(_bot.SteamId, "deaths");
					ClearOrder(say: false);
					PutMapAway(finished: false);
					_body?.SetActive(active: false);
					DropJob("Tick", 198);
					_bot.Velocity = Vector3.zero;
					_bot.Moving = false;
					_bot.Sprinting = false;
					_bot.Crouching = false;
				}
				_wasDisabled = true;
				return;
			}
			if (_wasDisabled)
			{
				_wasDisabled = false;
				BotHealth.Heal(avatar.playerHealth, 1, effect: true);
				BotSave.Add(_bot.SteamId, "revived");
				Plugin.Log.LogInfo((object)(_bot.Name + " is back on their feet"));
				OnRevived();
				_bot.Position = ((Component)avatar).transform.position;
				_bot.Velocity = Vector3.zero;
				if ((Object)(object)_body != (Object)null)
				{
					_body.Teleport(_bot.Position);
					_body.SetActive(active: true);
				}
				ResetProgress();
				_corners.Clear();
			}
			PlayerTumble tumble = avatar.tumble;
			if ((Object)(object)tumble != (Object)null && tumble.isTumbling)
			{
				WhileTumbling(tumble);
				return;
			}
			if (_wasTumbling)
			{
				_wasTumbling = false;
				Vector3 val = (((Object)(object)tumble != (Object)null) ? (((Component)tumble).transform.position - Vector3.up * 0.3f) : ((Component)avatar).transform.position);
				_bot.Position = SnapToGround(val, val);
				_bot.Velocity = Vector3.zero;
				if ((Object)(object)_body != (Object)null)
				{
					_body.Teleport(_bot.Position);
					_body.SetActive(active: true);
				}
				_corners.Clear();
				ResetProgress();
			}
			UpdateMemory();
			LookForValuables();
			LookForBoxes();
			if (Time.time >= _thinkAt)
			{
				_thinkAt = Time.time + 0.4f;
				if (!OpeningDoor)
				{
					Think();
				}
				else if (Plugin.BotsFlee.Value)
				{
					Job job = _job;
					if (AssessDanger() && _job != job && OpeningDoor)
					{
						EndDoor(opened: true);
					}
				}
			}
			Vector3? lookAt = null;
			bool crawl = false;
			bool sprint = false;
			bool crouch = false;
			Vector3 desired;
			switch (_job)
			{
			case Job.Freeze:
				desired = DoFreeze(out crawl);
				crouch = true;
				break;
			case Job.Flee:
				desired = DoFlee(out sprint);
				break;
			case Job.Hide:
				desired = DoHide(out crouch, out lookAt);
				break;
			case Job.Revive:
			case Job.Haul:
				desired = DoCarry(out lookAt);
				break;
			case Job.Cart:
				desired = DoCart(out lookAt);
				break;
			case Job.Activate:
				desired = DoActivate();
				break;
			case Job.Explore:
				desired = DoExplore();
				break;
			case Job.Truck:
				desired = DoTruck(out sprint, out lookAt);
				break;
			case Job.Assist:
				desired = DoAssist(out lookAt);
				break;
			case Job.Escort:
				desired = DoEscort(out sprint, out lookAt);
				break;
			case Job.Guard:
				desired = DoGuard(out lookAt);
				break;
			case Job.Heal:
				desired = DoHeal(out lookAt);
				break;
			case Job.Open:
				desired = DoOpen(out lookAt);
				break;
			case Job.HangOut:
				desired = DoHangOut(out lookAt);
				break;
			case Job.Gnome:
				desired = DoGnome(out lookAt);
				break;
			case Job.Use:
				desired = DoUse(out lookAt);
				break;
			case Job.Order:
				desired = DoOrder(out sprint, out lookAt);
				_orderMoving = ((Vector3)(ref desired)).sqrMagnitude > 0.01f;
				break;
			default:
				desired = DoFollow(out sprint);
				break;
			}
			EscapingZone(ref desired, ref sprint);
			Vector3 val2 = Flat(desired);
			_jobWantsToMove = ((Vector3)(ref val2)).magnitude > 0.3f;
			if (Time.time < _listenUntil)
			{
				desired = Vector3.zero;
			}
			float num = MapTick();
			if (num < 1f)
			{
				desired *= num;
				sprint = false;
			}
			if (Typing)
			{
				desired = Vector3.zero;
				sprint = false;
				lookAt = Eye() + Quaternion.Euler(_bot.Pitch, _bot.Yaw, 0f) * Vector3.forward * 5f;
			}
			if (_quiet && _job != Job.Freeze)
			{
				sprint = false;
				crouch = true;
				desired = Vector3.ClampMagnitude(desired, 1.6f);
			}
			desired += Separation(_bot.Position);
			if (Time.time < _grabCrouchUntil)
			{
				crouch = true;
			}
			int num2;
			if (_job == Job.Hide && _hideUnder)
			{
				val2 = Flat(_hideSpot - _bot.Position);
				if (((Vector3)(ref val2)).magnitude < 1.6f)
				{
					num2 = 1;
					goto IL_0569;
				}
			}
			num2 = ((_job == Job.Freeze && crawl) ? 1 : 0);
			goto IL_0569;
			IL_0569:
			bool wantCrawl = (byte)num2 != 0;
			UpdatePosture(desired, crouch, wantCrawl);
			if (_posture == 2)
			{
				desired = Vector3.ClampMagnitude(desired, 0.9f);
			}
			else if (_posture == 1)
			{
				desired = Vector3.ClampMagnitude(desired, 1.6f);
			}
			Vector3 val3 = desired;
			if (DoorTick(val3, ref desired, ref lookAt))
			{
				val3 = desired;
				sprint = false;
			}
			if (Plugin.KeyboardMouse.Value)
			{
				desired = Keys(desired, sprint);
			}
			Vector3 val5;
			if (Plugin.RealPhysics.Value && (Object)(object)Body() != (Object)null)
			{
				Vector3 val4 = EscapeFromCart();
				if (val4 != Vector3.zero)
				{
					desired = val4 * 3.2f;
					_body.WantJump = true;
				}
				_body.WantVelocity = desired;
				_body.WantSprint = sprint;
				_body.Posture = _posture;
				if (ShouldJump(desired))
				{
					_body.WantJump = true;
				}
				SyncBodyIgnores();
				Vector3 feet = _body.Feet;
				val5 = Flat(_body.Rb.velocity);
				CheckBlocked(desired, val5);
				_bot.Velocity = _body.Rb.velocity;
				_bot.Position = feet;
				_bot.Moving = ((Vector3)(ref val5)).sqrMagnitude > 0.2f;
				_bot.Sprinting = _body.Sprinting && _bot.Moving;
				_bot.Grounded = _body.Grounded;
			}
			else
			{
				val5 = Flat(_bot.Velocity);
				val5 = Vector3.MoveTowards(val5, desired, 18f * dt);
				Vector3 position = _bot.Position;
				Vector3 p = MoveWithCollision(position, val5 *