Decompiled source of MapClickCodes v1.0.12

MapClickCodes.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

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

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 MapClickCodes
{
	internal static class HostModGate
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static HandleNamedMessageDelegate <0>__OnMessage;

			public static Action<ulong> <1>__OnClientConnected;
		}

		public const string MessageName = "MrGlim.MapClickCodes";

		private const byte OpHostHello = 0;

		private const byte OpClientSyncRequest = 1;

		private const byte OpActivateRequest = 2;

		private const float SyncRetryInterval = 2f;

		private static bool _registered;

		private static bool _clientConnectedHooked;

		private static bool _requestedSync;

		private static bool _clientHostEnabled;

		private static float _nextSyncRetry;

		private static NetworkManager? _hookedNm;

		public static bool HostHasMod
		{
			get
			{
				EnsureRegistered();
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null)
				{
					return true;
				}
				if (singleton.IsServer || singleton.IsHost)
				{
					return LocalEnabled();
				}
				return _clientHostEnabled;
			}
		}

		public static bool FeaturesActive => HostHasMod;

		public static bool WaitingForHostHello
		{
			get
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton == (Object)null || singleton.IsServer || singleton.IsHost)
				{
					return false;
				}
				if (singleton.IsConnectedClient)
				{
					return !_clientHostEnabled;
				}
				return false;
			}
		}

		private static bool LocalEnabled()
		{
			if (Plugin.Enabled != null)
			{
				return Plugin.Enabled.Value;
			}
			return false;
		}

		public static void Reset()
		{
			UnhookClientConnected();
			_registered = false;
			_clientConnectedHooked = false;
			_requestedSync = false;
			_clientHostEnabled = false;
			_nextSyncRetry = 0f;
			_hookedNm = null;
		}

		public static void Tick()
		{
			EnsureRegistered();
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer && !singleton.IsHost && singleton.IsConnectedClient && !_clientHostEnabled)
			{
				float unscaledTime = Time.unscaledTime;
				if (!(unscaledTime < _nextSyncRetry))
				{
					_nextSyncRetry = unscaledTime + 2f;
					RequestSync();
					Plugin.Log.LogInfo((object)"MapClickCodes: retrying host hello sync (gate still closed).");
				}
			}
		}

		public static void EnsureRegistered()
		{
			//IL_0087: 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_0092: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				if (_registered || _clientConnectedHooked)
				{
					Reset();
				}
				return;
			}
			if ((Object)(object)_hookedNm != (Object)null && _hookedNm != singleton)
			{
				UnhookClientConnected();
				_registered = false;
				_clientConnectedHooked = false;
				_requestedSync = false;
				_clientHostEnabled = false;
				_nextSyncRetry = 0f;
			}
			_hookedNm = singleton;
			if (!_registered)
			{
				CustomMessagingManager customMessagingManager = singleton.CustomMessagingManager;
				object obj = <>O.<0>__OnMessage;
				if (obj == null)
				{
					HandleNamedMessageDelegate val = OnMessage;
					<>O.<0>__OnMessage = val;
					obj = (object)val;
				}
				customMessagingManager.RegisterNamedMessageHandler("MrGlim.MapClickCodes", (HandleNamedMessageDelegate)obj);
				_registered = true;
				Plugin.Log.LogInfo((object)"MrGlim.MapClickCodes net handler registered.");
			}
			if (singleton.IsServer && !_clientConnectedHooked)
			{
				singleton.OnClientConnectedCallback += OnClientConnected;
				_clientConnectedHooked = true;
			}
			if (!singleton.IsServer && singleton.IsConnectedClient && !_requestedSync)
			{
				_requestedSync = true;
				_nextSyncRetry = Time.unscaledTime + 2f;
				RequestSync();
			}
		}

		private static void UnhookClientConnected()
		{
			if ((Object)(object)_hookedNm != (Object)null && _clientConnectedHooked)
			{
				try
				{
					_hookedNm.OnClientConnectedCallback -= OnClientConnected;
				}
				catch
				{
				}
			}
			_clientConnectedHooked = false;
		}

		private static void OnClientConnected(ulong clientId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.IsServer && clientId != singleton.LocalClientId)
			{
				SendHello(clientId);
			}
		}

		private static void RequestSync()
		{
			//IL_0034: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer && singleton.CustomMessagingManager != null)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
				byte b = 1;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("MrGlim.MapClickCodes", 0uL, val, (NetworkDelivery)2);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void SendHello(ulong clientId)
		{
			//IL_002b: 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_0044: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.IsServer)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(16, (Allocator)2, -1);
				byte b = 0;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				bool flag = LocalEnabled();
				((FastBufferWriter)(ref val)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("MrGlim.MapClickCodes", clientId, val, (NetworkDelivery)2);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		public static void SendActivateRequest(ulong networkObjectId, string objectCode)
		{
			//IL_005b: 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_006e: 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_0091: Unknown result type (might be due to invalid IL or missing references)
			EnsureRegistered();
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && !singleton.IsServer && singleton.IsConnectedClient && singleton.CustomMessagingManager != null)
			{
				string text = objectCode ?? "";
				int byteCount = Encoding.UTF8.GetByteCount(text);
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(24 + byteCount, (Allocator)2, -1);
				byte b = 2;
				((FastBufferWriter)(ref val)).WriteValueSafe<byte>(ref b, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
				((FastBufferWriter)(ref val)).WriteValueSafe(text, false);
				singleton.CustomMessagingManager.SendNamedMessage("MrGlim.MapClickCodes", 0uL, val, (NetworkDelivery)2);
				((FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnMessage(ulong sender, FastBufferReader reader)
		{
			//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_007b: 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_0050: 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)
			byte b = default(byte);
			((FastBufferReader)(ref reader)).ReadValueSafe<byte>(ref b, default(ForPrimitives));
			NetworkManager singleton = NetworkManager.Singleton;
			switch (b)
			{
			case 1:
				if ((Object)(object)singleton != (Object)null && singleton.IsServer)
				{
					SendHello(sender);
				}
				break;
			case 2:
				if (!((Object)(object)singleton == (Object)null) && singleton.IsServer)
				{
					ulong networkObjectId = default(ulong);
					((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref networkObjectId, default(ForPrimitives));
					string objectCode = default(string);
					((FastBufferReader)(ref reader)).ReadValueSafe(ref objectCode, false);
					HandleActivateOnHost(sender, networkObjectId, objectCode);
				}
				break;
			case 0:
			{
				bool clientHostEnabled = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref clientHostEnabled, default(ForPrimitives));
				if ((Object)(object)singleton != (Object)null && !singleton.IsServer)
				{
					_clientHostEnabled = clientHostEnabled;
					Plugin.Log.LogInfo((object)("Host hello: enabled=" + clientHostEnabled));
				}
				break;
			}
			}
		}

		private static void HandleActivateOnHost(ulong sender, ulong networkObjectId, string objectCode)
		{
			if (!LocalEnabled())
			{
				Plugin.Log.LogWarning((object)$"Ignoring activate from client {sender}: mod disabled on host.");
				return;
			}
			TerminalAccessibleObject val = null;
			if (networkObjectId != 0L)
			{
				NetworkManager singleton = NetworkManager.Singleton;
				if ((Object)(object)singleton != (Object)null && singleton.SpawnManager != null && singleton.SpawnManager.SpawnedObjects.TryGetValue(networkObjectId, out var value) && (Object)(object)value != (Object)null)
				{
					val = ((Component)value).GetComponent<TerminalAccessibleObject>();
				}
			}
			if ((Object)(object)val == (Object)null && !string.IsNullOrEmpty(objectCode))
			{
				TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
				foreach (TerminalAccessibleObject val2 in array)
				{
					if ((Object)(object)val2 != (Object)null && val2.objectCode == objectCode)
					{
						val = val2;
						break;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Log.LogWarning((object)$"Activate from client {sender}: object not found (netId={networkObjectId}, code='{objectCode}').");
				return;
			}
			string arg = val.objectCode ?? objectCode ?? "?";
			TerminalCodeActivation.Activate(val, $"host-for-client-{sender}|netId={networkObjectId}|code={arg}");
		}
	}
	[HarmonyPatch(typeof(GameNetworkManager), "Disconnect")]
	internal static class HostModGateDisconnectPatch
	{
		public static void Prefix()
		{
			HostModGate.Reset();
			Plugin.Log.LogInfo((object)"MrGlim.MapClickCodes gate reset on disconnect.");
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	internal static class HostModGateStartPatch
	{
		public static void Postfix()
		{
			HostModGate.EnsureRegistered();
		}
	}
	[HarmonyPatch(typeof(NetworkManager), "Initialize")]
	internal static class HostModGateNetworkInitPatch
	{
		public static void Postfix()
		{
			HostModGate.EnsureRegistered();
		}
	}
	internal static class MapCodeClickController
	{
		private static float _cooldown;

		private static float _gateWarnCooldown;

		private static readonly Vector3[] CornerBuf = (Vector3[])(object)new Vector3[4];

		private static readonly RaycastHit[] RayHitBuf = (RaycastHit[])(object)new RaycastHit[24];

		private static readonly List<(Vector2 uv, string tag)> UvCandidates = new List<(Vector2, string)>(24);

		private static bool _hasPhysicsUv;

		private static Vector2 _physicsUv;

		private static string _physicsUvTag = "none";

		private static bool _ensuredMeshColliderMesh;

		private static bool _ensuredMeshColliderMesh2;

		private static bool _loggedNonReadableSkip;

		private static TerminalAccessibleObject? _peekCacheTao;

		private static string _peekCacheCode = "";

		private static float _peekCacheTime = -999f;

		private static ulong _peekCacheNetId;

		private const float PeekCacheMaxAge = 0.25f;

		private static bool _crewReflectTried;

		private static bool _crewReflectOk;

		private static Type? _crewManagerType;

		private static PropertyInfo? _crewInstanceProp;

		private static FieldInfo? _crewSlotsField;

		private static FieldInfo? _crewSlotMapFeedCam;

		private static FieldInfo? _crewSlotMapFeedTex;

		private static FieldInfo? _crewSlotHost;

		private static FieldInfo? _crewSlotRenderer;

		private static FieldInfo? _crewSlotShowMapFeed;

		private const int ShipMonitorVertexCount = 281;

		private static readonly Vector3[] ShipScreenPos = (Vector3[])(object)new Vector3[8]
		{
			new Vector3(0.05606965f, -0.18378264f, -0.660835f),
			new Vector3(-0.06036048f, -0.3977934f, 0.34548202f),
			new Vector3(0.05606965f, -0.18378264f, 0.53623223f),
			new Vector3(-0.06036048f, -0.3977934f, -0.47008458f),
			new Vector3(-0.20738617f, -1.7347777f, -0.66081136f),
			new Vector3(-0.2457081f, -1.4885061f, 0.34549904f),
			new Vector3(-0.20738617f, -1.7347777f, 0.5362559f),
			new Vector3(-0.2457081f, -1.4885061f, -0.47006756f)
		};

		private static readonly Vector2[] ShipScreenUv = (Vector2[])(object)new Vector2[8]
		{
			new Vector2(1f, 0f),
			new Vector2(0.8535156f, 0.8408203f),
			new Vector2(1f, 1f),
			new Vector2(0.8535156f, 0.15930176f),
			new Vector2(1.127E-05f, 2.4E-07f),
			new Vector2(0.15014648f, 0.8408203f),
			new Vector2(6E-08f, 1f),
			new Vector2(0.15014648f, 0.15930176f)
		};

		private static readonly int[] ShipScreenTris = new int[30]
		{
			0, 1, 2, 0, 3, 1, 4, 3, 0, 2,
			1, 5, 3, 5, 1, 2, 5, 6, 6, 7,
			4, 4, 7, 3, 6, 5, 7, 3, 7, 5
		};

		private const float VanillaLensIntensity = 0.45f;

		private static bool _lensReflectTried;

		private static bool _loggedLensFallback;

		private static FieldInfo? _lensVolumeField;

		private static Type? _lensDistortionType;

		private static MethodInfo? _volumeTryGet;

		internal static void Tick()
		{
			HostModGate.EnsureRegistered();
			if (Plugin.Enabled == null || !Plugin.Enabled.Value)
			{
				return;
			}
			_cooldown -= Time.unscaledDeltaTime;
			_gateWarnCooldown -= Time.unscaledDeltaTime;
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null);
			if (!((Object)(object)val == (Object)null) && !val.isPlayerDead && val.isPlayerControlled && val.isInHangarShipRoom && WasInteractPressed(val))
			{
				if (!HostModGate.FeaturesActive)
				{
					LogGateBlocked();
					return;
				}
				if (_cooldown > 0f)
				{
					Plugin.Log.LogInfo((object)"MapClick: interact edge ignored (cooldown).");
					return;
				}
				bool num = IsLookingNearMapScreen(val);
				bool flag = IsMapRelatedInteractTrigger(val.hoveringOverTrigger);
				bool forceMapContext = num || flag;
				TryActivateFromCurrentLook(requireInteractPress: false, forceMapContext, alwaysLog: true);
			}
		}

		internal static bool TryPeekMarkerUnderLook(out TerminalAccessibleObject matched, out string objectCode)
		{
			matched = null;
			objectCode = "";
			if (Plugin.Enabled == null || !Plugin.Enabled.Value)
			{
				return false;
			}
			if (!HostModGate.FeaturesActive)
			{
				return false;
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null);
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !val.isPlayerControlled)
			{
				return false;
			}
			if (!val.isInHangarShipRoom)
			{
				return false;
			}
			bool forceMapContext = IsLookingNearMapScreen(val) || IsMapRelatedInteractTrigger(val.hoveringOverTrigger);
			if (!TryResolveLookMarker(val, forceMapContext, alwaysLog: false, allowCenterFallback: false, requireMeshUv: false, out matched, out float _, out Vector2 _, out string _, out string _, out string _))
			{
				return false;
			}
			objectCode = matched.objectCode ?? "?";
			CachePeekMarker(matched, objectCode);
			return true;
		}

		internal static bool TryActivateFromCurrentLook(bool requireInteractPress, bool forceMapContext = false, bool alwaysLog = false)
		{
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: Unknown result type (might be due to invalid IL or missing references)
			HostModGate.EnsureRegistered();
			if (Plugin.Enabled == null || !Plugin.Enabled.Value)
			{
				return false;
			}
			if (!HostModGate.FeaturesActive)
			{
				if (requireInteractPress || alwaysLog || WasInteractPressed(GameNetworkManager.Instance?.localPlayerController))
				{
					LogGateBlocked();
				}
				return false;
			}
			if (_cooldown > 0f)
			{
				return false;
			}
			GameNetworkManager instance = GameNetworkManager.Instance;
			PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null);
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !val.isPlayerControlled)
			{
				return false;
			}
			if (!val.isInHangarShipRoom)
			{
				return false;
			}
			if (requireInteractPress && !WasInteractPressed(val))
			{
				return false;
			}
			int num = CountActiveMarkers();
			if (TryGetFreshPeekCache(out TerminalAccessibleObject tao, out string code))
			{
				Plugin.Log.LogInfo((object)("MapClick: via=peek-cache code=" + code));
				_cooldown = 0.28f;
				Plugin.ClickConsumedThisFrame = true;
				ClearPeekCache();
				return ActivateCode(tao, 0f, "via=peek-cache", Vector2.zero, "peek-cache", num, "peek-cache");
			}
			if (!TryResolveLookMarker(val, forceMapContext, alwaysLog, allowCenterFallback: false, requireMeshUv: false, out TerminalAccessibleObject matched, out float score, out Vector2 bestUv, out string uvTag, out string matchHow, out string hitDiag))
			{
				if (TryGetFreshPeekCache(out tao, out code))
				{
					Plugin.Log.LogInfo((object)("MapClick: via=peek-cache code=" + code + " (after resolve miss)"));
					_cooldown = 0.28f;
					Plugin.ClickConsumedThisFrame = true;
					ClearPeekCache();
					return ActivateCode(tao, 0f, "via=peek-cache", Vector2.zero, "peek-cache", num, "peek-cache");
				}
				return false;
			}
			if (!IsHighConfidenceMatch(matchHow))
			{
				if (TryGetFreshPeekCache(out tao, out code))
				{
					Plugin.Log.LogInfo((object)("MapClick: via=peek-cache code=" + code + " (after low-conf " + matchHow + ")"));
					_cooldown = 0.28f;
					Plugin.ClickConsumedThisFrame = true;
					ClearPeekCache();
					return ActivateCode(tao, 0f, "via=peek-cache", bestUv, "peek-cache", num, "peek-cache");
				}
				LogClickAttempt(hitDiag, bestUv, uvTag, num, $"ignore-low-conf '{matched.objectCode}' via={matchHow} score={score:F4} (no activate)");
				Plugin.V("MapClick: low-confidence match via=" + matchHow + " — no activate.");
				return false;
			}
			Plugin.V($"MapClick: matched '{matched.objectCode}' via={matchHow} uvTag={uvTag} vp=({bestUv.x:F3},{bestUv.y:F3}) {hitDiag}");
			_cooldown = 0.28f;
			Plugin.ClickConsumedThisFrame = true;
			ClearPeekCache();
			return ActivateCode(matched, score, hitDiag, bestUv, uvTag, num, matchHow);
		}

		private static bool IsHighConfidenceMatch(string matchHow)
		{
			if (string.IsNullOrEmpty(matchHow))
			{
				return false;
			}
			switch (matchHow)
			{
			default:
				return matchHow == "peek-cache";
			case "aabb":
			case "gvp":
			case "bary":
			case "phys":
				return true;
			}
		}

		private static void CachePeekMarker(TerminalAccessibleObject tao, string code)
		{
			_peekCacheTao = tao;
			_peekCacheCode = code ?? "";
			_peekCacheTime = Time.unscaledTime;
			_peekCacheNetId = 0uL;
			try
			{
				if ((Object)(object)tao != (Object)null && (Object)(object)((NetworkBehaviour)tao).NetworkObject != (Object)null)
				{
					_peekCacheNetId = ((NetworkBehaviour)tao).NetworkObject.NetworkObjectId;
				}
			}
			catch
			{
			}
		}

		private static void ClearPeekCache()
		{
			_peekCacheTao = null;
			_peekCacheCode = "";
			_peekCacheTime = -999f;
			_peekCacheNetId = 0uL;
		}

		private static bool TryGetFreshPeekCache(out TerminalAccessibleObject tao, out string code)
		{
			tao = null;
			code = "";
			if ((Object)(object)_peekCacheTao == (Object)null)
			{
				return false;
			}
			if (Time.unscaledTime - _peekCacheTime > 0.25f)
			{
				return false;
			}
			if ((Object)(object)_peekCacheTao == (Object)null)
			{
				return false;
			}
			try
			{
				if (!((Behaviour)_peekCacheTao).isActiveAndEnabled && !((Component)_peekCacheTao).gameObject.activeInHierarchy)
				{
					return false;
				}
				if ((Object)(object)_peekCacheTao.mapRadarObject != (Object)null && !_peekCacheTao.mapRadarObject.activeInHierarchy)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			tao = _peekCacheTao;
			code = ((!string.IsNullOrEmpty(_peekCacheCode)) ? _peekCacheCode : (_peekCacheTao.objectCode ?? "?"));
			return true;
		}

		private static bool TryResolveLookMarker(PlayerControllerB player, bool forceMapContext, bool alwaysLog, bool allowCenterFallback, bool requireMeshUv, out TerminalAccessibleObject matched, out float score, out Vector2 bestUv, out string uvTag, out string matchHow, out string hitDiag)
		{
			//IL_000e: 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_0339: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: 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_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			matched = null;
			score = float.MaxValue;
			bestUv = default(Vector2);
			uvTag = "none";
			matchHow = "none";
			hitDiag = "via=none";
			_hasPhysicsUv = false;
			_physicsUv = default(Vector2);
			_physicsUvTag = "none";
			StartOfRound instance = StartOfRound.Instance;
			ManualCameraRenderer val = (((Object)(object)instance != (Object)null) ? instance.mapScreen : null);
			if ((Object)(object)val == (Object)null || (Object)(object)val.mapCamera == (Object)null)
			{
				if (alwaysLog)
				{
					Plugin.Log.LogInfo((object)"MapClick: no mapScreen / mapCamera.");
				}
				return false;
			}
			Camera val2 = (((Object)(object)player.gameplayCamera != (Object)null) ? player.gameplayCamera : Camera.main);
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			float num = ((Plugin.InteractRange != null) ? Plugin.InteractRange.Value : 4.5f);
			Ray val3 = default(Ray);
			((Ray)(ref val3))..ctor(((Component)val2).transform.position, ((Component)val2).transform.forward);
			Camera val4 = val.mapCamera;
			string diag = "crew=skip";
			bool flag = false;
			if (TryResolveMapScreenHit(val3, num, val, forceMapContext, out MeshRenderer screenMesh, out Vector3 hitPoint, out hitDiag))
			{
				flag = true;
			}
			else
			{
				try
				{
					if (TryResolveCrewMonitorMapHit(val3, num, out screenMesh, out hitPoint, out Camera markerCam, out diag))
					{
						val4 = markerCam;
						hitDiag = diag;
						if (!_hasPhysicsUv)
						{
							StringBuilder stringBuilder = new StringBuilder(24);
							TryEnrichMeshColliderLookUv(val3, Mathf.Max(num, 10f), screenMesh, ref hitPoint, stringBuilder);
							hitDiag += stringBuilder.ToString();
						}
						flag = true;
					}
				}
				catch (Exception ex)
				{
					Plugin.V("CrewMonitors resolve skipped: " + ex.Message);
					diag = "crew=skip";
					flag = false;
				}
			}
			if (!flag)
			{
				if (!string.IsNullOrEmpty(diag) && diag != "crew=skip")
				{
					hitDiag = (hitDiag ?? "via=none") + " | " + diag;
				}
				if (alwaysLog)
				{
					Plugin.Log.LogInfo((object)("MapClick: resolve-fail " + hitDiag));
				}
				else
				{
					Plugin.V("Map look miss (no mesh / out of range). " + hitDiag);
				}
				return false;
			}
			if ((Object)(object)val4 == (Object)null)
			{
				if (alwaysLog)
				{
					Plugin.Log.LogInfo((object)("MapClick: resolve-fail " + hitDiag + " (markerCam null)"));
				}
				return false;
			}
			if (IsVanillaShipMonitorMesh(screenMesh))
			{
				bool flag2 = TryShipMonitorContentViewport(val3, screenMesh, val, out bestUv, out uvTag);
				if (!flag2 || !TryScoreMarkersAtViewport(val4, bestUv, out matched, out score, out matchHow, out var _) || !(matchHow == "aabb"))
				{
					if (!flag2)
					{
						uvTag = "ship-glass-miss";
						matchHow = "none";
						bestUv = default(Vector2);
					}
					else if (matchHow != "aabb")
					{
						matchHow = "screen-miss";
					}
					int num2 = CountActiveMarkers();
					string text = (flag2 ? "ship-screen-no-aabb" : "ship-glass-miss");
					if (alwaysLog && num2 > 0)
					{
						LogClickAttempt(hitDiag, bestUv, uvTag ?? "none", num2, "miss why=" + text);
					}
					else
					{
						Plugin.V($"MapClick: miss why={text} markers={num2} {hitDiag} uvTag={uvTag}");
					}
					return false;
				}
				hitDiag = hitDiag + " | " + uvTag;
				return true;
			}
			if (!TryPickBestMarker(player, val4, hitPoint, screenMesh, requireMeshUv, out matched, out score, out bestUv, out uvTag, out matchHow))
			{
				if (allowCenterFallback && TryPickCenterFallback(val4, out matched, out score, out bestUv, out uvTag, out matchHow))
				{
					return true;
				}
				int num3 = CountActiveMarkers();
				string text2 = DescribeMissWhy(uvTag, _hasPhysicsUv);
				if (alwaysLog && num3 > 0)
				{
					LogClickAttempt(hitDiag, bestUv, uvTag ?? "none", num3, "miss why=" + text2);
				}
				else
				{
					Plugin.V($"MapClick: miss why={text2} markers={num3} {hitDiag} uvTag={uvTag}");
				}
				return false;
			}
			return true;
		}

		internal static bool IsLookingNearMapScreen(PlayerControllerB player)
		{
			//IL_006c: 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_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			StartOfRound instance = StartOfRound.Instance;
			ManualCameraRenderer val = (((Object)(object)instance != (Object)null) ? instance.mapScreen : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Camera val2 = (((Object)(object)player.gameplayCamera != (Object)null) ? player.gameplayCamera : Camera.main);
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			float range = ((Plugin.InteractRange != null) ? Plugin.InteractRange.Value : 4.5f);
			Ray val3 = default(Ray);
			((Ray)(ref val3))..ctor(((Component)val2).transform.position, ((Component)val2).transform.forward);
			MeshRenderer mesh = val.mesh;
			MeshRenderer mesh2 = val.mesh2;
			Bounds bounds;
			if ((Object)(object)mesh != (Object)null)
			{
				if (!IsWithinMapScreenRange(((Ray)(ref val3)).origin, mesh, range))
				{
					bounds = ((Renderer)mesh).bounds;
					if (!((Bounds)(ref bounds)).IntersectRay(val3))
					{
						goto IL_00c2;
					}
				}
				return true;
			}
			goto IL_00c2;
			IL_00c2:
			if ((Object)(object)mesh2 != (Object)null)
			{
				if (!IsWithinMapScreenRange(((Ray)(ref val3)).origin, mesh2, range))
				{
					bounds = ((Renderer)mesh2).bounds;
					if (!((Bounds)(ref bounds)).IntersectRay(val3))
					{
						goto IL_00f4;
					}
				}
				return true;
			}
			goto IL_00f4;
			IL_00f4:
			try
			{
				if (TryResolveCrewMonitorMapHit(val3, range, out MeshRenderer _, out Vector3 _, out Camera _, out string _))
				{
					return true;
				}
			}
			catch (Exception ex)
			{
				Plugin.V("CrewMonitors near-check skipped: " + ex.Message);
			}
			return false;
		}

		private static bool TryResolveMapScreenHit(Ray ray, float range, ManualCameraRenderer map, bool forceMapContext, out MeshRenderer screenMesh, out Vector3 hitPoint, out string diag)
		{
			//IL_0006: 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_00e0: 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_00f5: 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_0106: 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_01f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0287: 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_021b: 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_0236: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0338: Unknown result type (might be due to invalid IL or missing references)
			//IL_0357: Unknown result type (might be due to invalid IL or missing references)
			//IL_039f: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_0456: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0504: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0543: Unknown result type (might be due to invalid IL or missing references)
			//IL_055c: Unknown result type (might be due to invalid IL or missing references)
			screenMesh = null;
			hitPoint = default(Vector3);
			StringBuilder stringBuilder = new StringBuilder(160);
			EnsureRuntimeMapMeshCollider(map.mesh, ref _ensuredMeshColliderMesh);
			EnsureRuntimeMapMeshCollider(map.mesh2, ref _ensuredMeshColliderMesh2);
			bool flag = HasMeshCollider(map.mesh);
			bool flag2 = HasMeshCollider(map.mesh2);
			stringBuilder.Append("mc=");
			stringBuilder.Append(flag ? "1" : "0");
			stringBuilder.Append('/');
			stringBuilder.Append(flag2 ? "1" : "0");
			stringBuilder.Append(' ');
			int num = Physics.RaycastNonAlloc(ray, RayHitBuf, range, -1, (QueryTriggerInteraction)1);
			for (int i = 0; i < num - 1; i++)
			{
				for (int j = i + 1; j < num; j++)
				{
					if (((RaycastHit)(ref RayHitBuf[j])).distance < ((RaycastHit)(ref RayHitBuf[i])).distance)
					{
						RaycastHit val = RayHitBuf[i];
						RayHitBuf[i] = RayHitBuf[j];
						RayHitBuf[j] = val;
					}
				}
			}
			int num2 = Mathf.Min(num, 5);
			stringBuilder.Append("hits=");
			stringBuilder.Append(num);
			stringBuilder.Append('[');
			for (int k = 0; k < num2; k++)
			{
				if (k > 0)
				{
					stringBuilder.Append(',');
				}
				Collider collider = ((RaycastHit)(ref RayHitBuf[k])).collider;
				stringBuilder.Append(((Object)(object)collider != (Object)null) ? ((Object)collider).name : "?");
				stringBuilder.Append('@');
				stringBuilder.Append(((RaycastHit)(ref RayHitBuf[k])).distance.ToString("F2"));
			}
			if (num > num2)
			{
				stringBuilder.Append(",...");
			}
			stringBuilder.Append(']');
			for (int l = 0; l < num; l++)
			{
				if (IsMainMapScreenHit(RayHitBuf[l], map, out MeshRenderer screenMesh2))
				{
					screenMesh = screenMesh2;
					hitPoint = ((RaycastHit)(ref RayHitBuf[l])).point;
					RememberPhysicsUv(RayHitBuf[l], "phys|RaycastAll");
					TryEnrichMeshColliderLookUv(ray, Mathf.Max(range, 10f), screenMesh2, ref hitPoint, stringBuilder);
					stringBuilder.Append(" via=RaycastAll#");
					stringBuilder.Append(l);
					diag = stringBuilder.ToString();
					return true;
				}
			}
			float range2 = Mathf.Max(range, 10f);
			if (TryColliderRaycastMesh(ray, range2, map.mesh, out hitPoint, out screenMesh))
			{
				TryEnrichMeshColliderLookUv(ray, range2, screenMesh, ref hitPoint, stringBuilder);
				stringBuilder.Append(" via=Collider.Raycast(mesh)");
				diag = stringBuilder.ToString();
				return true;
			}
			if (TryColliderRaycastMesh(ray, range2, map.mesh2, out hitPoint, out screenMesh))
			{
				TryEnrichMeshColliderLookUv(ray, range2, screenMesh, ref hitPoint, stringBuilder);
				stringBuilder.Append(" via=Collider.Raycast(mesh2)");
				diag = stringBuilder.ToString();
				return true;
			}
			MeshRenderer val2 = (((Object)(object)map.mesh != (Object)null) ? map.mesh : map.mesh2);
			if ((Object)(object)val2 == (Object)null)
			{
				diag = stringBuilder.Append(" via=none").ToString();
				return false;
			}
			bool flag3 = IsWithinMapScreenRange(((Ray)(ref ray)).origin, val2, range) || ((Object)(object)map.mesh2 != (Object)null && IsWithinMapScreenRange(((Ray)(ref ray)).origin, map.mesh2, range));
			if (!forceMapContext && !flag3)
			{
				diag = stringBuilder.Append(" via=none").ToString();
				return false;
			}
			float num3 = Mathf.Max(range + 0.5f, 12f);
			if (TryBoundsIntersectRay(ray, val2, num3, out hitPoint))
			{
				screenMesh = val2;
				TryEnrichMeshColliderLookUv(ray, num3, val2, ref hitPoint, stringBuilder);
				stringBuilder.Append(forceMapContext ? " via=IntersectRay(force)" : " via=IntersectRay(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			if ((Object)(object)map.mesh2 != (Object)null && map.mesh2 != val2 && TryBoundsIntersectRay(ray, map.mesh2, num3, out hitPoint))
			{
				screenMesh = map.mesh2;
				TryEnrichMeshColliderLookUv(ray, num3, map.mesh2, ref hitPoint, stringBuilder);
				stringBuilder.Append(forceMapContext ? " via=IntersectRay2(force)" : " via=IntersectRay2(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			if (TryProjectOntoMeshPlane(ray, val2, out hitPoint))
			{
				screenMesh = val2;
				TryEnrichMeshColliderLookUv(ray, 12f, val2, ref hitPoint, stringBuilder);
				stringBuilder.Append(forceMapContext ? " via=plane(force)" : " via=plane(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			if ((Object)(object)map.mesh2 != (Object)null && map.mesh2 != val2 && TryProjectOntoMeshPlane(ray, map.mesh2, out hitPoint))
			{
				screenMesh = map.mesh2;
				TryEnrichMeshColliderLookUv(ray, 12f, map.mesh2, ref hitPoint, stringBuilder);
				stringBuilder.Append(forceMapContext ? " via=plane2(force)" : " via=plane2(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			if (forceMapContext)
			{
				if (TryClosestBoundsOnRay(ray, val2, out hitPoint))
				{
					screenMesh = val2;
					TryEnrichMeshColliderLookUv(ray, 12f, val2, ref hitPoint, stringBuilder);
					stringBuilder.Append(" via=ClosestBounds(force)");
					diag = stringBuilder.ToString();
					return true;
				}
				if ((Object)(object)map.mesh2 != (Object)null && map.mesh2 != val2 && TryClosestBoundsOnRay(ray, map.mesh2, out hitPoint))
				{
					screenMesh = map.mesh2;
					TryEnrichMeshColliderLookUv(ray, 12f, map.mesh2, ref hitPoint, stringBuilder);
					stringBuilder.Append(" via=ClosestBounds2(force)");
					diag = stringBuilder.ToString();
					return true;
				}
			}
			diag = stringBuilder.Append(" via=none").ToString();
			return false;
		}

		internal static bool IsMapRelatedInteractTrigger(InteractTrigger? trigger)
		{
			if ((Object)(object)trigger == (Object)null)
			{
				return false;
			}
			string s = (((Object)(object)((Component)trigger).gameObject != (Object)null) ? (((Object)((Component)trigger).gameObject).name ?? "") : "");
			string text = trigger.hoverTip ?? "";
			try
			{
				if (trigger.hoverTip == null && text.Length == 0)
				{
					text = "";
				}
			}
			catch
			{
			}
			if (!ContainsMapInteractKeyword(s))
			{
				return ContainsMapInteractKeyword(text);
			}
			return true;
		}

		private static bool ContainsMapInteractKeyword(string s)
		{
			if (string.IsNullOrEmpty(s))
			{
				return false;
			}
			if (s.IndexOf("Map", StringComparison.OrdinalIgnoreCase) < 0 && s.IndexOf("Switch", StringComparison.OrdinalIgnoreCase) < 0 && s.IndexOf("Radar", StringComparison.OrdinalIgnoreCase) < 0 && s.IndexOf("monitor", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return s.IndexOf("Monitor", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private static bool HasMeshCollider(MeshRenderer? mesh)
		{
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			if ((Object)(object)((Component)mesh).GetComponent<MeshCollider>() != (Object)null)
			{
				return true;
			}
			return (Object)(object)((Component)mesh).GetComponentInChildren<MeshCollider>() != (Object)null;
		}

		private static void EnsureRuntimeMapMeshCollider(MeshRenderer? mesh, ref bool ensuredFlag)
		{
			if (ensuredFlag || (Object)(object)mesh == (Object)null)
			{
				return;
			}
			ensuredFlag = true;
			if (HasMeshCollider(mesh))
			{
				return;
			}
			MeshFilter component = ((Component)mesh).GetComponent<MeshFilter>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
			{
				return;
			}
			if (!IsMeshCpuReadable(component.sharedMesh))
			{
				LogNonReadableSkipOnce(component.sharedMesh, "MeshCollider-add");
				return;
			}
			try
			{
				MeshCollider obj = ((Component)mesh).gameObject.AddComponent<MeshCollider>();
				obj.convex = false;
				obj.sharedMesh = component.sharedMesh;
				Plugin.V("MapClick: added runtime MeshCollider on '" + ((Object)mesh).name + "'.");
			}
			catch (Exception ex)
			{
				Plugin.V("MapClick: MeshCollider add failed on '" + ((Object)mesh).name + "': " + ex.Message);
			}
		}

		private static bool TryBoundsIntersectRay(Ray ray, MeshRenderer mesh, float maxDist, out Vector3 hitPoint)
		{
			//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_0018: 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_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)
			hitPoint = default(Vector3);
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			Bounds bounds = ((Renderer)mesh).bounds;
			float num = default(float);
			if (!((Bounds)(ref bounds)).IntersectRay(ray, ref num))
			{
				return false;
			}
			if (num < 0f || num > maxDist)
			{
				return false;
			}
			hitPoint = ((Ray)(ref ray)).GetPoint(num);
			return true;
		}

		private static bool TryClosestBoundsOnRay(Ray ray, MeshRenderer mesh, out Vector3 hitPoint)
		{
			//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_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0030: 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_004a: 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_0056: 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_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)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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_0104: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			hitPoint = default(Vector3);
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			Bounds bounds = ((Renderer)mesh).bounds;
			Vector3 val = ((Ray)(ref ray)).direction;
			Vector3 val2;
			if (!(((Vector3)(ref val)).sqrMagnitude > 1E-08f))
			{
				val2 = Vector3.forward;
			}
			else
			{
				val = ((Ray)(ref ray)).direction;
				val2 = ((Vector3)(ref val)).normalized;
			}
			Vector3 val3 = val2;
			float num = Vector3.Dot(((Bounds)(ref bounds)).center - ((Ray)(ref ray)).origin, val3);
			if (num < 0f)
			{
				num = 0f;
			}
			if (num > 20f)
			{
				num = 20f;
			}
			Vector3 val4 = ((Ray)(ref ray)).origin + val3 * num;
			hitPoint = ((Bounds)(ref bounds)).ClosestPoint(val4);
			float num2 = Vector3.Distance(hitPoint, val4);
			val = ((Bounds)(ref bounds)).size;
			if (num2 > ((Vector3)(ref val)).magnitude + 0.5f)
			{
				hitPoint = ((Bounds)(ref bounds)).center;
			}
			MeshCollider val5 = ((Component)mesh).GetComponent<MeshCollider>();
			if ((Object)(object)val5 == (Object)null)
			{
				val5 = ((Component)mesh).GetComponentInChildren<MeshCollider>();
			}
			if ((Object)(object)val5 != (Object)null)
			{
				try
				{
					Vector3 val6 = ((Collider)val5).ClosestPoint(hitPoint);
					val = val6 - hitPoint;
					if (((Vector3)(ref val)).sqrMagnitude < 0.25f)
					{
						hitPoint = val6;
					}
				}
				catch
				{
				}
			}
			return true;
		}

		private static bool TryColliderRaycastMesh(Ray ray, float range, MeshRenderer? mesh, out Vector3 hitPoint, out MeshRenderer screenMesh)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_00f7: 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_0101: 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_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: 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_00dd: 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)
			hitPoint = default(Vector3);
			screenMesh = null;
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			Collider[] componentsInChildren = ((Component)mesh).GetComponentsInChildren<Collider>(true);
			float num = float.MaxValue;
			bool flag = false;
			Vector3 val = default(Vector3);
			RaycastHit hit = default(RaycastHit);
			RaycastHit val3 = default(RaycastHit);
			foreach (Collider val2 in componentsInChildren)
			{
				if (!((Object)(object)val2 == (Object)null) && val2.enabled && val2.Raycast(ray, ref val3, range) && ((RaycastHit)(ref val3)).distance < num)
				{
					num = ((RaycastHit)(ref val3)).distance;
					val = ((RaycastHit)(ref val3)).point;
					hit = val3;
					flag = true;
				}
			}
			Collider[] componentsInParent = ((Component)mesh).GetComponentsInParent<Collider>(true);
			RaycastHit val5 = default(RaycastHit);
			foreach (Collider val4 in componentsInParent)
			{
				if (!((Object)(object)val4 == (Object)null) && val4.enabled && val4.Raycast(ray, ref val5, range) && ((RaycastHit)(ref val5)).distance < num)
				{
					num = ((RaycastHit)(ref val5)).distance;
					val = ((RaycastHit)(ref val5)).point;
					hit = val5;
					flag = true;
				}
			}
			if (!flag)
			{
				return false;
			}
			hitPoint = val;
			screenMesh = mesh;
			RememberPhysicsUv(hit, "phys|ColliderRaycast");
			return true;
		}

		private static void RememberPhysicsUv(RaycastHit hit, string tag)
		{
			//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)
			if (((RaycastHit)(ref hit)).collider is MeshCollider)
			{
				_physicsUv = ((RaycastHit)(ref hit)).textureCoord;
				_physicsUvTag = tag;
				_hasPhysicsUv = true;
			}
		}

		private static void TryEnrichMeshColliderLookUv(Ray lookRay, float range, MeshRenderer screenMesh, ref Vector3 hitPoint, StringBuilder? sb)
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)screenMesh == (Object)null))
			{
				MeshCollider orAddMapMeshCollider = GetOrAddMapMeshCollider(screenMesh);
				if ((Object)(object)orAddMapMeshCollider == (Object)null)
				{
					sb?.Append(" mcLook=0");
					return;
				}
				RaycastHit hit = default(RaycastHit);
				if (!((Collider)orAddMapMeshCollider).Raycast(lookRay, ref hit, range))
				{
					sb?.Append(" mcLook=0");
					return;
				}
				hitPoint = ((RaycastHit)(ref hit)).point;
				RememberPhysicsUv(hit, "phys|MeshColliderLook");
				sb?.Append(" mcLook=1");
			}
		}

		private static MeshCollider? GetOrAddMapMeshCollider(MeshRenderer screenMesh)
		{
			MeshCollider val = ((Component)screenMesh).GetComponent<MeshCollider>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)screenMesh).GetComponentInChildren<MeshCollider>();
			}
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
			MeshFilter component = ((Component)screenMesh).GetComponent<MeshFilter>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.sharedMesh == (Object)null)
			{
				return null;
			}
			if (!IsMeshCpuReadable(component.sharedMesh))
			{
				LogNonReadableSkipOnce(component.sharedMesh, "MeshCollider-look");
				return null;
			}
			try
			{
				val = ((Component)screenMesh).gameObject.AddComponent<MeshCollider>();
				val.convex = false;
				val.sharedMesh = component.sharedMesh;
				Plugin.V("MapClick: added runtime MeshCollider on '" + ((Object)screenMesh).name + "' (look-ray enrich).");
				return val;
			}
			catch (Exception ex)
			{
				Plugin.V("MapClick: MeshCollider add failed on '" + ((Object)screenMesh).name + "': " + ex.Message);
				return null;
			}
		}

		private static string DescribeMissWhy(string? uvTag, bool havePhysicsUv)
		{
			if (uvTag != null && uvTag.IndexOf("ss-only", StringComparison.Ordinal) >= 0)
			{
				return "ss-uv-no-aabb";
			}
			if (uvTag != null && uvTag.IndexOf("bounds-only", StringComparison.Ordinal) >= 0)
			{
				return "bounds-uv-no-aabb";
			}
			if (uvTag != null && uvTag.IndexOf("junkUV", StringComparison.Ordinal) >= 0)
			{
				return "junk-uv";
			}
			if (!havePhysicsUv && (uvTag == null || uvTag.StartsWith("tried:", StringComparison.Ordinal) || (uvTag != null && uvTag.IndexOf("bounds", StringComparison.Ordinal) >= 0)))
			{
				return "no-mesh-uv-no-aabb";
			}
			return "no-aabb";
		}

		private static bool IsWithinMapScreenRange(Vector3 origin, MeshRenderer mesh, float range)
		{
			//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_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Bounds bounds = ((Renderer)mesh).bounds;
			return Vector3.Distance(origin, ((Bounds)(ref bounds)).ClosestPoint(origin)) <= range + 0.35f;
		}

		private static bool TryProjectOntoMeshPlane(Ray ray, MeshRenderer mesh, out Vector3 hitPoint)
		{
			//IL_0001: 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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: 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_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: 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_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			hitPoint = default(Vector3);
			Transform transform = ((Component)mesh).transform;
			Plane val = default(Plane);
			((Plane)(ref val))..ctor(transform.forward, transform.position);
			MeshFilter component = ((Component)mesh).GetComponent<MeshFilter>();
			if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
			{
				Bounds bounds = component.sharedMesh.bounds;
				Vector3 size = ((Bounds)(ref bounds)).size;
				Vector3 val2 = ((size.x <= size.y && size.x <= size.z) ? Vector3.right : ((!(size.y <= size.x) || !(size.y <= size.z)) ? Vector3.forward : Vector3.up));
				Vector3 val3 = transform.TransformDirection(val2);
				Vector3 normalized = ((Vector3)(ref val3)).normalized;
				Vector3 val4 = transform.TransformPoint(((Bounds)(ref bounds)).center);
				((Plane)(ref val))..ctor(normalized, val4);
				if (Vector3.Dot(((Plane)(ref val)).normal, ((Ray)(ref ray)).origin - val4) < 0f)
				{
					((Plane)(ref val))..ctor(-((Plane)(ref val)).normal, val4);
				}
			}
			else if (Vector3.Dot(((Plane)(ref val)).normal, ((Ray)(ref ray)).origin - transform.position) < 0f)
			{
				((Plane)(ref val))..ctor(-((Plane)(ref val)).normal, transform.position);
			}
			float num = default(float);
			if (!((Plane)(ref val)).Raycast(ray, ref num) || num < 0f || num > 12f)
			{
				return false;
			}
			hitPoint = ((Ray)(ref ray)).GetPoint(num);
			Bounds bounds2 = ((Renderer)mesh).bounds;
			((Bounds)(ref bounds2)).Expand(0.08f);
			if (!((Bounds)(ref bounds2)).Contains(hitPoint))
			{
				Vector3 val5 = ((Bounds)(ref bounds2)).ClosestPoint(hitPoint);
				if (Vector3.Distance(val5, hitPoint) > 0.15f)
				{
					return false;
				}
				hitPoint = val5;
			}
			return true;
		}

		private static void LogClickAttempt(string hitDiag, Vector2 uv, string flipUsed, int markerCount, string best)
		{
			//IL_0030: 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)
			string text = ((markerCount == 0) ? (" " + ExplainZeroMarkers()) : "");
			Plugin.Log.LogInfo((object)$"MapClick: {hitDiag} UV=({uv.x:F3},{uv.y:F3}) flip={flipUsed} markers={markerCount}{text} → {best}");
		}

		private static int CountActiveMarkers()
		{
			int num = 0;
			TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
			foreach (TerminalAccessibleObject val in array)
			{
				if ((Object)(object)val != (Object)null && (Object)(object)val.mapRadarObject != (Object)null && val.mapRadarObject.activeInHierarchy)
				{
					num++;
				}
			}
			return num;
		}

		private static string ExplainZeroMarkers()
		{
			TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
			int num = array.Length;
			int num2 = 0;
			int num3 = 0;
			foreach (TerminalAccessibleObject val in array)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				if ((Object)(object)val.mapRadarObject != (Object)null)
				{
					num2++;
				}
				try
				{
					if ((Object)(object)val.mapRadarText != (Object)null && !string.IsNullOrEmpty(((TMP_Text)val.mapRadarText).text))
					{
						num3++;
					}
				}
				catch
				{
				}
			}
			if (num == 0)
			{
				return "(why: no TerminalAccessibleObject in scene — orbit/ship phase or not landed)";
			}
			return $"(why: tao={num} withMapRadarObj={num2} withMapRadarText={num3}; none active — orbit/ship or radar UI not shown)";
		}

		private static void LogGateBlocked()
		{
			if (!(_gateWarnCooldown > 0f))
			{
				_gateWarnCooldown = 2.5f;
				if (HostModGate.WaitingForHostHello)
				{
					Plugin.Log.LogWarning((object)"Map click blocked: HostModGate waiting for host hello (retrying sync).");
				}
				else
				{
					Plugin.Log.LogWarning((object)"Map click blocked: HostModGate FeaturesActive=false (host missing mod or disabled).");
				}
			}
		}

		private static bool IsMainMapScreenHit(RaycastHit hit, ManualCameraRenderer map, out MeshRenderer screenMesh)
		{
			//IL_0014: 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)
			screenMesh = null;
			if ((Object)(object)((RaycastHit)(ref hit)).collider == (Object)null)
			{
				return false;
			}
			if (OwnsRenderer(hit, map.mesh))
			{
				screenMesh = map.mesh;
				return true;
			}
			if (OwnsRenderer(hit, map.mesh2))
			{
				screenMesh = map.mesh2;
				return true;
			}
			return false;
		}

		private static bool OwnsRenderer(RaycastHit hit, MeshRenderer? mesh)
		{
			if ((Object)(object)mesh == (Object)null)
			{
				return false;
			}
			Transform transform = ((Component)((RaycastHit)(ref hit)).collider).transform;
			if (!((Object)(object)transform == (Object)(object)((Component)mesh).transform) && !transform.IsChildOf(((Component)mesh).transform) && !((Component)mesh).transform.IsChildOf(transform) && !((Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponent<MeshRenderer>() == (Object)(object)mesh))
			{
				return (Object)(object)((Component)((RaycastHit)(ref hit)).collider).GetComponentInParent<MeshRenderer>() == (Object)(object)mesh;
			}
			return true;
		}

		private static bool IsVanillaShipMonitorMesh(MeshRenderer? screenMesh)
		{
			if ((Object)(object)screenMesh == (Object)null)
			{
				return false;
			}
			MeshFilter component = ((Component)screenMesh).GetComponent<MeshFilter>();
			Mesh val = (((Object)(object)component != (Object)null) ? component.sharedMesh : null);
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			if (val.vertexCount == 281)
			{
				return string.Equals(((Object)val).name, "Cube.001", StringComparison.Ordinal);
			}
			return false;
		}

		private static bool TryShipMonitorContentViewport(Ray worldRay, MeshRenderer screenMesh, ManualCameraRenderer map, out Vector2 viewport, out string tag)
		{
			//IL_0001: 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)
			//IL_0023: 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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			viewport = default(Vector2);
			tag = "ship-screen";
			if (!TryRayMeshLocal(((Component)screenMesh).transform, worldRay, out var localOrigin, out var localDir))
			{
				return false;
			}
			if (!TryIntersectShipScreen(localOrigin, localDir, 12f, out var uv))
			{
				return false;
			}
			if (!TryReadMapLensDistortion(map, out var intensity, out var xMul, out var yMul, out var center, out var scale))
			{
				intensity = 0.45f;
				xMul = 1f;
				yMul = 1f;
				((Vector2)(ref center))..ctor(0.5f, 0.5f);
				scale = 1f;
				tag = "ship-screen|lens-vanilla";
				if (!_loggedLensFallback)
				{
					_loggedLensFallback = true;
					Plugin.V("MapClick: lens volume unread; using vanilla RadarCameraVolume intensity 0.45.");
				}
			}
			else
			{
				tag = ((intensity > 0.001f || intensity < -0.001f) ? $"ship-screen|lens{intensity:F2}" : "ship-screen|lens0");
			}
			viewport = DistortUvHdrp(uv, intensity, xMul, yMul, center, scale);
			return true;
		}

		private static bool TryRayMeshLocal(Transform t, Ray worldRay, out Vector3 localOrigin, out Vector3 localDir)
		{
			//IL_0004: 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_000e: 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_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			localOrigin = t.InverseTransformPoint(((Ray)(ref worldRay)).origin);
			Vector3 val = t.InverseTransformPoint(((Ray)(ref worldRay)).origin + ((Ray)(ref worldRay)).direction);
			localDir = val - localOrigin;
			if (((Vector3)(ref localDir)).sqrMagnitude < 1E-12f)
			{
				return false;
			}
			((Vector3)(ref localDir)).Normalize();
			return true;
		}

		private static bool TryIntersectShipScreen(Vector3 origin, Vector3 dir, float maxDist, out Vector2 uv)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0037: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0053: 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_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_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_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			uv = default(Vector2);
			float maxT = maxDist;
			bool result = false;
			for (int i = 0; i < ShipScreenTris.Length; i += 3)
			{
				Vector3 a = ShipScreenPos[ShipScreenTris[i]];
				Vector3 b = ShipScreenPos[ShipScreenTris[i + 1]];
				Vector3 c = ShipScreenPos[ShipScreenTris[i + 2]];
				if (RayTriangleBothSides(origin, dir, a, b, c, maxT, out var t, out var w, out var w2, out var w3))
				{
					maxT = t;
					Vector2 val = ShipScreenUv[ShipScreenTris[i]];
					Vector2 val2 = ShipScreenUv[ShipScreenTris[i + 1]];
					Vector2 val3 = ShipScreenUv[ShipScreenTris[i + 2]];
					uv = val * w + val2 * w2 + val3 * w3;
					result = true;
				}
			}
			return result;
		}

		private static bool RayTriangleBothSides(Vector3 origin, Vector3 dir, Vector3 a, Vector3 b, Vector3 c, float maxT, out float t, out float w0, out float w1, out float w2)
		{
			//IL_0020: 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_0022: 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_0028: 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_0030: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: 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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00b2: Unknown result type (might be due to invalid IL or missing references)
			t = 0f;
			w0 = (w1 = (w2 = 0f));
			Vector3 val = b - a;
			Vector3 val2 = c - a;
			Vector3 val3 = Vector3.Cross(dir, val2);
			float num = Vector3.Dot(val, val3);
			if (Mathf.Abs(num) < 1E-08f)
			{
				return false;
			}
			float num2 = 1f / num;
			Vector3 val4 = origin - a;
			float num3 = Vector3.Dot(val4, val3) * num2;
			if (num3 < -0.001f || num3 > 1.001f)
			{
				return false;
			}
			Vector3 val5 = Vector3.Cross(val4, val);
			float num4 = Vector3.Dot(dir, val5) * num2;
			if (num4 < -0.001f || num3 + num4 > 1.001f)
			{
				return false;
			}
			float num5 = Vector3.Dot(val2, val5) * num2;
			if (num5 < 0f || num5 > maxT)
			{
				return false;
			}
			t = num5;
			w1 = num3;
			w2 = num4;
			w0 = 1f - w1 - w2;
			return true;
		}

		private static Vector2 DistortUvHdrp(Vector2 uv, float intensity, float xMul, float yMul, Vector2 center, float scale)
		{
			//IL_0016: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00dd: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			if (Mathf.Abs(intensity) < 1E-05f || scale < 0.0001f)
			{
				return uv;
			}
			float num = 1.6f * Mathf.Max(Mathf.Abs(intensity * 100f), 1f);
			float num2 = MathF.PI / 180f * Mathf.Min(160f, num);
			float num3 = 2f * Mathf.Tan(num2 * 0.5f);
			Vector2 val = center * 2f - Vector2.one;
			float num4 = Mathf.Max(xMul, 0.0001f);
			float num5 = Mathf.Max(yMul, 0.0001f);
			float num6 = ((intensity >= 0f) ? num2 : (1f / num2));
			float num7 = 1f / scale;
			float num8 = intensity * 100f;
			uv = (uv - new Vector2(0.5f, 0.5f)) * num7 + new Vector2(0.5f, 0.5f);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(num4 * (uv.x - 0.5f - val.x), num5 * (uv.y - 0.5f - val.y));
			float magnitude = ((Vector2)(ref val2)).magnitude;
			if (magnitude < 1E-06f)
			{
				return uv;
			}
			float num9 = ((num8 > 0f) ? (Mathf.Tan(magnitude * num6) / (magnitude * num3)) : (1f / magnitude * num6 * Mathf.Atan(magnitude * num3)));
			return uv + val2 * (num9 - 1f);
		}

		private static bool TryReadMapLensDistortion(ManualCameraRenderer map, out float intensity, out float xMul, out float yMul, out Vector2 center, out float scale)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			intensity = 0f;
			xMul = 1f;
			yMul = 1f;
			center = new Vector2(0.5f, 0.5f);
			scale = 1f;
			if ((Object)(object)map == (Object)null)
			{
				return false;
			}
			EnsureLensReflect();
			if (_lensVolumeField == null || _lensDistortionType == null || _volumeTryGet == null)
			{
				return false;
			}
			object value;
			try
			{
				value = _lensVolumeField.GetValue(map);
			}
			catch
			{
				return false;
			}
			if (value == null)
			{
				return false;
			}
			object obj2 = null;
			PropertyInfo property = value.GetType().GetProperty("sharedProfile");
			if (property != null)
			{
				obj2 = property.GetValue(value);
			}
			if (obj2 == null)
			{
				PropertyInfo property2 = value.GetType().GetProperty("profile");
				if (property2 != null)
				{
					obj2 = property2.GetValue(value);
				}
			}
			if (obj2 == null)
			{
				return false;
			}
			object[] array = new object[1];
			bool flag;
			try
			{
				flag = (bool)_volumeTryGet.Invoke(obj2, array);
			}
			catch
			{
				return false;
			}
			if (!flag || array[0] == null)
			{
				return false;
			}
			object obj4 = array[0];
			if (!ReadMemberBool(obj4, "active", fallback: true))
			{
				intensity = 0f;
				return true;
			}
			if (!TryReadVolumeFloat(obj4, "intensity", out intensity, out var overrideState))
			{
				return false;
			}
			if (!overrideState)
			{
				intensity = 0f;
			}
			TryReadVolumeFloat(obj4, "xMultiplier", out xMul, out var overrideState2);
			TryReadVolumeFloat(obj4, "yMultiplier", out yMul, out overrideState2);
			TryReadVolumeVector2(obj4, "center", out center);
			TryReadVolumeFloat(obj4, "scale", out scale, out overrideState2);
			if (scale < 0.0001f)
			{
				scale = 1f;
			}
			return true;
		}

		private static void EnsureLensReflect()
		{
			if (_lensReflectTried)
			{
				return;
			}
			_lensReflectTried = true;
			_lensVolumeField = typeof(ManualCameraRenderer).GetField("lensDistortionVolume", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			_lensDistortionType = FindType("UnityEngine.Rendering.HighDefinition.LensDistortion");
			Type type = FindType("UnityEngine.Rendering.VolumeProfile");
			if (_lensDistortionType == null || type == null)
			{
				return;
			}
			MethodInfo[] methods = type.GetMethods(BindingFlags.Instance | BindingFlags.Public);
			foreach (MethodInfo methodInfo in methods)
			{
				if (!(methodInfo.Name != "TryGet") && methodInfo.IsGenericMethodDefinition)
				{
					ParameterInfo[] parameters = methodInfo.GetParameters();
					if (parameters.Length == 1 && parameters[0].IsOut)
					{
						_volumeTryGet = methodInfo.MakeGenericMethod(_lensDistortionType);
						break;
					}
				}
			}
		}

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

		private static bool ReadMemberBool(object obj, string name, bool fallback)
		{
			PropertyInfo property = obj.GetType().GetProperty(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.PropertyType == typeof(bool))
			{
				return (bool)property.GetValue(obj);
			}
			FieldInfo field = obj.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && field.FieldType == typeof(bool))
			{
				return (bool)field.GetValue(obj);
			}
			return fallback;
		}

		private static bool TryReadVolumeFloat(object comp, string name, out float value, out bool overrideState)
		{
			value = 0f;
			overrideState = false;
			FieldInfo field = comp.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				return false;
			}
			object value2 = field.GetValue(comp);
			if (value2 == null)
			{
				return false;
			}
			overrideState = ReadMemberBool(value2, "overrideState", fallback: false);
			PropertyInfo property = value2.GetType().GetProperty("value", BindingFlags.Instance | BindingFlags.Public);
			if (property == null)
			{
				return false;
			}
			if (property.GetValue(value2) is float num)
			{
				value = num;
				return true;
			}
			return false;
		}

		private static bool TryReadVolumeVector2(object comp, string name, out Vector2 value)
		{
			//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_006b: 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_0073: 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)
			value = new Vector2(0.5f, 0.5f);
			FieldInfo field = comp.GetType().GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field == null)
			{
				return false;
			}
			object value2 = field.GetValue(comp);
			if (value2 == null)
			{
				return false;
			}
			PropertyInfo property = value2.GetType().GetProperty("value", BindingFlags.Instance | BindingFlags.Public);
			if (property == null)
			{
				return false;
			}
			if (property.GetValue(value2) is Vector2 val)
			{
				value = val;
				return true;
			}
			return false;
		}

		private static bool TryPickBestMarker(PlayerControllerB player, Camera mapCamera, Vector3 hitPoint, MeshRenderer screenMesh, bool requireMeshUv, out TerminalAccessibleObject matched, out float bestScore, out Vector2 bestUv, out string bestUvTag, out string matchHow)
		{
			//IL_000e: 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_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: 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_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0334: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			matched = null;
			bestScore = float.MaxValue;
			bestUv = default(Vector2);
			bestUvTag = "none";
			matchHow = "none";
			if (TryMatchMarkersByGameplayViewport(player, mapCamera, hitPoint, screenMesh, out matched, out bestScore, out bestUv, out bestUvTag, out matchHow))
			{
				Plugin.V($"MapClick: GVP win how={matchHow} score={bestScore:F4} tag={bestUvTag}");
				return true;
			}
			CollectUvCandidates(player, hitPoint, screenMesh, UvCandidates);
			if (UvCandidates.Count == 0)
			{
				return false;
			}
			bool flag = false;
			bool flag2 = false;
			for (int i = 0; i < UvCandidates.Count; i++)
			{
				string item = UvCandidates[i].tag;
				if (item.StartsWith("phys", StringComparison.Ordinal) || item.StartsWith("tex", StringComparison.Ordinal) || item.StartsWith("bary", StringComparison.Ordinal))
				{
					flag = true;
				}
				if (item.StartsWith("ss", StringComparison.Ordinal))
				{
					flag2 = true;
				}
			}
			bool flag3 = Plugin.FlipUvV == null || Plugin.FlipUvV.Value;
			TerminalAccessibleObject val = null;
			float num = float.MaxValue;
			Vector2 val2 = default(Vector2);
			string text = "none";
			string text2 = "none";
			for (int j = 0; j < UvCandidates.Count; j++)
			{
				(Vector2 uv, string tag) tuple = UvCandidates[j];
				Vector2 item2 = tuple.uv;
				string item3 = tuple.tag;
				bool flag4 = item3.StartsWith("phys", StringComparison.Ordinal) || item3.StartsWith("tex", StringComparison.Ordinal) || item3.StartsWith("bary", StringComparison.Ordinal);
				bool flag5 = item3.StartsWith("ss", StringComparison.Ordinal);
				bool flag6 = item3.IndexOf("bounds", StringComparison.Ordinal) >= 0;
				if (((flag2 || flag) && flag6) || (requireMeshUv && !flag4 && !flag5 && flag) || (flag5 && IsEdgeUv(item2) && flag) || (flag5 && IsEdgeUv(item2) && !flag))
				{
					continue;
				}
				float num2 = 0f;
				if (flag5)
				{
					num2 -= 0.55f;
				}
				if (flag4)
				{
					num2 -= 0.45f;
				}
				if (flag6)
				{
					num2 += 0.35f;
				}
				if (flag6 && IsEdgeUv(item2))
				{
					num2 += 0.5f;
				}
				bool flag7 = item3.IndexOf("vFlip", StringComparison.Ordinal) >= 0;
				bool flag8 = item3.IndexOf("vRaw", StringComparison.Ordinal) >= 0;
				if (flag3 && flag7)
				{
					num2 -= 0.001f;
				}
				else if (!flag3 && flag8)
				{
					num2 -= 0.001f;
				}
				if (TryScoreMarkersAtViewport(mapCamera, item2, out TerminalAccessibleObject matched2, out float bestScore2, out string matchHow2, out float rank))
				{
					float num3 = rank + num2;
					if (num3 < num)
					{
						num = num3;
						val = matched2;
						bestScore = bestScore2;
						val2 = item2;
						text = item3;
						text2 = matchHow2;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				bestUv = UvCandidates[0].uv;
				if (flag2 && !flag)
				{
					bestUvTag = "ss-only|tried:" + UvCandidates.Count;
				}
				else if (!flag && !flag2)
				{
					bestUvTag = "bounds-only|tried:" + UvCandidates.Count;
				}
				else
				{
					bestUvTag = (IsCornerJunkUv(bestUv) ? ("junkUV|tried:" + UvCandidates.Count) : ("tried:" + UvCandidates.Count));
				}
				return false;
			}
			matched = val;
			bestUv = val2;
			bestUvTag = ((flag2 || flag) ? text : (text + "|picked"));
			matchHow = text2;
			Plugin.V($"MapClick: UV win tag={bestUvTag} how={text2} score={bestScore:F4} ss={flag2} meshUv={flag}");
			return true;
		}

		private static void CollectUvCandidates(PlayerControllerB player, Vector3 worldPoint, MeshRenderer screenMesh, List<(Vector2 uv, string tag)> into)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_0040: 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_0065: 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_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: 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_0124: 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_0135: 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_0146: 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_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			into.Clear();
			bool flag = false;
			bool flag2 = false;
			if (TryScreenSpaceMonitorUv(player, screenMesh, worldPoint, out var uv) && !IsCornerJunkUv(uv))
			{
				AddUvVariants(into, uv, "ss");
				flag2 = true;
			}
			if (_hasPhysicsUv && !IsCornerJunkUv(_physicsUv))
			{
				AddUvVariants(into, _physicsUv, _physicsUvTag);
				flag = true;
			}
			if (TryMeshColliderTextureUv(screenMesh, worldPoint, out var uv2) && !IsCornerJunkUv(uv2))
			{
				AddUvVariants(into, uv2, "tex");
				flag = true;
			}
			if (TryBarycentricMeshUv(screenMesh, worldPoint, out var uv3, out var dist) && !IsCornerJunkUv(uv3))
			{
				AddUvVariants(into, uv3, $"bary|d{dist:F3}");
				flag = true;
			}
			if (flag2 || flag)
			{
				return;
			}
			MeshFilter component = ((Component)screenMesh).GetComponent<MeshFilter>();
			if (!((Object)(object)component == (Object)null) && !((Object)(object)component.sharedMesh == (Object)null))
			{
				Bounds bounds = component.sharedMesh.bounds;
				Vector3 local = ((Component)screenMesh).transform.InverseTransformPoint(worldPoint);
				float x = ((Bounds)(ref bounds)).size.x;
				float y = ((Bounds)(ref bounds)).size.y;
				float z = ((Bounds)(ref bounds)).size.z;
				if (x <= y && x <= z)
				{
					AddBoundsOrientation(into, bounds, local, 1, 2, "yz");
					AddBoundsOrientation(into, bounds, local, 0, 2, "xz");
					AddBoundsOrientation(into, bounds, local, 0, 1, "xy");
				}
				else if (y <= x && y <= z)
				{
					AddBoundsOrientation(into, bounds, local, 0, 2, "xz");
					AddBoundsOrientation(into, bounds, local, 1, 2, "yz");
					AddBoundsOrientation(into, bounds, local, 0, 1, "xy");
				}
				else
				{
					AddBoundsOrientation(into, bounds, local, 0, 1, "xy");
					AddBoundsOrientation(into, bounds, local, 1, 2, "yz");
					AddBoundsOrientation(into, bounds, local, 0, 2, "xz");
				}
				if (!HasNonJunkUv(into))
				{
					into.Clear();
				}
			}
		}

		private static bool IsEdgeUv(Vector2 uv)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			if (!(uv.x <= 0.02f) && !(uv.x >= 0.98f) && !(uv.y <= 0.02f))
			{
				return uv.y >= 0.98f;
			}
			return true;
		}

		private static bool IsCornerJunkUv(Vector2 uv)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: 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)
			bool num = uv.x <= 0.005f || uv.x >= 0.995f;
			bool flag = uv.y <= 0.005f || uv.y >= 0.995f;
			return num && flag;
		}

		private static bool HasNonJunkUv(List<(Vector2 uv, string tag)> list)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < list.Count; i++)
			{
				if (!IsCornerJunkUv(list[i].uv))
				{
					return true;
				}
			}
			return false;
		}

		private static bool TryMeshColliderTextureUv(MeshRenderer screenMesh, Vector3 worldPoint, out Vector2 uv)
		{
			//IL_0001: 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_0049: 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_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: 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_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: 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_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			uv = default(Vector2);
			MeshCollider val = ((Component)screenMesh).GetComponent<MeshCollider>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)screenMesh).GetComponentInChildren<MeshCollider>();
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Vector3[] array = (Vector3[])(object)new Vector3[6]
			{
				((Component)screenMesh).transform.forward,
				-((Component)screenMesh).transform.forward,
				((Component)screenMesh).transform.up,
				-((Component)screenMesh).transform.up,
				((Component)screenMesh).transform.right,
				-((Component)screenMesh).transform.right
			};
			Ray val3 = default(Ray);
			RaycastHit val4 = default(RaycastHit);
			for (int i = 0; i < array.Length; i++)
			{
				Vector3 val2 = array[i];
				if (((Vector3)(ref val2)).sqrMagnitude < 1E-08f)
				{
					continue;
				}
				((Vector3)(ref val2)).Normalize();
				((Ray)(ref val3))..ctor(worldPoint - val2 * 0.2f, val2);
				if (((Collider)val).Raycast(val3, ref val4, 0.5f))
				{
					uv = ((RaycastHit)(ref val4)).textureCoord;
					if (uv.x > 0.001f || uv.y > 0.001f || uv.x + uv.y > 0.001f)
					{
						return true;
					}
					if (((RaycastHit)(ref val4)).distance < 0.45f)
					{
						return true;
					}
				}
			}
			return false;
		}

		private static bool IsMeshCpuReadable(Mesh? mesh)
		{
			if ((Object)(object)mesh != (Object)null)
			{
				return mesh.isReadable;
			}
			return false;
		}

		private static void LogNonReadableSkipOnce(Mesh mesh, string path)
		{
			if (!_loggedNonReadableSkip)
			{
				_loggedNonReadableSkip = true;
				Plugin.V("MapClick: skip CPU mesh path '" + path + "' — mesh '" + ((Object)mesh).name + "' isReadable=false (use ss/gvp/phys/bounds).");
			}
		}

		private static bool TryBarycentricMeshUv(MeshRenderer screenMesh, Vector3 worldPoint, out Vector2 uv, out float dist)
		{
			//IL_0001: 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)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: 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_0132: 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