Decompiled source of REPOPathfinder v0.7.3

REPOPathfinder.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Rendering;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("REPOPathfinder")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.7.3.0")]
[assembly: AssemblyInformationalVersion("0.7.3")]
[assembly: AssemblyProduct("REPOPathfinder")]
[assembly: AssemblyTitle("REPOPathfinder")]
[assembly: AssemblyVersion("0.7.3.0")]
namespace REPOPathfinder;

internal static class GameAccess
{
	private static FieldRef<RoundDirector, ExtractionPoint> _extractionPointCurrent;

	private static FieldRef<RoundDirector, bool> _allExtractionPointsCompleted;

	private static FieldRef<PlayerAvatar, Vector3> _lastNavmeshPosition;

	private static FieldRef<PlayerAvatar, bool> _isDisabled;

	private static FieldRef<PlayerAvatar, bool> _deadSet;

	private static FieldRef<SpectateCamera, PlayerAvatar> _spectatedPlayer;

	public static bool Ready { get; private set; }

	public static void Bind(ManualLogSource log)
	{
		List<string> list = new List<string>();
		_extractionPointCurrent = Bind<RoundDirector, ExtractionPoint>("extractionPointCurrent", list);
		_allExtractionPointsCompleted = Bind<RoundDirector, bool>("allExtractionPointsCompleted", list);
		_lastNavmeshPosition = Bind<PlayerAvatar, Vector3>("LastNavmeshPosition", list);
		Ready = list.Count == 0;
		if (!Ready)
		{
			log.LogError((object)("This game version no longer has: " + string.Join(", ", list) + ". The trail is turned off until REPOPathfinder is updated."));
		}
		List<string> list2 = new List<string>();
		_isDisabled = Bind<PlayerAvatar, bool>("isDisabled", list2);
		_deadSet = Bind<PlayerAvatar, bool>("deadSet", list2);
		_spectatedPlayer = Bind<SpectateCamera, PlayerAvatar>("player", list2);
		if (list2.Count > 0)
		{
			log.LogWarning((object)("Not found in this game version: " + string.Join(", ", list2) + ". The trail will not follow the player you spectate."));
		}
	}

	private static FieldRef<T, F> Bind<T, F>(string name, List<string> missing) where T : class
	{
		try
		{
			FieldInfo field = typeof(T).GetField(name, AccessTools.all);
			if (field != null && field.FieldType == typeof(F))
			{
				return AccessTools.FieldRefAccess<T, F>(field);
			}
		}
		catch (Exception)
		{
		}
		missing.Add(typeof(T).Name + "." + name);
		return null;
	}

	public static ExtractionPoint CurrentExtraction(RoundDirector director)
	{
		return _extractionPointCurrent.Invoke(director);
	}

	public static bool AllExtractionsDone(RoundDirector director)
	{
		return _allExtractionPointsCompleted.Invoke(director);
	}

	public static Vector3 LastNavmeshPosition(PlayerAvatar avatar)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		return _lastNavmeshPosition.Invoke(avatar);
	}

	public static bool IsDead(PlayerAvatar avatar)
	{
		if (_isDisabled == null || !_isDisabled.Invoke(avatar))
		{
			if (_deadSet != null)
			{
				return _deadSet.Invoke(avatar);
			}
			return false;
		}
		return true;
	}

	public static PlayerAvatar SpectatedPlayer()
	{
		SpectateCamera instance = SpectateCamera.instance;
		if (!((Object)(object)instance != (Object)null) || _spectatedPlayer == null)
		{
			return null;
		}
		return _spectatedPlayer.Invoke(instance);
	}
}
internal static class GameInput
{
	private const float HoldSeconds = 0.25f;

	private static readonly List<InputKey> AllowedKeys = new List<InputKey> { (InputKey)25 };

	public static void HoldThisFrame()
	{
		InputManager instance = InputManager.instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.DisableMovement(0.25f);
			instance.DisableAiming(0.25f);
			instance.DisableControlsExcept(0.25f, AllowedKeys);
		}
		CursorManager instance2 = CursorManager.instance;
		if ((Object)(object)instance2 != (Object)null)
		{
			instance2.Unlock(0.25f);
		}
	}
}
public class PathfinderCustomizeUI : MonoBehaviour
{
	private bool _visible;

	private Rect _windowRect = new Rect(20f, 60f, 360f, 0f);

	private int _windowId;

	private Color _editColor;

	private string _hexBuffer;

	private bool _hexBufferDirty;

	private bool _needsSyncFromConfig = true;

	private static readonly (string label, string hex)[] Presets = new(string, string)[8]
	{
		("White", "#FFFFFF80"),
		("Cyan", "#00E5FF80"),
		("Yellow", "#FFEB3B80"),
		("Red", "#FF525280"),
		("Green", "#00E67680"),
		("Blue", "#448AFF80"),
		("Magenta", "#E040FB80"),
		("Orange", "#FF9100AA")
	};

	private Texture2D _whiteTex;

	private GUIStyle _boldStyle;

	private bool _savedCursorVisible;

	private bool _cursorOverridden;

	private GUIStyle BoldLabel
	{
		get
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			if (_boldStyle == null)
			{
				_boldStyle = new GUIStyle(GUI.skin.label)
				{
					fontStyle = (FontStyle)1
				};
			}
			return _boldStyle;
		}
	}

	private void Awake()
	{
		_windowId = ((Object)this).GetInstanceID();
	}

	private void Update()
	{
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		IInputSystem current = UnityInput.Current;
		if (current.GetKeyDown(Plugin.Instance.CustomizeMenuKey.Value))
		{
			if (_visible)
			{
				Close();
			}
			else
			{
				Open();
			}
		}
		else if (_visible && current.GetKeyDown((KeyCode)27))
		{
			Close();
		}
		if (_visible)
		{
			GameInput.HoldThisFrame();
		}
	}

	private void OnDisable()
	{
		if (_visible)
		{
			Close();
		}
	}

	private void Open()
	{
		_visible = true;
		_needsSyncFromConfig = true;
		_savedCursorVisible = Cursor.visible;
		_cursorOverridden = true;
		((BaseUnityPlugin)Plugin.Instance).Config.SaveOnConfigSet = false;
	}

	private void Close()
	{
		_visible = false;
		if (_cursorOverridden)
		{
			Cursor.visible = _savedCursorVisible;
			_cursorOverridden = false;
		}
		((BaseUnityPlugin)Plugin.Instance).Config.SaveOnConfigSet = true;
		try
		{
			((BaseUnityPlugin)Plugin.Instance).Config.Save();
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not save the config file: " + ex.Message));
		}
	}

	private void OnGUI()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Expected O, but got Unknown
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if (_visible)
		{
			if (_needsSyncFromConfig)
			{
				SyncFromConfig();
				_needsSyncFromConfig = false;
			}
			if ((int)Cursor.lockState != 0)
			{
				Cursor.lockState = (CursorLockMode)0;
			}
			if (!Cursor.visible)
			{
				Cursor.visible = true;
			}
			_windowRect = GUILayout.Window(_windowId, _windowRect, new WindowFunction(DrawWindow), "REPOPathfinder — Customize", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(360f) });
		}
	}

	private void SyncFromConfig()
	{
		//IL_003d: 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_0036: Unknown result type (might be due to invalid IL or missing references)
		if (!ColorUtility.TryParseHtmlString(Plugin.Instance.DotColorHex.Value, ref _editColor))
		{
			_editColor = new Color(1f, 1f, 1f, 0.5f);
		}
		_hexBuffer = ColorToHex(_editColor);
		_hexBufferDirty = false;
	}

	private void DrawWindow(int id)
	{
		//IL_0160: 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_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_0342: 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_01f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(4f);
		GUILayout.Label("Dot Color", BoldLabel, Array.Empty<GUILayoutOption>());
		DrawColorChannel("R", ref _editColor.r);
		DrawColorChannel("G", ref _editColor.g);
		DrawColorChannel("B", ref _editColor.b);
		DrawColorChannel("A", ref _editColor.a);
		GUILayout.Space(2f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label("Hex:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(30f) });
		string text = GUILayout.TextField(_hexBuffer ?? "", 9, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) });
		if (text != _hexBuffer)
		{
			_hexBuffer = text;
			_hexBufferDirty = true;
		}
		GUI.enabled = _hexBufferDirty;
		Color editColor = default(Color);
		if (GUILayout.Button("Apply", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(58f) }) && ColorUtility.TryParseHtmlString(_hexBuffer, ref editColor))
		{
			_editColor = editColor;
			_hexBufferDirty = false;
			PushColorToConfig();
		}
		GUI.enabled = true;
		GUILayout.Label("Preview:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) });
		DrawSwatch(_editColor, 60f, 18f);
		GUILayout.EndHorizontal();
		GUILayout.Space(6f);
		GUILayout.Label("Presets", BoldLabel, Array.Empty<GUILayoutOption>());
		Color editColor2 = default(Color);
		for (int i = 0; i < Presets.Length; i++)
		{
			if (i % 4 == 0)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			}
			if (GUILayout.Button(Presets[i].label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(78f) }) && ColorUtility.TryParseHtmlString(Presets[i].hex, ref editColor2))
			{
				_editColor = editColor2;
				_hexBuffer = ColorToHex(_editColor);
				_hexBufferDirty = false;
				PushColorToConfig();
			}
			if (i % 4 == 3 || i == Presets.Length - 1)
			{
				GUILayout.EndHorizontal();
			}
		}
		GUILayout.Space(8f);
		GUILayout.Label("Trail Shape", BoldLabel, Array.Empty<GUILayoutOption>());
		DrawFloatSlider("Dot size", Plugin.Instance.DotScale, 0.02f, 0.5f, "F2");
		DrawFloatSlider("Flow speed", Plugin.Instance.FlowSpeed, 0f, 6f, "F1");
		DrawFloatSlider("Spacing", Plugin.Instance.Spacing, 0.5f, 4f, "F1");
		GUILayout.Space(8f);
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button("Reset Visuals", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(110f) }))
		{
			ResetVisualDefaults();
		}
		GUILayout.FlexibleSpace();
		if (GUILayout.Button("Close", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }))
		{
			Close();
		}
		GUILayout.EndHorizontal();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 20f));
	}

	private void DrawColorChannel(string label, ref float value)
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(20f) });
		float num = value;
		value = GUILayout.HorizontalSlider(value, 0f, 1f, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(220f) });
		GUILayout.Label(Mathf.RoundToInt(Mathf.Clamp01(value) * 255f).ToString("D3"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(36f) });
		GUILayout.EndHorizontal();
		if (Mathf.Abs(value - num) > 0.0001f)
		{
			_hexBuffer = ColorToHex(_editColor);
			_hexBufferDirty = false;
			PushColorToConfig();
		}
	}

	private static void DrawFloatSlider(string label, ConfigEntry<float> entry, float min, float max, string format)
	{
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUILayout.Label(label, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(80f) });
		float value = entry.Value;
		float num = GUILayout.HorizontalSlider(entry.Value, min, max, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(180f) });
		GUILayout.Label(num.ToString(format), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) });
		GUILayout.EndHorizontal();
		if (Mathf.Abs(num - value) > 0.0001f)
		{
			entry.Value = num;
		}
	}

	private void DrawSwatch(Color c, float width, float height)
	{
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_002a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: 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_0052: Unknown result type (might be due to invalid IL or missing references)
		EnsureWhiteTex();
		Rect rect = GUILayoutUtility.GetRect(width, height, (GUILayoutOption[])(object)new GUILayoutOption[2]
		{
			GUILayout.Width(width),
			GUILayout.Height(height)
		});
		Color color = GUI.color;
		GUI.color = Color.white;
		GUI.DrawTexture(rect, (Texture)(object)_whiteTex);
		GUI.color = c;
		GUI.DrawTexture(rect, (Texture)(object)_whiteTex);
		GUI.color = color;
	}

	private void EnsureWhiteTex()
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_001c: Expected O, but got Unknown
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)_whiteTex != (Object)null))
		{
			_whiteTex = new Texture2D(1, 1);
			_whiteTex.SetPixel(0, 0, Color.white);
			_whiteTex.Apply();
			((Object)_whiteTex).hideFlags = (HideFlags)61;
		}
	}

	private void ResetVisualDefaults()
	{
		Plugin.Instance.DotColorHex.Value = (string)((ConfigEntryBase)Plugin.Instance.DotColorHex).DefaultValue;
		Plugin.Instance.DotScale.Value = (float)((ConfigEntryBase)Plugin.Instance.DotScale).DefaultValue;
		Plugin.Instance.FlowSpeed.Value = (float)((ConfigEntryBase)Plugin.Instance.FlowSpeed).DefaultValue;
		Plugin.Instance.Spacing.Value = (float)((ConfigEntryBase)Plugin.Instance.Spacing).DefaultValue;
		_needsSyncFromConfig = true;
	}

	private void PushColorToConfig()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		string text = ColorToHex(_editColor);
		if (Plugin.Instance.DotColorHex.Value != text)
		{
			Plugin.Instance.DotColorHex.Value = text;
		}
	}

	private static string ColorToHex(Color c)
	{
		//IL_0000: 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_003a: 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)
		int num = Mathf.Clamp(Mathf.RoundToInt(c.r * 255f), 0, 255);
		int num2 = Mathf.Clamp(Mathf.RoundToInt(c.g * 255f), 0, 255);
		int num3 = Mathf.Clamp(Mathf.RoundToInt(c.b * 255f), 0, 255);
		int num4 = Mathf.Clamp(Mathf.RoundToInt(c.a * 255f), 0, 255);
		return $"#{num:X2}{num2:X2}{num3:X2}{num4:X2}";
	}
}
public class PathfinderManager : MonoBehaviour
{
	private const float RetryAfterFailedPathSeconds = 0.75f;

	private const float MinSecondsBetweenPaths = 0.2f;

	private const float TargetSnapMeters = 4f;

	private const float SpectatedSnapMeters = 3f;

	private const float StaleStartMeters = 10f;

	private const int FailuresBeforeTurningOff = 5;

	private static readonly string[] ShaderNames = new string[4] { "Sprites/Default", "Unlit/Color", "Hidden/Internal-Colored", "Standard" };

	private bool _trailEnabled;

	private NavMeshPath _path;

	private Vector3[] _cornerBuffer = (Vector3[])(object)new Vector3[128];

	private Vector3[] _cachedCorners = (Vector3[])(object)new Vector3[128];

	private float[] _cachedArcs = new float[128];

	private int _cornerCount;

	private float _totalLength;

	private Transform _cachedTarget;

	private Transform _reportedTarget;

	private float _nextPathAttempt;

	private readonly List<GameObject> _dots = new List<GameObject>();

	private readonly List<MeshRenderer> _renderers = new List<MeshRenderer>();

	private Vector3[] _smoothedPositions = (Vector3[])(object)new Vector3[0];

	private bool[] _wasVisible = new bool[0];

	private bool _anyDotVisible;

	private float _animOffset;

	private int _frontPool;

	private Material _sharedMaterial;

	private bool _materialCreated;

	private MaterialPropertyBlock _mpb;

	private Color _baseColor;

	private static readonly int ColorPropId = Shader.PropertyToID("_Color");

	private int _failures;

	private bool _failureLogged;

	private float _toastUntil;

	private string _toastText;

	private GUIStyle _toastStyle;

	private void Awake()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//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)
		_path = new NavMeshPath();
		_mpb = new MaterialPropertyBlock();
		_trailEnabled = Plugin.Instance.EnabledOnStart.Value && GameAccess.Ready;
		_baseColor = ParseColor(Plugin.Instance.DotColorHex.Value);
		Plugin.Instance.DotColorHex.SettingChanged += OnDotColorChanged;
	}

	private void OnDestroy()
	{
		if ((Object)(object)Plugin.Instance != (Object)null && Plugin.Instance.DotColorHex != null)
		{
			Plugin.Instance.DotColorHex.SettingChanged -= OnDotColorChanged;
		}
	}

	private void OnDotColorChanged(object sender, EventArgs e)
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		_baseColor = ParseColor(Plugin.Instance.DotColorHex.Value);
	}

	private void OnEnable()
	{
		SceneManager.sceneLoaded += OnSceneLoaded;
	}

	private void OnDisable()
	{
		SceneManager.sceneLoaded -= OnSceneLoaded;
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		DropTrail();
	}

	private void Update()
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		HandleHotkeys();
		if (!_trailEnabled)
		{
			return;
		}
		try
		{
			UpdateTrail();
			_failures = 0;
		}
		catch (Exception ex)
		{
			DropTrail();
			if (!_failureLogged)
			{
				_failureLogged = true;
				Plugin.Log.LogError((object)("The trail could not be updated: " + ex));
			}
			if (++_failures >= 5)
			{
				_failures = 0;
				_trailEnabled = false;
				Plugin.Log.LogError((object)($"The trail was turned off after {5} failed updates in a row. " + $"Press {Plugin.Instance.ToggleKey.Value} to turn it on again."));
				ShowToast("Pathfinder: error, turned off");
			}
		}
	}

	private void HandleHotkeys()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		IInputSystem current = UnityInput.Current;
		if (current.GetKeyDown(Plugin.Instance.ToggleKey.Value))
		{
			if (!GameAccess.Ready)
			{
				ShowToast("Pathfinder: needs an update for this game version");
			}
			else
			{
				_trailEnabled = !_trailEnabled;
				_failures = 0;
				_failureLogged = false;
				ShowToast(_trailEnabled ? "Pathfinder: ON" : "Pathfinder: OFF");
				if (!_trailEnabled)
				{
					DropTrail();
				}
			}
		}
		if (current.GetKeyDown(Plugin.Instance.TargetToggleKey.Value))
		{
			PathfinderTargetMode pathfinderTargetMode = ((Plugin.Instance.TargetMode.Value == PathfinderTargetMode.Auto) ? PathfinderTargetMode.Truck : PathfinderTargetMode.Auto);
			Plugin.Instance.TargetMode.Value = pathfinderTargetMode;
			ShowToast((pathfinderTargetMode == PathfinderTargetMode.Truck) ? "Target: Truck" : "Target: Auto");
			InvalidateCache();
		}
	}

	private void UpdateTrail()
	{
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)Map.Instance == (Object)null || (Object)(object)PlayerController.instance == (Object)null || (Object)(object)LevelGenerator.Instance == (Object)null || !LevelGenerator.Instance.Generated || (Object)(object)RoundDirector.instance == (Object)null)
		{
			DropTrail();
			return;
		}
		Transform val = ResolveTarget();
		if ((Object)(object)val == (Object)null)
		{
			DropTrail();
			return;
		}
		if (!TryGetStart(out var start))
		{
			HideAllDots();
			return;
		}
		float arc = 0f;
		if ((_cornerCount < 2 || !((Object)(object)val == (Object)(object)_cachedTarget) || !ProjectOnCachedPath(start, out arc, out var dist) || !(dist <= Plugin.Instance.OffPathThreshold.Value)) && Time.unscaledTime >= _nextPathAttempt)
		{
			bool flag = RecomputePath(start, val);
			_nextPathAttempt = Time.unscaledTime + (flag ? 0.2f : 0.75f);
			if (flag)
			{
				ProjectOnCachedPath(start, out arc, out var _);
			}
		}
		if (_cornerCount < 2 || (Object)(object)val != (Object)(object)_cachedTarget || _totalLength <= 0.5f)
		{
			HideAllDots();
			return;
		}
		float num = _totalLength - arc;
		if (num < Plugin.Instance.MinDistanceToTarget.Value)
		{
			HideAllDots();
		}
		else
		{
			AdvanceAndPlace(Time.deltaTime, arc, num);
		}
	}

	private static Transform ResolveTarget()
	{
		LevelPoint levelPathTruck = LevelGenerator.Instance.LevelPathTruck;
		Transform result = (((Object)(object)levelPathTruck != (Object)null) ? ((Component)levelPathTruck).transform : null);
		if (Plugin.Instance.TargetMode.Value == PathfinderTargetMode.Truck)
		{
			return result;
		}
		RoundDirector instance = RoundDirector.instance;
		if (GameAccess.AllExtractionsDone(instance))
		{
			return result;
		}
		ExtractionPoint val = GameAccess.CurrentExtraction(instance);
		if (!((Object)(object)val != (Object)null))
		{
			return null;
		}
		return ((Component)val).transform;
	}

	private static bool TryGetStart(out Vector3 start)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0087: Unknown result type (might be due to invalid IL or missing references)
		start = default(Vector3);
		PlayerAvatar playerAvatarScript = PlayerController.instance.playerAvatarScript;
		if ((Object)(object)playerAvatarScript == (Object)null)
		{
			return false;
		}
		if (!GameAccess.IsDead(playerAvatarScript))
		{
			start = GameAccess.LastNavmeshPosition(playerAvatarScript);
			Vector3 position = ((Component)playerAvatarScript).transform.position;
			Vector3 val = start - position;
			if (((Vector3)(ref val)).sqrMagnitude <= 100f)
			{
				return true;
			}
			return SnapToNavMesh(position, 3f, out start);
		}
		PlayerAvatar val2 = GameAccess.SpectatedPlayer();
		if ((Object)(object)val2 == (Object)null || (Object)(object)val2 == (Object)(object)playerAvatarScript)
		{
			return false;
		}
		return SnapToNavMesh(((Component)val2).transform.position, 3f, out start);
	}

	private static bool SnapToNavMesh(Vector3 position, float maxDistance, out Vector3 snapped)
	{
		//IL_0000: 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_001d: 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_0014: Unknown result type (might be due to invalid IL or missing references)
		NavMeshHit val = default(NavMeshHit);
		if (NavMesh.SamplePosition(position, ref val, maxDistance, -1))
		{
			snapped = ((NavMeshHit)(ref val)).position;
			return true;
		}
		snapped = position;
		return false;
	}

	private bool RecomputePath(Vector3 start, Transform target)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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_002f: Invalid comparison between Unknown and I4
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Invalid comparison between Unknown and I4
		SnapToNavMesh(target.position, 4f, out var snapped);
		if (!NavMesh.CalculatePath(start, snapped, -1, _path) || (int)_path.status == 2)
		{
			return false;
		}
		int cornersNonAlloc = _path.GetCornersNonAlloc(_cornerBuffer);
		while (cornersNonAlloc == _cornerBuffer.Length && _cornerBuffer.Length < 4096)
		{
			_cornerBuffer = (Vector3[])(object)new Vector3[_cornerBuffer.Length * 2];
			cornersNonAlloc = _path.GetCornersNonAlloc(_cornerBuffer);
		}
		if (cornersNonAlloc < 2)
		{
			return false;
		}
		CachePath(cornersNonAlloc);
		_cachedTarget = target;
		if ((Object)(object)target != (Object)(object)_reportedTarget)
		{
			_reportedTarget = target;
			Plugin.Log.LogInfo((object)$"Path to {((Object)target).name}: {_path.status}, {cornersNonAlloc} corners, {_totalLength:F0} m.");
			if ((int)_path.status == 1)
			{
				ShowToast("Pathfinder: no full route, showing the closest one");
			}
		}
		return true;
	}

	private void CachePath(int count)
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: 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_008c: 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)
		if (_cachedCorners.Length < count)
		{
			_cachedCorners = (Vector3[])(object)new Vector3[_cornerBuffer.Length];
			_cachedArcs = new float[_cornerBuffer.Length];
		}
		_cachedCorners[0] = _cornerBuffer[0];
		_cachedArcs[0] = 0f;
		for (int i = 1; i < count; i++)
		{
			_cachedCorners[i] = _cornerBuffer[i];
			_cachedArcs[i] = _cachedArcs[i - 1] + Vector3.Distance(_cornerBuffer[i - 1], _cornerBuffer[i]);
		}
		_cornerCount = count;
		_totalLength = _cachedArcs[count - 1];
		Array.Clear(_wasVisible, 0, _wasVisible.Length);
	}

	private void InvalidateCache()
	{
		_cornerCount = 0;
		_totalLength = 0f;
		_cachedTarget = null;
		_nextPathAttempt = 0f;
	}

	private void DropTrail()
	{
		InvalidateCache();
		HideAllDots();
	}

	private bool ProjectOnCachedPath(Vector3 p, out float arc, out float dist)
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_0042: 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_005a: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_007f: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		arc = 0f;
		dist = float.MaxValue;
		if (_cornerCount < 2)
		{
			return false;
		}
		float num = float.MaxValue;
		for (int i = 1; i < _cornerCount; i++)
		{
			Vector3 val = _cachedCorners[i - 1];
			Vector3 val2 = _cachedCorners[i] - val;
			float sqrMagnitude = ((Vector3)(ref val2)).sqrMagnitude;
			if (!(sqrMagnitude < 1E-06f))
			{
				float num2 = Mathf.Clamp01(Vector3.Dot(p - val, val2) / sqrMagnitude);
				Vector3 val3 = val + val2 * num2 - p;
				float sqrMagnitude2 = ((Vector3)(ref val3)).sqrMagnitude;
				if (sqrMagnitude2 < num)
				{
					num = sqrMagnitude2;
					arc = _cachedArcs[i - 1] + Mathf.Sqrt(sqrMagnitude) * num2;
				}
			}
		}
		if (num == float.MaxValue)
		{
			return false;
		}
		dist = Mathf.Sqrt(num);
		return true;
	}

	private Vector3 CachedPointAtDistance(float distance)
	{
		//IL_000f: 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_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: 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)
		if (distance <= 0f)
		{
			return _cachedCorners[0];
		}
		for (int i = 1; i < _cornerCount; i++)
		{
			if (distance <= _cachedArcs[i])
			{
				float num = _cachedArcs[i] - _cachedArcs[i - 1];
				if (num < 1E-06f)
				{
					return _cachedCorners[i];
				}
				float num2 = (distance - _cachedArcs[i - 1]) / num;
				return Vector3.Lerp(_cachedCorners[i - 1], _cachedCorners[i], num2);
			}
		}
		return _cachedCorners[_cornerCount - 1];
	}

	private void AdvanceAndPlace(float dt, float playerArc, float availableLength)
	{
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0229: Unknown result type (might be due to invalid IL or missing references)
		//IL_0243: Unknown result type (might be due to invalid IL or missing references)
		//IL_0270: Unknown result type (might be due to invalid IL or missing references)
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		int num = Mathf.Max(1, Plugin.Instance.MaxDots.Value);
		float num2 = Mathf.Max(0.1f, Plugin.Instance.Spacing.Value);
		float value = Plugin.Instance.GroundOffset.Value;
		float num3 = Mathf.Max(0f, Plugin.Instance.FlowSpeed.Value);
		float num4 = Mathf.Clamp(Plugin.Instance.FadeZoneFraction.Value, 0.05f, 0.5f);
		float num5 = Mathf.Max(0.01f, Plugin.Instance.DotScale.Value);
		EnsurePool(num);
		if (_frontPool < 0 || _frontPool >= num)
		{
			_frontPool = (_frontPool % num + num) % num;
		}
		_animOffset += num3 * dt;
		while (_animOffset >= num2)
		{
			_animOffset -= num2;
			_frontPool = (_frontPool - 1 + num) % num;
			_wasVisible[_frontPool] = false;
		}
		int num6 = Mathf.Min(num, Mathf.Max(1, Mathf.CeilToInt(availableLength / num2)));
		float num7 = Mathf.Min(availableLength, (float)num6 * num2);
		float num8 = Mathf.Max(0.05f, Mathf.Min(num2, num7 * 0.5f) * num4);
		float value2 = Plugin.Instance.PositionSmoothRate.Value;
		float num9 = ((value2 > 0f) ? (1f - Mathf.Exp((0f - value2) * dt)) : 1f);
		Vector3 localScale = default(Vector3);
		((Vector3)(ref localScale))..ctor(num5, num5, num5);
		for (int i = 0; i < _dots.Count; i++)
		{
			int num10 = ((i < num) ? (((i - _frontPool) % num + num) % num) : int.MaxValue);
			if (num10 >= num6)
			{
				if (_dots[i].activeSelf)
				{
					_dots[i].SetActive(false);
				}
				_wasVisible[i] = false;
				continue;
			}
			float num11 = (float)num10 * num2 + _animOffset;
			Vector3 val = CachedPointAtDistance(playerArc + Mathf.Min(num11, availableLength));
			val.y += value;
			_smoothedPositions[i] = (_wasVisible[i] ? Vector3.Lerp(_smoothedPositions[i], val, num9) : val);
			_wasVisible[i] = true;
			Transform transform = _dots[i].transform;
			transform.position = _smoothedPositions[i];
			if (transform.localScale.x != num5)
			{
				transform.localScale = localScale;
			}
			float num12 = Mathf.SmoothStep(0f, 1f, num11 / num8);
			float num13 = Mathf.SmoothStep(0f, 1f, (num7 - num11) / num8);
			ApplyDotAlpha(i, Mathf.Min(num12, num13));
			if (!_dots[i].activeSelf)
			{
				_dots[i].SetActive(true);
			}
		}
		_anyDotVisible = true;
	}

	private void EnsurePool(int count)
	{
		if (!_materialCreated)
		{
			_materialCreated = true;
			_sharedMaterial = CreateSharedMaterial();
		}
		while (_dots.Count < count)
		{
			GameObject val = CreateDot(_dots.Count);
			_dots.Add(val);
			_renderers.Add(val.GetComponent<MeshRenderer>());
		}
		if (_smoothedPositions.Length < _dots.Count)
		{
			Array.Resize(ref _smoothedPositions, _dots.Count);
			Array.Resize(ref _wasVisible, _dots.Count);
		}
	}

	private GameObject CreateDot(int idx)
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		GameObject obj = GameObject.CreatePrimitive((PrimitiveType)0);
		((Object)obj).name = $"PathfinderDot_{idx}";
		obj.transform.SetParent(((Component)this).transform, false);
		Collider component = obj.GetComponent<Collider>();
		if ((Object)(object)component != (Object)null)
		{
			Object.Destroy((Object)(object)component);
		}
		MeshRenderer component2 = obj.GetComponent<MeshRenderer>();
		((Renderer)component2).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)component2).receiveShadows = false;
		((Renderer)component2).lightProbeUsage = (LightProbeUsage)0;
		((Renderer)component2).reflectionProbeUsage = (ReflectionProbeUsage)0;
		if ((Object)(object)_sharedMaterial != (Object)null)
		{
			((Renderer)component2).sharedMaterial = _sharedMaterial;
		}
		float num = Mathf.Max(0.01f, Plugin.Instance.DotScale.Value);
		obj.transform.localScale = new Vector3(num, num, num);
		obj.SetActive(false);
		return obj;
	}

	private Material CreateSharedMaterial()
	{
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_0079: Expected O, but got Unknown
		Shader val = null;
		string[] shaderNames = ShaderNames;
		for (int i = 0; i < shaderNames.Length; i++)
		{
			val = Shader.Find(shaderNames[i]);
			if ((Object)(object)val != (Object)null)
			{
				break;
			}
		}
		if ((Object)(object)val == (Object)null)
		{
			Plugin.Log.LogWarning((object)("None of these shaders is in this game build: " + string.Join(", ", ShaderNames) + ". The dots use Unity's default material, so they are not see-through."));
			return null;
		}
		Material val2 = new Material(val)
		{
			color = _baseColor,
			renderQueue = 3500
		};
		if (val2.HasProperty("_ZWrite"))
		{
			val2.SetFloat("_ZWrite", 0f);
		}
		if (val2.HasProperty("_SrcBlend"))
		{
			val2.SetFloat("_SrcBlend", 5f);
		}
		if (val2.HasProperty("_DstBlend"))
		{
			val2.SetFloat("_DstBlend", 10f);
		}
		return val2;
	}

	private void ApplyDotAlpha(int i, float fade)
	{
		//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_0043: Unknown result type (might be due to invalid IL or missing references)
		MeshRenderer obj = _renderers[i];
		Color baseColor = _baseColor;
		baseColor.a = _baseColor.a * Mathf.Clamp01(fade);
		((Renderer)obj).GetPropertyBlock(_mpb);
		_mpb.SetColor(ColorPropId, baseColor);
		((Renderer)obj).SetPropertyBlock(_mpb);
	}

	private void HideAllDots()
	{
		if (!_anyDotVisible)
		{
			return;
		}
		_anyDotVisible = false;
		for (int i = 0; i < _dots.Count; i++)
		{
			if ((Object)(object)_dots[i] != (Object)null && _dots[i].activeSelf)
			{
				_dots[i].SetActive(false);
			}
		}
		Array.Clear(_wasVisible, 0, _wasVisible.Length);
	}

	private static Color ParseColor(string hex)
	{
		//IL_0028: 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)
		Color result = default(Color);
		if (!string.IsNullOrEmpty(hex) && ColorUtility.TryParseHtmlString(hex, ref result))
		{
			return result;
		}
		return new Color(1f, 1f, 1f, 0.33f);
	}

	private void ShowToast(string text)
	{
		_toastText = text;
		_toastUntil = Time.unscaledTime + 2f;
	}

	private void OnGUI()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Expected O, but got Unknown
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: 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_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Expected O, but got Unknown
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		if (!(Time.unscaledTime > _toastUntil) && !string.IsNullOrEmpty(_toastText))
		{
			if (_toastStyle == null)
			{
				_toastStyle = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18,
					alignment = (TextAnchor)4,
					fontStyle = (FontStyle)1
				};
				_toastStyle.normal.textColor = Color.white;
			}
			GUIContent val = new GUIContent(_toastText);
			float num = Mathf.Max(240f, _toastStyle.CalcSize(val).x + 32f);
			float num2 = 40f;
			Rect val2 = new Rect(((float)Screen.width - num) / 2f, (float)Screen.height * 0.18f, num, num2);
			Color color = GUI.color;
			GUI.color = new Color(0f, 0f, 0f, 0.6f);
			GUI.Box(val2, GUIContent.none);
			GUI.color = color;
			GUI.Label(val2, val, _toastStyle);
		}
	}
}
public enum PathfinderTargetMode
{
	Auto,
	Truck
}
[BepInPlugin("isaia.repopathfinder", "REPOPathfinder", "0.7.3")]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "isaia.repopathfinder";

	public const string NAME = "REPOPathfinder";

	public const string VERSION = "0.7.3";

	private const int CurrentConfigVersion = 3;

	public ConfigEntry<KeyCode> ToggleKey;

	public ConfigEntry<KeyCode> TargetToggleKey;

	public ConfigEntry<KeyCode> CustomizeMenuKey;

	public ConfigEntry<bool> EnabledOnStart;

	public ConfigEntry<PathfinderTargetMode> TargetMode;

	public ConfigEntry<float> Spacing;

	public ConfigEntry<int> MaxDots;

	public ConfigEntry<float> GroundOffset;

	public ConfigEntry<float> DotScale;

	public ConfigEntry<string> DotColorHex;

	public ConfigEntry<float> RecalcInterval;

	public ConfigEntry<float> MinDistanceToTarget;

	public ConfigEntry<float> FlowSpeed;

	public ConfigEntry<float> FadeZoneFraction;

	public ConfigEntry<float> PositionSmoothRate;

	public ConfigEntry<float> OffPathThreshold;

	public ConfigEntry<int> ConfigVersion;

	public static Plugin Instance { get; private set; }

	public static ManualLogSource Log { get; private set; }

	private void Awake()
	{
		//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Expected O, but got Unknown
		//IL_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_013b: Expected O, but got Unknown
		//IL_0194: Unknown result type (might be due to invalid IL or missing references)
		//IL_019e: Expected O, but got Unknown
		//IL_0241: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Expected O, but got Unknown
		//IL_027f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0289: Expected O, but got Unknown
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c7: Expected O, but got Unknown
		//IL_0382: Unknown result type (might be due to invalid IL or missing references)
		//IL_0387: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Expected O, but got Unknown
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0395: Unknown result type (might be due to invalid IL or missing references)
		//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
		ToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "ToggleKey", (KeyCode)285, "Key that toggles the on-the-ground guidance trail.");
		TargetToggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "TargetToggleKey", (KeyCode)286, "Key that switches the trail's destination between Auto (game-driven: current extraction, or truck when all are complete) and Truck (forces the truck so you can run back to charge items mid-run).");
		CustomizeMenuKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Input", "CustomizeMenuKey", (KeyCode)287, "Key that opens/closes the in-game customization panel for changing dot color, size, flow speed, and spacing with live preview.");
		EnabledOnStart = ((BaseUnityPlugin)this).Config.Bind<bool>("Input", "EnabledOnStart", false, "If true, the trail is visible immediately on every level. If false, you must press the toggle key.");
		TargetMode = ((BaseUnityPlugin)this).Config.Bind<PathfinderTargetMode>("Input", "TargetMode", PathfinderTargetMode.Auto, "Current target mode. Auto follows the game's own pathing logic. Truck always points back to the truck regardless of extraction state. Persisted across sessions; toggle at runtime with TargetToggleKey.");
		Spacing = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "SpacingMeters", 1.5f, new ConfigDescription("Distance between dots in meters along the path.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 4f), Array.Empty<object>()));
		MaxDots = ((BaseUnityPlugin)this).Config.Bind<int>("Trail", "MaxDots", 30, new ConfigDescription("Maximum number of dots placed at once. Higher values reach further but cost more.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		GroundOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "GroundOffsetMeters", 0.1f, "Small vertical offset above the NavMesh surface so dots don't z-fight with the floor.");
		DotScale = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "DotScale", 0.07f, new ConfigDescription("Diameter of each dot in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.02f, 0.5f), Array.Empty<object>()));
		DotColorHex = ((BaseUnityPlugin)this).Config.Bind<string>("Trail", "DotColorHex", "#FFFFFF55", "Dot color as #RRGGBBAA. Default is faint translucent white (~33% alpha).");
		RecalcInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "RecalcIntervalSeconds", 0.25f, "[Deprecated as of 0.5.0 - has no effect.] Path is now cached and only recomputed when the player wanders off-path or the target changes; see OffPathRecomputeThresholdMeters.");
		MinDistanceToTarget = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "MinDistanceToTargetMeters", 1.5f, "If the player is within this distance of the target, dots are hidden.");
		FlowSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "FlowSpeedMetersPerSec", 2f, new ConfigDescription("How fast dots flow forward along the path, in meters per second. The trail recycles continuously so the path is always populated from the player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 6f), Array.Empty<object>()));
		FadeZoneFraction = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "FadeZoneFraction", 0.4f, new ConfigDescription("Fraction of one spacing over which dots fade in (near the player end of the recycle) and fade out (near the front). Smaller = sharper edges; larger = softer flow.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 0.5f), Array.Empty<object>()));
		PositionSmoothRate = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "PositionSmoothRate", 25f, new ConfigDescription("Damping rate for dot world positions (1/seconds). The trail does not move with the player, but smoothing softens the jump when the path is re-oriented after a turn. Higher = snappier. Lower = softer. Set to 0 to disable.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 60f), Array.Empty<object>()));
		OffPathThreshold = ((BaseUnityPlugin)this).Config.Bind<float>("Trail", "OffPathRecomputeThresholdMeters", 3f, "When the player drifts further than this many meters from the cached path's polyline, the path is recomputed. Lower values make the trail re-orient faster after a turn but can cause spurious recomputes when hugging walls in wide rooms; higher values are steadier but lag longer after a deliberate turn into a different corridor.");
		ConfigVersion = ((BaseUnityPlugin)this).Config.Bind<int>("Internal", "ConfigVersion", 0, "Internal: do not edit. Tracks which set of defaults this config was created with so newer mod versions can migrate stale values.");
		if (ConfigVersion.Value < 3)
		{
			MigrateConfig(ConfigVersion.Value);
			ConfigVersion.Value = 3;
		}
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		try
		{
			((BaseUnityPlugin)this).Config.Save();
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("Could not write the config file: " + ex.Message));
		}
		GameAccess.Bind(Log);
		GameObject val = new GameObject("REPOPathfinderManager");
		Object.DontDestroyOnLoad((Object)val);
		((Object)val).hideFlags = (HideFlags)61;
		val.AddComponent<PathfinderManager>();
		val.AddComponent<PathfinderCustomizeUI>();
		Log.LogInfo((object)string.Format("{0} {1} loaded. Trail: {2}, target: {3}, customize: {4}.", "REPOPathfinder", "0.7.3", ToggleKey.Value, TargetToggleKey.Value, CustomizeMenuKey.Value));
	}

	private void MigrateConfig(int fromVersion)
	{
		if (DotColorHex.Value == "#00E5FFFF" || DotColorHex.Value == "#FFFFFFFF" || DotColorHex.Value == "#FFFFFF80")
		{
			DotColorHex.Value = (string)((ConfigEntryBase)DotColorHex).DefaultValue;
		}
		if (Mathf.Approximately(DotScale.Value, 0.25f) || Mathf.Approximately(DotScale.Value, 0.125f))
		{
			DotScale.Value = (float)((ConfigEntryBase)DotScale).DefaultValue;
		}
		Log.LogInfo((object)$"Migrated config from version {fromVersion} -> {3}.");
	}
}
public static class MyPluginInfo
{
	public const string PLUGIN_GUID = "REPOPathfinder";

	public const string PLUGIN_NAME = "REPOPathfinder";

	public const string PLUGIN_VERSION = "0.7.3";
}
internal static class PluginVersion
{
	public const string Value = "0.7.3";
}