Decompiled source of Forger v1.0.0

Faussaire.dll

Decompiled 38 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.AI;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;

[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 Faussaire
{
	public class FaussaireAI : MonoBehaviour
	{
		public enum State
		{
			Spawn,
			Disguised,
			Reveal,
			Hunt,
			Recover,
			Stunned
		}

		private Enemy enemy;

		private PhotonView photonView;

		private EnemyHealth health;

		private EnemyRigidbody erb;

		private PhysGrabObject pgo;

		private MapCustom mapCustom;

		private ValuableDiscoverCustom discover;

		private bool lootLookConfigured;

		private Transform model;

		private Transform lid;

		private Transform teethLower;

		private Transform teethUpper;

		private Transform tongue;

		private Transform eye;

		private Renderer teethLowerR;

		private Renderer teethUpperR;

		private Renderer eyeR;

		private Light eyeLight;

		private GameObject hurtGO;

		private HurtCollider hurt;

		private Transform deathFx;

		private Transform rotationT;

		private Renderer[] renderers;

		private MaterialPropertyBlock mpb;

		private bool ready;

		public State state;

		private bool stateImpulse = true;

		private float stateTimer;

		private PlayerAvatar target;

		private float grabTime;

		private float biteCooldown;

		private float retargetTimer;

		private float twitchTimer;

		private float warpTimer;

		private bool revealBiteDone;

		private const float FootOffset = 0.155f;

		private float leapCooldown;

		private float blockedTimer;

		private float huntElapsed;

		private int leapPhase;

		private Vector3 leapDir;

		private Vector3 leapStartPos;

		private float leapClearY;

		private float leapLandY;

		private float leapReach;

		private float leapTimer;

		private float leapElapsed;

		private static readonly RaycastHit[] rayBuf = (RaycastHit[])(object)new RaycastHit[12];

		private static int obstacleMask = -1;

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

		private float t;

		private float lidAngle;

		private float teethS;

		private float tongueOut;

		private float eyeOpen;

		private float lightI;

		private float biteAnim;

		private float twitchAnim;

		private float hurtFlash;

		private float leapAnim;

		private Quaternion eyeRot = Quaternion.identity;

		private Vector3 lastBodyPos;

		private float bodySpeed;

		private float hopP;

		private float landSquash;

		private bool hopping;

		private int fakeValue;

		private bool flashApplied;

		internal static float SkipTeleportUntil;

		private static int lastDisguisedGrabFrame = -100;

		private static readonly int ColorId = Shader.PropertyToID("_Color");

		public static bool HideEnemyNameNow => Time.frameCount - lastDisguisedGrabFrame <= 1;

		private void Awake()
		{
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Expected O, but got Unknown
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: 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>();
			pgo = ((Component)erb).GetComponent<PhysGrabObject>();
			mapCustom = ((Component)erb).GetComponent<MapCustom>();
			discover = ((Component)erb).GetComponent<ValuableDiscoverCustom>();
			model = parent.Find("[VISUALS]/FaussaireModel");
			lid = model.Find("LidPivot");
			teethLower = model.Find("TeethLower");
			teethUpper = lid.Find("TeethUpper");
			tongue = model.Find("Tongue");
			eye = lid.Find("Eye");
			teethLowerR = ((Component)teethLower).GetComponent<Renderer>();
			teethUpperR = ((Component)teethUpper).GetComponent<Renderer>();
			eyeR = ((Component)eye).GetComponent<Renderer>();
			eyeLight = ((Component)eye).GetComponentInChildren<Light>(true);
			Transform val = model.Find("Hurt Collider");
			if (Object.op_Implicit((Object)(object)val))
			{
				hurtGO = ((Component)val).gameObject;
				hurt = ((Component)val).GetComponent<HurtCollider>();
			}
			deathFx = parent.parent.Find("Other/Death Effect");
			rotationT = ((Component)this).transform.Find("Move Offset/Back Away Offset/Rotation");
			renderers = ((Component)model).GetComponentsInChildren<Renderer>(true);
			mpb = 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)lid) && Object.op_Implicit((Object)(object)erb) && Object.op_Implicit((Object)(object)pgo);
			if (!ready)
			{
				Plugin.Log.LogError((object)"FaussaireAI: hierarchy incomplete, behaviour disabled.");
			}
			All.Add(this);
		}

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

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

		private void Start()
		{
			int num = (Object.op_Implicit((Object)(object)photonView) ? photonView.ViewID : ((Object)this).GetInstanceID());
			int num2 = Mathf.Min(Plugin.CfgFakeValueMin.Value, Plugin.CfgFakeValueMax.Value);
			int num3 = Mathf.Max(Plugin.CfgFakeValueMin.Value, Plugin.CfgFakeValueMax.Value);
			Random random = new Random(num * 7919 + 17);
			fakeValue = Mathf.RoundToInt(Mathf.Lerp((float)num2, (float)num3, (float)random.NextDouble()) / 50f) * 50;
			ResetVisuals();
		}

		private void OnEnable()
		{
			ResetVisuals();
			SetLootVisible(disguised: true);
			SetMonsterTag(Revealed(state));
		}

		private void OnDisable()
		{
			SetLootVisible(disguised: false);
		}

		private static bool Revealed(State s)
		{
			if (s != State.Disguised)
			{
				return s != State.Spawn;
			}
			return false;
		}

		private void SetMonsterTag(bool on)
		{
			if (Object.op_Implicit((Object)(object)enemy) && Object.op_Implicit((Object)(object)enemy.EnemyParent))
			{
				GameObject gameObject = ((Component)enemy.EnemyParent).gameObject;
				EnemyChecklist component = gameObject.GetComponent<EnemyChecklist>();
				if (on && !Object.op_Implicit((Object)(object)component))
				{
					gameObject.AddComponent<EnemyChecklist>();
				}
				else if (!on && Object.op_Implicit((Object)(object)component))
				{
					Object.Destroy((Object)(object)component);
				}
			}
		}

		private void ConfigureLootLook()
		{
			//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_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_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)
			if ((Object)(object)Map.Instance == (Object)null || (Object)(object)ValuableDiscover.instance == (Object)null)
			{
				return;
			}
			lootLookConfigured = true;
			try
			{
				if (Object.op_Implicit((Object)(object)mapCustom) && Object.op_Implicit((Object)(object)Map.Instance.ValuableObject))
				{
					MapValuable component = Map.Instance.ValuableObject.GetComponent<MapValuable>();
					if (Object.op_Implicit((Object)(object)component))
					{
						mapCustom.sprite = component.spriteSmall;
						if (Object.op_Implicit((Object)(object)component.spriteRenderer))
						{
							mapCustom.color = component.spriteRenderer.color;
						}
					}
				}
				if (Object.op_Implicit((Object)(object)discover) && Object.op_Implicit((Object)(object)ValuableDiscover.instance.graphicPrefab))
				{
					ValuableDiscoverGraphic component2 = ValuableDiscover.instance.graphicPrefab.GetComponent<ValuableDiscoverGraphic>();
					if (Object.op_Implicit((Object)(object)component2))
					{
						discover.colorCorner = component2.colorDiscoverCorner;
						discover.colorMiddle = component2.colorDiscoverMiddle;
						discover.waitTime = component2.waitTime;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Faussaire: could not copy the loot look: " + ex.Message));
			}
		}

		private void SetLootVisible(bool disguised)
		{
			if (!Object.op_Implicit((Object)(object)discover))
			{
				return;
			}
			if (disguised)
			{
				discover.discovered = false;
				return;
			}
			discover.discovered = true;
			if (Object.op_Implicit((Object)(object)mapCustom))
			{
				mapCustom.Hide();
			}
		}

		private void ResetVisuals()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			lidAngle = (teethS = (tongueOut = (eyeOpen = (lightI = (biteAnim = (twitchAnim = (hurtFlash = (leapAnim = 0f))))))));
			leapPhase = 0;
			blockedTimer = 0f;
			hopP = (landSquash = (bodySpeed = 0f));
			hopping = false;
			if (Object.op_Implicit((Object)(object)erb))
			{
				lastBodyPos = ((Component)erb).transform.position;
			}
			if (Object.op_Implicit((Object)(object)hurtGO))
			{
				hurtGO.SetActive(false);
			}
		}

		private void Update()
		{
			if (ready)
			{
				float deltaTime = Time.deltaTime;
				t += deltaTime;
				if (!lootLookConfigured)
				{
					ConfigureLootLook();
				}
				if (SemiFunc.IsMasterClientOrSingleplayer())
				{
					MasterLogic(deltaTime);
				}
				LocalLogic();
				Animate(deltaTime);
			}
		}

		private void MasterLogic(float dt)
		{
			//IL_016f: 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)
			if (biteCooldown > 0f)
			{
				biteCooldown -= dt;
			}
			if (enemy.IsStunned() && state != State.Stunned)
			{
				SetState(State.Stunned);
			}
			FaceTarget(dt);
			switch (state)
			{
			case State.Spawn:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1f;
				}
				stateTimer -= dt;
				if (stateTimer <= 0f)
				{
					SetState(State.Disguised);
				}
				break;
			case State.Disguised:
				if (stateImpulse)
				{
					stateImpulse = false;
					grabTime = 0f;
					twitchTimer = Random.Range(9f, 18f);
					StopAgentHere();
				}
				enemy.NavMeshAgent.Stop(0.2f);
				erb.DisableFollowPosition(0.3f, 5f);
				erb.DisableFollowRotation(0.3f, 5f);
				erb.WarpDisable(0.3f);
				erb.DeactivateCustomGravity(0.3f);
				warpTimer -= dt;
				if (warpTimer <= 0f)
				{
					warpTimer = 0.25f;
					if (Vector3.Distance(((Component)enemy.NavMeshAgent).transform.position, ((Component)erb).transform.position) > 0.2f)
					{
						StopAgentHere();
					}
				}
				if (pgo.playerGrabbing.Count > 0)
				{
					grabTime += dt;
					if (grabTime >= Plugin.CfgRevealGrabTime.Value)
					{
						target = pgo.playerGrabbing[0].playerAvatar;
						SetState(State.Reveal);
						break;
					}
				}
				else
				{
					grabTime = Mathf.Max(0f, grabTime - dt * 2f);
				}
				twitchTimer -= dt;
				if (twitchTimer <= 0f)
				{
					twitchTimer = Random.Range(9f, 18f);
					Send("FaussaireTwitchRPC");
				}
				break;
			case State.Reveal:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 0.8f;
					revealBiteDone = false;
					if (Object.op_Implicit((Object)(object)target))
					{
						Pull(target, Plugin.CfgPullForce.Value);
					}
					erb.GrabRelease(true, 0.6f);
				}
				stateTimer -= dt;
				if (!revealBiteDone && stateTimer < 0.35f)
				{
					revealBiteDone = true;
					Bite();
				}
				if (stateTimer <= 0f)
				{
					SetState(State.Hunt);
				}
				break;
			case State.Hunt:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = Plugin.CfgHuntDuration.Value;
					retargetTimer = 0f;
					huntElapsed = 0f;
				}
				HuntTick(dt);
				break;
			case State.Recover:
				if (stateImpulse)
				{
					stateImpulse = false;
					stateTimer = 1.4f;
					enemy.NavMeshAgent.ResetPath();
				}
				enemy.NavMeshAgent.Stop(0.2f);
				stateTimer -= dt;
				if (stateTimer <= 0f)
				{
					SetState(State.Disguised);
				}
				break;
			case State.Stunned:
				if (stateImpulse)
				{
					stateImpulse = false;
				}
				if (!enemy.IsStunned())
				{
					SetState(State.Recover);
				}
				break;
			}
		}

		private void HuntTick(float dt)
		{
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			stateTimer -= dt;
			if (stateTimer <= 0f)
			{
				SetState(State.Recover);
				return;
			}
			if (pgo.playerGrabbing.Count > 0 && biteCooldown <= 0f)
			{
				target = pgo.playerGrabbing[0].playerAvatar;
				Pull(target, Plugin.CfgPullForce.Value * 0.6f);
				erb.GrabRelease(true, 0.4f);
				Bite();
			}
			ObstacleTick(dt);
			retargetTimer -= dt;
			if (retargetTimer > 0f)
			{
				return;
			}
			retargetTimer = 0.2f;
			if (!ValidTarget(target))
			{
				PlayerAvatar p = SemiFunc.PlayerGetNearestPlayerAvatarWithinRange(10f, ((Component)erb).transform.position, false, default(LayerMask));
				if (!ValidTarget(p))
				{
					SetState(State.Recover);
					return;
				}
				SetTarget(p);
			}
			Vector3 val = Vector3.ProjectOnPlane(((Component)target).transform.position - ((Component)erb).transform.position, Vector3.up);
			if (((Vector3)(ref val)).magnitude > 15f)
			{
				SetState(State.Recover);
				return;
			}
			enemy.NavMeshAgent.SetDestination(((Component)target).transform.position);
			enemy.NavMeshAgent.OverrideAgent(Plugin.CfgHuntSpeed.Value, 30f, 0.3f);
			if (((Vector3)(ref val)).magnitude < 1.35f && biteCooldown <= 0f)
			{
				Bite();
				if (Object.op_Implicit((Object)(object)erb.rb))
				{
					erb.rb.AddForce(((Vector3)(ref val)).normalized * 2.5f + Vector3.up * 1.6f, (ForceMode)1);
				}
			}
		}

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

		private void ObstacleTick(float dt)
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: 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_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029f: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			if (leapCooldown > 0f)
			{
				leapCooldown -= dt;
			}
			huntElapsed += dt;
			Rigidbody rb = erb.rb;
			if (leapPhase != 0 || !Object.op_Implicit((Object)(object)rb) || !ValidTarget(target) || pgo.playerGrabbing.Count > 0)
			{
				blockedTimer = 0f;
				return;
			}
			Vector3 position = rb.position;
			float num = position.y - 0.155f;
			Vector3 linearVelocity = rb.linearVelocity;
			Vector2 val = new Vector2(linearVelocity.x, linearVelocity.z);
			float magnitude = ((Vector2)(ref val)).magnitude;
			Vector3 position2 = ((Component)enemy.NavMeshAgent).transform.position;
			Vector3 val2 = Flat(position2 - position);
			Vector3 position3 = ((Component)target).transform.position;
			Vector3 val3 = Flat(position3 - position);
			float magnitude2 = ((Vector3)(ref val3)).magnitude;
			bool flag = ((Vector3)(ref val2)).magnitude > 0.6f && magnitude < 0.6f && magnitude2 > 1.4f;
			blockedTimer = (flag ? (blockedTimer + dt) : Mathf.Max(0f, blockedTimer - 2f * dt));
			if (leapCooldown > 0f || huntElapsed < 0.6f || (enemy.HasGrounded && Object.op_Implicit((Object)(object)enemy.Grounded) && !enemy.Grounded.grounded) || Mathf.Abs(linearVelocity.y) > 0.8f)
			{
				return;
			}
			NavMeshAgent agent = enemy.NavMeshAgent.Agent;
			Vector3 val4 = Flat(enemy.NavMeshAgent.GetDestination() - position);
			float num2 = position3.y - num;
			if (Object.op_Implicit((Object)(object)agent) && !agent.pathPending && ((Vector3)(ref val4)).magnitude < 1f && magnitude2 > 1.3f && magnitude2 < 4.5f && num2 > -2f && num2 < 1.5f)
			{
				float num3 = ClearHeight(position, val3, magnitude2 - 0.45f);
				if (num3 >= 0f)
				{
					StartLeap(val3, num3, num2, magnitude2 - 0.6f);
					leapCooldown = 1.3f;
					return;
				}
			}
			if (blockedTimer > 0.3f)
			{
				Vector3 dir = ((((Vector3)(ref val2)).sqrMagnitude > 0.04f) ? val2 : val3);
				float num4 = Mathf.Max(0f, position2.y - num);
				float num5 = ClearHeight(position, dir, 0.9f);
				if (num5 >= 0f)
				{
					StartLeap(dir, Mathf.Max(num5, num4), num4, Mathf.Clamp(((Vector3)(ref val2)).magnitude, 0.8f, 1.6f));
					leapCooldown = 0.9f;
				}
				else
				{
					blockedTimer = 0f;
					leapCooldown = 0.5f;
				}
			}
		}

		private float ClearHeight(Vector3 body, Vector3 dir, float dist)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			dist = Mathf.Clamp(dist, 0.4f, 2.5f);
			Vector3 val = Flat(dir);
			dir = ((Vector3)(ref val)).normalized;
			Vector3 val2 = default(Vector3);
			((Vector3)(ref val2))..ctor(body.x, body.y - 0.155f, body.z);
			bool flag = false;
			for (int i = 0; i < 9; i++)
			{
				float num = 0.08f + (float)i * 0.2f;
				if (RayBlocked(val2 + Vector3.up * num, dir, dist))
				{
					flag = true;
				}
				else if (flag)
				{
					return num - 0.1f;
				}
			}
			if (!flag)
			{
				return 0f;
			}
			return -1f;
		}

		private bool RayBlocked(Vector3 origin, Vector3 dir, float dist)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (obstacleMask == -1)
			{
				obstacleMask = LayerMask.GetMask(new string[5] { "Default", "PhysGrabObject", "PhysGrabObjectCart", "PhysGrabObjectHinge", "StaticGrabObject" });
			}
			int num = Physics.RaycastNonAlloc(origin, dir, rayBuf, dist, obstacleMask, (QueryTriggerInteraction)1);
			for (int i = 0; i < num; i++)
			{
				Collider collider = ((RaycastHit)(ref rayBuf[i])).collider;
				if (Object.op_Implicit((Object)(object)collider) && (Object)(object)collider.attachedRigidbody != (Object)(object)erb.rb)
				{
					return true;
				}
			}
			return false;
		}

		private float EffectiveGravity(Rigidbody rb)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f - Physics.gravity.y;
			if (erb.gravity && erb.customGravity > 0f && rb.useGravity)
			{
				num += erb.customGravity / Mathf.Max(0.1f, rb.mass);
			}
			return Mathf.Max(1f, num);
		}

		private void StartLeap(Vector3 dir, float clearTop, float landDy, float reach)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = erb.rb;
			float num = EffectiveGravity(rb);
			float num2 = rb.position.y - 0.155f;
			float num3 = Mathf.Clamp(Mathf.Max(clearTop + 0.25f, landDy + 0.3f), 0.4f, 1.7f);
			float num4 = Mathf.Sqrt(2f * num * num3);
			float num5 = num4 / num + Mathf.Sqrt(2f * Mathf.Max(0.05f, num3 - landDy) / num);
			reach = Mathf.Max(0.5f, reach);
			Vector3 val = Flat(dir);
			leapDir = ((Vector3)(ref val)).normalized;
			leapStartPos = rb.position;
			leapClearY = num2 + clearTop + 0.12f;
			leapLandY = num2 + landDy;
			leapReach = reach;
			leapElapsed = 0f;
			leapTimer = num5 + 0.4f;
			bool flag = clearTop > 0.05f;
			leapPhase = (flag ? 1 : 2);
			float num6 = Mathf.Clamp(reach / num5, 0.8f, 5f) * (flag ? 0.25f : 1f);
			rb.linearVelocity = leapDir * num6 + Vector3.up * num4;
			erb.DisableFollowPosition(num5 + 0.15f, 10f);
			erb.WarpDisable(num5 + 0.5f);
			if (enemy.HasJump && Object.op_Implicit((Object)(object)enemy.Jump))
			{
				enemy.Jump.StuckDisable(num5 + 0.5f);
			}
			enemy.StuckCount = 0;
			blockedTimer = 0f;
			Send("FaussaireLeapRPC");
			Plugin.Log.LogDebug((object)$"[Faussaire] leap: obstacle {clearTop:0.00} m, land {landDy:0.00} m, reach {reach:0.00} m, apex {num3:0.00} m");
		}

		private void LeapFixed(Rigidbody rb, float dt)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0088: 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)
			//IL_00b0: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: 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_011f: 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_017a: Unknown result type (might be due to invalid IL or missing references)
			leapTimer -= dt;
			leapElapsed += dt;
			Vector3 linearVelocity = rb.linearVelocity;
			float num = rb.position.y - 0.155f;
			if (leapPhase == 1 && (num >= leapClearY || linearVelocity.y <= 0.3f))
			{
				leapPhase = 2;
				float num2 = EffectiveGravity(rb);
				float num3 = Mathf.Max(0f, num - leapLandY);
				float num4 = (linearVelocity.y + Mathf.Sqrt(Mathf.Max(0f, linearVelocity.y * linearVelocity.y + 2f * num2 * num3))) / num2;
				Vector3 val = Flat(rb.position - leapStartPos);
				float magnitude = ((Vector3)(ref val)).magnitude;
				float num5 = Mathf.Clamp(Mathf.Max(0.35f, leapReach - magnitude) / Mathf.Max(0.15f, num4), 1f, 5f);
				rb.linearVelocity = leapDir * num5 + Vector3.up * linearVelocity.y;
			}
			bool flag = !enemy.HasGrounded || !Object.op_Implicit((Object)(object)enemy.Grounded) || enemy.Grounded.grounded;
			if (leapTimer <= 0f || (leapElapsed > 0.2f && flag && linearVelocity.y <= 0.1f))
			{
				leapPhase = 0;
			}
		}

		private void FaceTarget(float dt)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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)
			if (Object.op_Implicit((Object)(object)rotationT) && Object.op_Implicit((Object)(object)target) && (state == State.Reveal || state == State.Hunt))
			{
				Vector3 val = Vector3.ProjectOnPlane(((Component)target).transform.position - ((Component)erb).transform.position, Vector3.up);
				if (!(((Vector3)(ref val)).sqrMagnitude < 0.01f))
				{
					Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
					float num = ((state == State.Reveal) ? 25f : 10f);
					rotationT.rotation = Quaternion.Slerp(rotationT.rotation, val2, 1f - Mathf.Exp((0f - num) * dt));
				}
			}
		}

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

		private void StopAgentHere()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			enemy.NavMeshAgent.Warp(((Component)erb).transform.position, false);
			enemy.NavMeshAgent.ResetPath();
		}

		private void Pull(PlayerAvatar p, float force)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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)
			//IL_0052: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)p) && !(force <= 0f))
			{
				Vector3 val = Vector3.ProjectOnPlane(((Component)erb).transform.position - ((Component)p).transform.position, Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				p.ForceImpulse(normalized * force + Vector3.up * force * 0.2f);
			}
		}

		private void Bite()
		{
			biteCooldown = 1.1f;
			Send("FaussaireBiteRPC");
		}

		private void SetState(State s)
		{
			if (s != state)
			{
				ApplyState(s, target);
				if (GameManager.Multiplayer())
				{
					photonView.RPC("FaussaireStateRPC", (RpcTarget)1, new object[2]
					{
						(int)s,
						Object.op_Implicit((Object)(object)target) ? target.photonView.ViewID : (-1)
					});
				}
			}
		}

		private void SetTarget(PlayerAvatar p)
		{
			target = p;
			if (GameManager.Multiplayer())
			{
				photonView.RPC("FaussaireStateRPC", (RpcTarget)1, new object[2]
				{
					(int)state,
					Object.op_Implicit((Object)(object)p) ? p.photonView.ViewID : (-1)
				});
			}
		}

		private void Send(string rpc)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			if (GameManager.Multiplayer())
			{
				photonView.RPC(rpc, (RpcTarget)0, Array.Empty<object>());
				return;
			}
			switch (rpc)
			{
			case "FaussaireBiteRPC":
				FaussaireBiteRPC();
				break;
			case "FaussaireTwitchRPC":
				FaussaireTwitchRPC();
				break;
			case "FaussaireLeapRPC":
				FaussaireLeapRPC();
				break;
			}
		}

		[PunRPC]
		private void FaussaireLeapRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				leapAnim = 0.6f;
				Sounds.Play(Sounds.Clink, ((Component)erb).transform.position, 0.6f);
			}
		}

		[PunRPC]
		private void FaussaireStateRPC(int s, int targetViewID, PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (!SemiFunc.MasterOnlyRPC(info))
			{
				return;
			}
			PlayerAvatar p = null;
			if (targetViewID >= 0)
			{
				PhotonView val = PhotonView.Find(targetViewID);
				if (Object.op_Implicit((Object)(object)val))
				{
					p = ((Component)val).GetComponent<PlayerAvatar>();
				}
			}
			if (s == (int)state)
			{
				target = p;
			}
			else
			{
				ApplyState((State)s, p);
			}
		}

		private void ApplyState(State s, PlayerAvatar p)
		{
			//IL_004c: 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_0051: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			State state = this.state;
			this.state = s;
			target = p;
			stateImpulse = true;
			stateTimer = 0f;
			Vector3 pos = (Object.op_Implicit((Object)(object)erb) ? ((Component)erb).transform.position : ((Component)this).transform.position);
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				Plugin.Log.LogInfo((object)($"[Faussaire] {state} -> {s}" + (Object.op_Implicit((Object)(object)p) ? (" (target: " + p.playerName + ")") : "")));
			}
			if (s == State.Disguised || s == State.Spawn)
			{
				if (state != State.Disguised && state != State.Spawn)
				{
					SetLootVisible(disguised: true);
				}
			}
			else
			{
				SetLootVisible(disguised: false);
			}
			SetMonsterTag(Revealed(s));
			if (s != State.Hunt)
			{
				leapPhase = 0;
			}
			switch (s)
			{
			case State.Reveal:
				Sounds.Play(Sounds.Reveal, pos);
				Sounds.Play(Sounds.TongueOut, pos, 0.8f);
				break;
			case State.Recover:
				if (state == State.Hunt || state == State.Reveal)
				{
					Sounds.Play(Sounds.TongueIn, pos, 0.8f);
				}
				break;
			case State.Disguised:
				if (state == State.Recover)
				{
					Sounds.Play(Sounds.Clink, pos, 0.7f);
				}
				break;
			case State.Stunned:
				Sounds.Play(Sounds.Stun, pos);
				break;
			case State.Hunt:
				break;
			}
		}

		[PunRPC]
		private void FaussaireBiteRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				biteAnim = 0.32f;
				Sounds.Play(Sounds.Bite, ((Component)erb).transform.position);
				if (Object.op_Implicit((Object)(object)hurtGO))
				{
					((MonoBehaviour)this).StartCoroutine(BiteWindow());
				}
			}
		}

		[PunRPC]
		private void FaussaireTwitchRPC(PhotonMessageInfo info = default(PhotonMessageInfo))
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (SemiFunc.MasterOnlyRPC(info))
			{
				twitchAnim = 0.4f;
				Sounds.Play(Sounds.Clink, ((Component)erb).transform.position, 0.55f);
			}
		}

		private IEnumerator BiteWindow()
		{
			yield return (object)new WaitForSeconds(0.07f);
			if (Object.op_Implicit((Object)(object)hurt))
			{
				hurt.playerDamage = Plugin.CfgBiteDamage.Value;
			}
			hurtGO.SetActive(true);
			yield return (object)new WaitForSeconds(0.22f);
			hurtGO.SetActive(false);
		}

		private void OnSpawn()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			ResetVisuals();
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			bool num = Time.time < SkipTeleportUntil;
			if (num)
			{
				SkipTeleportUntil = 0f;
			}
			string text = (num ? "placed" : null);
			if (text == null && TryFindLootSpot(15f, out var pos, out var _))
			{
				enemy.EnemyTeleported(pos);
				text = "next to loot";
			}
			if (text == null && SemiFunc.EnemySpawn(enemy))
			{
				text = "level point";
			}
			if (text != null)
			{
				Plugin.Log.LogInfo((object)("[Faussaire] Spawned at " + ((object)((Component)erb).transform.position/*cast due to .constrained prefix*/).ToString() + " (" + text + ")"));
				target = null;
				if (state == State.Spawn)
				{
					stateImpulse = true;
					stateTimer = 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;
			SetState(State.Spawn);
		}

		internal static bool TryFindLootSpot(float minPlayerDist, out Vector3 pos, out Quaternion rot)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e2: 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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: 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_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: 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)
			pos = Vector3.zero;
			rot = Quaternion.identity;
			ValuableDirector instance = ValuableDirector.instance;
			if ((Object)(object)instance == (Object)null || instance.valuableList == null || instance.valuableList.Count == 0)
			{
				return false;
			}
			List<PlayerAvatar> list = SemiFunc.PlayerGetList();
			List<Vector3> list2 = new List<Vector3>();
			foreach (ValuableObject valuable in instance.valuableList)
			{
				if (!Object.op_Implicit((Object)(object)valuable) || !((Component)valuable).gameObject.activeInHierarchy)
				{
					continue;
				}
				Vector3 position = ((Component)valuable).transform.position;
				bool flag = true;
				if (list != null)
				{
					foreach (PlayerAvatar item in list)
					{
						if (Object.op_Implicit((Object)(object)item) && Vector3.Distance(((Component)item).transform.position, position) < minPlayerDist)
						{
							flag = false;
							break;
						}
					}
				}
				if (flag)
				{
					list2.Add(position);
				}
			}
			if (list2.Count == 0)
			{
				return false;
			}
			if (obstacleMask == -1)
			{
				obstacleMask = LayerMask.GetMask(new string[5] { "Default", "PhysGrabObject", "PhysGrabObjectCart", "PhysGrabObjectHinge", "StaticGrabObject" });
			}
			NavMeshHit val2 = default(NavMeshHit);
			for (int i = 0; i < 60; i++)
			{
				Vector3 val = list2[Random.Range(0, list2.Count)];
				float num = Random.Range(0f, (float)Math.PI * 2f);
				float num2 = Random.Range(0.6f, 0.95f);
				if (NavMesh.SamplePosition(val + new Vector3(Mathf.Cos(num) * num2, 0f, Mathf.Sin(num) * num2), ref val2, 0.8f, -1) && !(Mathf.Abs(((NavMeshHit)(ref val2)).position.y - val.y) > 1.2f))
				{
					Vector3 position2 = ((NavMeshHit)(ref val2)).position;
					if (!Physics.CheckCapsule(position2 + Vector3.up * 0.26f, position2 + Vector3.up * 0.5f, 0.18f, obstacleMask, (QueryTriggerInteraction)1))
					{
						pos = position2 + Vector3.up * 0.05f;
						rot = Quaternion.Euler(0f, Random.Range(0f, 360f), 0f);
						return true;
					}
				}
			}
			return false;
		}

		private void OnHurt()
		{
			//IL_001b: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			hurtFlash = 0.18f;
			Sounds.Play(Sounds.Hurt, ((Component)erb).transform.position, 0.8f);
			if (SemiFunc.IsMasterClientOrSingleplayer() && state == State.Disguised)
			{
				PlayerAvatar p = health.onObjectHurtPlayer;
				if (!ValidTarget(p))
				{
					p = SemiFunc.PlayerGetNearestPlayerAvatarWithinRange(8f, ((Component)erb).transform.position, false, default(LayerMask));
				}
				target = p;
				SetState(State.Reveal);
			}
		}

		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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)erb).transform.position;
			Sounds.Play(Sounds.Shatter, position, 1.2f);
			Sounds.Play(Sounds.Death, position, 0.9f);
			if (Object.op_Implicit((Object)(object)deathFx))
			{
				deathFx.position = position + Vector3.up * 0.15f;
				ParticleSystem[] componentsInChildren = ((Component)deathFx).GetComponentsInChildren<ParticleSystem>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					componentsInChildren[i].Play(true);
				}
			}
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				enemy.EnemyParent.Despawn();
			}
		}

		private void LocalLogic()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			if (state == State.Disguised && pgo.grabbedLocal)
			{
				lastDisguisedGrabFrame = Time.frameCount;
				if (Object.op_Implicit((Object)(object)WorldSpaceUIValue.instance))
				{
					WorldSpaceUIValue.instance.Show(pgo, fakeValue, false, Vector3.zero);
				}
			}
		}

		private void AnimateBody(float dt, bool stunned)
		{
			//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_0075: 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_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_032f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)erb).transform.position;
			if (dt > 0f)
			{
				Vector3 val = (position - lastBodyPos) / dt;
				Vector2 val2 = new Vector2(val.x, val.z);
				float num = ((Vector2)(ref val2)).magnitude;
				if (num > 20f)
				{
					num = 0f;
				}
				bodySpeed = Damp(bodySpeed, num, 6f, dt);
			}
			lastBodyPos = position;
			bool flag = (state == State.Hunt || state == State.Reveal) && bodySpeed > 0.3f;
			float num2 = Mathf.Clamp(1.7f + bodySpeed * 0.3f, 1.8f, 3f);
			float num3 = Mathf.Lerp(0.09f, 0.2f, Mathf.Clamp01(bodySpeed / 4f));
			if (flag || hopP > 0f)
			{
				hopping = true;
				hopP += dt * num2;
				if (hopP >= 1f)
				{
					hopP = (flag ? (hopP - 1f) : 0f);
					landSquash = 0.14f;
					Sounds.Play(Sounds.Clink, position, 0.3f);
					if (!flag)
					{
						hopping = false;
					}
				}
			}
			else
			{
				hopping = false;
			}
			float num4 = Mathf.Sin((float)Math.PI * hopP);
			float num5 = (hopping ? (4f * num3 * hopP * (1f - hopP)) : 0f);
			float num6 = 1f;
			float num7 = 1f;
			if (hopping)
			{
				num6 += 0.08f * num4;
				num7 -= 0.04f * num4;
			}
			if (landSquash > 0f)
			{
				landSquash -= dt;
				float num8 = Mathf.Clamp01(landSquash / 0.14f);
				num6 -= 0.2f * num8;
				num7 += 0.1f * num8;
			}
			if (state == State.Disguised)
			{
				float num9 = 0.009f * Mathf.Sin(t * 1.7f);
				num6 += num9;
				num7 -= num9 * 0.5f;
			}
			model.localScale = new Vector3(num7, num6, num7);
			model.localPosition = new Vector3(0f, -0.155f + num5, 0f);
			if (leapAnim > 0f)
			{
				leapAnim -= dt;
				float num10 = Mathf.Sin((float)Math.PI * (1f - Mathf.Clamp01(leapAnim / 0.6f)));
				num6 += 0.12f * num10;
				num7 -= 0.05f * num10;
				model.localScale = new Vector3(num7, num6, num7);
			}
			if (stunned)
			{
				model.localRotation = Quaternion.Euler(4f * Mathf.Sin(t * 17f), 0f, 4f * Mathf.Sin(t * 13f));
			}
			else if (hopping)
			{
				model.localRotation = Quaternion.Euler(9f * num4 - 4f * Mathf.Clamp01(landSquash / 0.14f), 0f, 0f);
			}
			else
			{
				model.localRotation = Quaternion.Slerp(model.localRotation, Quaternion.identity, 1f - Mathf.Exp(-10f * dt));
			}
		}

		private void FixedUpdate()
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			if (!ready || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			Rigidbody rb = erb.rb;
			if (!Object.op_Implicit((Object)(object)rb) || rb.isKinematic)
			{
				return;
			}
			if (leapPhase != 0)
			{
				if (pgo.playerGrabbing.Count > 0 || enemy.IsStunned() || state != State.Hunt)
				{
					leapPhase = 0;
				}
				else
				{
					LeapFixed(rb, Time.fixedDeltaTime);
				}
			}
			if (pgo.playerGrabbing.Count <= 0 && !enemy.IsStunned() && state != State.Disguised)
			{
				Vector3 val = Vector3.Cross(((Component)rb).transform.up, Vector3.up);
				Vector3 angularVelocity = rb.angularVelocity;
				Vector3 val2 = val * 90f - new Vector3(angularVelocity.x, 0f, angularVelocity.z) * 12f;
				rb.AddTorque(val2, (ForceMode)5);
			}
		}

		private static float Damp(float current, float target, float speed, float dt)
		{
			return Mathf.Lerp(current, target, 1f - Mathf.Exp((0f - speed) * dt));
		}

		private void Animate(float dt)
		{
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0326: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_0430: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0478: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_0496: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_046f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0569: Unknown result type (might be due to invalid IL or missing references)
			//IL_057d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0584: Unknown result type (might be due to invalid IL or missing references)
			bool flag = state == State.Reveal || state == State.Hunt;
			bool flag2 = state == State.Stunned;
			float num = 0f;
			if (state == State.Reveal)
			{
				num = 74f;
			}
			else if (state == State.Hunt)
			{
				num = (hopping ? (18f + 50f * Mathf.Sin((float)Math.PI * hopP)) : (30f + 34f * (0.5f + 0.5f * Mathf.Sin(t * 7f))));
			}
			else if (flag2)
			{
				num = 26f + 5f * Mathf.Sin(t * 13f);
			}
			if (leapAnim > 0f && state == State.Hunt)
			{
				num = 72f;
			}
			if (biteAnim > 0f)
			{
				biteAnim -= dt;
				float num2 = 1f - Mathf.Clamp01(biteAnim / 0.32f);
				num = ((num2 < 0.35f) ? 2f : Mathf.Lerp(2f, num, (num2 - 0.35f) / 0.65f));
			}
			lidAngle = Damp(lidAngle, num, (biteAnim > 0f) ? 40f : (flag ? 20f : 12f), dt);
			float num3 = 0f;
			if (twitchAnim > 0f)
			{
				twitchAnim -= dt;
				num3 = 7f * Mathf.Sin((float)Math.PI * (1f - Mathf.Clamp01(twitchAnim / 0.4f)));
			}
			lid.localRotation = Quaternion.Euler(0f - (lidAngle + num3), 0f, 0f);
			teethS = Damp(teethS, (flag || flag2) ? 1f : 0f, 10f, dt);
			float num4 = Mathf.Max(teethS, 0.001f);
			teethLower.localScale = new Vector3(1f, num4, 1f);
			teethUpper.localScale = new Vector3(1f, num4, 1f);
			bool flag3 = teethS > 0.02f;
			if (teethLowerR.enabled != flag3)
			{
				teethLowerR.enabled = flag3;
				teethUpperR.enabled = flag3;
			}
			tongueOut = Damp(tongueOut, flag ? 1f : 0f, 7f, dt);
			tongue.localPosition = Vector3.Lerp(ModelLayout.TongueInPos, ModelLayout.TongueOutPos, tongueOut);
			float num5 = Mathf.Lerp(-64f, -3f, tongueOut) + tongueOut * 5f * Mathf.Sin(t * 4.1f);
			float num6 = tongueOut * 10f * Mathf.Sin(t * 6.3f);
			tongue.localRotation = Quaternion.Euler(num5, num6, 0f);
			eyeOpen = Damp(eyeOpen, flag ? 1f : (flag2 ? 0.35f : 0f), 9f, dt);
			float num7 = Mathf.Lerp(0.35f, 1f, eyeOpen);
			eye.localScale = new Vector3(num7, num7, num7);
			if (eyeR.enabled != eyeOpen > 0.02f)
			{
				eyeR.enabled = eyeOpen > 0.02f;
			}
			Quaternion val = Quaternion.identity;
			if (Object.op_Implicit((Object)(object)target) && flag)
			{
				Vector3 val2 = ((Component)target).transform.position + Vector3.up * 1.3f;
				Vector3 val3 = lid.InverseTransformDirection(val2 - eye.position);
				val = Quaternion.RotateTowards(Quaternion.identity, Quaternion.FromToRotation(Vector3.down, val3), 55f);
			}
			else if (flag2)
			{
				val = Quaternion.Euler(25f * Mathf.Sin(t * 9f), 0f, 25f * Mathf.Cos(t * 7f));
			}
			eyeRot = Quaternion.Slerp(eyeRot, val, 1f - Mathf.Exp(-8f * dt));
			eye.localRotation = eyeRot;
			lightI = Damp(lightI, flag ? 1.4f : (flag2 ? 0.3f : 0f), 6f, dt);
			if (Object.op_Implicit((Object)(object)eyeLight))
			{
				eyeLight.intensity = lightI;
				bool flag4 = lightI > 0.02f;
				if (((Behaviour)eyeLight).enabled != flag4)
				{
					((Behaviour)eyeLight).enabled = flag4;
				}
			}
			AnimateBody(dt, flag2);
			if (hurtFlash > 0f)
			{
				hurtFlash -= dt;
				float num8 = Mathf.Clamp01(hurtFlash / 0.18f);
				mpb.SetColor(ColorId, Color.Lerp(Color.white, new Color(1f, 0.25f, 0.25f), num8));
				Renderer[] array = renderers;
				foreach (Renderer val4 in array)
				{
					if (Object.op_Implicit((Object)(object)val4))
					{
						val4.SetPropertyBlock(mpb);
					}
				}
				flashApplied = true;
			}
			else
			{
				if (!flashApplied)
				{
					return;
				}
				mpb.Clear();
				Renderer[] array = renderers;
				foreach (Renderer val5 in array)
				{
					if (Object.op_Implicit((Object)(object)val5))
					{
						val5.SetPropertyBlock(mpb);
					}
				}
				flashApplied = false;
			}
		}
	}
	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<string, string> NameTable = new Dictionary<string, string>
		{
			{ "en", "Forger" },
			{ "fr", "Faussaire" },
			{ "de", "Fälscher" },
			{ "es", "Falsificador" },
			{ "es-419", "Falsificador" },
			{ "it", "Falsario" },
			{ "pt", "Falsário" },
			{ "pt-BR", "Falsário" },
			{ "ru", "Фальсификатор" },
			{ "uk", "Фальсифікатор" },
			{ "pl", "Fałszerz" },
			{ "tr", "Sahtekâr" },
			{ "ja", "贋作師" },
			{ "ko", "위조범" },
			{ "zh-Hans", "伪造者" },
			{ "zh-Hant", "偽造者" },
			{ "ar", "المزو\u0651ر" },
			{ "da", "Falskner" },
			{ "fi", "Väärentäjä" },
			{ "sv", "Förfalskare" },
			{ "th", "น\u0e31กปลอมแปลง" }
		};

		internal const bool HasMessages = false;

		internal static string Code
		{
			get
			{
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0071: Unknown result type (might be due to invalid IL or missing references)
				if (Time.unscaledTime - codeAt < 1f)
				{
					return code;
				}
				codeAt = Time.unscaledTime;
				string text = ((Cfg != null) ? Cfg.Value : "Auto");
				if (string.IsNullOrEmpty(text) || text.Trim().Equals("Auto", StringComparison.OrdinalIgnoreCase))
				{
					text = "en";
					try
					{
						Locale selectedLocale = LocalizationSettings.SelectedLocale;
						if ((Object)(object)selectedLocale != (Object)null)
						{
							LocaleIdentifier identifier = selectedLocale.Identifier;
							text = ((LocaleIdentifier)(ref identifier)).Code;
						}
					}
					catch (Exception)
					{
					}
				}
				code = Normalize(text);
				return code;
			}
		}

		internal static string Name => Pick(NameTable);

		internal static void Bind(ConfigFile config)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			List<string> list = new List<string> { "Auto" };
			list.AddRange(Codes);
			Cfg = config.Bind<string>("Language", "Language", "Auto", new ConfigDescription("Language of this monster's in-game texts (its name when grabbed). Auto = the game's language (English if the game's language is not one of these).", (AcceptableValueBase)(object)new AcceptableValueList<string>(list.ToArray()), Array.Empty<object>()));
		}

		internal static void Tick()
		{
			if (Time.unscaledTime < nextTick)
			{
				return;
			}
			nextTick = Time.unscaledTime + 1f;
			try
			{
				string name = Name;
				if (Object.op_Implicit((Object)(object)Plugin.Prefab))
				{
					EnemyParent componentInChildren = Plugin.Prefab.GetComponentInChildren<EnemyParent>(true);
					if (Object.op_Implicit((Object)(object)componentInChildren))
					{
						componentInChildren.enemyName = name;
					}
				}
				foreach (FaussaireAI item in FaussaireAI.All)
				{
					if (Object.op_Implicit((Object)(object)item))
					{
						EnemyParent componentInParent = ((Component)item).GetComponentInParent<EnemyParent>(true);
						if (Object.op_Implicit((Object)(object)componentInParent) && componentInParent.enemyName != name)
						{
							componentInParent.enemyName = name;
						}
					}
				}
			}
			catch (Exception)
			{
			}
		}

		internal static string Normalize(string c)
		{
			c = (c ?? "en").Trim().Replace('_', '-').ToLowerInvariant();
			if (c.StartsWith("zh"))
			{
				if (!c.Contains("hant") && !c.Contains("tw") && !c.Contains("hk") && !c.Contains("mo"))
				{
					return "zh-Hans";
				}
				return "zh-Hant";
			}
			if (c.StartsWith("es"))
			{
				if (!(c == "es") && !(c == "es-es"))
				{
					return "es-419";
				}
				return "es";
			}
			if (c.StartsWith("pt"))
			{
				if (!(c == "pt-br"))
				{
					return "pt";
				}
				return "pt-BR";
			}
			string text = ((c.Length >= 2) ? c.Substring(0, 2) : c);
			if (Array.IndexOf(Codes, text) < 0)
			{
				return "en";
			}
			return text;
		}

		internal static string Pick(Dictionary<string, string> t)
		{
			if (!t.TryGetValue(Code, out var value) || string.IsNullOrEmpty(value))
			{
				return t["en"];
			}
			return value;
		}
	}
	internal static class ModelLayout
	{
		public static readonly Vector3 Hinge = new Vector3(0f, 0.3f, -0.156f);

		public static readonly Vector3 EyeInLid = new Vector3(0f, 0.099f, 0.191f);

		public static readonly Vector3 TeethLowerPivot = new Vector3(0f, 0.3f, 0f);

		public static readonly Vector3 TongueInPos = new Vector3(0f, 0.092f, -0.1f);

		public const float TongueInRotX = -64f;

		public static readonly Vector3 TongueOutPos = new Vector3(0f, 0.372f, -0.06f);

		public const float TongueOutRotX = -3f;

		public const float Seam = 0.3f;

		public const float Height = 0.56f;

		public const float RadiusMax = 0.176f;
	}
	internal static class Sounds
	{
		public static Sound Reveal;

		public static Sound Bite;

		public static Sound TongueOut;

		public static Sound TongueIn;

		public static Sound Hurt;

		public static Sound Death;

		public static Sound Notice;

		public static Sound Clink;

		public static Sound Shatter;

		public static Sound Stun;

		public static Sound StunOutro;

		public static Sound Land;

		public static void Play(Sound s, Vector3 pos, float volume = 1f)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (s == null || s.Sounds == null || s.Sounds.Length == 0)
			{
				return;
			}
			try
			{
				s.Play(pos, volume, 1f, 1f, 1f);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Sound play failed: " + ex.Message));
			}
		}
	}
	[BepInPlugin("maxime.repo.faussaire", "Faussaire", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "maxime.repo.faussaire";

		public const string NAME = "Faussaire";

		public const string VERSION = "1.0.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static ConfigEntry<int> CfgPoolWeight;

		internal static ConfigEntry<int> CfgSpawnChance;

		internal static ConfigEntry<int> CfgDifficulty;

		internal static ConfigEntry<int> CfgHealth;

		internal static ConfigEntry<int> CfgBiteDamage;

		internal static ConfigEntry<float> CfgPullForce;

		internal static ConfigEntry<float> CfgHuntDuration;

		internal static ConfigEntry<float> CfgHuntSpeed;

		internal static ConfigEntry<float> CfgRevealGrabTime;

		internal static ConfigEntry<int> CfgFakeValueMin;

		internal static ConfigEntry<int> CfgFakeValueMax;

		internal static ConfigEntry<bool> CfgDebugSpawn;

		internal static ConfigEntry<KeyCode> CfgDebugSpawnKey;

		internal const float MinPlayerDistance = 15f;

		internal static EnemySetup Setup;

		internal static GameObject Prefab;

		private static GameObject holder;

		private Harmony harmony;

		private float lastDebugSpawn = -10f;

		private LevelGenerator handledLevel;

		private float levelReadyTime = -1f;

		private float nextSpawnTry;

		private bool rolled;

		internal static GameObject Holder
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				if ((Object)(object)holder == (Object)null)
				{
					holder = new GameObject("FaussairePrefabHolder");
					holder.SetActive(false);
					((Object)holder).hideFlags = (HideFlags)61;
					Object.DontDestroyOnLoad((Object)(object)holder);
				}
				return holder;
			}
		}

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			harmony = new Harmony("maxime.repo.faussaire");
			harmony.PatchAll(typeof(Plugin).Assembly);
			try
			{
				Prefab = PrefabBuilder.Build();
				Register();
				Log.LogInfo((object)"Faussaire v1.0.0 loaded: enemy prefab built and registered with REPOLib.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Failed to build/register the Faussaire: " + ex));
			}
		}

		private void BindConfig()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Expected O, but got Unknown
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Expected O, but got Unknown
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Expected O, but got Unknown
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Expected O, but got Unknown
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_022b: Expected O, but got Unknown
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Expected O, but got Unknown
			CfgSpawnChance = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "BonusChance", 0, new ConfigDescription("Optional extra copy ON TOP of the level's monsters: chance (%) per level, only if the normal draw did not pick it. 0 = off.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			CfgPoolWeight = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "PoolWeight", 100, new ConfigDescription("Weight in the game's normal monster draw: it takes the place of a vanilla pick, never adds one. 100 = as likely as a standard vanilla monster, 0 = never drawn. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 300), Array.Empty<object>()));
			CfgDifficulty = ((BaseUnityPlugin)this).Config.Bind<int>("Spawn", "DifficultyTier", 2, new ConfigDescription("Enemy tier (1 = easy, 2 = medium, 3 = hard): size of the orb it drops. Needs a restart.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 3), Array.Empty<object>()));
			CfgHealth = ((BaseUnityPlugin)this).Config.Bind<int>("Combat", "Health", 80, new ConfigDescription("Hit points (a Gnome has 20, a Hidden 200).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 500), Array.Empty<object>()));
			CfgBiteDamage = ((BaseUnityPlugin)this).Config.Bind<int>("Combat", "BiteDamage", 20, new ConfigDescription("Damage per bite (players have 100 HP).", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			CfgPullForce = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "PullForce", 7f, new ConfigDescription("How hard the grabbing player is yanked toward the Faussaire when it reveals itself.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 40f), Array.Empty<object>()));
			CfgHuntDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "HuntDuration", 9f, new ConfigDescription("Seconds it chases after revealing itself before disguising again.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(2f, 30f), Array.Empty<object>()));
			CfgHuntSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Combat", "HuntSpeed", 4.2f, new ConfigDescription("Chase speed in m/s (players walk ~2.5, sprint ~5).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 8f), Array.Empty<object>()));
			CfgRevealGrabTime = ((BaseUnityPlugin)this).Config.Bind<float>("Disguise", "RevealGrabTime", 0.35f, new ConfigDescription("Seconds a player must hold it before the trap springs.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 3f), Array.Empty<object>()));
			CfgFakeValueMin = ((BaseUnityPlugin)this).Config.Bind<int>("Disguise", "FakeValueMin", 4000, new ConfigDescription("Minimum fake price shown when grabbed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50000), Array.Empty<object>()));
			CfgFakeValueMax = ((BaseUnityPlugin)this).Config.Bind<int>("Disguise", "FakeValueMax", 9000, new ConfigDescription("Maximum fake price shown when grabbed.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 50000), Array.Empty<object>()));
			Lang.Bind(((BaseUnityPlugin)this).Config);
			CfgDebugSpawn = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableSpawnKey", false, "Host only: press the key below during a level to bring the level's Faussaire 2.5 m in front of you (spawns it if the level has none).");
			CfgDebugSpawnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Debug", "SpawnKey", (KeyCode)291, "Debug spawn key.");
		}

		private static void Register()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Setup = ScriptableObject.CreateInstance<EnemySetup>();
			((Object)Setup).name = "Enemy - Faussaire";
			((Object)Setup).hideFlags = (HideFlags)32;
			Setup.status = (Status)1;
			Setup.spawnObjects = new List<PrefabRef>();
			Setup.levelsCompletedCondition = false;
			Setup.levelsCompletedMin = 0;
			Setup.levelsCompletedMax = 10;
			RarityPreset val = ScriptableObject.CreateInstance<RarityPreset>();
			((Object)val).name = "Faussaire Rarity";
			val.chance = Mathf.Max(1f, (float)CfgPoolWeight.Value);
			((Object)val).hideFlags = (HideFlags)32;
			Setup.rarityPreset = val;
			EnemyContent val2 = ScriptableObject.CreateInstance<EnemyContent>();
			((Object)val2).name = "Faussaire";
			((Object)val2).hideFlags = (HideFlags)32;
			AccessTools.Field(typeof(EnemyContent), "_setup").SetValue(val2, Setup);
			AccessTools.Field(typeof(EnemyContent), "_spawnObjects").SetValue(val2, new List<GameObject> { Prefab });
			Enemies.RegisterEnemy(val2);
		}

		private void Update()
		{
			BonusSpawnTick();
			DebugKeyTick();
			Lang.Tick();
		}

		private void BonusSpawnTick()
		{
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Setup == (Object)null)
			{
				return;
			}
			LevelGenerator instance = LevelGenerator.Instance;
			if ((Object)(object)instance == (Object)null || !instance.Generated)
			{
				levelReadyTime = -1f;
			}
			else
			{
				if ((Object)(object)instance == (Object)(object)handledLevel)
				{
					return;
				}
				try
				{
					if (!SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
					{
						handledLevel = instance;
						return;
					}
					if (levelReadyTime < 0f)
					{
						levelReadyTime = Time.time;
						rolled = false;
						nextSpawnTry = 0f;
						return;
					}
					float num = Time.time - levelReadyTime;
					if (num < 4f || Time.time < nextSpawnTry)
					{
						return;
					}
					nextSpawnTry = Time.time + 1f;
					if ((Object)(object)FaussaireAI.Existing() != (Object)null)
					{
						handledLevel = instance;
						Log.LogInfo((object)"[Faussaire] Level already has its Faussaire.");
						return;
					}
					if (!rolled)
					{
						rolled = true;
						int num2 = Random.Range(0, 100);
						if (num2 >= CfgSpawnChance.Value)
						{
							handledLevel = instance;
							Log.LogInfo((object)$"[Faussaire] No Faussaire in this level (roll {num2} >= {CfgSpawnChance.Value}).");
							return;
						}
					}
					string arg = "next to loot";
					if (!FaussaireAI.TryFindLootSpot(15f, out var pos, out var rot))
					{
						if (num < 29f)
						{
							return;
						}
						if (!TryFarLevelPoint(out pos))
						{
							handledLevel = instance;
							Log.LogWarning((object)"[Faussaire] No spawn spot found, skipped this level.");
							return;
						}
						rot = Quaternion.identity;
						arg = "level point";
					}
					handledLevel = instance;
					FaussaireAI.SkipTeleportUntil = Time.time + 5f;
					Enemies.SpawnEnemy(Setup, pos, rot, false);
					Log.LogInfo((object)$"[Faussaire] Level Faussaire spawned at {pos} ({arg}).");
				}
				catch (Exception ex)
				{
					handledLevel = instance;
					Log.LogError((object)("[Faussaire] Level spawn failed: " + ex));
				}
			}
		}

		private static bool TryFarLevelPoint(out Vector3 pos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00e4: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			pos = Vector3.zero;
			List<LevelPoint> list = (Object.op_Implicit((Object)(object)LevelGenerator.Instance) ? LevelGenerator.Instance.LevelPathPoints : null);
			if (list == null || list.Count == 0)
			{
				return false;
			}
			List<PlayerAvatar> list2 = SemiFunc.PlayerGetList();
			for (int i = 0; i < 40; i++)
			{
				LevelPoint val = list[Random.Range(0, list.Count)];
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				bool flag = true;
				if (list2 != null)
				{
					foreach (PlayerAvatar item in list2)
					{
						if (Object.op_Implicit((Object)(object)item) && Vector3.Distance(((Component)item).transform.position, ((Component)val).transform.position) < 15f)
						{
							flag = false;
							break;
						}
					}
				}
				if (flag)
				{
					pos = ((Component)val).transform.position + Vector3.up * 0.1f;
					return true;
				}
			}
			return false;
		}

		private void DebugKeyTick()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: 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_00b0: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_0123: 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_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			if (!CfgDebugSpawn.Value || (Object)(object)Setup == (Object)null || !Input.GetKeyDown(CfgDebugSpawnKey.Value) || Time.unscaledTime - lastDebugSpawn < 0.75f)
			{
				return;
			}
			lastDebugSpawn = Time.unscaledTime;
			try
			{
				if (!SemiFunc.IsMasterClientOrSingleplayer())
				{
					Log.LogInfo((object)"[Debug] Only the host can spawn the Faussaire.");
					return;
				}
				if (!SemiFunc.RunIsLevel() || (Object)(object)PlayerAvatar.instance == (Object)null)
				{
					Log.LogInfo((object)"[Debug] Spawn key only works inside a level.");
					return;
				}
				Transform transform = ((Component)PlayerAvatar.instance).transform;
				Vector3 val = Vector3.ProjectOnPlane(transform.forward, Vector3.up);
				Vector3 normalized = ((Vector3)(ref val)).normalized;
				Vector3 val2 = transform.position + normalized * 2.5f + Vector3.up * 0.2f;
				FaussaireAI faussaireAI = FaussaireAI.Existing();
				if ((Object)(object)faussaireAI != (Object)null)
				{
					faussaireAI.DebugBring(val2);
					Log.LogInfo((object)$"[Debug] Faussaire brought to {val2}.");
					return;
				}
				FaussaireAI.SkipTeleportUntil = Time.time + 5f;
				Enemies.SpawnEnemy(Setup, val2, Quaternion.LookRotation(-normalized), false);
				handledLevel = LevelGenerator.Instance;
				Log.LogInfo((object)$"[Debug] Faussaire spawned at {val2}.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[Debug] Spawn failed: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "AmountSetup")]
	internal static class DirectorExcludePatch
	{
		private static void Prefix(EnemyDirector __instance)
		{
			if (Plugin.CfgPoolWeight.Value <= 0 && !((Object)(object)Plugin.Setup == (Object)null) && Strip(__instance.enemiesDifficulty1) + Strip(__instance.enemiesDifficulty2) + Strip(__instance.enemiesDifficulty3) > 0)
			{
				Plugin.Log.LogInfo((object)"[Faussaire] Removed from the regular monster picks (spawns as one extra per level).");
			}
		}

		private static int Strip(List<EnemySetup> list)
		{
			return list?.RemoveAll((EnemySetup s) => (Object)(object)s == (Object)(object)Plugin.Setup || ((Object)(object)s != (Object)null && ((Object)s).name == "Enemy - Faussaire")) ?? 0;
		}
	}
	[HarmonyPatch(typeof(ItemInfoUI), "ItemInfoText")]
	internal static class ItemInfoTextPatch
	{
		private static bool Prefix(bool enemy)
		{
			if (enemy)
			{
				return !FaussaireAI.HideEnemyNameNow;
			}
			return true;
		}
	}
	internal static class Resource
	{
		public static T Load<T>(string path) where T : Object
		{
			T val = Resources.Load<T>(path);
			if ((Object)(object)val == (Object)null)
			{
				val = Resources.Load<T>(path.ToLowerInvariant());
			}
			return val;
		}

		public static byte[] Embedded(string name)
		{
			using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream(name);
			if (stream == null)
			{
				throw new FileNotFoundException("Embedded resource missing: " + name);
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return memoryStream.ToArray();
		}
	}
	internal static class PrefabBuilder
	{
		private struct Part
		{
			public Mesh Mesh;

			public int[] MatIds;
		}

		private const float RigidbodyHeight = 0.155f;

		public static GameObject Build()
		{
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0364: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: 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)
			GameObject obj = Resource.Load<GameObject>("Enemies/Enemy - Gnome");
			if ((Object)(object)obj == (Object)null)
			{
				throw new Exception("Vanilla prefab 'Enemies/Enemy - Gnome' not found");
			}
			GameObject val = Object.Instantiate<GameObject>(obj, Plugin.Holder.transform);
			((Object)val).name = "Enemy - Faussaire";
			Transform obj2 = val.transform.Find("Enable");
			Transform val2 = obj2.Find("Controller");
			Transform val3 = obj2.Find("Rigidbody");
			Transform val4 = obj2.Find("[VISUALS]");
			if ((Object)(object)val2 == (Object)null || (Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null)
			{
				throw new Exception("Unexpected Gnome hierarchy (game update?)");
			}
			CollectSounds(obj);
			Kill((Component)(object)((Component)val2).GetComponent<EnemyGnome>());
			Kill((Component)(object)((Component)val2).GetComponent<GameEventObjectSwap>());
			Transform val5 = val.transform.Find("Stun Fly Loop");
			if (Object.op_Implicit((Object)(object)val5))
			{
				Object.DestroyImmediate((Object)(object)((Component)val5).gameObject);
			}
			Kill((Component)(object)((Component)val4).GetComponent<EnemyGnomeAnim>());
			Kill((Component)(object)((Component)val4).GetComponent<Animator>());
			Transform val6 = val4.Find("Hurt Collider");
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in val4)
			{
				Transform val7 = item;
				if ((Object)(object)val7 != (Object)(object)val6)
				{
					list.Add(((Component)val7).gameObject);
				}
			}
			foreach (GameObject item2 in list)
			{
				Object.DestroyImmediate((Object)(object)item2);
			}
			Kill((Component)(object)val.GetComponent<EnemyChecklist>());
			EnemyParent component = val.GetComponent<EnemyParent>();
			component.enemyName = "Faussaire";
			component.enemyNameLocalized = null;
			component.difficulty = (Difficulty)Mathf.Clamp(Plugin.CfgDifficulty.Value - 1, 0, 2);
			component.SpawnedTimeMin = 90f;
			component.SpawnedTimeMax = 150f;
			component.DespawnedTimeMin = 120f;
			component.DespawnedTimeMax = 200f;
			((Component)val2).GetComponent<Enemy>().Type = (EnemyType)1;
			EnemyHealth component2 = ((Component)val2).GetComponent<EnemyHealth>();
			component2.health = Plugin.CfgHealth.Value;
			component2.spawnValuable = true;
			component2.objectHurtMultiplier = 3f;
			EnemyRigidbody component3 = ((Component)val3).GetComponent<EnemyRigidbody>();
			component3.grabStun = false;
			component3.positionSpeedChase = 9f;
			component3.positionSpeedLerpChase = 9f;
			component3.distanceWarpChase = 3.5f;
			component3.rotationSpeedChase = 0.5f;
			MapCustom val8 = ((Component)val3).gameObject.AddComponent<MapCustom>();
			val8.autoAdd = false;
			ValuableDiscoverCustom obj3 = ((Component)val3).gameObject.AddComponent<ValuableDiscoverCustom>();
			obj3.customMap = new List<MapCustom> { val8 };
			obj3.hasCustomMap = true;
			obj3.hasCustomSound = false;
			Transform transform = new GameObject("Center of Mass").transform;
			transform.SetParent(val3, false);
			transform.localPosition = new Vector3(0f, -0.07f, 0f);
			Transform val9 = val3.Find("Semi Capsule Collider");
			if (Object.op_Implicit((Object)(object)val9))
			{
				val9.localScale = Vector3.one;
				val9.localPosition = new Vector3(0f, 0.125f, 0f);
				CapsuleCollider component4 = ((Component)val9).GetComponent<CapsuleCollider>();
				component4.radius = 0.165f;
				component4.height = 0.56f;
				component4.center = Vector3.zero;
				component4.direction = 1;
			}
			Transform val10 = (component2.meshParent = BuildModel(val4));
			if (Object.op_Implicit((Object)(object)val6))
			{
				val6.SetParent(val10, false);
				val6.localPosition = new Vector3(0f, 0.32000002f, 0.16f);
				val6.localRotation = Quaternion.identity;
				val6.localScale = new Vector3(0.45f, 0.42f, 0.55f);
				HurtCollider component5 = ((Component)val6).GetComponent<HurtCollider>();
				component5.playerLogic = true;
				component5.playerKill = false;
				component5.playerDamage = Plugin.CfgBiteDamage.Value;
				component5.playerDamageCooldown = 999f;
				component5.playerHitForce = 6f;
				component5.playerTumbleForce = 0f;
				component5.playerTumbleTorque = 0f;
				component5.physLogic = false;
				component5.enemyLogic = false;
				((Component)val6).gameObject.SetActive(false);
			}
			((Component)val2).gameObject.AddComponent<FaussaireAI>();
			return val;
		}

		private static void Kill(Component c)
		{
			if ((Object)(object)c != (Object)null)
			{
				Object.DestroyImmediate((Object)(object)c);
			}
		}

		private static void CollectSounds(GameObject gnomeAsset)
		{
			try
			{
				EnemyGnomeAnim componentInChildren = gnomeAsset.GetComponentInChildren<EnemyGnomeAnim>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					Sounds.Stun = componentInChildren.soundStun;
					Sounds.StunOutro = componentInChildren.soundStunOutro;
					Sounds.Land = componentInChildren.soundLand;
				}
				GameObject val = Resource.Load<GameObject>("Enemies/Enemy - Duck");
				EnemyDuckAnim val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponentInChildren<EnemyDuckAnim>(true) : null);
				if (Object.op_Implicit((Object)(object)val2))
				{
					Sounds.Reveal = val2.transformSound;
					Sounds.Bite = val2.biteSound;
					Sounds.TongueOut = val2.mouthExtendSound;
					Sounds.TongueIn = val2.mouthRetractSound;
					Sounds.Hurt = val2.hurtSound;
					Sounds.Death = val2.deathSound;
					Sounds.Notice = val2.noticeSound;
				}
				GameObject val3 = Resource.Load<GameObject>("Valuables/03 Medium/Valuable Manor Vase");
				ValuableObject val4 = (Object.op_Implicit((Object)(object)val3) ? val3.GetComponent<ValuableObject>() : null);
				if (Object.op_Implicit((Object)(object)val4) && Object.op_Implicit((Object)(object)val4.audioPreset))
				{
					Sounds.Clink = val4.audioPreset.impactLight;
					Sounds.Shatter = val4.audioPreset.destroy;
				}
				Plugin.Log.LogDebug((object)$"Sounds: duck={(Object)(object)val2 != (Object)null} vase={(Object)(object)val4 != (Object)null} gnome={(Object)(object)componentInChildren != (Object)null}");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Could not borrow vanilla sounds: " + ex.Message));
			}
		}

		private static Transform BuildModel(Transform vis)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_00bc: 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_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			Dictionary<string, Part> dictionary = LoadMeshes(Resource.Embedded("Faussaire.faussaire.mesh"));
			Material[] mats = MakeMaterials();
			Transform transform = new GameObject("FaussaireModel").transform;
			transform.SetParent(vis, false);
			transform.localPosition = new Vector3(0f, -0.155f, 0f);
			MakePart("Lower", dictionary["lower"], mats, transform, Vector3.zero);
			MakePart("TeethLower", dictionary["teeth_lower"], mats, transform, ModelLayout.TeethLowerPivot);
			MakePart("Tongue", dictionary["tongue"], mats, transform, ModelLayout.TongueInPos).localRotation = Quaternion.Euler(-64f, 0f, 0f);
			Transform transform2 = new GameObject("LidPivot").transform;
			transform2.SetParent(transform, false);
			transform2.localPosition = ModelLayout.Hinge;
			MakePart("Upper", dictionary["upper"], mats, transform2, Vector3.zero);
			MakePart("TeethUpper", dictionary["teeth_upper"], mats, transform2, Vector3.zero);
			Transform val = MakePart("Eye", dictionary["eye"], mats, transform2, ModelLayout.EyeInLid);
			GameObject val2 = new GameObject("EyeLight");
			val2.transform.SetParent(val, false);
			val2.transform.localPosition = new Vector3(0f, -0.07f, 0f);
			Light obj = val2.AddComponent<Light>();
			obj.type = (LightType)2;
			obj.range = 1.6f;
			obj.intensity = 0f;
			obj.color = new Color(1f, 0.68f, 0.22f);
			obj.shadows = (LightShadows)0;
			((Behaviour)obj).enabled = false;
			return transform;
		}

		private static Transform MakePart(string name, Part p, Material[] mats, Transform parent, Vector3 localPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPos;
			val.AddComponent<MeshFilter>().sharedMesh = p.Mesh;
			MeshRenderer val2 = val.AddComponent<MeshRenderer>();
			Material[] array = (Material[])(object)new Material[p.MatIds.Length];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = mats[Mathf.Clamp(p.MatIds[i], 0, mats.Length - 1)];
			}
			((Renderer)val2).sharedMaterials = array;
			return val.transform;
		}

		private static Material[] MakeMaterials()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			Texture2D tex = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(tex, Resource.Embedded("Faussaire.atlas.png"), false);
			((Object)tex).name = "Faussaire Atlas";
			((Texture)tex).wrapMode = (TextureWrapMode)1;
			((Texture)tex).filterMode = (FilterMode)2;
			((Texture)tex).anisoLevel = 4;
			tex.Apply(true, true);
			((Object)tex).hideFlags = (HideFlags)32;
			Material baseMat = null;
			GameObject val = Resource.Load<GameObject>("Valuables/03 Medium/Valuable Manor Vase");
			if (Object.op_Implicit((Object)(object)val))
			{
				MeshRenderer componentInChildren = val.GetComponentInChildren<MeshRenderer>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					baseMat = ((Renderer)componentInChildren).sharedMaterial;
				}
			}
			Shader shader = (Object.op_Implicit((Object)(object)baseMat) ? baseMat.shader : Shader.Find("Standard"));
			return (Material[])(object)new Material[3]
			{
				Make("Faussaire Ceramic", 0.78f),
				Make("Faussaire Flesh", 0.55f),
				Make("Faussaire Eye", 0.9f)
			};
			Material Make(string n, float gloss)
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0013: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Expected O, but got Unknown
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				Material val2 = (Object.op_Implicit((Object)(object)baseMat) ? new Material(baseMat) : new Material(shader));
				((Object)val2).name = n;
				val2.mainTexture = (Texture)(object)tex;
				val2.color = Color.white;
				if (val2.HasProperty("_Glossiness"))
				{
					val2.SetFloat("_Glossiness", gloss);
				}
				if (val2.HasProperty("_Metallic"))
				{
					val2.SetFloat("_Metallic", 0f);
				}
				((Object)val2).hideFlags = (HideFlags)32;
				return val2;
			}
		}

		private static Dictionary<string, Part> LoadMeshes(byte[] data)
		{
			//IL_0099: 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_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_012c: Expected O, but got Unknown
			Dictionary<string, Part> dictionary = new Dictionary<string, Part>();
			using BinaryReader binaryReader = new BinaryReader(new MemoryStream(data));
			if (new string(binaryReader.ReadChars(4)) != "FMSH")
			{
				throw new Exception("Bad mesh data");
			}
			int num = binaryReader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				string text = Encoding.UTF8.GetString(binaryReader.ReadBytes(binaryReader.ReadInt32()));
				int num2 = binaryReader.ReadInt32();
				Vector3[] array = (Vector3[])(object)new Vector3[num2];
				Vector3[] array2 = (Vector3[])(object)new Vector3[num2];
				Vector2[] array3 = (Vector2[])(object)new Vector2[num2];
				for (int j = 0; j < num2; j++)
				{
					array[j] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				for (int k = 0; k < num2; k++)
				{
					array2[k] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				for (int l = 0; l < num2; l++)
				{
					array3[l] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
				}
				int num3 = binaryReader.ReadInt32();
				Mesh val = new Mesh
				{
					name = "Faussaire " + text
				};
				val.vertices = array;
				val.normals = array2;
				val.uv = array3;
				val.subMeshCount = num3;
				int[] array4 = new int[num3];
				for (int m = 0; m < num3; m++)
				{
					array4[m] = binaryReader.ReadInt32();
					int num4 = binaryReader.ReadInt32();
					int[] array5 = new int[num4];
					for (int n = 0; n < num4; n++)
					{
						array5[n] = binaryReader.ReadInt32();
					}
					val.SetTriangles(array5, m);
				}
				val.RecalculateBounds();
				val.RecalculateTangents();
				((Object)val).hideFlags = (HideFlags)32;
				dictionary[text] = new Part
				{
					Mesh = val,
					MatIds = array4
				};
			}
			return dictionary;
		}
	}
}