Decompiled source of PowerupMinimap v1.1.0

PowerupMinimap.dll

Decompiled a day 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[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("PowerupMinimap")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d725f1c3f6a527ae04b334eb672e4476d1148f1f")]
[assembly: AssemblyProduct("PowerupMinimap")]
[assembly: AssemblyTitle("PowerupMinimap")]
[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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PowerupMinimap
{
	internal static class CollectiblePatches
	{
		[HarmonyPatch(typeof(CollectibleItemBase), "OnNetworkSpawn")]
		[HarmonyPostfix]
		private static void CollectibleItemBase_OnNetworkSpawn(CollectibleItemBase __instance)
		{
			TryRegister(__instance);
		}

		[HarmonyPatch(typeof(CollectibleItemBase), "OnNetworkDespawn")]
		[HarmonyPostfix]
		private static void CollectibleItemBase_OnNetworkDespawn(CollectibleItemBase __instance)
		{
			TryUnregister(__instance);
		}

		private static void TryRegister(CollectibleItemBase item)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)item == (Object)null))
				{
					EnsureOverlay();
					PickupCategory pickupCategory = ClassifyCollectible(item);
					if (IsVisible(pickupCategory))
					{
						MinimapBlipOverlay.Register(EntityId.op_Implicit(((Object)((Component)item).gameObject).GetEntityId()), ((Component)item).transform, pickupCategory);
					}
				}
			}
			catch (Exception ex)
			{
				PowerupMinimapPlugin.Log.LogDebug((object)("[PowerupMinimap] Register failed: " + ex.Message));
			}
		}

		private static void TryUnregister(CollectibleItemBase item)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)item == (Object)null))
				{
					MinimapBlipOverlay.Unregister(EntityId.op_Implicit(((Object)((Component)item).gameObject).GetEntityId()));
				}
			}
			catch
			{
			}
		}

		private static void RegisterGO(GameObject go, PickupCategory cat)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!((Object)(object)go == (Object)null))
				{
					EnsureOverlay();
					if (IsVisible(cat))
					{
						MinimapBlipOverlay.Register(EntityId.op_Implicit(((Object)go).GetEntityId()), go.transform, cat);
					}
				}
			}
			catch (Exception ex)
			{
				PowerupMinimapPlugin.Log.LogDebug((object)("[PowerupMinimap] RegisterGO failed: " + ex.Message));
			}
		}

		private static PickupCategory ClassifyCollectible(CollectibleItemBase item)
		{
			string name = ((object)item).GetType().Name;
			if (ContainsAny(name, "HP", "Heal", "Health", "Potion", "DropHP"))
			{
				return PickupCategory.HP;
			}
			if (ContainsAny(name, "Magnet"))
			{
				return PickupCategory.Magnet;
			}
			if (ContainsAny(name, "Bomb", "Explosive"))
			{
				return PickupCategory.Bomb;
			}
			if (ContainsAny(name, "Exp", "XP", "Experience"))
			{
				return PickupCategory.ExpBoost;
			}
			if (ContainsAny(name, "Speed"))
			{
				return PickupCategory.Speed;
			}
			if (ContainsAny(name, "Buff", "Builder", "Attack", "Upgrade"))
			{
				return PickupCategory.Buff;
			}
			if (ContainsAny(name, "Coin", "Currency", "Gold"))
			{
				return PickupCategory.Generic;
			}
			Component[] components = ((Component)item).GetComponents<Component>();
			foreach (Component val in components)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string name2 = ((object)val).GetType().Name;
					if (ContainsAny(name2, "HP", "Heal", "Health", "Potion"))
					{
						return PickupCategory.HP;
					}
					if (ContainsAny(name2, "Magnet"))
					{
						return PickupCategory.Magnet;
					}
					if (ContainsAny(name2, "Bomb", "Explosive"))
					{
						return PickupCategory.Bomb;
					}
					if (ContainsAny(name2, "Exp", "XP", "Experience"))
					{
						return PickupCategory.ExpBoost;
					}
					if (ContainsAny(name2, "Speed"))
					{
						return PickupCategory.Speed;
					}
					if (ContainsAny(name2, "Attack", "Buff", "Upgrade"))
					{
						return PickupCategory.Buff;
					}
				}
			}
			return PickupCategory.Generic;
		}

		private static bool ContainsAny(string source, params string[] tokens)
		{
			foreach (string value in tokens)
			{
				if (source.IndexOf(value, StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return true;
				}
			}
			return false;
		}

		private static bool IsVisible(PickupCategory cat)
		{
			return cat switch
			{
				PickupCategory.HP => PowerupMinimapPlugin.ShowHP.Value, 
				PickupCategory.Buff => PowerupMinimapPlugin.ShowBuff.Value, 
				PickupCategory.Bomb => PowerupMinimapPlugin.ShowBomb.Value, 
				PickupCategory.Magnet => PowerupMinimapPlugin.ShowMagnet.Value, 
				PickupCategory.ExpBoost => PowerupMinimapPlugin.ShowExpBoost.Value, 
				PickupCategory.Speed => PowerupMinimapPlugin.ShowSpeed.Value, 
				PickupCategory.Chest => PowerupMinimapPlugin.ShowChest.Value, 
				_ => PowerupMinimapPlugin.ShowGeneric.Value, 
			};
		}

		private static void EnsureOverlay()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)MinimapBlipOverlay.Instance != (Object)null))
			{
				new GameObject("PowerupMinimapOverlay").AddComponent<MinimapBlipOverlay>();
			}
		}
	}
	public enum PickupCategory
	{
		HP,
		Buff,
		Bomb,
		Magnet,
		ExpBoost,
		Speed,
		Chest,
		Generic
	}
	public sealed class PickupEntry
	{
		public Transform? Transform;

		public PickupCategory Category;
	}
	public sealed class MinimapBlipOverlay : MonoBehaviour
	{
		private static readonly Dictionary<int, PickupEntry> _pickups = new Dictionary<int, PickupEntry>();

		private static readonly object _lock = new object();

		private MinimapController? _minimapController;

		private RectTransform? _mapImageRT;

		private RectTransform? _maskRT;

		private Canvas? _canvas;

		private Camera? _canvasCam;

		private FieldInfo? _fViewState;

		private FieldInfo? _fFrameUnfolded;

		private FieldInfo? _fCircularMask;

		private FieldInfo? _fMinWorld;

		private FieldInfo? _fMaxWorld;

		private float _worldMinX;

		private float _worldMinZ;

		private float _worldMaxX;

		private float _worldMaxZ;

		private bool _boundsValid;

		private bool _isCircular;

		private float _boundsRefreshTimer;

		private const float BoundsRefreshInterval = 1f;

		private readonly List<(Vector3 world, PickupCategory cat)> _drawList = new List<(Vector3, PickupCategory)>(64);

		private Texture2D? _blipTex;

		private float _pulsePhase;

		private GUIStyle? _labelStyle;

		private float _pruneTimer;

		private const float PruneInterval = 2f;

		private readonly List<int> _removeBuffer = new List<int>(8);

		public static MinimapBlipOverlay? Instance { get; private set; }

		public static void Register(int id, Transform transform, PickupCategory category)
		{
			lock (_lock)
			{
				_pickups[id] = new PickupEntry
				{
					Transform = transform,
					Category = category
				};
			}
		}

		public static void Unregister(int id)
		{
			lock (_lock)
			{
				_pickups.Remove(id);
			}
		}

		private void Awake()
		{
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Instance = this;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			_blipTex = MakeCircleTexture(64);
		}

		private void OnDestroy()
		{
			if ((Object)(object)Instance == (Object)(object)this)
			{
				Instance = null;
			}
			if ((Object)(object)_blipTex != (Object)null)
			{
				Object.Destroy((Object)(object)_blipTex);
			}
		}

		private void Update()
		{
			if (!PowerupMinimapPlugin.Enabled.Value)
			{
				return;
			}
			float deltaTime = Time.deltaTime;
			float value = PowerupMinimapPlugin.PulseSpeed.Value;
			if (value > 0f)
			{
				_pulsePhase = (_pulsePhase + deltaTime * value * MathF.PI * 2f) % (MathF.PI * 2f);
			}
			RefreshMinimapRef();
			_pruneTimer += deltaTime;
			if (_pruneTimer >= 2f)
			{
				_pruneTimer = 0f;
				lock (_lock)
				{
					_removeBuffer.Clear();
					foreach (KeyValuePair<int, PickupEntry> pickup in _pickups)
					{
						if ((Object)(object)pickup.Value.Transform == (Object)null)
						{
							_removeBuffer.Add(pickup.Key);
						}
					}
					foreach (int item in _removeBuffer)
					{
						_pickups.Remove(item);
					}
				}
			}
			_boundsRefreshTimer += deltaTime;
			if (_boundsRefreshTimer >= 1f)
			{
				_boundsRefreshTimer = 0f;
				_boundsValid = TryGetWorldBounds(out _worldMinX, out _worldMinZ, out _worldMaxX, out _worldMaxZ);
				if (_fCircularMask != null && (Object)(object)_minimapController != (Object)null)
				{
					_isCircular = (bool)_fCircularMask.GetValue(_minimapController);
				}
			}
		}

		private void OnGUI()
		{
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: 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_0290: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d0: 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_02f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0325: Unknown result type (might be due to invalid IL or missing references)
			//IL_0327: Unknown result type (might be due to invalid IL or missing references)
			//IL_032c: Unknown result type (might be due to invalid IL or missing references)
			//IL_032e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			if (!PowerupMinimapPlugin.Enabled.Value || (Object)(object)_mapImageRT == (Object)null || (Object)(object)_blipTex == (Object)null || !_boundsValid)
			{
				return;
			}
			float num = _worldMaxX - _worldMinX;
			float num2 = _worldMaxZ - _worldMinZ;
			if (num < 0.001f || num2 < 0.001f)
			{
				return;
			}
			RectTransform val = _maskRT;
			bool flag = _isCircular;
			if (_fViewState != null && (Object)(object)_minimapController != (Object)null && (_fViewState.GetValue(_minimapController)?.ToString() ?? "") == "Unfolded" && _fFrameUnfolded != null)
			{
				object? value = _fFrameUnfolded.GetValue(_minimapController);
				GameObject val2 = (GameObject)((value is GameObject) ? value : null);
				if ((Object)(object)val2 != (Object)null && val2.activeInHierarchy)
				{
					RectTransform component = val2.GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						val = component;
						flag = false;
					}
				}
			}
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Rect val3 = GUIRectOf(val);
			if (((Rect)(ref val3)).width < 1f || ((Rect)(ref val3)).height < 1f)
			{
				return;
			}
			float num3 = 1f + Mathf.Sin(_pulsePhase) * PowerupMinimapPlugin.PulseScale.Value;
			float size = PowerupMinimapPlugin.BlipSize.Value * num3;
			if (_labelStyle == null)
			{
				BuildLabelStyle();
			}
			_drawList.Clear();
			lock (_lock)
			{
				foreach (KeyValuePair<int, PickupEntry> pickup in _pickups)
				{
					if (!((Object)(object)pickup.Value.Transform == (Object)null))
					{
						_drawList.Add((pickup.Value.Transform.position, pickup.Value.Category));
					}
				}
			}
			if (_drawList.Count == 0)
			{
				return;
			}
			float num4 = 0f;
			float num5 = ((Rect)(ref val3)).width * 0.5f;
			float num6 = ((Rect)(ref val3)).height * 0.5f;
			if (flag)
			{
				num4 = num5 * num5;
			}
			GUI.BeginClip(val3);
			foreach (var (val4, cat) in _drawList)
			{
				if (!IsVisible(cat))
				{
					continue;
				}
				float num7 = (val4.x - _worldMinX) / num;
				float num8 = (val4.z - _worldMinZ) / num2;
				float num9 = num7 - _mapImageRT.pivot.x;
				Rect rect = _mapImageRT.rect;
				float num10 = num9 * ((Rect)(ref rect)).width;
				float num11 = num8 - _mapImageRT.pivot.y;
				rect = _mapImageRT.rect;
				float num12 = num11 * ((Rect)(ref rect)).height;
				Vector3 val5 = ((Transform)_mapImageRT).TransformPoint(new Vector3(num10, num12, 0f));
				Vector2 val6 = RectTransformUtility.WorldToScreenPoint(_canvasCam, val5);
				float num13 = val6.x - ((Rect)(ref val3)).xMin;
				float num14 = (float)Screen.height - val6.y - ((Rect)(ref val3)).yMin;
				if (flag)
				{
					float num15 = num13 - num5;
					float num16 = num14 - num6;
					if (num15 * num15 + num16 * num16 > num4)
					{
						continue;
					}
				}
				else if (num13 < 0f || num13 > ((Rect)(ref val3)).width || num14 < 0f || num14 > ((Rect)(ref val3)).height)
				{
					continue;
				}
				DrawBlip(num13, num14, size, GetColor(cat), cat);
			}
			GUI.EndClip();
		}

		private void RefreshMinimapRef()
		{
			if ((Object)(object)_minimapController == (Object)null)
			{
				_minimapController = Object.FindAnyObjectByType<MinimapController>();
				if ((Object)(object)_minimapController == (Object)null)
				{
					return;
				}
				Type type = ((object)_minimapController).GetType();
				_fViewState = AccessTools.Field(type, "_viewState");
				_fFrameUnfolded = AccessTools.Field(type, "frameUnfolded");
				_fCircularMask = AccessTools.Field(type, "circularMask");
				_fMinWorld = AccessTools.Field(type, "_minWorld");
				_fMaxWorld = AccessTools.Field(type, "_maxWorld");
				_mapImageRT = null;
				_maskRT = null;
				_canvas = null;
				_canvasCam = null;
				_boundsRefreshTimer = 1f;
			}
			if ((Object)(object)_mapImageRT == (Object)null || (Object)(object)_maskRT == (Object)null)
			{
				Type type2 = ((object)_minimapController).GetType();
				FieldInfo fieldInfo = AccessTools.Field(type2, "mapImageRect");
				FieldInfo fieldInfo2 = AccessTools.Field(type2, "maskRect");
				if (fieldInfo != null)
				{
					ref RectTransform? mapImageRT = ref _mapImageRT;
					object? value = fieldInfo.GetValue(_minimapController);
					mapImageRT = (RectTransform?)((value is RectTransform) ? value : null);
				}
				if (fieldInfo2 != null)
				{
					ref RectTransform? maskRT = ref _maskRT;
					object? value2 = fieldInfo2.GetValue(_minimapController);
					maskRT = (RectTransform?)((value2 is RectTransform) ? value2 : null);
				}
				if ((Object)(object)_mapImageRT == (Object)null)
				{
					_mapImageRT = FindMinimapRect(_minimapController);
				}
				if ((Object)(object)_maskRT == (Object)null)
				{
					_maskRT = ((Component)_minimapController).GetComponent<RectTransform>();
				}
			}
			if ((Object)(object)_canvas == (Object)null && (Object)(object)_mapImageRT != (Object)null)
			{
				_canvas = ((Component)_mapImageRT).GetComponentInParent<Canvas>();
				_canvasCam = (((Object)(object)_canvas != (Object)null) ? _canvas.worldCamera : null);
			}
		}

		private static RectTransform? FindMinimapRect(MinimapController ctrl)
		{
			string[] array = new string[5] { "MinimapImage", "MapImage", "Minimap", "Map", "MinimapPanel" };
			foreach (string text in array)
			{
				Transform val = ((Component)ctrl).transform.Find(text);
				if ((Object)(object)val != (Object)null)
				{
					RectTransform component = ((Component)val).GetComponent<RectTransform>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
			}
			RectTransform component2 = ((Component)ctrl).GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null)
			{
				return component2;
			}
			if (((Component)ctrl).transform.childCount > 0)
			{
				RectTransform component3 = ((Component)((Component)ctrl).transform.GetChild(0)).GetComponent<RectTransform>();
				if ((Object)(object)component3 != (Object)null)
				{
					return component3;
				}
			}
			return null;
		}

		private bool TryGetWorldBounds(out float minX, out float minZ, out float maxX, out float maxZ)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: 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_0133: 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_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: 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_0172: 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)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0235: Unknown result type (might be due to invalid IL or missing references)
			//IL_023a: Unknown result type (might be due to invalid IL or missing references)
			//IL_023f: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			minX = (minZ = (maxX = (maxZ = 0f)));
			if ((Object)(object)_minimapController != (Object)null && _fMinWorld != null && _fMaxWorld != null)
			{
				object value = _fMinWorld.GetValue(_minimapController);
				object value2 = _fMaxWorld.GetValue(_minimapController);
				if (value is Vector2 val && value2 is Vector2 val2 && Mathf.Abs(val2.x - val.x) > 1f)
				{
					minX = val.x;
					minZ = val.y;
					maxX = val2.x;
					maxZ = val2.y;
					return true;
				}
			}
			Terrain[] array = Object.FindObjectsByType<Terrain>((FindObjectsInactive)0);
			if (array != null && array.Length != 0)
			{
				minX = float.MaxValue;
				minZ = float.MaxValue;
				maxX = float.MinValue;
				maxZ = float.MinValue;
				Terrain[] array2 = array;
				foreach (Terrain val3 in array2)
				{
					if (!((Object)(object)val3 == (Object)null) && !((Object)(object)val3.terrainData == (Object)null))
					{
						Vector3 position = ((Component)val3).transform.position;
						Vector3 size = val3.terrainData.size;
						minX = Mathf.Min(minX, position.x);
						minZ = Mathf.Min(minZ, position.z);
						maxX = Mathf.Max(maxX, position.x + size.x);
						maxZ = Mathf.Max(maxZ, position.z + size.z);
					}
				}
				if (maxX > minX && maxZ > minZ)
				{
					return true;
				}
			}
			lock (_lock)
			{
				if (_pickups.Count == 0)
				{
					return false;
				}
				minX = float.MaxValue;
				minZ = float.MaxValue;
				maxX = float.MinValue;
				maxZ = float.MinValue;
				foreach (KeyValuePair<int, PickupEntry> pickup in _pickups)
				{
					if (!((Object)(object)pickup.Value.Transform == (Object)null))
					{
						Vector3 position2 = pickup.Value.Transform.position;
						minX = Mathf.Min(minX, position2.x);
						minZ = Mathf.Min(minZ, position2.z);
						maxX = Mathf.Max(maxX, position2.x);
						maxZ = Mathf.Max(maxZ, position2.z);
					}
				}
				float num = 50f;
				minX -= num;
				minZ -= num;
				maxX += num;
				maxZ += num;
				return maxX > minX && maxZ > minZ;
			}
		}

		private void DrawBlip(float cx, float cy, float size, Color col, PickupCategory cat)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			float num = size * 0.5f;
			Color color = col;
			color.a *= 0.35f;
			GUI.color = color;
			GUI.DrawTexture(new Rect(cx - num * 1.8f, cy - num * 1.8f, size * 1.8f, size * 1.8f), (Texture)(object)_blipTex);
			GUI.color = col;
			GUI.DrawTexture(new Rect(cx - num, cy - num, size, size), (Texture)(object)_blipTex);
			if (_labelStyle != null && size >= 6f)
			{
				GUI.color = Color.white;
				_labelStyle.fontSize = Mathf.RoundToInt(size * 0.7f);
				GUI.Label(new Rect(cx - num, cy - num, size, size), CategoryLetter(cat), _labelStyle);
			}
			GUI.color = Color.white;
		}

		private static string CategoryLetter(PickupCategory cat)
		{
			return cat switch
			{
				PickupCategory.HP => "+", 
				PickupCategory.Buff => "B", 
				PickupCategory.Bomb => "\ud83d\udca3", 
				PickupCategory.Magnet => "M", 
				PickupCategory.ExpBoost => "E", 
				PickupCategory.Speed => "S", 
				PickupCategory.Chest => "C", 
				_ => "?", 
			};
		}

		private static Color GetColor(PickupCategory cat)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_005d: 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_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			return (Color)(cat switch
			{
				PickupCategory.HP => PowerupMinimapPlugin.ColorHP.Value, 
				PickupCategory.Buff => PowerupMinimapPlugin.ColorBuff.Value, 
				PickupCategory.Bomb => PowerupMinimapPlugin.ColorBomb.Value, 
				PickupCategory.Magnet => PowerupMinimapPlugin.ColorMagnet.Value, 
				PickupCategory.ExpBoost => PowerupMinimapPlugin.ColorExpBoost.Value, 
				PickupCategory.Speed => PowerupMinimapPlugin.ColorSpeed.Value, 
				PickupCategory.Chest => PowerupMinimapPlugin.ColorChest.Value, 
				_ => PowerupMinimapPlugin.ColorGeneric.Value, 
			});
		}

		private static bool IsVisible(PickupCategory cat)
		{
			return cat switch
			{
				PickupCategory.HP => PowerupMinimapPlugin.ShowHP.Value, 
				PickupCategory.Buff => PowerupMinimapPlugin.ShowBuff.Value, 
				PickupCategory.Bomb => PowerupMinimapPlugin.ShowBomb.Value, 
				PickupCategory.Magnet => PowerupMinimapPlugin.ShowMagnet.Value, 
				PickupCategory.ExpBoost => PowerupMinimapPlugin.ShowExpBoost.Value, 
				PickupCategory.Speed => PowerupMinimapPlugin.ShowSpeed.Value, 
				PickupCategory.Chest => PowerupMinimapPlugin.ShowChest.Value, 
				_ => PowerupMinimapPlugin.ShowGeneric.Value, 
			};
		}

		private static Rect GUIRectOf(RectTransform rt)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Canvas componentInParent = ((Component)rt).GetComponentInParent<Canvas>();
			Camera obj = ((componentInParent != null) ? componentInParent.worldCamera : null);
			Vector3[] array = (Vector3[])(object)new Vector3[4];
			rt.GetWorldCorners(array);
			Vector2 val = RectTransformUtility.WorldToScreenPoint(obj, array[0]);
			Vector2 val2 = RectTransformUtility.WorldToScreenPoint(obj, array[2]);
			return new Rect(val.x, (float)Screen.height - val2.y, val2.x - val.x, val2.y - val.y);
		}

		private static Texture2D MakeCircleTexture(int size)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(size, size, (TextureFormat)4, false);
			((Object)val).hideFlags = (HideFlags)61;
			float num = (float)size * 0.5f;
			float num2 = num - 1f;
			for (int i = 0; i < size; i++)
			{
				for (int j = 0; j < size; j++)
				{
					float num3 = (float)j - num + 0.5f;
					float num4 = (float)i - num + 0.5f;
					val.SetPixel(j, i, new Color(1f, 1f, 1f, Mathf.Clamp01((num2 - Mathf.Sqrt(num3 * num3 + num4 * num4)) / 1.5f)));
				}
			}
			val.Apply();
			return val;
		}

		private void BuildLabelStyle()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			_labelStyle = new GUIStyle(GUI.skin.label)
			{
				alignment = (TextAnchor)4,
				fontStyle = (FontStyle)1,
				fontSize = 8
			};
			_labelStyle.normal.textColor = Color.white;
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.sineusarena.powerupminimap";

		public const string PLUGIN_NAME = "Powerup Minimap";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.sineusarena.powerupminimap", "Powerup Minimap", "1.0.0")]
	public class PowerupMinimapPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static PowerupMinimapPlugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

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

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

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

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

		public static ConfigEntry<Color> ColorHP { get; private set; }

		public static ConfigEntry<Color> ColorBuff { get; private set; }

		public static ConfigEntry<Color> ColorBomb { get; private set; }

		public static ConfigEntry<Color> ColorMagnet { get; private set; }

		public static ConfigEntry<Color> ColorExpBoost { get; private set; }

		public static ConfigEntry<Color> ColorSpeed { get; private set; }

		public static ConfigEntry<Color> ColorChest { get; private set; }

		public static ConfigEntry<Color> ColorGeneric { get; private set; }

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

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

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

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

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

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

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

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

		private void Awake()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			BindConfig();
			_harmony = new Harmony("com.sineusarena.powerupminimap");
			_harmony.PatchAll(typeof(CollectiblePatches));
			SceneManager.sceneLoaded += OnSceneLoaded;
			Log.LogInfo((object)"Powerup Minimap loaded successfully!");
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)GameObject.Find("PowerupMinimapOverlay") == (Object)null)
				{
					new GameObject("PowerupMinimapOverlay").AddComponent<MinimapBlipOverlay>();
				}
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error in OnSceneLoaded: {arg}");
			}
		}

		private void OnDestroy()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			_harmony.UnpatchSelf();
		}

		private void BindConfig()
		{
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0190: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0238: Unknown result type (might be due to invalid IL or missing references)
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "Enabled", true, "Enable or disable the entire mod.");
			BlipSize = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "BlipSize", 8f, "Radius in minimap pixels of each powerup blip.");
			PulseSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "PulseSpeed", 2.5f, "How fast the blips pulse (cycles per second). Set to 0 to disable pulsing.");
			PulseScale = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Appearance", "PulseScale", 0.35f, "Fractional size change during pulsing (0 = no pulse, 0.5 = ±50% size).");
			ColorHP = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorHP", new Color(0.2f, 0.9f, 0.3f, 1f), "Colour for healing / HP pickups.");
			ColorBuff = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorBuff", new Color(0.9f, 0.6f, 0.1f, 1f), "Colour for buff pickups.");
			ColorBomb = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorBomb", new Color(0.95f, 0.25f, 0.1f, 1f), "Colour for bomb pickups.");
			ColorMagnet = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorMagnet", new Color(0.55f, 0.3f, 0.95f, 1f), "Colour for magnet pickups.");
			ColorExpBoost = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorExpBoost", new Color(0.1f, 0.7f, 0.95f, 1f), "Colour for experience boost pickups.");
			ColorSpeed = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorSpeed", new Color(0.95f, 0.95f, 0.1f, 1f), "Colour for speed buff pickups.");
			ColorChest = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorChest", new Color(1f, 0.8f, 0.1f, 1f), "Colour for buff chest items.");
			ColorGeneric = ((BaseUnityPlugin)this).Config.Bind<Color>("3 - Colors", "ColorGeneric", new Color(0.8f, 0.8f, 0.8f, 1f), "Colour for any other pickup types.");
			ShowHP = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowHP", true, "Show HP / healing pickups on the minimap.");
			ShowBuff = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowBuff", true, "Show buff pickups on the minimap.");
			ShowBomb = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowBomb", true, "Show bomb pickups on the minimap.");
			ShowMagnet = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowMagnet", true, "Show magnet pickups on the minimap.");
			ShowExpBoost = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowExpBoost", true, "Show experience boost pickups on the minimap.");
			ShowSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowSpeed", true, "Show speed buff pickups on the minimap.");
			ShowChest = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowChest", true, "Show buff chests on the minimap.");
			ShowGeneric = ((BaseUnityPlugin)this).Config.Bind<bool>("4 - Filters", "ShowGeneric", true, "Show all other pickup types on the minimap.");
		}
	}
}