Decompiled source of Vehicle Map Markers v1.0.0

plugins/VehicleMapMarkers.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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("BenjSammy")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VehicleMapMarkers")]
[assembly: AssemblyTitle("VehicleMapMarkers")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BenjSammy.VehicleMapMarkers
{
	internal sealed class ConfigurationManagerAttributes
	{
		public string DispName;

		public string Category;

		public Action<ConfigEntryBase> CustomDrawer;
	}
	[BepInPlugin("benjsammy.vehiclemapmarkers", "Vehicle Map Markers by BenjSammy", "1.0.0")]
	public sealed class VehicleMapMarkers : BaseUnityPlugin
	{
		private enum VehicleKind
		{
			Cart,
			Raft,
			Karve,
			Longship,
			Drakkar
		}

		private readonly struct Vehicle
		{
			public readonly Vector3 Position;

			public readonly VehicleKind Kind;

			public Vehicle(Vector3 position, VehicleKind kind)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				Position = position;
				Kind = kind;
			}
		}

		private const string PluginId = "benjsammy.vehiclemapmarkers";

		private const string RequestRpc = "benjsammy.vehiclemapmarkers.request.v1";

		private const string SnapshotRpc = "benjsammy.vehiclemapmarkers.snapshot.v1";

		private const int MaxPacketBytes = 2097152;

		private const float RefreshSeconds = 6f;

		private const float LocalRefreshSeconds = 2f;

		private const float MinimapScale = 0.6f;

		private static VehicleMapMarkers active;

		private static readonly float[] IconScales = new float[5] { 0.84f, 0.7f, 0.8f, 0.91f, 1f };

		private readonly Dictionary<ZDOID, (PinData Pin, VehicleKind Kind)> pins = new Dictionary<ZDOID, (PinData, VehicleKind)>();

		private readonly Dictionary<VehicleKind, Sprite> sprites = new Dictionary<VehicleKind, Sprite>();

		private readonly Dictionary<int, VehicleKind> prefabKinds = new Dictionary<int, VehicleKind>();

		private readonly HashSet<long> servedPeers = new HashSet<long>();

		private Dictionary<ZDOID, Vehicle> serverVehicles;

		private Dictionary<ZDOID, Vehicle> worldVehicles;

		private ZPackage serverResponse;

		private ZRoutedRpc router;

		private ZNetScene prefabScene;

		private Minimap map;

		private MapMode previousMode;

		private float localRefreshAt;

		private float requestAt;

		private float serverRefreshAt;

		private float worldRefreshAt;

		private float lastSnapshotAt;

		private Harmony harmony;

		private ConfigEntry<bool> showBoats;

		private ConfigEntry<bool> showCarts;

		private MethodInfo addPin;

		private MethodInfo getServerPeerId;

		private MethodInfo findPeer;

		private MethodInfo isPeerReady;

		private FieldInfo worldObjects;

		private FieldInfo scenePrefabs;

		private object[] pinArguments;

		private FieldRef<Minimap, MapMode> mapMode;

		private FieldRef<Minimap, float> smallPinSize;

		private FieldRef<Minimap, float> largePinSize;

		private FieldRef<PinData, RectTransform> pinElement;

		private ConfigEntry<bool> BindToggle(string key, string label, string description, bool french)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<bool>("Display", key, true, new ConfigDescription(description, (AcceptableValueBase)null, new object[1]
			{
				new ConfigurationManagerAttributes
				{
					DispName = label,
					Category = (french ? "Affichage" : "Display"),
					CustomDrawer = delegate(ConfigEntryBase entry)
					{
						ConfigEntry<bool> val = (ConfigEntry<bool>)(object)entry;
						val.Value = GUILayout.Toggle(val.Value, (!val.Value) ? (french ? "Non" : "No") : (french ? "Oui" : "Yes"), Array.Empty<GUILayoutOption>());
					}
				}
			}));
		}

		private static bool UsesFrench()
		{
			string text = PlayerPrefs.GetString("language", "English");
			Type type = AccessTools.TypeByName("Localization");
			if (type != null)
			{
				try
				{
					MethodInfo methodInfo = AccessTools.Method(type, "GetSelectedLanguage", Type.EmptyTypes, (Type[])null);
					object obj = (((object)methodInfo == null || methodInfo.IsStatic) ? null : AccessTools.PropertyGetter(type, "instance")?.Invoke(null, null));
					if (methodInfo != null && (methodInfo.IsStatic || obj != null))
					{
						text = (methodInfo.Invoke(obj, null) as string) ?? text;
					}
				}
				catch (Exception)
				{
				}
			}
			if (!string.Equals(text, "French", StringComparison.OrdinalIgnoreCase) && !string.Equals(text, "Français", StringComparison.OrdinalIgnoreCase) && !string.Equals(text, "fr", StringComparison.OrdinalIgnoreCase))
			{
				return text.StartsWith("fr-", StringComparison.OrdinalIgnoreCase);
			}
			return true;
		}

		private void Awake()
		{
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_038f: Expected O, but got Unknown
			//IL_03a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b4: Expected O, but got Unknown
			bool flag = UsesFrench();
			showBoats = BindToggle("Show boats", flag ? "Afficher les bateaux" : "Show boats", flag ? "Affiche les repères des bateaux sur la carte et la mini-carte." : "Show boat markers on the world map and minimap.", flag);
			showCarts = BindToggle("Show carts", flag ? "Afficher les chariots" : "Show carts", flag ? "Affiche les repères des chariots sur la carte et la mini-carte." : "Show cart markers on the world map and minimap.", flag);
			showBoats.SettingChanged += delegate
			{
				localRefreshAt = 0f;
			};
			showCarts.SettingChanged += delegate
			{
				localRefreshAt = 0f;
			};
			Type[] pinTypes = new Type[5]
			{
				typeof(Vector3),
				typeof(PinType),
				typeof(string),
				typeof(bool),
				typeof(bool)
			};
			addPin = AccessTools.GetDeclaredMethods(typeof(Minimap)).FirstOrDefault((MethodInfo method) => method.Name == "AddPin" && method.ReturnType == typeof(PinData) && (from p in method.GetParameters().Take(pinTypes.Length)
				select p.ParameterType).SequenceEqual(pinTypes) && method.GetParameters().Skip(pinTypes.Length).All((ParameterInfo p) => p.IsOptional));
			FieldInfo fieldInfo = AccessTools.DeclaredField(typeof(Minimap), "m_mode");
			if (addPin == null || fieldInfo?.FieldType != typeof(MapMode))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"The map pin API is unavailable on this Valheim build.");
				return;
			}
			mapMode = AccessTools.FieldRefAccess<Minimap, MapMode>(fieldInfo);
			pinArguments = (from p in addPin.GetParameters()
				select (!p.IsOptional) ? null : p.DefaultValue).ToArray();
			pinArguments[1] = (object)(PinType)6;
			pinArguments[2] = "";
			pinArguments[3] = false;
			pinArguments[4] = false;
			worldObjects = AccessTools.DeclaredField(typeof(ZDOMan), "m_objectsByID");
			scenePrefabs = AccessTools.DeclaredField(typeof(ZNetScene), "m_prefabs");
			getServerPeerId = AccessTools.DeclaredMethod(typeof(ZRoutedRpc), "GetServerPeerID", Type.EmptyTypes, (Type[])null);
			findPeer = AccessTools.DeclaredMethod(typeof(ZNet), "GetPeer", new Type[1] { typeof(long) }, (Type[])null);
			isPeerReady = AccessTools.DeclaredMethod(typeof(ZNetPeer), "IsReady", Type.EmptyTypes, (Type[])null);
			MethodInfo methodInfo = AccessTools.DeclaredMethod(typeof(Minimap), "UpdatePins", Type.EmptyTypes, (Type[])null);
			FieldInfo fieldInfo2 = AccessTools.DeclaredField(typeof(Minimap), "m_pinSizeSmall");
			FieldInfo fieldInfo3 = AccessTools.DeclaredField(typeof(Minimap), "m_pinSizeLarge");
			FieldInfo fieldInfo4 = AccessTools.DeclaredField(typeof(PinData), "m_uiElement");
			if (methodInfo == null || fieldInfo2?.FieldType != typeof(float) || fieldInfo3?.FieldType != typeof(float) || fieldInfo4?.FieldType != typeof(RectTransform))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Vehicle marker sizing is unavailable on this Valheim build.");
				return;
			}
			smallPinSize = AccessTools.FieldRefAccess<Minimap, float>(fieldInfo2);
			largePinSize = AccessTools.FieldRefAccess<Minimap, float>(fieldInfo3);
			pinElement = AccessTools.FieldRefAccess<PinData, RectTransform>(fieldInfo4);
			harmony = new Harmony("benjsammy.vehiclemapmarkers");
			harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(VehicleMapMarkers), "ResizePins", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			active = this;
		}

		private void Update()
		{
			//IL_00e4: 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_0129: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			if (mapMode == null)
			{
				return;
			}
			if (router != ZRoutedRpc.instance)
			{
				ClearPins();
				map = null;
				router = ZRoutedRpc.instance;
				serverResponse = null;
				serverVehicles = null;
				worldVehicles = null;
				servedPeers.Clear();
				localRefreshAt = (requestAt = (serverRefreshAt = (worldRefreshAt = 0f)));
				ZRoutedRpc obj = router;
				if (obj != null)
				{
					obj.Register<int>("benjsammy.vehiclemapmarkers.request.v1", (Action<long, int>)ReceiveRequest);
				}
				ZRoutedRpc obj2 = router;
				if (obj2 != null)
				{
					obj2.Register<ZPackage>("benjsammy.vehiclemapmarkers.snapshot.v1", (Action<long, ZPackage>)ReceiveSnapshot);
				}
			}
			Minimap instance = Minimap.instance;
			if ((Object)(object)map != (Object)(object)instance)
			{
				ClearPins();
				map = instance;
				previousMode = (MapMode)0;
			}
			MapMode val = (MapMode)(((Object)(object)map != (Object)null && (Object)(object)Player.m_localPlayer != (Object)null && (Object)(object)ZNet.instance != (Object)null) ? ((int)mapMode.Invoke(map)) : 0);
			if (val != previousMode)
			{
				previousMode = val;
				localRefreshAt = 0f;
			}
			if ((int)val == 0 || (!showBoats.Value && !showCarts.Value))
			{
				ClearPins();
				return;
			}
			float unscaledTime = Time.unscaledTime;
			bool flag = ZNet.instance.IsServer();
			if (!flag && router != null && unscaledTime >= requestAt)
			{
				requestAt = unscaledTime + 6f;
				long num = ServerPeerId();
				if (num != 0L)
				{
					router.InvokeRoutedRPC(num, "benjsammy.vehiclemapmarkers.request.v1", new object[1] { 1 });
				}
			}
			if (!(unscaledTime < localRefreshAt))
			{
				localRefreshAt = unscaledTime + 2f;
				Dictionary<ZDOID, Vehicle> dictionary = (flag ? ReadWorldVehicles() : ((serverVehicles != null && unscaledTime - lastSnapshotAt <= 18f) ? serverVehicles : null));
				Dictionary<ZDOID, Vehicle> vehicles = ((dictionary != null) ? new Dictionary<ZDOID, Vehicle>(dictionary) : new Dictionary<ZDOID, Vehicle>());
				AddLoadedVehicles<Ship>(vehicles, (Func<string, VehicleKind>)ClassifyShip);
				AddLoadedVehicles<Vagon>(vehicles, (Func<string, VehicleKind>)((string _) => VehicleKind.Cart));
				UpdatePins(vehicles);
			}
		}

		private void ReceiveRequest(long sender, int version)
		{
			ZNet instance = ZNet.instance;
			if (version != 1 || router == null || router != ZRoutedRpc.instance || (Object)(object)instance == (Object)null || !instance.IsServer())
			{
				return;
			}
			object? obj = findPeer?.Invoke(instance, new object[1] { sender });
			ZNetPeer val = (ZNetPeer)((obj is ZNetPeer) ? obj : null);
			if (val != null && object.Equals(isPeerReady?.Invoke(val, null), true))
			{
				if (Time.unscaledTime >= serverRefreshAt)
				{
					serverRefreshAt = Time.unscaledTime + 3f;
					servedPeers.Clear();
					Dictionary<ZDOID, Vehicle> dictionary = ReadWorldVehicles();
					serverResponse = ((dictionary == null) ? null : WriteSnapshot(dictionary));
				}
				if (serverResponse != null && servedPeers.Add(sender))
				{
					router.InvokeRoutedRPC(sender, "benjsammy.vehiclemapmarkers.snapshot.v1", new object[1] { serverResponse });
				}
			}
		}

		private long ServerPeerId()
		{
			object obj = getServerPeerId?.Invoke(router, null);
			if (obj is long)
			{
				return (long)obj;
			}
			return 0L;
		}

		private void ReceiveSnapshot(long sender, ZPackage package)
		{
			//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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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)
			if (router == null || router != ZRoutedRpc.instance || (Object)(object)ZNet.instance == (Object)null || ZNet.instance.IsServer() || sender == 0L || sender != ServerPeerId() || package == null || package.Size() > 2097152)
			{
				return;
			}
			try
			{
				int num = package.ReadInt();
				if (num < 0 || num > (package.Size() - 4) / 16)
				{
					return;
				}
				Dictionary<ZDOID, Vehicle> vehicles = new Dictionary<ZDOID, Vehicle>(num);
				for (int i = 0; i < num; i++)
				{
					ZDOID id = package.ReadZDOID();
					Vector3 position = package.ReadVector3();
					int num2 = package.ReadInt();
					if (num2 >= 0 && num2 < IconScales.Length)
					{
						AddVehicle(vehicles, id, position, (VehicleKind)num2);
					}
				}
				if (package.GetPos() == package.Size())
				{
					serverVehicles = vehicles;
					lastSnapshotAt = Time.unscaledTime;
					localRefreshAt = 0f;
				}
			}
			catch (IOException)
			{
			}
		}

		private static ZPackage WriteSnapshot(Dictionary<ZDOID, Vehicle> vehicles)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			ZPackage val = new ZPackage();
			val.Write(vehicles.Count);
			foreach (KeyValuePair<ZDOID, Vehicle> vehicle in vehicles)
			{
				val.Write(vehicle.Key);
				val.Write(vehicle.Value.Position);
				val.Write((int)vehicle.Value.Kind);
			}
			if (val.Size() > 2097152)
			{
				return null;
			}
			return val;
		}

		private Dictionary<ZDOID, Vehicle> ReadWorldVehicles()
		{
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			ZNetScene instance = ZNetScene.instance;
			ZDOMan instance2 = ZDOMan.instance;
			if ((Object)(object)instance == (Object)null || instance2 == null || !(worldObjects?.GetValue(instance2) is IDictionary<ZDOID, ZDO> dictionary))
			{
				return null;
			}
			if ((Object)(object)prefabScene == (Object)(object)instance && worldVehicles != null && Time.unscaledTime < worldRefreshAt)
			{
				return worldVehicles;
			}
			if ((Object)(object)prefabScene != (Object)(object)instance)
			{
				prefabScene = instance;
				prefabKinds.Clear();
				if (scenePrefabs?.GetValue(instance) is IEnumerable<GameObject> enumerable)
				{
					foreach (GameObject item in enumerable)
					{
						if (!((Object)(object)item == (Object)null))
						{
							if ((Object)(object)item.GetComponentInChildren<Ship>(true) != (Object)null)
							{
								prefabKinds[StringExtensionMethods.GetStableHashCode(((Object)item).name)] = ClassifyShip(((Object)item).name);
							}
							else if ((Object)(object)item.GetComponentInChildren<Vagon>(true) != (Object)null)
							{
								prefabKinds[StringExtensionMethods.GetStableHashCode(((Object)item).name)] = VehicleKind.Cart;
							}
						}
					}
				}
			}
			Dictionary<ZDOID, Vehicle> vehicles = new Dictionary<ZDOID, Vehicle>();
			foreach (KeyValuePair<ZDOID, ZDO> item2 in dictionary)
			{
				ZDO value = item2.Value;
				if (value != null && prefabKinds.TryGetValue(value.GetPrefab(), out var value2) && value.IsValid())
				{
					AddVehicle(vehicles, item2.Key, value.GetPosition(), value2);
				}
			}
			worldVehicles = vehicles;
			worldRefreshAt = Time.unscaledTime + 3f;
			return worldVehicles;
		}

		private static void AddLoadedVehicles<T>(Dictionary<ZDOID, Vehicle> vehicles, Func<string, VehicleKind> classify) where T : Component
		{
			//IL_003c: 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)
			T[] array = Object.FindObjectsOfType<T>();
			for (int i = 0; i < array.Length; i++)
			{
				ZNetView componentInParent = ((Component)array[i]).GetComponentInParent<ZNetView>();
				ZDO val = (((Object)(object)componentInParent != (Object)null) ? componentInParent.GetZDO() : null);
				if (val != null && val.IsValid())
				{
					AddVehicle(vehicles, val.m_uid, ((Component)componentInParent).transform.position, classify(((Object)((Component)componentInParent).gameObject).name));
				}
			}
		}

		private static VehicleKind ClassifyShip(string name)
		{
			if (name.StartsWith("Raft", StringComparison.OrdinalIgnoreCase))
			{
				return VehicleKind.Raft;
			}
			if (name.StartsWith("Karve", StringComparison.OrdinalIgnoreCase))
			{
				return VehicleKind.Karve;
			}
			if (name.StartsWith("VikingShip_Ashlands", StringComparison.OrdinalIgnoreCase) || name.StartsWith("Drakkar", StringComparison.OrdinalIgnoreCase))
			{
				return VehicleKind.Drakkar;
			}
			return VehicleKind.Longship;
		}

		private static void AddVehicle(Dictionary<ZDOID, Vehicle> vehicles, ZDOID id, Vector3 position, VehicleKind kind)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!float.IsNaN(((Vector3)(ref position)).sqrMagnitude) && !float.IsInfinity(((Vector3)(ref position)).sqrMagnitude))
			{
				vehicles[id] = new Vehicle(position, kind);
			}
		}

		private bool IsVisible(VehicleKind kind)
		{
			if (kind != VehicleKind.Cart)
			{
				return showBoats.Value;
			}
			return showCarts.Value;
		}

		private void UpdatePins(Dictionary<ZDOID, Vehicle> vehicles)
		{
			//IL_004f: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			Vehicle value3;
			ZDOID[] array = pins.Keys.Where((ZDOID id) => !vehicles.TryGetValue(id, out value3) || !IsVisible(value3.Kind) || pins[id].Pin.m_shouldDelete || pins[id].Kind != value3.Kind).ToArray();
			foreach (ZDOID key in array)
			{
				map.RemovePin(pins[key].Pin);
				pins.Remove(key);
			}
			foreach (KeyValuePair<ZDOID, Vehicle> vehicle in vehicles)
			{
				Vehicle value = vehicle.Value;
				if (IsVisible(value.Kind))
				{
					if (!pins.TryGetValue(vehicle.Key, out (PinData, VehicleKind) value2))
					{
						pinArguments[0] = value.Position;
						value2 = ((PinData)addPin.Invoke(map, pinArguments), value.Kind);
						value2.Item1.m_icon = GetSprite(value.Kind);
						pins.Add(vehicle.Key, value2);
					}
					value2.Item1.m_pos = value.Position;
				}
			}
		}

		private static void ResizePins(Minimap __instance)
		{
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			VehicleMapMarkers vehicleMapMarkers = active;
			if ((Object)(object)vehicleMapMarkers == (Object)null || (Object)(object)vehicleMapMarkers.map != (Object)(object)__instance || vehicleMapMarkers.pins.Count == 0)
			{
				return;
			}
			float num = (((int)vehicleMapMarkers.mapMode.Invoke(__instance) == 1) ? (vehicleMapMarkers.smallPinSize.Invoke(__instance) * 0.6f) : vehicleMapMarkers.largePinSize.Invoke(__instance));
			foreach (var value in vehicleMapMarkers.pins.Values)
			{
				RectTransform val = vehicleMapMarkers.pinElement.Invoke(value.Pin);
				if ((Object)(object)val != (Object)null)
				{
					float num2 = num * IconScales[(int)value.Kind];
					val.sizeDelta = new Vector2(num2, num2);
				}
			}
		}

		private Sprite GetSprite(VehicleKind kind)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			//IL_008f: 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)
			if (sprites.TryGetValue(kind, out var value))
			{
				return value;
			}
			using Stream stream = typeof(VehicleMapMarkers).Assembly.GetManifestResourceStream("VehicleMapMarkers.icons." + kind.ToString() + ".png");
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, memoryStream.ToArray(), true);
			((Texture)val).filterMode = (FilterMode)1;
			((Texture)val).wrapMode = (TextureWrapMode)1;
			value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			sprites.Add(kind, value);
			return value;
		}

		private void ClearPins()
		{
			if (pins.Count == 0)
			{
				return;
			}
			if ((Object)(object)map != (Object)null)
			{
				foreach (var value in pins.Values)
				{
					map.RemovePin(value.Pin);
				}
			}
			pins.Clear();
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			if ((Object)(object)active == (Object)(object)this)
			{
				active = null;
			}
			ClearPins();
			foreach (Sprite value in sprites.Values)
			{
				Object.Destroy((Object)(object)value.texture);
				Object.Destroy((Object)(object)value);
			}
		}
	}
}