Decompiled source of Strange Doors v1.0.1

Doors.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 Photon.Pun;
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: AssemblyCompany("Omniscye")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Doors")]
[assembly: AssemblyTitle("Doors")]
[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 StrangeDoors
{
	[BepInPlugin("Omniscye.StrangeDoors", "StrangeDoors", "1.6.0")]
	public class StrangeDoorsPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(LevelGenerator), "GenerateDone")]
		private static class LevelGenDonePatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				if (!((Object)(object)Instance == (Object)null))
				{
					HasTriggeredThisLevel = false;
					Instance.StopCoroutineSafe("MimicArmRoutine");
					((MonoBehaviour)Instance).StartCoroutine(Instance.MimicArmRoutine());
				}
			}
		}

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

			private object <>2__current;

			public StrangeDoorsPlugin <>4__this;

			private float <elapsed>5__1;

			private PhysGrabHinge[] <allHinges>5__2;

			private List<PhysGrabHinge> <candidates>5__3;

			private PhysGrabHinge[] <>s__4;

			private int <>s__5;

			private PhysGrabHinge <h>5__6;

			private PhysGrabObject <pgo>5__7;

			private int <seed>5__8;

			private List<int> <ids>5__9;

			private float <chance>5__10;

			private float <roll>5__11;

			private int <i>5__12;

			private PhotonView <pv>5__13;

			private int <id>5__14;

			private PhysGrabHinge <target>5__15;

			private uint <best>5__16;

			private int <i>5__17;

			private uint <h>5__18;

			private PhotonView <pv>5__19;

			private string <idStr>5__20;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<allHinges>5__2 = null;
				<candidates>5__3 = null;
				<>s__4 = null;
				<h>5__6 = null;
				<pgo>5__7 = null;
				<ids>5__9 = null;
				<pv>5__13 = null;
				<target>5__15 = null;
				<pv>5__19 = null;
				<idStr>5__20 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_044a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0454: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<elapsed>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					<elapsed>5__1 += 0.25f;
					<allHinges>5__2 = null;
					<candidates>5__3 = null;
					break;
				}
				if (<elapsed>5__1 < 8f)
				{
					<allHinges>5__2 = Object.FindObjectsOfType<PhysGrabHinge>();
					<candidates>5__3 = new List<PhysGrabHinge>();
					<>s__4 = <allHinges>5__2;
					for (<>s__5 = 0; <>s__5 < <>s__4.Length; <>s__5++)
					{
						<h>5__6 = <>s__4[<>s__5];
						if (!((Object)(object)<h>5__6 == (Object)null) && ((Component)<h>5__6).gameObject.activeInHierarchy && ((Behaviour)<h>5__6).isActiveAndEnabled)
						{
							<pgo>5__7 = ((Component)<h>5__6).GetComponent<PhysGrabObject>();
							if (!((Object)(object)<pgo>5__7 == (Object)null) && (!((Object)(object)<pgo>5__7.rb == (Object)null) || !((Object)(object)((Component)<h>5__6).GetComponent<Rigidbody>() == (Object)null)))
							{
								<candidates>5__3.Add(<h>5__6);
								<pgo>5__7 = null;
								<h>5__6 = null;
							}
						}
					}
					<>s__4 = null;
					if (<candidates>5__3.Count > 0)
					{
						<seed>5__8 = 1469598107;
						<ids>5__9 = new List<int>(<candidates>5__3.Count);
						<i>5__12 = 0;
						while (<i>5__12 < <candidates>5__3.Count)
						{
							<pv>5__13 = ((Component)<candidates>5__3[<i>5__12]).GetComponent<PhotonView>();
							<id>5__14 = (((Object)(object)<pv>5__13 != (Object)null) ? <pv>5__13.ViewID : ((Object)<candidates>5__3[<i>5__12]).GetInstanceID());
							<ids>5__9.Add(<id>5__14);
							<seed>5__8 = (<seed>5__8 * 16777619) ^ <id>5__14;
							<pv>5__13 = null;
							<i>5__12++;
						}
						<chance>5__10 = Mathf.Clamp01(DoorChance.Value);
						<roll>5__11 = ToUnitFloat(<seed>5__8);
						if (!(<roll>5__11 <= <chance>5__10))
						{
							Logger.LogInfo((object)$"[StrangeDoor] Roll {<roll>5__11:0.00} > {<chance>5__10:0.00}. None selected.");
							return false;
						}
						<target>5__15 = null;
						<best>5__16 = uint.MaxValue;
						<i>5__17 = 0;
						while (<i>5__17 < <candidates>5__3.Count)
						{
							<h>5__18 = Hash32((uint)(<ids>5__9[<i>5__17] ^ <seed>5__8));
							if (<h>5__18 < <best>5__16)
							{
								<best>5__16 = <h>5__18;
								<target>5__15 = <candidates>5__3[<i>5__17];
							}
							<i>5__17++;
						}
						if ((Object)(object)<target>5__15 != (Object)null)
						{
							if ((Object)(object)((Component)<target>5__15).GetComponent<MimicController>() == (Object)null)
							{
								((Component)<target>5__15).gameObject.AddComponent<MimicController>();
								<pv>5__19 = ((Component)<target>5__15).GetComponent<PhotonView>();
								<idStr>5__20 = (((Object)(object)<pv>5__19 != (Object)null) ? <pv>5__19.ViewID.ToString() : "noPV");
								Logger.LogInfo((object)("[StrangeDoor] Armed: " + ((Object)((Component)<target>5__15).gameObject).name + " (ViewID=" + <idStr>5__20 + ")"));
								<pv>5__19 = null;
								<idStr>5__20 = null;
							}
							return false;
						}
						<target>5__15 = null;
						<ids>5__9 = null;
					}
					<>2__current = (object)new WaitForSeconds(0.25f);
					<>1__state = 1;
					return true;
				}
				Logger.LogInfo((object)"[StrangeDoor] None found.");
				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();
			}
		}

		public static ConfigEntry<float> DoorChance;

		public static ConfigEntry<float> WaveDuration;

		public static ConfigEntry<float> FlipDuration;

		public static bool HasTriggeredThisLevel;

		internal static StrangeDoorsPlugin Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

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

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			//IL_00c0: Expected O, but got Unknown
			Instance = this;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			DoorChance = ((BaseUnityPlugin)this).Config.Bind<float>("General", "DoorChance", 0.05f, new ConfigDescription("Chance for a single door to trigger.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			WaveDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "WaveDuration", 3f, "Wave duration.");
			FlipDuration = ((BaseUnityPlugin)this).Config.Bind<float>("Effects", "FlipDuration", 40f, "Flip duration.");
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} loaded.");
		}

		private void StopCoroutineSafe(string routineName)
		{
			try
			{
				((MonoBehaviour)this).StopCoroutine(routineName);
			}
			catch
			{
			}
		}

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

		private static float ToUnitFloat(int x)
		{
			return (float)((uint)x & 0x7FFFFFFFu) / 2.1474836E+09f;
		}

		private static uint Hash32(uint x)
		{
			x ^= x >> 17;
			x *= 3982152891u;
			x ^= x >> 11;
			x *= 2890668881u;
			x ^= x >> 15;
			x *= 830770091;
			x ^= x >> 14;
			return x;
		}
	}
	public class MimicEffectPlayer : MonoBehaviour
	{
		private struct AshParticle
		{
			public Vector2 position;

			public Vector2 velocity;

			public float size;

			public Color color;
		}

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

			private object <>2__current;

			public MimicEffectPlayer <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_002c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0036: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(<>4__this.flipDuration);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>4__this.RevertEffect();
					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 <LoadAndPlayMusic>d__27 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MimicEffectPlayer <>4__this;

			private string <folderPath>5__1;

			private string <songPath>5__2;

			private string <url>5__3;

			private UnityWebRequest <www>5__4;

			private AudioClip <clip>5__5;

			private GameObject <musicObj>5__6;

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

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

			[DebuggerHidden]
			public <LoadAndPlayMusic>d__27(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();
					}
				}
				<folderPath>5__1 = null;
				<songPath>5__2 = null;
				<url>5__3 = null;
				<www>5__4 = null;
				<clip>5__5 = null;
				<musicObj>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Invalid comparison between Unknown and I4
				//IL_0141: Unknown result type (might be due to invalid IL or missing references)
				//IL_014b: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<folderPath>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)StrangeDoorsPlugin.Instance).Info.Location);
						<songPath>5__2 = Path.Combine(<folderPath>5__1, "upsidedown.ogg");
						if (!File.Exists(<songPath>5__2))
						{
							StrangeDoorsPlugin.Logger.LogWarning((object)("Music not found: " + <songPath>5__2));
							return false;
						}
						<url>5__3 = "file://" + <songPath>5__2;
						<www>5__4 = UnityWebRequestMultimedia.GetAudioClip(<url>5__3, (AudioType)14);
						<>1__state = -3;
						<>2__current = <www>5__4.SendWebRequest();
						<>1__state = 1;
						return true;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__4.result == 1)
						{
							<clip>5__5 = DownloadHandlerAudioClip.GetContent(<www>5__4);
							if ((Object)(object)<clip>5__5 != (Object)null)
							{
								if ((Object)(object)<>4__this.musicSource == (Object)null)
								{
									<musicObj>5__6 = new GameObject("StrangeDoorMusic");
									<musicObj>5__6.transform.SetParent(((Component)<>4__this).transform);
									<>4__this.musicSource = <musicObj>5__6.AddComponent<AudioSource>();
									<musicObj>5__6 = null;
								}
								<>4__this.musicSource.clip = <clip>5__5;
								<>4__this.musicSource.volume = 1f;
								<>4__this.musicSource.loop = false;
								<>4__this.musicSource.Play();
								StrangeDoorsPlugin.Logger.LogInfo((object)"Music Playing.");
							}
							<clip>5__5 = null;
						}
						else
						{
							StrangeDoorsPlugin.Logger.LogError((object)("Failed to load music: " + <www>5__4.error));
						}
						<>m__Finally1();
						<www>5__4 = null;
						return false;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			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 (<www>5__4 != null)
				{
					((IDisposable)<www>5__4).Dispose();
				}
			}

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

		private Camera cam;

		private AudioSource musicSource;

		private bool isWaving;

		private bool isFlipped;

		private float waveTimer;

		private float waveDuration;

		private float flipDuration;

		private float originalFOV;

		private Texture2D redTexture;

		private Texture2D particleTexture;

		private List<AshParticle> particles = new List<AshParticle>();

		private int particleCount = 120;

		private void Start()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_0057: 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_007b: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			cam = ((Component)this).GetComponent<Camera>();
			if ((Object)(object)cam != (Object)null)
			{
				originalFOV = cam.fieldOfView;
			}
			redTexture = new Texture2D(1, 1);
			redTexture.SetPixel(0, 0, new Color(1f, 0f, 0f, 0.35f));
			redTexture.Apply();
			particleTexture = new Texture2D(1, 1);
			particleTexture.SetPixel(0, 0, Color.white);
			particleTexture.Apply();
		}

		public void TriggerSequence(float w, float f)
		{
			if (!isWaving && !isFlipped)
			{
				waveDuration = w;
				flipDuration = f;
				waveTimer = 0f;
				isWaving = true;
				StrangeDoorsPlugin.Logger.LogInfo((object)"[StrangeDoorEffect] Start");
			}
		}

		private void Update()
		{
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: 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_00d9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)cam == (Object)null)
			{
				return;
			}
			if (isWaving)
			{
				waveTimer += Time.deltaTime;
				float num = waveTimer / waveDuration;
				float num2 = Mathf.Lerp(1f, 10f, num);
				float num3 = Mathf.Lerp(0f, 20f, num);
				float num4 = Mathf.Sin(Time.time * 10f) * num2;
				float num5 = Mathf.Cos(Time.time * 5f) * num3;
				Transform transform = ((Component)cam).transform;
				Quaternion localRotation = ((Component)cam).transform.localRotation;
				float x = ((Quaternion)(ref localRotation)).eulerAngles.x;
				localRotation = ((Component)cam).transform.localRotation;
				transform.localRotation = Quaternion.Euler(x, ((Quaternion)(ref localRotation)).eulerAngles.y, num4);
				cam.fieldOfView = originalFOV + num5;
				if (waveTimer >= waveDuration)
				{
					isWaving = false;
					ApplyFlip();
				}
			}
			if (isFlipped)
			{
				UpdateParticles();
			}
		}

		private void ApplyFlip()
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			isFlipped = true;
			StrangeDoorsPlugin.Logger.LogInfo((object)"[StrangeDoorEffect] Flip");
			Transform transform = ((Component)cam).transform;
			Quaternion localRotation = ((Component)cam).transform.localRotation;
			float x = ((Quaternion)(ref localRotation)).eulerAngles.x;
			localRotation = ((Component)cam).transform.localRotation;
			transform.localRotation = Quaternion.Euler(x, ((Quaternion)(ref localRotation)).eulerAngles.y, 0f);
			cam.fieldOfView = originalFOV;
			SpawnParticles();
			((MonoBehaviour)this).StartCoroutine(FlipTimerRoutine());
			((MonoBehaviour)this).StartCoroutine(LoadAndPlayMusic());
		}

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

		private void RevertEffect()
		{
			//IL_0057: 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_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			StrangeDoorsPlugin.Logger.LogInfo((object)"[StrangeDoorEffect] Revert");
			isFlipped = false;
			particles.Clear();
			if ((Object)(object)cam != (Object)null)
			{
				cam.ResetProjectionMatrix();
				Transform transform = ((Component)cam).transform;
				Quaternion localRotation = ((Component)cam).transform.localRotation;
				float x = ((Quaternion)(ref localRotation)).eulerAngles.x;
				localRotation = ((Component)cam).transform.localRotation;
				transform.localRotation = Quaternion.Euler(x, ((Quaternion)(ref localRotation)).eulerAngles.y, 0f);
			}
			GL.invertCulling = false;
			if ((Object)(object)musicSource != (Object)null)
			{
				musicSource.Stop();
			}
			Object.Destroy((Object)(object)this);
		}

		private void OnPreCull()
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: 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_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_005b: Unknown result type (might be due to invalid IL or missing references)
			if (isFlipped && (Object)(object)cam != (Object)null)
			{
				cam.ResetProjectionMatrix();
				Matrix4x4 projectionMatrix = cam.projectionMatrix;
				projectionMatrix *= Matrix4x4.Scale(new Vector3(1f, -1f, 1f));
				cam.projectionMatrix = projectionMatrix;
			}
		}

		private void OnPreRender()
		{
			if (isFlipped)
			{
				GL.invertCulling = true;
			}
		}

		private void OnPostRender()
		{
			if (isFlipped)
			{
				GL.invertCulling = false;
			}
		}

		private void OnGUI()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			if (isFlipped)
			{
				GUI.depth = -1000;
				GUI.color = Color.white;
				GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)redTexture);
				DrawParticles();
			}
		}

		private void SpawnParticles()
		{
			particles.Clear();
			for (int i = 0; i < particleCount; i++)
			{
				particles.Add(CreateParticle());
			}
		}

		private AshParticle CreateParticle()
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: 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_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			Color color = (Color)((Random.value > 0.4f) ? Color.black : new Color(0.8f, 0f, 0f, 0.9f));
			AshParticle result = default(AshParticle);
			result.position = new Vector2(Random.value, Random.value);
			result.velocity = new Vector2(Random.Range(-0.05f, 0.05f), Random.Range(-0.05f, 0.05f));
			result.size = Random.Range(2f, 6f);
			result.color = color;
			return result;
		}

		private void UpdateParticles()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: 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_0094: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < particles.Count; i++)
			{
				AshParticle value = particles[i];
				ref Vector2 position = ref value.position;
				position += value.velocity * Time.deltaTime;
				if (value.position.x < 0f)
				{
					value.position.x += 1f;
				}
				if (value.position.x > 1f)
				{
					value.position.x -= 1f;
				}
				if (value.position.y < 0f)
				{
					value.position.y += 1f;
				}
				if (value.position.y > 1f)
				{
					value.position.y -= 1f;
				}
				ref Vector2 position2 = ref value.position;
				position2 += new Vector2(Random.Range(-0.001f, 0.001f), Random.Range(-0.001f, 0.001f));
				particles[i] = value;
			}
		}

		private void DrawParticles()
		{
			//IL_002f: 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_004d: 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_0096: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)particleTexture == (Object)null)
			{
				return;
			}
			foreach (AshParticle particle in particles)
			{
				GUI.color = particle.color;
				GUI.DrawTexture(new Rect(particle.position.x * (float)Screen.width, particle.position.y * (float)Screen.height, particle.size, particle.size), (Texture)(object)particleTexture);
			}
			GUI.color = Color.white;
		}

		[IteratorStateMachine(typeof(<LoadAndPlayMusic>d__27))]
		private IEnumerator LoadAndPlayMusic()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <LoadAndPlayMusic>d__27(0)
			{
				<>4__this = this
			};
		}
	}
	public class MimicController : MonoBehaviourPun
	{
		[CompilerGenerated]
		private sealed class <WaitForReady>d__4 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MimicController <>4__this;

			private float <t>5__1;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<t>5__1 = 0f;
					break;
				case 1:
					<>1__state = -1;
					<t>5__1 += Time.deltaTime;
					break;
				}
				if (<t>5__1 < 6f)
				{
					if ((Object)(object)<>4__this.physObject == (Object)null)
					{
						<>4__this.physObject = ((Component)<>4__this).GetComponent<PhysGrabObject>();
					}
					if ((Object)(object)<>4__this.physObject != (Object)null && ((Object)(object)<>4__this.physObject.rb != (Object)null || (Object)(object)((Component)<>4__this).GetComponent<Rigidbody>() != (Object)null))
					{
						<>4__this.ready = true;
						StrangeDoorsPlugin.Logger.LogInfo((object)("[StrangeDoor] Controller ready: " + ((Object)((Component)<>4__this).gameObject).name));
						return false;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				Object.Destroy((Object)(object)<>4__this);
				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();
			}
		}

		private PhysGrabHinge hinge;

		private PhysGrabObject physObject;

		private bool ready;

		private void Start()
		{
			hinge = ((Component)this).GetComponent<PhysGrabHinge>();
			physObject = ((Component)this).GetComponent<PhysGrabObject>();
			((MonoBehaviour)this).StartCoroutine(WaitForReady());
		}

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

		private void Update()
		{
			if (!ready)
			{
				return;
			}
			if (Input.GetKeyDown((KeyCode)282))
			{
				StrangeDoorsPlugin.Logger.LogInfo((object)"[StrangeDoor] Manual Trigger");
				TryTrigger(force: true);
			}
			else
			{
				if (StrangeDoorsPlugin.HasTriggeredThisLevel || (Object)(object)physObject == (Object)null || (!physObject.grabbed && !physObject.grabbedLocal && (physObject.playerGrabbing == null || physObject.playerGrabbing.Count <= 0)))
				{
					return;
				}
				if (physObject.playerGrabbing != null && physObject.playerGrabbing.Count > 0)
				{
					foreach (PhysGrabber item in physObject.playerGrabbing)
					{
						if ((Object)(object)item.playerAvatar != (Object)null && item.playerAvatar.isLocal)
						{
							TryTrigger();
							break;
						}
					}
					return;
				}
				if (physObject.grabbedLocal)
				{
					TryTrigger();
				}
			}
		}

		private void TryTrigger(bool force = false)
		{
			if (StrangeDoorsPlugin.HasTriggeredThisLevel && !force)
			{
				return;
			}
			StrangeDoorsPlugin.HasTriggeredThisLevel = true;
			StrangeDoorsPlugin.Logger.LogInfo((object)"[StrangeDoor] Triggered");
			if ((Object)(object)Camera.main != (Object)null)
			{
				MimicEffectPlayer mimicEffectPlayer = ((Component)Camera.main).GetComponent<MimicEffectPlayer>();
				if ((Object)(object)mimicEffectPlayer == (Object)null)
				{
					mimicEffectPlayer = ((Component)Camera.main).gameObject.AddComponent<MimicEffectPlayer>();
				}
				mimicEffectPlayer.TriggerSequence(StrangeDoorsPlugin.WaveDuration.Value, StrangeDoorsPlugin.FlipDuration.Value);
			}
			else
			{
				StrangeDoorsPlugin.Logger.LogWarning((object)"[StrangeDoor] No Main Camera found.");
			}
		}
	}
}