Decompiled source of Minecraft Knight v0.4.0

plugins\FanRunnerTestClone\FanRunnerTestClone.dll

Decompiled 38 minutes ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("FanRunnerTestClone")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FanRunnerTestClone")]
[assembly: AssemblyTitle("FanRunnerTestClone")]
[assembly: AssemblyVersion("1.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 FanRunnerTestClone
{
	internal sealed class BakedMeshAnimationPlayer : MonoBehaviour
	{
		private sealed class PartData
		{
			public string ObjectName;

			public string MaterialName;

			public Vector2[] UVs;

			public int[] Triangles;

			public Mesh Mesh;

			public Vector3[] BlendVertices;

			public Vector3[] BlendNormals;
		}

		private sealed class ClipData
		{
			public string Name;

			public float FramesPerSecond;

			public int FrameCount;

			public int LoopFrameCount;

			public bool Loop;

			public Vector3[][][] Positions;

			public Vector3[][][] Normals;
		}

		private static readonly BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private const string Magic = "FANIM001";

		private const int FormatVersion = 1;

		[SerializeField]
		private string _animationPath;

		[SerializeField]
		private string _objPath;

		[SerializeField]
		private string _fallbackSkinPath;

		[SerializeField]
		private string _fallbackSwordPath;

		private PartData[] _parts;

		private readonly Dictionary<string, ClipData> _clips = new Dictionary<string, ClipData>(StringComparer.Ordinal);

		private Component _runner;

		private FieldInfo _stateField;

		private ClipData _currentClip;

		private float _framePosition;

		private bool _attackActive;

		private bool _initialized;

		private bool _reportedAttackMissing;

		private Vector3 _lastRunnerPosition;

		private bool _hasLastRunnerPosition;

		private float _runnerPlanarSpeed;

		public static GameObject Load(string animationPath, string objPath, string fallbackSkinPath, string fallbackSwordPath, Action<string> warning)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (string.IsNullOrEmpty(animationPath) || !File.Exists(animationPath))
			{
				return null;
			}
			GameObject val = new GameObject("Fan_RunnerTestClone_MinecraftAnimatedVisual");
			try
			{
				BakedMeshAnimationPlayer bakedMeshAnimationPlayer = val.AddComponent<BakedMeshAnimationPlayer>();
				bakedMeshAnimationPlayer._animationPath = animationPath;
				bakedMeshAnimationPlayer._objPath = objPath;
				bakedMeshAnimationPlayer._fallbackSkinPath = fallbackSkinPath;
				bakedMeshAnimationPlayer._fallbackSwordPath = fallbackSwordPath;
				bakedMeshAnimationPlayer.ReadAnimationFile(animationPath);
				bakedMeshAnimationPlayer.CreateRenderers(objPath, fallbackSkinPath, fallbackSwordPath, warning);
				bakedMeshAnimationPlayer.SelectClip("MC_Walk", loop: true, restart: true);
				bakedMeshAnimationPlayer.ApplyFrame(0, 0f);
				bakedMeshAnimationPlayer._initialized = true;
				return val;
			}
			catch
			{
				Object.Destroy((Object)(object)val);
				throw;
			}
		}

		public void BindRunner(Component runner)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			_runner = runner;
			_stateField = (((Object)(object)runner != (Object)null) ? ((object)runner).GetType().GetField("currentState", InstanceFlags) : null);
			_hasLastRunnerPosition = (Object)(object)runner != (Object)null;
			_lastRunnerPosition = (((Object)(object)runner != (Object)null) ? runner.transform.position : Vector3.zero);
			_runnerPlanarSpeed = 0f;
		}

		private void Start()
		{
			try
			{
				_clips.Clear();
				ReadAnimationFile(_animationPath);
				BindExistingMeshesAndMakeUniqueCopies();
				SelectClip("MC_Walk", loop: true, restart: true);
				ApplyFrame(0, 0f);
				ResolveRunnerAncestor();
				_initialized = true;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[RunnerTestClone] Could not initialize per-instance animation playback: " + ex));
				((Behaviour)this).enabled = false;
			}
		}

		public void PlayAttack()
		{
			if (!_clips.TryGetValue("MC_Attack", out var _))
			{
				if (!_reportedAttackMissing)
				{
					Debug.LogWarning((object)"[RunnerTestClone] MC_Attack was not found in runner_animations.bin.");
					_reportedAttackMissing = true;
				}
			}
			else if (!_attackActive || _currentClip == null || !(_currentClip.Name == "MC_Attack"))
			{
				_attackActive = true;
				SelectClip("MC_Attack", loop: false, restart: true);
				Debug.Log((object)"[RunnerTestClone] MC_Attack started; it temporarily overrides locomotion.");
			}
		}

		private void LateUpdate()
		{
			if (!_initialized || _currentClip == null)
			{
				return;
			}
			if ((Object)(object)_runner == (Object)null || _stateField == null)
			{
				ResolveRunnerAncestor();
			}
			if ((Object)(object)_runner == (Object)null || _stateField == null)
			{
				return;
			}
			string text = "";
			try
			{
				object value = _stateField.GetValue(_runner);
				if (value != null)
				{
					text = value.ToString();
				}
			}
			catch
			{
				return;
			}
			UpdateRunnerPlanarSpeed();
			if (text == "Stun")
			{
				ApplyCurrentFrame();
				return;
			}
			if (_attackActive)
			{
				Advance(Time.deltaTime);
				return;
			}
			bool flag = IsRunningState(text);
			bool flag2 = IsMovingState(text);
			bool flag3 = _runnerPlanarSpeed > 0.08f;
			bool flag4 = flag || flag2 || flag3;
			string name = (flag ? "MC_Run" : "MC_Walk");
			SelectClip(name, loop: true, restart: false);
			if (!flag4)
			{
				ApplyFrame(0, 0f);
			}
			else
			{
				Advance(Time.deltaTime);
			}
		}

		private void UpdateRunnerPlanarSpeed()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_runner == (Object)null))
			{
				Vector3 position = _runner.transform.position;
				if (_hasLastRunnerPosition && Time.deltaTime > 0.0001f)
				{
					Vector3 val = position - _lastRunnerPosition;
					val.y = 0f;
					float num = ((Vector3)(ref val)).magnitude / Time.deltaTime;
					_runnerPlanarSpeed = Mathf.Lerp(_runnerPlanarSpeed, num, Mathf.Clamp01(Time.deltaTime * 14f));
				}
				else
				{
					_runnerPlanarSpeed = 0f;
					_hasLastRunnerPosition = true;
				}
				_lastRunnerPosition = position;
			}
		}

		private static bool IsRunningState(string state)
		{
			switch (state)
			{
			default:
				return state == "LookUnderStart";
			case "AttackPlayer":
			case "AttackPlayerOver":
			case "AttackPlayerBackToNavMesh":
				return true;
			}
		}

		private static bool IsMovingState(string state)
		{
			switch (state)
			{
			default:
				return state == "Leave";
			case "Roam":
			case "Investigate":
			case "SeekPlayer":
			case "Sneak":
				return true;
			}
		}

		private void ReadAnimationFile(string path)
		{
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			using (FileStream fileStream = File.OpenRead(path))
			{
				using BinaryReader binaryReader = new BinaryReader(fileStream, Encoding.UTF8);
				string text = Encoding.ASCII.GetString(binaryReader.ReadBytes(8));
				if (text != "FANIM001")
				{
					throw new InvalidDataException("Unsupported animation cache header: " + text);
				}
				int num = binaryReader.ReadInt32();
				if (num != 1)
				{
					throw new InvalidDataException("Unsupported animation cache version: " + num);
				}
				int num2 = ReadBoundedCount(binaryReader, 1, 256, "mesh part");
				_parts = new PartData[num2];
				for (int i = 0; i < num2; i++)
				{
					PartData partData = new PartData();
					partData.ObjectName = ReadSafeString(binaryReader);
					partData.MaterialName = ReadSafeString(binaryReader);
					int num3 = ReadBoundedCount(binaryReader, 3, 200000, "vertex");
					int num4 = ReadBoundedCount(binaryReader, 3, 600000, "triangle index");
					if (num4 % 3 != 0)
					{
						throw new InvalidDataException("Mesh part has a non-triangular index count: " + partData.ObjectName);
					}
					partData.UVs = (Vector2[])(object)new Vector2[num3];
					for (int j = 0; j < num3; j++)
					{
						partData.UVs[j] = new Vector2(binaryReader.ReadSingle(), binaryReader.ReadSingle());
					}
					partData.Triangles = new int[num4];
					for (int k = 0; k < num4; k++)
					{
						int num5 = binaryReader.ReadInt32();
						if (num5 < 0 || num5 >= num3)
						{
							throw new InvalidDataException("Mesh part contains an out-of-range triangle index.");
						}
						partData.Triangles[k] = num5;
					}
					_parts[i] = partData;
				}
				int num6 = ReadBoundedCount(binaryReader, 3, 16, "animation clip");
				for (int l = 0; l < num6; l++)
				{
					ClipData clipData = new ClipData();
					clipData.Name = ReadSafeString(binaryReader);
					clipData.FramesPerSecond = Mathf.Clamp(binaryReader.ReadSingle(), 1f, 120f);
					clipData.FrameCount = ReadBoundedCount(binaryReader, 2, 1200, "animation frame");
					clipData.LoopFrameCount = ReadBoundedCount(binaryReader, 1, clipData.FrameCount, "loop frame");
					clipData.Loop = binaryReader.ReadInt32() != 0;
					if (!clipData.Loop)
					{
						clipData.LoopFrameCount = clipData.FrameCount;
					}
					clipData.Positions = new Vector3[clipData.FrameCount][][];
					clipData.Normals = new Vector3[clipData.FrameCount][][];
					for (int m = 0; m < clipData.FrameCount; m++)
					{
						clipData.Positions[m] = new Vector3[num2][];
						clipData.Normals[m] = new Vector3[num2][];
						for (int n = 0; n < num2; n++)
						{
							int num7 = _parts[n].UVs.Length;
							Vector3[] array = (Vector3[])(object)new Vector3[num7];
							Vector3[] array2 = (Vector3[])(object)new Vector3[num7];
							for (int num8 = 0; num8 < num7; num8++)
							{
								array[num8] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
							}
							for (int num9 = 0; num9 < num7; num9++)
							{
								array2[num9] = new Vector3(binaryReader.ReadSingle(), binaryReader.ReadSingle(), binaryReader.ReadSingle());
							}
							clipData.Positions[m][n] = array;
							clipData.Normals[m][n] = array2;
						}
					}
					if (_clips.ContainsKey(clipData.Name))
					{
						throw new InvalidDataException("Duplicate animation clip: " + clipData.Name);
					}
					_clips.Add(clipData.Name, clipData);
				}
				if (fileStream.Position != fileStream.Length)
				{
					Debug.LogWarning((object)("[RunnerTestClone] Animation cache has " + (fileStream.Length - fileStream.Position) + " unused trailing bytes."));
				}
			}
			if (!_clips.ContainsKey("MC_Walk") || !_clips.ContainsKey("MC_Run") || !_clips.ContainsKey("MC_Attack"))
			{
				throw new InvalidDataException("Animation cache must contain MC_Walk, MC_Run and MC_Attack.");
			}
		}

		private void CreateRenderers(string objPath, string fallbackSkinPath, string fallbackSwordPath, Action<string> warning)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: 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)
			ClipData clipData = _clips["MC_Walk"];
			for (int i = 0; i < _parts.Length; i++)
			{
				PartData partData = _parts[i];
				Mesh val = new Mesh();
				((Object)val).name = "RunnerTestClone_Animated_" + SafeName(partData.ObjectName) + "_" + SafeName(partData.MaterialName);
				if (partData.UVs.Length > 65535)
				{
					val.indexFormat = (IndexFormat)1;
				}
				val.MarkDynamic();
				val.vertices = clipData.Positions[0][i];
				val.uv = partData.UVs;
				val.triangles = partData.Triangles;
				val.normals = clipData.Normals[0][i];
				val.RecalculateBounds();
				partData.Mesh = val;
				partData.BlendVertices = (Vector3[])(object)new Vector3[partData.UVs.Length];
				partData.BlendNormals = (Vector3[])(object)new Vector3[partData.UVs.Length];
				GameObject val2 = new GameObject("AnimatedMeshPart_" + i.ToString(CultureInfo.InvariantCulture) + "_" + SafeName(partData.ObjectName) + "_" + SafeName(partData.MaterialName));
				val2.transform.SetParent(((Component)this).transform, false);
				val2.AddComponent<MeshFilter>().sharedMesh = val;
				((Renderer)val2.AddComponent<MeshRenderer>()).sharedMaterial = RuntimeObjModel.LoadMaterialForAnimation(partData.MaterialName, objPath, fallbackSkinPath, fallbackSwordPath, warning);
			}
		}

		private void BindExistingMeshesAndMakeUniqueCopies()
		{
			for (int i = 0; i < _parts.Length; i++)
			{
				PartData partData = _parts[i];
				string text = "AnimatedMeshPart_" + i.ToString(CultureInfo.InvariantCulture) + "_" + SafeName(partData.ObjectName) + "_" + SafeName(partData.MaterialName);
				Transform obj = ((Component)this).transform.Find(text);
				if ((Object)(object)obj == (Object)null)
				{
					throw new InvalidDataException("Animated mesh child was not found in the spawned prefab: " + text);
				}
				MeshFilter component = ((Component)obj).GetComponent<MeshFilter>();
				if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
				{
					throw new InvalidDataException("Animated mesh child has no MeshFilter/Mesh: " + text);
				}
				Mesh val = Object.Instantiate<Mesh>(component.sharedMesh);
				((Object)val).name = ((Object)component.sharedMesh).name + "_Instance";
				component.sharedMesh = val;
				partData.Mesh = val;
				partData.BlendVertices = (Vector3[])(object)new Vector3[partData.UVs.Length];
				partData.BlendNormals = (Vector3[])(object)new Vector3[partData.UVs.Length];
			}
		}

		private void ResolveRunnerAncestor()
		{
			Transform parent = ((Component)this).transform.parent;
			while ((Object)(object)parent != (Object)null)
			{
				Component[] components = ((Component)parent).GetComponents<Component>();
				foreach (Component val in components)
				{
					if (!((Object)(object)val == (Object)null) && string.Equals(((object)val).GetType().Name, "EnemyRunner", StringComparison.Ordinal))
					{
						BindRunner(val);
						if (_stateField != null)
						{
							return;
						}
					}
				}
				parent = parent.parent;
			}
		}

		private void SelectClip(string name, bool loop, bool restart)
		{
			if (_clips.TryGetValue(name, out var value) && (_currentClip != value || restart) && (_currentClip != value || loop || restart))
			{
				string text = ((_currentClip != null) ? _currentClip.Name : "<none>");
				_currentClip = value;
				_framePosition = 0f;
				if (name == "MC_Attack")
				{
					_attackActive = true;
				}
				if (!string.Equals(text, name, StringComparison.Ordinal))
				{
					Debug.Log((object)("[RunnerTestClone] Animation changed: " + text + " -> " + name + "."));
				}
			}
		}

		private void Advance(float deltaTime)
		{
			if (_currentClip == null || deltaTime <= 0f)
			{
				ApplyCurrentFrame();
				return;
			}
			_framePosition += deltaTime * _currentClip.FramesPerSecond;
			int num = (_currentClip.Loop ? _currentClip.LoopFrameCount : _currentClip.FrameCount);
			if (_currentClip.Loop)
			{
				if (_framePosition >= (float)num)
				{
					_framePosition %= num;
				}
			}
			else if (_framePosition >= (float)(_currentClip.FrameCount - 1))
			{
				_framePosition = _currentClip.FrameCount - 1;
				if (_currentClip.Name == "MC_Attack")
				{
					_attackActive = false;
				}
			}
			int num2 = Mathf.Clamp(Mathf.FloorToInt(_framePosition), 0, _currentClip.FrameCount - 1);
			int num3 = num2 + 1;
			ApplyFrame(frameB: (!_currentClip.Loop) ? Mathf.Min(num3, _currentClip.FrameCount - 1) : (num3 % num), frameA: num2, blend: _framePosition - (float)num2);
		}

		private void ApplyCurrentFrame()
		{
			if (_currentClip != null)
			{
				int num = Mathf.Clamp(Mathf.FloorToInt(_framePosition), 0, _currentClip.FrameCount - 1);
				int frameB = (_currentClip.Loop ? ((num + 1) % _currentClip.LoopFrameCount) : Mathf.Min(num + 1, _currentClip.FrameCount - 1));
				ApplyFrame(num, _framePosition - (float)num, frameB);
			}
		}

		private void ApplyFrame(int frameA, float blend)
		{
			int frameB = (_currentClip.Loop ? ((frameA + 1) % _currentClip.LoopFrameCount) : Mathf.Min(frameA + 1, _currentClip.FrameCount - 1));
			ApplyFrame(frameA, blend, frameB);
		}

		private void ApplyFrame(int frameA, float blend, int frameB)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_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)
			if (_currentClip == null)
			{
				return;
			}
			blend = Mathf.Clamp01(blend);
			for (int i = 0; i < _parts.Length; i++)
			{
				PartData partData = _parts[i];
				Vector3[] array = _currentClip.Positions[frameA][i];
				Vector3[] array2 = _currentClip.Positions[frameB][i];
				Vector3[] array3 = _currentClip.Normals[frameA][i];
				Vector3[] array4 = _currentClip.Normals[frameB][i];
				Vector3[] array5 = partData.BlendVertices;
				Vector3[] array6 = partData.BlendNormals;
				if (blend <= 0.001f || frameA == frameB)
				{
					array5 = array;
					array6 = array3;
				}
				else
				{
					for (int j = 0; j < array5.Length; j++)
					{
						array5[j] = Vector3.LerpUnclamped(array[j], array2[j], blend);
						Vector3[] array7 = array6;
						int num = j;
						Vector3 val = Vector3.SlerpUnclamped(array3[j], array4[j], blend);
						array7[num] = ((Vector3)(ref val)).normalized;
					}
				}
				partData.Mesh.vertices = array5;
				partData.Mesh.normals = array6;
				partData.Mesh.RecalculateBounds();
			}
		}

		private static int ReadBoundedCount(BinaryReader reader, int min, int max, string label)
		{
			int num = reader.ReadInt32();
			if (num < min || num > max)
			{
				throw new InvalidDataException("Invalid " + label + " count in animation cache: " + num);
			}
			return num;
		}

		private static string ReadSafeString(BinaryReader reader)
		{
			int num = ReadBoundedCount(reader, 0, 4096, "string byte");
			byte[] array = reader.ReadBytes(num);
			if (array.Length != num)
			{
				throw new EndOfStreamException("Unexpected end of animation cache string.");
			}
			return Encoding.UTF8.GetString(array);
		}

		private static string SafeName(string value)
		{
			if (string.IsNullOrEmpty(value))
			{
				return "unnamed";
			}
			StringBuilder stringBuilder = new StringBuilder(value.Length);
			foreach (char c in value)
			{
				stringBuilder.Append((char.IsLetterOrDigit(c) || c == '_' || c == '-') ? c : '_');
			}
			return stringBuilder.ToString();
		}
	}
	[BepInPlugin("fanteam.REPO.RunnerTestClone", "Runner Test Clone", "0.4.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		private const string PluginGuid = "fanteam.REPO.RunnerTestClone";

		private const string PluginName = "Runner Test Clone";

		private const string PluginVersion = "0.4.0";

		private const string ClonePrefabName = "Fan_RunnerTestClone";

		private const string CloneSetupName = "Enemy - Runner Test Clone";

		private const string CloneDisplayName = "RUNNER TEST CLONE";

		private static readonly BindingFlags InstanceFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		private static readonly BindingFlags StaticFlags = BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;

		private ConfigEntry<KeyCode> _spawnKey;

		private object _cloneSetup;

		private MethodInfo _spawnEnemyMethod;

		private GameObject _prefabHolder;

		private bool _registered;

		private float _nextRegistrationAttempt;

		private float _nextSpawnAllowed;

		private float _nextAutoSpawnPoll;

		private float _autoSpawnNotBefore;

		private bool _wasInLevel;

		private bool _autoSpawnedThisLevel;

		private string _activeLevelToken = string.Empty;

		private Harmony _harmony;

		private bool _movementPatchAttempted;

		private bool _visionPatchAttempted;

		private bool _attackSlashPatchAttempted;

		private bool _runnerDeathPatchAttempted;

		private ConfigEntry<float> _modelYawCorrection;

		private void Awake()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Invalid comparison between Unknown and I4
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Expected O, but got Unknown
			_spawnKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Controls", "SpawnKey", (KeyCode)288, "Key that manually spawns an additional Runner test clone in front of the host player.");
			if ((int)_spawnKey.Value == 287)
			{
				_spawnKey.Value = (KeyCode)288;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Migrated SpawnKey from F6 to F7.");
			}
			_modelYawCorrection = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "YawCorrection", 180f, "Yaw correction for the Minecraft model. 180 degrees matches the verified forward-facing orientation from the working build.");
			if (Mathf.Abs(Mathf.DeltaAngle(_modelYawCorrection.Value, 0f)) < 0.01f)
			{
				_modelYawCorrection.Value = 180f;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Migrated YawCorrection from 0 to the verified 180-degree orientation.");
			}
			_harmony = new Harmony("fanteam.REPO.RunnerTestClone.movementfix");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded v0.4.0. Keeps the original Runner spawn pool intact; adds one guaranteed clone spawn per level, F7 manual spawn, and clone-only movement collision guarding.");
		}

		private void Update()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			if (!_registered && Time.unscaledTime >= _nextRegistrationAttempt)
			{
				_nextRegistrationAttempt = Time.unscaledTime + 1.5f;
				TryBuildClone();
			}
			if (Input.GetKeyDown(_spawnKey.Value))
			{
				SpawnClone();
			}
			if (Time.unscaledTime >= _nextAutoSpawnPoll)
			{
				_nextAutoSpawnPoll = Time.unscaledTime + 1f;
				UpdateAutomaticLevelSpawn();
			}
		}

		private void UpdateAutomaticLevelSpawn()
		{
			try
			{
				UpdateAutomaticLevelSpawnInternal();
			}
			catch (Exception exception)
			{
				_autoSpawnNotBefore = Time.unscaledTime + 5f;
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Automatic clone spawn check failed safely and will retry: " + Unwrap(exception)));
			}
		}

		private void UpdateAutomaticLevelSpawnInternal()
		{
			//IL_010b: 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)
			if (!_registered || _cloneSetup == null || _spawnEnemyMethod == null || !IsHostOrSinglePlayer())
			{
				return;
			}
			Component localPlayerAvatar = GetLocalPlayerAvatar();
			if (!IsLevelGameplayReady(localPlayerAvatar))
			{
				if (_wasInLevel)
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Level ended or unloaded; automatic clone spawn will be re-armed for the next level.");
				}
				_wasInLevel = false;
				_autoSpawnedThisLevel = false;
				_activeLevelToken = string.Empty;
				return;
			}
			string currentLevelToken = GetCurrentLevelToken();
			if (!_wasInLevel || !string.Equals(currentLevelToken, _activeLevelToken, StringComparison.Ordinal))
			{
				_wasInLevel = true;
				_activeLevelToken = currentLevelToken;
				_autoSpawnedThisLevel = false;
				_autoSpawnNotBefore = Time.unscaledTime + 6f;
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Gameplay level detected (" + currentLevelToken + "). A separate Runner Test Clone will spawn automatically after level setup."));
			}
			else if (!_autoSpawnedThisLevel && !(Time.unscaledTime < _autoSpawnNotBefore))
			{
				if (!TryFindAutomaticSpawnPoint(localPlayerAvatar, out var position, out var rotation))
				{
					_autoSpawnNotBefore = Time.unscaledTime + 3f;
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Automatic clone spawn point is not ready yet; retrying after the level navigation is available.");
				}
				else if (SpawnRegisteredClone(position, rotation, "automatic level spawn"))
				{
					_autoSpawnedThisLevel = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Guaranteed clone spawn completed for level " + currentLevelToken + ". The vanilla Runner setup and its original spawn chance were not modified."));
				}
				else
				{
					_autoSpawnNotBefore = Time.unscaledTime + 5f;
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Automatic clone spawn failed; it will retry on this level.");
				}
			}
		}

		private static bool IsLevelGameplayReady(Component player)
		{
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null || !player.gameObject.activeInHierarchy)
			{
				return false;
			}
			Type type = FindLoadedType("SemiFunc");
			if (type != null)
			{
				MethodInfo method = type.GetMethod("RunIsLevel", StaticFlags, null, Type.EmptyTypes, null);
				if (method != null)
				{
					try
					{
						object obj = method.Invoke(null, null);
						if (obj is bool)
						{
							return (bool)obj;
						}
					}
					catch
					{
					}
				}
			}
			Type type2 = FindLoadedType("GameDirector");
			if (((type2 != null) ? GetStaticMember(type2, "instance") : null) != null)
			{
				Scene scene = player.gameObject.scene;
				return ((Scene)(ref scene)).IsValid();
			}
			return false;
		}

		private static string GetCurrentLevelToken()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string text = (((Scene)(ref activeScene)).IsValid() ? (((object)((Scene)(ref activeScene)).handle/*cast due to .constrained prefix*/).ToString() + ":" + ((Scene)(ref activeScene)).name) : "unknown-scene");
			Type type = FindLoadedType("RunManager");
			object instance = ((type != null) ? GetStaticMember(type, "instance") : null);
			string[] array = new string[5] { "level", "currentLevel", "levelNumber", "Level", "CurrentLevel" };
			for (int i = 0; i < array.Length; i++)
			{
				object memberValue = GetMemberValue(instance, array[i]);
				if (memberValue != null)
				{
					Type type2 = memberValue.GetType();
					if (type2.IsPrimitive || memberValue is string || type2.IsEnum)
					{
						text = text + "|" + array[i] + "=" + memberValue;
						break;
					}
				}
			}
			return text;
		}

		private static bool TryFindAutomaticSpawnPoint(Component player, out Vector3 position, out Quaternion rotation)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: 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_0070: 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_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: 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_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: 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_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_0103: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0231: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: 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_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			rotation = Quaternion.identity;
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			Vector3 forward = player.transform.forward;
			forward.y = 0f;
			if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
			{
				forward = Vector3.forward;
			}
			((Vector3)(ref forward)).Normalize();
			Vector3 val = Vector3.Cross(Vector3.up, forward);
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			Vector3[] obj = new Vector3[8]
			{
				forward * 14f,
				normalized * 14f,
				-forward * 14f,
				-normalized * 14f,
				default(Vector3),
				default(Vector3),
				default(Vector3),
				default(Vector3)
			};
			val = forward + normalized;
			obj[4] = ((Vector3)(ref val)).normalized * 17f;
			val = forward - normalized;
			obj[5] = ((Vector3)(ref val)).normalized * 17f;
			val = -forward + normalized;
			obj[6] = ((Vector3)(ref val)).normalized * 17f;
			val = -forward - normalized;
			obj[7] = ((Vector3)(ref val)).normalized * 17f;
			Vector3[] array = (Vector3[])(object)obj;
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 candidate = player.transform.position + array[i];
				Vector3 position2;
				bool flag = TrySampleNavMesh(candidate, out position2);
				if (!flag)
				{
					flag = TryRaycastGround(candidate, out position2);
				}
				if (flag && !Physics.CheckCapsule(position2 + Vector3.up * 0.32f, position2 + Vector3.up * 1.48f, 0.28f, -1, (QueryTriggerInteraction)1))
				{
					position = position2 + Vector3.up * 0.12f;
					rotation = Quaternion.LookRotation(-((Vector3)(ref array[i])).normalized, Vector3.up);
					return true;
				}
			}
			position = player.transform.position + forward * 14f + Vector3.up * 0.2f;
			rotation = Quaternion.LookRotation(-forward, Vector3.up);
			return true;
		}

		private static bool TrySampleNavMesh(Vector3 candidate, out Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			Type type = FindLoadedType("UnityEngine.AI.NavMesh");
			Type type2 = FindLoadedType("UnityEngine.AI.NavMeshHit");
			if (type == null || type2 == null)
			{
				return false;
			}
			MethodInfo methodInfo = null;
			MethodInfo[] methods = type.GetMethods(StaticFlags);
			for (int i = 0; i < methods.Length; i++)
			{
				if (string.Equals(methods[i].Name, "SamplePosition", StringComparison.Ordinal))
				{
					ParameterInfo[] parameters = methods[i].GetParameters();
					if (parameters.Length == 4 && parameters[0].ParameterType == typeof(Vector3) && parameters[1].ParameterType.IsByRef && parameters[1].ParameterType.GetElementType() == type2 && parameters[2].ParameterType == typeof(float) && parameters[3].ParameterType == typeof(int))
					{
						methodInfo = methods[i];
						break;
					}
				}
			}
			if (methodInfo == null)
			{
				return false;
			}
			try
			{
				object[] array = new object[4]
				{
					candidate,
					Activator.CreateInstance(type2),
					6f,
					-1
				};
				object obj = methodInfo.Invoke(null, array);
				if (!(obj is bool) || !(bool)obj)
				{
					return false;
				}
				object memberValue = GetMemberValue(array[1], "position");
				if (!(memberValue is Vector3))
				{
					return false;
				}
				position = (Vector3)memberValue;
				return true;
			}
			catch
			{
				return false;
			}
		}

		private static bool TryRaycastGround(Vector3 candidate, out Vector3 position)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//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 or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			position = Vector3.zero;
			RaycastHit val = default(RaycastHit);
			if (!Physics.Raycast(candidate + Vector3.up * 8f, Vector3.down, ref val, 18f, -1, (QueryTriggerInteraction)1))
			{
				return false;
			}
			if (((RaycastHit)(ref val)).normal.y < 0.55f)
			{
				return false;
			}
			position = ((RaycastHit)(ref val)).point;
			return true;
		}

		private void TryBuildClone()
		{
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_0296: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Expected O, but got Unknown
			try
			{
				Assembly assembly = FindAssembly("REPOLib");
				if (assembly == null)
				{
					return;
				}
				Type type = assembly.GetType("REPOLib.Modules.Enemies", throwOnError: false);
				Type type2 = assembly.GetType("REPOLib.Modules.NetworkPrefabs", throwOnError: false);
				Type type3 = FindLoadedType("EnemyRunner");
				Type type4 = FindLoadedType("EnemyParent");
				if (type == null || type2 == null || type3 == null || type4 == null)
				{
					return;
				}
				TryPatchRunnerOverMovement(type3);
				TryPatchRunnerOnVision(type3);
				TryPatchRunnerAttackSlash();
				TryPatchRunnerDeath(type3);
				PropertyInfo property = type.GetProperty("AllEnemies", StaticFlags);
				if (!(((property == null) ? null : property.GetValue(null, null)) is IEnumerable enumerable))
				{
					return;
				}
				object obj = null;
				GameObject val = null;
				foreach (object item in enumerable)
				{
					if (item == null)
					{
						continue;
					}
					FieldInfo field = item.GetType().GetField("spawnObjects", InstanceFlags);
					if (!(((field == null) ? null : field.GetValue(item)) is IEnumerable enumerable2))
					{
						continue;
					}
					foreach (object item2 in enumerable2)
					{
						if (item2 != null)
						{
							PropertyInfo property2 = item2.GetType().GetProperty("Prefab", InstanceFlags);
							GameObject val2 = (GameObject)((property2 == null) ? null : /*isinst with value type is only supported in some contexts*/);
							if (!((Object)(object)val2 == (Object)null) && !((Object)(object)val2.GetComponentInChildren(type3, true) == (Object)null))
							{
								obj = item;
								val = val2;
								break;
							}
						}
					}
					if ((Object)(object)val != (Object)null)
					{
						break;
					}
				}
				if (obj != null && !((Object)(object)val == (Object)null))
				{
					FieldInfo field2 = obj.GetType().GetField("spawnObjects", InstanceFlags);
					if (field2 == null)
					{
						throw new MissingFieldException(obj.GetType().FullName, "spawnObjects");
					}
					_prefabHolder = new GameObject("Fan_RunnerTestClone_PrefabHolder");
					_prefabHolder.SetActive(false);
					Object.DontDestroyOnLoad((Object)(object)_prefabHolder);
					GameObject val3 = Object.Instantiate<GameObject>(val, _prefabHolder.transform);
					((Object)val3).name = "Fan_RunnerTestClone";
					val3.transform.localPosition = Vector3.zero;
					val3.transform.localRotation = Quaternion.identity;
					val3.SetActive(true);
					Component componentInChildren = val3.GetComponentInChildren(type4, true);
					if ((Object)(object)componentInChildren == (Object)null)
					{
						throw new InvalidOperationException("The Runner prefab has no EnemyParent component.");
					}
					SetMember(componentInChildren, "enemyName", "RUNNER TEST CLONE");
					SetMember(componentInChildren, "enemyNameLocalized", null);
					Component componentInChildren2 = val3.GetComponentInChildren(type3, true);
					if ((Object)(object)componentInChildren2 == (Object)null)
					{
						throw new InvalidOperationException("The cloned prefab has no EnemyRunner component.");
					}
					ConfigureCloneVisuals(val3, componentInChildren2.transform);
					MethodInfo? method = type2.GetMethod("RegisterNetworkPrefab", StaticFlags, null, new Type[2]
					{
						typeof(string),
						typeof(GameObject)
					}, null);
					if (method == null)
					{
						throw new MissingMethodException(type2.FullName, "RegisterNetworkPrefab(string, GameObject)");
					}
					object obj2 = method.Invoke(null, new object[2] { "Enemies/Fan_RunnerTestClone", val3 });
					if (obj2 == null)
					{
						throw new InvalidOperationException("REPOLib did not return a PrefabRef for the clone.");
					}
					Object val4 = Object.Instantiate((Object)obj);
					val4.name = "Enemy - Runner Test Clone";
					object obj3 = Activator.CreateInstance(field2.FieldType);
					((obj3 as IList) ?? throw new InvalidOperationException("EnemySetup.spawnObjects is not an IList.")).Add(obj2);
					field2.SetValue(val4, obj3);
					_cloneSetup = val4;
					_spawnEnemyMethod = FindSpawnEnemyMethod(type, obj.GetType());
					if (_spawnEnemyMethod == null)
					{
						throw new MissingMethodException(type.FullName, "SpawnEnemy(EnemySetup, Vector3, Quaternion, bool)");
					}
					_registered = true;
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Runner clone prepared: original prefab was cloned; separate network ID is Enemies/Fan_RunnerTestClone.");
				}
			}
			catch (Exception exception)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Could not prepare Runner clone: " + Unwrap(exception)));
				CleanupFailedBuild();
			}
		}

		private void SpawnClone()
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: 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_00f0: 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_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			if (Time.unscaledTime < _nextSpawnAllowed)
			{
				return;
			}
			_nextSpawnAllowed = Time.unscaledTime + 0.75f;
			if (!IsHostOrSinglePlayer())
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Only the host can spawn the Runner test clone. Ask the host to press F7.");
				return;
			}
			if (!_registered || _cloneSetup == null || _spawnEnemyMethod == null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Runner clone is not ready yet. Wait until the level finishes loading, then press F7 again.");
				return;
			}
			Component localPlayerAvatar = GetLocalPlayerAvatar();
			if ((Object)(object)localPlayerAvatar == (Object)null)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find PlayerAvatar. Start a run before pressing F7.");
				return;
			}
			try
			{
				Transform transform = localPlayerAvatar.transform;
				Vector3 forward = transform.forward;
				forward.y = 0f;
				if (((Vector3)(ref forward)).sqrMagnitude < 0.001f)
				{
					forward = Vector3.forward;
				}
				((Vector3)(ref forward)).Normalize();
				Vector3 position = transform.position + forward * 3f + Vector3.up * 0.15f;
				Quaternion rotation = Quaternion.LookRotation(forward, Vector3.up);
				if (!SpawnRegisteredClone(position, rotation, "manual F7"))
				{
					((BaseUnityPlugin)this).Logger.LogError((object)"REPOLib SpawnEnemy returned no spawned EnemyParent. Check that a level is active and this client is host.");
					ShowMissionText("RUNNER CLONE SPAWN FAILED - CHECK LOG", Color.red);
				}
			}
			catch (Exception exception)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Runner clone spawn failed: " + Unwrap(exception)));
				ShowMissionText("RUNNER CLONE SPAWN FAILED", Color.red);
			}
		}

		private bool SpawnRegisteredClone(Vector3 position, Quaternion rotation, string source)
		{
			//IL_0030: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			if (_cloneSetup == null || _spawnEnemyMethod == null)
			{
				return false;
			}
			object obj = _spawnEnemyMethod.Invoke(null, new object[4] { _cloneSetup, position, rotation, false });
			if (GetCollectionCount(obj) <= 0)
			{
				return false;
			}
			RegisterExistingPlayersWithSpawnedClone(obj);
			((BaseUnityPlugin)this).Logger.LogInfo((object)("SUCCESS: spawned RUNNER TEST CLONE via " + source + ". Its separate network prefab/setup leaves the vanilla Runner spawn list untouched."));
			ShowMissionText("RUNNER TEST CLONE SPAWNED", new Color(0.35f, 1f, 0.35f));
			return true;
		}

		private static MethodInfo FindSpawnEnemyMethod(Type enemiesType, Type setupType)
		{
			MethodInfo[] methods = enemiesType.GetMethods(StaticFlags);
			for (int i = 0; i < methods.Length; i++)
			{
				if (!(methods[i].Name != "SpawnEnemy"))
				{
					ParameterInfo[] parameters = methods[i].GetParameters();
					if (parameters.Length == 4 && parameters[0].ParameterType == setupType && parameters[1].ParameterType == typeof(Vector3) && parameters[2].ParameterType == typeof(Quaternion) && parameters[3].ParameterType == typeof(bool))
					{
						return methods[i];
					}
				}
			}
			return null;
		}

		private void ConfigureCloneVisuals(GameObject clone, Transform visualFollowTransform)
		{
			//IL_018a: 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_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0205: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_0590: Unknown result type (might be due to invalid IL or missing references)
			//IL_0595: Unknown result type (might be due to invalid IL or missing references)
			//IL_059a: Unknown result type (might be due to invalid IL or missing references)
			//IL_054c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0558: Unknown result type (might be due to invalid IL or missing references)
			//IL_056a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_02d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_030d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0314: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_034c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0358: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0389: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0390: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0298: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_05db: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_05f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0506: Unknown result type (might be due to invalid IL or missing references)
			//IL_0420: Unknown result type (might be due to invalid IL or missing references)
			//IL_0522: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_0467: Unknown result type (might be due to invalid IL or missing references)
			//IL_0673: Unknown result type (might be due to invalid IL or missing references)
			//IL_067a: Expected O, but got Unknown
			//IL_06aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)visualFollowTransform == (Object)null)
			{
				visualFollowTransform = clone.transform;
			}
			Renderer[] componentsInChildren = clone.GetComponentsInChildren<Renderer>(true);
			Bounds bounds;
			bool flag = TryGetBodyRendererBounds(componentsInChildren, out bounds);
			string path = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty, "assets");
			string objPath = Path.Combine(path, "runner_test_clone.obj");
			string animationPath = Path.Combine(path, "runner_animations.bin");
			string text = Path.Combine(path, "skin.png");
			string text2 = Path.Combine(path, "sword.png");
			GameObject val = null;
			try
			{
				val = BakedMeshAnimationPlayer.Load(animationPath, objPath, text, text2, delegate(string message)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)message);
				});
				if ((Object)(object)val != (Object)null)
				{
					BakedMeshAnimationPlayer component = val.GetComponent<BakedMeshAnimationPlayer>();
					Type type = FindLoadedType("EnemyRunner");
					Component runner = ((type != null) ? ((Component)visualFollowTransform).GetComponent(type) : null);
					component.BindRunner(runner);
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded baked MC_Walk, MC_Run and MC_Attack animation cache. Locomotion follows Runner states; the slash event starts MC_Attack.");
				}
			}
			catch (Exception ex)
			{
				if ((Object)(object)val != (Object)null)
				{
					Object.Destroy((Object)(object)val);
				}
				val = null;
				((BaseUnityPlugin)this).Logger.LogError((object)("Baked Minecraft animation cache could not be loaded; trying the static OBJ fallback. " + ex));
			}
			if ((Object)(object)val == (Object)null)
			{
				try
				{
					val = RuntimeObjModel.Load(objPath, text, text2, delegate(string message)
					{
						((BaseUnityPlugin)this).Logger.LogWarning((object)message);
					});
				}
				catch (Exception ex2)
				{
					((BaseUnityPlugin)this).Logger.LogError((object)("Custom Minecraft model could not be loaded; keeping the red Runner fallback. " + ex2));
				}
			}
			Bounds val2 = (Bounds)(flag ? bounds : new Bounds(clone.transform.position, Vector3.up * 2f));
			bool flag2 = flag;
			if ((Object)(object)val != (Object)null)
			{
				if ((Object)(object)val.GetComponent<CloneVisualLifetime>() == (Object)null)
				{
					val.AddComponent<CloneVisualLifetime>();
				}
				val.transform.SetParent(clone.transform, false);
				val.transform.localPosition = Vector3.zero;
				val.transform.localRotation = Quaternion.Euler(0f, _modelYawCorrection.Value, 0f);
				val.transform.localScale = Vector3.one;
				Renderer[] componentsInChildren2 = val.GetComponentsInChildren<Renderer>(true);
				CloneVisualVisibility cloneVisualVisibility = clone.GetComponent<CloneVisualVisibility>();
				if ((Object)(object)cloneVisualVisibility == (Object)null)
				{
					cloneVisualVisibility = clone.AddComponent<CloneVisualVisibility>();
				}
				cloneVisualVisibility.Initialize(componentsInChildren2);
				bool flag3 = TryGetVisualBodyRendererBounds(componentsInChildren2, out var bounds2);
				if (flag && flag3 && ((Bounds)(ref bounds2)).size.y > 0.001f)
				{
					float num = Mathf.Clamp(((Bounds)(ref bounds)).size.y / ((Bounds)(ref bounds2)).size.y, 0.05f, 20f);
					val.transform.localScale = Vector3.one * num;
					flag3 = TryGetVisualBodyRendererBounds(componentsInChildren2, out bounds2);
				}
				Vector3 position = val.transform.position;
				Quaternion rotation = val.transform.rotation;
				float x = val.transform.localScale.x;
				val.transform.SetParent(visualFollowTransform, true);
				val.transform.position = position;
				val.transform.rotation = rotation;
				val.transform.localScale = Vector3.one * x;
				flag3 = TryGetVisualBodyRendererBounds(componentsInChildren2, out bounds2);
				if (flag && flag3)
				{
					Vector3 val3 = default(Vector3);
					((Vector3)(ref val3))..ctor(((Bounds)(ref bounds)).center.x - ((Bounds)(ref bounds2)).center.x, ((Bounds)(ref bounds)).min.y - ((Bounds)(ref bounds2)).min.y, ((Bounds)(ref bounds)).center.z - ((Bounds)(ref bounds2)).center.z);
					Transform transform = val.transform;
					transform.position += val3;
					flag3 = TryGetVisualBodyRendererBounds(componentsInChildren2, out bounds2);
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Bound Minecraft visual in EnemyRunner-local space. Verified yaw correction=" + _modelYawCorrection.Value.ToString("F1") + " degrees."));
				Component enemyComponent = GetEnemyComponent(clone);
				if ((Object)(object)val.GetComponent<CloneVisualFallFollower>() == (Object)null)
				{
					val.AddComponent<CloneVisualFallFollower>();
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Installed runtime-bound whole-body fall follower on the visual prefab. Each spawned clone will resolve its own Runner, Enemy and physics Rigidbody in Start().");
				if (flag3 && (Object)(object)enemyComponent != (Object)null)
				{
					CreateVisualDamageProxy(clone, enemyComponent, val.transform, bounds2);
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not create the full-body damage proxy: custom bounds or Enemy component was missing. Original Runner colliders remain active.");
				}
				for (int num2 = 0; num2 < componentsInChildren.Length; num2++)
				{
					if ((Object)(object)componentsInChildren[num2] != (Object)null)
					{
						componentsInChildren[num2].enabled = false;
					}
				}
				if (flag3)
				{
					val2 = bounds2;
					flag2 = true;
				}
				((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded Minecraft visual. Applied yaw correction=" + _modelYawCorrection.Value.ToString("F1") + " degrees; model follows EnemyRunner.transform. Clone-only death cleanup and Runner-state locomotion/attack animation bridge are active when the baked animation cache is present."));
			}
			else
			{
				Color val4 = default(Color);
				((Color)(ref val4))..ctor(0.78f, 0.035f, 0.025f, 1f);
				for (int num3 = 0; num3 < componentsInChildren.Length; num3++)
				{
					if ((Object)(object)componentsInChildren[num3] == (Object)null)
					{
						continue;
					}
					Material[] materials = componentsInChildren[num3].materials;
					foreach (Material val5 in materials)
					{
						if (!((Object)(object)val5 == (Object)null))
						{
							if (val5.HasProperty("_Color"))
							{
								val5.SetColor("_Color", val4);
							}
							if (val5.HasProperty("_BaseColor"))
							{
								val5.SetColor("_BaseColor", val4);
							}
						}
					}
				}
			}
			Vector3 val6 = default(Vector3);
			if (flag2)
			{
				((Vector3)(ref val6))..ctor(((Bounds)(ref val2)).center.x, ((Bounds)(ref val2)).max.y + 0.35f, ((Bounds)(ref val2)).center.z);
			}
			else
			{
				val6 = clone.transform.position + Vector3.up * 2.5f;
			}
			GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
			((Object)obj).name = "RUNNER_TEST_CLONE_GREEN_MARKER";
			Transform val7 = (((Object)(object)val != (Object)null) ? val.transform : visualFollowTransform);
			obj.transform.SetParent(val7, false);
			obj.transform.localPosition = val7.InverseTransformPoint(val6);
			obj.transform.localScale = Vector3.one * 0.22f;
			Collider component2 = obj.GetComponent<Collider>();
			if ((Object)(object)component2 != (Object)null)
			{
				Object.Destroy((Object)(object)component2);
			}
			MeshRenderer component3 = obj.GetComponent<MeshRenderer>();
			if (!((Object)(object)component3 != (Object)null))
			{
				return;
			}
			Shader val8 = Shader.Find("Standard");
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = Shader.Find("Universal Render Pipeline/Lit");
			}
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = Shader.Find("Unlit/Color");
			}
			if ((Object)(object)val8 != (Object)null)
			{
				Material val9 = new Material(val8);
				Color val10 = default(Color);
				((Color)(ref val10))..ctor(0.05f, 1f, 0.08f, 1f);
				if (val9.HasProperty("_Color"))
				{
					val9.SetColor("_Color", val10);
				}
				if (val9.HasProperty("_BaseColor"))
				{
					val9.SetColor("_BaseColor", val10);
				}
				if (val9.HasProperty("_EmissionColor"))
				{
					val9.EnableKeyword("_EMISSION");
					val9.SetColor("_EmissionColor", val10 * 2f);
				}
				((Renderer)component3).material = val9;
			}
		}

		private static Component GetEnemyComponent(GameObject clone)
		{
			Type type = FindLoadedType("Enemy");
			if (!(type == null))
			{
				return clone.GetComponentInChildren(type, true);
			}
			return null;
		}

		private static Component GetRunnerPhysicsComponent(GameObject clone, Component enemyComponent)
		{
			object memberValue = GetMemberValue(enemyComponent, "Rigidbody");
			Component val = (Component)((memberValue is Component) ? memberValue : null);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Type type = FindLoadedType("EnemyRigidbody");
			if (!(type == null))
			{
				return clone.GetComponentInChildren(type, true);
			}
			return null;
		}

		private bool TryPatchRunnerOnVision(Type runnerType)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			if (_visionPatchAttempted)
			{
				return true;
			}
			_visionPatchAttempted = true;
			try
			{
				MethodInfo methodInfo = AccessTools.Method(runnerType, "OnVision", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), "RunnerOnVisionPostfix", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null || _harmony == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find EnemyRunner.OnVision for the visibility bridge. Vanilla Sneak/Notice selection remains active.");
					return false;
				}
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Installed visibility-aware OnVision postfix: when the custom Minecraft renderer is actually visible, the clone transitions from Sneak to Notice just like a visible vanilla Runner.");
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not install Runner visibility bridge: " + ex));
				return false;
			}
		}

		private static void RunnerOnVisionPostfix(object __instance)
		{
			try
			{
				Component val = (Component)((__instance is Component) ? __instance : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				CloneVisualVisibility componentInParent = val.GetComponentInParent<CloneVisualVisibility>();
				if ((Object)(object)componentInParent == (Object)null || !componentInParent.IsVisibleToCamera())
				{
					return;
				}
				Type type = ((object)val).GetType();
				FieldInfo field = type.GetField("currentState", InstanceFlags);
				if (field == null)
				{
					return;
				}
				object value = field.GetValue(val);
				if (value != null && string.Equals(value.ToString(), "Sneak", StringComparison.Ordinal))
				{
					MethodInfo method = type.GetMethod("UpdateState", InstanceFlags, null, new Type[1] { field.FieldType }, null);
					if (!(method == null))
					{
						object obj = Enum.Parse(field.FieldType, "Notice");
						method.Invoke(val, new object[1] { obj });
					}
				}
			}
			catch
			{
			}
		}

		private bool TryPatchRunnerDeath(Type runnerType)
		{
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			if (_runnerDeathPatchAttempted)
			{
				return true;
			}
			_runnerDeathPatchAttempted = true;
			try
			{
				MethodInfo methodInfo = AccessTools.Method(runnerType, "OnDeath", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), "RunnerOnDeathPostfix", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null || _harmony == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find EnemyRunner.OnDeath. The custom visual may remain visible during the death/despawn sequence.");
					return false;
				}
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Installed clone-only death visual cleanup on EnemyRunner.OnDeath.");
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not install the Runner death visual cleanup: " + ex));
				return false;
			}
		}

		private static void RunnerOnDeathPostfix(object __instance)
		{
			try
			{
				Component val = (Component)((__instance is Component) ? __instance : null);
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				CloneVisualLifetime.HideForRunner(val);
				object memberValue = GetMemberValue(val, "enemy");
				Component val2 = (Component)((memberValue is Component) ? memberValue : null);
				if (!((Object)(object)val2 != (Object)null))
				{
					return;
				}
				Transform[] componentsInChildren = val2.GetComponentsInChildren<Transform>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					if ((Object)(object)componentsInChildren[i] != (Object)null && ((Object)componentsInChildren[i]).name == "Fan_RunnerTestClone_VisualDamageProxy")
					{
						((Component)componentsInChildren[i]).gameObject.SetActive(false);
					}
				}
			}
			catch
			{
			}
		}

		private bool TryPatchRunnerAttackSlash()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Expected O, but got Unknown
			if (_attackSlashPatchAttempted)
			{
				return true;
			}
			_attackSlashPatchAttempted = true;
			try
			{
				Type type = FindLoadedType("EnemyRunnerAnim");
				MethodInfo methodInfo = ((type == null) ? null : AccessTools.Method(type, "SfxAttackSlash", (Type[])null, (Type[])null));
				MethodInfo methodInfo2 = AccessTools.Method(typeof(Plugin), "RunnerAttackSlashPostfix", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo2 == null || _harmony == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find EnemyRunnerAnim.SfxAttackSlash. MC_Attack will not receive the original slash-event trigger.");
					return false;
				}
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Installed clone-only attack animation bridge on EnemyRunnerAnim.SfxAttackSlash.");
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not install the slash-event animation bridge: " + ex));
				return false;
			}
		}

		private static void RunnerAttackSlashPostfix(object __instance)
		{
			try
			{
				object memberValue = GetMemberValue(__instance, "controller");
				Component val = (Component)((memberValue is Component) ? memberValue : null);
				if (!((Object)(object)val == (Object)null))
				{
					BakedMeshAnimationPlayer componentInChildren = val.GetComponentInChildren<BakedMeshAnimationPlayer>(true);
					if ((Object)(object)componentInChildren != (Object)null)
					{
						componentInChildren.PlayAttack();
					}
				}
			}
			catch
			{
			}
		}

		private void RegisterExistingPlayersWithSpawnedClone(object spawned)
		{
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(spawned is IEnumerable enumerable))
				{
					return;
				}
				Type type = FindLoadedType("Enemy");
				Type type2 = FindLoadedType("EnemyVision");
				Type type3 = FindLoadedType("GameDirector");
				Type type4 = FindLoadedType("Photon.Pun.PhotonView");
				if (type == null || type2 == null || type3 == null || type4 == null || !(GetMemberValue(GetStaticMember(type3, "instance"), "PlayerList") is IEnumerable enumerable2))
				{
					return;
				}
				MethodInfo method = type2.GetMethod("PlayerAdded", InstanceFlags, null, new Type[1] { typeof(int) }, null);
				if (method == null)
				{
					return;
				}
				foreach (object item in enumerable)
				{
					Component val = (Component)((item is Component) ? item : null);
					if ((Object)(object)val == (Object)null && item is GameObject)
					{
						val = (Component)(object)((GameObject)item).transform;
					}
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Component componentInChildren = val.GetComponentInChildren(type, true);
					Component val2 = (((Object)(object)componentInChildren == (Object)null) ? null : componentInChildren.GetComponent(type2));
					if ((Object)(object)val2 == (Object)null)
					{
						continue;
					}
					FieldInfo field = type2.GetField("VisionTriggered", InstanceFlags);
					IDictionary dictionary = ((field == null) ? null : (field.GetValue(val2) as IDictionary));
					foreach (object item2 in enumerable2)
					{
						Component val3 = (Component)((item2 is Component) ? item2 : null);
						if ((Object)(object)val3 == (Object)null)
						{
							continue;
						}
						Component component = val3.GetComponent(type4);
						if ((Object)(object)component == (Object)null)
						{
							continue;
						}
						PropertyInfo property = type4.GetProperty("ViewID", InstanceFlags);
						if (((property == null) ? null : property.GetValue(component, null)) is int num && (dictionary == null || !dictionary.Contains(num)))
						{
							try
							{
								method.Invoke(val2, new object[1] { num });
							}
							catch
							{
							}
						}
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not refresh the clone's existing player vision registrations: " + ex.Message));
			}
		}

		private static object GetMemberValue(object instance, string name)
		{
			if (instance == null)
			{
				return null;
			}
			Type type = instance.GetType();
			FieldInfo field = type.GetField(name, InstanceFlags);
			if (field != null)
			{
				return field.GetValue(instance);
			}
			PropertyInfo property = type.GetProperty(name, InstanceFlags);
			if (!(property == null))
			{
				return property.GetValue(instance, null);
			}
			return null;
		}

		private void CreateVisualDamageProxy(GameObject clone, Component enemyComponent, Transform visualFollowTransform, Bounds worldBounds)
		{
			//IL_001a: 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_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				int num = LayerMask.NameToLayer("Enemy");
				int num2 = ((num >= 0) ? num : FindMostCommonEnemyColliderLayer(clone, enemyComponent));
				Bounds val = ConvertWorldBoundsToLocal(worldBounds, visualFollowTransform);
				GameObject val2 = new GameObject("Fan_RunnerTestClone_VisualDamageProxy")
				{
					layer = num2
				};
				val2.transform.SetParent(enemyComponent.transform, false);
				BoxCollider val3 = val2.AddComponent<BoxCollider>();
				((Collider)val3).isTrigger = true;
				val3.center = Vector3.zero;
				val2.AddComponent<VisualDamageHitboxFollower>().Initialize(visualFollowTransform, ((Bounds)(ref val)).center, ((Bounds)(ref val)).size * 1.08f, val3);
				ManualLogSource logger = ((BaseUnityPlugin)this).Logger;
				string[] obj = new string[9]
				{
					"Created visual body damage proxy. Layer=",
					num2.ToString(),
					" (",
					LayerMask.LayerToName(num2),
					"), size=",
					null,
					null,
					null,
					null
				};
				Vector3 size = ((Bounds)(ref val)).size;
				obj[5] = ((Vector3)(ref size)).ToString("F2");
				obj[6] = ", linked Enemy=";
				obj[7] = ((Object)enemyComponent).name;
				obj[8] = ". Trigger collider follows the visible Minecraft body without changing the original physical colliders.";
				logger.LogInfo((object)string.Concat(obj));
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not create visual damage proxy: " + ex.Message));
			}
		}

		private static int FindMostCommonEnemyColliderLayer(GameObject clone, Component enemyComponent)
		{
			Dictionary<int, int> dictionary = new Dictionary<int, int>();
			Collider[] componentsInChildren = clone.GetComponentsInChildren<Collider>(true);
			foreach (Collider val in componentsInChildren)
			{
				if (!((Object)(object)val == (Object)null) && val.enabled && !val.isTrigger)
				{
					dictionary.TryGetValue(((Component)val).gameObject.layer, out var value);
					dictionary[((Component)val).gameObject.layer] = value + 1;
				}
			}
			int result = (((Object)(object)enemyComponent != (Object)null) ? enemyComponent.gameObject.layer : clone.layer);
			int num = -1;
			foreach (KeyValuePair<int, int> item in dictionary)
			{
				if (item.Value > num)
				{
					result = item.Key;
					num = item.Value;
				}
			}
			return result;
		}

		private static Bounds ConvertWorldBoundsToLocal(Bounds worldBounds, Transform target)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_002f: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: 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_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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_0090: 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_009c: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: 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_0116: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			Vector3 min = ((Bounds)(ref worldBounds)).min;
			Vector3 max = ((Bounds)(ref worldBounds)).max;
			Vector3[] array = (Vector3[])(object)new Vector3[8]
			{
				new Vector3(min.x, min.y, min.z),
				new Vector3(min.x, min.y, max.z),
				new Vector3(min.x, max.y, min.z),
				new Vector3(min.x, max.y, max.z),
				new Vector3(max.x, min.y, min.z),
				new Vector3(max.x, min.y, max.z),
				new Vector3(max.x, max.y, min.z),
				new Vector3(max.x, max.y, max.z)
			};
			Bounds result = default(Bounds);
			((Bounds)(ref result))..ctor(target.InverseTransformPoint(array[0]), Vector3.zero);
			for (int i = 1; i < array.Length; i++)
			{
				((Bounds)(ref result)).Encapsulate(target.InverseTransformPoint(array[i]));
			}
			return result;
		}

		private bool TryPatchRunnerOverMovement(Type runnerType)
		{
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Expected O, but got Unknown
			//IL_00b1: Expected O, but got Unknown
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			if (_movementPatchAttempted)
			{
				return true;
			}
			_movementPatchAttempted = true;
			try
			{
				MethodInfo methodInfo = AccessTools.Method(runnerType, "StateAttackPlayerOver", (Type[])null, (Type[])null);
				MethodInfo methodInfo2 = AccessTools.Method(runnerType, "StateAttackPlayerBackToNavMesh", (Type[])null, (Type[])null);
				MethodInfo methodInfo3 = AccessTools.Method(typeof(Plugin), "SmoothAttackOverMovementTranspiler", (Type[])null, (Type[])null);
				MethodInfo methodInfo4 = AccessTools.Method(typeof(Plugin), "RunnerMovementCollisionPostfix", (Type[])null, (Type[])null);
				if (methodInfo == null || methodInfo3 == null || methodInfo4 == null || _harmony == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Runner over-navigation collision patch could not find its target methods. Vanilla movement remains active.");
					return false;
				}
				_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo4), new HarmonyMethod(methodInfo3), (HarmonyMethod)null, (HarmonyMethod)null);
				if (methodInfo2 != null)
				{
					_harmony.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, new HarmonyMethod(methodInfo4), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
					((BaseUnityPlugin)this).Logger.LogInfo((object)"Installed clone-only world collision guard on Runner over-navigation and return-to-NavMesh movement.");
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"Could not find StateAttackPlayerBackToNavMesh; the collision guard only covers StateAttackPlayerOver in this game build.");
				}
				return true;
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not install Runner movement smoothing/collision guard: " + ex));
				return false;
			}
		}

		private static void RunnerMovementCollisionPostfix(object __instance)
		{
			try
			{
				Component val = (Component)((__instance is Component) ? __instance : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val.GetComponentInChildren<CloneVisualFallFollower>(true) == (Object)null))
				{
					RunnerWorldCollisionGuard runnerWorldCollisionGuard = val.GetComponent<RunnerWorldCollisionGuard>();
					if ((Object)(object)runnerWorldCollisionGuard == (Object)null)
					{
						runnerWorldCollisionGuard = val.gameObject.AddComponent<RunnerWorldCollisionGuard>();
					}
					runnerWorldCollisionGuard.ResolveAfterMovement();
				}
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[RunnerTestClone] Clone collision guard failed safely: " + ex.Message));
			}
		}

		private static IEnumerable<CodeInstruction> SmoothAttackOverMovementTranspiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> codes = new List<CodeInstruction>(instructions);
			Type type = AccessTools.TypeByName("EnemyRunner");
			FieldInfo speedField = ((type == null) ? null : AccessTools.Field(type, "agentSpeed"));
			MethodInfo deltaGetter = AccessTools.PropertyGetter(typeof(Time), "deltaTime");
			if (speedField == null || deltaGetter == null)
			{
				for (int i = 0; i < codes.Count; i++)
				{
					yield return codes[i];
				}
				yield break;
			}
			for (int i = 0; i < codes.Count; i++)
			{
				CodeInstruction instruction = codes[i];
				yield return instruction;
				if (instruction.opcode == OpCodes.Ldfld && object.Equals(instruction.operand, speedField) && (i + 1 >= codes.Count || (!(codes[i + 1].opcode == OpCodes.Call) && !(codes[i + 1].opcode == OpCodes.Callvirt)) || !object.Equals(codes[i + 1].operand, deltaGetter)))
				{
					yield return new CodeInstruction(OpCodes.Call, (object)deltaGetter);
					yield return new CodeInstruction(OpCodes.Mul, (object)null);
				}
			}
		}

		private static bool TryGetBodyRendererBounds(Renderer[] renderers, out Bounds bounds)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			bounds = new Bounds(Vector3.zero, Vector3.zero);
			if (renderers == null)
			{
				return false;
			}
			foreach (Renderer val in renderers)
			{
				if ((Object)(object)val == (Object)null || (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer)))
				{
					continue;
				}
				Bounds bounds2 = val.bounds;
				Vector3 size = ((Bounds)(ref bounds2)).size;
				if (!(((Vector3)(ref size)).sqrMagnitude < 1E-06f))
				{
					if (!flag)
					{
						bounds = bounds2;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(bounds2);
					}
				}
			}
			return flag;
		}

		private static bool TryGetVisualBodyRendererBounds(Renderer[] renderers, out Bounds bounds)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			bool flag = false;
			bounds = new Bounds(Vector3.zero, Vector3.zero);
			if (renderers == null)
			{
				return false;
			}
			foreach (Renderer val in renderers)
			{
				if ((Object)(object)val == (Object)null || (!(val is MeshRenderer) && !(val is SkinnedMeshRenderer)))
				{
					continue;
				}
				string text = (((Object)(object)((Component)val).gameObject != (Object)null) ? ((Object)((Component)val).gameObject).name : string.Empty);
				if (text.IndexOf("sword", StringComparison.OrdinalIgnoreCase) >= 0 || text.IndexOf("weapon", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					continue;
				}
				Bounds bounds2 = val.bounds;
				Vector3 size = ((Bounds)(ref bounds2)).size;
				if (!(((Vector3)(ref size)).sqrMagnitude < 1E-06f))
				{
					if (!flag)
					{
						bounds = bounds2;
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(bounds2);
					}
				}
			}
			return flag;
		}

		private static Component GetLocalPlayerAvatar()
		{
			Type type = FindLoadedType("PlayerAvatar");
			if (type == null)
			{
				return null;
			}
			object staticMember = GetStaticMember(type, "instance");
			Component val = (Component)((staticMember is Component) ? staticMember : null);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			Object obj = Object.FindObjectOfType(type);
			return (Component)(object)((obj is Component) ? obj : null);
		}

		private static bool IsHostOrSinglePlayer()
		{
			Type type = FindLoadedType("SemiFunc");
			if (type == null)
			{
				return true;
			}
			MethodInfo method = type.GetMethod("IsMasterClientOrSingleplayer", StaticFlags);
			if (method == null)
			{
				return true;
			}
			object obj = method.Invoke(null, null);
			if (obj is bool)
			{
				return (bool)obj;
			}
			return true;
		}

		private void ShowMissionText(string message, Color color)
		{
			//IL_0091: 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)
			try
			{
				Type type = FindLoadedType("MissionUI");
				if (type == null)
				{
					return;
				}
				object staticMember = GetStaticMember(type, "instance");
				if (staticMember != null)
				{
					MethodInfo method = type.GetMethod("MissionText", InstanceFlags, null, new Type[4]
					{
						typeof(string),
						typeof(Color),
						typeof(Color),
						typeof(float)
					}, null);
					if (method != null)
					{
						method.Invoke(staticMember, new object[4] { message, color, color, 3f });
					}
				}
			}
			catch
			{
			}
		}

		private static object GetStaticMember(Type type, string name)
		{
			FieldInfo field = type.GetField(name, StaticFlags);
			if (field != null)
			{
				return field.GetValue(null);
			}
			PropertyInfo property = type.GetProperty(name, StaticFlags);
			if (!(property == null))
			{
				return property.GetValue(null, null);
			}
			return null;
		}

		private static void SetMember(object instance, string name, object value)
		{
			if (instance == null)
			{
				return;
			}
			Type type = instance.GetType();
			FieldInfo field = type.GetField(name, InstanceFlags);
			if (field != null)
			{
				field.SetValue(instance, value);
				return;
			}
			PropertyInfo property = type.GetProperty(name, InstanceFlags);
			if (property != null && property.CanWrite)
			{
				property.SetValue(instance, value, null);
			}
		}

		private static int GetCollectionCount(object value)
		{
			if (value == null)
			{
				return 0;
			}
			if (value is ICollection collection)
			{
				return collection.Count;
			}
			PropertyInfo property = value.GetType().GetProperty("Count", InstanceFlags);
			object obj = ((property == null) ? null : property.GetValue(value, null));
			if (!(obj is int))
			{
				return 0;
			}
			return (int)obj;
		}

		private static Type FindLoadedType(string fullName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType(fullName, throwOnError: false);
				if (type != null)
				{
					return type;
				}
			}
			return null;
		}

		private static Assembly FindAssembly(string simpleName)
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				if (string.Equals(assemblies[i].GetName().Name, simpleName, StringComparison.OrdinalIgnoreCase))
				{
					return assemblies[i];
				}
			}
			return null;
		}

		private void CleanupFailedBuild()
		{
			_registered = false;
			_cloneSetup = null;
			_spawnEnemyMethod = null;
			if ((Object)(object)_prefabHolder != (Object)null)
			{
				Object.Destroy((Object)(object)_prefabHolder);
			}
			_prefabHolder = null;
		}

		private static string Unwrap(Exception exception)
		{
			if (!(exception is TargetInvocationException { InnerException: not null } ex))
			{
				return exception.ToString();
			}
			return ex.InnerException.ToString();
		}
	}
	internal sealed class RunnerWorldCollisionGuard : MonoBehaviour
	{
		private const float Radius = 0.29f;

		private const float LowerHeight = 0.3f;

		private const float UpperHeight = 1.46f;

		private const float MaxStepDistance = 4.5f;

		private const float ResetAfterSeconds = 0.45f;

		private Vector3 _lastPosition;

		private float _lastCallTime;

		private bool _initialized;

		private bool _reportedBlock;

		public void ResolveAfterMovement()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003f: 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_004b: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: 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_0084: 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_008c: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_01ea: 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)
			float time = Time.time;
			Vector3 position = ((Component)this).transform.position;
			if (!_initialized || time - _lastCallTime > 0.45f)
			{
				_lastPosition = position;
				_lastCallTime = time;
				_initialized = true;
				return;
			}
			Vector3 val = position - _lastPosition;
			val.y = 0f;
			float magnitude = ((Vector3)(ref val)).magnitude;
			if (magnitude > 4.5f)
			{
				_lastPosition = position;
				_lastCallTime = time;
				return;
			}
			if (magnitude > 0.001f)
			{
				Vector3 val2 = val / magnitude;
				Vector3 val3 = _lastPosition + Vector3.up * 0.3f;
				Vector3 val4 = _lastPosition + Vector3.up * 1.46f;
				RaycastHit[] array = Physics.CapsuleCastAll(val3, val4, 0.29f, val2, magnitude + 0.04f, -1, (QueryTriggerInteraction)1);
				float num = float.MaxValue;
				Collider val5 = null;
				for (int i = 0; i < array.Length; i++)
				{
					Collider collider = ((RaycastHit)(ref array[i])).collider;
					if (!((Object)(object)collider == (Object)null) && !collider.isTrigger)
					{
						Transform transform = ((Component)collider).transform;
						if (!((Object)(object)transform == (Object)(object)((Component)this).transform) && !transform.IsChildOf(((Component)this).transform) && !((Component)this).transform.IsChildOf(transform) && !IsPlayerCollider(collider) && !(((RaycastHit)(ref array[i])).normal.y > 0.68f) && ((RaycastHit)(ref array[i])).distance < num)
						{
							num = ((RaycastHit)(ref array[i])).distance;
							val5 = collider;
						}
					}
				}
				if ((Object)(object)val5 != (Object)null)
				{
					float num2 = Mathf.Clamp(num - 0.05f, 0f, magnitude);
					Vector3 position2 = _lastPosition + val2 * num2;
					position2.y = position.y;
					((Component)this).transform.position = position2;
					if (!_reportedBlock)
					{
						_reportedBlock = true;
						Debug.Log((object)("[RunnerTestClone] Clone movement was clamped by world collider '" + ((Object)val5).name + "'."));
					}
				}
			}
			_lastPosition = ((Component)this).transform.position;
			_lastCallTime = time;
		}

		private static bool IsPlayerCollider(Collider collider)
		{
			Type type = FindPlayerAvatarType();
			if (type == null || (Object)(object)collider == (Objec