Decompiled source of Magic Orbs v1.0.0

MagicOrbs.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MagicOrbs")]
[assembly: AssemblyTitle("MagicOrbs")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Empress.OrbRitual
{
	[BepInPlugin("Empress.OrbRitual", "Orb Ritual", "1.3.3")]
	public class OrbRitualPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "Empress.OrbRitual";

		public const string PluginName = "Orb Ritual";

		public const string PluginVersion = "1.3.3";

		internal static ConfigEntry<bool> C_Enable;

		internal static ConfigEntry<float> C_ClusterJoinRadius;

		internal static ConfigEntry<float> C_CircleRadius;

		internal static ConfigEntry<float> C_SpinHeight;

		internal static ConfigEntry<float> C_SpinRampDuration;

		internal static ConfigEntry<float> C_RotationSpeedStart;

		internal static ConfigEntry<float> C_RotationSpeedEnd;

		internal static ConfigEntry<float> C_LaunchSpeed;

		internal static ConfigEntry<float> C_ExplosionSize;

		internal static ConfigEntry<int> C_ExplosionDamagePlayer;

		internal static ConfigEntry<int> C_ExplosionDamageEnemy;

		internal static ConfigEntry<bool> C_CallEnemyImpulseVFX;

		internal static ConfigEntry<float> C_SfxBaseVolume;

		internal static ConfigEntry<bool> C_Sfx3D;

		private OrbRitualManager _manager = null;

		internal static OrbRitualPlugin Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			BindConfig();
			_manager = ((Component)this).gameObject.AddComponent<OrbRitualManager>();
			((Object)_manager).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		private void BindConfig()
		{
			C_Enable = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "C_Enable", true, "");
			C_ClusterJoinRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Detection", "C_ClusterJoinRadius", 2.5f, "");
			C_CircleRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Ritual", "C_CircleRadius", 1.6f, "");
			C_SpinHeight = ((BaseUnityPlugin)this).Config.Bind<float>("Ritual", "C_SpinHeight", 1.2f, "");
			C_SpinRampDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Ritual", "C_SpinRampDuration", 30f, "");
			C_RotationSpeedStart = ((BaseUnityPlugin)this).Config.Bind<float>("Ritual", "C_RotationSpeedStart", 120f, "");
			C_RotationSpeedEnd = ((BaseUnityPlugin)this).Config.Bind<float>("Ritual", "C_RotationSpeedEnd", 1080f, "");
			C_LaunchSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Launch", "C_LaunchSpeed", 55f, "");
			C_ExplosionSize = ((BaseUnityPlugin)this).Config.Bind<float>("Explosion", "C_ExplosionSize", 1.2f, "");
			C_ExplosionDamagePlayer = ((BaseUnityPlugin)this).Config.Bind<int>("Explosion", "C_ExplosionDamagePlayer", 60, "");
			C_ExplosionDamageEnemy = ((BaseUnityPlugin)this).Config.Bind<int>("Explosion", "C_ExplosionDamageEnemy", 160, "");
			C_CallEnemyImpulseVFX = ((BaseUnityPlugin)this).Config.Bind<bool>("Explosion", "C_CallEnemyImpulseVFX", true, "");
			C_SfxBaseVolume = ((BaseUnityPlugin)this).Config.Bind<float>("Audio", "C_SfxBaseVolume", 0.3f, "");
			C_Sfx3D = ((BaseUnityPlugin)this).Config.Bind<bool>("Audio", "C_Sfx3D", true, "");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	internal sealed class OrbRitualManager : MonoBehaviour
	{
		private sealed class ValNode
		{
			public readonly EnemyValuable Val;

			public readonly PhysGrabObject PGO;

			public readonly Rigidbody RB;

			public readonly PhysGrabObjectImpactDetector Impact;

			public bool PrevDestroyDisable;

			public Vector3 Position => Object.op_Implicit((Object)(object)RB) ? RB.position : ((Component)Val).transform.position;

			public ValNode(EnemyValuable val, PhysGrabObject pgo, Rigidbody rb, PhysGrabObjectImpactDetector impact)
			{
				Val = val;
				PGO = pgo;
				RB = rb;
				Impact = impact;
			}
		}

		private sealed class Ritual
		{
			[CompilerGenerated]
			private sealed class <DetonateAfter>d__16 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public ValNode n;

				public float delay;

				public Ritual <>4__this;

				private Vector3 <pos>5__1;

				private Exception <ex>5__2;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <DetonateAfter>d__16(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<ex>5__2 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0027: Unknown result type (might be due to invalid IL or missing references)
					//IL_0031: Expected O, but got Unknown
					//IL_00dd: 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_0064: 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)
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = (object)new WaitForSeconds(delay);
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						<pos>5__1 = (Object.op_Implicit((Object)(object)n.RB) ? n.RB.position : ((Component)n.Val).transform.position);
						if (OrbRitualPlugin.C_CallEnemyImpulseVFX.Value)
						{
							try
							{
								n.Val.DestroyImpulse();
							}
							catch (Exception ex)
							{
								<ex>5__2 = ex;
								OrbRitualPlugin.Logger.LogDebug((object)("DestroyImpulse safely ignored: " + <ex>5__2.Message));
							}
						}
						<>4__this._mgr.DoExplosion(<pos>5__1);
						if (Object.op_Implicit((Object)(object)n.Impact))
						{
							n.Impact.destroyDisable = n.PrevDestroyDisable;
						}
						return false;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			[CompilerGenerated]
			private sealed class <RunRoutine>d__15 : IEnumerator<object>, IEnumerator, IDisposable
			{
				private int <>1__state;

				private object <>2__current;

				public Ritual <>4__this;

				private float <gatherTime>5__1;

				private float <t>5__2;

				private Vector3[] <startPos>5__3;

				private float[] <targetAngles>5__4;

				private float <elapsed>5__5;

				private float <angleAcc>5__6;

				private GameObject <go>5__7;

				private float <p>5__8;

				private int <i>5__9;

				private ValNode <n>5__10;

				private Vector3 <basePos>5__11;

				private Vector3 <target>5__12;

				private Vector3 <hover>5__13;

				private float <ramp>5__14;

				private float <speed>5__15;

				private int <i>5__16;

				private float <a>5__17;

				private Vector3 <pos>5__18;

				private int <i>5__19;

				private ValNode <n>5__20;

				private Vector3 <outward>5__21;

				private Vector3 <impulse>5__22;

				private List<ValNode>.Enumerator <>s__23;

				private ValNode <n>5__24;

				private OrbRitualTag <tag>5__25;

				object IEnumerator<object>.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				object IEnumerator.Current
				{
					[DebuggerHidden]
					get
					{
						return <>2__current;
					}
				}

				[DebuggerHidden]
				public <RunRoutine>d__15(int <>1__state)
				{
					this.<>1__state = <>1__state;
				}

				[DebuggerHidden]
				void IDisposable.Dispose()
				{
					<startPos>5__3 = null;
					<targetAngles>5__4 = null;
					<go>5__7 = null;
					<n>5__10 = null;
					<n>5__20 = null;
					<>s__23 = default(List<ValNode>.Enumerator);
					<n>5__24 = null;
					<tag>5__25 = null;
					<>1__state = -2;
				}

				private bool MoveNext()
				{
					//IL_0099: Unknown result type (might be due to invalid IL or missing references)
					//IL_00a3: Expected O, but got Unknown
					//IL_00b4: 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_026d: Unknown result type (might be due to invalid IL or missing references)
					//IL_0278: Unknown result type (might be due to invalid IL or missing references)
					//IL_0289: 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_029a: 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_02bb: Unknown result type (might be due to invalid IL or missing references)
					//IL_02c0: Unknown result type (might be due to invalid IL or missing references)
					//IL_02d0: 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_02e1: Unknown result type (might be due to invalid IL or missing references)
					//IL_02e7: Unknown result type (might be due to invalid IL or missing references)
					//IL_02f2: Unknown result type (might be due to invalid IL or missing references)
					//IL_02f7: Unknown result type (might be due to invalid IL or missing references)
					//IL_0307: Unknown result type (might be due to invalid IL or missing references)
					//IL_030c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0311: Unknown result type (might be due to invalid IL or missing references)
					//IL_031d: Unknown result type (might be due to invalid IL or missing references)
					//IL_04a6: Unknown result type (might be due to invalid IL or missing references)
					//IL_04bb: Unknown result type (might be due to invalid IL or missing references)
					//IL_04c0: 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_04d5: Unknown result type (might be due to invalid IL or missing references)
					//IL_04da: Unknown result type (might be due to invalid IL or missing references)
					//IL_04df: Unknown result type (might be due to invalid IL or missing references)
					//IL_04ef: Unknown result type (might be due to invalid IL or missing references)
					//IL_04f4: Unknown result type (might be due to invalid IL or missing references)
					//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
					//IL_0515: Unknown result type (might be due to invalid IL or missing references)
					//IL_0601: Unknown result type (might be due to invalid IL or missing references)
					//IL_060c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0611: Unknown result type (might be due to invalid IL or missing references)
					//IL_0621: Unknown result type (might be due to invalid IL or missing references)
					//IL_0626: Unknown result type (might be due to invalid IL or missing references)
					//IL_062b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0630: 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_07b3: Expected O, but got Unknown
					//IL_0676: Unknown result type (might be due to invalid IL or missing references)
					//IL_0686: Unknown result type (might be due to invalid IL or missing references)
					//IL_068b: Unknown result type (might be due to invalid IL or missing references)
					//IL_0695: Unknown result type (might be due to invalid IL or missing references)
					//IL_069a: Unknown result type (might be due to invalid IL or missing references)
					//IL_069f: Unknown result type (might be due to invalid IL or missing references)
					//IL_065e: Unknown result type (might be due to invalid IL or missing references)
					//IL_0663: Unknown result type (might be due to invalid IL or missing references)
					//IL_06d8: Unknown result type (might be due to invalid IL or missing references)
					//IL_06ee: Unknown result type (might be due to invalid IL or missing references)
					//IL_0705: Unknown result type (might be due to invalid IL or missing references)
					//IL_071c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0726: Unknown result type (might be due to invalid IL or missing references)
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<>2__current = ((MonoBehaviour)<>4__this._mgr).StartCoroutine(<>4__this._mgr.EnsureOrbClipLoaded());
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -1;
						if (Object.op_Implicit((Object)(object)<>4__this._mgr._orbClip))
						{
							<go>5__7 = new GameObject("Empress_OrbRitual_SFX");
							<go>5__7.transform.position = <>4__this._center;
							<>4__this._src = <go>5__7.AddComponent<AudioSource>();
							<>4__this._src.clip = <>4__this._mgr._orbClip;
							<>4__this._src.loop = true;
							<>4__this._src.volume = Mathf.Clamp01(OrbRitualPlugin.C_SfxBaseVolume.Value);
							<>4__this._src.spatialBlend = (OrbRitualPlugin.C_Sfx3D.Value ? 1f : 0f);
							<>4__this._src.minDistance = 4f;
							<>4__this._src.maxDistance = 25f;
							<>4__this._src.Play();
							<go>5__7 = null;
						}
						<gatherTime>5__1 = 1.25f;
						<t>5__2 = 0f;
						<startPos>5__3 = <>4__this._nodes.Select((ValNode n) => n.Position).ToArray();
						<targetAngles>5__4 = new float[4] { 0f, 90f, 180f, 270f };
						goto IL_0377;
					case 2:
						<>1__state = -1;
						goto IL_0377;
					case 3:
						<>1__state = -1;
						goto IL_056a;
					case 4:
						{
							<>1__state = -1;
							<>s__23 = <>4__this._nodes.GetEnumerator();
							try
							{
								while (<>s__23.MoveNext())
								{
									<n>5__24 = <>s__23.Current;
									<tag>5__25 = ((Component)<n>5__24.Val).GetComponent<OrbRitualTag>();
									if (Object.op_Implicit((Object)(object)<tag>5__25))
									{
										<tag>5__25.InRitual = false;
										<tag>5__25.LastFinished = Time.time;
									}
									<tag>5__25 = null;
									<n>5__24 = null;
								}
							}
							finally
							{
								((IDisposable)<>s__23).Dispose();
							}
							<>s__23 = default(List<ValNode>.Enumerator);
							<>4__this._running = false;
							return false;
						}
						IL_056a:
						if (<elapsed>5__5 < <>4__this._spinDuration)
						{
							<elapsed>5__5 += Time.deltaTime;
							<ramp>5__14 = Mathf.Clamp01(<elapsed>5__5 / <>4__this._spinDuration);
							<speed>5__15 = Mathf.Lerp(<>4__this._speedStart, <>4__this._speedEnd, <ramp>5__14);
							<angleAcc>5__6 += <speed>5__15 * Time.deltaTime;
							if (Object.op_Implicit((Object)(object)<>4__this._src))
							{
								<>4__this._src.pitch = Mathf.Lerp(0.8f, 1.8f, <ramp>5__14);
								((Component)<>4__this._src).transform.position = <>4__this._center;
							}
							<i>5__16 = 0;
							while (<i>5__16 < <>4__this._nodes.Count)
							{
								<a>5__17 = <angleAcc>5__6 + <targetAngles>5__4[<i>5__16];
								<pos>5__18 = <>4__this._center + Quaternion.Euler(0f, <a>5__17, 0f) * Vector3.right * <>4__this._circleRadius + Vector3.up * <>4__this._spinHeight;
								MoveKinematic(<>4__this._nodes[<i>5__16], <pos>5__18);
								<i>5__16++;
							}
							<>2__current = null;
							<>1__state = 3;
							return true;
						}
						if (Object.op_Implicit((Object)(object)<>4__this._src))
						{
							<>4__this._src.Stop();
							Object.Destroy((Object)(object)((Component)<>4__this._src).gameObject);
							<>4__this._src = null;
						}
						<i>5__19 = 0;
						while (<i>5__19 < <>4__this._nodes.Count)
						{
							<n>5__20 = <>4__this._nodes[<i>5__19];
							<outward>5__21 = <n>5__20.Position - (<>4__this._center + Vector3.up * <>4__this._spinHeight);
							<outward>5__21.y = 0f;
							if (((Vector3)(ref <outward>5__21)).sqrMagnitude < 0.01f)
							{
								<outward>5__21 = Vector3.forward;
							}
							((Vector3)(ref <outward>5__21)).Normalize();
							<impulse>5__22 = <outward>5__21 * <>4__this._launchSpeed + Vector3.up * 2.5f;
							if (Object.op_Implicit((Object)(object)<n>5__20.RB))
							{
								<n>5__20.RB.isKinematic = false;
								<n>5__20.RB.velocity = Vector3.zero;
								<n>5__20.RB.angularVelocity = Vector3.zero;
								<n>5__20.RB.AddForce(<impulse>5__22, (ForceMode)2);
								<n>5__20.RB.AddTorque(Random.onUnitSphere * 2f, (ForceMode)2);
							}
							((MonoBehaviour)<n>5__20.Val).StartCoroutine(<>4__this.DetonateAfter(<n>5__20, 0.75f + Random.Range(-0.15f, 0.15f)));
							<n>5__20 = null;
							<i>5__19++;
						}
						<>2__current = (object)new WaitForSeconds(1.5f);
						<>1__state = 4;
						return true;
						IL_0377:
						if (<t>5__2 < <gatherTime>5__1)
						{
							<t>5__2 += Time.deltaTime;
							<p>5__8 = Mathf.SmoothStep(0f, 1f, <t>5__2 / <gatherTime>5__1);
							<i>5__9 = 0;
							while (<i>5__9 < <>4__this._nodes.Count)
							{
								<n>5__10 = <>4__this._nodes[<i>5__9];
								<basePos>5__11 = Vector3.Lerp(<startPos>5__3[<i>5__9], <>4__this._center, <p>5__8 * 0.8f);
								<target>5__12 = <>4__this._center + Quaternion.Euler(0f, <targetAngles>5__4[<i>5__9], 0f) * Vector3.right * <>4__this._circleRadius;
								<hover>5__13 = Vector3.Lerp(<basePos>5__11, <target>5__12, <p>5__8) + Vector3.up * <>4__this._spinHeight;
								MoveKinematic(<n>5__10, <hover>5__13);
								<n>5__10 = null;
								<i>5__9++;
							}
							<>2__current = null;
							<>1__state = 2;
							return true;
						}
						<elapsed>5__5 = 0f;
						<angleAcc>5__6 = 0f;
						goto IL_056a;
					}
				}

				bool IEnumerator.MoveNext()
				{
					//ILSpy generated this explicit interface implementation from .override directive in MoveNext
					return this.MoveNext();
				}

				[DebuggerHidden]
				void IEnumerator.Reset()
				{
					throw new NotSupportedException();
				}
			}

			private readonly List<ValNode> _nodes;

			private readonly OrbRitualManager _mgr;

			private readonly float _circleRadius;

			private readonly float _spinHeight;

			private readonly float _spinDuration;

			private readonly float _speedStart;

			private readonly float _speedEnd;

			private readonly float _launchSpeed;

			private Vector3 _center;

			private bool _running;

			private AudioSource? _src;

			public bool IsDone => !_running;

			public Ritual(List<ValNode> nodes, OrbRitualManager mgr)
			{
				_nodes = nodes;
				_mgr = mgr;
				_circleRadius = OrbRitualPlugin.C_CircleRadius.Value;
				_spinHeight = OrbRitualPlugin.C_SpinHeight.Value;
				_spinDuration = Mathf.Max(1f, OrbRitualPlugin.C_SpinRampDuration.Value);
				_speedStart = Mathf.Max(0f, OrbRitualPlugin.C_RotationSpeedStart.Value);
				_speedEnd = Mathf.Max(_speedStart, OrbRitualPlugin.C_RotationSpeedEnd.Value);
				_launchSpeed = Mathf.Max(1f, OrbRitualPlugin.C_LaunchSpeed.Value);
			}

			public void Begin()
			{
				//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_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_002b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Unknown result type (might be due to invalid IL or missing references)
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0067: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0150: Unknown result type (might be due to invalid IL or missing references)
				//IL_00da: 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)
				_center = Vector3.zero;
				foreach (ValNode node in _nodes)
				{
					_center += node.Position;
				}
				_center /= (float)_nodes.Count;
				foreach (ValNode node2 in _nodes)
				{
					OrbRitualTag orbRitualTag = ((Component)node2.Val).GetComponent<OrbRitualTag>() ?? ((Component)node2.Val).gameObject.AddComponent<OrbRitualTag>();
					orbRitualTag.InRitual = true;
					if (Object.op_Implicit((Object)(object)node2.RB))
					{
						node2.RB.isKinematic = true;
						node2.RB.velocity = Vector3.zero;
						node2.RB.angularVelocity = Vector3.zero;
					}
					if (Object.op_Implicit((Object)(object)node2.Impact))
					{
						node2.PrevDestroyDisable = node2.Impact.destroyDisable;
						node2.Impact.destroyDisable = true;
					}
				}
				OrbRitualPlugin.Logger.LogInfo((object)$"[EnemyValuableRitual] Starting ritual at {_center} with {_nodes.Count} valuables.");
				((MonoBehaviour)_nodes[0].Val).StartCoroutine(RunRoutine());
				_running = true;
			}

			[IteratorStateMachine(typeof(<RunRoutine>d__15))]
			private IEnumerator RunRoutine()
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <RunRoutine>d__15(0)
				{
					<>4__this = this
				};
			}

			[IteratorStateMachine(typeof(<DetonateAfter>d__16))]
			private IEnumerator DetonateAfter(ValNode n, float delay)
			{
				//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
				return new <DetonateAfter>d__16(0)
				{
					<>4__this = this,
					n = n,
					delay = delay
				};
			}

			private static void MoveKinematic(ValNode n, Vector3 worldPos)
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)n.RB))
				{
					n.RB.MovePosition(worldPos);
				}
				else
				{
					((Component)n.Val).transform.position = worldPos;
				}
			}
		}

		[CompilerGenerated]
		private sealed class <EnsureOrbClipLoaded>d__12 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public OrbRitualManager <>4__this;

			private string <dllDir>5__1;

			private string <path>5__2;

			private UnityWebRequest <uwr>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <EnsureOrbClipLoaded>d__12(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<dllDir>5__1 = null;
				<path>5__2 = null;
				<uwr>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						if (Object.op_Implicit((Object)(object)<>4__this._orbClip) || <>4__this._orbClipAttempted)
						{
							result = false;
							break;
						}
						<>4__this._orbClipAttempted = true;
						<dllDir>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)OrbRitualPlugin.Instance).Info.Location) ?? Paths.PluginPath;
						<path>5__2 = Path.Combine(<dllDir>5__1, "orb.ogg");
						if (!File.Exists(<path>5__2))
						{
							result = false;
							break;
						}
						<uwr>5__3 = UnityWebRequestMultimedia.GetAudioClip("file://" + <path>5__2, (AudioType)14);
						<>1__state = -3;
						<>2__current = <uwr>5__3.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					case 1:
						<>1__state = -3;
						if (<uwr>5__3.isNetworkError || <uwr>5__3.isHttpError)
						{
							OrbRitualPlugin.Logger.LogWarning((object)("Failed to load orb.ogg: " + <uwr>5__3.error));
							result = false;
							<>m__Finally1();
						}
						else
						{
							<>4__this._orbClip = DownloadHandlerAudioClip.GetContent(<uwr>5__3);
							<>m__Finally1();
							<uwr>5__3 = null;
							result = false;
						}
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<uwr>5__3 != null)
				{
					((IDisposable)<uwr>5__3).Dispose();
				}
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private readonly List<Ritual> _activeRituals = new List<Ritual>();

		private float _scanTimer;

		private ParticleScriptExplosion? _explosionHelper;

		private ExplosionPreset? _fallbackPreset;

		internal AudioClip? _orbClip;

		private bool _orbClipAttempted;

		private static readonly int RequiredCount = 4;

		private void Update()
		{
			if (!OrbRitualPlugin.C_Enable.Value || !SemiFunc.IsMasterClientOrSingleplayer())
			{
				return;
			}
			for (int num = _activeRituals.Count - 1; num >= 0; num--)
			{
				if (_activeRituals[num].IsDone)
				{
					_activeRituals.RemoveAt(num);
				}
			}
			_scanTimer += Time.deltaTime;
			if (!(_scanTimer < 0.2f))
			{
				_scanTimer = 0f;
				TryStartNewRitual();
			}
		}

		private void TryStartNewRitual()
		{
			//IL_0230: Unknown result type (might be due to invalid IL or missing references)
			//IL_023c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			EnemyValuable[] array = Object.FindObjectsOfType<EnemyValuable>(false);
			if (array == null || array.Length == 0)
			{
				return;
			}
			List<ValNode> list = new List<ValNode>(array.Length);
			EnemyValuable[] array2 = array;
			OrbRitualTag orbRitualTag = default(OrbRitualTag);
			foreach (EnemyValuable val in array2)
			{
				if (!Object.op_Implicit((Object)(object)val))
				{
					continue;
				}
				PhysGrabObject val2 = ((Component)val).GetComponent<PhysGrabObject>();
				if (!Object.op_Implicit((Object)(object)val2))
				{
					val2 = ((Component)val).GetComponentInChildren<PhysGrabObject>();
				}
				Rigidbody val3 = null;
				val3 = ((!Object.op_Implicit((Object)(object)val2) || !Object.op_Implicit((Object)(object)val2.rb)) ? (((Component)val).GetComponent<Rigidbody>() ?? ((Component)val).GetComponentInChildren<Rigidbody>()) : val2.rb);
				if (Object.op_Implicit((Object)(object)val2) || Object.op_Implicit((Object)(object)val3))
				{
					PhysGrabObjectImpactDetector componentInChildren = ((Component)val).GetComponentInChildren<PhysGrabObjectImpactDetector>();
					if ((!Object.op_Implicit((Object)(object)val2) || val2.playerGrabbing == null || val2.playerGrabbing.Count <= 0) && (!((Component)val).TryGetComponent<OrbRitualTag>(ref orbRitualTag) || !orbRitualTag.InRitual))
					{
						list.Add(new ValNode(val, val2, val3, componentInChildren));
					}
				}
			}
			if (list.Count < RequiredCount)
			{
				return;
			}
			float join = OrbRitualPlugin.C_ClusterJoinRadius.Value;
			OrbRitualTag orbRitualTag2 = default(OrbRitualTag);
			for (int j = 0; j < list.Count; j++)
			{
				ValNode root = list[j];
				if (((Component)root.Val).TryGetComponent<OrbRitualTag>(ref orbRitualTag2) && orbRitualTag2.InRitual)
				{
					continue;
				}
				List<ValNode> list2 = (from o in list
					where o != root && Vector3.Distance(o.Position, root.Position) <= @join
					orderby Vector3.Distance(o.Position, root.Position)
					select o).Take(RequiredCount - 1).ToList();
				if (list2.Count != RequiredCount - 1)
				{
					continue;
				}
				bool flag = true;
				for (int k = 0; k < list2.Count && flag; k++)
				{
					if (Vector3.Distance(list2[k].Position, root.Position) > join)
					{
						flag = false;
						break;
					}
					for (int l = k + 1; l < list2.Count && flag; l++)
					{
						if (Vector3.Distance(list2[k].Position, list2[l].Position) > join)
						{
							flag = false;
						}
					}
				}
				if (flag)
				{
					List<ValNode> list3 = new List<ValNode>(RequiredCount) { root };
					list3.AddRange(list2);
					Ritual ritual = new Ritual(list3, this);
					_activeRituals.Add(ritual);
					ritual.Begin();
					break;
				}
			}
		}

		internal void DoExplosion(Vector3 position)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			EnsureExplosionHelper();
			if ((Object)(object)_explosionHelper != (Object)null)
			{
				try
				{
					_explosionHelper.Spawn(position, OrbRitualPlugin.C_ExplosionSize.Value, OrbRitualPlugin.C_ExplosionDamagePlayer.Value, OrbRitualPlugin.C_ExplosionDamageEnemy.Value, 1f, true, false, 1f);
				}
				catch (Exception ex)
				{
					OrbRitualPlugin.Logger.LogWarning((object)("Explosion spawn failed: " + ex.Message));
				}
			}
		}

		private void EnsureExplosionHelper()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Expected O, but got Unknown
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_explosionHelper != (Object)null))
			{
				_explosionHelper = Object.FindObjectOfType<ParticleScriptExplosion>(true);
				if (!((Object)(object)_explosionHelper != (Object)null) || !((Object)(object)_explosionHelper.explosionPreset != (Object)null))
				{
					GameObject val = new GameObject("Empress_EnemyValuableExplosion_Helper");
					((Object)val).hideFlags = (HideFlags)61;
					Object.DontDestroyOnLoad((Object)(object)val);
					_explosionHelper = val.AddComponent<ParticleScriptExplosion>();
					_fallbackPreset = ScriptableObject.CreateInstance<ExplosionPreset>();
					_fallbackPreset.explosionColors = MakeGradient(new Color(1f, 0.6f, 0.1f), new Color(0.3f, 0.05f, 0.01f));
					_fallbackPreset.smokeColors = MakeGradient(new Color(0.2f, 0.2f, 0.2f), new Color(0.05f, 0.05f, 0.05f));
					_fallbackPreset.lightColor = MakeGradient(new Color(1f, 0.8f, 0.4f), new Color(0.2f, 0.1f, 0f));
					_explosionHelper.explosionPreset = _fallbackPreset;
				}
			}
		}

		private static Gradient MakeGradient(Color a, Color b)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: 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)
			Gradient val = new Gradient();
			val.SetKeys((GradientColorKey[])(object)new GradientColorKey[2]
			{
				new GradientColorKey(a, 0f),
				new GradientColorKey(b, 1f)
			}, (GradientAlphaKey[])(object)new GradientAlphaKey[2]
			{
				new GradientAlphaKey(a.a, 0f),
				new GradientAlphaKey(b.a, 1f)
			});
			return val;
		}

		[IteratorStateMachine(typeof(<EnsureOrbClipLoaded>d__12))]
		internal IEnumerator EnsureOrbClipLoaded()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <EnsureOrbClipLoaded>d__12(0)
			{
				<>4__this = this
			};
		}
	}
	[HarmonyPatch(typeof(PhysGrabObjectImpactDetector))]
	internal static class ImpactBlockPatches
	{
		private static bool IsInRitual(PhysGrabObjectImpactDetector inst)
		{
			if (!Object.op_Implicit((Object)(object)inst))
			{
				return false;
			}
			EnemyValuable componentInParent = ((Component)inst).GetComponentInParent<EnemyValuable>();
			if (!Object.op_Implicit((Object)(object)componentInParent))
			{
				return false;
			}
			OrbRitualTag component = ((Component)componentInParent).GetComponent<OrbRitualTag>();
			return Object.op_Implicit((Object)(object)component) && component.InRitual;
		}

		[HarmonyPrefix]
		[HarmonyPatch("Break")]
		private static bool Break_Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !IsInRitual(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("BreakMedium")]
		private static bool BreakMedium_Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !IsInRitual(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("DestroyObject")]
		private static bool DestroyObject_Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !IsInRitual(__instance);
		}

		[HarmonyPrefix]
		[HarmonyPatch("DestroyObjectRPC")]
		private static bool DestroyObjectRPC_Prefix(PhysGrabObjectImpactDetector __instance)
		{
			return !IsInRitual(__instance);
		}
	}
	[HarmonyPatch(typeof(EnemyValuable))]
	internal static class EnemyValuable_Finalizers
	{
		[HarmonyFinalizer]
		[HarmonyPatch("DestroyImpulse")]
		private static Exception DestroyImpulse_Finalizer(Exception __exception)
		{
			if (__exception != null)
			{
				OrbRitualPlugin.Logger.LogDebug((object)("DestroyImpulse exception suppressed: " + __exception.Message));
				return null;
			}
			return null;
		}
	}
	internal sealed class OrbRitualTag : MonoBehaviour
	{
		public bool InRitual;

		public float LastFinished;
	}
}