Decompiled source of SlenderTubby Enemy v1.0.0

BepInEx\plugins\Empress-SlenderTubby\SlenderTubby.dll

Decompiled 3 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using REPOLib.Modules;
using REPOLib.Objects.Sdk;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Animations;
using UnityEngine.Events;
using UnityEngine.Playables;

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

		private const string SlenderTubbyAudioBundleFileName = "empressslendertubbyaudio";

		private const float SlenderTubbyBundleVisualScale = 0.94f;

		private const string BodyAlbedoTextureFileName = "tinky2024_TinkyReb_AlbedoTransparency.png";

		private const string BodyNormalTextureFileName = "TinkyReb_Normal_OpenGL.png";

		private const string AxeAlbedoTextureFileName = "Tinky_axe_Base_color.png";

		private const string AxeNormalTextureFileName = "Tinky_axe_Normal_OpenGL.png";

		private const string EyeAlbedoTextureFileName = "tinky_eye_Base_color.png";

		private static readonly string[] SlenderTubbyBundlePrefabCandidates = new string[4] { "SlenderTubby", "TinkyVisual_Main", "TinkyReb2024", "Tinky" };

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

		internal const string PluginName = "Empress REPO SlenderTubby";

		internal const string PluginVersion = "1.0.0";

		internal const string TemplatePrefabName = "EmpressSlenderTubbyPrefab";

		private static Harmony? _harmony;

		private static bool _registered;

		private static MethodInfo? _spawnManagerRefreshMethod;

		private static AssetBundle? _slenderTubbyBundle;

		private static AssetBundle? _slenderTubbyAudioBundle;

		private static GameObject? _slenderTubbyVisualPrefab;

		private static Material? _bodyMaterial;

		private static Material? _axeMaterial;

		private static Material? _eyeMaterial;

		private static Texture2D? _bodyAlbedoTexture;

		private static Texture2D? _bodyNormalTexture;

		private static Texture2D? _axeAlbedoTexture;

		private static Texture2D? _axeNormalTexture;

		private static Texture2D? _eyeAlbedoTexture;

		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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin location: " + ((BaseUnityPlugin)this).Info.Location));
			PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location) ?? string.Empty;
			((Component)this).transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			if (_harmony == null)
			{
				_harmony = new Harmony("Empress.REPO.SlenderTubby");
			}
			PatchTemplateGuards(_harmony);
			RegisterEnemy();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded Empress REPO SlenderTubby v1.0.0");
		}

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

		internal static void ConfigureRuntimeInstance(EnemyParent enemyParent, Enemy enemy, EnemyStateSpawn stateSpawn, EnemyStateStunned stateStunned, PhotonView rootPhotonView, PhotonView enemyPhotonView, Transform centerTransform)
		{
			//IL_0010: 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_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: 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_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Expected O, but got Unknown
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Expected O, but got Unknown
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Expected O, but got Unknown
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Expected O, but got Unknown
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Expected O, but got Unknown
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0384: Expected O, but got Unknown
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Expected O, but got Unknown
			Transform centerTransform2;
			Transform headTransform;
			Animator visualAnimator;
			Transform val = BuildSlenderTubbyVisualRig(enemy, out centerTransform2, out headTransform, out visualAnimator);
			enemy.Type = (EnemyType)3;
			enemy.CenterTransform = centerTransform2;
			enemy.KillLookAtTransform = headTransform;
			enemy.CustomValuableSpawnTransform = centerTransform2;
			enemy.CurrentState = (EnemyState)1;
			EmpressRepoSlenderTubbyController empressRepoSlenderTubbyController = ((Component)enemy).GetComponent<EmpressRepoSlenderTubbyController>() ?? ((Component)enemy).gameObject.AddComponent<EmpressRepoSlenderTubbyController>();
			empressRepoSlenderTubbyController.VisualRoot = val;
			empressRepoSlenderTubbyController.CenterTransform = centerTransform2;
			empressRepoSlenderTubbyController.HeadTransform = headTransform;
			empressRepoSlenderTubbyController.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(empressRepoSlenderTubbyController.HandleHurt));
			val8.onDeathStart.AddListener(new UnityAction(empressRepoSlenderTubbyController.HandleDeathStart));
			val8.onObjectHurt.AddListener(new UnityAction(empressRepoSlenderTubbyController.HandleObjectHurt));
			val8.onDeath.AddListener(new UnityAction(empressRepoSlenderTubbyController.HandleDeath));
			empressRepoSlenderTubbyController.Health = val8;
			empressRepoSlenderTubbyController.GrabObject = val3;
			RefreshHealthVisuals(val8, val);
			val8.OnSpawn();
			RepoEnemyAccess.SetEnemyParentEnemy(enemyParent, enemy);
			RepoEnemyAccess.SetEnemyParent(enemy, enemyParent);
			RepoEnemyAccess.SetPhotonView(enemy, enemyPhotonView);
			RepoEnemyAccess.SetHealth(enemy, val8);
			RepoEnemyAccess.SetHasHealth(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, empressRepoSlenderTubbyController.NavAgent);
			RepoEnemyAccess.SetHasNavMeshAgent(enemy, (Object)(object)empressRepoSlenderTubbyController.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
			};
			empressRepoSlenderTubbyController.InitializeRuntime();
		}

		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 BuildSlenderTubbyVisualRig(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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Expected O, but got Unknown
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			visualRoot = null;
			centerTransform = null;
			headTransform = null;
			visualAnimator = null;
			GameObject val = LoadSlenderTubbyVisualPrefab();
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			GameObject val2 = Object.Instantiate<GameObject>(val, attachRoot);
			((Object)val2).name = "SlenderTubbyVisualRoot";
			val2.transform.localPosition = Vector3.zero;
			val2.transform.localRotation = Quaternion.identity;
			Transform transform = val2.transform;
			transform.localScale *= 0.94f;
			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);
			}
			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("SlenderTubbyCenter");
			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 SlenderTubby.");
			return true;
		}

		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;
			return name.IndexOf("MapDot", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("ScanNode", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Debug", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Point", StringComparison.OrdinalIgnoreCase) >= 0 || name.IndexOf("Trigger", StringComparison.OrdinalIgnoreCase) >= 0;
		}

		private static void ConvertBundleMaterials(GameObject instance)
		{
			Shader val = Shader.Find("Standard");
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)"[SlenderTubby] Could not find Standard shader for material conversion.");
				return;
			}
			Material orCreateBodyMaterial = GetOrCreateBodyMaterial(val);
			Material orCreateAxeMaterial = GetOrCreateAxeMaterial(val);
			Material orCreateEyeMaterial = GetOrCreateEyeMaterial(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("axe", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("axe", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("item.r", StringComparison.OrdinalIgnoreCase) < 0) ? ((text.IndexOf("eye", StringComparison.OrdinalIgnoreCase) < 0 && name.IndexOf("eye", StringComparison.OrdinalIgnoreCase) < 0) ? orCreateBodyMaterial : orCreateEyeMaterial) : orCreateAxeMaterial);
					if (sharedMaterials[j] != val4)
					{
						sharedMaterials[j] = val4;
						flag = true;
					}
				}
				if (flag)
				{
					val2.sharedMaterials = sharedMaterials;
				}
			}
		}

		private static Material GetOrCreateBodyMaterial(Shader standardShader)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			if ((Object)(object)_bodyMaterial != (Object)null)
			{
				return _bodyMaterial;
			}
			_bodyMaterial = new Material(standardShader)
			{
				name = "SlenderTubbyBodyBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("tinky2024_TinkyReb_AlbedoTransparency.png", ref _bodyAlbedoTexture, isNormalMap: false);
			Texture2D val2 = ResolvePreferredTexture("TinkyReb_Normal_OpenGL.png", 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 GetOrCreateAxeMaterial(Shader standardShader)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			if ((Object)(object)_axeMaterial != (Object)null)
			{
				return _axeMaterial;
			}
			_axeMaterial = new Material(standardShader)
			{
				name = "SlenderTubbyAxeBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("Tinky_axe_Base_color.png", ref _axeAlbedoTexture, isNormalMap: false);
			Texture2D val2 = ResolvePreferredTexture("Tinky_axe_Normal_OpenGL.png", ref _axeNormalTexture, isNormalMap: true);
			if ((Object)(object)val != (Object)null)
			{
				_axeMaterial.mainTexture = (Texture)(object)val;
				_axeMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			if ((Object)(object)val2 != (Object)null)
			{
				_axeMaterial.SetTexture("_BumpMap", (Texture)(object)val2);
				_axeMaterial.EnableKeyword("_NORMALMAP");
				_axeMaterial.SetFloat("_BumpScale", 0.85f);
			}
			_axeMaterial.SetFloat("_Metallic", 0.35f);
			_axeMaterial.SetFloat("_Glossiness", 0.36f);
			return _axeMaterial;
		}

		private static Material GetOrCreateEyeMaterial(Shader standardShader)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: 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_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_eyeMaterial != (Object)null)
			{
				return _eyeMaterial;
			}
			_eyeMaterial = new Material(standardShader)
			{
				name = "SlenderTubbyEyeBuiltIn",
				hideFlags = (HideFlags)61,
				color = Color.white
			};
			Texture2D val = ResolvePreferredTexture("tinky_eye_Base_color.png", ref _eyeAlbedoTexture, isNormalMap: false);
			if ((Object)(object)val != (Object)null)
			{
				_eyeMaterial.mainTexture = (Texture)(object)val;
				_eyeMaterial.SetTexture("_MainTex", (Texture)(object)val);
			}
			_eyeMaterial.EnableKeyword("_EMISSION");
			_eyeMaterial.SetColor("_EmissionColor", new Color(0.14f, 0.14f, 0.14f, 1f));
			_eyeMaterial.SetFloat("_Glossiness", 0.18f);
			return _eyeMaterial;
		}

		private static Texture2D? ResolvePreferredTexture(string expectedFileName, ref Texture2D? cache, bool isNormalMap)
		{
			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)_slenderTubbyBundle == (Object)null)
			{
				return null;
			}
			Texture2D[] array = _slenderTubbyBundle.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_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_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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)("[SlenderTubby] Failed to load texture '" + path + "': " + ex.Message));
				return null;
			}
		}

		private static Transform BuildFallbackVisualRig(Transform attachRoot, out Transform centerTransform, out Transform headTransform)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0268: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Unknown result type (might be due to invalid IL or missing references)
			//IL_031b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_035a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_039c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("SlenderTubbyVisualRoot");
			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("SlenderTubbyCenter").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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ce: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = enemyObject.transform;
			Transform val = transform.Find("Grab Collider");
			GameObject val2;
			if ((Object)(object)val == (Object)null)
			{
				val2 = new GameObject("Grab Collider");
				val2.transform.SetParent(transform, false);
			}
			else
			{
				val2 = ((Component)val).gameObject;
			}
			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 val3 = transform.InverseTransformPoint(((Bounds)(ref bounds)).center);
			val2.transform.localPosition = val3;
			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 val5 = val2.GetComponent<CapsuleCollider>() ?? val2.AddComponent<CapsuleCollider>();
			((Collider)val5).isTrigger = false;
			val5.direction = 1;
			val5.center = Vector3.zero;
			val5.height = Mathf.Clamp(((Bounds)(ref bounds)).size.y * 0.92f, 2f, 3.4f);
			val5.radius = Mathf.Clamp(Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.z) * 0.22f, 0.28f, 0.72f);
			PhysGrabObjectCollider val6 = val2.GetComponent<PhysGrabObjectCollider>() ?? val2.AddComponent<PhysGrabObjectCollider>();
			val6.colliderID = 0;
			val6.physGrabObject = physGrabObject;
			if (!physGrabObject.colliders.Contains(val2.transform))
			{
				physGrabObject.colliders.Add(val2.transform);
			}
			Transform val7 = transform.Find("Center of Mass");
			if ((Object)(object)val7 == (Object)null)
			{
				GameObject val8 = new GameObject("Center of Mass");
				val8.transform.SetParent(transform, false);
				val7 = val8.transform;
			}
			val7.localPosition = val3;
			val7.localRotation = Quaternion.identity;
			val7.localScale = Vector3.one;
			Transform val9 = transform.Find("ForceCenterPoint");
			if ((Object)(object)val9 == (Object)null)
			{
				GameObject val10 = new GameObject("ForceCenterPoint");
				val10.transform.SetParent(transform, false);
				val9 = val10.transform;
			}
			val9.localPosition = val3 + new Vector3(0f, 0.1f, 0.08f);
			val9.localRotation = Quaternion.identity;
			val9.localScale = Vector3.one;
		}

		private static PhysAttribute GetOrCreateGrabPhysAttribute()
		{
			if ((Object)(object)_grabPhysAttribute != (Object)null)
			{
				return _grabPhysAttribute;
			}
			_grabPhysAttribute = ScriptableObject.CreateInstance<PhysAttribute>();
			((Object)_grabPhysAttribute).hideFlags = (HideFlags)61;
			((Object)_grabPhysAttribute).name = "PhysAttributeSlenderTubbyGrab";
			_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 = "DurabilitySlenderTubbyGrab";
			_grabDurability.fragility = 100f;
			_grabDurability.durability = 100f;
			return _grabDurability;
		}

		private static void RefreshHealthVisuals(EnemyHealth health, Transform meshRoot)
		{
			//IL_0186: 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? LoadSlenderTubbyVisualPrefab()
		{
			if ((Object)(object)_slenderTubbyVisualPrefab != (Object)null)
			{
				return _slenderTubbyVisualPrefab;
			}
			string text = ResolvePluginFile("empressslendertubby");
			if (string.IsNullOrEmpty(text))
			{
				return null;
			}
			try
			{
				if (_slenderTubbyBundle == null)
				{
					_slenderTubbyBundle = AssetBundle.LoadFromFile(text);
				}
				if ((Object)(object)_slenderTubbyBundle == (Object)null)
				{
					Log.LogWarning((object)("[SlenderTubby] Failed to load asset bundle at " + text));
					return null;
				}
				string[] slenderTubbyBundlePrefabCandidates = SlenderTubbyBundlePrefabCandidates;
				foreach (string text2 in slenderTubbyBundlePrefabCandidates)
				{
					GameObject val = _slenderTubbyBundle.LoadAsset<GameObject>(text2);
					if ((Object)(object)val != (Object)null)
					{
						_slenderTubbyVisualPrefab = val;
						return _slenderTubbyVisualPrefab;
					}
				}
				GameObject[] array = _slenderTubbyBundle.LoadAllAssets<GameObject>();
				foreach (GameObject val2 in array)
				{
					if (!((Object)(object)val2 == (Object)null))
					{
						_slenderTubbyVisualPrefab = val2;
						Log.LogWarning((object)("[SlenderTubby] Falling back to first prefab '" + ((Object)val2).name + "' from asset bundle."));
						return _slenderTubbyVisualPrefab;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[SlenderTubby] Failed while loading visual asset bundle: " + ex.Message));
			}
			return null;
		}

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

		internal static AudioClip? LoadAudioClip(string clipName)
		{
			AssetBundle val = LoadSlenderTubbyAudioBundle();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			try
			{
				return val.LoadAsset<AudioClip>(clipName);
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[SlenderTubby] 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)("[SlenderTubby] 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_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			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);
					}
				}
			}
			return flag ? new Bounds?(value) : null;
		}

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

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

		private static Material FindSeedMaterial(GameObject prefab)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: 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 SlenderTubby visuals.");
		}

		private static Material CreateTintedMaterial(Material seedMaterial, Color color)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			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_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive(primitiveType);
			((Object)val).name = name;
			val.transform.SetParent(parent, false);
			val.transform.localPosition = localPosition;
			val.transform.localScale = localScale;
			val.transform.localRotation = Quaternion.Euler((Vector3)(((??)localEulerAngles) ?? Vector3.zero));
			Collider[] components = val.GetComponents<Collider>();
			foreach (Collider val2 in components)
			{
				val2.enabled = false;
			}
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				component.sharedMaterial = material;
			}
			return val.transform;
		}

		private static void PatchTemplateGuards(Harmony harmony)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Expected O, but got Unknown
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Expected O, but got Unknown
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Expected O, but got Unknown
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Expected O, but got Unknown
			harmony.Patch((MethodBase)AccessTools.Method(typeof(EnemyParent), "Awake", (Type[])null, (Type[])null), new HarmonyMethod(typeof(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "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(EmpressRepoSlenderTubbyPlugin), "SkipTemplateEnemyStateStunnedUpdate", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

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

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

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

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

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

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

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

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

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

		private static bool SkipTemplateEnemyStateStunnedUpdate(EnemyStateStunned __instance)
		{
			return !SlenderTubbyTemplateBootstrap.IsTemplateInstance(((Component)__instance).gameObject);
		}
	}
	[HarmonyPatch(typeof(EnemyDirector), "Start")]
	internal static class EmpressRepoSlenderTubbyEnemyDirectorStartPatch
	{
		private static void Postfix()
		{
			EmpressRepoSlenderTubbyPlugin.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> 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, 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 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 SlenderTubbyTemplateBootstrap : MonoBehaviour
	{
		private const string EnableObjectName = "EnableObject";

		private const string EnemyObjectName = "SlenderTubbyEnemy";

		private const string CenterObjectName = "Center";

		private const string TemplateContainerName = "EmpressSlenderTubbyTemplateContainer";

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

		private static GameObject? _templateContainer;

		private bool _runtimeBuilt;

		internal static GameObject CreateTemplate(ManualLogSource log)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = EnsureTemplateContainer();
			GameObject val2 = new GameObject("EmpressSlenderTubbyPrefab")
			{
				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 SlenderTubby template core.");
			return val2;
		}

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

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

		private static void BuildTemplateCore(Transform root)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: 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_02ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c5: 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<SlenderTubbyTemplateBootstrap>();
			GameObject val3 = new GameObject("EnableObject");
			val3.transform.SetParent(root, false);
			val3.layer = layer;
			TrySetTag(val3, "Enemy");
			GameObject val4 = new GameObject("SlenderTubbyEnemy");
			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 = "SlenderTubby";
			val.difficulty = (Difficulty)0;
			val.actionMultiplier = 1.5f;
			val.overchargeMultiplier = 1.18f;
			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)
			{
				EmpressRepoSlenderTubbyPlugin.Log.LogError((object)$"Failed to finish SlenderTubby 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("SlenderTubby core components were not present on spawned clone.");
			}
			SetHideFlagsRecursively(((Component)this).transform, (HideFlags)0);
			((Behaviour)rootPhotonView).enabled = true;
			((Behaviour)enemyPhotonView).enabled = true;
			EnsureRuntimeNavMeshAgent(enemy);
			EmpressRepoSlenderTubbyPlugin.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/SlenderTubbyEnemy/Center"));
			enemyPhotonView = val;
			centerTransform = val2;
			return (Object)(object)enemyParent != (Object)null && (Object)(object)enemy != (Object)null && (Object)(object)stateSpawn != (Object)null && (Object)(object)stateStunned != (Object)null && (Object)(object)rootPhotonView != (Object)null && (Object)(object)val != (Object)null && (Object)(object)val2 != (Object)null;
		}

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

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

		private static void ConfigureNavMeshAgent(NavMeshAgent navMeshAgent)
		{
			navMeshAgent.speed = 4.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);
			return (num >= 0) ? num : 0;
		}

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

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

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

		private static void TrySetTag(GameObject gameObject, string tag)
		{
			try
			{
				gameObject.tag = tag;
			}
			catch (UnityException)
			{
			}
		}
	}
	public sealed class EmpressRepoSlenderTubbyController : MonoBehaviour
	{
		private enum SlenderTubbyState
		{
			Roaming,
			Stalking,
			Chasing,
			Attacking,
			Recovering,
			Dead
		}

		private const float RoamSpeed = 1.7f;

		private const float StalkSpeed = 2.15f;

		private const float ChaseSpeed = 4.15f;

		private const float DetectionRange = 19f;

		private const float ForcedDetectDistance = 5f;

		private const float LoseTargetDistance = 28f;

		private const float TeleportDistanceMin = 11f;

		private const float AttackDistance = 1.78f;

		private const float AttackCooldown = 2.2f;

		private const float RecoverDuration = 0.85f;

		private const float TurnSpeed = 10f;

		private const float BreathIntervalMin = 3.2f;

		private const float BreathIntervalMax = 6.1f;

		private const float StareIntervalMin = 5.5f;

		private const float StareIntervalMax = 9.5f;

		private const float StepMoveThreshold = 1.25f;

		private const float AttackDamage = 20f;

		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 = "tinkybreath";

		private const string StareClipName = "tinky_stare";

		private const string TeleportClipName = "tinky_appear";

		private const string AttackSwingClipName = "axe_swing";

		private const string AttackHitClipPrimaryName = "AXEHIT2";

		private const string AttackHitSecondaryName = "AXEHIT3";

		private static readonly string[] StepClipNames = new string[9] { "wood_step_1", "wood_step_2", "wood_step_3", "wood_step_4", "wood_step_5", "wood_step_6", "wood_step_7", "wood_step_8", "wood_step_9" };

		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_LOOKAROUND";

		private const string AttackRunningStateName = "TINKY_RUNNING_ATTACK";

		private const string AttackHorizontalStateName = "AXE_HIT_HORIZONTAL";

		private const string AttackStationaryStateName = "AXE_HIT1";

		private const string AttackBackLeftStateName = "AXE_HIT_BACKLEFT";

		private const string AttackBackRightStateName = "AXE_HIT_BACKRIGHT";

		private const string TeleportForwardStateName = "TELEPORT_FORWARD";

		private const string TeleportBackwardStateName = "TELEPORT_BACKWARD";

		private const string DeathStateName = "TinkyDie";

		private const string MovementStateName = "Movement Default";

		public Transform VisualRoot = null;

		public Transform CenterTransform = null;

		public Transform HeadTransform = null;

		public Animator? VisualAnimator;

		public EnemyHealth? Health;

		public PhysGrabObject? GrabObject;

		private Enemy _enemy = null;

		private EnemyParent _enemyParent = null;

		private PhotonView _photonView = null;

		private EnemyNavMeshAgent? _navAgent;

		private PlayerAvatar? _targetPlayer;

		private SlenderTubbyState _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 _movementSpeed;

		private float _attackDuration;

		private float _attackHitTime;

		private Vector3 _roamDestination;

		private Vector3 _lastPosition;

		private bool _hasLastPosition;

		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 _stepTimer;

		private float _doorPushCooldown;

		private string? _lockedAnimatorStateName;

		private string? _lastRequestedAnimatorStateName;

		private PlayableGraph _oneShotGraph;

		private bool _oneShotGraphValid;

		private float _oneShotTimer;

		private string? _activeOneShotClipName;

		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;

		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()
		{
			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);
			}
			EnsureAudio();
			_state = SlenderTubbyState.Roaming;
			_initialized = true;
			_nextBreathTime = Time.time + Random.Range(0.8f, 2.2f);
			_nextStareTime = Time.time + Random.Range(2.4f, 4.8f);
			_stepTimer = 0f;
			UpdateAnimatorState(forceIdle: 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 Update()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			if (!_initialized)
			{
				return;
			}
			if (_hasLastPosition && Time.deltaTime > 0f)
			{
				_movementSpeed = Vector3.Distance(((Component)this).transform.position, _lastPosition) / Time.deltaTime;
			}
			_lastPosition = ((Component)this).transform.position;
			_hasLastPosition = true;
			_stateTimer += Time.deltaTime;
			if (_attackCooldownTimer > 0f)
			{
				_attackCooldownTimer -= Time.deltaTime;
			}
			if (_teleportCooldownTimer > 0f)
			{
				_teleportCooldownTimer -= Time.deltaTime;
			}
			if (_doorPushCooldown > 0f)
			{
				_doorPushCooldown -= Time.deltaTime;
			}
			if (_animatorLockTimer > 0f)
			{
				_animatorLockTimer -= Time.deltaTime;
				if (_animatorLockTimer <= 0f)
				{
					_animatorLockTimer = 0f;
					_lockedAnimatorStateName = null;
				}
			}
			if (_oneShotTimer > 0f)
			{
				_oneShotTimer -= Time.deltaTime;
				if (_oneShotTimer <= 0f)
				{
					StopOneShotClipPlayback();
				}
			}
			bool flag = (Object)(object)_enemyParent != (Object)null && _enemyParent.Spawned && ((Object)(object)_enemyParent.EnableObject == (Object)null || _enemyParent.EnableObject.activeSelf);
			if (flag != _spawnedPrevious)
			{
				_spawnedPrevious = flag;
				if (flag)
				{
					ResetBehaviour();
				}
			}
			if (!flag)
			{
				StopMoving();
				StopLoopingAudio();
				UpdateAnimatorState(forceIdle: true);
				return;
			}
			if (HasAuthority())
			{
				RunAuthorityLogic();
			}
			else
			{
				ClientUpdateFacing();
			}
			UpdatePhysicalInteraction();
			UpdateAudio();
			UpdateAnimatorState(forceIdle: false);
		}

		private void ResetBehaviour()
		{
			_dead = false;
			_dying = false;
			_state = SlenderTubbyState.Roaming;
			_stateAware = false;
			_stateTimer = 0f;
			_targetRefreshTimer = 0f;
			_attackCooldownTimer = 1f;
			_teleportCooldownTimer = 4f;
			_roamRetargetTimer = 0f;
			_attackDamageDone = false;
			_targetPlayer = null;
			_syncedTargetViewId = -1;
			_lockedAnimatorStateName = null;
			_lastRequestedAnimatorStateName = null;
			_animatorLockTimer = 0f;
			StopOneShotClipPlayback();
			_nextBreathTime = Time.time + Random.Range(1.2f, 2.8f);
			_nextStareTime = Time.time + Random.Range(3.2f, 6.2f);
			_stepTimer = 0f;
			RepoEnemyAccess.SetTargetPlayerViewId(_enemy, -1);
			StopMoving();
			BroadcastState();
		}

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

		private void RunAuthorityLogic()
		{
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0233: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if (_dead || _dying || _state == SlenderTubbyState.Dead)
			{
				return;
			}
			if (IsBeingGrabbed())
			{
				StopMoving();
				_stateAware = false;
				return;
			}
			_targetRefreshTimer -= Time.deltaTime;
			if (_targetRefreshTimer <= 0f)
			{
				_targetRefreshTimer = 0.35f;
				AcquireNearestTarget();
			}
			if (_state == SlenderTubbyState.Attacking)
			{
				HandleAttacking();
				return;
			}
			if (_state == SlenderTubbyState.Recovering)
			{
				HandleRecovering();
				return;
			}
			if ((Object)(object)_targetPlayer == (Object)null || !IsTargetValid(_targetPlayer))
			{
				_targetPlayer = null;
				_syncedTargetViewId = -1;
				RepoEnemyAccess.SetTargetPlayerViewId(_enemy, -1);
				_stateAware = false;
				SetState(SlenderTubbyState.Roaming);
				HandleRoam();
				return;
			}
			Vector3 position = ((Component)_targetPlayer).transform.position;
			float num = Vector3.Distance(((Component)this).transform.position, position);
			bool flag = HasLineOfSightTo(_targetPlayer);
			if (!flag && num > 28f)
			{
				_targetPlayer = null;
				_syncedTargetViewId = -1;
				RepoEnemyAccess.SetTargetPlayerViewId(_enemy, -1);
				_stateAware = false;
				SetState(SlenderTubbyState.Roaming);
				HandleRoam();
				return;
			}
			_stateAware = true;
			if (num <= 1.78f && _attackCooldownTimer <= 0f)
			{
				BeginAttack(num > 1.95f);
			}
			else if (!flag && num >= 11f && _teleportCooldownTimer <= 0f)
			{
				TryTeleportAroundTarget();
			}
			else if (num > 8f || !flag)
			{
				SetState(SlenderTubbyState.Stalking);
				MoveTowards(position, 2.15f);
			}
			else
			{
				SetState(SlenderTubbyState.Chasing);
				MoveTowards(position, 4.15f);
			}
		}

		private void HandleRoam()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			_roamRetargetTimer -= Time.deltaTime;
			if (_roamRetargetTimer <= 0f || !HasPath())
			{
				_roamRetargetTimer = Random.Range(2.6f, 4.8f);
				_roamDestination = PickRoamDestination();
			}
			MoveTowards(_roamDestination, 1.7f);
		}

		private void HandleAttacking()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			StopMoving();
			if ((Object)(object)_targetPlayer != (Object)null && IsTargetValid(_targetPlayer))
			{
				FaceTowards(((Component)_targetPlayer).transform.position, 14f);
			}
			if (!_attackDamageDone && _stateTimer >= _attackHitTime)
			{
				_attackDamageDone = true;
				DoAttackHit();
			}
			if (_stateTimer >= _attackDuration)
			{
				_attackCooldownTimer = 2.2f;
				SetState(SlenderTubbyState.Recovering);
			}
		}

		private void HandleRecovering()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			StopMoving();
			if ((Object)(object)_targetPlayer != (Object)null && IsTargetValid(_targetPlayer))
			{
				FaceTowards(((Component)_targetPlayer).transform.position, 10f);
			}
			if (_stateTimer >= 0.85f)
			{
				SetState(((Object)(object)_targetPlayer != (Object)null) ? SlenderTubbyState.Chasing : SlenderTubbyState.Roaming);
			}
		}

		private bool IsBeingGrabbed()
		{
			return (Object)(object)GrabObject != (Object)null && (GrabObject.grabbed || GrabObject.grabbedLocal || GrabObject.playerGrabbing.Count > 0);
		}

		private void AcquireNearestTarget()
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameDirector.instance == (Object)null)
			{
				_targetPlayer = null;
				_syncedTargetViewId = -1;
				RepoEnemyAccess.SetTargetPlayerViewId(_enemy, -1);
				BroadcastState();
				return;
			}
			PlayerAvatar val = null;
			float num = 19f;
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (IsTargetValid(player))
				{
					float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)player).transform.position);
					if (!(num2 > 19f) && (!(num2 > 5f) || CanDetectPlayer(player)) && num2 < num)
					{
						val = player;
						num = num2;
					}
				}
			}
			int syncedTargetViewId = _syncedTargetViewId;
			_targetPlayer = val;
			_syncedTargetViewId = (((Object)(object)val != (Object)null) ? val.photonView.ViewID : (-1));
			RepoEnemyAccess.SetTargetPlayerViewId(_enemy, _syncedTargetViewId);
			if (syncedTargetViewId != _syncedTargetViewId)
			{
				BroadcastState();
			}
		}

		private bool CanDetectPlayer(PlayerAvatar player)
		{
			//IL_003b: 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_0040: 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_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			if (!IsTargetValid(player))
			{
				return false;
			}
			Vector3 val = (((Object)(object)HeadTransform != (Object)null) ? HeadTransform.position : CenterTransform.position);
			Transform val2 = (((Object)(object)player.PlayerVisionTarget != (Object)null && (Object)(object)player.PlayerVisionTarget.VisionTransform != (Object)null) ? player.PlayerVisionTarget.VisionTransform : ((Component)player).transform);
			Vector3 val3 = val2.position - val;
			float magnitude = ((Vector3)(ref val3)).magnitude;
			if (magnitude <= 5f)
			{
				return true;
			}
			if (magnitude > 19f)
			{
				return false;
			}
			float num = Vector3.Angle(((Component)this).transform.forward, val3);
			if (num > 75f)
			{
				return false;
			}
			int num2 = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct());
			RaycastHit val4 = default(RaycastHit);
			if (Physics.Linecast(val, val2.position, ref val4, num2, (QueryTriggerInteraction)1) && !((RaycastHit)(ref val4)).transform.IsChildOf(((Component)player).transform))
			{
				return false;
			}
			return true;
		}

		private bool HasLineOfSightTo(PlayerAvatar player)
		{
			//IL_003b: 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_0040: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			if (!IsTargetValid(player))
			{
				return false;
			}
			Vector3 val = (((Object)(object)HeadTransform != (Object)null) ? HeadTransform.position : CenterTransform.position);
			Transform val2 = (((Object)(object)player.PlayerVisionTarget != (Object)null && (Object)(object)player.PlayerVisionTarget.VisionTransform != (Object)null) ? player.PlayerVisionTarget.VisionTransform : ((Component)player).transform);
			int num = LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct());
			RaycastHit val3 = default(RaycastHit);
			if (Physics.Linecast(val, val2.position, ref val3, num, (QueryTriggerInteraction)1) && !((RaycastHit)(ref val3)).transform.IsChildOf(((Component)player).transform))
			{
				return false;
			}
			return true;
		}

		private void BeginAttack(bool runningAttack)
		{
			_attackDamageDone = false;
			_attackDuration = (runningAttack ? 1.25f : 1.05f);
			_attackHitTime = (runningAttack ? 0.62f : 0.48f);
			SetState(SlenderTubbyState.Attacking);
			StopMoving();
			_movementSpeed = 0f;
			string text = SelectAttackState(runningAttack);
			if (!PlayLockedAnimation(text, 0.05f, _attackDuration + 0.08f))
			{
				PlayLockedAnimatorState(text, 0.05f, _attackDuration + 0.08f);
			}
			PlayAttackSwingAudio();
			if (SemiFunc.IsMultiplayer())
			{
				_photonView.RPC("PlayAttackRpc", (RpcTarget)1, new object[1] { text });
			}
		}

		private void DoAttackHit()
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: 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)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: 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_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)GameDirector.instance == (Object)null)
			{
				return;
			}
			Vector3 val = (((Object)(object)CenterTransform != (Object)null) ? CenterTransform.position : ((Component)this).transform.position);
			Vector3 forward = ((Component)this).transform.forward;
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				if (!IsTargetValid(player))
				{
					continue;
				}
				Vector3 val2 = ((Component)player).transform.position - val;
				float magnitude = ((Vector3)(ref val2)).magnitude;
				if (!(magnitude > 2.05f) && !(Vector3.Angle(forward, val2) > 54f))
				{
					PlayAttackHitAudio();
					Vector3 val3 = ((((Vector3)(ref val2)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val2)).normalized : forward);
					val3.y = 0f;
					if (((Vector3)(ref val3)).sqrMagnitude <= 0.001f)
					{
						val3 = forward;
					}
					player.playerHealth.HurtOther(20, ((Component)player).transform.position, true, SemiFunc.EnemyGetIndex(_enemy));
					if ((Object)(object)player.tumble != (Object)null)
					{
						player.tumble.TumbleRequest(true, false);
						player.tumble.TumbleForce(((Vector3)(ref val3)).normalized * 8.5f + Vector3.up * 3.25f);
						player.tumble.TumbleTorque(Vector3.up * Random.Range(-7f, 7f) + ((Component)this).transform.right * Random.Range(3.5f, 6f));
						player.tumble.OverrideLookAtCamera(0.45f, 6f, 4f);
						player.tumble.OverrideEnemyHurt(0.4f);
						player.tumble.ImpactHurtSet(0.35f, 0);
					}
				}
			}
		}

		private void TryTeleportAroundTarget()
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_targetPlayer == (Object)null || !IsTargetValid(_targetPlayer))
			{
				return;
			}
			Vector3 position = ((Component)_targetPlayer).transform.position;
			Vector3 val = default(Vector3);
			NavMeshHit val4 = default(NavMeshHit);
			for (int i = 0; i < 8; i++)
			{
				if (i == 0)
				{
					val = -((Component)_targetPlayer).transform.forward * Random.Range(5.2f, 7.6f);
				}
				else
				{
					Vector2 insideUnitCircle = Random.insideUnitCircle;
					Vector2 val2 = ((Vector2)(ref insideUnitCircle)).normalized * Random.Range(5.2f, 8.4f);
					((Vector3)(ref val))..ctor(val2.x, 0f, val2.y);
				}
				Vector3 val3 = position + val;
				if (NavMesh.SamplePosition(val3, ref val4, 8f, -1) && !(Vector3.Distance(((NavMeshHit)(ref val4)).position, position) < 4.5f))
				{
					Vector3 forward = ((Component)_targetPlayer).transform.forward;
					Vector3 val5 = ((Component)this).transform.position - position;
					bool backward = Vector3.Dot(forward, ((Vector3)(ref val5)).normalized) > 0f;
					PerformTeleport(((NavMeshHit)(ref val4)).position, backward);
					break;
				}
			}