Decompiled source of CreepyMita Enemy v1.1.1

BepInEx\plugins\Omniscye-CreepyMita_Enemy\Mita.dll

Decompiled a week 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.Playables;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5f1b735e473ca4ccf3b383128fbebd889cb564da")]
[assembly: AssemblyProduct("Mita")]
[assembly: AssemblyTitle("Mita")]
[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.Mita
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("Empress.REPO.Mita", "Empress REPO Mita", "1.0.0")]
	public sealed class EmpressRepoMitaPlugin : BaseUnityPlugin
	{
		private const string MitaBundleFileName = "empressmita";

		private const string MitaAudioBundleFileName = "empressmitaaudio";

		private const float MitaBundleVisualScale = 0.96f;

		private const string BodyAlbedoTextureFileName = "CreepyMitaBody.png";

		private const string BodyNormalTextureFileName = "";

		private const string ClothesAlbedoTextureFileName = "CreepyMitaClothes.png";

		private const string ClothesNormalTextureFileName = "";

		private const string FaceAlbedoTextureFileName = "Face_2.png";

		private const string HairAlbedoTextureFileName = "TestHairsalpha2.png";

		private const string HairNormalTextureFileName = "TestHairsN2.png";

		private const string TeddyAlbedoTextureFileName = "TeddyBear.png";

		private static readonly string[] MitaBundlePrefabCandidates = new string[4] { "MitaCreepy", "Mita", "MitaCreepyVisual", "CreepyMita" };

		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.Mita";

		internal const string PluginName = "Empress REPO Mita";

		internal const string PluginVersion = "1.0.0";

		internal const string TemplatePrefabName = "EmpressMitaPrefab";

		private static Harmony? _harmony;

		private static bool _registered;

		private static MethodInfo? _spawnManagerRefreshMethod;

		private static AssetBundle? _mitaBundle;

		private static AssetBundle? _mitaAudioBundle;

		private static GameObject? _mitaVisualPrefab;

		internal static AnimationClip[]? BundleAnimationClips;

		private static Material? _bodyMaterial;

		private static Material? _clothesMaterial;

		private static Material? _faceMaterial;

		private static Material? _hairMaterial;

		private static Material? _teddyMaterial;

		private static Texture2D? _bodyAlbedoTexture;

		private static Texture2D? _bodyNormalTexture;

		private static Texture2D? _clothesAlbedoTexture;

		private static Texture2D? _clothesNormalTexture;

		private static Texture2D? _faceAlbedoTexture;

		private static Texture2D? _hairAlbedoTexture;

		private static Texture2D? _hairNormalTexture;

		private static Texture2D? _teddyAlbedoTexture;

		private static PhysAttribute? _grabPhysAttribute;

		private static Durability? _grabDurability;

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


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


		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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.Mita");
			}
			PatchTemplateGuards(_harmony);
			RegisterEnemy();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Empress REPO Mita v1.0.0");
		}

		private void RegisterEnemy()
		{
			if (!_registered)
			{
				GameObject item = MitaTemplateBootstrap.CreateTemplate(((BaseUnityPlugin)this).Logger);
				RarityPreset val = ScriptableObject.CreateInstance<RarityPreset>();
				((Object)val).hideFlags = (HideFlags)61;
				((Object)val).name = "Rarity - Mita";
				val.chance = 100f;
				EnemySetup val2 = ScriptableObject.CreateInstance<EnemySetup>();
				((Object)val2).hideFlags = (HideFlags)61;
				((Object)val2).name = "Enemy - Mita";
				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 = "EnemyContentEmpressMita";
				EnemySetupField.SetValue(val3, val2);
				SpawnObjectsField.SetValue(val3, new List<GameObject> { item });
				Enemies.RegisterEnemy(val3);
				_registered = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Registered the Mita enemy with REPOLib.");
			}
		}

		internal static void ConfigureRuntimeInstance(EnemyParent enemyParent, Enemy enemy, EnemyStateSpawn stateSpawn, EnemyStateStunned stateStunned, PhotonView rootPhotonView, PhotonView enemyPhotonView, Transform centerTransform)
		{
			//IL_000f: 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_0202: 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_021d: 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_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Expected O, but got Unknown
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected O, but got Unknown
			//IL_027f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0289: Expected O, but got Unknown
			//IL_0321: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Expected O, but got Unknown
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Expected O, but got Unknown
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_035d: Expected O, but got Unknown
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Expected O, but got Unknown
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Expected O, but got Unknown
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c7: Expected O, but got Unknown
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Expected O, but got Unknown
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Expected O, but got Unknown
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_040f: Expected O, but got Unknown
			//IL_041d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0427: Expected O, but got Unknown
			//IL_03ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Expected O, but got Unknown
			//IL_048b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: Expected O, but got Unknown
			//IL_04e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Expected O, but got Unknown
			Transform centerTransform2;
			Transform headTransform;
			Animator visualAnimator;
			Transform val = BuildMitaVisualRig(enemy, out centerTransform2, out headTransform, out visualAnimator);
			enemy.Type = (EnemyType)3;
			enemy.CenterTransform = centerTransform2;
			enemy.KillLookAtTransform = headTransform;
			enemy.CustomValuableSpawnTransform = centerTransform2;
			enemy.CurrentState = (EnemyState)1;
			EmpressRepoMitaController empressRepoMitaController = ((Component)enemy).GetComponent<EmpressRepoMitaController>() ?? ((Component)enemy).gameObject.AddComponent<EmpressRepoMitaController>();
			empressRepoMitaController.VisualRoot = val;
			empressRepoMitaController.CenterTransform = centerTransform2;
			empressRepoMitaController.HeadTransform = headTransform;
			empressRepoMitaController.VisualAnimator = visualAnimator;
			PhotonTransformView val2 = ((Component)enemy).GetComponent<PhotonTransformView>() ?? ((Component)enemy).gameObject.AddComponent<PhotonTransformView>();
			PhysGrabObject val3 = ((Component)enemy).GetComponent<PhysGrabObject>() ?? ((Component)enemy).gameObject.AddComponent<PhysGrabObject>();
			PhysGrabObjectImpactDetector val4 = ((Component)enemy).GetComponent<PhysGrabObjectImpactDetector>() ?? ((Component)enemy).gameObject.AddComponent<PhysGrabObjectImpactDetector>();
			RoomVolumeCheck val5 = ((Component)enemy).GetComponent<RoomVolumeCheck>() ?? ((Component)enemy).gameObject.AddComponent<RoomVolumeCheck>();
			NotValuableObject val6 = ((Component)enemy).GetComponent<NotValuableObject>() ?? ((Component)enemy).gameObject.AddComponent<NotValuableObject>();
			ConfigureGrabbableBody(((Component)enemy).gameObject, val, val3);
			Rigidbody component = ((Component)enemy).GetComponent<Rigidbody>();
			if ((Object)(object)component != (Object)null)
			{
				component.mass = 3f;
				component.interpolation = (RigidbodyInterpolation)1;
				component.collisionDetectionMode = (CollisionDetectionMode)2;
			}
			val3.overrideTagsAndLayers = false;
			val3.photonView = enemyPhotonView;
			val3.photonTransformView = val2;
			val3.rb = component;
			val3.roomVolumeCheck = val5;
			val3.impactDetector = val4;
			val3.massOriginal = 3f;
			val4.physGrabObject = val3;
			val4.photonView = enemyPhotonView;
			val4.rb = component;
			val4.playerHurtDisable = false;
			val4.slidingDisable = true;
			val4.destroyDisable = true;
			val4.canHurtLogic = true;
			val6.physAttributePreset = GetOrCreateGrabPhysAttribute();
			val6.durabilityPreset = GetOrCreateGrabDurability();
			val6.audioPreset = null;
			val6.audioPresetPitch = 1f;
			val6.hasHealth = false;
			val6.rb = component;
			val6.physGrabObject = val3;
			RoomVolumeCheck val7 = val5;
			if (val7.CurrentRooms == null)
			{
				val7.CurrentRooms = new List<RoomVolume>();
			}
			val5.CheckPosition = new Vector3(0f, 1.2f, 0f);
			val5.currentSize = new Vector3(1.45f, 3.05f, 1.45f);
			EnemyHealth val8 = ((Component)enemy).GetComponent<EnemyHealth>() ?? ((Component)enemy).gameObject.AddComponent<EnemyHealth>();
			EnemyHealth val9 = val8;
			if (val9.onHurt == null)
			{
				val9.onHurt = new UnityEvent();
			}
			val9 = val8;
			if (val9.onDeathStart == null)
			{
				val9.onDeathStart = new UnityEvent();
			}
			val9 = val8;
			if (val9.onDeath == null)
			{
				val9.onDeath = new UnityEvent();
			}
			val9 = val8;
			if (val9.onObjectHurt == null)
			{
				val9.onObjectHurt = new UnityEvent();
			}
			val8.health = 130;
			val8.healthCurrent = val8.health;
			val8.meshParent = val;
			val8.spawnValuable = true;
			val8.spawnValuableMax = 1;
			val8.objectHurt = true;
			val8.objectHurtStun = true;
			val8.objectHurtStunTime = 1.15f;
			val8.impactHurt = true;
			val8.impactLightDamage = 5;
			val8.impactMediumDamage = 12;
			val8.impactHeavyDamage = 22;
			val8.onHurt.AddListener(new UnityAction(empressRepoMitaController.HandleHurt));
			val8.onDeathStart.AddListener(new UnityAction(empressRepoMitaController.HandleDeathStart));
			val8.onObjectHurt.AddListener(new UnityAction(empressRepoMitaController.HandleObjectHurt));
			val8.onDeath.AddListener(new UnityAction(empressRepoMitaController.HandleDeath));
			empressRepoMitaController.Health = val8;
			empressRepoMitaController.GrabObject = val3;
			RefreshHealthVisuals(val8, val);
			val8.OnSpawn();
			if (stateSpawn.OnSpawn == null)
			{
				stateSpawn.OnSpawn = new UnityEvent();
			}
			stateSpawn.OnSpawn.AddListener(new UnityAction(empressRepoMitaController.HandleSpawn));
			EnemyStateStunned val10 = stateStunned;
			if (val10.onStunnedStart == null)
			{
				val10.onStunnedStart = new UnityEvent();
			}
			val10 = stateStunned;
			if (val10.onStunnedEnd == null)
			{
				val10.onStunnedEnd = new UnityEvent();
			}
			stateStunned.onStunnedStart.AddListener(new UnityAction(empressRepoMitaController.HandleStunnedStart));
			stateStunned.onStunnedEnd.AddListener(new UnityAction(empressRepoMitaController.HandleStunnedEnd));
			EnemyStateInvestigate val11 = ((Component)enemy).GetComponent<EnemyStateInvestigate>() ?? ((Component)enemy).gameObject.AddComponent<EnemyStateInvestigate>();
			val11.Enemy = enemy;
			val11.PhotonView = enemyPhotonView;
			val11.OnlyEvent = true;
			val11.rangeMultiplier = 1.2f;
			EnemyStateInvestigate val12 = val11;
			if (val12.onInvestigateTriggered == null)
			{
				val12.onInvestigateTriggered = new UnityEvent();
			}
			val11.onInvestigateTriggered.AddListener(new UnityAction(empressRepoMitaController.HandleInvestigate));
			RepoEnemyAccess.SetEnemyParentEnemy(enemyParent, enemy);
			RepoEnemyAccess.SetEnemyParent(enemy, enemyParent);
			RepoEnemyAccess.SetPhotonView(enemy, enemyPhotonView);
			RepoEnemyAccess.SetHealth(enemy, val8);
			RepoEnemyAccess.SetHasHealth(enemy, value: true);
			RepoEnemyAccess.SetStateInvestigate(enemy, val11);
			RepoEnemyAccess.SetHasStateInvestigate(enemy, value: true);
			RepoEnemyAccess.SetStateSpawn(enemy, stateSpawn);
			RepoEnemyAccess.SetHasStateSpawn(enemy, value: true);
			RepoEnemyAccess.SetStateStunned(enemy, stateStunned);
			RepoEnemyAccess.SetHasStateStunned(enemy, value: true);
			RepoEnemyAccess.SetVisionMask(enemy, LayerMask.op_Implicit(LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "HideTriggers" })));
			RepoEnemyAccess.SetTargetPlayerViewId(enemy, -1);
			RepoEnemyAccess.SetNavMeshAgent(enemy, empressRepoMitaController.NavAgent);
			RepoEnemyAccess.SetHasNavMeshAgent(enemy, (Object)(object)empressRepoMitaController.NavAgent != (Object)null);
			RepoEnemyAccess.SetStateSpawnEnemy(stateSpawn, enemy);
			RepoEnemyAccess.SetStateStunnedEnemy(stateStunned, enemy);
			rootPhotonView.ObservedComponents = new List<Component> { (Component)(object)enemyParent };
			enemyPhotonView.ObservedComponents = new List<Component>
			{
				(Component)(object)enemy,
				(Component)(object)val2,
				(Component)(object)val3,
				(Component)(object)val4
			};
			empressRepoMitaController.InitializeRuntime();
			RepoEnemyAccess.SetSetupDone(enemyParent, value: true);
		}

		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);
			}
		}

		private static Transform BuildMitaVisualRig(Enemy enemy, out Transform centerTransform, out Transform headTransform, out Animator? visualAnimator)
		{
			if (TryBuildBundleVisualRig(((Component)enemy).transform, out Transform visualRoot, out centerTransform, out headTransform, out visualAnimator))
			{
				return visualRoot;
			}
			visualAnimator = null;
			return BuildFallbackVisualRig(((Component)enemy).transform, out centerTransform, out headTransform);
		}

		private static bool TryBuildBundleVisualRig(Transform attachRoot, out Transform visualRoot, out Transform centerTransform, out Transform headTransform, out Animator? visualAnimator)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Expected O, but got Unknown
			//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_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			visualRoot = null;
			centerTransform = null;
			headTransform = null;
			visualAnimator = null;
			GameObject val = LoadMitaVisualPrefab();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			RemoveExistingVisualRoots(attachRoot);
			GameObject val2 = Object.Instantiate<GameObject>(val, attachRoot);
			((Object)val2).name = "MitaVisualRoot";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			Transform transform = val2.transform;
			transform.localScale *= 0.96f;
			SetVisualLayerRecursively(val2.transform, ResolveVisualLayer("Enemy"));
			SanitizeBundleInstance(val2.transform);
			ConvertBundleMaterials(val2);
			Collider[] componentsInChildren = val2.GetComponentsInChildren<Collider>(true);
			foreach (Collider val3 in componentsInChildren)
			{
				val3.enabled = false;
			}
			NavMeshAgent[] componentsInChildren2 = val2.GetComponentsInChildren<NavMeshAgent>(true);
			foreach (NavMeshAgent val4 in componentsInChildren2)
			{
				((Behaviour)val4).enabled = false;
				Object.Destroy((Object)(object)val4);
			}
			visualRoot = val2.transform;
			visualAnimator = val2.GetComponentInChildren<Animator>(true);
			if ((Object)(object)visualAnimator != (Object)null)
			{
				((Behaviour)visualAnimator).enabled = true;
				visualAnimator.applyRootMotion = false;
				visualAnimator.cullingMode = (AnimatorCullingMode)0;
				visualAnimator.Rebind();
				visualAnimator.Update(0f);
			}
			PruneExtraBundleActors(val2.transform, visualAnimator);
			Transform val5 = FindChildByName(val2.transform, "Head") ?? FindChildByName(val2.transform, "head") ?? FindChildByName(val2.transform, "ORG-head");
			headTransform = val5 ?? val2.transform;
			Bounds? combinedRendererBounds = GetCombinedRendererBounds(val2);
			GameObject val6 = new GameObject("MitaCenter");
			val6.transform.SetParent(attachRoot, false);
			Transform transform2 = val6.transform;
			Vector3 position;
			if (!combinedRendererBounds.HasValue)
			{
				position = attachRoot.position + Vector3.up * 1.5f;
			}
			else
			{
				Bounds valueOrDefault = combinedRendererBounds.GetValueOrDefault();
				position = ((Bounds)(ref valueOrDefault)).center;
			}
			transform2.position = position;
			val6.transform.rotation = Quaternion.identity;
			centerTransform = val6.transform;
			Log.LogInfo((object)"Using asset bundle visual prefab for Mita.");
			return true;
		}

		private static void RemoveExistingVisualRoots(Transform attachRoot)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			List<GameObject> list = new List<GameObject>();
			foreach (Transform item in attachRoot)
			{
				Transform val = item;
				if (string.Equals(((Object)val).name, "MitaVisualRoot", StringComparison.Ordinal) || string.Equals(((Object)val).name, "MitaVisualRoot(Clone)", StringComparison.Ordinal))
				{
					list.Add(((Component)val).gameObject);
				}
			}
			foreach (GameObject item2 in list)
			{
				Object.Destroy((Object)(object)item2);
			}
		}

		private static void PruneExtraBundleActors(Transform root, Animator? primaryAnimator)
		{
			if ((Object)(object)primaryAnimator == (Object)null)
			{
				return;
			}
			Animator[] componentsInChildren = ((Component)root).GetComponentsInChildren<Animator>(true);
			foreach (Animator val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)primaryAnimator))
				{
					((Behaviour)val).enabled = false;
					((Component)val).gameObject.SetActive(false);
					Log.LogInfo((object)("Disabled extra Mita bundle actor '" + ((Object)val).name + "'."));
				}
			}
		}

		private static void SanitizeBundleInstance(Transform root)
		{
			Transform[] componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if (ShouldHideBundleHelperObject(val))
				{
					((Component)val).gameObject.SetActive(false);
				}
			}
		}

		private static bool ShouldHideBundleHelperObject(Transform candidate)
		{
			string name = ((Object)candidate).name;
			if (name.IndexOf("MapDot", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("ScanNode", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Debug", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("Point", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return name.IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private static void ConvertBundleMaterials(GameObject instance)
		{
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)"[Mita] Could not find Standard shader for material conversion.");
				return;
			}
			Material orCreateBodyMaterial = GetOrCreateBodyMaterial(val);
			Material orCreateClothesMaterial = GetOrCreateClothesMaterial(val);
			Material orCreateFaceMaterial = GetOrCreateFaceMaterial(val);
			Material orCreateHairMaterial = GetOrCreateHairMaterial(val);
			Material orCreateTeddyMaterial = GetOrCreateTeddyMaterial(val);
			Renderer[] componentsInChildren = instance.GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val2 in componentsInChildren)
			{
				if (!val2.enabled || ShouldHideBundleHelperObject(((Component)val2).transform))
				{
					val2.enabled = false;
					continue;
				}
				Material[] sharedMaterials = val2.sharedMaterials;
				bool flag = false;
				for (int j = 0; j < sharedMaterials.Length; j++)
				{
					Material val3 = sharedMaterials[j];
					string text = (((Object)(object)val3 != (Object)null) ? ((Object)val3).name : string.Empty);
					string name = ((Object)val2).name;
					Material val4 = ((text.IndexOf("tedd", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("tedd", StringComparison.OrdinalIgnoreCase) < 0) ? ((text.IndexOf("hair", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("hair", StringComparison.OrdinalIgnoreCase) < 0) ? ((text.IndexOf("cloth", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("skirt", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("cloth", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("skirt", StringComparison.OrdinalIgnoreCase) < 0) ? ((text.IndexOf("head", StringComparison.OrdinalIgnoreCase) < 0 && text.IndexOf("face", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("head", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("face", StringComparison.OrdinalIgnoreCase) < 0) ? orCreateBodyMaterial : orCreateFaceMaterial) : orCreateClothesMaterial) : orCreateHairMaterial) : orCreateTeddyMaterial);
					if (sharedMaterials[j] != val4)
					{
						sharedMaterials[j] = val4;
						flag = true;
					}
				}
				if (flag)
				{
					val2.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static Material GetOrCreateBodyMaterial(Shader standardShader)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)(object)_bodyMaterial != (Object)null)
			{
				return _bodyMaterial;
			}
			_bodyMaterial = new Material(standardShader)
			{
				name = "MitaBodyBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("CreepyMitaBody.png", ref _bodyAlbedoTexture, isNormalMap: false);
			Texture2D val2 = ResolvePreferredTexture("", ref _bodyNormalTexture, isNormalMap: true);
			if ((Object)(object)val != (Object)null)
			{
				_bodyMaterial.mainTexture = (Texture)(object)val;
				_bodyMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				_bodyMaterial.SetTexture("_BumpMap", (Texture)(object)val2);
				_bodyMaterial.EnableKeyword("_NORMALMAP");
				_bodyMaterial.SetFloat("_BumpScale", 0.8f);
			}
			_bodyMaterial.SetFloat("_Metallic", 0.18f);
			_bodyMaterial.SetFloat("_Glossiness", 0.42f);
			return _bodyMaterial;
		}

		private static Material GetOrCreateClothesMaterial(Shader standardShader)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)(object)_clothesMaterial != (Object)null)
			{
				return _clothesMaterial;
			}
			_clothesMaterial = new Material(standardShader)
			{
				name = "MitaClothesBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("CreepyMitaClothes.png", ref _clothesAlbedoTexture, isNormalMap: false);
			Texture2D val2 = ResolvePreferredTexture("", ref _clothesNormalTexture, isNormalMap: true);
			if ((Object)(object)val != (Object)null)
			{
				_clothesMaterial.mainTexture = (Texture)(object)val;
				_clothesMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				_clothesMaterial.SetTexture("_BumpMap", (Texture)(object)val2);
				_clothesMaterial.EnableKeyword("_NORMALMAP");
				_clothesMaterial.SetFloat("_BumpScale", 0.75f);
			}
			_clothesMaterial.SetFloat("_Metallic", 0.02f);
			_clothesMaterial.SetFloat("_Glossiness", 0.24f);
			return _clothesMaterial;
		}

		private static Material GetOrCreateFaceMaterial(Shader standardShader)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)(object)_faceMaterial != (Object)null)
			{
				return _faceMaterial;
			}
			_faceMaterial = new Material(standardShader)
			{
				name = "MitaFaceBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("Face_2.png", ref _faceAlbedoTexture, isNormalMap: false);
			if ((Object)(object)val != (Object)null)
			{
				_faceMaterial.mainTexture = (Texture)(object)val;
				_faceMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			_faceMaterial.SetFloat("_Glossiness", 0.18f);
			return _faceMaterial;
		}

		private static Material GetOrCreateHairMaterial(Shader standardShader)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)(object)_hairMaterial != (Object)null)
			{
				return _hairMaterial;
			}
			_hairMaterial = new Material(standardShader)
			{
				name = "MitaHairBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("TestHairsalpha2.png", ref _hairAlbedoTexture, isNormalMap: false);
			Texture2D val2 = ResolvePreferredTexture("TestHairsN2.png", ref _hairNormalTexture, isNormalMap: true);
			if ((Object)(object)val != (Object)null)
			{
				_hairMaterial.mainTexture = (Texture)(object)val;
				_hairMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				_hairMaterial.SetTexture("_BumpMap", (Texture)(object)val2);
				_hairMaterial.EnableKeyword("_NORMALMAP");
				_hairMaterial.SetFloat("_BumpScale", 0.85f);
			}
			_hairMaterial.SetFloat("_Glossiness", 0.28f);
			_hairMaterial.SetFloat("_Cutoff", 0.58f);
			ConfigureCutoutMaterial(_hairMaterial, 0.58f);
			return _hairMaterial;
		}

		private static void ConfigureCutoutMaterial(Material material, float cutoff)
		{
			material.SetFloat("_Mode", 1f);
			material.SetFloat("_Cutoff", cutoff);
			material.SetFloat("_SrcBlend", 1f);
			material.SetFloat("_DstBlend", 0f);
			material.SetFloat("_ZWrite", 1f);
			material.DisableKeyword("_ALPHABLEND_ON");
			material.DisableKeyword("_ALPHAPREMULTIPLY_ON");
			material.EnableKeyword("_ALPHATEST_ON");
			material.renderQueue = 2450;
		}

		private static Material GetOrCreateTeddyMaterial(Shader standardShader)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			if ((Object)(object)_teddyMaterial != (Object)null)
			{
				return _teddyMaterial;
			}
			_teddyMaterial = new Material(standardShader)
			{
				name = "MitaTeddyBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("TeddyBear.png", ref _teddyAlbedoTexture, isNormalMap: false);
			if ((Object)(object)val != (Object)null)
			{
				_teddyMaterial.mainTexture = (Texture)(object)val;
				_teddyMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			_teddyMaterial.SetFloat("_Glossiness", 0.08f);
			return _teddyMaterial;
		}

		private static Texture2D? ResolvePreferredTexture(string expectedFileName, ref Texture2D? cache, bool isNormalMap)
		{
			if (string.IsNullOrWhiteSpace(expectedFileName))
			{
				return null;
			}
			if ((Object)(object)cache != (Object)null)
			{
				return cache;
			}
			string text = ResolvePluginFile(expectedFileName);
			if (!string.IsNullOrEmpty(text))
			{
				cache = LoadTextureFromDisk(text, expectedFileName, isNormalMap);
				if ((Object)(object)cache != (Object)null)
				{
					return cache;
				}
			}
			if ((Object)(object)_mitaBundle == (Object)null)
			{
				return null;
			}
			Texture2D[] array = _mitaBundle.LoadAllAssets<Texture2D>();
			foreach (Texture2D val in array)
			{
				if (!((Object)(object)val == (Object)null) && (string.Equals(((Object)val).name, Path.GetFileNameWithoutExtension(expectedFileName), StringComparison.OrdinalIgnoreCase) || string.Equals(((Object)val).name, expectedFileName, StringComparison.OrdinalIgnoreCase)))
				{
					cache = val;
					return cache;
				}
			}
			return null;
		}

		private static Texture2D? LoadTextureFromDisk(string path, string textureName, bool isNormalMap)
		{
			//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_001d: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			try
			{
				byte[] array = File.ReadAllBytes(path);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true, isNormalMap)
				{
					name = Path.GetFileNameWithoutExtension(textureName),
					wrapMode = (TextureWrapMode)0,
					filterMode = (FilterMode)1,
					hideFlags = (HideFlags)61
				};
				if (!ImageConversion.LoadImage(val, array, false))
				{
					Object.Destroy((Object)(object)val);
					return null;
				}
				val.Apply(true, false);
				return val;
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Mita] Failed to load texture '" + path + "': " + ex.Message));
				return null;
			}
		}

		private static Transform BuildFallbackVisualRig(Transform attachRoot, out Transform centerTransform, out Transform headTransform)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_001e: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: 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_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: 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_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0264: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: 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_02ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0302: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0372: 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)
			GameObject val = new GameObject("MitaVisualRoot");
			val.transform.SetParent(attachRoot, false);
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			Material seedMaterial = FindSeedMaterial(val);
			Material material = CreateTintedMaterial(seedMaterial, new Color(0.42f, 0.2f, 0.54f));
			Material material2 = CreateTintedMaterial(seedMaterial, new Color(0.32f, 0.32f, 0.34f));
			Material material3 = CreateTintedMaterial(seedMaterial, new Color(0.96f, 0.96f, 0.96f));
			Transform val2 = CreatePiece("Torso", (PrimitiveType)1, val.transform, new Vector3(0f, 1.2f, 0f), new Vector3(0.5f, 0.78f, 0.42f), material);
			Transform val3 = CreatePiece("Head", (PrimitiveType)0, val.transform, new Vector3(0f, 2.15f, 0.1f), new Vector3(0.48f, 0.48f, 0.48f), material);
			CreatePiece("LeftEye", (PrimitiveType)0, val3, new Vector3(-0.1f, 0.03f, 0.42f), new Vector3(0.12f, 0.12f, 0.08f), material3);
			CreatePiece("RightEye", (PrimitiveType)0, val3, new Vector3(0.1f, 0.03f, 0.42f), new Vector3(0.12f, 0.12f, 0.08f), material3);
			CreatePiece("LeftArm", (PrimitiveType)2, val.transform, new Vector3(-0.68f, 1.25f, 0f), new Vector3(0.11f, 0.52f, 0.11f), material, (Vector3?)new Vector3(0f, 0f, 34f));
			CreatePiece("RightArm", (PrimitiveType)2, val.transform, new Vector3(0.68f, 1.25f, 0f), new Vector3(0.11f, 0.52f, 0.11f), material, (Vector3?)new Vector3(0f, 0f, -12f));
			CreatePiece("LeftLeg", (PrimitiveType)2, val.transform, new Vector3(-0.21f, 0.42f, 0f), new Vector3(0.13f, 0.48f, 0.13f), material);
			CreatePiece("RightLeg", (PrimitiveType)2, val.transform, new Vector3(0.21f, 0.42f, 0f), new Vector3(0.13f, 0.48f, 0.13f), material);
			CreatePiece("AxeHandle", (PrimitiveType)2, val.transform, new Vector3(0.95f, 1.05f, 0f), new Vector3(0.07f, 0.8f, 0.07f), material2, (Vector3?)new Vector3(0f, 0f, 22f));
			CreatePiece("AxeHead", (PrimitiveType)3, val.transform, new Vector3(1.18f, 1.55f, 0f), new Vector3(0.18f, 0.36f, 0.72f), material2);
			centerTransform = new GameObject("MitaCenter").transform;
			centerTransform.SetParent(attachRoot, false);
			centerTransform.localPosition = new Vector3(0f, 1.45f, 0f);
			headTransform = val3;
			return val.transform;
		}

		private static void ConfigureGrabbableBody(GameObject enemyObject, Transform visualRoot, PhysGrabObject physGrabObject)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: 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_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = enemyObject.transform;
			Bounds bounds = default(Bounds);
			((Bounds)(ref bounds))..ctor(transform.position + Vector3.up * 1.4f, new Vector3(0.9f, 2.8f, 0.9f));
			Renderer[] componentsInChildren = ((Component)visualRoot).GetComponentsInChildren<Renderer>(true);
			if (componentsInChildren.Length != 0)
			{
				bounds = componentsInChildren[0].bounds;
				for (int i = 1; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null && componentsInChildren[i].enabled)
					{
						((Bounds)(ref bounds)).Encapsulate(componentsInChildren[i].bounds);
					}
				}
			}
			Vector3 val = transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
			physGrabObject.colliders.Clear();
			if (!ConfigureMeshGrabColliders(visualRoot, physGrabObject))
			{
				ConfigureFallbackGrabCollider(transform, val, bounds, physGrabObject);
			}
			Transform val2 = transform.Find("Center of Mass");
			if ((Object)(object)val2 == (Object)null)
			{
				GameObject val3 = new GameObject("Center of Mass");
				val3.transform.SetParent(transform, false);
				val2 = val3.transform;
			}
			val2.localPosition = val;
			val2.localRotation = Quaternion.identity;
			val2.localScale = Vector3.one;
			Transform val4 = transform.Find("ForceCenterPoint");
			if ((Object)(object)val4 == (Object)null)
			{
				GameObject val5 = new GameObject("ForceCenterPoint");
				val5.transform.SetParent(transform, false);
				val4 = val5.transform;
			}
			val4.localPosition = val + new Vector3(0f, 0.1f, 0.08f);
			val4.localRotation = Quaternion.identity;
			val4.localScale = Vector3.one;
		}

		private static bool ConfigureMeshGrabColliders(Transform visualRoot, PhysGrabObject physGrabObject)
		{
			int num = LayerMask.NameToLayer("PhysGrabObject");
			int num2 = 0;
			SkinnedMeshRenderer[] componentsInChildren = ((Component)visualRoot).GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || !((Renderer)val).enabled || (Object)(object)val.sharedMesh == (Object)null || ShouldHideBundleHelperObject(((Component)val).transform))
				{
					continue;
				}
				string name = ((Object)val).name;
				if (name.IndexOf("hair", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("face", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("eye", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("teddy", StringComparison.OrdinalIgnoreCase) < 0)
				{
					GameObject gameObject = ((Component)val).gameObject;
					if (num >= 0)
					{
						gameObject.layer = num;
					}
					try
					{
						gameObject.tag = "Phys Grab Object";
					}
					catch (UnityException)
					{
					}
					MeshCollider val3 = gameObject.GetComponent<MeshCollider>() ?? gameObject.AddComponent<MeshCollider>();
					val3.sharedMesh = val.sharedMesh;
					val3.convex = true;
					((Collider)val3).isTrigger = false;
					PhysGrabObjectCollider val4 = gameObject.GetComponent<PhysGrabObjectCollider>() ?? gameObject.AddComponent<PhysGrabObjectCollider>();
					val4.colliderID = num2++;
					val4.physGrabObject = physGrabObject;
					if (!physGrabObject.colliders.Contains(gameObject.transform))
					{
						physGrabObject.colliders.Add(gameObject.transform);
					}
				}
			}
			return physGrabObject.colliders.Count > 0;
		}

		private static void ConfigureFallbackGrabCollider(Transform enemyTransform, Vector3 centerLocal, Bounds bounds, PhysGrabObject physGrabObject)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_003c: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			Transform val = enemyTransform.Find("Grab Collider");
			GameObject val2;
			if ((Object)(object)val == (Object)null)
			{
				val2 = new GameObject("Grab Collider");
				val2.transform.SetParent(enemyTransform, false);
			}
			else
			{
				val2 = ((Component)val).gameObject;
			}
			val2.transform.localPosition = centerLocal;
			val2.transform.localRotation = Quaternion.identity;
			val2.transform.localScale = Vector3.one;
			int num = LayerMask.NameToLayer("PhysGrabObject");
			val2.layer = ((num >= 0) ? num : 0);
			try
			{
				val2.tag = "Phys Grab Object";
			}
			catch (UnityException)
			{
			}
			CapsuleCollider val4 = val2.GetComponent<CapsuleCollider>() ?? val2.AddComponent<CapsuleCollider>();
			((Collider)val4).isTrigger = false;
			val4.direction = 1;
			val4.center = Vector3.zero;
			val4.height = Mathf.Clamp(((Bounds)(ref bounds)).size.y * 0.86f, 1.65f, 2.8f);
			val4.radius = Mathf.Clamp(Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) * 0.18f, 0.22f, 0.46f);
			PhysGrabObjectCollider val5 = val2.GetComponent<PhysGrabObjectCollider>() ?? val2.AddComponent<PhysGrabObjectCollider>();
			val5.colliderID = 0;
			val5.physGrabObject = physGrabObject;
			physGrabObject.colliders.Add(val2.transform);
		}

		private static PhysAttribute GetOrCreateGrabPhysAttribute()
		{
			if ((Object)(object)_grabPhysAttribute != (Object)null)
			{
				return _grabPhysAttribute;
			}
			_grabPhysAttribute = ScriptableObject.CreateInstance<PhysAttribute>();
			((Object)_grabPhysAttribute).hideFlags = (HideFlags)61;
			((Object)_grabPhysAttribute).name = "PhysAttributeMitaGrab";
			_grabPhysAttribute.mass = 3f;
			return _grabPhysAttribute;
		}

		private static Durability GetOrCreateGrabDurability()
		{
			if ((Object)(object)_grabDurability != (Object)null)
			{
				return _grabDurability;
			}
			_grabDurability = ScriptableObject.CreateInstance<Durability>();
			((Object)_grabDurability).hideFlags = (HideFlags)61;
			((Object)_grabDurability).name = "DurabilityMitaGrab";
			_grabDurability.fragility = 100f;
			_grabDurability.durability = 100f;
			return _grabDurability;
		}

		private static void RefreshHealthVisuals(EnemyHealth health, Transform meshRoot)
		{
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			health.meshParent = meshRoot;
			health.renderers = new List<MeshRenderer>();
			health.sharedMaterials = new List<Material>();
			health.instancedMaterials = new List<Material>();
			health.renderers.AddRange(((Component)meshRoot).GetComponentsInChildren<MeshRenderer>(true));
			foreach (MeshRenderer renderer in health.renderers)
			{
				Material val = null;
				foreach (Material sharedMaterial in health.sharedMaterials)
				{
					if ((Object)(object)((Renderer)renderer).sharedMaterial != (Object)null && ((Object)((Renderer)renderer).sharedMaterial).name == ((Object)sharedMaterial).name)
					{
						val = sharedMaterial;
						((Renderer)renderer).sharedMaterial = health.instancedMaterials[health.sharedMaterials.IndexOf(sharedMaterial)];
						break;
					}
				}
				if ((Object)(object)val == (Object)null)
				{
					val = ((Renderer)renderer).sharedMaterial;
					if (!((Object)(object)val == (Object)null))
					{
						health.sharedMaterials.Add(val);
						health.instancedMaterials.Add(((Renderer)renderer).material);
					}
				}
			}
			health.materialHurtColor = Shader.PropertyToID("_ColorOverlay");
			health.materialHurtAmount = Shader.PropertyToID("_ColorOverlayAmount");
			foreach (Material instancedMaterial in health.instancedMaterials)
			{
				instancedMaterial.SetColor(health.materialHurtColor, health.hurtColor);
				instancedMaterial.SetFloat(health.materialHurtAmount, 0f);
			}
		}

		private static GameObject? LoadMitaVisualPrefab()
		{
			if ((Object)(object)_mitaVisualPrefab != (Object)null)
			{
				return _mitaVisualPrefab;
			}
			string text = ResolvePluginFile("empressmita");
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			try
			{
				if (_mitaBundle == null)
				{
					_mitaBundle = AssetBundle.LoadFromFile(text);
				}
				if ((Object)(object)_mitaBundle == (Object)null)
				{
					Log.LogWarning((object)("[Mita] Failed to load asset bundle at " + text));
					return null;
				}
				if (BundleAnimationClips == null)
				{
					BundleAnimationClips = _mitaBundle.LoadAllAssets<AnimationClip>();
				}
				string[] mitaBundlePrefabCandidates = MitaBundlePrefabCandidates;
				foreach (string text2 in mitaBundlePrefabCandidates)
				{
					GameObject val = _mitaBundle.LoadAsset<GameObject>(text2);
					if ((Object)(object)val != (Object)null)
					{
						_mitaVisualPrefab = val;
						return _mitaVisualPrefab;
					}
				}
				GameObject[] array = _mitaBundle.LoadAllAssets<GameObject>();
				foreach (GameObject val2 in array)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						_mitaVisualPrefab = val2;
						Log.LogWarning((object)("[Mita] Falling back to first prefab '" + ((Object)val2).name + "' from asset bundle."));
						return _mitaVisualPrefab;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Mita] Failed while loading visual asset bundle: " + ex.Message));
			}
			return null;
		}

		internal static AssetBundle? LoadMitaAudioBundle()
		{
			if ((Object)(object)_mitaAudioBundle != (Object)null)
			{
				return _mitaAudioBundle;
			}
			string text = ResolvePluginFile("empressmitaaudio");
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			try
			{
				_mitaAudioBundle = AssetBundle.LoadFromFile(text);
				if ((Object)(object)_mitaAudioBundle == (Object)null)
				{
					Log.LogWarning((object)("[Mita] Failed to load audio asset bundle at " + text));
				}
				return _mitaAudioBundle;
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Mita] Failed while loading audio asset bundle: " + ex.Message));
				return null;
			}
		}

		internal static AudioClip? LoadAudioClip(string clipName)
		{
			AssetBundle val = LoadMitaAudioBundle();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			try
			{
				return val.LoadAsset<AudioClip>(clipName);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[Mita] Failed to load audio clip '" + clipName + "': " + ex.Message));
				return null;
			}
		}

		internal static AudioClip[] LoadAudioClips(IEnumerable<string> clipNames)
		{
			List<AudioClip> list = new List<AudioClip>();
			foreach (string clipName in clipNames)
			{
				AudioClip val = LoadAudioClip(clipName);
				if ((Object)(object)val != (Object)null)
				{
					list.Add(val);
				}
			}
			return list.ToArray();
		}

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

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

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

		private static int ResolveVisualLayer(string layerName)
		{
			int num = LayerMask.NameToLayer(layerName);
			if (num < 0)
			{
				return 0;
			}
			return num;
		}

		private static void SetVisualLayerRecursively(Transform root, int layer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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);
			}
			Shader val3 = Shader.Find("Standard");
			if ((Object)(object)val3 != (Object)null)
			{
				return new Material(val3);
			}
			throw new InvalidOperationException("Could not resolve a fallback material for the Mita visuals.");
		}

		private static Material CreateTintedMaterial(Material seedMaterial, Color color)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: 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);
			}
			return val;
		}

		private static Transform CreatePiece(string name, PrimitiveType primitiveType, Transform parent, Vector3 localPosition, Vector3 localScale, Material material, Vector3? localEulerAngles = null)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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)
			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 void PatchTemplateGuards(Harmony harmony)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Expected O, but got Unknown
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Expected O, but got Unknown
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyParent), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "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(EmpressRepoMitaPlugin), "SkipTemplateEnemyStateStunnedUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

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

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

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

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

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

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

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

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

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

		private static bool SkipTemplateEnemyStateStunnedUpdate(EnemyStateStunned __instance)
		{
			return !MitaTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "Start")]
	internal static class EmpressRepoMitaEnemyDirectorStartPatch
	{
		private static void Postfix()
		{
			EmpressRepoMitaPlugin.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> EnemyHasHealthRef = AccessTools.FieldRefAccess<Enemy, bool>("HasHealth");

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

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

		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, EnemyHealth> EnemyHealthRef = AccessTools.FieldRefAccess<Enemy, EnemyHealth>("Health");

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

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

		private static readonly FieldRef<Enemy, EnemyStateInvestigate> EnemyStateInvestigateRef = AccessTools.FieldRefAccess<Enemy, EnemyStateInvestigate>("StateInvestigate");

		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, LayerMask> EnemyVisionMaskRef = AccessTools.FieldRefAccess<Enemy, LayerMask>("VisionMask");

		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 SetHealth(Enemy enemy, EnemyHealth health)
		{
			EnemyHealthRef.Invoke(enemy) = health;
		}

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

		internal static void SetNavMeshAgent(Enemy enemy, EnemyNavMeshAgent? navMeshAgent)
		{
			EnemyNavMeshAgentRef.Invoke(enemy) = navMeshAgent;
		}

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

		internal static void SetStateInvestigate(Enemy enemy, EnemyStateInvestigate stateInvestigate)
		{
			EnemyStateInvestigateRef.Invoke(enemy) = stateInvestigate;
		}

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

		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)
		{
			enemy.TargetPlayerViewID = 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;
		}
	}
	[DefaultExecutionOrder(-100)]
	internal sealed class MitaTemplateBootstrap : MonoBehaviour
	{
		private const string EnableObjectName = "EnableObject";

		private const string EnemyObjectName = "MitaEnemy";

		private const string CenterObjectName = "Center";

		private const string TemplateContainerName = "EmpressMitaTemplateContainer";

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

		private static GameObject? _templateContainer;

		private bool _runtimeBuilt;

		internal static GameObject CreateTemplate(ManualLogSource log)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = EnsureTemplateContainer();
			GameObject val2 = new GameObject("EmpressMitaPrefab")
			{
				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 Mita 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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			if ((Object)(object)_templateContainer != (Object)null)
			{
				return _templateContainer;
			}
			_templateContainer = new GameObject("EmpressMitaTemplateContainer");
			((Object)_templateContainer).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)_templateContainer);
			_templateContainer.SetActive(false);
			return _templateContainer;
		}

		private static void BuildTemplateCore(Transform root)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Expected O, but got Unknown
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: 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<MitaTemplateBootstrap>();
			GameObject val3 = new GameObject("EnableObject");
			val3.transform.SetParent(root, false);
			val3.layer = layer;
			TrySetTag(val3, "Enemy");
			GameObject val4 = new GameObject("MitaEnemy");
			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.45f, 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.42f, 0f);
			val7.height = 3.18f;
			val7.radius = 0.66f;
			Rigidbody val8 = val4.AddComponent<Rigidbody>();
			val8.isKinematic = true;
			val8.useGravity = false;
			val8.collisionDetectionMode = (CollisionDetectionMode)3;
			val8.constraints = (RigidbodyConstraints)112;
			EnemyStateSpawn stateSpawn = val4.AddComponent<EnemyStateSpawn>();
			EnemyStateStunned stateStunned = val4.AddComponent<EnemyStateStunned>();
			Enemy val9 = val4.AddComponent<Enemy>();
			val.enemyName = "Mita";
			val.difficulty = (Difficulty)1;
			val.actionMultiplier = 1.55f;
			val.overchargeMultiplier = 1.2f;
			val.EnableObject = val3;
			val.SpawnedTimeMin = 30f;
			val.SpawnedTimeMax = 55f;
			val.DespawnedTimeMin = 18f;
			val.DespawnedTimeMax = 28f;
			RepoEnemyAccess.SetSetupDone(val, value: false);
			RepoEnemyAccess.SetEnemyParentEnemy(val, val9);
			RepoEnemyAccess.SetEnemyParent(val9, val);
			RepoEnemyAccess.SetPhotonView(val9, val6);
			val9.CenterTransform = val5.transform;
			val9.KillLookAtTransform = val5.transform;
			val9.CustomValuableSpawnTransform = val5.transform;
			RepoEnemyAccess.SetStateSpawn(val9, stateSpawn);
			RepoEnemyAccess.SetHasStateSpawn(val9, value: true);
			RepoEnemyAccess.SetStateStunned(val9, stateStunned);
			RepoEnemyAccess.SetHasStateStunned(val9, value: true);
			RepoEnemyAccess.SetVisionMask(val9, LayerMask.op_Implicit(LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()) + LayerMask.GetMask(new string[1] { "HideTriggers" })));
			RepoEnemyAccess.SetTargetPlayerViewId(val9, -1);
			val9.CurrentState = (EnemyState)1;
			RepoEnemyAccess.SetStateSpawnEnemy(stateSpawn, val9);
			RepoEnemyAccess.SetStateStunnedEnemy(stateStunned, val9);
			val4.SetActive(true);
			val2.ObservedComponents = new List<Component> { (Component)(object)val };
			val6.ObservedComponents = new List<Component> { (Component)(object)val9 };
			SetLayerRecursively(root, layer);
			TrySetTagRecursively(root, "Enemy");
		}

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

		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("Mita core components were not present on spawned clone.");
			}
			SetHideFlagsRecursively(((Component)this).transform, (HideFlags)0);
			((Behaviour)rootPhotonView).enabled = true;
			((Behaviour)enemyPhotonView).enabled = true;
			EnsureRuntimeNavMeshAgent(enemy);
			EmpressRepoMitaPlugin.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/MitaEnemy/Center"));
			enemyPhotonView = val;
			centerTransform = val2;
			if ((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)
			{
				return (Object)(object)val2 != (Object)null;
			}
			return false;
		}

		private static EnemyNavMeshAgent EnsureRuntimeNavMeshAgent(Enemy enemy)
		{
			//IL_0058: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			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
			{
				EmpressRepoMitaPlugin.Log.LogWarning((object)$"[Mita] Could not find nearby NavMesh for spawned Mita 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 = true;
			if (!((Behaviour)val).enabled && TryFindNearestNavMeshPoint(enemy, out var hit2))
			{
				((Behaviour)val).enabled = true;
				if (val.isOnNavMesh)
				{
					val.Warp(((NavMeshHit)(ref hit2)).position);
				}
			}
			return val2;
		}

		private static bool TryFindNearestNavMeshPoint(Enemy enemy, out NavMeshHit hit)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] 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 = 3.15f;
			navMeshAgent.acceleration = 24f;
			navMeshAgent.angularSpeed = 220f;
			navMeshAgent.stoppingDistance = 0.9f;
			navMeshAgent.radius = 0.48f;
			navMeshAgent.height = 2.9f;
			navMeshAgent.autoTraverseOffMeshLink = true;
			navMeshAgent.obstacleAvoidanceType = (ObstacleAvoidanceType)4;
		}

		private static int ResolveLayer(string layerName)
		{
			int num = LayerMask.NameToLayer(layerName);
			if (num < 0)
			{
				return 0;
			}
			return num;
		}

		private static void SetHideFlagsRecursively(Transform root, HideFlags hideFlags)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0022: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: 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)
			{
			}
		}
	}
	public sealed class EmpressRepoMitaController : MonoBehaviour
	{
		private enum MitaState
		{
			Roaming,
			Stalking,
			Chasing,
			Attacking,
			Recovering,
			Leaving,
			Dead
		}

		private const float RoamSpeed = 1.3f;

		private const float StalkSpeed = 1.75f;

		private const float ChaseSpeed = 3.25f;

		private const float LeaveSpeed = 2.25f;

		private const float DetectionRange = 20f;

		private const float ForcedDetectDistance = 5f;

		private const float LoseTargetDistance = 34f;

		private const float TeleportDistanceMin = 9.5f;

		private const float AttackDistance = 1.45f;

		private const float AttackCooldown = 2.8f;

		private const float RecoverDuration = 0.95f;

		private const float LeaveDuration = 6.5f;

		private const float StareDurationMin = 0.25f;

		private const float StareDurationMax = 0.65f;

		private const float AmbushChance = 0.14f;

		private const float TurnSpeed = 10f;

		private const float BreathIntervalMin = 6.5f;

		private const float BreathIntervalMax = 11f;

		private const float StareIntervalMin = 5.5f;

		private const float StareIntervalMax = 9.5f;

		private const float VoiceIntervalMin = 5.5f;

		private const float VoiceIntervalMax = 13f;

		private const float VoiceGlitchDurationMin = 0.85f;

		private const float VoiceGlitchDurationMax = 4.75f;

		private const float HauntRushDurationMin = 1.35f;

		private const float HauntRushDurationMax = 2.45f;

		private const float HauntRushSpeedBonus = 0.72f;

		private const float MemoryHuntDuration = 4.2f;

		private const float StepMoveThreshold = 0.92f;

		private const float AttackDamage = 25f;

		private const float DoorPushCooldownTime = 0.1f;

		private const float DoorPushRadius = 0.72f;

		private const float DoorPushForce = 3.1f;

		private const float DoorPushTorque = 1.35f;

		private const float ObjectPushRadius = 0.9f;

		private const float ObjectPushForce = 2.2f;

		private const float ObjectPushUpward = 0.12f;

		private const string BreathClipName = "Ambient MitaNear";

		private const string StareClipName = "MitaBreath";

		private const string TeleportClipName = "MitaHide";

		private const string AttackSwingClipName = "Move MitaAttack";

		private const string AttackHitClipPrimaryName = "MitaCreepy Hit 1";

		private const string AttackHitSecondaryName = "MitaCreepy Hit 2";

		private static readonly string[] VoiceClipNames = new string[3] { "Mita Creepy", "MitaCreepy Killing", "Mita Screamer" };

		private static readonly string[] StepClipNames = new string[1] { "MitaStep" };

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

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

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

		private static readonly Collider[] ObjectPushHits = (Collider[])(object)new Collider[12];

		private const string IdleStateName = "Idle";

		private const string AttackRunningStateName = "Mita Attack";

		private const string AttackHorizontalStateName = "Mita Attack";

		private const string AttackStationaryStateName = "Mita Attack";

		private const string AttackBackLeftStateName = "Mita Attack";

		private const string AttackBackRightStateName = "Mita Attack";

		private const string TeleportForwardStateName = "Mita Appear";

		private const string TeleportBackwardStateName = "Mita Appear";

		private const string DeathStateName = "Mita Break";

		private const string MovementStateName = "Walk";

		public Transform VisualRoot;

		public Transform CenterTransform;

		public Transform HeadTransform;

		public Animator? VisualAnimator;

		public EnemyHealth? Health;

		public PhysGrabObject? GrabObject;

		private Enemy _enemy;

		private EnemyParent _enemyParent;

		private PhotonView _photonView;

		private EnemyNavMeshAgent? _navAgent;

		private PlayerAvatar? _targetPlayer;

		private MitaState _state;

		private bool _initialized;

		private bool _spawnedPrevious;

		private bool _dead;

		private bool _dying;

		private bool _attackDamageDone;

		private bool _stateAware;

		private float _stateTimer;

		private float _targetRefreshTimer;

		private float _attackCooldownTimer;

		private float _teleportCooldownTimer;

		private float _roamRetargetTimer;

		private float _stareDuration;

		private float _movementSpeed;

		private float _attackDuration;

		private float _attackHitTime;

		private Vector3 _roamDestination;

		private Vector3 _leaveDestination;

		private Vector3 _lastPosition;

		private Vector3 _lastKnownTargetPosition;

		private bool _hasLastPosition;

		private bool _hasLastKnownTargetPosition;

		private bool _wasStunned;

		private int _syncedTargetViewId = -1;

		private bool _animatorHasSpeed;

		private bool _animatorHasAware;

		private bool _animatorHasStress;

		private bool _animatorHasMoveValue;

		private bool _animatorHasArming;

		private bool _animatorHasAttackSpeed;

		private float _animatorLockTimer;

		private float _nextBreathTime;

		private float _nextStareTime;

		private float _nextVoiceTime;

		private float _stepTimer;

		private float _doorPushCooldown;

		private float _locomotionSuppressTimer;

		private float _hauntRushTimer;

		private float _memoryHuntTimer;

		private string? _lockedAnimatorStateName;

		private string? _lastRequestedAnimatorStateName;

		private PlayableGraph _oneShotGraph;

		private bool _oneShotGraphValid;

		private AnimationClipPlayable _activeClipPlayable;

		private bool _activeClipLooping;

		private float _activeClipLength;

		private float _oneShotTimer;

		private string? _activeOneShotClipName;

		private Transform? _leftArmBone;

		private Transform? _rightArmBone;

		private Transform? _chestBone;

		private Transform? _headBone;

		private Quaternion _leftArmBaseRotation;

		private Quaternion _rightArmBaseRotation;

		private Quaternion _chestBaseRotation;

		private Quaternion _headBaseRotation;

		private Renderer[]? _teddyRenderers;

		private bool _teddyVisible = true;

		private float _glitchTimer;

		private float _glitchDuration;

		private Vector3 _visualRootBaseLocalPosition;

		private Quaternion _visualRootBaseLocalRotation;

		private bool _hasVisualRootBaseTransform;

		private AudioSource? _voiceSource;

		private AudioSource? _stepSource;

		private AudioSource? _fxSource;

		private static AudioClip? _breathClip;

		private static AudioClip? _stareClip;

		private static AudioClip[]? _stepClips;

		private static AudioClip? _teleportClip;

		private static AudioClip? _attackSwingClip;

		private static AudioClip? _attackHitClip;

		private static AudioClip[]? _voiceClips;

		internal EnemyNavMeshAgent? NavAgent => _navAgent;

		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>();
			_navAgent = (EnemyNavMeshAgent?)(_enemy.HasNavMeshAgent ? ((object)_enemy.NavMeshAgent) : ((object)FindNearbyComponent<EnemyNavMeshAgent>((Component)(object)_enemy)));
		}

		private void OnDestroy()
		{
			StopOneShotClipPlayback();
		}

		public void InitializeRuntime()
		{
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			if (_initialized)
			{
				return;
			}
			if ((Object)(object)VisualAnimator != (Object)null)
			{
				((Behaviour)VisualAnimator).enabled = true;
				VisualAnimator.applyRootMotion = false;
				_animatorHasSpeed = HasAnimatorParameter(VisualAnimator, "Speed", (AnimatorControllerParameterType)1);
				_animatorHasAware = HasAnimatorParameter(VisualAnimator, "IsAware", (AnimatorControllerParameterType)4);
				_animatorHasStress = HasAnimatorParameter(VisualAnimator, "Stress", (AnimatorControllerParameterType)1);
				_animatorHasMoveValue = HasAnimatorParameter(VisualAnimator, "MoveValue", (AnimatorControllerParameterType)1);
				_animatorHasArming = HasAnimatorParameter(VisualAnimator, "Arming", (AnimatorControllerParameterType)1);
				_animatorHasAttackSpeed = HasAnimatorParameter(VisualAnimator, "AttackSpeed", (AnimatorControllerParameterType)1);
				VisualAnimator.Rebind();
				for (int i = 0; i < VisualAnimator.layerCount; i++)
				{
					VisualAnimator.SetLayerWeight(i, (i == 0) ? 1f : 0f);
				}
				VisualAnimator.Update(0f);
				BindProceduralBones();
				BindTeddyRenderers();
			}
			if ((Object)(object)VisualRoot != (Object)null)
			{
				_visualRootBaseLocalPosition = VisualRoot.localPosition;
				_visualRootBaseLocalRotation = VisualRoot.localRotation;
				_hasVisualRootBaseTransform = true;
			}
			EnsureAudio();
			_state = MitaState.Roaming;
			_initialized = true;
			_nextBreathTime = Time.time + Random.Range(0.8f, 2.2f);
			_nextStareTime = Time.time + Random.Range(2.4f, 4.8f);
			_nextVoiceTime = Time.time + Random.Range(3.5f, 7.5f);
			_stepTimer = 0f;
			UpdateAnimatorState(forceIdle: true);
			UpdateTeddyVisibility(force: true);
		}

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

		private void BindProceduralBones()
		{
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)VisualRoot == (Object)null))
			{
				_leftArmBone = FindChildRecursive(VisualRoot, "Left arm");
				_rightArmBone = FindChildRecursive(VisualRoot, "Right arm");
				_chestBone = FindChildRecursive(VisualRoot, "Chest");
				_headBone = FindChildRecursive(VisualRoot, "Head");
				_leftArmBaseRotation = (((Object)(object)_leftArmBone != (Object)null) ? _leftArmBone.localRotation : Quaternion.identity);
				_rightArmBaseRotation = (((Object)(object)_rightArmBone != (Object)null) ? _rightArmBone.localRotation : Quaternion.identity);
				_chestBaseRotation = (((Object)(object)_chestBone != (Object)null) ? _chestBone.localRotation : Quaternion.identity);
				_headBaseRotation = (((Object)(object)_headBone != (Object)null) ? _headBone.localRotation : Quaternion.identity);
			}
		}

		private void BindTeddyRenderers()
		{
			if ((Object)(object)VisualRoot == (Object)null)
			{
				_teddyRenderers = Array.Empty<Renderer>();
				return;
			}
			List<Renderer> list = new List<Renderer>();
			Renderer[] componentsInChildren = ((Component)VisualRoot).GetComponentsInChildren<Renderer>(true);
			foreach (Renderer val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string name = ((Object)val).name;
					string text = (((Object)(object)val.sharedMaterial != (Object)null) ? ((Object)val.sharedMaterial).name : string.Empty);
					if (name.IndexOf("teddy", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("bear", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("teddy", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("bear", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						list.Add(val);
					}
				}
			}
			_teddyRenderers = list.ToArray();
			_teddyVisible = true;
		}

		private static Transform? FindChildRecursive(Transform root, string name)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			foreach (Transform item in root)
			{
				Transform val = item;
				if (string.Equals(((Object)val).name, name, StringComparison.OrdinalIgnoreCase))
				{
					return val;
				}
				Transform val2 = FindChildRecursive(val, name);
				if ((Object)(object)val2 != (Object)null)
				{
					return val2;
				}
			}
			return null;
		}

		private void UpdateProceduralPose()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: 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_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_leftArmBone == (Object)null) || !((Object)(object)_rightArmBone == (Object)null) || !((Object)(object)_chestBone == (Object)null) || !((Object)(object)_headBone == (Object)null))
			{
				bool flag = _state == MitaState.Attacking;
				float num = ((flag && _attackDuration > 0.01f) ? Mathf.Clamp01(_stateTimer / _attackDuration) : 0f);
				if (!flag)
				{
					RestoreProceduralBone(_leftArmBone, _leftArmBaseRotation, 12f);
					RestoreProceduralBone(_rightArmBone, _rightArmBaseRotation, 12f);
					RestoreProceduralBone(_chestBone, _chestBaseRotation, 10f);
					RestoreProceduralBone(_headBone, _headBaseRotation, 10f);
					return;
				}
				float num2 = Mathf.Clamp01(num / 0.35f);
				float num3 = ((num < 0.35f) ? (num2 * 0.55f) : Mathf.Sin(Mathf.Clamp01((num - 0.35f) / 0.45f) * MathF.PI));
				float num4 = Mathf.SmoothStep(1f, 0f, Mathf.Clamp01((num - 0.72f) / 0.28f));
				float num5 = Mathf.Clamp01(Mathf.Max(num3, num2 * num4));
				SetProceduralBone(_leftArmBone, _leftArmBaseRotation * Quaternion.Euler(Mathf.Lerp(0f, -48f, num5), Mathf.Lerp(0f, -18f, num5), Mathf.Lerp(0f, 24f, num5)), 22f);
				SetProceduralBone(_rightArmBone, _rightArmBaseRotation * Quaternion.Euler(Mathf.Lerp(0f, -74f, num5), Mathf.Lerp(0f, 24f, num5), Mathf.Lerp(0f, -30f, num5)), 22f);
				SetProceduralBone(_chestBone, _chestBaseRotation * Quaternion.Euler(Mathf.Lerp(0f, 12f, num5), 0f, Mathf.Lerp(0f, -9f, num5)), 18f);
				SetProceduralBone(_headBone, _headBaseRotation * Quaternion.Euler(Mathf.Lerp(0f, 7f, num5), 0f, Mathf.Lerp(0f, 5f, num5)), 18f);
			}
		}

		private static void RestoreProceduralBone(Transform? bone, Quaternion baseRotation, float speed)
		{
			//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_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)bone == (Object)null))
			{
				bone.localRotation = Quaternion.Slerp(bone.localRotation, baseRotation, Mathf.Clamp01(Time.deltaTime * speed));
			}
		}

		private static void SetProceduralBone(Transform? bone, Quaternion targetRotation, float speed)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be du