Decompiled source of MasterHand v1.0.0

MH.dll

Decompiled 4 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Security.Cryptography;
using BepInEx;
using BepInEx.Logging;
using DM;
using HarmonyLib;
using Landfall.TABS;
using Landfall.TABS.AI;
using Landfall.TABS.AI.Components.Modifiers;
using Landfall.TABS.AI.Components.Tags;
using Landfall.TABS.Workshop;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 MasterHandMod
{
	[BepInPlugin("com.openai.masterhand", "Master Hand", "1.7.2")]
	public sealed class MasterHandPlugin : BaseUnityPlugin
	{
		private sealed class ScopeToken : IDisposable
		{
			private Action _dispose;

			internal ScopeToken(Action dispose)
			{
				_dispose = dispose;
			}

			public void Dispose()
			{
				Action dispose = _dispose;
				_dispose = null;
				dispose?.Invoke();
			}
		}

		[HarmonyPatch(typeof(CustomContentLoaderModIO), "DoneDownloading")]
		private static class CustomContentLoaderDoneDownloadingPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				if ((Object)(object)Instance != (Object)null)
				{
					Instance.TryRegisterFaction();
				}
			}
		}

		[HarmonyPatch(typeof(Unit), "Start")]
		private static class UnitStartSpawnPatch
		{
			[HarmonyPostfix]
			private static void Postfix(Unit __instance)
			{
				TrySpawnFromDummy(__instance);
			}

			[HarmonyFinalizer]
			private static Exception Finalizer(Unit __instance, Exception __exception)
			{
				if (__exception != null)
				{
					TrySpawnFromDummy(__instance);
				}
				return IsMasterHandTriggerUnit(__instance) ? null : __exception;
			}
		}

		[HarmonyPatch(typeof(UnitAPI), "Start")]
		private static class UnitApiDummyGuardPatch
		{
			[HarmonyPrefix]
			private static bool Prefix(UnitAPI __instance)
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return true;
				}
				Unit unit = null;
				try
				{
					unit = ((Component)__instance).GetComponent<Unit>();
				}
				catch
				{
				}
				return !IsMasterHandTriggerUnit(unit);
			}
		}

		[HarmonyPatch]
		private static class TabsLifecycleGate
		{
			private static readonly string[] NameTokens = new string[6] { "despawn", "destroy", "remove", "kill", "die", "death" };

			private static readonly HashSet<string> ExcludedTypeNames = new HashSet<string>(StringComparer.Ordinal) { "UnityEngine.Object", "UnityEngine.GameObject", "UnityEngine.Component" };

			private static IEnumerable<MethodBase> TargetMethods()
			{
				Assembly assembly = typeof(Unit).Assembly;
				foreach (Type type in SafeGetTypes(assembly))
				{
					if (type == null || type == typeof(Object))
					{
						continue;
					}
					MethodInfo[] methods;
					try
					{
						methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					}
					catch
					{
						continue;
					}
					MethodInfo[] array = methods;
					foreach (MethodInfo method in array)
					{
						if (method == null || method.IsAbstract || method.ContainsGenericParameters || method.IsStatic || method.DeclaringType == typeof(HealthHandler) || (method.DeclaringType != null && method.DeclaringType.Assembly != assembly))
						{
							continue;
						}
						string name = method.Name;
						if (NameTokens.Any((string t) => name.IndexOf(t, StringComparison.OrdinalIgnoreCase) >= 0))
						{
							string fullName = ((method.DeclaringType != null) ? method.DeclaringType.FullName : "");
							if (fullName.IndexOf("UnityEditor", StringComparison.OrdinalIgnoreCase) < 0)
							{
								yield return method;
							}
						}
					}
				}
			}

			private static IEnumerable<Type> SafeGetTypes(Assembly assembly)
			{
				try
				{
					return assembly.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					return ex.Types.Where((Type t) => t != null);
				}
				catch
				{
					return Enumerable.Empty<Type>();
				}
			}

			[HarmonyPrefix]
			private static bool Prefix(object __instance)
			{
				Object val = (Object)((__instance is Object) ? __instance : null);
				return val == (Object)null || !IsProtected(val);
			}
		}

		public const string PluginGuid = "com.openai.masterhand";

		public const string PluginName = "Master Hand";

		private const string FactionName = "MasterHand";

		public const string PluginVersion = "1.7.2";

		internal static MasterHandPlugin Instance;

		internal static Faction MasterHandFaction;

		internal static UnitBlueprint TriggerBlueprint;

		private Harmony _harmony;

		private float _integrityTimer;

		private Coroutine _factionRetryRoutine;

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

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

		private static int _privilegedScope;

		private static GameObject _masterHandInstance;

		private static bool _masterHandSpawnInProgress;

		private static int _cachedDecoyPositionFrame = -1;

		private static Vector3 _cachedDecoyPosition;

		private static int _cachedDecoyRotationFrame = -1;

		private static Quaternion _cachedDecoyRotation;

		private static readonly FieldInfo s_unitBlueprintEntityField = typeof(UnitBlueprint).GetField("m_entity", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly string[] DecoyNames = new string[3] { "skibidi toilette", "Spiderman", "tungtunhsahur" };

		private static int _decoyCounter;

		internal static bool IsPrivileged => _privilegedScope > 0;

		internal static ManualLogSource LogSource => ((Object)(object)Instance != (Object)null) ? ((BaseUnityPlugin)Instance).Logger : null;

		internal static IDisposable EnterPrivilegedScope()
		{
			_privilegedScope++;
			return new ScopeToken(delegate
			{
				_privilegedScope--;
			});
		}

		private void Awake()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			Instance = this;
			MasterHandShaderCache.EnsureFiles(((BaseUnityPlugin)this).Logger);
			MasterHandShaderCache.ExtractEmbeddedBundle(((BaseUnityPlugin)this).Logger);
			MasterHandShaderCache.TryLoadAssetBundles(((BaseUnityPlugin)this).Logger);
			SceneManager.sceneLoaded += OnFirstSceneLoaded;
			((MonoBehaviour)this).StartCoroutine(WaitForContentDatabaseThenRegister());
			try
			{
				_harmony = new Harmony("com.openai.masterhand");
				_harmony.PatchAll(typeof(MasterHandPlugin).Assembly);
				NativeMemoryGuard.Initialize();
				PatchIntegrity.Initialize(_harmony, typeof(MasterHandPlugin).Assembly);
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Master Hand hook initialization failed: " + ex));
			}
		}

		private void OnDestroy()
		{
			_masterHandInstance = null;
			_masterHandSpawnInProgress = false;
			SceneManager.sceneLoaded -= OnFirstSceneLoaded;
			if (_factionRetryRoutine != null)
			{
				try
				{
					((MonoBehaviour)this).StopCoroutine(_factionRetryRoutine);
				}
				catch
				{
				}
				_factionRetryRoutine = null;
			}
			try
			{
				Harmony harmony = _harmony;
				if (harmony != null)
				{
					harmony.UnpatchSelf();
				}
			}
			catch
			{
			}
			NativeMemoryGuard.Dispose();
		}

		private void OnFirstSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			TriggeredDummyIds.Clear();
			_masterHandSpawnInProgress = false;
			((MonoBehaviour)this).StartCoroutine(SceneFactionRetry());
		}

		private IEnumerator WaitForContentDatabaseThenRegister()
		{
			float elapsed = 0f;
			while (elapsed < 60f)
			{
				ContentDatabase db = null;
				try
				{
					db = ContentDatabase.Instance();
				}
				catch
				{
				}
				if (db != null && db.GetAllFactions() != null && db.GetAllFactions().Any())
				{
					TryRegisterFaction();
					break;
				}
				elapsed += Time.unscaledDeltaTime;
				yield return null;
			}
		}

		private IEnumerator SceneFactionRetry()
		{
			float[] delays = new float[5] { 0.1f, 0.5f, 1.5f, 3f, 6f };
			for (int i = 0; i < delays.Length; i++)
			{
				yield return (object)new WaitForSecondsRealtime(delays[i]);
				TryRegisterFaction();
				if (IsFactionActuallyRegistered())
				{
					break;
				}
			}
		}

		private void TryRegisterFaction()
		{
			try
			{
				RegisterFactionAndTrigger();
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogDebug((object)("Master Hand faction registration deferred: " + ex.Message));
			}
		}

		private static bool IsFactionActuallyRegistered()
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)MasterHandFaction == (Object)null || MasterHandFaction.Entity == null || (Object)(object)TriggerBlueprint == (Object)null || TriggerBlueprint.Entity == null)
				{
					return false;
				}
				ContentDatabase val = ContentDatabase.Instance();
				if (val == null)
				{
					return false;
				}
				return (Object)(object)val.GetFaction(MasterHandFaction.Entity.GUID) == (Object)(object)MasterHandFaction && (Object)(object)val.GetUnitBlueprint(TriggerBlueprint.Entity.GUID) == (Object)(object)TriggerBlueprint;
			}
			catch
			{
				return false;
			}
		}

		private void Update()
		{
			if (!((_integrityTimer += 1f) < 180f))
			{
				_integrityTimer = 0f;
				PatchIntegrity.Verify(_harmony, typeof(MasterHandPlugin).Assembly, ((BaseUnityPlugin)this).Logger);
				NativeMemoryGuard.Verify(((BaseUnityPlugin)this).Logger);
				if (!IsFactionActuallyRegistered())
				{
					TryRegisterFaction();
				}
			}
		}

		private static void InitUnitBlueprintEntity(UnitBlueprint blueprint, string entityName)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if ((Object)(object)blueprint == (Object)null || s_unitBlueprintEntityField == null)
			{
				throw new MissingFieldException("UnitBlueprint.m_entity");
			}
			DatabaseEntity val = new DatabaseEntity((WorkshopContentType)0);
			val.Name = entityName;
			s_unitBlueprintEntityField.SetValue(blueprint, val);
		}

		private static GameObject FindTemplateUnitBase(ContentDatabase db)
		{
			string[] array = new string[5] { "Farmer", "Peasant", "Peon", "Squire", "Warrior" };
			string[] array2 = array;
			foreach (string name in array2)
			{
				try
				{
					UnitBlueprint val = (from f in db.GetAllFactions()
						where (Object)(object)f != (Object)null && f.Units != null
						select f).SelectMany((Faction f) => f.Units).FirstOrDefault((Func<UnitBlueprint, bool>)((UnitBlueprint u) => (Object)(object)u != (Object)null && u.Entity != null && u.Entity.Name == name && (Object)(object)u.UnitBase != (Object)null));
					if ((Object)(object)val != (Object)null)
					{
						return val.UnitBase;
					}
				}
				catch
				{
				}
			}
			try
			{
				UnitBlueprint val2 = (from f in db.GetAllFactions()
					where (Object)(object)f != (Object)null && !f.IsSecret && f.Units != null
					select f).SelectMany((Faction f) => f.Units).FirstOrDefault((Func<UnitBlueprint, bool>)((UnitBlueprint u) => (Object)(object)u != (Object)null && (Object)(object)u.UnitBase != (Object)null && !u.HasMissingComponents));
				return ((Object)(object)val2 != (Object)null) ? val2.UnitBase : null;
			}
			catch
			{
				return null;
			}
		}

		private static GameObject CloneTemplateInactive(GameObject template)
		{
			if ((Object)(object)template == (Object)null)
			{
				return null;
			}
			bool activeSelf = template.activeSelf;
			try
			{
				if (activeSelf)
				{
					template.SetActive(false);
				}
				GameObject val = Object.Instantiate<GameObject>(template);
				((Object)val).name = "MasterHand_Dummy";
				val.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)val);
				return val;
			}
			finally
			{
				if (activeSelf)
				{
					try
					{
						template.SetActive(true);
					}
					catch
					{
					}
				}
			}
		}

		private static void RemoveTeamColorComponents(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			TeamColor[] componentsInChildren = root.GetComponentsInChildren<TeamColor>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
				}
			}
		}

		private static UnitBlueprint CreateTriggerBlueprint(GameObject templateUnitBase)
		{
			//IL_006b: 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_0086: 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)
			UnitBlueprint val = ScriptableObject.CreateInstance<UnitBlueprint>();
			((Object)val).name = "MasterHand_UnitTrigger";
			InitUnitBlueprintEntity(val, "MasterHand");
			GameObject val2 = CloneTemplateInactive(templateUnitBase);
			if ((Object)(object)val2 == (Object)null)
			{
				throw new InvalidOperationException("No se pudo clonar el UnitBase de la Dummy.");
			}
			RemoveTeamColorComponents(val2);
			val.UnitBase = val2;
			val.RightWeapon = null;
			val.LeftWeapon = null;
			val.excludeFromWinCondition = true;
			val.MovementComponents = new List<IMovementComponent> { (IMovementComponent)(object)default(KeepPreferredDistance) };
			val.TargetingComponent = (ITargetingComponent)(object)default(EnemyLeastWeightTargeting);
			val.turnSpeed = 18f;
			val.turnSpeedCurve = AnimationCurve.Linear(0f, 1f, 1f, 1f);
			Unit component = val2.GetComponent<Unit>();
			if ((Object)(object)component != (Object)null)
			{
				component.unitBlueprint = val;
			}
			return val;
		}

		private static Faction CreateMasterHandFaction(UnitBlueprint blueprint)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			Faction val = ScriptableObject.CreateInstance<Faction>();
			((Object)val).name = "MasterHand";
			val.Init();
			val.Entity.Name = "MasterHand";
			val.IsCustom = true;
			val.m_displayFaction = true;
			val.m_FactionCatagory = (FactionCatagory)1;
			val.Units = (UnitBlueprint[])(object)new UnitBlueprint[1] { blueprint };
			return val;
		}

		private static void RegisterFactionAndTrigger()
		{
			//IL_0060: 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)
			ContentDatabase val = ContentDatabase.Instance();
			if (val == null)
			{
				throw new InvalidOperationException("ContentDatabase is not ready.");
			}
			if ((Object)(object)MasterHandFaction != (Object)null && MasterHandFaction.Entity != null && (Object)(object)TriggerBlueprint != (Object)null && TriggerBlueprint.Entity != null)
			{
				UnitBlueprint unitBlueprint = val.GetUnitBlueprint(TriggerBlueprint.Entity.GUID);
				Faction faction = val.GetFaction(MasterHandFaction.Entity.GUID);
				if ((Object)(object)unitBlueprint != (Object)(object)TriggerBlueprint)
				{
					val.AddUserUnitBlueprint(TriggerBlueprint);
				}
				if ((Object)(object)faction != (Object)(object)MasterHandFaction)
				{
					val.AddUserFaction(MasterHandFaction);
				}
			}
			else
			{
				GameObject val2 = FindTemplateUnitBase(val);
				if ((Object)(object)val2 == (Object)null)
				{
					throw new InvalidOperationException("No se encontró un UnitBase válido para MasterHand.");
				}
				TriggerBlueprint = CreateTriggerBlueprint(val2);
				MasterHandFaction = CreateMasterHandFaction(TriggerBlueprint);
				val.AddUserUnitBlueprint(TriggerBlueprint);
				val.AddUserFaction(MasterHandFaction);
			}
		}

		private static int GetStableModId()
		{
			return 1296580942;
		}

		internal static bool IsProtected(Object obj)
		{
			if (obj == (Object)null)
			{
				return false;
			}
			GameObject val = (GameObject)(object)((obj is GameObject) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				Component val2 = (Component)(object)((obj is Component) ? obj : null);
				if ((Object)(object)val2 != (Object)null)
				{
					val = val2.gameObject;
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			return ProtectedRoots.Contains(((Object)val).GetInstanceID());
		}

		internal static void ProtectTree(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					ProtectedRoots.Add(((Object)((Component)val).gameObject).GetInstanceID());
				}
			}
		}

		internal static bool IsProtectedComponent(Component component)
		{
			return (Object)(object)component != (Object)null && IsProtected((Object)(object)component);
		}

		internal static string GetDecoyName()
		{
			_decoyCounter++;
			int num = _decoyCounter & 0x7FFFFFFF;
			return DecoyNames[num % DecoyNames.Length];
		}

		internal static string GetDecoyName(Object obj)
		{
			if (obj == (Object)null)
			{
				return DecoyNames[0];
			}
			int num = obj.GetInstanceID() & 0x7FFFFFFF;
			return DecoyNames[num % DecoyNames.Length];
		}

		internal static Vector3 GetDecoyPosition(Transform real)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			int frameCount = Time.frameCount;
			if (_cachedDecoyPositionFrame != frameCount)
			{
				_cachedDecoyPositionFrame = frameCount;
				float num = (float)frameCount * 0.031f;
				_cachedDecoyPosition = new Vector3(Mathf.Sin(num) * 999f, 777f + Mathf.Cos(num * 0.7f) * 50f, Mathf.Cos(num * 1.13f) * 999f);
			}
			return _cachedDecoyPosition;
		}

		internal static Quaternion GetDecoyRotation(Transform real)
		{
			//IL_0061: 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_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			int frameCount = Time.frameCount;
			if (_cachedDecoyRotationFrame != frameCount)
			{
				_cachedDecoyRotationFrame = frameCount;
				float num = (float)frameCount * 0.017f;
				_cachedDecoyRotation = Quaternion.Euler(Mathf.Sin(num) * 180f, Mathf.Cos(num * 0.73f) * 180f, Mathf.Sin(num * 1.21f) * 90f);
			}
			return _cachedDecoyRotation;
		}

		internal static string GetDecoyTypeName()
		{
			return GetDecoyName();
		}

		internal static object GetDecoyValue()
		{
			return Math.Abs(_decoyCounter++ % 3) switch
			{
				0 => "skibidi toilette", 
				1 => "Spiderman", 
				_ => "tungtunhsahur", 
			};
		}

		internal static bool IsMasterHandGameObject(GameObject go)
		{
			return (Object)(object)go != (Object)null && IsProtected((Object)(object)go);
		}

		internal static bool IsInternalMasterHandCreation()
		{
			return MasterHandController.CreationScope > 0;
		}

		internal static void SpawnMasterHand(Vector3 position, Quaternion rotation)
		{
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Expected O, but got Unknown
			//IL_0047: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			if (_masterHandSpawnInProgress || (Object)(object)_masterHandInstance != (Object)null)
			{
				return;
			}
			_masterHandSpawnInProgress = true;
			MasterHandController.CreationScope++;
			try
			{
				GameObject val = new GameObject("MasterHand");
				val.transform.SetPositionAndRotation(position + Vector3.up * 1.5f, rotation);
				MasterHandController masterHandController = val.AddComponent<MasterHandController>();
				masterHandController.Initialize();
				_masterHandInstance = val;
				ProtectTree(val);
				ManualLogSource logSource = LogSource;
				if (logSource != null)
				{
					logSource.LogInfo((object)"MasterHand real GameObject spawned independently from Dummy.");
				}
			}
			finally
			{
				MasterHandController.CreationScope--;
				_masterHandSpawnInProgress = false;
			}
		}

		private static void TrySpawnFromDummy(Unit __instance)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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)
			if (!IsMasterHandTriggerUnit(__instance))
			{
				return;
			}
			int num = (((Object)(object)((Component)__instance).gameObject != (Object)null) ? ((Object)((Component)__instance).gameObject).GetInstanceID() : 0);
			if (num != 0 && !TriggeredDummyIds.Add(num))
			{
				return;
			}
			try
			{
				Vector3 position = ((Component)__instance).transform.position;
				Quaternion rotation = ((Component)__instance).transform.rotation;
				SpawnMasterHand(position, rotation);
				NeutralizeMasterHandTriggerUnit(__instance);
				if ((Object)(object)Instance != (Object)null)
				{
					((MonoBehaviour)Instance).StartCoroutine(DestroyMasterHandTriggerAfterSpawn(((Component)__instance).gameObject));
				}
			}
			catch
			{
				if (num != 0)
				{
					TriggeredDummyIds.Remove(num);
				}
			}
		}

		private static void NeutralizeMasterHandTriggerUnit(Unit unit)
		{
			if ((Object)(object)unit == (Object)null)
			{
				return;
			}
			try
			{
				unit.ShowRenderers(false);
			}
			catch
			{
			}
			Collider[] componentsInChildren = ((Component)unit).GetComponentsInChildren<Collider>(true);
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				if ((Object)(object)componentsInChildren[i] != (Object)null)
				{
					componentsInChildren[i].enabled = false;
				}
			}
			MonoBehaviour[] componentsInChildren2 = ((Component)unit).GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren2)
			{
				if (!((Object)(object)val == (Object)null) && !(val is Unit))
				{
					try
					{
						((Behaviour)val).enabled = false;
					}
					catch
					{
					}
				}
			}
			try
			{
				UnitAPI component = ((Component)unit).GetComponent<UnitAPI>();
				if ((Object)(object)component != (Object)null)
				{
					component.SetIsDead();
					((Behaviour)component).enabled = false;
				}
			}
			catch
			{
			}
			((Behaviour)unit).enabled = false;
		}

		private static IEnumerator DestroyMasterHandTriggerAfterSpawn(GameObject dummy)
		{
			yield return null;
			yield return (object)new WaitForSecondsRealtime(0.1f);
			if ((Object)(object)dummy != (Object)null)
			{
				try
				{
					Object.Destroy((Object)(object)dummy);
				}
				catch
				{
				}
			}
		}

		private static bool IsMasterHandTriggerUnit(Unit unit)
		{
			//IL_007e: 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)
			if ((Object)(object)unit == (Object)null)
			{
				return false;
			}
			UnitBlueprint unitBlueprint = unit.unitBlueprint;
			if ((Object)(object)unitBlueprint == (Object)null)
			{
				return false;
			}
			if ((Object)(object)TriggerBlueprint != (Object)null && unitBlueprint == TriggerBlueprint)
			{
				return true;
			}
			try
			{
				if ((Object)(object)TriggerBlueprint != (Object)null && TriggerBlueprint.Entity != null && unitBlueprint.Entity != null && TriggerBlueprint.Entity.GUID == unitBlueprint.Entity.GUID)
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				if (unitBlueprint.Entity != null && string.Equals(unitBlueprint.Entity.Name, "MasterHand", StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			catch
			{
			}
			try
			{
				return ((Object)unit).name.IndexOf("MasterHand", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			catch
			{
				return false;
			}
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(HealthHandler), "Die", new Type[] { typeof(Unit) })]
		private static bool HealthDiePrefix(HealthHandler __instance, Unit damager)
		{
			return (Object)(object)__instance == (Object)null || !IsProtected((Object)(object)__instance) || IsPrivileged;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(HealthHandler), "Die", new Type[] { typeof(bool) })]
		private static bool HealthDieRemoteGuardPrefix(HealthHandler __instance)
		{
			return (Object)(object)__instance == (Object)null || !IsProtected((Object)(object)__instance) || IsPrivileged;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(HealthHandler), "Die", new Type[] { typeof(bool) })]
		private static bool HealthDieRemotePrefix(HealthHandler __instance)
		{
			return (Object)(object)__instance == (Object)null || !IsProtected((Object)(object)__instance);
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "get_name")]
		private static bool GameObjectNamePrefix(GameObject __instance, ref string __result)
		{
			if (!IsProtected((Object)(object)__instance))
			{
				return true;
			}
			__result = GetDecoyName((Object)(object)__instance);
			return false;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Object), "get_name")]
		private static bool ObjectNamePrefix(Object __instance, ref string __result)
		{
			if (!IsProtected(__instance))
			{
				return true;
			}
			__result = GetDecoyName(__instance);
			return false;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Component), "get_tag")]
		private static bool ComponentTagPrefix(Component __instance, ref string __result)
		{
			if (!IsProtected((Object)(object)__instance))
			{
				return true;
			}
			__result = "Spiderman";
			return false;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Transform), "get_position")]
		private static bool TransformPositionPrefix(Transform __instance, ref Vector3 __result)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (!IsProtected((Object)(object)__instance))
			{
				return true;
			}
			__result = GetDecoyPosition(__instance);
			return false;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Transform), "get_rotation")]
		private static bool TransformRotationPrefix(Transform __instance, ref Quaternion __result)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (!IsProtected((Object)(object)__instance))
			{
				return true;
			}
			__result = GetDecoyRotation(__instance);
			return false;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "CompareTag")]
		private static bool CompareTagPrefix(GameObject __instance, string tag, ref bool __result)
		{
			if (!IsProtected((Object)(object)__instance))
			{
				return true;
			}
			__result = false;
			return false;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Component), "BroadcastMessage")]
		private static bool DecoyBroadcastPrefix(Component __instance, string methodName, SendMessageOptions options)
		{
			return true;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "AddComponent", new Type[] { typeof(Type) })]
		private static bool AddComponentTypePrefix(GameObject __instance, Type componentType)
		{
			if (IsInternalMasterHandCreation() || IsPrivileged)
			{
				return true;
			}
			return !IsProtected((Object)(object)__instance);
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "AddComponent", new Type[] { typeof(string) })]
		private static bool AddComponentStringPrefix(GameObject __instance, string componentType)
		{
			if (IsInternalMasterHandCreation() || IsPrivileged)
			{
				return true;
			}
			return !IsProtected((Object)(object)__instance);
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Component), "GetComponent")]
		private static bool GetComponentPrefix(Component __instance, Type type)
		{
			return true;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "GetComponents", new Type[] { typeof(Type) })]
		private static bool GameObjectGetComponentsPrefix(GameObject __instance, Type type)
		{
			return !IsProtected((Object)(object)__instance) || IsPrivileged;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "GetComponentInChildren", new Type[]
		{
			typeof(Type),
			typeof(bool)
		})]
		private static bool GameObjectGetComponentInChildrenPrefix(GameObject __instance, Type type, bool includeInactive)
		{
			return !IsProtected((Object)(object)__instance) || IsPrivileged;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "GetComponentInParent", new Type[]
		{
			typeof(Type),
			typeof(bool)
		})]
		private static bool GameObjectGetComponentInParentPrefix(GameObject __instance, Type type, bool includeInactive)
		{
			return !IsProtected((Object)(object)__instance) || IsPrivileged;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool BehaviourEnabledPrefix(Behaviour __instance, bool value)
		{
			return !IsProtected((Object)(object)__instance) || value;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool RendererEnabledPrefix(Renderer __instance, bool value)
		{
			return !IsProtected((Object)(object)__instance) || value;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool ColliderEnabledPrefix(Collider __instance, bool value)
		{
			return !IsProtected((Object)(object)__instance) || value;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Transform), "SetParent", new Type[] { typeof(Transform) })]
		private static bool TransformSetParentPrefix(Transform __instance, Transform parent)
		{
			bool flag = IsProtected((Object)(object)__instance);
			if (!flag && (Object)(object)__instance != (Object)null && (Object)(object)parent != (Object)null && IsProtected((Object)(object)parent))
			{
				ProtectedRoots.Add(((Object)((Component)__instance).gameObject).GetInstanceID());
			}
			return IsPrivileged || !flag;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(typeof(Transform), "SetParent", new Type[]
		{
			typeof(Transform),
			typeof(bool)
		})]
		private static bool TransformSetParentWorldPrefix(Transform __instance, Transform parent, bool worldPositionStays)
		{
			bool flag = IsProtected((Object)(object)__instance);
			if (!flag && (Object)(object)__instance != (Object)null && (Object)(object)parent != (Object)null && IsProtected((Object)(object)parent))
			{
				ProtectedRoots.Add(((Object)((Component)__instance).gameObject).GetInstanceID());
			}
			return IsPrivileged || !flag;
		}

		[HarmonyPriority(int.MaxValue)]
		[HarmonyPrefix]
		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static bool TransformParentSetterPrefix(Transform __instance, Transform value)
		{
			bool flag = IsProtected((Object)(object)__instance);
			if (!flag && (Object)(object)__instance != (Object)null && (Object)(object)value != (Object)null && IsProtected((Object)(object)value))
			{
				ProtectedRoots.Add(((Object)((Component)__instance).gameObject).GetInstanceID());
			}
			return IsPrivileged || !flag;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Object), "Destroy", new Type[] { typeof(Object) })]
		private static bool DestroyPrefix(Object obj)
		{
			return IsPrivileged || !IsProtected(obj);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Object), "Destroy", new Type[]
		{
			typeof(Object),
			typeof(float)
		})]
		private static bool DestroyTimedPrefix(Object obj, float t)
		{
			return IsPrivileged || !IsProtected(obj);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Object), "DestroyImmediate", new Type[] { typeof(Object) })]
		private static bool DestroyImmediatePrefix(Object obj)
		{
			return IsPrivileged || !IsProtected(obj);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(Object), "DestroyImmediate", new Type[]
		{
			typeof(Object),
			typeof(bool)
		})]
		private static bool DestroyImmediateAllowAssetsPrefix(Object obj, bool allowDestroyingAssets)
		{
			return IsPrivileged || !IsProtected(obj);
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(GameObject), "SetActive")]
		private static bool SetActivePrefix(GameObject __instance, bool value)
		{
			return IsPrivileged || !IsProtected((Object)(object)__instance) || value;
		}
	}
	internal static class PatchIntegrity
	{
		private static Harmony _harmony;

		private static Assembly _assembly;

		private static readonly HashSet<string> Required = new HashSet<string>(StringComparer.Ordinal) { "UnitStartPostfix", "HealthDiePrefix", "ObjectNamePrefix", "TransformPositionPrefix", "TransformRotationPrefix", "DestroyPrefix", "SetActivePrefix" };

		internal static void Initialize(Harmony harmony, Assembly assembly)
		{
			_harmony = harmony;
			_assembly = assembly;
		}

		internal static void Verify(Harmony harmony, Assembly assembly, ManualLogSource logger)
		{
			if (harmony == null || assembly == null)
			{
				return;
			}
			try
			{
				HashSet<string> hashSet = new HashSet<string>(from m in assembly.GetTypes().SelectMany((Type t) => t.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic))
					where m.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0
					select m.Name, StringComparer.Ordinal);
				MethodBase[] array = Harmony.GetAllPatchedMethods().ToArray();
				MethodBase[] array2 = array;
				foreach (MethodBase methodBase in array2)
				{
					Patches patchInfo = Harmony.GetPatchInfo(methodBase);
					if (patchInfo == null)
					{
						continue;
					}
					foreach (Patch item in patchInfo.Prefixes.Concat(patchInfo.Postfixes).Concat(patchInfo.Transpilers).Concat(patchInfo.Finalizers)
						.Concat(patchInfo.ILManipulators))
					{
						if (item != null && !(item.PatchMethod == null) && !(item.owner == harmony.Id) && item.priority > 0 && item.PatchMethod.DeclaringType != null && item.PatchMethod.DeclaringType.Assembly == assembly)
						{
							logger.LogDebug((object)("Unexpected priority state: " + GeneralExtensions.FullDescription(methodBase) + " <- " + GeneralExtensions.FullDescription((MethodBase)item.PatchMethod)));
						}
					}
				}
			}
			catch (Exception ex)
			{
				logger.LogDebug((object)("Patch integrity audit failed: " + ex.Message));
			}
		}
	}
	internal static class NativeMemoryGuard
	{
		private struct MEMORY_BASIC_INFORMATION
		{
			public IntPtr BaseAddress;

			public IntPtr AllocationBase;

			public uint AllocationProtect;

			public UIntPtr RegionSize;

			public uint State;

			public uint Protect;

			public uint Type;
		}

		private const uint MEM_COMMIT = 4096u;

		private const uint PAGE_EXECUTE = 16u;

		private const uint PAGE_EXECUTE_READ = 32u;

		private const uint PAGE_EXECUTE_READWRITE = 64u;

		private const uint PAGE_READONLY = 2u;

		private const uint PAGE_READWRITE = 4u;

		private static readonly List<MethodInfo> CriticalMethods = new List<MethodInfo>();

		private static readonly Dictionary<RuntimeMethodHandle, string> Fingerprints = new Dictionary<RuntimeMethodHandle, string>();

		internal static void Initialize()
		{
			CriticalMethods.Clear();
			CriticalMethods.Add(typeof(MasterHandPlugin).GetMethod("DestroyPrefix", BindingFlags.Static | BindingFlags.NonPublic));
			CriticalMethods.Add(typeof(MasterHandPlugin).GetMethod("SetActivePrefix", BindingFlags.Static | BindingFlags.NonPublic));
			CriticalMethods.Add(typeof(MasterHandPlugin).GetMethod("HealthDiePrefix", BindingFlags.Static | BindingFlags.NonPublic));
			foreach (MethodInfo item in CriticalMethods.Where((MethodInfo m) => m != null))
			{
				try
				{
					RuntimeHelpers.PrepareMethod(item.MethodHandle);
					IntPtr functionPointer = item.MethodHandle.GetFunctionPointer();
					if (IsReadableExecutable(functionPointer))
					{
						Fingerprints[item.MethodHandle] = HashBytes(functionPointer, 32);
					}
				}
				catch
				{
				}
			}
		}

		internal static void Verify(ManualLogSource logger)
		{
			foreach (MethodInfo item in CriticalMethods.Where((MethodInfo m) => m != null))
			{
				try
				{
					RuntimeHelpers.PrepareMethod(item.MethodHandle);
					IntPtr functionPointer = item.MethodHandle.GetFunctionPointer();
					if (!IsReadableExecutable(functionPointer))
					{
						logger.LogDebug((object)("Native code page validation failed for " + GeneralExtensions.FullDescription((MethodBase)item)));
						continue;
					}
					string b = HashBytes(functionPointer, 32);
					if (Fingerprints.TryGetValue(item.MethodHandle, out var value) && !string.Equals(value, b, StringComparison.Ordinal))
					{
						logger.LogDebug((object)("Native integrity delta detected for " + GeneralExtensions.FullDescription((MethodBase)item)));
					}
				}
				catch
				{
				}
			}
		}

		internal static void Dispose()
		{
			CriticalMethods.Clear();
			Fingerprints.Clear();
		}

		private static string HashBytes(IntPtr ptr, int length)
		{
			byte[] array = new byte[length];
			Marshal.Copy(ptr, array, 0, array.Length);
			using SHA256 sHA = SHA256.Create();
			return BitConverter.ToString(sHA.ComputeHash(array));
		}

		private static bool IsReadableExecutable(IntPtr address)
		{
			if (VirtualQuery(address, out var lpBuffer, (UIntPtr)(ulong)Marshal.SizeOf(typeof(MEMORY_BASIC_INFORMATION))) == UIntPtr.Zero)
			{
				return false;
			}
			if (lpBuffer.State != 4096)
			{
				return false;
			}
			return (lpBuffer.Protect & 0x70) != 0 && (lpBuffer.Protect & 0x66) != 0;
		}

		[DllImport("kernel32.dll", SetLastError = true)]
		private static extern UIntPtr VirtualQuery(IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, UIntPtr dwLength);
	}
	internal sealed class MasterHandController : MonoBehaviour
	{
		internal static int CreationScope;

		private readonly List<Transform> allBones = new List<Transform>();

		private readonly List<Transform> indexBones = new List<Transform>();

		private readonly List<Transform> thumbBones = new List<Transform>();

		private readonly List<Transform> middleBones = new List<Transform>();

		private readonly List<Transform> ringBones = new List<Transform>();

		private readonly List<Transform> pinkyBones = new List<Transform>();

		private readonly List<Renderer> renderers = new List<Renderer>();

		private Transform indexTip;

		private Animator handAnimator;

		private Renderer blackHoleCoreRenderer;

		private readonly Collider[] overlapBuffer = (Collider[])(object)new Collider[128];

		private readonly RaycastHit[] raycastBuffer = (RaycastHit[])(object)new RaycastHit[24];

		private float nextShot;

		private float nextTargetScan;

		private float nextBlackHoleScan;

		private Transform target;

		private Rigidbody targetBody;

		private Material beamMaterial;

		private Material blackHoleMaterial;

		private Material blackCoreMaterial;

		private GameObject blackHole;

		private LineRenderer blackHoleRing;

		private ParticleSystem blackHoleParticles;

		private BlackHoleLensingEffect lensingEffect;

		private float nextLensingCameraScan;

		private readonly Dictionary<int, LightLensingState> lensedLights = new Dictionary<int, LightLensingState>();

		private Vector3 flightVelocity;

		private Vector3 recoilVelocity;

		private Vector3 recoilAngular;

		private bool specialCharging;

		private float specialTimer;

		private int shotsSinceSpecial;

		private float specialCooldown;

		private bool meleeActive;

		private bool meleeCharging;

		private float meleeTimer;

		private float nextMelee;

		private Vector3 blackHoleTargetPoint;

		private bool blackHoleHasTarget;

		private Vector3 smoothedAim = Vector3.forward;

		private int nearbyUnitCount;

		private readonly Dictionary<int, Quaternion> baseRotationById = new Dictionary<int, Quaternion>();

		private readonly HashSet<int> absorbedIds = new HashSet<int>();

		private int activeAttackCount;

		private int lastAttackKind = -1;

		private float attackLockUntil;

		private CameraShakeEffect cameraShake;

		private bool fractalSequenceRunning;

		private float attackWatchdogDeadline;

		private bool attackReleaseGuard;

		private const float TargetScanInterval = 0.18f;

		private const float PreferredDistance = 11f;

		private const float MinDistance = 7f;

		private const float MaxDistance = 17f;

		private const float BaseAltitude = 5.5f;

		private const float SpecialChance = 0.15f;

		private const float MeleeChance = 0.22f;

		private const float SpecialChargeTime = 1.25f;

		private const float MeleeChargeTime = 0.42f;

		private const float MeleeRange = 8.5f;

		private const float MeleeImpactRadius = 1.35f;

		private const float MeleeTriggerRange = 13.5f;

		private const float MeleeCooldown = 1.35f;

		private const float FractalChance = 0.3f;

		private const float SpecialDuration = 5.5f;

		private const float BlackHoleWorldRadius = 1.15f;

		private const float LensStrength = 0.0225f;

		private const int MaxConcurrentAttacks = 1;

		private const float FractalFlightLock = 2.15f;

		private const float MeleeChanceNear = 0.38f;

		private const float GunPoseBlend = 30f;

		public void Initialize()
		{
			//IL_0018: 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)
			((Object)((Component)this).gameObject).name = "MasterHand";
			((Component)this).transform.localScale = Vector3.one * 2.2f;
			MasterHandPlugin.ProtectTree(((Component)this).gameObject);
			try
			{
				BuildDebugHandVisual();
			}
			catch
			{
				BuildPrimitiveFallbackVisual();
			}
			BuildNeonBeamMaterial();
			BuildBlackHoleMaterial();
			ApplyMasterHandVhsShader();
			Camera main = Camera.main;
			if ((Object)(object)main != (Object)null)
			{
				cameraShake = ((Component)main).gameObject.GetComponent<CameraShakeEffect>();
				if ((Object)(object)cameraShake == (Object)null)
				{
					cameraShake = ((Component)main).gameObject.AddComponent<CameraShakeEffect>();
				}
			}
			nextTargetScan = 0f;
			nextShot = Time.time + 0.6f;
		}

		private void BuildPrimitiveFallbackVisual()
		{
			//IL_003c: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val).name = "MasterHand_PalmFallback";
			val.transform.SetParent(((Component)this).transform, false);
			val.transform.localScale = new Vector3(1.8f, 0.7f, 2.2f);
			Renderer component = val.GetComponent<Renderer>();
			if ((Object)(object)component != (Object)null)
			{
				renderers.Add(component);
			}
			for (int i = 0; i < 5; i++)
			{
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)1);
				((Object)val2).name = "Finger_" + i;
				val2.transform.SetParent(((Component)this).transform, false);
				val2.transform.localPosition = new Vector3((float)(i - 2) * 0.32f, 0f, 1f);
				val2.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
				val2.transform.localScale = new Vector3(0.22f, 0.55f, 0.22f);
				allBones.Add(val2.transform);
				baseRotationById[((Object)val2.transform).GetInstanceID()] = val2.transform.localRotation;
				switch (i)
				{
				case 0:
					thumbBones.Add(val2.transform);
					break;
				case 1:
					indexBones.Add(val2.transform);
					break;
				case 2:
					middleBones.Add(val2.transform);
					break;
				case 3:
					ringBones.Add(val2.transform);
					break;
				default:
					pinkyBones.Add(val2.transform);
					break;
				}
				Renderer component2 = val2.GetComponent<Renderer>();
				if ((Object)(object)component2 != (Object)null)
				{
					renderers.Add(component2);
				}
			}
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = true;
				}
			}
		}

		private void BuildDebugHandVisual()
		{
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			Animator[] source = Resources.FindObjectsOfTypeAll<Animator>();
			Animator val = ((IEnumerable<Animator>)(from a in source
				where (Object)(object)a != (Object)null && (Object)(object)a.runtimeAnimatorController != (Object)null
				orderby ScoreHandAnimator(a) descending
				select a)).FirstOrDefault((Func<Animator, bool>)((Animator a) => a.runtimeAnimatorController.animationClips.Any((AnimationClip c) => (Object)(object)c != (Object)null && (((Object)c).name.IndexOf("GrabbyHand", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)c).name.IndexOf("MasterHand", StringComparison.OrdinalIgnoreCase) >= 0 || ((Object)c).name.IndexOf("Hand", StringComparison.OrdinalIgnoreCase) >= 0))));
			if ((Object)(object)val != (Object)null)
			{
				GameObject gameObject = ((Component)val).gameObject;
				if ((Object)(object)gameObject.GetComponentInParent<Unit>() != (Object)null || (Object)(object)gameObject.GetComponentInChildren<Unit>(true) != (Object)null || ((Object)gameObject).name.IndexOf("unit", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					val = null;
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)this).transform);
				((Object)val2).name = "MasterHand_AnimatedModel";
				val2.transform.localPosition = Vector3.zero;
				val2.transform.localRotation = Quaternion.identity;
				val2.transform.localScale = Vector3.one;
				SetLayerRecursively(val2, ((Component)this).gameObject.layer);
				StripUnitGameplayComponents(val2);
				Animator val3 = (handAnimator = val2.GetComponentInChildren<Animator>());
				if ((Object)(object)val3 != (Object)null)
				{
					((Behaviour)val3).enabled = true;
					val3.cullingMode = (AnimatorCullingMode)0;
					val3.speed = 1f;
					val3.Rebind();
					val3.Update(0f);
				}
				Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
				foreach (Transform val4 in componentsInChildren)
				{
					if (!((Object)(object)val4 == (Object)null) && !((Object)(object)val4 == (Object)(object)val2.transform))
					{
						allBones.Add(val4);
						baseRotationById[((Object)val4).GetInstanceID()] = val4.localRotation;
						ClassifyFingerBone(val4);
					}
				}
				BuildFingerFallbackGroups();
				Renderer[] componentsInChildren2 = val2.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val5 in componentsInChildren2)
				{
					if ((Object)(object)val5 != (Object)null)
					{
						renderers.Add(val5);
					}
				}
			}
			else
			{
				GameObject val6 = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)val6).name = "MasterHand_PalmFallback";
				val6.transform.SetParent(((Component)this).transform, false);
				val6.transform.localScale = new Vector3(1.8f, 0.7f, 2.2f);
				renderers.Add(val6.GetComponent<Renderer>());
				for (int num3 = 0; num3 < 5; num3++)
				{
					GameObject val7 = GameObject.CreatePrimitive((PrimitiveType)1);
					((Object)val7).name = "Finger_" + num3;
					val7.transform.SetParent(((Component)this).transform, false);
					val7.transform.localPosition = new Vector3((float)(num3 - 2) * 0.32f, 0f, 1f);
					val7.transform.localRotation = Quaternion.Euler(90f, 0f, 0f);
					val7.transform.localScale = new Vector3(0.22f, 0.55f, 0.22f);
					allBones.Add(val7.transform);
					baseRotationById[((Object)val7.transform).GetInstanceID()] = val7.transform.localRotation;
					switch (num3)
					{
					case 0:
						thumbBones.Add(val7.transform);
						break;
					case 1:
						indexBones.Add(val7.transform);
						break;
					case 2:
						middleBones.Add(val7.transform);
						break;
					case 3:
						ringBones.Add(val7.transform);
						break;
					default:
						pinkyBones.Add(val7.transform);
						break;
					}
					renderers.Add(val7.GetComponent<Renderer>());
				}
			}
			foreach (Renderer renderer in renderers)
			{
				if ((Object)(object)renderer != (Object)null)
				{
					renderer.enabled = true;
				}
			}
			MasterHandPlugin.ProtectTree(((Component)this).gameObject);
		}

		private static int ScoreHandAnimator(Animator a)
		{
			if ((Object)(object)a == (Object)null)
			{
				return int.MinValue;
			}
			int num = 0;
			string text = (((Object)(object)((Component)a).gameObject != (Object)null) ? ((Object)((Component)a).gameObject).name : string.Empty);
			if (ContainsAny(text, "MasterHand", "GrabbyHand"))
			{
				num += 100;
			}
			RuntimeAnimatorController runtimeAnimatorController = a.runtimeAnimatorController;
			if ((Object)(object)runtimeAnimatorController != (Object)null)
			{
				if (ContainsAny(((Object)runtimeAnimatorController).name, "MasterHand", "GrabbyHand"))
				{
					num += 80;
				}
				AnimationClip[] animationClips = runtimeAnimatorController.animationClips;
				for (int i = 0; i < animationClips.Length; i++)
				{
					if ((Object)(object)animationClips[i] != (Object)null && ContainsAny(((Object)animationClips[i]).name, "MasterHand", "GrabbyHand"))
					{
						num += 15;
					}
				}
			}
			return num;
		}

		private static void SetLayerRecursively(GameObject root, int layer)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren = root.GetComponentsInChildren<Transform>(true);
			foreach (Transform val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null)
				{
					((Component)val).gameObject.layer = layer;
				}
			}
		}

		private static void StripUnitGameplayComponents(GameObject root)
		{
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			MonoBehaviour[] componentsInChildren = root.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string text = ((object)val).GetType().FullName ?? string.Empty;
					if (val is Unit || text.IndexOf("UnitAPI", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("HealthHandler", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("GroundChecker", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("UnitSounds", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("MovementBehaviour", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("Movement", StringComparison.OrdinalIgnoreCase) >= 0)
					{
						Object.DestroyImmediate((Object)(object)val);
					}
				}
			}
			Collider[] componentsInChildren2 = root.GetComponentsInChildren<Collider>(true);
			foreach (Collider val2 in componentsInChildren2)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			Rigidbody[] componentsInChildren3 = root.GetComponentsInChildren<Rigidbody>(true);
			foreach (Rigidbody val3 in componentsInChildren3)
			{
				if ((Object)(object)val3 != (Object)null)
				{
					Object.DestroyImmediate((Object)(object)val3);
				}
			}
		}

		private void ClassifyFingerBone(Transform tr)
		{
			if (!((Object)(object)tr == (Object)null))
			{
				string name = ((Object)tr).name;
				if (ContainsAny(name, "index", "point", "fore", "pointer", "digit2"))
				{
					indexBones.Add(tr);
				}
				else if (ContainsAny(name, "thumb", "pollex", "digit1"))
				{
					thumbBones.Add(tr);
				}
				else if (ContainsAny(name, "middle", "mid", "digit3"))
				{
					middleBones.Add(tr);
				}
				else if (ContainsAny(name, "ring", "digit4"))
				{
					ringBones.Add(tr);
				}
				else if (ContainsAny(name, "pinky", "little", "digit5"))
				{
					pinkyBones.Add(tr);
				}
			}
		}

		private void BuildFingerFallbackGroups()
		{
			List<Transform>[] array = new List<Transform>[5] { thumbBones, indexBones, middleBones, ringBones, pinkyBones };
			if (array.All((List<Transform> g) => g.Count > 0))
			{
				return;
			}
			List<Transform> list = new List<Transform>();
			for (int num = 0; num < allBones.Count; num++)
			{
				Transform val = allBones[num];
				if ((Object)(object)val == (Object)null || (Object)(object)val == (Object)(object)((Component)this).transform)
				{
					continue;
				}
				bool flag = false;
				for (int num2 = 0; num2 < allBones.Count; num2++)
				{
					Transform val2 = allBones[num2];
					if ((Object)(object)val2 != (Object)null && (Object)(object)val2.parent == (Object)(object)val)
					{
						flag = true;
						break;
					}
				}
				if (!flag && !ContainsAny(((Object)val).name, "palm", "wrist", "forearm", "root", "arm"))
				{
					list.Add(val);
				}
			}
			list.Sort((Transform a, Transform b) => a.position.x.CompareTo(b.position.x));
			if (list.Count < 5)
			{
				return;
			}
			List<Transform> list2 = new List<Transform>(5);
			int[] array2 = new int[5] { 0, 1, 2, 3, 4 };
			for (int num3 = 0; num3 < array2.Length; num3++)
			{
				int index = Mathf.Clamp(Mathf.RoundToInt((float)(list.Count - 1) * ((float)num3 / 4f)), 0, list.Count - 1);
				Transform item = list[index];
				if (!list2.Contains(item))
				{
					list2.Add(item);
				}
			}
			while (list2.Count < 5)
			{
				Transform item2 = list[list2.Count % list.Count];
				if (!list2.Contains(item2))
				{
					list2.Add(item2);
					continue;
				}
				break;
			}
			for (int num4 = 0; num4 < 5; num4++)
			{
				if (array[num4].Count <= 0)
				{
					Transform val3 = list2[Mathf.Clamp(num4, 0, list2.Count - 1)];
					int num5 = 0;
					while ((Object)(object)val3 != (Object)null && (Object)(object)val3 != (Object)(object)((Component)this).transform && num5++ < 10)
					{
						array[num4].Add(val3);
						val3 = val3.parent;
					}
				}
			}
		}

		private static bool ContainsAny(string text, params string[] tokens)
		{
			if (string.IsNullOrEmpty(text))
			{
				return false;
			}
			for (int i = 0; i < tokens.Length; i++)
			{
				if (text.IndexOf(tokens[i], StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private void BuildNeonBeamMaterial()
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Expected O, but got Unknown
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			Shader val = MasterHandShaderCache.GetShader("MasterHand/RayMonochromeVHS") ?? Shader.Find("Particles/Additive") ?? Shader.Find("Unlit/Color");
			if ((Object)(object)val != (Object)null)
			{
				beamMaterial = new Material(val);
				((Object)beamMaterial).name = "MasterHand_MonochromeVHS_Ray";
				if (beamMaterial.HasProperty("_Color"))
				{
					beamMaterial.color = Color.white;
				}
				if (beamMaterial.HasProperty("_Noise"))
				{
					beamMaterial.SetFloat("_Noise", 0.38f);
				}
				if (beamMaterial.HasProperty("_Scanlines"))
				{
					beamMaterial.SetFloat("_Scanlines", 0.92f);
				}
			}
		}

		private void ApplyMasterHandVhsShader()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			Shader shader = MasterHandShaderCache.GetShader("MasterHand/VHSMonochrome");
			if ((Object)(object)shader == (Object)null)
			{
				return;
			}
			for (int i = 0; i < renderers.Count; i++)
			{
				Renderer val = renderers[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					Material val2 = null;
					try
					{
						val2 = val.material;
					}
					catch
					{
					}
					Material val3 = new Material(shader);
					((Object)val3).name = "MasterHand_VHSMonochrome";
					if ((Object)(object)val2 != (Object)null && val3.HasProperty("_MainTex") && val2.HasProperty("_MainTex"))
					{
						val3.SetTexture("_MainTex", val2.GetTexture("_MainTex"));
					}
					if ((Object)(object)val2 != (Object)null && val3.HasProperty("_Color") && val2.HasProperty("_Color"))
					{
						val3.SetColor("_Color", val2.GetColor("_Color"));
					}
					if (val3.HasProperty("_Noise"))
					{
						val3.SetFloat("_Noise", 0.2f);
					}
					if (val3.HasProperty("_Warp"))
					{
						val3.SetFloat("_Warp", 0.11f);
					}
					if (val3.HasProperty("_Scanlines"))
					{
						val3.SetFloat("_Scanlines", 0.68f);
					}
					if (val3.HasProperty("_MainTex_ST") && (Object)(object)val2 != (Object)null && val2.HasProperty("_MainTex_ST"))
					{
						val3.SetVector("_MainTex_ST", val2.GetVector("_MainTex_ST"));
					}
					if (val is SkinnedMeshRenderer || val is MeshRenderer)
					{
						val.material = val3;
					}
				}
				catch
				{
				}
			}
		}

		private void BuildBlackHoleMaterial()
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			Shader val = Shader.Find("Standard") ?? Shader.Find("Particles/Standard Unlit") ?? Shader.Find("Particles/Alpha Blended") ?? Shader.Find("Unlit/Transparent");
			if ((Object)(object)val != (Object)null)
			{
				blackHoleMaterial = new Material(val);
				((Object)blackHoleMaterial).name = "MasterHand_BlackHole_Accretion";
				if (blackHoleMaterial.HasProperty("_Color"))
				{
					blackHoleMaterial.color = new Color(0.015f, 0.012f, 0.02f, 1f);
				}
				if (blackHoleMaterial.HasProperty("_Glossiness"))
				{
					blackHoleMaterial.SetFloat("_Glossiness", 0.92f);
				}
				if (blackHoleMaterial.HasProperty("_Metallic"))
				{
					blackHoleMaterial.SetFloat("_Metallic", 0.82f);
				}
			}
			Shader val2 = Shader.Find("Unlit/Color") ?? Shader.Find("UI/Default");
			if ((Object)(object)val2 != (Object)null)
			{
				blackCoreMaterial = new Material(val2);
				((Object)blackCoreMaterial).name = "MasterHand_BlackHole_Core";
				if (blackCoreMaterial.HasProperty("_Color"))
				{
					blackCoreMaterial.color = Color.black;
				}
			}
		}

		private void Update()
		{
			using (MasterHandPlugin.EnterPrivilegedScope())
			{
				if ((Object)(object)target == (Object)null || Time.unscaledTime >= nextTargetScan)
				{
					nextTargetScan = Time.unscaledTime + 0.18f;
					AcquireTarget();
				}
				UpdateRecoilAndPose();
				RecoverAttackState();
				UpdateFlightPathfinder();
				RecoverFromGroundClip();
				if (specialCharging)
				{
					specialTimer += Time.deltaTime;
					if (specialTimer >= 1.25f)
					{
						specialCharging = false;
						LaunchBlackHole();
					}
				}
				else if (meleeCharging)
				{
					meleeTimer += Time.deltaTime;
					if (meleeTimer >= 0.42f)
					{
						meleeCharging = false;
						DoMeleeStrike();
					}
				}
				else
				{
					Combat();
				}
				if (activeAttackCount <= 0 && !specialCharging && !meleeCharging && !meleeActive && !fractalSequenceRunning)
				{
					UpdateBlackHole();
				}
			}
		}

		private void LateUpdate()
		{
			if ((Object)(object)this == (Object)null || !((Behaviour)this).isActiveAndEnabled)
			{
				return;
			}
			using (MasterHandPlugin.EnterPrivilegedScope())
			{
				if ((Object)(object)handAnimator != (Object)null)
				{
					if (!((Behaviour)handAnimator).enabled)
					{
						((Behaviour)handAnimator).enabled = true;
					}
					handAnimator.speed = 1f;
					handAnimator.cullingMode = (AnimatorCullingMode)0;
				}
			}
		}

		private void ForceBoneDelta(Transform b, Quaternion delta, float weight)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0023: 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)
			if (!((Object)(object)b == (Object)null))
			{
				Quaternion val = FindBaseRotation(b) * delta;
				b.localRotation = Quaternion.Slerp(b.localRotation, val, Mathf.Clamp01(weight));
			}
		}

		private void AcquireTarget()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: 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_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			Unit[] array = Object.FindObjectsOfType<Unit>();
			float num = float.PositiveInfinity;
			Transform val = null;
			Rigidbody val2 = null;
			Vector3 position = ((Component)this).transform.position;
			Vector3 val5;
			foreach (Unit val3 in array)
			{
				if ((Object)(object)val3 == (Object)null || (Object)(object)((Component)val3).transform == (Object)null || ((Component)val3).transform.IsChildOf(((Component)this).transform))
				{
					continue;
				}
				Vector3 val4 = ((Component)val3).transform.position - position;
				float sqrMagnitude = ((Vector3)(ref val4)).sqrMagnitude;
				if (!(sqrMagnitude < 0.01f))
				{
					float num2 = sqrMagnitude;
					Rigidbody componentInChildren = ((Component)val3).GetComponentInChildren<Rigidbody>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						float num3 = num2;
						val5 = componentInChildren.velocity;
						num2 = num3 + Mathf.Min(45f, ((Vector3)(ref val5)).magnitude * 2.5f);
					}
					if (num2 < num)
					{
						num = num2;
						val = ((Component)val3).transform;
						val2 = componentInChildren;
					}
				}
			}
			nearbyUnitCount = 0;
			if ((Object)(object)val != (Object)null)
			{
				Vector3 position2 = val.position;
				for (int j = 0; j < array.Length; j++)
				{
					if (nearbyUnitCount >= 12)
					{
						break;
					}
					Unit val6 = array[j];
					if (!((Object)(object)val6 == (Object)null) && !((Object)(object)((Component)val6).transform == (Object)null) && !((Object)(object)((Component)val6).transform == (Object)(object)val))
					{
						val5 = ((Component)val6).transform.position - position2;
						if (((Vector3)(ref val5)).sqrMagnitude < 64f)
						{
							nearbyUnitCount++;
						}
					}
				}
			}
			target = val;
			targetBody = val2;
		}

		private void UpdateRecoilAndPose()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Min(0.05f, Time.deltaTime);
			recoilVelocity = Vector3.Lerp(recoilVelocity, Vector3.zero, 1f - Mathf.Exp(-12f * num));
			recoilAngular = Vector3.Lerp(recoilAngular, Vector3.zero, 1f - Mathf.Exp(-10f * num));
			Transform transform = ((Component)this).transform;
			transform.position += recoilVelocity * num;
			((Component)this).transform.Rotate(recoilAngular * num, (Space)1);
		}

		private void ApplyPose(float weight)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_0070: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			Quaternion delta = Quaternion.Euler(58f, 0f, 0f);
			Quaternion delta2 = Quaternion.Euler(82f, 0f, 0f);
			Quaternion identity = Quaternion.identity;
			if (meleeActive || meleeCharging)
			{
				BlendFingerPose(indexBones, delta2, 1f);
				BlendFingerPose(thumbBones, Quaternion.Euler(65f, 0f, 0f), 1f);
				BlendFingerPose(middleBones, delta2, 1f);
				BlendFingerPose(ringBones, delta2, 1f);
				BlendFingerPose(pinkyBones, delta2, 1f);
			}
			else
			{
				BlendFingerPose(indexBones, identity, weight);
				BlendFingerPose(thumbBones, Quaternion.Euler(-18f, -10f, 24f), weight);
				BlendFingerPose(middleBones, delta, weight);
				BlendFingerPose(ringBones, delta, weight);
				BlendFingerPose(pinkyBones, delta, weight);
			}
		}

		private void BlendFingerPose(List<Transform> bones, Quaternion delta, float weight)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < bones.Count; i++)
			{
				Transform val = bones[i];
				if (!((Object)(object)val == (Object)null))
				{
					Quaternion localRotation = val.localRotation;
					Quaternion val2 = FindBaseRotation(val);
					Quaternion val3 = val2 * delta;
					localRotation = Quaternion.Slerp(val2, val3, weight);
					val.localRotation = Quaternion.Slerp(val.localRotation, localRotation, 1f - Mathf.Exp(-18f * Time.deltaTime));
				}
			}
		}

		private Quaternion FindBaseRotation(Transform tr)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: 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_0041: 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)
			if ((Object)(object)tr != (Object)null && baseRotationById.TryGetValue(((Object)tr).GetInstanceID(), out var value))
			{
				return value;
			}
			return ((Object)(object)tr != (Object)null) ? tr.localRotation : Quaternion.identity;
		}

		private void UpdateFlightPathfinder()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: 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_00eb: 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_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_017d: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_020c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_0220: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: 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_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_0355: 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_0372: Unknown result type (might be due to invalid IL or missing references)
			//IL_0377: Unknown result type (might be due to invalid IL or missing references)
			//IL_0383: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_0393: Unknown result type (might be due to invalid IL or missing references)
			//IL_0398: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b5: 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_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0403: Unknown result type (might be due to invalid IL or missing references)
			//IL_0408: Unknown result type (might be due to invalid IL or missing references)
			//IL_041f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: 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_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: 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_02fe: 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_0320: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				return;
			}
			Vector3 position = target.position;
			Vector3 val = (((Object)(object)targetBody != (Object)null) ? targetBody.velocity : Vector3.zero);
			float magnitude = ((Vector3)(ref val)).magnitude;
			Vector3 val2 = position - ((Component)this).transform.position;
			float magnitude2 = ((Vector3)(ref val2)).magnitude;
			if (magnitude2 < 0.01f)
			{
				return;
			}
			float num = Mathf.Clamp(11f + magnitude * 0.35f + Mathf.Abs(val.y) * 0.5f, 7f, 17f);
			float num2 = Mathf.Clamp01((float)nearbyUnitCount / 8f);
			num += num2 * 2.2f;
			float num3 = 5.5f + Mathf.Clamp(magnitude * 0.25f, 0f, 4f);
			if (val.y > 1f)
			{
				num3 += 2f;
			}
			if (val.y < -2f)
			{
				num3 -= 1.8f;
			}
			num3 += Mathf.Sin(Time.time * 0.8f) * (1f + num2);
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
			Vector3 val4 = ((((Vector3)(ref val3)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val3)).normalized : ((Component)this).transform.forward);
			Vector3 val5 = Vector3.Cross(Vector3.up, val4);
			float num4 = ((Mathf.Sin(Time.time * 0.23f) >= 0f) ? 1f : (-1f));
			Vector3 val6 = position + val * 0.28f;
			Vector3 val7 = val6 - val4 * num;
			val7.y = val6.y + num3;
			val7 += val5 * num4 * Mathf.Clamp(num2 + magnitude * 0.07f, 0.4f, 2.5f);
			Vector3 val8 = (val7 - ((Component)this).transform.position) * 1.9f + val * 0.22f;
			val8 = Vector3.ClampMagnitude(val8, 18f);
			Vector3 val9 = ((((Vector3)(ref val8)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val8)).normalized : ((Component)this).transform.forward);
			int num5 = Physics.SphereCastNonAlloc(((Component)this).transform.position, 0.65f, val9, raycastBuffer, 2.8f, -1, (QueryTriggerInteraction)1);
			if (num5 > 0)
			{
				Vector3 val10 = Vector3.zero;
				for (int i = 0; i < num5; i++)
				{
					RaycastHit val11 = raycastBuffer[i];
					if (!((Object)(object)((RaycastHit)(ref val11)).collider == (Object)null) && !((Component)((RaycastHit)(ref val11)).collider).transform.IsChildOf(((Component)this).transform))
					{
						val10 += ((RaycastHit)(ref val11)).normal * Mathf.Clamp01(1f - ((RaycastHit)(ref val11)).distance / 2.8f);
					}
				}
				val8 += val10 * 10f;
			}
			flightVelocity = Vector3.Lerp(flightVelocity, val8, 1f - Mathf.Exp(-6f * Time.deltaTime));
			Transform transform = ((Component)this).transform;
			transform.position += flightVelocity * Time.deltaTime;
			Vector3 val12 = val6 - ((Component)this).transform.position;
			if (((Vector3)(ref val12)).sqrMagnitude > 0.01f)
			{
				smoothedAim = Vector3.Slerp(smoothedAim, ((Vector3)(ref val12)).normalized, 1f - Mathf.Exp(-8f * Time.deltaTime));
				Vector3 val13 = -smoothedAim;
				if (((Vector3)(ref val13)).sqrMagnitude > 0.01f)
				{
					Quaternion val14 = Quaternion.LookRotation(val13, Vector3.up);
					((Component)this).transform.rotation = Quaternion.Slerp(((Component)this).transform.rotation, val14, 1f - Mathf.Exp(-9f * Time.deltaTime));
				}
			}
		}

		private void Combat()
		{
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || activeAttackCount > 0 || specialCharging || meleeCharging || meleeActive || fractalSequenceRunning || Time.time < nextShot || Time.time < nextMelee || Time.time < attackLockUntil)
			{
				return;
			}
			Vector3 val = target.position;
			if ((Object)(object)targetBody != (Object)null)
			{
				val += targetBody.velocity * 0.22f;
			}
			float num = Vector3.Distance(((Component)this).transform.position, val);
			if (num > 25f)
			{
				return;
			}
			attackReleaseGuard = false;
			if (num <= 13.5f && Random.value < 0.38f)
			{
				lastAttackKind = 2;
				activeAttackCount = 1;
				meleeActive = true;
				meleeCharging = true;
				meleeTimer = 0f;
				flightVelocity *= 0.06f;
				nextMelee = Time.time + 1.35f;
				nextShot = Time.time + 0.95f;
				attackWatchdogDeadline = Time.time + 3f;
				return;
			}
			int num2 = ChooseNextAttack();
			activeAttackCount = 1;
			shotsSinceSpecial++;
			if (num2 == 1)
			{
				lastAttackKind = 1;
				fractalSequenceRunning = true;
				attackLockUntil = Time.time + 2.15f;
				nextShot = Time.time + 2.45f;
				attackWatchdogDeadline = Time.time + 5f;
				((MonoBehaviour)this).StartCoroutine(FireFractalSequence());
			}
			else
			{
				lastAttackKind = 0;
				nextShot = Time.time + Mathf.Clamp(0.95f + num * 0.025f, 0.98f, 1.45f);
				attackWatchdogDeadline = Time.time + 4f;
				((MonoBehaviour)this).StartCoroutine(FireLaserSequence(val));
			}
			if (shotsSinceSpecial >= 5 && specialCooldown <= 0f && (Object)(object)target != (Object)null && Random.value < 0.15f)
			{
				shotsSinceSpecial = 0;
				attackWatchdogDeadline = Time.time + 4f;
			}
		}

		private void RecoverAttackState()
		{
			if (activeAttackCount <= 0)
			{
				fractalSequenceRunning = false;
				attackReleaseGuard = false;
			}
			else if (attackWatchdogDeadline > 0f && Time.time > attackWatchdogDeadline)
			{
				activeAttackCount = 0;
				fractalSequenceRunning = false;
				meleeCharging = false;
				meleeActive = false;
				specialCharging = false;
				attackReleaseGuard = false;
				attackLockUntil = Time.time + 0.05f;
				nextShot = Time.time + 0.18f;
			}
		}

		private IEnumerator FireLaserSequence(Vector3 predicted)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			yield return (object)new WaitForSecondsRealtime(0.22f);
			if ((Object)(object)this == (Object)null || (Object)(object)target == (Object)null)
			{
				ReleaseAttackSlot();
				yield break;
			}
			if (!FireRainbowBeam(predicted))
			{
				ReleaseAttackSlot();
				yield break;
			}
			ApplyRecoil();
			cameraShake?.AddImpulse(0.55f, 0.15f);
			yield return (object)new WaitForSecondsRealtime(0.05f);
		}

		private IEnumerator FireFractalSequence()
		{
			yield return (object)new WaitForSecondsRealtime(0.42f);
			if ((Object)(object)this == (Object)null || (Object)(object)target == (Object)null)
			{
				fractalSequenceRunning = false;
				ReleaseAttackSlot();
				yield break;
			}
			Vector3 predicted = target.position;
			if ((Object)(object)targetBody != (Object)null)
			{
				predicted += targetBody.velocity * 0.24f;
			}
			FireFractalHyperCube(predicted);
			ApplyRecoil();
			cameraShake?.AddImpulse(0.82f, 0.2f);
		}

		private void ReleaseAttackSlot()
		{
			if (!attackReleaseGuard)
			{
				attackReleaseGuard = true;
				activeAttackCount = 0;
				fractalSequenceRunning = false;
				meleeCharging = false;
				meleeActive = false;
				specialCharging = false;
				attackWatchdogDeadline = 0f;
				attackLockUntil = Mathf.Min(attackLockUntil, Time.time + 0.1f);
				nextShot = Mathf.Max(nextShot, Time.time + 0.08f);
			}
		}

		private int ChooseNextAttack()
		{
			float value = Random.value;
			if (lastAttackKind < 0)
			{
				return (!(value < 0.52f)) ? 1 : 0;
			}
			if (lastAttackKind == 0)
			{
				return (value < 0.72f) ? 1 : 0;
			}
			if (lastAttackKind == 1)
			{
				return (!(value < 0.7f)) ? 1 : 0;
			}
			return (!(value < 0.55f)) ? 1 : 0;
		}

		internal void ReleaseFractalAttackSlot()
		{
			ReleaseAttackSlot();
		}

		internal void ReleaseProjectileSlotFromLaser()
		{
			ReleaseAttackSlot();
		}

		internal void FractalImpactShake()
		{
			if ((Object)(object)cameraShake != (Object)null)
			{
				cameraShake.AddImpulse(1f, 0.26f);
			}
		}

		private void ApplyRecoil()
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//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_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_0027: 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_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			recoilVelocity += -((Component)this).transform.forward * 4.6f;
			recoilAngular += new Vector3(Random.Range(-9f, 9f), Random.Range(-14f, 14f), Random.Range(-8f, 8f));
		}

		private void BeginBlackHoleCharge()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: 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_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)target == (Object)null))
			{
				specialCharging = true;
				specialTimer = 0f;
				specialCooldown = 9f;
				blackHoleHasTarget = true;
				blackHoleTargetPoint = target.position + (((Object)(object)targetBody != (Object)null) ? (targetBody.velocity * 0.25f) : Vector3.zero);
				attackLockUntil = Time.time + 1.25f + 0.55f;
				flightVelocity *= 0.35f;
			}
		}

		private void DoMeleeStrike()
		{
			//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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: 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_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Transform val = GetIndexTip();
				Vector3 position = ((Component)this).transform.position;
				Vector3 val2 = ((((Vector3)(ref smoothedAim)).sqrMagnitude > 0.01f) ? ((Vector3)(ref smoothedAim)).normalized : ((Component)this).transform.forward);
				float num = 11f;
				RaycastHit val3 = default(RaycastHit);
				if (!Physics.SphereCast(position, 1.35f, val2, ref val3, num, -1, (QueryTriggerInteraction)1) || !((Object)(object)((RaycastHit)(ref val3)).collider != (Object)null) || ((Component)((RaycastHit)(ref val3)).collider).transform.IsChildOf(((Component)this).transform))
				{
					return;
				}
				Unit componentInParent = ((Component)((RaycastHit)(ref val3)).collider).GetComponentInParent<Unit>();
				if ((Object)(object)componentInParent != (Object)null && (Object)(object)((Component)componentInParent).transform != (Object)(object)((Component)this).transform && !((Component)componentInParent).transform.IsChildOf(((Component)this).transform))
				{
					Rigidbody componentInChildren = ((Component)componentInParent).GetComponentInChildren<Rigidbody>();
					if ((Object)(object)componentInChildren != (Object)null && !componentInChildren.isKinematic)
					{
						componentInChildren.AddForce(val2 * 48f + Vector3.up * 14f, (ForceMode)1);
						componentInChildren.AddTorque(Random.insideUnitSphere * 25f, (ForceMode)1);
					}
					DistortUnitMesh(((Component)componentInParent).gameObject, ((RaycastHit)(ref val3)).point, val2);
					CreateMeleeShockwave(((RaycastHit)(ref val3)).point);
				}
			}
			finally
			{
				ApplyRecoil();
				meleeActive = false;
			}
		}

		private void DistortUnitMesh(GameObject root, Vector3 worldImpact, Vector3 impulseDirection)
		{
			//IL_0066: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			MeshFilter[] componentsInChildren = root.GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if ((Object)(object)val == (Object)null || (Object)(object)val.mesh == (Object)null)
				{
					continue;
				}
				try
				{
					Mesh mesh = val.mesh;
					Vector3[] vertices = mesh.vertices;
					Vector3 val2 = ((Component)val).transform.InverseTransformPoint(worldImpact);
					Vector3 val3 = ((Component)val).transform.InverseTransformDirection(impulseDirection);
					for (int j = 0; j < vertices.Length; j++)
					{
						Vector3 val4 = vertices[j] - val2;
						float magnitude = ((Vector3)(ref val4)).magnitude;
						if (!(magnitude > 0.9f))
						{
							float num = 1f - magnitude / 0.9f;
							ref Vector3 reference = ref vertices[j];
							reference += val3 * (0.3f * num) + Random.insideUnitSphere * (0.035f * num);
						}
					}
					mesh.vertices = vertices;
					mesh.RecalculateBounds();
				}
				catch
				{
				}
			}
			SkinnedMeshRenderer[] componentsInChildren2 = root.GetComponentsInChildren<SkinnedMeshRenderer>(true);
			foreach (SkinnedMeshRenderer val5 in componentsInChildren2)
			{
				if (!((Object)(object)val5 == (Object)null) && !((Object)(object)((Component)val5).transform == (Object)null))
				{
					try
					{
						((MonoBehaviour)this).StartCoroutine(PunchTransformDistortion(((Component)val5).transform, impulseDirection));
					}
					catch
					{
					}
				}
			}
		}

		private IEnumerator PunchTransformDistortion(Transform victimTransform, Vector3 direction)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)victimTransform == (Object)null))
			{
				Vector3 baseScale = victimTransform.localScale;
				Quaternion baseRotation = victimTransform.localRotation;
				float t = 0f;
				while ((Object)(object)victimTransform != (Object)null && t < 0.24f)
				{
					t += Time.deltaTime;
					float n = Mathf.Clamp01(t / 0.24f);
					float pulse = Mathf.Sin(n * (float)Math.PI) * 0.2f;
					Vector3 localDir = victimTransform.InverseTransformDirection(direction);
					Vector3 scale = new Vector3(1f + Mathf.Abs(localDir.x) * pulse, 1f + Mathf.Abs(localDir.y) * pulse, 1f + Mathf.Abs(localDir.z) * pulse);
					victimTransform.localScale = Vector3.Scale(baseScale, scale);
					victimTransform.localRotation = baseRotation * Quaternion.Euler(localDir.z * pulse * 35f, (0f - localDir.x) * pulse * 35f, localDir.y * pulse * 20f);
					yield return null;
				}
				if ((Object)(object)victimTransform != (Object)null)
				{
					victimTransform.localScale = baseScale;
					victimTransform.localRotation = baseRotation;
				}
			}
		}

		private void CreateMeleeShockwave(Vector3 point)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)val).name = "MasterHand_MeleeShockwave";
			val.transform.position = point;
			val.transform.localScale = Vector3.one * 0.35f;
			Collider component = val.GetComponent<Collider>();
			if ((Object)(object)component != (Object)null)
			{
				Object.Destroy((Object)(object)component);
			}
			Renderer component2 = val.GetComponent<Renderer>();
			if ((Object)(object)component2 != (Object)null && (Object)(object)beamMaterial != (Object)null)
			{
				component2.sharedMaterial = beamMaterial;
			}
			Object.Destroy((Object)(object)val, 0.28f);
			((MonoBehaviour)this).StartCoroutine(ExpandShockwave(val));
		}

		private IEnumerator ExpandShockwave(GameObject wave)
		{
			if (!((Object)(object)wave == (Object)null))
			{
				float t = 0f;
				while ((Object)(object)wave != (Object)null && t < 0.28f)
				{
					t += Time.deltaTime;
					float n = Mathf.Clamp01(t / 0.28f);
					wave.transform.localScale = Vector3.one * Mathf.Lerp(0.35f, 3.2f, n);
					yield return null;
				}
			}
		}

		private void SpecialImpactAtPoint(Vector3 point)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			int num = Physics.OverlapSphereNonAlloc(point, 4.5f, overlapBuffer, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < num; i++)
			{
				Collider val = overlapBuffer[i];
				if (!((Object)(object)val == (Object)null) && !((Component)val).transform.IsChildOf(((Component)this).transform))
				{
					Unit componentInParent = ((Component)val).GetComponentInParent<Unit>();
					if ((Object)(object)componentInParent != (Object)null && (Object)(object)((Component)componentInParent).transform != (Object)(object)((Component)this).transform && !((Component)componentInParent).transform.IsChildOf(((Component)this).transform))
					{
						((MonoBehaviour)this).StartCoroutine(DissolveAndBreakTarget(((Component)componentInParent).transform));
					}
				}
			}
		}

		private void RecoverFromGroundClip()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL