Decompiled source of Doctor Strange v1.0.2

BepInEx/plugins/StrangeModel.dll

Decompiled a week ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using ModelReplacement;
using ModelReplacement.AvatarBodyUpdater;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.AI;
using UnityEngine.Audio;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyTitle("StrangeModel")]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace StrangeModel;

internal class CapeSim : MonoBehaviour
{
	private class Chain
	{
		public Transform[] bones;

		public Quaternion[] rest;

		public float[] length;

		public Vector3[] pos;

		public Vector3[] prev;

		public Vector3[] target;
	}

	private struct Capsule
	{
		public Transform a;

		public Transform b;

		public float radius;
	}

	public PlayerControllerB player;

	private readonly List<Chain> chains = new List<Chain>();

	private readonly List<Capsule> capsules = new List<Capsule>();

	private float[,] across;

	private int lastFrame = -1;

	private bool ready;

	private bool primed;

	private float flutter;

	private void Start()
	{
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: 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_0246: Unknown result type (might be due to invalid IL or missing references)
		//IL_0262: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 1; i <= 5; i++)
		{
			List<Transform> list = new List<Transform>();
			for (int j = 1; j <= 10; j++)
			{
				Transform val = FindDeep(((Component)this).transform, "Cape" + i.ToString("00") + "_" + j);
				if ((Object)(object)val != (Object)null)
				{
					list.Add(val);
				}
			}
			if (list.Count >= 3)
			{
				Chain chain = new Chain();
				chain.bones = list.ToArray();
				chain.rest = (Quaternion[])(object)new Quaternion[chain.bones.Length];
				chain.length = new float[chain.bones.Length];
				chain.pos = (Vector3[])(object)new Vector3[chain.bones.Length];
				chain.prev = (Vector3[])(object)new Vector3[chain.bones.Length];
				chain.target = (Vector3[])(object)new Vector3[chain.bones.Length];
				for (int k = 0; k < chain.bones.Length; k++)
				{
					ref Quaternion reference = ref chain.rest[k];
					reference = chain.bones[k].localRotation;
					chain.length[k] = ((k == 0) ? 0f : Vector3.Distance(chain.bones[k].position, chain.bones[k - 1].position));
				}
				chains.Add(chain);
			}
		}
		Animator component = ((Component)this).GetComponent<Animator>();
		if ((Object)(object)component != (Object)null && component.isHuman)
		{
			AddCapsule(component, (HumanBodyBones)1, (HumanBodyBones)3, 0.12f);
			AddCapsule(component, (HumanBodyBones)2, (HumanBodyBones)4, 0.12f);
			AddCapsule(component, (HumanBodyBones)3, (HumanBodyBones)5, 0.09f);
			AddCapsule(component, (HumanBodyBones)4, (HumanBodyBones)6, 0.09f);
			AddCapsule(component, (HumanBodyBones)0, (HumanBodyBones)54, 0.17f);
		}
		if (chains.Count > 1)
		{
			int num = 10;
			across = new float[chains.Count, num];
			for (int l = 0; l + 1 < chains.Count; l++)
			{
				for (int m = 0; m < num && m < chains[l].bones.Length && m < chains[l + 1].bones.Length; m++)
				{
					across[l, m] = Vector3.Distance(chains[l].bones[m].position, chains[l + 1].bones[m].position);
				}
			}
		}
		ready = chains.Count > 0;
	}

	private void AddCapsule(Animator animator, HumanBodyBones a, HumanBodyBones b, float radius)
	{
		//IL_0001: 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)
		Transform boneTransform = animator.GetBoneTransform(a);
		Transform boneTransform2 = animator.GetBoneTransform(b);
		if (!((Object)(object)boneTransform == (Object)null) && !((Object)(object)boneTransform2 == (Object)null))
		{
			Capsule item = new Capsule
			{
				a = boneTransform,
				b = boneTransform2,
				radius = radius
			};
			capsules.Add(item);
		}
	}

	private static Transform FindDeep(Transform root, string name)
	{
		if (((Object)root).name == name)
		{
			return root;
		}
		for (int i = 0; i < root.childCount; i++)
		{
			Transform val = FindDeep(root.GetChild(i), name);
			if ((Object)(object)val != (Object)null)
			{
				return val;
			}
		}
		return null;
	}

	private void OnEnable()
	{
		RenderPipelineManager.beginContextRendering += OnBeginRendering;
		primed = false;
	}

	private void OnDisable()
	{
		RenderPipelineManager.beginContextRendering -= OnBeginRendering;
	}

	private void OnBeginRendering(ScriptableRenderContext context, List<Camera> cameras)
	{
		if (!ready || Time.frameCount == lastFrame || (Object)(object)this == (Object)null)
		{
			return;
		}
		lastFrame = Time.frameCount;
		try
		{
			Step(Mathf.Clamp(Time.deltaTime, 0.001f, 1f / 30f));
		}
		catch (Exception ex)
		{
			ready = false;
			Plugin.Log.LogWarning((object)("Cape physics stopped: " + ex.Message));
		}
	}

	private void Step(float dt)
	{
		//IL_0006: 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_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: 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_0080: 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_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_017d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0187: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e7: 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_0204: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_0219: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_023e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0251: Unknown result type (might be due to invalid IL or missing references)
		//IL_0256: Unknown result type (might be due to invalid IL or missing references)
		//IL_0260: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0283: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028e: Unknown result type (might be due to invalid IL or missing references)
		//IL_030f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0314: Unknown result type (might be due to invalid IL or missing references)
		//IL_0316: Unknown result type (might be due to invalid IL or missing references)
		//IL_031b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0321: Unknown result type (might be due to invalid IL or missing references)
		//IL_0326: 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_02b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02da: Unknown result type (might be due to invalid IL or missing references)
		//IL_02df: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_03fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0413: Unknown result type (might be due to invalid IL or missing references)
		//IL_0418: Unknown result type (might be due to invalid IL or missing references)
		//IL_041d: Unknown result type (might be due to invalid IL or missing references)
		//IL_08c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_08d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_08dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_08ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_08fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0903: Unknown result type (might be due to invalid IL or missing references)
		//IL_0908: Unknown result type (might be due to invalid IL or missing references)
		//IL_0378: Unknown result type (might be due to invalid IL or missing references)
		//IL_037d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0388: Unknown result type (might be due to invalid IL or missing references)
		//IL_038d: Unknown result type (might be due to invalid IL or missing references)
		//IL_047d: Unknown result type (might be due to invalid IL or missing references)
		//IL_048d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0492: Unknown result type (might be due to invalid IL or missing references)
		//IL_04a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_04b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_04c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_04ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_04cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_04d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0460: Unknown result type (might be due to invalid IL or missing references)
		//IL_0465: Unknown result type (might be due to invalid IL or missing references)
		//IL_046c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0471: Unknown result type (might be due to invalid IL or missing references)
		//IL_0476: Unknown result type (might be due to invalid IL or missing references)
		//IL_0930: Unknown result type (might be due to invalid IL or missing references)
		//IL_0932: Unknown result type (might be due to invalid IL or missing references)
		//IL_0934: Unknown result type (might be due to invalid IL or missing references)
		//IL_0943: Unknown result type (might be due to invalid IL or missing references)
		//IL_0948: Unknown result type (might be due to invalid IL or missing references)
		//IL_0551: Unknown result type (might be due to invalid IL or missing references)
		//IL_0564: Unknown result type (might be due to invalid IL or missing references)
		//IL_0569: Unknown result type (might be due to invalid IL or missing references)
		//IL_056e: Unknown result type (might be due to invalid IL or missing references)
		//IL_06bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_06d5: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_06e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_05f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_05fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0612: Unknown result type (might be due to invalid IL or missing references)
		//IL_0617: Unknown result type (might be due to invalid IL or missing references)
		//IL_0619: Unknown result type (might be due to invalid IL or missing references)
		//IL_061e: Unknown result type (might be due to invalid IL or missing references)
		//IL_077a: Unknown result type (might be due to invalid IL or missing references)
		//IL_078f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0794: Unknown result type (might be due to invalid IL or missing references)
		//IL_0799: Unknown result type (might be due to invalid IL or missing references)
		//IL_07a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_07be: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_07c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_07e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_07f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_080b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0810: Unknown result type (might be due to invalid IL or missing references)
		//IL_0830: Unknown result type (might be due to invalid IL or missing references)
		//IL_0837: Unknown result type (might be due to invalid IL or missing references)
		//IL_0846: Unknown result type (might be due to invalid IL or missing references)
		//IL_084b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0850: Unknown result type (might be due to invalid IL or missing references)
		float num = Mathf.Max(((Component)this).transform.lossyScale.x, 0.01f);
		bool flag = (Object)(object)player != (Object)null && Magic.IsLevitating(player);
		flutter += dt * (flag ? 9f : 4f);
		Vector3 val = -((Component)this).transform.forward;
		Vector3 val2 = Vector3.down * (flag ? 2.5f : 9.8f);
		Vector3 val3 = (flag ? (val * 7f + Vector3.up * 3.5f) : Vector3.zero);
		foreach (Chain chain4 in chains)
		{
			for (int i = 0; i < chain4.bones.Length; i++)
			{
				chain4.bones[i].localRotation = chain4.rest[i];
			}
		}
		bool flag2 = !primed;
		if (!flag2 && chains[0].pos[0] != Vector3.zero)
		{
			Vector3 val4 = chains[0].bones[0].position - chains[0].pos[0];
			if (((Vector3)(ref val4)).sqrMagnitude > 4f * num * num)
			{
				flag2 = true;
			}
		}
		for (int j = 0; j < chains.Count; j++)
		{
			Chain chain = chains[j];
			int num2 = chain.bones.Length;
			for (int k = 0; k < num2; k++)
			{
				Vector3 position = chain.bones[k].position;
				chain.target[k] = position;
				if (flag2 || k == 0)
				{
					chain.pos[k] = position;
					chain.prev[k] = position;
					continue;
				}
				float num3 = (float)k / (float)(num2 - 1);
				Vector3 val5 = (chain.pos[k] - chain.prev[k]) * 0.9f;
				ref Vector3 reference = ref chain.prev[k];
				reference = chain.pos[k];
				Vector3 val6 = val2;
				if (flag)
				{
					float num4 = Mathf.Sin(flutter + (float)k * 0.7f + (float)j * 1.3f);
					val6 += val3 * num3 + ((Component)this).transform.right * (num4 * 2.5f * num3) + Vector3.up * (num4 * 2f * num3);
				}
				ref Vector3 reference2 = ref chain.pos[k];
				reference2 += val5 + val6 * (dt * dt) * num;
				float num5 = Mathf.Lerp(flag ? 5f : 12f, flag ? 0.8f : 3f, num3);
				ref Vector3 reference3 = ref chain.pos[k];
				reference3 = Vector3.Lerp(chain.pos[k], position, Mathf.Clamp01(num5 * dt));
			}
		}
		primed = true;
		if (flag2)
		{
			return;
		}
		for (int l = 0; l < 3; l++)
		{
			foreach (Chain chain5 in chains)
			{
				for (int m = 1; m < chain5.bones.Length; m++)
				{
					Vector3 val7 = chain5.pos[m] - chain5.pos[m - 1];
					float magnitude = ((Vector3)(ref val7)).magnitude;
					if (!(magnitude < 1E-05f))
					{
						float num6 = chain5.length[m];
						if (m == 1)
						{
							ref Vector3 reference4 = ref chain5.pos[m];
							reference4 = chain5.pos[0] + val7 * (num6 / magnitude);
							continue;
						}
						Vector3 val8 = val7 * (0.5f * (magnitude - num6) / magnitude);
						ref Vector3 reference5 = ref chain5.pos[m - 1];
						reference5 += val8;
						ref Vector3 reference6 = ref chain5.pos[m];
						reference6 -= val8;
					}
				}
			}
			if (across != null)
			{
				for (int n = 0; n + 1 < chains.Count; n++)
				{
					Chain chain2 = chains[n];
					Chain chain3 = chains[n + 1];
					for (int num7 = 1; num7 < chain2.bones.Length && num7 < chain3.bones.Length && num7 < 10; num7++)
					{
						Vector3 val9 = chain3.pos[num7] - chain2.pos[num7];
						float magnitude2 = ((Vector3)(ref val9)).magnitude;
						float num8 = across[n, num7];
						if (!(magnitude2 < 1E-05f) && !(num8 <= 0f))
						{
							float num9 = Mathf.Clamp(magnitude2, num8 * 0.55f, num8 * 1.4f);
							if (!(Mathf.Abs(num9 - magnitude2) < 1E-05f))
							{
								Vector3 val10 = val9 * (0.5f * (magnitude2 - num9) / magnitude2);
								ref Vector3 reference7 = ref chain2.pos[num7];
								reference7 += val10;
								ref Vector3 reference8 = ref chain3.pos[num7];
								reference8 -= val10;
							}
						}
					}
				}
			}
			foreach (Chain chain6 in chains)
			{
				for (int num10 = 2; num10 < chain6.bones.Length; num10++)
				{
					foreach (Capsule capsule in capsules)
					{
						ref Vector3 reference9 = ref chain6.pos[num10];
						reference9 = PushOut(chain6.pos[num10], capsule.a.position, capsule.b.position, capsule.radius * num);
					}
				}
			}
			float num11 = (flag ? 110f : 55f);
			foreach (Chain chain7 in chains)
			{
				for (int num12 = 1; num12 < chain7.bones.Length; num12++)
				{
					Vector3 val11 = chain7.target[num12] - chain7.target[num12 - 1];
					Vector3 val12 = chain7.pos[num12] - chain7.pos[num12 - 1];
					if (!(((Vector3)(ref val11)).sqrMagnitude < 1E-08f) && !(((Vector3)(ref val12)).sqrMagnitude < 1E-08f))
					{
						float num13 = Vector3.Angle(val11, val12);
						if (!(num13 <= num11))
						{
							val12 = Vector3.RotateTowards(val12, val11, (num13 - num11) * ((float)Math.PI / 180f), 0f);
							ref Vector3 reference10 = ref chain7.pos[num12];
							reference10 = chain7.pos[num12 - 1] + ((Vector3)(ref val12)).normalized * chain7.length[num12];
						}
					}
				}
			}
		}
		foreach (Chain chain8 in chains)
		{
			for (int num14 = 0; num14 + 1 < chain8.bones.Length; num14++)
			{
				Vector3 val13 = chain8.bones[num14 + 1].position - chain8.bones[num14].position;
				Vector3 val14 = chain8.pos[num14 + 1] - chain8.bones[num14].position;
				if (!(((Vector3)(ref val13)).sqrMagnitude < 1E-08f) && !(((Vector3)(ref val14)).sqrMagnitude < 1E-08f))
				{
					chain8.bones[num14].rotation = Quaternion.FromToRotation(val13, val14) * chain8.bones[num14].rotation;
				}
			}
		}
	}

	private static Vector3 PushOut(Vector3 p, Vector3 a, Vector3 b, float radius)
	{
		//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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: 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_005a: 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_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)
		Vector3 val = b - a;
		float num = Mathf.Clamp01(Vector3.Dot(p - a, val) / Mathf.Max(((Vector3)(ref val)).sqrMagnitude, 1E-08f));
		Vector3 val2 = a + val * num;
		Vector3 val3 = p - val2;
		float magnitude = ((Vector3)(ref val3)).magnitude;
		if (magnitude >= radius || magnitude < 1E-06f)
		{
			return p;
		}
		return val2 + val3 * (radius / magnitude);
	}
}
internal static class Emotes
{
	private static bool searched;

	private static bool available;

	private static FieldInfo dictField;

	private static FieldInfo performingField;

	private static FieldInfo emoteField;

	private static PropertyInfo localProperty;

	private static MethodInfo tryMethod;

	private static MethodInfo stopMethod;

	private static PropertyInfo allowMovingProperty;

	private static bool allowMovingWas;

	private static bool allowMovingForced;

	private static object Local => localProperty.GetValue(null, null);

	private static void Find()
	{
		if (searched)
		{
			return;
		}
		searched = true;
		try
		{
			Type type = AccessTools.TypeByName("TooManyEmotes.EmotesManager");
			Type type2 = AccessTools.TypeByName("TooManyEmotes.EmoteControllerPlayer");
			Type type3 = AccessTools.TypeByName("TooManyEmotes.EmoteController");
			if (!(type == null) && !(type2 == null) && !(type3 == null))
			{
				dictField = AccessTools.Field(type, "allUnlockableEmotesDict");
				localProperty = AccessTools.Property(type2, "emoteControllerLocal");
				tryMethod = AccessTools.Method(type2, "TryPerformingEmoteLocal", (Type[])null, (Type[])null);
				stopMethod = AccessTools.Method(type2, "StopPerformingEmote", (Type[])null, (Type[])null);
				performingField = AccessTools.Field(type3, "isPerformingEmote");
				emoteField = AccessTools.Field(type3, "performingEmote");
				Type type4 = AccessTools.TypeByName("TooManyEmotes.Patches.ThirdPersonEmoteController");
				if (type4 != null)
				{
					allowMovingProperty = AccessTools.Property(type4, "allowMovingWhileEmoting");
				}
				available = dictField != null && localProperty != null && tryMethod != null && stopMethod != null && performingField != null && emoteField != null;
				Plugin.Log.LogInfo((object)(available ? "TooManyEmotes found: levitation can play an emote." : "TooManyEmotes found but its API changed; levitation plays no emote."));
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not look into TooManyEmotes: " + ex.Message));
		}
	}

	private static object Emote(string id)
	{
		if (!(dictField.GetValue(null) is IDictionary dictionary) || !dictionary.Contains(id))
		{
			return null;
		}
		return dictionary[id];
	}

	internal static bool IsPerforming(string id)
	{
		Find();
		if (!available || string.IsNullOrEmpty(id))
		{
			return false;
		}
		try
		{
			object local = Local;
			if (local == null || !(bool)performingField.GetValue(local))
			{
				return false;
			}
			object value = emoteField.GetValue(local);
			return value != null && value == Emote(id);
		}
		catch (Exception)
		{
			return false;
		}
	}

	internal static bool Start(string id)
	{
		Find();
		if (!available || string.IsNullOrEmpty(id))
		{
			return false;
		}
		try
		{
			object local = Local;
			object obj = Emote(id);
			if (local == null)
			{
				return false;
			}
			if (obj == null)
			{
				Plugin.Log.LogWarning((object)("TooManyEmotes has no emote '" + id + "'."));
				available = false;
				return false;
			}
			return (bool)tryMethod.Invoke(local, new object[3] { obj, -1, null });
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("TooManyEmotes refused the emote: " + ex.Message));
			return false;
		}
	}

	internal static void AllowMoving(bool on)
	{
		Find();
		if (!available || allowMovingProperty == null)
		{
			return;
		}
		try
		{
			if (on && !allowMovingForced)
			{
				allowMovingWas = (bool)allowMovingProperty.GetValue(null, null);
				allowMovingProperty.SetValue(null, true, null);
				allowMovingForced = true;
			}
			else if (!on && allowMovingForced)
			{
				allowMovingProperty.SetValue(null, allowMovingWas, null);
				allowMovingForced = false;
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Could not switch TooManyEmotes' moving emotes: " + ex.Message));
		}
	}

	internal static void Stop(string id)
	{
		if (!IsPerforming(id))
		{
			return;
		}
		try
		{
			stopMethod.Invoke(Local, null);
		}
		catch (Exception)
		{
		}
	}
}
internal static class Fx
{
	internal static readonly Color Gold = new Color(1f, 0.55f, 0.12f);

	internal static readonly Color Ember = new Color(1f, 0.32f, 0.05f);

	private static Shader shader;

	private static bool unlit;

	private static bool searched;

	private static Texture2D mandala;

	private static Texture2D rim;

	private static Texture2D puff;

	private static Texture2D swirl;

	private static Texture2D dagger;

	private static Mesh quad;

	private static Mesh daggerMesh;

	private static readonly Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>();

	internal static Texture2D Mandala
	{
		get
		{
			//IL_037b: 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)
			if ((Object)(object)mandala != (Object)null)
			{
				return mandala;
			}
			mandala = NewTexture("StrangeMandala", 512, (TextureWrapMode)1);
			Color32[] array = (Color32[])(object)new Color32[262144];
			float num = 0.003125f;
			for (int i = 0; i < 512; i++)
			{
				for (int j = 0; j < 512; j++)
				{
					float num2 = ((float)j + 0.5f) / 512f * 2f - 1f;
					float num3 = ((float)i + 0.5f) / 512f * 2f - 1f;
					float num4 = Mathf.Sqrt(num2 * num2 + num3 * num3);
					float num5 = Mathf.Atan2(num3, num2);
					float num6 = 0f;
					num6 = Mathf.Max(num6, Line(num4 - 0.97f, num * 3f));
					num6 = Mathf.Max(num6, Line(num4 - 0.9f, num * 2f));
					num6 = Mathf.Max(num6, Line(num4 - 0.62f, num * 2.2f));
					num6 = Mathf.Max(num6, Line(num4 - 0.55f, num * 1.6f));
					num6 = Mathf.Max(num6, Line(num4 - 0.22f, num * 2f));
					if (num4 > 0.905f && num4 < 0.965f)
					{
						float num7 = (num5 / ((float)Math.PI * 2f) + 0.5f) * 48f;
						float num8 = num7 - Mathf.Floor(num7);
						int num9 = (int)Mathf.Floor(num7);
						float num10 = (num4 - 0.905f) / 0.06f;
						float num11 = 0f;
						num11 = ((num9 % 3 == 0) ? Line(num8 - 0.5f, 0.09f) : ((num9 % 3 != 1) ? Line(Mathf.Sqrt((num8 - 0.5f) * (num8 - 0.5f) + (num10 - 0.5f) * (num10 - 0.5f)) - 0.25f, 0.08f) : (Line(num10 - (0.3f + 0.4f * num8), 0.12f) * ((num8 > 0.15f && num8 < 0.85f) ? 1f : 0f))));
						num6 = Mathf.Max(num6, num11 * 0.9f);
					}
					for (int k = 0; k < 2; k++)
					{
						float num12 = (float)k * (float)Math.PI / 4f;
						float num13 = num2 * Mathf.Cos(num12) + num3 * Mathf.Sin(num12);
						float num14 = (0f - num2) * Mathf.Sin(num12) + num3 * Mathf.Cos(num12);
						float num15 = 0.9f / Mathf.Sqrt(2f);
						float d = Mathf.Max(Mathf.Abs(num13), Mathf.Abs(num14)) - num15;
						num6 = Mathf.Max(num6, Line(d, num * 2.2f));
					}
					if (num4 < 0.55f && num4 > 0.22f)
					{
						float d2 = Mathf.Abs(Mathf.Sin(num5 * 4f));
						num6 = Mathf.Max(num6, Line(d2, 0.03f / Mathf.Max(num4, 0.1f)) * 0.7f);
					}
					num6 = Mathf.Max(num6, Mathf.Clamp01(1f - num4) * 0.08f);
					if (num4 > 1f)
					{
						num6 = 0f;
					}
					byte b = (byte)Mathf.RoundToInt(255f * Mathf.Clamp01(num6));
					ref Color32 reference = ref array[i * 512 + j];
					reference = new Color32(b, b, b, byte.MaxValue);
				}
			}
			mandala.SetPixels32(array);
			mandala.Apply(true, true);
			return mandala;
		}
	}

	internal static Texture2D Rim
	{
		get
		{
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)rim != (Object)null)
			{
				return rim;
			}
			rim = NewTexture("StrangeRim", 256, (TextureWrapMode)1);
			Color32[] array = (Color32[])(object)new Color32[65536];
			Random random = new Random(7);
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num = ((float)j + 0.5f) / 256f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 256f * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Atan2(num2, num);
					float num5 = Mathf.Clamp01(1f - Mathf.Abs(num3 - 0.9f) / 0.07f);
					float num6 = 0.55f + 0.45f * Mathf.PerlinNoise(num4 * 9f + 30f, num3 * 14f);
					float num7 = (((float)random.NextDouble() > 0.985f) ? 1f : 0f);
					float num8 = num5 * num5 * num6 + num7 * Mathf.Clamp01(1f - Mathf.Abs(num3 - 0.9f) / 0.12f);
					byte b = (byte)Mathf.RoundToInt(255f * Mathf.Clamp01(num8));
					ref Color32 reference = ref array[i * 256 + j];
					reference = new Color32(b, b, b, byte.MaxValue);
				}
			}
			rim.SetPixels32(array);
			rim.Apply(true, true);
			return rim;
		}
	}

	internal static Texture2D Swirl
	{
		get
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)swirl != (Object)null)
			{
				return swirl;
			}
			swirl = NewTexture("StrangeSwirl", 256, (TextureWrapMode)1);
			Color32[] array = (Color32[])(object)new Color32[65536];
			for (int i = 0; i < 256; i++)
			{
				for (int j = 0; j < 256; j++)
				{
					float num = ((float)j + 0.5f) / 256f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 256f * 2f - 1f;
					float num3 = Mathf.Sqrt(num * num + num2 * num2);
					float num4 = Mathf.Atan2(num2, num) + num3 * 5f;
					float num5 = 0.5f + 0.5f * Mathf.Sin(num4 * 3f);
					float num6 = Mathf.Clamp01(1f - num3 / 0.88f) * (0.25f + 0.75f * num5 * num5) * (0.35f + 0.65f * num3);
					byte b = (byte)Mathf.RoundToInt(255f * Mathf.Clamp01(num6));
					ref Color32 reference = ref array[i * 256 + j];
					reference = new Color32(b, b, b, byte.MaxValue);
				}
			}
			swirl.SetPixels32(array);
			swirl.Apply(true, true);
			return swirl;
		}
	}

	internal static Texture2D Puff
	{
		get
		{
			//IL_00ba: 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)
			if ((Object)(object)puff != (Object)null)
			{
				return puff;
			}
			puff = NewTexture("StrangePuff", 64, (TextureWrapMode)1);
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = ((float)j + 0.5f) / 64f * 2f - 1f;
					float num2 = ((float)i + 0.5f) / 64f * 2f - 1f;
					float num3 = Mathf.Clamp01(1f - Mathf.Sqrt(num * num + num2 * num2));
					byte b = (byte)Mathf.RoundToInt(255f * num3 * num3);
					ref Color32 reference = ref array[i * 64 + j];
					reference = new Color32(b, b, b, byte.MaxValue);
				}
			}
			puff.SetPixels32(array);
			puff.Apply(true, true);
			return puff;
		}
	}

	internal static Texture2D DaggerTex
	{
		get
		{
			//IL_00ba: 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)
			if ((Object)(object)dagger != (Object)null)
			{
				return dagger;
			}
			dagger = NewTexture("StrangeDagger", 64, (TextureWrapMode)1);
			Color32[] array = (Color32[])(object)new Color32[4096];
			for (int i = 0; i < 64; i++)
			{
				for (int j = 0; j < 64; j++)
				{
					float num = Mathf.Abs(((float)j + 0.5f) / 64f * 2f - 1f);
					float num2 = Mathf.Clamp01(1f - num) * Mathf.Clamp01(1f - num) + ((num < 0.15f) ? 0.6f : 0f);
					byte b = (byte)Mathf.RoundToInt(255f * Mathf.Clamp01(num2));
					ref Color32 reference = ref array[i * 64 + j];
					reference = new Color32(b, b, b, byte.MaxValue);
				}
			}
			dagger.SetPixels32(array);
			dagger.Apply(true, true);
			return dagger;
		}
	}

	internal static Mesh Quad
	{
		get
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: 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_0111: 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_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)quad != (Object)null)
			{
				return quad;
			}
			quad = new Mesh();
			((Object)quad).name = "StrangeQuad";
			quad.vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3(-0.5f, -0.5f, 0f),
				new Vector3(0.5f, -0.5f, 0f),
				new Vector3(0.5f, 0.5f, 0f),
				new Vector3(-0.5f, 0.5f, 0f)
			};
			quad.uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(1f, 1f),
				new Vector2(0f, 1f)
			};
			quad.triangles = new int[6] { 0, 2, 1, 0, 3, 2 };
			quad.RecalculateNormals();
			quad.RecalculateBounds();
			return quad;
		}
	}

	internal static Mesh DaggerMesh
	{
		get
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: 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_00b8: 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_00d2: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)daggerMesh != (Object)null)
			{
				return daggerMesh;
			}
			daggerMesh = new Mesh();
			((Object)daggerMesh).name = "StrangeDaggerMesh";
			float num = 0.75f;
			float num2 = 0.09f;
			List<Vector3> list = new List<Vector3>();
			List<Vector2> list2 = new List<Vector2>();
			List<int> list3 = new List<int>();
			for (int i = 0; i < 2; i++)
			{
				Vector3 val = ((i == 0) ? Vector3.right : Vector3.up);
				int count = list.Count;
				list.Add(new Vector3(0f, 0f, num * 0.5f));
				list2.Add(new Vector2(0.5f, 1f));
				list.Add(val * num2 + new Vector3(0f, 0f, num * 0.18f));
				list2.Add(new Vector2(1f, 0.7f));
				list.Add(new Vector3(0f, 0f, (0f - num) * 0.5f));
				list2.Add(new Vector2(0.5f, 0f));
				list.Add(-val * num2 + new Vector3(0f, 0f, num * 0.18f));
				list2.Add(new Vector2(0f, 0.7f));
				list3.AddRange(new int[6]
				{
					count,
					count + 1,
					count + 2,
					count,
					count + 2,
					count + 3
				});
			}
			daggerMesh.SetVertices(list);
			daggerMesh.SetUVs(0, list2);
			daggerMesh.SetTriangles(list3, 0);
			daggerMesh.RecalculateNormals();
			daggerMesh.RecalculateBounds();
			return daggerMesh;
		}
	}

	private static void FindShader()
	{
		if (!searched)
		{
			searched = true;
			shader = Shader.Find("HDRP/Unlit");
			unlit = (Object)(object)shader != (Object)null;
			if ((Object)(object)shader == (Object)null)
			{
				shader = Shader.Find("HDRP/Lit");
			}
		}
	}

	internal static Material Glow(Texture2D tex, Color colour, float brightness)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: Expected O, but got Unknown
		//IL_00eb: 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_0109: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		FindShader();
		if ((Object)(object)shader == (Object)null)
		{
			return null;
		}
		Material val = new Material(shader);
		((Object)val).name = "StrangeGlow";
		val.SetFloat("_SurfaceType", 1f);
		val.SetFloat("_BlendMode", 1f);
		val.SetFloat("_ZWrite", 0f);
		val.SetFloat("_TransparentZWrite", 0f);
		val.SetFloat("_DoubleSidedEnable", 1f);
		val.SetFloat("_CullMode", 0f);
		val.SetFloat("_CullModeForward", 0f);
		val.SetFloat("_AlphaCutoffEnable", 0f);
		if (unlit)
		{
			val.SetTexture("_UnlitColorMap", (Texture)(object)tex);
			val.SetColor("_UnlitColor", colour * brightness);
		}
		else
		{
			val.SetColor("_BaseColor", new Color(0f, 0f, 0f, 1f));
			val.SetTexture("_EmissiveColorMap", (Texture)(object)tex);
			val.SetColor("_EmissiveColor", colour * brightness);
		}
		try
		{
			HDMaterial.ValidateMaterial(val);
		}
		catch (Exception)
		{
			val.EnableKeyword("_SURFACE_TYPE_TRANSPARENT");
			val.EnableKeyword("_BLENDMODE_ADD");
			val.EnableKeyword("_DOUBLESIDED_ON");
			val.SetOverrideTag("RenderType", "Transparent");
		}
		val.SetFloat("_SrcBlend", 1f);
		val.SetFloat("_DstBlend", 1f);
		val.SetFloat("_AlphaSrcBlend", 1f);
		val.SetFloat("_AlphaDstBlend", 1f);
		val.renderQueue = 3000;
		return val;
	}

	internal static void SetBrightness(Material m, Color colour, float brightness)
	{
		//IL_001e: 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)
		if (!((Object)(object)m == (Object)null))
		{
			m.SetColor(unlit ? "_UnlitColor" : "_EmissiveColor", colour * brightness);
		}
	}

	private static Texture2D NewTexture(string name, int size, TextureWrapMode wrap)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = new Texture2D(size, size, (TextureFormat)4, true, true);
		((Object)val).name = name;
		((Object)val).hideFlags = (HideFlags)61;
		((Texture)val).wrapMode = wrap;
		((Texture)val).filterMode = (FilterMode)2;
		return val;
	}

	private static float Line(float d, float width)
	{
		return Mathf.Clamp01(1f - Mathf.Abs(d) / width);
	}

	internal static GameObject MeshObject(string name, Mesh mesh, Material material, Transform parent)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject(name);
		if ((Object)(object)parent != (Object)null)
		{
			val.transform.SetParent(parent, false);
		}
		val.AddComponent<MeshFilter>().sharedMesh = mesh;
		MeshRenderer val2 = val.AddComponent<MeshRenderer>();
		((Renderer)val2).sharedMaterial = material;
		((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val2).receiveShadows = false;
		((Renderer)val2).motionVectorGenerationMode = (MotionVectorGenerationMode)0;
		return val;
	}

	internal static ParticleSystem Sparks(Transform parent, float rate, float speed, float life, float size)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0028: 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_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_0082: Unknown result type (might be due to invalid IL or missing references)
		//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_00b1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Expected O, but got Unknown
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: Unknown result type (might be due to invalid IL or missing references)
		//IL_0108: Unknown result type (might be due to invalid IL or missing references)
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Unknown result type (might be due to invalid IL or missing references)
		//IL_0181: Unknown result type (might be due to invalid IL or missing references)
		//IL_0186: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("StrangeSparks");
		val.transform.SetParent(parent, false);
		ParticleSystem val2 = val.AddComponent<ParticleSystem>();
		val2.Stop(true, (ParticleSystemStopBehavior)0);
		MainModule main = val2.main;
		((MainModule)(ref main)).loop = true;
		((MainModule)(ref main)).duration = 1f;
		((MainModule)(ref main)).startLifetime = new MinMaxCurve(life * 0.5f, life);
		((MainModule)(ref main)).startSpeed = new MinMaxCurve(speed * 0.4f, speed);
		((MainModule)(ref main)).startSize = new MinMaxCurve(size * 0.5f, size);
		((MainModule)(ref main)).startColor = new MinMaxGradient(Gold, Ember);
		((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)1;
		((MainModule)(ref main)).maxParticles = 400;
		((MainModule)(ref main)).gravityModifier = MinMaxCurve.op_Implicit(0.15f);
		EmissionModule emission = val2.emission;
		((EmissionModule)(ref emission)).rateOverTime = MinMaxCurve.op_Implicit(rate);
		ColorOverLifetimeModule colorOverLifetime = val2.colorOverLifetime;
		((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled = true;
		Gradient val3 = new Gradient();
		val3.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
		{
			new GradientColorKey(Color.white, 0f),
			new GradientColorKey(Color.white, 1f)
		}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
		{
			new GradientAlphaKey(1f, 0f),
			new GradientAlphaKey(0f, 1f)
		});
		((ColorOverLifetimeModule)(ref colorOverLifetime)).color = MinMaxGradient.op_Implicit(val3);
		SizeOverLifetimeModule sizeOverLifetime = val2.sizeOverLifetime;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).enabled = true;
		((SizeOverLifetimeModule)(ref sizeOverLifetime)).size = new MinMaxCurve(1f, AnimationCurve.Linear(0f, 1f, 1f, 0f));
		ParticleSystemRenderer component = val.GetComponent<ParticleSystemRenderer>();
		((Renderer)component).sharedMaterial = Glow(Puff, Color.white, 2.5f);
		component.renderMode = (ParticleSystemRenderMode)0;
		((Renderer)component).shadowCastingMode = (ShadowCastingMode)0;
		return val2;
	}

	internal static Light AddLight(Transform parent, Color colour, float intensity, float range)
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("StrangeLight");
		val.transform.SetParent(parent, false);
		Light val2 = val.AddComponent<Light>();
		val2.type = (LightType)2;
		val2.color = colour;
		val2.range = range;
		val2.shadows = (LightShadows)0;
		HDAdditionalLightData val3 = val.AddComponent<HDAdditionalLightData>();
		try
		{
			val3.intensity = intensity;
			val3.range = range;
			val3.affectsVolumetric = false;
		}
		catch (Exception)
		{
			val2.intensity = intensity;
		}
		return val2;
	}

	internal static AudioClip Clip(string name)
	{
		if (clips.TryGetValue(name, out var value))
		{
			return value;
		}
		value = null;
		try
		{
			string text = StrangeAssets.FindFile("strange_" + name + ".wav");
			if (text != null)
			{
				value = LoadWav(text);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Sound " + name + " could not be loaded: " + ex.Message));
		}
		clips[name] = value;
		return value;
	}

	internal static AudioSource Play(string name, Vector3 at, float volume, float pitch, float maxDistance)
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001d: Expected O, but got Unknown
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		AudioClip val = Clip(name);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		GameObject val2 = new GameObject("StrangeSound");
		val2.transform.position = at;
		AudioSource val3 = val2.AddComponent<AudioSource>();
		Setup(val3, maxDistance);
		val3.clip = val;
		val3.pitch = pitch;
		val3.volume = volume * Plugin.EffectVolume.Value;
		val3.Play();
		Object.Destroy((Object)(object)val2, val.length / Mathf.Max(0.1f, pitch) + 0.2f);
		return val3;
	}

	internal static AudioSource Loop(string name, Transform parent, float maxDistance)
	{
		AudioClip val = Clip(name);
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		AudioSource val2 = ((Component)parent).gameObject.AddComponent<AudioSource>();
		Setup(val2, maxDistance);
		val2.clip = val;
		val2.loop = true;
		val2.volume = 0.5f * Plugin.EffectVolume.Value;
		val2.Play();
		return val2;
	}

	private static void Setup(AudioSource src, float maxDistance)
	{
		src.spatialBlend = 1f;
		src.rolloffMode = (AudioRolloffMode)1;
		src.minDistance = 2f;
		src.maxDistance = maxDistance;
		src.dopplerLevel = 0f;
		src.playOnAwake = false;
		try
		{
			if ((Object)(object)SoundManager.Instance != (Object)null && (Object)(object)SoundManager.Instance.diageticMixer != (Object)null)
			{
				AudioMixerGroup[] array = SoundManager.Instance.diageticMixer.FindMatchingGroups("SFX");
				if (array != null && array.Length > 0)
				{
					src.outputAudioMixerGroup = array[0];
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static AudioClip LoadWav(string path)
	{
		byte[] array = File.ReadAllBytes(path);
		int num = 0;
		int num2 = 0;
		int num3 = -1;
		int num4 = 0;
		int num5;
		for (int i = 12; i + 8 <= array.Length; i += 8 + num5 + (num5 & 1))
		{
			string text = Encoding.ASCII.GetString(array, i, 4);
			num5 = BitConverter.ToInt32(array, i + 4);
			if (text == "fmt ")
			{
				num = BitConverter.ToInt16(array, i + 10);
				num2 = BitConverter.ToInt32(array, i + 12);
			}
			else if (text == "data")
			{
				num3 = i + 8;
				num4 = Math.Min(num5, array.Length - num3);
				break;
			}
		}
		if (num3 < 0 || num < 1)
		{
			throw new InvalidDataException("not a 16 bit WAV");
		}
		int num6 = num4 / 2;
		float[] array2 = new float[num6];
		for (int j = 0; j < num6; j++)
		{
			array2[j] = (float)BitConverter.ToInt16(array, num3 + j * 2) / 32768f;
		}
		AudioClip val = AudioClip.Create(Path.GetFileNameWithoutExtension(path), num6 / num, num, num2, false);
		val.SetData(array2, 0);
		((Object)val).hideFlags = (HideFlags)61;
		return val;
	}
}
internal class Magic : MonoBehaviour
{
	private class Caster
	{
		public ShieldFx shield;

		public LevitateFx levitate;

		public PortalFx[] portals = new PortalFx[2];

		public float portalsClose;
	}

	private static readonly Dictionary<int, Caster> casters = new Dictionary<int, Caster>();

	private static readonly Dictionary<EnemyAI, float> enemyCooldown = new Dictionary<EnemyAI, float>();

	internal static bool LocalLevitating;

	internal static float LevitateStarted;

	private static int ammo = -1;

	private static float nextVolley;

	private static float reloadDone;

	private static float shieldEnergy = -1f;

	private static float levitateEnergy = -1f;

	private static float portalReady;

	private static float portalPending;

	private static float travelReady;

	private static bool shieldHeld;

	private static bool tipShown;

	private static bool wasWearing;

	private static int portalNext;

	private static readonly Dictionary<string, Key> keyCache = new Dictionary<string, Key>();

	private static float nextEmoteTry;

	private static InputAction moveAction;

	internal static PlayerControllerB Local
	{
		get
		{
			if (!((Object)(object)GameNetworkManager.Instance != (Object)null))
			{
				return null;
			}
			return GameNetworkManager.Instance.localPlayerController;
		}
	}

	internal static int IndexOf(PlayerControllerB p)
	{
		if (!((Object)(object)p == (Object)null))
		{
			return (int)p.playerClientId;
		}
		return -1;
	}

	internal static PlayerControllerB PlayerAt(int index)
	{
		if ((Object)(object)StartOfRound.Instance == (Object)null || index < 0 || index >= StartOfRound.Instance.allPlayerScripts.Length)
		{
			return null;
		}
		return StartOfRound.Instance.allPlayerScripts[index];
	}

	internal static bool IsStrange(PlayerControllerB p)
	{
		if ((Object)(object)p == (Object)null)
		{
			return false;
		}
		StrangeReplacement component = ((Component)p).GetComponent<StrangeReplacement>();
		if ((Object)(object)component != (Object)null)
		{
			return ((Behaviour)component).enabled;
		}
		return false;
	}

	internal static bool IsLevitating(PlayerControllerB p)
	{
		if ((Object)(object)p != (Object)null && casters.TryGetValue(IndexOf(p), out var value))
		{
			return (Object)(object)value.levitate != (Object)null;
		}
		return false;
	}

	internal static bool IsProtected(PlayerControllerB victim)
	{
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_006f: 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_0075: 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_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)
		foreach (KeyValuePair<int, Caster> caster in casters)
		{
			ShieldFx shield = caster.Value.shield;
			if ((Object)(object)shield == (Object)null)
			{
				continue;
			}
			if (caster.Key == IndexOf(victim))
			{
				return true;
			}
			Vector3 val = ((Component)victim).transform.position + Vector3.up * 1.2f;
			Vector3 val2 = ((Component)shield).transform.InverseTransformPoint(val);
			float num = Plugin.ShieldSize.Value * 0.5f / Mathf.Max(((Component)shield).transform.lossyScale.x, 0.01f);
			if (val2.z < 0f && val2.z > -6f)
			{
				Vector2 val3 = new Vector2(val2.x, val2.y);
				if (((Vector2)(ref val3)).magnitude < num * 1.3f)
				{
					return true;
				}
			}
		}
		return false;
	}

	private static Caster Get(int index)
	{
		if (!casters.TryGetValue(index, out var value))
		{
			value = new Caster();
			casters[index] = value;
		}
		return value;
	}

	internal static void ResetAll()
	{
		foreach (Caster value in casters.Values)
		{
			if ((Object)(object)value.shield != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value.shield).gameObject);
			}
			if ((Object)(object)value.levitate != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)value.levitate).gameObject);
			}
			for (int i = 0; i < 2; i++)
			{
				if ((Object)(object)value.portals[i] != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value.portals[i]).gameObject);
				}
			}
		}
		casters.Clear();
		enemyCooldown.Clear();
		LocalLevitating = false;
		shieldHeld = false;
		portalNext = 0;
	}

	internal static void OnEvent(byte kind, int player, BinaryReader r)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: 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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		//IL_024b: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0252: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		Caster caster = Get(player);
		PlayerControllerB val = PlayerAt(player);
		bool flag = (Object)(object)val != (Object)null && (Object)(object)val == (Object)(object)Local;
		switch (kind)
		{
		case 1:
		{
			Vector3 origin = StrangeNet.ReadVector(r);
			Vector3 dir = StrangeNet.ReadVector(r);
			int count = r.ReadByte();
			int seed = r.ReadInt32();
			DaggerBolt.Volley(val, origin, dir, count, seed, flag);
			break;
		}
		case 2:
		{
			bool flag2 = r.ReadBoolean();
			if (flag2 && (Object)(object)caster.shield == (Object)null && (Object)(object)val != (Object)null)
			{
				caster.shield = ShieldFx.Create(val);
			}
			else if (!flag2 && (Object)(object)caster.shield != (Object)null)
			{
				caster.shield.Close();
				caster.shield = null;
			}
			break;
		}
		case 5:
		{
			bool flag3 = r.ReadBoolean();
			if (flag3 && (Object)(object)caster.levitate == (Object)null && (Object)(object)val != (Object)null)
			{
				caster.levitate = LevitateFx.Create(val);
			}
			else if (!flag3 && (Object)(object)caster.levitate != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)caster.levitate).gameObject);
				caster.levitate = null;
			}
			if (flag)
			{
				if (flag3 && !LocalLevitating)
				{
					LevitateStarted = Time.time;
				}
				LocalLevitating = flag3;
			}
			break;
		}
		case 3:
		{
			int num2 = r.ReadByte() & 1;
			Vector3 pos = StrangeNet.ReadVector(r);
			Vector3 forward = StrangeNet.ReadVector(r);
			if ((Object)(object)caster.portals[num2] != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)caster.portals[num2]).gameObject);
			}
			caster.portals[num2] = PortalFx.Create(pos, forward, num2);
			if ((Object)(object)caster.portals[0] != (Object)null && (Object)(object)caster.portals[1] != (Object)null)
			{
				caster.portalsClose = Time.time + Plugin.PortalLifetime.Value;
				caster.portals[0].Link(caster.portals[1]);
				caster.portals[1].Link(caster.portals[0]);
			}
			else
			{
				caster.portalsClose = Time.time + 20f;
			}
			break;
		}
		case 4:
			ClosePortals(caster);
			break;
		case 6:
		{
			Vector3 val2 = StrangeNet.ReadVector(r);
			float num = r.ReadSingle();
			if ((Object)(object)val != (Object)null && !flag)
			{
				val.TeleportPlayer(val2, true, num, false, true);
			}
			Fx.Play("portal_travel", val2 + Vector3.up, 0.8f, 1f, 25f);
			break;
		}
		}
	}

	private static void ClosePortals(Caster c)
	{
		for (int i = 0; i < 2; i++)
		{
			if ((Object)(object)c.portals[i] != (Object)null)
			{
				c.portals[i].Close();
			}
			c.portals[i] = null;
		}
	}

	private void Update()
	{
		PlayerControllerB local = Local;
		float time = Time.time;
		try
		{
			if ((Object)(object)local != (Object)null && Plugin.MagicEnabled.Value)
			{
				LocalCaster(local, time);
			}
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("Spell input failed: " + ex));
		}
		foreach (KeyValuePair<int, Caster> caster in casters)
		{
			Caster value = caster.Value;
			if (((Object)(object)value.portals[0] != (Object)null || (Object)(object)value.portals[1] != (Object)null) && time > value.portalsClose)
			{
				ClosePortals(value);
				if (caster.Key == IndexOf(local))
				{
					portalReady = time + Plugin.PortalCooldown.Value;
				}
			}
			PlayerControllerB val = PlayerAt(caster.Key);
			if ((Object)(object)val == (Object)null || val.isPlayerDead || !val.isPlayerControlled)
			{
				if ((Object)(object)value.shield != (Object)null)
				{
					value.shield.Close();
					value.shield = null;
				}
				if ((Object)(object)value.levitate != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value.levitate).gameObject);
					value.levitate = null;
				}
			}
		}
		try
		{
			if ((Object)(object)local != (Object)null && !local.isPlayerDead)
			{
				PortalTravel(local, time);
			}
			if (Plugin.PortalEnemies.Value)
			{
				EnemyTravel(time);
			}
		}
		catch (Exception ex2)
		{
			Plugin.Log.LogWarning((object)("Portal travel failed: " + ex2.Message));
		}
	}

	private static void LocalCaster(PlayerControllerB me, float now)
	{
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: 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_0263: Unknown result type (might be due to invalid IL or missing references)
		//IL_043b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0440: Unknown result type (might be due to invalid IL or missing references)
		//IL_0445: Unknown result type (might be due to invalid IL or missing references)
		int index = IndexOf(me);
		bool flag = IsStrange(me) && !me.isPlayerDead && me.isPlayerControlled;
		if (ammo < 0)
		{
			ammo = Plugin.DaggerAmmo.Value;
		}
		if (shieldEnergy < 0f)
		{
			shieldEnergy = Plugin.ShieldEnergy.Value;
		}
		if (levitateEnergy < 0f)
		{
			levitateEnergy = Plugin.LevitateTime.Value;
		}
		if (!flag)
		{
			if (shieldHeld)
			{
				SetShield(index, on: false);
			}
			if (LocalLevitating)
			{
				SetLevitate(index, on: false);
			}
			wasWearing = false;
			return;
		}
		if (!wasWearing)
		{
			wasWearing = true;
			if (!tipShown && (Object)(object)HUDManager.Instance != (Object)null)
			{
				tipShown = true;
				HUDManager.Instance.DisplayTip("Doctor Strange", "Daggers: LMB (empty hands) / " + Plugin.DaggerKey.Value + "   Shield: hold " + Plugin.ShieldKey.Value + " / wheel\nPortals: " + Plugin.PortalKey.Value + " twice   Levitate: " + Plugin.LevitateKey.Value, false, false, "StrangeTip");
			}
		}
		if (ammo <= 0 && reloadDone > 0f && now >= reloadDone)
		{
			ammo = Plugin.DaggerAmmo.Value;
			reloadDone = 0f;
		}
		if (!shieldHeld)
		{
			shieldEnergy = Mathf.Min(Plugin.ShieldEnergy.Value, shieldEnergy + Time.deltaTime * Plugin.ShieldEnergy.Value / Mathf.Max(0.5f, Plugin.ShieldRecharge.Value));
		}
		else
		{
			shieldEnergy -= Time.deltaTime;
		}
		if (!LocalLevitating)
		{
			levitateEnergy = Mathf.Min(Plugin.LevitateTime.Value, levitateEnergy + Time.deltaTime * Plugin.LevitateTime.Value / Mathf.Max(0.5f, Plugin.LevitateRecharge.Value));
		}
		else
		{
			levitateEnergy -= Time.deltaTime;
		}
		if (shieldHeld && shieldEnergy <= 0f)
		{
			SetShield(index, on: false);
			Fx.Play("fizzle", ((Component)me).transform.position + Vector3.up * 1.5f, 0.7f, 1f, 20f);
		}
		if (LocalLevitating && levitateEnergy <= 0f)
		{
			SetLevitate(index, on: false);
		}
		if (LocalLevitating)
		{
			KeepLevitateEmote(me, now);
		}
		bool flag2 = CanCast(me);
		Keyboard current = Keyboard.current;
		Mouse current2 = Mouse.current;
		bool flag3 = (Object)(object)me.currentlyHeldObjectServer == (Object)null && !me.isGrabbingObjectAnimation && !me.activatingItem;
		if (flag2 && (Held(current, Plugin.DaggerKey.Value) || (Plugin.MouseWhenEmptyHanded.Value && flag3 && current2 != null && current2.leftButton.isPressed)) && now >= nextVolley && ammo > 0)
		{
			CastDaggers(me, index);
			nextVolley = now + Plugin.DaggerInterval.Value;
			ammo--;
			if (ammo <= 0)
			{
				reloadDone = now + Plugin.DaggerReload.Value;
			}
		}
		bool flag4 = flag2 && shieldEnergy > 0.3f * (shieldHeld ? 0f : 1f) && (Held(current, Plugin.ShieldKey.Value) || (Plugin.MouseWhenEmptyHanded.Value && current2 != null && current2.middleButton.isPressed));
		if (flag4 != shieldHeld)
		{
			SetShield(index, flag4);
		}
		if (flag2 && Pressed(current, Plugin.PortalKey.Value))
		{
			PortalKey(me, index, now);
		}
		if (flag2 && Pressed(current, Plugin.LevitateKey.Value))
		{
			if (LocalLevitating)
			{
				SetLevitate(index, on: false);
			}
			else if (levitateEnergy > 1f)
			{
				SetLevitate(index, on: true);
			}
			else
			{
				Fx.Play("fizzle", ((Component)me).transform.position + Vector3.up, 0.6f, 1.2f, 15f);
			}
		}
	}

	private static bool CanCast(PlayerControllerB me)
	{
		if (me.inTerminalMenu || me.isTypingChat || me.inSpecialInteractAnimation || me.isClimbingLadder)
		{
			return false;
		}
		if ((Object)(object)me.quickMenuManager != (Object)null && me.quickMenuManager.isMenuOpen)
		{
			return false;
		}
		if ((Object)(object)ShipBuildModeManager.Instance != (Object)null && ShipBuildModeManager.Instance.InBuildMode)
		{
			return false;
		}
		return true;
	}

	private static bool TryKey(string name, out Key key)
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Expected I4, but got Unknown
		if (keyCache.TryGetValue(name, out key))
		{
			return (int)key != 0;
		}
		key = (Key)0;
		if (!string.IsNullOrEmpty(name))
		{
			try
			{
				key = (Key)(int)(Key)Enum.Parse(typeof(Key), name.Trim(), ignoreCase: true);
			}
			catch (Exception)
			{
				Plugin.Log.LogWarning((object)("Unknown key name '" + name + "' in the config."));
			}
		}
		keyCache[name] = key;
		return (int)key != 0;
	}

	private static bool Held(Keyboard kb, string name)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		if (kb != null && TryKey(name, out var key))
		{
			return ((ButtonControl)kb[key]).isPressed;
		}
		return false;
	}

	private static bool Pressed(Keyboard kb, string name)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		if (kb != null && TryKey(name, out var key))
		{
			return ((ButtonControl)kb[key]).wasPressedThisFrame;
		}
		return false;
	}

	private static Ray Aim(PlayerControllerB me, out Vector3 point, float range)
	{
		//IL_000f: 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_003a: 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_005f: 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_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)me.gameplayCamera).transform;
		Ray val = default(Ray);
		((Ray)(ref val))..ctor(transform.position, transform.forward);
		int num = StartOfRound.Instance.collidersAndRoomMaskAndDefault | (1 << LayerMask.NameToLayer("Enemies"));
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val, ref val2, range, num, (QueryTriggerInteraction)1))
		{
			point = ((RaycastHit)(ref val2)).point;
		}
		else
		{
			point = ((Ray)(ref val)).GetPoint(range);
		}
		return val;
	}

	private static void CastDaggers(PlayerControllerB me, int index)
	{
		//IL_001f: 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_002d: 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)
		//IL_0042: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0071: 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_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_0080: 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)
		Transform transform = ((Component)me.gameplayCamera).transform;
		Aim(me, out var point, Plugin.DaggerRange.Value);
		Vector3 origin = transform.position + transform.forward * 0.55f + transform.right * 0.28f - transform.up * 0.22f;
		Vector3 val = point - origin;
		Vector3 dir = ((Vector3)(ref val)).normalized;
		int count = Mathf.Clamp(Plugin.DaggersPerCast.Value, 1, 12);
		int seed = Random.Range(1, int.MaxValue);
		StrangeNet.Send(1, index, delegate(BinaryWriter w)
		{
			//IL_0002: 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)
			StrangeNet.WriteVector(w, origin);
			StrangeNet.WriteVector(w, dir);
			w.Write((byte)count);
			w.Write(seed);
		});
	}

	private static void SetShield(int index, bool on)
	{
		shieldHeld = on;
		StrangeNet.Send(2, index, delegate(BinaryWriter w)
		{
			w.Write(on);
		});
	}

	private static void SetLevitate(int index, bool on)
	{
		if (on && !LocalLevitating)
		{
			LevitateStarted = Time.time;
		}
		LocalLevitating = on;
		StrangeNet.Send(5, index, delegate(BinaryWriter w)
		{
			w.Write(on);
		});
		bool flag = !string.IsNullOrEmpty(Plugin.LevitateEmote.Value);
		if (on && flag)
		{
			if (Plugin.LevitateEmoteWhileMoving.Value)
			{
				Emotes.AllowMoving(on: true);
			}
			Emotes.Start(Plugin.LevitateEmote.Value);
		}
		else if (!on)
		{
			Emotes.Stop(Plugin.LevitateEmote.Value);
			Emotes.AllowMoving(on: false);
		}
		nextEmoteTry = Time.time + 0.8f;
	}

	private static void KeepLevitateEmote(PlayerControllerB me, float now)
	{
		//IL_0075: 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)
		string value = Plugin.LevitateEmote.Value;
		if (string.IsNullOrEmpty(value) || now < nextEmoteTry || Emotes.IsPerforming(value))
		{
			return;
		}
		if (moveAction == null && (Object)(object)IngamePlayerSettings.Instance != (Object)null && (Object)(object)IngamePlayerSettings.Instance.playerInput != (Object)null)
		{
			moveAction = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Move", false);
		}
		if (moveAction != null)
		{
			Vector2 val = moveAction.ReadValue<Vector2>();
			if (((Vector2)(ref val)).sqrMagnitude > 0.04f)
			{
				return;
			}
		}
		nextEmoteTry = now + 0.6f;
		Emotes.Start(value);
	}

	private static void PortalKey(PlayerControllerB me, int index, float now)
	{
		//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		Caster caster = Get(index);
		bool flag = (Object)(object)caster.portals[0] != (Object)null || (Object)(object)caster.portals[1] != (Object)null;
		if (!flag)
		{
			portalNext = 0;
		}
		if (flag && (portalNext == 0 || (Object)(object)caster.portals[0] == (Object)null))
		{
			StrangeNet.Send(4, index, null);
			portalReady = now + Plugin.PortalCooldown.Value * 0.5f;
			portalNext = 0;
			return;
		}
		if (!flag && now < portalReady)
		{
			Fx.Play("fizzle", ((Component)me).transform.position + Vector3.up, 0.6f, 1f, 15f);
			return;
		}
		if (!PlacePortal(me, out var pos, out var fwd))
		{
			Fx.Play("fizzle", ((Component)me).transform.position + Vector3.up, 0.6f, 0.9f, 15f);
			return;
		}
		int slot = portalNext;
		StrangeNet.Send(3, index, delegate(BinaryWriter w)
		{
			//IL_000f: 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)
			w.Write((byte)slot);
			StrangeNet.WriteVector(w, pos);
			StrangeNet.WriteVector(w, fwd);
		});
		portalNext = ((slot == 0) ? 1 : 0);
		portalPending = now;
	}

	private static bool PlacePortal(PlayerControllerB me, out Vector3 pos, out Vector3 fwd)
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_002d: 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_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0103: 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_0105: 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_00be: 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_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_00e0: 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_0086: 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_0095: 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_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_00ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0160: Unknown result type (might be due to invalid IL or missing references)
		//IL_0165: Unknown result type (might be due to invalid IL or missing references)
		//IL_0167: Unknown result type (might be due to invalid IL or missing references)
		//IL_0171: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: 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_0113: 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_0116: Unknown result type (might be due to invalid IL or missing references)
		//IL_011b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_021b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		Transform transform = ((Component)me.gameplayCamera).transform;
		int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
		Vector3 val = transform.position - transform.forward * 0f;
		float value = Plugin.PortalRange.Value;
		RaycastHit val2 = default(RaycastHit);
		Vector3 val4;
		Vector3 val5;
		if (Physics.Raycast(transform.position, transform.forward, ref val2, value, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
		{
			if (Mathf.Abs(((RaycastHit)(ref val2)).normal.y) < 0.6f)
			{
				Vector3 val3 = new Vector3(((RaycastHit)(ref val2)).normal.x, 0f, ((RaycastHit)(ref val2)).normal.z);
				val4 = ((Vector3)(ref val3)).normalized;
				val5 = ((RaycastHit)(ref val2)).point + val4 * 0.6f;
			}
			else
			{
				val5 = ((RaycastHit)(ref val2)).point + ((RaycastHit)(ref val2)).normal * 0.3f;
				val4 = Vector3.zero;
			}
		}
		else
		{
			val5 = transform.position + transform.forward * value;
			val4 = Vector3.zero;
		}
		if (val4 == Vector3.zero)
		{
			Vector3 val6 = val - val5;
			val6.y = 0f;
			val4 = ((((Vector3)(ref val6)).sqrMagnitude > 0.01f) ? ((Vector3)(ref val6)).normalized : (-((Component)me).transform.forward));
		}
		pos = Vector3.zero;
		fwd = val4;
		RaycastHit val7 = default(RaycastHit);
		if (!Physics.Raycast(val5 + Vector3.up * 0.5f, Vector3.down, ref val7, 30f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
		{
			return false;
		}
		pos = ((RaycastHit)(ref val7)).point + Vector3.up * 1.25f;
		RaycastHit val8 = default(RaycastHit);
		if (Physics.Raycast(((RaycastHit)(ref val7)).point + Vector3.up * 0.2f, Vector3.up, ref val8, 2.6f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1) && ((RaycastHit)(ref val8)).distance < 2.4f)
		{
			pos = ((RaycastHit)(ref val7)).point + Vector3.up * Mathf.Max(0.9f, ((RaycastHit)(ref val8)).distance * 0.5f + 0.1f);
		}
		return true;
	}

	private static PortalFx Touching(Vector3 centre, out PortalFx other)
	{
		//IL_0065: 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_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_0080: 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_00ad: 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)
		other = null;
		foreach (Caster value in casters.Values)
		{
			if ((Object)(object)value.portals[0] == (Object)null || (Object)(object)value.portals[1] == (Object)null)
			{
				continue;
			}
			for (int i = 0; i < 2; i++)
			{
				PortalFx portalFx = value.portals[i];
				if (portalFx.Opening)
				{
					continue;
				}
				Vector3 val = Quaternion.Inverse(((Component)portalFx).transform.rotation) * (centre - ((Component)portalFx).transform.position);
				if (Mathf.Abs(val.z) < 0.45f)
				{
					Vector2 val2 = new Vector2(val.x, val.y * 0.85f);
					if (((Vector2)(ref val2)).magnitude < 1f)
					{
						other = value.portals[1 - i];
						return portalFx;
					}
				}
			}
		}
		return null;
	}

	private static void PortalTravel(PlayerControllerB me, float now)
	{
		//IL_001e: 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_0032: 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_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: 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_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: 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)
		if (now < travelReady || me.inSpecialInteractAnimation)
		{
			return;
		}
		PortalFx other;
		PortalFx portalFx = Touching(((Component)me).transform.position + Vector3.up * 1f, out other);
		if ((Object)(object)portalFx == (Object)null)
		{
			return;
		}
		Vector3 dest = ExitPoint(other);
		Quaternion val = Quaternion.LookRotation(other.Forward);
		float yaw = ((Quaternion)(ref val)).eulerAngles.y;
		bool inside = other.Inside;
		me.TeleportPlayer(dest, true, yaw, false, true);
		me.isInElevator = false;
		me.isInHangarShipRoom = false;
		if ((Object)(object)StartOfRound.Instance.shipInnerRoomBounds != (Object)null)
		{
			Bounds bounds = StartOfRound.Instance.shipInnerRoomBounds.bounds;
			if (((Bounds)(ref bounds)).Contains(dest + Vector3.up))
			{
				me.isInElevator = true;
				me.isInHangarShipRoom = true;
			}
		}
		if (me.isInsideFactory != inside)
		{
			me.isInsideFactory = inside;
			GrabbableObject[] itemSlots = me.ItemSlots;
			foreach (GrabbableObject val2 in itemSlots)
			{
				if ((Object)(object)val2 != (Object)null)
				{
					val2.isInFactory = inside;
				}
			}
			SetReverb(me, inside);
		}
		travelReady = now + 1.2f;
		int player = IndexOf(me);
		StrangeNet.Send(6, player, delegate(BinaryWriter w)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			StrangeNet.WriteVector(w, dest);
			w.Write(yaw);
		});
		portalFx.Flash();
		other.Flash();
	}

	private static Vector3 ExitPoint(PortalFx portal)
	{
		//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_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_0020: 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_002d: 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)
		//IL_0041: 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_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_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)
		Vector3 val = ((Component)portal).transform.position + portal.Forward * 1.2f;
		int collidersAndRoomMaskAndDefault = StartOfRound.Instance.collidersAndRoomMaskAndDefault;
		RaycastHit val2 = default(RaycastHit);
		if (Physics.Raycast(val + Vector3.up * 0.5f, Vector3.down, ref val2, 4f, collidersAndRoomMaskAndDefault, (QueryTriggerInteraction)1))
		{
			return ((RaycastHit)(ref val2)).point + Vector3.up * 0.05f;
		}
		return ((Component)portal).transform.position - Vector3.up * 1.2f;
	}

	private static void SetReverb(PlayerControllerB me, bool inside)
	{
		try
		{
			AudioReverbPresets val = Object.FindObjectOfType<AudioReverbPresets>();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			EntranceTeleport[] array = Object.FindObjectsOfType<EntranceTeleport>();
			foreach (EntranceTeleport val2 in array)
			{
				if (val2.isEntranceToBuilding == inside && val2.audioReverbPreset >= 0 && val2.audioReverbPreset < val.audioPresets.Length)
				{
					val.audioPresets[val2.audioReverbPreset].ChangeAudioReverbForPlayer(me);
					break;
				}
			}
		}
		catch (Exception)
		{
		}
	}

	private static void EnemyTravel(float now)
	{
		//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_010f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: 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_0155: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)RoundManager.Instance == (Object)null || RoundManager.Instance.SpawnedEnemies == null || casters.Count == 0)
		{
			return;
		}
		NavMeshHit val = default(NavMeshHit);
		foreach (EnemyAI spawnedEnemy in RoundManager.Instance.SpawnedEnemies)
		{
			if ((Object)(object)spawnedEnemy == (Object)null || spawnedEnemy.isEnemyDead || !((NetworkBehaviour)spawnedEnemy).IsOwner || (Object)(object)spawnedEnemy.agent == (Object)null || !((Behaviour)spawnedEnemy.agent).enabled || !spawnedEnemy.agent.isOnNavMesh || (enemyCooldown.TryGetValue(spawnedEnemy, out var value) && now < value))
			{
				continue;
			}
			PortalFx other;
			PortalFx portalFx = Touching(((Component)spawnedEnemy).transform.position + Vector3.up * 0.8f, out other);
			if ((Object)(object)portalFx == (Object)null)
			{
				continue;
			}
			enemyCooldown[spawnedEnemy] = now + 3f;
			if (NavMesh.SamplePosition(ExitPoint(other), ref val, 2.5f, -1))
			{
				spawnedEnemy.agent.Warp(((NavMeshHit)(ref val)).position);
				((Component)spawnedEnemy).transform.rotation = Quaternion.LookRotation(other.Forward);
				if (spawnedEnemy.isOutside == other.Inside)
				{
					spawnedEnemy.SetEnemyOutside(!other.Inside);
				}
				spawnedEnemy.serverPosition = ((NavMeshHit)(ref val)).position;
				portalFx.Flash();
				other.Flash();
			}
		}
	}
}
[HarmonyPatch]
internal static class Patches
{
	private static InputAction jump;

	private static InputAction crouch;

	private static float hoverStart = -1f;

	private static float hoverY;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(PlayerControllerB), "Update")]
	private static void AfterUpdate(PlayerControllerB __instance)
	{
		//IL_0092: Unknown result type (might be due to invalid IL or missing references)
		if (Magic.LocalLevitating && !((Object)(object)__instance != (Object)(object)Magic.Local) && !__instance.isPlayerDead)
		{
			if (jump == null && (Object)(object)IngamePlayerSettings.Instance != (Object)null && (Object)(object)IngamePlayerSettings.Instance.playerInput != (Object)null)
			{
				jump = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Jump", false);
				crouch = IngamePlayerSettings.Instance.playerInput.actions.FindAction("Crouch", false);
			}
			float value = Plugin.LevitateRise.Value;
			float y = ((Component)__instance).transform.position.y;
			if (hoverStart != Magic.LevitateStarted)
			{
				hoverStart = Magic.LevitateStarted;
				hoverY = y + 1.2f;
			}
			float fallValue;
			if (jump != null && jump.IsPressed())
			{
				fallValue = value;
				hoverY = y;
			}
			else if (crouch != null && crouch.IsPressed())
			{
				fallValue = 0f - value;
				hoverY = y;
			}
			else
			{
				fallValue = Mathf.Clamp((hoverY - y) * 5f, 0f - value, value) + 0.15f * Mathf.Sin(Time.time * 2.2f);
			}
			__instance.fallValue = fallValue;
			__instance.fallValueUncapped = -6f;
			__instance.takingFallDamage = false;
		}
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
	private static bool BeforeDamage(PlayerControllerB __instance, ref int damageNumber, bool fallDamage)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		if (fallDamage || damageNumber <= 0 || !((NetworkBehaviour)__instance).IsOwner)
		{
			return true;
		}
		if (!Magic.IsProtected(__instance))
		{
			return true;
		}
		int num = damageNumber;
		damageNumber = Mathf.RoundToInt((float)damageNumber * (1f - Mathf.Clamp01(Plugin.ShieldBlock.Value)));
		Fx.Play("hit", ((Component)__instance).transform.position + Vector3.up * 1.4f + ((Component)__instance).transform.forward, 0.7f, 0.6f, 20f);
		Plugin.Log.LogInfo((object)("Shield took " + (num - damageNumber) + " of " + num + " damage."));
		return damageNumber > 0;
	}
}
[BepInPlugin("reagan.strangemodel", "Doctor Strange", "1.0.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "reagan.strangemodel";

	public const string Name = "Doctor Strange";

	public const string Version = "1.0.2";

	internal static ManualLogSource Log;

	internal static ConfigEntry<string> SuitNames;

	internal static ConfigEntry<string> FitTo;

	internal static ConfigEntry<float> ScaleMultiplier;

	internal static ConfigEntry<float> HipsOffset;

	internal static ConfigEntry<float> MaxSmoothness;

	internal static ConfigEntry<float> GlowStrength;

	internal static ConfigEntry<bool> CompressTextures;

	internal static ConfigEntry<bool> GenerateViewModel;

	internal static ConfigEntry<bool> CapePhysics;

	internal static ConfigEntry<bool> MagicEnabled;

	internal static ConfigEntry<bool> MouseWhenEmptyHanded;

	internal static ConfigEntry<string> DaggerKey;

	internal static ConfigEntry<string> ShieldKey;

	internal static ConfigEntry<string> PortalKey;

	internal static ConfigEntry<string> LevitateKey;

	internal static ConfigEntry<int> DaggersPerCast;

	internal static ConfigEntry<int> DaggerAmmo;

	internal static ConfigEntry<float> DaggerDamage;

	internal static ConfigEntry<float> DaggerInterval;

	internal static ConfigEntry<float> DaggerReload;

	internal static ConfigEntry<float> DaggerSpeed;

	internal static ConfigEntry<float> DaggerRange;

	internal static ConfigEntry<bool> FriendlyFire;

	internal static ConfigEntry<float> ShieldBlock;

	internal static ConfigEntry<float> ShieldEnergy;

	internal static ConfigEntry<float> ShieldRecharge;

	internal static ConfigEntry<float> ShieldSize;

	internal static ConfigEntry<float> PortalRange;

	internal static ConfigEntry<float> PortalLifetime;

	internal static ConfigEntry<float> PortalCooldown;

	internal static ConfigEntry<bool> PortalEnemies;

	internal static ConfigEntry<bool> PortalLight;

	internal static ConfigEntry<float> LevitateTime;

	internal static ConfigEntry<float> LevitateRecharge;

	internal static ConfigEntry<float> LevitateRise;

	internal static ConfigEntry<string> LevitateEmote;

	internal static ConfigEntry<bool> LevitateEmoteWhileMoving;

	internal static ConfigEntry<float> EffectVolume;

	private static bool started;

	private static int attempts;

	private void Awake()
	{
		//IL_006c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Expected O, but got Unknown
		//IL_0584: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		SuitNames = ((BaseUnityPlugin)this).Config.Bind<string>("General", "SuitNames", "Strange", "Comma separated suit names that turn the wearer into Doctor Strange.");
		FitTo = ((BaseUnityPlugin)this).Config.Bind<string>("Model", "FitTo", "Arms", new ConfigDescription("What the automatic size is matched to. Arms: the hands land on the player's hands. Legs: the legs are as long as the player's.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Arms", "Legs" }), new object[0]));
		ScaleMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "ScaleMultiplier", 1f, "Extra scale on top of the automatic size.");
		HipsOffset = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "HipsOffset", 0f, "Raises (positive) or lowers the model, in game units. The soles are put on the floor automatically.");
		MaxSmoothness = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "MaxSmoothness", 0.75f, "Upper limit of surface smoothness.");
		GlowStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Model", "GlowStrength", 3f, "Brightness of the glowing parts (the Eye of Agamotto).");
		CompressTextures = ((BaseUnityPlugin)this).Config.Bind<bool>("Performance", "CompressTextures", true, "Compress textures on load. Uses about a quarter of the video memory; loading takes a little longer.");
		GenerateViewModel = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "GenerateViewModel", false, "Let ModelReplacementAPI build first person arms from the model instead of showing the vanilla arms.");
		CapePhysics = ((BaseUnityPlugin)this).Config.Bind<bool>("Model", "CapePhysics", true, "The cloak swings and flutters instead of hanging stiff.");
		MagicEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Magic", "Enabled", true, "Whoever wears the suit can cast Strange's spells.");
		MouseWhenEmptyHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("Magic", "MouseWhenEmptyHanded", true, "With empty hands, left mouse fires the Daggers of Denak; holding the middle mouse button raises the Shield of the Seraphim (right mouse stays the scanner).");
		DaggerKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Daggers", "F", "Key for the Daggers of Denak (works with an item in hand too). Key names as in Unity's Input System, None to disable.");
		ShieldKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Shield", "C", "Hold for the Shield of the Seraphim.");
		PortalKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Portal", "X", "Pentagram of Farallah: first press opens a portal where you look, second press opens its pair; press again to close them.");
		LevitateKey = ((BaseUnityPlugin)this).Config.Bind<string>("Keys", "Levitate", "V", "Cloak of Levitation on/off. Hold jump to rise, crouch to sink.");
		DaggerDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Daggers", "DamagePerDagger", 0.35f, "Damage of one dagger; a shovel hit is 1. Fractions add up on the monster, so 0.35 with 3 daggers a volley is about one shovel hit per volley.");
		DaggersPerCast = ((BaseUnityPlugin)this).Config.Bind<int>("Daggers", "PerCast", 3, "Daggers in one volley.");
		DaggerAmmo = ((BaseUnityPlugin)this).Config.Bind<int>("Daggers", "Ammo", 15, "Volleys before the spell recharges.");
		DaggerInterval = ((BaseUnityPlugin)this).Config.Bind<float>("Daggers", "Interval", 0.4f, "Seconds between volleys while held.");
		DaggerReload = ((BaseUnityPlugin)this).Config.Bind<float>("Daggers", "Recharge", 1.8f, "Seconds to recharge an empty spell