Decompiled source of GuidedCompany v1.0.1

GuidedCompany.dll

Decompiled 7 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GuidedCompany
{
	public static class Configuration
	{
		public static ConfigEntry<string> TrailColorHex { get; private set; }

		public static ConfigEntry<float> PulseDuration { get; private set; }

		public static ConfigEntry<float> PulseSpeed { get; private set; }

		public static ConfigEntry<float> TrailWidth { get; private set; }

		public static ConfigEntry<float> HeightOffset { get; private set; }

		public static ConfigEntry<string> TargetMode { get; private set; }

		public static Color TrailColor { get; private set; } = new Color(1f, 0.42f, 0f, 1f);

		public static void Init(ConfigFile config)
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			TrailColorHex = config.Bind<string>("Visual", "TrailColorHex", "#FF6A00", "Hex color code for the orange pulse trail (default: #FF6A00 high-vis orange).");
			PulseDuration = config.Bind<float>("Visual", "PulseDuration", 2.5f, "Duration of the pulse animation in seconds (matches scan duration).");
			PulseSpeed = config.Bind<float>("Visual", "PulseSpeed", 45f, "Speed at which the pulse wave travels along the path in meters per second.");
			TrailWidth = config.Bind<float>("Visual", "TrailWidth", 0.24f, "Width of the trail in meters.");
			HeightOffset = config.Bind<float>("Visual", "HeightOffset", 0.25f, "Vertical offset in meters above terrain to prevent clipping/z-fighting.");
			TargetMode = config.Bind<string>("Behavior", "TargetMode", "MainEntrance", "Entrance target mode: 'MainEntrance' or 'NearestEntrance'.");
			Color trailColor = default(Color);
			if (ColorUtility.TryParseHtmlString(TrailColorHex.Value, ref trailColor))
			{
				TrailColor = trailColor;
			}
			else
			{
				TrailColor = new Color(1f, 0.42f, 0f, 1f);
			}
		}
	}
	public static class EntranceManager
	{
		public struct EntranceInfo
		{
			public int entranceId;

			public Vector3 worldPosition;

			public Vector3 navMeshPosition;

			public bool hasNavMesh;

			public bool isMainEntrance;
		}

		private static readonly List<EntranceInfo> cachedOutsideEntrances = new List<EntranceInfo>();

		private static bool isCacheValid = false;

		public static void ClearCache()
		{
			cachedOutsideEntrances.Clear();
			isCacheValid = false;
		}

		public static void RefreshEntrances()
		{
			//IL_0100: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: 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_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			cachedOutsideEntrances.Clear();
			EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>(true);
			if (array != null && array.Length != 0)
			{
				NavMeshHit val3 = default(NavMeshHit);
				foreach (EntranceTeleport val in array)
				{
					if (!((Object)(object)val == (Object)null) && val.isEntranceToBuilding)
					{
						Vector3 val2 = (((Object)(object)val.entrancePoint != (Object)null) ? val.entrancePoint.position : ((Component)val).transform.position);
						bool flag = NavMesh.SamplePosition(val2, ref val3, 30f, -1);
						EntranceInfo item = new EntranceInfo
						{
							entranceId = val.entranceId,
							worldPosition = val2,
							navMeshPosition = (flag ? ((NavMeshHit)(ref val3)).position : val2),
							hasNavMesh = flag,
							isMainEntrance = (val.entranceId == 0)
						};
						cachedOutsideEntrances.Add(item);
					}
				}
			}
			if (cachedOutsideEntrances.Count == 0 && (Object)(object)RoundManager.Instance != (Object)null)
			{
				Vector3 val4 = RoundManager.FindMainEntrancePosition(false, true);
				if (val4 != Vector3.zero)
				{
					NavMeshHit val5 = default(NavMeshHit);
					bool flag2 = NavMesh.SamplePosition(val4, ref val5, 30f, -1);
					EntranceInfo item2 = new EntranceInfo
					{
						entranceId = 0,
						worldPosition = val4,
						navMeshPosition = (flag2 ? ((NavMeshHit)(ref val5)).position : val4),
						hasNavMesh = flag2,
						isMainEntrance = true
					};
					cachedOutsideEntrances.Add(item2);
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogInfo((object)"EntranceManager: Found main entrance via RoundManager.FindMainEntrancePosition fallback.");
					}
				}
			}
			isCacheValid = cachedOutsideEntrances.Count > 0;
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogInfo((object)$"EntranceManager: Cached {cachedOutsideEntrances.Count} outside facility entrances.");
			}
		}

		public static bool GetTargetEntrance(Vector3 playerPos, out Vector3 targetWorldPos, out Vector3 targetNavPos)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: 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_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			targetWorldPos = Vector3.zero;
			targetNavPos = Vector3.zero;
			if (!isCacheValid || cachedOutsideEntrances.Count == 0)
			{
				RefreshEntrances();
				if (!isCacheValid || cachedOutsideEntrances.Count == 0)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)"EntranceManager: Could not find any outside facility entrance.");
					}
					return false;
				}
			}
			if (!string.Equals(Configuration.TargetMode.Value, "NearestEntrance", StringComparison.OrdinalIgnoreCase))
			{
				for (int i = 0; i < cachedOutsideEntrances.Count; i++)
				{
					if (cachedOutsideEntrances[i].isMainEntrance)
					{
						targetWorldPos = cachedOutsideEntrances[i].worldPosition;
						targetNavPos = cachedOutsideEntrances[i].navMeshPosition;
						return true;
					}
				}
			}
			float num = float.MaxValue;
			int num2 = -1;
			for (int j = 0; j < cachedOutsideEntrances.Count; j++)
			{
				float num3 = Vector3.Distance(playerPos, cachedOutsideEntrances[j].worldPosition);
				if (num3 < num)
				{
					num = num3;
					num2 = j;
				}
			}
			if (num2 >= 0)
			{
				targetWorldPos = cachedOutsideEntrances[num2].worldPosition;
				targetNavPos = cachedOutsideEntrances[num2].navMeshPosition;
				return true;
			}
			return false;
		}
	}
	[BepInPlugin("com.khameli0n.guidedcompany", "GuidedCompany", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.khameli0n.guidedcompany";

		public const string PLUGIN_NAME = "GuidedCompany";

		public const string PLUGIN_VERSION = "1.0.1";

		public const string PLUGIN_AUTHOR = "Khameli0n";

		private Harmony harmony;

		private bool subscribedToGlobalScanAction;

		private float lastMouseScanTime = -1f;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_0072: 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_0083: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Configuration.Init(((BaseUnityPlugin)this).Config);
			try
			{
				harmony = new Harmony("com.khameli0n.guidedcompany");
				harmony.PatchAll();
				Log.LogInfo((object)"Harmony patches applied successfully!");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply Harmony patches: {arg}");
			}
			if ((Object)(object)PulseTrailRenderer.Instance == (Object)null)
			{
				GameObject val = new GameObject("GuidedCompany_PulseTrailRenderer");
				val.AddComponent<PulseTrailRenderer>();
				Object.DontDestroyOnLoad((Object)val);
			}
			Log.LogInfo((object)"GuidedCompany v1.0.1 by Khameli0n loaded successfully!");
		}

		private void Update()
		{
			if (!subscribedToGlobalScanAction)
			{
				try
				{
					InputActionAsset actions = InputSystem.actions;
					InputAction val = ((actions != null) ? actions.FindAction("PingScan", false) : null);
					if (val != null)
					{
						val.performed += OnGlobalScanPerformed;
						subscribedToGlobalScanAction = true;
						ManualLogSource log = Log;
						if (log != null)
						{
							log.LogInfo((object)"Successfully subscribed to InputSystem global 'PingScan' action performed event!");
						}
					}
				}
				catch (Exception ex)
				{
					ManualLogSource log2 = Log;
					if (log2 != null)
					{
						log2.LogWarning((object)("InputSystem action subscription error: " + ex.Message));
					}
				}
			}
			try
			{
				if (Mouse.current != null && (Mouse.current.rightButton.wasPressedThisFrame || (Mouse.current.rightButton.isPressed && Time.time - lastMouseScanTime > 0.45f)))
				{
					lastMouseScanTime = Time.time;
					ManualLogSource log3 = Log;
					if (log3 != null)
					{
						log3.LogInfo((object)"Scan triggered via Mouse.current.rightButton!");
					}
					PulseTrailRenderer.Instance?.TriggerPulse();
				}
			}
			catch
			{
			}
			try
			{
				InputActionAsset actions2 = InputSystem.actions;
				InputAction val2 = ((actions2 != null) ? actions2.FindAction("PingScan", false) : null);
				if (val2 != null && (val2.WasPressedThisFrame() || val2.triggered) && Time.time - lastMouseScanTime > 0.45f)
				{
					lastMouseScanTime = Time.time;
					ManualLogSource log4 = Log;
					if (log4 != null)
					{
						log4.LogInfo((object)"Scan triggered via InputSystem PingScan.WasPressedThisFrame!");
					}
					PulseTrailRenderer.Instance?.TriggerPulse();
				}
			}
			catch
			{
			}
		}

		private void OnGlobalScanPerformed(CallbackContext context)
		{
			if (((CallbackContext)(ref context)).performed)
			{
				ManualLogSource log = Log;
				if (log != null)
				{
					log.LogInfo((object)"Scan triggered via global PingScan action callback!");
				}
				PulseTrailRenderer.Instance?.TriggerPulse();
			}
		}

		private void OnDestroy()
		{
			try
			{
				Harmony obj = harmony;
				if (obj != null)
				{
					obj.UnpatchSelf();
				}
			}
			catch
			{
			}
		}
	}
	public class PulseTrailRenderer : MonoBehaviour
	{
		private LineRenderer lineRenderer;

		private Material trailMaterial;

		private GameObject entranceBeacon;

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

		private readonly List<Vector3> waypoints = new List<Vector3>(128);

		private float pulseStartTime;

		private bool isPulsing;

		private float lastTriggerTime = -1f;

		public static PulseTrailRenderer Instance { get; private set; }

		public bool HasEnteredFacilityThisRound { get; private set; }

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			SetupComponents();
		}

		private void SetupComponents()
		{
			//IL_00fe: 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)
			((Component)this).gameObject.layer = LayerMask.NameToLayer("Default");
			lineRenderer = ((Component)this).gameObject.GetComponent<LineRenderer>();
			if ((Object)(object)lineRenderer == (Object)null)
			{
				lineRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>();
			}
			lineRenderer.useWorldSpace = true;
			lineRenderer.numCornerVertices = 6;
			lineRenderer.numCapVertices = 6;
			lineRenderer.alignment = (LineAlignment)0;
			((Renderer)lineRenderer).shadowCastingMode = (ShadowCastingMode)0;
			((Renderer)lineRenderer).receiveShadows = false;
			lineRenderer.startWidth = 0.42f;
			lineRenderer.endWidth = 0.42f;
			((Renderer)lineRenderer).enabled = false;
			if ((Object)(object)entranceBeacon == (Object)null)
			{
				entranceBeacon = GameObject.CreatePrimitive((PrimitiveType)0);
				((Object)entranceBeacon).name = "GuidedCompany_EntranceBeacon";
				Object.Destroy((Object)(object)entranceBeacon.GetComponent<Collider>());
				entranceBeacon.transform.localScale = Vector3.one * 2.2f;
				entranceBeacon.SetActive(false);
				Object.DontDestroyOnLoad((Object)(object)entranceBeacon);
			}
		}

		public void EnsureMaterial()
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Expected O, but got Unknown
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Expected O, but got Unknown
			if ((Object)(object)trailMaterial != (Object)null && (Object)(object)trailMaterial.shader != (Object)null && ((Object)trailMaterial.shader).name != "HDRP/Unlit")
			{
				return;
			}
			Material val = null;
			if ((Object)(object)HUDManager.Instance != (Object)null && (Object)(object)HUDManager.Instance.hologramMaterial != (Object)null)
			{
				val = HUDManager.Instance.hologramMaterial;
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"PulseTrailRenderer: Cloned hologramMaterial from HUDManager.");
				}
			}
			else if ((Object)(object)StartOfRound.Instance != (Object)null && (Object)(object)StartOfRound.Instance.mapScreen != (Object)null && (Object)(object)StartOfRound.Instance.mapScreen.radarLineMaterial != (Object)null)
			{
				val = StartOfRound.Instance.mapScreen.radarLineMaterial;
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogInfo((object)"PulseTrailRenderer: Cloned radarLineMaterial from mapScreen.");
				}
			}
			else if ((Object)(object)ShipBuildModeManager.Instance != (Object)null && (Object)(object)ShipBuildModeManager.Instance.ghostObjectGreen != (Object)null)
			{
				val = ShipBuildModeManager.Instance.ghostObjectGreen;
				ManualLogSource log3 = Plugin.Log;
				if (log3 != null)
				{
					log3.LogInfo((object)"PulseTrailRenderer: Cloned ghostObjectGreen from ShipBuildModeManager.");
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				trailMaterial = new Material(val);
			}
			else if ((Object)(object)trailMaterial == (Object)null)
			{
				Shader val2 = Shader.Find("Sprites/Default") ?? Shader.Find("Legacy Shaders/Particles/Additive") ?? Shader.Find("Unlit/Color");
				if ((Object)(object)val2 != (Object)null)
				{
					trailMaterial = new Material(val2);
				}
			}
			if (!((Object)(object)trailMaterial != (Object)null))
			{
				return;
			}
			ConfigureMaterial(trailMaterial);
			if ((Object)(object)lineRenderer != (Object)null)
			{
				((Renderer)lineRenderer).material = trailMaterial;
			}
			if ((Object)(object)entranceBeacon != (Object)null)
			{
				((Renderer)entranceBeacon.GetComponent<MeshRenderer>()).material = trailMaterial;
			}
			for (int i = 0; i < guideSpheres.Count; i++)
			{
				if ((Object)(object)guideSpheres[i] != (Object)null)
				{
					((Renderer)guideSpheres[i].GetComponent<MeshRenderer>()).material = trailMaterial;
				}
			}
		}

		private void ConfigureMaterial(Material mat)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_008a: 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)
			if (!((Object)(object)mat == (Object)null))
			{
				Color val = default(Color);
				((Color)(ref val))..ctor(1f, 0.42f, 0f, 1f);
				mat.color = val;
				if (mat.HasProperty("_UnlitColor"))
				{
					mat.SetColor("_UnlitColor", val);
				}
				if (mat.HasProperty("_BaseColor"))
				{
					mat.SetColor("_BaseColor", val);
				}
				if (mat.HasProperty("_Color"))
				{
					mat.SetColor("_Color", val);
				}
				if (mat.HasProperty("_EmissiveColor"))
				{
					mat.SetColor("_EmissiveColor", val * 5f);
				}
				mat.renderQueue = 3200;
			}
		}

		public void TriggerPulse()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			if (Time.time - lastTriggerTime < 0.25f)
			{
				return;
			}
			lastTriggerTime = Time.time;
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController ?? GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val == (Object)null || val.isPlayerDead)
			{
				return;
			}
			if (val.isInsideFactory)
			{
				HasEnteredFacilityThisRound = true;
				StopPulse();
			}
			else
			{
				if (HasEnteredFacilityThisRound || ((Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipHasLanded))
				{
					return;
				}
				EnsureMaterial();
				Vector3 position = ((Component)val).transform.position;
				if (!EntranceManager.GetTargetEntrance(position, out var targetWorldPos, out var targetNavPos) || targetWorldPos == Vector3.zero)
				{
					ManualLogSource log = Plugin.Log;
					if (log != null)
					{
						log.LogWarning((object)"TriggerPulse: Could not locate facility entrance.");
					}
					return;
				}
				BuildPath(position, targetWorldPos, targetNavPos);
				if (waypoints.Count >= 2)
				{
					lineRenderer.positionCount = waypoints.Count;
					lineRenderer.SetPositions(waypoints.ToArray());
					((Renderer)lineRenderer).enabled = true;
					if ((Object)(object)entranceBeacon != (Object)null)
					{
						entranceBeacon.transform.position = targetWorldPos + Vector3.up * 1.8f;
						entranceBeacon.SetActive(true);
					}
					UpdateGuideSpheres();
					SetAlpha(1f);
					pulseStartTime = Time.time;
					isPulsing = true;
					ManualLogSource log2 = Plugin.Log;
					if (log2 != null)
					{
						log2.LogInfo((object)$"TriggerPulse: Displaying pulse trail ({waypoints.Count} waypoints) to entrance at {targetWorldPos}!");
					}
					if ((Object)(object)HUDManager.Instance != (Object)null)
					{
						HUDManager.Instance.DisplayTip("GuidedCompany", "Facility path mapped!", false, false, "LC_GuidedCompany");
					}
				}
			}
		}

		private void BuildPath(Vector3 playerPos, Vector3 targetWorldPos, Vector3 targetNavPos)
		{
			//IL_0011: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			//IL_005c: 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_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: 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_0055: 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_0051: 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_0084: 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_013f: 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_0143: 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_014a: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			waypoints.Clear();
			float num = 0.55f;
			NavMeshHit val2 = default(NavMeshHit);
			Vector3 val = (NavMesh.SamplePosition(playerPos, ref val2, 60f, -1) ? ((NavMeshHit)(ref val2)).position : playerPos);
			Vector3 val3 = targetNavPos;
			if (val3 == Vector3.zero)
			{
				NavMeshHit val4 = default(NavMeshHit);
				val3 = ((!NavMesh.SamplePosition(targetWorldPos, ref val4, 60f, -1)) ? targetWorldPos : ((NavMeshHit)(ref val4)).position);
			}
			NavMeshPath val5 = new NavMeshPath();
			if (NavMesh.CalculatePath(val, val3, -1, val5) && val5.corners != null && val5.corners.Length != 0)
			{
				waypoints.Add(playerPos + Vector3.up * num);
				for (int i = 0; i < val5.corners.Length; i++)
				{
					waypoints.Add(val5.corners[i] + Vector3.up * num);
				}
				waypoints.Add(targetWorldPos + Vector3.up * num);
				return;
			}
			waypoints.Add(playerPos + Vector3.up * num);
			int num2 = 28;
			int num3 = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.walkableSurfacesMask : (-1));
			RaycastHit val7 = default(RaycastHit);
			for (int j = 1; j < num2; j++)
			{
				float num4 = (float)j / (float)num2;
				Vector3 val6 = Vector3.Lerp(playerPos, targetWorldPos, num4);
				if (Physics.Raycast(val6 + Vector3.up * 50f, Vector3.down, ref val7, 100f, num3))
				{
					val6.y = ((RaycastHit)(ref val7)).point.y;
				}
				waypoints.Add(val6 + Vector3.up * num);
			}
			waypoints.Add(targetWorldPos + Vector3.up * num);
		}

		private void UpdateGuideSpheres()
		{
			//IL_0019: 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_0077: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			float num2 = 0f;
			for (int i = 1; i < waypoints.Count - 1; i++)
			{
				num2 += Vector3.Distance(waypoints[i - 1], waypoints[i]);
				if (!(num2 >= 6f))
				{
					continue;
				}
				num2 = 0f;
				GameObject val;
				if (num < guideSpheres.Count)
				{
					val = guideSpheres[num];
				}
				else
				{
					val = GameObject.CreatePrimitive((PrimitiveType)0);
					Object.Destroy((Object)(object)val.GetComponent<Collider>());
					val.transform.localScale = Vector3.one * 0.6f;
					if ((Object)(object)trailMaterial != (Object)null)
					{
						((Renderer)val.GetComponent<MeshRenderer>()).material = trailMaterial;
					}
					guideSpheres.Add(val);
					Object.DontDestroyOnLoad((Object)(object)val);
				}
				val.transform.position = waypoints[i];
				val.SetActive(true);
				num++;
			}
			for (int j = num; j < guideSpheres.Count; j++)
			{
				if ((Object)(object)guideSpheres[j] != (Object)null)
				{
					guideSpheres[j].SetActive(false);
				}
			}
		}

		private void SetAlpha(float alpha)
		{
			//IL_002b: 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_006b: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//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)
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.42f, 0f, alpha);
			if ((Object)(object)lineRenderer != (Object)null)
			{
				lineRenderer.startColor = val;
				lineRenderer.endColor = val;
			}
			if ((Object)(object)trailMaterial != (Object)null)
			{
				if (trailMaterial.HasProperty("_UnlitColor"))
				{
					trailMaterial.SetColor("_UnlitColor", val);
				}
				if (trailMaterial.HasProperty("_BaseColor"))
				{
					trailMaterial.SetColor("_BaseColor", val);
				}
				if (trailMaterial.HasProperty("_Color"))
				{
					trailMaterial.SetColor("_Color", val);
				}
				if (trailMaterial.HasProperty("_EmissiveColor"))
				{
					trailMaterial.SetColor("_EmissiveColor", val * 5f * alpha);
				}
			}
		}

		public void StopPulse()
		{
			isPulsing = false;
			if ((Object)(object)lineRenderer != (Object)null)
			{
				((Renderer)lineRenderer).enabled = false;
				lineRenderer.positionCount = 0;
			}
			if ((Object)(object)entranceBeacon != (Object)null)
			{
				entranceBeacon.SetActive(false);
			}
			for (int i = 0; i < guideSpheres.Count; i++)
			{
				if ((Object)(object)guideSpheres[i] != (Object)null)
				{
					guideSpheres[i].SetActive(false);
				}
			}
		}

		public void ResetRoundState()
		{
			HasEnteredFacilityThisRound = false;
			StopPulse();
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"PulseTrailRenderer: State reset for new landing/round.");
			}
		}

		private void Update()
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			PlayerControllerB val = StartOfRound.Instance?.localPlayerController ?? GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.inShipPhase && !StartOfRound.Instance.shipHasLanded)
			{
				if (HasEnteredFacilityThisRound)
				{
					ResetRoundState();
				}
				if (isPulsing)
				{
					StopPulse();
				}
			}
			else if ((Object)(object)val != (Object)null && val.isInsideFactory && !HasEnteredFacilityThisRound)
			{
				HasEnteredFacilityThisRound = true;
				StopPulse();
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"PulseTrailRenderer: Player entered complex. Guidance completed for this expedition.");
				}
			}
			else
			{
				if (!isPulsing)
				{
					return;
				}
				if ((Object)(object)val == (Object)null || val.isPlayerDead || val.isInsideFactory || HasEnteredFacilityThisRound)
				{
					StopPulse();
					return;
				}
				float num = 3f;
				float num2 = Time.time - pulseStartTime;
				if (num2 >= num)
				{
					StopPulse();
					return;
				}
				float alpha = ((num2 < 1.2f) ? 1f : Mathf.Clamp01(1f - (num2 - 1.2f) / (num - 1.2f)));
				if (lineRenderer.positionCount > 0 && waypoints.Count > 0)
				{
					lineRenderer.SetPosition(0, ((Component)val).transform.position + Vector3.up * 0.55f);
				}
				SetAlpha(alpha);
			}
		}
	}
}
namespace GuidedCompany.Patches
{
	[HarmonyPatch(typeof(HUDManager))]
	public static class HUDScanPatch
	{
		private static float lastScanTime = -1f;

		[HarmonyPatch("PingScan_performed")]
		[HarmonyPrefix]
		public static void PingScan_Prefix(CallbackContext context)
		{
			try
			{
				if (!(Time.time - lastScanTime < 0.25f))
				{
					lastScanTime = Time.time;
					PulseTrailRenderer.Instance?.TriggerPulse();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("HUDScanPatch PingScan_Prefix error: " + ex.Message));
				}
			}
		}

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void HUDUpdate_Postfix(HUDManager __instance, float ___playerPingingScan)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null) && ___playerPingingScan > 0.05f && Time.time - lastScanTime > 0.35f)
				{
					lastScanTime = Time.time;
					PulseTrailRenderer.Instance?.TriggerPulse();
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogWarning((object)("HUDScanPatch HUDUpdate error: " + ex.Message));
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public static class PlayerControllerScanPatch
	{
		private static float lastPlayerScanTime = -1f;

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void PlayerUpdate_Postfix(PlayerControllerB __instance)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)__instance == (Object)null || ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController) || __instance.isPlayerDead)
				{
					return;
				}
				bool flag = false;
				try
				{
					int num;
					if (__instance.playerActions != null)
					{
						MovementActions movement = __instance.playerActions.Movement;
						if (((MovementActions)(ref movement)).PingScan.triggered)
						{
							num = 1;
							goto IL_007c;
						}
					}
					num = ((Mouse.current != null && Mouse.current.rightButton.wasPressedThisFrame) ? 1 : 0);
					goto IL_007c;
					IL_007c:
					flag = (byte)num != 0;
				}
				catch
				{
				}
				if (flag && Time.time - lastPlayerScanTime > 0.3f)
				{
					lastPlayerScanTime = Time.time;
					PulseTrailRenderer.Instance?.TriggerPulse();
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound))]
	public static class RoundLifecyclePatch
	{
		[HarmonyPatch("ShipLeave")]
		[HarmonyPostfix]
		public static void ShipLeave_Postfix()
		{
			try
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"RoundLifecyclePatch: Ship is leaving. Resetting GuidedCompany state.");
				}
				EntranceManager.ClearCache();
				PulseTrailRenderer.Instance?.ResetRoundState();
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("RoundLifecyclePatch ShipLeave error: " + ex.Message));
				}
			}
		}

		[HarmonyPatch("StartGame")]
		[HarmonyPostfix]
		public static void StartGame_Postfix()
		{
			try
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					log.LogInfo((object)"RoundLifecyclePatch: New day/round started. Resetting GuidedCompany state.");
				}
				EntranceManager.ClearCache();
				PulseTrailRenderer.Instance?.ResetRoundState();
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					log2.LogWarning((object)("RoundLifecyclePatch StartGame error: " + ex.Message));
				}
			}
		}
	}
}