Decompiled source of Mana Gain Leader v1.0.1

ManaGainLeader.dll

Decompiled an hour 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.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BrigadeModMenu;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppSystem;
using ManaGainLeader;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(ManaGainLeaderMod), "Mana Gain Leader", "1.0.1", "Mana Gain Leader", null)]
[assembly: MelonGame("BoltBlasterGames", "TheSpellBrigade")]
[assembly: MelonOptionalDependencies(new string[] { "BrigadeModMenu" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ManaGainLeader")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("ManaGainLeader")]
[assembly: AssemblyTitle("ManaGainLeader")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
internal static class Tr
{
	private static Func<string, string> _t;

	private static Func<int> _version;

	private static float _nextLook;

	private static bool _found;

	public static int Version
	{
		get
		{
			if (!Find())
			{
				return 0;
			}
			try
			{
				return _version();
			}
			catch
			{
				return 0;
			}
		}
	}

	private static bool Find()
	{
		if (_found)
		{
			return true;
		}
		float unscaledTime = Time.unscaledTime;
		if (unscaledTime < _nextLook)
		{
			return false;
		}
		_nextLook = unscaledTime + 5f;
		try
		{
			Type type = null;
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			foreach (Assembly assembly in assemblies)
			{
				if (assembly.GetName().Name == "BrigadeModMenu")
				{
					type = assembly.GetType("BrigadeModMenu.Lang");
					break;
				}
			}
			MethodInfo methodInfo = type?.GetMethod("T", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(string) }, null);
			MethodInfo methodInfo2 = type?.GetProperty("Version", BindingFlags.Static | BindingFlags.Public)?.GetGetMethod();
			if (methodInfo == null || methodInfo2 == null)
			{
				return false;
			}
			_t = (Func<string, string>)Delegate.CreateDelegate(typeof(Func<string, string>), methodInfo);
			_version = (Func<int>)Delegate.CreateDelegate(typeof(Func<int>), methodInfo2);
			_found = true;
		}
		catch
		{
		}
		return _found;
	}

	public static string T(string english)
	{
		if (string.IsNullOrEmpty(english) || !Find())
		{
			return english;
		}
		try
		{
			return _t(english);
		}
		catch
		{
			return english;
		}
	}

	public static string F(string englishPattern, params object[] args)
	{
		try
		{
			return string.Format(T(englishPattern), args);
		}
		catch (FormatException)
		{
			return string.Format(englishPattern, args);
		}
	}
}
namespace BrigadeModMenu
{
	public static class ModMenuCompat
	{
		public static Page Entry(this Page page, MelonPreferences_Entry entry, Func<string> label = null)
		{
			if (entry != null)
			{
				return page.Entry(entry.Raw, label ?? ((Func<string>)(() => entry.DisplayName)));
			}
			return page;
		}

		public static Page Category(this Page page, MelonPreferences_Category category)
		{
			if (category == null)
			{
				return page;
			}
			Menu.HideCategory(category.Identifier);
			foreach (MelonPreferences_Entry e in category.Entries)
			{
				if (e != null && !e.IsHidden)
				{
					page.Entry(e.Raw, (Func<string>)(() => e.DisplayName));
				}
			}
			return page;
		}
	}
}
namespace ManaGainLeader
{
	public class ManaGainLeaderMod : MelonMod
	{
		internal static MelonLogger.Instance Log;

		internal static MelonPreferences_Entry<bool> Enabled;

		internal static MelonPreferences_Entry<string> Icon;

		internal static MelonPreferences_Entry<float> TeamSize;

		internal static MelonPreferences_Entry<float> TeamX;

		internal static MelonPreferences_Entry<float> TeamY;

		internal static MelonPreferences_Entry<float> YouSize;

		internal static MelonPreferences_Entry<float> YouX;

		internal static MelonPreferences_Entry<float> YouY;

		internal static readonly string[] IconChoices = new string[2] { "Mana Magnet", "Mana Beast" };

		internal const string MagnetSprite = "ui_ping_magnet";

		internal static readonly string[] BeastSprites = new string[2] { "ui_objective_icon_herding", "ui_ping_objective_herding" };

		internal const float TeamMinX = -11f;

		internal const float TeamMaxX = 414f;

		internal const float TeamMinY = -110f;

		internal const float TeamMaxY = 10f;

		internal const float DefaultSize = 1.3f;

		internal const float YouDefaultSize = 2f;

		internal const float TeamDefaultX = 8f;

		internal const float TeamDefaultY = -8f;

		internal const float BaseSize = 64f;

		internal const string BadgePortrait = "PlayerPortrait_Panel";

		internal const string LevelPath = "LevelDisplay_Panel/Bar/Level";

		private const float CheckEvery = 0.25f;

		private const float Tie = 0.05f;

		private static ManaGainLeaderMod _instance;

		private static bool _hasMenu;

		private static float _editTeamUntil;

		private static float _editYouUntil;

		private float _nextCheck;

		private float _retryAt;

		private float _nextHudSearch;

		private string _lastError;

		private string _lastSummary = "";

		private Canvas _hud;

		private readonly Dictionary<IntPtr, Image> _badgeIcons = new Dictionary<IntPtr, Image>();

		private Image _youIcon;

		internal static readonly Vector2 TeamCorner = new Vector2(0f, 1f);

		internal static readonly Vector2 YouCorner = new Vector2(1f, 1f);

		private static Sprite _wanted;

		private static float _nextSpriteSearch;

		private static float _spriteSearchGap = 1f;

		internal static bool UseBeast => Icon.Value == IconChoices[1];

		public override void OnInitializeMelon()
		{
			Log = base.LoggerInstance;
			_instance = this;
			MelonPreferences_Category melonPreferences_Category = MelonPreferences.CreateCategory("ManaGainLeader", "Mana Gain Leader");
			Enabled = melonPreferences_Category.CreateEntry("Enabled", default_value: true, "Show Mana Gain Leader", "In multiplayer, mark the player with the most Mana Gain: they get the most mana out of each orb and magnet");
			Icon = melonPreferences_Category.CreateEntry("Icon", IconChoices[0], "Icon", "Mana Magnet or Mana Beast");
			TeamSize = melonPreferences_Category.CreateEntry("TeammateSize", 1.3f, "Teammate Icon Size", "Size of the icon on a teammate's badge", is_hidden: false, dont_save_default: false, new ValueRange<float>(0.5f, 1.8f));
			TeamX = melonPreferences_Category.CreateEntry("TeammateX", 8f, "Teammate Icon Left / Right", "From the top-left corner of the teammate's picture (the same on every teammate's badge)", is_hidden: false, dont_save_default: false, new ValueRange<float>(-11f, 414f));
			TeamY = melonPreferences_Category.CreateEntry("TeammateY", -8f, "Teammate Icon Up / Down", "From the top-left corner of the teammate's picture (the same on every teammate's badge)", is_hidden: false, dont_save_default: false, new ValueRange<float>(-110f, 10f));
			YouSize = melonPreferences_Category.CreateEntry("YouSize", 2f, "Your Icon Size", "Size of the icon by your level number", is_hidden: false, dont_save_default: false, new ValueRange<float>(0.5f, 3f));
			YouX = melonPreferences_Category.CreateEntry("YouX", 0f, "Your Icon Left / Right", "From the top-right corner of your level number", is_hidden: false, dont_save_default: false, new ValueRange<float>(-1000f, 4000f));
			YouY = melonPreferences_Category.CreateEntry("YouY", 0f, "Your Icon Up / Down", "From the top-right corner of your level number", is_hidden: false, dont_save_default: false, new ValueRange<float>(-1000f, 2000f));
			Icon.OnEntryValueChanged.Subscribe(delegate
			{
				_wanted = null;
				_nextSpriteSearch = 0f;
				_spriteSearchGap = 1f;
			});
			MelonPreferences_Entry<bool> melonPreferences_Entry = melonPreferences_Category.CreateEntry("BiggerDefault", default_value: false, null, null, is_hidden: true);
			if (!melonPreferences_Entry.Value)
			{
				if (Mathf.Approximately(TeamSize.Value, 1f))
				{
					TeamSize.Value = 1.3f;
				}
				if (Mathf.Approximately(YouSize.Value, 1f))
				{
					YouSize.Value = 1.3f;
				}
				melonPreferences_Entry.Value = true;
				melonPreferences_Category.SaveToFile(printmsg: false);
			}
			MelonPreferences_Entry<bool> melonPreferences_Entry2 = melonPreferences_Category.CreateEntry("Defaults110", default_value: false, null, null, is_hidden: true);
			if (!melonPreferences_Entry2.Value)
			{
				if (Array.IndexOf(IconChoices, Icon.Value) < 0)
				{
					Icon.Value = IconChoices[1];
				}
				if (Mathf.Approximately(YouSize.Value, 1.3f))
				{
					YouSize.Value = 2f;
				}
				if (Mathf.Approximately(TeamX.Value, 0f) && Mathf.Approximately(TeamY.Value, 0f))
				{
					TeamX.Value = 8f;
					TeamY.Value = -8f;
				}
				melonPreferences_Entry2.Value = true;
				melonPreferences_Category.SaveToFile(printmsg: false);
			}
			MelonPreferences_Entry<bool> melonPreferences_Entry3 = melonPreferences_Category.CreateEntry("TopLeftCorner", default_value: false, null, null, is_hidden: true);
			if (!melonPreferences_Entry3.Value)
			{
				TeamX.Value = 8f;
				TeamY.Value = -8f;
				YouX.Value = 0f;
				YouY.Value = 0f;
				melonPreferences_Entry3.Value = true;
				melonPreferences_Category.SaveToFile(printmsg: false);
			}
			if (Array.Exists(AppDomain.CurrentDomain.GetAssemblies(), (Assembly a) => a.GetName().Name == "BrigadeModMenu"))
			{
				_hasMenu = true;
				try
				{
					RegisterMenu();
				}
				catch (Exception ex)
				{
					Log.Warning("Mod Menu page: " + ex.Message);
				}
			}
			Log.Msg("ready");
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		private static void RegisterMenu()
		{
			MenuPage.Register();
		}

		public override void OnUpdate()
		{
			if (Time.unscaledTime < _retryAt || (!(Time.unscaledTime < _editTeamUntil) && !(Time.unscaledTime < _editYouUntil) && Time.unscaledTime < _nextCheck))
			{
				return;
			}
			_nextCheck = Time.unscaledTime + 0.25f;
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				string name = ex.GetType().Name;
				string? stackTrace = ex.StackTrace;
				string text = name + ((stackTrace != null) ? stackTrace.Split('\n')[0] : null);
				if (_lastError != text)
				{
					_lastError = text;
					Log.Error($"mana magnet: {ex}");
				}
				_retryAt = Time.unscaledTime + 3f;
				HideAll();
			}
		}

		private void Tick()
		{
			RunManager instance = NetworkSingleton<RunManager>.Instance;
			if ((Object)(object)instance == (Object)null || !instance.runHasStarted || !EnsureHud())
			{
				HideAll();
				return;
			}
			HashSet<IntPtr> hashSet = new HashSet<IntPtr>();
			List<(GameplayPlayerIdentity, float)> list = new List<(GameplayPlayerIdentity, float)>();
			if (Enabled.Value)
			{
				foreach (GameplayPlayerIdentity item2 in Object.FindObjectsByType<GameplayPlayerIdentity>((FindObjectsSortMode)0))
				{
					if ((Object)(object)item2 != (Object)null && item2.Stats != null)
					{
						list.Add((item2, ManaGain(item2)));
					}
				}
				if (list.Count > 1)
				{
					float num = float.MinValue;
					foreach (var item3 in list)
					{
						num = Mathf.Max(num, item3.Item2);
					}
					foreach (var item4 in list)
					{
						if (item4.Item2 >= num - 0.05f)
						{
							hashSet.Add(((Il2CppObjectBase)item4.Item1).Pointer);
						}
					}
				}
			}
			LogTop(list, hashSet);
			Sprite sprite = WantedSprite();
			bool flag = Time.unscaledTime < _editTeamUntil;
			bool flag2 = false;
			HashSet<IntPtr> hashSet2 = new HashSet<IntPtr>();
			foreach (GameplayPlayerOverviewUI item5 in Object.FindObjectsByType<GameplayPlayerOverviewUI>((FindObjectsSortMode)0))
			{
				if ((Object)(object)item5 == (Object)null || !((Behaviour)item5).isActiveAndEnabled)
				{
					continue;
				}
				hashSet2.Add(((Il2CppObjectBase)item5).Pointer);
				GameplayPlayerIdentity identity = item5.Identity;
				bool flag3 = (Object)(object)identity != (Object)null && hashSet.Contains(((Il2CppObjectBase)identity).Pointer);
				if (flag && !flag2)
				{
					flag3 = true;
					flag2 = true;
				}
				Image val = BadgeIcon(item5);
				if (!((Object)(object)val == (Object)null))
				{
					Show(val, flag3, sprite);
					if (flag3)
					{
						PlaceTeam(((Graphic)val).rectTransform, ((Component)_hud).transform);
					}
				}
			}
			List<IntPtr> list2 = new List<IntPtr>();
			foreach (var (item, val3) in _badgeIcons)
			{
				if (!hashSet2.Contains(item) || (Object)(object)val3 == (Object)null || ((Il2CppObjectBase)val3).WasCollected)
				{
					list2.Add(item);
				}
			}
			foreach (IntPtr item6 in list2)
			{
				_badgeIcons.Remove(item6);
			}
			GameplayPlayerIdentity val4 = null;
			foreach (var item7 in list)
			{
				if (((NetworkBehaviour)item7.Item1).IsOwner)
				{
					(val4, _) = item7;
				}
			}
			bool flag4 = ((Object)(object)val4 != (Object)null && hashSet.Contains(((Il2CppObjectBase)val4).Pointer)) || Time.unscaledTime < _editYouUntil;
			Image val5 = YouIcon();
			if ((Object)(object)val5 != (Object)null)
			{
				Show(val5, flag4, sprite);
				if (flag4)
				{
					PlaceYou(((Graphic)val5).rectTransform, ((Component)_hud).transform);
				}
			}
		}

		private void LogTop(List<(GameplayPlayerIdentity id, float gain)> players, HashSet<IntPtr> top)
		{
			if (players.Count < 2)
			{
				return;
			}
			List<string> list = new List<string>();
			foreach (var player in players)
			{
				string value;
				try
				{
					value = player.id.GetDisplayName();
				}
				catch
				{
					value = "?";
				}
				list.Add($"{value} {player.gain:0}{(top.Contains(((Il2CppObjectBase)player.id).Pointer) ? "*" : "")}");
			}
			string text = string.Join(", ", list);
			if (!(text == _lastSummary))
			{
				_lastSummary = text;
				Log.Msg("Mana Gain: " + text);
			}
		}

		private static float ManaGain(GameplayPlayerIdentity id)
		{
			try
			{
				return id.Stats.GetCharacterValue((StatType)10);
			}
			catch
			{
				return 0f;
			}
		}

		private bool EnsureHud()
		{
			if ((Object)(object)_hud != (Object)null && !((Il2CppObjectBase)_hud).WasCollected && ((Behaviour)_hud).isActiveAndEnabled)
			{
				return true;
			}
			_hud = null;
			if (Time.unscaledTime < _nextHudSearch)
			{
				return false;
			}
			_nextHudSearch = Time.unscaledTime + 1f;
			foreach (SpellSlotsDisplay item in Object.FindObjectsOfType<SpellSlotsDisplay>())
			{
				Canvas componentInParent = ((Component)item).GetComponentInParent<Canvas>();
				_hud = ((componentInParent != null) ? componentInParent.rootCanvas : null);
				if ((Object)(object)_hud != (Object)null)
				{
					break;
				}
			}
			return (Object)(object)_hud != (Object)null;
		}

		private Image BadgeIcon(GameplayPlayerOverviewUI badge)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if (_badgeIcons.TryGetValue(((Il2CppObjectBase)badge).Pointer, out var value) && (Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
			{
				return value;
			}
			Transform val = ((Component)badge).transform.Find("PlayerPortrait_Panel");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			value = MakeIcon(val, TeamCorner);
			_badgeIcons[((Il2CppObjectBase)badge).Pointer] = value;
			return value;
		}

		private Image YouIcon()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_youIcon != (Object)null && !((Il2CppObjectBase)_youIcon).WasCollected)
			{
				return _youIcon;
			}
			Transform val = ((Component)_hud).transform.Find("LevelDisplay_Panel/Bar/Level");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			_youIcon = MakeIcon(val, YouCorner);
			return _youIcon;
		}

		private static void Show(Image icon, bool on, Sprite sprite)
		{
			on &= (Object)(object)sprite != (Object)null;
			if (on && (Object)(object)icon.sprite != (Object)(object)sprite)
			{
				icon.sprite = sprite;
				Shape(icon);
			}
			if (((Component)icon).gameObject.activeSelf != on)
			{
				((Component)icon).gameObject.SetActive(on);
			}
		}

		private void HideAll()
		{
			foreach (Image value in _badgeIcons.Values)
			{
				if ((Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected)
				{
					((Component)value).gameObject.SetActive(false);
				}
			}
			if ((Object)(object)_youIcon != (Object)null && !((Il2CppObjectBase)_youIcon).WasCollected)
			{
				((Component)_youIcon).gameObject.SetActive(false);
			}
		}

		internal static Image MakeIcon(Transform parent, Vector2 corner)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = new GameObject("ManaMagnetIcon").AddComponent<RectTransform>();
			((Transform)val).SetParent(parent, false);
			Vector2 anchorMin = (val.anchorMax = corner);
			val.anchorMin = anchorMin;
			val.pivot = new Vector2(0.5f, 0.5f);
			val.sizeDelta = new Vector2(64f, 64f);
			Image obj = ((Component)val).gameObject.AddComponent<Image>();
			obj.preserveAspect = true;
			((Graphic)obj).raycastTarget = false;
			((Component)val).gameObject.SetActive(false);
			return obj;
		}

		internal static void Shape(Image icon)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: 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_0032: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			Sprite sprite = icon.sprite;
			float num;
			if ((Object)(object)sprite != (Object)null)
			{
				Rect rect = sprite.rect;
				if (((Rect)(ref rect)).height > 0f)
				{
					rect = sprite.rect;
					float width = ((Rect)(ref rect)).width;
					rect = sprite.rect;
					num = width / ((Rect)(ref rect)).height;
					goto IL_0049;
				}
			}
			num = 1f;
			goto IL_0049;
			IL_0049:
			float num2 = num;
			((Graphic)icon).rectTransform.sizeDelta = ((num2 > 1.2f) ? new Vector2(64f * num2, 64f) : new Vector2(64f, 64f));
		}

		internal static void PlaceTeam(RectTransform icon, Transform hudRoot)
		{
			Place(icon, hudRoot, TeamSize.Value, Mathf.Clamp(TeamX.Value, -11f, 414f), Mathf.Clamp(TeamY.Value, -110f, 10f));
		}

		internal static void PlaceYou(RectTransform icon, Transform hudRoot)
		{
			Place(icon, hudRoot, YouSize.Value, YouX.Value, YouY.Value);
		}

		private static void Place(RectTransform icon, Transform hudRoot, float size, float x, float y)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			float num = 1f;
			if ((Object)(object)((Transform)icon).parent != (Object)null && (Object)(object)hudRoot != (Object)null && hudRoot.lossyScale.x > 1E-06f)
			{
				num = ((Transform)icon).parent.lossyScale.x / hudRoot.lossyScale.x;
			}
			if (num < 0.0001f)
			{
				num = 1f;
			}
			((Transform)icon).localScale = new Vector3(size / num, size / num, 1f);
			icon.anchoredPosition = new Vector2(x, y) / num;
		}

		internal static Sprite WantedSprite()
		{
			if ((Object)(object)_wanted != (Object)null && !((Il2CppObjectBase)_wanted).WasCollected)
			{
				_spriteSearchGap = 1f;
				return _wanted;
			}
			_wanted = null;
			if (Time.unscaledTime < _nextSpriteSearch)
			{
				return null;
			}
			_nextSpriteSearch = Time.unscaledTime + _spriteSearchGap;
			_spriteSearchGap = Mathf.Min(_spriteSearchGap * 2f, 30f);
			string[] array = (UseBeast ? BeastSprites : new string[1] { "ui_ping_magnet" });
			Dictionary<string, Sprite> dictionary = new Dictionary<string, Sprite>();
			foreach (Sprite item in Resources.FindObjectsOfTypeAll<Sprite>())
			{
				if ((Object)(object)item != (Object)null && Array.IndexOf(array, ((Object)item).name) >= 0 && !dictionary.ContainsKey(((Object)item).name))
				{
					dictionary[((Object)item).name] = item;
				}
			}
			string[] array2 = array;
			foreach (string text in array2)
			{
				if (dictionary.TryGetValue(text, out var value))
				{
					return _wanted = value;
				}
				if (_hasMenu)
				{
					Sprite val = MenuPage.Recorded(text);
					if (val != null)
					{
						return _wanted = val;
					}
				}
			}
			return null;
		}

		internal static RectTransform LiveTeam()
		{
			_editTeamUntil = Time.unscaledTime + 0.3f;
			ManaGainLeaderMod instance = _instance;
			if (instance == null)
			{
				return null;
			}
			instance.Tick();
			foreach (Image value in instance._badgeIcons.Values)
			{
				if ((Object)(object)value != (Object)null && !((Il2CppObjectBase)value).WasCollected && ((Component)value).gameObject.activeSelf)
				{
					return ((Graphic)value).rectTransform;
				}
			}
			return null;
		}

		internal static RectTransform LiveYou()
		{
			_editYouUntil = Time.unscaledTime + 0.3f;
			ManaGainLeaderMod instance = _instance;
			if (instance == null)
			{
				return null;
			}
			instance.Tick();
			if (!((Object)(object)instance._youIcon != (Object)null) || ((Il2CppObjectBase)instance._youIcon).WasCollected || !((Component)instance._youIcon).gameObject.activeSelf)
			{
				return null;
			}
			return ((Graphic)instance._youIcon).rectTransform;
		}
	}
	internal static class MenuPage
	{
		private const string Indent = "      ";

		private const string BadgePath = "PartyInfo_Panel/Content/GameplayPlayerOverviewUI(Clone)/PlayerPortrait_Panel";

		private static Transform _hudArea;

		private static readonly HudElement TeamElement = new HudElement
		{
			Name = "Mana Gain Leader: Teammates",
			Build = delegate(RectTransform parent)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				_hudArea = (Transform)(object)parent;
				return Preview("PartyInfo_Panel/Content/GameplayPlayerOverviewUI(Clone)/PlayerPortrait_Panel", ManaGainLeaderMod.TeamCorner, ManaGainLeaderMod.PlaceTeam, parent);
			},
			Place = delegate(RectTransform root)
			{
				ManaGainLeaderMod.PlaceTeam(root, _hudArea);
			},
			Live = ManaGainLeaderMod.LiveTeam,
			GetOffset = () => new Vector2(ManaGainLeaderMod.TeamX.Value, ManaGainLeaderMod.TeamY.Value),
			SetOffset = delegate(Vector2 v)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				ManaGainLeaderMod.TeamX.Value = Mathf.Clamp(Mathf.Round(v.x), -11f, 414f);
				ManaGainLeaderMod.TeamY.Value = Mathf.Clamp(Mathf.Round(v.y), -110f, 10f);
			},
			GetSize = () => ManaGainLeaderMod.TeamSize.Value,
			SetSize = delegate(float s)
			{
				ManaGainLeaderMod.TeamSize.Value = Mathf.Clamp(s, 0.5f, 1.8f);
			},
			Reset = delegate
			{
				ManaGainLeaderMod.TeamX.Value = 8f;
				ManaGainLeaderMod.TeamY.Value = -8f;
				ManaGainLeaderMod.TeamSize.Value = 1.3f;
			}
		};

		private static readonly HudElement YouElement = new HudElement
		{
			Name = "Mana Gain Leader: You",
			Build = delegate(RectTransform parent)
			{
				//IL_000b: Unknown result type (might be due to invalid IL or missing references)
				_hudArea = (Transform)(object)parent;
				return Preview("LevelDisplay_Panel/Bar/Level", ManaGainLeaderMod.YouCorner, ManaGainLeaderMod.PlaceYou, parent);
			},
			Place = delegate(RectTransform root)
			{
				ManaGainLeaderMod.PlaceYou(root, _hudArea);
			},
			Live = ManaGainLeaderMod.LiveYou,
			GetOffset = () => new Vector2(ManaGainLeaderMod.YouX.Value, ManaGainLeaderMod.YouY.Value),
			SetOffset = delegate(Vector2 v)
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				ManaGainLeaderMod.YouX.Value = Mathf.Clamp(Mathf.Round(v.x), -1000f, 4000f);
				ManaGainLeaderMod.YouY.Value = Mathf.Clamp(Mathf.Round(v.y), -1000f, 2000f);
			},
			GetSize = () => ManaGainLeaderMod.YouSize.Value,
			SetSize = delegate(float s)
			{
				ManaGainLeaderMod.YouSize.Value = Mathf.Clamp(s, 0.5f, 3f);
			},
			Reset = delegate
			{
				ManaGainLeaderMod.YouX.Value = 0f;
				ManaGainLeaderMod.YouY.Value = 0f;
				ManaGainLeaderMod.YouSize.Value = 2f;
			}
		};

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static void Register()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			List<string> list = new List<string>();
			list.Add("ui_ping_magnet");
			list.AddRange(ManaGainLeaderMod.BeastSprites);
			HudEditor.RecordSprites(list.ToArray());
			HudEditor.Register(TeamElement);
			HudEditor.Register(YouElement);
			Menu.AddPage("ManaGainLeader", "Mana Gain Leader").Entry(ManaGainLeaderMod.Enabled, () => "Show Mana Gain Leader").Choice("Icon", (IList<string>)ManaGainLeaderMod.IconChoices, (Func<int>)(() => Math.Max(0, Array.IndexOf(ManaGainLeaderMod.IconChoices, ManaGainLeaderMod.Icon.Value))), (Action<int>)delegate(int i)
			{
				ManaGainLeaderMod.Icon.Value = ManaGainLeaderMod.IconChoices[i];
				ManaGainLeaderMod.Icon.Category.SaveToFile(printmsg: false);
			}, (int?)0)
				.Note((Func<string>)(() => "Marks the player with the most Mana Gain. Mana Gain counts when mana is collected: the collector's Mana Gain multiplies every orb, and a magnet pulls all orbs to whoever takes it. So the marked player should take the mana and the magnets."))
				.Buttons((MenuButton[])(object)new MenuButton[1]
				{
					new MenuButton("Edit Position & Size", (Action)delegate
					{
						HudEditor.Open(TeamElement);
					}, false)
				})
				.Header((Func<string>)(() => "On a Teammate's Badge"))
				.Note((Func<string>)(() => "One place for every teammate: from the corner of their picture, on their own badge."))
				.Entry(ManaGainLeaderMod.TeamSize, () => "      Size")
				.Entry(ManaGainLeaderMod.TeamX, () => "      Move Left / Right")
				.Entry(ManaGainLeaderMod.TeamY, () => "      Move Up / Down")
				.Header((Func<string>)(() => "By Your Level"))
				.Entry(ManaGainLeaderMod.YouSize, () => "      Size")
				.Entry(ManaGainLeaderMod.YouX, () => "      Move Left / Right")
				.Entry(ManaGainLeaderMod.YouY, () => "      Move Up / Down");
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		internal static Sprite Recorded(string name)
		{
			return HudEditor.Sprite(name);
		}

		private static RectTransform Preview(string path, Vector2 corner, Action<RectTransform, Transform> place, RectTransform hudArea)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = HudEditor.Recorded(path);
			Sprite val2 = ManaGainLeaderMod.WantedSprite();
			if ((Object)(object)val == (Object)null || (Object)(object)val2 == (Object)null)
			{
				return null;
			}
			Image val3 = ManaGainLeaderMod.MakeIcon((Transform)(object)val, corner);
			val3.sprite = val2;
			ManaGainLeaderMod.Shape(val3);
			((Component)val3).gameObject.SetActive(true);
			place(((Graphic)val3).rectTransform, (Transform)(object)hudArea);
			return ((Graphic)val3).rectTransform;
		}
	}
}
namespace ManaGainLeader.BepInExPlugin
{
	[BepInPlugin("SpellBrigade.ManaGainLeader", "Mana Gain Leader", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BasePlugin
	{
		public const string Guid = "SpellBrigade.ManaGainLeader";

		public override void Load()
		{
			MelonCompat.Start<ManaGainLeaderMod, Runner>((BasePlugin)(object)this, "SpellBrigade.ManaGainLeader");
		}
	}
	public class Runner : MonoBehaviour
	{
		public Runner(IntPtr ptr)
			: base(ptr)
		{
		}

		private void Update()
		{
			MelonCompat.Update();
		}
	}
}
namespace MelonLoader
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonInfoAttribute : Attribute
	{
		public MelonInfoAttribute(Type type, string name, string version, string author, string downloadLink = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	public sealed class MelonGameAttribute : Attribute
	{
		public MelonGameAttribute(string developer = null, string name = null)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Assembly)]
	public sealed class MelonOptionalDependenciesAttribute : Attribute
	{
		public MelonOptionalDependenciesAttribute(params string[] names)
		{
		}
	}
	public abstract class MelonBase
	{
		public MelonLogger.Instance LoggerInstance { get; internal set; }

		public Harmony HarmonyInstance { get; internal set; }

		public static object FindMelon(string name, string author)
		{
			try
			{
				foreach (PluginInfo value in ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.Values)
				{
					if (((value != null) ? value.Metadata : null) != null && string.Equals(value.Metadata.Name, name, StringComparison.OrdinalIgnoreCase) && value.Instance != null)
					{
						return value;
					}
				}
			}
			catch
			{
			}
			return null;
		}
	}
	public abstract class MelonMod : MelonBase
	{
		public virtual void OnInitializeMelon()
		{
		}

		public virtual void OnLateInitializeMelon()
		{
		}

		public virtual void OnUpdate()
		{
		}

		public virtual void OnLateUpdate()
		{
		}

		public virtual void OnFixedUpdate()
		{
		}

		public virtual void OnGUI()
		{
		}

		public virtual void OnApplicationQuit()
		{
		}

		public virtual void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasInitialized(int buildIndex, string sceneName)
		{
		}

		public virtual void OnSceneWasUnloaded(int buildIndex, string sceneName)
		{
		}
	}
	public static class MelonLogger
	{
		public sealed class Instance
		{
			private readonly ManualLogSource _log;

			public Instance(ManualLogSource log)
			{
				_log = log;
			}

			public void Msg(string text)
			{
				_log.LogInfo((object)text);
			}

			public void Msg(object value)
			{
				_log.LogInfo(value);
			}

			public void Msg(string format, params object[] args)
			{
				_log.LogInfo((object)string.Format(format, args));
			}

			public void Warning(string text)
			{
				_log.LogWarning((object)text);
			}

			public void Warning(object value)
			{
				_log.LogWarning(value);
			}

			public void Error(string text)
			{
				_log.LogError((object)text);
			}

			public void Error(object value)
			{
				_log.LogError(value);
			}

			public void Error(string text, Exception e)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Expected O, but got Unknown
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(1, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\n");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(e);
				}
				log.LogError(val);
			}
		}
	}
	public static class MelonCompat
	{
		internal static ConfigFile Config;

		private static MelonMod _mod;

		private static bool _lateInit;

		public static void Start<TMod, TRunner>(BasePlugin plugin, string harmonyId) where TMod : MelonMod, new() where TRunner : MonoBehaviour
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Expected O, but got Unknown
			Config = plugin.Config;
			_mod = new TMod
			{
				LoggerInstance = new MelonLogger.Instance(plugin.Log),
				HarmonyInstance = new Harmony(harmonyId)
			};
			try
			{
				_mod.HarmonyInstance.PatchAll(typeof(TMod).Assembly);
			}
			catch (Exception ex)
			{
				ManualLogSource log = plugin.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Harmony patches: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_mod.OnInitializeMelon();
			HookScenes();
			ClassInjector.RegisterTypeInIl2Cpp<TRunner>();
			plugin.AddComponent<TRunner>();
		}

		private static void HookScenes()
		{
			SceneManager.sceneLoaded += DelegateSupport.ConvertDelegate<UnityAction<Scene, LoadSceneMode>>((Delegate)new Action<Scene, LoadSceneMode>(OnSceneLoaded));
			SceneManager.sceneUnloaded += DelegateSupport.ConvertDelegate<UnityAction<Scene>>((Delegate)new Action<Scene>(OnSceneUnloaded));
		}

		private static void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasLoaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
			Guard(delegate
			{
				_mod.OnSceneWasInitialized(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		private static void OnSceneUnloaded(Scene scene)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			Guard(delegate
			{
				_mod.OnSceneWasUnloaded(((Scene)(ref scene)).buildIndex, ((Scene)(ref scene)).name);
			});
		}

		public static void Update()
		{
			if (_mod != null)
			{
				if (!_lateInit)
				{
					_lateInit = true;
					Guard(_mod.OnLateInitializeMelon);
				}
				_mod.OnUpdate();
			}
		}

		public static void LateUpdate()
		{
			_mod?.OnLateUpdate();
		}

		public static void FixedUpdate()
		{
			_mod?.OnFixedUpdate();
		}

		public static void OnGUI()
		{
			_mod?.OnGUI();
		}

		public static void Quit()
		{
			_mod?.OnApplicationQuit();
		}

		private static void Guard(Action a)
		{
			try
			{
				a();
			}
			catch (Exception ex)
			{
				_mod.LoggerInstance.Error(ex.ToString());
			}
		}
	}
	public static class MelonPreferences
	{
		private static readonly Dictionary<string, MelonPreferences_Category> Categories = new Dictionary<string, MelonPreferences_Category>();

		public static MelonPreferences_Category CreateCategory(string identifier, string displayName = null, bool is_hidden = false, bool is_inlined = false)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				value = (Categories[identifier] = new MelonPreferences_Category(identifier, displayName ?? identifier)
				{
					IsHidden = is_hidden
				});
			}
			return value;
		}

		public static MelonPreferences_Category GetCategory(string identifier)
		{
			if (!Categories.TryGetValue(identifier, out var value))
			{
				return null;
			}
			return value;
		}

		public static void Save()
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}
	}
	public sealed class MelonPreferences_Category
	{
		public readonly List<MelonPreferences_Entry> Entries = new List<MelonPreferences_Entry>();

		public string Identifier { get; }

		public string DisplayName { get; }

		public bool IsHidden { get; internal set; }

		internal MelonPreferences_Category(string identifier, string displayName)
		{
			Identifier = identifier;
			DisplayName = displayName;
		}

		public MelonPreferences_Entry<T> CreateEntry<T>(string identifier, T default_value, string display_name = null, string description = null, bool is_hidden = false, bool dont_save_default = false, ValueValidator validator = null, string oldIdentifier = null)
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Expected O, but got Unknown
			ConfigurationManagerAttributes configurationManagerAttributes = new ConfigurationManagerAttributes
			{
				DispName = (display_name ?? identifier),
				Browsable = (!is_hidden && !IsHidden),
				Order = -Entries.Count,
				Category = DisplayName
			};
			AcceptableValueBase val = validator?.ToAcceptable(typeof(T));
			ConfigEntry<T> cfg = MelonCompat.Config.Bind<T>(Identifier, identifier, default_value, new ConfigDescription(description ?? "", val, new object[1] { configurationManagerAttributes }));
			MelonPreferences_Entry<T> melonPreferences_Entry = new MelonPreferences_Entry<T>(this, cfg, identifier, display_name ?? identifier, description, is_hidden);
			Entries.Add(melonPreferences_Entry);
			return melonPreferences_Entry;
		}

		public MelonPreferences_Entry GetEntry(string identifier)
		{
			return Entries.Find((MelonPreferences_Entry e) => e.Identifier == identifier);
		}

		public MelonPreferences_Entry<T> GetEntry<T>(string identifier)
		{
			return GetEntry(identifier) as MelonPreferences_Entry<T>;
		}

		public bool HasEntry(string identifier)
		{
			return GetEntry(identifier) != null;
		}

		public void SaveToFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Save();
			}
		}

		public void LoadFromFile(bool printmsg = true)
		{
			ConfigFile config = MelonCompat.Config;
			if (config != null)
			{
				config.Reload();
			}
		}
	}
	public abstract class MelonPreferences_Entry
	{
		public readonly MelonEvent<object, object> OnEntryValueChangedUntyped = new MelonEvent<object, object>();

		public MelonPreferences_Category Category { get; protected set; }

		public string Identifier { get; protected set; }

		public string DisplayName { get; protected set; }

		public string Description { get; protected set; }

		public bool IsHidden { get; protected set; }

		public abstract ConfigEntryBase Raw { get; }

		public abstract object BoxedValue { get; set; }

		public abstract void ResetToDefault();
	}
	public sealed class MelonPreferences_Entry<T> : MelonPreferences_Entry
	{
		private readonly ConfigEntry<T> _cfg;

		private T _last;

		public readonly MelonEvent<T, T> OnEntryValueChanged = new MelonEvent<T, T>();

		public readonly MelonEvent<T, T> OnValueChanged;

		public T Value
		{
			get
			{
				return _cfg.Value;
			}
			set
			{
				_cfg.Value = value;
			}
		}

		public T DefaultValue => (T)((ConfigEntryBase)_cfg).DefaultValue;

		public override ConfigEntryBase Raw => (ConfigEntryBase)(object)_cfg;

		public override object BoxedValue
		{
			get
			{
				return ((ConfigEntryBase)_cfg).BoxedValue;
			}
			set
			{
				((ConfigEntryBase)_cfg).BoxedValue = value;
			}
		}

		internal MelonPreferences_Entry(MelonPreferences_Category category, ConfigEntry<T> cfg, string identifier, string displayName, string description, bool hidden)
		{
			base.Category = category;
			_cfg = cfg;
			base.Identifier = identifier;
			base.DisplayName = displayName;
			base.Description = description;
			base.IsHidden = hidden;
			OnValueChanged = OnEntryValueChanged;
			_last = cfg.Value;
			cfg.SettingChanged += OnSettingChanged;
		}

		private void OnSettingChanged(object sender, EventArgs e)
		{
			T last = _last;
			_last = _cfg.Value;
			if (!EqualityComparer<T>.Default.Equals(last, _last))
			{
				OnEntryValueChanged.Invoke(last, _last);
				OnEntryValueChangedUntyped.Invoke(last, _last);
			}
		}

		public override void ResetToDefault()
		{
			_cfg.Value = DefaultValue;
		}
	}
	public sealed class MelonEvent<T1, T2>
	{
		private readonly List<Action<T1, T2>> _handlers = new List<Action<T1, T2>>();

		public void Subscribe(Action<T1, T2> handler, int priority = 0, bool unsubscribeOnFirstInvocation = false)
		{
			_handlers.Add(handler);
		}

		public void Unsubscribe(Action<T1, T2> handler)
		{
			_handlers.Remove(handler);
		}

		internal void Invoke(T1 a, T2 b)
		{
			Action<T1, T2>[] array = _handlers.ToArray();
			foreach (Action<T1, T2> action in array)
			{
				try
				{
					action(a, b);
				}
				catch (Exception ex)
				{
					Debug.LogError(Object.op_Implicit(ex.ToString()));
				}
			}
		}
	}
	public sealed class ConfigurationManagerAttributes
	{
		public string DispName;

		public bool? Browsable;

		public int? Order;

		public string Category;
	}
}
namespace MelonLoader.Preferences
{
	public abstract class ValueValidator
	{
		public abstract AcceptableValueBase ToAcceptable(Type type);
	}
	public sealed class ValueRange<T> : ValueValidator where T : IComparable
	{
		public T MinValue { get; }

		public T MaxValue { get; }

		public ValueRange(T min, T max)
		{
			MinValue = min;
			MaxValue = max;
		}

		public override AcceptableValueBase ToAcceptable(Type type)
		{
			if (!(type == typeof(T)))
			{
				return null;
			}
			return (AcceptableValueBase)(object)new AcceptableValueRange<T>(MinValue, MaxValue);
		}
	}
}
namespace Il2CppTMPro
{
	internal static class NamespaceStandIn
	{
	}
}
namespace Il2Cpp
{
	internal static class NamespaceStandIn
	{
	}
}