Decompiled source of MultiAbilitySlots v2.1.0

MultiAbilitySlots.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BoplFixedMath;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Steamworks;
using Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MultiAbilitySlots
{
	internal static class Diagnostics
	{
		private static string OutPath(string file)
		{
			return Path.Combine(Paths.BepInExRootPath, file);
		}

		private static Type[] SafeTypes(Assembly asm)
		{
			try
			{
				return asm.GetTypes();
			}
			catch (ReflectionTypeLoadException ex)
			{
				List<Type> list = new List<Type>();
				Type[] types = ex.Types;
				foreach (Type type in types)
				{
					if (type != null)
					{
						list.Add(type);
					}
				}
				return list.ToArray();
			}
		}

		private static string Describe(MemberInfo m)
		{
			FieldInfo fieldInfo = m as FieldInfo;
			if (fieldInfo != null)
			{
				return "  field  " + fieldInfo.FieldType.Name + " " + fieldInfo.Name + (fieldInfo.IsStatic ? " [static]" : "");
			}
			MethodInfo methodInfo = m as MethodInfo;
			if (methodInfo != null)
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append("  method ").Append(methodInfo.ReturnType.Name).Append(' ')
					.Append(methodInfo.Name)
					.Append('(');
				ParameterInfo[] parameters = methodInfo.GetParameters();
				for (int i = 0; i < parameters.Length; i++)
				{
					if (i > 0)
					{
						stringBuilder.Append(", ");
					}
					stringBuilder.Append(parameters[i].ParameterType.Name).Append(' ').Append(parameters[i].Name);
				}
				stringBuilder.Append(')');
				if (methodInfo.IsStatic)
				{
					stringBuilder.Append(" [static]");
				}
				return stringBuilder.ToString();
			}
			PropertyInfo propertyInfo = m as PropertyInfo;
			if (propertyInfo != null)
			{
				return "  prop   " + propertyInfo.PropertyType.Name + " " + propertyInfo.Name;
			}
			return "  " + m.MemberType.ToString() + " " + m.Name;
		}

		private static bool Interesting(string name)
		{
			string text = name.ToLowerInvariant();
			if (!text.Contains("setting") && !text.Contains("numberofability") && !text.Contains("numabilit") && !text.Contains("abilitycount") && !text.Contains("optionsmenu"))
			{
				return text.Contains("abilitiesperplayer");
			}
			return true;
		}

		internal static void DumpTypes()
		{
			Assembly assembly = typeof(SlimeController).Assembly;
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.AppendLine("Multi Ability Slots - type dump of " + assembly.GetName().Name);
			stringBuilder.AppendLine();
			BindingFlags bindingAttr = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic;
			Type[] array = SafeTypes(assembly);
			foreach (Type type in array)
			{
				bool flag = Interesting(type.Name);
				List<string> list = new List<string>();
				try
				{
					MemberInfo[] members = type.GetMembers(bindingAttr);
					foreach (MemberInfo memberInfo in members)
					{
						if (flag || Interesting(memberInfo.Name))
						{
							list.Add(Describe(memberInfo));
						}
					}
				}
				catch
				{
				}
				if (!flag && list.Count <= 0)
				{
					continue;
				}
				stringBuilder.AppendLine((type.IsClass ? "class " : "type ") + type.FullName + " : " + ((type.BaseType != null) ? type.BaseType.Name : ""));
				foreach (string item in list)
				{
					stringBuilder.AppendLine(item);
				}
				stringBuilder.AppendLine();
			}
			File.WriteAllText(OutPath("MultiAbilitySlots-types.txt"), stringBuilder.ToString());
			Rt.Log.LogInfo((object)("Wrote " + OutPath("MultiAbilitySlots-types.txt")));
		}

		private static string PathOf(Transform t)
		{
			StringBuilder stringBuilder = new StringBuilder(((Object)t).name);
			while ((Object)(object)t.parent != (Object)null)
			{
				t = t.parent;
				stringBuilder.Insert(0, ((Object)t).name + "/");
			}
			return stringBuilder.ToString();
		}

		internal static void DumpUi()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			StringBuilder stringBuilder = new StringBuilder();
			Scene activeScene = SceneManager.GetActiveScene();
			stringBuilder.AppendLine("Multi Ability Slots - UI dump (scene: " + ((Scene)(ref activeScene)).name + ")");
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("== TEXT ==");
			TMP_Text[] array = Object.FindObjectsOfType<TMP_Text>();
			foreach (TMP_Text val in array)
			{
				if ((Object)(object)val != (Object)null && ((Component)val).gameObject.activeInHierarchy)
				{
					stringBuilder.AppendLine(PathOf(val.transform) + "  =>  \"" + val.text + "\"");
				}
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("== INTERACTIVE ==");
			Selectable[] array2 = Object.FindObjectsOfType<Selectable>();
			foreach (Selectable val2 in array2)
			{
				if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeInHierarchy)
				{
					stringBuilder.AppendLine(PathOf(((Component)val2).transform) + "  [" + ((object)val2).GetType().Name + "]");
				}
			}
			stringBuilder.AppendLine();
			stringBuilder.AppendLine("== ALL ACTIVE MONOBEHAVIOURS (game types only) ==");
			HashSet<string> hashSet = new HashSet<string>();
			Assembly assembly = typeof(SlimeController).Assembly;
			MonoBehaviour[] array3 = Object.FindObjectsOfType<MonoBehaviour>();
			foreach (MonoBehaviour val3 in array3)
			{
				if ((Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeInHierarchy && ((object)val3).GetType().Assembly == assembly)
				{
					string text = ((object)val3).GetType().Name + "  @ " + PathOf(((Component)val3).transform);
					if (hashSet.Add(text))
					{
						stringBuilder.AppendLine(text);
					}
				}
			}
			File.WriteAllText(OutPath("MultiAbilitySlots-ui.txt"), stringBuilder.ToString());
			Rt.Log.LogInfo((object)("Wrote " + OutPath("MultiAbilitySlots-ui.txt")));
		}
	}
	[HarmonyPatch(typeof(KeyBindButton), "Awake")]
	internal static class KeyBindAwakePatch
	{
		private static void Prefix(KeyBindButton __instance)
		{
			Rt.PrepareKeyBindMenu(__instance);
		}

		private static void Postfix(KeyBindButton __instance)
		{
			Rt.FinishKeyBindMenu(__instance);
		}
	}
	[HarmonyPatch(typeof(KeyBindButton), "SetToPlayerChoices")]
	internal static class KeyBindPlayerChoicesPatch
	{
		internal sealed class BindingState
		{
			internal Player Player;

			internal InputControl[] Canonical;
		}

		private static void Prefix(KeyBindButton __instance, Player player, ref BindingState __state)
		{
			Rt.EnsureExtraBindings(player);
			int num = Rt.ExtraRowsInMenu(__instance);
			if (player != null && num > 0)
			{
				__state = new BindingState
				{
					Player = player,
					Canonical = player.CustomKeyBinding
				};
				player.CustomKeyBinding = Rt.ToBindingMenuOrder(player, num);
			}
		}

		private static void Postfix(BindingState __state)
		{
			if (__state != null && __state.Player != null)
			{
				__state.Player.CustomKeyBinding = __state.Canonical;
			}
		}

		private static Exception Finalizer(Exception __exception, BindingState __state)
		{
			if (__state != null && __state.Player != null)
			{
				__state.Player.CustomKeyBinding = __state.Canonical;
			}
			return __exception;
		}
	}
	[HarmonyPatch(typeof(KeyBindButton), "UpdateKeybind")]
	internal static class KeyBindUpdatePatch
	{
		private static bool Prefix(KeyBindButton __instance)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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)
			CharacterSelectBox field = Rt.GetField<CharacterSelectBox>(__instance, "charSelectBox");
			if ((Object)(object)field == (Object)null)
			{
				return true;
			}
			bool field2 = Rt.GetField<bool>(field, "UseskeyboardMouse");
			InputControl[] field3 = Rt.GetField<InputControl[]>(__instance, field2 ? "newBinding_keyboardMouse" : "newBinding_gamepad");
			if (field3 == null || field3.Length <= 8)
			{
				return true;
			}
			int num = field3.Length - 8;
			int boxKey = Rt.GetBoxKey(field);
			if (boxKey != int.MinValue)
			{
				if (!Rt.ExtraBindings.TryGetValue(boxKey, out var value) || value == null || value.Length < 6)
				{
					value = Rt.Resize(value, 6);
					Rt.ExtraBindings[boxKey] = value;
				}
				for (int i = 0; i < num && i < value.Length; i++)
				{
					value[i] = field3[i];
				}
			}
			PlayerInit field4 = Rt.GetField<PlayerInit>(field, "playerInit");
			field4.keybindOverride = Rt.ToVanillaBindingOrder(field3, num);
			Rt.SetField(field, "playerInit", field4);
			return false;
		}
	}
	[HarmonyPatch(typeof(SlimeController), "AddAdditionalAbility")]
	internal static class AbilityPickupPatch
	{
		private static void Prefix(SlimeController __instance, ref Rt.PickupState __state)
		{
			__state = Rt.BeginVanillaPickup(__instance);
		}

		private static void Postfix(SlimeController __instance, Rt.PickupState __state)
		{
			Rt.EndVanillaPickup(__instance, __state);
		}

		private static Exception Finalizer(SlimeController __instance, Exception __exception, Rt.PickupState __state)
		{
			Rt.EndVanillaPickup(__instance, __state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(PlayerCollision), "SpawnClone")]
	internal static class SpawnClonePatch
	{
		internal sealed class CloneState
		{
			internal SlimeController Source;

			internal List<AbilityMonoBehaviour> Abilities;

			internal AbilityReadyIndicator[] Indicators;
		}

		private static void Prefix(SlimeController slimeContToRevive, ref CloneState __state)
		{
			if ((Object)(object)slimeContToRevive == (Object)null)
			{
				return;
			}
			List<AbilityMonoBehaviour> field = Rt.GetField<List<AbilityMonoBehaviour>>(slimeContToRevive, "abilities");
			AbilityReadyIndicator[] field2 = Rt.GetField<AbilityReadyIndicator[]>(slimeContToRevive, "AbilityReadyIndicators");
			if (field != null && field.Count > 3 && field2 != null && field2.Length >= field.Count)
			{
				__state = new CloneState
				{
					Source = slimeContToRevive,
					Abilities = field,
					Indicators = field2
				};
				List<AbilityMonoBehaviour> list = new List<AbilityMonoBehaviour>();
				AbilityReadyIndicator[] array = (AbilityReadyIndicator[])(object)new AbilityReadyIndicator[3];
				for (int i = 0; i < 3; i++)
				{
					list.Add(field[i]);
					array[i] = field2[i];
				}
				Rt.SetField(slimeContToRevive, "abilities", list);
				Rt.SetField(slimeContToRevive, "AbilityReadyIndicators", array);
			}
		}

		private static void Postfix(Player player, SlimeController slimeContToRevive, ref SlimeController __result, CloneState __state)
		{
			if (__state != null)
			{
				Rt.SetField(slimeContToRevive, "abilities", __state.Abilities);
				Rt.SetField(slimeContToRevive, "AbilityReadyIndicators", __state.Indicators);
				if ((Object)(object)__result != (Object)null)
				{
					int extraCount = __state.Abilities.Count - 3;
					Rt.AddExtrasToClone(__result, __state.Source, player, __state.Indicators, extraCount);
				}
			}
		}

		private static Exception Finalizer(SlimeController slimeContToRevive, Exception __exception, CloneState __state)
		{
			if (__state != null && (Object)(object)slimeContToRevive != (Object)null)
			{
				Rt.SetField(slimeContToRevive, "abilities", __state.Abilities);
				Rt.SetField(slimeContToRevive, "AbilityReadyIndicators", __state.Indicators);
			}
			return __exception;
		}
	}
	[HarmonyPatch(typeof(CharacterSelectBox), "Awake")]
	internal static class CharacterSelectAwakePatch
	{
		private static void Postfix(CharacterSelectBox __instance)
		{
			Rt.BuildBox(__instance, Rt.Effective());
		}
	}
	[HarmonyPatch(typeof(CharacterSelectBox), "UpdatePlayerInit")]
	internal static class CharacterSelectSavePatch
	{
		private static void Postfix(CharacterSelectBox __instance)
		{
			Rt.SaveChoice(__instance);
		}
	}
	[HarmonyPatch(typeof(SelectAbility), "Select")]
	internal static class ExtraSelectPatch
	{
		private static void Postfix(SelectAbility __instance)
		{
			if (Rt.BoxesBySlot.TryGetValue(((Object)__instance).GetInstanceID(), out var value) && value != null)
			{
				Rt.SaveChoice(value.Box);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterSelectBox), "LateUpdate")]
	internal static class CharacterSelectLateUpdatePatch
	{
		private static bool Prefix(CharacterSelectBox __instance)
		{
			object field = Rt.GetField<object>(__instance, "menuState");
			if (field == null || Convert.ToInt32(field) != 1)
			{
				return true;
			}
			if (!Rt.SlotsByBox.TryGetValue(((Object)__instance).GetInstanceID(), out var value) || value == null)
			{
				return true;
			}
			List<SelectableMonoBehaviour> field2 = Rt.GetField<List<SelectableMonoBehaviour>>(__instance, "selectables");
			int field3 = Rt.GetField<int>(__instance, "selectedIndex");
			if (!Rt.IsExtraIndex(value, field2, field3))
			{
				return true;
			}
			bool flag;
			if (Rt.GetField<bool>(__instance, "UseskeyboardMouse"))
			{
				Keyboard current = Keyboard.current;
				flag = current != null && ((ButtonControl)current.enterKey).wasPressedThisFrame;
			}
			else
			{
				Gamepad field4 = Rt.GetField<Gamepad>(__instance, "currentGamePad");
				flag = field4 != null && field4.aButton.wasPressedThisFrame;
			}
			if (!flag)
			{
				return true;
			}
			Rt.SaveChoice(__instance);
			__instance.EnterAbilityGrid();
			return false;
		}

		private static void Postfix(CharacterSelectBox __instance)
		{
			Rt.MaintainExtraSlots(__instance);
		}
	}
	[HarmonyPatch(typeof(CharacterSelectBox), "SetSelected")]
	internal static class CharacterSelectArrowPatch
	{
		private static void Postfix(CharacterSelectBox __instance, int __0)
		{
			Rt.FixCharacterArrow(__instance, __0);
		}
	}
	[HarmonyPatch(typeof(MidGameAbilitySelect), "SetPlayer")]
	internal static class MidGameSetPlayerPatch
	{
		private static void Prefix(MidGameAbilitySelect __instance, ref MidGameState __state)
		{
			Rt.BeforeMidGameSetPlayer(__instance, ref __state);
		}

		private static void Postfix(MidGameAbilitySelect __instance, MidGameState __state)
		{
			Rt.RestoreMidGameSetPlayer(__instance, __state);
			Rt.SetupMidGameSelector(__instance);
		}

		private static Exception Finalizer(MidGameAbilitySelect __instance, Exception __exception, MidGameState __state)
		{
			Rt.RestoreMidGameSetPlayer(__instance, __state);
			return __exception;
		}
	}
	[HarmonyPatch(typeof(MidGameAbilitySelect), "Down")]
	internal static class MidGameDownPatch
	{
		private static bool Prefix(MidGameAbilitySelect __instance)
		{
			return !Rt.MoveMidGameRow(__instance, 1);
		}
	}
	[HarmonyPatch(typeof(MidGameAbilitySelect), "Up")]
	internal static class MidGameUpPatch
	{
		private static bool Prefix(MidGameAbilitySelect __instance)
		{
			return !Rt.MoveMidGameRow(__instance, -1);
		}
	}
	[HarmonyPatch(typeof(MidGameAbilitySelect), "UpdatePlayerAbilityChoices")]
	internal static class MidGameChoicePatch
	{
		private static void Postfix(MidGameAbilitySelect __instance)
		{
			Rt.SaveMidGameChoice(__instance);
		}
	}
	[HarmonyPatch(typeof(AbilitySelectController), "UpdateAnimation")]
	internal static class AbilitySelectAnimationPatch
	{
		private static void Prefix(AbilitySelectController __instance)
		{
			Rt.EnsureAbilitySelectAnimationTargets(__instance);
		}

		[HarmonyPriority(0)]
		private static void Postfix(AbilitySelectController __instance)
		{
			Rt.LiftOpenLossAbilityCircles(__instance);
			Rt.LiftOpenLossSelectorArrow(__instance);
		}
	}
	[HarmonyPatch(typeof(Player), "AbilityButtonIsDown")]
	internal static class ExtraAbilityInputPatch
	{
		private static bool Prefix(Player __instance, int index012, ref bool __result)
		{
			if (index012 < 3)
			{
				return true;
			}
			__result = Rt.ExtraInputHeld(__instance, index012 - 3);
			return false;
		}
	}
	[HarmonyPatch(typeof(Host), "CurrentInputAsPacket")]
	internal static class ExtraAbilityPacketPatch
	{
		private static void Postfix(int __0, ref InputPacket __result)
		{
			Rt.PutExtraInputInPacket(__0, ref __result);
		}
	}
	[HarmonyPatch(typeof(GameSessionHandler), "SpawnPlayers")]
	internal static class SpawnPlayersPatch
	{
		private static void Prefix()
		{
			PlayerHandler val = PlayerHandler.Get();
			if (val != null)
			{
				Rt.AddExtrasToPlayers(val.PlayerList());
			}
		}

		private static void Postfix(GameSessionHandler __instance)
		{
			Rt.FinishSpawn(__instance);
		}
	}
	[HarmonyPatch(typeof(SlimeController), "Init")]
	internal static class SlimeInitPatch
	{
		private static void Postfix(SlimeController __instance)
		{
			List<AbilityMonoBehaviour> field = Rt.GetField<List<AbilityMonoBehaviour>>(__instance, "abilities");
			if (field != null && field.Count > 3)
			{
				Rt.EnsureCooldownArray(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(SteamSocket), "OnMessage")]
	internal static class NetworkReceivePatch
	{
		private static bool Prefix(NetIdentity identity, IntPtr data, int size)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			if (size < 5 || data == IntPtr.Zero)
			{
				return true;
			}
			byte[] array = new byte[size];
			Marshal.Copy(data, array, 0, size);
			if (!Rt.IsOurPacket(array))
			{
				return true;
			}
			Rt.ReceivePacket(array, identity);
			return false;
		}
	}
	internal static class Cfg
	{
		internal const int MaxExtra = 6;

		internal static ConfigEntry<int> Extra;

		internal static ConfigEntry<int> HudColumns;

		internal static ConfigEntry<float> HudSpacing;

		internal static ConfigEntry<bool> ShowCountButton;
	}
	[BepInPlugin("com.multiabilityslots.boplbattle", "Multi Ability Slots", "2.1.0")]
	public sealed class MultiAbilityPlugin : BaseUnityPlugin
	{
		internal const string PluginGuid = "com.multiabilityslots.boplbattle";

		internal const string PluginVersion = "2.1.0";

		private float toastUntil;

		private string toastText = "";

		private bool showPanel = true;

		private bool inGameplay;

		private float nextGameplayCheck;

		private bool loggedUpdate;

		private bool loggedGui;

		private void Awake()
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Rt.Log = ((BaseUnityPlugin)this).Logger;
			Cfg.Extra = ((BaseUnityPlugin)this).Config.Bind<int>("General", "ExtraAbilities", 4, new ConfigDescription("How many abilities to add on top of the vanilla three (1 to " + 6 + "). You can also change this in-game with the on-screen panel or F7 / F8. Online matches are always limited to 1 extra ability.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 6), Array.Empty<object>()));
			Cfg.HudColumns = ((BaseUnityPlugin)this).Config.Bind<int>("HUD", "IndicatorColumns", 3, new ConfigDescription("Max number of ability-ready icons per row in the cluster that replaces the 3rd vanilla icon.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 6), Array.Empty<object>()));
			Cfg.HudSpacing = ((BaseUnityPlugin)this).Config.Bind<float>("HUD", "IndicatorSpacing", 1f, new ConfigDescription("Multiplier for the distance between ability-ready icons above the player.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.4f, 3f), Array.Empty<object>()));
			Cfg.ShowCountButton = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ShowCountButton", true, "Show the on-screen '- / +' panel (F7 = fewer, F8 = more, F9 = hide/show panel) outside of matches.");
			Harmony val = new Harmony("com.multiabilityslots.boplbattle");
			int num = 0;
			int num2 = 0;
			Type[] types = typeof(MultiAbilityPlugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: true).Length != 0)
				{
					try
					{
						val.CreateClassProcessor(type).Patch();
						num++;
					}
					catch (Exception ex)
					{
						num2++;
						((BaseUnityPlugin)this).Logger.LogError((object)("PATCH FAILED: " + type.Name + " -> " + ex.GetType().Name + ": " + ex.Message));
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Multi Ability Slots 2.1.0 loaded. Patches ok=" + num + " failed=" + num2 + ". Extra abilities: " + Cfg.Extra.Value));
			try
			{
				Diagnostics.DumpTypes();
			}
			catch (Exception ex2)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Diagnostics dump failed: " + ex2.Message));
			}
		}

		private void Update()
		{
			if (!loggedUpdate)
			{
				loggedUpdate = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Update loop is running (F7 / F8 / F9 / F10 are active).");
			}
			Rt.NetworkUpdate();
			if (Time.unscaledTime >= nextGameplayCheck)
			{
				nextGameplayCheck = Time.unscaledTime + 0.5f;
				try
				{
					inGameplay = (Object)(object)Object.FindObjectOfType<SlimeController>() != (Object)null;
				}
				catch
				{
					inGameplay = false;
				}
			}
			try
			{
				Keyboard current = Keyboard.current;
				if (current == null)
				{
					return;
				}
				if (((ButtonControl)current.f10Key).wasPressedThisFrame)
				{
					Diagnostics.DumpUi();
					Toast("UI dump written to BepInEx folder");
				}
				if (!Cfg.ShowCountButton.Value || inGameplay)
				{
					return;
				}
				if (((ButtonControl)current.f9Key).wasPressedThisFrame)
				{
					showPanel = !showPanel;
				}
				if (!Rt.IsOnline())
				{
					if (((ButtonControl)current.f7Key).wasPressedThisFrame)
					{
						Change(-1);
					}
					else if (((ButtonControl)current.f8Key).wasPressedThisFrame)
					{
						Change(1);
					}
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Hotkey handling failed: " + ex.Message));
			}
		}

		private void Change(int delta)
		{
			int value = Cfg.Extra.Value;
			int num = Mathf.Clamp(value + delta, 1, 6);
			if (num == value)
			{
				Toast("Extra abilities: " + value + ((delta > 0) ? " (maximum)" : " (minimum)"));
				return;
			}
			Rt.SetExtraCount(num);
			Toast("Extra abilities: " + num + "  (total " + (3 + num) + ")");
		}

		private void Toast(string text)
		{
			toastText = text;
			toastUntil = Time.unscaledTime + 2.5f;
		}

		private void OnGUI()
		{
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			if (!loggedGui)
			{
				loggedGui = true;
				((BaseUnityPlugin)this).Logger.LogInfo((object)"OnGUI is running (the on-screen panel can be drawn).");
			}
			if (!Cfg.ShowCountButton.Value || inGameplay)
			{
				return;
			}
			float num = 300f;
			float num2 = 80f;
			if (showPanel)
			{
				GUILayout.BeginArea(new Rect(((float)Screen.width - num) * 0.5f, 8f, num, num2), GUI.skin.box);
				if (Rt.IsOnline())
				{
					GUILayout.Label("Extra abilities: 1 (online matches are limited to 1)", Array.Empty<GUILayoutOption>());
				}
				else
				{
					int value = Cfg.Extra.Value;
					GUILayout.Label("Extra abilities: " + value + "  (total " + (3 + value) + ")   F7 / F8, F9 hides", Array.Empty<GUILayoutOption>());
					GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
					if (GUILayout.Button("-", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
					{
						Change(-1);
					}
					if (GUILayout.Button("+", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Height(28f) }))
					{
						Change(1);
					}
					GUILayout.EndHorizontal();
				}
				GUILayout.EndArea();
			}
			if (Time.unscaledTime < toastUntil)
			{
				GUI.Label(new Rect(((float)Screen.width - 320f) * 0.5f, 8f + num2 + 4f, 320f, 24f), toastText);
			}
		}
	}
	internal sealed class BoxState
	{
		internal CharacterSelectBox Box;

		internal readonly List<SelectAbility> Extras = new List<SelectAbility>();

		internal Vector3[] VanillaScales = (Vector3[])(object)new Vector3[3];

		internal float[] Targets = new float[3];

		internal float SignedSpacing;
	}
	internal sealed class SlotRef
	{
		internal CharacterSelectBox Box;

		internal int Index;
	}
	internal static class Rt
	{
		internal sealed class PickupState
		{
			internal List<AbilityMonoBehaviour> Abilities = new List<AbilityMonoBehaviour>();

			internal List<AbilityReadyIndicator> Indicators = new List<AbilityReadyIndicator>();

			internal List<Fix> Cooldowns = new List<Fix>();

			internal bool Active;
		}

		internal const string ExtraSlotName = "Extra Ability Slot";

		internal static readonly Dictionary<int, BoxState> SlotsByBox = new Dictionary<int, BoxState>();

		internal static readonly Dictionary<int, SlotRef> BoxesBySlot = new Dictionary<int, SlotRef>();

		internal static ManualLogSource Log;

		internal const int VanillaAbilities = 3;

		internal const int VanillaBindings = 8;

		internal const byte PacketHello = 1;

		internal const byte PacketChoice = 2;

		internal const byte ProtocolVersion = 20;

		internal static readonly byte[] PacketMagic = new byte[4] { 77, 65, 83, 49 };

		internal static float nextNetworkHeartbeat;

		internal static readonly Dictionary<int, int> OnlineChoices = new Dictionary<int, int>();

		internal static readonly HashSet<string> SeenOnlinePeers = new HashSet<string>();

		internal static readonly Dictionary<int, int[]> Choices = new Dictionary<int, int[]>();

		internal static readonly Dictionary<int, InputControl[]> ExtraBindings = new Dictionary<int, InputControl[]>();

		internal static readonly HashSet<int> VerifiedInput = new HashSet<int>();

		internal static NamedSpriteList AllIcons;

		private static readonly Key[] KeyboardDefaults;

		private const float LossCircleLift = 105f;

		private const float LossArrowLift = 95f;

		private const float LossBaseLift = 34f;

		private static readonly HashSet<int> LossSelectorLiftApplied;

		internal static bool AnyBoxAlive()
		{
			bool result = false;
			List<int> list = null;
			foreach (KeyValuePair<int, BoxState> item in SlotsByBox)
			{
				if (item.Value != null && (Object)(object)item.Value.Box != (Object)null)
				{
					result = true;
					continue;
				}
				if (list == null)
				{
					list = new List<int>();
				}
				list.Add(item.Key);
			}
			if (list != null)
			{
				foreach (int item2 in list)
				{
					SlotsByBox.Remove(item2);
				}
			}
			return result;
		}

		internal static void SetExtraCount(int n)
		{
			n = Mathf.Clamp(n, 1, 6);
			Cfg.Extra.Value = n;
			foreach (BoxState item in new List<BoxState>(SlotsByBox.Values))
			{
				if (item != null && (Object)(object)item.Box != (Object)null)
				{
					BuildBox(item.Box, Effective());
				}
			}
			Log.LogInfo((object)("Extra ability count set to " + n + "."));
		}

		private static float SpacingFactor(int totalSlots)
		{
			if (totalSlots <= 4)
			{
				return 0.78f;
			}
			return Mathf.Max(0.45f, 2.34f / (float)(totalSlots - 1));
		}

		internal static void AdjustAnimationTarget(SelectAbility slot, float oldTarget, float newTarget)
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)slot == (Object)null)
			{
				return;
			}
			float num = newTarget - oldTarget;
			AnimateInOutUI component = ((Component)slot).GetComponent<AnimateInOutUI>();
			if ((Object)(object)component != (Object)null)
			{
				bool field = GetField<bool>(component, "horizontalInstead");
				float[] field2 = GetField<float[]>(component, "originalHeights");
				if (!field && field2 != null)
				{
					for (int i = 0; i < field2.Length; i++)
					{
						field2[i] += num;
					}
				}
			}
			RectTransform component2 = ((Component)slot).GetComponent<RectTransform>();
			if ((Object)(object)component2 != (Object)null && Mathf.Abs(component2.anchoredPosition.y - oldTarget) < 1f)
			{
				Vector2 anchoredPosition = component2.anchoredPosition;
				anchoredPosition.y = newTarget;
				component2.anchoredPosition = anchoredPosition;
			}
		}

		internal static AnimateInOutUI[] InsertAnimation(AnimateInOutUI[] source, AnimateInOutUI after, AnimateInOutUI item)
		{
			if (source == null)
			{
				if (!((Object)(object)item != (Object)null))
				{
					return null;
				}
				return (AnimateInOutUI[])(object)new AnimateInOutUI[1] { item };
			}
			int num = source.Length;
			for (int i = 0; i < source.Length; i++)
			{
				if ((Object)(object)source[i] == (Object)(object)after)
				{
					num = i + 1;
					break;
				}
			}
			AnimateInOutUI[] array = (AnimateInOutUI[])(object)new AnimateInOutUI[source.Length + 1];
			for (int j = 0; j < num; j++)
			{
				array[j] = source[j];
			}
			array[num] = item;
			for (int k = num; k < source.Length; k++)
			{
				array[k + 1] = source[k];
			}
			return array;
		}

		internal static bool EventCalls(UnityEvent callback, string methodName)
		{
			if (callback == null)
			{
				return false;
			}
			for (int i = 0; i < ((UnityEventBase)callback).GetPersistentEventCount(); i++)
			{
				if (string.Equals(((UnityEventBase)callback).GetPersistentMethodName(i), methodName, StringComparison.Ordinal))
				{
					return true;
				}
			}
			return false;
		}

		internal static void InstallSlotPointer(CharacterSelectBox box, SelectAbility slot)
		{
			if ((Object)(object)box == (Object)null || (Object)(object)slot == (Object)null)
			{
				return;
			}
			bool flag = false;
			CallOnHover[] componentsInChildren = ((Component)slot).GetComponentsInChildren<CallOnHover>(true);
			foreach (CallOnHover val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && (EventCalls(val.onHover, "SetSelectedHover") || EventCalls(val.onClick, "ClickEnterAbilityGrid")))
				{
					GameObject gameObject = ((Component)val).gameObject;
					Object.Destroy((Object)(object)val);
					SlotPointer slotPointer = gameObject.GetComponent<SlotPointer>();
					if ((Object)(object)slotPointer == (Object)null)
					{
						slotPointer = gameObject.AddComponent<SlotPointer>();
					}
					slotPointer.Box = box;
					slotPointer.Slot = slot;
					flag = true;
				}
			}
			if (!flag)
			{
				Image field = GetField<Image>(slot, "abilityIconRenderer");
				GameObject val2 = (((Object)(object)field == (Object)null) ? ((Component)slot).gameObject : ((Component)field).gameObject);
				SlotPointer slotPointer2 = val2.GetComponent<SlotPointer>();
				if ((Object)(object)slotPointer2 == (Object)null)
				{
					slotPointer2 = val2.AddComponent<SlotPointer>();
				}
				slotPointer2.Box = box;
				slotPointer2.Slot = slot;
			}
		}

		private static void RemoveExtras(BoxState st)
		{
			CharacterSelectBox box = st.Box;
			List<SelectableMonoBehaviour> field = GetField<List<SelectableMonoBehaviour>>(box, "selectables");
			List<Vector2> field2 = GetField<List<Vector2>>(box, "arrow_Separation_YPos");
			List<Image> field3 = GetField<List<Image>>(box, "imagesToDisable");
			AnimateInOutUI[] array = GetField<AnimateInOutUI[]>(box, "animateSelectables");
			foreach (SelectAbility extra in st.Extras)
			{
				if ((Object)(object)extra == (Object)null)
				{
					continue;
				}
				if (field != null)
				{
					int num = field.IndexOf((SelectableMonoBehaviour)(object)extra);
					if (num >= 0)
					{
						field.RemoveAt(num);
						if (field2 != null && num < field2.Count)
						{
							field2.RemoveAt(num);
						}
						if (field3 != null && num < field3.Count)
						{
							field3.RemoveAt(num);
						}
					}
				}
				if (array != null)
				{
					AnimateInOutUI component = ((Component)extra).GetComponent<AnimateInOutUI>();
					List<AnimateInOutUI> list = new List<AnimateInOutUI>();
					AnimateInOutUI[] array2 = array;
					foreach (AnimateInOutUI val in array2)
					{
						if ((Object)(object)val != (Object)(object)component)
						{
							list.Add(val);
						}
					}
					array = list.ToArray();
				}
				BoxesBySlot.Remove(((Object)extra).GetInstanceID());
				Object.Destroy((Object)(object)((Component)extra).gameObject);
			}
			st.Extras.Clear();
			if (array != null)
			{
				SetField(box, "animateSelectables", array);
			}
			if (field != null && GetField<int>(box, "selectedIndex") >= field.Count)
			{
				SetField(box, "selectedIndex", Math.Min(4, field.Count - 1));
			}
		}

		internal static void BuildBox(CharacterSelectBox box, int n)
		{
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0307: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)box == (Object)null)
			{
				return;
			}
			try
			{
				List<SelectableMonoBehaviour> field = GetField<List<SelectableMonoBehaviour>>(box, "selectables");
				if (field == null || field.Count < 5)
				{
					Log.LogWarning((object)("CharacterSelectBox has an unexpected 'selectables' list (" + ((field == null) ? "null" : field.Count.ToString()) + "); extra slots not built."));
					return;
				}
				SelectAbility[] array = (SelectAbility[])(object)new SelectAbility[3];
				for (int i = 0; i < 3; i++)
				{
					ref SelectAbility reference = ref array[i];
					SelectableMonoBehaviour obj = field[2 + i];
					reference = (SelectAbility)(object)((obj is SelectAbility) ? obj : null);
					if ((Object)(object)array[i] == (Object)null)
					{
						return;
					}
				}
				int instanceID = ((Object)box).GetInstanceID();
				float[] field2 = GetField<float[]>(box, "originalAbilitySelectPos");
				if (!SlotsByBox.TryGetValue(instanceID, out var value) || value == null)
				{
					value = new BoxState
					{
						Box = box
					};
					for (int j = 0; j < 3; j++)
					{
						value.VanillaScales[j] = ((Component)array[j]).transform.localScale;
						value.Targets[j] = ((field2 != null && field2.Length > j) ? field2[j] : 0f);
					}
					SlotsByBox[instanceID] = value;
				}
				List<int> list = new List<int>();
				foreach (SelectAbility extra in value.Extras)
				{
					list.Add(((Object)(object)extra != (Object)null) ? extra.SelectedIndex : array[2].SelectedIndex);
				}
				RemoveExtras(value);
				int num = 3 + n;
				float num2 = SpacingFactor(num);
				float num3 = 0.76f * Mathf.Min(1f, num2 / 0.78f);
				for (int k = 0; k < 3; k++)
				{
					((Component)array[k]).transform.localScale = value.VanillaScales[k] * num3;
				}
				List<Vector2> field3 = GetField<List<Vector2>>(box, "arrow_Separation_YPos");
				List<Image> field4 = GetField<List<Image>>(box, "imagesToDisable");
				AnimateInOutUI[] array2 = GetField<AnimateInOutUI[]>(box, "animateSelectables");
				AnimateInOutUI after = ((Component)array[2]).GetComponent<AnimateInOutUI>();
				for (int l = 0; l < n; l++)
				{
					GameObject val = Object.Instantiate<GameObject>(((Component)array[2]).gameObject, ((Component)array[2]).transform.parent);
					((Object)val).name = "Extra Ability Slot " + (4 + l);
					val.transform.SetSiblingIndex(((Component)array[2]).transform.GetSiblingIndex() + 1 + l);
					SelectAbility component = val.GetComponent<SelectAbility>();
					if ((Object)(object)component == (Object)null)
					{
						Object.Destroy((Object)(object)val);
						continue;
					}
					SetField(component, "csb", box);
					SetField(component, "Skip", false);
					((Component)component).transform.localScale = ((Component)array[2]).transform.localScale;
					int num4 = 5 + value.Extras.Count;
					field.Insert(num4, (SelectableMonoBehaviour)(object)component);
					if (field3 != null && field3.Count >= 5)
					{
						field3.Insert(Math.Min(num4, field3.Count), field3[4]);
					}
					if (field4 != null && field4.Count >= 5)
					{
						field4.Insert(Math.Min(num4, field4.Count), null);
					}
					AnimateInOutUI component2 = ((Component)component).GetComponent<AnimateInOutUI>();
					array2 = InsertAnimation(array2, after, component2);
					after = component2;
					value.Extras.Add(component);
				}
				SetField(box, "animateSelectables", array2);
				if (field2 != null && field2.Length >= 3)
				{
					float num5 = (field2[2] - field2[0]) * 0.5f;
					float num6 = (field2[0] + field2[2]) * 0.5f;
					float num7 = (value.SignedSpacing = num5 * num2);
					float oldTarget = value.Targets[2];
					for (int m = 0; m < value.Extras.Count; m++)
					{
						float newTarget = num6 + num7 * ((float)(3 + m) - (float)(num - 1) * 0.5f);
						AdjustAnimationTarget(value.Extras[m], oldTarget, newTarget);
					}
					for (int num8 = 0; num8 < 3; num8++)
					{
						float num9 = num6 + num7 * ((float)num8 - (float)(num - 1) * 0.5f);
						AdjustAnimationTarget(array[num8], value.Targets[num8], num9);
						value.Targets[num8] = num9;
					}
				}
				AllIcons = GetField<NamedSpriteList>((value.Extras.Count > 0) ? value.Extras[0] : array[2], "abilityIcons");
				for (int num10 = 0; num10 < value.Extras.Count; num10++)
				{
					int num11 = ((num10 < list.Count) ? list[num10] : array[2].SelectedIndex);
					((SelectableMonoBehaviour)value.Extras[num10]).Select(num11);
					BoxesBySlot[((Object)value.Extras[num10]).GetInstanceID()] = new SlotRef
					{
						Box = box,
						Index = num10
					};
					InstallSlotPointer(box, value.Extras[num10]);
				}
				SaveChoice(box);
				Log.LogInfo((object)("Character select box " + instanceID + " now shows " + value.Extras.Count + " extra ability slot(s)."));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not build the extra character-select slots: " + ex));
			}
		}

		internal static void SaveChoice(CharacterSelectBox box)
		{
			if ((Object)(object)box == (Object)null || !SlotsByBox.TryGetValue(((Object)box).GetInstanceID(), out var value) || value == null)
			{
				return;
			}
			int boxKey = GetBoxKey(box);
			if (boxKey == int.MinValue)
			{
				return;
			}
			int[] array = ChoicesFor(boxKey);
			for (int i = 0; i < value.Extras.Count && i < array.Length; i++)
			{
				if ((Object)(object)value.Extras[i] != (Object)null)
				{
					array[i] = value.Extras[i].SelectedIndex;
				}
			}
			if (!IsOnline() || value.Extras.Count == 0 || (Object)(object)value.Extras[0] == (Object)null)
			{
				return;
			}
			PlayerHandler val = PlayerHandler.Get();
			List<Player> list = ((val == null) ? null : val.PlayerList());
			if (list == null)
			{
				return;
			}
			for (int j = 0; j < list.Count; j++)
			{
				Player val2 = list[j];
				if (val2 != null && val2.IsLocalPlayer && GetPlayerKey(val2) == boxKey)
				{
					OnlineChoices[val2.Id] = value.Extras[0].SelectedIndex;
					SendChoice(val2.Id, value.Extras[0].SelectedIndex);
					break;
				}
			}
		}

		internal static bool IsExtraIndex(BoxState st, List<SelectableMonoBehaviour> selectables, int index)
		{
			if (st == null || selectables == null || index < 0 || index >= selectables.Count)
			{
				return false;
			}
			SelectableMonoBehaviour obj = selectables[index];
			SelectAbility val = (SelectAbility)(object)((obj is SelectAbility) ? obj : null);
			if ((Object)(object)val != (Object)null)
			{
				return st.Extras.Contains(val);
			}
			return false;
		}

		internal static void CopyImageAppearance(Image source, Image target)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)source == (Object)null) && !((Object)(object)target == (Object)null))
			{
				((Graphic)target).color = ((Graphic)source).color;
				((Graphic)target).material = ((Graphic)source).material;
				((Behaviour)target).enabled = ((Behaviour)source).enabled;
				((Graphic)target).canvasRenderer.SetAlpha(((Graphic)source).canvasRenderer.GetAlpha());
			}
		}

		internal static void MaintainExtraSlots(CharacterSelectBox box)
		{
			//IL_0108: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)box == (Object)null || !SlotsByBox.TryGetValue(((Object)box).GetInstanceID(), out var value) || value == null || value.Extras.Count == 0)
			{
				return;
			}
			List<SelectableMonoBehaviour> field = GetField<List<SelectableMonoBehaviour>>(box, "selectables");
			SelectAbility val = (SelectAbility)((field != null && field.Count > 4) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			bool activeSelf = ((Component)val).gameObject.activeSelf;
			RectTransform component = ((Component)val).GetComponent<RectTransform>();
			CanvasGroup component2 = ((Component)val).GetComponent<CanvasGroup>();
			Image field2 = GetField<Image>(val, "abilityIconRenderer");
			Image field3 = GetField<Image>(val, "BorderRenderer");
			Image field4 = GetField<Image>(val, "circlesRenderer");
			for (int i = 0; i < value.Extras.Count; i++)
			{
				SelectAbility val2 = value.Extras[i];
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				if (((Component)val2).gameObject.activeSelf != activeSelf)
				{
					((Component)val2).gameObject.SetActive(activeSelf);
				}
				if (activeSelf)
				{
					RectTransform component3 = ((Component)val2).GetComponent<RectTransform>();
					if ((Object)(object)component3 != (Object)null && (Object)(object)component != (Object)null)
					{
						Vector2 anchoredPosition = component.anchoredPosition;
						anchoredPosition.y += value.SignedSpacing * (float)(i + 1);
						component3.anchoredPosition = anchoredPosition;
					}
					CanvasGroup component4 = ((Component)val2).GetComponent<CanvasGroup>();
					if ((Object)(object)component4 != (Object)null && (Object)(object)component2 != (Object)null)
					{
						component4.alpha = component2.alpha;
						component4.interactable = component2.interactable;
						component4.blocksRaycasts = component2.blocksRaycasts;
					}
					Image field5 = GetField<Image>(val2, "abilityIconRenderer");
					if ((Object)(object)field2 != (Object)null && (Object)(object)field5 != (Object)null)
					{
						Sprite sprite = field5.sprite;
						CopyImageAppearance(field2, field5);
						field5.sprite = sprite;
					}
					CopyImageAppearance(field3, GetField<Image>(val2, "BorderRenderer"));
					CopyImageAppearance(field4, GetField<Image>(val2, "circlesRenderer"));
				}
			}
		}

		internal static void FixCharacterArrow(CharacterSelectBox box, int selectedIndex)
		{
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)box == (Object)null)
			{
				return;
			}
			List<SelectableMonoBehaviour> field = GetField<List<SelectableMonoBehaviour>>(box, "selectables");
			if (field == null || selectedIndex < 0 || selectedIndex >= field.Count)
			{
				return;
			}
			SelectableMonoBehaviour obj = field[selectedIndex];
			SelectAbility val = (SelectAbility)(object)((obj is SelectAbility) ? obj : null);
			if (!((Object)(object)val == (Object)null) && ((Object)((Component)val).gameObject).name.StartsWith("Extra Ability Slot", StringComparison.Ordinal))
			{
				RectTransform field2 = GetField<RectTransform>(box, "arrows");
				RectTransform component = ((Component)val).GetComponent<RectTransform>();
				if ((Object)(object)field2 != (Object)null && (Object)(object)component != (Object)null)
				{
					Vector2 anchoredPosition = field2.anchoredPosition;
					anchoredPosition.y = component.anchoredPosition.y;
					field2.anchoredPosition = anchoredPosition;
				}
			}
		}

		internal static FieldInfo Field(Type type, string name)
		{
			return AccessTools.Field(type, name);
		}

		internal static T GetField<T>(object instance, string name)
		{
			if (instance == null)
			{
				return default(T);
			}
			FieldInfo fieldInfo = Field(instance.GetType(), name);
			if (fieldInfo == null)
			{
				return default(T);
			}
			object value = fieldInfo.GetValue(instance);
			if (value == null)
			{
				return default(T);
			}
			return (T)value;
		}

		internal static void SetField(object instance, string name, object value)
		{
			if (instance != null)
			{
				FieldInfo fieldInfo = Field(instance.GetType(), name);
				if (fieldInfo != null)
				{
					fieldInfo.SetValue(instance, value);
				}
			}
		}

		internal static T[] Resize<T>(T[] source, int length)
		{
			T[] array = new T[length];
			if (source != null)
			{
				Array.Copy(source, array, Math.Min(source.Length, length));
			}
			return array;
		}

		internal static T[] PrependCopies<T>(T[] source, int count, T value)
		{
			int num = ((source != null) ? source.Length : 0);
			T[] array = new T[num + count];
			for (int i = 0; i < count; i++)
			{
				array[i] = value;
			}
			for (int j = 0; j < num; j++)
			{
				array[count + j] = source[j];
			}
			return array;
		}

		internal static bool IsOnline()
		{
			try
			{
				FieldInfo fieldInfo = Field(typeof(GameLobby), "isOnlineGame");
				return fieldInfo != null && (bool)fieldInfo.GetValue(null);
			}
			catch
			{
				return false;
			}
		}

		internal static int Effective()
		{
			if (IsOnline() || GameLobby.isPlayingAReplay)
			{
				return 1;
			}
			return Mathf.Clamp((Cfg.Extra != null) ? Cfg.Extra.Value : 4, 1, 6);
		}

		internal static string SlotLabel(int extraIndex)
		{
			return "A" + (4 + extraIndex);
		}

		internal static bool IsOurPacket(byte[] data)
		{
			if (data != null && data.Length >= 5 && data[0] == PacketMagic[0] && data[1] == PacketMagic[1] && data[2] == PacketMagic[2])
			{
				return data[3] == PacketMagic[3];
			}
			return false;
		}

		internal static byte[] NewPacket(byte type, int payloadBytes)
		{
			byte[] array = new byte[5 + payloadBytes];
			for (int i = 0; i < PacketMagic.Length; i++)
			{
				array[i] = PacketMagic[i];
			}
			array[4] = type;
			return array;
		}

		internal static void WriteInt(byte[] data, int offset, int value)
		{
			byte[] bytes = BitConverter.GetBytes(value);
			for (int i = 0; i < 4; i++)
			{
				data[offset + i] = bytes[i];
			}
		}

		internal static void SendPacket(byte[] data)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOnline() || data == null)
			{
				return;
			}
			try
			{
				SteamManager instance = SteamManager.instance;
				if ((Object)(object)instance == (Object)null || instance.connectedPlayers == null)
				{
					return;
				}
				foreach (SteamConnection connectedPlayer in instance.connectedPlayers)
				{
					if (connectedPlayer != null && ((ConnectionManager)connectedPlayer).Connected)
					{
						((Connection)(ref ((ConnectionManager)connectedPlayer).Connection)).SendMessage(data, (SendType)8);
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Extra-slot network send failed: " + ex.Message));
			}
		}

		internal static void SendHello()
		{
			byte[] array = NewPacket(1, 1);
			array[5] = 20;
			SendPacket(array);
		}

		internal static void SendChoice(int playerId, int choice)
		{
			byte[] data = NewPacket(2, 8);
			WriteInt(data, 5, playerId);
			WriteInt(data, 9, choice);
			SendPacket(data);
		}

		internal static void NetworkUpdate()
		{
			if (!IsOnline() || Time.unscaledTime < nextNetworkHeartbeat)
			{
				return;
			}
			nextNetworkHeartbeat = Time.unscaledTime + 0.5f;
			SendHello();
			foreach (KeyValuePair<int, int> onlineChoice in OnlineChoices)
			{
				SendChoice(onlineChoice.Key, onlineChoice.Value);
			}
		}

		internal static bool SenderMatchesPlayer(int playerId, NetIdentity identity)
		{
			//IL_0024: 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)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerHandler val = PlayerHandler.Get();
				Player val2 = ((val == null) ? null : val.GetPlayer(playerId));
				if (val2 == null || val2.IsLocalPlayer)
				{
					return false;
				}
				return string.Equals(((object)val2.steamId/*cast due to .constrained prefix*/).ToString(), ((object)((NetIdentity)(ref identity)).SteamId/*cast due to .constrained prefix*/).ToString(), StringComparison.Ordinal);
			}
			catch
			{
				return false;
			}
		}

		internal static void ReceivePacket(byte[] data, NetIdentity identity)
		{
			//IL_001d: 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_009a: Unknown result type (might be due to invalid IL or missing references)
			if (!IsOurPacket(data))
			{
				return;
			}
			try
			{
				switch (data[4])
				{
				case 1:
				{
					string text = ((object)((NetIdentity)(ref identity)).SteamId/*cast due to .constrained prefix*/).ToString();
					int num2 = ((data.Length > 5) ? data[5] : 0);
					if (SeenOnlinePeers.Add(text))
					{
						if (num2 == 20)
						{
							Log.LogInfo((object)("Multi Ability Slots handshake received from online peer " + text + "."));
						}
						else
						{
							Log.LogWarning((object)("Online peer " + text + " runs a different Multi Ability Slots version."));
						}
					}
					break;
				}
				case 2:
					if (data.Length >= 13)
					{
						int num = BitConverter.ToInt32(data, 5);
						if (SenderMatchesPlayer(num, identity))
						{
							OnlineChoices[num] = BitConverter.ToInt32(data, 9);
						}
					}
					break;
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Ignored malformed network packet: " + ex.Message));
			}
		}

		internal static int GetBoxKey(CharacterSelectBox box)
		{
			if (GetField<bool>(box, "UseskeyboardMouse"))
			{
				return -1;
			}
			Gamepad field = GetField<Gamepad>(box, "currentGamePad");
			if (field != null)
			{
				return ((InputDevice)field).deviceId;
			}
			return int.MinValue;
		}

		internal static int GetPlayerKey(Player player)
		{
			if (player.UsesKeyboardAndMouse)
			{
				return -1;
			}
			InputDevice inputDevice = player.inputDevice;
			Gamepad val = (Gamepad)(object)((inputDevice is Gamepad) ? inputDevice : null);
			if (val != null)
			{
				return ((InputDevice)val).deviceId;
			}
			return int.MinValue;
		}

		internal static int DefaultChoice(int extraIndex)
		{
			int num = 1 + extraIndex;
			if ((Object)(object)AllIcons != (Object)null && AllIcons.sprites != null && num >= AllIcons.sprites.Count)
			{
				num = 1;
			}
			return num;
		}

		internal static int[] ChoicesFor(int key)
		{
			if (!Choices.TryGetValue(key, out var value) || value == null || value.Length < 6)
			{
				int[] array = new int[6];
				for (int i = 0; i < array.Length; i++)
				{
					array[i] = ((value != null && i < value.Length) ? value[i] : DefaultChoice(i));
				}
				Choices[key] = array;
				return array;
			}
			return value;
		}

		internal static InputControl DefaultBinding(bool keyboardMouse, Gamepad pad, int slot)
		{
			if (keyboardMouse)
			{
				if (slot == 0)
				{
					Mouse current = Mouse.current;
					if (current == null)
					{
						return null;
					}
					return (InputControl)(object)current.middleButton;
				}
				Keyboard current2 = Keyboard.current;
				int num = slot - 1;
				if (current2 != null && num >= 0 && num < KeyboardDefaults.Length)
				{
					return (InputControl)(object)current2[KeyboardDefaults[num]];
				}
				return null;
			}
			if (pad == null)
			{
				return null;
			}
			return (InputControl)(slot switch
			{
				0 => pad.rightTrigger, 
				1 => pad.leftTrigger, 
				2 => pad.rightStickButton, 
				3 => pad.leftStickButton, 
				4 => pad.dpad.up, 
				5 => pad.dpad.down, 
				_ => null, 
			});
		}

		internal static Gamepad ResolvePlayerGamepad(Player player)
		{
			if (player == null)
			{
				return null;
			}
			InputDevice inputDevice = player.inputDevice;
			Gamepad val = (Gamepad)(object)((inputDevice is Gamepad) ? inputDevice : null);
			if (val != null)
			{
				return val;
			}
			InputControl[] customKeyBinding = player.CustomKeyBinding;
			if (customKeyBinding != null)
			{
				InputControl[] array = customKeyBinding;
				foreach (InputControl val2 in array)
				{
					if (val2 != null)
					{
						InputDevice device = val2.device;
						Gamepad val3 = (Gamepad)(object)((device is Gamepad) ? device : null);
						if (val3 != null)
						{
							return val3;
						}
					}
				}
			}
			return null;
		}

		internal static void EnsureExtraBindings(Player player)
		{
			if (player == null || !player.IsLocalPlayer)
			{
				return;
			}
			int playerKey = GetPlayerKey(player);
			if (playerKey == int.MinValue)
			{
				return;
			}
			if (!ExtraBindings.TryGetValue(playerKey, out var value) || value == null || value.Length < 6)
			{
				value = Resize(value, 6);
				ExtraBindings[playerKey] = value;
			}
			InputDevice inputDevice = player.inputDevice;
			Gamepad pad = (Gamepad)(object)((inputDevice is Gamepad) ? inputDevice : null);
			for (int i = 0; i < value.Length; i++)
			{
				if (value[i] == null)
				{
					value[i] = DefaultBinding(player.UsesKeyboardAndMouse, pad, i);
				}
			}
		}

		internal static InputControl ControlForPlayer(Player player, int slot)
		{
			if (player == null)
			{
				return null;
			}
			InputControl val = null;
			int playerKey = GetPlayerKey(player);
			if (playerKey != int.MinValue && ExtraBindings.TryGetValue(playerKey, out var value) && value != null && slot < value.Length)
			{
				val = value[slot];
			}
			if (player.UsesKeyboardAndMouse)
			{
				if (val == null)
				{
					return DefaultBinding(keyboardMouse: true, null, slot);
				}
				return val;
			}
			Gamepad val2 = ResolvePlayerGamepad(player);
			if (val2 != null)
			{
				if (val != null && (object)val.device == val2)
				{
					return val;
				}
				return DefaultBinding(keyboardMouse: false, val2, slot);
			}
			return val;
		}

		internal static InputControl[] ToBindingMenuOrder(Player player, int extraCount)
		{
			if (player == null)
			{
				return null;
			}
			InputControl[] customKeyBinding = player.CustomKeyBinding;
			InputControl[] array = (InputControl[])(object)new InputControl[extraCount + 8];
			for (int i = 0; i < extraCount; i++)
			{
				array[i] = ControlForPlayer(player, i);
			}
			for (int j = 0; j < 8; j++)
			{
				array[extraCount + j] = ((customKeyBinding != null && customKeyBinding.Length > j) ? customKeyBinding[j] : null);
			}
			return array;
		}

		internal static InputControl[] ToVanillaBindingOrder(InputControl[] ordered, int extraCount)
		{
			if (ordered == null || ordered.Length <= 8)
			{
				return ordered;
			}
			InputControl[] array = (InputControl[])(object)new InputControl[8];
			for (int i = 0; i < 8; i++)
			{
				array[i] = ordered[extraCount + i];
			}
			return array;
		}

		internal static T CloneUiAbove<T>(T[] source, string objectName) where T : Component
		{
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (source == null || source.Length == 0 || (Object)(object)source[0] == (Object)null)
			{
				return default(T);
			}
			T val = source[0];
			GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent);
			((Object)obj).name = objectName;
			obj.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex());
			RectTransform component = obj.GetComponent<RectTransform>();
			RectTransform component2 = ((Component)val).GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null && (Object)(object)component2 != (Object)null)
			{
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(0f, 34f);
				if (source.Length > 1 && (Object)(object)source[1] != (Object)null)
				{
					RectTransform component3 = ((Component)source[1]).GetComponent<RectTransform>();
					if ((Object)(object)component3 != (Object)null)
					{
						val2 = component2.anchoredPosition - component3.anchoredPosition;
					}
				}
				component.anchoredPosition = component2.anchoredPosition + val2;
			}
			return obj.GetComponent<T>();
		}

		internal static int ExtraRowsInMenu(KeyBindButton button)
		{
			string[] field = GetField<string[]>(button, "KeyListKeyboardMouse");
			if (field == null)
			{
				return 0;
			}
			return Math.Max(0, field.Length - 8);
		}

		internal static void PrepareKeyBindMenu(KeyBindButton button)
		{
			if ((Object)(object)button == (Object)null)
			{
				return;
			}
			try
			{
				string[] field = GetField<string[]>(button, "KeyListGamePad");
				string[] field2 = GetField<string[]>(button, "KeyListKeyboardMouse");
				if (field == null || field2 == null || field.Length > 8 || field2.Length > 8)
				{
					return;
				}
				int num = Effective();
				string value = field[Math.Min(3, field.Length - 1)];
				string value2 = field2[Math.Min(3, field2.Length - 1)];
				SetField(button, "KeyListGamePad", PrependCopies(field, num, value));
				SetField(button, "KeyListKeyboardMouse", PrependCopies(field2, num, value2));
				bool[] field3 = GetField<bool[]>(button, "MouseOnlyKeyList");
				SetField(button, "MouseOnlyKeyList", PrependCopies(field3, num, value: false));
				Sprite[] field4 = GetField<Sprite[]>(button, "CircleIndicators_gamePad");
				Sprite[] field5 = GetField<Sprite[]>(button, "CircleIndicators_keyboard");
				Sprite value3 = ((field4 != null && field4.Length > 3) ? field4[3] : null);
				Sprite value4 = ((field5 != null && field5.Length > 3) ? field5[3] : null);
				SetField(button, "CircleIndicators_gamePad", PrependCopies(field4, num, value3));
				SetField(button, "CircleIndicators_keyboard", PrependCopies(field5, num, value4));
				SetField(button, "indicatorRotations_keyboard", PrependCopies(GetField<float[]>(button, "indicatorRotations_keyboard"), num, 0f));
				TextMeshProUGUI[] array = GetField<TextMeshProUGUI[]>(button, "bindingListLabels");
				TextMeshProUGUI[] array2 = GetField<TextMeshProUGUI[]>(button, "bindingListChoices");
				TMP_Text source = (TMP_Text)(object)((array != null && array.Length != 0) ? array[0] : null);
				TMP_Text source2 = (TMP_Text)(object)((array2 != null && array2.Length != 0) ? array2[0] : null);
				for (int num2 = num - 1; num2 >= 0; num2--)
				{
					TextMeshProUGUI val = Rt.CloneUiAbove<TextMeshProUGUI>(array, "Ability " + (4 + num2) + " Binding Label");
					if ((Object)(object)val != (Object)null)
					{
						((TMP_Text)val).text = SlotLabel(num2);
						MatchTeamTextColor matchTeamTextColor = ((Component)val).gameObject.GetComponent<MatchTeamTextColor>();
						if ((Object)(object)matchTeamTextColor == (Object)null)
						{
							matchTeamTextColor = ((Component)val).gameObject.AddComponent<MatchTeamTextColor>();
						}
						matchTeamTextColor.Source = source;
					}
					array = PrependCopies(array, 1, val);
					TextMeshProUGUI val2 = Rt.CloneUiAbove<TextMeshProUGUI>(array2, "Ability " + (4 + num2) + " Binding Choice");
					if ((Object)(object)val2 != (Object)null)
					{
						((TMP_Text)val2).text = "";
						MatchTeamTextColor matchTeamTextColor2 = ((Component)val2).gameObject.GetComponent<MatchTeamTextColor>();
						if ((Object)(object)matchTeamTextColor2 == (Object)null)
						{
							matchTeamTextColor2 = ((Component)val2).gameObject.AddComponent<MatchTeamTextColor>();
						}
						matchTeamTextColor2.Source = source2;
					}
					array2 = PrependCopies(array2, 1, val2);
				}
				SetField(button, "bindingListLabels", array);
				SetField(button, "bindingListChoices", array2);
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not extend the in-game keybind menu: " + ex));
			}
		}

		internal static void FinishKeyBindMenu(KeyBindButton button)
		{
			if ((Object)(object)button == (Object)null)
			{
				return;
			}
			int num = ExtraRowsInMenu(button);
			string[] field = GetField<string[]>(button, "keyListGamepad_spaced");
			string[] field2 = GetField<string[]>(button, "KeyListKeyboardMouse_spaced");
			for (int i = 0; i < num; i++)
			{
				if (field != null && field.Length > 8 + i)
				{
					field[i] = SlotLabel(i);
				}
				if (field2 != null && field2.Length > 8 + i)
				{
					field2[i] = SlotLabel(i);
				}
			}
		}

		internal static bool RawExtraInputHeld(Player player, int slot)
		{
			if (player == null || player.ignoreAllInputs || !player.IsLocalPlayer)
			{
				return false;
			}
			EnsureExtraBindings(player);
			InputControl obj = ControlForPlayer(player, slot);
			ButtonControl val = (ButtonControl)(object)((obj is ButtonControl) ? obj : null);
			bool flag = val != null && val.isPressed;
			if (flag && VerifiedInput.Add(player.Id * 16 + slot))
			{
				Log.LogInfo((object)("Input for " + SlotLabel(slot) + " detected for local player " + player.Id + "."));
			}
			return flag;
		}

		internal static bool ExtraInputHeld(Player player, int slot)
		{
			if (player == null || player.ignoreAllInputs)
			{
				return false;
			}
			if (IsOnline() || GameLobby.isPlayingAReplay)
			{
				if (slot == 0)
				{
					return player.SelectButton_isDown();
				}
				return false;
			}
			return RawExtraInputHeld(player, slot);
		}

		internal static void PutExtraInputInPacket(int playerId, ref InputPacket packet)
		{
			if (IsOnline())
			{
				PlayerHandler val = PlayerHandler.Get();
				Player val2 = ((val == null) ? null : val.GetPlayer(playerId));
				if (val2 != null && val2.IsLocalPlayer)
				{
					packet.select = RawExtraInputHeld(val2, 0);
				}
			}
		}

		internal static void AddExtrasToPlayers(List<Player> players)
		{
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c4: Unknown result type (might be due to invalid IL or missing references)
			if (players == null)
			{
				return;
			}
			if ((Object)(object)AllIcons == (Object)null)
			{
				foreach (BoxState value2 in SlotsByBox.Values)
				{
					if (value2 != null && value2.Extras.Count > 0 && (Object)(object)value2.Extras[0] != (Object)null)
					{
						AllIcons = GetField<NamedSpriteList>(value2.Extras[0], "abilityIcons");
						if ((Object)(object)AllIcons != (Object)null)
						{
							break;
						}
					}
				}
			}
			if ((Object)(object)AllIcons == (Object)null || AllIcons.sprites == null || AllIcons.sprites.Count <= 1)
			{
				Log.LogError((object)"The ability icon list was unavailable; extra loadout abilities were not added.");
				return;
			}
			int num = Effective();
			bool flag = IsOnline();
			for (int i = 0; i < players.Count; i++)
			{
				Player val = players[i];
				if (val == null)
				{
					continue;
				}
				if (val.IsLocalPlayer)
				{
					EnsureExtraBindings(val);
				}
				if (val.Abilities == null)
				{
					val.Abilities = new List<GameObject>();
				}
				if (val.AbilityIcons == null)
				{
					val.AbilityIcons = new List<Sprite>();
				}
				while (val.Abilities.Count > 3 + num)
				{
					val.Abilities.RemoveAt(val.Abilities.Count - 1);
				}
				while (val.AbilityIcons.Count > 3 + num)
				{
					val.AbilityIcons.RemoveAt(val.AbilityIcons.Count - 1);
				}
				int num2 = (val.IsLocalPlayer ? GetPlayerKey(val) : int.MinValue);
				for (int j = 0; j < num; j++)
				{
					int num3 = DefaultChoice(j);
					int value;
					if (val.IsLocalPlayer && num2 != int.MinValue)
					{
						num3 = ChoicesFor(num2)[j];
					}
					else if (flag && j == 0 && OnlineChoices.TryGetValue(val.Id, out value))
					{
						num3 = value;
					}
					if (num3 <= 0 || num3 >= AllIcons.sprites.Count)
					{
						num3 = 1;
					}
					if (flag && j == 0)
					{
						if (val.IsLocalPlayer)
						{
							OnlineChoices[val.Id] = num3;
							SendChoice(val.Id, num3);
						}
						else if (!OnlineChoices.ContainsKey(val.Id))
						{
							Log.LogWarning((object)("No extra-ability selection received yet for online player " + val.Id + "; using default."));
						}
					}
					NamedSprite val2 = AllIcons.sprites[num3];
					if (!((Object)(object)val2.associatedGameObject == (Object)null))
					{
						int index = 3 + j;
						SetListSlot(val.Abilities, index, val2.associatedGameObject);
						SetListSlot(val.AbilityIcons, index, val2.sprite);
					}
				}
				Log.LogInfo((object)("Prepared " + num + " extra abilities for player " + val.Id + " (loadout size " + val.Abilities.Count + ")."));
			}
		}

		private static void SetListSlot<T>(List<T> list, int index, T value)
		{
			while (list.Count < index)
			{
				list.Add(default(T));
			}
			if (list.Count > index)
			{
				list[index] = value;
			}
			else
			{
				list.Add(value);
			}
		}

		internal static void EnsureCooldownArray(SlimeController controller)
		{
			//IL_005b: 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_007f: 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)
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			int num = Math.Max(4, GetField<List<AbilityMonoBehaviour>>(controller, "abilities")?.Count ?? 0);
			Fix[] field = GetField<Fix[]>(controller, "abilityCooldownTimers");
			if (field == null || field.Length < num)
			{
				Fix[] array = (Fix[])(object)new Fix[num];
				int num2 = ((field != null) ? field.Length : 0);
				for (int i = 0; i < num2; i++)
				{
					array[i] = field[i];
				}
				for (int j = num2; j < array.Length; j++)
				{
					array[j] = (Fix)(-1.5f);
				}
				SetField(controller, "abilityCooldownTimers", array);
			}
		}

		internal static Vector3 IndicatorOffset(AbilityReadyIndicator indicator)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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)
			if ((Object)(object)indicator == (Object)null)
			{
				return Vector3.zero;
			}
			FollowTransform component = ((Component)indicator).GetComponent<FollowTransform>();
			if ((Object)(object)component != (Object)null && GetField<bool>(component, "initializedPosition"))
			{
				return GetField<Vector3>(component, "PositionOffset");
			}
			return ((Component)indicator).transform.localPosition;
		}

		internal static void SetIndicatorOffset(AbilityReadyIndicator indicator, SlimeController controller, Vector3 offset)
		{
			//IL_0019: 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)
			if (!((Object)(object)indicator == (Object)null) && !((Object)(object)controller == (Object)null))
			{
				((Component)indicator).transform.localPosition = offset;
				FollowTransform component = ((Component)indicator).GetComponent<FollowTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.Leader = ((Component)controller).transform;
					SetField(component, "PositionOffset", offset);
				}
			}
		}

		internal static void AppendExtraIndicators(SlimeController controller, Sprite[] sprites)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)controller == (Object)null || sprites == null || sprites.Length == 0)
			{
				return;
			}
			AbilityReadyIndicator[] field = GetField<AbilityReadyIndicator[]>(controller, "AbilityReadyIndicators");
			if (field == null || field.Length < 3 || (Object)(object)field[0] == (Object)null || (Object)(object)field[1] == (Object)null || (Object)(object)field[2] == (Object)null)
			{
				return;
			}
			int num = sprites.Length;
			Vector3 val = IndicatorOffset(field[0]);
			Vector3 val2 = IndicatorOffset(field[1]);
			Vector3 val3 = IndicatorOffset(field[2]);
			AbilityReadyIndicator[] array = (AbilityReadyIndicator[])(object)new AbilityReadyIndicator[Math.Max(3 + num, field.Length)];
			for (int i = 0; i < field.Length; i++)
			{
				array[i] = field[i];
			}
			AbilityReadyIndicator val4 = field[2];
			for (int j = 0; j < num; j++)
			{
				int num2 = 3 + j;
				AbilityReadyIndicator val5 = array[num2];
				if ((Object)(object)val5 == (Object)null)
				{
					GameObject obj = Object.Instantiate<GameObject>(((Component)val4).gameObject, ((Component)val4).transform.parent);
					((Object)obj).name = "Extra Ability Ready Indicator " + (4 + j);
					val5 = obj.GetComponent<AbilityReadyIndicator>();
					if ((Object)(object)val5 != (Object)null)
					{
						val5.Init();
					}
				}
				if ((Object)(object)val5 != (Object)null)
				{
					if ((Object)(object)sprites[j] != (Object)null)
					{
						val5.SetSprite(sprites[j], true);
					}
					((Component)val5).gameObject.SetActive(true);
					IndicatorVisibilityFollower indicatorVisibilityFollower = ((Component)controller).gameObject.AddComponent<IndicatorVisibilityFollower>();
					indicatorVisibilityFollower.Source = val4;
					indicatorVisibilityFollower.Target = val5;
					indicatorVisibilityFollower.SyncNow();
				}
				array[num2] = val5;
			}
			SetField(controller, "AbilityReadyIndicators", array);
			int num3 = 1 + num;
			int val6 = Mathf.Clamp((Cfg.HudColumns != null) ? Cfg.HudColumns.Value : 3, 1, 6);
			val6 = Math.Min(val6, num3);
			float num4 = Mathf.Max(0.9f, Mathf.Abs(val2.x - val.x));
			float num5 = Mathf.Max(0.38f, num4 * 0.25f) * 2f * ((Cfg.HudSpacing != null) ? Cfg.HudSpacing.Value : 1f);
			float num6 = ((((val + val2) * 0.5f).y >= val3.y) ? (-1f) : 1f);
			for (int k = 0; k < num3; k++)
			{
				int num7 = k / val6;
				int num8 = k % val6;
				int num9 = Math.Min(val6, num3 - num7 * val6);
				float num10 = ((float)num8 - (float)(num9 - 1) * 0.5f) * num5;
				float num11 = num6 * (float)num7 * num5 * 0.9f;
				Vector3 offset = val3 + new Vector3(num10, num11, 0f);
				SetIndicatorOffset((k == 0) ? array[2] : array[3 + k - 1], controller, offset);
			}
		}

		internal static void FinishSpawn(GameSessionHandler handler)
		{
			if ((Object)(object)handler == (Object)null)
			{
				return;
			}
			SlimeController[] field = GetField<SlimeController[]>(handler, "slimeControllers");
			PlayerHandler val = PlayerHandler.Get();
			if (field == null || val == null)
			{
				return;
			}
			SlimeController[] array = field;
			foreach (SlimeController val2 in array)
			{
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				int num = GetField<List<AbilityMonoBehaviour>>(val2, "abilities")?.Count ?? 0;
				if (num <= 3)
				{
					Log.LogError((object)("Player " + val2.GetPlayerId() + " spawned with " + num + " abilities; extra ability injection failed before SpawnPlayers."));
					continue;
				}
				Player player = val.GetPlayer(val2.GetPlayerId());
				int num2 = num - 3;
				Sprite[] array2 = (Sprite[])(object)new Sprite[num2];
				for (int j = 0; j < num2; j++)
				{
					int num3 = 3 + j;
					array2[j] = ((player != null && player.AbilityIcons != null && player.AbilityIcons.Count > num3) ? player.AbilityIcons[num3] : null);
				}
				AppendExtraIndicators(val2, array2);
				EnsureCooldownArray(val2);
				Log.LogInfo((object)("Gameplay slots ready for player " + val2.GetPlayerId() + ": abilities=" + num + "."));
			}
		}

		internal static PickupState BeginVanillaPickup(SlimeController controller)
		{
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)controller == (Object)null)
			{
				return null;
			}
			List<AbilityMonoBehaviour> field = GetField<List<AbilityMonoBehaviour>>(controller, "abilities");
			AbilityReadyIndicator[] field2 = GetField<AbilityReadyIndicator[]>(controller, "AbilityReadyIndicators");
			Fix[] field3 = GetField<Fix[]>(controller, "abilityCooldownTimers");
			if (field == null || field.Count <= 3 || field2 == null || field3 == null)
			{
				return null;
			}
			int count = field.Count;
			if (field2.Length < count || field3.Length < count)
			{
				return null;
			}
			PickupState pickupState = new PickupState
			{
				Active = true
			};
			for (int i = 3; i < count; i++)
			{
				pickupState.Abilities.Add(field[i]);
				pickupState.Indicators.Add(field2[i]);
				pickupState.Cooldowns.Add(field3[i]);
			}
			List<AbilityMonoBehaviour> list = new List<AbilityMonoBehaviour>();
			AbilityReadyIndicator[] array = (AbilityReadyIndicator[])(object)new AbilityReadyIndicator[3];
			Fix[] array2 = (Fix[])(object)new Fix[3];
			for (int j = 0; j < 3; j++)
			{
				list.Add(field[j]);
				array[j] = field2[j];
				array2[j] = field3[j];
			}
			SetField(controller, "abilities", list);
			SetField(controller, "AbilityReadyIndicators", array);
			SetField(controller, "abilityCooldownTimers", array2);
			return pickupState;
		}

		internal static void EndVanillaPickup(SlimeController controller, PickupState state)
		{
			//IL_0122: 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_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)controller == (Object)null) && state != null && state.Active)
			{
				state.Active = false;
				List<AbilityMonoBehaviour> list = GetField<List<AbilityMonoBehaviour>>(controller, "abilities");
				if (list == null)
				{
					list = new List<AbilityMonoBehaviour>();
				}
				while (list.Count > 3)
				{
					list.RemoveAt(list.Count - 1);
				}
				while (list.Count < 3)
				{
					list.Add(null);
				}
				list.AddRange(state.Abilities);
				SetField(controller, "abilities", list);
				int num = 3 + state.Abilities.Count;
				AbilityReadyIndicator[] field = GetField<AbilityReadyIndicator[]>(controller, "AbilityReadyIndicators");
				AbilityReadyIndicator[] array = (AbilityReadyIndicator[])(object)new AbilityReadyIndicator[num];
				for (int i = 0; i < 3; i++)
				{
					array[i] = ((field != null && field.Length > i) ? field[i] : null);
				}
				for (int j = 0; j < state.Indicators.Count; j++)
				{
					array[3 + j] = state.Indicators[j];
				}
				SetField(controller, "AbilityReadyIndicators", array);
				Fix[] field2 = GetField<Fix[]>(controller, "abilityCooldownTimers");
				Fix[] array2 = (Fix[])(object)new Fix[num];
				for (int k = 0; k < 3; k++)
				{
					array2[k] = ((field2 != null && field2.Length > k) ? field2[k] : ((Fix)(-1.5f)));
				}
				for (int l = 0; l < state.Cooldowns.Count; l++)
				{
					array2[3 + l] = state.Cooldowns[l];
				}
				SetField(controller, "abilityCooldownTimers", array2);
			}
		}

		internal static void AddExtrasToClone(SlimeController clone, SlimeController source, Player player, AbilityReadyIndicator[] sourceIndicators, int extraCount)
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)clone == (Object)null || (Object)(object)source == (Object)null || extraCount <= 0)
			{
				return;
			}
			try
			{
				List<AbilityMonoBehaviour> list = GetField<List<AbilityMonoBehaviour>>(clone, "abilities");
				if (list == null)
				{
					list = new List<AbilityMonoBehaviour>();
					SetField(clone, "abilities", list);
				}
				Sprite[] array = (Sprite[])(object)new Sprite[extraCount];
				List<int> list2 = new List<int>();
				List<AbilityMonoBehaviour> list3 = new List<AbilityMonoBehaviour>();
				for (int i = 0; i < extraCount; i++)
				{
					int num = 3 + i;
					Sprite val = null;
					if (sourceIndicators != null && sourceIndicators.Length > num && (Object)(object)sourceIndicators[num] != (Object)null)
					{
						val = sourceIndicators[num].GetPrimarySprite();
					}
					if ((Object)(object)val == (Object)null && player != null && player.AbilityIcons != null && player.AbilityIcons.Count > num)
					{
						val = player.AbilityIcons[num];
					}
					array[i] = val;
					GameObject val2 = null;
					NamedSpriteList abilityIcons = source.abilityIcons;
					if ((Object)(object)abilityIcons != (Object)null && (Object)(object)val != (Object)null)
					{
						int num2 = abilityIcons.IndexOf(val);
						if (num2 >= 0 && num2 < abilityIcons.sprites.Count)
						{
							val2 = abilityIcons.sprites[num2].associatedGameObject;
						}
					}
					if ((Object)(object)val2 == (Object)null && player != null && player.Abilities != null && player.Abilities.Count > num)
					{
						val2 = player.Abilities[num];
					}
					if (!((Object)(object)val2 == (Object)null))
					{
						GameObject obj = FixTransform.InstantiateFixed(val2, Vec2.zero);
						obj.SetActive(false);
						AbilityMonoBehaviour component = obj.GetComponent<AbilityMonoBehaviour>();
						list.Add(component);
						list3.Add(component);
						list2.Add(num);
					}
				}
				AppendExtraIndicators(clone, array);
				EnsureCooldownArray(clone);
				Fix[] field = GetField<Fix[]>(clone, "abilityCooldownTimers");
				for (int j = 0; j < list3.Count; j++)
				{
					AbilityMonoBehaviour val3 = list3[j];
					Revive val4 = (((Object)(object)val3 == (Object)null) ? null : ((Component)val3).GetComponent<Revive>());
					if ((Object)(object)val4 != (Object)null && player != null && (Object)(object)player.ReviveInstance != (Object)null && ((Object)val4).GetInstanceID() == ((Object)player.ReviveInstance).GetInstanceID() && field != null && field.Length > list2[j])
					{
						field[list2[j]] = Fix.Zero;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not restore the extra abilities on a clone: " + ex));
			}
		}

		internal static void CopyUiTreeAppearance(Component sourceRoot, Component targetRoot, Image sourceAbilityImage, Image targetAbilityImage)
		{
			if ((Object)(object)sourceRoot == (Object)null || (Object)(object)targetRoot == (Object)null)
			{
				return;
			}
			Image[] componentsInChildren = sourceRoot.GetComponentsInChildren<Image>(true);
			Image[] componentsInChildren2 = targetRoot.GetComponentsInChildren<Image>(true);
			int num = Math.Min(componentsInChildren.Length, componentsInChildren2.Length);
			for (int i = 0; i < num; i++)
			{
				if (!((Object)(object)componentsInChildren[i] == (Object)null) && !((Object)(object)componentsInChildren2[i] == (Object)null))
				{
					Sprite sprite = componentsInChildren2[i].sprite;
					CopyImageAppearance(componentsInChildren[i], componentsInChildren2[i]);
					if ((Object)(object)componentsInChildren2[i] == (Object)(object)targetAbilityImage || (Object)(object)componentsInChildren[i] == (Object)(object)sourceAbilityImage)
					{
						componentsInChildren2[i].sprite = sprite;
					}
				}
			}
		}

		internal static void BeforeMidGameSetPlayer(MidGameAbilitySelect selector, ref MidGameState state)
		{
			state = new MidGameState();
			if ((Object)(object)selector != (Object)null)
			{
				LossSelectorLiftApplied.Remove(((Object)selector).GetInstanceID());
			}
			try
			{
				Settings val = Settings.Get();
				FieldInfo fieldInfo = (((Object)(object)val == (Object)null) ? null : Field(((object)val).GetType(), "numberOfAbilities"));
				if ((Object)(object)val != (Object)null && fieldInfo != null)
				{
					int num = (int)fieldInfo.GetValue(val);
					state.Settings = val;
					state.RawAbilityCountField = fieldInfo;
					state.RawAbilityCount = num;
					if (num > 3)
					{
						fieldInfo.SetValue(val, 3);
						state.ChangedRawAbilityCount = true;
					}
				}
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("Could not temporarily vanilla-size SetPlayer's raw ability count: " + ex.Message));
			}
			RectTransform[] field = GetField<RectTransform[]>(selector, "Circles");
			if (field == null || field.Length <= 3)
			{
				return;
			}
			state.FullCircles = field;
			RectTransform[] array = (RectTransform[])(object)new RectTransform[3];
			for (int i = 0; i < 3; i++)
			{
				array[i] = field[i];
			}
			for (int j = 3; j < field.Length; j++)
			{
				if ((Object)(object)field[j] != (Object)null)
				{
					((Component)field[j]).gameObject.SetActive(false);
				}
			}
			SetField(selector, "Circles", array);
		}

		internal static void RestoreMidGameSetPlayer(MidGameAbilitySelect selector, MidGameState state)
		{
			if (state == null)
			{
				return;
			}
			if (state.FullCircles != null)
			{
				SetField(selector, "Circles", state.FullCircles);
			}
			if (!state.ChangedRawAbilityCount || !((Object)(object)state.Settings != (Object)null) || !(state.RawAbilityCountField != null))
			{
				return;
			}
			try
			{
				state.RawAbilityCountField.SetValue(state.Settings, state.RawAbilityCount);
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Could not restore raw NumberOfAbilities after SetPlayer: " + ex.Message));
			}
		}

		internal static void SetupMidGameSelector(MidGameAbilitySelect selector)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: 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)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: 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_019f: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)selector == (Object)null)
			{
				return;
			}
			Player field = GetField<Player>(selector, "player");
			if (field == null || field.Abilities == null || field.Abilities.Count <= 3)
			{
				return;
			}
			RectTransform[] field2 = GetField<RectTransform[]>(selector, "Circles");
			if (field2 == null || field2.Length < 3 || (Object)(object)field2[1] == (Object)null || (Object)(object)field2[2] == (Object)null)
			{
				return;
			}
			int count = field.Abilities.Count;
			RectTransform[] array = (RectTransform[])(object)new RectTransform[count];
			for (int i = 0; i < 3; i++)
			{
				array[i] = field2[i];
			}
			Vector2 val = field2[2].anchoredPosition - field2[1].anchoredPosition;
			if (((Vector2)(ref val)).sqrMagnitude < 0.0001f)
			{
				float field3 = GetField<float>(selector, "circleDistance");
				val = Vector2.down * ((Mathf.Abs(field3) > 0.01f) ? Mathf.Abs(field3) : 60f);
			}
			float stepMagnitude = Mathf.Abs(val.y);
			for (int j = 3; j < count; j++)
			{
				RectTransform val2 = ((j < field2.Length) ? field2[j] : null);
				if ((Object)(object)val2 == (Object)null)
				{
					GameObject val3 = Object.Instantiate<GameObject>(((Component)field2[2]).gameObject, ((Transform)field2[2]).parent);
					((Object)val3).name = "Extra Between-Round Ability Circle " + (j + 1);
					val3.transform.SetSiblingIndex(((Transform)field2[2]).GetSiblingIndex() + (j - 2));
					val2 = val3.GetComponent<RectTransform>();
					if ((Object)(object)val2 == (Object)null)
					{
						Object.Destroy((Object)(object)val3);
						return;
					}
				}
				val2.anchoredPosition = field2[2].anchoredPosition + val * (float)(j - 2);
				((Transform)val2).localScale = ((Transform)field2[2]).localScale;
				((Component)val2).gameObject.SetActive(((Component)field2[2]).gameObject.activeSelf);
				array[j] = val2;
				InstallMidGamePointer(selector, val2, j);
			}
			for (int k = count; k < field2.Length; k++)
			{
				if ((Object)(object)field2[k] != (Object)null)
				{
					((Component)field2[k]).gameObject.SetActive(false);
				}
			}
			SetField(selector, "Circles", array);
			PrepareMidGameSelector(selector, field, array);
			AbilitySelectController componentInParent = ((Component)selector).GetComponentInParent<AbilitySelectController>();
			EnsureAbilitySelectAnimationTargets(componentInParent);
			LiftLossSelector(selector, componentInParent, stepMagnitude, count);
			Image[] field4 = GetField<Image[]>(selector, "CircleImages");
			MidGameRowFollower midGameRowFollower = ((Component)selector).GetComponent<MidGameRowFollower>();
			if ((Object)(object)midGameRowFollower == (Object)null)
			{
				midGameRowFollower = ((Component)selector).gameObject.AddComponent<MidGameRowFollower>();
			}
			midGameRowFollower.Third = array[2];
			midGameRowFollower.ThirdImage = ((field4 != null && field4.Length > 2) ? field4[2] : null);
			int num = count - 3;
			midGameRowFollower.Extras = (RectTransform[])(object)new RectTransform[num];
			midGameRowFollower.ExtraImages = (Image[])(object)new Image[num];
			for (int l = 0; l < num; l++)
			{
				midGameRowFollower.Extras[l] = array[3 + l];
				midGameRowFollower.ExtraImages[l] = ((field4 != null && field4.Length > 3 + l) ? field4[3 + l] : null);
			}
		}

		internal static void InstallMidGamePointer(MidGameAbilitySelect selector, RectTransform circle, int row)
		{
			if ((Object)(object)selector == (Object)null || (Object)(object)circle == (Object)null)
			{
				return;
			}
			bool flag = false;
			CallOnHover[] componentsInChildren = ((Component)circle).GetComponentsInChildren<CallOnHover>(true);
			foreach (CallOnHover val in componentsInChildren)
			{
				if ((Object)(object)val != (Object)null && EventCalls(val.onHover, "HoverCircle"))
				{
					GameObject gameObject = ((Component)val).gameObject;
					Object.Destroy((Object)(object)val);
					MidGamePointer midGamePointer = gameObject.GetComponent<MidGamePointer>();
					if ((Object)(object)midGamePointer == (Object)null)
					{
						midGamePointer = gameObject.AddComponent<MidGamePointer>();
					}
					midGamePointer.Selector = selector;
					midGamePointer.Row = row;
					flag = true;
				}
			}
			if (!flag)
			{
				MidGamePointer midGamePointer2 = ((Component)circle).GetComponent<MidGamePointer>();
				if ((Object)(object)midGamePointer2 == (Object)null)
				{
					midGamePointer2 = ((Component)circle).gameObject.AddComponent<MidGamePointer>();
				}
				midGamePointer2.Selector = selector;
				midGamePointer2.Row = row;
			}
		}

		private static Image MatchingClonedCircleImage(RectTransform sourceCircle, RectTransform cloneCircle, Image sourceImage)
		{
			if ((Object)(object)sourceCircle == (Object)null || (Object)(object)cloneCircle == (Object)null)
			{
				return null;
			}
			if (((Transform)cloneCircle).childCount > 0)
			{
				Image component = ((Component)((Transform)cloneCircle).GetChild(0)).GetComponent<Image>();
				if ((Object)(object)component != (Object)null)
				{
					return component;
				}
			}
			Image[] componentsInChildren = ((Component)sourceCircle).GetComponentsInChildren<Image>(true);
			Image[] componentsInChildren2 = ((Component)cloneCircle).GetComponentsInChildren<Image>(true);
			if ((Object)(object)sourceImage != (Object)null)
			{
				int num = Math.Min(componentsInChildren.Length, componentsInChildren2.Length);
				for (int i = 0; i < num; i++)
				{
					if ((Object)(object)componentsInChildren[i] == (Object)(object)sourceImage)
					{
						return componentsInChildren2[i];
					}
				}
			}
			Image component2 = ((Component)cloneCircle).GetComponent<Image>();
			if ((Object)(object)component2 != (Object)null)
			{
				return component2;
			}
			if (componentsInChildren2.Length == 0)
			{
				return null;
			}
			return componentsInChildren2[0];
		}

		private static void PrepareMidGameSelector(MidGameAbilitySelect selector, Player player, RectTransform[] circles)
		{
			NamedSpriteList field = GetField<NamedSpriteList>(selector, "localAbilityIcons");
			if ((Object)(object)field == (Object)null || circles == null || circles.Length <= 3)
			{
				return;
			}
			int num = circles.Length;
			Image[] field2 = GetField<Image[]>(selector, "CircleImages");
			int[] field3 = GetField<int[]>(selector, "XPos");
			Image[] array = (Image[])(object)new Image[num];
			int[] array2 = new int[num];
			for (int i = 0; i < 3; i++)
			{
				array[i] = ((field2 != null && field2.Length > i) ? field2[i] : null);
				array2[i] = ((field3 == null || field3.Length <= i) ? 1 : field3[i]);
			}
			Image sourceImage = ((field2 != null && field2.Length > 2) ? field2[2] : null);
			for (int j = 3; j < num; j++)
			{
				array[j] = MatchingClonedCircleImage(circles[2], circles[j], sourceImage);
				int num2 = 1;
				if (player.Abilities.Count > j && (Object)(object)player.Abilities[j] != (Object)null)
				{
					num2 = field.IndexOf(((Object)player.Abilities[j]).name);
				}
				if (num2 <= 0 || field.sprites == null || num2 >= field.sprites.Count)
				{
					num2 = 1;
				}
				array2[j] = num2;
				if ((Object)(object)array[j] != (Object)null)
				{
					array[j].sprite = field.GetSprite(num2);
				}
			}
			SetField(selector, "CircleImages", array);
			SetField(selector, "XPos", array2);
			selector.SyncArrowPositionToCurrentYPos();
		}

		internal static void EnsureAbilitySelectAnimationTargets(AbilitySelectController controller)
		{
			//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_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00ae: 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_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: 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_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			MidGameAbilitySelect field = GetField<MidGameAbilitySelect>(controller, "abilityCirclesParent");
			RectTransform[] array = (((Object)(object)field == (Object)null) ? null : GetField<RectTransform[]>(field, "Circles"));
			if (array == null || array.Length < 4)
			{
				return;
			}
			Vector2[] field2 = GetField<Vector2[]>(controller, "abilityListOriginalPositions");
			if (field2 != null && field2.Length >= array.Length)
			{
				return;
			}
			Vector2[] array2 = (Vector2[])(object)new Vector2[array.Length];
			int num = ((field2 != null) ? Math.Min(field2.Length, array2.Length) : 0);
			for (int i = 0; i < num; i++)
			{
				array2[i] = field2[i];
			}
			for (int j = num; j < array2.Length; j++)
			{
				if (j >= 3)
				{
					Vector2 val = array2[j - 1];
					Vector2 val2 = val - array2[j - 2];
					if (((Vector2)(ref val2)).sqrMagnitude < 0.0001f && (Object)(object)array[j - 1] != (Object)null && (Object)(object)array[j - 2] != (Object)null)
					{
						val2 = array[j - 1].anchoredPosition - array[j - 2].anchoredPosition;
					}
					array2[j] = val + val2;
				}
				else
				{
					array2[j] = (((Object)(object)array[j] == (Object)null) ? Vector2.zero : array[j].anchoredPosition);
				}
			}
			SetField(controller, "abilityListOriginalPositions", array2);
		}

		private static void LiftLossSelector(MidGameAbilitySelect selector, AbilitySelectController owner, float stepMagnitude, int total)
		{
			//IL_0063: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)selector == (Object)null)
			{
				return;
			}
			int instanceID = ((Object)selector).GetInstanceID();
			if (!LossSelectorLiftApplied.Add(instanceID))
			{
				return;
			}
			float num = ((total > 4) ? ((float)(total - 4) * 0.5f * stepMagnitude) : 0f);
			float num2 = 34f + num;
			RectTransform[] field = GetField<RectTransform[]>(selector, "Circles");
			if (field != null)
			{
				for (int i = 0; i < field.Length; i++)
				{
					if ((Object)(object)field[i] != (Object)null)
					{
						Vector2 anchoredPosition = field[i].anchoredPosition;
						anchoredPosition.y += num2;
						field[i].anchoredPosition = anchoredPosition;
					}
				}
			}
			if (!((Object)(object)owner != (Object)null))
			{
				return;
			}
			Vector2[] field2 = GetField<Vector2[]>(owner, "abilityListOriginalPositions");
			if (field2 != null)
			{
				for (int j = 0; j < field2.Length; j++)
				{
					field2[j].y += num2;
				}
				SetField(owner, "abilityListOriginalPositions", field2);
			}
		}

		internal static void LiftOpenLossAbilityCircles(AbilitySelectController controller)
		{
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: 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)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)controller == (Object)null)
			{
				return;
			}
			bool field = GetField<bool>(controller, "isOpen");
			MidGameAbilitySelect field2 = GetField<MidGameAbilitySelect>(controller, "abilityCirclesParent");
			RectTransform[] array = (((Object)(object)field2 == (Object)null) ? null : GetField<RectTransform[]>(field2, "Circles"));
			LossCircleLiftState lossCircleLiftState = ((Component)controller).GetComponent<LossCircleLiftState>();
			if ((Object)(object)lossCircleLiftState == (Object)null)
			{
				lossCircleLiftState = ((Component)controller).gameObject.AddComponent<LossCircleLiftState>();
			}
			if (array == null || array.Length < 4 || !field)
			{
				lossCircleLiftState.Applied = false;
				lossCircleLiftState.Circles = array;
				return;
			}
			if (lossCircleLiftState.Circles != array || lossCircleLiftState.BasePositions == null || lossCircleLiftState.ShiftedPositions == null || lossCircleLiftState.BasePositions.Length != array.Length || lossCircleLiftState.ShiftedPositions.Length != array.Length)
			{
				lossCircleLiftState.Circles = array;
				lossCircleLiftState.BasePositions = (Vector2[])(object)new Vector2[array.Length];
				lossCircleLiftState.ShiftedPositions = (Vector2[])(object)new Vector2[array.Length];
				lossCircleLiftState.Applied = false;
			}
			for (int i = 0; i < array.Length; i++)
			{
				RectTransform val = array[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				Vector2 anchoredPosition = val.anchoredPosition;
				if (lossCircleLiftState.Applied)
				{
					Vector2 val2 = anchoredPosition - lossCircleLiftState.ShiftedPositions[i];
					if (((Vector2)(ref val2)).sqrMagnitude <= 0.25f)
					{
						goto IL_0135;
					}
				}
				lossCircleLiftState.BasePositions[i] = anchoredPosition;
				goto IL_0135;
				IL_0135:
				Vector2 val3 = lossCircleLiftState.BasePositions[i];
				val3.y += 105f;
				val.anchoredPosition = val3;
				lossCircleLiftState.ShiftedPositions[i] = val3;
			}
			lossCircleLiftState.Applied = true;
		}

		internal static void LiftOpenLossSelectorArrow(AbilitySelectController controller)
		{
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_0128: Unknown result type