Decompiled source of Bobl Mods v0.2.0

plugins/BoplModKit/BoplModKit.dll

Decompiled 26 minutes ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BoplFixedMath;
using BoplModKit.Abilities;
using BoplModKit.Cpu;
using BoplModKit.Status;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BoplModKit")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BoplModKit")]
[assembly: AssemblyTitle("BoplModKit")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BoplModKit
{
	[BepInPlugin("local.boplmodkit", "Bobl Mods", "0.2.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "local.boplmodkit";

		public const string Name = "Bobl Mods";

		public const string Version = "0.2.0";

		internal static Plugin Instance;

		internal static ManualLogSource Log;

		internal static string PluginDir;

		internal static ConfigEntry<bool> RocketHopEnabled;

		internal static ConfigEntry<float> RocketHopCooldown;

		internal static ConfigEntry<float> RocketHopWindup;

		internal static ConfigEntry<float> RocketHopSpeed;

		internal static ConfigEntry<float> RocketHopKnockback;

		internal static ConfigEntry<float> RocketHopHover;

		internal static ConfigEntry<bool> ShieldEnabled;

		internal static ConfigEntry<float> ShieldDuration;

		internal static ConfigEntry<float> ShieldCooldown;

		internal static ConfigEntry<float> ShieldRadius;

		internal static ConfigEntry<float> ShieldPush;

		internal static ConfigEntry<bool> FreezeEnabled;

		internal static ConfigEntry<float> FreezeDuration;

		internal static ConfigEntry<bool> SpeedEnabled;

		internal static ConfigEntry<float> SpeedDuration;

		internal static ConfigEntry<float> SpeedMultiplier;

		internal static ConfigEntry<float> SpeedCooldown;

		internal static ConfigEntry<bool> BatEnabled;

		internal static ConfigEntry<float> BatCooldown;

		internal static ConfigEntry<float> BatReach;

		internal static ConfigEntry<float> BatLaunchSpeed;

		internal static ConfigEntry<float> BatUpwardAngle;

		internal static ConfigEntry<float> BatTumbleSeconds;

		internal static ConfigEntry<bool> GlueEnabled;

		internal static ConfigEntry<float> GlueSlowMultiplier;

		internal static ConfigEntry<float> GlueJumpMultiplier;

		internal static ConfigEntry<float> GlueSplatRadius;

		internal static ConfigEntry<float> GlueOnPlayerSeconds;

		internal static ConfigEntry<int> GlueMaxSplats;

		internal static ConfigEntry<float> GlueGravityMultiplier;

		internal static ConfigEntry<float> GlueDashMultiplier;

		internal static ConfigEntry<string> GlueCleansedBy;

		internal static ConfigEntry<bool> DisarmEnabled;

		internal static ConfigEntry<int> DisarmMaxRemoved;

		internal static ConfigEntry<bool> SplitterEnabled;

		internal static ConfigEntry<int> SplitterClones;

		internal static ConfigEntry<float> SplitterTinyScale;

		internal static ConfigEntry<int> CpuCount;

		internal static ConfigEntry<string> CpuAbilities;

		internal static ConfigEntry<float> CpuAggression;

		internal static ConfigEntry<float> CpuRange;

		internal static ConfigEntry<bool> CpuFights;

		internal static ConfigEntry<bool> CustomMapsEnabled;

		internal static ConfigEntry<bool> DumpLevelLayouts;

		internal static ConfigEntry<int> ForceLevel;

		internal static ConfigEntry<bool> ResizeFixedPlatforms;

		private void Awake()
		{
			//IL_0660: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			PluginDir = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			RocketHopEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Rocket Hop", "Enabled", true, "Add the Rocket Hop ability to the ability list.");
			RocketHopCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Rocket Hop", "Cooldown", 2.5f, "Cooldown in seconds.");
			RocketHopWindup = ((BaseUnityPlugin)this).Config.Bind<float>("Rocket Hop", "WindupSeconds", 0.2f, "How long you can aim before launching.");
			RocketHopSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Rocket Hop", "LaunchSpeed", 75f, "Self-propelled launch speed (Dash exits at 100).");
			RocketHopKnockback = ((BaseUnityPlugin)this).Config.Bind<float>("Rocket Hop", "LaunchMomentum", 55f, "Extra momentum that decays like knockback, so the hop carries.");
			RocketHopHover = ((BaseUnityPlugin)this).Config.Bind<float>("Rocket Hop", "HoverSeconds", 2f, "After launching, hover without gravity for this long (0 = off).");
			ShieldEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Bubble", "Enabled", true, "Add the Bubble ability (protective bubble everything bounces off).");
			ShieldDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Bubble", "DurationSeconds", 5f, "How long the bubble lasts.");
			ShieldCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Bubble", "Cooldown", 12f, "Cooldown in seconds (counted from when you cast it).");
			ShieldRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Bubble", "Radius", 2.5f, "Bubble radius in world units; anything entering it bounces off.");
			ShieldPush = ((BaseUnityPlugin)this).Config.Bind<float>("Bubble", "PlayerKnockback", 40f, "How hard other players are knocked away when they touch the bubble.");
			FreezeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Freeze Ray", "Enabled", true, "Add the Freeze Ray ability.");
			FreezeDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Freeze Ray", "FreezeSeconds", 1.5f, "How long a hit player is frozen.");
			SpeedEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Super Speed", "Enabled", true, "Add the Super Speed ability.");
			SpeedDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Super Speed", "DurationSeconds", 2f, "How long Super Speed lasts.");
			SpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Super Speed", "SpeedMultiplier", 2f, "Run speed and acceleration multiplier.");
			SpeedCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Super Speed", "Cooldown", 8f, "Cooldown in seconds.");
			BatEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Baseball Bat", "Enabled", true, "Add the Baseball Bat ability.");
			BatCooldown = ((BaseUnityPlugin)this).Config.Bind<float>("Baseball Bat", "Cooldown", 3f, "Cooldown in seconds.");
			BatReach = ((BaseUnityPlugin)this).Config.Bind<float>("Baseball Bat", "Reach", 2.6f, "How far the swing reaches (world units).");
			BatLaunchSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Baseball Bat", "LaunchSpeed", 60f, "How hard a hit player is flung (Magnet Gun-style tumble).");
			BatUpwardAngle = ((BaseUnityPlugin)this).Config.Bind<float>("Baseball Bat", "UpwardAngle", 0.6f, "How much hits angle upward (0 = straight along the swing, 1 = 45 degrees up).");
			BatTumbleSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Baseball Bat", "TumbleSeconds", 0.45f, "How long a hit player tumbles out of control before landing normally.");
			GlueEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Glue Gun", "Enabled", true, "Add the Glue Gun ability.");
			GlueSlowMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "SlowMultiplier", 0.35f, "Movement speed while touching goo (0.35 = 35% of normal).");
			GlueJumpMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "JumpMultiplier", 0.6f, "Jump strength while touching goo.");
			GlueSplatRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "SplatRadius", 1.4f, "Size of each goo splat (world units).");
			GlueOnPlayerSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "GooedPlayerSeconds", 0f, "How long a player hit directly stays gooed (0 = rest of the round, until cleansed).");
			GlueGravityMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "GooedGravityMultiplier", 2f, "Gooed players are heavy: gravity multiplier while gooed.");
			GlueDashMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Glue Gun", "GooedDashMultiplier", 0.5f, "Gooed players' Dash distance and Rocket Hop launch are multiplied by this (and Rocket Hop loses its hover).");
			DisarmEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Disarm Ray", "Enabled", true, "Add the Disarm Ray ability.");
			DisarmMaxRemoved = ((BaseUnityPlugin)this).Config.Bind<int>("Disarm Ray", "MaxRemoved", 3, "How many of a player's abilities can be taken away in one round (1-3).");
			SplitterEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Splitter", "Enabled", true, "Add the Splitter ability.");
			SplitterClones = ((BaseUnityPlugin)this).Config.Bind<int>("Splitter", "Copies", 3, "Extra tiny copies made per hit (1-5; the game also caps total clones).");
			SplitterTinyScale = ((BaseUnityPlugin)this).Config.Bind<float>("Splitter", "SizeMultiplier", 0.5f, "Size multiplier applied to the player and all copies per hit (game minimum is 0.3).");
			CpuCount = ((BaseUnityPlugin)this).Config.Bind<int>("CPU", "Count", 0, "CPU opponents in local games (0-3). Press C in character select to change it.");
			CpuAbilities = ((BaseUnityPlugin)this).Config.Bind<string>("CPU", "Abilities", "random", "CPU abilities: 'random', or a comma list of ability names, e.g. 'Baseball Bat,Glue Gun,Bubble' (missing slots are random).");
			CpuAggression = ((BaseUnityPlugin)this).Config.Bind<float>("CPU", "Aggression", 0.6f, "0 = passive, 1 = uses abilities as often as possible.");
			CpuRange = ((BaseUnityPlugin)this).Config.Bind<float>("CPU", "AbilityRange", 14f, "CPUs use abilities when an opponent is closer than this.");
			CpuFights = ((BaseUnityPlugin)this).Config.Bind<bool>("CPU", "Fights", false, "false = CPUs stand still (test dummies). true = CPUs move, jump and use abilities.");
			GlueCleansedBy = ((BaseUnityPlugin)this).Config.Bind<string>("Glue Gun", "CleansedBy", "Teleport,Rock", "Abilities that remove goo from a player (shape-shifting). Dying or being revived also removes it.");
			GlueMaxSplats = ((BaseUnityPlugin)this).Config.Bind<int>("Glue Gun", "MaxSplats", 40, "Most goo splats at once; the oldest disappears beyond this.");
			CustomMapsEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Maps", "Enabled", true, "Replace levels with JSON layouts from the maps folder.");
			DumpLevelLayouts = ((BaseUnityPlugin)this).Config.Bind<bool>("Maps", "DumpLevelLayouts", false, "Write each level's original layout to maps/dumps/ when it loads.");
			ResizeFixedPlatforms = ((BaseUnityPlugin)this).Config.Bind<bool>("Maps", "ResizeFixedPlatforms", false, "Experimental: apply halfWidth/halfHeight/bevel to level platforms that are normally fixed-size (may render them invisible).");
			ForceLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Maps", "ForceLevel", -1, "Always play this level index after the first round (-1 = normal random rotation). Local play only.");
			new Harmony("local.boplmodkit").PatchAll();
			StatusVisuals.Create();
			CpuMenuOverlay.Create();
			Log.LogInfo((object)("Bobl Mods 0.2.0 loaded from " + PluginDir));
		}
	}
}
namespace BoplModKit.Status
{
	public enum Effect
	{
		Shield,
		Freeze,
		Speed,
		Hover,
		Goo,
		BatSwing
	}
	internal static class StatusEffects
	{
		private static readonly Dictionary<(int, Effect), Fix> Timers = new Dictionary<(int, Effect), Fix>();

		private static readonly Dictionary<(int, Effect), Fix> Durations = new Dictionary<(int, Effect), Fix>();

		private static readonly Effect[] AllEffects = new Effect[6]
		{
			Effect.Shield,
			Effect.Freeze,
			Effect.Speed,
			Effect.Hover,
			Effect.Goo,
			Effect.BatSwing
		};

		public static void Apply(int playerId, Effect e, Fix seconds)
		{
			//IL_0011: 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)
			StatusVisuals.Ensure();
			Timers[(playerId, e)] = seconds;
			Durations[(playerId, e)] = seconds;
		}

		public static void Clear(int playerId, Effect e)
		{
			Timers.Remove((playerId, e));
		}

		public static bool Has(int playerId, Effect e)
		{
			//IL_0015: 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)
			if (Timers.TryGetValue((playerId, e), out var value))
			{
				return value > Fix.Zero;
			}
			return false;
		}

		public static float Remaining(int playerId, Effect e)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			if (!Timers.TryGetValue((playerId, e), out var value) || !(value > Fix.Zero))
			{
				return 0f;
			}
			return (float)value;
		}

		public static float Duration(int playerId, Effect e)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			if (!Durations.TryGetValue((playerId, e), out var value))
			{
				return 1f;
			}
			return (float)value;
		}

		public static void ClearAll()
		{
			Timers.Clear();
		}

		internal static void Tick(Player player, Fix deltaTime)
		{
			//IL_0008: 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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			int id = player.Id;
			Fix val = GameTime.FixedDeltaTime(id, deltaTime);
			Effect[] allEffects = AllEffects;
			foreach (Effect item in allEffects)
			{
				(int, Effect) key = (id, item);
				if (Timers.TryGetValue(key, out var value))
				{
					value -= val;
					if (value <= Fix.Zero)
					{
						Timers.Remove(key);
					}
					else
					{
						Timers[key] = value;
					}
				}
			}
			if (Has(id, Effect.Shield))
			{
				ShortShield.DeflectProjectiles(player);
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlayer")]
	internal static class Player_UpdatePlayer_Patch
	{
		private static void Postfix(Player __instance, Fix deltaTime)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			StatusEffects.Tick(__instance, deltaTime);
		}
	}
	[HarmonyPatch(typeof(GameSessionHandler), "Init")]
	internal static class GameSessionHandler_Init_ClearStatus
	{
		private static void Postfix()
		{
			StatusEffects.ClearAll();
			GooManager.Clear();
			Disarm.Clear();
			StatusVisuals.Ensure();
		}
	}
	internal class StatusVisuals : MonoBehaviour
	{
		private const int TexSize = 256;

		private const int SpeedLineCount = 4;

		private static StatusVisuals instance;

		private readonly Dictionary<string, SpriteRenderer> renderers = new Dictionary<string, SpriteRenderer>();

		private readonly Dictionary<int, SlimeController> slimes = new Dictionary<int, SlimeController>();

		private readonly Dictionary<int, Vector2> lastPos = new Dictionary<int, Vector2>();

		private readonly Dictionary<int, Vector2> velocity = new Dictionary<int, Vector2>();

		private Sprite bubble;

		private Sprite disc;

		private Sprite streak;

		private Sprite flame;

		private float nextSlimeScan;

		private bool loggedRunning;

		private bool loggedSetup;

		private bool loggedMissingSlime;

		private Sprite cross;

		private Sprite bat;

		public static void Create()
		{
			Ensure();
		}

		public static void Ensure()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)instance != (Object)null))
			{
				GameObject val = new GameObject("BoplModKit_StatusVisuals");
				Object.DontDestroyOnLoad((Object)val);
				((Object)val).hideFlags = (HideFlags)61;
				instance = val.AddComponent<StatusVisuals>();
			}
		}

		private void OnDestroy()
		{
			if ((Object)(object)instance == (Object)(object)this)
			{
				instance = null;
			}
		}

		private void Awake()
		{
			bubble = MakeBubble();
			disc = MakeDisc();
			streak = MakeStreak();
			flame = MakeFlame();
		}

		private void LateUpdate()
		{
			//IL_00b0: 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)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			if (!loggedRunning)
			{
				loggedRunning = true;
				Plugin.Log.LogInfo((object)"Status overlays running.");
			}
			foreach (KeyValuePair<string, SpriteRenderer> renderer in renderers)
			{
				if ((Object)(object)renderer.Value != (Object)null)
				{
					((Renderer)renderer.Value).enabled = false;
				}
			}
			PlayerHandler val = PlayerHandler.Get();
			List<Player> list = ((val != null) ? val.PlayerList() : null);
			if (list == null)
			{
				return;
			}
			float dt = Mathf.Max(Time.deltaTime, 0.0001f);
			foreach (Player item in list)
			{
				if (item != null)
				{
					Vector2 pos = (Vector2)item.Position;
					TrackVelocity(item.Id, pos, dt);
					if (item.IsAlive)
					{
						float scale = Mathf.Max(0.1f, (float)item.Scale);
						DrawFreeze(item, pos, scale);
						DrawBubble(item, pos, scale);
						DrawSpeedLines(item, pos, scale);
						DrawFlame(item, pos, scale);
						DrawGoo(item, pos, scale);
						DrawBat(item, pos, scale);
						DrawDisarmed(item);
					}
				}
			}
		}

		private void DrawDisarmed(Player p)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: 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_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			SlimeController val = FindSlime(p.Id);
			if ((Object)(object)val == (Object)null || val.AbilityReadyIndicators == null)
			{
				return;
			}
			for (int i = 0; i < val.AbilityReadyIndicators.Length; i++)
			{
				AbilityReadyIndicator val2 = val.AbilityReadyIndicators[i];
				if ((Object)(object)val2 == (Object)null || !((Component)val2).gameObject.activeInHierarchy || !Disarm.IsDisabled(p.Id, i))
				{
					continue;
				}
				SpriteRenderer spriteRen = val2.GetSpriteRen();
				if (!((Object)(object)spriteRen == (Object)null))
				{
					spriteRen.color = new Color(0.35f, 0.35f, 0.35f, 0.7f);
					if ((Object)(object)cross == (Object)null)
					{
						cross = MakeCross();
					}
					SpriteRenderer obj = Get($"disarm{p.Id}_{i}", cross, p.Id, 0);
					((Component)obj).gameObject.layer = ((Component)spriteRen).gameObject.layer;
					((Renderer)obj).sortingLayerID = ((Renderer)spriteRen).sortingLayerID;
					((Renderer)obj).sortingOrder = ((Renderer)spriteRen).sortingOrder + 1;
					Bounds bounds = ((Renderer)spriteRen).bounds;
					((Component)obj).transform.position = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).center.y, ((Component)spriteRen).transform.position.z - 0.01f);
					((Component)obj).transform.rotation = Quaternion.identity;
					float num = Mathf.Max(((Bounds)(ref bounds)).size.x, ((Bounds)(ref bounds)).size.y) * 0.8f;
					((Component)obj).transform.localScale = new Vector3(num, num, 1f);
					obj.color = Color.white;
					((Renderer)obj).enabled = true;
				}
			}
		}

		private static Sprite MakeCross()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0121: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 64, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.95f, 0.15f, 0.15f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.3f, 0.02f, 0.02f);
			float num = 31.5f;
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num2 = ((float)j - num) / num;
					float num3 = ((float)i - num) / num;
					float num4 = Mathf.Min(Mathf.Abs(num2 - num3), Mathf.Abs(num2 + num3)) / 1.414f;
					float num5 = ((Mathf.Max(Mathf.Abs(num2), Mathf.Abs(num3)) < 0.85f) ? 1f : 0f);
					Color val4 = ((num4 < 0.1f) ? val2 : val3);
					val4.a = num5 * Mathf.Clamp01((0.17f - num4) * 40f);
					val.SetPixel(j, i, val4);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 64f), new Vector2(0.5f, 0.5f), 64f);
		}

		private void DrawGoo(Player p, Vector2 pos, float scale)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			if (!(StatusEffects.Remaining(p.Id, Effect.Goo) <= 0f))
			{
				SpriteRenderer obj = Get($"goo{p.Id}", disc, p.Id, 5);
				float num = 1f + 0.05f * Mathf.Sin(Time.time * 9f);
				Place(obj, pos, 1.9f * scale * num, 0f);
				obj.color = new Color(0.45f, 0.9f, 0.2f, 0.55f);
			}
		}

		private void DrawBat(Player p, Vector2 pos, float scale)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			float num = StatusEffects.Remaining(p.Id, Effect.BatSwing);
			if (!(num <= 0f))
			{
				if ((Object)(object)bat == (Object)null)
				{
					bat = MakeBat();
				}
				Vector2 value;
				Vector2 val = (BaseballBat.SwingDirection.TryGetValue(p.Id, out value) ? value : Vector2.right);
				float num2 = Mathf.Clamp01(1f - num / 0.3f);
				float num3 = Mathf.Lerp(80f, -80f, 1f - (1f - num2) * (1f - num2));
				float num4 = ((val.x >= 0f) ? 1f : (-1f));
				float num5 = Mathf.Atan2(val.y, val.x) * 57.29578f + num3 * num4;
				SpriteRenderer val2 = Get($"bat{p.Id}", bat, p.Id, 9);
				((Component)val2).transform.position = new Vector3(pos.x, pos.y, ((Component)val2).transform.position.z);
				((Component)val2).transform.rotation = Quaternion.Euler(0f, 0f, num5);
				float num6 = Plugin.BatReach.Value * scale * 1.3f;
				((Component)val2).transform.localScale = new Vector3(num6, num6 * 1.35f, 1f);
				val2.color = Color.white;
				((Renderer)val2).enabled = true;
			}
		}

		private static Sprite MakeBat()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_01b4: 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_011b: 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_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: 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_0156: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(128, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(0.86f, 0.62f, 0.33f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(0.6f, 0.38f, 0.17f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.15f, 0.15f, 0.2f);
			Color val5 = default(Color);
			((Color)(ref val5))..ctor(0.25f, 0.13f, 0.05f);
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = (float)j / 127f;
					float num2 = Mathf.Lerp(0.09f, 0.42f, Mathf.SmoothStep(0f, 1f, Mathf.InverseLerp(0.25f, 0.85f, num)));
					if (num > 0.93f)
					{
						num2 *= Mathf.Sqrt(Mathf.Clamp01((1f - num) / 0.07f));
					}
					if (num < 0.04f)
					{
						num2 = 0.14f;
					}
					float num3 = Mathf.Abs((float)i - 15.5f) / 16f;
					float num4 = num2 - num3;
					if (num4 < 0f)
					{
						val.SetPixel(j, i, Color.clear);
						continue;
					}
					Color val6 = ((num < 0.3f) ? val4 : Color.Lerp(val2, val3, num3 / Mathf.Max(0.01f, num2)));
					if (num4 < 0.07f)
					{
						val6 = val5;
					}
					val6.a = Mathf.Clamp01(num4 * 40f);
					val.SetPixel(j, i, val6);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 128f, 32f), new Vector2(0.08f, 0.5f), 128f);
		}

		private void TrackVelocity(int id, Vector2 pos, float dt)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: 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_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_003b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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)
			Vector2 value;
			Vector2 val = (lastPos.TryGetValue(id, out value) ? ((pos - value) / dt) : Vector2.zero);
			Vector2 val2 = pos - value;
			if (((Vector2)(ref val2)).sqrMagnitude > 25f)
			{
				val = Vector2.zero;
			}
			velocity[id] = (velocity.TryGetValue(id, out var value2) ? Vector2.Lerp(value2, val, 0.35f) : val);
			lastPos[id] = pos;
		}

		private void DrawBubble(Player p, Vector2 pos, float scale)
		{
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
			float num = StatusEffects.Remaining(p.Id, Effect.Shield);
			if (!(num <= 0f))
			{
				SpriteRenderer obj = Get($"bubble{p.Id}", bubble, p.Id, 8);
				float num2 = 1f + 0.03f * Mathf.Sin(Time.time * 6f);
				Place(obj, pos, Plugin.ShieldRadius.Value * 2f * scale * num2, 0f);
				Color color = default(Color);
				((Color)(ref color))..ctor(0.55f, 0.9f, 1f, 1f);
				if (num < 1f)
				{
					color.a = 0.3f + 0.7f * Mathf.Abs(Mathf.Sin(Time.time * 16f));
				}
				obj.color = color;
			}
		}

		private void DrawFreeze(Player p, Vector2 pos, float scale)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (!(StatusEffects.Remaining(p.Id, Effect.Freeze) <= 0f))
			{
				SpriteRenderer obj = Get($"freeze{p.Id}", disc, p.Id, 6);
				Place(obj, pos, 2.3f * scale, 0f);
				obj.color = new Color(0.7f, 0.92f, 1f, 0.6f);
			}
		}

		private void DrawSpeedLines(Player p, Vector2 pos, float scale)
		{
			//IL_0030: 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_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: 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_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			if (StatusEffects.Remaining(p.Id, Effect.Speed) <= 0f)
			{
				return;
			}
			Vector2 value;
			Vector2 val = (velocity.TryGetValue(p.Id, out value) ? value : Vector2.zero);
			float magnitude = ((Vector2)(ref val)).magnitude;
			if (!(magnitude < 2f))
			{
				Vector2 val2 = val / magnitude;
				Vector2 val3 = default(Vector2);
				((Vector2)(ref val3))..ctor(0f - val2.y, val2.x);
				float num = Mathf.Atan2(val2.y, val2.x) * 57.29578f;
				float num2 = Mathf.Clamp01(magnitude / 25f);
				for (int i = 0; i < 4; i++)
				{
					SpriteRenderer val4 = Get($"speed{p.Id}_{i}", streak, p.Id, -1);
					float num3 = ((float)i - 1.5f) * 0.38f * scale;
					float num4 = Mathf.Sin(Time.time * 23f + (float)i * 1.7f);
					float num5 = (1.4f + 0.5f * num4 + 0.4f * (float)(i % 2)) * scale * (0.6f + 0.6f * num2);
					Vector2 val5 = pos - val2 * (0.9f * scale + num5 * 0.5f) + val3 * num3;
					((Component)val4).transform.position = new Vector3(val5.x, val5.y, ((Component)val4).transform.position.z);
					((Component)val4).transform.rotation = Quaternion.Euler(0f, 0f, num);
					((Component)val4).transform.localScale = new Vector3(num5, 0.12f * scale, 1f);
					val4.color = new Color(1f, 1f, 1f, 0.75f * num2);
					((Renderer)val4).enabled = true;
				}
			}
		}

		private void DrawFlame(Player p, Vector2 pos, float scale)
		{
			//IL_00a6: 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_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			if (!(StatusEffects.Remaining(p.Id, Effect.Hover) <= 0f))
			{
				SpriteRenderer val = Get($"flame{p.Id}", flame, p.Id, -1);
				float num = 1f + 0.18f * Mathf.Sin(Time.time * 40f) + 0.1f * Mathf.Sin(Time.time * 67f + 1.3f);
				float num2 = 1.6f * scale * num;
				float num3 = 0.9f * scale * (1f + 0.06f * Mathf.Sin(Time.time * 53f));
				Vector2 val2 = pos + Vector2.down * (0.65f * scale + num2 * 0.5f);
				((Component)val).transform.position = new Vector3(val2.x, val2.y, ((Component)val).transform.position.z);
				((Component)val).transform.rotation = Quaternion.identity;
				((Component)val).transform.localScale = new Vector3(num3, num2, 1f);
				val.color = Color.white;
				((Renderer)val).enabled = true;
			}
		}

		private static void Place(SpriteRenderer sr, Vector2 pos, float size, float angle)
		{
			//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_0018: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			((Component)sr).transform.position = new Vector3(pos.x, pos.y, ((Component)sr).transform.position.z);
			((Component)sr).transform.rotation = Quaternion.Euler(0f, 0f, angle);
			((Component)sr).transform.localScale = Vector3.one * size;
			((Renderer)sr).enabled = true;
		}

		private SpriteRenderer Get(string key, Sprite sprite, int playerId, int orderOffset)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			if (!renderers.TryGetValue(key, out var value) || (Object)(object)value == (Object)null)
			{
				GameObject val = new GameObject("Status_" + key);
				val.transform.SetParent(((Component)this).transform, false);
				value = val.AddComponent<SpriteRenderer>();
				value.sprite = sprite;
				renderers[key] = value;
			}
			MatchPlayerLayers(playerId, value, orderOffset);
			return value;
		}

		private void MatchPlayerLayers(int playerId, SpriteRenderer sr, int orderOffset)
		{
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			SlimeController val = FindSlime(playerId);
			SpriteRenderer val2 = (((Object)(object)val != (Object)null) ? val.GetPlayerSprite() : null);
			if ((Object)(object)val2 == (Object)null)
			{
				if (!loggedMissingSlime)
				{
					loggedMissingSlime = true;
					Plugin.Log.LogWarning((object)$"Status overlay: could not find player {playerId}'s sprite; drawing with default layers.");
				}
				((Renderer)sr).sortingOrder = 5000 + orderOffset;
				return;
			}
			((Component)sr).gameObject.layer = ((Component)val2).gameObject.layer;
			((Renderer)sr).sortingLayerID = ((Renderer)val2).sortingLayerID;
			((Renderer)sr).sortingOrder = ((Renderer)val2).sortingOrder + orderOffset;
			Vector3 position = ((Component)sr).transform.position;
			((Component)sr).transform.position = new Vector3(position.x, position.y, ((Component)val2).transform.position.z - 0.01f * (float)orderOffset);
			if (!loggedSetup)
			{
				loggedSetup = true;
				Plugin.Log.LogInfo((object)("Status overlays use layer " + LayerMask.LayerToName(((Component)sr).gameObject.layer) + ", " + $"sorting layer {((Renderer)sr).sortingLayerName}, player order {((Renderer)val2).sortingOrder}."));
			}
		}

		private SlimeController FindSlime(int playerId)
		{
			if (slimes.TryGetValue(playerId, out var value) && (Object)(object)value != (Object)null && !((MonoUpdatable)value).IsDestroyed)
			{
				return value;
			}
			if (Time.unscaledTime < nextSlimeScan)
			{
				return null;
			}
			nextSlimeScan = Time.unscaledTime + 0.5f;
			slimes.Clear();
			SlimeController[] array = Object.FindObjectsOfType<SlimeController>();
			foreach (SlimeController val in array)
			{
				if ((Object)(object)val != (Object)null && !((MonoUpdatable)val).IsDestroyed)
				{
					slimes[val.GetPlayerId()] = val;
				}
			}
			if (!slimes.TryGetValue(playerId, out value))
			{
				return null;
			}
			return value;
		}

		private static Sprite Finish(Texture2D tex, int w, int h, Vector2 pivot)
		{
			//IL_0015: 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)
			tex.Apply();
			return Sprite.Create(tex, new Rect(0f, 0f, (float)w, (float)h), pivot, (float)Mathf.Max(w, h));
		}

		private static Sprite MakeBubble()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			float num = 127.5f;
			float num2 = 122.88f;
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num3 = (float)j - num;
					float num4 = (float)i - num;
					float num5 = Mathf.Sqrt(num3 * num3 + num4 * num4);
					float num6 = Mathf.Clamp01(num2 - num5);
					float num7 = num5 / num2;
					float num8 = (0.18f + 0.5f * Mathf.Pow(num7, 6f)) * num6;
					num8 = Mathf.Max(num8, Mathf.Clamp01(1f - Mathf.Abs(num5 - (num2 - 4f)) / 4f) * num6);
					float num9 = num3 + num2 * 0.38f;
					float num10 = num4 - num2 * 0.38f;
					float num11 = Mathf.Clamp01(1f - Mathf.Sqrt(num9 * num9 * 0.6f + num10 * num10 * 1.6f) / (num2 * 0.28f));
					num8 = Mathf.Max(num8, num11 * 0.9f * num6);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, Mathf.Clamp01(num8)));
				}
			}
			return Finish(val, 256, 256, new Vector2(0.5f, 0.5f));
		}

		private static Sprite MakeDisc()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			float num = 127.5f;
			float num2 = 122.88f;
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num3 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
					val.SetPixel(j, i, new Color(1f, 1f, 1f, 0.85f * Mathf.Clamp01(num2 - num3)));
				}
			}
			return Finish(val, 256, 256, new Vector2(0.5f, 0.5f));
		}

		private static Sprite MakeStreak()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: 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)
			Texture2D val = new Texture2D(128, 16, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			for (int i = 0; i < 16; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = (float)j / 127f;
					float num2 = Mathf.Abs((float)i - 7.5f) / 8f;
					float num3 = Mathf.Pow(num, 1.5f) * Mathf.Clamp01(1f - num2 * num2) * Mathf.Clamp01((1f - num) * 12f + 0.2f);
					val.SetPixel(j, i, new Color(1f, 1f, 1f, Mathf.Clamp01(num3)));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 128f, 16f), new Vector2(0.5f, 0.5f), 128f);
		}

		private static Sprite MakeFlame()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_011f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(64, 128, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.98f, 0.8f);
			Color val3 = default(Color);
			((Color)(ref val3))..ctor(1f, 0.62f, 0.12f);
			Color val4 = default(Color);
			((Color)(ref val4))..ctor(0.95f, 0.22f, 0.08f);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = 1f - (float)i / 127f;
					float num2 = 0.5f * (1f - Mathf.Pow(num, 1.6f)) * (0.75f + 0.25f * (1f - num));
					float num3 = Mathf.Abs((float)j - 31.5f) / 32f;
					if (num2 <= 0f)
					{
						val.SetPixel(j, i, Color.clear);
						continue;
					}
					float num4 = Mathf.Clamp01((num2 * 2f - num3) * 8f);
					float num5 = Mathf.Clamp01(1f - num3 / (num2 * 1.1f)) * (1f - num);
					Color val5 = Color.Lerp(Color.Lerp(val3, val4, Mathf.Pow(num, 1.5f)), val2, num5);
					val5.a = num4 * Mathf.Clamp01(1.2f - num * 0.9f);
					val.SetPixel(j, i, val5);
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 64f, 128f), new Vector2(0.5f, 0.5f), 128f);
		}
	}
}
namespace BoplModKit.Online
{
	internal static class OnlineCompat
	{
		private const string Marker = " | mods ";

		private static string tag;

		public static string Tag => tag ?? (tag = "Bobl Mods 0.2.0 #" + Fingerprint());

		public static string Fingerprint()
		{
			StringBuilder stringBuilder = new StringBuilder();
			stringBuilder.Append("0.2.0").Append(';');
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in from kv in (IEnumerable<KeyValuePair<ConfigDefinition, ConfigEntryBase>>)((BaseUnityPlugin)Plugin.Instance).Config
				orderby kv.Key.Section, kv.Key.Key
				select kv)
			{
				if ((!(item.Key.Section == "Maps") || !(item.Key.Key == "DumpLevelLayouts")) && !(item.Key.Section == "CPU"))
				{
					stringBuilder.Append(item.Key.Section).Append('.').Append(item.Key.Key)
						.Append('=')
						.Append(item.Value.GetSerializedValue())
						.Append(';');
				}
			}
			string path = Path.Combine(Plugin.PluginDir, "maps");
			if (Plugin.CustomMapsEnabled.Value && Directory.Exists(path))
			{
				foreach (string item2 in from p in Directory.GetFiles(path, "*.json")
					orderby Path.GetFileName(p)
					select p)
				{
					stringBuilder.Append(Path.GetFileName(item2)).Append('=').Append(File.ReadAllText(item2).Replace("\r", ""))
						.Append(';');
				}
			}
			uint num = 2166136261u;
			byte[] bytes = Encoding.UTF8.GetBytes(stringBuilder.ToString());
			foreach (byte b in bytes)
			{
				num ^= b;
				num *= 16777619;
			}
			return num.ToString("x8").Substring(0, 6);
		}

		internal static string WithTag(string baseVersion)
		{
			if (baseVersion == null)
			{
				return null;
			}
			int num = baseVersion.IndexOf(" | mods ");
			return ((num >= 0) ? baseVersion.Substring(0, num) : baseVersion) + " | mods " + Tag;
		}
	}
	[HarmonyPatch(typeof(printText), "Awake")]
	internal static class PrintText_Awake_Patch
	{
		private static void Postfix(printText __instance)
		{
			string text = OnlineCompat.WithTag(Constants.version);
			if (text != null)
			{
				Constants.version = text;
				TextMeshProUGUI component = ((Component)__instance).GetComponent<TextMeshProUGUI>();
				if ((Object)(object)component != (Object)null)
				{
					((TMP_Text)component).text = text;
					((TMP_Text)component).enableWordWrapping = false;
				}
				Plugin.Log.LogInfo((object)("Online version: \"" + text + "\" (only players with this exact text can play together)."));
			}
		}
	}
}
namespace BoplModKit.Maps
{
	[HarmonyPatch]
	internal static class ForceLevelPatches
	{
		private static void Force(ref int __result)
		{
			int value = Plugin.ForceLevel.Value;
			if (value >= 0)
			{
				Traverse.Create(typeof(GameSession)).Field("currentLevel").SetValue((object)(byte)value);
				__result = value;
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameSession), "RandomBagLevel")]
		private static void RandomBagLevel(ref int __result)
		{
			Force(ref __result);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameSession), "NextLevel")]
		private static void NextLevel(ref int __result)
		{
			Force(ref __result);
		}
	}
	public class MapFile
	{
		public string name;

		public int level = -1;

		public bool enabled = true;

		public List<float[]> spawns;

		public List<PlatformDef> platforms = new List<PlatformDef>();
	}
	public class PlatformDef
	{
		public float x;

		public float y;

		public float halfWidth = 5f;

		public float halfHeight = 1f;

		public float bevel = 1f;

		public float rotation;

		public int copyFrom;
	}
	[HarmonyPatch(typeof(GameSessionHandler), "Awake")]
	internal static class GameSessionHandler_Awake_Patch
	{
		private static void Prefix(GameSessionHandler __instance)
		{
			try
			{
				MapLoader.OnLevelAwake(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Map loader failed, level left unchanged: " + ex));
			}
		}
	}
	internal static class MapLoader
	{
		private const float Rad2Deg = 57.29578f;

		private static bool warnedFixedSize;

		private static string MapsDir => Path.Combine(Plugin.PluginDir, "maps");

		internal static void OnLevelAwake(GameSessionHandler gsh)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			int num = ((Scene)(ref activeScene)).buildIndex - 6;
			if ((Object)(object)gsh.Level == (Object)null || num < 0)
			{
				return;
			}
			StickyRoundedRectangle[] array = (from g in ((Component)gsh.Level.transform.root).GetComponentsInChildren<StickyRoundedRectangle>()
				where (Object)(object)g != (Object)null && !((MonoUpdatable)g).IsDestroyed
				select g).ToArray();
			if (Plugin.DumpLevelLayouts.Value)
			{
				Dump(gsh, activeScene, num, array);
			}
			if (!Plugin.CustomMapsEnabled.Value || array.Length == 0)
			{
				return;
			}
			MapFile mapFile = FindMap(num);
			if (mapFile == null)
			{
				return;
			}
			Plugin.Log.LogInfo((object)$"Loading custom map '{mapFile.name}' over level {num} ({((Scene)(ref activeScene)).name}).");
			StickyRoundedRectangle[] array2 = array;
			foreach (StickyRoundedRectangle val in array2)
			{
				LogRenderInfo("original", ((Component)val).gameObject);
			}
			int num3 = 0;
			foreach (PlatformDef platform in mapFile.platforms)
			{
				if (SpawnPlatform(array[Mathf.Clamp(platform.copyFrom, 0, array.Length - 1)], platform))
				{
					num3++;
				}
			}
			if (num3 == 0)
			{
				Plugin.Log.LogWarning((object)"Custom map produced no platforms; keeping the original level.");
				return;
			}
			array2 = array;
			for (int num2 = 0; num2 < array2.Length; num2++)
			{
				Updater.DestroyFix(((Component)array2[num2]).gameObject);
			}
			if (mapFile.spawns != null)
			{
				for (int num4 = 0; num4 < mapFile.spawns.Count && num4 < gsh.teamSpawns.Length; num4++)
				{
					float[] array3 = mapFile.spawns[num4];
					if (array3 != null && array3.Length >= 2)
					{
						gsh.teamSpawns[num4] = new Vec2((Fix)array3[0], (Fix)array3[1]);
					}
				}
			}
			Plugin.Log.LogInfo((object)$"Custom map '{mapFile.name}': {num3} platforms, {array.Length} originals removed.");
		}

		private static bool SpawnPlatform(StickyRoundedRectangle template, PlatformDef p)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = ((Component)template).transform.parent;
			GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, parent);
			((Object)val).name = ((Object)((Component)template).gameObject).name + " (custom)";
			Vec2 val2 = default(Vec2);
			((Vec2)(ref val2))..ctor((Fix)p.x, (Fix)p.y);
			Fix val3 = (Fix)(p.rotation / 57.29578f);
			FixTransform component = val.GetComponent<FixTransform>();
			if ((Object)(object)component == (Object)null)
			{
				Object.Destroy((Object)(object)val);
				return false;
			}
			Traverse obj = Traverse.Create((object)component);
			obj.Field("_position").SetValue((object)val2);
			obj.Field("_rotation").SetValue((object)val3);
			component.position = val2;
			component.rotation = val3;
			Fix val4 = (Fix)Mathf.Max(0.05f, p.halfHeight);
			Fix val5 = (Fix)Mathf.Max(0.05f, p.halfWidth);
			Fix val6 = (Fix)Mathf.Max(0.05f, p.bevel);
			ResizablePlatform val7 = val.GetComponent<ResizablePlatform>();
			if ((Object)(object)val7 == (Object)null && Plugin.ResizeFixedPlatforms.Value && (Object)(object)val.GetComponent<AnimateVelocity>() != (Object)null)
			{
				try
				{
					val7 = val.AddComponent<ResizablePlatform>();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Could not make platform resizable: " + ex.Message));
					val7 = null;
				}
			}
			if ((Object)(object)val7 != (Object)null)
			{
				val7.ResizePlatform(val4, val5, val6, true);
			}
			else if (!warnedFixedSize)
			{
				warnedFixedSize = true;
				Plugin.Log.LogInfo((object)"Level platforms are fixed-size: halfWidth/halfHeight/bevel are ignored, pick the shape with copyFrom instead.");
			}
			LogRenderInfo("custom", val);
			return true;
		}

		private static MapFile FindMap(int levelIndex)
		{
			if (!Directory.Exists(MapsDir))
			{
				return null;
			}
			string[] files = Directory.GetFiles(MapsDir, "*.json", SearchOption.TopDirectoryOnly);
			foreach (string path in files)
			{
				try
				{
					MapFile mapFile = JsonConvert.DeserializeObject<MapFile>(File.ReadAllText(path));
					if (mapFile != null && mapFile.enabled && mapFile.level == levelIndex && mapFile.platforms != null && mapFile.platforms.Count > 0)
					{
						if (string.IsNullOrEmpty(mapFile.name))
						{
							mapFile.name = Path.GetFileNameWithoutExtension(path);
						}
						return mapFile;
					}
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Could not read map " + Path.GetFileName(path) + ": " + ex.Message));
				}
			}
			return null;
		}

		private static void Dump(GameSessionHandler gsh, Scene scene, int levelIndex, StickyRoundedRectangle[] grounds)
		{
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: 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)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			MapFile mapFile = new MapFile
			{
				name = ((Scene)(ref scene)).name + " (original)",
				level = levelIndex,
				enabled = false,
				spawns = gsh.teamSpawns.Select((Vec2 s) => new float[2]
				{
					(float)s.x,
					(float)s.y
				}).ToList()
			};
			foreach (StickyRoundedRectangle obj in grounds)
			{
				FixTransform component = ((Component)obj).GetComponent<FixTransform>();
				DPhysicsRoundedRect component2 = ((Component)obj).GetComponent<DPhysicsRoundedRect>();
				if (!((Object)(object)component == (Object)null) && !((Object)(object)component2 == (Object)null))
				{
					Vec2 val = component2.CalcExtents();
					mapFile.platforms.Add(new PlatformDef
					{
						x = (float)component.serializedPosition.x,
						y = (float)component.serializedPosition.y,
						halfWidth = (float)val.x,
						halfHeight = (float)val.y,
						bevel = (float)component2.radius,
						rotation = (float)component.serializedRotation * 57.29578f,
						copyFrom = 0
					});
				}
			}
			string text = Path.Combine(MapsDir, "dumps");
			Directory.CreateDirectory(text);
			string text2 = Path.Combine(text, $"level_{levelIndex:D2}_{Sanitize(((Scene)(ref scene)).name)}.json");
			var anon = new
			{
				info = "Original layout dumped by BoplModKit. Copy to the maps folder, set enabled=true, and edit.",
				platformNames = grounds.Select((StickyRoundedRectangle g) => ((Object)((Component)g).gameObject).name).ToArray(),
				platformTypes = grounds.Select((StickyRoundedRectangle g) => ((object)Unsafe.As<PlatformType, PlatformType>(ref g.platformType)/*cast due to .constrained prefix*/).ToString()).ToArray(),
				resizable = grounds.Select((StickyRoundedRectangle g) => (Object)(object)((Component)g).GetComponent<ResizablePlatform>() != (Object)null).ToArray(),
				levelType = ((object)Unsafe.As<LevelType, LevelType>(ref gsh.levelType)/*cast due to .constrained prefix*/).ToString()
			};
			string contents = JsonConvert.SerializeObject((object)mapFile, (Formatting)1);
			string contents2 = JsonConvert.SerializeObject((object)anon, (Formatting)1);
			File.WriteAllText(text2, contents);
			File.WriteAllText(Path.ChangeExtension(text2, ".info.txt"), contents2);
			Plugin.Log.LogInfo((object)$"Dumped level {levelIndex} ({((Scene)(ref scene)).name}, {grounds.Length} platforms) to {text2}");
		}

		internal static void LogRenderInfo(string label, GameObject go)
		{
			//IL_0043: 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)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				StringBuilder stringBuilder = new StringBuilder();
				stringBuilder.Append($"[render:{label}] {((Object)go).name} active={go.activeInHierarchy} layer={go.layer} scale={go.transform.localScale} z={go.transform.position.z:F2}");
				Renderer[] componentsInChildren = go.GetComponentsInChildren<Renderer>(true);
				foreach (Renderer val in componentsInChildren)
				{
					stringBuilder.Append($"\n    {((object)val).GetType().Name} on '{((Object)((Component)val).gameObject).name}' enabled={val.enabled} sortLayer={val.sortingLayerName} order={val.sortingOrder}");
					SpriteRenderer val2 = (SpriteRenderer)(object)((val is SpriteRenderer) ? val : null);
					if (val2 != null && (Object)(object)val2.sprite != (Object)null)
					{
						object[] obj = new object[7]
						{
							((Object)val2.sprite).name,
							((Texture)val2.sprite.texture).width,
							((Texture)val2.sprite.texture).height,
							null,
							null,
							null,
							null
						};
						Rect rect = val2.sprite.rect;
						obj[3] = ((Rect)(ref rect)).width;
						rect = val2.sprite.rect;
						obj[4] = ((Rect)(ref rect)).height;
						obj[5] = val2.sprite.pixelsPerUnit;
						obj[6] = val2.color;
						stringBuilder.Append(string.Format(" sprite={0} tex={1}x{2} rect={3}x{4} ppu={5} color={6}", obj));
					}
					Material sharedMaterial = val.sharedMaterial;
					if (!((Object)(object)sharedMaterial != (Object)null))
					{
						continue;
					}
					stringBuilder.Append(" shader=" + ((Object)sharedMaterial.shader).name);
					string[] array = new string[4] { "_Scale", "_BevelRadius", "_RHeight", "_RWidth" };
					foreach (string text in array)
					{
						if (sharedMaterial.HasProperty(text))
						{
							stringBuilder.Append($" {text}={sharedMaterial.GetFloat(text):F3}");
						}
					}
				}
				Plugin.Log.LogInfo((object)stringBuilder.ToString());
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("render info failed: " + ex.Message));
			}
		}

		private static string Sanitize(string s)
		{
			return new string(s.Select((char c) => (!char.IsLetterOrDigit(c)) ? '_' : c).ToArray());
		}
	}
}
namespace BoplModKit.Cpu
{
	internal class CpuBrain : MonoBehaviour
	{
		public int playerId;

		private float jumpHold;

		private float jumpCooldown;

		private readonly float[] abilityHold = new float[3];

		private readonly float[] abilityCooldown = new float[3];

		private float wanderTimer;

		private float wanderDir = 1f;

		private Vector2 lastPos;

		private float stuckTime;

		private Random rng;

		private void Start()
		{
			rng = new Random(playerId * 7919 + Time.frameCount);
			for (int i = 0; i < 3; i++)
			{
				abilityCooldown[i] = 1.5f + (float)rng.NextDouble() * 2f;
			}
		}

		private float Rand()
		{
			return (float)rng.NextDouble();
		}

		private void Update()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: 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_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_020a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_02d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02da: Unknown result type (might be due to invalid IL or missing references)
			//IL_02df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d7: Unknown result type (might be due to invalid IL or missing references)
			PlayerHandler val = PlayerHandler.Get();
			Player val2 = ((val != null) ? val.GetPlayer(playerId) : null);
			if (val2 == null)
			{
				return;
			}
			if (!val2.IsAlive || GameSessionHandler.GameIsPaused || !Plugin.CpuFights.Value)
			{
				val2.ForceSetInputProfile(false, false, false, false, false, false, (byte)0, false, false, false, false);
				return;
			}
			float deltaTime = Time.deltaTime;
			float num = Mathf.Clamp01(Plugin.CpuAggression.Value);
			Vector2 val3 = (Vector2)val2.Position;
			float num2 = (float)SceneBounds.WaterHeight;
			Player val4 = FindTarget(val2, val.PlayerList(), val3);
			bool flag = false;
			Vector2 normalized = default(Vector2);
			Vector2 val6;
			if (val4 != null)
			{
				Vector2 val5 = (Vector2)val4.Position - val3;
				float num3 = ((Mathf.Abs(val5.x) > 2.5f) ? Mathf.Sign(val5.x) : ((0f - Mathf.Sign(val5.x)) * 0.4f));
				((Vector2)(ref normalized))..ctor(num3, 0f);
				val6 = ((Vector2)(ref val5)).normalized;
				if (val5.y > 2.5f && Rand() < deltaTime * 2.5f)
				{
					flag = true;
				}
			}
			else
			{
				wanderTimer -= deltaTime;
				if (wanderTimer <= 0f)
				{
					wanderTimer = 1f + Rand() * 2f;
					wanderDir = ((Rand() < 0.5f) ? (-1f) : 1f);
				}
				((Vector2)(ref normalized))..ctor(wanderDir, 0f);
				val6 = normalized;
			}
			Vector2 val7;
			if (val3.y < num2 + 3.5f)
			{
				val7 = new Vector2(0f - Mathf.Sign((val3.x == 0f) ? 1f : val3.x), 0.6f);
				normalized = ((Vector2)(ref val7)).normalized;
				val6 = normalized;
				flag = true;
			}
			val7 = val3 - lastPos;
			if (((Vector2)(ref val7)).sqrMagnitude < 0.0004f)
			{
				stuckTime += deltaTime;
			}
			else
			{
				stuckTime = 0f;
			}
			lastPos = val3;
			if (stuckTime > 0.8f)
			{
				flag = true;
				stuckTime = 0f;
			}
			if (Rand() < deltaTime * 0.35f * (0.5f + num))
			{
				flag = true;
			}
			jumpCooldown -= deltaTime;
			if (jumpHold > 0f)
			{
				jumpHold -= deltaTime;
			}
			else if (flag && jumpCooldown <= 0f)
			{
				jumpHold = 0.08f;
				jumpCooldown = 0.35f;
			}
			bool flag2 = jumpHold > 0f;
			bool[] array = new bool[3];
			int num4 = ((val2.Abilities != null) ? Mathf.Min(3, val2.Abilities.Count) : 0);
			float num5 = ((val4 != null) ? Vector2.Distance(val3, (Vector2)val4.Position) : float.MaxValue);
			for (int i = 0; i < num4; i++)
			{
				abilityCooldown[i] -= deltaTime;
				if (abilityHold[i] > 0f)
				{
					abilityHold[i] -= deltaTime;
					array[i] = true;
				}
				else if (num5 < Plugin.CpuRange.Value && abilityCooldown[i] <= 0f && Rand() < deltaTime * (0.6f + 2.4f * num))
				{
					abilityHold[i] = 0.2f + Rand() * 0.2f;
					abilityCooldown[i] = Mathf.Lerp(4f, 1f, num) + Rand() * 1.5f;
					array[i] = true;
				}
			}
			byte b = InputProfile.JoyStickAngleByteFromVector((Vec2)((array[0] || array[1] || array[2]) ? val6 : normalized));
			val2.ForceSetInputProfile(false, false, flag2, array[0], array[1], array[2], b, false, false, false, false);
		}

		private static Player FindTarget(Player me, List<Player> players, Vector2 pos)
		{
			//IL_0037: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			Player result = null;
			float num = float.MaxValue;
			foreach (Player player in players)
			{
				if (player != null && player != me && player.IsAlive && player.Team != me.Team)
				{
					Vector2 val = (Vector2)player.Position - pos;
					float sqrMagnitude = ((Vector2)(ref val)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = player;
					}
				}
			}
			return result;
		}
	}
	internal static class CpuPlayers
	{
		internal static readonly HashSet<int> BotIds = new HashSet<int>();

		private static readonly Random Rng = new Random();

		public static bool IsBot(int playerId)
		{
			return BotIds.Contains(playerId);
		}

		public static bool IsBot(Player p)
		{
			if (p != null)
			{
				return BotIds.Contains(p.Id);
			}
			return false;
		}

		internal static void AddBots(CharacterSelectHandler handler)
		{
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: 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_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Expected O, but got Unknown
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_01df: 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)
			BotIds.Clear();
			int num = Mathf.Clamp(Plugin.CpuCount.Value, 0, 3);
			if (num == 0 || GameLobby.isOnlineGame)
			{
				return;
			}
			List<Player> list = PlayerHandler.Get().PlayerList();
			PlayerColors value = Traverse.Create((object)handler).Field("playerColors").GetValue<PlayerColors>();
			NamedSpriteList abilityIcons = SteamManager.instance.abilityIcons;
			int slots = Mathf.Clamp(((Object)(object)Settings.Get() != (Object)null) ? Settings.Get().NumberOfAbilities : 3, 1, 3);
			HashSet<int> usedTeams = new HashSet<int>(list.Select((Player p) => p.Team));
			HashSet<Material> hashSet = new HashSet<Material>(list.Select((Player p) => p.Color));
			for (int num2 = 0; num2 < num; num2++)
			{
				if (list.Count >= 4)
				{
					break;
				}
				int num3 = list.Count + 1;
				int num4 = Enumerable.Range(0, 4).FirstOrDefault((int t) => !usedTeams.Contains(t));
				usedTeams.Add(num4);
				Player val = new Player(num3, num4)
				{
					UsesKeyboardAndMouse = false,
					CanUseAbilities = true,
					inputDevice = null,
					CustomKeyBinding = null,
					Abilities = new List<GameObject>(3),
					AbilityIcons = new List<Sprite>(3)
				};
				if ((Object)(object)value != (Object)null)
				{
					for (int num5 = 0; num5 < value.Length; num5++)
					{
						Material playerMaterial = value[num5].playerMaterial;
						if (!hashSet.Contains(playerMaterial))
						{
							val.Color = playerMaterial;
							hashSet.Add(playerMaterial);
							break;
						}
					}
				}
				foreach (int item in PickAbilities(abilityIcons, slots))
				{
					val.Abilities.Add(abilityIcons.sprites[item].associatedGameObject);
					val.AbilityIcons.Add(abilityIcons.sprites[item].sprite);
				}
				list.Add(val);
				BotIds.Add(num3);
				Plugin.Log.LogInfo((object)string.Format("CPU player {0} (team {1}) with: {2}", num3, num4, string.Join(", ", val.Abilities.Select((GameObject a) => ((Object)a).name))));
			}
		}

		private static IEnumerable<int> PickAbilities(NamedSpriteList icons, int slots)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			List<int> chosen = new List<int>();
			string text = Plugin.CpuAbilities.Value.Trim();
			if (!string.Equals(text, "random", StringComparison.OrdinalIgnoreCase) && text.Length > 0)
			{
				string[] array = text.Split(',');
				foreach (string text2 in array)
				{
					int num = icons.IndexOf(text2.Trim());
					if (num >= 2 && (Object)(object)icons.sprites[num].associatedGameObject != (Object)null && !chosen.Contains(num))
					{
						chosen.Add(num);
					}
					if (chosen.Count == slots)
					{
						break;
					}
				}
			}
			List<int> list = (from num2 in Enumerable.Range(2, icons.sprites.Count - 2)
				where (Object)(object)icons.sprites[num2].associatedGameObject != (Object)null && !chosen.Contains(num2)
				select num2).ToList();
			while (chosen.Count < slots && list.Count > 0)
			{
				int item = list[Rng.Next(list.Count)];
				list.Remove(item);
				chosen.Add(item);
			}
			return chosen;
		}
	}
	[HarmonyPatch(typeof(CharacterSelectHandler), "TryStartGame_inner")]
	internal static class CharacterSelectHandler_TryStart_Cpu
	{
		private static void Prefix(out bool __state)
		{
			__state = CharacterSelectHandler.startButtonAvailable;
		}

		private static void Postfix(CharacterSelectHandler __instance, bool __state)
		{
			if (!__state || CharacterSelectHandler.startButtonAvailable)
			{
				return;
			}
			try
			{
				CpuPlayers.AddBots(__instance);
			}
			catch (Exception ex)
			{
				Plugin.Log.LogError((object)("Could not add CPU players: " + ex));
			}
		}
	}
	[HarmonyPatch(typeof(CharacterSelectHandler), "Start")]
	internal static class CharacterSelectHandler_Start_Cpu
	{
		private static void Prefix()
		{
			PlayerHandler obj = PlayerHandler.Get();
			if (obj != null)
			{
				obj.PlayerList()?.RemoveAll((Player p) => CpuPlayers.IsBot(p));
			}
			CpuPlayers.BotIds.Clear();
		}
	}
	[HarmonyPatch(typeof(InputUpdater), "Init")]
	internal static class InputUpdater_Init_Cpu
	{
		private static bool Prefix(InputUpdater __instance, int playerId)
		{
			if (!CpuPlayers.IsBot(playerId))
			{
				return true;
			}
			Traverse obj = Traverse.Create((object)__instance);
			obj.Field("linkedPlayer").SetValue((object)PlayerHandler.Get().GetPlayer(playerId));
			obj.Field("hasBeenInited").SetValue((object)true);
			PlayerInput component = ((Component)__instance).GetComponent<PlayerInput>();
			if ((Object)(object)component != (Object)null)
			{
				((Behaviour)component).enabled = false;
			}
			((Component)__instance).gameObject.AddComponent<CpuBrain>().playerId = playerId;
			return false;
		}
	}
	[HarmonyPatch(typeof(InputUpdater), "Update")]
	internal static class InputUpdater_Update_Cpu
	{
		private static bool Prefix(InputUpdater __instance)
		{
			return (Object)(object)((Component)__instance).GetComponent<CpuBrain>() == (Object)null;
		}
	}
	[HarmonyPatch(typeof(Player), "PlayerHasValidGamepad")]
	internal static class Player_PlayerHasValidGamepad_Cpu
	{
		private static bool Prefix(Player __instance, ref bool __result)
		{
			if (!CpuPlayers.IsBot(__instance))
			{
				return true;
			}
			__result = false;
			return false;
		}
	}
	internal class CpuMenuOverlay : MonoBehaviour
	{
		private CharacterSelectHandler handler;

		private float nextLookup;

		private GUIStyle style;

		public static void Create()
		{
			//IL_0005: 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_0010: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("BoplModKit_CpuMenu");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<CpuMenuOverlay>();
		}

		private void Update()
		{
			if ((Object)(object)handler == (Object)null && Time.unscaledTime >= nextLookup)
			{
				nextLookup = Time.unscaledTime + 0.5f;
				handler = Object.FindObjectOfType<CharacterSelectHandler>();
			}
			if ((Object)(object)handler == (Object)null || GameLobby.isOnlineGame)
			{
				return;
			}
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current.cKey).wasPressedThisFrame)
			{
				Plugin.CpuCount.Value = (Plugin.CpuCount.Value + 1) % 4;
				AudioManager obj = AudioManager.Get();
				if (obj != null)
				{
					obj.Play("navigateMenu");
				}
			}
		}

		private void OnGUI()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_005a: 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)
			//IL_00b5: Expected O, but got Unknown
			//IL_00b0: 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)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)handler == (Object)null) && !GameLobby.isOnlineGame)
			{
				if (style == null)
				{
					style = new GUIStyle(GUI.skin.box)
					{
						fontSize = Mathf.Max(18, Screen.height / 40),
						alignment = (TextAnchor)4
					};
					style.normal.textColor = Color.white;
				}
				int value = Plugin.CpuCount.Value;
				string arg = (Plugin.CpuFights.Value ? "" : " (standing still)");
				string text = ((value == 0) ? "CPU opponents: off   (press C)" : $"CPU opponents: {value}{arg}   (press C)");
				Vector2 val = style.CalcSize(new GUIContent(text));
				GUI.Box(new Rect(((float)Screen.width - val.x - 30f) / 2f, (float)Screen.height - val.y - 30f, val.x + 30f, val.y + 12f), text, style);
			}
		}
	}
}
namespace BoplModKit.Abilities
{
	internal class AbilityGridScroller : MonoBehaviour
	{
		public AbilityGrid grid;

		public Vector2[] basePositions;

		public float entrySize;

		public int columns;

		public int totalRows;

		public int visibleRows;

		public int scrollRow;

		public int lastSelected = -1;

		public Vector3 circleScale = Vector3.one;

		public RectTransform track;

		public RectTransform thumb;

		public float trackTop;

		public float trackHeight;

		private static Sprite rounded;

		internal void BuildScrollBar(AbilityGridEntry template, Color color)
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: 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_0128: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rounded == (Object)null)
			{
				rounded = MakeRoundedSprite();
			}
			RectTransform rectTrans = template.rectTrans;
			float num = basePositions[columns - 1].x + entrySize * 0.62f;
			trackTop = basePositions[0].y + entrySize * 0.42f;
			trackHeight = (float)visibleRows * entrySize - entrySize * 0.16f;
			float width = Mathf.Max(6f, entrySize * 0.12f);
			track = MakeBar("ScrollTrack", rectTrans, new Color(color.r * 0.6f, color.g * 0.6f, color.b * 0.6f, 0.55f), num, width, trackHeight);
			track.anchoredPosition = new Vector2(num, trackTop - trackHeight / 2f);
			thumb = MakeBar("ScrollThumb", rectTrans, new Color(1f, 1f, 1f, 0.95f), num, width, trackHeight * (float)visibleRows / (float)totalRows);
		}

		internal void UpdateScrollBar()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)thumb == (Object)null))
			{
				float num = trackHeight * (float)visibleRows / (float)totalRows;
				int num2 = Mathf.Max(1, totalRows - visibleRows);
				float num3 = trackTop - (trackHeight - num) * ((float)scrollRow / (float)num2);
				thumb.anchoredPosition = new Vector2(track.anchoredPosition.x, num3 - num / 2f);
				((Transform)thumb).SetAsLastSibling();
			}
		}

		private RectTransform MakeBar(string name, RectTransform like, Color color, float x, float width, float height)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			//IL_003c: 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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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)
			GameObject val = new GameObject(name, new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(((Transform)like).parent, false);
			component.anchorMin = like.anchorMin;
			component.anchorMax = like.anchorMax;
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = new Vector2(width, height);
			Image component2 = val.GetComponent<Image>();
			component2.sprite = rounded;
			component2.type = (Type)1;
			((Graphic)component2).color = color;
			((Graphic)component2).raycastTarget = false;
			return component;
		}

		private static Sprite MakeRoundedSprite()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			Texture2D val = new Texture2D(32, 32, (TextureFormat)4, false)
			{
				filterMode = (FilterMode)1
			};
			float num = 15.5f;
			float num2 = 15.5f;
			for (int i = 0; i < 32; i++)
			{
				for (int j = 0; j < 32; j++)
				{
					float num3 = Mathf.Sqrt(((float)j - num) * ((float)j - num) + ((float)i - num) * ((float)i - num));
					val.SetPixel(j, i, new Color(1f, 1f, 1f, Mathf.Clamp01(num2 - num3 + 0.5f)));
				}
			}
			val.Apply();
			return Sprite.Create(val, new Rect(0f, 0f, 32f, 32f), new Vector2(0.5f, 0.5f), 100f, 0u, (SpriteMeshType)0, new Vector4(15f, 15f, 15f, 15f));
		}
	}
	[HarmonyPatch(typeof(AbilityGrid), "Awake")]
	internal static class AbilityGrid_Awake_Scroll
	{
		private static void Postfix(AbilityGrid __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: 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_01c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
			Traverse val = Traverse.Create((object)__instance);
			AbilityGridEntry[] value = val.Field("grid").GetValue<AbilityGridEntry[]>();
			RectTransform value2 = val.Field("recTrans").GetValue<RectTransform>();
			int columns = __instance.columns;
			int addedCount = AbilityRegistry.AddedCount;
			if (value == null || (Object)(object)value2 == (Object)null || columns <= 0 || addedCount <= 0)
			{
				return;
			}
			int num = Mathf.CeilToInt((float)(value.Length - addedCount) / (float)columns);
			int num2 = Mathf.CeilToInt((float)value.Length / (float)columns);
			if (num2 > num)
			{
				Rect rect = value2.rect;
				float width = ((Rect)(ref rect)).width;
				rect = value2.rect;
				float height = ((Rect)(ref rect)).height;
				float num3 = Mathf.Sqrt(width * (height * 0.9f) / (float)(columns * num));
				val.Field("entrySize").SetValue((object)num3);
				Vector2 val2 = default(Vector2);
				((Vector2)(ref val2))..ctor(126f, -122f);
				Vector2[] array = (Vector2[])(object)new Vector2[value.Length];
				for (int i = 0; i < value.Length; i++)
				{
					int num4 = i / columns;
					int num5 = i % columns;
					array[i] = val2 + new Vector2((float)num5 * num3 - width / 2f, (float)(-num4) * num3 + height / 2f);
				}
				AbilityGridScroller abilityGridScroller = ((Component)__instance).gameObject.AddComponent<AbilityGridScroller>();
				abilityGridScroller.grid = __instance;
				abilityGridScroller.basePositions = array;
				abilityGridScroller.entrySize = num3;
				abilityGridScroller.columns = columns;
				abilityGridScroller.totalRows = num2;
				abilityGridScroller.visibleRows = num;
				if ((Object)(object)__instance.selectionCircle != (Object)null)
				{
					abilityGridScroller.circleScale = ((Transform)__instance.selectionCircle).localScale;
				}
				Color color = (Color)(((Object)(object)__instance.borderImage != (Object)null) ? ((Graphic)__instance.borderImage).color : new Color(0.1f, 0.3f, 0.6f));
				abilityGridScroller.BuildScrollBar(value[0], color);
				AbilityGrid_Update_Scroll.Layout(abilityGridScroller, value);
				Plugin.Log.LogInfo((object)$"Ability grid: {value.Length} abilities, {num2} rows, showing {num} at a time.");
			}
		}
	}
	[HarmonyPatch(typeof(AbilityGrid), "Update")]
	internal static class AbilityGrid_Update_Scroll
	{
		private static void Postfix(AbilityGrid __instance)
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			AbilityGridScroller component = ((Component)__instance).GetComponent<AbilityGridScroller>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			Traverse val = Traverse.Create((object)__instance);
			AbilityGridEntry[] value = val.Field("grid").GetValue<AbilityGridEntry[]>();
			if (value == null)
			{
				return;
			}
			int num = Mathf.Max(0, component.totalRows - component.visibleRows);
			if (val.Field("usesKeyboardAndMouse").GetValue<bool>() && Mouse.current != null)
			{
				float y = ((InputControl<Vector2>)(object)Mouse.current.scroll).ReadValue().y;
				if (Mathf.Abs(y) > 0.01f)
				{
					int scrollRow = component.scrollRow;
					component.scrollRow = Mathf.Clamp(component.scrollRow + ((y < 0f) ? 1 : (-1)), 0, num);
					if (component.scrollRow != scrollRow)
					{
						AudioManager.Get().Play("navigateMenu");
					}
				}
			}
			int selectedIcon = __instance.SelectedIcon;
			if (selectedIcon != component.lastSelected)
			{
				component.lastSelected = selectedIcon;
				int num2 = selectedIcon / component.columns;
				if (num2 < component.scrollRow)
				{
					component.scrollRow = num2;
				}
				if (num2 >= component.scrollRow + component.visibleRows)
				{
					component.scrollRow = num2 - component.visibleRows + 1;
				}
			}
			component.scrollRow = Mathf.Clamp(component.scrollRow, 0, num);
			Layout(component, value);
			if (selectedIcon >= 0 && selectedIcon < value.Length && (Object)(object)__instance.selectionCircle != (Object)null)
			{
				int num3 = selectedIcon / component.columns;
				bool flag = num3 >= component.scrollRow && num3 < component.scrollRow + component.visibleRows;
				__instance.selectionCircle.anchoredPosition = value[selectedIcon].rectTrans.anchoredPosition;
				((Transform)__instance.selectionCircle).localScale = (flag ? component.circleScale : Vector3.zero);
			}
		}

		internal static void Layout(AbilityGridScroller s, AbilityGridEntry[] entries)
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			float num = (float)s.scrollRow * s.entrySize;
			for (int i = 0; i < entries.Length && i < s.basePositions.Length; i++)
			{
				AbilityGridEntry val = entries[i];
				if (!((Object)(object)val == (Object)null))
				{
					int num2 = i / s.columns;
					bool num3 = num2 >= s.scrollRow && num2 < s.scrollRow + s.visibleRows;
					val.rectTrans.anchoredPosition = s.basePositions[i] + new Vector2(0f, num);
					if (!num3)
					{
						((Transform)val.rectTrans).localScale = Vector3.zero;
					}
				}
			}
			s.UpdateScrollBar();
		}
	}
	internal static class AbilityRegistry
	{
		private sealed class CustomAbility
		{
			public string Name;

			public string BaseAbility;

			public string IconFile;

			public bool IsOffensive;

			public IconStyle Icon;

			public Func<bool> Enabled;

			public Action<GameObject, GameObject> Build;
		}

		private static GameObject templateRoot;

		private static bool registered;

		internal static int AddedCount;

		private static readonly List<CustomAbility> Abilities = new List<CustomAbility>
		{
			new CustomAbility
			{
				Name = "Rocket Hop",
				BaseAbility = "Dash",
				IconFile = "rocket_hop.png",
				IsOffensive = false,
				Icon = new IconStyle(new Color(1f, 0.85f, 0.35f), new Color(1f, 0.55f, 0.15f), Glyph.Chevron),
				Enabled = () => Plugin.RocketHopEnabled.Value,
				Build = RocketHop.BuildFromDash
			},
			new CustomAbility
			{
				Name = "Bubble",
				BaseAbility = "Invisibility",
				IconFile = "bubble.png",
				IsOffensive = false,
				Icon = new IconStyle(new Color(0.75f, 0.95f, 1f), new Color(0.2f, 0.6f, 0.95f), Glyph.Ring),
				Enabled = () => Plugin.ShieldEnabled.Value,
				Build = delegate(GameObject p, GameObject b)
				{
					InstantEffect.BuildFromInvisibility<ShortShield>(p, Plugin.ShieldCooldown.Value);
				}
			},
			new CustomAbility
			{
				Name = "Freeze Ray",
				BaseAbility = "Shrink ray",
				IconFile = "freeze_ray.png",
				IsOffensive = true,
				Icon = new IconStyle(new Color(0.85f, 0.97f, 1f), new Color(0.35f, 0.75f, 1f), Glyph.Snowflake),
				Enabled = () => Plugin.FreezeEnabled.Value,
				Build = FreezeRayMarker.BuildFromShrinkRay
			},
			new CustomAbility
			{
				Name = "Super Speed",
				BaseAbility = "Invisibility",
				IconFile = "super_speed.png",
				IsOffensive = false,
				Icon = new IconStyle(new Color(1f, 0.97f, 0.6f), new Color(0.95f, 0.75f, 0.1f), Glyph.DoubleChevron),
				Enabled = () => Plugin.SpeedEnabled.Value,
				Build = delegate(GameObject p, GameObject b)
				{
					InstantEffect.BuildFromInvisibility<SuperSpeed>(p, Plugin.SpeedCooldown.Value);
				}
			},
			new CustomAbility
			{
				Name = "Baseball Bat",
				BaseAbility = "Invisibility",
				IconFile = "baseball_bat.png",
				IsOffensive = true,
				Icon = new IconStyle(new Color(0.98f, 0.8f, 0.5f), new Color(0.78f, 0.5f, 0.22f), Glyph.Bat),
				Enabled = () => Plugin.BatEnabled.Value,
				Build = delegate(GameObject p, GameObject b)
				{
					InstantEffect.BuildFromInvisibility<BaseballBat>(p, Plugin.BatCooldown.Value);
				}
			},
			new CustomAbility
			{
				Name = "Glue Gun",
				BaseAbility = "Shrink ray",
				IconFile = "glue_gun.png",
				IsOffensive = true,
				Icon = new IconStyle(new Color(0.75f, 1f, 0.45f), new Color(0.35f, 0.75f, 0.15f), Glyph.Goo),
				Enabled = () => Plugin.GlueEnabled.Value,
				Build = GlueGunMarker.BuildFromShrinkRay
			},
			new CustomAbility
			{
				Name = "Disarm Ray",
				BaseAbility = "Shrink ray",
				IconFile = "disarm_ray.png",
				IsOffensive = true,
				Icon = new IconStyle(new Color(1f, 0.75f, 0.7f), new Color(0.9f, 0.2f, 0.2f), Glyph.Ban),
				Enabled = () => Plugin.DisarmEnabled.Value,
				Build = DisarmRayMarker.Build
			},
			new CustomAbility
			{
				Name = "Splitter",
				BaseAbility = "Shrink ray",
				IconFile = "splitter.png",
				IsOffensive = true,
				Icon = new IconStyle(new Color(1f, 0.8f, 0.97f), new Color(0.85f, 0.35f, 0.85f), Glyph.Split),
				Enabled = () => Plugin.SplitterEnabled.Value,
				Build = SplitterMarker.Build
			}
		};

		public static void EnsureRegistered()
		{
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: 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_0208: Unknown result type (might be due to invalid IL or missing references)
			//IL_024c: 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)
			if (registered || (Object)(object)SteamManager.instance == (Object)null)
			{
				return;
			}
			NamedSpriteList value = Traverse.Create((object)SteamManager.instance).Field("abilityIconsFull").GetValue<NamedSpriteList>();
			if ((Object)(object)value == (Object)null || value.sprites == null)
			{
				Plugin.Log.LogWarning((object)"Ability list not ready yet; will retry.");
				return;
			}
			registered = true;
			Plugin.Log.LogInfo((object)("Game abilities: " + string.Join(", ", value.sprites.Select((NamedSprite s) => s.name))));
			IconLoader.MeasureStandardRadius(value.sprites);
			if ((Object)(object)templateRoot == (Object)null)
			{
				templateRoot = new GameObject("BoplModKit_AbilityTemplates");
				Object.DontDestroyOnLoad((Object)(object)templateRoot);
				templateRoot.SetActive(false);
			}
			foreach (CustomAbility a in Abilities)
			{
				if (!a.Enabled() || value.IndexOf(a.Name) >= 0)
				{
					continue;
				}
				int num = value.sprites.FindIndex((NamedSprite s) => string.Equals(s.name, a.BaseAbility, StringComparison.OrdinalIgnoreCase));
				if (num < 0 || (Object)(object)value.sprites[num].associatedGameObject == (Object)null)
				{
					Plugin.Log.LogError((object)("Cannot add '" + a.Name + "': base ability '" + a.BaseAbility + "' not found."));
					continue;
				}
				NamedSprite val = value.sprites[num];
				try
				{
					GameObject val2 = Object.Instantiate<GameObject>(val.associatedGameObject, templateRoot.transform);
					((Object)val2).name = a.Name;
					a.Build(val2, val.associatedGameObject);
					Sprite val3 = IconLoader.Load(a.IconFile, val.sprite, a.Name, a.Icon);
					value.sprites.Add(new NamedSprite(a.Name, val3, val2, a.IsOffensive));
					AddedCount++;
					Plugin.Log.LogInfo((object)$"Added ability '{a.Name}' (cloned from {val.name}) at index {value.sprites.Count - 1}.");
				}
				catch (Exception arg)
				{
					Plugin.Log.LogError((object)$"Failed to add '{a.Name}': {arg}");
				}
			}
		}

		internal static Fix F(float v)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return (Fix)v;
		}
	}
	[HarmonyPatch(typeof(SteamManager), "Awake")]
	internal static class SteamManager_Awake_Patch
	{
		private static void Postfix()
		{
			AbilityRegistry.EnsureRegistered();
		}
	}
	[HarmonyPatch(typeof(AbilityGrid), "Awake")]
	internal static class AbilityGrid_Awake_Patch
	{
		private static void Prefix()
		{
			AbilityRegistry.EnsureRegistered();
		}
	}
	internal enum Glyph
	{
		Chevron,
		Ring,
		Snowflake,
		DoubleChevron,
		Bat,
		Goo,
		Ban,
		Split
	}
	internal sealed class IconStyle
	{
		public readonly Color Fill;

		public readonly Color Ring;

		public readonly Glyph Glyph;

		public IconStyle(Color fill, Color ring, Glyph glyph)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			Fill = fill;
			Ring = ring;
			Glyph = glyph;
		}
	}
	internal static class IconLoader
	{
		internal static float StandardRadius;

		public static Sprite Load(string file, Sprite reference, string label, IconStyle style)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_00ac: 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_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)