Decompiled source of Librarian v1.0.0

Bibliothecaire.dll

Decompiled 37 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("PhotonUnityNetworking")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public string AssemblyName { get; }

		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
			AssemblyName = assemblyName;
		}
	}
}
namespace Bibliothecaire
{
	public class BiblioAI : MonoBehaviour
	{
		public enum State
		{
			Spawn,
			Patrol,
			Idle,
			Warn,
			Alert,
			Charge,
			Gag,
			Recover,
			Tidy,
			PickUp,
			Dazed,
			Refuse
		}

		private Enemy enemy;

		private PhotonView photonView;

		private EnemyHealth health;

		private EnemyRigidbody erb;

		private Transform visuals;

		private Transform model;

		private Transform particles;

		private Transform handleL;

		private Transform handleR;

		private Transform mouth;

		private readonly Transform[] slots = (Transform[])(object)new Transform[3];

		private readonly Dictionary<string, Transform> J = new Dictionary<string, Transform>();

		private readonly Dictionary<string, Vector3> restPos = new Dictionary<string, Vector3>();

		private Renderer headR;

		private Renderer bookR;

		private Light eyeLight;

		private int eyeMat = -1;

		private MaterialPropertyBlock eyeMpb;

		private static readonly int EmissionId = Shader.PropertyToID("_EmissionColor");

		private static readonly Color EyeCalm = new Color(0.45f, 1.9f, 1.7f);

		private static readonly Color EyeAngry = new Color(2.4f, 0.25f, 0.2f);

		private bool ready;

		public State state;

		private bool stateImpulse = true;

		private float stateTimer;

		private float stateTime;

		private PlayerAvatar target;

		private Vector3 soundPos;

		private bool hasSoundPos;

		private float pathTimer;

		private float warnUntil;

		private float busyUntil;

		private float lastTargetLoud;

		private float dazeCooldown;

		private bool hitDone;

		private bool pickDone;

		private PhysGrabObject tidyItem;

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

		private const int MaxCart = 8;

		private readonly PhysGrabObject[] cart = (PhysGrabObject[])(object)new PhysGrabObject[8];

		private readonly float[] cartSize = new float[8];

		private readonly float[] cartLift = new float[8];

		private readonly float[] cartTall = new float[8];

		private readonly float[] cartFar = new float[8];

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

		private Vector3 patrolDest;

		private bool hasPatrolDest;

		private float loudTime;

		private float reportCooldown;

		private float airTime;

		private float landNoise;

		private float grabTime;

		private float angryLose;

		private float angryEnd;

		private bool angry;

		private bool gaggedOnce;

		private Vector3 angryLastSeen;

		private float t;

		private float walkPhase;

		private float bodySpeed;

		private float wheelAngle;

		private float distAcc;

		private float stepAcc;

		private float neckExt;

		private float eyeGlow = 1f;

		private float trumpetYaw;

		private float headYaw;

		private float headPitch;

		private Vector3 lastVisPos;

		private Color eyeColor = new Color(0.45f, 1.9f, 1.7f);

		internal static float SkipTeleportUntil;

		internal static readonly List<BiblioAI> All = new List<BiblioAI>();

		private readonly Dictionary<string, Vector3> pose = new Dictionary<string, Vector3>();

		private static bool MP => GameManager.Multiplayer();

		private static bool Master => SemiFunc.IsMasterClientOrSingleplayer();

		internal static BiblioAI Existing()
		{
			All.RemoveAll((BiblioAI a) => (Object)(object)a == (Object)null);
			if (All.Count <= 0)
			{
				return null;
			}
			return All[0];
		}

		private void Awake()
		{
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Expected O, but got Unknown
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bc: Expected O, but got Unknown
			enemy = ((Component)this).GetComponent<Enemy>();
			photonView = ((Component)this).GetComponent<PhotonView>();
			health = ((Component)this).GetComponent<EnemyHealth>();
			Transform parent = ((Component)this).transform.parent;
			erb = ((Component)parent.Find("Rigidbody")).GetComponent<EnemyRigidbody>();
			visuals = parent.Find("Visuals");
			model = (Object.op_Implicit((Object)(object)visuals) ? visuals.Find("BiblioModel") : null);
			particles = parent.parent.Find("Particles");
			if (Object.op_Implicit((Object)(object)model))
			{
				Transform[] componentsInChildren = ((Component)model).GetComponentsInChildren<Transform>(true);
				foreach (Transform val in componentsInChildren)
				{
					if (Array.IndexOf(ModelLayout.Parts, ((Object)val).name) >= 0)
					{
						J[((Object)val).name] = val;
						restPos[((Object)val).name] = val.localPosition;
					}
					if (((Object)val).name == "HandleL")
					{
						handleL = val;
					}
					if (((Object)val).name == "HandleR")
					{
						handleR = val;
					}
					if (((Object)val).name == "Mouth")
					{
						mouth = val;
					}
					if (((Object)val).name.StartsWith("Slot") && int.TryParse(((Object)val).name.Substring(4), out var result) && result < 3)
					{
						slots[result] = val;
					}
					if (((Object)val).name == "EyeLight")
					{
						eyeLight = ((Component)val).GetComponent<Light>();
					}
				}
			}
			if (J.TryGetValue("head", out var value))
			{
				headR = ((Component)value).GetComponent<Renderer>();
				Material[] sharedMaterials = headR.sharedMaterials;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					if (Object.op_Implicit((Object)(object)sharedMaterials[j]) && ((Object)sharedMaterials[j]).name.StartsWith("Biblio Eye"))
					{
						eyeMat = j;
					}
				}
			}
			if (J.TryGetValue("book", out var value2))
			{
				bookR = ((Component)value2).GetComponent<Renderer>();
			}
			eyeMpb = new MaterialPropertyBlock();
			EnemyStateSpawn component = ((Component)this).GetComponent<EnemyStateSpawn>();
			if (Object.op_Implicit((Object)(object)component))
			{
				component.OnSpawn.AddListener(new UnityAction(OnSpawn));
			}
			if (Object.op_Implicit((Object)(object)health))
			{
				health.onHurt.AddListener(new UnityAction(OnHurt));
				health.onDeath.AddListener(new UnityAction(OnDeath));
			}
			ready = Object.op_Implicit((Object)(object)model) && Object.op_Implicit((Object)(object)erb) && J.Count >= 22 && Object.op_Implicit((Object)(object)handleL) && Object.op_Implicit((Object)(object)handleR) && Object.op_Implicit((Object)(object)mouth) && Object.op_Implicit((Object)(object)slots[0]);
			if (!ready)
			{
				Plugin.Log.LogError((object)"BiblioAI: hierarchy incomplete, behaviour disabled.");
			}
			All.Add(this);
		}

		private void OnDestroy()
		{
			All.Remove(this);
		}

		private void OnEnable()
		{
			//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)
			if (Object.op_Implicit((Object)(object)erb))
			{
				lastVisPos = ((Component)erb).transform.position;
			}
		}

		private void OnDisable()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (!Master)
			{
				return;
			}
			for (int i = 0; i < cart.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)cart[i]))
				{
					DropFromCart(i, Vector3.zero);
				}
			}
		}

		private void Update()
		{
			if (ready)
			{
				float deltaTime = Time.deltaTime;
				t += deltaTime;
				HearingTick(deltaTime);
				if (Master)
				{
					MasterLogic(deltaTime);
				}
			}
		}

		private void LateUpdate()
		{
			//IL_001a: 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)
			if (ready)
			{
				visuals.position = ((Component)erb).transform.position;
				visuals.rotation = ((Component)erb).transform.rotation;
				Animate(Time.deltaTime);
			}
		}

		private void FixedUpdate()
		{
			//IL_0075: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			if (!ready || !Master)
			{
				return;
			}
			float fixedDeltaTime = Time.fixedDeltaTime;
			for (int i = 0; i < cart.Length; i++)
			{
				PhysGrabObject val = cart[i];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				if (val.playerGrabbing.Count > 0 || !((Component)val).gameObject.activeInHierarchy)
				{
					cart[i] = null;
					Shrink(val, on: false);
					Protect(val);
				}
				else if (Object.op_Implicit((Object)(object)slots[1]) && Vector3.Distance(val.midPoint, slots[1].position) > 3.5f)
				{
					if ((cartFar[i] += fixedDeltaTime) > 1f)
					{
						cartFar[i] = 0f;
						cart[i] = null;
						Shrink(val, on: false);
						Protect(val);
					}
				}
				else
				{
					cartFar[i] = 0f;
				}
			}
			CartLayout(fixedDeltaTime);
			Rigidbody rb = erb.rb;
			if (Object.op_Implicit((Object)(object)rb) && !rb.isKinematic && !enemy.IsStunned() && erb.physGrabObject.playerGrabbing.Count == 0)
			{
				Vector3 val2 = Vector3.Cross(((Component)rb).transform.up, Vector3.up);
				Vector3 angularVelocity = rb.angularVelocity;
				rb.AddTorque(val2 * 60f - new Vector3(angularVelocity.x, 0f, angularVelocity.z) * 10f, (ForceMode)5);
			}
		}

		internal static float AmpToDb(float amp)
		{
			if (!(amp <= 1E-06f))
			{
				return 60f + 20f * Mathf.Log10(amp / 0.025f);
			}
			return 0f;
		}

		private void HearingTick(float dt)
		{
			//IL_0053: 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_00d8: 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_012a: Unknown result type (might be due to invalid IL or missing references)
			if (reportCooldown > 0f)
			{
				reportCooldown -= dt;
			}
			PlayerAvatar val = SemiFunc.PlayerAvatarLocal();
			if (!Object.op_Implicit((Object)(object)val) || val.isDisabled || val.deadSet || state == State.Spawn)
			{
				loudTime = 0f;
				return;
			}
			if (Vector3.Distance(((Component)val).transform.position, ((Component)erb).transform.position) > Plugin.CfgHearingRange.Value)
			{
				loudTime = 0f;
				return;
			}
			float num = 0f;
			PlayerVoiceChat val2 = (Object.op_Implicit((Object)(object)val.voiceChat) ? val.voiceChat : PlayerVoiceChat.instance);
			if (Object.op_Implicit((Object)(object)val2) && val2.overrideMuteTimer <= 0f)
			{
				num = AmpToDb(val2.clipLoudnessNoTTS);
			}
			if (Plugin.CfgDebugSpawn.Value && Input.GetKey(Plugin.CfgDebugShoutKey.Value))
			{
				num = Mathf.Max(num, 70f);
			}
			PlayerController instance;
			float num2;
			int num3;
			if (Plugin.CfgFootsteps.Value && Object.op_Implicit((Object)(object)PlayerController.instance))
			{
				instance = PlayerController.instance;
				num2 = Vector3.Distance(((Component)val).transform.position, ((Component)erb).transform.position);
				if (Object.op_Implicit((Object)(object)PlayerCollisionGrounded.instance))
				{
					num3 = (PlayerCollisionGrounded.instance.Grounded ? 1 : 0);
					if (num3 == 0)
					{
						airTime += dt;
						goto IL_0193;
					}
				}
				else
				{
					num3 = 1;
				}
				if (airTime > 0.35f && num2 <= Plugin.CfgLandRange.Value)
				{
					landNoise = 0.5f;
				}
				airTime = 0f;
				goto IL_0193;
			}
			goto IL_01ee;
			IL_0193:
			if (landNoise > 0f)
			{
				landNoise -= dt;
				num = Mathf.Max(num, 68f);
			}
			if (num3 != 0 && instance.sprinting && instance.moving && !instance.Crouching && num2 <= Plugin.CfgSprintRange.Value)
			{
				num = Mathf.Max(num, 64f);
			}
			goto IL_01ee;
			IL_01ee:
			if (num >= Plugin.CfgThresholdDb.Value)
			{
				loudTime += dt;
			}
			else
			{
				loudTime = Mathf.Max(0f, loudTime - dt * 2f);
			}
			if (loudTime >= 0.2f && reportCooldown <= 0f)
			{
				reportCooldown = 0.6f;
				int num4 = Mathf.RoundToInt(num);
				if (MP)
				{
					photonView.RPC("BiblioLoudRPC", (RpcTarget)2, new object[1] { num4 });
				}
				else
				{
					OnLoud(val, num4);
				}
			}
		}

		[PunRPC]
		private void BiblioLoudRPC(int db, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0007: 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)
			if (Master && info.Sender != null)
			{
				PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonPlayer(info.Sender);
				if (Object.op_Implicit((Object)(object)val))
				{
					OnLoud(val, db);
				}
			}
		}

		private void OnLoud(PlayerAvatar p, int db)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (!ValidPlayer(p) || !ready || state == State.Spawn || state == State.Gag || state == State.Recover || state == State.Dazed || enemy.IsStunned() || (Time.time < busyUntil && (state == State.Tidy || state == State.PickUp || state == State.Refuse)))
			{
				return;
			}
			int viewID = p.photonView.ViewID;
			if (state == State.Charge)
			{
				if ((Object)(object)p == (Object)(object)target)
				{
					lastTargetLoud = Time.time;
				}
				return;
			}
			Plugin.Log.LogInfo((object)$"[Bibliothecaire] {p.playerName} too loud ({db} dB)");
			soundPos = ((Component)p).transform.position + Vector3.up;
			hasSoundPos = true;
			if (lastWarn.TryGetValue(viewID, out var value) && Time.time - value <= Plugin.CfgWarningWindow.Value && Time.time - value > 2f)
			{
				target = p;
				lastTargetLoud = Time.time;
				SetState(State.Charge);
			}
			else if (!lastWarn.TryGetValue(viewID, out value) || !(Time.time - value <= 2f))
			{
				lastWarn[viewID] = Time.time;
				target = p;
				if (state == State.Warn || state == State.Alert)
				{
					ApplyState(State.Warn);
					SyncState();
				}
				else
				{
					SetState(State.Warn);
				}
			}
		}

		private void MasterLogic(float dt)
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: 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_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0957: Unknown result type (might be due to invalid IL or missing references)
			//IL_095d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0514: Unknown result type (might be due to invalid IL or missing references)
			//IL_052c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0576: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_058b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_072f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0734: Unknown result type (might be due to invalid IL or missing references)
			//IL_0747: Unknown result type (might be due to invalid IL or missing references)
			//IL_0771: Unknown result type (might be due to invalid IL or missing references)
			//IL_0781: Unknown result type (might be due to invalid IL or missing references)
			//IL_0786: Unknown result type (might be due to invalid IL or missing references)
			//IL_078b: 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_05b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: 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_07a5: 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_07b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_07be: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//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_081e: Unknown result type (might be due to invalid IL or missing references)
			//IL_082d: Unknown result type (might be due to invalid IL or missing references)
			//IL_083c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0417: Unknown result type (might be due to invalid IL or missing references)
			//IL_041c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			if (dazeCooldown > 0f)
			{
				dazeCooldown -= dt;
			}
			stateTime += dt;
			if (enemy.IsStunned() && state != State.Dazed)
			{
				SetState(State.Dazed);
			}
			GrabTick(dt);
			AngerTick(dt);
			Face(dt);
			Vector3 val;
			switch (state)
			{
			case State.Spawn:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1.5f;
				}
				Halt();
				if ((stateTimer -= dt) <= 0f)
				{
					SetState(State.Patrol);
				}
				break;
			case State.Patrol:
				if (stateImpulse)
				{
					stateImpulse = false;
					hasPatrolDest = false;
				}
				if (hasPatrolDest)
				{
					val = Flat(patrolDest - ((Component)erb).transform.position);
					if (!(((Vector3)(ref val)).magnitude < 1.2f))
					{
						goto IL_0176;
					}
				}
				if (hasPatrolDest)
				{
					SetState(State.Idle);
					break;
				}
				hasPatrolDest = Plugin.TryQuietPoint(((Component)erb).transform.position, 6f, 35f, out patrolDest);
				if (!hasPatrolDest)
				{
					SetState(State.Idle);
					break;
				}
				goto IL_0176;
			case State.Idle:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = Random.Range(2f, 5f);
				}
				Halt();
				if ((stateTimer -= dt) <= 0f)
				{
					SetState(State.Patrol);
				}
				break;
			case State.Warn:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1.8f;
					if (MP)
					{
						photonView.RPC("BiblioChutRPC", (RpcTarget)0, new object[1] { false });
					}
					else
					{
						BiblioChutRPC(angry: false);
					}
				}
				Halt();
				if ((stateTimer -= dt) <= 0f)
				{
					warnUntil = Time.time + Mathf.Max(0f, Plugin.CfgWarningWindow.Value - 1.8f);
					SetState(State.Alert);
				}
				break;
			case State.Alert:
				if (stateImpulse)
				{
					stateImpulse = false;
				}
				Halt();
				if (Time.time > warnUntil)
				{
					SetState(State.Patrol);
				}
				break;
			case State.Charge:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 20f;
					if (!angry || !gaggedOnce)
					{
						if (MP)
						{
							photonView.RPC("BiblioChutRPC", (RpcTarget)0, new object[1] { true });
						}
						else
						{
							BiblioChutRPC(angry: true);
						}
					}
				}
				if (angry)
				{
					if (!ValidPlayer(target))
					{
						EndAnger("target gone");
						break;
					}
					lastTargetLoud = Time.time;
					bool flag = angryLose <= 0f;
					float num = (gaggedOnce ? Plugin.CfgAngrySpeed.Value : Plugin.CfgChargeSpeed.Value);
					soundPos = (flag ? ((Component)target).transform.position : angryLastSeen) + Vector3.up;
					hasSoundPos = true;
					GoTo(flag ? ((Component)target).transform.position : angryLastSeen, num, dt, 0.2f);
					if (!gaggedOnce)
					{
						erb.OverrideFollowPosition(0.3f, num + 2f, -1f);
					}
					if (flag)
					{
						val = Flat(((Component)target).transform.position - ((Component)erb).transform.position);
						if (((Vector3)(ref val)).magnitude < 1.5f && Mathf.Abs(((Component)target).transform.position.y - ((Component)erb).transform.position.y) < 2f)
						{
							SetState(State.Gag);
						}
					}
				}
				else if (!ValidPlayer(target) || Time.time - lastTargetLoud > Plugin.CfgForgetTime.Value || (stateTimer -= dt) <= 0f)
				{
					Plugin.Log.LogInfo((object)("[Bibliothecaire] Lost interest in " + (Object.op_Implicit((Object)(object)target) ? target.playerName : "?")));
					target = null;
					SetState(State.Patrol);
				}
				else
				{
					soundPos = ((Component)target).transform.position + Vector3.up;
					hasSoundPos = true;
					GoTo(((Component)target).transform.position, Plugin.CfgChargeSpeed.Value, dt, 0.2f);
					erb.OverrideFollowPosition(0.3f, Plugin.CfgChargeSpeed.Value + 2f, -1f);
					val = Flat(((Component)target).transform.position - ((Component)erb).transform.position);
					if (((Vector3)(ref val)).magnitude < 1.5f && Mathf.Abs(((Component)target).transform.position.y - ((Component)erb).transform.position.y) < 2f)
					{
						SetState(State.Gag);
					}
				}
				break;
			case State.Gag:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1.1f;
					hitDone = false;
				}
				Halt();
				stateTimer -= dt;
				if (!hitDone && stateTimer <= 0.65f)
				{
					hitDone = true;
					GagHit();
				}
				if (stateTimer <= 0f)
				{
					SetState(State.Recover);
				}
				break;
			case State.Recover:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = (angry ? 0.7f : 1.5f);
				}
				Halt();
				if ((stateTimer -= dt) <= 0f)
				{
					SetState((!angry) ? State.Patrol : State.Charge);
				}
				break;
			case State.Tidy:
			{
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 12f;
				}
				if (!Object.op_Implicit((Object)(object)tidyItem) || tidyItem.playerGrabbing.Count > 0 || !((Component)tidyItem).gameObject.activeInHierarchy || (stateTimer -= dt) <= 0f)
				{
					tidyItem = null;
					SetState(State.Patrol);
					break;
				}
				soundPos = tidyItem.midPoint;
				hasSoundPos = true;
				GoTo(tidyItem.midPoint, Mathf.Max(2.6f, Plugin.CfgPatrolSpeed.Value), dt);
				val = Flat(tidyItem.midPoint - ((Component)erb).transform.position);
				if (!(((Vector3)(ref val)).magnitude < 1.4f))
				{
					Bounds val2 = BoundsOf(tidyItem);
					val = Flat(((Bounds)(ref val2)).ClosestPoint(((Component)erb).transform.position) - ((Component)erb).transform.position);
					if (!(((Vector3)(ref val)).magnitude < 0.9f))
					{
						break;
					}
				}
				if (TooBig(tidyItem, out var sorted))
				{
					Plugin.Log.LogInfo((object)$"[Bibliothecaire] {((Object)tidyItem).name} is too big for the cart ({sorted.x:0.00} x {sorted.y:0.00} x {sorted.z:0.00} m): leaves it.");
					refused[tidyItem] = Time.time + 20f;
					SetState(State.Refuse);
				}
				else
				{
					SetState(State.PickUp);
				}
				break;
			}
			case State.PickUp:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1.3f;
					pickDone = false;
				}
				Halt();
				stateTimer -= dt;
				if (!pickDone && stateTimer <= 0.6f)
				{
					pickDone = true;
					PutOnCart(tidyItem);
					tidyItem = null;
				}
				if (stateTimer <= 0f)
				{
					SetState(State.Patrol);
				}
				break;
			case State.Refuse:
				if (stateImpulse)
				{
					stateImpulse = false;
					pickDone = false;
				}
				Halt();
				if (!pickDone && stateTime >= 0.85f)
				{
					pickDone = true;
					if (MP)
					{
						photonView.RPC("BiblioTskRPC", (RpcTarget)0, Array.Empty<object>());
					}
					else
					{
						BiblioTskRPC();
					}
				}
				if (stateTime >= 2.3f)
				{
					tidyItem = null;
					SetState(State.Patrol);
				}
				break;
			case State.Dazed:
				{
					if (stateImpulse)
					{
						stateImpulse = false;
					}
					if (!enemy.IsStunned())
					{
						lastWarn.Clear();
						if (!angry)
						{
							target = null;
						}
						SetState((!angry) ? State.Patrol : State.Charge);
					}
					break;
				}
				IL_0176:
				GoTo(patrolDest, Plugin.CfgPatrolSpeed.Value, dt);
				break;
			}
		}

		private void GoTo(Vector3 p, float speed, float dt, float repath = 0.4f)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			pathTimer -= dt;
			if (pathTimer <= 0f)
			{
				pathTimer = repath;
				enemy.NavMeshAgent.SetDestination(p);
			}
			enemy.NavMeshAgent.OverrideAgent(speed, (speed > 4f) ? 30f : 10f, 0.4f);
		}

		private void Halt()
		{
			enemy.NavMeshAgent.Stop(0.2f);
		}

		private void Face(float dt)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//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_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			if ((state == State.Warn || state == State.Alert || state == State.Gag) && ValidPlayer(target))
			{
				val = ((Component)target).transform.position - ((Component)erb).transform.position;
			}
			else if ((state == State.PickUp || state == State.Refuse) && Object.op_Implicit((Object)(object)tidyItem))
			{
				val = tidyItem.midPoint - ((Component)erb).transform.position;
			}
			else if (state == State.Dazed || state == State.Spawn)
			{
				return;
			}
			if (val == Vector3.zero)
			{
				Vector3 agentVelocity = enemy.NavMeshAgent.AgentVelocity;
				if (((Vector3)(ref agentVelocity)).sqrMagnitude > 0.04f)
				{
					val = agentVelocity;
				}
			}
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude < 0.0001f))
			{
				float num = ((state == State.Charge) ? 10f : 5f);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up), 1f - Mathf.Exp((0f - num) * dt));
			}
		}

		private void GrabTick(float dt)
		{
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			List<PhysGrabber> playerGrabbing = erb.physGrabObject.playerGrabbing;
			if (!Plugin.CfgGrabAnger.Value || playerGrabbing.Count == 0 || state == State.Spawn || state == State.Dazed || enemy.IsStunned())
			{
				grabTime = 0f;
			}
			else
			{
				if ((grabTime += dt) < 0.25f)
				{
					return;
				}
				grabTime = 0f;
				PlayerAvatar val = null;
				int viewID = erb.physGrabObject.photonView.ViewID;
				foreach (PhysGrabber item in new List<PhysGrabber>(playerGrabbing))
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						if (!Object.op_Implicit((Object)(object)val) && ValidPlayer(item.playerAvatar))
						{
							val = item.playerAvatar;
						}
						if (SemiFunc.IsMultiplayer())
						{
							item.ReleaseObject(viewID, 1.5f);
						}
						else
						{
							item.OverrideGrabRelease(viewID, 1.5f);
						}
					}
				}
				if (Object.op_Implicit((Object)(object)val))
				{
					Plugin.Log.LogInfo((object)("[Bibliothecaire] Grabbed by " + val.playerName + ": hunting them."));
					if (!angry)
					{
						gaggedOnce = false;
					}
					angry = true;
					angryLose = 0f;
					angryEnd = Time.time + Plugin.CfgAngryMaxTime.Value;
					angryLastSeen = ((Component)val).transform.position;
					target = val;
					lastTargetLoud = Time.time;
					if (state == State.Charge)
					{
						SyncState();
					}
					else if (state != State.Gag && state != State.Recover)
					{
						SetState(State.Charge);
					}
				}
			}
		}

		private static bool ClearLine(Vector3 a, Vector3 b, int mask)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			bool queriesHitBackfaces = Physics.queriesHitBackfaces;
			Physics.queriesHitBackfaces = true;
			try
			{
				return !Physics.Linecast(a, b, mask, (QueryTriggerInteraction)1);
			}
			finally
			{
				Physics.queriesHitBackfaces = queriesHitBackfaces;
			}
		}

		private void AngerTick(float dt)
		{
			//IL_004e: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: 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_0082: 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_008d: 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_00be: 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_010a: 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)
			if (!angry)
			{
				return;
			}
			if (!ValidPlayer(target) || Time.time > angryEnd)
			{
				EndAnger((Time.time > angryEnd) ? "time limit" : "target gone");
				return;
			}
			Vector3 val = ((Component)erb).transform.position + Vector3.up * 0.8f;
			Vector3 val2 = ((Component)target).transform.position + Vector3.up * 1.4f;
			int mask = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) & ~LayerMask.GetMask(new string[3] { "Player", "PhysGrabObject", "Enemy" });
			if (ClearLine(val, val2, mask))
			{
				angryLose = 0f;
				angryLastSeen = ((Component)target).transform.position;
			}
			else
			{
				angryLose += dt;
			}
			if (angryLose > Plugin.CfgLoseSight.Value || Vector3.Distance(val, val2) > Plugin.CfgLoseDistance.Value)
			{
				EndAnger("shaken off");
			}
		}

		private void EndAnger(string why)
		{
			if (angry)
			{
				angry = false;
				gaggedOnce = false;
				Plugin.Log.LogInfo((object)("[Bibliothecaire] Gives up the chase (" + why + ")."));
				target = null;
				if (state == State.Charge || state == State.Recover)
				{
					SetState(State.Patrol);
				}
			}
		}

		private void GagHit()
		{
			//IL_0016: 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_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_0031: 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)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = target;
			if (!ValidPlayer(val))
			{
				return;
			}
			Vector3 v = ((Component)val).transform.position - ((Component)erb).transform.position;
			Vector3 val2 = Flat(v);
			if (((Vector3)(ref val2)).magnitude > 2.2f)
			{
				return;
			}
			if (angry && gaggedOnce)
			{
				if (Plugin.CfgAngryHitDamage.Value > 0)
				{
					val.playerHealth.HurtOther(Plugin.CfgAngryHitDamage.Value, ((Component)val).transform.position + Vector3.up, false, SemiFunc.EnemyGetIndex(enemy), false);
				}
				val2 = Flat(v);
				val.ForceImpulse(((Vector3)(ref val2)).normalized * 4f + Vector3.up * 1.5f);
				Sounds.Play(Sounds.Swing, ((Component)erb).transform.position, 0.9f, 1.15f);
				return;
			}
			if (Plugin.CfgGagDamage.Value > 0)
			{
				val.playerHealth.HurtOther(Plugin.CfgGagDamage.Value, ((Component)val).transform.position + Vector3.up, false, SemiFunc.EnemyGetIndex(enemy), false);
			}
			val2 = Flat(v);
			val.ForceImpulse(((Vector3)(ref val2)).normalized * 4f + Vector3.up * 2f);
			if (MP)
			{
				photonView.RPC("BiblioGagRPC", (RpcTarget)0, new object[2]
				{
					val.photonView.ViewID,
					Plugin.CfgMuteDuration.Value
				});
			}
			else
			{
				BiblioGagRPC(val.photonView.ViewID, Plugin.CfgMuteDuration.Value);
			}
			lastWarn.Remove(val.photonView.ViewID);
			Plugin.Log.LogInfo((object)("[Bibliothecaire] Gagged " + val.playerName));
			if (angry)
			{
				gaggedOnce = true;
			}
			else
			{
				target = null;
			}
		}

		[PunRPC]
		private void BiblioGagRPC(int playerViewID, float duration, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				PhotonView val = PhotonView.Find(playerViewID);
				PlayerAvatar val2 = (Object.op_Implicit((Object)(object)val) ? ((Component)val).GetComponent<PlayerAvatar>() : null);
				Vector3 pos = (Object.op_Implicit((Object)(object)erb) ? ((Component)erb).transform.position : ((Component)this).transform.position);
				Sounds.Play(Sounds.Slam, pos, 0.8f, 1.2f);
				if (Object.op_Implicit((Object)(object)val2))
				{
					Sounds.Play(Sounds.Tape, ((Component)val2).transform.position + Vector3.up);
					Gag.Apply(val2, duration);
				}
			}
		}

		[PunRPC]
		private void BiblioChutRPC(bool angry, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: 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_0028: 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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				Transform value;
				Vector3 val = (J.TryGetValue("head", out value) ? value.position : ((Component)erb).transform.position);
				Sounds.Play(angry ? Sounds.ChutAngry : Sounds.Chut, val);
				if (angry && Object.op_Implicit((Object)(object)GameDirector.instance) && Object.op_Implicit((Object)(object)GameDirector.instance.CameraShake))
				{
					GameDirector.instance.CameraShake.ShakeDistance(2f, 3f, 15f, val, 0.3f);
				}
			}
		}

		internal static void Noise(PhysGrabObjectImpactDetector det, float radius, Vector3 position)
		{
			if (!Master || (Object)(object)det == (Object)null)
			{
				return;
			}
			BiblioAI biblioAI = Existing();
			if (!((Object)(object)biblioAI == (Object)null) && biblioAI.ready && ((Behaviour)biblioAI).isActiveAndEnabled)
			{
				PhysGrabObject physGrabObject = det.physGrabObject;
				if (Object.op_Implicit((Object)(object)physGrabObject) && !det.inCart && !det.isCart && physGrabObject.playerGrabbing.Count <= 0 && !Object.op_Implicit((Object)(object)((Component)physGrabObject).GetComponent<EnemyRigidbody>()) && (Object.op_Implicit((Object)(object)((Component)physGrabObject).GetComponent<ValuableObject>()) || Object.op_Implicit((Object)(object)((Component)physGrabObject).GetComponent<ItemAttributes>())))
				{
					biblioAI.OnNoise(physGrabObject);
				}
			}
		}

		private void OnNoise(PhysGrabObject p)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)p == (Object)(object)tidyItem) && Array.IndexOf(cart, p) < 0 && state != State.Spawn && state != State.Gag && state != State.Recover && state != State.Dazed && state != State.PickUp && state != State.Tidy && state != State.Refuse && (!refused.TryGetValue(p, out var value) || !(Time.time < value)))
			{
				float num = Vector3.Distance(p.midPoint, ((Component)erb).transform.position);
				float num2 = ((state == State.Charge) ? Plugin.CfgChargeDistractRange.Value : Plugin.CfgDistractRange.Value);
				if (!(num > num2))
				{
					tidyItem = p;
					busyUntil = Time.time + Plugin.CfgDistractTime.Value;
					soundPos = p.midPoint;
					hasSoundPos = true;
					Plugin.Log.LogInfo((object)$"[Bibliothecaire] Noise: going to tidy {((Object)p).name} ({num:0.0} m)");
					SetState(State.Tidy);
				}
			}
		}

		private void PutOnCart(PhysGrabObject p)
		{
			//IL_00f4: 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_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)p) || p.playerGrabbing.Count > 0)
			{
				return;
			}
			int num = Mathf.Clamp(Plugin.CfgCartSlots.Value, 1, 8);
			int num2 = -1;
			for (int i = 0; i < num; i++)
			{
				if (!Object.op_Implicit((Object)(object)cart[i]))
				{
					num2 = i;
					break;
				}
			}
			if (num2 < 0)
			{
				DropFromCart(0, Flat(-((Component)erb).transform.right) * 0.6f);
				for (int j = 0; j < num - 1; j++)
				{
					cart[j] = cart[j + 1];
					cartSize[j] = cartSize[j + 1];
					cartLift[j] = cartLift[j + 1];
					cartTall[j] = cartTall[j + 1];
				}
				cart[num - 1] = null;
				num2 = num - 1;
			}
			Bounds val = BoundsOf(p);
			float value = Plugin.CfgCartShrink.Value;
			cart[num2] = p;
			cartSize[num2] = Mathf.Clamp(2f * Mathf.Max(((Bounds)(ref val)).extents.x, ((Bounds)(ref val)).extents.z) * value, 0.1f, 1.2f);
			cartLift[num2] = Mathf.Max(0.02f, (p.midPoint.y - ((Bounds)(ref val)).min.y) * value);
			cartTall[num2] = Mathf.Max(0.04f, ((Bounds)(ref val)).size.y * value);
			Shrink(p, on: true);
			if (MP)
			{
				photonView.RPC("BiblioPickRPC", (RpcTarget)0, Array.Empty<object>());
			}
			else
			{
				BiblioPickRPC();
			}
		}

		private void DropFromCart(int i, Vector3 push)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			PhysGrabObject val = cart[i];
			cart[i] = null;
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.rb))
			{
				Shrink(val, on: false);
				Protect(val);
				val.rb.linearVelocity = push + Vector3.up * 0.5f;
			}
		}

		private void CartLayout(float dt)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)slots[0]) || !Object.op_Implicit((Object)(object)slots[2]))
			{
				return;
			}
			Vector3 position = slots[0].position;
			Vector3 val = slots[2].position - position;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude < 0.1f)
			{
				return;
			}
			val /= magnitude;
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			for (int i = 0; i < cart.Length; i++)
			{
				PhysGrabObject val2 = cart[i];
				if (Object.op_Implicit((Object)(object)val2) && Object.op_Implicit((Object)(object)val2.rb))
				{
					float num4 = Mathf.Min(cartSize[i], magnitude + 0.2f);
					if (num > 0f && num + num4 > magnitude + 0.1f)
					{
						num2 = num3;
						num = 0f;
					}
					float num5 = ((num4 > magnitude) ? (magnitude * 0.5f) : (num + num4 * 0.5f));
					Vector3 val3 = position + val * num5 + Vector3.up * (num2 + cartLift[i] + 0.02f);
					num += num4 + 0.03f;
					num3 = Mathf.Max(num3, num2 + cartTall[i] + 0.02f);
					val2.OverrideZeroGravity(0.25f);
					val2.OverrideIndestructible(0.5f);
					val2.OverrideBreakEffects(0.5f);
					Vector3 val4 = val3 - val2.midPoint;
					val2.rb.linearVelocity = Vector3.ClampMagnitude(val4 / dt * 0.5f, 25f) + erb.rb.linearVelocity * 0.3f;
					Rigidbody rb = val2.rb;
					rb.angularVelocity *= 0.6f;
				}
			}
		}

		private static Bounds BoundsOf(PhysGrabObject p)
		{
			//IL_0005: 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_0014: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(p.midPoint, Vector3.one * 0.3f);
			Collider[] componentsInChildren = ((Component)p).GetComponentsInChildren<Collider>();
			foreach (Collider val in componentsInChildren)
			{
				if (Object.op_Implicit((Object)(object)val) && val.enabled && !val.isTrigger)
				{
					if (!flag)
					{
						bounds = val.bounds;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val.bounds);
					}
				}
			}
			return bounds;
		}

		private static bool TooBig(PhysGrabObject p, out Vector3 sorted)
		{
			//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_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: 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_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: 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_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)p).transform;
			bool flag = false;
			Bounds val = default(Bounds);
			((Bounds)(ref val))..ctor(Vector3.zero, Vector3.zero);
			Collider[] componentsInChildren = ((Component)p).GetComponentsInChildren<Collider>();
			Bounds bounds = default(Bounds);
			foreach (Collider val2 in componentsInChildren)
			{
				if (!Object.op_Implicit((Object)(object)val2) || !val2.enabled || val2.isTrigger)
				{
					continue;
				}
				BoxCollider val3 = (BoxCollider)(object)((val2 is BoxCollider) ? val2 : null);
				if (val3 != null)
				{
					((Bounds)(ref bounds))..ctor(val3.center, val3.size);
				}
				else
				{
					SphereCollider val4 = (SphereCollider)(object)((val2 is SphereCollider) ? val2 : null);
					if (val4 != null)
					{
						((Bounds)(ref bounds))..ctor(val4.center, Vector3.one * val4.radius * 2f);
					}
					else
					{
						CapsuleCollider val5 = (CapsuleCollider)(object)((val2 is CapsuleCollider) ? val2 : null);
						if (val5 != null)
						{
							Vector3 val6 = Vector3.one * val5.radius * 2f;
							((Vector3)(ref val6))[Mathf.Clamp(val5.direction, 0, 2)] = Mathf.Max(val5.height, val5.radius * 2f);
							((Bounds)(ref bounds))..ctor(val5.center, val6);
						}
						else
						{
							MeshCollider val7 = (MeshCollider)(object)((val2 is MeshCollider) ? val2 : null);
							if (val7 != null && Object.op_Implicit((Object)(object)val7.sharedMesh))
							{
								bounds = val7.sharedMesh.bounds;
							}
							else
							{
								Transform transform2 = ((Component)val2).transform;
								Bounds bounds2 = val2.bounds;
								Vector3 val8 = transform2.InverseTransformVector(((Bounds)(ref bounds2)).size);
								Transform transform3 = ((Component)val2).transform;
								bounds2 = val2.bounds;
								((Bounds)(ref bounds))..ctor(transform3.InverseTransformPoint(((Bounds)(ref bounds2)).center), new Vector3(Mathf.Abs(val8.x), Mathf.Abs(val8.y), Mathf.Abs(val8.z)));
							}
						}
					}
				}
				for (int j = 0; j < 8; j++)
				{
					Vector3 val9 = ((Bounds)(ref bounds)).center + Vector3.Scale(((Bounds)(ref bounds)).extents, new Vector3((float)(((j & 1) != 0) ? 1 : (-1)), (float)(((j & 2) != 0) ? 1 : (-1)), (float)(((j & 4) != 0) ? 1 : (-1))));
					Vector3 val10 = transform.InverseTransformPoint(((Component)val2).transform.TransformPoint(val9));
					if (!flag)
					{
						((Bounds)(ref val))..ctor(val10, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref val)).Encapsulate(val10);
					}
				}
			}
			Vector3 lossyScale = transform.lossyScale;
			float[] array = new float[3]
			{
				Mathf.Abs(((Bounds)(ref val)).size.x * lossyScale.x),
				Mathf.Abs(((Bounds)(ref val)).size.y * lossyScale.y),
				Mathf.Abs(((Bounds)(ref val)).size.z * lossyScale.z)
			};
			Array.Sort(array);
			sorted = new Vector3(array[2], array[1], array[0]);
			if (!flag)
			{
				return false;
			}
			sorted *= Plugin.CfgCartShrink.Value;
			if (!(sorted.x > Plugin.CfgTooBig.Value) && !(sorted.y > 0.75f))
			{
				return sorted.z > 1f;
			}
			return true;
		}

		[PunRPC]
		private void BiblioTskRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				Sounds.Play(Sounds.Tsk, ((Component)erb).transform.position + Vector3.up * 1.5f, 0.8f);
			}
		}

		private static void Protect(PhysGrabObject p)
		{
			float value = Plugin.CfgCartProtect.Value;
			if (Object.op_Implicit((Object)(object)p) && !(value <= 0f) && Master)
			{
				p.OverrideIndestructible(value);
				if (Object.op_Implicit((Object)(object)Plugin.Instance))
				{
					((MonoBehaviour)Plugin.Instance).StartCoroutine(ProtectRun(p, value));
				}
			}
		}

		private static IEnumerator ProtectRun(PhysGrabObject p, float time)
		{
			float end = Time.time + time;
			while (Object.op_Implicit((Object)(object)p) && Time.time < end)
			{
				p.OverrideIndestructible(Mathf.Max(0.3f, end - Time.time));
				yield return (object)new WaitForSeconds(0.2f);
			}
		}

		private void Shrink(PhysGrabObject p, bool on)
		{
			//IL_0081: 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)
			if (!Object.op_Implicit((Object)(object)p) || !Object.op_Implicit((Object)(object)p.photonView))
			{
				return;
			}
			float num = (on ? Plugin.CfgCartShrink.Value : 1f);
			if (!on || !(num >= 0.999f))
			{
				if (MP)
				{
					photonView.RPC("BiblioShrinkRPC", (RpcTarget)0, new object[2]
					{
						p.photonView.ViewID,
						num
					});
				}
				else
				{
					BiblioShrinkRPC(p.photonView.ViewID, num);
				}
			}
		}

		[PunRPC]
		private void BiblioShrinkRPC(int viewId, float factor, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				PhotonView val = PhotonView.Find(viewId);
				if (Object.op_Implicit((Object)(object)val))
				{
					PhysGrabObject component = ((Component)val).GetComponent<PhysGrabObject>();
					CartShrink.Set(Object.op_Implicit((Object)(object)component) ? ((Component)component).gameObject : ((Component)val).gameObject, factor, (MonoBehaviour)(object)this);
				}
			}
		}

		[PunRPC]
		private void BiblioPickRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				Sounds.Play(Sounds.PickUp, ((Component)erb).transform.position, 0.6f);
				Sounds.Play(Sounds.Squeak, ((Component)erb).transform.position, 0.5f, 1.2f);
			}
		}

		private void SetState(State s)
		{
			if (s != state)
			{
				ApplyState(s);
				SyncState();
			}
		}

		private void SyncState()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			if (MP)
			{
				photonView.RPC("BiblioStateRPC", (RpcTarget)1, new object[4]
				{
					(int)state,
					Object.op_Implicit((Object)(object)target) ? target.photonView.ViewID : (-1),
					soundPos,
					hasSoundPos
				});
			}
		}

		[PunRPC]
		private void BiblioStateRPC(int s, int targetID, Vector3 sound, bool hasSound, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.MasterOnlyRPC(info))
			{
				return;
			}
			target = null;
			if (targetID >= 0)
			{
				PhotonView val = PhotonView.Find(targetID);
				if (Object.op_Implicit((Object)(object)val))
				{
					target = ((Component)val).GetComponent<PlayerAvatar>();
				}
			}
			soundPos = sound;
			hasSoundPos = hasSound;
			if (s != (int)state || s == 3)
			{
				ApplyState((State)s);
			}
		}

		private void ApplyState(State s)
		{
			//IL_005f: 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_0064: 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_00f1: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			State state = this.state;
			this.state = s;
			stateImpulse = true;
			stateTimer = 0f;
			stateTime = 0f;
			if (s == State.Patrol || s == State.Idle)
			{
				hasSoundPos = false;
			}
			Vector3 pos = (Object.op_Implicit((Object)(object)erb) ? ((Component)erb).transform.position : ((Component)this).transform.position);
			if (Master)
			{
				Plugin.Log.LogInfo((object)($"[Bibliothecaire] {state} -> {s}" + (Object.op_Implicit((Object)(object)target) ? (" (" + target.playerName + ")") : "")));
			}
			switch (s)
			{
			case State.Alert:
				Sounds.Play(Sounds.Notice, pos, 0.4f, 1.3f);
				break;
			case State.Dazed:
				Sounds.Play(Sounds.Stun, pos);
				break;
			case State.Patrol:
				if (state == State.Dazed)
				{
					Sounds.Play(Sounds.StunOutro, pos, 0.8f);
				}
				break;
			case State.Gag:
				Sounds.Play(Sounds.Swing, pos, 0.9f);
				break;
			}
		}

		private void OnSpawn()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			angry = false;
			if (Object.op_Implicit((Object)(object)erb))
			{
				lastVisPos = ((Component)erb).transform.position;
			}
			if (!Master)
			{
				return;
			}
			bool flag = Time.time < SkipTeleportUntil;
			if (flag)
			{
				SkipTeleportUntil = 0f;
			}
			if (!flag && Plugin.TryQuietPoint(Vector3.zero, 0f, 999f, out var pos))
			{
				enemy.EnemyTeleported(pos);
				flag = true;
			}
			if (!flag)
			{
				flag = SemiFunc.EnemySpawn(enemy);
			}
			if (flag)
			{
				Plugin.Log.LogInfo((object)("[Bibliothecaire] Spawned at " + ((object)((Component)erb).transform.position/*cast due to .constrained prefix*/).ToString()));
				target = null;
				lastWarn.Clear();
				if (state == State.Spawn)
				{
					stateImpulse = true;
					stateTimer = 0f;
					stateTime = 0f;
				}
				else
				{
					SetState(State.Spawn);
				}
			}
		}

		internal void DebugBring(Vector3 pos)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			EnemyParent enemyParent = enemy.EnemyParent;
			if (Object.op_Implicit((Object)(object)enemyParent) && !enemyParent.Spawned)
			{
				SkipTeleportUntil = Time.time + 5f;
				enemyParent.Spawn();
			}
			enemy.EnemyTeleported(pos);
			target = null;
			lastWarn.Clear();
			SetState(State.Spawn);
		}

		private void OnHurt()
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)erb).transform.position;
			Sounds.Play(Sounds.Hurt, position, 0.8f);
			if (!Master || dazeCooldown > 0f || enemy.IsStunned() || !enemy.HasStateStunned)
			{
				return;
			}
			PlayerAvatar val = health.onObjectHurtPlayer;
			if (!ValidPlayer(val) || Vector3.Distance(((Component)val).transform.position, position) > 6f)
			{
				val = SemiFunc.PlayerGetNearestPlayerAvatarWithinRange(4f, position, false, default(LayerMask));
			}
			if (ValidPlayer(val))
			{
				Vector3 val2 = Flat(((Component)val).transform.position - position);
				Vector3 val3 = Flat(((Component)erb).transform.forward);
				if (!(Vector3.Dot(((Vector3)(ref val3)).normalized, ((Vector3)(ref val2)).normalized) < 0.3f) && !(Plugin.CfgDazeDuration.Value <= 0f))
				{
					dazeCooldown = 12f;
					enemy.StateStunned.Set(Plugin.CfgDazeDuration.Value);
				}
			}
		}

		private void OnDeath()
		{
			//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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)erb).transform.position;
			Sounds.Play(Sounds.Death, position);
			Sounds.Play(Sounds.DeathSpark, position, 0.9f);
			if (Object.op_Implicit((Object)(object)particles))
			{
				particles.position = position + Vector3.up * 0.7f;
				ParticleSystem[] componentsInChildren = ((Component)particles).GetComponentsInChildren<ParticleSystem>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].Play(true);
				}
			}
			if (!Master)
			{
				return;
			}
			for (int j = 0; j < cart.Length; j++)
			{
				if (Object.op_Implicit((Object)(object)cart[j]))
				{
					DropFromCart(j, Random.insideUnitSphere * 2f);
				}
			}
			enemy.EnemyParent.Despawn();
		}

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

		private static bool ValidPlayer(PlayerAvatar p)
		{
			if ((Object)(object)p != (Object)null && !p.isDisabled)
			{
				return !p.deadSet;
			}
			return false;
		}

		private static float Damp(float c, float tg, float s, float dt)
		{
			return Mathf.Lerp(c, tg, 1f - Mathf.Exp((0f - s) * dt));
		}

		private static float Smooth(float a, float b, float x)
		{
			float num = Mathf.Clamp01((x - a) / (b - a));
			return num * num * (3f - 2f * num);
		}

		private void P(string j, float x, float y = 0f, float z = 0f)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			pose[j] = new Vector3(x, y, z);
		}

		private void Blend(string j, float x, float y, float z, float w)
		{
			//IL_0017: 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			Vector3 value;
			Vector3 val = (pose.TryGetValue(j, out value) ? value : Vector3.zero);
			pose[j] = Vector3.Lerp(val, new Vector3(x, y, z), w);
		}

		private void Apply(string j)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (pose.TryGetValue(j, out var value) && J.TryGetValue(j, out var value2))
			{
				value2.localRotation = Quaternion.Euler(value);
			}
		}

		private Vector2 ArmIK(string side, Vector3 targetWorld)
		{
			//IL_0027: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = J["torso"];
			Transform val = J["upperarm_" + side];
			Vector3 val2 = obj.InverseTransformDirection(targetWorld - val.position);
			float num = 0.29f;
			float num2 = 0.33f;
			Vector2 val3 = new Vector2(val2.y, val2.z);
			float num3 = Mathf.Clamp(((Vector2)(ref val3)).magnitude, 0.05f, num + num2 - 0.001f);
			float num4 = Mathf.Atan2(val2.z, 0f - val2.y);
			float num5 = Mathf.Acos(Mathf.Clamp((num * num + num3 * num3 - num2 * num2) / (2f * num * num3), -1f, 1f));
			float num6 = Mathf.Acos(Mathf.Clamp((num * num + num2 * num2 - num3 * num3) / (2f * num * num2), -1f, 1f));
			return new Vector2((0f - (num4 - num5)) * 57.29578f, (0f - ((float)Math.PI - num6)) * 57.29578f);
		}

		private void Animate(float dt)
		{
			//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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0348: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_044e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Unknown result type (might be due to invalid IL or missing references)
			//IL_042f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0477: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0481: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0488: 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_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b98: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bbd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bc2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bcd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bd2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0bf7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c1c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c06: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c21: Unknown result type (might be due to invalid IL or missing references)
			//IL_0c86: Unknown result type (might be due to invalid IL or missing references)
			//IL_0caa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0caf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cb4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cc7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ccc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cd4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0cf0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0d28: Unknown result type (might be due to invalid IL or missing references)
			//IL_0db0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dc5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dcf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dd9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0dde: Unknown result type (might be due to invalid IL or missing references)
			//IL_0de6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0e04: Unknown result type (might be due to invalid IL or missing references)
			//IL_10bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_1084: Unknown result type (might be due to invalid IL or missing references)
			//IL_108f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1099: Unknown result type (might be due to invalid IL or missing references)
			//IL_109e: Unknown result type (might be due to invalid IL or missing references)
			//IL_10a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_10ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_10b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f73: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f38: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f43: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f4d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f52: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f57: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f61: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f66: Unknown result type (might be due to invalid IL or missing references)
			//IL_10c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_10cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_10ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_10d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_10db: Unknown result type (might be due to invalid IL or missing references)
			//IL_10dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_10e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_10f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_10f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_1101: Unknown result type (might be due to invalid IL or missing references)
			//IL_1106: Unknown result type (might be due to invalid IL or missing references)
			//IL_110b: Unknown result type (might be due to invalid IL or missing references)
			//IL_1110: Unknown result type (might be due to invalid IL or missing references)
			//IL_1118: Unknown result type (might be due to invalid IL or missing references)
			//IL_1136: Unknown result type (might be due to invalid IL or missing references)
			//IL_1154: Unknown result type (might be due to invalid IL or missing references)
			//IL_1172: Unknown result type (might be due to invalid IL or missing references)
			//IL_1190: Unknown result type (might be due to invalid IL or missing references)
			//IL_11ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f78: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f80: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f82: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f87: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f91: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f96: Unknown result type (might be due to invalid IL or missing references)
			//IL_0f9e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fbc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0fda: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ff8: Unknown result type (might be due to invalid IL or missing references)
			//IL_12c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_12cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_12f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_12fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_1371: Unknown result type (might be due to invalid IL or missing references)
			//IL_1376: Unknown result type (might be due to invalid IL or missing references)
			//IL_138a: Unknown result type (might be due to invalid IL or missing references)
			//IL_138f: Unknown result type (might be due to invalid IL or missing references)
			//IL_141b: Unknown result type (might be due to invalid IL or missing references)
			//IL_142f: Unknown result type (might be due to invalid IL or missing references)
			//IL_1434: Unknown result type (might be due to invalid IL or missing references)
			//IL_1436: Unknown result type (might be due to invalid IL or missing references)
			//IL_13b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_13c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_144e: Unknown result type (might be due to invalid IL or missing references)
			if (dt <= 0f)
			{
				return;
			}
			if (!Master)
			{
				stateTime += dt;
			}
			float num = stateTime;
			Vector3 position = ((Component)erb).transform.position;
			Vector3 val = Flat(position - lastVisPos);
			lastVisPos = position;
			float num2 = ((Vector3)(ref val)).magnitude;
			if (num2 / dt > 15f)
			{
				num2 = 0f;
			}
			bodySpeed = Damp(bodySpeed, num2 / dt, 8f, dt);
			float num3 = Mathf.Clamp01(bodySpeed / 1.4f);
			bool flag = state == State.Charge;
			walkPhase += num2 / (flag ? 1.6f : 1.1f) * (float)Math.PI * 2f;
			wheelAngle += num2 / 0.045f * 57.29578f;
			distAcc += num2;
			stepAcc += num2;
			if (distAcc > (flag ? 0.9f : 0.7f) && state != State.Dazed)
			{
				distAcc = 0f;
				if (Random.value < (flag ? 0.9f : 0.55f))
				{
					Sounds.Play(Sounds.Squeak, position + ((Component)this).transform.forward * 0.6f, flag ? 0.6f : 0.35f, Random.Range(0.9f, 1.15f));
				}
			}
			if (stepAcc > (flag ? 0.8f : 0.55f))
			{
				stepAcc = 0f;
				Sounds.Play(Sounds.Footstep, position - Vector3.up * 0.45f, 0.25f, 1.15f);
			}
			float num4 = Mathf.Sin(walkPhase);
			float num5 = Mathf.Cos(walkPhase);
			float num6 = (flag ? 46f : 32f);
			pose.Clear();
			float num7 = (flag ? 26f : 18f) * num3;
			float num8 = (flag ? 44f : 30f) * num3;
			P("pelvis", 0f, 3f * num3 * num4);
			P("torso", num6, -4f * num3 * num4);
			P("thigh_l", (0f - num7) * num4 - 2f);
			P("thigh_r", num7 * num4 - 2f);
			P("shin_l", num8 * Mathf.Pow(Mathf.Max(0f, num5), 1.3f) + 3f * num3);
			P("shin_r", num8 * Mathf.Pow(Mathf.Max(0f, 0f - num5), 1.3f) + 3f * num3);
			P("foot_l", (0f - (pose["thigh_l"].x + pose["shin_l"].x)) * 0.85f);
			P("foot_r", (0f - (pose["thigh_r"].x + pose["shin_r"].x)) * 0.85f);
			float num9 = -0.015f * num3 * Mathf.Abs(num5);
			float num10 = (0f - num6) * 0.7f;
			float tg = 0f;
			float num11 = 0f;
			float tg2 = 0f;
			float tg3 = 0f;
			Vector3 val2 = Vector3.zero;
			bool flag2 = false;
			if (ValidPlayer(target) && (state == State.Warn || state == State.Alert || state == State.Charge || state == State.Gag))
			{
				val2 = ((Component)target).transform.position + Vector3.up;
				flag2 = true;
			}
			else if (hasSoundPos)
			{
				val2 = soundPos;
				flag2 = true;
			}
			if (flag2)
			{
				Vector3 val3 = visuals.InverseTransformDirection(val2 - J["head"].position);
				num11 = Mathf.Clamp(Mathf.Atan2(val3.x, val3.z) * 57.29578f, -60f, 60f);
				float y = val3.y;
				Vector2 val4 = new Vector2(val3.x, val3.z);
				tg2 = Mathf.Clamp((0f - Mathf.Atan2(y, ((Vector2)(ref val4)).magnitude)) * 57.29578f, -30f, 35f);
				tg3 = Mathf.Clamp(num11 * 0.6f, -40f, 40f);
			}
			if (state == State.Alert || state == State.Warn)
			{
				tg = 0.12f;
			}
			if (state == State.Tidy)
			{
				tg = 0.06f;
			}
			if (state == State.Spawn)
			{
				num11 = 35f * Mathf.Sin(num * 3f);
				tg = 0.12f * Smooth(0.2f, 0.8f, num);
			}
			if (state == State.Patrol || state == State.Idle)
			{
				tg3 = 18f * Mathf.Sin(t * 0.9f);
				num11 = ((state == State.Idle) ? (25f * Mathf.Sin(t * 0.6f)) : 0f);
			}
			headYaw = Damp(headYaw, num11, 6f, dt);
			headPitch = Damp(headPitch, tg2, 6f, dt);
			trumpetYaw = Damp(trumpetYaw, tg3, 5f, dt);
			neckExt = Damp(neckExt, tg, 6f, dt);
			P("head", num10 + headPitch, headYaw);
			P("trumpet_l", 0f, 0f - trumpetYaw);
			P("trumpet_r", 0f, 0f - trumpetYaw);
			P("glasses", 0f);
			P("cart", 0f);
			switch (state)
			{
			case State.Warn:
			{
				float w5 = Smooth(0f, 0.25f, num) * (1f - Smooth(1.5f, 1.8f, num));
				Blend("torso", 16f, 0f, 0f, w5);
				break;
			}
			case State.Gag:
			{
				float w3 = Smooth(0f, 0.35f, num) * (1f - Smooth(0.42f, 0.5f, num));
				float w4 = Smooth(0.42f, 0.5f, num) * (1f - Smooth(0.8f, 1.1f, num));
				Blend("torso", 10f, 15f, 0f, w3);
				Blend("torso", 52f, -12f, 0f, w4);
				break;
			}
			case State.PickUp:
			{
				float num13 = Smooth(0f, 0.4f, num) * (1f - Smooth(0.9f, 1.3f, num));
				Blend("torso", 62f, 0f, 0f, num13);
				Blend("thigh_l", -20f, 0f, 0f, num13);
				Blend("thigh_r", -20f, 0f, 0f, num13);
				Blend("shin_l", 30f, 0f, 0f, num13);
				Blend("shin_r", 30f, 0f, 0f, num13);
				num9 -= 0.05f * num13;
				break;
			}
			case State.Refuse:
			{
				float num12 = Smooth(0f, 0.35f, num) * (1f - Smooth(0.7f, 0.95f, num));
				float w2 = Smooth(0.85f, 1.05f, num) * (1f - Smooth(1.9f, 2.3f, num));
				Blend("torso", 62f + 3f * Mathf.Sin(t * 40f), 0f, 0f, num12);
				Blend("thigh_l", -20f, 0f, 0f, num12);
				Blend("thigh_r", -20f, 0f, 0f, num12);
				Blend("shin_l", 30f, 0f, 0f, num12);
				Blend("shin_r", 30f, 0f, 0f, num12);
				Blend("torso", 14f, 0f, 0f, w2);
				Blend("head", num10 + 6f, 28f * Mathf.Sin(t * 10f), 0f, w2);
				num9 -= 0.05f * num12;
				break;
			}
			case State.Dazed:
			{
				float w = Smooth(0f, 0.3f, num);
				Blend("torso", 40f, 8f * Mathf.Sin(t * 7f), 6f * Mathf.Sin(t * 9f), w);
				Blend("head", num10 + 25f + 8f * Mathf.Sin(t * 11f), 18f * Mathf.Sin(t * 4f), 10f * Mathf.Sin(t * 13f), w);
				Blend("glasses", 0f, 0f, 28f, w);
				break;
			}
			case State.Charge:
				P("cart", -3f + 2f * Mathf.Sin(t * 30f), 0f, 1.5f * Mathf.Sin(t * 23f));
				break;
			}
			string[] array = new string[13]
			{
				"pelvis", "torso", "head", "trumpet_l", "trumpet_r", "glasses", "thigh_l", "shin_l", "foot_l", "thigh_r",
				"shin_r", "foot_r", "cart"
			};
			foreach (string j in array)
			{
				Apply(j);
			}
			model.localPosition = new Vector3(0f, -0.5f + num9, 0f);
			J["head"].localPosition = restPos["head"] + Vector3.up * neckExt;
			J["glasses"].localPosition = restPos["glasses"] + (Vector3)((state == State.Dazed) ? new Vector3(0.01f, -0.025f, 0.01f) : Vector3.zero);
			float num14 = wheelAngle % 360f;
			array = new string[4] { "wheel_fl", "wheel_fr", "wheel_bl", "wheel_br" };
			foreach (string key in array)
			{
				J[key].localRotation = Quaternion.Euler(num14, 0f, 0f);
			}
			Vector2 val5 = ArmIK("l", handleL.position);
			Vector2 val6 = ArmIK("r", handleR.position);
			P("upperarm_l", val5.x);
			P("forearm_l", val5.y);
			P("upperarm_r", val6.x);
			P("forearm_r", val6.y);
			bool flag3 = false;
			switch (state)
			{
			case State.Warn:
			{
				float w11 = Smooth(0.05f, 0.35f, num) * (1f - Smooth(1.45f, 1.8f, num));
				Vector2 val10 = ArmIK("r", mouth.position + J["head"].forward * 0.03f);
				Blend("upperarm_r", val10.x, 0f, -14f, w11);
				Blend("forearm_r", val10.y, 0f, 0f, w11);
				break;
			}
			case State.Gag:
			{
				flag3 = num < 1f;
				float w9 = Smooth(0f, 0.35f, num) * (1f - Smooth(0.42f, 0.5f, num));
				float w10 = Smooth(0.42f, 0.5f, num) * (1f - Smooth(0.85f, 1.1f, num));
				Blend("upperarm_r", -165f, 0f, -10f, w9);
				Blend("forearm_r", -40f, 0f, 0f, w9);
				Blend("upperarm_r", -70f, 0f, -5f, w10);
				Blend("forearm_r", -10f, 0f, 0f, w10);
				break;
			}
			case State.Refuse:
			{
				float w12 = Smooth(0f, 0.35f, num) * (1f - Smooth(0.7f, 0.95f, num));
				Vector3 targetWorld2 = (Object.op_Implicit((Object)(object)tidyItem) ? tidyItem.midPoint : (J["torso"].position + ((Component)this).transform.forward * 0.6f - Vector3.up * 0.6f));
				Vector2 val11 = ArmIK("l", targetWorld2);
				Vector2 val12 = ArmIK("r", targetWorld2);
				Blend("upperarm_l", val11.x, 0f, 0f, w12);
				Blend("forearm_l", val11.y, 0f, 0f, w12);
				Blend("upperarm_r", val12.x, 0f, 0f, w12);
				Blend("forearm_r", val12.y, 0f, 0f, w12);
				break;
			}
			case State.PickUp:
			{
				float w7 = Smooth(0f, 0.45f, num) * (1f - Smooth(0.55f, 0.75f, num));
				float w8 = Smooth(0.55f, 0.75f, num) * (1f - Smooth(1f, 1.3f, num));
				Vector3 targetWorld = (Object.op_Implicit((Object)(object)tidyItem) ? tidyItem.midPoint : (J["torso"].position + ((Component)this).transform.forward * 0.6f - Vector3.up * 0.6f));
				Vector2 val7 = ArmIK("l", targetWorld);
				Vector2 val8 = ArmIK("r", targetWorld);
				Vector2 val9 = ArmIK("r", slots[0].position + Vector3.up * 0.1f);
				Blend("upperarm_l", val7.x, 0f, 0f, w7);
				Blend("forearm_l", val7.y, 0f, 0f, w7);
				Blend("upperarm_r", val8.x, 0f, 0f, w7);
				Blend("forearm_r", val8.y, 0f, 0f, w7);
				Blend("upperarm_r", val9.x, 0f, 0f, w8);
				Blend("forearm_r", val9.y, 0f, 0f, w8);
				break;
			}
			case State.Dazed:
			{
				float w6 = Smooth(0f, 0.3f, num);
				Blend("upperarm_l", 4f, 0f, -10f, w6);
				Blend("forearm_l", -15f, 0f, 0f, w6);
				Blend("upperarm_r", 4f, 0f, 10f, w6);
				Blend("forearm_r", -15f, 0f, 0f, w6);
				break;
			}
			}
			array = new string[4] { "upperarm_l", "forearm_l", "upperarm_r", "forearm_r" };
			foreach (string j2 in array)
			{
				Apply(j2);
			}
			if (Object.op_Implicit((Object)(object)bookR) && bookR.enabled != flag3)
			{
				bookR.enabled = flag3;
			}
			float tg4 = 1f;
			Color val13 = EyeCalm;
			if (state == State.Alert || state == State.Warn)
			{
				tg4 = 1.7f;
			}
			if (state == State.Charge || state == State.Gag)
			{
				val13 = EyeAngry;
				tg4 = 1.6f;
			}
			if (state == State.Dazed)
			{
				tg4 = ((Mathf.PerlinNoise(t * 14f, 1f) > 0.5f) ? 0.6f : 0.05f);
			}
			if (state == State.Spawn)
			{
				tg4 = Smooth(0.1f, 1f, num);
			}
			eyeGlow = Damp(eyeGlow, tg4, 12f, dt);
			eyeColor = Color.Lerp(eyeColor, val13, 1f - Mathf.Exp(-8f * dt));
			if (Object.op_Implicit((Object)(object)headR) && eyeMat >= 0)
			{
				eyeMpb.SetColor(EmissionId, eyeColor * eyeGlow);
				headR.SetPropertyBlock(eyeMpb, eyeMat);
			}
			if (Object.op_Implicit((Object)(object)eyeLight))
			{
				eyeLight.intensity = 0.7f * eyeGlow;
				eyeLight.color = Color.Lerp(new Color(1f, 0.25f, 0.2f), new Color(0.4f, 1f, 0.9f), (val13 == EyeCalm) ? 1f : 0f);
			}
		}
	}
	internal static class Gag
	{
		private static readonly Dictionary<int, GameObject> tapes = new Dictionary<int, GameObject>();

		public static void Apply(PlayerAvatar p, float duration)
		{
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_015f: 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)
			if (!Object.op_Implicit((Object)(object)p))
			{
				return;
			}
			PlayerVoiceChat val = p.voiceChat;
			if (!Object.op_Implicit((Object)(object)val))
			{
				PlayerVoiceChat[] array = Object.FindObjectsOfType<PlayerVoiceChat>();
				foreach (PlayerVoiceChat val2 in array)
				{
					if ((Object)(object)val2.playerAvatar == (Object)(object)p)
					{
						val = val2;
						break;
					}
				}
			}
			if (Object.op_Implicit((Object)(object)val))
			{
				val.OverrideMute(duration);
			}
			int viewID = p.photonView.ViewID;
			if (tapes.TryGetValue(viewID, out var value) && Object.op_Implicit((Object)(object)value))
			{
				Object.Destroy((Object)(object)value);
			}
			if (p.isLocal)
			{
				SemiFunc.UIFocusText(Lang.M("gag", Mathf.RoundToInt(duration)), new Color(1f, 0.85f, 0.4f), new Color(1f, 0.3f, 0.2f), 4f);
				return;
			}
			Transform val3 = ((!Object.op_Implicit((Object)(object)p.playerAvatarVisuals)) ? null : (Object.op_Implicit((Object)(object)p.playerAvatarVisuals.attachPointJawTop) ? p.playerAvatarVisuals.attachPointJawTop : p.playerAvatarVisuals.headLookAtTransform));
			if (Object.op_Implicit((Object)(object)val3) && !((Object)(object)PrefabBuilder.TapeMesh == (Object)null))
			{
				GameObject val4 = new GameObject("Bibliothecaire Tape");
				val4.transform.SetParent(val3, false);
				val4.transform.localPosition = new Vector3(0f, -0.02f, 0.12f);
				val4.transform.localRotation = Quaternion.identity;
				val4.AddComponent<MeshFilter>().sharedMesh = PrefabBuilder.TapeMesh;
				MeshRenderer obj = val4.AddComponent<MeshRenderer>();
				((Renderer)obj).sharedMaterial = PrefabBuilder.Materials[0];
				((Renderer)obj).shadowCastingMode = (ShadowCastingMode)0;
				tapes[viewID] = val4;
				Object.Destroy((Object)(object)val4, duration);
			}
		}
	}
	public class CartShrink : MonoBehaviour
	{
		private Vector3 original;

		private float target = 1f;

		private float current = 1f;

		private MonoBehaviour owner;

		internal static void Set(GameObject go, float factor, MonoBehaviour owner)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)go))
			{
				return;
			}
			CartShrink cartShrink = go.GetComponent<CartShrink>();
			if (!Object.op_Implicit((Object)(object)cartShrink))
			{
				if (factor >= 0.999f)
				{
					return;
				}
				cartShrink = go.AddComponent<CartShrink>();
				cartShrink.original = go.transform.localScale;
			}
			cartShrink.target = Mathf.Clamp(factor, 0.3f, 1f);
			cartShrink.owner = owner;
		}

		private void Update()
		{
			//IL_004e: 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_0084: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)owner) || !((Behaviour)owner).isActiveAndEnabled)
			{
				target = 1f;
			}
			current = Mathf.MoveTowards(current, target, Time.deltaTime * 1.2f);
			((Component)this).transform.localScale = original * current;
			if (target >= 0.999f && current >= 0.999f)
			{
				((Component)this).transform.localScale = original;
				Object.Destroy((Object)(object)this);
			}
		}

		private void OnDestroy()
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)this) && Object.op_Implicit((Object)(object)((Component)this).transform))
			{
				((Component)this).transform.localScale = original;
			}
		}
	}
	internal static class Lang
	{
		internal static readonly string[] Codes = new string[21]
		{
			"en", "fr", "de", "es", "es-419", "it", "pt", "pt-BR", "ru", "uk",
			"pl", "tr", "ja", "ko", "zh-Hans", "zh-Hant", "ar", "da", "fi", "sv",
			"th"
		};

		internal static ConfigEntry<string> Cfg;

		private static string code = "en";

		private static float codeAt = -99f;

		private static float nextTick;

		internal static readonly Dictionary<s