Decompiled source of Gungeon PVPVE v0.6.31

plugins/GungeonRounds/GungeonRounds.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Net;
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Dungeonator;
using GungeonRounds.Arena;
using GungeonRounds.Combat;
using GungeonRounds.Data;
using GungeonRounds.Fighters;
using GungeonRounds.Fx;
using GungeonRounds.Match;
using GungeonRounds.Net;
using GungeonRounds.Shop;
using GungeonRounds.UI;
using HarmonyLib;
using InControl;
using Microsoft.CodeAnalysis;
using Pathfinding;
using Steamworks;
using UnityEngine;
using UnityEngine.Profiling;
using UnityEngine.SceneManagement;
using tk2dRuntime.TileMap;

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

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace GungeonRounds
{
	internal static class AllocProbe
	{
		private static readonly Dictionary<MethodBase, long> Bytes = new Dictionary<MethodBase, long>();

		private static readonly Dictionary<MethodBase, int> Calls = new Dictionary<MethodBase, int>();

		public static bool Installed;

		public static void Install(Harmony h)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			HarmonyMethod val = new HarmonyMethod(typeof(AllocProbe).GetMethod("Pre", BindingFlags.Static | BindingFlags.NonPublic));
			HarmonyMethod val2 = new HarmonyMethod(typeof(AllocProbe).GetMethod("Post", BindingFlags.Static | BindingFlags.NonPublic));
			string[] array = new string[9] { "Update", "LateUpdate", "FixedUpdate", "OnGUI", "OnWillRenderObject", "OnPreRender", "OnPostRender", "OnRenderImage", "OnPreCull" };
			int num = 0;
			int num2 = 0;
			foreach (Assembly item in new List<Assembly>
			{
				typeof(PlayerController).Assembly,
				typeof(dfControl).Assembly,
				typeof(Plugin).Assembly
			})
			{
				Type[] types;
				try
				{
					types = item.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					types = ex.Types;
				}
				Type[] array2 = types;
				foreach (Type type in array2)
				{
					if ((object)type == null || type.IsGenericTypeDefinition || type.ContainsGenericParameters || !typeof(MonoBehaviour).IsAssignableFrom(type))
					{
						continue;
					}
					string[] array3 = array;
					foreach (string text in array3)
					{
						MethodInfo methodInfo = null;
						try
						{
							MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
							foreach (MethodInfo methodInfo2 in methods)
							{
								if (methodInfo2.Name == text && !methodInfo2.IsAbstract && !methodInfo2.IsGenericMethodDefinition)
								{
									methodInfo = methodInfo2;
									break;
								}
							}
							if ((object)methodInfo != null && methodInfo.GetMethodBody() != null)
							{
								h.Patch((MethodBase)methodInfo, val, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								num++;
							}
						}
						catch
						{
							num2++;
						}
					}
				}
			}
			Installed = true;
			Plugin.Log.LogInfo((object)$"[alloc] probing {num} methods ({num2} skipped)");
		}

		private static void Pre(out long __state)
		{
			__state = GC.GetTotalMemory(forceFullCollection: false);
		}

		private static void Post(MethodBase __originalMethod, long __state)
		{
			long num = GC.GetTotalMemory(forceFullCollection: false) - __state;
			Calls.TryGetValue(__originalMethod, out var value);
			Calls[__originalMethod] = value + 1;
			if (num > 0)
			{
				Bytes.TryGetValue(__originalMethod, out var value2);
				Bytes[__originalMethod] = value2 + num;
			}
		}

		public static string Report()
		{
			List<KeyValuePair<MethodBase, long>> list = new List<KeyValuePair<MethodBase, long>>(Bytes);
			list.Sort((KeyValuePair<MethodBase, long> a, KeyValuePair<MethodBase, long> b) => b.Value.CompareTo(a.Value));
			StringBuilder stringBuilder = new StringBuilder("[alloc] top KB:");
			long num = 0L;
			foreach (KeyValuePair<MethodBase, long> item in list)
			{
				num += item.Value;
			}
			stringBuilder.Append(" sum=").Append(num >> 10);
			for (int num2 = 0; num2 < list.Count && num2 < 12; num2++)
			{
				MethodBase key = list[num2].Key;
				Calls.TryGetValue(key, out var value);
				stringBuilder.Append(' ').Append(key.DeclaringType.Name).Append('.')
					.Append(key.Name)
					.Append('=')
					.Append(list[num2].Value >> 10)
					.Append("(x")
					.Append(value)
					.Append(')');
			}
			Bytes.Clear();
			Calls.Clear();
			return stringBuilder.ToString();
		}
	}
	public sealed class FileLog : ILogListener, IDisposable
	{
		private readonly StreamWriter _w;

		private readonly Dictionary<string, int> _repeats = new Dictionary<string, int>();

		public static FileLog Instance;

		public FileLog(string path)
		{
			Instance = this;
			_w = new StreamWriter(new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.ReadWrite))
			{
				AutoFlush = true
			};
			_w.WriteLine(string.Format("{0} {1} log {2:yyyy-MM-dd HH:mm:ss}", "Enter the Rounds", "0.6.31", DateTime.Now));
		}

		public void LogEvent(object sender, LogEventArgs e)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Invalid comparison between Unknown and I4
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				bool num = e.Source != null && e.Source.SourceName == "Enter the Rounds";
				bool flag = e.Source != null && e.Source.SourceName == "Unity Log" && (e.Level & 7) > 0;
				if (!num && !flag)
				{
					return;
				}
				string text = ((e.Data != null) ? e.Data.ToString() : "");
				string key = ((text.Length > 300) ? text.Substring(0, 300) : text);
				lock (_repeats)
				{
					if (_repeats.Count > 5000)
					{
						_repeats.Clear();
					}
					_repeats.TryGetValue(key, out var value);
					int num2 = (_repeats[key] = value + 1);
					value = num2;
					if (value <= 20 || value % 1000 == 0)
					{
						if (value > 20)
						{
							text = $"(repeated {value}x) " + text;
						}
						_w.WriteLine($"{DateTime.Now:HH:mm:ss.fff} [{e.Level}:{e.Source.SourceName}] {text}");
					}
				}
			}
			catch
			{
			}
		}

		public static void Raw(string level, string text)
		{
			FileLog instance = Instance;
			if (instance == null)
			{
				return;
			}
			try
			{
				lock (instance._repeats)
				{
					instance._w.WriteLine(string.Format("{0:HH:mm:ss.fff} [{1}:{2}] {3}", DateTime.Now, level, "Enter the Rounds", text));
				}
			}
			catch
			{
			}
		}

		public void Dispose()
		{
			try
			{
				_w.Dispose();
			}
			catch
			{
			}
		}
	}
	internal static class GameCrumbs
	{
		[HarmonyPatch(typeof(PhysicsEngine), "LateUpdate")]
		private static class Physics
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Physics", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Physics", __state);
			}
		}

		[HarmonyPatch(typeof(Projectile), "Update")]
		private static class Bullets
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Projectile", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Projectile", __state);
			}
		}

		[HarmonyPatch(typeof(BasicBeamController), "Update")]
		private static class Beams
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Beam", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Beam", __state);
			}
		}

		[HarmonyPatch(typeof(Gun), "Update")]
		private static class Guns
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Gun", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Gun", __state);
			}
		}

		[HarmonyPatch(typeof(PlayerController), "Update")]
		private static class Players
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Player", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Player", __state);
			}
		}

		[HarmonyPatch(typeof(PlayerController), "LateUpdate")]
		private static class PlayersLate
		{
			private static void Prefix(out long __state)
			{
				Pre("G.PlayerLate", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.PlayerLate", __state);
			}
		}

		[HarmonyPatch(typeof(GunInventory), "FrameUpdate")]
		private static class Inventory
		{
			private static void Prefix()
			{
				Hang.At = "G.Inventory";
			}

			private static void Postfix()
			{
				Hang.At = "G.Inventory done";
			}
		}

		[HarmonyPatch(typeof(PlayerController), "HandlePlayerInput")]
		private static class Input
		{
			private static void Prefix()
			{
				Hang.At = "G.HandlePlayerInput";
			}

			private static void Postfix()
			{
				Hang.At = "G.HandlePlayerInput done";
			}
		}

		[HarmonyPatch(typeof(Gun), "Attack")]
		private static class GunAttack
		{
			private static void Prefix()
			{
				Hang.At = "G.Gun.Attack";
			}

			private static void Postfix()
			{
				Hang.At = "G.Gun.Attack done";
			}
		}

		[HarmonyPatch(typeof(Gun), "ShootSingleProjectile")]
		private static class GunShoot
		{
			private static int _frame;

			private static int _count;

			private static int _logged;

			private static void Prefix(Gun __instance)
			{
				Hang.At = "G.Gun.ShootSingleProjectile";
				int frameCount = Time.frameCount;
				if (frameCount != _frame)
				{
					_frame = frameCount;
					_count = 0;
				}
				if (++_count <= 600)
				{
					return;
				}
				if (_logged++ < 3)
				{
					string text = (((Object)(object)__instance != (Object)null && (Object)(object)__instance.CurrentOwner != (Object)null) ? ((Object)__instance.CurrentOwner).name : "?");
					int num = (((Object)(object)__instance != (Object)null && (Object)(object)__instance.Volley != (Object)null) ? __instance.Volley.projectiles.Count : (-1));
					Plugin.Log.LogWarning((object)("[hang] broke a firing loop: " + (((Object)(object)__instance != (Object)null) ? ((Object)__instance).name : "?") + " (" + text + ") fired 600+ modules in one frame (volley " + num + " modules)"));
				}
				throw new InvalidOperationException("GR: firing loop stopped");
			}

			private static void Postfix()
			{
				Hang.At = "G.Gun.ShootSingleProjectile done";
			}
		}

		[HarmonyPatch(typeof(Gun), "ContinueAttack")]
		private static class GunContinue
		{
			private static void Prefix()
			{
				Hang.At = "G.Gun.ContinueAttack";
			}

			private static void Postfix()
			{
				Hang.At = "G.Gun.ContinueAttack done";
			}
		}

		[HarmonyPatch(typeof(PlayerController), "HandleContinueDodgeRoll")]
		private static class Dodge
		{
			private static void Prefix()
			{
				Hang.At = "G.DodgeRoll";
			}

			private static void Postfix()
			{
				Hang.At = "G.DodgeRoll done";
			}
		}

		[HarmonyPatch(typeof(PlayerController), "HandleRoomProcessing")]
		private static class Rooms
		{
			private static void Prefix()
			{
				Hang.At = "G.RoomProcessing";
			}

			private static void Postfix()
			{
				Hang.At = "G.RoomProcessing done";
			}
		}

		[HarmonyPatch(typeof(RoomHandler), "PlayerEnter")]
		private static class RoomEnter
		{
			private static void Prefix()
			{
				Hang.At = "G.RoomEnter";
			}

			private static void Postfix()
			{
				Hang.At = "G.RoomEnter done";
			}
		}

		[HarmonyPatch(typeof(GameActor), "HandlePitChecks")]
		private static class Pits
		{
			private static void Prefix()
			{
				Hang.At = "G.PitChecks";
			}

			private static void Postfix()
			{
				Hang.At = "G.PitChecks done";
			}
		}

		[HarmonyPatch(typeof(PlayerStats), "RecalculateStatsInternal")]
		private static class Stats
		{
			private static void Prefix()
			{
				Hang.At = "G.RecalculateStats";
			}

			private static void Postfix()
			{
				Hang.At = "G.RecalculateStats done";
			}
		}

		[HarmonyPatch(typeof(GameActor), "Update")]
		private static class Actor
		{
			private static void Prefix()
			{
				Hang.At = "G.GameActor";
			}

			private static void Postfix()
			{
				Hang.At = "G.GameActor done";
			}
		}

		[HarmonyPatch(typeof(AIActor), "Update")]
		private static class Enemies
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Enemy", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Enemy", __state);
			}
		}

		[HarmonyPatch(typeof(GameManager), "Update")]
		private static class Game
		{
			private static void Prefix(out long __state)
			{
				Pre("G.GameManager", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.GameManager", __state);
			}
		}

		[HarmonyPatch(typeof(DeadlyDeadlyGoopManager), "LateUpdate")]
		private static class Goop
		{
			private static void Prefix(out long __state)
			{
				Pre("G.Goop", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.Goop", __state);
			}
		}

		[HarmonyPatch(typeof(SpawnManager), "Update")]
		private static class Spawns
		{
			private static void Prefix(out long __state)
			{
				Pre("G.SpawnManager", out __state);
			}

			private static void Postfix(long __state)
			{
				Post("G.SpawnManager", __state);
			}
		}

		private static void Pre(string at, out long t)
		{
			Hang.At = at;
			t = (Prof.On ? Prof.S : 0);
		}

		private static void Post(string done, long t)
		{
			Hang.Done = done;
			if (t != 0L)
			{
				Prof.Ms(done, t);
			}
		}
	}
	public static class Hang
	{
		private static readonly Stopwatch Sw = Stopwatch.StartNew();

		private static long _beat;

		private static volatile int _frame;

		public static volatile string At = "start";

		public static volatile string Done = "";

		public static volatile bool InMatch;

		public static volatile bool Focused = true;

		private static Thread _thread;

		public static void Start()
		{
			if (_thread == null)
			{
				Interlocked.Exchange(ref _beat, Sw.ElapsedTicks);
				_thread = new Thread(Watch)
				{
					IsBackground = true,
					Name = "GR_HangWatch",
					Priority = ThreadPriority.BelowNormal
				};
				_thread.Start();
			}
		}

		public static void Beat(int frame)
		{
			Interlocked.Exchange(ref _beat, Sw.ElapsedTicks);
			_frame = frame;
		}

		private static void Watch()
		{
			double num = 0.0;
			int num2 = -1;
			double num3 = 0.0;
			string text = "";
			bool flag = false;
			while (true)
			{
				try
				{
					Thread.Sleep(500);
					long num4 = Interlocked.Read(in _beat);
					double num5 = (double)(Sw.ElapsedTicks - num4) / (double)Stopwatch.Frequency;
					if (num5 > 4.0)
					{
						if (num2 != _frame)
						{
							num2 = _frame;
							num3 = 0.0;
							text = At + " / after " + Done;
							flag = !Focused;
						}
						if (!flag && num5 >= num3)
						{
							string text2 = "[hang] the game has not finished a frame for " + num5.ToString("0.0") + "s (frame " + _frame + ") - in: " + At + " - last finished job: " + Done + SafeProcMem();
							if (InMatch)
							{
								FileLog.Raw("Warning", text2);
							}
							else
							{
								FileLog.Raw("Info", text2 + " (not in a match: loading?)");
							}
							num3 = ((num3 == 0.0) ? 10.0 : (num3 + 10.0));
						}
						num = num5;
					}
					else if (num > 0.0)
					{
						if (flag)
						{
							FileLog.Raw("Info", "[hang] back after " + num.ToString("0.0") + "s with the window in the background (the game sleeps there)");
						}
						else if (InMatch)
						{
							FileLog.Raw("Warning", "[hang] the game came back after about " + num.ToString("0.0") + "s (it was in: " + text + ")");
						}
						else
						{
							FileLog.Raw("Info", "[hang] a " + num.ToString("0.0") + "s frame outside a match (it was in: " + text + ")");
						}
						num = 0.0;
						num2 = -1;
					}
				}
				catch
				{
				}
			}
		}

		private static string SafeProcMem()
		{
			try
			{
				return ProcMem();
			}
			catch
			{
				return "";
			}
		}

		private static string ProcMem()
		{
			try
			{
				using Process process = Process.GetCurrentProcess();
				return " (process " + (process.PrivateMemorySize64 >> 20) + " MB private, " + (process.WorkingSet64 >> 20) + " MB in RAM)";
			}
			catch
			{
				return "";
			}
		}
	}
	public static class Mem
	{
		private const double MB = 1048576.0;

		public static void Log()
		{
			try
			{
				Plugin.Log.LogInfo((object)Line());
			}
			catch
			{
			}
		}

		private static string Proc()
		{
			using Process process = Process.GetCurrentProcess();
			return ", process " + ((double)process.PrivateMemorySize64 / 1048576.0).ToString("0") + " MB private / " + ((double)process.WorkingSet64 / 1048576.0).ToString("0") + " MB in RAM";
		}

		private static string Unity()
		{
			return ", mono heap " + ((double)Profiler.GetMonoHeapSizeLong() / 1048576.0).ToString("0") + " MB, unity " + ((double)Profiler.GetTotalAllocatedMemoryLong() / 1048576.0).ToString("0") + " MB";
		}

		private static string Line()
		{
			StringBuilder stringBuilder = new StringBuilder("[mem]");
			try
			{
				stringBuilder.Append(" managed ").Append(((double)GC.GetTotalMemory(forceFullCollection: false) / 1048576.0).ToString("0")).Append(" MB");
			}
			catch
			{
			}
			try
			{
				stringBuilder.Append(Unity());
			}
			catch
			{
			}
			try
			{
				stringBuilder.Append(Proc());
			}
			catch
			{
			}
			try
			{
				stringBuilder.Append(", textures ").Append(Resources.FindObjectsOfTypeAll<Texture2D>().Length).Append(", sprites ")
					.Append(Resources.FindObjectsOfTypeAll<Sprite>().Length);
			}
			catch
			{
			}
			try
			{
				stringBuilder.Append(", objects ").Append(Object.FindObjectsOfType<GameObject>().Length);
			}
			catch
			{
			}
			stringBuilder.Append(", up ").Append((Time.realtimeSinceStartup / 60f).ToString("0.0")).Append(" min");
			return stringBuilder.ToString();
		}
	}
	public static class NanGuard
	{
		[HarmonyPatch(typeof(PlayerController), "GetDodgeRollSpeed")]
		private static class RollSpeed
		{
			private static void Postfix(ref float __result)
			{
				if (!Ok(__result))
				{
					__result = 0f;
				}
			}
		}

		[HarmonyPatch(/*Could not decode attribute arguments.*/)]
		private static class Ray
		{
			private unsafe static bool Prefix(Position origin, Vector2 direction, float dist, out RaycastResult result, ref bool __result)
			{
				//IL_0003: Unknown result type (might be due to invalid IL or missing references)
				//IL_0004: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_008e: 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_0022: Unknown result type (might be due to invalid IL or missing references)
				//IL_0023: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: 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_0049: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				result = null;
				IntVector2 position = origin.m_position;
				if (Ok(direction) && Ok(dist) && !(dist > 2000f) && Ok(origin.m_remainder) && position.x >= -2000000 && position.x <= 2000000 && position.y >= -2000000 && position.y <= 2000000)
				{
					return true;
				}
				RaysRefused++;
				if (RaysRefused <= 3)
				{
					ManualLogSource log = Plugin.Log;
					string[] array = new string[6] { "[nan guard] refused a raycast toward a bad number (dir ", null, null, null, null, null };
					Vector2 val = direction;
					array[1] = ((object)(*(Vector2*)(&val))/*cast due to .constrained prefix*/).ToString();
					array[2] = ", dist ";
					array[3] = dist.ToString();
					array[4] = ") during ";
					array[5] = Hang.At;
					log.LogWarning((object)string.Concat(array));
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(Gun), "Attack")]
		private static class Attack
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Gun __instance, ref AttackResult __result)
			{
				int ghostShots = GhostShots;
				if (GunOk(__instance))
				{
					return true;
				}
				if (GhostShots != ghostShots)
				{
					__instance.CeaseAttack(false, (ProjectileData)null);
					__result = (AttackResult)4;
					return false;
				}
				ShotsRefused++;
				if (ShotsRefused <= 3)
				{
					Plugin.Log.LogWarning((object)("[nan guard] a gun aimed at a bad number didn't fire: " + ((Object)__instance).name));
				}
				__result = (AttackResult)4;
				return false;
			}
		}

		[HarmonyPatch(typeof(Gun), "ContinueAttack")]
		private static class Continue
		{
			[HarmonyPriority(800)]
			private static bool Prefix(Gun __instance, ref bool __result)
			{
				int ghostShots = GhostShots;
				if (GunOk(__instance))
				{
					return true;
				}
				if (GhostShots == ghostShots)
				{
					ShotsRefused++;
				}
				__result = false;
				return false;
			}
		}

		public static int Fixed;

		public static int RaysRefused;

		public static int ShotsRefused;

		public static int GhostShots;

		private static readonly Dictionary<Fighter, Vector2> _lastGood = new Dictionary<Fighter, Vector2>();

		private static readonly HashSet<string> _logged = new HashSet<string>();

		private static readonly FieldRef<KnockbackDoer, List<ActiveKnockbackData>> KnockRef = AccessTools.FieldRefAccess<KnockbackDoer, List<ActiveKnockbackData>>("m_activeKnockbacks");

		private static readonly FieldRef<PlayerController, float> GunAngleRef = AccessTools.FieldRefAccess<PlayerController, float>("m_currentGunAngle");

		public static bool Ok(float v)
		{
			if (!float.IsNaN(v) && !float.IsInfinity(v) && v > -1000000f)
			{
				return v < 1000000f;
			}
			return false;
		}

		public static bool Ok(Vector2 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			if (Ok(v.x))
			{
				return Ok(v.y);
			}
			return false;
		}

		public static bool Ok(Vector3 v)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			if (Ok(v.x) && Ok(v.y))
			{
				return Ok(v.z);
			}
			return false;
		}

		private static void Note(string who, string what)
		{
			Fixed++;
			string item = who + "|" + what;
			if (_logged.Count < 40 && _logged.Add(item))
			{
				Plugin.Log.LogWarning((object)("[nan guard] " + who + ": " + what + " was not a number - reset (phase " + MatchState.Phase.ToString() + ", time scale " + Time.timeScale.ToString("0.##") + ")"));
			}
		}

		public static void Tick()
		{
			foreach (Fighter fighter in MatchState.Fighters)
			{
				if (fighter.HasBody)
				{
					try
					{
						Check(fighter);
					}
					catch
					{
					}
				}
			}
		}

		private static void Check(Fighter f)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: 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_0069: 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_0091: 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_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0210: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0249: Unknown result type (might be due to invalid IL or missing references)
			//IL_0242: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			PlayerController pc = f.Pc;
			SpeculativeRigidbody specRigidbody = ((BraveBehaviour)pc).specRigidbody;
			if ((Object)(object)specRigidbody == (Object)null)
			{
				return;
			}
			if (!Ok(specRigidbody.Velocity))
			{
				specRigidbody.Velocity = Vector2.zero;
				Note(f.Name, "velocity");
			}
			if (!Ok(((GameActor)pc).ImpartedVelocity))
			{
				((GameActor)pc).ImpartedVelocity = Vector2.zero;
				Note(f.Name, "pushed velocity");
			}
			if (!Ok(pc.knockbackComponent))
			{
				pc.knockbackComponent = Vector2.zero;
				Note(f.Name, "knockback");
			}
			if (!Ok(pc.immutableKnockbackComponent))
			{
				pc.immutableKnockbackComponent = Vector2.zero;
				Note(f.Name, "knockback");
			}
			if (Object.op_Implicit((Object)(object)((BraveBehaviour)pc).knockbackDoer))
			{
				List<ActiveKnockbackData> list = KnockRef.Invoke(((BraveBehaviour)pc).knockbackDoer);
				if (list != null)
				{
					for (int num = list.Count - 1; num >= 0; num--)
					{
						if (list[num] == null || !Ok(list[num].knockback) || !Ok(list[num].initialKnockback))
						{
							list.RemoveAt(num);
							Note(f.Name, "knockback");
						}
					}
				}
			}
			if (!Ok(pc.forceAimPoint.GetValueOrDefault()))
			{
				pc.forceAimPoint = null;
				Note(f.Name, "aim");
			}
			if (!Ok(GunAngleRef.Invoke(pc)))
			{
				GunAngleRef.Invoke(pc) = 0f;
				Note(f.Name, "gun angle");
			}
			if ((Object)(object)((GameActor)pc).CurrentGun != (Object)null && !Ok(((GameActor)pc).CurrentGun.CurrentAngle))
			{
				((GameActor)pc).CurrentGun.HandleAimRotation(Vector2.op_Implicit(specRigidbody.UnitCenter + Vector2.right), false, 1f);
				Note(f.Name, "gun angle");
			}
			Vector2 unitCenter = specRigidbody.UnitCenter;
			if (Ok(unitCenter) && Ok(Vector2.op_Implicit(((BraveBehaviour)pc).transform.position)))
			{
				_lastGood[f] = unitCenter;
				return;
			}
			if (!_lastGood.TryGetValue(f, out var value))
			{
				value = ((IntVector2)(ref ArenaBuilder.IslandCenter)).ToCenterVector2();
			}
			Respawn.Warp(f, value);
			Note(f.Name, "position");
		}

		public static void Clear()
		{
			_lastGood.Clear();
		}

		private static bool GunOk(Gun g)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)g == (Object)null)
			{
				return true;
			}
			try
			{
				GameActor currentOwner = g.CurrentOwner;
				PlayerController val = (PlayerController)(object)((currentOwner is PlayerController) ? currentOwner : null);
				if ((Object)(object)val != (Object)null && MatchState.Active)
				{
					Fighter fighter = MatchState.ByPc(val);
					if (fighter != null && (fighter.Dead || fighter.Eliminated))
					{
						GhostShots++;
						return false;
					}
				}
				if (!Ok(g.CurrentAngle))
				{
					return false;
				}
				if ((Object)(object)g.barrelOffset != (Object)null && !Ok(g.barrelOffset.position))
				{
					return false;
				}
				GameActor currentOwner2 = g.CurrentOwner;
				if ((Object)(object)currentOwner2 != (Object)null && (Object)(object)((BraveBehaviour)currentOwner2).specRigidbody != (Object)null && !Ok(((BraveBehaviour)currentOwner2).specRigidbody.UnitCenter))
				{
					return false;
				}
			}
			catch
			{
			}
			return true;
		}
	}
	[BepInPlugin("heartpulse.entertherounds", "Enter the Rounds", "0.6.31")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "heartpulse.entertherounds";

		public const string Name = "Enter the Rounds";

		public const string Version = "0.6.31";

		public static Plugin Instance;

		public static ManualLogSource Log;

		public static string DataDir;

		public static string LocalDir;

		public static ConfigEntry<bool> DevTools;

		public static bool Autopilot;

		public static ConfigEntry<string> PlayerName;

		public static ConfigEntry<int> PlayerColor;

		public static ConfigEntry<int> ScreenShake;

		public static GameObject Root;

		public static readonly bool SecondCopy = Array.IndexOf(Environment.GetCommandLineArgs(), "-gr-second") >= 0;

		private float _windowCheck;

		private float _syncLogAt;

		private int _memN;

		private int _hitches;

		private float _hitch;

		private int _shotN;

		private void Awake()
		{
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_037b: Expected O, but got Unknown
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			DataDir = Path.Combine(Paths.BepInExRootPath, "GungeonRounds");
			Directory.CreateDirectory(DataDir);
			LocalDir = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "GungeonRounds");
			Directory.CreateDirectory(LocalDir);
			try
			{
				Logger.Listeners.Add((ILogListener)(object)new FileLog(Path.Combine(DataDir, SecondCopy ? "gungeonrounds.2.log" : "gungeonrounds.log")));
			}
			catch
			{
			}
			if (SecondCopy)
			{
				SecondCopySetup();
			}
			DevTools = ((BaseUnityPlugin)this).Config.Bind<bool>("Dev", "DevTools", false, "Developer hotkeys (F6 solo test, F7 skip round, F8 money).");
			PlayerName = ((BaseUnityPlugin)this).Config.Bind<string>("Player", "Name", "", "Name shown to other players (blank = Steam name).");
			ScreenShake = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "ScreenShake", 40, "Screen shake in a match, 0-100 (set in the lobby or the pause menu).");
			PlayerColor = ((BaseUnityPlugin)this).Config.Bind<int>("Player", "Color", -1, "Your gunslinger's colour (an index into the lobby's palette; -1 = whatever's free). Picked in the lobby.");
			Harmony val = new Harmony("heartpulse.entertherounds");
			int num = 0;
			int num2 = 0;
			Type[] types = typeof(Plugin).Assembly.GetTypes();
			foreach (Type type in types)
			{
				if (type.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0)
				{
					try
					{
						val.CreateClassProcessor(type).Patch();
						num++;
					}
					catch (Exception ex)
					{
						num2++;
						Log.LogError((object)("Patch " + type.FullName + " failed: " + ex.Message));
					}
				}
			}
			Log.LogInfo((object)$"Harmony: {num} patch classes applied, {num2} failed");
			ConfigEntry<int> val2 = ((BaseUnityPlugin)this).Config.Bind<int>("Dev", "NetSimLatencyMs", 0, "Developer: the local test link (two copies on one PC) delays every packet this copy receives by this many ms.");
			ConfigEntry<int> val3 = ((BaseUnityPlugin)this).Config.Bind<int>("Dev", "NetSimJitterMs", 0, "Developer: and up to this many ms more at random (packets can arrive out of order).");
			ConfigEntry<int> val4 = ((BaseUnityPlugin)this).Config.Bind<int>("Dev", "NetSimLossPct", 0, "Developer: and drops this percentage of them.");
			if (DevTools.Value)
			{
				UdpTransport.SimLatencyMs = val2.Value;
				UdpTransport.SimJitterMs = val3.Value;
				UdpTransport.SimLossPct = val4.Value;
			}
			if (UdpTransport.SimLatencyMs + UdpTransport.SimJitterMs + UdpTransport.SimLossPct > 0)
			{
				Log.LogInfo((object)$"[net] dev: simulating a bad link: {val2.Value} ms + up to {val3.Value} ms, {val4.Value}% lost");
			}
			ConfigEntry<string> val5 = ((BaseUnityPlugin)this).Config.Bind<string>("Dev", "Autopilot", "", "Developer: the AI plays this copy's own fighter in a match: \"second\" (only the second copy), \"both\", or blank (off). For testing online play with two copies.");
			if (DevTools.Value)
			{
				Autopilot = val5.Value == "both" || (val5.Value == "second" && SecondCopy);
			}
			if (Autopilot)
			{
				Log.LogInfo((object)"[dev] autopilot: the AI plays this copy's fighter");
			}
			ConfigEntry<bool> val6 = ((BaseUnityPlugin)this).Config.Bind<bool>("Dev", "AllocProbe", false, "Developer: measure what allocates memory every frame (slow start).");
			if (DevTools.Value && val6.Value)
			{
				try
				{
					AllocProbe.Install(val);
				}
				catch (Exception ex2)
				{
					Log.LogWarning((object)("[alloc] " + ex2.Message));
				}
			}
			Root = new GameObject("GungeonRounds");
			Object.DontDestroyOnLoad((Object)(object)Root);
			Root.AddComponent<NetSession>();
			Root.AddComponent<MatchDirector>();
			Root.AddComponent<Hud>();
			Root.AddComponent<LobbyScreen>();
			Root.AddComponent<ShopScreen>();
			Hang.Start();
			AutoTest.Init();
			Log.LogInfo((object)("Enter the Rounds 0.6.31 loaded. Data: " + DataDir));
		}

		private static void SecondCopySetup()
		{
			try
			{
				string savePath = SaveManager.SavePath;
				string text = Path.Combine(LocalDir, "second_copy_saves");
				Directory.CreateDirectory(text);
				if (Directory.GetFiles(text).Length == 0 && Directory.Exists(savePath))
				{
					string[] files = Directory.GetFiles(savePath);
					foreach (string text2 in files)
					{
						File.Copy(text2, Path.Combine(text, Path.GetFileName(text2)), overwrite: true);
					}
				}
				SaveManager.SavePath = text;
				Log.LogInfo((object)("[dev] second copy: saves in " + text));
			}
			catch (Exception ex)
			{
				Log.LogError((object)("[dev] second copy saves: " + ex.Message));
			}
		}

		private void OnApplicationFocus(bool focused)
		{
			Hang.Focused = focused;
		}

		private void Update()
		{
			//IL_03d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_03dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_03fc: Unknown result type (might be due to invalid IL or missing references)
			Hang.Beat(Time.frameCount);
			Hang.At = "frame start";
			Hang.InMatch = MatchState.Active && MatchState.Phase != Phase.Loading;
			AutoTest.Tick();
			Prof.FrameMark();
			float unscaledDeltaTime = Time.unscaledDeltaTime;
			if (unscaledDeltaTime > _hitch)
			{
				_hitch = unscaledDeltaTime;
			}
			if (unscaledDeltaTime > 0.05f)
			{
				_hitches++;
			}
			if (SecondCopy && Time.unscaledTime > _windowCheck)
			{
				_windowCheck = Time.unscaledTime + 2f;
				if (Screen.fullScreen || Screen.width != 1280)
				{
					Screen.SetResolution(1280, 720, false);
				}
			}
			if (DevTools.Value && Input.GetKeyDown((KeyCode)291))
			{
				((MonoBehaviour)this).StartCoroutine(Capture());
			}
			if (DevTools.Value && (!MatchState.Active || (MatchState.Phase != Phase.Round && MatchState.Phase != Phase.Boss)) && Time.unscaledTime > _syncLogAt)
			{
				_syncLogAt = Time.unscaledTime + 10f;
				Log.LogInfo((object)("[" + (MatchState.Active ? MatchState.Phase.ToString() : "menu") + "] " + Prof.Report() + " heap=" + (GC.GetTotalMemory(forceFullCollection: false) >> 20) + "MB"));
				if (AllocProbe.Installed)
				{
					Log.LogInfo((object)AllocProbe.Report());
				}
			}
			else
			{
				if (!DevTools.Value || !MatchState.Active || (MatchState.Phase != Phase.Round && MatchState.Phase != Phase.Boss) || !(Time.unscaledTime > _syncLogAt))
				{
					return;
				}
				_syncLogAt = Time.unscaledTime + 10f;
				StringBuilder stringBuilder = new StringBuilder("[sync] t=" + MatchState.Clock.ToString("0.0") + " enemies=" + Waves.Live.Count + " fallen=" + Crumble.Fallen + " pvp=" + FighterHealth.PvpHitCount + "/" + FighterHealth.PvpDamage.ToString("0") + " coins=" + MoneyDrops.Count + " proj=" + StaticReferenceManager.AllProjectiles.Count + " mem=" + (GC.GetTotalMemory(forceFullCollection: false) >> 20) + "/" + (Profiler.GetTotalAllocatedMemoryLong() >> 20) + "MB fps=" + (1f / Mathf.Max(0.001f, Time.smoothDeltaTime)).ToString("0") + " worst=" + (_hitch * 1000f).ToString("0") + "ms hitches=" + _hitches);
				_hitch = 0f;
				_hitches = 0;
				foreach (Fighter fighter in MatchState.Fighters)
				{
					stringBuilder.Append(" | ").Append(fighter.Slot).Append(' ')
						.Append(fighter.Name)
						.Append(fighter.HasBody ? (" @" + fighter.Center.x.ToString("0.0") + "," + fighter.Center.y.ToString("0.0")) : " nobody")
						.Append(" hp")
						.Append(fighter.Hp.ToString("0"))
						.Append(fighter.Dead ? " dead" : "")
						.Append(" $")
						.Append(fighter.Money);
				}
				Log.LogInfo((object)stringBuilder.ToString());
				Log.LogInfo((object)Prof.Report());
				if (AllocProbe.Installed)
				{
					Log.LogInfo((object)AllocProbe.Report());
				}
				if (_memN++ % 3 == 0)
				{
					Log.LogInfo((object)("[mem] tex=" + Resources.FindObjectsOfTypeAll(typeof(Texture2D)).Length + " mat=" + Resources.FindObjectsOfTypeAll(typeof(Material)).Length + " go=" + Resources.FindObjectsOfTypeAll(typeof(GameObject)).Length + " sprite=" + Resources.FindObjectsOfTypeAll(typeof(Sprite)).Length + " mesh=" + Resources.FindObjectsOfTypeAll(typeof(Mesh)).Length + " gfx=" + Gfx.CacheCount + " px=" + PixelArt.CacheCount + " mono=" + (Profiler.GetMonoUsedSizeLong() >> 20) + "MB reserved=" + (Profiler.GetTotalReservedMemoryLong() >> 20) + "MB" + TopNames(typeof(Material)) + TopNames(typeof(Mesh))));
					Log.LogInfo((object)("[mem] instanced materials held by: " + MatOwners()));
				}
				if (SecondCopy && _shotN++ % 2 == 0)
				{
					((MonoBehaviour)this).StartCoroutine(Capture());
				}
			}
		}

		private static string MatOwners()
		{
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Expected O, but got Unknown
			HashSet<Material> hashSet = new HashSet<Material>();
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			foreach (Renderer val in array)
			{
				Material[] sharedMaterials = val.sharedMaterials;
				foreach (Material val2 in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val2) && ((Object)val2).name.EndsWith("(Instance)") && hashSet.Add(val2))
					{
						string text = (Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<Projectile>()) ? "bullet" : (Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<AIActor>()) ? "enemy" : (Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<PlayerController>()) ? "player" : (Object.op_Implicit((Object)(object)((Component)val).GetComponentInParent<DebrisObject>()) ? "debris" : ((Object)((Component)val).transform.root).name))));
						if (text.Length > 24)
						{
							text = text.Substring(0, 24);
						}
						dictionary.TryGetValue(text, out var value);
						dictionary[text] = value + 1;
					}
				}
			}
			int num = 0;
			Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
			Object[] array2 = Resources.FindObjectsOfTypeAll(typeof(Material));
			for (int k = 0; k < array2.Length; k++)
			{
				Material val3 = (Material)array2[k];
				if (!((Object)val3).name.EndsWith("(Instance)"))
				{
					continue;
				}
				num++;
				if (!hashSet.Contains(val3))
				{
					string text2 = (((Object)(object)val3.shader != (Object)null) ? ((Object)val3.shader).name : "?") + "/" + (((Object)(object)val3.mainTexture != (Object)null) ? ((Object)val3.mainTexture).name : "-");
					if (text2.Length > 60)
					{
						text2 = text2.Substring(text2.Length - 60);
					}
					dictionary2.TryGetValue(text2, out var value2);
					dictionary2[text2] = value2 + 1;
				}
			}
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("unheld=").Append(num - hashSet.Count).Append(" held=")
				.Append(hashSet.Count);
			List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(dictionary2);
			list.Sort((KeyValuePair<string, int> x, KeyValuePair<string, int> y) => y.Value.CompareTo(x.Value));
			stringBuilder.Append(" | unheld:");
			for (int num2 = 0; num2 < list.Count && num2 < 5; num2++)
			{
				stringBuilder.Append(' ').Append(list[num2].Key).Append('=')
					.Append(list[num2].Value);
			}
			stringBuilder.Append(" | held by:");
			List<KeyValuePair<string, int>> list2 = new List<KeyValuePair<string, int>>(dictionary);
			list2.Sort((KeyValuePair<string, int> x, KeyValuePair<string, int> y) => y.Value.CompareTo(x.Value));
			for (int num3 = 0; num3 < list2.Count && num3 < 6; num3++)
			{
				stringBuilder.Append(' ').Append(list2[num3].Key).Append('=')
					.Append(list2[num3].Value);
			}
			return stringBuilder.ToString();
		}

		private static string TopNames(Type t)
		{
			Dictionary<string, int> dictionary = new Dictionary<string, int>();
			Object[] array = Resources.FindObjectsOfTypeAll(t);
			for (int i = 0; i < array.Length; i++)
			{
				string name = array[i].name;
				dictionary.TryGetValue(name, out var value);
				dictionary[name] = value + 1;
			}
			List<KeyValuePair<string, int>> list = new List<KeyValuePair<string, int>>(dictionary);
			list.Sort((KeyValuePair<string, int> a, KeyValuePair<string, int> b) => b.Value.CompareTo(a.Value));
			StringBuilder stringBuilder = new StringBuilder(" " + t.Name + "[");
			for (int num = 0; num < list.Count && num < 5; num++)
			{
				stringBuilder.Append((list[num].Key.Length > 40) ? list[num].Key.Substring(0, 40) : list[num].Key).Append('=').Append(list[num].Value)
					.Append((num < 4) ? "; " : "");
			}
			return stringBuilder.Append(']').ToString();
		}

		private IEnumerator Capture()
		{
			yield return (object)new WaitForEndOfFrame();
			try
			{
				string text = Path.Combine(DataDir, "shots");
				Directory.CreateDirectory(text);
				string text2 = Path.Combine(text, (SecondCopy ? "client_" : "gr_") + DateTime.Now.ToString("yyyyMMdd_HHmmss") + ".png");
				Texture2D val = new Texture2D(Screen.width, Screen.height, (TextureFormat)3, false);
				val.ReadPixels(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), 0, 0);
				val.Apply();
				File.WriteAllBytes(text2, ImageConversion.EncodeToPNG(val));
				Object.Destroy((Object)(object)val);
				Log.LogInfo((object)("[dev] screenshot " + text2));
			}
			catch (Exception ex)
			{
				Log.LogWarning((object)("[dev] screenshot: " + ex.Message));
			}
		}
	}
	public static class Prof
	{
		private static readonly Stopwatch Sw = Stopwatch.StartNew();

		private static readonly Dictionary<string, double> _frame = new Dictionary<string, double>();

		private static readonly Dictionary<string, double> _max = new Dictionary<string, double>();

		private static readonly Dictionary<string, double> _sum = new Dictionary<string, double>();

		private static int _reportFrame = -1;

		private static readonly List<string> _keys = new List<string>();

		private static int _frameNo = -1;

		private static int _gc0 = -1;

		private static long _m0;

		private static readonly Dictionary<string, long> _alloc = new Dictionary<string, long>();

		private static readonly List<string> _akeys = new List<string>();

		private static long _lastTotal = -1L;

		private static long _allAlloc;

		public static bool On
		{
			get
			{
				if (Plugin.DevTools != null)
				{
					return Plugin.DevTools.Value;
				}
				return false;
			}
		}

		public static long T
		{
			get
			{
				if (On)
				{
					_m0 = GC.GetTotalMemory(forceFullCollection: false);
				}
				return Sw.ElapsedTicks;
			}
		}

		public static long M
		{
			get
			{
				if (!On)
				{
					return 0L;
				}
				return GC.GetTotalMemory(forceFullCollection: false);
			}
		}

		public static long S => Sw.ElapsedTicks;

		public static void Add(string key, long t0)
		{
			Hang.Done = key;
			if (On)
			{
				if (Time.frameCount != _frameNo)
				{
					Flush();
				}
				double num = (double)(Sw.ElapsedTicks - t0) * 1000.0 / (double)Stopwatch.Frequency;
				_frame.TryGetValue(key, out var value);
				_frame[key] = value + num;
				long num2 = GC.GetTotalMemory(forceFullCollection: false) - _m0;
				if (num2 > 0)
				{
					_alloc.TryGetValue(key, out var value2);
					_alloc[key] = value2 + num2;
				}
			}
		}

		public static void Sub(string key, long t0, long m0)
		{
			if (On)
			{
				if (Time.frameCount != _frameNo)
				{
					Flush();
				}
				double num = (double)(Sw.ElapsedTicks - t0) * 1000.0 / (double)Stopwatch.Frequency;
				_frame.TryGetValue(key, out var value);
				_frame[key] = value + num;
				long num2 = GC.GetTotalMemory(forceFullCollection: false) - m0;
				if (num2 > 0)
				{
					_alloc.TryGetValue(key, out var value2);
					_alloc[key] = value2 + num2;
				}
			}
		}

		public static void Ms(string key, long t0)
		{
			if (On)
			{
				if (Time.frameCount != _frameNo)
				{
					Flush();
				}
				double num = (double)(Sw.ElapsedTicks - t0) * 1000.0 / (double)Stopwatch.Frequency;
				_frame.TryGetValue(key, out var value);
				_frame[key] = value + num;
			}
		}

		public static void FrameMark()
		{
			if (On)
			{
				long totalMemory = GC.GetTotalMemory(forceFullCollection: false);
				if (_lastTotal >= 0 && totalMemory > _lastTotal)
				{
					_allAlloc += totalMemory - _lastTotal;
				}
				_lastTotal = totalMemory;
			}
		}

		private static void Flush()
		{
			foreach (KeyValuePair<string, double> item in _frame)
			{
				_max.TryGetValue(item.Key, out var value);
				if (item.Value > value)
				{
					_max[item.Key] = item.Value;
				}
				_sum.TryGetValue(item.Key, out var value2);
				_sum[item.Key] = value2 + item.Value;
			}
			_frame.Clear();
			_frameNo = Time.frameCount;
		}

		public static string Report()
		{
			Flush();
			_keys.Clear();
			_keys.AddRange(_max.Keys);
			_keys.Sort((string a, string b) => _max[b].CompareTo(_max[a]));
			int num = Mathf.Max(1, (_reportFrame < 0) ? 1 : (Time.frameCount - _reportFrame));
			_reportFrame = Time.frameCount;
			StringBuilder stringBuilder = new StringBuilder("[prof] worst-frame ms (~average):");
			for (int num2 = 0; num2 < _keys.Count && num2 < 9; num2++)
			{
				_sum.TryGetValue(_keys[num2], out var value);
				stringBuilder.Append(' ').Append(_keys[num2]).Append('=')
					.Append(_max[_keys[num2]].ToString("0.0"))
					.Append('~')
					.Append((value / (double)num).ToString("0.0"));
			}
			stringBuilder.Append(" | frames=").Append(num);
			_akeys.Clear();
			_akeys.AddRange(_alloc.Keys);
			_akeys.Sort((string a, string b) => _alloc[b].CompareTo(_alloc[a]));
			stringBuilder.Append(" | alloc KB: all=").Append(_allAlloc >> 10);
			_allAlloc = 0L;
			for (int num3 = 0; num3 < _akeys.Count && num3 < 7; num3++)
			{
				stringBuilder.Append(' ').Append(_akeys[num3]).Append('=')
					.Append(_alloc[_akeys[num3]] >> 10);
			}
			_alloc.Clear();
			int num4 = GC.CollectionCount(0);
			if (_gc0 >= 0)
			{
				stringBuilder.Append(" | gc=").Append(num4 - _gc0);
			}
			_gc0 = num4;
			_max.Clear();
			_sum.Clear();
			return stringBuilder.ToString();
		}
	}
	public sealed class Rng
	{
		private uint _s;

		public Rng(int seed)
		{
			_s = (uint)(seed ^ -1640531527);
			if (_s == 0)
			{
				_s = 1u;
			}
			Next();
			Next();
		}

		public uint Next()
		{
			_s ^= _s << 13;
			_s ^= _s >> 17;
			_s ^= _s << 5;
			return _s;
		}

		public float Value()
		{
			return (float)(Next() & 0xFFFFFF) / 16777216f;
		}

		public int Range(int minInclusive, int maxExclusive)
		{
			if (maxExclusive > minInclusive)
			{
				return minInclusive + (int)(Next() % (uint)(maxExclusive - minInclusive));
			}
			return minInclusive;
		}

		public float Range(float a, float b)
		{
			return a + (b - a) * Value();
		}

		public T Pick<T>(IList<T> list)
		{
			return list[Range(0, list.Count)];
		}

		public void Shuffle<T>(IList<T> list)
		{
			for (int num = list.Count - 1; num > 0; num--)
			{
				int index = Range(0, num + 1);
				T value = list[num];
				list[num] = list[index];
				list[index] = value;
			}
		}

		public int Weighted(IList<float> weights)
		{
			float num = 0f;
			for (int i = 0; i < weights.Count; i++)
			{
				if (weights[i] > 0f)
				{
					num += weights[i];
				}
			}
			if (num <= 0f)
			{
				return -1;
			}
			float num2 = Value() * num;
			for (int j = 0; j < weights.Count; j++)
			{
				if (!(weights[j] <= 0f))
				{
					num2 -= weights[j];
					if (num2 <= 0f)
					{
						return j;
					}
				}
			}
			for (int num3 = weights.Count - 1; num3 >= 0; num3--)
			{
				if (weights[num3] > 0f)
				{
					return num3;
				}
			}
			return -1;
		}
	}
	public static class Sfx
	{
		private struct Transient
		{
			public GameObject Go;

			public float Until;
		}

		private static GameObject _stage;

		private static readonly List<Transient> _transients = new List<Transient>();

		public static GameObject StageGo
		{
			get
			{
				//IL_0012: Unknown result type (might be due to invalid IL or missing references)
				//IL_001c: Expected O, but got Unknown
				//IL_0063: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)_stage == (Object)null)
				{
					_stage = new GameObject("GR_StageAudio");
					Object.DontDestroyOnLoad((Object)(object)_stage);
					try
					{
						_stage.AddComponent<AkGameObj>();
					}
					catch
					{
					}
				}
				PlayerController val = (GameManager.HasInstance ? GameManager.Instance.PrimaryPlayer : null);
				if (Object.op_Implicit((Object)(object)val))
				{
					_stage.transform.position = ((BraveBehaviour)val).transform.position;
				}
				return _stage;
			}
		}

		public static void Play(string evt, GameObject at = null)
		{
			try
			{
				if ((Object)(object)at == (Object)null)
				{
					PlayerController val = (GameManager.HasInstance ? GameManager.Instance.PrimaryPlayer : null);
					at = (Object.op_Implicit((Object)(object)val) ? ((Component)val).gameObject : (GameManager.HasInstance ? ((Component)GameManager.Instance).gameObject : null));
				}
				if ((Object)(object)at != (Object)null)
				{
					AkSoundEngine.PostEvent(evt, at);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("sfx " + evt + ": " + ex.Message));
			}
		}

		public static void PlayStage(string evt)
		{
			Play(evt, StageGo);
		}

		public static void PlayFor(string evt, GameObject at, float seconds)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)at == (Object)null)
				{
					PlayerController val = (GameManager.HasInstance ? GameManager.Instance.PrimaryPlayer : null);
					at = (Object.op_Implicit((Object)(object)val) ? ((Component)val).gameObject : null);
				}
				GameObject val2 = new GameObject("GR_Sfx");
				if ((Object)(object)at != (Object)null)
				{
					val2.transform.position = at.transform.position;
				}
				try
				{
					val2.AddComponent<AkGameObj>();
				}
				catch
				{
				}
				AkSoundEngine.PostEvent(evt, val2);
				_transients.Add(new Transient
				{
					Go = val2,
					Until = Time.realtimeSinceStartup + seconds
				});
				if (_transients.Count > 48)
				{
					Cut(0);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("sfx " + evt + ": " + ex.Message));
			}
		}

		private static void Cut(int i)
		{
			Transient transient = _transients[i];
			_transients.RemoveAt(i);
			if (!((Object)(object)transient.Go == (Object)null))
			{
				try
				{
					AkSoundEngine.StopAll(transient.Go);
				}
				catch
				{
				}
				Object.Destroy((Object)(object)transient.Go);
			}
		}

		public static void Tick()
		{
			float realtimeSinceStartup = Time.realtimeSinceStartup;
			for (int num = _transients.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_transients[num].Go == (Object)null || realtimeSinceStartup >= _transients[num].Until)
				{
					Cut(num);
				}
			}
		}

		public static void CutAll()
		{
			for (int num = _transients.Count - 1; num >= 0; num--)
			{
				Cut(num);
			}
		}

		public static void StopStage()
		{
			if ((Object)(object)_stage == (Object)null)
			{
				return;
			}
			try
			{
				AkSoundEngine.StopAll(_stage);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("sfx stop stage: " + ex.Message));
			}
		}

		public static void RoundStart()
		{
			Play("Play_UI_boss_intro_01");
		}

		public static void CountdownTick()
		{
			Play("Play_UI_menu_select_01");
		}

		public static void CrumbleWarn(GameObject at = null)
		{
			Play("Play_OBJ_stone_crumble_01", at);
		}

		public static void CrumbleFall(GameObject at = null)
		{
			Play("Play_OBJ_rock_break_01", at);
		}

		public static void QuakeLoop()
		{
			PlayStage("Play_ENV_quake_loop_01");
		}

		public static void QuakeStop()
		{
			PlayStage("Stop_ENV_quake_loop_01");
		}

		public static void MoneySmall(GameObject at = null)
		{
			Play("Play_OBJ_coin_small_01", at);
		}

		public static void MoneyLarge(GameObject at = null)
		{
			Play("Play_OBJ_coin_large_01", at);
		}

		public static void MoneyLost(GameObject at = null)
		{
			Play("Play_OBJ_coin_spill_01", at);
		}

		public static void Respawn(GameObject at = null)
		{
			PlayFor("Play_OBJ_teleport_arrive_01", at, 2.5f);
		}

		public static void Death(GameObject at = null)
		{
			Play("Play_CHR_general_death_01", at);
		}

		public static void Fall(GameObject at = null)
		{
			PlayFor("Play_Fall", at, 2.5f);
		}

		public static void Eliminated()
		{
			Play("Play_UI_gameover_shot_01");
		}

		public static void ShopOpen()
		{
			Play("Play_UI_card_open_01");
		}

		public static void Buy()
		{
			Play("Play_OBJ_item_purchase_01");
		}

		public static void BuyFail()
		{
			Play("Play_OBJ_purchase_unable_01");
		}

		public static void Reroll()
		{
			PlayFor("Play_OBJ_Chest_Synergy_Slots_01", null, 2.5f);
		}

		public static void Ready()
		{
			Play("Play_UI_menu_confirm_01");
		}

		public static void RoundWin()
		{
			Play("Play_MUS_Anthem_Winner_Short_01");
		}

		public static void BossClear()
		{
			Play("Play_MUS_Victory_Theme_01");
		}

		public static void MatchOver()
		{
			Play("Play_UI_gameover_start_01");
		}

		public static void EnemySpawn(GameObject at = null)
		{
			Play("Play_ENM_spawn_appear_01", at);
		}

		public static void EnemySpawnWarn(GameObject at = null)
		{
			Play("Play_ENM_spawn_reticle_01", at);
		}

		public static void UiBack()
		{
			Play("Play_UI_menu_back_01");
		}

		public static void UiMove()
		{
			Play("Play_UI_menu_select_01");
		}

		public static void Hurt(GameObject at = null)
		{
			Play("Play_CHR_general_hurt_01", at);
		}

		public static void HeavyHurt(GameObject at = null)
		{
			Play("Play_CHR_major_damage_01", at);
		}

		public static void QuickReload(GameObject at = null)
		{
			Play("Play_WPN_active_reload_01", at);
		}

		public static void CoinDrop(GameObject at = null)
		{
			Play("Play_OBJ_coin_spill_01", at);
		}

		public static void CoinPickup(GameObject at = null)
		{
			Play("Play_OBJ_coin_medium_01", at);
		}

		public static void ChestSpawn(GameObject at = null)
		{
			Play("Play_OBJ_smallchest_spawn_01", at);
		}

		public static void ChestOpen(GameObject at = null)
		{
			Play("Play_OBJ_chest_open_01", at);
		}

		public static void ChestNoKey()
		{
			Play("Play_OBJ_purchase_unable_01");
		}

		public static void KeyUse(GameObject at = null)
		{
			Play("Play_OBJ_key_impact_01", at);
		}

		public static void KeysRefill()
		{
			Play("Play_OBJ_goldkey_pickup_01");
		}

		public static void RelicGet()
		{
			Play("Play_OBJ_metacoin_collect_01");
		}

		public static void BlankDash(GameObject at = null)
		{
			Play("Play_CHR_ninja_dash_01", at);
		}

		public static void LastRoom()
		{
			PlayStage("Play_BOSS_DragunGold_Thunder_01");
		}

		public static void DuelStart()
		{
			PlayStage("Play_OBJ_time_bell_01");
		}

		public static void Overtime()
		{
			PlayStage("Play_ENV_thunder_flash_01");
		}

		public static void BountyClaimed()
		{
			Play("Play_WPN_bountyhunterarm_shot_01");
		}

		public static void SlotSpin()
		{
			PlayFor("Play_OBJ_Chest_Synergy_Slots_01", null, 2.5f);
		}

		public static void SlotStop()
		{
			Play("Play_OBJ_coin_small_01");
		}

		public static void SecondWind(GameObject at = null)
		{
			PlayFor("Play_OBJ_silenceblank_small_01", at, 2.5f);
		}

		public static void HitConfirm(GameObject at = null)
		{
			Play("Play_WPN_metalbullet_impact_01", at);
		}

		public static void KillConfirm(GameObject at = null)
		{
			Play("Play_WPN_Vorpal_Shot_Critical_01", at);
		}

		public static void CritHit(GameObject at = null)
		{
			Play("Play_WPN_spark_impact_01", at);
		}

		public static void ShieldUp(GameObject at = null)
		{
			PlayFor("Play_OBJ_powerstar_use_01", at, 2f);
		}

		public static void ShieldBlock(GameObject at = null)
		{
			Play("Play_OBJ_metalskin_deflect_01", at);
		}

		public static void ShieldEnd(GameObject at = null)
		{
			PlayFor("Play_ITM_Macho_Brace_Fade_01", at, 2f);
		}

		public static void BurnIgnite(GameObject at = null)
		{
			Play("Play_ENV_oilfire_ignite_01", at);
		}

		public static void Freeze(GameObject at = null)
		{
			Play("Play_OBJ_crystal_shatter_01", at);
		}

		public static void ShockDischarge(GameObject at = null)
		{
			Play("Play_BOSS_lichC_zap_01", at);
		}

		public static void ToxinHit(GameObject at = null)
		{
			Play("Play_wpn_toxic_impact_01", at);
		}

		public static void ChainZap(GameObject at = null)
		{
			Play("Play_ENV_puddle_zap_01", at);
		}

		public static void DuelWarningTick(GameObject at = null)
		{
			Play("Play_UI_menu_select_01", at);
		}

		public static void ShowdownWhistle(GameObject at = null)
		{
			Play("Play_ENM_smiley_whistle_01", at ?? StageGo);
		}

		public static void ShowdownMusic(GameObject at = null)
		{
			Play("Play_MUS_Intro_Drum_01", at ?? StageGo);
		}

		public static void ShowdownBell(GameObject at = null)
		{
			Play("Play_FS_bell_step_01", at ?? StageGo);
		}

		public static void DrawShot(GameObject at = null)
		{
			Play("Play_WPN_smileyrevolver_shot_01", at ?? StageGo);
		}

		public static void DuelMusic(GameObject at = null)
		{
			Play("Play_MUS_Boss_Theme_Gull", at);
		}

		public static void MusicStop(GameObject at = null)
		{
			Play("Stop_MUS_All", at);
		}

		public static void Jackpot(GameObject at = null)
		{
			PlayFor("Play_OBJ_Chest_Synergy_Win_01", at, 4f);
		}

		public static void LeverPull(GameObject at = null)
		{
			Play("Play_OBJ_secret_switch_01", at);
		}

		public static void Payout(GameObject at = null)
		{
			PlayFor("Play_OBJ_shells_shower_01", at, 3f);
		}

		public static void RelicReveal(GameObject at = null)
		{
			PlayFor("Play_OBJ_passive_get_01", at, 4f);
		}

		public static void Synergy(GameObject at = null)
		{
			Play("Play_OBJ_power_up_01", at);
		}

		public static void WingFlap(GameObject at = null)
		{
			PlayFor("Play_ENM_Wing_Flap_01", at, 1.5f);
		}

		public static void StandPunch(GameObject at = null)
		{
			Play("Play_BOSS_Punchout_Punch_Hit_01", at);
		}

		public static void PhoenixRise(GameObject at = null)
		{
			PlayFor("Play_BOSS_dragun_heart_burst_01", at, 4f);
		}

		public static void BeeSting(GameObject at = null)
		{
			Play("Play_WPN_bees_impact_01", at);
		}

		public static void GuonBlock(GameObject at = null)
		{
			Play("Play_OBJ_daggershield_shot_01", at);
		}

		public static void GhostPhase(GameObject at = null)
		{
			PlayFor("Play_CHR_ghost_appear_01", at, 2.5f);
		}

		public static void JetStart(GameObject at = null)
		{
			PlayFor("Play_OBJ_jetpack_start_01", at, 0.7f);
		}

		public static void TabPut(GameObject at = null)
		{
			Play("Play_OBJ_key_impact_01", at);
		}

		public static void KillBlast(GameObject at = null)
		{
			Play("Play_WPN_grenade_blast_01", at);
		}

		public static void Blink(GameObject at = null)
		{
			PlayFor("Play_OBJ_teleport_depart_01", at, 2f);
		}

		public static void Ascend(GameObject at = null)
		{
			PlayFor("Play_OBJ_Chest_Synergy_Win_01", at, 4f);
		}
	}
}
namespace GungeonRounds.UI
{
	public static class BossCardPosse
	{
		[HarmonyPatch(typeof(BossCardUIController), "ToggleCoreVisiblity")]
		private static class Card
		{
			private static void Postfix(BossCardUIController __instance, bool visible)
			{
				//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_0105: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0118: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: 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_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0143: Unknown result type (might be due to invalid IL or missing references)
				//IL_014f: Unknown result type (might be due to invalid IL or missing references)
				if (!visible || !MatchState.Active || (Object)(object)__instance.playerSprite == (Object)null)
				{
					return;
				}
				try
				{
					Texture texture = __instance.playerSprite.Texture;
					Texture2D val = (Texture2D)(object)((texture is Texture2D) ? texture : null);
					if (!((Object)(object)val == (Object)(object)_tex) || !((Object)(object)_tex != (Object)null))
					{
						int num = (((Object)(object)val != (Object)null) ? ((Texture)val).width : 512);
						int num2 = (((Object)(object)val != (Object)null) ? ((Texture)val).height : 512);
						RectInt? artBox = ((num <= 2048 && num2 <= 2048) ? ArtBox(val) : ((RectInt?)null));
						if (artBox.HasValue)
						{
							Plugin.Log.LogInfo((object)$"[boss card] character art {num}x{num2}, drawn in {artBox.Value}");
						}
						int num3 = Mathf.Clamp(Mathf.Min(1800 / Mathf.Max(1, num), 1800 / Mathf.Max(1, num2)), 1, 4);
						if (artBox.HasValue)
						{
							RectInt value = artBox.Value;
							int num4 = ((RectInt)(ref value)).x * num3;
							value = artBox.Value;
							int num5 = ((RectInt)(ref value)).y * num3;
							value = artBox.Value;
							int num6 = ((RectInt)(ref value)).width * num3;
							value = artBox.Value;
							artBox = new RectInt(num4, num5, num6, ((RectInt)(ref value)).height * num3);
						}
						Texture2D val2 = Build(Mathf.Clamp(num * num3, 128, 2048), Mathf.Clamp(num2 * num3, 128, 2048), artBox);
						__instance.playerSprite.Texture = (Texture)(object)val2;
						__instance.playerSprite.OverrideMaterial = null;
						((dfControl)__instance.playerSprite).IsVisible = true;
						BraveDFTextureAnimator component = ((Component)__instance.playerSprite).GetComponent<BraveDFTextureAnimator>();
						if ((Object)(object)component != (Object)null)
						{
							component.textures = (Texture2D[])(object)new Texture2D[1] { val2 };
						}
						if ((Object)(object)__instance.coopSprite != (Object)null)
						{
							((dfControl)__instance.coopSprite).IsVisible = false;
						}
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("[boss card] " + ex.Message));
				}
			}
		}

		private static Texture2D _tex;

		private static string _key;

		private static readonly Dictionary<Texture2D, Color32[]> _pixels = new Dictionary<Texture2D, Color32[]>();

		private static string KeyFor(List<Fighter> list, int w, int h)
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append(w).Append('x').Append(h);
			foreach (Fighter item in list)
			{
				stringBuilder.Append('|').Append(item.Face).Append(item.Look)
					.Append(((object)Unsafe.As<Color, Color>(ref item.Color)/*cast due to .constrained prefix*/).ToString());
			}
			return stringBuilder.ToString();
		}

		public static Texture2D Build(int w, int h, RectInt? artBox = null)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0313: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0328: 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_0346: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0413: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0438: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_044b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0454: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0497: Unknown result type (might be due to invalid IL or missing references)
			//IL_049c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b7: Expected O, but got Unknown
			//IL_0517: Unknown result type (might be due to invalid IL or missing references)
			List<Fighter> list = new List<Fighter>(MatchState.Fighters);
			list.Sort((Fighter x, Fighter y) => (y.IsLocalHuman ? 1 : 0).CompareTo(x.IsLocalHuman ? 1 : 0));
			string text = KeyFor(list, w, h) + (artBox.HasValue ? ((object)artBox.Value/*cast due to .constrained prefix*/).ToString() : "");
			if ((Object)(object)_tex != (Object)null && _key == text)
			{
				return _tex;
			}
			if ((Object)(object)_tex != (Object)null)
			{
				Object.Destroy((Object)(object)_tex);
			}
			Color32[] array = (Color32[])(object)new Color32[w * h];
			_pixels.Clear();
			RectInt val = (RectInt)(((??)artBox) ?? new RectInt(Mathf.RoundToInt((float)w * 0.03f), 0, Mathf.RoundToInt((float)w * 0.3f), Mathf.RoundToInt((float)h * 0.48f)));
			int num = Mathf.Min(((RectInt)(ref val)).x, Mathf.RoundToInt((float)w * 0.02f));
			int num2 = Mathf.Min(Mathf.Max(((RectInt)(ref val)).xMax, Mathf.RoundToInt((float)w * 0.47f)), Mathf.RoundToInt((float)w * 0.47f));
			int num3 = Mathf.Max(((RectInt)(ref val)).yMax, Mathf.RoundToInt((float)h * 0.64f));
			RectInt val2 = default(RectInt);
			((RectInt)(ref val2))..ctor(num, ((RectInt)(ref val)).y, Mathf.Max(8, num2 - num), Mathf.Max(8, num3 - ((RectInt)(ref val)).y));
			float num4 = Mathf.Max((float)((RectInt)(ref val2)).y, (float)h * 0.07f);
			float num5 = ((RectInt)(ref val2)).yMax;
			int num6 = Mathf.Max(1, list.Count);
			int[] array2 = ((num6 > 4) ? new int[2]
			{
				(num6 + 1) / 2,
				num6 / 2
			} : new int[1] { num6 });
			List<Vector3> list2 = new List<Vector3>();
			for (int num7 = Mathf.Max(1, Mathf.FloorToInt((float)h * 0.42f / 32f)); num7 >= 1; num7--)
			{
				list2.Clear();
				for (int num8 = 0; num8 < array2.Length; num8++)
				{
					float num9 = (float)num7 * ((num8 == 1) ? 0.8f : 1f);
					float num10 = (float)((RectInt)(ref val2)).xMax - 13f * (float)num7 - (float)num8 * 0.5f * 24f * 0.75f * (float)num7;
					float num11 = num4 + (float)num8 * 0.5f * 32f * (float)num7;
					int num12 = 0;
					for (int num13 = 0; num13 < array2[num8]; num13++)
					{
						int num14 = Mathf.Max(1, Mathf.RoundToInt(num9 * Mathf.Pow(0.84f, (float)num13)));
						if (num13 > 0)
						{
							num10 -= (12f * (float)num12 + 12f * (float)num14) * 0.8f;
							num11 += 9.6f * (float)num12;
						}
						list2.Add(new Vector3(num10, num11, (float)num14));
						num12 = num14;
					}
				}
				float num15 = float.MaxValue;
				float num16 = 0f;
				foreach (Vector3 item in list2)
				{
					num15 = Mathf.Min(num15, item.x - 13f * item.z);
					num16 = Mathf.Max(num16, item.y + 32f * item.z);
				}
				if (num15 >= (float)((RectInt)(ref val2)).x && num16 <= num5)
				{
					break;
				}
			}
			List<int> list3 = new List<int>();
			if (array2.Length == 1)
			{
				for (int num17 = 0; num17 < num6; num17++)
				{
					list3.Add(num17);
				}
			}
			else
			{
				List<int> list4 = new List<int>();
				List<int> list5 = new List<int>();
				for (int num18 = 0; num18 < num6; num18++)
				{
					((num18 % 2 == 0) ? list4 : list5).Add(num18);
				}
				list3.AddRange(list4);
				list3.AddRange(list5);
			}
			for (int num19 = list2.Count - 1; num19 >= 0; num19--)
			{
				Vector3 val3 = list2[num19];
				if (list3[num19] < list.Count)
				{
					Paint(array, w, h, list[list3[num19]], val3.x, val3.y + 12f * val3.z, (int)val3.z);
				}
			}
			int num20 = ((list2.Count > 0) ? ((int)list2[0].z) : 0);
			_pixels.Clear();
			_tex = new Texture2D(w, h, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)0,
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)61
			};
			_tex.SetPixels32(array);
			_tex.Apply(false);
			_key = text;
			Plugin.Log.LogInfo((object)$"[boss card] posse of {num6} drawn {w}x{h}: leader at {num20}x, {array2.Length} line(s), in {val2}");
			return _tex;
		}

		private static void Paint(Color32[] px, int w, int h, Fighter f, float cx, float cy, int k)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			DrawShadow(px, w, h, (int)cx, (int)(cy - (float)(12 * k)), 11 * k, Mathf.Max(2, 3 * k));
			int num = Mathf.Max(2, Mathf.RoundToInt((float)k * 0.75f));
			Color32 value = default(Color32);
			((Color32)(ref value))..ctor((byte)18, (byte)10, (byte)14, byte.MaxValue);
			DrawFighter(px, w, h, (int)cx - num, (int)cy, k, f, value);
			DrawFighter(px, w, h, (int)cx + num, (int)cy, k, f, value);
			DrawFighter(px, w, h, (int)cx, (int)cy - num, k, f, value);
			DrawFighter(px, w, h, (int)cx, (int)cy + num, k, f, value);
			DrawFighter(px, w, h, (int)cx, (int)cy, k, f, null);
		}

		private static void DrawShadow(Color32[] px, int w, int h, int cx, int cy, int rx, int ry)
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			for (int i = -ry; i <= ry; i++)
			{
				for (int j = -rx; j <= rx; j++)
				{
					float num = (float)(j * j) / (float)(rx * rx) + (float)(i * i) / (float)(ry * ry);
					if (!(num > 1f))
					{
						int num2 = cx + j;
						int num3 = cy + i;
						if (num2 >= 0 && num3 >= 0 && num2 < w && num3 < h)
						{
							int num4 = num3 * w + num2;
							byte b = (byte)Mathf.Max((float)(int)px[num4].a, 110f * (1f - num * 0.6f));
							px[num4] = new Color32((byte)0, (byte)0, (byte)0, b);
						}
					}
				}
			}
		}

		private static RectInt? ArtBox(Texture2D orig)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)orig == (Object)null)
			{
				return null;
			}
			try
			{
				Color32[] array = GunStyles.ReadRegion(orig, 0, 0, ((Texture)orig).width, ((Texture)orig).height);
				if (array == null || array.Length != ((Texture)orig).width * ((Texture)orig).height)
				{
					return null;
				}
				int num = int.MaxValue;
				int num2 = int.MaxValue;
				int num3 = -1;
				int num4 = -1;
				for (int i = 0; i < ((Texture)orig).height; i++)
				{
					for (int j = 0; j < ((Texture)orig).width; j++)
					{
						if (array[i * ((Texture)orig).width + j].a > 40)
						{
							if (j < num)
							{
								num = j;
							}
							if (j > num3)
							{
								num3 = j;
							}
							if (i < num2)
							{
								num2 = i;
							}
							if (i > num4)
							{
								num4 = i;
							}
						}
					}
				}
				if (num3 < 0 || num3 - num < 16 || num4 - num2 < 16)
				{
					return null;
				}
				return new RectInt(num, num2, num3 - num + 1, num4 - num2 + 1);
			}
			catch
			{
				return null;
			}
		}

		private static void DrawFighter(Color32[] px, int w, int h, int cx, int cy, int k, Fighter f, Color32? ink)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			Sprite val = Faces.BodySprite(f.Color);
			Texture2D texture = val.texture;
			Rect textureRect = val.textureRect;
			float num = cx;
			Rect textureRect2 = val.textureRect;
			float left = num - ((Rect)(ref textureRect2)).width * (float)k / 2f;
			float num2 = cy;
			textureRect2 = val.textureRect;
			Blit(px, w, h, texture, textureRect, left, num2 - ((Rect)(ref textureRect2)).height * (float)k / 2f, k, ink);
			Texture2D val2 = FaceArt.Texture(FaceDesign.Resolve(f.Look, f.Face), Faces.HatHidden(f));
			float left2 = (float)cx - 16f * (float)k;
			float bottom = (float)cy - 12f * (float)k;
			Blit(px, w, h, val2, new Rect(0f, 0f, (float)((Texture)val2).width, (float)((Texture)val2).height), left2, bottom, k, ink);
		}

		private static void Blit(Color32[] px, int w, int h, Texture2D src, Rect r, float left, float bottom, int k, Color32? ink)
		{
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)src == (Object)null)
			{
				return;
			}
			if (!_pixels.TryGetValue(src, out var value))
			{
				try
				{
					value = src.GetPixels32();
				}
				catch
				{
					value = null;
				}
				_pixels[src] = value;
			}
			if (value == null)
			{
				return;
			}
			int width = ((Texture)src).width;
			int num = (int)((Rect)(ref r)).x;
			int num2 = (int)((Rect)(ref r)).y;
			int num3 = (int)((Rect)(ref r)).width;
			int num4 = (int)((Rect)(ref r)).height;
			int num5 = Mathf.RoundToInt(left);
			int num6 = Mathf.RoundToInt(bottom);
			for (int i = 0; i < num4; i++)
			{
				for (int j = 0; j < num3; j++)
				{
					Color32 val = value[(num2 + i) * width + num + j];
					if (val.a == 0)
					{
						continue;
					}
					if (ink.HasValue)
					{
						if (val.a < 100)
						{
							continue;
						}
						val = ink.Value;
					}
					for (int l = 0; l < k; l++)
					{
						int num7 = num6 + i * k + l;
						if (num7 < 0 || num7 >= h)
						{
							continue;
						}
						for (int m = 0; m < k; m++)
						{
							int num8 = num5 + j * k + m;
							if (num8 >= 0 && num8 < w)
							{
								int num9 = num7 * w + num8;
								if (val.a == byte.MaxValue)
								{
									px[num9] = val;
								}
								else
								{
									px[num9] = Color32.Lerp(px[num9], new Color32(val.r, val.g, val.b, byte.MaxValue), (float)(int)val.a / 255f);
								}
							}
						}
					}
				}
			}
		}
	}
	public static class BossMarker
	{
		private static Texture2D _arrow;

		private static readonly HashSet<tk2dBaseSprite> _outlined = new HashSet<tk2dBaseSprite>();

		private static float _nextNote;

		private static bool Showing
		{
			get
			{
				if (MatchState.Active && MatchState.IsBossStage && (MatchState.Phase == Phase.Boss || MatchState.Phase == Phase.Countdown))
				{
					return !GameManager.IsBossIntro;
				}
				return false;
			}
		}

		public unsafe static void Draw(float s, float now)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Invalid comparison between Unknown and I4
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: 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_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0294: Unknown result type (might be due to invalid IL or missing references)
			if (!Showing)
			{
				_outlined.Clear();
				return;
			}
			if (BossStage.Bosses.Count == 0 && Event.current != null && (int)Event.current.type == 7 && Time.realtimeSinceStartup >= _nextNote)
			{
				_nextNote = Time.realtimeSinceStartup + 10f;
				Plugin.Log.LogInfo((object)"[boss marker] no boss known yet");
			}
			bool flag = Event.current != null && (int)Event.current.type == 7;
			float num = 0.5f + 0.5f * Mathf.Sin(now * 6f);
			Color col = Color.Lerp(new Color(1f, 0.16f, 0.06f), new Color(1f, 0.82f, 0.25f), num);
			foreach (HealthHaver boss in BossStage.Bosses)
			{
				if (!Object.op_Implicit((Object)(object)boss) || !boss.IsAlive || boss.IsDead || (Object)(object)((BraveBehaviour)boss).aiActor == (Object)null)
				{
					continue;
				}
				tk2dBaseSprite sprite = ((BraveBehaviour)((BraveBehaviour)boss).aiActor).sprite;
				if ((Object)(object)sprite == (Object)null || (Object)(object)((BraveBehaviour)sprite).renderer == (Object)null || !((BraveBehaviour)sprite).renderer.enabled)
				{
					Note(boss, "its sprite is hidden");
					continue;
				}
				if (flag)
				{
					Glow(sprite, col);
				}
				SpeculativeRigidbody specRigidbody = ((BraveBehaviour)((BraveBehaviour)boss).aiActor).specRigidbody;
				Vector2 val;
				Vector2 val2;
				if ((Object)(object)specRigidbody != (Object)null && specRigidbody.HitboxPixelCollider != null)
				{
					val = specRigidbody.HitboxPixelCollider.UnitBottomLeft;
					val2 = specRigidbody.HitboxPixelCollider.UnitTopRight;
				}
				else
				{
					val = sprite.WorldBottomLeft;
					val2 = sprite.WorldTopRight;
				}
				Vector2 world = (val + val2) * 0.5f;
				Vector2 gui;
				bool flag2 = ToGui(world, out gui) && gui.x > 0f && gui.x < (float)Screen.width && gui.y > 0f && gui.y < (float)Screen.height;
				if (flag2)
				{
					Frame(boss, val, val2, s, col);
				}
				else
				{
					Arrow(boss, world, gui, s, col);
				}
				if (flag)
				{
					string[] array = new string[7]
					{
						flag2 ? "framed" : "arrow",
						" at ",
						null,
						null,
						null,
						null,
						null
					};
					Vector2 val3 = gui;
					array[2] = ((object)(*(Vector2*)(&val3))/*cast due to .constrained prefix*/).ToString();
					array[3] = ", world ";
					val3 = val;
					array[4] = ((object)(*(Vector2*)(&val3))/*cast due to .constrained prefix*/).ToString();
					array[5] = "-";
					val3 = val2;
					array[6] = ((object)(*(Vector2*)(&val3))/*cast due to .constrained prefix*/).ToString();
					Note(boss, string.Concat(array));
				}
			}
		}

		private static void Note(HealthHaver hh, string what)
		{
			if (!(Time.realtimeSinceStartup < _nextNote))
			{
				_nextNote = Time.realtimeSinceStartup + 10f;
				Plugin.Log.LogInfo((object)("[boss marker] " + (((Object)(object)((BraveBehaviour)hh).aiActor != (Object)null) ? ((BraveBehaviour)hh).aiActor.GetActorName() : "boss") + ": " + what));
			}
		}

		private static void Glow(tk2dBaseSprite spr, Color col)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			try
			{
				if (!_outlined.Contains(spr))
				{
					if (!SpriteOutlineManager.HasOutline(spr))
					{
						SpriteOutlineManager.AddOutlineToSprite(spr, col);
					}
					_outlined.Add(spr);
				}
				Material outlineMaterial = SpriteOutlineManager.GetOutlineMaterial(spr);
				if ((Object)(object)outlineMaterial != (Object)null)
				{
					outlineMaterial.SetColor("_OverrideColor", col * 1.6f);
				}
			}
			catch
			{
			}
		}

		private static void Frame(HealthHaver hh, Vector2 lo, Vector2 hi, float s, Color col)
		{
			//IL_0000: 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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_0068: 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_007b: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0138: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0229: Unknown result type (might be due to invalid IL or missing references)
			//IL_0252: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			if (ToGui(new Vector2(lo.x, hi.y), out var gui) && ToGui(new Vector2(hi.x, lo.y), out var gui2))
			{
				float num = 4f * s;
				Rect val = Rect.MinMaxRect(Mathf.Min(gui.x, gui2.x) - num, Mathf.Min(gui.y, gui2.y) - num, Mathf.Max(gui.x, gui2.x) + num, Mathf.Max(gui.y, gui2.y) + num);
				float len = Mathf.Max(8f * s, Mathf.Min(((Rect)(ref val)).width, ((Rect)(ref val)).height) * 0.28f);
				float num2 = Mathf.Max(2f, Mathf.Round(2f * s));
				Corner(((Rect)(ref val)).xMin, ((Rect)(ref val)).yMin, len, num2, 1, 1, col);
				Corner(((Rect)(ref val)).xMax, ((Rect)(ref val)).yMin, len, num2, -1, 1, col);
				Corner(((Rect)(ref val)).xMin, ((Rect)(ref val)).yMax, len, num2, 1, -1, col);
				Corner(((Rect)(ref val)).xMax, ((Rect)(ref val)).yMax, len, num2, -1, -1, col);
				float small = West.Small;
				float num3 = Mathf.Clamp(((Rect)(ref val)).width, 60f * s, 160f * s);
				float num4 = 7f * small;
				Rect r = default(Rect);
				((Rect)(ref r))..ctor(Mathf.Round(((Rect)(ref val)).center.x - num3 / 2f), Mathf.Round(((Rect)(ref val)).yMin - num4 - 6f * s), num3, num4);
				float num5 = ((hh.GetMaxHealth() > 0f) ? Mathf.Clamp01(hh.GetCurrentHealth() / hh.GetMaxHealth()) : 0f);
				Gfx.Fill(new Rect(((Rect)(ref r)).x - num2, ((Rect)(ref r)).y - num2, ((Rect)(ref r)).width + num2 * 2f, ((Rect)(ref r)).height + num2 * 2f), West.Outline);
				Gfx.Fill(r, new Color(0.25f, 0.04f, 0.03f, 0.9f));
				Gfx.Fill(new Rect(((Rect)(ref r)).x, ((Rect)(ref r)).y, ((Rect)(ref r)).width * num5, ((Rect)(ref r)).height), col);
				string text = (((Object)(object)((BraveBehaviour)hh).aiActor != (Object)null) ? ((BraveBehaviour)hh).aiActor.GetActorName() : "BOSS");
				West.Text(((Rect)(ref r)).center.x, ((Rect)(ref r)).y - West.LineH(small) - 2f * s, text.ToUpperInvariant(), small, col, (TextAnchor)1);
			}
		}

		private static void Corner(float x, float y, float len, float th, int dx, int dy, Color col)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			Gfx.Fill(new Rect((dx > 0) ? (x - 1f) : (x - len - 1f), (dy > 0) ? (y - 1f) : (y - th - 1f), len + 2f, th + 2f), West.Outline);
			Gfx.Fill(new Rect((dx > 0) ? (x - 1f) : (x - th - 1f), (dy > 0) ? (y - 1f) : (y - len - 1f), th + 2f, len + 2f), West.Outline);
			Gfx.Fill(new Rect((dx > 0) ? x : (x - len), (dy > 0) ? y : (y - th), len, th), col);
			Gfx.Fill(new Rect((dx > 0) ? x : (x - th), (dy > 0) ? y : (y - len), th, len), col);
		}

		private static void Arrow(HealthHaver hh, Vector2 world, Vector2 gui, float s, Color col)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0186: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: 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_01c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_020f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0214: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			Fighter local = MatchState.Local;
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor((float)Screen.width / 2f, (float)Screen.height / 2f);
			Vector2 val2 = gui - val;
			if (!(((Vector2)(ref val2)).sqrMagnitude < 1f))
			{
				float num = 46f * s;
				float num2 = ((float)Screen.width / 2f - num) / Mathf.Max(0.001f, Mathf.Abs(val2.x));
				float num3 = ((float)Screen.height / 2f - num) / Mathf.Max(0.001f, Mathf.Abs(val2.y));
				Vector2 val3 = val + val2 * Mathf.Min(num2, num3);
				if ((Object)(object)_arrow == (Object)null)
				{
					_arrow = PixelArt.Tex("boss_arrow", new string[12]
					{
						"....OO......", "....OWO.....", "....OWWO....", "OOOOOWWWO...", "OWWWWWWWWO..", "OWWWWWWWWWO.", "OWWWWWWWWWO.", "OWWWWWWWWO..", "OOOOOWWWO...", "....OWWO....",
						"....OWO.....", "....OO......"
					}, PixelArt.Pal('O', "#1a0d06", 'W', "#ffffff"));
				}
				float num4 = 26f * s;
				float num5 = Mathf.Atan2(val2.y, val2.x) * 57.29578f;
				Matrix4x4 matrix = GUI.matrix;
				Color color = GUI.color;
				GUIUtility.RotateAroundPivot(num5, val3);
				GUI.color = col;
				GUI.DrawTexture(new Rect(val3.x - num4 / 2f, val3.y - num4 / 2f, num4, num4), (Texture)(object)_arrow);
				GUI.matrix = matrix;
				GUI.color = color;
				float num6 = ((local != null && local.HasBody) ? Vector2.Distance(local.Center, world) : 0f);
				Vector2 val4 = val3 - ((Vector2)(ref val2)).normalized * (num4 * 0.9f);
				West.Text(val4.x, val4.y - West.LineH(West.Small) / 2f, (num6 > 0f) ? ("BOSS " + Mathf.RoundToInt(num6)) : "BOSS", West.Small, col, (TextAnchor)1);
			}
		}

		private static bool ToGui(Vector2 world, out Vector2 gui)
		{
			//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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			gui = Vector2.zero;
			if (!GameManager.HasInstance || (Object)(object)GameManager.Instance.MainCameraController == (Object)null)
			{
				return false;
			}
			Camera camera = GameManager.Instance.MainCameraController.Camera;
			if ((Object)(object)camera == (Object)null)
			{
				return false;
			}
			Vector3 val = camera.WorldToViewportPoint(new Vector3(world.x, world.y, world.y));
			if (val.z < 0f)
			{
				return false;
			}
			Rect rect = BraveCameraUtility.GetRect();
			gui.x = (((Rect)(ref rect)).x + val.x * ((Rect)(ref rect)).width) * (float)Screen.width;
			gui.y = (float)Screen.height - (((Rect)(ref rect)).y + val.y * ((Rect)(ref rect)).height) * (float)Screen.height;
			return true;
		}
	}
	public static class FaceMaker
	{
		public static bool Open;

		private static Texture2D _preview;

		private static string _previewKey;

		private static float _bounceAt = -9f;

		private static readonly byte[] _owner = new byte[1024];

		private static int _sel = 0;

		private static bool _dragging;

		private static Vector2 _dragFrom;

		private static int _dragX;

		private static int _dragY;

		public static void Show()
		{
			FaceBook.Load();
			Open = true;
			Sfx.UiMove();
		}

		public static void Close()
		{
			if (Open)
			{
				Open = false;
				Sfx.UiBack();
			}
		}

		public static void Draw(float s, Color body)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: 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_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0263: Unknown result type (might be due to invalid IL or missing references)
			//IL_0277: Unknown result type (might be due to invalid IL or missing references)
			//IL_033d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0370: Unknown result type (might be due to invalid IL or missing references)
			//IL_038b: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0418: Unknown result type (might be due to invalid IL or missing references)
			//IL_0444: Unknown result type (might be due to invalid IL or missing references)
			//IL_048a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_050b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0530: 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_05c6: 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_0a8a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0a8f: Unknown result type (might be due to invalid IL or missing references)
			//IL_06