Decompiled source of AutoFollowPath v1.6.1

plugins\AutoFollowPath.dll

Decompiled a month ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Configs;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JotunnModStub")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JotunnModStub")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace AutoFollowPath;

[BepInPlugin("org.bepinex.plugins.bid.autofollowpath", "AutoFollowPath", "1.6.1")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class AutoFollowPath : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Character), "GetRunSpeedFactor")]
	private class Character_GetRunSpeedFactor_patch
	{
		private static void Postfix(Character __instance, ref float __result)
		{
			if ((Object)(object)__instance == (Object)(object)m_mount && __instance.HaveRider())
			{
				__result *= MountSpeedModifierFactorConfig.Value;
				float num = MountSpeedGroupModifierFactorConfig.Value * (float)m_fellowRiderCount;
				if (num > MaxMountSpeedGroupModifierFactorConfig.Value)
				{
					num = MaxMountSpeedGroupModifierFactorConfig.Value;
				}
				__result *= 1f + num;
			}
		}
	}

	[HarmonyPatch(typeof(Sadle), "UseStamina")]
	private class Sadle_UseStamina_patch
	{
		private static void Prefix(ref float v)
		{
			v *= MountStaminaModifierFactorConfig.Value;
			float num = MountStaminaGroupModifierFactorConfig.Value * (float)m_fellowRiderCount;
			if (num > MaxMountStaminaGroupModifierFactorConfig.Value)
			{
				num = MountStaminaGroupModifierFactorConfig.Value;
			}
			v *= 1f - num;
		}
	}

	internal class DebugObject
	{
		public Vector3 source;

		public Vector3 target;

		public float weight;

		public bool colorError;

		public bool slopeError;

		public Color targetColor;

		public float targetHeight;

		public bool collission;

		public bool onStructure;

		public bool isCheck;

		public bool succeeded;
	}

	[HarmonyPatch(typeof(Player), "SetControls")]
	public class Player_SetControls_patch
	{
		private static void Prefix(Player __instance, ref bool run, Vector3 movedir)
		{
			if (IsSprint && (GlobalSprintToggleConfig.Value || __instance.m_autoRun))
			{
				if (IsExhausted && __instance.m_stamina >= __instance.m_maxStamina)
				{
					IsExhausted = false;
				}
				if (!IsExhausted && __instance.m_stamina > StaminaMinThresholdConfig.Value)
				{
					run = true;
				}
				else
				{
					IsExhausted = true;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Player), "Update")]
	private class Player_UpdateInput
	{
		private static void Prefix(Player __instance)
		{
			//IL_0005: 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)
			KeyboardShortcut value = AutoSprintShortcut.Value;
			if ((((KeyboardShortcut)(ref value)).IsDown() || ZInput.GetButtonDown(AutoSprintButtonConfig.Name)) && (GlobalSprintToggleConfig.Value || __instance.m_autoRun))
			{
				if (IsSprint)
				{
					IsExhausted = false;
				}
				IsSprint = !IsSprint;
			}
		}
	}

	public const string PluginGUID = "org.bepinex.plugins.bid.autofollowpath";

	public const string PluginName = "AutoFollowPath";

	public const string PluginVersion = "1.6.1";

	public static ConfigEntry<bool> GlobalSprintToggleConfig;

	public static ConfigEntry<float> StaminaMinThresholdConfig;

	public static ConfigEntry<int> UpdateTimeMillisConfig;

	public static ConfigEntry<int> MaxAngleConfig;

	public static ConfigEntry<int> NumAnglesConfig;

	public static ConfigEntry<int> MaxDistanceConfig;

	public static ConfigEntry<int> PathPointsConfig;

	public static ConfigEntry<float> PathToleranceConfig;

	public static ConfigEntry<float> AngleWeightFactorConfig;

	public static ConfigEntry<float> DistanceWeightFactorConfig;

	public static ConfigEntry<float> MaxInclineConfig;

	public static ConfigEntry<bool> PavedOnlyConfig;

	public static ConfigEntry<bool> EnabledConfig;

	public static ConfigEntry<bool> VisualDebugConfig;

	public static ConfigEntry<float> HeightmapSearchRadiusConfig;

	public static ConfigEntry<float> RaycastHeightConfig;

	public static ConfigEntry<float> CollissionHeightIncreaseConfig;

	public static ConfigEntry<float> CollissionRayLengthDownConfig;

	public static ConfigEntry<float> NearCollissionDetectionAngleConfig;

	public static ConfigEntry<float> NearCollissionCorrectionAngleConfig;

	public static ConfigEntry<float> NearCollissionDetectionLengthScaleConfig;

	public static ConfigEntry<float> RidingDistanceFactorConfig;

	public static ConfigEntry<bool> NearCollissionDetectionEnabledConfig;

	public static ConfigEntry<float> MountSpeedModifierFactorConfig;

	public static ConfigEntry<float> MountSpeedGroupModifierFactorConfig;

	public static ConfigEntry<float> MaxMountSpeedGroupModifierFactorConfig;

	public static ConfigEntry<float> MountStaminaModifierFactorConfig;

	public static ConfigEntry<float> MountStaminaGroupModifierFactorConfig;

	public static ConfigEntry<float> MaxMountStaminaGroupModifierFactorConfig;

	public static ConfigEntry<int> FellowRiderDistanceConfig;

	public static ConfigEntry<KeyboardShortcut> AutoSprintShortcut;

	public static ButtonConfig AutoSprintButtonConfig;

	private static Shader LegacyShader = null;

	private static Material LineMaterial = null;

	private static bool IsSprint = false;

	private static bool IsExhausted = false;

	public static string[] mask_default = new string[8] { "piece", "terrain", "piece_nonsolid", "static_solid", "Default", "vehicle", "pathblocker", "character" };

	public static string[] mask_riding = new string[7] { "piece", "terrain", "piece_nonsolid", "static_solid", "Default", "vehicle", "pathblocker" };

	private float m_updateTimer;

	private readonly Harmony harmony = new Harmony("org.bepinex.plugins.bid.autofollowpath");

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private static SortedList<float, SortedList<int, DebugObject>> rayCasts = new SortedList<float, SortedList<int, DebugObject>>();

	private static List<LineRenderer> lineRendrerList = new List<LineRenderer>();

	private static List<GameObject> textList = new List<GameObject>();

	private static Character m_mount = null;

	private static int m_fellowRiderCount = 0;

	private static bool IsPath(Color color)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: 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_001e: Unknown result type (might be due to invalid IL or missing references)
		if (ColorsAreEqual(color, Heightmap.m_paintMaskPaved))
		{
			return true;
		}
		if (PavedOnlyConfig.Value)
		{
			return false;
		}
		if (ColorsAreEqual(color, Heightmap.m_paintMaskDirt))
		{
			return true;
		}
		return false;
	}

	private static bool ColorsAreEqual(Color color1, Color color2)
	{
		//IL_000b: 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_0020: 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_0035: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		float value = PathToleranceConfig.Value;
		if (Mathf.Abs(color1.r - color2.r) <= value && Mathf.Abs(color1.g - color2.g) <= value && Mathf.Abs(color1.b - color2.b) <= value)
		{
			return Mathf.Abs(color1.a - color2.a) <= value;
		}
		return false;
	}

	private static bool CollissionDetected(Vector3 targetPosition, float lastHeight, float targetHeight, Vector3 lastPosition, Vector3 direction, float pathLength, out float heightDiff, DebugObject dobj, bool noPathCheck = false)
	{
		//IL_0045: 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_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_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_0056: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: 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_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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_0092: 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_00a3: 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)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0079: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d2: 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_00f8: 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_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: 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_0197: 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_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_023f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0242: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: 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_024d: 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)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: 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)
		int mask = LayerMask.GetMask(mask_default);
		if (IsRiding())
		{
			mask = LayerMask.GetMask(mask_riding);
		}
		heightDiff = 0f;
		float value = RaycastHeightConfig.Value;
		lastPosition.y = lastHeight + value;
		targetPosition.y = targetHeight + value;
		direction = targetPosition - lastPosition;
		((Vector3)(ref direction)).Normalize();
		pathLength = Vector3.Distance(lastPosition, targetPosition);
		RaycastHit val = default(RaycastHit);
		bool flag = Physics.Raycast(lastPosition, direction, ref val, pathLength, mask);
		Vector3 val2 = targetPosition;
		if (flag)
		{
			val2 = ((RaycastHit)(ref val)).point;
		}
		val2.y += CollissionHeightIncreaseConfig.Value;
		val2 += direction * 0.005f;
		RaycastHit val3 = default(RaycastHit);
		bool num = Physics.Raycast(val2, Vector3.down, ref val3, CollissionRayLengthDownConfig.Value, mask);
		if (VisualDebugConfig.Value)
		{
			LineRenderer val4 = new GameObject("Line").AddComponent<LineRenderer>();
			((Renderer)val4).material = LineMaterial;
			val4.startColor = Color.black;
			val4.endColor = Color.black;
			val4.startWidth = 0.02f;
			val4.endWidth = 0.02f;
			val4.positionCount = 2;
			val4.useWorldSpace = true;
			val4.SetPosition(0, val2);
			val4.SetPosition(1, val2 + Vector3.down * CollissionRayLengthDownConfig.Value);
			lineRendrerList.Add(val4);
		}
		if (!num)
		{
			dobj.slopeError = true;
			dobj.target.y -= CollissionRayLengthDownConfig.Value;
			return true;
		}
		if (((RaycastHit)(ref val3)).point.y < ((RaycastHit)(ref val)).point.y)
		{
			((RaycastHit)(ref val3)).point = val2;
		}
		heightDiff = ((RaycastHit)(ref val3)).point.y - (lastPosition.y - value);
		float num2 = pathLength;
		if (flag)
		{
			num2 = ((RaycastHit)(ref val)).distance;
		}
		if (heightDiff != 0f && num2 / Math.Abs(heightDiff) < MaxInclineConfig.Value)
		{
			dobj.target = ((RaycastHit)(ref val3)).point;
			dobj.targetHeight = dobj.target.y;
			if (heightDiff < 0f)
			{
				dobj.slopeError = true;
			}
			return true;
		}
		if (((Component)((RaycastHit)(ref val3)).collider).gameObject.layer == 11)
		{
			Heightmap h;
			Color color = (dobj.targetColor = GetHitColor(targetPosition, out h));
			if (!noPathCheck && !IsPath(color))
			{
				dobj.colorError = true;
				return true;
			}
			return false;
		}
		if ((Object)(object)((Component)((RaycastHit)(ref val3)).collider).gameObject.GetComponentInParent<Piece>() == (Object)null)
		{
			dobj.target = ((RaycastHit)(ref val3)).point;
			dobj.targetHeight = dobj.target.y;
			dobj.slopeError = true;
			return true;
		}
		return false;
	}

	private static float CountPathWeight(Vector3 startPoint, Vector3 direction, float angle, out DebugObject dobj, int to = 0, bool isCheck = false, bool noPathCheck = false)
	{
		//IL_004d: 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_0050: 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_0083: 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_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_00be: 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_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		int num = to;
		int value = PathPointsConfig.Value;
		if (num == 0)
		{
			num = PathPointsConfig.Value;
			if (IsRiding() && !isCheck)
			{
				num = (int)((float)num * RidingDistanceFactorConfig.Value);
			}
		}
		float num2 = 0f;
		float num3 = (float)PathPointsConfig.Value / (float)value;
		Vector3 lastPosition = startPoint;
		float y = startPoint.y;
		float lastHeight = y;
		float num4 = 0f;
		dobj = new DebugObject();
		if (isCheck)
		{
			num3 *= NearCollissionDetectionLengthScaleConfig.Value;
		}
		int i;
		for (i = 1; i <= num; i++)
		{
			Vector3 val = startPoint + direction * ((float)i * num3);
			y = (val.y += num4);
			dobj = new DebugObject();
			if (isCheck)
			{
				dobj.isCheck = true;
			}
			dobj.target = val;
			dobj.weight = 0f;
			dobj.targetHeight = y;
			if (CollissionDetected(val, lastHeight, y, lastPosition, direction, num3, out var heightDiff, dobj, noPathCheck))
			{
				if (VisualDebugConfig.Value)
				{
					if (!dobj.slopeError && !dobj.colorError)
					{
						dobj.collission = true;
					}
					if (rayCasts[angle].ContainsKey(i))
					{
						rayCasts[angle].Remove(i);
					}
					rayCasts[angle].Add(i, dobj);
				}
				break;
			}
			dobj.target.y += heightDiff;
			y += heightDiff;
			num4 += heightDiff;
			float num5 = Mathf.Clamp01(1f - Mathf.Abs(Vector3.Angle(direction, ((Component)Player.m_localPlayer).transform.forward)) / (float)MaxAngleConfig.Value * AngleWeightFactorConfig.Value);
			float num6 = Mathf.Clamp01(1f - (float)i * num3 / (float)MaxDistanceConfig.Value * DistanceWeightFactorConfig.Value);
			num2 += num5 + num6;
			if (VisualDebugConfig.Value)
			{
				dobj.weight = num2;
				if (rayCasts[angle].ContainsKey(i))
				{
					rayCasts[angle].Remove(i);
				}
				rayCasts[angle].Add(i, dobj);
			}
			lastHeight = y;
			lastPosition = val;
		}
		return i;
	}

	private static bool IsRiding(IDoodadController dobj = null)
	{
		if (dobj == null)
		{
			dobj = Player.m_localPlayer.m_doodadController;
		}
		if (dobj == null)
		{
			return false;
		}
		if (dobj is Sadle)
		{
			return true;
		}
		return false;
	}

	private static Vector3 GetStartPoint(out Vector3 lookDir)
	{
		//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_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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_0050: 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)
		Vector3 position = ((Component)Player.m_localPlayer).transform.position;
		lookDir = ((Component)Player.m_localPlayer).transform.forward;
		if (IsRiding())
		{
			Component controlledComponent = Player.m_localPlayer.m_doodadController.GetControlledComponent();
			position = controlledComponent.transform.position;
			lookDir = controlledComponent.transform.forward;
		}
		return position;
	}

	private static Vector3 CalculateMoveDir()
	{
		//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_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_008a: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: 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_021e: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0224: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c7: 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_0210: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
		Vector3 lookDir;
		Vector3 startPoint = GetStartPoint(out lookDir);
		Vector3 val = lookDir;
		float num = 0f;
		float angle = 0f;
		DebugObject debugObject = null;
		int num2 = PathPointsConfig.Value;
		rayCasts.Clear();
		if (IsRiding())
		{
			num2 = (int)((float)num2 * RidingDistanceFactorConfig.Value);
		}
		float num3 = (float)MaxAngleConfig.Value / (float)NumAnglesConfig.Value;
		for (int i = 0; i < NumAnglesConfig.Value; i++)
		{
			for (int j = -1; j <= 1; j += 2)
			{
				float num4 = (float)i * num3 * (float)j;
				Vector3 val2 = Quaternion.Euler(0f, num4, 0f) * lookDir;
				val2.y = 0f;
				((Vector3)(ref val2)).Normalize();
				if (VisualDebugConfig.Value)
				{
					rayCasts.Add(num4, new SortedList<int, DebugObject>());
				}
				DebugObject dobj;
				float num5 = CountPathWeight(startPoint, val2, num4, out dobj);
				if (num5 > num)
				{
					num = num5;
					val = val2;
					angle = num4;
					debugObject = dobj;
					if (num > (float)num2)
					{
						break;
					}
				}
				if (i == 0)
				{
					break;
				}
			}
			if (num > (float)num2)
			{
				break;
			}
		}
		bool flag = num <= (float)num2;
		if (flag)
		{
			for (int k = 0; k < NumAnglesConfig.Value; k++)
			{
				for (int l = -1; l <= 1; l += 2)
				{
					float num6 = (float)k * num3 * (float)l;
					Vector3 val3 = Quaternion.Euler(0f, num6, 0f) * lookDir;
					val3.y = 0f;
					((Vector3)(ref val3)).Normalize();
					if (VisualDebugConfig.Value && !rayCasts.ContainsKey(num6))
					{
						rayCasts.Add(num6, new SortedList<int, DebugObject>());
					}
					DebugObject dobj2;
					float num7 = CountPathWeight(startPoint, val3, num6, out dobj2, 0, isCheck: false, noPathCheck: true);
					if (num7 > num)
					{
						num = num7;
						val = val3;
						angle = num6;
						debugObject = dobj2;
						if (num > (float)num2)
						{
							break;
						}
					}
					if (k == 0)
					{
						break;
					}
				}
				if (num > (float)num2)
				{
					break;
				}
			}
		}
		if (val == lookDir && debugObject.colorError)
		{
			CheckPath(startPoint, val, angle, flag);
			return lookDir;
		}
		return CheckPath(startPoint, val, angle, flag);
	}

	private static Vector3 CalcDirection(Vector3 direction, float angle)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: 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_002a: Unknown result type (might be due to invalid IL or missing references)
		Vector3 result = Quaternion.Euler(0f, angle, 0f) * direction;
		result.y = 0f;
		((Vector3)(ref result)).Normalize();
		return result;
	}

	private static Vector3 CheckPath(Vector3 startPoint, Vector3 direction, float angle, bool noPathCheck = false)
	{
		//IL_002a: 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_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: 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_000c: 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_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: 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_00d5: 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_00fa: 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)
		if (!NearCollissionDetectionEnabledConfig.Value)
		{
			return direction;
		}
		float num = -1f * NearCollissionDetectionAngleConfig.Value;
		float value = NearCollissionDetectionAngleConfig.Value;
		Vector3 direction2 = CalcDirection(direction, num);
		Vector3 direction3 = CalcDirection(direction, value);
		if (VisualDebugConfig.Value)
		{
			if (!rayCasts.ContainsKey(num))
			{
				rayCasts.Add(num, new SortedList<int, DebugObject>());
			}
			if (!rayCasts.ContainsKey(value))
			{
				rayCasts.Add(value, new SortedList<int, DebugObject>());
			}
		}
		DebugObject dobj;
		float num2 = CountPathWeight(startPoint, direction2, num, out dobj, 1, isCheck: true, noPathCheck);
		float num3 = CountPathWeight(startPoint, direction3, value, out dobj, 1, isCheck: true, noPathCheck);
		if (num2 <= 1f && num3 > 1f)
		{
			return CalcDirection(direction, angle + NearCollissionCorrectionAngleConfig.Value);
		}
		if (num3 <= 1f && num2 > 1f)
		{
			return CalcDirection(direction, angle - NearCollissionCorrectionAngleConfig.Value);
		}
		if (num3 <= 1f && num2 <= 1f)
		{
			return CalcDirection(direction, angle - 180f);
		}
		return direction;
	}

	private static Color GetHitColor(Vector3 point, out Heightmap h)
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: 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_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_0072: Unknown result type (might be due to invalid IL or missing references)
		List<Heightmap> list = new List<Heightmap>();
		Heightmap.FindHeightmap(point, HeightmapSearchRadiusConfig.Value, list);
		Color val = Heightmap.m_paintMaskNothing;
		h = null;
		int num = default(int);
		int num2 = default(int);
		foreach (Heightmap item in list)
		{
			item.WorldToVertex(point, ref num, ref num2);
			val = item.GetPaintMask(num, num2);
			h = item;
			if (IsPath(val))
			{
				return val;
			}
		}
		return val;
	}

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Logger.LogInfo((object)"AutoFollowPath has landed");
		CreateConfigValues();
		AddInputs();
		new Harmony("org.bepinex.plugins.bid.autofollowpath").PatchAll();
		CreatureManager.OnVanillaCreaturesAvailable += ModifyAndCloneVanillaCreatures;
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private void AddInputs()
	{
		//IL_001a: 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_0034: Expected O, but got Unknown
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: 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_005f: 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_0072: Expected O, but got Unknown
		AutoSprintShortcut = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Client config", "AutoSprint", new KeyboardShortcut((KeyCode)304, Array.Empty<KeyCode>()), new ConfigDescription("keycode to toggle sprint", (AcceptableValueBase)null, Array.Empty<object>()));
		AutoSprintButtonConfig = new ButtonConfig
		{
			Name = "AutoSprint",
			ShortcutConfig = AutoSprintShortcut,
			HintToken = "sprint",
			ActiveInCustomGUI = true,
			ActiveInGUI = true
		};
		InputManager.Instance.AddButton("org.bepinex.plugins.bid.autofollowpath", AutoSprintButtonConfig);
	}

	private void CreateConfigValues()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e8: Expected O, but got Unknown
		//IL_0109: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Expected O, but got Unknown
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Expected O, but got Unknown
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_016e: Expected O, but got Unknown
		//IL_0193: Unknown result type (might be due to invalid IL or missing references)
		//IL_019d: Expected O, but got Unknown
		//IL_01c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Expected O, but got Unknown
		//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Expected O, but got Unknown
		//IL_021c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0226: Expected O, but got Unknown
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Expected O, but got Unknown
		//IL_0272: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Expected O, but got Unknown
		//IL_02a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ab: Expected O, but got Unknown
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Expected O, but got Unknown
		//IL_02ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0309: Expected O, but got Unknown
		//IL_032e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0338: Expected O, but got Unknown
		//IL_035d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Expected O, but got Unknown
		//IL_038c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Expected O, but got Unknown
		//IL_03bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c5: Expected O, but got Unknown
		//IL_03ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f4: Expected O, but got Unknown
		//IL_0415: Unknown result type (might be due to invalid IL or missing references)
		//IL_041f: Expected O, but got Unknown
		//IL_0447: Unknown result type (might be due to invalid IL or missing references)
		//IL_044c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0454: Expected O, but got Unknown
		//IL_0454: Unknown result type (might be due to invalid IL or missing references)
		//IL_045e: Expected O, but got Unknown
		//IL_0486: Unknown result type (might be due to invalid IL or missing references)
		//IL_048b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0493: Expected O, but got Unknown
		//IL_0493: Unknown result type (might be due to invalid IL or missing references)
		//IL_049d: Expected O, but got Unknown
		//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c7: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cf: Expected O, but got Unknown
		//IL_04cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d9: Expected O, but got Unknown
		//IL_0501: 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_050e: Expected O, but got Unknown
		//IL_050e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0518: Expected O, but got Unknown
		//IL_0540: 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_054d: Expected O, but got Unknown
		//IL_054d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0557: Expected O, but got Unknown
		//IL_057f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0584: Unknown result type (might be due to invalid IL or missing references)
		//IL_058c: Expected O, but got Unknown
		//IL_058c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0596: Expected O, but got Unknown
		//IL_05be: Unknown result type (might be due to invalid IL or missing references)
		//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cb: Expected O, but got Unknown
		//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_05d5: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		GlobalSprintToggleConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "GlobalSprintToggle", false, new ConfigDescription("Only sprint in autorun mode, or also in normal run mode (global)", (AcceptableValueBase)null, Array.Empty<object>()));
		StaminaMinThresholdConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "StaminaMinThreshold", 30f, new ConfigDescription("Stop sprinting if stamina is below this value", (AcceptableValueBase)null, Array.Empty<object>()));
		UpdateTimeMillisConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "UpdateMillis", 200, new ConfigDescription("Update direction every x milliseconds", (AcceptableValueBase)null, Array.Empty<object>()));
		MaxAngleConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "MaxAngle", 90, new ConfigDescription("Max angle to look for a path", (AcceptableValueBase)null, Array.Empty<object>()));
		NumAnglesConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "NumAngles", 10, new ConfigDescription("Number of angles to check a path between current forward direction and MaxAngle", (AcceptableValueBase)null, Array.Empty<object>()));
		MaxDistanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "MaxDistance", 8, new ConfigDescription("Max distance ahead of player to check for a path per angle", (AcceptableValueBase)null, Array.Empty<object>()));
		PathPointsConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Client config", "PathPoints", 10, new ConfigDescription("Number of points to check between player position and MaxDistance per angle", (AcceptableValueBase)null, Array.Empty<object>()));
		PathToleranceConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "PathTolerance", 0.3f, new ConfigDescription("Tolerance a point is still considered a path (0-1)", (AcceptableValueBase)null, Array.Empty<object>()));
		AngleWeightFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "AngleWeightFactor", 0.3f, new ConfigDescription("weight higher angles less (0-1)", (AcceptableValueBase)null, Array.Empty<object>()));
		MaxInclineConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "MaxInclineRatio", 1f, new ConfigDescription("maximum ratio forward/height", (AcceptableValueBase)null, Array.Empty<object>()));
		DistanceWeightFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "DistanceWeightFactor", 0.5f, new ConfigDescription("weight path farer away less (0-1)", (AcceptableValueBase)null, Array.Empty<object>()));
		PavedOnlyConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "PavedOnly", false, new ConfigDescription("Only consider paved roads as paths", (AcceptableValueBase)null, Array.Empty<object>()));
		EnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "enabled", true, new ConfigDescription("enable or disable the mod", (AcceptableValueBase)null, Array.Empty<object>()));
		VisualDebugConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "VisualDebug", false, new ConfigDescription("enable or disable visual debugging", (AcceptableValueBase)null, Array.Empty<object>()));
		HeightmapSearchRadiusConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "HeightmapSearchRadius", 0.5f, new ConfigDescription("radius to look for heightmaps (internal)", (AcceptableValueBase)null, Array.Empty<object>()));
		RaycastHeightConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "RaycastHeight", 0.5f, new ConfigDescription("height of the raycast for horizontal collission detection", (AcceptableValueBase)null, Array.Empty<object>()));
		CollissionHeightIncreaseConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "CollissionHeightIncrease", 1.25f, new ConfigDescription("height of the vertical collission detectcion line = hitpoint height + CollissionHeightIncrease ", (AcceptableValueBase)null, Array.Empty<object>()));
		CollissionRayLengthDownConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "CollissonRayLengthDown", 4f, new ConfigDescription("length of the vertical raycast for collission detection going down", (AcceptableValueBase)null, Array.Empty<object>()));
		NearCollissionDetectionAngleConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "NearCollissionDetectionAngle", 30f, new ConfigDescription("angle for near collission detection", (AcceptableValueBase)null, Array.Empty<object>()));
		NearCollissionCorrectionAngleConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "NearCollissionCorrectionAngle", 30f, new ConfigDescription("if near collissin is detected, correct found path by this angle", (AcceptableValueBase)null, Array.Empty<object>()));
		NearCollissionDetectionLengthScaleConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "NearCollissionDetectionLengthScale", 1f, new ConfigDescription("scale factor of the length of the near collission detection ray", (AcceptableValueBase)null, Array.Empty<object>()));
		RidingDistanceFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Client config", "RidingDistanceFactor", 2f, new ConfigDescription("increase MaxDistance by this multiplier when riding", (AcceptableValueBase)null, Array.Empty<object>()));
		NearCollissionDetectionEnabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Client config", "NearCollissionDetectionEnabled", true, new ConfigDescription("Near collission detection enabled", (AcceptableValueBase)null, Array.Empty<object>()));
		MountSpeedModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MountSpeedBaseModifier", 1f, new ConfigDescription("Mount run speed base modifier factor", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MountStaminaModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MountStaminaUsageBaseModifier", 1f, new ConfigDescription("Stamina usage modifier factor for mounts", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		FellowRiderDistanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Server config", "FellowRiderDistance", 70, new ConfigDescription("Radius to search fellow riders", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MountSpeedGroupModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MountSpeedGroupModifier", 0.1f, new ConfigDescription("Modify mount speed per fellow rider", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MaxMountSpeedGroupModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MaxMountSpeedGroupModifier", 1f, new ConfigDescription("Maximum mount speed group bonus", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MountStaminaGroupModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MountStaminaUsageGroupModifier", 0.1f, new ConfigDescription("Modify stamina usage per fellow rider", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		MaxMountStaminaGroupModifierFactorConfig = ((BaseUnityPlugin)this).Config.Bind<float>("Server config", "MaxMountStaminaUsageGroupModifier", 0.9f, new ConfigDescription("Maximum stamina usage group reduction", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
	}

	private static void VisualDebug()
	{
		//IL_0000: 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_0024: 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_004a: 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_00b2: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: 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_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0230: Unknown result type (might be due to invalid IL or missing references)
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_0239: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_021a: Unknown result type (might be due to invalid IL or missing references)
		CalculateMoveDir();
		foreach (KeyValuePair<float, SortedList<int, DebugObject>> rayCast in rayCasts)
		{
			Vector3 lookDir;
			Vector3 val = GetStartPoint(out lookDir);
			if (Player.m_localPlayer.m_doodadController != null)
			{
				val = Player.m_localPlayer.m_doodadController.GetControlledComponent().transform.position;
			}
			val.y += RaycastHeightConfig.Value;
			foreach (KeyValuePair<int, DebugObject> item in rayCast.Value)
			{
				Vector3 target = item.Value.target;
				if (!item.Value.collission)
				{
					target.y += RaycastHeightConfig.Value;
				}
				LineRenderer val2 = new GameObject("Line").AddComponent<LineRenderer>();
				((Renderer)val2).material = LineMaterial;
				val2.startColor = Color.green;
				val2.endColor = Color.green;
				val2.startWidth = 0.02f;
				val2.endWidth = 0.02f;
				val2.positionCount = 2;
				val2.useWorldSpace = true;
				if (item.Value.colorError)
				{
					val2.startColor = Color.red;
					val2.endColor = Color.red;
				}
				if (item.Value.slopeError)
				{
					val2.startColor = Color.magenta;
					val2.endColor = Color.magenta;
				}
				if (item.Value.collission)
				{
					val2.startColor = Color.blue;
					val2.endColor = Color.blue;
				}
				if (item.Value.succeeded)
				{
					val2.startWidth = 0.05f;
					val2.endWidth = 0.05f;
				}
				if (item.Value.isCheck)
				{
					val2.startColor = Color.yellow;
					val2.endColor = Color.yellow;
					if (item.Value.collission)
					{
						val2.startWidth = 0.04f;
						val2.endWidth = 0.04f;
						val2.startColor = new Color(1f, 0.271f, 0f);
						val2.endColor = new Color(1f, 0.271f, 0f);
					}
				}
				val2.SetPosition(0, val);
				val2.SetPosition(1, target);
				val = target;
				lineRendrerList.Add(val2);
			}
		}
	}

	private int GetFellowRiderCount()
	{
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		int mask = LayerMask.GetMask(new string[2] { "character", "character_net" });
		Collider[] array = Physics.OverlapSphere(((Component)Player.m_localPlayer).transform.position, (float)FellowRiderDistanceConfig.Value, mask);
		for (int i = 0; i < array.Length; i++)
		{
			Sadle componentInChildren = ((Component)array[i]).GetComponentInChildren<Sadle>();
			if (!((Object)(object)componentInChildren == (Object)null) && componentInChildren.GetUser() != 0L)
			{
				num++;
			}
		}
		return num - 1;
	}

	private void Update()
	{
		//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ff: 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_0146: 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_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		if (!EnabledConfig.Value)
		{
			return;
		}
		foreach (LineRenderer lineRendrer in lineRendrerList)
		{
			Object.Destroy((Object)(object)lineRendrer);
		}
		foreach (GameObject text in textList)
		{
			Object.Destroy((Object)(object)text);
		}
		lineRendrerList.Clear();
		textList.Clear();
		if ((Object)(object)Player.m_localPlayer != (Object)null && VisualDebugConfig.Value)
		{
			VisualDebug();
		}
		if (!((Object)(object)Player.m_localPlayer != (Object)null) || ((Character)Player.m_localPlayer).IsDebugFlying() || (!Player.m_localPlayer.m_autoRun && !IsRiding()))
		{
			return;
		}
		m_updateTimer -= Time.fixedDeltaTime;
		if (!(m_updateTimer < 0f))
		{
			return;
		}
		Vector3 val = CalculateMoveDir();
		m_mount = null;
		m_fellowRiderCount = GetFellowRiderCount();
		IDoodadController doodadController = Player.m_localPlayer.m_doodadController;
		if (doodadController != null)
		{
			if (doodadController is Sadle)
			{
				Sadle val2 = (Sadle)doodadController;
				m_mount = val2.m_character;
				val2.m_controlDir = val;
			}
		}
		else
		{
			((Character)Player.m_localPlayer).m_moveDir = val;
		}
		m_updateTimer = (float)UpdateTimeMillisConfig.Value / 1000f;
	}

	private void ModifyAndCloneVanillaCreatures()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_005a: Expected O, but got Unknown
		Shader[] array = Resources.FindObjectsOfTypeAll<Shader>();
		foreach (Shader val in array)
		{
			if (((Object)val).name == "Legacy Shaders/Particles/Alpha Blended Premultiply")
			{
				LegacyShader = val;
				break;
			}
		}
		if ((Object)(object)LegacyShader == (Object)null)
		{
			MonoBehaviour.print((object)"legacy shader not found");
		}
		else
		{
			LineMaterial = new Material(LegacyShader);
		}
		CreatureManager.OnVanillaCreaturesAvailable -= ModifyAndCloneVanillaCreatures;
	}
}