Decompiled source of TrailMarkers v1.0.0

TrailMarkers.dll

Decompiled 3 days 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 BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TrailMarkers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TrailMarkers")]
[assembly: AssemblyTitle("TrailMarkers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace TrailMarkers
{
	public enum MarkerType
	{
		Cairn,
		Ribbon,
		GlowMoss
	}
	internal static class MarkerVisuals
	{
		private static Shader _cachedShader;

		private static Shader GetWorkingShader()
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			if ((Object)(object)_cachedShader != (Object)null)
			{
				return _cachedShader;
			}
			string[] array = new string[7] { "Universal Render Pipeline/Lit", "Universal Render Pipeline/Simple Lit", "Universal Render Pipeline/Unlit", "HDRP/Lit", "Standard", "Legacy Shaders/Diffuse", "Sprites/Default" };
			string[] array2 = array;
			bool flag = default(bool);
			foreach (string text in array2)
			{
				Shader val = Shader.Find(text);
				if (!((Object)(object)val != (Object)null))
				{
					continue;
				}
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(30, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("MarkerVisuals: using shader '");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(text);
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
					}
					log.LogInfo(val2);
				}
				_cachedShader = val;
				return val;
			}
			ManualLogSource log2 = Plugin.Log;
			if (log2 != null)
			{
				log2.LogWarning((object)"MarkerVisuals: no known URP shader found by name.");
			}
			return null;
		}

		private static void ApplyColor(Renderer rend, Color color)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_002f: 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)
			Shader workingShader = GetWorkingShader();
			if ((Object)(object)workingShader != (Object)null)
			{
				Material val = new Material(workingShader);
				if (val.HasProperty("_BaseColor"))
				{
					val.SetColor("_BaseColor", color);
				}
				if (val.HasProperty("_Color"))
				{
					val.SetColor("_Color", color);
				}
				rend.material = val;
			}
			else
			{
				rend.material.color = color;
			}
		}

		public static GameObject Build(MarkerType type, Vector3 position, Quaternion rotation)
		{
			//IL_0045: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			if (1 == 0)
			{
			}
			GameObject val = (GameObject)(type switch
			{
				MarkerType.Cairn => BuildCairn(), 
				MarkerType.Ribbon => BuildRibbon(), 
				MarkerType.GlowMoss => BuildGlowMoss(), 
				_ => BuildCairn(), 
			});
			if (1 == 0)
			{
			}
			GameObject val2 = val;
			val2.transform.position = position;
			val2.transform.rotation = ((type == MarkerType.Cairn) ? Quaternion.identity : rotation);
			return val2;
		}

		private static GameObject BuildCairn()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_0090: 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_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("TrailMarker_Cairn");
			float[] array = new float[4] { 0.28f, 0.22f, 0.16f, 0.1f };
			Color color = default(Color);
			((Color)(ref color))..ctor(0.55f, 0.53f, 0.5f);
			float num = 0f;
			float num2 = 0f;
			float[] array2 = array;
			foreach (float num3 in array2)
			{
				GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
				val2.transform.SetParent(val.transform, false);
				val2.transform.localScale = new Vector3(num3 * 2f, num3 * 1.1f, num3 * 2f);
				float num4 = num3 * 0.55f;
				num += num2 + num4;
				num2 = num4;
				val2.transform.localPosition = new Vector3(Random.Range(-0.015f, 0.015f), num, Random.Range(-0.015f, 0.015f));
				Object.Destroy((Object)(object)val2.GetComponent<Collider>());
				ApplyColor(val2.GetComponent<Renderer>(), color);
			}
			CapsuleCollider val3 = val.AddComponent<CapsuleCollider>();
			val3.height = num + 0.2f;
			val3.radius = 0.3f;
			val3.center = new Vector3(0f, (num + 0.2f) / 2f, 0f);
			((Collider)val3).isTrigger = true;
			return val;
		}

		private static GameObject BuildRibbon()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_003b: 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_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_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_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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)
			GameObject val = new GameObject("TrailMarker_Ribbon");
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)3);
			val2.transform.SetParent(val.transform, false);
			val2.transform.localScale = new Vector3(0.06f, 0.28f, 0.01f);
			val2.transform.localPosition = new Vector3(0f, 1.2f, 0.02f);
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			Color[] array = (Color[])(object)new Color[3]
			{
				new Color(0.85f, 0.15f, 0.15f),
				new Color(0.95f, 0.75f, 0.1f),
				new Color(0.15f, 0.55f, 0.85f)
			};
			ApplyColor(val2.GetComponent<Renderer>(), array[Random.Range(0, array.Length)]);
			SphereCollider val3 = val.AddComponent<SphereCollider>();
			val3.radius = 0.25f;
			((Collider)val3).isTrigger = true;
			return val;
		}

		private static GameObject BuildGlowMoss()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_003b: 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_0090: 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_00c6: 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)
			GameObject val = new GameObject("TrailMarker_GlowMoss");
			GameObject val2 = GameObject.CreatePrimitive((PrimitiveType)0);
			val2.transform.SetParent(val.transform, false);
			val2.transform.localScale = new Vector3(0.35f, 0.12f, 0.3f);
			val2.transform.localPosition = new Vector3(0f, 0.05f, 0f);
			Object.Destroy((Object)(object)val2.GetComponent<Collider>());
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.3f, 0.9f, 0.5f);
			Renderer component = val2.GetComponent<Renderer>();
			ApplyColor(component, val3);
			Material material = component.material;
			if (material.HasProperty("_EmissionColor"))
			{
				material.EnableKeyword("_EMISSION");
				material.SetColor("_EmissionColor", val3 * 2.5f);
			}
			Light val4 = val.AddComponent<Light>();
			val4.type = (LightType)2;
			val4.color = val3;
			val4.range = 3.5f;
			val4.intensity = 1.5f;
			SphereCollider val5 = val.AddComponent<SphereCollider>();
			val5.radius = 0.3f;
			((Collider)val5).isTrigger = true;
			return val;
		}
	}
	public struct MarkerData
	{
		public string Id;

		public ulong OwnerId;

		public MarkerType Type;

		public Vector3 Position;

		public Quaternion Rotation;

		public Color OwnerColor;
	}
	public interface INetworkAdapter
	{
		ulong LocalPlayerId { get; }

		event Action<MarkerData> MarkerConfirmed;

		event Action<string> MarkerRemoved;

		event Action<List<MarkerData>> FullSyncReceived;

		void RequestPlace(MarkerData data);

		void RequestRemove(string markerId);

		void RequestFullSync();
	}
	public class LocalOnlyAdapter : INetworkAdapter
	{
		public ulong LocalPlayerId => 1uL;

		public event Action<MarkerData> MarkerConfirmed;

		public event Action<string> MarkerRemoved;

		public event Action<List<MarkerData>> FullSyncReceived;

		public void RequestPlace(MarkerData data)
		{
			this.MarkerConfirmed?.Invoke(data);
		}

		public void RequestRemove(string markerId)
		{
			this.MarkerRemoved?.Invoke(markerId);
		}

		public void RequestFullSync()
		{
			this.FullSyncReceived?.Invoke(new List<MarkerData>());
		}
	}
	public static class NetworkAdapter
	{
		public static void RegisterHandlers()
		{
		}
	}
	[BepInPlugin("gogogadgetjustice.bigwalk.trailmarkers", "Trail Markers", "1.0.0")]
	public class Plugin : BasePlugin
	{
		public static ManualLogSource Log;

		public override void Load()
		{
			Log = ((BasePlugin)this).Log;
			Log.LogInfo((object)"Trail Markers loaded.");
			ClassInjector.RegisterTypeInIl2Cpp<TrailMarkerManager>();
			ClassInjector.RegisterTypeInIl2Cpp<TrailMarker>();
			TrailMarkerConfig.Init(((BasePlugin)this).Config);
			TrailMarkerManager.EnsureExists();
		}
	}
	public class TrailMarker : MonoBehaviour
	{
		public string MarkerId;

		public ulong OwnerId;

		public MarkerType Type;

		public Color OwnerColor;

		public TrailMarker(IntPtr ptr)
			: base(ptr)
		{
		}

		public MarkerData ToData()
		{
			//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_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)
			return new MarkerData
			{
				Id = MarkerId,
				OwnerId = OwnerId,
				Type = Type,
				Position = ((Component)this).transform.position,
				Rotation = ((Component)this).transform.rotation,
				OwnerColor = OwnerColor
			};
		}
	}
	public static class TrailMarkerConfig
	{
		public static ConfigEntry<KeyCode> PlaceKey { get; private set; }

		public static ConfigEntry<KeyCode> CycleTypeKey { get; private set; }

		public static ConfigEntry<KeyCode> PickUpKey { get; private set; }

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

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

		public static ConfigEntry<int> MaxMarkers { get; private set; }

		public static ConfigEntry<bool> FifoRemoval { get; private set; }

		public static void Init(ConfigFile config)
		{
			PlaceKey = config.Bind<KeyCode>("Controls", "PlaceKey", (KeyCode)116, "Key to place a trail marker.");
			CycleTypeKey = config.Bind<KeyCode>("Controls", "CycleTypeKey", (KeyCode)9, "Key to cycle through marker types.");
			PickUpKey = config.Bind<KeyCode>("Controls", "PickUpKey", (KeyCode)101, "Key to pick up nearest marker.");
			PlaceRange = config.Bind<float>("Settings", "PlaceRange", 10f, "Max range to place/pickup markers.");
			DropToGroundMaxDistance = config.Bind<float>("Settings", "DropToGroundMaxDistance", 2f, "Max distance to snap markers to floor geometry.");
			MaxMarkers = config.Bind<int>("Settings", "MaxMarkers", 10, "Max markers per player.");
			FifoRemoval = config.Bind<bool>("Settings", "FifoRemoval", true, "Automatically remove oldest marker when at cap.");
		}
	}
	public class TrailMarkerManager : MonoBehaviour
	{
		private readonly Dictionary<ulong, LinkedList<TrailMarker>> _ownerMarkers = new Dictionary<ulong, LinkedList<TrailMarker>>();

		private readonly Dictionary<string, TrailMarker> _byId = new Dictionary<string, TrailMarker>();

		private INetworkAdapter _net;

		private MarkerType _selectedType = MarkerType.GlowMoss;

		public static TrailMarkerManager Instance { get; private set; }

		public TrailMarkerManager(IntPtr ptr)
			: base(ptr)
		{
		}

		public static void EnsureExists()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject val = new GameObject("TrailMarkerManager");
				Object.DontDestroyOnLoad((Object)(object)val);
				Instance = val.AddComponent<TrailMarkerManager>();
			}
		}

		private void Awake()
		{
			Instance = this;
			_net = new LocalOnlyAdapter();
			_net.MarkerConfirmed += OnMarkerConfirmed;
			_net.MarkerRemoved += OnMarkerRemovedRemote;
			_net.FullSyncReceived += OnFullSync;
			_net.RequestFullSync();
			ManualLogSource log = Plugin.Log;
			if (log != null)
			{
				log.LogInfo((object)"TrailMarkerManager ready.");
			}
		}

		private void Update()
		{
			//IL_0006: 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_0081: 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_0039: Expected O, but got Unknown
			if (Input.GetKeyDown(TrailMarkerConfig.CycleTypeKey.Value))
			{
				_selectedType = (MarkerType)((int)(_selectedType + 1) % 3);
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(19, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Trail Marker type: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<MarkerType>(_selectedType);
					}
					log.LogInfo(val);
				}
			}
			if (Input.GetKeyDown(TrailMarkerConfig.PlaceKey.Value))
			{
				TryPlaceMarker();
			}
			if (Input.GetKeyDown(TrailMarkerConfig.PickUpKey.Value))
			{
				TryPickUpNearest();
			}
		}

		public void CreateMarkerAt(Vector3 position, ulong ownerId)
		{
			//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_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)
			MarkerData data = new MarkerData
			{
				Id = Guid.NewGuid().ToString("N"),
				OwnerId = ownerId,
				Type = _selectedType,
				Position = position,
				Rotation = Quaternion.identity
			};
			OnMarkerConfirmed(data);
		}

		private void TryPlaceMarker()
		{
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Expected O, but got Unknown
			//IL_0411: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Expected O, but got Unknown
			//IL_0026: 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_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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0055: 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)
			//IL_03cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e4: 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_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: 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_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01de: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_025b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: 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_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_02fe: 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_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Unknown result type (might be due to invalid IL or missing references)
			bool flag = default(bool);
			try
			{
				Camera main = Camera.main;
				if (main == null || (Object)(object)main == (Object)null)
				{
					return;
				}
				Vector3 position = ((Component)main).transform.position;
				Vector3 forward = ((Component)main).transform.forward;
				Transform root = ((Component)main).transform.root;
				Vector3 val = position + forward * 0.5f;
				float num = Mathf.Max(0f, TrailMarkerConfig.PlaceRange.Value - 0.5f);
				RaycastHit[] array = Il2CppArrayBase<RaycastHit>.op_Implicit((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(val, forward, num, -1, (QueryTriggerInteraction)0));
				if (array == null || array.Length == 0)
				{
					return;
				}
				Array.Sort(array, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
				RaycastHit? val2 = null;
				RaycastHit[] array2 = array;
				for (int num2 = 0; num2 < array2.Length; num2++)
				{
					RaycastHit value = array2[num2];
					if (!((Object)(object)((RaycastHit)(ref value)).collider == (Object)null) && !((RaycastHit)(ref value)).collider.isTrigger && !((Object)((RaycastHit)(ref value)).collider).name.Contains("Plane") && (!((Object)(object)root != (Object)null) || !((Object)(object)((RaycastHit)(ref value)).transform.root == (Object)(object)root)))
					{
						val2 = value;
						break;
					}
				}
				if (!val2.HasValue)
				{
					return;
				}
				RaycastHit value2 = val2.Value;
				Vector3 val3 = ((RaycastHit)(ref value2)).point + ((RaycastHit)(ref value2)).normal * 0.05f;
				Vector3 normal = ((RaycastHit)(ref value2)).normal;
				float value3 = TrailMarkerConfig.DropToGroundMaxDistance.Value;
				if (value3 > 0f)
				{
					try
					{
						Vector3 val4 = val3 + Vector3.up * 0.5f;
						RaycastHit[] array3 = Il2CppArrayBase<RaycastHit>.op_Implicit((Il2CppArrayBase<RaycastHit>)(object)Physics.RaycastAll(val4, Vector3.down, value3 + 0.5f, -1, (QueryTriggerInteraction)0));
						if (array3 != null && array3.Length != 0)
						{
							Array.Sort(array3, (RaycastHit a, RaycastHit b) => ((RaycastHit)(ref a)).distance.CompareTo(((RaycastHit)(ref b)).distance));
							RaycastHit[] array4 = array3;
							for (int num3 = 0; num3 < array4.Length; num3++)
							{
								RaycastHit val5 = array4[num3];
								if (!((Object)(object)((RaycastHit)(ref val5)).collider == (Object)null) && !((RaycastHit)(ref val5)).collider.isTrigger && !((Object)((RaycastHit)(ref val5)).collider).name.Contains("Plane") && (!((Object)(object)root != (Object)null) || !((Object)(object)((RaycastHit)(ref val5)).transform.root == (Object)(object)root)) && !(Vector3.Dot(((RaycastHit)(ref val5)).normal, Vector3.up) < 0.5f))
								{
									val3 = ((RaycastHit)(ref val5)).point + ((RaycastHit)(ref val5)).normal * 0.02f;
									normal = ((RaycastHit)(ref val5)).normal;
									break;
								}
							}
						}
					}
					catch (Exception ex)
					{
						ManualLogSource log = Plugin.Log;
						if (log != null)
						{
							BepInExWarningLogInterpolatedStringHandler val6 = new BepInExWarningLogInterpolatedStringHandler(20, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val6).AppendLiteral("Ground-check error: ");
								((BepInExLogInterpolatedStringHandler)val6).AppendFormatted<string>(ex.Message);
							}
							log.LogWarning(val6);
						}
					}
				}
				ulong localPlayerId = _net.LocalPlayerId;
				if (MakeRoomForNewMarker(localPlayerId))
				{
					MarkerData data = new MarkerData
					{
						Id = Guid.NewGuid().ToString("N"),
						OwnerId = localPlayerId,
						Type = _selectedType,
						Position = val3,
						Rotation = Quaternion.FromToRotation(Vector3.up, normal)
					};
					_net.RequestPlace(data);
				}
			}
			catch (Exception ex2)
			{
				ManualLogSource log2 = Plugin.Log;
				if (log2 != null)
				{
					BepInExErrorLogInterpolatedStringHandler val7 = new BepInExErrorLogInterpolatedStringHandler(22, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val7).AppendLiteral("TryPlaceMarker error: ");
						((BepInExLogInterpolatedStringHandler)val7).AppendFormatted<Exception>(ex2);
					}
					log2.LogError(val7);
				}
			}
		}

		private bool MakeRoomForNewMarker(ulong owner)
		{
			if (!_ownerMarkers.TryGetValue(owner, out var value) || value.Count < TrailMarkerConfig.MaxMarkers.Value)
			{
				return true;
			}
			if (TrailMarkerConfig.FifoRemoval.Value)
			{
				TrailMarker value2 = value.First.Value;
				_net.RequestRemove(value2.MarkerId);
				return true;
			}
			return false;
		}

		private void TryPickUpNearest()
		{
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_007c: 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)
			try
			{
				Camera main = Camera.main;
				if (main == null || (Object)(object)main == (Object)null)
				{
					return;
				}
				ulong localPlayerId = _net.LocalPlayerId;
				if (!_ownerMarkers.TryGetValue(localPlayerId, out var value) || value.Count == 0)
				{
					return;
				}
				TrailMarker trailMarker = null;
				float num = TrailMarkerConfig.PlaceRange.Value;
				foreach (TrailMarker item in value)
				{
					float num2 = Vector3.Distance(((Component)main).transform.position, ((Component)item).transform.position);
					if (num2 < num)
					{
						num = num2;
						trailMarker = item;
					}
				}
				if ((Object)(object)trailMarker != (Object)null)
				{
					_net.RequestRemove(trailMarker.MarkerId);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("TryPickUpNearest error: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					log.LogError(val);
				}
			}
		}

		private void OnMarkerConfirmed(MarkerData data)
		{
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!_byId.ContainsKey(data.Id))
				{
					GameObject val = MarkerVisuals.Build(data.Type, data.Position, data.Rotation);
					TrailMarker trailMarker = val.AddComponent<TrailMarker>();
					trailMarker.MarkerId = data.Id;
					trailMarker.OwnerId = data.OwnerId;
					trailMarker.Type = data.Type;
					_byId[data.Id] = trailMarker;
					if (!_ownerMarkers.TryGetValue(data.OwnerId, out var value))
					{
						value = new LinkedList<TrailMarker>();
						_ownerMarkers[data.OwnerId] = value;
					}
					value.AddLast(trailMarker);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = Plugin.Log;
				if (log != null)
				{
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("OnMarkerConfirmed error: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					log.LogError(val2);
				}
			}
		}

		private void OnMarkerRemovedRemote(string markerId)
		{
			if (_byId.TryGetValue(markerId, out var value))
			{
				_byId.Remove(markerId);
				if (_ownerMarkers.TryGetValue(value.OwnerId, out var value2))
				{
					value2.Remove(value);
				}
				Object.Destroy((Object)(object)((Component)value).gameObject);
			}
		}

		private void OnFullSync(List<MarkerData> markers)
		{
			foreach (MarkerData marker in markers)
			{
				OnMarkerConfirmed(marker);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "TrailMarkers";

		public const string PLUGIN_NAME = "TrailMarkers";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}