Decompiled source of MapEnhancement v1.1.1

MapEnhancement.dll

Decompiled 6 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
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(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MapEnhancement")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Map enhancement mod for REPO. Adds zoom and custom icons.")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+810898a586823aa9d10bd4dccc62938902efec1e")]
[assembly: AssemblyProduct("MapEnhancement")]
[assembly: AssemblyTitle("MapEnhancement")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MapEnhancement
{
	[BepInPlugin("semimodder-mapenhancement", "Map Enhancement", "1.1.1")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly HashSet<ValuableObject> mappedValuables = new HashSet<ValuableObject>();

		private readonly HashSet<Component> trackedEntities = new HashSet<Component>();

		internal static readonly Dictionary<MapCustom, Sprite> OriginalItemSprites = new Dictionary<MapCustom, Sprite>();

		internal static readonly Dictionary<MapCustom, Color> OriginalItemColors = new Dictionary<MapCustom, Color>();

		internal static readonly Dictionary<MapValuable, Sprite> OriginalValuableSprites = new Dictionary<MapValuable, Sprite>();

		internal static readonly Dictionary<MapValuable, Color> OriginalValuableColors = new Dictionary<MapValuable, Color>();

		private static readonly Dictionary<string, Sprite> ShapeSpriteCache = new Dictionary<string, Sprite>();

		private static FieldInfo? isDisabledField;

		private static FieldInfo? enemyParentField;

		private static FieldInfo? mapCustomEntityField;

		private static FieldInfo? enemyField;

		internal static Plugin Instance { get; private set; } = null;

		internal ConfigEntry<string> MapMode { get; private set; } = null;

		internal ConfigEntry<float> MapIconScale { get; private set; } = null;

		internal ConfigEntry<bool> ShowTeammates { get; private set; } = null;

		internal ConfigEntry<string> TeammatesColor { get; private set; } = null;

		internal ConfigEntry<string> TeammatesShape { get; private set; } = null;

		internal ConfigEntry<bool> ShowDeadTeammates { get; private set; } = null;

		internal ConfigEntry<string> DeadTeammatesColor { get; private set; } = null;

		internal ConfigEntry<string> DeadTeammatesShape { get; private set; } = null;

		internal ConfigEntry<bool> ShowEnemies { get; private set; } = null;

		internal ConfigEntry<string> Level1EnemiesColor { get; private set; } = null;

		internal ConfigEntry<string> Level1EnemiesShape { get; private set; } = null;

		internal ConfigEntry<string> Level2EnemiesColor { get; private set; } = null;

		internal ConfigEntry<string> Level2EnemiesShape { get; private set; } = null;

		internal ConfigEntry<string> Level3EnemiesColor { get; private set; } = null;

		internal ConfigEntry<string> Level3EnemiesShape { get; private set; } = null;

		internal ConfigEntry<bool> ShowValuables { get; private set; } = null;

		internal ConfigEntry<string> ValuablesColor { get; private set; } = null;

		internal ConfigEntry<string> ValuablesShape { get; private set; } = null;

		internal ConfigEntry<bool> ShowCosmeticBoxes { get; private set; } = null;

		internal ConfigEntry<string> CosmeticBoxesColor { get; private set; } = null;

		internal ConfigEntry<string> CosmeticBoxesShape { get; private set; } = null;

		internal ConfigEntry<bool> ShowItems { get; private set; } = null;

		internal ConfigEntry<string> ItemsColor { get; private set; } = null;

		internal ConfigEntry<string> ItemsShape { get; private set; } = null;

		private void Awake()
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_03b8: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			MapMode = ((BaseUnityPlugin)this).Config.Bind<string>("General", "MapModeSelect", "Normal", new ConfigDescription("Select the map display mode.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[3] { "Normal", "Explored Rooms", "Full Map" }), Array.Empty<object>()));
			MapIconScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "MapIconScale", 0.15f, "Scale of the custom map icons (default: 0.15).");
			ShowTeammates = ((BaseUnityPlugin)this).Config.Bind<bool>("Teammates", "ShowTeammates", true, "Show teammate locations.");
			TeammatesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Teammates", "TeammatesColor", "lightgreen", "Color of teammate icon.");
			TeammatesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Teammates", "TeammatesShape", "circle", "Shape of teammate icon.");
			ShowDeadTeammates = ((BaseUnityPlugin)this).Config.Bind<bool>("Teammates", "ShowDeadTeammates", true, "Show dead teammate locations.");
			DeadTeammatesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Teammates", "DeadTeammatesColor", "red", "Color of dead teammate icon.");
			DeadTeammatesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Teammates", "DeadTeammatesShape", "cross", "Shape of dead teammate icon.");
			ShowEnemies = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "ShowEnemies", true, "Show enemy locations.");
			Level1EnemiesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level1EnemiesColor", "purple", "Color of Level 1 enemy icon.");
			Level1EnemiesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level1EnemiesShape", "circle", "Shape of Level 1 enemy icon.");
			Level2EnemiesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level2EnemiesColor", "purple", "Color of Level 2 enemy icon.");
			Level2EnemiesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level2EnemiesShape", "triangle", "Shape of Level 2 enemy icon.");
			Level3EnemiesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level3EnemiesColor", "purple", "Color of Level 3 enemy icon.");
			Level3EnemiesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Enemies", "Level3EnemiesShape", "square", "Shape of Level 3 enemy icon.");
			ShowValuables = ((BaseUnityPlugin)this).Config.Bind<bool>("Valuables", "ShowValuables", true, "Show valuable locations.");
			ValuablesColor = ((BaseUnityPlugin)this).Config.Bind<string>("Valuables", "ValuablesColor", "yellow", "Color of valuable icon.");
			ValuablesShape = ((BaseUnityPlugin)this).Config.Bind<string>("Valuables", "ValuablesShape", "circle", "Shape of valuable icon.");
			ShowCosmeticBoxes = ((BaseUnityPlugin)this).Config.Bind<bool>("CosmeticBoxes", "ShowCosmeticBoxes", true, "Show cosmetic box locations.");
			CosmeticBoxesColor = ((BaseUnityPlugin)this).Config.Bind<string>("CosmeticBoxes", "CosmeticBoxesColor", "orange", "Color of cosmetic box icon.");
			CosmeticBoxesShape = ((BaseUnityPlugin)this).Config.Bind<string>("CosmeticBoxes", "CosmeticBoxesShape", "square", "Shape of cosmetic box icon.");
			ShowItems = ((BaseUnityPlugin)this).Config.Bind<bool>("Items", "ShowItems", true, "Show item locations.");
			ItemsColor = ((BaseUnityPlugin)this).Config.Bind<string>("Items", "ItemsColor", "default", "Color of item icon (use 'default' to keep the game's original light blue).");
			ItemsShape = ((BaseUnityPlugin)this).Config.Bind<string>("Items", "ItemsShape", "default", "Shape of item icon (use 'default' to keep the game's original circle).");
			new Harmony("semimodder-mapenhancement").PatchAll();
			Action onConfigChanged = delegate
			{
				ShapeSpriteCache.Clear();
				MapEntityTracker[] array = Object.FindObjectsOfType<MapEntityTracker>();
				foreach (MapEntityTracker mapEntityTracker in array)
				{
					if ((Object)(object)mapEntityTracker != (Object)null)
					{
						mapEntityTracker.ForceUpdate();
					}
				}
				MapValuable[] array2 = Object.FindObjectsOfType<MapValuable>();
				foreach (MapValuable val in array2)
				{
					if ((Object)(object)val != (Object)null)
					{
						UpdateMapValuable(val);
					}
				}
				MapCustom[] array3 = Object.FindObjectsOfType<MapCustom>();
				foreach (MapCustom val2 in array3)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						ItemAttributes componentInParent = ((Component)val2).GetComponentInParent<ItemAttributes>();
						if ((Object)(object)componentInParent != (Object)null)
						{
							UpdateMapCustomItem(val2);
						}
					}
				}
			};
			MapIconScale.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowTeammates.SettingChanged += delegate
			{
				onConfigChanged();
			};
			TeammatesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			TeammatesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowDeadTeammates.SettingChanged += delegate
			{
				onConfigChanged();
			};
			DeadTeammatesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			DeadTeammatesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowEnemies.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level1EnemiesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level1EnemiesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level2EnemiesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level2EnemiesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level3EnemiesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			Level3EnemiesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowValuables.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ValuablesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ValuablesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowCosmeticBoxes.SettingChanged += delegate
			{
				onConfigChanged();
			};
			CosmeticBoxesColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			CosmeticBoxesShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ShowItems.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ItemsColor.SettingChanged += delegate
			{
				onConfigChanged();
			};
			ItemsShape.SettingChanged += delegate
			{
				onConfigChanged();
			};
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Map Enhancement 1.1.1 loaded.");
		}

		internal Color GetColorFromConfig(ConfigEntry<string> config, Color defaultColor)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: 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)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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)
			string text = config.Value.Trim().ToLower();
			if (text == "default" || text == "original")
			{
				return defaultColor;
			}
			if (text == "light green" || text == "lightgreen")
			{
				return new Color(0.5f, 1f, 0.5f);
			}
			switch (text)
			{
			case "purple":
				return new Color(0.5f, 0f, 0.5f);
			case "orange":
				return new Color(1f, 0.35f, 0f);
			default:
				if (!(text == "lightblue"))
				{
					Color result = default(Color);
					if (ColorUtility.TryParseHtmlString(config.Value, ref result))
					{
						return result;
					}
					if (ColorUtility.TryParseHtmlString("#" + config.Value, ref result))
					{
						return result;
					}
					return defaultColor;
				}
				goto case "light blue";
			case "light blue":
				return new Color(0f, 1f, 0.92f);
			}
		}

		internal Color GetTeammatesColor()
		{
			//IL_0016: 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)
			return GetColorFromConfig(TeammatesColor, new Color(0.5f, 1f, 0.5f));
		}

		internal Color GetDeadTeammatesColor()
		{
			//IL_0007: 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)
			return GetColorFromConfig(DeadTeammatesColor, Color.red);
		}

		internal Color GetLevel1EnemiesColor()
		{
			//IL_0016: 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)
			return GetColorFromConfig(Level1EnemiesColor, new Color(0.5f, 0f, 0.5f));
		}

		internal Color GetLevel2EnemiesColor()
		{
			//IL_0016: 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)
			return GetColorFromConfig(Level2EnemiesColor, new Color(0.5f, 0f, 0.5f));
		}

		internal Color GetLevel3EnemiesColor()
		{
			//IL_0016: 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)
			return GetColorFromConfig(Level3EnemiesColor, new Color(0.5f, 0f, 0.5f));
		}

		internal Color GetValuablesColor(Color originalColor)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return GetColorFromConfig(ValuablesColor, originalColor);
		}

		internal Color GetCosmeticBoxesColor()
		{
			//IL_0016: 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)
			return GetColorFromConfig(CosmeticBoxesColor, new Color(1f, 0.35f, 0f));
		}

		internal Color GetItemsColor(Color originalColor)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return GetColorFromConfig(ItemsColor, originalColor);
		}

		public static Sprite GetOrCreateShapeSprite(string shapeName)
		{
			shapeName = shapeName.Trim().ToLower();
			if (ShapeSpriteCache.TryGetValue(shapeName, out var value) && (Object)(object)value != (Object)null)
			{
				return value;
			}
			Sprite val = CreateProceduralSprite(shapeName);
			ShapeSpriteCache[shapeName] = val;
			return val;
		}

		public static Sprite CreateProceduralSprite(string shapeName)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Expected O, but got Unknown
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_037c: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			int num = 64;
			Texture2D val = new Texture2D(num, num, (TextureFormat)4, false);
			Color[] array = (Color[])(object)new Color[num * num];
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Color.clear;
			}
			float num2 = (float)num / 2f;
			float num3 = (float)num * 0.42f;
			for (int j = 0; j < num; j++)
			{
				for (int k = 0; k < num; k++)
				{
					float num4 = (float)k - num2 + 0.5f;
					float num5 = (float)j - num2 + 0.5f;
					float num6 = Mathf.Sqrt(num4 * num4 + num5 * num5);
					bool flag = false;
					switch (shapeName.ToLower())
					{
					case "circle":
						flag = num6 <= num3;
						break;
					case "square":
						flag = Mathf.Abs(num4) <= num3 && Mathf.Abs(num5) <= num3;
						break;
					case "triangle":
						flag = num5 >= (0f - num3) * 0.5f && num5 <= num3 - 1.5f * Mathf.Abs(num4);
						break;
					case "cross":
					case "x":
					{
						float num7 = (num4 + num5) * 0.7071f;
						float num8 = (num4 - num5) * 0.7071f;
						float num9 = (float)num * 0.12f;
						flag = (Mathf.Abs(num7) <= num3 && Mathf.Abs(num8) <= num9) || (Mathf.Abs(num8) <= num3 && Mathf.Abs(num7) <= num9);
						break;
					}
					case "diamond":
						flag = Mathf.Abs(num4) + Mathf.Abs(num5) <= num3;
						break;
					case "star":
						flag = Mathf.Pow(Mathf.Abs(num4) / num3, 0.5f) + Mathf.Pow(Mathf.Abs(num5) / num3, 0.5f) <= 1f;
						break;
					default:
						flag = num6 <= num3;
						break;
					}
					if (flag)
					{
						array[j * num + k] = Color.white;
					}
				}
			}
			val.SetPixels(array);
			val.Apply();
			float num10 = 0.15f;
			if ((Object)(object)Instance != (Object)null && Instance.MapIconScale != null)
			{
				num10 = Instance.MapIconScale.Value;
			}
			float num11 = 100f / num10;
			return Sprite.Create(val, new Rect(0f, 0f, (float)num, (float)num), new Vector2(0.5f, 0.5f), num11);
		}

		internal void LevelGenerated()
		{
			mappedValuables.Clear();
			trackedEntities.Clear();
			OriginalItemSprites.Clear();
			OriginalItemColors.Clear();
			OriginalValuableSprites.Clear();
			OriginalValuableColors.Clear();
			if (MapMode.Value == "Full Map")
			{
				RoomVolume[] array = Object.FindObjectsOfType<RoomVolume>();
				foreach (RoomVolume val in array)
				{
					if ((Object)(object)val != (Object)null)
					{
						val.SetExplored();
					}
				}
				ValuableObject[] array2 = Object.FindObjectsOfType<ValuableObject>();
				foreach (ValuableObject valuable in array2)
				{
					AddValuable(valuable);
				}
			}
			if (ShowTeammates.Value)
			{
				PlayerAvatar[] array3 = Object.FindObjectsOfType<PlayerAvatar>();
				foreach (PlayerAvatar player in array3)
				{
					TryTrackPlayer(player);
				}
			}
			if (ShowEnemies.Value)
			{
				EnemyParent[] array4 = Object.FindObjectsOfType<EnemyParent>();
				foreach (EnemyParent val2 in array4)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Enemy enemyFromParent = GetEnemyFromParent(val2);
						if ((Object)(object)enemyFromParent != (Object)null)
						{
							TryTrackEnemy(enemyFromParent);
						}
					}
				}
			}
			if (ShowCosmeticBoxes.Value)
			{
				CosmeticWorldObject[] array5 = Object.FindObjectsOfType<CosmeticWorldObject>();
				foreach (CosmeticWorldObject cosmetic in array5)
				{
					TryTrackCosmetic(cosmetic);
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("[MapMod] Level initialized: mode=" + MapMode.Value + ", " + $"players={Object.FindObjectsOfType<PlayerAvatar>().Length}, enemies={Object.FindObjectsOfType<Enemy>().Length}, " + $"cosmetics={Object.FindObjectsOfType<CosmeticWorldObject>().Length}."));
		}

		internal void RoomExplored(RoomVolume room)
		{
			//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_00b0: 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_00b9: Unknown result type (might be due to invalid IL or missing references)
			if (MapMode.Value != "Explored Rooms" || (Object)(object)room == (Object)null || (Object)(object)Map.Instance == (Object)null)
			{
				return;
			}
			Collider[] componentsInChildren = ((Component)room).GetComponentsInChildren<Collider>();
			if (componentsInChildren.Length == 0)
			{
				return;
			}
			ValuableObject[] array = Object.FindObjectsOfType<ValuableObject>();
			foreach (ValuableObject val in array)
			{
				if ((Object)(object)val == (Object)null || mappedValuables.Contains(val))
				{
					continue;
				}
				Vector3 position = ((Component)val).transform.position;
				Collider[] array2 = componentsInChildren;
				foreach (Collider val2 in array2)
				{
					if ((Object)(object)val2 != (Object)null)
					{
						Bounds bounds = val2.bounds;
						if (((Bounds)(ref bounds)).Contains(position))
						{
							AddValuable(val);
							break;
						}
					}
				}
			}
		}

		internal bool RegisterValuable(ValuableObject valuable)
		{
			return (Object)(object)valuable != (Object)null && mappedValuables.Add(valuable);
		}

		private void AddValuable(ValuableObject valuable)
		{
			if ((Object)(object)valuable != (Object)null && (Object)(object)Map.Instance != (Object)null)
			{
				Map.Instance.AddValuable(valuable);
			}
		}

		internal void TryTrackPlayer(PlayerAvatar player)
		{
			if (ShowTeammates.Value && !((Object)(object)player == (Object)null) && !trackedEntities.Contains((Component)(object)player) && (!((Object)(object)player.photonView != (Object)null) || !player.photonView.IsMine))
			{
				AddTracker((Component)(object)player);
			}
		}

		internal void TryTrackEnemy(Enemy enemy)
		{
			if (ShowEnemies.Value && !((Object)(object)enemy == (Object)null) && !trackedEntities.Contains((Component)(object)enemy))
			{
				AddTracker((Component)(object)enemy);
			}
		}

		internal void TryTrackCosmetic(CosmeticWorldObject cosmetic)
		{
			if (ShowCosmeticBoxes.Value && !((Object)(object)cosmetic == (Object)null) && !trackedEntities.Contains((Component)(object)cosmetic))
			{
				AddTracker((Component)(object)cosmetic);
			}
		}

		private void AddTracker(Component target)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			if (!((Object)(object)Map.Instance == (Object)null))
			{
				GameObject val = new GameObject("MapEnhancement_" + ((Object)target).name);
				MapEntityTracker mapEntityTracker = val.AddComponent<MapEntityTracker>();
				mapEntityTracker.Initialize(target);
				trackedEntities.Add(target);
			}
		}

		internal static bool IsPlayerDisabled(PlayerAvatar player)
		{
			if ((Object)(object)player == (Object)null)
			{
				return false;
			}
			if (isDisabledField == null)
			{
				isDisabledField = typeof(PlayerAvatar).GetField("isDisabled", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (isDisabledField != null)
			{
				return (bool)isDisabledField.GetValue(player);
			}
			return false;
		}

		internal static EnemyParent? GetEnemyParent(Enemy enemy)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if ((Object)(object)enemy == (Object)null)
			{
				return null;
			}
			if (enemyParentField == null)
			{
				enemyParentField = typeof(Enemy).GetField("EnemyParent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (enemyParentField != null)
			{
				return (EnemyParent)enemyParentField.GetValue(enemy);
			}
			return null;
		}

		internal static MapCustomEntity? GetMapCustomEntity(MapCustom mapCustom)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if ((Object)(object)mapCustom == (Object)null)
			{
				return null;
			}
			if (mapCustomEntityField == null)
			{
				mapCustomEntityField = typeof(MapCustom).GetField("mapCustomEntity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (mapCustomEntityField != null)
			{
				return (MapCustomEntity)mapCustomEntityField.GetValue(mapCustom);
			}
			return null;
		}

		internal static Enemy? GetEnemyFromParent(EnemyParent enemyParent)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if ((Object)(object)enemyParent == (Object)null)
			{
				return null;
			}
			if (enemyField == null)
			{
				enemyField = typeof(EnemyParent).GetField("Enemy", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (enemyField != null)
			{
				return (Enemy)enemyField.GetValue(enemyParent);
			}
			return null;
		}

		internal static void SetMapCustomEntity(MapCustom mapCustom, MapCustomEntity? entity)
		{
			if (!((Object)(object)mapCustom == (Object)null))
			{
				if (mapCustomEntityField == null)
				{
					mapCustomEntityField = typeof(MapCustom).GetField("mapCustomEntity", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (mapCustomEntityField != null)
				{
					mapCustomEntityField.SetValue(mapCustom, entity);
				}
			}
		}

		internal static void UpdateMapValuable(MapValuable valuable)
		{
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: 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_015c: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null || (Object)(object)valuable == (Object)null || (Object)(object)valuable.spriteRenderer == (Object)null)
			{
				return;
			}
			if (!OriginalValuableSprites.ContainsKey(valuable))
			{
				OriginalValuableSprites[valuable] = valuable.spriteRenderer.sprite;
				OriginalValuableColors[valuable] = valuable.spriteRenderer.color;
			}
			if (!Instance.ShowValuables.Value)
			{
				((Component)valuable).gameObject.SetActive(false);
				return;
			}
			((Component)valuable).gameObject.SetActive(true);
			string text = Instance.ValuablesShape.Value.Trim().ToLower();
			if (text != "default" && text != "original")
			{
				Sprite orCreateShapeSprite = GetOrCreateShapeSprite(text);
				if ((Object)(object)orCreateShapeSprite != (Object)null)
				{
					valuable.spriteRenderer.sprite = orCreateShapeSprite;
				}
			}
			else
			{
				valuable.spriteRenderer.sprite = OriginalValuableSprites[valuable];
			}
			Color valuablesColor = Instance.GetValuablesColor(OriginalValuableColors[valuable]);
			valuablesColor.a = valuable.spriteRenderer.color.a;
			valuable.spriteRenderer.color = valuablesColor;
		}

		internal static void UpdateMapCustomItem(MapCustom mapCustom)
		{
			//IL_004d: 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_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: 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_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Instance == (Object)null || (Object)(object)mapCustom == (Object)null)
			{
				return;
			}
			if (!OriginalItemSprites.ContainsKey(mapCustom))
			{
				OriginalItemSprites[mapCustom] = mapCustom.sprite;
				OriginalItemColors[mapCustom] = mapCustom.color;
			}
			MapCustomEntity mapCustomEntity = GetMapCustomEntity(mapCustom);
			if (!Instance.ShowItems.Value)
			{
				if ((Object)(object)mapCustomEntity != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)mapCustomEntity).gameObject);
					SetMapCustomEntity(mapCustom, null);
				}
			}
			else if ((Object)(object)mapCustomEntity == (Object)null && (Object)(object)Map.Instance != (Object)null && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				mapCustom.Add();
			}
			else if ((Object)(object)mapCustomEntity != (Object)null)
			{
				Sprite sprite = OriginalItemSprites[mapCustom];
				string text = Instance.ItemsShape.Value.Trim().ToLower();
				if (text != "default" && text != "original")
				{
					sprite = GetOrCreateShapeSprite(text);
				}
				Color itemsColor = Instance.GetItemsColor(OriginalItemColors[mapCustom]);
				mapCustom.sprite = sprite;
				mapCustom.color = itemsColor;
				if ((Object)(object)mapCustomEntity.spriteRenderer != (Object)null)
				{
					mapCustomEntity.spriteRenderer.sprite = sprite;
					float a = mapCustomEntity.spriteRenderer.color.a;
					Color color = itemsColor;
					color.a = a;
					mapCustomEntity.spriteRenderer.color = color;
				}
			}
		}
	}
	[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
	internal static class LevelGeneratorGenerateDonePatch
	{
		private static void Postfix()
		{
			Plugin.Instance?.LevelGenerated();
		}
	}
	[HarmonyPatch(typeof(RoomVolume), "SetExplored")]
	internal static class RoomVolumeSetExploredPatch
	{
		private static void Postfix(RoomVolume __instance, bool __result)
		{
			if (__result)
			{
				Plugin.Instance?.RoomExplored(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Map), "AddValuable")]
	internal static class MapAddValuablePatch
	{
		private static bool Prefix(ValuableObject _valuable)
		{
			return (Object)(object)Plugin.Instance == (Object)null || Plugin.Instance.RegisterValuable(_valuable);
		}
	}
	[HarmonyPatch(typeof(PlayerAvatar), "Start")]
	internal static class PlayerAvatarStartPatch
	{
		private static void Postfix(PlayerAvatar __instance)
		{
			if ((Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				Plugin.Instance?.TryTrackPlayer(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(EnemyParent), "Awake")]
	internal static class EnemyParentAwakePatch
	{
		private static void Postfix(EnemyParent __instance)
		{
			if (!((Object)(object)Plugin.Instance == (Object)null) && !((Object)(object)__instance == (Object)null))
			{
				((MonoBehaviour)__instance).StartCoroutine(TrackEnemyCoroutine(__instance));
			}
		}

		private static IEnumerator TrackEnemyCoroutine(EnemyParent enemyParent)
		{
			yield return null;
			if ((Object)(object)enemyParent != (Object)null)
			{
				Enemy enemy = Plugin.GetEnemyFromParent(enemyParent);
				if ((Object)(object)enemy != (Object)null)
				{
					Plugin.Instance.TryTrackEnemy(enemy);
				}
			}
		}
	}
	[HarmonyPatch(typeof(EnemyParent), "Update")]
	internal static class EnemyParentUpdatePatch
	{
		private static void Postfix(EnemyParent __instance)
		{
			if (!((Object)(object)Plugin.Instance == (Object)null) && !((Object)(object)__instance == (Object)null) && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				Enemy enemyFromParent = Plugin.GetEnemyFromParent(__instance);
				if ((Object)(object)enemyFromParent != (Object)null)
				{
					Plugin.Instance.TryTrackEnemy(enemyFromParent);
				}
			}
		}
	}
	[HarmonyPatch(typeof(CosmeticWorldObject), "Start")]
	internal static class CosmeticWorldObjectStartPatch
	{
		private static void Postfix(CosmeticWorldObject __instance)
		{
			if ((Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				Plugin.Instance?.TryTrackCosmetic(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(Map), "AddCustom")]
	internal static class MapAddCustomPatch
	{
		private static bool Prefix(MapCustom mapCustom, ref Sprite sprite, ref Color color)
		{
			//IL_00cf: 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_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Plugin.Instance == (Object)null || (Object)(object)mapCustom == (Object)null)
			{
				return true;
			}
			CosmeticWorldObject val = ((Component)mapCustom).GetComponentInParent<CosmeticWorldObject>();
			if ((Object)(object)val == (Object)null)
			{
				ValuableDiscoverCustom componentInParent = ((Component)mapCustom).GetComponentInParent<ValuableDiscoverCustom>();
				if ((Object)(object)componentInParent != (Object)null)
				{
					val = ((Component)componentInParent).GetComponent<CosmeticWorldObject>();
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				return false;
			}
			PlayerDeathHead componentInParent2 = ((Component)mapCustom).GetComponentInParent<PlayerDeathHead>();
			if ((Object)(object)componentInParent2 != (Object)null)
			{
				return false;
			}
			ItemAttributes componentInParent3 = ((Component)mapCustom).GetComponentInParent<ItemAttributes>();
			if ((Object)(object)componentInParent3 != (Object)null)
			{
				if (!Plugin.OriginalItemSprites.ContainsKey(mapCustom))
				{
					Plugin.OriginalItemSprites[mapCustom] = sprite;
					Plugin.OriginalItemColors[mapCustom] = color;
				}
				if (!Plugin.Instance.ShowItems.Value)
				{
					return false;
				}
				string text = Plugin.Instance.ItemsShape.Value.Trim().ToLower();
				if (text != "default" && text != "original")
				{
					sprite = Plugin.GetOrCreateShapeSprite(text);
				}
				color = Plugin.Instance.GetItemsColor(color);
				mapCustom.sprite = sprite;
				mapCustom.color = color;
				return true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(MapValuable), "Start")]
	internal static class MapValuableStartPatch
	{
		private static void Postfix(MapValuable __instance)
		{
			Plugin.UpdateMapValuable(__instance);
		}
	}
	internal sealed class MapEntityTracker : MonoBehaviour
	{
		private Component target = null;

		private MapCustom mapCustom = null;

		private Map addedToMap = null;

		private bool isDeadPlayer = false;

		private Difficulty enemyDifficulty;

		internal void Initialize(Component trackedTarget)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			target = trackedTarget;
			((Component)this).transform.position = target.transform.position;
			mapCustom = ((Component)this).gameObject.AddComponent<MapCustom>();
			mapCustom.autoAdd = false;
			UpdateShapeAndColor(force: true);
			AddToCurrentMap();
		}

		internal void ForceUpdate()
		{
			addedToMap = null;
			UpdateShapeAndColor(force: true);
		}

		private void Update()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			bool activeInHierarchy = target.gameObject.activeInHierarchy;
			if (activeInHierarchy)
			{
				((Component)this).transform.position = target.transform.position;
				((Component)this).transform.rotation = target.transform.rotation;
				UpdateShapeAndColor();
			}
			if ((Object)(object)Map.Instance != (Object)null && (Object)(object)Map.Instance != (Object)(object)addedToMap && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
			{
				MapCustomEntity mapCustomEntity = Plugin.GetMapCustomEntity(mapCustom);
				if ((Object)(object)mapCustomEntity != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)mapCustomEntity).gameObject);
					Plugin.SetMapCustomEntity(mapCustom, null);
				}
				AddToCurrentMap();
			}
			if (activeInHierarchy)
			{
				MapCustomEntity mapCustomEntity2 = Plugin.GetMapCustomEntity(mapCustom);
				if ((Object)(object)mapCustomEntity2 == (Object)null && (Object)(object)Map.Instance != (Object)null && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated)
				{
					AddToCurrentMap();
				}
				return;
			}
			MapCustomEntity mapCustomEntity3 = Plugin.GetMapCustomEntity(mapCustom);
			if ((Object)(object)mapCustomEntity3 != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)mapCustomEntity3).gameObject);
				Plugin.SetMapCustomEntity(mapCustom, null);
			}
		}

		private void UpdateShapeAndColor(bool force = false)
		{
			//IL_0036: 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)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: 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)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: 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_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Invalid comparison between Unknown and I4
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Invalid comparison between Unknown and I4
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)target == (Object)null || (Object)(object)mapCustom == (Object)null || (Object)(object)Plugin.Instance == (Object)null)
			{
				return;
			}
			Sprite val = null;
			Color val2 = Color.white;
			Component obj = target;
			PlayerAvatar val3 = (PlayerAvatar)(object)((obj is PlayerAvatar) ? obj : null);
			if (val3 != null)
			{
				bool flag = Plugin.IsPlayerDisabled(val3);
				if (force || flag != isDeadPlayer)
				{
					isDeadPlayer = flag;
					if (isDeadPlayer)
					{
						val = Plugin.GetOrCreateShapeSprite(Plugin.Instance.DeadTeammatesShape.Value);
						val2 = Plugin.Instance.GetDeadTeammatesColor();
					}
					else
					{
						val = Plugin.GetOrCreateShapeSprite(Plugin.Instance.TeammatesShape.Value);
						val2 = Plugin.Instance.GetTeammatesColor();
					}
				}
			}
			else
			{
				Component obj2 = target;
				Enemy val4 = (Enemy)(object)((obj2 is Enemy) ? obj2 : null);
				if (val4 != null)
				{
					EnemyParent enemyParent = Plugin.GetEnemyParent(val4);
					Difficulty val5 = (Difficulty)(((Object)(object)enemyParent != (Object)null) ? ((int)enemyParent.difficulty) : 0);
					if (force || val5 != enemyDifficulty)
					{
						enemyDifficulty = val5;
						string value = Plugin.Instance.Level1EnemiesShape.Value;
						Color val6 = Plugin.Instance.GetLevel1EnemiesColor();
						if ((int)enemyDifficulty == 1)
						{
							value = Plugin.Instance.Level2EnemiesShape.Value;
							val6 = Plugin.Instance.GetLevel2EnemiesColor();
						}
						else if ((int)enemyDifficulty == 2)
						{
							value = Plugin.Instance.Level3EnemiesShape.Value;
							val6 = Plugin.Instance.GetLevel3EnemiesColor();
						}
						val = Plugin.GetOrCreateShapeSprite(value);
						val2 = val6;
					}
				}
				else if (target is CosmeticWorldObject && force)
				{
					val = Plugin.GetOrCreateShapeSprite(Plugin.Instance.CosmeticBoxesShape.Value);
					val2 = Plugin.Instance.GetCosmeticBoxesColor();
				}
			}
			if ((Object)(object)val != (Object)null)
			{
				mapCustom.sprite = val;
				mapCustom.color = val2;
				MapCustomEntity mapCustomEntity = Plugin.GetMapCustomEntity(mapCustom);
				if ((Object)(object)mapCustomEntity != (Object)null && (Object)(object)mapCustomEntity.spriteRenderer != (Object)null)
				{
					mapCustomEntity.spriteRenderer.sprite = val;
					float a = mapCustomEntity.spriteRenderer.color.a;
					Color color = val2;
					color.a = a;
					mapCustomEntity.spriteRenderer.color = color;
				}
			}
		}

		private void AddToCurrentMap()
		{
			if (!((Object)(object)Map.Instance == (Object)null) && !((Object)(object)mapCustom == (Object)null))
			{
				addedToMap = Map.Instance;
				mapCustom.Add();
			}
		}
	}
}