Decompiled source of WishDragon v0.1.9

WishDragon.dll

Decompiled 2 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 ExitGames.Client.Photon;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using Microsoft.CodeAnalysis;
using ModShared;
using Photon.Pun;
using Photon.Realtime;
using REPOLib.Modules;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
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("WishDragon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WishDragon")]
[assembly: AssemblyTitle("WishDragon")]
[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 ModShared
{
	internal static class ConfigSync
	{
		private const float Interval = 2f;

		private static ConfigFile _cfg;

		private static ManualLogSource _log;

		private static string _property;

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

		private static readonly Dictionary<ConfigDefinition, string> Own = new Dictionary<ConfigDefinition, string>();

		private static string _published;

		private static string _applied;

		internal static bool Overridden => Own.Count > 0;

		internal static float TickInterval => 2f;

		internal static event Action Changed;

		internal static void Init(ConfigFile cfg, string modName, ManualLogSource log, params string[] localKeys)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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_005a: Expected O, but got Unknown
			_cfg = cfg;
			_log = log;
			_property = modName + "_config";
			foreach (string item in localKeys)
			{
				LocalKeys.Add(item);
			}
			GameObject val = new GameObject(modName + "_ConfigSync")
			{
				hideFlags = (HideFlags)61
			};
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<ConfigSyncRunner>().Tick = Tick;
		}

		private static void Tick()
		{
			//IL_005a: 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_006b: Expected O, but got Unknown
			//IL_0072: Expected O, but got Unknown
			if (_cfg == null)
			{
				return;
			}
			if (!SemiFunc.IsMultiplayer() || !PhotonNetwork.InRoom || PhotonNetwork.CurrentRoom == null)
			{
				Restore();
				_published = null;
			}
			else if (PhotonNetwork.IsMasterClient)
			{
				Restore();
				string text = Serialize();
				if (!(text == _published))
				{
					_published = text;
					Room currentRoom = PhotonNetwork.CurrentRoom;
					Hashtable val = new Hashtable();
					((Dictionary<object, object>)val).Add((object)_property, (object)text);
					currentRoom.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
					_log.LogInfo((object)"Settings shared with the other players.");
				}
			}
			else
			{
				_published = null;
				if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)_property, out object value) && value is string text2 && !(text2 == _applied))
				{
					Apply(text2);
				}
			}
		}

		private static bool IsLocal(ConfigDefinition def)
		{
			return LocalKeys.Contains(def.Section + "|" + def.Key);
		}

		private static string Serialize()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (KeyValuePair<ConfigDefinition, ConfigEntryBase> item in _cfg)
			{
				if (!IsLocal(item.Key))
				{
					string text = item.Value.GetSerializedValue() ?? "";
					stringBuilder.Append(item.Key.Section).Append('\t').Append(item.Key.Key)
						.Append('\t')
						.Append(text.Replace("\n", " ").Replace("\t", " "))
						.Append('\n');
				}
			}
			return stringBuilder.ToString();
		}

		private static void Apply(string data)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			int num = 0;
			_cfg.SaveOnConfigSet = false;
			string[] array = data.Split('\n');
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split('\t');
				if (array2.Length < 3)
				{
					continue;
				}
				ConfigDefinition val = new ConfigDefinition(array2[0], array2[1]);
				if (IsLocal(val) || !_cfg.ContainsKey(val))
				{
					continue;
				}
				ConfigEntryBase val2 = _cfg[val];
				try
				{
					string serializedValue = val2.GetSerializedValue();
					if (!(serializedValue == array2[2]))
					{
						if (!Own.ContainsKey(val))
						{
							Own[val] = serializedValue;
						}
						val2.SetSerializedValue(array2[2]);
						num++;
					}
				}
				catch (Exception ex)
				{
					_log.LogDebug((object)("Host setting " + array2[0] + "." + array2[1] + " ignored: " + ex.Message));
				}
			}
			_applied = data;
			if (Own.Count == 0)
			{
				_cfg.SaveOnConfigSet = true;
			}
			_log.LogInfo((object)$"Using the host's settings ({num} value(s) differ from yours).");
			if (num > 0)
			{
				Notify();
			}
		}

		private static void Restore()
		{
			_applied = null;
			if (Own.Count == 0)
			{
				return;
			}
			foreach (KeyValuePair<ConfigDefinition, string> item in Own)
			{
				try
				{
					if (_cfg.ContainsKey(item.Key))
					{
						_cfg[item.Key].SetSerializedValue(item.Value);
					}
				}
				catch (Exception ex)
				{
					_log.LogDebug((object)("Could not restore " + item.Key.Section + "." + item.Key.Key + ": " + ex.Message));
				}
			}
			Own.Clear();
			_cfg.SaveOnConfigSet = true;
			_log.LogInfo((object)"Back to your own settings.");
			Notify();
		}

		private static void Notify()
		{
			try
			{
				ConfigSync.Changed?.Invoke();
			}
			catch (Exception arg)
			{
				_log.LogError((object)$"Applying changed settings failed: {arg}");
			}
		}
	}
	public class ConfigSyncRunner : MonoBehaviour
	{
		internal Action Tick;

		private float _timer;

		private void Update()
		{
			_timer -= Time.unscaledDeltaTime;
			if (_timer > 0f)
			{
				return;
			}
			_timer = ConfigSync.TickInterval;
			try
			{
				Tick?.Invoke();
			}
			catch (Exception)
			{
			}
		}
	}
	internal class MeshBuilder
	{
		private readonly List<Vector3> _verts = new List<Vector3>();

		private readonly List<Vector2> _uvs = new List<Vector2>();

		private readonly List<int> _tris = new List<int>();

		private readonly float _uvScale;

		public MeshBuilder(float uvScale = 1f)
		{
			_uvScale = uvScale;
		}

		public void Tri(Vector3 a, Vector3 b, Vector3 c, Vector3 outward)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//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_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0027: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.Cross(b - a, c - a);
			if (Vector3.Dot(val, outward) < 0f)
			{
				Vector3 val2 = b;
				b = c;
				c = val2;
				val = -val;
			}
			int count = _verts.Count;
			_verts.Add(a);
			_verts.Add(b);
			_verts.Add(c);
			_uvs.Add(Uv(a, val));
			_uvs.Add(Uv(b, val));
			_uvs.Add(Uv(c, val));
			_tris.Add(count);
			_tris.Add(count + 1);
			_tris.Add(count + 2);
		}

		public void Quad(Vector3 a, Vector3 b, Vector3 c, Vector3 d, Vector3 outward)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: 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)
			Tri(a, b, c, outward);
			Tri(a, c, d, outward);
		}

		private Vector2 Uv(Vector3 p, Vector3 n)
		{
			//IL_0000: 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_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_0047: 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_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0074: Unknown result type (might be due to invalid IL or missing references)
			float num = Mathf.Abs(n.x);
			float num2 = Mathf.Abs(n.y);
			float num3 = Mathf.Abs(n.z);
			Vector2 val = default(Vector2);
			if (num >= num2 && num >= num3)
			{
				((Vector2)(ref val))..ctor(p.z, p.y);
			}
			else if (num2 >= num3)
			{
				((Vector2)(ref val))..ctor(p.z, p.x);
			}
			else
			{
				((Vector2)(ref val))..ctor(p.x, p.y);
			}
			return val * _uvScale;
		}

		public Mesh ToMesh(string name)
		{
			//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_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: 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_0047: Expected O, but got Unknown
			Mesh val = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)32
			};
			val.SetVertices(_verts);
			val.SetUVs(0, _uvs);
			val.SetTriangles(_tris, 0);
			val.RecalculateNormals();
			val.RecalculateBounds();
			return val;
		}

		public static Vector3 Centroid(Vector3[] ring)
		{
			//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_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = Vector3.zero;
			foreach (Vector3 val2 in ring)
			{
				val += val2;
			}
			return val / (float)ring.Length;
		}

		public void Loft(Vector3[] a, Vector3[] b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: 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_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = (Centroid(a) + Centroid(b)) * 0.5f;
			for (int i = 0; i < a.Length; i++)
			{
				int num = (i + 1) % a.Length;
				Vector3 val2 = (a[i] + a[num] + b[num] + b[i]) * 0.25f;
				Quad(a[i], a[num], b[num], b[i], val2 - val);
			}
		}

		public void Cap(Vector3[] ring, Vector3 outward)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Vector3 a = Centroid(ring);
			for (int i = 0; i < ring.Length; i++)
			{
				Tri(a, ring[i], ring[(i + 1) % ring.Length], outward);
			}
		}

		public void Solid(Vector3[] back, Vector3[] front)
		{
			//IL_000a: 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)
			Loft(back, front);
			Cap(back, Vector3.back);
			Cap(front, Vector3.forward);
		}

		public static Vector3[] Circle(Vector2 center, float radius, float z, int segments, float startDeg = 0f)
		{
			//IL_0022: 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_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			Vector3[] array = (Vector3[])(object)new Vector3[segments];
			for (int i = 0; i < segments; i++)
			{
				float num = (startDeg + (float)i * 360f / (float)segments) * (MathF.PI / 180f);
				array[i] = new Vector3(center.x + Mathf.Cos(num) * radius, center.y + Mathf.Sin(num) * radius, z);
			}
			return array;
		}

		public void Annulus(Vector2 center, float rIn, float rOut, float z0, float z1, int segments)
		{
			//IL_0000: 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_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00aa: 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_00b5: 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_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_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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)
			Vector3[] array = Circle(center, rOut, z0, segments);
			Vector3[] array2 = Circle(center, rOut, z1, segments);
			Vector3[] array3 = Circle(center, rIn, z0, segments);
			Vector3[] array4 = Circle(center, rIn, z1, segments);
			Vector3 val = default(Vector3);
			((Vector3)(ref val))..ctor(center.x, center.y, 0f);
			for (int i = 0; i < segments; i++)
			{
				int num = (i + 1) % segments;
				Vector3 val2 = (array[i] + array[num]) * 0.5f - new Vector3(val.x, val.y, z0);
				Vector3 normalized = ((Vector3)(ref val2)).normalized;
				Quad(array[i], array[num], array2[num], array2[i], normalized);
				Quad(array3[i], array3[num], array4[num], array4[i], -normalized);
				Quad(array4[i], array4[num], array2[num], array2[i], Vector3.forward);
			}
		}
	}
	internal static class MeshTools
	{
		public static Mesh Sphere(float radius, int lon = 28, int lat = 18, string name = "Sphere")
		{
			//IL_0082: 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_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_015b: 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_016a: Expected O, but got Unknown
			List<Vector3> list = new List<Vector3>();
			List<Vector3> list2 = new List<Vector3>();
			List<Vector2> list3 = new List<Vector2>();
			List<int> list4 = new List<int>();
			Vector3 val = default(Vector3);
			for (int i = 0; i <= lat; i++)
			{
				float num = (float)i / (float)lat;
				float num2 = (num - 0.5f) * MathF.PI;
				for (int j = 0; j <= lon; j++)
				{
					float num3 = (float)j / (float)lon;
					float num4 = num3 * MathF.PI * 2f;
					((Vector3)(ref val))..ctor(Mathf.Cos(num2) * Mathf.Cos(num4), Mathf.Sin(num2), Mathf.Cos(num2) * Mathf.Sin(num4));
					list.Add(val * radius);
					list2.Add(val);
					list3.Add(new Vector2(num3, num));
				}
			}
			int num5 = lon + 1;
			for (int k = 0; k < lat; k++)
			{
				for (int l = 0; l < lon; l++)
				{
					int num6 = k * num5 + l;
					int item = num6 + 1;
					int num7 = num6 + num5;
					int item2 = num7 + 1;
					list4.Add(num6);
					list4.Add(num7);
					list4.Add(item);
					list4.Add(item);
					list4.Add(num7);
					list4.Add(item2);
				}
			}
			Mesh val2 = new Mesh
			{
				name = name,
				hideFlags = (HideFlags)32
			};
			val2.SetVertices(list);
			val2.SetNormals(list2);
			val2.SetUVs(0, list3);
			val2.SetTriangles(list4, 0);
			val2.RecalculateBounds();
			return val2;
		}

		public static GameObject AddPart(Transform parent, string name, Mesh mesh, Material material)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.transform.SetParent(parent, false);
			val.layer = ((Component)parent).gameObject.layer;
			val.AddComponent<MeshFilter>().sharedMesh = mesh;
			((Renderer)val.AddComponent<MeshRenderer>()).sharedMaterial = material;
			return val;
		}

		public static List<MeshFilter> FindVisualMeshes(Transform root)
		{
			List<MeshFilter> list = new List<MeshFilter>();
			MeshFilter[] componentsInChildren = ((Component)root).GetComponentsInChildren<MeshFilter>(true);
			foreach (MeshFilter val in componentsInChildren)
			{
				if (!((Object)(object)val.sharedMesh == (Object)null) && !((Object)(object)((Component)val).GetComponent<MeshRenderer>() == (Object)null) && !((Object)(object)((Component)val).GetComponentInParent<ItemVolume>(true) != (Object)null) && !((Object)(object)((Component)val).GetComponent<Collider>() != (Object)null) && !(((Object)val).name == "ItemEquipCube"))
				{
					list.Add(val);
				}
			}
			return list;
		}

		public static bool LocalBounds(Transform root, List<MeshFilter> meshes, out Bounds bounds)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_0067: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			bounds = default(Bounds);
			bool flag = false;
			foreach (MeshFilter mesh in meshes)
			{
				Bounds bounds2 = mesh.sharedMesh.bounds;
				for (int i = 0; i < 8; i++)
				{
					Vector3 val = ((Bounds)(ref bounds2)).center + Vector3.Scale(((Bounds)(ref bounds2)).extents, new Vector3((float)(((i & 1) != 0) ? 1 : (-1)), (float)(((i & 2) != 0) ? 1 : (-1)), (float)(((i & 4) != 0) ? 1 : (-1))));
					Vector3 val2 = root.InverseTransformPoint(((Component)mesh).transform.TransformPoint(val));
					if (!flag)
					{
						bounds = new Bounds(val2, Vector3.zero);
						flag = true;
					}
					else
					{
						((Bounds)(ref bounds)).Encapsulate(val2);
					}
				}
			}
			return flag;
		}
	}
	internal static class MaterialTools
	{
		public static Material Make(Material template, string name, Color baseColor, float metallic, float smoothness, Texture baseTex, Color emission, Texture emissionTex = null, Color? fresnel = null)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_0222: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0215: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			Material val = new Material(template)
			{
				name = name,
				hideFlags = (HideFlags)32
			};
			bool flag = ((Color)(ref emission)).maxColorComponent > 0.001f;
			Texture whiteTexture = (Texture)(object)Texture2D.whiteTexture;
			if (val.HasProperty("_BaseTexture"))
			{
				val.SetTexture("_BaseTexture", ((Object)(object)baseTex != (Object)null) ? baseTex : whiteTexture);
			}
			if (val.HasProperty("_BaseColor"))
			{
				val.SetColor("_BaseColor", baseColor);
			}
			string[] array = new string[2] { "_MetallicTexture", "_SmoothnessTexture" };
			foreach (string text in array)
			{
				if (val.HasProperty(text))
				{
					val.SetTexture(text, whiteTexture);
				}
			}
			if (val.HasProperty("_Metallic"))
			{
				val.SetFloat("_Metallic", metallic);
			}
			if (val.HasProperty("_Smoothness"))
			{
				val.SetFloat("_Smoothness", smoothness);
			}
			if (val.HasProperty("_NormalTexture"))
			{
				val.SetTexture("_NormalTexture", (Texture)null);
			}
			if (val.HasProperty("_NormalStrength"))
			{
				val.SetFloat("_NormalStrength", 0f);
			}
			array = new string[2] { "_TilingX", "_TilingY" };
			foreach (string text2 in array)
			{
				if (val.HasProperty(text2))
				{
					val.SetFloat(text2, 1f);
				}
			}
			array = new string[2] { "_OffsetX", "_OffsetY" };
			foreach (string text3 in array)
			{
				if (val.HasProperty(text3))
				{
					val.SetFloat(text3, 0f);
				}
			}
			if (val.HasProperty("_EmissionTexture"))
			{
				val.SetTexture("_EmissionTexture", (Texture)((!flag) ? ((object)Texture2D.blackTexture) : ((object)(((Object)(object)emissionTex != (Object)null) ? emissionTex : whiteTexture))));
			}
			if (val.HasProperty("_EmissionColor"))
			{
				val.SetColor("_EmissionColor", emission);
			}
			Color val2 = (Color)(((??)fresnel) ?? (flag ? emission : new Color(0.25f, 0.3f, 0.35f)));
			if (val.HasProperty("_FresnelColor"))
			{
				val.SetColor("_FresnelColor", val2);
			}
			if (val.HasProperty("_FresnelEmissionColor"))
			{
				val.SetColor("_FresnelEmissionColor", flag ? val2 : Color.black);
			}
			return val;
		}

		public static Material FindTemplate()
		{
			GameObject val = Resources.Load<GameObject>("Items/Item Melee Sword");
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform val2 = val.transform.Find("Mesh Healthy");
			MeshRenderer val3 = (((Object)(object)val2 != (Object)null) ? ((Component)val2).GetComponentInChildren<MeshRenderer>(true) : null);
			if ((Object)(object)val3 == (Object)null)
			{
				using List<MeshFilter>.Enumerator enumerator = MeshTools.FindVisualMeshes(val.transform).GetEnumerator();
				if (enumerator.MoveNext())
				{
					val3 = ((Component)enumerator.Current).GetComponent<MeshRenderer>();
				}
			}
			if (!((Object)(object)val3 != (Object)null))
			{
				return null;
			}
			return ((Renderer)val3).sharedMaterial;
		}
	}
}
namespace WishDragon
{
	internal enum AbilityId
	{
		Beam,
		PowerForm,
		EraseOrb,
		ChocolateBeam
	}
	internal class AbilityConfig
	{
		public AbilityId Id;

		public ConfigEntry<string> Name;

		public ConfigEntry<float> ChargeTime;

		public ConfigEntry<float> Cooldown;

		public ConfigEntry<string> ChargeShout;

		public ConfigEntry<string> FireShout;

		public ConfigEntry<Color> Color;

		public float CooldownLeft;

		public static AbilityConfig Bind(ConfigFile cfg, AbilityId id, string section, string name, float charge, float cooldown, string chargeShout, string fireShout, Color color)
		{
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			return new AbilityConfig
			{
				Id = id,
				Name = cfg.Bind<string>(section, "Name", name, "Name of the ability. Rename it to anything you like, for example your favorite move."),
				ChargeTime = cfg.Bind<float>(section, "ChargeTime", charge, new ConfigDescription("Seconds the key must be held.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 3.5f), Array.Empty<object>())),
				Cooldown = cfg.Bind<float>(section, "Cooldown", cooldown, new ConfigDescription("Seconds before the ability can be used again.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 600f), Array.Empty<object>())),
				ChargeShout = cfg.Bind<string>(section, "ChargeShout", chargeShout, "What your character says while charging. Write anything you like. Parts separated by '-' are said one by one. Empty = silence."),
				FireShout = cfg.Bind<string>(section, "FireShout", fireShout, "What your character says when the ability is used. Empty = silence."),
				Color = cfg.Bind<Color>(section, "Color", color, "Color of the effect.")
			};
		}
	}
	internal static class Abilities
	{
		internal struct Target
		{
			public EnemyParent Parent;

			public Enemy Enemy;

			public EnemyHealth Health;

			public Vector3 Position;
		}

		private const byte EventCode = 144;

		private const int KindCharge = 0;

		private const int KindCancel = 1;

		private const int KindUse = 2;

		internal static readonly Dictionary<AbilityId, AbilityConfig> Configs = new Dictionary<AbilityId, AbilityConfig>();

		internal static int LocalAbility = -1;

		private static readonly Dictionary<Color, Material> GlowMaterials = new Dictionary<Color, Material>();

		private static readonly FieldRef<EnemyParent, Enemy> ParentEnemy = AccessTools.FieldRefAccess<EnemyParent, Enemy>("Enemy");

		private static readonly FieldRef<Enemy, EnemyHealth> EnemyHealthRef = AccessTools.FieldRefAccess<Enemy, EnemyHealth>("Health");

		private static readonly FieldRef<PlayerAvatar, bool> DeadSet = AccessTools.FieldRefAccess<PlayerAvatar, bool>("deadSet");

		internal static AbilityConfig Get(AbilityId id)
		{
			return Configs[id];
		}

		internal static bool Has(AbilityId id)
		{
			return LocalAbility == (int)id;
		}

		internal static int ReadLocalAbility()
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			if (!((Object)(object)instance != (Object)null))
			{
				return -1;
			}
			return State.AbilityOf(SemiFunc.PlayerGetSteamID(instance));
		}

		internal static void Grant(AbilityId id, PlayerAvatar who)
		{
			if ((Object)(object)who == (Object)null)
			{
				Plugin.Log.LogWarning((object)"Ability wish: could not tell who made the wish, nobody got the ability.");
			}
			else
			{
				State.SetAbility(SemiFunc.PlayerGetSteamID(who), (int)id);
			}
		}

		internal static string Name(AbilityId id)
		{
			return Get(id).Name.Value;
		}

		internal static string KeyHint(AbilityId id)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return $"hold [{Plugin.AbilityKey.Value}], then release";
		}

		internal static void RegisterNetwork()
		{
			PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
		}

		private static void OnEvent(EventData data)
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			if (data.Code != 144)
			{
				return;
			}
			try
			{
				if (data.CustomData is object[] array && array.Length >= 5)
				{
					Dispatch((int)array[0], (AbilityId)(int)array[1], (int)array[2], (Vector3)array[3], (Vector3)array[4]);
				}
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Ability event failed: {arg}");
			}
		}

		private static void Send(int kind, AbilityId id, int viewId, Vector3 origin, Vector3 dir)
		{
			//IL_0062: 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)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: 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_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			if (SemiFunc.IsMultiplayer() && PhotonNetwork.InRoom)
			{
				PhotonNetwork.RaiseEvent((byte)144, (object)new object[5]
				{
					kind,
					(int)id,
					viewId,
					origin,
					dir
				}, new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)1
				}, SendOptions.SendReliable);
			}
			else
			{
				Dispatch(kind, id, viewId, origin, dir);
			}
		}

		internal static void SendCharge(AbilityId id, int viewId)
		{
			//IL_0003: 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)
			Send(0, id, viewId, Vector3.zero, Vector3.zero);
		}

		internal static void SendCancel(AbilityId id, int viewId)
		{
			//IL_0003: 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)
			Send(1, id, viewId, Vector3.zero, Vector3.zero);
		}

		internal static void SendUse(AbilityId id, int viewId, Vector3 origin, Vector3 dir)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			Send(2, id, viewId, origin, dir);
		}

		private static void Dispatch(int kind, AbilityId id, int viewId, Vector3 origin, Vector3 dir)
		{
			//IL_0023: 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)
			//IL_0033: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			if (!Configs.TryGetValue(id, out var value) || (Object)(object)Plugin.Template == (Object)null)
			{
				return;
			}
			Color value2 = value.Color.Value;
			ChargeFx.Stop(viewId);
			switch (kind)
			{
			case 0:
				ChargeFx.Start(viewId, value2, value.ChargeTime.Value, id == AbilityId.PowerForm);
				break;
			case 2:
				switch (id)
				{
				case AbilityId.Beam:
					BeamFx.Fire(viewId, origin, dir, value2, chocolate: false);
					break;
				case AbilityId.ChocolateBeam:
					BeamFx.Fire(viewId, origin, dir, value2, chocolate: true);
					break;
				case AbilityId.PowerForm:
					PowerForm.Activate(viewId, value2);
					break;
				case AbilityId.EraseOrb:
					EraseOrb.Activate(viewId, origin, dir);
					break;
				}
				break;
			}
		}

		internal static Material Glow(Color c)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: 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_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			if (!GlowMaterials.TryGetValue(c, out var value) || (Object)(object)value == (Object)null)
			{
				value = MaterialTools.Make(Plugin.Template, "Ability Glow", Color.Lerp(c, Color.white, 0.6f), 0f, 0.3f, null, c * 4f, null, c);
				GlowMaterials[c] = value;
			}
			return value;
		}

		internal static Light AddLight(Transform parent, Color color, float range, float intensity)
		{
			//IL_0005: 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)
			Light obj = new GameObject("Light").AddComponent<Light>();
			((Component)obj).transform.SetParent(parent, false);
			obj.type = (LightType)2;
			obj.color = color;
			obj.range = range;
			obj.intensity = intensity;
			obj.shadows = (LightShadows)0;
			return obj;
		}

		internal static void Aim(PlayerAvatar player, out Vector3 origin, out Vector3 dir)
		{
			//IL_0023: 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)
			//IL_0034: 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_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: 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_00bd: 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)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)player == (Object)(object)PlayerAvatar.instance && (Object)(object)main != (Object)null)
			{
				dir = ((Component)main).transform.forward;
				origin = ((Component)main).transform.position + dir * 0.7f - ((Component)main).transform.up * 0.25f;
			}
			else
			{
				Transform val = (((Object)(object)player.playerTransform != (Object)null) ? player.playerTransform : ((Component)player).transform);
				dir = val.forward;
				origin = val.position + Vector3.up * 0.9f + dir * 0.6f;
			}
		}

		internal static Vector3 Center(PlayerAvatar player)
		{
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			return (((Object)(object)player.playerTransform != (Object)null) ? player.playerTransform : ((Component)player).transform).position + Vector3.up * 0.7f;
		}

		internal static List<Target> Enemies()
		{
			//IL_00bc: 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_00c1: Unknown result type (might be due to invalid IL or missing references)
			List<Target> list = new List<Target>();
			if ((Object)(object)EnemyDirector.instance == (Object)null || EnemyDirector.instance.enemiesSpawned == null)
			{
				return list;
			}
			foreach (EnemyParent item in EnemyDirector.instance.enemiesSpawned)
			{
				if (!((Object)(object)item == (Object)null))
				{
					Enemy val = ParentEnemy.Invoke(item);
					if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeInHierarchy)
					{
						list.Add(new Target
						{
							Parent = item,
							Enemy = val,
							Health = EnemyHealthRef.Invoke(val),
							Position = (((Object)(object)val.CenterTransform != (Object)null) ? val.CenterTransform.position : ((Component)val).transform.position)
						});
					}
				}
			}
			return list;
		}

		internal static List<PlayerAvatar> OtherPlayers(PlayerAvatar except)
		{
			List<PlayerAvatar> list = new List<PlayerAvatar>();
			foreach (PlayerAvatar item in SemiFunc.PlayerGetAll())
			{
				if ((Object)(object)item != (Object)null && (Object)(object)item != (Object)(object)except && !DeadSet.Invoke(item))
				{
					list.Add(item);
				}
			}
			return list;
		}

		internal static void KillPlayer(PlayerAvatar player)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)player == (Object)null) && !((Object)(object)player.playerHealth == (Object)null))
			{
				player.playerHealth.HurtOther(999999, Center(player), false, -1, false);
			}
		}
	}
	public class AbilityController : MonoBehaviour
	{
		internal const float MaxHold = 4f;

		private const int Unknown = -2;

		private int _known = -2;

		private float _pollTimer;

		private AbilityConfig _active;

		private float _charge;

		private string[] _shoutParts = new string[0];

		private int _shoutIndex;

		private bool _inLevel;

		private int _viewId;

		private GUIStyle _hudStyle;

		private static Texture2D _white;

		private void Update()
		{
			try
			{
				Tick();
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Ability update failed: " + ex.Message));
			}
		}

		private void Tick()
		{
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bd: 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)
			foreach (AbilityConfig value in Abilities.Configs.Values)
			{
				if (value.CooldownLeft > 0f)
				{
					value.CooldownLeft -= Time.deltaTime;
				}
			}
			PlayerAvatar instance = PlayerAvatar.instance;
			bool flag = (Object)(object)instance != (Object)null && (Object)(object)LevelGenerator.Instance != (Object)null && LevelGenerator.Instance.Generated && SemiFunc.RunIsLevel();
			int viewId = (((Object)(object)instance != (Object)null && (Object)(object)instance.photonView != (Object)null) ? instance.photonView.ViewID : 0);
			if ((Object)(object)instance == (Object)null)
			{
				_known = -2;
				Abilities.LocalAbility = -1;
			}
			else
			{
				_pollTimer -= Time.deltaTime;
				if (_pollTimer <= 0f)
				{
					_pollTimer = 0.5f;
					Announce();
				}
			}
			_inLevel = flag;
			_viewId = viewId;
			if (!flag)
			{
				if (_active != null && (Object)(object)instance != (Object)null)
				{
					Abilities.SendCancel(_active.Id, viewId);
				}
				_active = null;
				return;
			}
			bool flag2 = !SemiFunc.IsSpectating() && SemiFunc.NoTextInputsActive() && !WishMenu.IsOpen && Keyboard.current != null;
			if (_active == null)
			{
				if (!flag2)
				{
					return;
				}
				{
					foreach (AbilityConfig value2 in Abilities.Configs.Values)
					{
						if (Abilities.Has(value2.Id) && !(value2.CooldownLeft > 0f) && ((ButtonControl)Keyboard.current[Plugin.AbilityKey.Value]).isPressed)
						{
							_active = value2;
							_charge = 0f;
							Abilities.SendCharge(value2.Id, viewId);
							_shoutParts = (value2.ChargeShout.Value ?? "").Split(new char[1] { '-' }, StringSplitOptions.RemoveEmptyEntries);
							_shoutIndex = 0;
							SayNextPart(instance);
							break;
						}
					}
					return;
				}
			}
			AbilityConfig active = _active;
			bool num = flag2 && ((ButtonControl)Keyboard.current[Plugin.AbilityKey.Value]).isPressed;
			_charge += Time.deltaTime;
			SayNextPart(instance);
			bool flag3 = _charge >= active.ChargeTime.Value;
			if (!num || !(_charge < 4f))
			{
				_active = null;
				if (flag3 && flag2)
				{
					Abilities.Aim(instance, out var origin, out var dir);
					Abilities.SendUse(active.Id, viewId, origin, dir);
					Shout(instance, active.FireShout.Value);
					active.CooldownLeft = active.Cooldown.Value;
				}
				else
				{
					Abilities.SendCancel(active.Id, viewId);
					active.CooldownLeft = 0.5f;
				}
			}
		}

		private void OnGUI()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Invalid comparison between Unknown and I4
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: 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)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0255: Unknown result type (might be due to invalid IL or missing references)
			//IL_026e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0318: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_03c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_03d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0217: Unknown result type (might be due to invalid IL or missing references)
			//IL_021c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0236: Expected O, but got Unknown
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			if (!_inLevel || !Plugin.ShowHud.Value || (int)Event.current.type != 7)
			{
				return;
			}
			int localAbility = Abilities.LocalAbility;
			if (localAbility >= 0 && Abilities.Configs.TryGetValue((AbilityId)localAbility, out var value) && !WishMenu.IsOpen && !SemiFunc.IsSpectating())
			{
				float num = ((value.Id == AbilityId.PowerForm) ? PowerForm.Remaining(_viewId) : 0f);
				float value2 = Plugin.PowerDuration.Value;
				Color val = value.Color.Value;
				float num2;
				string status;
				if (_active == value)
				{
					num2 = Mathf.Clamp01(_charge / Mathf.Max(0.1f, value.ChargeTime.Value));
					status = ((num2 >= 1f) ? "RELEASE!" : "CHARGING");
					val = Color.Lerp(val, Color.white, (num2 >= 1f) ? 0.6f : 0.2f);
				}
				else if (num > 0f)
				{
					num2 = Mathf.Clamp01(num / Mathf.Max(0.1f, value2));
					status = $"ACTIVE {Mathf.CeilToInt(num)}s";
				}
				else if (value.CooldownLeft > 0f)
				{
					num2 = 1f - Mathf.Clamp01(value.CooldownLeft / Mathf.Max(0.1f, value.Cooldown.Value));
					status = $"{Mathf.CeilToInt(value.CooldownLeft)}s";
					((Color)(ref val))..ctor(0.55f, 0.55f, 0.6f, 1f);
				}
				else
				{
					num2 = 1f;
					status = "READY";
				}
				float num3 = (float)Screen.height / 1080f;
				float num4 = 340f * num3;
				float num5 = 54f * num3;
				Rect val2 = default(Rect);
				((Rect)(ref val2))..ctor((float)Screen.width - num4 - 28f * num3, (float)Screen.height - num5 - 28f * num3, num4, num5);
				if ((Object)(object)_white == (Object)null)
				{
					_white = Texture2D.whiteTexture;
				}
				if (_hudStyle == null)
				{
					_hudStyle = new GUIStyle(GUI.skin.label)
					{
						alignment = (TextAnchor)4,
						fontStyle = (FontStyle)1,
						richText = false
					};
				}
				_hudStyle.fontSize = Mathf.Max(10, Mathf.RoundToInt(19f * num3));
				Color color = GUI.color;
				GUI.color = new Color(0f, 0f, 0f, 0.55f);
				GUI.DrawTexture(val2, (Texture)(object)_white);
				float num6 = 6f * num3;
				float num7 = 9f * num3;
				Rect val3 = default(Rect);
				((Rect)(ref val3))..ctor(((Rect)(ref val2)).x + num6, ((Rect)(ref val2)).yMax - num6 - num7, ((Rect)(ref val2)).width - num6 * 2f, num7);
				GUI.color = new Color(1f, 1f, 1f, 0.15f);
				GUI.DrawTexture(val3, (Texture)(object)_white);
				GUI.color = val;
				GUI.DrawTexture(new Rect(((Rect)(ref val3)).x, ((Rect)(ref val3)).y, ((Rect)(ref val3)).width * num2, ((Rect)(ref val3)).height), (Texture)(object)_white);
				Rect val4 = default(Rect);
				((Rect)(ref val4))..ctor(((Rect)(ref val2)).x, ((Rect)(ref val2)).y + 2f * num3, ((Rect)(ref val2)).width, ((Rect)(ref val2)).height - num7 - num6);
				GUI.color = new Color(0f, 0f, 0f, 0.9f);
				GUI.Label(new Rect(((Rect)(ref val4)).x + 1.5f * num3, ((Rect)(ref val4)).y + 1.5f * num3, ((Rect)(ref val4)).width, ((Rect)(ref val4)).height), Label(value, status), _hudStyle);
				GUI.color = Color.Lerp(val, Color.white, 0.35f);
				GUI.Label(val4, Label(value, status), _hudStyle);
				GUI.color = color;
			}
		}

		private static string Label(AbilityConfig cfg, string status)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			return $"[{Plugin.AbilityKey.Value}] {cfg.Name.Value}  -  {status}";
		}

		private void SayNextPart(PlayerAvatar me)
		{
			if (_active != null && _shoutIndex < _shoutParts.Length)
			{
				float num = _active.ChargeTime.Value / (float)_shoutParts.Length;
				if (!(_charge < (float)_shoutIndex * num))
				{
					Shout(me, _shoutParts[_shoutIndex].Trim());
					_shoutIndex++;
				}
			}
		}

		private static void Shout(PlayerAvatar me, string text)
		{
			if ((Object)(object)me == (Object)null || string.IsNullOrWhiteSpace(text))
			{
				return;
			}
			try
			{
				me.ChatMessageSend(text, "");
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Shout failed: " + ex.Message));
			}
		}

		private void Announce()
		{
			//IL_0067: 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_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)
			int num = (Abilities.LocalAbility = Abilities.ReadLocalAbility());
			if (_known == -2)
			{
				_known = num;
			}
			else if (num != _known)
			{
				_known = num;
				if (num >= 0 && Abilities.Configs.ContainsKey((AbilityId)num))
				{
					AbilityId id = (AbilityId)num;
					SemiFunc.UIBigMessage("NEW ABILITY: " + Abilities.Name(id).ToUpperInvariant(), "{!}", 25f, Plugin.DragonAccent.Value, Color.white);
					SemiFunc.UIFocusText(Abilities.Name(id) + ": " + Abilities.KeyHint(id), Plugin.DragonAccent.Value, Color.white, 8f);
				}
			}
		}
	}
	public class ChargeFx : MonoBehaviour
	{
		private static readonly Dictionary<int, GameObject> Active = new Dictionary<int, GameObject>();

		private PlayerAvatar _player;

		private Light _light;

		private float _chargeTime;

		private bool _aroundBody;

		private float _age;

		internal static void Start(int viewId, Color color, float chargeTime, bool aroundBody)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			if (!((Object)(object)val == (Object)null))
			{
				GameObject val2 = new GameObject("Ability Charge");
				MeshTools.AddPart(val2.transform, "Ball", Plugin.UnitSphere, Abilities.Glow(color));
				ChargeFx chargeFx = val2.AddComponent<ChargeFx>();
				chargeFx._player = val;
				chargeFx._light = Abilities.AddLight(val2.transform, color, 2f, 0.5f);
				chargeFx._chargeTime = Mathf.Max(0.1f, chargeTime);
				chargeFx._aroundBody = aroundBody;
				Sfx.Attach(val2, Sfx.Charge, 0.6f, 25f);
				Active[viewId] = val2;
			}
		}

		internal static void Stop(int viewId)
		{
			if (Active.TryGetValue(viewId, out var value) && (Object)(object)value != (Object)null)
			{
				Object.Destroy((Object)(object)value);
			}
			Active.Remove(viewId);
		}

		private void Update()
		{
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: 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_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)_player == (Object)null)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			_age += Time.deltaTime;
			if (_age > 5f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float num = Mathf.Clamp01(_age / _chargeTime);
			float num2 = 1f + 0.12f * Mathf.Sin(_age * Mathf.Lerp(10f, 40f, num));
			if (_aroundBody)
			{
				Transform val = (((Object)(object)_player.playerTransform != (Object)null) ? _player.playerTransform : ((Component)_player).transform);
				((Component)this).transform.position = val.position + Vector3.up * 0.1f;
				((Component)this).transform.localScale = new Vector3(1f, 0.15f, 1f) * Mathf.Lerp(0.3f, 1.6f, num) * num2;
			}
			else
			{
				Abilities.Aim(_player, out var origin, out var _);
				((Component)this).transform.position = origin;
				((Component)this).transform.localScale = Vector3.one * Mathf.Lerp(0.06f, 0.38f, num) * num2;
			}
			_light.range = Mathf.Lerp(2f, 6f, num);
			_light.intensity = Mathf.Lerp(0.5f, 3.5f, num) * num2;
		}
	}
	internal static class BeamFx
	{
		private static Mesh _beamMesh;

		internal static void Fire(int viewId, Vector3 origin, Vector3 dir, Color color, bool chocolate)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: 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_000b: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: 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_0101: Expected O, but got Unknown
			//IL_0108: 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_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_0310: Unknown result type (might be due to invalid IL or missing references)
			//IL_0315: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_032d: Unknown result type (might be due to invalid IL or missing references)
			if (((Vector3)(ref dir)).sqrMagnitude < 0.0001f)
			{
				return;
			}
			((Vector3)(ref dir)).Normalize();
			float length;
			float num = (length = Plugin.BeamRange.Value);
			RaycastHit val = default(RaycastHit);
			if (Physics.Raycast(origin, dir, ref val, num, LayerMask.op_Implicit(SemiFunc.LayerMaskGetVisionObstruct()), (QueryTriggerInteraction)1))
			{
				length = ((RaycastHit)(ref val)).distance;
			}
			float width = Plugin.BeamWidth.Value * (chocolate ? 0.6f : 1f);
			if ((Object)(object)_beamMesh == (Object)null)
			{
				MeshBuilder meshBuilder = new MeshBuilder();
				meshBuilder.Solid(MeshBuilder.Circle(Vector2.zero, 0.5f, 0f, 12), MeshBuilder.Circle(Vector2.zero, 0.5f, 1f, 12));
				_beamMesh = meshBuilder.ToMesh("Ability Beam");
			}
			GameObject val2 = new GameObject("Ability Beam");
			val2.transform.SetPositionAndRotation(origin, Quaternion.LookRotation(dir, Vector3.up));
			Material material = Abilities.Glow(color);
			BeamVisual beamVisual = val2.AddComponent<BeamVisual>();
			beamVisual.Length = length;
			beamVisual.Width = width;
			beamVisual.Body = MeshTools.AddPart(val2.transform, "Body", _beamMesh, material).transform;
			beamVisual.Head = MeshTools.AddPart(val2.transform, "Head", Plugin.UnitSphere, material).transform;
			beamVisual.Tail = MeshTools.AddPart(val2.transform, "Tail", Plugin.UnitSphere, material).transform;
			beamVisual.Tail.localPosition = new Vector3(0f, 0f, length);
			Abilities.AddLight(beamVisual.Head, color, 9f, 4f);
			Abilities.AddLight(beamVisual.Tail, color, 9f, 4f);
			Sfx.Attach(val2, Sfx.Blast, 0.8f, 45f);
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			PlayerAvatar val3 = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			int num2 = 0;
			int num3 = ((!chocolate) ? Damage(val3, viewId) : 0);
			foreach (Abilities.Target item in Abilities.Enemies())
			{
				if (!InBeam(item.Position, 1f))
				{
					continue;
				}
				num2++;
				if (!chocolate)
				{
					if ((Object)(object)item.Health != (Object)null)
					{
						item.Health.Hurt(num3, dir);
					}
				}
				else
				{
					Chocolate.Spawn(item.Position);
					item.Parent.Despawn();
					item.Parent.DespawnedTimerSet(Plugin.ChocolateEnemyAway.Value, false);
				}
			}
			if (chocolate && Plugin.ChocolateHitsPlayers.Value && (Object)(object)val3 != (Object)null)
			{
				foreach (PlayerAvatar item2 in Abilities.OtherPlayers(val3))
				{
					Vector3 val4 = Abilities.Center(item2);
					if (InBeam(val4, 0.5f))
					{
						num2++;
						Chocolate.Spawn(val4);
						Abilities.KillPlayer(item2);
					}
				}
			}
			Plugin.Log.LogInfo((object)(chocolate ? $"Chocolate beam fired: {num2} target(s) turned into chocolate." : $"Beam fired: {num3} damage, {num2} enemy hit(s), length {length:F1} m."));
			bool InBeam(Vector3 p, float extra)
			{
				//IL_0000: Unknown result type (might be due to invalid IL or missing references)
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: 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)
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: 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)
				float num4 = Mathf.Clamp(Vector3.Dot(p - origin, dir), 0f, length);
				return Vector3.Distance(p, origin + dir * num4) <= width * 0.5f + extra;
			}
		}

		private static int Damage(PlayerAvatar shooter, int viewId)
		{
			int num = 0;
			try
			{
				string text = (((Object)(object)shooter != (Object)null) ? SemiFunc.PlayerGetSteamID(shooter) : null);
				if (text != null && (Object)(object)StatsManager.instance != (Object)null && StatsManager.instance.playerUpgradeStrength.TryGetValue(text, out var value))
				{
					num = value;
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Strength lookup failed: " + ex.Message));
			}
			if (PowerForm.IsActive(viewId))
			{
				num += Plugin.PowerMultiplier.Value;
			}
			return Plugin.BeamDamage.Value + Plugin.BeamDamagePerStrength.Value * num;
		}
	}
	public class BeamVisual : MonoBehaviour
	{
		internal float Length;

		internal float Width;

		internal Transform Body;

		internal Transform Head;

		internal Transform Tail;

		private float _age;

		private const float Life = 1.1f;

		private void Update()
		{
			//IL_008d: 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_00ad: 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_00c3: 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)
			_age += Time.deltaTime;
			if (_age >= 1.1f)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			float num = _age / 1.1f;
			float num2 = Mathf.Clamp01(num * 12f) * Mathf.Clamp01((1f - num) * 2.5f);
			float num3 = Width * num2 * (1f + 0.08f * Mathf.Sin(_age * 60f));
			Body.localScale = new Vector3(num3, num3, Length);
			Head.localScale = Vector3.one * num3 * 1.5f;
			Tail.localScale = Vector3.one * num3 * 2.2f;
		}
	}
	public class PowerForm : MonoBehaviour
	{
		private static readonly Dictionary<int, PowerForm> Active = new Dictionary<int, PowerForm>();

		private static readonly FieldRef<PlayerHealth, int> Health = AccessTools.FieldRefAccess<PlayerHealth, int>("health");

		private static readonly FieldRef<PlayerHealth, int> MaxHealth = AccessTools.FieldRefAccess<PlayerHealth, int>("maxHealth");

		private const int Shards = 10;

		private int _viewId;

		private PlayerAvatar _player;

		private float _left;

		private int _multiplier;

		private int _originalMax;

		private bool _healthBoosted;

		private Transform[] _shards;

		private Light _light;

		internal static bool IsActive(int viewId)
		{
			if (Active.TryGetValue(viewId, out var value))
			{
				return (Object)(object)value != (Object)null;
			}
			return false;
		}

		internal static float Remaining(int viewId)
		{
			if (!Active.TryGetValue(viewId, out var value) || !((Object)(object)value != (Object)null))
			{
				return 0f;
			}
			return Mathf.Max(0f, value._left);
		}

		internal static void Activate(int viewId, Color color)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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)
			PlayerAvatar val = SemiFunc.PlayerAvatarGetFromPhotonID(viewId);
			if (!((Object)(object)val == (Object)null))
			{
				if (Active.TryGetValue(viewId, out var value) && (Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
				GameObject val2 = new GameObject("Power Form");
				PowerForm powerForm = val2.AddComponent<PowerForm>();
				powerForm._viewId = viewId;
				powerForm._player = val;
				powerForm._left = Plugin.PowerDuration.Value;
				powerForm._multiplier = Mathf.Max(1, Plugin.PowerMultiplier.Value);
				Material material = Abilities.Glow(color);
				powerForm._shards = (Transform[])(object)new Transform[10];
				for (int i = 0; i < 10; i++)
				{
					Transform transform = MeshTools.AddPart(val2.transform, "Shard", Plugin.UnitSphere, material).transform;
					transform.localScale = new Vector3(0.07f, 0.32f, 0.07f);
					powerForm._shards[i] = transform;
				}
				powerForm._light = Abilities.AddLight(val2.transform, color, 6f, 3f);
				((Component)powerForm._light).transform.localPosition = Vector3.up * 0.8f;
				Sfx.Attach(val2, Sfx.Blast, 0.6f, 35f);
				Active[viewId] = powerForm;
				powerForm.BoostHealth();
			}
		}

		private void BoostHealth()
		{
			if ((Object)(object)_player != (Object)(object)PlayerAvatar.instance || (Object)(object)_player.playerHealth == (Object)null)
			{
				return;
			}
			try
			{
				PlayerHealth playerHealth = _player.playerHealth;
				_originalMax = MaxHealth.Invoke(playerHealth);
				MaxHealth.Invoke(playerHealth) = _originalMax * _multiplier;
				Health.Invoke(playerHealth) = Health.Invoke(playerHealth) * _multiplier;
				_healthBoosted = true;
				SyncHealth(playerHealth);
				Plugin.Log.LogInfo((object)$"Power form on: health {Health.Invoke(playerHealth)}/{MaxHealth.Invoke(playerHealth)}.");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Power form health boost failed: {arg}");
			}
		}

		private void RestoreHealth()
		{
			if (!_healthBoosted || (Object)(object)_player == (Object)null || (Object)(object)_player.playerHealth == (Object)null)
			{
				return;
			}
			_healthBoosted = false;
			try
			{
				PlayerHealth playerHealth = _player.playerHealth;
				int num = Health.Invoke(playerHealth);
				MaxHealth.Invoke(playerHealth) = _originalMax;
				Health.Invoke(playerHealth) = ((num > 0) ? Mathf.Clamp(Mathf.CeilToInt((float)num / (float)_multiplier), 1, _originalMax) : 0);
				SyncHealth(playerHealth);
				Plugin.Log.LogInfo((object)$"Power form off: health {Health.Invoke(playerHealth)}/{MaxHealth.Invoke(playerHealth)}.");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Power form health restore failed: {arg}");
			}
		}

		private static void SyncHealth(PlayerHealth ph)
		{
			if (SemiFunc.IsMultiplayer())
			{
				PhotonView component = ((Component)ph).GetComponent<PhotonView>();
				if ((Object)(object)component != (Object)null)
				{
					component.RPC("UpdateHealthRPC", (RpcTarget)1, new object[4]
					{
						Health.Invoke(ph),
						MaxHealth.Invoke(ph),
						true,
						false
					});
				}
			}
		}

		private void Update()
		{
			//IL_0073: 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_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0164: Unknown result type (might be due to invalid IL or missing references)
			_left -= Time.deltaTime;
			if ((Object)(object)_player == (Object)null || _left <= 0f || !SemiFunc.RunIsLevel())
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Transform val = (((Object)(object)_player.playerTransform != (Object)null) ? _player.playerTransform : ((Component)_player).transform);
			((Component)this).transform.position = val.position;
			if ((Object)(object)_player.physGrabber != (Object)null)
			{
				_player.physGrabber.OverrideGrabStrength(Mathf.Max(1f, _player.physGrabber.grabStrength) * (float)_multiplier, 0.25f);
			}
			float time = Time.time;
			for (int i = 0; i < 10; i++)
			{
				float num = (time * 0.9f + (float)i / 10f) % 1f;
				float num2 = (float)i * 2.4f + time * 1.5f;
				float num3 = Mathf.Lerp(0.55f, 0.3f, num);
				_shards[i].localPosition = new Vector3(Mathf.Cos(num2) * num3, num * 1.7f, Mathf.Sin(num2) * num3);
				_shards[i].localScale = new Vector3(0.07f, 0.32f, 0.07f) * Mathf.Sin(num * MathF.PI);
			}
			if ((Object)(object)_light != (Object)null)
			{
				_light.intensity = 2.5f + Mathf.Sin(time * 14f) * 0.6f;
			}
		}

		private void OnDestroy()
		{
			RestoreHealth();
			if (Active.TryGetValue(_viewId, out var value) && (Object)(object)value == (Object)(object)this)
			{
				Active.Remove(_viewId);
			}
		}
	}
	public class EraseOrb : MonoBehaviour
	{
		private static readonly Dictionary<int, EraseOrb> Active = new Dictionary<int, EraseOrb>();

		private static PrefabRef _prefabRef;

		private int _ownerId;

		private bool _registered;

		private PlayerAvatar _owner;

		private float _ownerTimer;

		private PhysGrabObject _grab;

		private ItemEquippable _equip;

		private PhotonView _view;

		private Transform _core;

		private Vector3 _coreScale;

		private Light _light;

		private float _checkTimer;

		private float _age;

		private float _hintTime;

		private readonly Dictionary<int, float> _erased = new Dictionary<int, float>();

		internal static Sprite Icon;

		private static readonly FieldInfo EquipState = AccessTools.Field(typeof(ItemEquippable), "currentState");

		private Renderer _coreRenderer;

		private bool _wasHidden;

		private bool _vanished;

		internal static void CreatePrefab(GameObject vanilla, Transform holder)
		{
			//IL_0019: 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_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: 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_0164: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0181: Unknown result type (might be due to invalid IL or missing references)
			//IL_0188: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b6: 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_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02af: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(vanilla, holder);
			((Object)val).name = "Item Star Orb Erase";
			val.transform.localPosition = Vector3.zero;
			val.transform.localRotation = Quaternion.identity;
			ItemAttributes component = val.GetComponent<ItemAttributes>();
			if ((Object)(object)component == (Object)null || (Object)(object)component.item == (Object)null)
			{
				return;
			}
			Item val2 = Object.Instantiate<Item>(component.item);
			((Object)val2).name = ((Object)val).name;
			val2.itemName = Abilities.Name(AbilityId.EraseOrb);
			val2.itemNameLocalized = null;
			val2.description = "Erases anything living it touches. Only the one who summoned it can hold it.";
			val2.itemType = (itemType)13;
			val2.maxAmountInShop = 0;
			val2.maxPurchase = true;
			val2.maxPurchaseAmount = 0;
			component.item = val2;
			PhysGrabObjectImpactDetector component2 = val.GetComponent<PhysGrabObjectImpactDetector>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.destroyDisable = true;
			}
			List<MeshFilter> list = MeshTools.FindVisualMeshes(val.transform);
			Vector3 val3 = Vector3.zero;
			if (MeshTools.LocalBounds(val.transform, list, out var bounds))
			{
				val3 = ((Bounds)(ref bounds)).center;
			}
			foreach (MeshFilter item in list)
			{
				item.sharedMesh = null;
			}
			float value = Plugin.EraseSize.Value;
			Plugin.MakeRound(val, val3, value, log: false);
			Color value2 = Abilities.Get(AbilityId.EraseOrb).Color.Value;
			Material material = MaterialTools.Make(Plugin.Template, "Erase Orb", new Color(0.02f, 0f, 0.04f), 0f, 0.9f, null, value2 * 0.6f, null, value2 * 3f);
			GameObject obj = MeshTools.AddPart(val.transform, "Erase Core", Plugin.UnitSphere, material);
			obj.transform.localPosition = val3;
			obj.transform.localScale = Vector3.one * value;
			Abilities.AddLight(obj.transform, value2, 5f, 2.5f);
			if ((Object)(object)val.GetComponent<ItemEquippable>() == (Object)null)
			{
				ItemEquippable val4 = val.AddComponent<ItemEquippable>();
				GameObject val5 = Resources.Load<GameObject>("Items/Item Melee Sword");
				ItemEquippable val6 = (((Object)(object)val5 != (Object)null) ? val5.GetComponent<ItemEquippable>() : null);
				if ((Object)(object)val6 != (Object)null)
				{
					val4.ObstructionLayers = val6.ObstructionLayers;
				}
				Transform val7 = (((Object)(object)val5 != (Object)null) ? val5.transform.Find("ItemEquipCube") : null);
				if ((Object)(object)val7 != (Object)null && (Object)(object)val.transform.Find("ItemEquipCube") == (Object)null)
				{
					GameObject obj2 = Object.Instantiate<GameObject>(((Component)val7).gameObject, val.transform);
					((Object)obj2).name = "ItemEquipCube";
					obj2.transform.localPosition = val3;
					obj2.transform.localRotation = Quaternion.identity;
				}
				Plugin.Log.LogInfo((object)$"Erase orb made equippable (settings from sword: {(Object)(object)val6 != (Object)null}, equip cube: {(Object)(object)val7 != (Object)null}).");
			}
			Icon = MakeIcon(value2);
			component.icon = Icon;
			ItemEquippable component3 = val.GetComponent<ItemEquippable>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.ItemIcon = Icon;
			}
			val.AddComponent<EraseOrb>();
			_prefabRef = Items.RegisterItem(component);
			Plugin.Log.LogInfo((object)"Erase orb registered.");
		}

		private static Sprite MakeIcon(Color color)
		{
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: 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_0189: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
			Color[] array = (Color[])(object)new Color[16384];
			Color val = default(Color);
			((Color)(ref val))..ctor(0.05f, 0f, 0.09f, 1f);
			for (int i = 0; i < 128; i++)
			{
				for (int j = 0; j < 128; j++)
				{
					float num = ((float)j + 0.5f) / 128f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 128f * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2) / 0.9f;
					Color val2 = Color.clear;
					if (num3 <= 1f)
					{
						val2 = Color.Lerp(val, color, Mathf.Pow(num3, 3f));
						float num4 = Mathf.Clamp01(1f - Vector2.Distance(new Vector2(num, num2), new Vector2(-0.3f, 0.35f)) / 0.25f);
						val2 = Color.Lerp(val2, Color.white, num4 * num4 * 0.7f);
						val2.a = Mathf.Clamp01((1f - num3) * 24f);
					}
					array[i * 128 + j] = val2;
				}
			}
			Texture2D val3 = new Texture2D(128, 128, (TextureFormat)4, false)
			{
				name = "Erase Orb Icon",
				wrapMode = (TextureWrapMode)1,
				hideFlags = (HideFlags)32
			};
			val3.SetPixels(array);
			val3.Apply(false, false);
			Sprite obj = Sprite.Create(val3, new Rect(0f, 0f, 128f, 128f), new Vector2(0.5f, 0.5f), 100f);
			((Object)obj).name = "Erase Orb Icon";
			((Object)obj).hideFlags = (HideFlags)32;
			return obj;
		}

		private bool Stored()
		{
			//IL_0041: 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)
			bool flag = (Object)(object)_core == (Object)null || !((Component)_core).gameObject.activeInHierarchy || ((Object)(object)_coreRenderer != (Object)null && !_coreRenderer.enabled) || ((Component)this).transform.lossyScale.x < 0.5f;
			if (flag != _wasHidden)
			{
				_wasHidden = flag;
				int num = (((Object)(object)_equip != (Object)null && EquipState != null) ? Convert.ToInt32(EquipState.GetValue(_equip)) : (-1));
				Plugin.Log.LogInfo((object)string.Format("Erase orb {0}: state {1}, grabbed {2}, scale {3:F2}.", flag ? "stored" : "out", num, (Object)(object)_grab != (Object)null && _grab.grabbed, ((Component)this).transform.lossyScale.x));
			}
			return flag;
		}

		internal static void Activate(int viewId, Vector3 origin, Vector3 dir)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Flash(origin);
			if (!SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			if (_prefabRef == null)
			{
				Plugin.Log.LogWarning((object)"Erase orb prefab is missing, nothing spawned.");
				return;
			}
			try
			{
				GameObject val = NetworkPrefabs.SpawnNetworkPrefab(_prefabRef, origin + dir * 0.5f, Quaternion.identity, (byte)0, new object[1] { viewId });
				EraseOrb eraseOrb = (((Object)(object)val != (Object)null) ? val.GetComponent<EraseOrb>() : null);
				if ((Object)(object)eraseOrb != (Object)null)
				{
					eraseOrb.SetOwner(viewId);
				}
				Plugin.Log.LogInfo((object)$"Erase orb spawned for player view {viewId}.");
			}
			catch (Exception arg)
			{
				Plugin.Log.LogError((object)$"Erase orb spawn failed: {arg}");
			}
		}

		private void SetOwner(int viewId)
		{
			_ownerId = viewId;
			_owner = null;
			_ownerTimer = 0f;
			Active[viewId] = this;
			_registered = true;
		}

		private void Start()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			_grab = ((Component)this).GetComponent<PhysGrabObject>();
			_equip = ((Component)this).GetComponent<ItemEquippable>();
			_view = ((Component)this).GetComponent<PhotonView>();
			_core = ((Component)this).transform.Find("Erase Core");
			if ((Object)(object)_core != (Object)null)
			{
				_coreScale = _core.localScale;
				_coreRenderer = ((Component)_core).GetComponent<Renderer>();
				_light = ((Component)_core).GetComponentInChildren<Light>();
			}
			if (!_registered && (Object)(object)_view != (Object)null && _view.InstantiationData != null && _view.InstantiationData.Length != 0 && _view.InstantiationData[0] is int owner)
			{
				SetOwner(owner);
			}
			Sfx.Attach(((Component)this).gameObject, Sfx.Charge, 0.25f, 15f);
			if ((Object)(object)Icon != (Object)null)
			{
				ItemAttributes component = ((Component)this).GetComponent<ItemAttributes>();
				if ((Object)(object)component != (Object)null)
				{
					component.icon = Icon;
				}
				if ((Object)(object)_equip != (Object)null)
				{
					_equip.ItemIcon = Icon;
				}
			}
		}

		internal bool IsLocalOwner()
		{
			PlayerAvatar instance = PlayerAvatar.instance;
			if (_registered && (Object)(object)instance != (Object)null && (Object)(object)instance.photonView != (Object)null)
			{
				return instance.photonView.ViewID == _ownerId;
			}
			return false;
		}

		internal bool LocalMayHold()
		{
			if (!IsLocalOwner())
			{
				return Abilities.Has(AbilityId.EraseOrb);
			}
			return true;
		}

		private static bool Immune(PlayerAvatar p)
		{
			try
			{
				return State.AbilityOf(SemiFunc.PlayerGetSteamID(p)) == 2;
			}
			catch
			{
				return false;
			}
		}

		private PlayerAvatar Owner()
		{
			_ownerTimer -= Time.deltaTime;
			if ((Object)(object)_owner == (Object)null && _registered && _ownerTimer <= 0f)
			{
				_ownerTimer = 1f;
				_owner = SemiFunc.PlayerAvatarGetFromPhotonID(_ownerId);
			}
			return _owner;
		}

		private void Update()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e4: 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_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: 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_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_021e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0223: Unknown result type (might be due to invalid IL or missing references)
			//IL_022a: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_0275: Unknown result type (might be due to invalid IL or missing references)
			//IL_0276: Unknown result type (might be due to invalid IL or missing references)
			//IL_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_032b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0330: Unknown result type (might be due to invalid IL or missing references)
			//IL_0353: Unknown result type (might be due to invalid IL or missing references)
			//IL_0356: Unknown result type (might be due to invalid IL or missing references)
			//IL_035b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0365: Unknown result type (might be due to invalid IL or missing references)
			//IL_036a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0371: Unknown result type (might be due to invalid IL or missing references)
			//IL_0376: Unknown result type (might be due to invalid IL or missing references)
			//IL_0380: Unknown result type (might be due to invalid IL or missing references)
			//IL_0385: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			_age += Time.deltaTime;
			if ((Object)(object)_core != (Object)null)
			{
				_core.localScale = _coreScale * (1f + 0.06f * Mathf.Sin(_age * 18f));
			}
			if ((Object)(object)_light != (Object)null)
			{
				_light.intensity = 2.5f + Mathf.Sin(_age * 9f) * 0.5f;
			}
			PlayerAvatar val = Owner();
			PlayerAvatar instance = PlayerAvatar.instance;
			if ((Object)(object)_grab != (Object)null && _grab.grabbedLocal && (Object)(object)instance != (Object)null && !LocalMayHold() && (Object)(object)instance.physGrabber != (Object)null)
			{
				instance.physGrabber.OverrideGrabRelease(((Object)(object)_view != (Object)null) ? _view.ViewID : (-1), 1f);
				if (Time.time > _hintTime)
				{
					_hintTime = Time.time + 2f;
					Color value = Abilities.Get(AbilityId.EraseOrb).Color.Value;
					SemiFunc.UIFocusText("Only players with " + Abilities.Name(AbilityId.EraseOrb) + " can hold this", value, Color.white, 2f);
				}
			}
			bool flag = Stored();
			if ((Object)(object)_light != (Object)null)
			{
				((Behaviour)_light).enabled = !flag;
			}
			if (flag || !SemiFunc.IsMasterClientOrSingleplayer() || !SemiFunc.RunIsLevel())
			{
				return;
			}
			_checkTimer -= Time.deltaTime;
			if (_checkTimer > 0f)
			{
				return;
			}
			_checkTimer = 0.1f;
			Vector3 val2 = (((Object)(object)_core != (Object)null) ? _core.position : ((Component)this).transform.position);
			float num = Plugin.EraseSize.Value * 0.5f;
			foreach (Abilities.Target item in Abilities.Enemies())
			{
				if (!(DistanceToBody(val2, item.Position + Vector3.down, item.Position + Vector3.up) > num + 0.9f) && !((Object)(object)item.Health == (Object)null) && Mark(((Object)item.Enemy).GetInstanceID()))
				{
					Vector3 val3 = item.Position - val2;
					item.Health.Hurt(999999, (((Vector3)(ref val3)).sqrMagnitude > 0.001f) ? ((Vector3)(ref val3)).normalized : Vector3.up);
					Plugin.Log.LogInfo((object)"Erase orb erased an enemy.");
					Flash(item.Position);
					Vanish();
					return;
				}
			}
			if (!Plugin.EraseHitsPlayers.Value || (Object)(object)val == (Object)null)
			{
				return;
			}
			foreach (PlayerAvatar item2 in Abilities.OtherPlayers(val))
			{
				if (!Immune(item2))
				{
					Vector3 position = Abilities.Center(item2);
					Transform val4 = (((Object)(object)item2.playerTransform != (Object)null) ? item2.playerTransform : ((Component)item2).transform);
					if (!(DistanceToBody(val2, val4.position + Vector3.up * 0.1f, val4.position + Vector3.up * 1.7f) > num + 0.45f) && Mark(((Object)item2).GetInstanceID()))
					{
						Abilities.KillPlayer(item2);
						Plugin.Log.LogInfo((object)"Erase orb erased a player.");
						Flash(position);
						Vanish();
						break;
					}
				}
			}
		}

		private static float DistanceToBody(Vector3 point, Vector3 bottom, Vector3 top)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//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_000a: 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)
			//IL_002d: 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_002f: 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_0036: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = top - bottom;
			float num = Mathf.Clamp01(Vector3.Dot(point - bottom, val) / Mathf.Max(0.0001f, ((Vector3)(ref val)).sqrMagnitude));
			return Vector3.Distance(point, bottom + val * num);
		}

		private void Vanish()
		{
			if (!_vanished)
			{
				_vanished = true;
				((Behaviour)this).enabled = false;
				if ((Object)(object)_grab != (Object)null)
				{
					_grab.DestroyPhysGrabObject();
				}
				else
				{
					Object.Destroy((Object)(object)((Component)this).gameObject);
				}
			}
		}

		private bool Mark(int id)
		{
			if (_erased.TryGetValue(id, out var value) && Time.time < value)
			{
				return false;
			}
			_erased[id] = Time.time + 3f;
			return true;
		}

		private static void Flash(Vector3 position)
		{
			//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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			//IL_0036: Expected O, but got Unknown
			GameObject val = new GameObject("Erase Flash");
			val.transform.position = position;
			Sfx.Attach(val, Sfx.Blast, 0.5f, 30f);
			Object.Destroy((Object)val, 2f);
		}

		private void OnDestroy()
		{
			if (_registered && Active.TryGetValue(_ownerId, out var value) && (Object)(object)value == (Object)(object)this)
			{
				Active.Remove(_ownerId);
			}
		}
	}
	[HarmonyPatch(typeof(InventorySpot), "UpdateUI")]
	internal static class EraseOrbIconPatch
	{
		private static readonly FieldRef<InventorySpot, Image> IconRef = AccessTools.FieldRefAccess<InventorySpot, Image>("inventoryIcon");

		[HarmonyPostfix]
		private static void Postfix(InventorySpot __instance)
		{
			try
			{
				ItemEquippable currentItem = __instance.CurrentItem;
				if (!((Object)(object)currentItem == (Object)null) && !((Object)(object)EraseOrb.Icon == (Object)null) && !((Object)(object)((Component)currentItem).GetComponent<EraseOrb>() == (Object)null))
				{
					currentItem.ItemIcon = EraseOrb.Icon;
					Image val = IconRef.Invoke(__instance);
					if (!((Object)(object)val == (Object)null))
					{
						val.sprite = EraseOrb.Icon;
						((Behaviour)val).enabled = true;
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogDebug((object)("Erase orb icon failed: " + ex.Message));
			}
		}
	}
	[HarmonyPatch(typeof(ItemEquippable), "RequestEquip")]
	internal static class EraseOrbEquipPatch
	{
		[HarmonyPrefix]
		private static bool Prefix(ItemEquippable __instance)
		{
			EraseOrb eraseOrb = (((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<EraseOrb>() : null);
			if (!((Object)(object)eraseOrb == (Object)null))
			{
				return eraseOrb.LocalMayHold();
			}
			return true;
		}
	}
	public class Altar : MonoBehaviour
	{
		private struct Wall
		{
			public Vector3 Point;

			public Vector3 Normal;

			public float Distance;
		}

		internal static Altar Instance;

		private const float PlateRadius = 0.44f;

		private const float SocketRing = 0.27f;

		private const float SocketRadius = 0.075f;

		private readonly GameObject[] _orbs = (GameObject[])(object)new GameObject[7];

		private readonly MeshRenderer[] _rings = (MeshRenderer[])(object)new MeshRenderer[7];

		private Material _ringOff;

		private Material _ringOn;

		private Light _light;

		private int _shownMask = -1;

		private float _timer;

		private Dragon _dragon;

		private int _dragonShown;

		internal static void Create()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: 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)
			//IL_01c3: 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_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_010d: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_