Decompiled source of RiskOfPVP v1.1.12

plugins/ArenaPvP/ArenaPvP.dll

Decompiled 4 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Text;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using EntityStates;
using EntityStates.InfiniteTowerSafeWard;
using EntityStates.Seeker;
using EntityStates.Toolbot;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using R2API;
using R2API.Utils;
using RiskOfOptions;
using RiskOfOptions.Components.Options;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.Artifacts;
using RoR2.CharacterAI;
using RoR2.Items;
using RoR2.Navigation;
using RoR2.Networking;
using RoR2.Projectile;
using RoR2.Skills;
using RoR2.UI;
using TMPro;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.Rendering.PostProcessing;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyInformationalVersion("1.1.12")]
[assembly: AssemblyCompany("claytemplar")]
[assembly: AssemblyVersion("1.1.12.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace ArenaPvP
{
	internal static class ArenaAbilityDiagnostics
	{
		private static readonly FieldInfo age = AccessTools.Field(typeof(SojournVehicleBase), "age");

		private static readonly FieldInfo overlap = AccessTools.Field(typeof(SojournVehicleBase), "overlapAttack");

		private static readonly HashSet<int> logged = new HashSet<int>();

		private static Run run;

		internal static void EarlyExit(VehicleSeat seat, Collision collision = null)
		{
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Expected I4, but got Unknown
			//IL_0288: Unknown result type (might be due to invalid IL or missing references)
			//IL_028f: Expected I4, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Expected I4, but got Unknown
			try
			{
				SojournVehicleBase val = (Object.op_Implicit((Object)(object)seat) ? ((Component)seat).GetComponent<SojournVehicleBase>() : null);
				CharacterBody val2 = (Object.op_Implicit((Object)(object)seat) ? seat.currentPassengerBody : null);
				if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val2) || age == null)
				{
					return;
				}
				float num = (float)age.GetValue(val);
				if (num > 1.5f)
				{
					return;
				}
				if ((Object)(object)run != (Object)(object)Run.instance)
				{
					logged.Clear();
					run = Run.instance;
				}
				if (logged.Count >= 256)
				{
					logged.Clear();
				}
				if (logged.Add(((Object)seat).GetInstanceID()))
				{
					OverlapAttack val3 = (OverlapAttack)((overlap == null) ? null : /*isinst with value type is only supported in some contexts*/);
					CharacterBody val4 = ((val3 != null && Object.op_Implicit((Object)(object)val3.lastHitObject)) ? val3.lastHitObject.GetComponentInParent<CharacterBody>() : null);
					HealthComponent healthComponent = val2.healthComponent;
					string text = string.Join(" > ", new StackTrace(fNeedFileInfo: false).GetFrames().Take(12).Select(delegate(StackFrame frame)
					{
						MethodBase method = frame.GetMethod();
						return ((method.DeclaringType == null) ? "" : (method.DeclaringType.Name + ".")) + method.Name;
					})
						.ToArray());
					Plugin.Log("Ability early exit: " + ((object)val).GetType().Name + "; role=" + (NetworkServer.active ? "server" : "client") + "; age=" + num.ToString("0.000", CultureInfo.InvariantCulture) + "; barrier=" + (Object.op_Implicit((Object)(object)healthComponent) ? (healthComponent.barrier + "/" + healthComponent.fullBarrier + "; fullHealth=" + healthComponent.fullHealth) : "missing") + "; utilityHeld=" + ((Object)(object)seat.currentPassengerInputBank != (Object)null && seat.currentPassengerInputBank.skill3.down) + "; bodyTeam=" + (Object.op_Implicit((Object)(object)val2.teamComponent) ? ((int)val2.teamComponent.teamIndex).ToString() : "none") + "; attackTeam=" + ((val3 == null) ? "none" : ((int)val3.teamIndex).ToString()) + "; lastHit=" + (Object.op_Implicit((Object)(object)val4) ? (((Object)val4).name + "/team=" + (Object.op_Implicit((Object)(object)val4.teamComponent) ? ((int)val4.teamComponent.teamIndex).ToString() : "none")) : "none") + "; collision=" + ((collision != null && Object.op_Implicit((Object)(object)collision.collider)) ? (((Object)collision.collider).name + "/layer=" + ((Component)collision.collider).gameObject.layer) : "none") + "; nativePath=" + text);
				}
			}
			catch (Exception ex)
			{
				Plugin.Warn("Ability exit trace unavailable: " + ex.Message);
			}
		}
	}
	[HarmonyPatch(typeof(VehicleSeat), "CallCmdEjectPassenger")]
	internal static class TraceArenaVehicleEjectRequest
	{
		private static void Prefix(VehicleSeat __instance)
		{
			if (Plugin.Active)
			{
				ArenaAbilityDiagnostics.EarlyExit(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(VehicleSeat), "SetPassengerInternal")]
	internal static class TraceArenaVehicleRemoval
	{
		private static void Prefix(VehicleSeat __instance, GameObject newPassengerBodyObject)
		{
			if (Plugin.Active && !Object.op_Implicit((Object)(object)newPassengerBodyObject))
			{
				ArenaAbilityDiagnostics.EarlyExit(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(SojournVehicleBase), "OnCollisionEnter")]
	internal static class TraceArenaFlightCollision
	{
		private static void Prefix(SojournVehicleBase __instance, Collision collision)
		{
			if (Plugin.Active && __instance.detonateOnCollision && Util.HasEffectiveAuthority(((Component)__instance).GetComponent<NetworkIdentity>()))
			{
				ArenaAbilityDiagnostics.EarlyExit(((Component)__instance).GetComponent<VehicleSeat>(), collision);
			}
		}
	}
	internal sealed class ArenaAeroltCompatibility : MonoBehaviour
	{
		private static ArenaAeroltCompatibility instance;

		private readonly DeferredMenuStartup startup = new DeferredMenuStartup();

		private readonly object[] keyArgument = new object[1];

		private static readonly object[] visibleArgument = new object[1] { true };

		private Harmony patches;

		private MethodInfo isReady;

		private MethodInfo bootstrap;

		private MethodInfo setVisible;

		private MethodInfo getKeyPressed;

		private FieldInfo keyBindings;

		private object menuKey;

		private bool installed;

		private void Awake()
		{
			instance = this;
			RoR2Application.onLoad = (Action)Delegate.Combine(RoR2Application.onLoad, new Action(Install));
		}

		private void Install()
		{
			//IL_026c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Expected O, but got Unknown
			//IL_028d: Unknown result type (might be due to invalid IL or missing references)
			//IL_029b: Expected O, but got Unknown
			if (!Chainloader.PluginInfos.TryGetValue("com.Lodington.Aerolt", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
			{
				return;
			}
			if (value.Metadata.Version.ToString() != "4.3.1")
			{
				Plugin.Warn("Optional Aerolt adapter: unverified version; native startup retained.");
				return;
			}
			try
			{
				Type type = ((object)value.Instance).GetType();
				Type type2 = type.Assembly.GetType("Aerolt.UI.AeroltUniverseUI", throwOnError: true);
				MethodInfo method = type.GetMethod("OnRunStart", BindingFlags.Static | BindingFlags.NonPublic, null, new Type[1] { typeof(Run) }, null);
				isReady = type2.GetProperty("IsReady", BindingFlags.Static | BindingFlags.Public)?.GetGetMethod();
				bootstrap = type2.GetMethod("Bootstrap", BindingFlags.Static | BindingFlags.Public, null, Type.EmptyTypes, null);
				setVisible = type2.GetMethod("SetVisible", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { typeof(bool) }, null);
				keyBindings = type.GetField("KeyBinds", BindingFlags.Static | BindingFlags.Public);
				Type[] array = keyBindings?.FieldType.GetGenericArguments();
				if (array == null || array.Length != 2 || !array[0].IsEnum || !typeof(IDictionary).IsAssignableFrom(keyBindings.FieldType))
				{
					throw new InvalidOperationException("Unverified public keybind contract.");
				}
				menuKey = Enum.Parse(array[0], "OpenMenu");
				getKeyPressed = type.GetMethod("GetKeyPressed", BindingFlags.Static | BindingFlags.Public, null, new Type[1] { array[1] }, null);
				if (method == null || method.ReturnType != typeof(void) || isReady == null || isReady.ReturnType != typeof(bool) || bootstrap == null || bootstrap.ReturnType != typeof(void) || setVisible == null || setVisible.ReturnType != typeof(void) || getKeyPressed == null || getKeyPressed.ReturnType != typeof(bool))
				{
					throw new InvalidOperationException("Unverified Aerolt menu API.");
				}
				patches = new Harmony("com.fireb.arenapvp.optional-aerolt-menu");
				patches.Patch((MethodBase)method, new HarmonyMethod(typeof(ArenaAeroltCompatibility), "BeforeRunStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				installed = true;
				Plugin.Log("Optional Aerolt adapter enabled: Arena defers the menu until its configured open key is pressed.");
			}
			catch (Exception error)
			{
				Stop(error);
			}
		}

		private static bool BeforeRunStart()
		{
			if (!Object.op_Implicit((Object)(object)instance) || !instance.installed)
			{
				return true;
			}
			try
			{
				return instance.startup.OnRunStarting(Plugin.Active, instance.Ready());
			}
			catch (Exception error)
			{
				instance.Stop(error);
				return true;
			}
		}

		private bool Ready()
		{
			return (bool)isReady.Invoke(null, null);
		}

		private void Update()
		{
			if (!installed || !startup.Waiting)
			{
				return;
			}
			try
			{
				if (Ready())
				{
					if (startup.Complete(ready: true))
					{
						setVisible.Invoke(null, visibleArgument);
					}
					return;
				}
				IDictionary dictionary = keyBindings.GetValue(null) as IDictionary;
				keyArgument[0] = dictionary?[menuKey];
				bool pressed = keyArgument[0] != null && (bool)getKeyPressed.Invoke(null, keyArgument);
				if (startup.Request(pressed))
				{
					Plugin.Log("Aerolt menu requested: invoking its public Bootstrap API; native initialization may pause on first use.");
					bootstrap.Invoke(null, null);
				}
			}
			catch (Exception error)
			{
				Stop(error);
			}
		}

		private void Stop(Exception error)
		{
			installed = false;
			startup.Reset();
			if (patches != null)
			{
				patches.UnpatchSelf();
			}
			Plugin.Warn("Optional Aerolt adapter disabled; native startup retained: " + (error.InnerException ?? error).Message);
		}

		private void OnDestroy()
		{
			RoR2Application.onLoad = (Action)Delegate.Remove(RoR2Application.onLoad, new Action(Install));
			startup.Reset();
			installed = false;
			if (patches != null)
			{
				patches.UnpatchSelf();
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}
	}
	internal static class ArenaArtwork
	{
		private static readonly Dictionary<int, AsyncOperationHandle<Texture>> maps = new Dictionary<int, AsyncOperationHandle<Texture>>();

		private static readonly Dictionary<int, Sprite> mapSprites = new Dictionary<int, Sprite>();

		private static readonly Dictionary<int, AsyncOperationHandle<Sprite>> pickups = new Dictionary<int, AsyncOperationHandle<Sprite>>();

		internal static Sprite Map(int index)
		{
			//IL_00b6: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Invalid comparison between Unknown and I4
			if (mapSprites.TryGetValue(index, out var value))
			{
				return value;
			}
			SceneDef sceneDef = SceneCatalog.GetSceneDef((SceneIndex)index);
			if (!Object.op_Implicit((Object)(object)sceneDef))
			{
				return null;
			}
			Texture2D val = null;
			AssetReferenceTexture previewTextureReference = sceneDef.previewTextureReference;
			if (previewTextureReference != null && ((AssetReference)previewTextureReference).RuntimeKeyIsValid())
			{
				if (!maps.TryGetValue(index, out var value2))
				{
					value2 = Addressables.LoadAssetAsync<Texture>(((AssetReference)previewTextureReference).RuntimeKey);
					maps.Add(index, value2);
				}
				if (value2.IsDone && (int)value2.Status == 1)
				{
					Texture result = value2.Result;
					val = (Texture2D)(object)((result is Texture2D) ? result : null);
				}
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				Texture previewTexture = sceneDef.previewTexture;
				val = (Texture2D)(object)((previewTexture is Texture2D) ? previewTexture : null);
			}
			if (!Object.op_Implicit((Object)(object)val))
			{
				return null;
			}
			value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			mapSprites.Add(index, value);
			return value;
		}

		internal static Sprite Pickup(int index)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Invalid comparison between Unknown and I4
			PickupDef pickupDef = PickupCatalog.GetPickupDef(new PickupIndex(index));
			if (pickupDef == null)
			{
				return null;
			}
			if (Object.op_Implicit((Object)(object)pickupDef.iconSprite))
			{
				return pickupDef.iconSprite;
			}
			AssetReferenceT<Sprite> iconSpriteReference = pickupDef.iconSpriteReference;
			if (iconSpriteReference == null || !((AssetReference)iconSpriteReference).RuntimeKeyIsValid())
			{
				return null;
			}
			if (!pickups.TryGetValue(index, out var value))
			{
				value = Addressables.LoadAssetAsync<Sprite>(((AssetReference)iconSpriteReference).RuntimeKey);
				pickups.Add(index, value);
			}
			if (!value.IsDone || (int)value.Status != 1)
			{
				return null;
			}
			return value.Result;
		}

		internal static void Dispose()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			foreach (Sprite value in mapSprites.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					Object.Destroy((Object)(object)value);
				}
			}
			foreach (AsyncOperationHandle<Texture> value2 in maps.Values)
			{
				if (value2.IsValid())
				{
					Addressables.Release<Texture>(value2);
				}
			}
			foreach (AsyncOperationHandle<Sprite> value3 in pickups.Values)
			{
				if (value3.IsValid())
				{
					Addressables.Release<Sprite>(value3);
				}
			}
			maps.Clear();
			mapSprites.Clear();
			pickups.Clear();
		}
	}
	internal sealed class ArenaOptionArt : MonoBehaviour
	{
		internal Image Image;

		private int pickup = -1;

		internal void Bind(int index)
		{
			pickup = index;
			Image.sprite = null;
			((Behaviour)Image).enabled = false;
			Refresh();
		}

		internal void Set(Sprite sprite)
		{
			pickup = -1;
			Image.sprite = sprite;
			((Behaviour)Image).enabled = Object.op_Implicit((Object)(object)sprite);
		}

		private void LateUpdate()
		{
			Refresh();
		}

		private void Refresh()
		{
			if (pickup >= 0 && Object.op_Implicit((Object)(object)Image))
			{
				Sprite val = ArenaArtwork.Pickup(pickup);
				if (Object.op_Implicit((Object)(object)val))
				{
					Image.sprite = val;
					((Behaviour)Image).enabled = true;
				}
			}
		}
	}
	internal static class ArenaBeadExperience
	{
		internal static void LevelsGained(ArenaPlayer player, int previous, int current)
		{
			if (Plugin.Active && NetworkServer.active && Object.op_Implicit((Object)(object)player.Master) && Object.op_Implicit((Object)(object)player.Master.inventory))
			{
				player.BeadExperience.Record(previous, current, player.Master.inventory.GetItemCountEffective(Items.ExtraStatsOnLevelUp) > 0, (Func<uint, ulong>)TeamManager.GetExperienceForLevel);
				Flush(player);
			}
		}

		internal static void Flush(ArenaPlayer player)
		{
			if (Plugin.Active && NetworkServer.active && Object.op_Implicit((Object)(object)player.Master) && Object.op_Implicit((Object)(object)TeamManager.instance))
			{
				CharacterBody body = player.Master.GetBody();
				player.BeadExperience.Drain(Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body.healthComponent) && body.healthComponent.alive, (Action<ulong>)player.Master.TrackBeadExperience);
			}
		}
	}
	[HarmonyPatch(typeof(CharacterBody), "RecalculateStats")]
	internal static class ArenaBeadStats
	{
		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			List<CodeInstruction> list = instructions.ToList();
			MethodInfo methodInfo = AccessTools.PropertyGetter(typeof(TeamComponent), "teamIndex");
			MethodInfo operand = AccessTools.Method(typeof(ArenaBeadStats), "TeamForBeadStats", (Type[])null, (Type[])null);
			HashSet<string> hashSet = new HashSet<string> { "beadAppliedHealth", "beadAppliedShield", "beadAppliedRegen", "beadAppliedDamage" };
			int num = 0;
			for (int i = 0; i + 2 < list.Count; i++)
			{
				if (!CodeInstructionExtensions.Calls(list[i], methodInfo) || list[i + 1].opcode != OpCodes.Ldc_I4_1 || list[i + 2].opcode.FlowControl != FlowControl.Cond_Branch)
				{
					continue;
				}
				bool flag = false;
				for (int j = i + 3; j < Math.Min(list.Count, i + 30) && !CodeInstructionExtensions.Calls(list[j], methodInfo); j++)
				{
					FieldInfo fieldInfo = list[j].operand as FieldInfo;
					if (fieldInfo != null && fieldInfo.DeclaringType == typeof(Inventory) && hashSet.Contains(fieldInfo.Name))
					{
						hashSet.Remove(fieldInfo.Name);
						flag = true;
						break;
					}
				}
				if (flag)
				{
					list[i].opcode = OpCodes.Call;
					list[i].operand = operand;
					num++;
				}
			}
			if (num != 4)
			{
				throw new InvalidOperationException("Native Prayer Beads stat clauses changed; expected four isolated team checks.");
			}
			return list;
		}

		internal static TeamIndex TeamForBeadStats(TeamComponent component)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			TeamIndex teamIndex = component.teamIndex;
			if (!Plugin.Active || !ArenaTeams.IsArenaTeam(teamIndex))
			{
				return teamIndex;
			}
			CharacterBody component2 = ((Component)component).GetComponent<CharacterBody>();
			if (Object.op_Implicit((Object)(object)component2) && (ArenaTeams.IsCombatantBody(component2) || Object.op_Implicit((Object)(object)ArenaMatch.PlayerOwner(component2.master))))
			{
				return (TeamIndex)1;
			}
			return teamIndex;
		}
	}
	internal sealed class ArenaBlacklistSettings : MonoBehaviour
	{
		private sealed class Entry
		{
			internal string Name;

			internal string Title;

			internal int Pickup;

			internal int Category;

			internal bool Reserved;

			internal bool Internal;
		}

		private const int Columns = 12;

		private const int PageSize = 72;

		private static ArenaBlacklistSettings instance;

		private ConfigEntry<string> setting;

		private bool requireHost;

		private bool readOnly;

		private bool equipment;

		private BlacklistSelection selection;

		private Entry[] catalog;

		private Entry[] filtered;

		private Entry[] shown = new Entry[72];

		private int page;

		private int filter;

		private bool bannedOnly;

		private Entry selected;

		private TMP_Text heading;

		private TMP_Text pageLabel;

		private TMP_Text status;

		private TMP_InputField search;

		private TMP_Text[] names = (TMP_Text[])(object)new TMP_Text[72];

		private TMP_Text[] states = (TMP_Text[])(object)new TMP_Text[72];

		private TMP_Text[] limits = (TMP_Text[])(object)new TMP_Text[72];

		private ArenaOptionArt[] artwork = new ArenaOptionArt[72];

		private MPButton[] buttons;

		private MPButton previous;

		private MPButton next;

		private MPButton filterButton;

		private MPButton bannedButton;

		private MPButton apply;

		private MPButton back;

		private MPEventSystem eventSystem;

		private GameObject previousSelection;

		private GameObject canvasObject;

		private TMP_FontAsset font;

		internal static bool IsOpen => Object.op_Implicit((Object)(object)instance);

		internal static int LastClosedFrame { get; private set; } = -1;

		internal static void CloseOpen()
		{
			if (Object.op_Implicit((Object)(object)instance))
			{
				instance.Dismiss();
			}
		}

		internal static bool IsRule(string key)
		{
			string text = SettingsLayout.Title(key);
			if (!(text == "Banned internal item names"))
			{
				return text == "Banned internal equipment names";
			}
			return true;
		}

		internal static bool EquipmentRule(string key)
		{
			return SettingsLayout.Title(key) == "Banned internal equipment names";
		}

		internal static string RuleTitle(string key)
		{
			if (!EquipmentRule(key))
			{
				return "Item blacklist";
			}
			return "Equipment blacklist";
		}

		internal static void Open(ConfigEntry<string> entry, bool gear, bool hostOnly = false)
		{
			Create(entry, entry.Value, gear, hostOnly, viewOnly: false, ((ConfigEntryBase)entry).Definition.Section);
		}

		internal static void OpenReadOnly(string values, bool gear, string profile)
		{
			Create(null, values, gear, hostOnly: true, viewOnly: true, profile);
		}

		private static void Create(ConfigEntry<string> entry, string values, bool gear, bool hostOnly, bool viewOnly, string profile)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			if ((hostOnly && !ArenaLobby.Selected) || (hostOnly && !viewOnly && !NetworkServer.active))
			{
				return;
			}
			CloseOpen();
			instance = new GameObject("RiskOfArena Blacklist").AddComponent<ArenaBlacklistSettings>();
			instance.setting = entry;
			instance.requireHost = hostOnly;
			instance.readOnly = viewOnly;
			instance.equipment = gear;
			instance.selection = new BlacklistSelection(values);
			try
			{
				instance.Show(profile);
			}
			catch (Exception ex)
			{
				Plugin.Warn("Could not open item blacklist: " + ex);
				instance.Dismiss();
			}
		}

		private bool CanEdit()
		{
			if (!readOnly && setting != null)
			{
				if (requireHost)
				{
					if (NetworkServer.active && ArenaLobby.Selected)
					{
						return Plugin.Settings.MatchEntries.Contains((ConfigEntryBase)(object)setting);
					}
					return false;
				}
				return true;
			}
			return false;
		}

		private void Show(string profile)
		{
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Expected O, but got Unknown
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_041e: Unknown result type (might be due to invalid IL or missing references)
			//IL_044d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0453: Expected O, but got Unknown
			//IL_047b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0490: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ef: Expected O, but got Unknown
			//IL_062c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0636: Expected O, but got Unknown
			//IL_069d: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_070a: Unknown result type (might be due to invalid IL or missing references)
			//IL_071e: Unknown result type (might be due to invalid IL or missing references)
			//IL_096a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0974: Expected O, but got Unknown
			//IL_0a0c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a16: Expected O, but got Unknown
			//IL_0a6c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a73: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a85: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a9a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0aae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0acc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0ad6: Expected O, but got Unknown
			//IL_0b08: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b12: Expected O, but got Unknown
			//IL_0b48: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b52: Expected O, but got Unknown
			//IL_0b89: Unknown result type (might be due to invalid IL or missing references)
			//IL_0b93: Expected O, but got Unknown
			//IL_0bd7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0be1: Expected O, but got Unknown
			//IL_01e2: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Invalid comparison between Unknown and I4
			eventSystem = ((IEnumerable<MPEventSystem>)MPEventSystem.readOnlyInstancesList).FirstOrDefault((Func<MPEventSystem, bool>)((MPEventSystem e) => Object.op_Implicit((Object)(object)e)));
			if (Object.op_Implicit((Object)(object)eventSystem))
			{
				previousSelection = ((EventSystem)eventSystem).currentSelectedGameObject;
				MPEventSystem obj = eventSystem;
				int cursorOpenerCount = obj.cursorOpenerCount;
				obj.cursorOpenerCount = cursorOpenerCount + 1;
				MPEventSystem obj2 = eventSystem;
				cursorOpenerCount = obj2.cursorOpenerForGamepadCount;
				obj2.cursorOpenerForGamepadCount = cursorOpenerCount + 1;
			}
			PickupPickerController val = (Object.op_Implicit((Object)(object)CommandArtifactManager.commandCubePrefab) ? CommandArtifactManager.commandCubePrefab.GetComponent<PickupPickerController>() : null);
			PickupPickerPanel val2 = ((Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.panelPrefab)) ? val.panelPrefab.GetComponent<PickupPickerPanel>() : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				throw new InvalidOperationException("Command visual assets are not ready.");
			}
			font = (Object.op_Implicit((Object)(object)HGTextMeshProUGUI.defaultLanguageFont) ? HGTextMeshProUGUI.defaultLanguageFont : TMP_Settings.defaultFontAsset);
			List<Entry> list = new List<Entry>();
			for (int num = 0; num < (equipment ? EquipmentCatalog.equipmentCount : ItemCatalog.itemCount); num++)
			{
				ItemDef val3 = (equipment ? null : ItemCatalog.GetItemDef((ItemIndex)num));
				EquipmentDef val4 = (equipment ? EquipmentCatalog.GetEquipmentDef((EquipmentIndex)num) : null);
				if (!Object.op_Implicit((Object)(object)val3) && !Object.op_Implicit((Object)(object)val4))
				{
					continue;
				}
				PickupIndex val5 = (Object.op_Implicit((Object)(object)val3) ? PickupCatalog.FindPickupIndex(val3.itemIndex) : PickupCatalog.FindPickupIndex(val4.equipmentIndex));
				if (!(val5 == PickupIndex.none))
				{
					string text = (Object.op_Implicit((Object)(object)val3) ? ((Object)val3).name : ((Object)val4).name);
					string text2 = (Object.op_Implicit((Object)(object)val3) ? val3.nameToken : val4.nameToken);
					string text3 = Language.GetString(text2 ?? "");
					if (string.IsNullOrWhiteSpace(text3) || text3 == text2)
					{
						text3 = text;
					}
					list.Add(new Entry
					{
						Name = text,
						Title = text3,
						Pickup = val5.value,
						Category = ((!equipment) ? ((int)ItemPool.Category(val5.value)) : (val4.isLunar ? 3 : 5)),
						Internal = (Object.op_Implicit((Object)(object)val3) && (val3.hidden || (int)val3.tier == 5)),
						Reserved = (!equipment && (text == "LevelBonus" || text == "UseAmbientLevel"))
					});
				}
			}
			catalog = (from e in list
				orderby e.Internal, e.Category
				select e).ThenBy<Entry, string>((Entry e) => e.Title, StringComparer.CurrentCultureIgnoreCase).ToArray();
			canvasObject = new GameObject("Blacklist canvas", new Type[6]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster),
				typeof(MPEventSystemProvider),
				typeof(Image)
			});
			canvasObject.transform.SetParent(((Component)this).transform, false);
			Canvas component = canvasObject.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 200;
			CanvasScaler component2 = canvasObject.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1920f, 1080f);
			component2.matchWidthOrHeight = 0.5f;
			canvasObject.GetComponent<MPEventSystemProvider>().eventSystem = eventSystem;
			canvasObject.GetComponent<MPEventSystemProvider>().fallBackToMainEventSystem = true;
			((Graphic)canvasObject.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.5f);
			GameObject val6 = new GameObject("Blacklist panel", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val6.transform.SetParent(canvasObject.transform, false);
			RectTransform component3 = val6.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.05f, 0.05f);
			component3.anchorMax = new Vector2(0.95f, 0.95f);
			Vector2 val7 = (component3.offsetMin = (component3.offsetMax = Vector2.zero));
			((Graphic)val6.GetComponent<Image>()).color = new Color(0.04f, 0.07f, 0.09f, 0.92f);
			ArenaStyle.Border(val6, new Color(0.55f, 0.95f, 0.3f), 2f);
			heading = Label(val6.transform, (equipment ? "Equipment blacklist" : "Item blacklist") + " - " + profile.Substring(3), 32);
			Place(heading.rectTransform, 20f, 12f, -20f, 48f);
			heading.fontStyle = (FontStyles)3;
			Place(Label(val6.transform, readOnly ? "Host settings - view only. On: allowed. Off: banned. A number is the maximum held stack." : "Left-click: On / Off. Right-click: increase stack limit. Shift + right-click: decrease (zero removes the limit).\nOn allows rewards; Off bans them. Apply saves this mode; active hosts update immediately.", 19).rectTransform, 20f, 65f, -20f, 54f);
			search = Search(val6.transform);
			Place(((Component)search).GetComponent<RectTransform>(), 40f, 130f, -590f, 44f);
			filterButton = Button(val6.transform, "All rarities", (UnityAction)delegate
			{
				filter = (filter + 1) % (equipment ? 3 : 8);
				Refilter();
			});
			Place(((Component)filterButton).GetComponent<RectTransform>(), 1160f, 130f, -280f, 44f);
			bannedButton = Button(val6.transform, "Show all", (UnityAction)delegate
			{
				bannedOnly = !bannedOnly;
				Refilter();
			});
			Place(((Component)bannedButton).GetComponent<RectTransform>(), 1460f, 130f, -40f, 44f);
			ArenaCommandPanel arenaCommandPanel = ArenaCommandPanel.Create(val6, val2);
			arenaCommandPanel.maxColumnCount = 12;
			arenaCommandPanel.gridlayoutGroup.constraint = (Constraint)1;
			arenaCommandPanel.gridlayoutGroup.constraintCount = 12;
			arenaCommandPanel.gridlayoutGroup.cellSize = new Vector2(122f, 88f);
			arenaCommandPanel.gridlayoutGroup.spacing = new Vector2(8f, 8f);
			RectTransform buttonContainer = arenaCommandPanel.buttonContainer;
			((Vector2)(ref val7))..ctor(0.5f, 1f);
			buttonContainer.anchorMax = val7;
			buttonContainer.anchorMin = val7;
			buttonContainer.pivot = new Vector2(0.5f, 1f);
			buttonContainer.anchoredPosition = new Vector2(0f, -193f);
			buttonContainer.sizeDelta = new Vector2(1552f, 568f);
			buttons = arenaCommandPanel.Populate(Enumerable.Range(0, 72).Select((Func<int, Option>)((int i) => new Option
			{
				available = true
			})).ToArray());
			for (int num2 = 0; num2 < 72; num2++)
			{
				int index = num2;
				artwork[num2] = ((Component)buttons[num2]).GetComponentInParent<ArenaOptionArt>();
				ArenaStyle.Fill(((Graphic)artwork[num2].Image).rectTransform, 20f, 6f, 20f, 27f);
				names[num2] = Label(((Component)buttons[num2]).transform.parent, "", 13);
				Place(names[num2].rectTransform, 3f, 62f, -3f, 23f);
				names[num2].enableAutoSizing = true;
				names[num2].fontSizeMin = 10f;
				names[num2].fontSizeMax = 13f;
				names[num2].richText = false;
				states[num2] = Label(((Component)buttons[num2]).transform.parent, "", 13);
				Place(states[num2].rectTransform, 3f, 1f, -84f, 20f);
				limits[num2] = Label(((Component)buttons[num2]).transform.parent, "", 22);
				limits[num2].alignment = (TextAlignmentOptions)1028;
				limits[num2].enableAutoSizing = true;
				limits[num2].fontSizeMin = 10f;
				limits[num2].fontSizeMax = 22f;
				ArenaStyle.Fill(limits[num2].rectTransform, 60f, 38f, 5f, 24f);
				limits[num2].fontStyle = (FontStyles)1;
				((UnityEvent)((Button)buttons[num2]).onClick).AddListener((UnityAction)delegate
				{
					Toggle(index);
				});
				ArenaBlacklistRightClick arenaBlacklistRightClick = ((Component)buttons[num2]).gameObject.AddComponent<ArenaBlacklistRightClick>();
				arenaBlacklistRightClick.Clicked = delegate
				{
					Adjust(index, (!Input.GetKey((KeyCode)304) && !Input.GetKey((KeyCode)303)) ? 1 : (-1));
				};
				arenaBlacklistRightClick.Selected = delegate
				{
					selected = shown[index];
					RefreshStatus();
				};
			}
			status = Label(val6.transform, "", 17);
			Place(status.rectTransform, 25f, 775f, -25f, 34f);
			previous = Button(val6.transform, "Previous", (UnityAction)delegate
			{
				page--;
				RefreshPage();
			});
			Footer(previous, -610f, 92f, 210f);
			pageLabel = Label(val6.transform, "", 18);
			RectTransform rectTransform = pageLabel.rectTransform;
			((Vector2)(ref val7))..ctor(0.5f, 0f);
			rectTransform.anchorMax = val7;
			rectTransform.anchorMin = val7;
			rectTransform.pivot = new Vector2(0.5f, 0f);
			rectTransform.anchoredPosition = new Vector2(0f, 99f);
			rectTransform.sizeDelta = new Vector2(440f, 30f);
			next = Button(val6.transform, "Next", (UnityAction)delegate
			{
				page++;
				RefreshPage();
			});
			Footer(next, 610f, 92f, 210f);
			MPButton obj3 = Button(val6.transform, "Limit -", (UnityAction)delegate
			{
				AdjustSelected(-1);
			});
			Footer(obj3, -600f, 26f, 170f);
			((Selectable)obj3).interactable = !readOnly;
			MPButton obj4 = Button(val6.transform, "Limit +", (UnityAction)delegate
			{
				AdjustSelected(1);
			});
			Footer(obj4, -410f, 26f, 170f);
			((Selectable)obj4).interactable = !readOnly;
			back = Button(val6.transform, "Back", new UnityAction(Dismiss));
			Footer(back, (!readOnly) ? 100 : 0, 26f, 240f);
			if (!readOnly)
			{
				apply = Button(val6.transform, "Apply", new UnityAction(Save));
				Footer(apply, 390f, 26f, 240f);
			}
			Refilter();
			if (Object.op_Implicit((Object)(object)eventSystem))
			{
				((EventSystem)eventSystem).SetSelectedGameObject(((Component)search).gameObject);
			}
		}

		private void Refilter()
		{
			string text = search.text.Trim();
			filtered = catalog.Where((Entry e) => (text.Length == 0 || e.Title.IndexOf(text, StringComparison.CurrentCultureIgnoreCase) >= 0 || e.Name.IndexOf(text, StringComparison.OrdinalIgnoreCase) >= 0) && (!bannedOnly || e.Reserved || selection.Limit(e.Name) >= 0) && MatchesFilter(e)).ToArray();
			page = 0;
			RefreshPage();
		}

		private bool MatchesFilter(Entry entry)
		{
			if (filter == 0)
			{
				return true;
			}
			if (equipment)
			{
				return entry.Category == ((filter == 1) ? 5 : 3);
			}
			return entry.Category == (new int[8] { -1, 0, 1, 2, 3, 4, 6, 7 })[filter];
		}

		private void RefreshPage()
		{
			//IL_00ed: 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)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			int num = Math.Max(1, (filtered.Length + 72 - 1) / 72);
			page = Math.Max(0, Math.Min(page, num - 1));
			selected = null;
			for (int i = 0; i < 72; i++)
			{
				int num2 = page * 72 + i;
				shown[i] = ((num2 < filtered.Length) ? filtered[num2] : null);
				((Component)((Component)buttons[i]).transform.parent).gameObject.SetActive(shown[i] != null);
				if (shown[i] != null)
				{
					names[i].text = shown[i].Title;
					artwork[i].Bind(shown[i].Pickup);
					RefreshCell(i);
					ArenaDescriptions.BindPickup(buttons[i], new PickupIndex(shown[i].Pickup));
					Navigation navigation = ((Selectable)buttons[i]).navigation;
					((Navigation)(ref navigation)).mode = (Mode)4;
					((Navigation)(ref navigation)).selectOnLeft = (Selectable)(object)((i % 12 > 0) ? buttons[i - 1] : null);
					((Navigation)(ref navigation)).selectOnRight = (Selectable)(object)((i % 12 + 1 < 12 && num2 + 1 < filtered.Length && i + 1 < 72) ? buttons[i + 1] : null);
					((Navigation)(ref navigation)).selectOnUp = (Selectable)((i >= 12) ? ((object)buttons[i - 12]) : ((object)search));
					((Navigation)(ref navigation)).selectOnDown = (Selectable)(object)((num2 + 12 < filtered.Length && i + 12 < 72) ? buttons[i + 12] : back);
					((Selectable)buttons[i]).navigation = navigation;
				}
			}
			((Selectable)previous).interactable = page > 0;
			((Selectable)next).interactable = page + 1 < num;
			pageLabel.text = "Page " + (page + 1) + " / " + num + " - " + filtered.Length + " pickups";
			((Component)filterButton).GetComponentInChildren<TMP_Text>().text = (equipment ? (new string[3] { "All rarities", "Ordinary", "Lunar" })[filter] : (new string[8] { "All rarities", "White", "Green", "Red", "Lunar", "Void", "Boss", "Other" })[filter]);
			((Component)bannedButton).GetComponentInChildren<TMP_Text>().text = (bannedOnly ? "Bans / limits" : "Show all");
			RefreshStatus();
		}

		private void RefreshCell(int i)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			Entry entry = shown[i];
			bool flag = entry.Reserved || selection.Contains(entry.Name);
			int num = selection.Limit(entry.Name);
			states[i].text = (flag ? "Off" : "On");
			((Graphic)states[i]).color = (flag ? new Color(0.72f, 0.72f, 0.72f) : new Color(0.65f, 1f, 0.6f));
			((Graphic)artwork[i].Image).color = (Color)(flag ? new Color(0.45f, 0.45f, 0.45f, 0.65f) : Color.white);
			limits[i].text = ((!flag && num > 0) ? num.ToString() : "");
		}

		private void Toggle(int i)
		{
			if (CanEdit() && shown[i] != null && !shown[i].Reserved)
			{
				selected = shown[i];
				selection.Toggle(selected.Name);
				RefreshCell(i);
				RefreshStatus();
			}
		}

		private void Adjust(int i, int amount)
		{
			if (CanEdit() && shown[i] != null && !shown[i].Reserved)
			{
				selected = shown[i];
				selection.Adjust(selected.Name, amount);
				RefreshCell(i);
				RefreshStatus();
			}
		}

		private void AdjustSelected(int amount)
		{
			if (selected != null)
			{
				int num = Array.IndexOf(shown, selected);
				if (num >= 0)
				{
					Adjust(num, amount);
				}
			}
		}

		private void RefreshStatus()
		{
			if (Object.op_Implicit((Object)(object)status))
			{
				status.text = ((selected == null) ? "Hover an icon for its full description. Search includes internal names; all loaded DLC and custom definitions are shown." : (selected.Title + " - " + (selected.Reserved ? "Reserved by the level system" : (selection.Contains(selected.Name) ? "Off - banned" : ((selection.Limit(selected.Name) > 0) ? ("On - maximum " + selection.Limit(selected.Name) + " held") : "On - unlimited"))) + (selected.Internal ? " (internal item)" : "")));
			}
		}

		private void Save()
		{
			if (!CanEdit())
			{
				Dismiss();
			}
			else if (!requireHost || ArenaHostSettings.TryEdit((ConfigEntryBase)(object)setting, selection.Serialize()))
			{
				if (!requireHost)
				{
					setting.Value = selection.Serialize();
				}
				((ConfigEntryBase)setting).ConfigFile.Save();
				if (Plugin.Active && NetworkServer.active && Object.op_Implicit((Object)(object)ArenaMatch.Instance))
				{
					ArenaMatch.Instance.RefreshItemRules();
					ArenaNetwork.SendSnapshots();
				}
				Plugin.Log("Saved " + ((ConfigEntryBase)setting).Definition.Section + " " + (equipment ? "equipment" : "item") + " bans/limits.");
				Dismiss();
			}
		}

		private void Update()
		{
			if ((requireHost && (!ArenaLobby.Selected || (!readOnly && !NetworkServer.active))) || Input.GetKeyDown((KeyCode)27))
			{
				Dismiss();
			}
		}

		private void Dismiss()
		{
			LastClosedFrame = Time.frameCount;
			if (Object.op_Implicit((Object)(object)canvasObject))
			{
				canvasObject.SetActive(false);
			}
			Object.Destroy((Object)(object)((Component)this).gameObject);
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)eventSystem))
			{
				((EventSystem)eventSystem).SetSelectedGameObject(Object.op_Implicit((Object)(object)previousSelection) ? previousSelection : null);
				eventSystem.cursorOpenerCount = Math.Max(0, eventSystem.cursorOpenerCount - 1);
				eventSystem.cursorOpenerForGamepadCount = Math.Max(0, eventSystem.cursorOpenerForGamepadCount - 1);
			}
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		private TMP_Text Label(Transform parent, string text, int size)
		{
			TMP_Text obj = ArenaStyle.Label(parent, "Label", font, size, (TextAlignmentOptions)514);
			obj.text = text;
			return obj;
		}

		private MPButton Button(Transform parent, string text, UnityAction action)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_004e: 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)
			GameObject val = new GameObject(text, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.18f, 0.22f, 0.25f, 0.65f);
			ArenaStyle.Border(val, new Color(0.8f, 0.9f, 0.9f));
			MPButton obj = val.AddComponent<MPButton>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val.GetComponent<Image>();
			((UnityEvent)((Button)obj).onClick).AddListener(action);
			ArenaStyle.Fill(Label(val.transform, text, 20).rectTransform, 5f, 3f, 5f, 3f);
			return obj;
		}

		private TMP_InputField Search(Transform parent)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0052: 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_0087: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Search items", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.12f, 0.19f, 0.22f, 0.9f);
			GameObject val2 = new GameObject("Text viewport", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			val2.transform.SetParent(val.transform, false);
			ArenaStyle.Fill(val2.GetComponent<RectTransform>(), 12f, 4f, 12f, 4f);
			TMP_Text val3 = Label(val2.transform, "", 20);
			val3.richText = false;
			val3.alignment = (TextAlignmentOptions)4097;
			ArenaStyle.Fill(val3.rectTransform);
			TMP_Text val4 = Label(val2.transform, "Search items...", 20);
			((Graphic)val4).color = new Color(0.7f, 0.75f, 0.8f);
			val4.alignment = (TextAlignmentOptions)4097;
			ArenaStyle.Fill(val4.rectTransform);
			TMP_InputField obj = val.AddComponent<TMP_InputField>();
			obj.textViewport = val2.GetComponent<RectTransform>();
			obj.textComponent = val3;
			obj.placeholder = (Graphic)(object)val4;
			((Selectable)obj).targetGraphic = (Graphic)(object)val.GetComponent<Image>();
			obj.lineType = (LineType)0;
			((UnityEvent<string>)(object)obj.onValueChanged).AddListener((UnityAction<string>)delegate
			{
				Refilter();
			});
			return obj;
		}

		private static void Place(RectTransform rect, float left, float top, float right, float height)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			rect.anchorMin = new Vector2(0f, 1f);
			rect.anchorMax = Vector2.one;
			rect.pivot = new Vector2(0.5f, 1f);
			rect.offsetMin = new Vector2(left, 0f - top - height);
			rect.offsetMax = new Vector2(right, 0f - top);
		}

		private static void Footer(MPButton button, float x, float y, float width)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = ((Component)button).GetComponent<RectTransform>();
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0.5f, 0f);
			component.anchorMax = val;
			component.anchorMin = val;
			component.pivot = new Vector2(0.5f, 0f);
			component.anchoredPosition = new Vector2(x, y);
			component.sizeDelta = new Vector2(width, 44f);
		}
	}
	internal sealed class ArenaBlacklistRightClick : MonoBehaviour, IPointerClickHandler, IEventSystemHandler, ISelectHandler
	{
		internal Action Clicked;

		internal Action Selected;

		public void OnPointerClick(PointerEventData e)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Invalid comparison between Unknown and I4
			Selected?.Invoke();
			if ((int)e.button == 1)
			{
				Clicked?.Invoke();
			}
		}

		public void OnSelect(BaseEventData e)
		{
			Selected?.Invoke();
		}
	}
	internal struct BotTarget
	{
		internal ArenaPlayer Player;

		internal CharacterBody Body;
	}
	internal sealed class ArenaBotBrain : MonoBehaviour
	{
		internal float NextThink;

		private ArenaPlayer player;

		private BaseAI[] ais;

		private AISkillDriver movement;

		private GameObject goal;

		private float range;

		private CharacterBody previousEnemy;

		private Vector3 lastSeen;

		private float seenAt = -100f;

		internal void Initialize(ArenaPlayer participant, string bodyName)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			player = participant;
			int num;
			switch (bodyName)
			{
			default:
				num = 24;
				break;
			case "CrocoBody":
				num = 10;
				break;
			case "MercBody":
			case "LoaderBody":
			case "FalseSonBody":
				num = 5;
				break;
			}
			range = num;
			goal = new GameObject("Arena bot navigation goal");
			CharacterBody body = player.Master.GetBody();
			if (Object.op_Implicit((Object)(object)body))
			{
				goal.transform.position = body.footPosition;
			}
			movement = ((Component)this).gameObject.AddComponent<AISkillDriver>();
			movement.customName = "Arena tactical movement";
			movement.skillSlot = (SkillSlot)0;
			movement.requireSkillReady = false;
			movement.moveTargetType = (TargetType)3;
			movement.aimType = (AimType)2;
			movement.movementType = (MovementType)1;
			movement.buttonPressType = (ButtonPressType)0;
			movement.activationRequiresAimTargetLoS = true;
			movement.buttonEnsureReleasedForOneSample = true;
			movement.driverUpdateTimerOverride = 0.25f;
			AISkillDriver[] array = (from d in ((Component)this).gameObject.GetComponents<AISkillDriver>()
				where (Object)(object)d != (Object)(object)movement
				select d).ToArray();
			AISkillDriver[] array2 = array.Where((AISkillDriver d) => (int)d.skillSlot != 0 && (int)d.skillSlot != -1).Concat((IEnumerable<AISkillDriver>)(object)new AISkillDriver[1] { movement }).Concat(array)
				.Distinct()
				.ToArray();
			ais = ((Component)this).gameObject.GetComponents<BaseAI>();
			BaseAI[] array3 = ais;
			foreach (BaseAI obj in array3)
			{
				obj.neverRetaliateFriendlies = true;
				obj.aimVectorDampTime = 0.18f;
				obj.aimVectorMaxSpeed = 10f;
				obj.ReplaceSkillDrivers(array2);
				obj.SetCustomTargetGameObject(goal);
			}
			NextThink = Time.unscaledTime + (float)(player.BotOrdinal % 8) * 0.06f;
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)goal))
			{
				Object.Destroy((Object)(object)goal);
			}
		}

		internal void Think(ArenaMatch match, List<BotTarget> targets, float now)
		{
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Invalid comparison between Unknown and I4
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_028a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_031f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0324: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0333: Unknown result type (might be due to invalid IL or missing references)
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_033f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0344: Unknown result type (might be due to invalid IL or missing references)
			//IL_0459: Unknown result type (might be due to invalid IL or missing references)
			//IL_045a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0360: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_0471: Unknown result type (might be due to invalid IL or missing references)
			//IL_0476: Unknown result type (might be due to invalid IL or missing references)
			//IL_051d: Unknown result type (might be due to invalid IL or missing references)
			//IL_051f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0529: Unknown result type (might be due to invalid IL or missing references)
			//IL_052e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0533: Unknown result type (might be due to invalid IL or missing references)
			//IL_053f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0544: Unknown result type (might be due to invalid IL or missing references)
			//IL_0548: Unknown result type (might be due to invalid IL or missing references)
			//IL_05eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_055f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_0577: Unknown result type (might be due to invalid IL or missing references)
			//IL_0581: Unknown result type (might be due to invalid IL or missing references)
			//IL_0586: Unknown result type (might be due to invalid IL or missing references)
			//IL_058d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0592: Unknown result type (might be due to invalid IL or missing references)
			//IL_059c: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0399: Unknown result type (might be due to invalid IL or missing references)
			//IL_039e: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0400: Unknown result type (might be due to invalid IL or missing references)
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Invalid comparison between Unknown and I4
			//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0631: Unknown result type (might be due to invalid IL or missing references)
			//IL_0416: Unknown result type (might be due to invalid IL or missing references)
			//IL_041b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0502: Unknown result type (might be due to invalid IL or missing references)
			//IL_064c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0651: Unknown result type (might be due to invalid IL or missing references)
			//IL_0432: Unknown result type (might be due to invalid IL or missing references)
			//IL_0433: Unknown result type (might be due to invalid IL or missing references)
			//IL_043b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Unknown result type (might be due to invalid IL or missing references)
			//IL_044a: Unknown result type (might be due to invalid IL or missing references)
			//IL_044f: Unknown result type (might be due to invalid IL or missing references)
			NextThink = now + Mathf.Clamp(match.Rules.BotThinkSeconds, 0.2f, 2f);
			if (!player.Connected || player.Dead || !Object.op_Implicit((Object)(object)player.Master) || !Object.op_Implicit((Object)(object)goal))
			{
				return;
			}
			CharacterBody body = player.Master.GetBody();
			if (!Object.op_Implicit((Object)(object)body) || !Object.op_Implicit((Object)(object)body.healthComponent) || !body.healthComponent.alive)
			{
				return;
			}
			HillView hillView = ((match.Rules.Mode == ArenaMode.KOTH) ? match.Hill.View(match.Rules) : null);
			bool flag = hillView?.Ready ?? false;
			Vector3 val = (flag ? hillView.To : body.footPosition);
			CharacterBody val2 = null;
			CharacterBody val3 = null;
			CharacterBody val4 = null;
			float num = float.NegativeInfinity;
			float num2 = num;
			float num3 = num;
			Vector3 val5;
			foreach (BotTarget target in targets)
			{
				CharacterBody body2 = target.Body;
				if (!Object.op_Implicit((Object)(object)body2) || !Object.op_Implicit((Object)(object)body2.healthComponent) || !body2.healthComponent.alive || !match.AreOpponents(player, target.Player) || (int)body2.GetVisibilityLevel(body) != 5)
				{
					continue;
				}
				float num4 = Vector3.Distance(body.corePosition, body2.corePosition);
				if (!(num4 > 140f))
				{
					int num5;
					if (flag)
					{
						val5 = body2.footPosition - val;
						num5 = ((((Vector3)(ref val5)).sqrMagnitude < hillView.Radius * hillView.Radius) ? 1 : 0);
					}
					else
					{
						num5 = 0;
					}
					bool onObjective = (byte)num5 != 0;
					float num6 = BotBuildRules.TargetScore(num4, body2.healthComponent.combinedHealthFraction, (Object)(object)body2 == (Object)(object)previousEnemy, onObjective, target.Player.ProtectionUntil > match.Clock);
					if (num6 > num)
					{
						val4 = val3;
						num3 = num2;
						val3 = val2;
						num2 = num;
						val2 = body2;
						num = num6;
					}
					else if (num6 > num2)
					{
						val4 = val3;
						num3 = num2;
						val3 = body2;
						num2 = num6;
					}
					else if (num6 > num3)
					{
						val4 = body2;
						num3 = num6;
					}
				}
			}
			CharacterBody val6 = (Visible(body, val2) ? val2 : (Visible(body, val3) ? val3 : (Visible(body, val4) ? val4 : null)));
			if (Object.op_Implicit((Object)(object)val6))
			{
				previousEnemy = val6;
				lastSeen = val6.footPosition;
				seenAt = now;
			}
			BaseAI[] array = ais;
			foreach (BaseAI val7 in array)
			{
				if (Object.op_Implicit((Object)(object)val7) && val7.currentEnemy != null)
				{
					val7.currentEnemy.gameObject = (Object.op_Implicit((Object)(object)val6) ? ((Component)val6).gameObject : null);
					if (Object.op_Implicit((Object)(object)val6))
					{
						val7.currentEnemy.bestHurtBox = val6.mainHurtBox;
						val7.enemyAttention = 2.5f;
					}
				}
			}
			float combinedHealthFraction = body.healthComponent.combinedHealthFraction;
			Vector3 val8 = body.footPosition;
			if (Object.op_Implicit((Object)(object)val6))
			{
				Vector3 val9 = body.footPosition - val6.footPosition;
				val9.y = 0f;
				if (((Vector3)(ref val9)).sqrMagnitude < 0.01f)
				{
					val9 = Vector3.forward;
				}
				else
				{
					((Vector3)(ref val9)).Normalize();
				}
				bool flag2 = combinedHealthFraction < 0.3f;
				float num7 = (flag2 ? Mathf.Max(32f, range) : range);
				Vector3 val10 = Vector3.Cross(Vector3.up, val9) * Mathf.Sin(now * 0.65f + (float)player.BotOrdinal * 2.4f) * ((range < 12f) ? 1.5f : 7f);
				val8 = val6.footPosition + val9 * num7 + val10;
				if (flag && !flag2 && Vector3.Distance(val6.footPosition, val) > hillView.Radius * 1.5f)
				{
					val8 = val + val9 * hillView.Radius * 0.35f;
				}
			}
			else if (flag)
			{
				val8 = val;
			}
			else if (now - seenAt < 3f)
			{
				val8 = lastSeen;
			}
			else
			{
				float num8 = float.PositiveInfinity;
				foreach (BotTarget target2 in targets)
				{
					if (Object.op_Implicit((Object)(object)target2.Body) && match.AreOpponents(player, target2.Player) && (int)target2.Body.GetVisibilityLevel(body) == 5)
					{
						val5 = target2.Body.footPosition - body.footPosition;
						float sqrMagnitude = ((Vector3)(ref val5)).sqrMagnitude;
						if (sqrMagnitude < num8)
						{
							num8 = sqrMagnitude;
							val8 = target2.Body.footPosition;
						}
					}
				}
			}
			Vector3 val11 = val8 + Vector3.up * 8f;
			Vector3 down = Vector3.down;
			LayerIndex world = LayerIndex.world;
			RaycastHit val12 = default(RaycastHit);
			if (Physics.Raycast(val11, down, ref val12, 24f, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1) && ((RaycastHit)(ref val12)).normal.y > 0.55f)
			{
				Vector3 val13 = ((RaycastHit)(ref val12)).point + Vector3.up * 1.5f;
				Vector3 val14 = ((RaycastHit)(ref val12)).point + Vector3.up * 3f;
				world = LayerIndex.world;
				if (!Physics.CheckCapsule(val13, val14, 0.6f, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1))
				{
					goal.transform.position = ((RaycastHit)(ref val12)).point;
					goto IL_05f5;
				}
			}
			goal.transform.position = body.footPosition;
			goto IL_05f5;
			IL_05f5:
			movement.shouldSprint = !Object.op_Implicit((Object)(object)val6) || combinedHealthFraction < 0.3f;
			movement.buttonPressType = (ButtonPressType)((!Object.op_Implicit((Object)(object)val6) || !(combinedHealthFraction >= 0.3f)) ? 1 : 0);
			EquipmentDef val15 = (Object.op_Implicit((Object)(object)body.inventory) ? EquipmentCatalog.GetEquipmentDef(body.inventory.GetActiveEquipment().equipmentIndex) : null);
			movement.shouldFireEquipment = Object.op_Implicit((Object)(object)val15) && ((((Object)val15).name == "Fruit") ? (combinedHealthFraction < 0.5f) : ((!(((Object)val15).name == "GainArmor")) ? Object.op_Implicit((Object)(object)val6) : (combinedHealthFraction < 0.6f && Object.op_Implicit((Object)(object)val6))));
		}

		private static bool Visible(CharacterBody body, CharacterBody enemy)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)enemy))
			{
				Vector3 corePosition = body.corePosition;
				Vector3 val = (Object.op_Implicit((Object)(object)enemy.mainHurtBox) ? ((Component)enemy.mainHurtBox).transform.position : enemy.corePosition);
				LayerIndex world = LayerIndex.world;
				return !Physics.Linecast(corePosition, val, LayerMask.op_Implicit(((LayerIndex)(ref world)).mask), (QueryTriggerInteraction)1);
			}
			return false;
		}
	}
	internal static class ArenaBotBuilds
	{
		internal static int Choose(ArenaPlayer bot, int[] offered, ItemSelection mode)
		{
			Inventory inventory = bot.Master.inventory;
			BotBuildItem[] offered2 = offered.Select(delegate(int id)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0010: Unknown result type (might be due to invalid IL or missing references)
				//IL_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Invalid comparison between Unknown and I4
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Invalid comparison between Unknown and I4
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cb: Invalid comparison between Unknown and I4
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d4: Invalid comparison between Unknown and I4
				PickupDef pickupDef = PickupCatalog.GetPickupDef(new PickupIndex(id));
				ItemDef val = ((pickupDef == null) ? null : ItemCatalog.GetItemDef(pickupDef.itemIndex));
				EquipmentDef val2 = ((pickupDef == null) ? null : EquipmentCatalog.GetEquipmentDef(pickupDef.equipmentIndex));
				return new BotBuildItem
				{
					Pickup = id,
					Name = (Object.op_Implicit((Object)(object)val) ? ((Object)val).name : (Object.op_Implicit((Object)(object)val2) ? ((Object)val2).name : "")),
					Owned = (Object.op_Implicit((Object)(object)val) ? inventory.GetItemCountPermanent(val.itemIndex) : (((int)inventory.GetActiveEquipment().equipmentIndex != -1) ? 1 : 0)),
					Equipment = Object.op_Implicit((Object)(object)val2),
					Rare = (Object.op_Implicit((Object)(object)val2) || (Object.op_Implicit((Object)(object)val) && ((int)val.tier == 2 || (int)val.tier == 4 || (int)val.tier == 3))),
					AiAllowed = (!Object.op_Implicit((Object)(object)val) || !val.ContainsTag((ItemTag)4))
				};
			}).ToArray();
			return BotBuildRules.Choose(bot.BotBuild, offered2, bot.BotRewards, mode == ItemSelection.Command);
		}
	}
	internal sealed class ArenaBotMenu : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static Func<ArenaPlayer, bool> <>9__5_2;

			public static Func<PauseScreenController, bool> <>9__5_0;

			public static UnityAction <>9__6_0;

			public static UnityAction <>9__6_1;

			public static UnityAction <>9__6_2;

			internal bool <Update>b__5_2(ArenaPlayer p)
			{
				return p.Connected;
			}

			internal bool <Update>b__5_0(PauseScreenController p)
			{
				if (Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)p.mainPanel))
				{
					return ((Component)p.mainPanel).gameObject.activeInHierarchy;
				}
				return false;
			}

			internal void <Open>b__6_0()
			{
				ArenaBots.Instance.NextSurvivor();
			}

			internal void <Open>b__6_1()
			{
				ArenaBots.Instance.Add();
			}

			internal void <Open>b__6_2()
			{
				ArenaBots.Instance.Remove();
			}
		}

		private MPButton entry;

		private GameObject panel;

		private TMP_Text selection;

		private TMP_Text status;

		private float nextPoll;

		private void Update()
		{
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026f: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Expected O, but got Unknown
			//IL_0319: Unknown result type (might be due to invalid IL or missing references)
			//IL_0323: Expected O, but got Unknown
			//IL_02bb: 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_02d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fd: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Active || !NetworkServer.active)
			{
				if (Object.op_Implicit((Object)(object)entry))
				{
					Object.Destroy((Object)(object)((Component)entry).gameObject);
				}
				if (Object.op_Implicit((Object)(object)panel))
				{
					Object.Destroy((Object)(object)panel);
				}
			}
			else if (Object.op_Implicit((Object)(object)panel))
			{
				ArenaBots instance = ArenaBots.Instance;
				ArenaMatch instance2 = ArenaMatch.Instance;
				if (Object.op_Implicit((Object)(object)instance) && Object.op_Implicit((Object)(object)instance2))
				{
					selection.text = "Survivor: " + instance.SelectionName + "  >";
					status.text = instance2.Bots.Count((ArenaPlayer p) => p.Connected) + "/" + ArenaTeams.BotCapacity + " bots active\n" + instance.Status;
				}
			}
			else
			{
				if (Time.unscaledTime < nextPoll)
				{
					return;
				}
				nextPoll = Time.unscaledTime + 0.25f;
				PauseScreenController pause = ((IEnumerable<PauseScreenController>)PauseScreenController.instancesList).FirstOrDefault((Func<PauseScreenController, bool>)((PauseScreenController p) => Object.op_Implicit((Object)(object)p) && Object.op_Implicit((Object)(object)p.mainPanel) && ((Component)p.mainPanel).gameObject.activeInHierarchy));
				if (!Object.op_Implicit((Object)(object)pause) || Object.op_Implicit((Object)(object)entry))
				{
					return;
				}
				MPButton val = (Object.op_Implicit((Object)(object)pause.exitGameButton) ? pause.exitGameButton.GetComponent<MPButton>() : ((Component)pause.mainPanel).GetComponentInChildren<MPButton>());
				if (Object.op_Implicit((Object)(object)val))
				{
					GameObject val2 = Object.Instantiate<GameObject>(((Component)val).gameObject, ((Component)val).transform.parent, false);
					((Object)val2).name = "Arena bots";
					val2.transform.SetSiblingIndex(((Component)val).transform.GetSiblingIndex());
					LanguageTextMeshController[] componentsInChildren = val2.GetComponentsInChildren<LanguageTextMeshController>(true);
					for (int num = 0; num < componentsInChildren.Length; num++)
					{
						componentsInChildren[num].token = "ARENA_PVP_BOTS";
					}
					TMP_Text[] componentsInChildren2 = val2.GetComponentsInChildren<TMP_Text>(true);
					for (int num = 0; num < componentsInChildren2.Length; num++)
					{
						componentsInChildren2[num].text = "Arena bots";
					}
					entry = val2.GetComponent<MPButton>();
					((Button)entry).onClick = new ButtonClickedEvent();
					((UnityEvent)((Button)entry).onClick).AddListener((UnityAction)delegate
					{
						Open(pause);
					});
					if (!Object.op_Implicit((Object)(object)((Component)((Component)val).transform.parent).GetComponent<VerticalLayoutGroup>()))
					{
						RectTransform component = val2.GetComponent<RectTransform>();
						Vector2 val3 = default(Vector2);
						((Vector2)(ref val3))..ctor(0.5f, 0f);
						component.anchorMax = val3;
						component.anchorMin = val3;
						component.pivot = new Vector2(0.5f, 0f);
						component.anchoredPosition = new Vector2(0f, 8f);
						component.sizeDelta = new Vector2(260f, 44f);
					}
					val2.SetActive(true);
					LayoutRebuilder.MarkLayoutForRebuild((RectTransform)val2.transform.parent);
				}
			}
		}

		private void Open(PauseScreenController pause)
		{
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Expected O, but got Unknown
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: 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_026d: Expected O, but got Unknown
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ae: Expected O, but got Unknown
			//IL_0300: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Expected O, but got Unknown
			//IL_02d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Expected O, but got Unknown
			if (!Plugin.Active || !NetworkServer.active || !Object.op_Implicit((Object)(object)pause) || !Object.op_Implicit((Object)(object)ArenaBots.Instance) || Object.op_Implicit((Object)(object)panel))
			{
				return;
			}
			panel = new GameObject("Arena bot controls", new Type[6]
			{
				typeof(RectTransform),
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster),
				typeof(Image),
				typeof(MPEventSystemProvider)
			});
			panel.transform.SetParent(((Component)pause).transform, false);
			Canvas component = panel.GetComponent<Canvas>();
			component.renderMode = (RenderMode)0;
			component.sortingOrder = 180;
			CanvasScaler component2 = panel.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1920f, 1080f);
			component2.matchWidthOrHeight = 0.5f;
			((Graphic)panel.GetComponent<Image>()).color = new Color(0f, 0f, 0f, 0.65f);
			panel.GetComponent<MPEventSystemProvider>().eventSystem = entry.eventSystem;
			GameObject val = new GameObject("Bot controls", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(panel.transform, false);
			RectTransform component3 = val.GetComponent<RectTransform>();
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			component3.anchorMax = val2;
			component3.anchorMin = val2;
			component3.sizeDelta = new Vector2(650f, 480f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.04f, 0.075f, 0.1f, 0.96f);
			ArenaStyle.Border(val, new Color(0.65f, 0.9f, 0.65f));
			Text(val.transform, "Arena bots", 28, 20f, 42f).fontStyle = (FontStyles)3;
			status = Text(val.transform, "", 17, 73f, 65f);
			Transform transform = val.transform;
			object obj = <>c.<>9__6_0;
			if (obj == null)
			{
				UnityAction val3 = delegate
				{
					ArenaBots.Instance.NextSurvivor();
				};
				<>c.<>9__6_0 = val3;
				obj = (object)val3;
			}
			MPButton val4 = MakeButton(transform, "", 151f, (UnityAction)obj);
			selection = ((Component)val4).GetComponentInChildren<TMP_Text>();
			Transform transform2 = val.transform;
			object obj2 = <>c.<>9__6_1;
			if (obj2 == null)
			{
				UnityAction val5 = delegate
				{
					ArenaBots.Instance.Add();
				};
				<>c.<>9__6_1 = val5;
				obj2 = (object)val5;
			}
			MakeButton(transform2, "Add bot", 218f, (UnityAction)obj2);
			Transform transform3 = val.transform;
			object obj3 = <>c.<>9__6_2;
			if (obj3 == null)
			{
				UnityAction val6 = delegate
				{
					ArenaBots.Instance.Remove();
				};
				<>c.<>9__6_2 = val6;
				obj3 = (object)val6;
			}
			MakeButton(transform3, "Remove last bot", 285f, (UnityAction)obj3);
			MakeButton(val.transform, "Back", 392f, (UnityAction)delegate
			{
				if (Object.op_Implicit((Object)(object)panel))
				{
					Object.Destroy((Object)(object)panel);
				}
				if (Object.op_Implicit((Object)(object)entry) && Object.op_Implicit((Object)(object)entry.eventSystem))
				{
					((EventSystem)entry.eventSystem).SetSelectedGameObject(((Component)entry).gameObject);
				}
			});
			if (Object.op_Implicit((Object)(object)entry.eventSystem))
			{
				((EventSystem)entry.eventSystem).SetSelectedGameObject(((Component)val4).gameObject);
			}
		}

		private static TMP_Text Text(Transform parent, string content, int size, float top, float height)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: 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)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Label", new Type[2]
			{
				typeof(RectTransform),
				typeof(HGTextMeshProUGUI)
			});
			val.transform.SetParent(parent, false);
			HGTextMeshProUGUI component = val.GetComponent<HGTextMeshProUGUI>();
			((TMP_Text)component).text = content;
			((TMP_Text)component).fontSize = size;
			((TMP_Text)component).alignment = (TextAlignmentOptions)514;
			((Graphic)component).color = Color.white;
			((Graphic)component).raycastTarget = false;
			RectTransform rectTransform = ((TMP_Text)component).rectTransform;
			rectTransform.anchorMin = new Vector2(0f, 1f);
			rectTransform.anchorMax = Vector2.one;
			rectTransform.offsetMin = new Vector2(20f, 0f - top - height);
			rectTransform.offsetMax = new Vector2(-20f, 0f - top);
			return (TMP_Text)(object)component;
		}

		private static MPButton MakeButton(Transform parent, string title, float top, UnityAction action)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(title, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = Vector2.one;
			component.offsetMin = new Vector2(45f, 0f - top - 50f);
			component.offsetMax = new Vector2(-45f, 0f - top);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.15f, 0.2f, 0.24f, 0.6f);
			ArenaStyle.Border(val, new Color(0.8f, 0.9f, 0.9f, 0.65f));
			MPButton obj = val.AddComponent<MPButton>();
			((Selectable)obj).targetGraphic = (Graphic)(object)val.GetComponent<Image>();
			((UnityEvent)((Button)obj).onClick).AddListener(action);
			ArenaStyle.Fill(Text(val.transform, title, 22, 0f, 50f).rectTransform);
			return obj;
		}

		private void OnDestroy()
		{
			if (Object.op_Implicit((Object)(object)entry))
			{
				Object.Destroy((Object)(object)((Component)entry).gameObject);
			}
			if (Object.op_Implicit((Object)(object)panel))
			{
				Object.Destroy((Object)(object)panel);
			}
		}
	}
	internal sealed class ArenaBots : MonoBehaviour
	{
		internal static ArenaBots Instance;

		private bool initialSpawned;

		private int startingRemaining;

		private float nextRoster;

		private float nextSpawn;

		private int nextBrain;

		private readonly Stopwatch decisionBudget = new Stopwatch();

		private readonly List<ArenaBotBrain> brains = new List<ArenaBotBrain>();

		private readonly List<BotTarget> targets = new List<BotTarget>();

		private int choice;

		private SurvivorDef[] survivors;

		internal string Status = "";

		internal SurvivorDef[] Survivors
		{
			get
			{
				//IL_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_004e: Unknown result type (might be due to invalid IL or missing references)
				if (survivors == null)
				{
					List<SurvivorDef> list = new List<SurvivorDef>();
					for (int i = 0; i < SurvivorCatalog.survivorCount; i++)
					{
						SurvivorDef survivorDef = SurvivorCatalog.GetSurvivorDef((SurvivorIndex)i);
						if (Object.op_Implicit((Object)(object)survivorDef) && Object.op_Implicit((Object)(object)survivorDef.bodyPrefab))
						{
							CharacterBody component = survivorDef.bodyPrefab.GetComponent<CharacterBody>();
							GameObject val = (Object.op_Implicit((Object)(object)component) ? MasterCatalog.GetMasterPrefab(MasterCatalog.FindAiMasterIndexForBody(component.bodyIndex)) : null);
							if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.GetComponent<BaseAI>()))
							{
								list.Add(survivorDef);
							}
						}
					}
					survivors = (from s in list
						orderby (!(((Object)s.bodyPrefab).name == "CommandoBody")) ? 1 : 0, s.cachedName
						select s).ToArray();
				}
				return survivors;
			}
		}

		internal string SelectionName
		{
			get
			{
				if (Survivors.Length != 0)
				{
					return Language.GetString(Survivors[choice % Survivors.Length].displayNameToken);
				}
				return "No registered survivor AI";
			}
		}

		private void Awake()
		{
			Instance = this;
		}

		private void OnDestroy()
		{
			Reset();
			Instance = null;
		}

		internal void Reset()
		{
			initialSpawned = false;
			startingRemaining = 0;
			nextRoster = (nextSpawn = 0f);
			nextBrain = 0;
			brains.Clear();
			targets.Clear();
			Status = "";
		}

		internal void NextSurvivor()
		{
			if (Survivors.Length != 0)
			{
				choice = (choice + 1) % Survivors.Length;
			}
		}

		internal void Tick(ArenaMatch match)
		{
			if (!NetworkServer.active || !Plugin.Active || match.Rules == null)
			{
				return;
			}
			if (!initialSpawned)
			{
				initialSpawned = true;
				startingRemaining = Math.Min(ArenaTeams.BotCapacity, match.Rules.StartingBots);
			}
			if (startingRemaining > 0 && !match.Finished && Time.unscaledTime >= nextSpawn)
			{
				nextSpawn = Time.unscaledTime + 0.15f;
				if (Add(starting: true))
				{
					startingRemaining--;
				}
				else
				{
					startingRemaining = 0;
				}
			}
			if (match.Finished || brains.Count == 0)
			{
				return;
			}
			float unscaledTime = Time.unscaledTime;
			if (unscaledTime >= nextRoster)
			{
				nextRoster = unscaledTime + 0.25f;
				targets.Clear();
				brains.RemoveAll((ArenaBotBrain b) => !Object.op_Implicit((Object)(object)b));
				foreach (ArenaPlayer allPlayer in match.AllPlayers)
				{
					CharacterBody val = ((allPlayer.Connected && !allPlayer.Dead && Object.op_Implicit((Object)(object)allPlayer.Master)) ? allPlayer.Master.GetBody() : null);
					if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)val.healthComponent) && val.healthComponent.alive)
					{
						targets.Add(new BotTarget
						{
							Player = allPlayer,
							Body = val
						});
					}
				}
			}
			if (brains.Count == 0)
			{
				return;
			}
			decisionBudget.Restart();
			int count = brains.Count;
			while (count-- > 0)
			{
				nextBrain %= brains.Count;
				ArenaBotBrain arenaBotBrain = brains[nextBrain++];
				if (Object.op_Implicit((Object)(object)arenaBotBrain) && unscaledTime >= arenaBotBrain.NextThink)
				{
					arenaBotBrain.Think(match, targets, unscaledTime);
				}
				if (decisionBudget.Elapsed.TotalMilliseconds >= 2.0)
				{
					break;
				}
			}
		}

		internal bool Add(bool starting = false)
		{
			//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)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			//IL_038e: Expected O, but got Unknown
			ArenaMatch instance = ArenaMatch.Instance;
			if (!Plugin.Active || !NetworkServer.active || !Object.op_Implicit((Object)(object)instance) || instance.Rules == null || !Object.op_Implicit((Object)(object)SceneInfo.instance))
			{
				return false;
			}
			if (instance.Finished)
			{
				Status = "Continue the match before spawning more bots.";
				return false;
			}
			if (Survivors.Length == 0)
			{
				Status = "No survivor has a registered AI master.";
				return false;
			}
			ArenaPlayer arenaPlayer = instance.Bots.FirstOrDefault((ArenaPlayer p) => p.BotRemoved);
			bool flag = arenaPlayer == null;
			if (flag && instance.Bots.Count >= ArenaTeams.BotCapacity)
			{
				Status = "Bot limit reached (" + ArenaTeams.BotCapacity + ").";
				return false;
			}
			SurvivorDef val = Survivors[choice % Survivors.Length];
			GameObject masterPrefab = MasterCatalog.GetMasterPrefab(MasterCatalog.FindAiMasterIndexForBody(val.bodyPrefab.GetComponent<CharacterBody>().bodyIndex));
			GameObject val2 = null;
			GameObject val3 = null;
			try
			{
				if (flag)
				{
					arenaPlayer = new ArenaPlayer
					{
						BotOrdinal = instance.Bots.Count
					};
					instance.Bots.Add(arenaPlayer);
				}
				val2 = new GameObject("Arena bot staging");
				val2.SetActive(false);
				val3 = Object.Instantiate<GameObject>(masterPrefab, val2.transform, false);
				arenaPlayer.BotMaster = val3.GetComponent<CharacterMaster>();
				arenaPlayer.BotRemoved = false;
				arenaPlayer.Dead = false;
				arenaPlayer.LastBody = 0;
				arenaPlayer.InitialGranted = false;
				arenaPlayer.Rewards.Clear();
				arenaPlayer.Level = ((instance.Rules.Selection != ItemSelection.Random) ? 1 : instance.Cap);
				arenaPlayer.LateEntrant = !starting && instance.Elapsed > 0f;
				arenaPlayer.CatchupRemaining = (arenaPlayer.CatchupTarget = 0);
				arenaPlayer.CatchupPrepared = false;
				arenaPlayer.BeadExperience.Clear();
				arenaPlayer.BotBuild = BotBuildRules.ForBody(((Object)val.bodyPrefab).name, arenaPlayer.BotOrdinal, instance.Rules.Mode == ArenaMode.KOTH);
				arenaPlayer.BotRewards = 0;
				arenaPlayer.Name = "Bot " + (arenaPlayer.BotOrdinal + 1) + " - " + Language.GetString(val.displayNameToken);
				ArenaBotBrain arenaBotBrain = val3.AddComponent<ArenaBotBrain>();
				val3.transform.SetParent((Transform)null, true);
				val3.SetActive(true);
				Object.Destroy((Object)(object)val2);
				val2 = null;
				instance.RefreshTeamAssignments();
				NetworkServer.Spawn(val3);
				ArenaTeams.Ensure(arenaPlayer.BotMaster);
				Vector3[] array = instance.SpawnPositions.ToArray();
				Vector3 val4 = ((array.Length != 0) ? array[Random.Range(0, array.Length)] : arenaPlayer.Master.CalculateSafeRespawnPosition());
				arenaPlayer.BotMaster.Respawn(val4, Quaternion.identity, true);
				arenaBotBrain.Initialize(arenaPlayer, ((Object)val.bodyPrefab).name);
				brains.Add(arenaBotBrain);
				ItemDef[] array2 = (ItemDef[])(object)new ItemDef[2]
				{
					Items.UseAmbientLevel,
					Items.InvadingDoppelganger
				};
				foreach (ItemDef val5 in array2)
				{
					int itemCountPermanent = arenaPlayer.Master.inventory.GetItemCountPermanent(val5);
					if (itemCountPermanent > 0)
					{
						arenaPlayer.Master.inventory.RemoveItemPermanent(val5, itemCountPermanent);
					}
				}
				instance.EnsureParticipant(arenaPlayer);
				Status = "Spawned " + arenaPlayer.Name + " (" + BotBuildRules.Name(arenaPlayer.BotBuild) + ").";
				SimpleChatMessage val6 = new SimpleChatMessage();
				val6.baseToken = "ARENA_PVP_BOT_SPAWNED";
				val6.paramTokens = new string[1] { ArenaMatch.SafeName(arenaPlayer.Name) };
				Chat.SendBroadcastChat((ChatMessageBase)(object)val6);
				ArenaNetwork.SendSnapshots();
				return true;
			}
			catch (Exception ex)
			{
				if (arenaPlayer != null)
				{
					arenaPlayer.BotRemoved = true;
					arenaPlayer.BotMaster = null;
				}
				instance.RefreshTeamAssignments();
				if (Object.op_Implicit((Object)(object)val3))
				{
					NetworkServer.Destroy(val3);
				}
				Status = "Could not spawn this survivor AI. Try another survivor.";
				Plugin.Warn("Arena bot spawn failed: " + ex);
				return false;
			}
			finally
			{
				if (Object.op_Implicit((Object)(object)val2))
				{
					Object.Destroy((Object)(object)val2);
				}
			}
		}

		internal bool Remove()
		{
			ArenaMatch instance = ArenaMatch.Instance;
			if (!Plugin.Active || !NetworkServer.active || !Object.op_Implicit((Object)(object)instance) || instance.Rules == null)
			{
				return false;
			}
			ArenaPlayer arenaPlayer = instance.Bots.LastOrDefault((ArenaPlayer p) => p.Connected);
			if (arenaPlayer == null)
			{
				Status = "No bots to remove.";
				return false;
			}
			Despawn(arenaPlayer);
			Status = "Removed " + arenaPlayer.Name + ".";
			ArenaNetwork.SendSnapshots();
			return true;
		}

		internal static void Despawn(ArenaPlayer bot, bool rebalance = true)
		{
			CharacterMaster master = bot.BotMaster;
			HashSet<CharacterMaster> hashSet = new HashSet<CharacterMaster>(CharacterMaster.readOnlyInstancesList.Where((CharacterMaster m) => Object.op_Implicit((Object)(object)m) && Object.op_Implicit((Object)(object)master) && (Object)(object)ArenaMatch.PlayerOwner(m) == (Object)(object)master));
			bot.BotRemoved = true;
			ProjectileController[] array = Object.FindObjectsOfType<ProjectileController>();
			foreach (ProjectileController val in array)
			{
				CharacterBody val2 = (Object.op_Implicit((Object)(object)val.owner) ? val.owner.GetComponent<CharacterBody>() : null);
				if (Object.op_Implicit((Object)(object)val2) && hashSet.Contains(val2.master))
				{
					if (Object.op_Implicit((Object)(object)((Component)val).GetComponent<NetworkIdentity>()))
					{
						NetworkServer.Destroy(((Component)val).gameObject);
					}
					else
					{
						Object.Destroy((Object)(object)((Component)val).gameObject);
					}
				}
			}
			foreach (CharacterMaster item in hashSet)
			{
				if (Object.op_Implicit((Object)(object)item))
				{
					NetworkServer.Destroy(((Component)item).gameObject);
				}
			}
			bot.BotMaster = null;
			if (rebalance && Object.op_Implicit((Object)(object)ArenaMatch.Instance))
			{
				ArenaMatch.Instance.RefreshTeamAssignments();
			}
		}
	}
	internal sealed class ArenaBotScoreboard : MonoBehaviour
	{
		private ScoreboardController controller;

		private readonly Dictionary<uint, ScoreboardStrip> rows = new Dictionary<uint, ScoreboardStrip>();

		private readonly HashSet<uint> present = new HashSet<uint>();

		private readonly List<uint> removed = new List<uint>();

		private float nextRefresh;

		internal void NativeRebuilt(ScoreboardController source)
		{
			controller = source;
			Refresh(rebuildOrder: true);
		}

		private void Update()
		{
			if (!Plugin.Active)
			{
				Clear();
			}
			else if (!(Time.unscaledTime < nextRefresh))
			{
				nextRefresh = Time.unscaledTime + 0.25f;
				Refresh(rebuildOrder: false);
			}
		}

		private void Refresh(bool rebuildOrder)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.Active || !Object.op_Implicit((Object)(object)controller) || !Object.op_Implicit((Object)(object)controller.container) || !Object.op_Implicit((Object)(object)controller.stripPrefab))
			{
				return;
			}
			MatchView matchView = (Object.op_Implicit((Object)(object)ArenaUI.Instance) ? ArenaUI.Instance.CurrentMatch : null);
			present.Clear();
			if (matchView != null && matchView.Players != null)
			{
				PlayerView[] players = matchView.Players;
				foreach (PlayerView playerView in players)
				{
					if (!playerView.IsBot || !playerView.Online || playerView.MasterId == 0 || !present.Add(playerView.MasterId))
					{
						continue;
					}
					if (!rows.TryGetValue(playerView.MasterId, out var value) || !Object.op_Implicit((Object)(object)value))
					{
						GameObject val = (NetworkServer.active ? NetworkServer.FindLocalObject(new NetworkInstanceId(playerView.MasterId)) : ClientScene.FindLocalObject(new NetworkInstanceId(playerView.MasterId)));
						CharacterMaster val2 = (Object.op_Implicit((Object)(object)val) ? val.GetComponent<CharacterMaster>() : null);
						if (!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.inventory))
						{
							continue;
						}
						GameObject val3 = Object.Instantiate<GameObject>(controller.stripPrefab, (Transform)(object)controller.container, false);
						((Object)val3).name = "Arena bot inventory " + playerView.MasterId;
						value = val3.GetComponent<ScoreboardStrip>();
						if (!Object.op_Implicit((Object)(object)value))
						{
							Object.Destroy((Object)(object)val3);
							continue;
						}
						if (Object.op_Implicit((Object)(object)value.userAvatar))
						{
							((Behaviour)value.userAvatar).enabled = false;
							RawImage component = ((Component)value.userAvatar).GetComponent<RawImage>();
							if (Object.op_Implicit((Object)(object)component))
							{
								((Behaviour)component).enabled = false;
							}
						}
						value.SetMaster(val2);
						rows[playerView.MasterId] = value;
					}
					if (Object.op_Implicit((Object)(object)value.nameLabel))
					{
						((TMP_Text)value.nameLabel).text = ArenaMatch.SafeName(playerView.Name);
					}
					if (rebuildOrder)
					{
						((Component)value).transform.SetAsLastSibling();
					}
				}
			}
			removed.Clear();
			foreach (KeyValuePair<uint, ScoreboardStrip> row in rows)
			{
				if (!present.Contains(row.Key) || !Object.op_Implicit((Object)(object)row.Value))
				{
					removed.Add(row.Key);
				}
			}
			foreach (uint item in removed)
			{
				ScoreboardStrip val4 = rows[item];
				if (Object.op_Implicit((Object)(object)val4))
				{
					((Component)val4).gameObject.SetActive(false);
					Object.Destroy((Object)(object)((Component)val4).gameObject);
				}
				rows.Remove(item);
			}
		}

		private void Clear()
		{
			foreach (ScoreboardStrip value in rows.Values)
			{
				if (Object.op_Implicit((Object)(object)value))
				{
					((Component)value).gameObject.SetActive(false);
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
			rows.Clear();
			present.Clear();
			removed.Clear();
		}

		private void OnDisable()
		{
			Clear();
		}

		private void OnDestroy()
		{
			Clear();
		}
	}
	[HarmonyPatch(typeof(ScoreboardController), "Rebuild")]
	internal static class AddArenaBotInventoryRows
	{
		private static void Postfix(ScoreboardController __instance)
		{
			if (Plugin.Active)
			{
				ArenaBotScoreboard arenaBotScoreboard = ((Component)__instance).GetComponent<ArenaBotScoreboard>();
				if (!Object.op_Implicit((Object)(object)arenaBotScoreboard))
				{
					arenaBotScoreboard = ((Component)__instance).gameObject.AddComponent<ArenaBotScoreboard>();
				}
				arenaBotScoreboard.NativeRebuilt(__instance);
			}
		}
	}
	[HarmonyPatch(typeof(ScoreboardController), "SelectFirstScoreboardStrip")]
	internal static class SelectArenaInventoryRow
	{
		private static bool Prefix(ScoreboardController __instance, MPEventSystem ___eventSystem)
		{
			if (!Plugin.Active || !Object.op_Implicit((Object)(object)((Component)__instance).GetComponent<ArenaBotScoreboard>()))
			{
				return true;
			}
			ScoreboardStrip val = (Object.op_Implicit((Object)(object)__instance.container) ? ((Component)__instance.container).GetComponentInChildren<ScoreboardStrip>() : null);
			if (Object.op_Implicit((Object)(object)val) && Object.op_Implicit((Object)(object)___eventSystem))
			{
				___eventSystem.SetSelectedObject(((Component)val).gameObject);
			}
			return false;
		}
	}
	internal static class ArenaBurstProtection
	{
		private static CharacterMaster Owner(GameObject source)
		{
			int num = 0;
			while (Object.op_Implicit((Object)(object)source) && num < 8)
			{
				CharacterBody component = source.GetComponent<CharacterBody>();
				if (Object.op_Implicit((Object)(object)component))
				{
					return ArenaMatch.PlayerOwner(component.master);
				}
				CharacterMaster component2 = source.GetComponent<CharacterMaster>();
				if (Object.op_Implicit((Object)(object)component2))
				{
					return ArenaMatch.PlayerOwner(component2);
				}
				ProjectileController component3 = source.GetComponent<ProjectileController>();
				source = (Object.op_Implicit((Object)(object)component3) ? component3.owner : null);
				num++;
			}
			return null;
		}

		internal static ArenaPlayer Victim(HealthComponent health, DamageInfo info)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: 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_00e5: Invalid comparison between Unknown and I4
			ArenaMatch instance = ArenaMatch.Instance;
			if (!Plugin.Active || !NetworkServer.active || !Object.op_Implicit((Object)(object)instance) || instance.Rules == null || !instance.Rules.AntiOneShot || !Object.op_Implicit((Object)(object)health.body) || !Object.op_Implicit((Object)(object)health.body.master) || DamageTypeCombo.op_Implicit(info.damageType & DamageTypeCombo.op_Implicit((DamageType)int.MinValue)) != 0L)
			{
				return null;
			}
			ArenaPlayer arenaPlayer = instance.Find(health.body.master);
			if (arenaPlayer == null || arenaPlayer.Dead || (Object)(object)arenaPlayer.Master != (Object)(object)health.body.master)
			{
				return null;
			}
			CharacterMaster val = Owner(info.attacker) ?? Owner(info.inflictor);
			ArenaPlayer b = instance.Find(val);
			if (Object.op_Implicit((Object)(object)val))
			{
				if (!instance.AreOpponents(arenaPlayer, b))
				{
					return null;
				}
				return arenaPlayer;
			}
			if ((int)info.dotIndex != -1 && instance.Clock - arenaPlayer.LastHitTime <= 10f)
			{
				foreach (ArenaPlayer allPlayer in instance.AllPlayers)
				{
					if (allPlayer.UserId == arenaPlayer.LastAttacker && instance.AreOpponents(arenaPlayer, allPlayer))
					{
						return arenaPlayer;
					}
				}
			}
			return null;
		}

		internal static bool Before(HealthComponent health, DamageInfo info)
		{
			ArenaPlayer arenaPlayer = Victim(health, info);
			if (arenaPlayer == null)
			{
				return true;
			}
			double now = ArenaMatch.Instance.Clock;
			if (arenaPlayer.Burst.Protected(now))
			{
				info.rejected = true;
				return false;
			}
			arenaPlayer.Burst.Observe(now, (health.fullCombinedHealth > 0f) ? (health.combinedHealth / health.fullCombinedHealth) : 0f);
			return true;
		}

		internal static void SetHealth(HealthComponent health, float proposed, DamageInfo info)
		{
			ArenaPlayer arenaPlayer = Victim(health, info);
			if (arenaPlayer != null)
			{