Decompiled source of MapClickCodes v1.0.3

MapClickCodes.dll

Decompiled 19 hours ago
using System;
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 Unity.Collections;
using Unity.Netcode;
using UnityEngine;
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.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3")]
[assembly: AssemblyProduct("MapClickCodes")]
[assembly: AssemblyTitle("MapClickCodes")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.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 ?? "?";
			Plugin.Log.LogInfo((object)$"Host activating terminal code '{arg}' for client {sender} (netId={networkObjectId}).");
			val.CallFunctionFromTerminal();
		}
	}
	[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)>(16);

		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 = (Object)(object)val.hoveringOverTrigger != (Object)null;
				bool forceMapContext = num || flag;
				TryActivateFromCurrentLook(requireInteractPress: false, forceMapContext, alwaysLog: true);
			}
		}

		internal static bool TryActivateFromCurrentLook(bool requireInteractPress, bool forceMapContext = false, bool alwaysLog = false)
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: 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;
			}
			StartOfRound instance2 = StartOfRound.Instance;
			ManualCameraRenderer val2 = (((Object)(object)instance2 != (Object)null) ? instance2.mapScreen : null);
			if ((Object)(object)val2 == (Object)null || (Object)(object)val2.mapCamera == (Object)null)
			{
				if (alwaysLog || forceMapContext)
				{
					Plugin.Log.LogInfo((object)"MapClick: no mapScreen / mapCamera.");
				}
				return false;
			}
			Camera val3 = (((Object)(object)val.gameplayCamera != (Object)null) ? val.gameplayCamera : Camera.main);
			if ((Object)(object)val3 == (Object)null)
			{
				return false;
			}
			float range = ((Plugin.InteractRange != null) ? Plugin.InteractRange.Value : 4.5f);
			if (!TryResolveMapScreenHit(new Ray(((Component)val3).transform.position, ((Component)val3).transform.forward), range, val2, forceMapContext, out MeshRenderer screenMesh, out Vector3 hitPoint, out string diag))
			{
				if (alwaysLog || forceMapContext)
				{
					Plugin.Log.LogInfo((object)("MapClick: resolve-fail " + diag));
				}
				else
				{
					Plugin.V("Map look miss (no mesh / out of range). " + diag);
				}
				return false;
			}
			if (!TryPickBestMarker(val2.mapCamera, hitPoint, screenMesh, out TerminalAccessibleObject matched, out float bestScore, out Vector2 bestUv, out string bestUvTag, out string matchHow))
			{
				int markerCount = CountActiveMarkers();
				LogClickAttempt(diag, bestUv, bestUvTag, markerCount, "miss");
				Plugin.V("Map look UV candidates exhausted — no marker. " + diag);
				return false;
			}
			int markerCount2 = CountActiveMarkers();
			LogClickAttempt(diag, bestUv, bestUvTag, markerCount2, $"hit '{matched.objectCode}' score={bestScore:F4} via={matchHow} vp=({bestUv.x:F3},{bestUv.y:F3})");
			_cooldown = 0.28f;
			Plugin.ClickConsumedThisFrame = true;
			ActivateCode(matched, bestScore);
			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_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_00f3;
					}
				}
				return true;
			}
			goto IL_00f3;
			IL_00f3:
			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_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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_0078: 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_0086: 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)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_0254: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_03af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0342: Unknown result type (might be due to invalid IL or missing references)
			//IL_0303: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_037f: Unknown result type (might be due to invalid IL or missing references)
			screenMesh = null;
			hitPoint = default(Vector3);
			StringBuilder stringBuilder = new StringBuilder(128);
			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;
					stringBuilder.Append(" via=RaycastAll#");
					stringBuilder.Append(l);
					diag = stringBuilder.ToString();
					return true;
				}
			}
			if (TryColliderRaycastMesh(ray, range, map.mesh, out hitPoint, out screenMesh))
			{
				stringBuilder.Append(" via=Collider.Raycast(mesh)");
				diag = stringBuilder.ToString();
				return true;
			}
			if (TryColliderRaycastMesh(ray, range, map.mesh2, out hitPoint, out screenMesh))
			{
				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 flag = IsWithinMapScreenRange(((Ray)(ref ray)).origin, val2, range) || ((Object)(object)map.mesh2 != (Object)null && IsWithinMapScreenRange(((Ray)(ref ray)).origin, map.mesh2, range));
			if (!forceMapContext && !flag)
			{
				diag = stringBuilder.Append(" via=none").ToString();
				return false;
			}
			float maxDist = Mathf.Max(range + 0.5f, 12f);
			if (TryBoundsIntersectRay(ray, val2, maxDist, out hitPoint))
			{
				screenMesh = val2;
				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, maxDist, out hitPoint))
			{
				screenMesh = map.mesh2;
				stringBuilder.Append(forceMapContext ? " via=IntersectRay2(force)" : " via=IntersectRay2(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			if (forceMapContext)
			{
				if (TryClosestBoundsOnRay(ray, val2, out hitPoint))
				{
					screenMesh = val2;
					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;
					stringBuilder.Append(" via=ClosestBounds2(force)");
					diag = stringBuilder.ToString();
					return true;
				}
			}
			if (TryProjectOntoMeshPlane(ray, val2, out hitPoint))
			{
				screenMesh = val2;
				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;
				stringBuilder.Append(forceMapContext ? " via=plane2(force)" : " via=plane2(near)");
				diag = stringBuilder.ToString();
				return true;
			}
			diag = stringBuilder.Append(" via=none").ToString();
			return false;
		}

		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)
			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;
			}
			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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			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 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;
					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;
					flag = true;
				}
			}
			if (!flag)
			{
				return false;
			}
			hitPoint = val;
			screenMesh = mesh;
			return true;
		}

		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_0016: 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)
			Plugin.Log.LogInfo((object)$"MapClick: {hitDiag} UV=({uv.x:F3},{uv.y:F3}) flip={flipUsed} markers={markerCount} → {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 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 TryPickBestMarker(Camera mapCamera, Vector3 hitPoint, MeshRenderer screenMesh, out TerminalAccessibleObject matched, out float bestScore, out Vector2 bestUv, out string bestUvTag, out string matchHow)
		{
			//IL_000d: 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_005c: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			matched = null;
			bestScore = float.MaxValue;
			bestUv = default(Vector2);
			bestUvTag = "none";
			matchHow = "none";
			CollectUvCandidates(hitPoint, screenMesh, UvCandidates);
			if (UvCandidates.Count == 0)
			{
				return false;
			}
			bool flag = 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 i = 0; i < UvCandidates.Count; i++)
			{
				(Vector2 uv, string tag) tuple = UvCandidates[i];
				Vector2 item = tuple.uv;
				string item2 = tuple.tag;
				float num2 = 0f;
				bool flag2 = item2.IndexOf("vFlip", StringComparison.Ordinal) >= 0;
				bool flag3 = item2.IndexOf("vRaw", StringComparison.Ordinal) >= 0;
				if (flag && flag2)
				{
					num2 = -0.001f;
				}
				else if (!flag && flag3)
				{
					num2 = -0.001f;
				}
				if (TryScoreMarkersAtViewport(mapCamera, item, 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 = item;
						text = item2;
						text2 = matchHow2;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				bestUv = UvCandidates[0].uv;
				bestUvTag = "tried:" + UvCandidates.Count;
				return false;
			}
			matched = val;
			bestUv = val2;
			bestUvTag = text;
			matchHow = text2;
			return true;
		}

		private static void CollectUvCandidates(Vector3 worldPoint, MeshRenderer screenMesh, List<(Vector2 uv, string tag)> into)
		{
			//IL_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_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_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0100: 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_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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			into.Clear();
			MeshCollider val = ((Component)screenMesh).GetComponent<MeshCollider>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)screenMesh).GetComponentInChildren<MeshCollider>();
			}
			if ((Object)(object)val != (Object)null)
			{
				Ray val2 = default(Ray);
				((Ray)(ref val2))..ctor(worldPoint - ((Component)screenMesh).transform.forward * 0.05f, ((Component)screenMesh).transform.forward);
				if (Vector3.Dot(((Ray)(ref val2)).direction, worldPoint - ((Ray)(ref val2)).origin) < 0f)
				{
					((Ray)(ref val2))..ctor(worldPoint + ((Component)screenMesh).transform.forward * 0.05f, -((Component)screenMesh).transform.forward);
				}
				RaycastHit val3 = default(RaycastHit);
				if (((Collider)val).Raycast(val2, ref val3, 0.25f))
				{
					Vector2 textureCoord = ((RaycastHit)(ref val3)).textureCoord;
					AddUvVariants(into, textureCoord, "tex");
				}
			}
			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);
				AddBoundsOrientation(into, bounds, local, 1, 2, "yz");
				AddBoundsOrientation(into, bounds, local, 0, 2, "xz");
				AddBoundsOrientation(into, bounds, local, 0, 1, "xy");
			}
		}

		private static void AddBoundsOrientation(List<(Vector2 uv, string tag)> into, Bounds lb, Vector3 local, int axisU, int axisV, string orientName)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((Bounds)(ref lb)).min;
			float num = ((Vector3)(ref val))[axisU];
			val = ((Bounds)(ref lb)).max;
			float num2 = Mathf.InverseLerp(num, ((Vector3)(ref val))[axisU], ((Vector3)(ref local))[axisU]);
			val = ((Bounds)(ref lb)).min;
			float num3 = ((Vector3)(ref val))[axisV];
			val = ((Bounds)(ref lb)).max;
			float num4 = Mathf.InverseLerp(num3, ((Vector3)(ref val))[axisV], ((Vector3)(ref local))[axisV]);
			num2 = Mathf.Clamp01(num2);
			num4 = Mathf.Clamp01(num4);
			AddUvVariants(into, new Vector2(num2, num4), orientName);
		}

		private static void AddUvVariants(List<(Vector2 uv, string tag)> into, Vector2 raw, string prefix)
		{
			//IL_0008: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: 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)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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)
			Add(raw, prefix + "|uRaw|vRaw");
			Add(new Vector2(raw.x, 1f - raw.y), prefix + "|uRaw|vFlip");
			Add(new Vector2(1f - raw.x, raw.y), prefix + "|uFlip|vRaw");
			Add(new Vector2(1f - raw.x, 1f - raw.y), prefix + "|uFlip|vFlip");
			void Add(Vector2 uv, 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)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < into.Count; i++)
				{
					if (Vector2.Distance(into[i].uv, uv) < 0.0005f)
					{
						return;
					}
				}
				into.Add((uv, tag));
			}
		}

		private static bool TryScoreMarkersAtViewport(Camera mapCamera, Vector2 clickUv, out TerminalAccessibleObject matched, out float bestScore, out string matchHow, out float rank)
		{
			//IL_0075: 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_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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: 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_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0250: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02de: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0336: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_0362: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_043e: Unknown result type (might be due to invalid IL or missing references)
			matched = null;
			bestScore = float.MaxValue;
			matchHow = "none";
			rank = float.MaxValue;
			float num = ((Plugin.HitRadius != null) ? Plugin.HitRadius.Value : 0.022f);
			float num2 = Mathf.Max(0.028f, num * 1.25f);
			float num3 = Mathf.Max(0.06f, num * 3f);
			TerminalAccessibleObject val = null;
			float num4 = float.MaxValue;
			TerminalAccessibleObject val2 = null;
			float num5 = float.MaxValue;
			TerminalAccessibleObject val3 = null;
			float num6 = float.MaxValue;
			Ray val4 = mapCamera.ViewportPointToRay(new Vector3(clickUv.x, clickUv.y, 0f));
			TerminalAccessibleObject[] array = Object.FindObjectsOfType<TerminalAccessibleObject>();
			foreach (TerminalAccessibleObject val5 in array)
			{
				if ((Object)(object)val5 == (Object)null || (Object)(object)val5.mapRadarObject == (Object)null || !val5.mapRadarObject.activeInHierarchy)
				{
					continue;
				}
				RectTransform component = val5.mapRadarObject.GetComponent<RectTransform>();
				Vector3 val6 = val5.mapRadarObject.transform.position;
				if ((Object)(object)component != (Object)null)
				{
					component.GetWorldCorners(CornerBuf);
					val6 = (CornerBuf[0] + CornerBuf[1] + CornerBuf[2] + CornerBuf[3]) * 0.25f;
				}
				Vector3 val7 = val6 - ((Ray)(ref val4)).origin;
				Vector3 direction = ((Ray)(ref val4)).direction;
				float num7 = Vector3.Dot(val7, ((Vector3)(ref direction)).normalized);
				Vector3 val8;
				if (!(num7 > 0f))
				{
					val8 = ((Ray)(ref val4)).origin;
				}
				else
				{
					Vector3 origin = ((Ray)(ref val4)).origin;
					direction = ((Ray)(ref val4)).direction;
					val8 = origin + ((Vector3)(ref direction)).normalized * num7;
				}
				Vector3 val9 = val8;
				float num8 = Vector3.Distance(val6, val9);
				Vector3 val10 = mapCamera.WorldToViewportPoint(val6);
				float num9 = ((val10.z > 0f) ? Vector2.Distance(clickUv, new Vector2(val10.x, val10.y)) : float.MaxValue);
				if ((num8 <= 4f || num9 <= 0.1f) && num8 < num6)
				{
					num6 = num8;
					val3 = val5;
				}
				if ((Object)(object)component == (Object)null)
				{
					continue;
				}
				float num10 = float.PositiveInfinity;
				float num11 = float.PositiveInfinity;
				float num12 = float.NegativeInfinity;
				float num13 = float.NegativeInfinity;
				bool flag = false;
				for (int j = 0; j < 4; j++)
				{
					Vector3 val11 = mapCamera.WorldToViewportPoint(CornerBuf[j]);
					if (val11.z > 0f)
					{
						flag = true;
					}
					if (val11.x < num10)
					{
						num10 = val11.x;
					}
					if (val11.x > num12)
					{
						num12 = val11.x;
					}
					if (val11.y < num11)
					{
						num11 = val11.y;
					}
					if (val11.y > num13)
					{
						num13 = val11.y;
					}
				}
				if (!flag)
				{
					continue;
				}
				Vector3 val12 = mapCamera.WorldToViewportPoint(((Transform)component).position);
				if (val12.z > 0f)
				{
					float num14 = Vector2.Distance(clickUv, new Vector2(val12.x, val12.y));
					if (num14 < num5 && num14 <= num3)
					{
						num5 = num14;
						val2 = val5;
					}
				}
				float num15 = num12 - num10;
				float num16 = num13 - num11;
				if (num15 < 0.008f || num16 < 0.008f)
				{
					if (val12.z <= 0f)
					{
						continue;
					}
					float num17 = Mathf.Max(num2, num * 2.5f);
					num10 = val12.x - num17;
					num12 = val12.x + num17;
					num11 = val12.y - num17;
					num13 = val12.y + num17;
				}
				else
				{
					num10 -= num;
					num12 += num;
					num11 -= num;
					num13 += num;
					float num18 = (num10 + num12) * 0.5f;
					float num19 = (num11 + num13) * 0.5f;
					float num20 = Mathf.Max((num12 - num10) * 0.5f, num2);
					float num21 = Mathf.Max((num13 - num11) * 0.5f, num2);
					num10 = num18 - num20;
					num12 = num18 + num20;
					num11 = num19 - num21;
					num13 = num19 + num21;
				}
				if (!(clickUv.x < num10) && !(clickUv.x > num12) && !(clickUv.y < num11) && !(clickUv.y > num13))
				{
					float num22 = (num10 + num12) * 0.5f;
					float num23 = (num11 + num13) * 0.5f;
					float num24 = Vector2.Distance(clickUv, new Vector2(num22, num23));
					if (num24 < num4)
					{
						num4 = num24;
						val = val5;
					}
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				matched = val;
				bestScore = num4;
				matchHow = "aabb";
				rank = 0f + num4;
				return true;
			}
			if ((Object)(object)val2 != (Object)null)
			{
				matched = val2;
				bestScore = num5;
				matchHow = "center";
				rank = 10f + num5;
				Plugin.V($"Marker match via nearest-center dist={num5:F4} (max={num3:F3}).");
				return true;
			}
			if ((Object)(object)val3 != (Object)null)
			{
				matched = val3;
				bestScore = num6;
				matchHow = "ray";
				rank = 20f + num6 / 4f;
				Plugin.V($"Marker match via ray-to-marker worldDist={num6:F3}m.");
				return true;
			}
			return false;
		}

		private static void ActivateCode(TerminalAccessibleObject matched, float score)
		{
			string text = matched.objectCode ?? "?";
			ulong num = 0uL;
			try
			{
				if ((Object)(object)((NetworkBehaviour)matched).NetworkObject != (Object)null)
				{
					num = ((NetworkBehaviour)matched).NetworkObject.NetworkObjectId;
				}
			}
			catch
			{
			}
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.IsConnectedClient && !singleton.IsServer && !singleton.IsHost)
			{
				Plugin.Log.LogInfo((object)$"Client map click → host activate '{text}' netId={num} (score={score:F4}).");
				HostModGate.SendActivateRequest(num, text);
				TryPlayBroadcastEffect();
			}
			else
			{
				Plugin.Log.LogInfo((object)$"Activating terminal code '{text}' via map click (score={score:F4}).");
				Plugin.V("CallFunctionFromTerminal on '" + ((Object)((Component)matched).gameObject).name + "' code=" + text);
				matched.CallFunctionFromTerminal();
				TryPlayBroadcastEffect();
			}
		}

		private static void TryPlayBroadcastEffect()
		{
			try
			{
				Terminal val = Object.FindObjectOfType<Terminal>();
				if (!((Object)(object)val == (Object)null))
				{
					if ((Object)(object)val.codeBroadcastAnimator != (Object)null)
					{
						val.codeBroadcastAnimator.SetTrigger("display");
					}
					if ((Object)(object)val.terminalAudio != (Object)null && (Object)(object)val.codeBroadcastSFX != (Object)null)
					{
						val.terminalAudio.PlayOneShot(val.codeBroadcastSFX, 1f);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.V("Broadcast SFX skipped: " + ex.Message);
			}
		}

		private static bool WasInteractPressed(PlayerControllerB? player)
		{
			//IL_01ef: 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_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			try
			{
				object obj = (Type.GetType("IngamePlayerSettings, Assembly-CSharp")?.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public))?.GetValue(null);
				object obj2 = obj?.GetType().GetField("playerInput")?.GetValue(obj) ?? obj?.GetType().GetProperty("playerInput")?.GetValue(obj);
				object obj3 = obj2?.GetType().GetProperty("actions")?.GetValue(obj2);
				if (obj3 != null)
				{
					object obj4 = obj3.GetType().GetMethod("FindAction", new Type[2]
					{
						typeof(string),
						typeof(bool)
					})?.Invoke(obj3, new object[2] { "Interact", false });
					if (obj4 == null)
					{
						obj4 = obj3.GetType().GetMethod("FindAction", new Type[1] { typeof(string) })?.Invoke(obj3, new object[1] { "Interact" });
					}
					if (obj4 == null)
					{
						obj4 = obj3.GetType().GetProperty("Item", new Type[1] { typeof(string) })?.GetValue(obj3, new object[1] { "Interact" });
					}
					MethodInfo methodInfo = obj4?.GetType().GetMethod("WasPressedThisFrame");
					bool flag = default(bool);
					int num;
					if (methodInfo != null)
					{
						object obj5 = methodInfo.Invoke(obj4, null);
						if (obj5 is bool)
						{
							flag = (bool)obj5;
							num = 1;
						}
						else
						{
							num = 0;
						}
					}
					else
					{
						num = 0;
					}
					if (((uint)num & (flag ? 1u : 0u)) != 0)
					{
						return true;
					}
				}
			}
			catch
			{
			}
			try
			{
				if (player.playerActions != null)
				{
					MovementActions movement = player.playerActions.Movement;
					PropertyInfo property = ((object)movement).GetType().GetProperty("Interact");
					if (property != null)
					{
						object value = property.GetValue(movement);
						MethodInfo methodInfo2 = value?.GetType().GetMethod("WasPressedThisFrame");
						bool flag2 = default(bool);
						int num2;
						if (methodInfo2 != null)
						{
							object obj5 = methodInfo2.Invoke(value, null);
							if (obj5 is bool)
							{
								flag2 = (bool)obj5;
								num2 = 1;
							}
							else
							{
								num2 = 0;
							}
						}
						else
						{
							num2 = 0;
						}
						if (((uint)num2 & (flag2 ? 1u : 0u)) != 0)
						{
							return true;
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				if (Keyboard.current != null && ((ButtonControl)Keyboard.current.eKey).wasPressedThisFrame)
				{
					return true;
				}
			}
			catch
			{
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(ManualCameraRenderer), "SwitchRadarTargetForward")]
	internal static class SwitchRadarTargetForwardPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ManualCameraRenderer __instance)
		{
			if (Plugin.ClickConsumedThisFrame)
			{
				Plugin.V("Suppressed SwitchRadarTargetForward — prior marker click.");
				return false;
			}
			ManualCameraRenderer val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.mapScreen : null);
			if ((Object)(object)val == (Object)null || __instance != val)
			{
				return true;
			}
			if (!HostModGate.FeaturesActive)
			{
				return true;
			}
			if (MapCodeClickController.TryActivateFromCurrentLook(requireInteractPress: false, forceMapContext: true, alwaysLog: true))
			{
				Plugin.V("Suppressed SwitchRadarTargetForward — code marker activated.");
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(ManualCameraRenderer), "SwitchRadarTargetAndSync")]
	internal static class SwitchRadarTargetAndSyncPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ManualCameraRenderer __instance)
		{
			if (!Plugin.ClickConsumedThisFrame)
			{
				return true;
			}
			ManualCameraRenderer val = (((Object)(object)StartOfRound.Instance != (Object)null) ? StartOfRound.Instance.mapScreen : null);
			if ((Object)(object)val == (Object)null || __instance != val)
			{
				return true;
			}
			Plugin.V("Suppressed SwitchRadarTargetAndSync — code marker click consumed.");
			return false;
		}
	}
	[HarmonyPatch(typeof(InteractTrigger), "Interact")]
	internal static class InteractTriggerInteractPatch
	{
		[HarmonyPrefix]
		private static void Prefix(InteractTrigger __instance, Transform playerTransform)
		{
			if (Plugin.Enabled != null && Plugin.Enabled.Value && HostModGate.FeaturesActive && !Plugin.ClickConsumedThisFrame)
			{
				GameNetworkManager instance = GameNetworkManager.Instance;
				PlayerControllerB val = (((Object)(object)instance != (Object)null) ? instance.localPlayerController : null);
				if (!((Object)(object)val == (Object)null) && !((Object)(object)playerTransform == (Object)null) && playerTransform == ((Component)val).transform && val.isInHangarShipRoom && MapCodeClickController.IsLookingNearMapScreen(val))
				{
					MapCodeClickController.TryActivateFromCurrentLook(requireInteractPress: false, forceMapContext: true, alwaysLog: true);
				}
			}
		}
	}
	[BepInPlugin("com.benhough.lethal.MapClickCodes", "MapClickCodes", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.benhough.lethal.MapClickCodes";

		public const string ModName = "MapClickCodes";

		public const string ModVersion = "1.0.3";

		private readonly Harmony _harmony = new Harmony("com.benhough.lethal.MapClickCodes");

		private float _consumeClearTimer;

		internal static Plugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal static ConfigEntry<bool> Enabled { get; private set; }

		internal static ConfigEntry<bool> VerboseLogging { get; private set; }

		internal static ConfigEntry<float> HitRadius { get; private set; }

		internal static ConfigEntry<bool> FlipUvV { get; private set; }

		internal static ConfigEntry<float> InteractRange { get; private set; }

		internal static bool ClickConsumedThisFrame { get; set; }

		private void Awake()
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master toggle: click code markers on the main ship radar to activate terminal codes.");
			VerboseLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "VerboseLogging", false, "Log UV hits, matched codes, and misses.");
			HitRadius = ((BaseUnityPlugin)this).Config.Bind<float>("General", "HitRadius", 0.022f, new ConfigDescription("Extra UV / viewport padding around each code marker RectTransform (raise if clicks miss the box).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 0.08f), Array.Empty<object>()));
			FlipUvV = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FlipUvV", true, "Flip V when converting mesh UV to mapCamera viewport. Try toggling if markers feel vertically inverted.");
			InteractRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "InteractRange", 4.5f, new ConfigDescription("Max raycast distance from the player camera to the main map screen mesh.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1.5f, 8f), Array.Empty<object>()));
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"MapClickCodes v1.0.3 loaded.");
		}

		private void Update()
		{
			HostModGate.Tick();
			if (ClickConsumedThisFrame)
			{
				_consumeClearTimer += Time.unscaledDeltaTime;
				if (_consumeClearTimer >= 0.12f)
				{
					ClickConsumedThisFrame = false;
					_consumeClearTimer = 0f;
				}
			}
			else
			{
				_consumeClearTimer = 0f;
			}
			MapCodeClickController.Tick();
		}

		internal static void V(string msg)
		{
			if (VerboseLogging != null && VerboseLogging.Value)
			{
				Log.LogInfo((object)msg);
			}
		}
	}
	internal static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.benhough.lethal.MapClickCodes";

		public const string PLUGIN_NAME = "MapClickCodes";

		public const string PLUGIN_VERSION = "1.0.3";
	}
}