Decompiled source of Jester Enemy v1.0.3

BepInEx\plugins\Omniscye-Jester_Enemy\Jester.dll

Decompiled 20 hours 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.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Playables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Jester")]
[assembly: AssemblyTitle("Jester")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Empress.REPO.Jester
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Empress.REPO.Jester", "Empress REPO Jester", "1.0.0")]
	public sealed class EmpressRepoJesterPlugin : BaseUnityPlugin
	{
		private const string JesterBundleFileName = "empressjester";

		private const string JesterBundlePrefabName = "Box Jester";

		private static readonly FieldInfo EnemySetupField = AccessTools.Field(typeof(EnemyContent), "_setup");

		private static readonly FieldInfo SpawnObjectsField = AccessTools.Field(typeof(EnemyContent), "_spawnObjects");

		internal const string PluginGuid = "Empress.REPO.Jester";

		internal const string PluginName = "Empress REPO Jester";

		internal const string PluginVersion = "1.0.0";

		internal const string TemplatePrefabName = "EmpressJesterPrefab";

		private static Harmony? _harmony;

		private static bool _registered;

		private static MethodInfo? _spawnManagerRefreshMethod;

		private static AssetBundle? _jesterBundle;

		private static GameObject? _jesterVisualPrefab;

		private static readonly Dictionary<string, AnimationClip> JesterAnimationClips = new Dictionary<string, AnimationClip>(StringComparer.Ordinal);

		internal static ManualLogSource Log { get; private set; } = null;


		internal static string PluginDirectory { get; private set; } = string.Empty;


		private void Awake()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin location: " + ((BaseUnityPlugin)this).Info.Location));
			PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty;
			((Component)this).transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			if (_harmony == null)
			{
				_harmony = new Harmony("Empress.REPO.Jester");
			}
			PatchTemplateGuards(_harmony);
			((MonoBehaviour)this).StartCoroutine(EmpressRepoJesterAudioBank.LoadAudioAsync(((BaseUnityPlugin)this).Logger));
			RegisterEnemy();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Empress REPO Jester v1.0.0");
		}

		internal static void RefreshSpawnManagerEnemyNames()
		{
			Type type = AccessTools.TypeByName("SpawnManager.Managers.EnemyManager");
			if (!(type == null))
			{
				if ((object)_spawnManagerRefreshMethod == null)
				{
					_spawnManagerRefreshMethod = AccessTools.Method(type, "RefreshAllEnemyNames", (Type[])null, (Type[])null);
				}
				_spawnManagerRefreshMethod?.Invoke(null, null);
			}
		}

		internal static void ConfigureRuntimeInstance(EnemyParent enemyParent, Enemy enemy, EnemyStateSpawn stateSpawn, EnemyStateStunned stateStunned, PhotonView rootPhotonView, PhotonView enemyPhotonView, Transform centerTransform)
		{
			//IL_001e: 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_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			Transform centerTransform2;
			Transform headTransform;
			Transform lidTransform;
			Transform leftArmTransform;
			Transform rightArmTransform;
			Transform windKeyTransform;
			Transform springTransform;
			Animator visualAnimator;
			Transform jesterMeshTransform;
			EmpressRepoJesterAuthoring authoring;
			Transform visualRoot = BuildJesterVisualRig(enemy, out centerTransform2, out headTransform, out lidTransform, out leftArmTransform, out rightArmTransform, out windKeyTransform, out springTransform, out visualAnimator, out jesterMeshTransform, out authoring);
			enemy.Type = (EnemyType)3;
			enemy.CenterTransform = centerTransform2;
			enemy.KillLookAtTransform = headTransform;
			enemy.CustomValuableSpawnTransform = centerTransform2;
			enemy.CurrentState = (EnemyState)1;
			AudioSource musicSource = CreateAudioSource(((Component)enemy).gameObject, "JesterMusic", 1f, 8f, 0.8f);
			AudioSource sfxSource = CreateAudioSource(((Component)enemy).gameObject, "JesterSfx", 1f, 10f, 1f);
			AudioSource voiceSource = CreateAudioSource(((Component)enemy).gameObject, "JesterVoice", 1f, 12f, 0.9f);
			EmpressRepoJesterController empressRepoJesterController = ((Component)enemy).GetComponent<EmpressRepoJesterController>() ?? ((Component)enemy).gameObject.AddComponent<EmpressRepoJesterController>();
			empressRepoJesterController.TemplateBehaviourTypeName = string.Empty;
			empressRepoJesterController.VisualRoot = visualRoot;
			empressRepoJesterController.CenterTransform = centerTransform2;
			empressRepoJesterController.HeadTransform = headTransform;
			empressRepoJesterController.LidTransform = lidTransform;
			empressRepoJesterController.LeftArmTransform = leftArmTransform;
			empressRepoJesterController.RightArmTransform = rightArmTransform;
			empressRepoJesterController.WindKeyTransform = windKeyTransform;
			empressRepoJesterController.SpringTransform = springTransform;
			empressRepoJesterController.VisualAnimator = visualAnimator;
			empressRepoJesterController.JesterMeshTransform = jesterMeshTransform;
			empressRepoJesterController.DoorPushProbeTransform = (((Object)(object)authoring != (Object)null) ? authoring.DoorPushProbe : null);
			empressRepoJesterController.DoorPushRadius = (((Object)(object)authoring != (Object)null) ? authoring.ResolveDoorPushRadius() : 0.55f);
			empressRepoJesterController.DoorPushForce = (((Object)(object)authoring != (Object)null) ? authoring.DoorPushForce : 2.8f);
			empressRepoJesterController.DoorPushTorque = (((Object)(object)authoring != (Object)null) ? authoring.DoorPushTorque : 1.1f);
			empressRepoJesterController.MusicSource = musicSource;
			empressRepoJesterController.SfxSource = sfxSource;
			empressRepoJesterController.VoiceSource = voiceSource;
			empressRepoJesterController.WindupClip = EmpressRepoJesterAudioBank.WindupClip;
			empressRepoJesterController.PopClip = EmpressRepoJesterAudio.BuildPopClip();
			empressRepoJesterController.ScreamClip = EmpressRepoJesterAudio.BuildScreamClip();
			empressRepoJesterController.KillClip = EmpressRepoJesterAudio.BuildKillClip();
			empressRepoJesterController.StompClips = EmpressRepoJesterAudioBank.GetStompClips();
			empressRepoJesterController.InitializeRuntime();
			RepoEnemyAccess.SetEnemyParentEnemy(enemyParent, enemy);
			RepoEnemyAccess.SetEnemyParent(enemy, enemyParent);
			RepoEnemyAccess.SetPhotonView(enemy, enemyPhotonView);
			RepoEnemyAccess.SetStateSpawn(enemy, stateSpawn);
			RepoEnemyAccess.SetHasStateSpawn(enemy, value: true);
			RepoEnemyAccess.SetStateStunned(enemy, stateStunned);
			RepoEnemyAccess.SetHasStateStunned(enemy, value: true);
			RepoEnemyAccess.SetTargetPlayerViewId(enemy, -1);
			RepoEnemyAccess.SetVisionMask(enemy, LayerMask.op_Implicit(LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "HideTriggers" })));
			RepoEnemyAccess.SetStateSpawnEnemy(stateSpawn, enemy);
			RepoEnemyAccess.SetStateStunnedEnemy(stateStunned, enemy);
			rootPhotonView.ObservedComponents = new List<Component> { (Component)(object)enemyParent };
			enemyPhotonView.ObservedComponents = new List<Component> { (Component)(object)enemy };
		}

		private void RegisterEnemy()
		{
			if (!_registered)
			{
				GameObject item = JesterTemplateBootstrap.CreateTemplate(((BaseUnityPlugin)this).Logger);
				RarityPreset val = ScriptableObject.CreateInstance<RarityPreset>();
				((Object)val).hideFlags = (HideFlags)61;
				((Object)val).name = "Rarity - Jester";
				val.chance = 60f;
				EnemySetup val2 = ScriptableObject.CreateInstance<EnemySetup>();
				((Object)val2).hideFlags = (HideFlags)61;
				((Object)val2).name = "Enemy - Jester";
				val2.spawnObjects = new List<PrefabRef>();
				val2.levelsCompletedCondition = false;
				val2.levelsCompletedMin = 0;
				val2.levelsCompletedMax = 10;
				val2.rarityPreset = val;
				val2.runsPlayed = 0;
				EnemyContent val3 = ScriptableObject.CreateInstance<EnemyContent>();
				((Object)val3).hideFlags = (HideFlags)61;
				((Object)val3).name = "EnemyContentEmpressJester";
				EnemySetupField.SetValue(val3, val2);
				SpawnObjectsField.SetValue(val3, new List<GameObject> { item });
				Enemies.RegisterEnemy(val3);
				_registered = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the Jester enemy with REPOLib.");
			}
		}

		private static void PatchTemplateGuards(Harmony harmony)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyParent), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyParentAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyParent), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyParentUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Enemy), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Enemy), "Start", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(Enemy), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyNavMeshAgent), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyNavMeshAgentAwake", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyNavMeshAgent), "OnEnable", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyNavMeshAgentOnEnable", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyNavMeshAgent), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyNavMeshAgentUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyStateSpawn), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyStateSpawnUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyStateStunned), "Update", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoJesterPlugin), "SkipTemplateEnemyStateStunnedUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static bool SkipTemplateEnemyParentAwake(EnemyParent __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyParentUpdate(EnemyParent __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyAwake(Enemy __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyStart(Enemy __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyUpdate(Enemy __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyNavMeshAgentAwake(EnemyNavMeshAgent __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyNavMeshAgentOnEnable(EnemyNavMeshAgent __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyNavMeshAgentUpdate(EnemyNavMeshAgent __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyStateSpawnUpdate(EnemyStateSpawn __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static bool SkipTemplateEnemyStateStunnedUpdate(EnemyStateStunned __instance)
		{
			return !JesterTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}

		private static Transform BuildJesterVisualRig(Enemy enemy, out Transform centerTransform, out Transform headTransform, out Transform lidTransform, out Transform leftArmTransform, out Transform rightArmTransform, out Transform windKeyTransform, out Transform springTransform, out Animator? visualAnimator, out Transform? jesterMeshTransform, out EmpressRepoJesterAuthoring? authoring)
		{
			//IL_0041: 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_0071: 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_00b4: 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_0108: 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_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: 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_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_0347: Unknown result type (might be due to invalid IL or missing references)
			//IL_0375: 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_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_048d: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_051c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_0570: Unknown result type (might be due to invalid IL or missing references)
			//IL_0597: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0624: Unknown result type (might be due to invalid IL or missing references)
			//IL_0638: Unknown result type (might be due to invalid IL or missing references)
			//IL_0666: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_06fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_072c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0740: Unknown result type (might be due to invalid IL or missing references)
			//IL_076e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0782: Unknown result type (might be due to invalid IL or missing references)
			//IL_0798: Unknown result type (might be due to invalid IL or missing references)
			//IL_07af: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0800: Unknown result type (might be due to invalid IL or missing references)
			//IL_0816: Unknown result type (might be due to invalid IL or missing references)
			//IL_083e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0852: Unknown result type (might be due to invalid IL or missing references)
			//IL_0870: Unknown result type (might be due to invalid IL or missing references)
			//IL_0899: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_08c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_08ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0913: Unknown result type (might be due to invalid IL or missing references)
			//IL_0930: Unknown result type (might be due to invalid IL or missing references)
			//IL_0956: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)enemy).transform;
			if (TryBuildBundleVisualRig(transform, out Transform visualRoot, out centerTransform, out headTransform, out lidTransform, out leftArmTransform, out rightArmTransform, out windKeyTransform, out springTransform, out visualAnimator, out jesterMeshTransform, out authoring))
			{
				return visualRoot;
			}
			visualAnimator = null;
			jesterMeshTransform = null;
			authoring = null;
			Transform transform2 = new GameObject("JesterVisualRoot").transform;
			transform2.SetParent(transform, false);
			transform2.localPosition = new Vector3(0f, 0.1f, 0f);
			transform2.localRotation = Quaternion.identity;
			Material seedMaterial = FindSeedMaterial(((Component)enemy).gameObject);
			Material material = CreateTintedMaterial(seedMaterial, new Color(0.72f, 0.12f, 0.14f));
			Material material2 = CreateTintedMaterial(seedMaterial, new Color(0.16f, 0.32f, 0.74f));
			Material material3 = CreateTintedMaterial(seedMaterial, new Color(0.93f, 0.87f, 0.71f));
			Material material4 = CreateTintedMaterial(seedMaterial, new Color(0.08f, 0.08f, 0.1f));
			Material material5 = CreateTintedMaterial(seedMaterial, new Color(0.82f, 0.68f, 0.18f));
			Material material6 = CreateTintedMaterial(seedMaterial, new Color(0.68f, 0.72f, 0.78f));
			Transform transform3 = new GameObject("JesterBox").transform;
			transform3.SetParent(transform2, false);
			transform3.localPosition = Vector3.zero;
			CreatePiece("BodyBase", (PrimitiveType)3, transform3, new Vector3(0f, 0.45f, 0f), new Vector3(0.95f, 0.9f, 0.95f), material);
			CreatePiece("BodyStripeFront", (PrimitiveType)3, transform3, new Vector3(0f, 0.45f, 0.475f), new Vector3(0.78f, 0.6f, 0.04f), material3);
			CreatePiece("BodyStripeSideL", (PrimitiveType)3, transform3, new Vector3(-0.475f, 0.45f, 0f), new Vector3(0.04f, 0.58f, 0.72f), material2);
			CreatePiece("BodyStripeSideR", (PrimitiveType)3, transform3, new Vector3(0.475f, 0.45f, 0f), new Vector3(0.04f, 0.58f, 0.72f), material2);
			CreatePiece("TrimTop", (PrimitiveType)3, transform3, new Vector3(0f, 0.93f, 0f), new Vector3(1.02f, 0.06f, 1.02f), material5);
			CreatePiece("TrimBottom", (PrimitiveType)3, transform3, new Vector3(0f, 0.02f, 0f), new Vector3(1.02f, 0.06f, 1.02f), material5);
			lidTransform = new GameObject("LidPivot").transform;
			lidTransform.SetParent(transform3, false);
			lidTransform.localPosition = new Vector3(0f, 0.9f, -0.38f);
			CreatePiece("Lid", (PrimitiveType)3, lidTransform, new Vector3(0f, 0f, 0.38f), new Vector3(1f, 0.08f, 0.88f), material2);
			CreatePiece("LidTrim", (PrimitiveType)3, lidTransform, new Vector3(0f, 0.01f, 0.38f), new Vector3(1.04f, 0.02f, 0.92f), material5);
			windKeyTransform = new GameObject("WindKey").transform;
			windKeyTransform.SetParent(transform3, false);
			windKeyTransform.localPosition = new Vector3(0.62f, 0.56f, -0.02f);
			CreatePiece("KeyStem", (PrimitiveType)2, windKeyTransform, Vector3.zero, new Vector3(0.08f, 0.16f, 0.08f), material6, (Vector3?)new Vector3(90f, 0f, 0f));
			CreatePiece("KeyWingTop", (PrimitiveType)3, windKeyTransform, new Vector3(0.16f, 0f, 0f), new Vector3(0.22f, 0.04f, 0.1f), material6);
			CreatePiece("KeyWingBottom", (PrimitiveType)3, windKeyTransform, new Vector3(-0.16f, 0f, 0f), new Vector3(0.22f, 0.04f, 0.1f), material6);
			springTransform = new GameObject("Spring").transform;
			springTransform.SetParent(transform2, false);
			springTransform.localPosition = new Vector3(0f, 0.94f, 0f);
			for (int i = 0; i < 6; i++)
			{
				float num = (float)i / 5f;
				CreatePiece($"SpringRing{i}", (PrimitiveType)2, springTransform, new Vector3(0f, 0.12f + num * 0.38f, 0f), new Vector3(0.23f, 0.015f, 0.23f), material6, (Vector3?)new Vector3(90f, 0f, 0f));
			}
			Transform transform4 = new GameObject("HeadRoot").transform;
			transform4.SetParent(transform2, false);
			transform4.localPosition = new Vector3(0f, 1.2f, 0f);
			headTransform = new GameObject("Head").transform;
			headTransform.SetParent(transform4, false);
			headTransform.localPosition = new Vector3(0f, 0.42f, 0f);
			CreatePiece("HeadBall", (PrimitiveType)0, headTransform, Vector3.zero, new Vector3(0.5f, 0.56f, 0.5f), material3);
			CreatePiece("HatBrim", (PrimitiveType)2, headTransform, new Vector3(0f, 0.32f, 0f), new Vector3(0.3f, 0.02f, 0.3f), material4);
			CreatePiece("HatTop", (PrimitiveType)2, headTransform, new Vector3(0f, 0.48f, 0f), new Vector3(0.18f, 0.18f, 0.18f), material4);
			CreatePiece("EyeLeft", (PrimitiveType)0, headTransform, new Vector3(-0.1f, 0.03f, 0.21f), new Vector3(0.08f, 0.08f, 0.08f), material4);
			CreatePiece("EyeRight", (PrimitiveType)0, headTransform, new Vector3(0.1f, 0.03f, 0.21f), new Vector3(0.08f, 0.08f, 0.08f), material4);
			CreatePiece("Nose", (PrimitiveType)0, headTransform, new Vector3(0f, -0.03f, 0.25f), new Vector3(0.11f, 0.11f, 0.11f), material);
			CreatePiece("Jaw", (PrimitiveType)3, headTransform, new Vector3(0f, -0.16f, 0.08f), new Vector3(0.22f, 0.08f, 0.2f), material3, (Vector3?)new Vector3(12f, 0f, 0f));
			leftArmTransform = new GameObject("LeftArm").transform;
			leftArmTransform.SetParent(transform4, false);
			leftArmTransform.localPosition = new Vector3(-0.34f, 0.16f, 0.02f);
			CreatePiece("LeftArmUpper", (PrimitiveType)2, leftArmTransform, Vector3.zero, new Vector3(0.06f, 0.22f, 0.06f), material2, (Vector3?)new Vector3(0f, 0f, 90f));
			CreatePiece("LeftHand", (PrimitiveType)0, leftArmTransform, new Vector3(-0.24f, 0f, 0f), new Vector3(0.08f, 0.08f, 0.08f), material5);
			rightArmTransform = new GameObject("RightArm").transform;
			rightArmTransform.SetParent(transform4, false);
			rightArmTransform.localPosition = new Vector3(0.34f, 0.16f, 0.02f);
			CreatePiece("RightArmUpper", (PrimitiveType)2, rightArmTransform, Vector3.zero, new Vector3(0.06f, 0.22f, 0.06f), material2, (Vector3?)new Vector3(0f, 0f, 90f));
			CreatePiece("RightHand", (PrimitiveType)0, rightArmTransform, new Vector3(0.24f, 0f, 0f), new Vector3(0.08f, 0.08f, 0.08f), material5);
			centerTransform = new GameObject("JesterCenter").transform;
			centerTransform.SetParent(transform2, false);
			centerTransform.localPosition = new Vector3(0f, 0.92f, 0f);
			return transform2;
		}

		private static bool TryBuildBundleVisualRig(Transform attachRoot, out Transform visualRoot, out Transform centerTransform, out Transform headTransform, out Transform lidTransform, out Transform leftArmTransform, out Transform rightArmTransform, out Transform windKeyTransform, out Transform springTransform, out Animator? visualAnimator, out Transform? jesterMeshTransform, out EmpressRepoJesterAuthoring? authoring)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: 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_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0241: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: 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_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: 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_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_030f: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0359: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0397: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03db: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			visualRoot = null;
			centerTransform = null;
			headTransform = null;
			lidTransform = null;
			leftArmTransform = null;
			rightArmTransform = null;
			windKeyTransform = null;
			springTransform = null;
			visualAnimator = null;
			jesterMeshTransform = null;
			authoring = null;
			GameObject val = LoadJesterVisualPrefab();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, attachRoot, false);
			((Object)val2).name = "JesterVisualRoot";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			SetVisualLayerRecursively(val2.transform, ResolveVisualLayer("Enemy"));
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren)
			{
				val3.enabled = false;
			}
			visualRoot = val2.transform;
			visualAnimator = val2.GetComponentInChildren<Animator>(true);
			jesterMeshTransform = FindNamedChildTransform(val2.transform, "JesterMesh");
			authoring = val2.GetComponentInChildren<EmpressRepoJesterAuthoring>(true);
			if ((Object)(object)authoring != (Object)null)
			{
				EmpressRepoJesterAuthoring empressRepoJesterAuthoring = authoring;
				if (empressRepoJesterAuthoring.DoorPushProbe == null)
				{
					empressRepoJesterAuthoring.DoorPushProbe = FindNamedChildTransform(val2.transform, "DoorPushProbe");
				}
				if ((Object)(object)authoring.DoorPushProbe != (Object)null)
				{
					Log.LogInfo((object)$"[Jester] Using authored door push probe '{((Object)authoring.DoorPushProbe).name}' with radius {authoring.ResolveDoorPushRadius():0.##}.");
				}
				else
				{
					Log.LogWarning((object)"[Jester] EmpressRepoJesterAuthoring was found, but DoorPushProbe is not assigned.");
				}
			}
			Bounds? combinedRendererBounds = GetCombinedRendererBounds(val2);
			? val4;
			Bounds value;
			if (!combinedRendererBounds.HasValue)
			{
				val4 = new Vector3(0f, 0.9f, 0f);
			}
			else
			{
				Transform obj = visualRoot;
				value = combinedRendererBounds.Value;
				val4 = obj.InverseTransformPoint(((Bounds)(ref value)).center);
			}
			Vector3 val5 = (Vector3)val4;
			float num;
			if (!combinedRendererBounds.HasValue)
			{
				num = 1.8f;
			}
			else
			{
				Transform obj2 = visualRoot;
				value = combinedRendererBounds.Value;
				float x = ((Bounds)(ref value)).center.x;
				value = combinedRendererBounds.Value;
				float y = ((Bounds)(ref value)).max.y;
				value = combinedRendererBounds.Value;
				num = obj2.InverseTransformPoint(new Vector3(x, y, ((Bounds)(ref value)).center.z)).y;
			}
			float num2 = num;
			centerTransform = new GameObject("JesterCenter").transform;
			centerTransform.SetParent(visualRoot, false);
			centerTransform.localPosition = val5;
			headTransform = new GameObject("JesterHead").transform;
			headTransform.SetParent(visualRoot, false);
			headTransform.localPosition = new Vector3(val5.x, Mathf.Max(val5.y + 0.35f, num2 - 0.15f), val5.z + 0.05f);
			lidTransform = new GameObject("JesterLidProxy").transform;
			lidTransform.SetParent(visualRoot, false);
			lidTransform.localPosition = new Vector3(val5.x, num2 - 0.1f, val5.z - 0.15f);
			leftArmTransform = new GameObject("JesterLeftArmProxy").transform;
			leftArmTransform.SetParent(visualRoot, false);
			leftArmTransform.localPosition = new Vector3(val5.x - 0.3f, val5.y + 0.1f, val5.z);
			rightArmTransform = new GameObject("JesterRightArmProxy").transform;
			rightArmTransform.SetParent(visualRoot, false);
			rightArmTransform.localPosition = new Vector3(val5.x + 0.3f, val5.y + 0.1f, val5.z);
			windKeyTransform = new GameObject("JesterWindKeyProxy").transform;
			windKeyTransform.SetParent(visualRoot, false);
			windKeyTransform.localPosition = new Vector3(val5.x + 0.45f, val5.y, val5.z);
			springTransform = new GameObject("JesterSpringProxy").transform;
			springTransform.SetParent(visualRoot, false);
			springTransform.localPosition = new Vector3(val5.x, val5.y + 0.2f, val5.z);
			if ((Object)(object)jesterMeshTransform == (Object)null)
			{
				Log.LogWarning((object)"[Jester] Could not find child transform 'JesterMesh' in the asset bundle prefab.");
			}
			Log.LogInfo((object)"Using asset bundle visual prefab for Jester.");
			return true;
		}

		private static Transform? FindNamedChildTransform(Transform root, string targetName)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (string.Equals(((Object)val).name, targetName, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
			}
			return null;
		}

		private static GameObject? LoadJesterVisualPrefab()
		{
			if ((Object)(object)_jesterVisualPrefab != (Object)null)
			{
				return _jesterVisualPrefab;
			}
			string text = ResolvePluginFile("empressjester");
			if (string.IsNullOrEmpty(text) || !File.Exists(text))
			{
				Log.LogWarning((object)("[Jester] Asset bundle 'empressjester' was not found under " + PluginDirectory));
				return null;
			}
			if (_jesterBundle == null)
			{
				_jesterBundle = AssetBundle.LoadFromFile(text);
			}
			if ((Object)(object)_jesterBundle == (Object)null)
			{
				Log.LogWarning((object)("[Jester] Failed to load asset bundle: " + text));
				return null;
			}
			_jesterVisualPrefab = _jesterBundle.LoadAsset<GameObject>("Box Jester");
			if ((Object)(object)_jesterVisualPrefab == (Object)null)
			{
				Log.LogWarning((object)"[Jester] Could not find prefab 'Box Jester' in asset bundle.");
			}
			else
			{
				CacheJesterAnimationClips(_jesterBundle);
			}
			return _jesterVisualPrefab;
		}

		private static void CacheJesterAnimationClips(AssetBundle bundle)
		{
			if (JesterAnimationClips.Count > 0)
			{
				return;
			}
			AnimationClip[] array = bundle.LoadAllAssets<AnimationClip>();
			foreach (AnimationClip val in array)
			{
				if ((Object)(object)val != (Object)null && !JesterAnimationClips.ContainsKey(((Object)val).name))
				{
					JesterAnimationClips.Add(((Object)val).name, val);
				}
			}
			Log.LogInfo((object)$"[Jester] Cached {JesterAnimationClips.Count} animation clips from asset bundle.");
		}

		internal static string? ResolvePluginFile(string fileName)
		{
			string text = Path.Combine(PluginDirectory, fileName);
			if (File.Exists(text))
			{
				return text;
			}
			try
			{
				string[] files = Directory.GetFiles(PluginDirectory, fileName, SearchOption.AllDirectories);
				foreach (string text2 in files)
				{
					if (File.Exists(text2))
					{
						return text2;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Jester] Failed while searching for '" + fileName + "' in plugin directory: " + ex.Message));
			}
			return null;
		}

		internal static AnimationClip? GetJesterAnimationClip(string clipName)
		{
			LoadJesterVisualPrefab();
			AnimationClip value;
			return JesterAnimationClips.TryGetValue(clipName, out value) ? value : null;
		}

		private static Bounds? GetCombinedRendererBounds(GameObject gameObject)
		{
			//IL_0005: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			Bounds value = default(Bounds);
			Renderer[] componentsInChildren = gameObject.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!flag)
				{
					value = val.bounds;
					flag = true;
				}
				else
				{
					((Bounds)(ref value)).Encapsulate(val.bounds);
				}
			}
			return flag ? new Bounds?(value) : null;
		}

		private static int ResolveVisualLayer(string layerName)
		{
			int num = LayerMask.NameToLayer(layerName);
			return (num >= 0) ? num : 0;
		}

		private static void SetVisualLayerRecursively(Transform root, int layer)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			((Component)root).gameObject.layer = layer;
			foreach (Transform item in root)
			{
				Transform root2 = item;
				SetVisualLayerRecursively(root2, layer);
			}
		}

		private static Material FindSeedMaterial(GameObject prefab)
		{
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			Renderer[] componentsInChildren = prefab.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if ((Object)(object)val.sharedMaterial != (Object)null)
				{
					return val.sharedMaterial;
				}
			}
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)3);
			try
			{
				Renderer component = val2.GetComponent<Renderer>();
				if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMaterial != (Object)null)
				{
					return component.sharedMaterial;
				}
			}
			finally
			{
				Object.Destroy((Object)(object)val2);
			}
			string[] array = new string[4] { "Standard", "Universal Render Pipeline/Lit", "HDRP/Lit", "Sprites/Default" };
			foreach (string text in array)
			{
				Shader val3 = Shader.Find(text);
				if ((Object)(object)val3 != (Object)null)
				{
					return new Material(val3);
				}
			}
			throw new InvalidOperationException("Could not resolve a fallback material for the Jester visuals.");
		}

		private static Material CreateTintedMaterial(Material seedMaterial, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: 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)
			Material val = new Material(seedMaterial);
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", color);
			}
			if (val.HasProperty("_Color"))
			{
				val.SetColor("_Color", color);
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", color * 0.08f);
			}
			return val;
		}

		private static Transform CreatePiece(string name, PrimitiveType primitiveType, Transform parent, Vector3 localPosition, Vector3 localScale, Material material, Vector3? localEulerAngles = null)
		{
			//IL_0001: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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)
			GameObject val = GameObject.CreatePrimitive(primitiveType);
			((Object)val).name = name;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localScale = localScale;
			val.transform.localRotation = Quaternion.Euler((Vector3)(((??)localEulerAngles) ?? Vector3.zero));
			Collider[] components = val.GetComponents<Collider>();
			foreach (Collider val2 in components)
			{
				val2.enabled = false;
			}
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.sharedMaterial = material;
			}
			return val.transform;
		}

		private static AudioSource CreateAudioSource(GameObject owner, string name, float spatialBlend, float maxDistance, float volume)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(owner.transform, false);
			AudioSource val2 = val.AddComponent<AudioSource>();
			val2.playOnAwake = false;
			val2.loop = false;
			val2.spatialBlend = spatialBlend;
			val2.rolloffMode = (AudioRolloffMode)1;
			val2.minDistance = 1f;
			val2.maxDistance = maxDistance;
			val2.dopplerLevel = 0f;
			val2.volume = volume;
			return val2;
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "Start")]
	internal static class EmpressRepoJesterEnemyDirectorStartPatch
	{
		private static void Postfix()
		{
			EmpressRepoJesterPlugin.RefreshSpawnManagerEnemyNames();
		}
	}
	internal static class RepoEnemyAccess
	{
		private static readonly FieldRef<EnemyParent, Enemy> EnemyParentEnemyRef = AccessTools.FieldRefAccess<EnemyParent, Enemy>("Enemy");

		private static readonly FieldRef<EnemyParent, bool> EnemyParentSetupDoneRef = AccessTools.FieldRefAccess<EnemyParent, bool>("SetupDone");

		private static readonly FieldRef<Enemy, EnemyParent> EnemyEnemyParentRef = AccessTools.FieldRefAccess<Enemy, EnemyParent>("EnemyParent");

		private static readonly FieldRef<Enemy, bool> EnemyHasStateSpawnRef = AccessTools.FieldRefAccess<Enemy, bool>("HasStateSpawn");

		private static readonly FieldRef<Enemy, bool> EnemyHasStateStunnedRef = AccessTools.FieldRefAccess<Enemy, bool>("HasStateStunned");

		private static readonly FieldRef<Enemy, PhotonView> EnemyPhotonViewRef = AccessTools.FieldRefAccess<Enemy, PhotonView>("PhotonView");

		private static readonly FieldRef<Enemy, EnemyStateSpawn> EnemyStateSpawnRef = AccessTools.FieldRefAccess<Enemy, EnemyStateSpawn>("StateSpawn");

		private static readonly FieldRef<Enemy, EnemyStateStunned> EnemyStateStunnedRef = AccessTools.FieldRefAccess<Enemy, EnemyStateStunned>("StateStunned");

		private static readonly FieldRef<Enemy, int> EnemyTargetPlayerViewIdRef = AccessTools.FieldRefAccess<Enemy, int>("TargetPlayerViewID");

		private static readonly FieldRef<Enemy, LayerMask> EnemyVisionMaskRef = AccessTools.FieldRefAccess<Enemy, LayerMask>("VisionMask");

		private static readonly FieldRef<EnemyNavMeshAgent, NavMeshAgent> EnemyNavMeshAgentAgentRef = AccessTools.FieldRefAccess<EnemyNavMeshAgent, NavMeshAgent>("Agent");

		private static readonly FieldRef<EnemyStateSpawn, Enemy> EnemyStateSpawnEnemyRef = AccessTools.FieldRefAccess<EnemyStateSpawn, Enemy>("Enemy");

		private static readonly FieldRef<EnemyStateStunned, Enemy> EnemyStateStunnedEnemyRef = AccessTools.FieldRefAccess<EnemyStateStunned, Enemy>("enemy");

		internal static void SetSetupDone(EnemyParent enemyParent, bool value)
		{
			EnemyParentSetupDoneRef.Invoke(enemyParent) = value;
		}

		internal static void SetEnemyParentEnemy(EnemyParent enemyParent, Enemy enemy)
		{
			EnemyParentEnemyRef.Invoke(enemyParent) = enemy;
		}

		internal static void SetEnemyParent(Enemy enemy, EnemyParent enemyParent)
		{
			EnemyEnemyParentRef.Invoke(enemy) = enemyParent;
		}

		internal static void SetPhotonView(Enemy enemy, PhotonView photonView)
		{
			EnemyPhotonViewRef.Invoke(enemy) = photonView;
		}

		internal static void SetStateSpawn(Enemy enemy, EnemyStateSpawn stateSpawn)
		{
			EnemyStateSpawnRef.Invoke(enemy) = stateSpawn;
		}

		internal static void SetHasStateSpawn(Enemy enemy, bool value)
		{
			EnemyHasStateSpawnRef.Invoke(enemy) = value;
		}

		internal static void SetStateStunned(Enemy enemy, EnemyStateStunned stateStunned)
		{
			EnemyStateStunnedRef.Invoke(enemy) = stateStunned;
		}

		internal static void SetHasStateStunned(Enemy enemy, bool value)
		{
			EnemyHasStateStunnedRef.Invoke(enemy) = value;
		}

		internal static void SetVisionMask(Enemy enemy, LayerMask visionMask)
		{
			//IL_000b: 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)
			EnemyVisionMaskRef.Invoke(enemy) = visionMask;
		}

		internal static void SetTargetPlayerViewId(Enemy enemy, int viewId)
		{
			EnemyTargetPlayerViewIdRef.Invoke(enemy) = viewId;
		}

		internal static void SetStateSpawnEnemy(EnemyStateSpawn stateSpawn, Enemy enemy)
		{
			EnemyStateSpawnEnemyRef.Invoke(stateSpawn) = enemy;
		}

		internal static void SetStateStunnedEnemy(EnemyStateStunned stateStunned, Enemy enemy)
		{
			EnemyStateStunnedEnemyRef.Invoke(stateStunned) = enemy;
		}

		internal static NavMeshAgent GetAgent(EnemyNavMeshAgent enemyNavMeshAgent)
		{
			return EnemyNavMeshAgentAgentRef.Invoke(enemyNavMeshAgent);
		}
	}
	[DefaultExecutionOrder(-100)]
	internal sealed class JesterTemplateBootstrap : MonoBehaviour
	{
		private const string EnableObjectName = "EnableObject";

		private const string EnemyObjectName = "JesterEnemy";

		private const string CenterObjectName = "Center";

		private const string TemplateContainerName = "EmpressJesterTemplateContainer";

		private static readonly HashSet<int> TemplateInstanceIds = new HashSet<int>();

		private static GameObject? _templateContainer;

		private bool _runtimeBuilt;

		internal static GameObject CreateTemplate(ManualLogSource log)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = EnsureTemplateContainer();
			GameObject val2 = new GameObject("EmpressJesterPrefab")
			{
				layer = ResolveLayer("Enemy")
			};
			val2.transform.SetParent(val.transform, false);
			TemplateInstanceIds.Add(((Object)val2).GetInstanceID());
			((Object)val2).hideFlags = (HideFlags)61;
			val2.transform.position = new Vector3(0f, -5000f, 0f);
			BuildTemplateCore(val2.transform);
			log.LogInfo((object)"Created Jester template core.");
			return val2;
		}

		internal static bool IsTemplateInstance(GameObject gameObject)
		{
			Transform val = gameObject.transform;
			while ((Object)(object)val.parent != (Object)null)
			{
				val = val.parent;
			}
			return TemplateInstanceIds.Contains(((Object)((Component)val).gameObject).GetInstanceID());
		}

		private static GameObject EnsureTemplateContainer()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if ((Object)(object)_templateContainer != (Object)null)
			{
				return _templateContainer;
			}
			_templateContainer = new GameObject("EmpressJesterTemplateContainer");
			((Object)_templateContainer).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)_templateContainer);
			_templateContainer.SetActive(false);
			return _templateContainer;
		}

		private void Start()
		{
			if (IsTemplateInstance(((Component)this).gameObject) || _runtimeBuilt)
			{
				return;
			}
			_runtimeBuilt = true;
			try
			{
				BuildRuntimeInstance();
			}
			catch (Exception arg)
			{
				EmpressRepoJesterPlugin.Log.LogError((object)$"Failed to finish Jester spawn: {arg}");
			}
		}

		private static void BuildTemplateCore(Transform root)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00b1: 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_00e7: Expected O, but got Unknown
			//IL_0112: 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_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: 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)
			int layer = ResolveLayer("Enemy");
			((Component)root).gameObject.layer = layer;
			TrySetTag(((Component)root).gameObject, "Enemy");
			EnemyParent val = ((Component)root).gameObject.AddComponent<EnemyParent>();
			PhotonView val2 = ((Component)root).gameObject.AddComponent<PhotonView>();
			val2.Synchronization = (ViewSynchronization)3;
			((Behaviour)val2).enabled = false;
			((Component)root).gameObject.AddComponent<JesterTemplateBootstrap>();
			GameObject val3 = new GameObject("EnableObject");
			val3.transform.SetParent(root, false);
			val3.layer = layer;
			TrySetTag(val3, "Enemy");
			GameObject val4 = new GameObject("JesterEnemy");
			val4.transform.SetParent(val3.transform, false);
			val4.transform.localPosition = Vector3.zero;
			val4.layer = layer;
			val4.SetActive(false);
			TrySetTag(val4, "Enemy");
			GameObject val5 = new GameObject("Center");
			val5.transform.SetParent(val4.transform, false);
			val5.transform.localPosition = new Vector3(0f, 1.1f, 0f);
			PhotonView val6 = val4.AddComponent<PhotonView>();
			val6.Synchronization = (ViewSynchronization)3;
			((Behaviour)val6).enabled = false;
			CapsuleCollider val7 = val4.AddComponent<CapsuleCollider>();
			val7.center = new Vector3(0f, 1.1f, 0f);
			val7.height = 2.4f;
			val7.radius = 0.48f;
			EnemyStateSpawn stateSpawn = val4.AddComponent<EnemyStateSpawn>();
			EnemyStateStunned stateStunned = val4.AddComponent<EnemyStateStunned>();
			Enemy val8 = val4.AddComponent<Enemy>();
			val.enemyName = "Jester";
			val.difficulty = (Difficulty)2;
			val.actionMultiplier = 1.45f;
			val.overchargeMultiplier = 1.3f;
			val.EnableObject = val3;
			val.SpawnedTimeMin = 25f;
			val.SpawnedTimeMax = 40f;
			val.DespawnedTimeMin = 18f;
			val.DespawnedTimeMax = 32f;
			RepoEnemyAccess.SetSetupDone(val, value: false);
			RepoEnemyAccess.SetEnemyParentEnemy(val, val8);
			RepoEnemyAccess.SetEnemyParent(val8, val);
			RepoEnemyAccess.SetPhotonView(val8, val6);
			val8.CenterTransform = val5.transform;
			val8.KillLookAtTransform = val5.transform;
			val8.CustomValuableSpawnTransform = val5.transform;
			RepoEnemyAccess.SetStateSpawn(val8, stateSpawn);
			RepoEnemyAccess.SetHasStateSpawn(val8, value: true);
			RepoEnemyAccess.SetStateStunned(val8, stateStunned);
			RepoEnemyAccess.SetHasStateStunned(val8, value: true);
			RepoEnemyAccess.SetVisionMask(val8, LayerMask.op_Implicit(LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "HideTriggers" })));
			val8.CurrentState = (EnemyState)1;
			RepoEnemyAccess.SetTargetPlayerViewId(val8, -1);
			RepoEnemyAccess.SetStateSpawnEnemy(stateSpawn, val8);
			RepoEnemyAccess.SetStateStunnedEnemy(stateStunned, val8);
			val4.SetActive(true);
			val2.ObservedComponents = new List<Component> { (Component)(object)val };
			val6.ObservedComponents = new List<Component> { (Component)(object)val8 };
			SetLayerRecursively(root, layer);
			TrySetTagRecursively(root, "Enemy");
		}

		private void BuildRuntimeInstance()
		{
			if (!TryResolveCore(out EnemyParent enemyParent, out Enemy enemy, out EnemyStateSpawn stateSpawn, out EnemyStateStunned stateStunned, out PhotonView rootPhotonView, out PhotonView enemyPhotonView, out Transform centerTransform))
			{
				throw new InvalidOperationException("Jester core components were not present on spawned clone.");
			}
			SetHideFlagsRecursively(((Component)this).transform, (HideFlags)0);
			((Behaviour)rootPhotonView).enabled = true;
			((Behaviour)enemyPhotonView).enabled = true;
			EnsureRuntimeNavMeshAgent(enemy);
			EmpressRepoJesterPlugin.ConfigureRuntimeInstance(enemyParent, enemy, stateSpawn, stateStunned, rootPhotonView, enemyPhotonView, centerTransform);
		}

		private bool TryResolveCore(out EnemyParent enemyParent, out Enemy enemy, out EnemyStateSpawn stateSpawn, out EnemyStateStunned stateStunned, out PhotonView rootPhotonView, out PhotonView enemyPhotonView, out Transform centerTransform)
		{
			enemyParent = ((Component)this).GetComponent<EnemyParent>();
			rootPhotonView = ((Component)this).GetComponent<PhotonView>();
			enemy = ((Component)this).GetComponentInChildren<Enemy>(true);
			stateSpawn = ((Component)this).GetComponentInChildren<EnemyStateSpawn>(true);
			stateStunned = ((Component)this).GetComponentInChildren<EnemyStateStunned>(true);
			PhotonView val = (((Object)(object)enemy != (Object)null) ? ((Component)enemy).GetComponent<PhotonView>() : null);
			Transform val2 = (((Object)(object)enemy != (Object)null && (Object)(object)enemy.CenterTransform != (Object)null) ? enemy.CenterTransform : ((Component)this).transform.Find("EnableObject/JesterEnemy/Center"));
			enemyPhotonView = val;
			centerTransform = val2;
			return (Object)(object)enemyParent != (Object)null && (Object)(object)enemy != (Object)null && (Object)(object)stateSpawn != (Object)null && (Object)(object)stateStunned != (Object)null && (Object)(object)rootPhotonView != (Object)null && (Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null;
		}

		private static EnemyNavMeshAgent EnsureRuntimeNavMeshAgent(Enemy enemy)
		{
			//IL_0068: 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_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			if (TryFindNearestNavMeshPoint(enemy, out var hit))
			{
				((Component)enemy).transform.position = ((NavMeshHit)(ref hit)).position;
				if ((Object)(object)((Component)enemy).transform.parent != (Object)null)
				{
					((Component)enemy).transform.parent.position = ((NavMeshHit)(ref hit)).position;
				}
			}
			else
			{
				EmpressRepoJesterPlugin.Log.LogWarning((object)$"[Jester] Could not find nearby NavMesh for spawned Jester at {((Component)enemy).transform.position}.");
			}
			NavMeshAgent val = ((Component)enemy).GetComponent<NavMeshAgent>() ?? ((Component)enemy).gameObject.AddComponent<NavMeshAgent>();
			ConfigureNavMeshAgent(val);
			EnemyNavMeshAgent val2 = ((Component)enemy).GetComponent<EnemyNavMeshAgent>() ?? ((Component)enemy).gameObject.AddComponent<EnemyNavMeshAgent>();
			val2.Agent = val;
			val2.updateRotation = false;
			val2.DefaultSpeed = val.speed;
			val2.DefaultAcceleration = val.acceleration;
			((Behaviour)val2).enabled = false;
			if (!((Behaviour)val).enabled && TryFindNearestNavMeshPoint(enemy, out var hit2))
			{
				((Behaviour)val).enabled = true;
				val.Warp(((NavMeshHit)(ref hit2)).position);
			}
			return val2;
		}

		private static bool TryFindNearestNavMeshPoint(Enemy enemy, out NavMeshHit hit)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_004b: 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_0066: 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_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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[3]
			{
				((Component)enemy).transform.position,
				((Object)(object)((Component)enemy).transform.parent != (Object)null) ? ((Component)enemy).transform.parent.position : ((Component)enemy).transform.position,
				((Object)(object)enemy.EnemyParent != (Object)null) ? ((Component)enemy.EnemyParent).transform.position : ((Component)enemy).transform.position
			};
			float[] array2 = new float[5] { 6f, 12f, 24f, 48f, 96f };
			Vector3[] array3 = array;
			foreach (Vector3 val in array3)
			{
				float[] array4 = array2;
				foreach (float num in array4)
				{
					if (NavMesh.SamplePosition(val, ref hit, num, -1))
					{
						return true;
					}
				}
			}
			hit = default(NavMeshHit);
			return false;
		}

		private static void ConfigureNavMeshAgent(NavMeshAgent navMeshAgent)
		{
			navMeshAgent.speed = 6f;
			navMeshAgent.acceleration = 48f;
			navMeshAgent.angularSpeed = 220f;
			navMeshAgent.stoppingDistance = 1.15f;
			navMeshAgent.radius = 0.42f;
			navMeshAgent.height = 2.55f;
			navMeshAgent.autoTraverseOffMeshLink = true;
			navMeshAgent.obstacleAvoidanceType = (ObstacleAvoidanceType)4;
		}

		private static int ResolveLayer(string layerName)
		{
			int num = LayerMask.NameToLayer(layerName);
			return (num >= 0) ? num : 0;
		}

		private static void SetHideFlagsRecursively(Transform root, HideFlags hideFlags)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			((Object)((Component)root).gameObject).hideFlags = hideFlags;
			foreach (Transform item in root)
			{
				Transform root2 = item;
				SetHideFlagsRecursively(root2, hideFlags);
			}
		}

		private static void SetLayerRecursively(Transform root, int layer)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			((Component)root).gameObject.layer = layer;
			foreach (Transform item in root)
			{
				Transform root2 = item;
				SetLayerRecursively(root2, layer);
			}
		}

		private static void TrySetTagRecursively(Transform root, string tag)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			TrySetTag(((Component)root).gameObject, tag);
			foreach (Transform item in root)
			{
				Transform root2 = item;
				TrySetTagRecursively(root2, tag);
			}
		}

		private static void TrySetTag(GameObject gameObject, string tag)
		{
			try
			{
				gameObject.tag = tag;
			}
			catch (UnityException)
			{
			}
		}
	}
	[DisallowMultipleComponent]
	public sealed class EmpressRepoJesterAuthoring : MonoBehaviour
	{
		internal const float DefaultDoorPushRadius = 0.55f;

		internal const float DefaultDoorPushForce = 2.8f;

		internal const float DefaultDoorPushTorque = 1.1f;

		public Transform? DoorPushProbe;

		public bool UseProbeScaleAsRadius = true;

		public float DoorPushRadius = 0.55f;

		public float DoorPushForce = 2.8f;

		public float DoorPushTorque = 1.1f;

		public float ResolveDoorPushRadius()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			float result = Mathf.Max(0.05f, DoorPushRadius);
			if (!UseProbeScaleAsRadius || (Object)(object)DoorPushProbe == (Object)null)
			{
				return result;
			}
			Vector3 lossyScale = DoorPushProbe.lossyScale;
			float num = Mathf.Max(new float[3]
			{
				Mathf.Abs(lossyScale.x),
				Mathf.Abs(lossyScale.y),
				Mathf.Abs(lossyScale.z)
			}) * 0.5f;
			return Mathf.Max(0.05f, num);
		}
	}
	public sealed class EmpressRepoJesterController : MonoBehaviour
	{
		private enum JesterPhase
		{
			Boxed,
			Cranking,
			Popping,
			Chasing
		}

		private const string IdleAnimationState = "jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_idl";

		private const string WalkAnimationState = "jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_wal";

		private const string WindAnimationState = "jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_win";

		private const string PopAnimationState = "jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_pop";

		private const string RunAnimationState = "jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_run";

		private const float WindupPopCueTime = 40f;

		private const float JesterMeshClosedY = -0.348f;

		private const float JesterMeshOpenY = -0.156f;

		private const float DoorPushCooldownTime = 0.12f;

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

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

		public string TemplateBehaviourTypeName = string.Empty;

		public Transform VisualRoot = null;

		public Transform CenterTransform = null;

		public Transform HeadTransform = null;

		public Transform LidTransform = null;

		public Transform LeftArmTransform = null;

		public Transform RightArmTransform = null;

		public Transform WindKeyTransform = null;

		public Transform SpringTransform = null;

		public Animator? VisualAnimator;

		public Transform? JesterMeshTransform;

		public Transform? DoorPushProbeTransform;

		public float DoorPushRadius = 0.55f;

		public float DoorPushForce = 2.8f;

		public float DoorPushTorque = 1.1f;

		public AudioSource MusicSource = null;

		public AudioSource SfxSource = null;

		public AudioSource VoiceSource = null;

		public AudioClip WindupClip = null;

		public AudioClip PopClip = null;

		public AudioClip ScreamClip = null;

		public AudioClip KillClip = null;

		public AudioClip[] StompClips = Array.Empty<AudioClip>();

		private Enemy _enemy = null;

		private EnemyParent _enemyParent = null;

		private EnemyVision? _vision;

		private EnemyNavMeshAgent? _navAgent;

		private EnemyRigidbody? _enemyBody;

		private EnemyHealth? _health;

		private PhotonView _photonView = null;

		private PlayerAvatar? _targetPlayer;

		private int _targetViewId = -1;

		private JesterPhase _phase;

		private float _phaseTimer;

		private float _beginCrankingTimer;

		private float _popTimer;

		private float _noTargetTimer;

		private float _speed;

		private float _roamRetargetTimer;

		private float _windKeySpin;

		private float _bodyBobTime;

		private Vector3 _roamDestination;

		private bool _spawnedPrevious;

		private bool _listenersHooked;

		private float _killCooldown;

		private bool _audioPausedForStun;

		private bool _initialized;

		private bool _windupStarted;

		private float _windupClipLength;

		private int _stompIndex;

		private float _stompTimer;

		private Vector3 _lastPosition;

		private float _movementSpeed;

		private bool _hasLastPosition;

		private float _doorPushCooldown;

		private string _currentAnimationState = string.Empty;

		private float _popAnimationDuration = 0.8f;

		private Vector3 _jesterMeshClosedLocalPosition;

		private Vector3 _jesterMeshOpenLocalPosition;

		private bool _hasJesterMeshPose;

		private PlayableGraph _animationGraph;

		private bool _animationGraphCreated;

		private void Awake()
		{
			_enemy = ((Component)this).GetComponent<Enemy>();
			_enemyParent = ((Component)this).GetComponentInParent<EnemyParent>() ?? ((Component)this).GetComponent<EnemyParent>() ?? ((Component)this).GetComponentInChildren<EnemyParent>(true);
			_photonView = ((Component)this).GetComponent<PhotonView>();
			_vision = (_enemy.HasVision ? _enemy.Vision : null);
			_navAgent = (EnemyNavMeshAgent?)(_enemy.HasNavMeshAgent ? ((object)_enemy.NavMeshAgent) : ((object)FindNearbyComponent<EnemyNavMeshAgent>((Component)(object)_enemy)));
			_enemyBody = (EnemyRigidbody?)(_enemy.HasRigidbody ? ((object)_enemy.Rigidbody) : ((object)FindNearbyComponent<EnemyRigidbody>((Component)(object)_enemy)));
			_health = (_enemy.HasHealth ? _enemy.Health : null);
		}

		public void InitializeRuntime()
		{
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				if ((Object)(object)VisualAnimator != (Object)null)
				{
					((Behaviour)VisualAnimator).enabled = true;
					VisualAnimator.applyRootMotion = false;
					VisualAnimator.runtimeAnimatorController = null;
					VisualAnimator.Rebind();
					VisualAnimator.Update(0f);
					_popAnimationDuration = GetAnimationDuration("jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_jester_lc_jester.dmx_skeleton_pop", 0.8f);
				}
				if ((Object)(object)JesterMeshTransform != (Object)null)
				{
					_jesterMeshClosedLocalPosition = JesterMeshTransform.localPosition;
					_jesterMeshClosedLocalPosition.y = -0.348f;
					_jesterMeshOpenLocalPosition = _jesterMeshClosedLocalPosition;
					_jesterMeshOpenLocalPosition.y = -0.156f;
					JesterMeshTransform.localPosition = _jesterMeshClosedLocalPosition;
					_hasJesterMeshPose = true;
				}
				DisableLegacyBehaviour();
				DisableGenericAiModules();
				ResetBoxCycle();
				ApplyVisualPose(forceClosed: true);
				_initialized = true;
			}
		}

		private void OnDestroy()
		{
			DestroyAnimationGraph();
		}

		private static T? FindNearbyComponent<T>(Component component) where T : Component
		{
			return component.GetComponent<T>() ?? component.GetComponentInChildren<T>(true) ?? component.GetComponentInParent<T>(true);
		}

		private void OnEnable()
		{
			if (_initialized)
			{
				HookListeners();
			}
		}

		private void OnDisable()
		{
			UnhookListeners();
		}

		private void Update()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				return;
			}
			if (_hasLastPosition && Time.deltaTime > 0f)
			{
				_movementSpeed = Vector3.Distance(((Component)this).transform.position, _lastPosition) / Time.deltaTime;
			}
			_lastPosition = ((Component)this).transform.position;
			_hasLastPosition = true;
			_bodyBobTime += Time.deltaTime;
			_phaseTimer += Time.deltaTime;
			bool flag = (Object)(object)_enemyParent != (Object)null && _enemyParent.Spawned && ((Object)(object)_enemyParent.EnableObject == (Object)null || _enemyParent.EnableObject.activeSelf);
			if (flag != _spawnedPrevious)
			{
				_spawnedPrevious = flag;
				if (flag)
				{
					ResetBoxCycle();
				}
				else
				{
					StopAllAudio();
				}
			}
			if (!flag)
			{
				ApplyVisualPose(forceClosed: true);
				return;
			}
			if (HasAuthority())
			{
				RunAuthorityLogic();
			}
			else
			{
				UpdateRemoteAudioState();
			}
			AnimateVisuals();
		}

		private void UpdateRemoteAudioState()
		{
			switch (_phase)
			{
			case JesterPhase.Boxed:
				StopAllAudio();
				break;
			case JesterPhase.Cranking:
				if (!_windupStarted && (Object)(object)MusicSource != (Object)null && (Object)(object)WindupClip != (Object)null)
				{
					MusicSource.clip = WindupClip;
					MusicSource.loop = false;
					MusicSource.time = 0f;
					MusicSource.Play();
					_windupClipLength = (((Object)(object)MusicSource.clip != (Object)null) ? MusicSource.clip.length : 0f);
					_windupStarted = true;
				}
				break;
			case JesterPhase.Popping:
				break;
			case JesterPhase.Chasing:
				UpdateStompAudio();
				break;
			}
		}

		private void HookListeners()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Expected O, but got Unknown
			if (!_listenersHooked)
			{
				if ((Object)(object)_vision != (Object)null)
				{
					_vision.onVisionTriggered.AddListener(new UnityAction(OnVisionTriggered));
				}
				if ((Object)(object)_health != (Object)null)
				{
					_health.onDeath.AddListener(new UnityAction(OnDeath));
				}
				_listenersHooked = true;
			}
		}

		private void UnhookListeners()
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Expected O, but got Unknown
			if (_listenersHooked)
			{
				if ((Object)(object)_vision != (Object)null)
				{
					_vision.onVisionTriggered.RemoveListener(new UnityAction(OnVisionTriggered));
				}
				if ((Object)(object)_health != (Object)null)
				{
					_health.onDeath.RemoveListener(new UnityAction(OnDeath));
				}
				_listenersHooked = false;
			}
		}

		private void DisableLegacyBehaviour()
		{
			MonoBehaviour[] components = ((Component)this).GetComponents<MonoBehaviour>();
			foreach (MonoBehaviour val in components)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)this))
				{
					string name = ((object)val).GetType().Name;
					if ((!string.IsNullOrEmpty(TemplateBehaviourTypeName) && name.StartsWith(TemplateBehaviourTypeName, StringComparison.Ordinal)) || name.EndsWith("Anim", StringComparison.Ordinal))
					{
						((Behaviour)val).enabled = false;
					}
				}
			}
		}

		private void DisableGenericAiModules()
		{
			if (_enemy.HasStateInvestigate && (Object)(object)_enemy.StateInvestigate != (Object)null)
			{
				((Behaviour)_enemy.StateInvestigate).enabled = false;
			}
			if (_enemy.HasStateChaseBegin && (Object)(object)_enemy.StateChaseBegin != (Object)null)
			{
				((Behaviour)_enemy.StateChaseBegin).enabled = false;
			}
			if (_enemy.HasStateChase && (Object)(object)_enemy.StateChase != (Object)null)
			{
				((Behaviour)_enemy.StateChase).enabled = false;
			}
			if (_enemy.HasStateLookUnder && (Object)(object)_enemy.StateLookUnder != (Object)null)
			{
				((Behaviour)_enemy.StateLookUnder).enabled = false;
			}
			if (_enemy.HasAttackPhysObject && (Object)(object)_enemy.AttackStuckPhysObject != (Object)null)
			{
				((Behaviour)_enemy.AttackStuckPhysObject).enabled = false;
			}
		}

		private bool HasAuthority()
		{
			return !SemiFunc.IsMultiplayer() || PhotonNetwork.IsMasterClient;
		}

		private void RunAuthorityLogic()
		{
			if (_killCooldown > 0f)
			{
				_killCooldown -= Time.deltaTime;
			}
			if (_doorPushCooldown > 0f)
			{
				_doorPushCooldown -= Time.deltaTime;
			}
			if ((Object)(object)_targetPlayer != (Object)null && !IsTargetValid(_targetPlayer))
			{
				_targetPlayer = null;
				_targetViewId = -1;
			}
			switch (_phase)
			{
			case JesterPhase.Boxed:
				RunBoxedLogic();
				break;
			case JesterPhase.Cranking:
				RunCrankingLogic();
				break;
			case JesterPhase.Popping:
				RunPoppingLogic();
				break;
			case JesterPhase.Chasing:
				RunChasingLogic();
				break;
			}
			UpdateDoorInteraction();
		}

		private void RunBoxedLogic()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			StopVoiceLoop();
			if ((Object)(object)MusicSource != (Object)null)
			{
				MusicSource.loop = false;
			}
			_speed = Mathf.MoveTowards(_speed, 0f, Time.deltaTime * 8f);
			AcquireNearestTarget(55f);
			if (_enemy.IsStunned())
			{
				_beginCrankingTimer -= Time.deltaTime * 12f;
			}
			else if ((Object)(object)_targetPlayer != (Object)null)
			{
				float num = Vector3.Distance(((Component)this).transform.position, ((Component)_targetPlayer).transform.position);
				if (num > 7f)
				{
					_beginCrankingTimer = 1.15f;
					MoveTowardsPosition(GetStandOffPosition(((Component)_targetPlayer).transform.position, 5.5f), 1.6f, 7f, 8f, 7f);
				}
				else
				{
					FaceTowards(((Component)_targetPlayer).transform.position, 8f);
					StopMoving();
					_beginCrankingTimer -= Time.deltaTime;
				}
			}
			else
			{
				RoamStep();
				_beginCrankingTimer = Mathf.Max(_beginCrankingTimer, 1.15f);
			}
			if (_beginCrankingTimer <= 0f)
			{
				SwitchPhase(JesterPhase.Cranking);
			}
		}

		private void RunCrankingLogic()
		{
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			_enemyParent.SpawnedTimerPause(0.5f);
			AcquireNearestTarget(60f);
			StopMoving();
			if (_enemy.IsStunned())
			{
				if (!_audioPausedForStun && (Object)(object)MusicSource != (Object)null && MusicSource.isPlaying)
				{
					MusicSource.Pause();
					_audioPausedForStun = true;
				}
				return;
			}
			if (_audioPausedForStun)
			{
				AudioSource musicSource = MusicSource;
				if (musicSource != null)
				{
					musicSource.UnPause();
				}
				_audioPausedForStun = false;
			}
			if (!_windupStarted && (Object)(object)MusicSource != (Object)null && (Object)(object)WindupClip != (Object)null)
			{
				MusicSource.clip = WindupClip;
				MusicSource.loop = false;
				MusicSource.pitch = 1f;
				MusicSource.time = 0f;
				MusicSource.Play();
				_windupClipLength = (((Object)(object)MusicSource.clip != (Object)null) ? MusicSource.clip.length : 0f);
				_windupStarted = true;
			}
			else if (!_windupStarted && (Object)(object)WindupClip == (Object)null)
			{
				EmpressRepoJesterPlugin.Log.LogWarning((object)"[Jester] Windup clip was not loaded from the plugin folder.");
				_windupStarted = true;
				_windupClipLength = 0f;
			}
			if ((Object)(object)_targetPlayer != (Object)null)
			{
				FaceTowards(((Component)_targetPlayer).transform.position, 8f);
			}
			if (_windupStarted && ShouldBeginPop())
			{
				SwitchPhase(JesterPhase.Popping);
			}
		}

		private void RunPoppingLogic()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			_enemyParent.SpawnedTimerPause(0.5f);
			StopMoving();
			if ((Object)(object)_targetPlayer != (Object)null)
			{
				FaceTowards(((Component)_targetPlayer).transform.position, 10f);
			}
			if (_windupStarted && ShouldPopNow())
			{
				SwitchPhase(JesterPhase.Chasing);
			}
		}

		private void RunChasingLogic()
		{
			//IL_00b7: 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_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			_enemyParent.SpawnedTimerPause(1f);
			if (_phaseTimer >= 10f)
			{
				ExpireChaseMode();
				return;
			}
			AcquireNearestTarget(250f);
			if ((Object)(object)_targetPlayer == (Object)null)
			{
				_noTargetTimer -= Time.deltaTime;
				RoamStep(13.5f, 30f, fastRoam: true);
				UpdateStompAudio();
				return;
			}
			_noTargetTimer = 5f;
			_speed = Mathf.MoveTowards(_speed, 17.5f, Time.deltaTime * 4.5f);
			Vector3 position = ((Component)_targetPlayer).transform.position;
			if (_enemy.IsStunned())
			{
				StopMoving();
				return;
			}
			UpdateStompAudio();
			MoveTowardsPosition(position, _speed, 12f, Mathf.Max(20f, _speed * 4f), 18f);
			_enemy.CurrentState = (EnemyState)2;
			TryKillNearbyPlayer();
		}

		private void RoamStep(float speedOverride = 2.8f, float accelerationOverride = 10f, bool fastRoam = false)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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_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_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			_roamRetargetTimer -= Time.deltaTime;
			if (_roamRetargetTimer <= 0f || Vector3.Distance(((Component)this).transform.position, _roamDestination) <= (fastRoam ? 2.2f : 1.2f))
			{
				LevelPoint val = SemiFunc.LevelPointGet(((Component)this).transform.position, fastRoam ? 10f : 4f, fastRoam ? 48f : 16f);
				if ((Object)(object)val == (Object)null)
				{
					val = SemiFunc.LevelPointGet(((Component)this).transform.position, 0f, fastRoam ? 90f : 40f);
				}
				if ((Object)(object)val != (Object)null)
				{
					_roamDestination = ((Component)val).transform.position;
				}
				else
				{
					_roamDestination = ((Component)this).transform.position + ((Component)this).transform.forward * (fastRoam ? 8f : 2f);
				}
				_roamRetargetTimer = (fastRoam ? Random.Range(0.75f, 1.5f) : Random.Range(2.5f, 5f));
			}
			MoveTowardsPosition(_roamDestination, speedOverride, fastRoam ? 14f : 8f, accelerationOverride, fastRoam ? 18f : 12f);
			_enemy.CurrentState = (EnemyState)2;
		}

		private void MoveTowardsPosition(Vector3 targetPosition, float speed, float turnSpeed, float acceleration, float bodyFollowSpeed)
		{
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00b4: 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)
			bool flag = false;
			if ((Object)(object)_navAgent != (Object)null && (Object)(object)_navAgent.Agent != (Object)null)
			{
				try
				{
					_navAgent.Enable();
					if (((Behaviour)_navAgent.Agent).enabled && _navAgent.Agent.isOnNavMesh)
					{
						_navAgent.UpdateAgent(speed, acceleration);
						_navAgent.SetDestination(targetPosition);
						Vector3 desiredVelocity = _navAgent.Agent.desiredVelocity;
						if (((Vector3)(ref desiredVelocity)).sqrMagnitude > 0.01f)
						{
							FaceAlongDirection(desiredVelocity, turnSpeed);
						}
						else
						{
							FaceTowards(targetPosition, turnSpeed);
						}
						flag = true;
					}
				}
				catch
				{
					flag = false;
				}
			}
			if (!flag)
			{
				FaceTowards(targetPosition, turnSpeed);
				StopMoving();
			}
			else if ((Object)(object)_enemyBody != (Object)null)
			{
				_enemyBody.OverrideFollowPosition(0.15f, bodyFollowSpeed, 18f);
				_enemyBody.OverrideFollowRotation(0.15f, turnSpeed + 4f);
				_enemyBody.IdleSet(0f);
			}
		}

		private Vector3 GetStandOffPosition(Vector3 playerPosition, float desiredDistance)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Component)this).transform.position - playerPosition;
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude <= 0.001f)
			{
				val = -((Component)this).transform.forward;
			}
			return playerPosition + ((Vector3)(ref val)).normalized * desiredDistance;
		}

		private void StopMoving()
		{
			if ((Object)(object)_navAgent != (Object)null)
			{
				_navAgent.Stop(0.1f);
				_navAgent.ResetPath();
			}
			if ((Object)(object)_enemyBody != (Object)null)
			{
				_enemyBody.IdleSet(0.25f);
			}
		}

		private void FaceAlongDirection(Vector3 worldDirection, float turnSpeed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = worldDirection;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude <= 0.001f))
			{
				Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, turnSpeed * Time.deltaTime);
				if ((Object)(object)_enemyBody != (Object)null && (Object)(object)_enemyBody.followTarget != (Object)null)
				{
					_enemyBody.followTarget.rotation = ((Component)this).transform.rotation;
				}
			}
		}

		private void FaceTowards(Vector3 worldPosition, float turnSpeed)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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)
			Vector3 val = worldPosition - ((Component)this).transform.position;
			val.y = 0f;
			if (!(((Vector3)(ref val)).sqrMagnitude <= 0.001f))
			{
				Quaternion val2 = Quaternion.LookRotation(((Vector3)(ref val)).normalized, Vector3.up);
				((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val2, turnSpeed * Time.deltaTime);
				if ((Object)(object)_enemyBody != (Object)null && (Object)(object)_enemyBody.followTarget != (Object)null)
				{
					_enemyBody.followTarget.rotation = ((Component)this).transform.rotation;
				}
			}
		}

		private void OnVisionTriggered()
		{
			if (!((Object)(object)_vision?.onVisionTriggeredPlayer == (Object)null))
			{
				_targetPlayer = _vision.onVisionTriggeredPlayer;
				_targetViewId = _targetPlayer.photonView.ViewID;
				if (_phase == JesterPhase.Boxed)
				{
					_beginCrankingTimer = Mathf.Min(_beginCrankingTimer, Random.Range(2.5f, 5f));
				}
			}
		}

		private void ResetBoxCycle()
		{
			_targetPlayer = null;
			_targetViewId = -1;
			_beginCrankingTimer = Random.Range(13f, 21f);
			if ((Object)(object)GameDirector.instance != (Object)null && GameDirector.instance.PlayerList.Count <= 1)
			{
				_beginCrankingTimer = Random.Range(18f, 28f);
			}
			_popTimer = Random.Range(10.5f, 13.5f);
			_noTargetTimer = 5f;
			_roamRetargetTimer = 0f;
			_speed = 0f;
			_windupStarted = false;
			_windupClipLength = 0f;
			_stompIndex = 0;
			_stompTimer = 0f;
			SwitchPhase(JesterPhase.Boxed, broadcast: false);
			StopAllAudio();
			if ((Object)(object)_vision != (Object)null)
			{
				_vision.DisableVision(0.4f);
			}
		}

		private void ExpireChaseMode()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			StopAllAudio();
			StopMoving();
			if ((Object)(object)_health != (Object)null && !_health.dead && !_health.deadImpulse)
			{
				_health.Death(Vector3.zero);
			}
			else
			{
				_enemyParent.Despawn();
			}
		}

		private bool ShouldPopNow()
		{
			if (!_windupStarted)
			{
				return false;
			}
			if ((Object)(object)MusicSource == (Object)null)
			{
				return true;
			}
			if ((Object)(object)MusicSource.clip == (Object)null)
			{
				return !MusicSource.isPlaying;
			}
			float num = ((_windupClipLength > 0f) ? _windupClipLength : MusicSource.clip.length);
			if (num > 0f && MusicSource.time >= num - 0.03f)
			{
				return true;
			}
			return !MusicSource.isPlaying && MusicSource.time > 0f;
		}

		private bool ShouldBeginPop()
		{
			if (!_windupStarted)
			{
				return false;
			}
			if ((Object)(object)MusicSource == (Object)null || (Object)(object)MusicSource.clip == (Object)null)
			{
				return ShouldPopNow();
			}
			float num = Mathf.Min(40f, Mathf.Max(0.05f, MusicSource.clip.length - 0.05f));
			return MusicSource.time >= num;
		}

		private void UpdateStompAudio()
		{
			if ((Object)(object)SfxSource == (Object)null || StompClips == null || StompClips.Length == 0)
			{
				return;
			}
			if (_movementSpeed < 1.25f || _phase != JesterPhase.Chasing)
			{
				if (SfxSource.isPlaying)
				{
					SfxSource.Stop();
				}
				_stompTimer = 0f;
				return;
			}
			_stompTimer -= Time.deltaTime;
			float num = Mathf.InverseLerp(7f, 18f, Mathf.Max(_speed, _movementSpeed));
			float stompTimer = Mathf.Lerp(0.52f, 0.18f, num);
			SfxSource.pitch = Mathf.Lerp(0.95f, 1.18f, num);
			if (!(_stompTimer > 0f))
			{
				AudioClip val = StompClips[_stompIndex % StompClips.Length];
				if ((Object)(object)val != (Object)null)
				{
					SfxSource.PlayOneShot(val);
				}
				_stompIndex++;
				_stompTimer = stompTimer;
			}
		}

		private void UpdateDoorInteraction()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: 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_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: 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_023d: Unknown result type (might be due to invalid IL or missing references)
			bool flag = _doorPushCooldown > 0f;
			bool flag2 = flag;
			if (!flag2)
			{
				JesterPhase phase = _phase;
				bool flag3 = (uint)(phase - 1) <= 1u;
				flag2 = flag3;
			}
			if (flag2)
			{
				return;
			}
			Vector3 doorPushDirection = GetDoorPushDirection();
			if (((Vector3)(ref doorPushDirection)).sqrMagnitude <= 0.04f)
			{
				return;
			}
			Vector3 val = (((Object)(object)DoorPushProbeTransform != (Object)null) ? DoorPushProbeTransform.position : (CenterTransform.position + doorPushDirection * 0.72f));
			float num = Mathf.Max(0.05f, DoorPushRadius);
			int num2 = Physics.OverlapSphereNonAlloc(val, num, DoorPushHits, DoorPushMask, (QueryTriggerInteraction)1);
			if (num2 <= 0)
			{
				return;
			}
			for (int i = 0; i < num2; i++)
			{
				Collider val2 = DoorPushHits[i];
				DoorPushHits[i] = null;
				if ((Object)(object)val2 == (Object)null || ((Component)val2).transform.IsChildOf(((Component)this).transform))
				{
					continue;
				}
				PhysGrabHinge componentInParent = ((Component)val2).GetComponentInParent<PhysGrabHinge>();
				if ((Object)(object)componentInParent == (Object)null)
				{
					continue;
				}
				PhysGrabObject component = ((Component)componentInParent).GetComponent<PhysGrabObject>();
				Rigidbody component2 = ((Component)componentInParent).GetComponent<Rigidbody>();
				HingeJoint component3 = ((Component)componentInParent).GetComponent<HingeJoint>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null) && !((Object)(object)component3 == (Object)null) && !component2.isKinematic)
				{
					Vector3 val3 = val2.ClosestPoint(val);
					Vector3 val4 = doorPushDirection * DoorPushForce;
					val4.y = Mathf.Max(val4.y, 0.08f);
					Vector3 val5 = ((Component)componentInParent).transform.position - ((Component)this).transform.position;
					val5.y = 0f;
					float num3 = Mathf.Sign(Vector3.Dot(Vector3.Cross(val5, doorPushDirection), Vector3.up));
					if (Mathf.Abs(num3) < 0.01f)
					{
						num3 = 1f;
					}
					component.EnemyInteractTimeSet();
					component2.AddForceAtPosition(val4, val3, (ForceMode)1);
					component2.AddTorque(Vector3.up * (DoorPushTorque * num3), (ForceMode)1);
					_doorPushCooldown = 0.12f;
					break;
				}
			}
		}

		private Vector3 GetDoorPushDirection()
		{
			//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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: 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_00c6: 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)
			Vector3 val = Vector3.zero;
			if ((Object)(object)_navAgent != (Object)null && (Object)(object)_navAgent.Agent != (Object)null && ((Behaviour)_navAgent.Agent).enabled && _navAgent.Agent.isOnNavMesh)
			{
				val = _navAgent.Agent.desiredVelocity;
			}
			val.y = 0f;
			if (((Vector3)(ref val)).sqrMagnitude > 0.04f)
			{
				return ((Vector3)(ref val)).normalized;
			}
			Vector3 forward = ((Component)this).transform.forward;
			forward.y = 0f;
			return (((Vector3)(ref forward)).sqrMagnitude > 0.001f) ? ((Vector3)(ref forward)).normalized : Vector3.zero;
		}

		private void SwitchPhase(JesterPhase phase, bool broadcast = true)
		{
			_phase = phase;
			_phaseTimer = 0f;
			_audioPausedForStun = false;
			switch (phase)
			{
			case JesterPhase.Boxed:
				StopAllAudio();
				break;
			case JesterPhase.Cranking:
				StopVoiceLoop();
				_windupStarted = false;
				_windupClipLength = 0f;
				if (