Decompiled source of SpiderPositionFix v1.5.1

DLLs/fandovec03.SpiderPositionFix.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SpiderPositionFix.Patches;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;

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

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

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

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SpiderPositionFix
{
	[BepInPlugin("fandovec03.SpiderPositionFix", "SpiderPositionFix", "1.5.1")]
	public class InitialScript : BaseUnityPlugin
	{
		public static AssetBundle SpiderAssets;

		public static InitialScript Instance { get; private set; }

		internal static ManualLogSource Logger { get; private set; }

		internal static Harmony? Harmony { get; set; }

		internal static ConfigClass configSettings { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			configSettings = new ConfigClass(((BaseUnityPlugin)this).Config);
			Patch();
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			SpiderAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "spideranimationfixbundle"));
			if ((Object)(object)SpiderAssets == (Object)null)
			{
				Logger.LogError((object)"Failed to load Assets");
			}
			Logger.LogInfo((object)"fandovec03.SpiderPositionFix v1.5.1 has loaded!");
		}

		internal static void Patch()
		{
			//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_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("fandovec03.SpiderPositionFix");
			}
			Logger.LogDebug((object)"Patching spider position fix...");
			Harmony.PatchAll(typeof(SpiderPositionPatch));
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching spider position fix...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	internal class ConfigClass
	{
		public readonly ConfigEntry<bool> applyMask;

		public readonly ConfigEntry<bool> debugLogs;

		public readonly ConfigEntry<bool> debugVisuals;

		public ConfigClass(ConfigFile cfg)
		{
			cfg.SaveOnConfigSet = false;
			applyMask = cfg.Bind<bool>("Settings", "Apply changes to agent areaMask", true, "Apply the changes made to the spider agent areaMask. This will affect the pathfinding over offMeshLinks");
			debugLogs = cfg.Bind<bool>("Debug", "Debug logs", false, "Enable debug logs");
			debugVisuals = cfg.Bind<bool>("Debug", "Debug visuals", false, "Enable visual debug tools.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		public void ClearOrphanedEntries(ConfigFile cfg)
		{
			PropertyInfo propertyInfo = AccessTools.Property(typeof(ConfigFile), "OrphanedEntries");
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)propertyInfo.GetValue(cfg);
			dictionary.Clear();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "fandovec03.SpiderPositionFix";

		public const string PLUGIN_NAME = "SpiderPositionFix";

		public const string PLUGIN_VERSION = "1.5.1";
	}
}
namespace SpiderPositionFix.Patches
{
	internal class spiderPositionData
	{
		public int currentJumpMaskBit = 1;

		public bool startPatch = false;

		public bool applySpeedSlowdown = false;

		public float originalSpeed = 4.25f;

		public float offsetSpeed = 0f;

		public float reachedWallTimer = 0f;

		public float delayTimer = 0f;

		public int delayTimes = 0;

		public bool reachTheWallFail = false;

		public Dictionary<int, GameObject> debugObjects = new Dictionary<int, GameObject>();

		public float time = 0.2f;

		public Vector3 originalWallPosition = Vector3.zero;

		public float invalidPositionTimer = 0f;

		public int faildetToGetPositionTimes = 0;

		public Transform altWallPosForMesh = new Transform();
	}
	[HarmonyPatch(typeof(SandSpiderAI))]
	public class SpiderPositionPatch
	{
		private static bool debugLogs = InitialScript.configSettings.debugLogs.Value;

		private static bool debugVisals = InitialScript.configSettings.debugVisuals.Value;

		private static Dictionary<SandSpiderAI, spiderPositionData> spiderData = new Dictionary<SandSpiderAI, spiderPositionData>();

		private static GameObject ballPrefab;

		private static Material whiteBall;

		private static Material redBall;

		private static Material blueBall;

		private static Material greenBall;

		private static Material yellowBall;

		public static Transform getWallPosTransform(SandSpiderAI instance)
		{
			string text = "";
			if (spiderData[instance].faildetToGetPositionTimes > 10)
			{
				text = "homeNode instance.homeNode";
				spiderData[instance].altWallPosForMesh = instance.homeNode;
			}
			else
			{
				text = "transform instance.transform";
				spiderData[instance].altWallPosForMesh = ((Component)instance).transform;
			}
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)("Returning " + text));
			}
			return spiderData[instance].altWallPosForMesh;
		}

		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		private static void StartPostfix(SandSpiderAI __instance)
		{
			if ((Object)(object)InitialScript.SpiderAssets != (Object)null)
			{
				try
				{
					AnimatorOverrideController runtimeAnimatorController = InitialScript.SpiderAssets.LoadAsset<AnimatorOverrideController>("Assets/LethalCompany/CustomAnims/SandSpider/Spider Anim Override.overrideController");
					if (debugVisals)
					{
						try
						{
							ballPrefab = InitialScript.SpiderAssets.LoadAsset<GameObject>("Assets/LethalCompany/CustomAnims/SandSpider/WhiteBall.prefab");
							whiteBall = InitialScript.SpiderAssets.LoadAsset<Material>("Assets/LethalCompany/CustomAnims/SandSpider/WhiteBallMat.mat");
							redBall = InitialScript.SpiderAssets.LoadAsset<Material>("Assets/LethalCompany/CustomAnims/SandSpider/RedBallMat.mat");
							blueBall = InitialScript.SpiderAssets.LoadAsset<Material>("Assets/LethalCompany/CustomAnims/SandSpider/BlueBallMat.mat");
							greenBall = InitialScript.SpiderAssets.LoadAsset<Material>("Assets/LethalCompany/CustomAnims/SandSpider/GreenBallMat.mat");
							yellowBall = InitialScript.SpiderAssets.LoadAsset<Material>("Assets/LethalCompany/CustomAnims/SandSpider/YellowBallMat.mat");
						}
						catch (Exception ex)
						{
							InitialScript.Logger.LogWarning((object)"Failed to load visual debug asset");
							InitialScript.Logger.LogWarning((object)ex);
						}
					}
					((EnemyAI)__instance).creatureAnimator.runtimeAnimatorController = (RuntimeAnimatorController)(object)runtimeAnimatorController;
				}
				catch
				{
					InitialScript.Logger.LogError((object)"Failed to load OverrideController asset");
				}
			}
			if (!spiderData.ContainsKey(__instance))
			{
				spiderData.Add(__instance, new spiderPositionData());
			}
			spiderData[__instance].startPatch = true;
			spiderData[__instance].altWallPosForMesh = ((Component)__instance).transform;
		}

		[HarmonyPatch("Update")]
		[HarmonyPrefix]
		private static void UpdatePrefix(SandSpiderAI __instance)
		{
			spiderPositionData spiderPositionData2 = spiderData[__instance];
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				if (spiderPositionData2.time > 0f)
				{
					spiderPositionData2.time -= Time.deltaTime;
				}
				if (__instance.reachedWallPosition && ((Behaviour)((EnemyAI)__instance).agent).enabled && ((EnemyAI)__instance).agent.avoidancePriority == 25)
				{
					((EnemyAI)__instance).agent.avoidancePriority = 99;
					((Behaviour)((EnemyAI)__instance).agent).enabled = false;
				}
				if (!((Behaviour)((EnemyAI)__instance).agent).enabled && (!__instance.onWall || __instance.waitOnWallTimer <= 0f) && ((EnemyAI)__instance).agent.avoidancePriority == 99)
				{
					((EnemyAI)__instance).agent.avoidancePriority = 25;
					((Behaviour)((EnemyAI)__instance).agent).enabled = true;
					if (!__instance.onWall)
					{
					}
				}
			}
			else if (spiderPositionData2.time <= 0f)
			{
				spiderPositionData2.time = 0f;
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void UpdatePostfix(SandSpiderAI __instance)
		{
			spiderPositionData spiderPositionData2 = spiderData[__instance];
			if (!((NetworkBehaviour)__instance).IsOwner)
			{
				return;
			}
			if (spiderPositionData2.invalidPositionTimer > 0f)
			{
				spiderPositionData2.invalidPositionTimer -= Time.deltaTime;
			}
			if (InitialScript.configSettings.applyMask.Value)
			{
				if (((EnemyAI)__instance).isOutside && spiderPositionData2.currentJumpMaskBit != 1)
				{
					ChangeJumpMask(__instance, ref spiderPositionData2.currentJumpMaskBit);
					spiderPositionData2.currentJumpMaskBit = 1;
				}
				else if (!((EnemyAI)__instance).isOutside && spiderPositionData2.currentJumpMaskBit != 0)
				{
					ChangeJumpMask(__instance, ref spiderPositionData2.currentJumpMaskBit);
					spiderPositionData2.currentJumpMaskBit = 0;
				}
			}
			if (__instance.watchFromDistance)
			{
				return;
			}
			if (!__instance.onWall)
			{
				__instance.spiderSpeed = ((EnemyAI)__instance).agent.speed;
				if (((EnemyAI)__instance).agent.isOnOffMeshLink)
				{
					((EnemyAI)__instance).agent.speed = spiderPositionData2.originalSpeed / 1.15f;
					if (debugLogs)
					{
						InitialScript.Logger.LogDebug((object)"On offMeshLink. Cutting speed");
					}
				}
			}
			else
			{
				__instance.spiderSpeed = 3.75f;
				if (__instance.onWall)
				{
					((EnemyAI)__instance).agent.speed = 0f;
				}
			}
			if (__instance.reachedWallPosition)
			{
				spiderData[__instance].reachTheWallFail = false;
			}
		}

		[HarmonyPatch("LateUpdate")]
		[HarmonyPostfix]
		private static void MeshContainerPositionFix(SandSpiderAI __instance)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: 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_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: 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_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			spiderPositionData spiderPositionData2 = spiderData[__instance];
			if (((NetworkBehaviour)__instance).IsOwner)
			{
				if (!spiderPositionData2.startPatch)
				{
					return;
				}
				if (!__instance.onWall && !((EnemyAI)__instance).agent.isOnOffMeshLink && Vector3.Distance(__instance.meshContainer.position, ((Component)__instance).transform.position) > 0.35f)
				{
					Vector3 velocity = ((EnemyAI)__instance).agent.velocity;
					if (((Vector3)(ref velocity)).magnitude > 3f && ((EnemyAI)__instance).agent.speed > 0.5f)
					{
						Vector3 position = ((Component)__instance).transform.position;
						velocity = ((EnemyAI)__instance).agent.velocity;
						__instance.meshContainerTarget = position + ((Vector3)(ref velocity)).normalized * 1.25f;
					}
					else
					{
						__instance.meshContainerTarget = ((Component)__instance).transform.position + ((EnemyAI)__instance).agent.velocity * Time.deltaTime;
					}
				}
			}
			if (__instance.onWall || __instance.gotWallPositionInLOS || !debugVisals)
			{
				return;
			}
			foreach (GameObject item in spiderPositionData2.debugObjects.Values.ToList())
			{
				Object.Destroy((Object)(object)item);
			}
			spiderPositionData2.debugObjects.Clear();
			GameObject spawningPrefab = ballPrefab;
			InstantiateVisalTool(__instance, spawningPrefab, yellowBall, "path1 corner #1", -5, __instance.meshContainer.position + ((EnemyAI)__instance).agent.velocity * Time.deltaTime * -1f);
			InstantiateVisalTool(__instance, spawningPrefab, greenBall, "refVel", -4, __instance.meshContainer.position + __instance.refVel);
			InstantiateVisalTool(__instance, spawningPrefab, redBall, "meshContainerTarget", -3, __instance.meshContainerTarget);
			InstantiateVisalTool(__instance, spawningPrefab, blueBall, "meshContainerServerPosition", -2, __instance.meshContainerServerPosition);
		}

		[HarmonyPatch("CalculateMeshMovement")]
		[HarmonyPrefix]
		private static bool MeshMovementPatch(SandSpiderAI __instance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.lookingForWallPosition && __instance.gotWallPositionInLOS && !__instance.onWall)
			{
				float num = Vector3.Distance(((Component)__instance).transform.position, __instance.floorPosition);
				float num2 = Vector3.Distance(__instance.meshContainer.position, __instance.floorPosition);
				if (spiderData[__instance].delayTimer > 1f)
				{
					if (debugLogs)
					{
						InitialScript.Logger.LogDebug((object)("distanceFromFloorPosition: " + num));
						InitialScript.Logger.LogDebug((object)("distanceFromFloorPositionMesh: " + num2));
					}
					spiderData[__instance].delayTimer = 0f;
					spiderData[__instance].delayTimes++;
					if (spiderData[__instance].delayTimes >= 20)
					{
						InitialScript.Logger.LogWarning((object)(((object)__instance)?.ToString() + ", NWID " + ((NetworkBehaviour)__instance).NetworkObjectId + " failing to climb walls within set timer!"));
						spiderData[__instance].delayTimes = 0;
					}
				}
				else
				{
					spiderData[__instance].delayTimer += Time.deltaTime;
				}
				((EnemyAI)__instance).SetDestinationToPosition(__instance.floorPosition, false);
				__instance.CalculateSpiderPathToPosition();
				if (num < 0.7f && num2 < 0.7f)
				{
					__instance.onWall = true;
					spiderData[__instance].delayTimes = 0;
					return true;
				}
				return false;
			}
			return true;
		}

		[HarmonyPatch("CalculateMeshMovement")]
		[HarmonyPostfix]
		private static void MeshMovementPostfixPatch(SandSpiderAI __instance)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: 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_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			if (__instance.onWall)
			{
				return;
			}
			if (((EnemyAI)__instance).agent.isOnOffMeshLink)
			{
				__instance.meshContainer.position = Vector3.Lerp(__instance.meshContainer.position, ((Component)((EnemyAI)__instance).agent).transform.position, Distance(Vector3.Distance(__instance.meshContainer.position, ((Component)__instance).transform.position), 0.5f));
				__instance.meshContainerPosition = __instance.meshContainer.position;
				Quaternion rotation = __instance.meshContainer.rotation;
				OffMeshLinkData currentOffMeshLinkData = ((EnemyAI)__instance).agent.currentOffMeshLinkData;
				__instance.meshContainerTargetRotation = Quaternion.Lerp(rotation, Quaternion.LookRotation(((OffMeshLinkData)(ref currentOffMeshLinkData)).endPos - __instance.meshContainer.position, Vector3.up), 0.75f);
				return;
			}
			Vector3 velocity;
			if (spiderData[__instance].time <= 0f && debugLogs)
			{
				ManualLogSource logger = InitialScript.Logger;
				velocity = ((EnemyAI)__instance).agent.velocity;
				logger.LogDebug((object)((Vector3)(ref velocity)).magnitude);
				spiderData[__instance].time = 0.4f;
			}
			velocity = ((EnemyAI)__instance).agent.velocity;
			if (((Vector3)(ref velocity)).magnitude > 3f && !__instance.overrideSpiderLookRotation)
			{
				velocity = ((EnemyAI)__instance).agent.velocity;
				__instance.meshContainerTargetRotation = Quaternion.LookRotation(((Vector3)(ref velocity)).normalized * Time.deltaTime, Vector3.up);
			}
			velocity = ((EnemyAI)__instance).agent.velocity;
			if (((Vector3)(ref velocity)).magnitude > 3f && ((EnemyAI)__instance).agent.speed > 0.5f)
			{
				Vector3 position = ((Component)__instance).transform.position;
				velocity = ((EnemyAI)__instance).agent.velocity;
				__instance.navigateToPositionTarget = position + ((Vector3)(ref velocity)).normalized * 1.25f;
			}
			else
			{
				__instance.navigateToPositionTarget = ((Component)__instance).transform.position + ((EnemyAI)__instance).agent.velocity;
			}
		}

		private static float Distance(float distance, float time)
		{
			return distance / time;
		}

		private static void ChangeJumpMask(SandSpiderAI __instance, ref int bit)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				NavMeshAgent agent = ((EnemyAI)__instance).agent;
				agent.areaMask ^= 1 << NavMesh.GetAreaFromName("Jump");
				if (bit == 0)
				{
					bit = 1;
				}
				else if (bit == 1)
				{
					bit = 0;
				}
				if (debugLogs)
				{
					InitialScript.Logger.LogDebug((object)("Spider: Toggled mask bit to " + bit));
				}
			}
		}

		[HarmonyPatch("GetWallPositionForSpiderMesh")]
		[HarmonyPrefix]
		private static void GetWallPositionForSpiderMeshPrefix(SandSpiderAI __instance)
		{
			//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)
			__instance.floorPosition = Vector3.zero;
		}

		[HarmonyPatch("GetWallPositionForSpiderMesh")]
		[HarmonyPostfix]
		private static void GetWallPositionForSpiderMeshPatch(SandSpiderAI __instance, ref bool __result)
		{
			//IL_000f: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_004c: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0af7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0afc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Invalid comparison between Unknown and I4
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Invalid comparison between Unknown and I4
			//IL_06ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_070a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0931: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Invalid comparison between Unknown and I4
			//IL_03fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0406: Unknown result type (might be due to invalid IL or missing references)
			//IL_0407: Unknown result type (might be due to invalid IL or missing references)
			//IL_0409: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_042b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0435: Unknown result type (might be due to invalid IL or missing references)
			//IL_0451: Unknown result type (might be due to invalid IL or missing references)
			//IL_046c: Unknown result type (might be due to invalid IL or missing references)
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04db: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Invalid comparison between Unknown and I4
			//IL_0504: 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_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_050f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0513: Unknown result type (might be due to invalid IL or missing references)
			//IL_051a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0521: Unknown result type (might be due to invalid IL or missing references)
			//IL_0541: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_0545: Unknown result type (might be due to invalid IL or missing references)
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_0551: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_062b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0630: Unknown result type (might be due to invalid IL or missing references)
			//IL_060a: Unknown result type (might be due to invalid IL or missing references)
			//IL_09ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a01: Unknown result type (might be due to invalid IL or missing references)
			spiderPositionData spiderPositionData2 = spiderData[__instance];
			NavMeshHit val = default(NavMeshHit);
			Vector3 val2 = __instance.wallPosition + __instance.wallNormal;
			Vector3 val3 = default(Vector3);
			((Vector3)(ref val3))..ctor(val2.x, __instance.wallPosition.y, val2.z);
			NavMeshPath val4 = new NavMeshPath();
			Vector3 point = ((RaycastHit)(ref __instance.rayHit)).point;
			List<int> list = new List<int>();
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)$"Test | WallPosition: {__instance.wallPosition}, unmodifiedWallPosition: {point}");
			}
			if (__instance.floorPosition == Vector3.zero || RoundManager.Instance.GetNavMeshPosition(__instance.floorPosition, val, 0.7f, -1) == __instance.floorPosition || !((EnemyAI)__instance).agent.CalculatePath(__instance.floorPosition, val4) || (int)val4.status == 1 || (int)val4.status == 2)
			{
				if (spiderPositionData2.invalidPositionTimer <= 0f)
				{
					InitialScript.Logger.LogWarning((object)"failed to get valid position for floorPosition.");
					spiderPositionData2.invalidPositionTimer = 5f;
				}
				Vector3 zero = Vector3.zero;
				for (int i = 0; i < 4; i++)
				{
					zero = Vector3.Lerp(point, val3, (float)(i + 1) / 4f);
					Vector3 val5 = Vector3.zero;
					RaycastHit val6 = default(RaycastHit);
					if (Physics.Raycast(zero, Vector3.down, ref val6, 20f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
					{
						val5 = ((RaycastHit)(ref val6)).point;
					}
					if (val5 == Vector3.zero || RoundManager.Instance.GetNavMeshPosition(val5, val, 0.7f, -1) == val5 || !((EnemyAI)__instance).agent.CalculatePath(val5, val4) || (int)val4.status == 1 || (int)val4.status == 2)
					{
						__result = false;
						spiderData[__instance].faildetToGetPositionTimes++;
						continue;
					}
					__instance.floorPosition = val5;
					spiderData[__instance].faildetToGetPositionTimes = 0;
					__result = true;
					spiderPositionData2.invalidPositionTimer = 0f;
					InitialScript.Logger.LogMessage((object)"Assigned new floor position.");
					break;
				}
			}
			val4.ClearCorners();
			foreach (GameObject item in spiderPositionData2.debugObjects.Values.ToList())
			{
				Object.Destroy((Object)(object)item);
			}
			spiderPositionData2.debugObjects.Clear();
			if (!debugVisals)
			{
				return;
			}
			Dictionary<int, List<Vector3>> dictionary = new Dictionary<int, List<Vector3>>();
			GameObject val7 = ballPrefab;
			Vector3 val8 = default(Vector3);
			((Vector3)(ref val8))..ctor(__instance.meshContainer.position.x, point.y, __instance.meshContainer.position.z);
			((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(redBall);
			val7.GetComponent<ScanNodeProperties>().headerText = "projected WallPosition";
			float num = Vector3.Distance(__instance.meshContainer.position, val8);
			int num2 = (int)MathF.Round(num * 2f, 0);
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)$"Rounded up {num} to {num2}");
			}
			LineRenderer componentInChildren = val7.GetComponentInChildren<LineRenderer>();
			((Renderer)componentInChildren).SetMaterial(redBall);
			componentInChildren.useWorldSpace = true;
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)"projected wallPosition");
			}
			spiderPositionData2.debugObjects.Add(-1, Object.Instantiate<GameObject>(val7, val8, Quaternion.identity));
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)$"instantiated projectedWallPosition {val8}");
			}
			Vector3 val9 = Vector3.Project(__instance.meshContainer.position - point, val3 - point) + point;
			Vector3 val10 = default(Vector3);
			((Vector3)(ref val10))..ctor(val9.x, __instance.meshContainer.position.y, val9.z);
			dictionary.Add(0, new List<Vector3>(1) { __instance.meshContainer.position });
			dictionary.Add(1, new List<Vector3>(2)
			{
				point,
				((Component)__instance).transform.position
			});
			dictionary.Add(2, new List<Vector3>(2) { __instance.floorPosition, point });
			dictionary.Add(3, new List<Vector3>(2) { val3, point });
			dictionary.Add(4, new List<Vector3>(2) { val9, point });
			Vector3 val12 = default(Vector3);
			Ray val13 = default(Ray);
			RaycastHit val14 = default(RaycastHit);
			for (int j = 1; j < num2; j++)
			{
				float num3 = (float)j / (float)num2;
				Vector3 val11 = Vector3.Lerp(val10, val9, num3);
				((Vector3)(ref val12))..ctor(point.x, val11.y, point.z);
				((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(whiteBall);
				((Ray)(ref val13))..ctor(val11, val12 - val11);
				if (!Physics.Raycast(val13, ref val14, 7f, StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
				{
					InitialScript.Logger.LogWarning((object)"Raycast failed to hit anything within set distance.");
					list.Add(j);
				}
				val7.GetComponent<ScanNodeProperties>().headerText = $"Generated lerpedVector {j}";
				dictionary.Add(4 + j, new List<Vector3>(2)
				{
					((Ray)(ref val13)).GetPoint(((RaycastHit)(ref val14)).distance - 0.2f),
					val11
				});
				if (debugLogs)
				{
					InitialScript.Logger.LogInfo((object)$"set wallVector[{j}] to {dictionary[4 + j][0]}");
				}
				if (dictionary[4 + j][0] == Vector3.zero)
				{
					InitialScript.Logger.LogWarning((object)"Invalid raycast position detected");
				}
			}
			if (debugLogs)
			{
				InitialScript.Logger.LogInfo((object)$"final splitNum count = {num2}");
				InitialScript.Logger.LogInfo((object)$"total count = {num2}");
			}
			for (int k = 0; k < 4 + num2; k++)
			{
				InitialScript.Logger.LogInfo((object)$"Processing wallVector[{k}] |{k}|");
				try
				{
					bool flag = !Physics.Linecast(__instance.floorPosition, dictionary[k][0], StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) || !Physics.Linecast(val3, dictionary[k][0], StartOfRound.Instance.collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1);
					switch (k)
					{
					case 0:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(greenBall);
						val7.GetComponent<ScanNodeProperties>().headerText = "meshContainer position";
						((Object)val7.gameObject).name = $"meshContainer position {k}";
						break;
					case 1:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(blueBall);
						val7.GetComponent<ScanNodeProperties>().headerText = "wall position";
						((Object)val7.gameObject).name = $"wall position {k}";
						break;
					case 2:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(yellowBall);
						val7.GetComponent<ScanNodeProperties>().headerText = "floor position";
						((Object)val7.gameObject).name = $"floor position {k}";
						break;
					case 3:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(blueBall);
						val7.GetComponent<ScanNodeProperties>().headerText = "projected normal position";
						((Object)val7.gameObject).name = $"projected normal position {k}";
						break;
					case 4:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(blueBall);
						val7.GetComponent<ScanNodeProperties>().headerText = "projected meshContainer position on Normal";
						((Object)val7.gameObject).name = $"projected meshContainer position on Normal {k}";
						break;
					default:
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).SetMaterial(whiteBall);
						val7.GetComponent<ScanNodeProperties>().headerText = $"Generated position {k}";
						((Object)val7.gameObject).name = $"Generated position {k}";
						break;
					}
					if (debugLogs)
					{
						InitialScript.Logger.LogInfo((object)$"Successfully spawned ball at {dictionary[k][0]} |{k}|");
					}
					if (k > 4 && flag)
					{
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).material = yellowBall;
					}
					if (k > 4 && list.Contains(k))
					{
						((Renderer)val7.GetComponentInChildren<MeshRenderer>()).material = redBall;
					}
					if (dictionary[k].Count > 1)
					{
						if (debugLogs)
						{
							InitialScript.Logger.LogInfo((object)"Found multiple vectors");
						}
						try
						{
							InitialScript.Logger.LogInfo((object)$"Setting rendered line for {k}, 0: {dictionary[k][0]}, 1: {dictionary[k][1]}");
							componentInChildren = val7.GetComponentInChildren<LineRenderer>();
							((Renderer)componentInChildren).material = ((Renderer)val7.GetComponentInChildren<MeshRenderer>()).sharedMaterial;
							componentInChildren.useWorldSpace = true;
							((Object)((Component)componentInChildren).gameObject).name = $"{((Object)val7.gameObject).name} {k}";
							InitialScript.Logger.LogInfo((object)$"Set name for {k}, 0: {((Object)((Component)componentInChildren).gameObject).name}, 1: {((Object)val7.gameObject).name}");
							SetRenderedLinePoints(dictionary[k].ToArray(), componentInChildren);
						}
						catch (Exception ex)
						{
							InitialScript.Logger.LogError((object)$"failed to spawn a ray |{k}|");
							InitialScript.Logger.LogError((object)ex);
						}
					}
					spiderPositionData2.debugObjects.Add(k, Object.Instantiate<GameObject>(val7, dictionary[k][0], Quaternion.identity));
				}
				catch (Exception ex2)
				{
					InitialScript.Logger.LogError((object)$"failed to spawn a ball |{k}|");
					InitialScript.Logger.LogError((object)ex2);
				}
			}
		}

		public static void SetRenderedLinePoints(Vector3[] positions, LineRenderer lr)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			lr.positionCount = positions.Length;
			for (int i = 0; i < lr.positionCount; i++)
			{
				if (lr.positionCount < 2)
				{
					break;
				}
				lr.SetPosition(i, positions[i]);
			}
		}

		public static void InstantiateVisalTool(SandSpiderAI __instance, GameObject spawningPrefab, Material material, string headerText, int index, Vector3 position)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			spiderPositionData spiderPositionData2 = spiderData[__instance];
			((Renderer)spawningPrefab.GetComponentInChildren<MeshRenderer>()).material = material;
			spawningPrefab.GetComponent<ScanNodeProperties>().headerText = headerText;
			spiderPositionData2.debugObjects.Add(index, Object.Instantiate<GameObject>(spawningPrefab, position, Quaternion.identity));
		}
	}
}