Decompiled source of PizzaTowerEscapeMusic ForkForMe v2.4.1

BepInEx/plugins/PizzaTowerEscapeMusic.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using PizzaTowerEscapeMusic.Scripting;
using PizzaTowerEscapeMusic.Scripting.Conditions;
using PizzaTowerEscapeMusic.Scripting.ScriptEvents;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(/*Could not decode attribute arguments.*/)]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("PizzaTowerEscapeMusic")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Plays music from Pizza Tower when the early ship leave alert appears")]
[assembly: AssemblyFileVersion("2.4.0.0")]
[assembly: AssemblyInformationalVersion("2.4.0")]
[assembly: AssemblyProduct("PizzaTowerEscapeMusic")]
[assembly: AssemblyTitle("PizzaTowerEscapeMusic")]
[assembly: SecurityPermission(8, SkipVerification = true)]
[assembly: AssemblyVersion("2.4.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

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

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(/*Could not decode attribute arguments.*/)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace PizzaTowerEscapeMusic
{
	public class Configuration : Object
	{
		private readonly ConfigFile config;

		internal ConfigEntry<float> volumeMaster;

		internal ConfigEntry<string> scriptingScripts;

		public Configuration(ConfigFile config)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			this.config = config;
			scriptingScripts = config.Bind<string>("Scripting", "Scripts", "Default", new ConfigDescription("The names of the JSON script files that will be loaded (Separated by commas, do not put a space after the commas)", (AcceptableValueBase)null, Array.Empty<object>()));
			volumeMaster = config.Bind<float>("Volume", "Master", 0.5f, new ConfigDescription("The volume of the music as a whole, all volumes are scaled by this value", (AcceptableValueBase)null, Array.Empty<object>()));
			RemoveObsoleteEntries();
		}

		private void RemoveObsoleteEntry(string section, string key)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ConfigDefinition val = new ConfigDefinition(section, key);
			config.Bind<string>(val, "", (ConfigDescription)null);
			config.Remove(val);
		}

		private void ReplaceObsoleteEntry<T>(string section, string key, ConfigEntry<T> replacement)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			ConfigDefinition val = new ConfigDefinition(section, key);
			ConfigEntry<T> val2 = config.Bind<T>(val, (T)((ConfigEntryBase)replacement).DefaultValue, (ConfigDescription)null);
			if (!EqualityComparer<T>.Default.Equals(val2.Value, (T)((ConfigEntryBase)replacement).DefaultValue))
			{
				replacement.Value = val2.Value;
			}
			config.Remove(val);
		}

		private void RemoveObsoleteEntries()
		{
			RemoveObsoleteEntry("Volume", "InsideFacility");
			RemoveObsoleteEntry("Volume", "OutsideFacility");
			RemoveObsoleteEntry("Volume", "InsideShip");
			RemoveObsoleteEntry("Volume", "CrouchingScale");
			RemoveObsoleteEntry("Music", "InsideFacility");
			RemoveObsoleteEntry("Music", "OutsideFacility");
			RemoveObsoleteEntry("Music", "HeavyWeather");
			ReplaceObsoleteEntry<string>("Scripting", "Script", scriptingScripts);
			config.Save();
		}
	}
	internal static class CustomManager : Object
	{
		public static string GetFilePath(string path, string fallbackPath)
		{
			string[] directories = Directory.GetDirectories(Paths.PluginPath);
			for (int i = 0; i < directories.Length; i++)
			{
				string text = String.Concat(directories[i], "/BGN-PizzaTowerEscapeMusic/", path);
				if (File.Exists(text))
				{
					return text;
				}
			}
			string text2 = String.Concat(Paths.PluginPath, "/BGN-PizzaTowerEscapeMusic_Custom/", path);
			if (File.Exists(text2))
			{
				return text2;
			}
			return String.Concat(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "/", fallbackPath);
		}
	}
	public class GameEventListener : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c : Object
		{
			public static readonly <>c <>9 = new <>c();

			public static Action <>9__35_0;

			public static Action <>9__35_1;

			public static Action <>9__35_2;

			public static Action <>9__35_3;

			public static Action <>9__35_4;

			public static Action <>9__35_5;

			public static Action <>9__35_6;

			public static Action <>9__35_7;

			public static Action <>9__35_8;

			public static Action <>9__35_9;

			public static Action <>9__35_10;

			public static Action <>9__35_11;

			public static Action <>9__35_12;

			public static Action <>9__35_13;

			public static Action <>9__35_14;

			public static Action<SelectableLevel?> <>9__35_15;

			internal void <.ctor>b__35_0()
			{
			}

			internal void <.ctor>b__35_1()
			{
			}

			internal void <.ctor>b__35_2()
			{
			}

			internal void <.ctor>b__35_3()
			{
			}

			internal void <.ctor>b__35_4()
			{
			}

			internal void <.ctor>b__35_5()
			{
			}

			internal void <.ctor>b__35_6()
			{
			}

			internal void <.ctor>b__35_7()
			{
			}

			internal void <.ctor>b__35_8()
			{
			}

			internal void <.ctor>b__35_9()
			{
			}

			internal void <.ctor>b__35_10()
			{
			}

			internal void <.ctor>b__35_11()
			{
			}

			internal void <.ctor>b__35_12()
			{
			}

			internal void <.ctor>b__35_13()
			{
			}

			internal void <.ctor>b__35_14()
			{
			}

			internal void <.ctor>b__35_15(SelectableLevel? l)
			{
			}
		}

		private ManualLogSource logger;

		public Action OnFrameUpdate;

		public Action OnSoundManagerCreated;

		public Action OnSoundManagerDestroyed;

		public Action OnDungeonDoneGenerating;

		public Action OnShipLanded;

		public Action OnShipTakeOff;

		public Action OnShipReturnToOrbit;

		public Action OnShipLeavingAlertCalled;

		public Action OnPlayerDamaged;

		public Action OnPlayerDeath;

		public Action OnPlayerEnteredFacility;

		public Action OnPlayerExitedFacility;

		public Action OnPlayerEnteredShip;

		public Action OnPlayerExitedShip;

		public Action OnApparatusTaken;

		public Action<SelectableLevel?> OnCurrentMoonChanged;

		private readonly Dictionary<string, object?> previousValues;

		private static LungProp? dockedApparatus;

		private void Awake()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			logger = Logger.CreateLogSource("PizzaTowerEscapeMusic GameEventListener");
			OnShipLanded = (Action)Delegate.Combine((Delegate)(object)OnShipLanded, (Delegate)new Action(FindDockedApparatus));
		}

		private void FindDockedApparatus()
		{
			logger.LogDebug((object)"Checking for docked Apparatus...");
			LungProp[] array = Object.FindObjectsOfType<LungProp>();
			foreach (LungProp val in array)
			{
				if (val.isLungDocked)
				{
					logger.LogDebug((object)"Found docked Apparatus");
					dockedApparatus = val;
					return;
				}
			}
			logger.LogDebug((object)"Could not find docked Apparatus");
		}

		public static bool IsApparatusDocked()
		{
			return (Object)(object)dockedApparatus != (Object)null;
		}

		private void Update()
		{
			if ((Object)(object)SoundManager.Instance != (Object)null)
			{
				OnFrameUpdate.Invoke();
			}
			CheckSoundManager();
			CheckDungeonDoneGenerating();
			CheckShipLanded();
			CheckShipReturnToOrbit();
			CheckShipLeavingAlertCalled();
			CheckPlayerDamaged();
			CheckPlayerDeath();
			CheckPlayerInsideFacility();
			CheckPlayerInsideShip();
			CheckApparatusTaken();
			CheckCurrentMoonChanged();
		}

		private T? UpdateCached<T>(string key, T? currentValue, T? defaultValue)
		{
			object obj = default(object);
			if (!previousValues.TryGetValue(key, ref obj))
			{
				obj = defaultValue;
			}
			previousValues[key] = currentValue;
			return (T)obj;
		}

		private void CheckSoundManager()
		{
			bool flag = (Object)(object)SoundManager.Instance != (Object)null;
			if (UpdateCached("SoundManager", flag, defaultValue: false) != flag)
			{
				if (flag)
				{
					logger.LogDebug((object)"Sound Manager created");
					OnSoundManagerCreated.Invoke();
				}
				else
				{
					logger.LogDebug((object)"Sound Manager destroyed");
					OnSoundManagerDestroyed.Invoke();
				}
			}
		}

		private void CheckDungeonDoneGenerating()
		{
			bool flag = (Object)(object)RoundManager.Instance != (Object)null && RoundManager.Instance.dungeonCompletedGenerating;
			bool flag2 = UpdateCached("DungeonDoneGenerating", flag, defaultValue: false);
			if (flag != flag2 && flag)
			{
				logger.LogDebug((object)"Dungeon done generating");
				OnDungeonDoneGenerating.Invoke();
			}
		}

		private void CheckShipLanded()
		{
			bool flag = (Object)(object)StartOfRound.Instance != (Object)null && StartOfRound.Instance.shipHasLanded;
			bool flag2 = UpdateCached("ShipLanded", flag, defaultValue: true);
			if (flag != flag2 && !((Object)(object)StartOfRound.Instance == (Object)null))
			{
				if (flag)
				{
					logger.LogDebug((object)"Ship has landed");
					OnShipLanded.Invoke();
				}
				else
				{
					logger.LogDebug((object)"Ship has taken off");
					OnShipTakeOff.Invoke();
				}
			}
		}

		private void CheckShipReturnToOrbit()
		{
			bool flag = (Object)(object)StartOfRound.Instance == (Object)null || (!StartOfRound.Instance.shipHasLanded && !StartOfRound.Instance.shipIsLeaving);
			bool flag2 = UpdateCached("ShipReturnToOrbit", flag, defaultValue: true);
			if (flag != flag2 && flag)
			{
				logger.LogDebug((object)"Ship returned to orbit");
				OnShipReturnToOrbit.Invoke();
			}
		}

		private void CheckShipLeavingAlertCalled()
		{
			bool flag = (Object)(object)TimeOfDay.Instance != (Object)null && TimeOfDay.Instance.shipLeavingAlertCalled;
			bool flag2 = UpdateCached("ShipLeavingAlertCalled", flag, defaultValue: false);
			if (flag != flag2 && flag)
			{
				logger.LogDebug((object)"Ship leaving alert called");
				OnShipLeavingAlertCalled.Invoke();
			}
		}

		private void CheckPlayerDamaged()
		{
			if (!((Object)(object)GameNetworkManager.Instance == (Object)null) && !((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null))
			{
				int health = GameNetworkManager.Instance.localPlayerController.health;
				int num = UpdateCached("PlayerDamaged", health, 100);
				if (health < num)
				{
					logger.LogDebug((object)String.Format("Player took damage (Health: {0})", (object)GameNetworkManager.Instance.localPlayerController.health));
					OnPlayerDamaged.Invoke();
				}
			}
		}

		private void CheckPlayerDeath()
		{
			bool flag = (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && GameNetworkManager.Instance.localPlayerController.isPlayerDead;
			bool flag2 = UpdateCached("PlayerDeath", flag, defaultValue: false);
			if (flag != flag2 && flag)
			{
				logger.LogDebug((object)"Player has died");
				OnPlayerDeath.Invoke();
			}
		}

		private void CheckPlayerInsideFacility()
		{
			bool flag = (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && GameNetworkManager.Instance.localPlayerController.isInsideFactory;
			bool flag2 = UpdateCached("PlayerInsideFacility", flag, defaultValue: false);
			if (flag != flag2)
			{
				if (flag)
				{
					logger.LogDebug((object)"Player entered facility");
					OnPlayerEnteredFacility.Invoke();
				}
				else
				{
					logger.LogDebug((object)"Player exited facility");
					OnPlayerExitedFacility.Invoke();
				}
			}
		}

		private void CheckPlayerInsideShip()
		{
			bool flag = (Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null && GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom;
			bool flag2 = UpdateCached("PlayerInsideShip", flag, defaultValue: false);
			if (flag != flag2)
			{
				if (flag)
				{
					logger.LogDebug((object)"Player entered ship");
					OnPlayerEnteredShip.Invoke();
				}
				else
				{
					logger.LogDebug((object)"Player exited ship");
					OnPlayerExitedShip.Invoke();
				}
			}
		}

		private void CheckApparatusTaken()
		{
			bool flag = (Object)(object)dockedApparatus != (Object)null && !dockedApparatus.isLungDocked;
			bool flag2 = UpdateCached("ApparatusTaken", flag, defaultValue: false);
			if (flag != flag2 && flag)
			{
				dockedApparatus = null;
				logger.LogDebug((object)"Apparatus was taken");
				OnApparatusTaken.Invoke();
			}
		}

		private void CheckCurrentMoonChanged()
		{
			SelectableLevel val = TimeOfDay.Instance?.currentLevel;
			SelectableLevel val2 = UpdateCached<SelectableLevel>("CurrentMoon", val, null);
			if (!((Object)(object)val == (Object)(object)val2))
			{
				logger.LogDebug((object)String.Concat("Level has changed to ", val?.PlanetName));
				OnCurrentMoonChanged.Invoke(val);
			}
		}

		public GameEventListener()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_005f: 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_006a: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Expected O, but got Unknown
			//IL_00a9: 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_00b4: Expected O, but got Unknown
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Expected O, but got Unknown
			//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_0123: Expected O, but got Unknown
			//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_0148: Expected O, but got Unknown
			//IL_0162: 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_016d: Expected O, but got Unknown
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Expected O, but got Unknown
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Expected O, but got Unknown
			//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_0226: Expected O, but got Unknown
			object obj = <>c.<>9__35_0;
			if (obj == null)
			{
				Action val = delegate
				{
				};
				<>c.<>9__35_0 = val;
				obj = (object)val;
			}
			OnFrameUpdate = (Action)obj;
			object obj2 = <>c.<>9__35_1;
			if (obj2 == null)
			{
				Action val2 = delegate
				{
				};
				<>c.<>9__35_1 = val2;
				obj2 = (object)val2;
			}
			OnSoundManagerCreated = (Action)obj2;
			object obj3 = <>c.<>9__35_2;
			if (obj3 == null)
			{
				Action val3 = delegate
				{
				};
				<>c.<>9__35_2 = val3;
				obj3 = (object)val3;
			}
			OnSoundManagerDestroyed = (Action)obj3;
			object obj4 = <>c.<>9__35_3;
			if (obj4 == null)
			{
				Action val4 = delegate
				{
				};
				<>c.<>9__35_3 = val4;
				obj4 = (object)val4;
			}
			OnDungeonDoneGenerating = (Action)obj4;
			object obj5 = <>c.<>9__35_4;
			if (obj5 == null)
			{
				Action val5 = delegate
				{
				};
				<>c.<>9__35_4 = val5;
				obj5 = (object)val5;
			}
			OnShipLanded = (Action)obj5;
			object obj6 = <>c.<>9__35_5;
			if (obj6 == null)
			{
				Action val6 = delegate
				{
				};
				<>c.<>9__35_5 = val6;
				obj6 = (object)val6;
			}
			OnShipTakeOff = (Action)obj6;
			object obj7 = <>c.<>9__35_6;
			if (obj7 == null)
			{
				Action val7 = delegate
				{
				};
				<>c.<>9__35_6 = val7;
				obj7 = (object)val7;
			}
			OnShipReturnToOrbit = (Action)obj7;
			object obj8 = <>c.<>9__35_7;
			if (obj8 == null)
			{
				Action val8 = delegate
				{
				};
				<>c.<>9__35_7 = val8;
				obj8 = (object)val8;
			}
			OnShipLeavingAlertCalled = (Action)obj8;
			object obj9 = <>c.<>9__35_8;
			if (obj9 == null)
			{
				Action val9 = delegate
				{
				};
				<>c.<>9__35_8 = val9;
				obj9 = (object)val9;
			}
			OnPlayerDamaged = (Action)obj9;
			object obj10 = <>c.<>9__35_9;
			if (obj10 == null)
			{
				Action val10 = delegate
				{
				};
				<>c.<>9__35_9 = val10;
				obj10 = (object)val10;
			}
			OnPlayerDeath = (Action)obj10;
			object obj11 = <>c.<>9__35_10;
			if (obj11 == null)
			{
				Action val11 = delegate
				{
				};
				<>c.<>9__35_10 = val11;
				obj11 = (object)val11;
			}
			OnPlayerEnteredFacility = (Action)obj11;
			object obj12 = <>c.<>9__35_11;
			if (obj12 == null)
			{
				Action val12 = delegate
				{
				};
				<>c.<>9__35_11 = val12;
				obj12 = (object)val12;
			}
			OnPlayerExitedFacility = (Action)obj12;
			object obj13 = <>c.<>9__35_12;
			if (obj13 == null)
			{
				Action val13 = delegate
				{
				};
				<>c.<>9__35_12 = val13;
				obj13 = (object)val13;
			}
			OnPlayerEnteredShip = (Action)obj13;
			object obj14 = <>c.<>9__35_13;
			if (obj14 == null)
			{
				Action val14 = delegate
				{
				};
				<>c.<>9__35_13 = val14;
				obj14 = (object)val14;
			}
			OnPlayerExitedShip = (Action)obj14;
			object obj15 = <>c.<>9__35_14;
			if (obj15 == null)
			{
				Action val15 = delegate
				{
				};
				<>c.<>9__35_14 = val15;
				obj15 = (object)val15;
			}
			OnApparatusTaken = (Action)obj15;
			OnCurrentMoonChanged = delegate
			{
			};
			previousValues = new Dictionary<string, object>();
			((MonoBehaviour)this)..ctor();
		}
	}
	public class MusicManager : MonoBehaviour
	{
		private class MusicInstance : Object
		{
			public Script script;

			public ScriptEvent_PlayMusic musicEvent;

			public AudioSource audioSource;

			public Script.VolumeGroup volumeGroup;

			private bool isStopping;

			private float volume;

			[field: CompilerGenerated]
			public float FadeSpeed
			{
				[CompilerGenerated]
				get;
				[CompilerGenerated]
				private set;
			}

			public MusicInstance(Script script, ScriptEvent_PlayMusic musicEvent, AudioSource audioSource, AudioClip? musicClip)
			{
				this.script = script;
				this.musicEvent = musicEvent;
				this.audioSource = audioSource;
				audioSource.clip = musicClip;
				audioSource.loop = musicEvent.loop;
				audioSource.Play();
				musicInstances.Add(this);
				if (musicEvent.tag != null)
				{
					List<MusicInstance> val = default(List<MusicInstance>);
					if (!musicInstancesByTag.TryGetValue(musicEvent.tag, ref val))
					{
						val = new List<MusicInstance>(1);
						musicInstancesByTag.Add(musicEvent.tag, val);
					}
					val.Add(this);
				}
				volumeGroup = script.TryGetVolumeGroupOrDefault(musicEvent.tag);
				volume = volumeGroup.GetVolume(script);
			}

			public void Update(float deltaTime)
			{
				float num = (isStopping ? 0f : volumeGroup.GetVolume(script));
				float num2 = (isStopping ? volumeGroup.stoppingVolumeLerpSpeed : volumeGroup.volumeLerpSpeed);
				volume = Mathf.Lerp(volume, num, num2 * deltaTime);
				audioSource.volume = volume * PizzaTowerEscapeMusicManager.Configuration.volumeMaster.Value;
				if (!audioSource.isPlaying || (isStopping && audioSource.volume < 0.005f))
				{
					StopCompletely();
				}
			}

			public void FadeStop()
			{
				if (!isStopping)
				{
					isStopping = true;
					FadeSpeed = volumeGroup.stoppingVolumeLerpSpeed;
				}
			}

			public void StopCompletely()
			{
				audioSource.Stop();
				audioSourcePool.Push(audioSource);
				musicInstances.Remove(this);
				List<MusicInstance> val = default(List<MusicInstance>);
				if (musicEvent.tag != null && musicInstancesByTag.TryGetValue(musicEvent.tag, ref val))
				{
					val.Remove(this);
				}
			}
		}

		[StructLayout(3)]
		[CompilerGenerated]
		private struct <LoadMusicClip>d__15 : ValueType, IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncTaskMethodBuilder<AudioClip> <>t__builder;

			public MusicManager <>4__this;

			public string musicFileName;

			private AudioType <audioType>5__2;

			private string <path>5__3;

			private UnityWebRequest <request>5__4;

			private TaskAwaiter <>u__1;

			private void MoveNext()
			{
				//IL_01a9: Expected O, but got Unknown
				//IL_0058: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: 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_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f1: Invalid comparison between Unknown and I4
				//IL_009a: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Unknown result type (might be due to invalid IL or missing references)
				//IL_014a: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				MusicManager musicManager = <>4__this;
				AudioClip result;
				try
				{
					if (num != 0)
					{
						musicManager.InterpretMusicFileName(musicFileName, out <audioType>5__2, out string finalFileName);
						<path>5__3 = String.Concat("file:///", CustomManager.GetFilePath(String.Concat("Music/", finalFileName), String.Concat("DefaultMusic/", finalFileName)));
						<request>5__4 = UnityWebRequestMultimedia.GetAudioClip(<path>5__3, <audioType>5__2);
					}
					try
					{
						if (num != 0)
						{
							<request>5__4.SendWebRequest();
							goto IL_00d8;
						}
						TaskAwaiter awaiter = <>u__1;
						<>u__1 = default(TaskAwaiter);
						num = (<>1__state = -1);
						goto IL_00d1;
						IL_00d1:
						((TaskAwaiter)(ref awaiter)).GetResult();
						goto IL_00d8;
						IL_00d8:
						if (!<request>5__4.isDone)
						{
							awaiter = Task.Delay(50).GetAwaiter();
							if (!((TaskAwaiter)(ref awaiter)).IsCompleted)
							{
								num = (<>1__state = 0);
								<>u__1 = awaiter;
								<>t__builder.AwaitUnsafeOnCompleted<TaskAwaiter, <LoadMusicClip>d__15>(ref awaiter, ref this);
								return;
							}
							goto IL_00d1;
						}
						if ((int)<request>5__4.result == 1)
						{
							musicManager.logger.LogInfo((object)String.Concat("Loaded music (", musicFileName, ") from file"));
							AudioClip content = DownloadHandlerAudioClip.GetContent(<request>5__4);
							((Object)content).name = musicFileName;
							result = content;
						}
						else
						{
							musicManager.logger.LogError((object)String.Concat((string[])(object)new String[5]
							{
								String.Format("Failed to load music ({0}) from file as audio type {1}, if the file extension and the audio type do not match the file extension may not be supported.", (object)musicFileName, (object)<audioType>5__2),
								"\n- Path: ",
								<path>5__3,
								"\n- Error: ",
								<request>5__4.error
							}));
							result = null;
						}
					}
					finally
					{
						if (num < 0 && <request>5__4 != null)
						{
							((IDisposable)<request>5__4).Dispose();
						}
					}
				}
				catch (Exception val)
				{
					Exception exception = val;
					<>1__state = -2;
					<path>5__3 = null;
					<request>5__4 = null;
					<>t__builder.SetException(exception);
					return;
				}
				<>1__state = -2;
				<path>5__3 = null;
				<request>5__4 = null;
				<>t__builder.SetResult(result);
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				<>t__builder.SetStateMachine(stateMachine);
			}
		}

		[StructLayout(3)]
		[CompilerGenerated]
		private struct <LoadNecessaryMusicClips>d__13 : ValueType, IAsyncStateMachine
		{
			public int <>1__state;

			public AsyncVoidMethodBuilder <>t__builder;

			public MusicManager <>4__this;

			private Enumerator<Script> <>7__wrap1;

			private ScriptEvent[] <>7__wrap2;

			private int <>7__wrap3;

			private string[] <>7__wrap4;

			private int <>7__wrap5;

			private string <musicName>5__7;

			private TaskAwaiter<AudioClip?> <>u__1;

			private void MoveNext()
			{
				//IL_01fe: Expected O, but got Unknown
				//IL_0048: 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_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)
				//IL_012a: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_0102: 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)
				int num = <>1__state;
				MusicManager musicManager = <>4__this;
				try
				{
					if (num == 0)
					{
						goto IL_0053;
					}
					if (PizzaTowerEscapeMusicManager.ScriptManager.loadedScripts.Count != 0)
					{
						musicManager.UnloadMusicClips();
						<>7__wrap1 = PizzaTowerEscapeMusicManager.ScriptManager.loadedScripts.GetEnumerator();
						goto IL_0053;
					}
					musicManager.logger.LogError((object)"No scripts are loaded, cannot load their music!");
					goto end_IL_000e;
					IL_0053:
					try
					{
						if (num != 0)
						{
							goto IL_01b6;
						}
						TaskAwaiter<AudioClip> awaiter = <>u__1;
						<>u__1 = default(TaskAwaiter<AudioClip>);
						num = (<>1__state = -1);
						goto IL_0139;
						IL_018e:
						<>7__wrap3++;
						goto IL_019c;
						IL_0139:
						AudioClip result = awaiter.GetResult();
						if (!((Object)(object)result == (Object)null))
						{
							musicManager.loadedMusic.Add(<musicName>5__7, result);
							<musicName>5__7 = null;
						}
						goto IL_0166;
						IL_019c:
						if (<>7__wrap3 < <>7__wrap2.Length)
						{
							if (<>7__wrap2[<>7__wrap3] is ScriptEvent_PlayMusic scriptEvent_PlayMusic)
							{
								<>7__wrap4 = scriptEvent_PlayMusic.musicNames;
								<>7__wrap5 = 0;
								goto IL_0174;
							}
							goto IL_018e;
						}
						<>7__wrap2 = null;
						goto IL_01b6;
						IL_0166:
						<>7__wrap5++;
						goto IL_0174;
						IL_0174:
						if (<>7__wrap5 < <>7__wrap4.Length)
						{
							<musicName>5__7 = <>7__wrap4[<>7__wrap5];
							if (!musicManager.loadedMusic.ContainsKey(<musicName>5__7))
							{
								awaiter = musicManager.LoadMusicClip(<musicName>5__7).GetAwaiter();
								if (!awaiter.IsCompleted)
								{
									num = (<>1__state = 0);
									<>u__1 = awaiter;
									((AsyncVoidMethodBuilder)(ref <>t__builder)).AwaitUnsafeOnCompleted<TaskAwaiter<AudioClip>, <LoadNecessaryMusicClips>d__13>(ref awaiter, ref this);
									return;
								}
								goto IL_0139;
							}
							goto IL_0166;
						}
						<>7__wrap4 = null;
						goto IL_018e;
						IL_01b6:
						if (<>7__wrap1.MoveNext())
						{
							Script current = <>7__wrap1.Current;
							<>7__wrap2 = current.scriptEvents;
							<>7__wrap3 = 0;
							goto IL_019c;
						}
					}
					finally
					{
						if (num < 0)
						{
							((IDisposable)<>7__wrap1).Dispose();
						}
					}
					<>7__wrap1 = default(Enumerator<Script>);
					musicManager.logger.LogInfo((object)"Music clips done loading");
					end_IL_000e:;
				}
				catch (Exception val)
				{
					Exception exception = val;
					<>1__state = -2;
					((AsyncVoidMethodBuilder)(ref <>t__builder)).SetException(exception);
					return;
				}
				<>1__state = -2;
				((AsyncVoidMethodBuilder)(ref <>t__builder)).SetResult();
			}

			[DebuggerHidden]
			private void SetStateMachine(IAsyncStateMachine stateMachine)
			{
				((AsyncVoidMethodBuilder)(ref <>t__builder)).SetStateMachine(stateMachine);
			}
		}

		private ManualLogSource logger;

		private static readonly List<MusicInstance> musicInstances = new List<MusicInstance>();

		private static readonly Dictionary<string, List<MusicInstance>> musicInstancesByTag = new Dictionary<string, List<MusicInstance>>();

		private static readonly Stack<AudioSource> audioSourcePool = new Stack<AudioSource>();

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

		private void Awake()
		{
			logger = Logger.CreateLogSource("PizzaTowerEscapeMusic MusicManager");
		}

		private void Update()
		{
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return;
			}
			for (int num = musicInstances.Count - 1; num >= 0; num--)
			{
				musicInstances[num].Update(Time.deltaTime);
			}
			bool flag = false;
			Enumerator<MusicInstance> enumerator = musicInstances.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.musicEvent.silenceGameMusic)
					{
						flag = true;
						break;
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			if (flag)
			{
				if (SoundManager.Instance.playingOutsideMusic && GetIsMusicPlaying())
				{
					SoundManager.Instance.playingOutsideMusic = false;
					logger.LogInfo((object)"Silenced the outside music because alternate music is playing");
				}
				if (TimeOfDay.Instance.TimeOfDayMusic.isPlaying && GetIsMusicPlaying())
				{
					TimeOfDay.Instance.TimeOfDayMusic.Stop();
					logger.LogInfo((object)"Silenced the time of day music because alternate music is playing");
				}
			}
		}

		public bool GetIsMusicPlaying(string? tag = null)
		{
			if (tag == null)
			{
				return musicInstances.Count > 0;
			}
			List<MusicInstance> val = default(List<MusicInstance>);
			if (musicInstancesByTag.TryGetValue(tag, ref val))
			{
				logger.LogDebug((object)String.Format("GetIsMusicPlaying says there's {0} music instance(s) with the tag \"{1}\"", (object)val.Count, (object)tag));
				return val.Count > 0;
			}
			logger.LogDebug((object)String.Concat("GetIsMusicPlaying says there was no music instance list for tag \"", tag, "\""));
			return false;
		}

		public void PlayMusic(Script script, ScriptEvent_PlayMusic musicEvent)
		{
			logger.LogDebug((object)String.Concat((string[])(object)new String[5]
			{
				"PlayMusic called\nTag:                         ",
				musicEvent.tag,
				String.Format("\nOverlap handling:            {0}", (object)musicEvent.overlapHandling),
				String.Format("\nAny music playing?:          {0}", (object)GetIsMusicPlaying()),
				String.Format("\nAny music playing with tag?: {0}", (object)GetIsMusicPlaying(musicEvent.tag))
			}));
			if (musicEvent.overlapHandling == ScriptEvent_PlayMusic.OverlapHandling.IgnoreAll && GetIsMusicPlaying())
			{
				logger.LogDebug((object)"PlayMusic canceled because other music was playing");
				return;
			}
			if (musicEvent.overlapHandling == ScriptEvent_PlayMusic.OverlapHandling.IgnoreTag && GetIsMusicPlaying(musicEvent.tag))
			{
				logger.LogDebug((object)String.Concat("PlayMusic canceled because other music with the tag \"", musicEvent.tag, "\" was playing"));
				return;
			}
			switch (musicEvent.overlapHandling)
			{
			case ScriptEvent_PlayMusic.OverlapHandling.OverrideAll:
				StopMusic();
				break;
			case ScriptEvent_PlayMusic.OverlapHandling.OverrideTag:
				StopMusic(musicEvent.tag);
				break;
			case ScriptEvent_PlayMusic.OverlapHandling.OverrideFadeAll:
				FadeStopMusic();
				break;
			case ScriptEvent_PlayMusic.OverlapHandling.OverrideFadeTag:
				FadeStopMusic(musicEvent.tag);
				break;
			}
			string text = musicEvent.musicNames[Random.Range(0, musicEvent.musicNames.Length)];
			AudioClip val = default(AudioClip);
			loadedMusic.TryGetValue(text, ref val);
			if ((Object)(object)val != (Object)null)
			{
				new MusicInstance(script, musicEvent, GetAudioSource(), val);
				logger.LogInfo((object)String.Concat("Playing music (", text, ")"));
			}
			else
			{
				logger.LogWarning((object)String.Concat("Music (", text, ") is null, cannot play. Maybe it wasn't loaded correctly?"));
			}
		}

		public void StopMusic(string? targetTag = null)
		{
			//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)
			Enumerator<MusicInstance> enumerator = new List<MusicInstance>((IEnumerable<MusicInstance>)(object)musicInstances).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MusicInstance current = enumerator.Current;
					if (targetTag == null || !(current.musicEvent.tag != targetTag))
					{
						current.StopCompletely();
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void FadeStopMusic(string? targetTag = null)
		{
			//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)
			Enumerator<MusicInstance> enumerator = new List<MusicInstance>((IEnumerable<MusicInstance>)(object)musicInstances).GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					MusicInstance current = enumerator.Current;
					if (targetTag == null || !(current.musicEvent.tag != targetTag))
					{
						current.FadeStop();
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		private AudioSource GetAudioSource()
		{
			AudioSource result = default(AudioSource);
			if (!audioSourcePool.TryPop(ref result))
			{
				return ((Component)this).gameObject.AddComponent<AudioSource>();
			}
			return result;
		}

		[AsyncStateMachine(/*Could not decode attribute arguments.*/)]
		public void LoadNecessaryMusicClips()
		{
			//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)
			<LoadNecessaryMusicClips>d__13 <LoadNecessaryMusicClips>d__ = default(<LoadNecessaryMusicClips>d__13);
			<LoadNecessaryMusicClips>d__.<>t__builder = AsyncVoidMethodBuilder.Create();
			<LoadNecessaryMusicClips>d__.<>4__this = this;
			<LoadNecessaryMusicClips>d__.<>1__state = -1;
			((AsyncVoidMethodBuilder)(ref <LoadNecessaryMusicClips>d__.<>t__builder)).Start<<LoadNecessaryMusicClips>d__13>(ref <LoadNecessaryMusicClips>d__);
		}

		public void UnloadMusicClips()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<string, AudioClip> enumerator = loadedMusic.Values.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					enumerator.Current.UnloadAudioData();
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
			loadedMusic.Clear();
			logger.LogInfo((object)"All music clips unloaded");
		}

		[AsyncStateMachine(/*Could not decode attribute arguments.*/)]
		private Task<AudioClip?> LoadMusicClip(string musicFileName)
		{
			//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)
			<LoadMusicClip>d__15 <LoadMusicClip>d__ = default(<LoadMusicClip>d__15);
			<LoadMusicClip>d__.<>t__builder = AsyncTaskMethodBuilder<AudioClip>.Create();
			<LoadMusicClip>d__.<>4__this = this;
			<LoadMusicClip>d__.musicFileName = musicFileName;
			<LoadMusicClip>d__.<>1__state = -1;
			<LoadMusicClip>d__.<>t__builder.Start<<LoadMusicClip>d__15>(ref <LoadMusicClip>d__);
			return <LoadMusicClip>d__.<>t__builder.Task;
		}

		private void InterpretMusicFileName(string musicFileName, out AudioType audioType, out string finalFileName)
		{
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected I4, but got Unknown
			//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)
			if (!musicFileName.Contains('.'))
			{
				audioType = (AudioType)20;
				finalFileName = String.Concat(musicFileName, ".wav");
				return;
			}
			string text = Enumerable.Last<string>((IEnumerable<string>)(object)musicFileName.Split('.', (StringSplitOptions)0)).ToLower();
			AudioType val = ((text == "ogg") ? ((AudioType)14) : ((!(text == "mp3")) ? ((AudioType)20) : ((AudioType)13)));
			audioType = (AudioType)(int)val;
			finalFileName = musicFileName;
		}
	}
	public class PizzaTowerEscapeMusicManager : MonoBehaviour
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c : Object
		{
			public static readonly <>c <>9 = new <>c();

			public static Action <>9__14_0;

			internal void <Initialise>b__14_0()
			{
				MusicManager.StopMusic();
			}
		}

		private GameEventListener gameEventListener;

		private ManualLogSource logger;

		[field: CompilerGenerated]
		public static Configuration Configuration
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		[field: CompilerGenerated]
		public static ScriptManager ScriptManager
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		[field: CompilerGenerated]
		public static MusicManager MusicManager
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		public void Initialise(ManualLogSource logger, ConfigFile config)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Expected O, but got Unknown
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Expected O, but got Unknown
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Expected O, but got Unknown
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Expected O, but got Unknown
			this.logger = logger;
			Configuration = new Configuration(config);
			MusicManager = ((Component)this).gameObject.AddComponent<MusicManager>();
			gameEventListener = ((Component)this).gameObject.AddComponent<GameEventListener>();
			GameEventListener obj = gameEventListener;
			obj.OnSoundManagerCreated = (Action)Delegate.Combine((Delegate)(object)obj.OnSoundManagerCreated, (Delegate)new Action(MusicManager.LoadNecessaryMusicClips));
			GameEventListener obj2 = gameEventListener;
			Action onSoundManagerDestroyed = obj2.OnSoundManagerDestroyed;
			object obj3 = <>c.<>9__14_0;
			if (obj3 == null)
			{
				Action val = delegate
				{
					MusicManager.StopMusic();
				};
				<>c.<>9__14_0 = val;
				obj3 = (object)val;
			}
			obj2.OnSoundManagerDestroyed = (Action)Delegate.Combine((Delegate)(object)onSoundManagerDestroyed, (Delegate)obj3);
			GameEventListener obj4 = gameEventListener;
			obj4.OnSoundManagerDestroyed = (Action)Delegate.Combine((Delegate)(object)obj4.OnSoundManagerDestroyed, (Delegate)new Action(MusicManager.UnloadMusicClips));
			ScriptManager = new ScriptManager(Configuration.scriptingScripts.Value.Split(',', (StringSplitOptions)0), gameEventListener);
			GameEventListener obj5 = gameEventListener;
			obj5.OnSoundManagerDestroyed = (Action)Delegate.Combine((Delegate)(object)obj5.OnSoundManagerDestroyed, (Delegate)new Action(ScriptManager.ClearAllScriptTimers));
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			logger.LogInfo((object)"Plugin bgn.pizzatowerescapemusic is loaded!");
		}

		private void Update()
		{
			ScriptManager.UpdateAllScriptTimers(Time.deltaTime);
		}
	}
	[BepInPlugin("bgn.pizzatowerescapemusic", "PizzaTowerEscapeMusic", "2.4.1")]
	[BepInProcess("Lethal Company.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string GUID = "bgn.pizzatowerescapemusic";

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("PizzaTowerEscapeMusic Manager");
			val.AddComponent<PizzaTowerEscapeMusicManager>().Initialise(((BaseUnityPlugin)this).Logger, ((BaseUnityPlugin)this).Config);
			((Object)val).hideFlags = (HideFlags)61;
		}
	}
	public static class PluginInfo : Object
	{
		public const string PLUGIN_GUID = "PizzaTowerEscapeMusic";

		public const string PLUGIN_NAME = "PizzaTowerEscapeMusic";

		public const string PLUGIN_VERSION = "2.4.0";
	}
}
namespace PizzaTowerEscapeMusic.Scripting
{
	public class Script : Object
	{
		public class VolumeRule : Object
		{
			public string comment = String.Empty;

			[JsonRequired]
			public float volume;

			public Condition? condition;
		}

		public class VolumeModifier : Object
		{
			public string comment = String.Empty;

			[JsonRequired]
			public float volumeScale;

			public Condition? condition;
		}

		public class VolumeGroup : Object
		{
			public string comment = String.Empty;

			public string tag = String.Empty;

			public float volumeLerpSpeed = 1f;

			public float stoppingVolumeLerpSpeed = 1f;

			public float masterVolume = 1f;

			public VolumeRule[] volumeRules = Array.Empty<VolumeRule>();

			public VolumeModifier[] volumeModifiers = Array.Empty<VolumeModifier>();

			public float GetVolume(Script script)
			{
				float num = 1f;
				VolumeRule[] array = volumeRules;
				foreach (VolumeRule volumeRule in array)
				{
					if (volumeRule.condition == null || volumeRule.condition.Check(script))
					{
						num = volumeRule.volume;
						break;
					}
				}
				VolumeModifier[] array2 = volumeModifiers;
				foreach (VolumeModifier volumeModifier in array2)
				{
					if (volumeModifier.condition == null || volumeModifier.condition.Check(script))
					{
						num *= volumeModifier.volumeScale;
					}
				}
				return num * masterVolume;
			}
		}

		public class Timer : Object
		{
			public string name;

			public float time;

			public Timer(string name)
			{
				this.name = name;
			}
		}

		public string comment = String.Empty;

		public bool isAddon;

		public VolumeGroup[] volumeGroups = Array.Empty<VolumeGroup>();

		[JsonRequired]
		public ScriptEvent[] scriptEvents = Array.Empty<ScriptEvent>();

		[JsonIgnore]
		public readonly Dictionary<ScriptEvent.GameEventType, List<ScriptEvent>> loadedScriptEvents = new Dictionary<ScriptEvent.GameEventType, List<ScriptEvent>>();

		[JsonIgnore]
		public readonly Dictionary<string, VolumeGroup> loadedScriptVolumeGroups = new Dictionary<string, VolumeGroup>();

		[JsonIgnore]
		public readonly Dictionary<string, Timer> activeTimers = new Dictionary<string, Timer>();

		[JsonIgnore]
		[field: CompilerGenerated]
		public static VolumeGroup DefaultVolumeGroup
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		} = new VolumeGroup();


		public void Initialise(ManualLogSource logger)
		{
			ScriptEvent[] array = scriptEvents;
			List<ScriptEvent> val = default(List<ScriptEvent>);
			foreach (ScriptEvent scriptEvent in array)
			{
				if (!loadedScriptEvents.TryGetValue(scriptEvent.gameEventType, ref val))
				{
					val = new List<ScriptEvent>(1);
					loadedScriptEvents.Add(scriptEvent.gameEventType, val);
				}
				val.Add(scriptEvent);
			}
			VolumeGroup[] array2 = volumeGroups;
			foreach (VolumeGroup volumeGroup in array2)
			{
				if (!loadedScriptVolumeGroups.TryAdd(volumeGroup.tag, volumeGroup))
				{
					logger.LogError((object)String.Concat("Volume group tag \"", volumeGroup.tag, "\" was already declared, you cannot have two volume groups with the same tag"));
				}
			}
		}

		public VolumeGroup TryGetVolumeGroupOrDefault(string? tag)
		{
			if (tag == null || !loadedScriptVolumeGroups.ContainsKey(tag))
			{
				return DefaultVolumeGroup;
			}
			return loadedScriptVolumeGroups[tag];
		}

		public bool TryGetVolumeGroup(string? tag, [NotNullWhen(true)] out VolumeGroup? volumeGroup)
		{
			if (tag == null || !loadedScriptVolumeGroups.ContainsKey(tag))
			{
				volumeGroup = null;
				return false;
			}
			volumeGroup = loadedScriptVolumeGroups[tag];
			return true;
		}

		public void UpdateTimers(float deltaTime)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<string, Timer> enumerator = activeTimers.Values.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					enumerator.Current.time += deltaTime;
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void ClearTimers()
		{
			activeTimers.Clear();
		}

		internal void ClearTimer(string timerName)
		{
			activeTimers.Remove(timerName);
		}
	}
	public class ScriptManager : Object
	{
		public readonly List<Script> loadedScripts = new List<Script>();

		[field: CompilerGenerated]
		public ManualLogSource Logger
		{
			[CompilerGenerated]
			get;
			[CompilerGenerated]
			private set;
		}

		public ScriptManager(string[] scriptNames, GameEventListener gameEventListener)
		{
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Expected O, but got Unknown
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Expected O, but got Unknown
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Expected O, but got Unknown
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Expected O, but got Unknown
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019d: Expected O, but got Unknown
			//IL_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bf: Expected O, but got Unknown
			//IL_01bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c9: Expected O, but got Unknown
			//IL_01d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Expected O, but got Unknown
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Expected O, but got Unknown
			//IL_01f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Expected O, but got Unknown
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: Expected O, but got Unknown
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Expected O, but got Unknown
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Expected O, but got Unknown
			//IL_023d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0251: Expected O, but got Unknown
			//IL_025f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Expected O, but got Unknown
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Expected O, but got Unknown
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Expected O, but got Unknown
			//IL_028b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			Logger = Logger.CreateLogSource("PizzaTowerEscapeMusic ScriptManager");
			Script script = new Script();
			loadedScripts.Add(script);
			foreach (string text in scriptNames)
			{
				Script script2 = DeserializeScript(text);
				if (script2 != null)
				{
					script2.Initialise(Logger);
					if (script2.isAddon)
					{
						List<Script.VolumeGroup> val = Enumerable.ToList<Script.VolumeGroup>((IEnumerable<Script.VolumeGroup>)(object)script.volumeGroups);
						val.AddRange((IEnumerable<Script.VolumeGroup>)(object)script2.volumeGroups);
						script.volumeGroups = val.ToArray();
						List<ScriptEvent> val2 = Enumerable.ToList<ScriptEvent>((IEnumerable<ScriptEvent>)(object)script.scriptEvents);
						val2.AddRange((IEnumerable<ScriptEvent>)(object)script2.scriptEvents);
						script.scriptEvents = val2.ToArray();
					}
					else
					{
						loadedScripts.Add(script2);
					}
					if (script2.isAddon)
					{
						Logger.LogInfo((object)String.Concat("Script (", text, ") loaded as addon"));
					}
					else
					{
						Logger.LogInfo((object)String.Concat("Script (", text, ") loaded"));
					}
				}
			}
			script.Initialise(Logger);
			gameEventListener.OnFrameUpdate = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnFrameUpdate, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.FrameUpdated);
			}));
			gameEventListener.OnShipLanded = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnShipLanded, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.ShipLanded);
			}));
			gameEventListener.OnShipTakeOff = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnShipTakeOff, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.ShipTakeOff);
			}));
			gameEventListener.OnShipLeavingAlertCalled = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnShipLeavingAlertCalled, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.ShipLeavingAlertCalled);
			}));
			gameEventListener.OnPlayerDamaged = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerDamaged, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerDamaged);
			}));
			gameEventListener.OnPlayerDeath = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerDeath, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerDied);
			}));
			gameEventListener.OnPlayerEnteredFacility = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerEnteredFacility, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerEnteredFacility);
			}));
			gameEventListener.OnPlayerExitedFacility = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerExitedFacility, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerExitedFacility);
			}));
			gameEventListener.OnPlayerEnteredShip = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerEnteredShip, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerEnteredShip);
			}));
			gameEventListener.OnPlayerExitedShip = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnPlayerExitedShip, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.PlayerExitedShip);
			}));
			gameEventListener.OnApparatusTaken = (Action)Delegate.Combine((Delegate)(object)gameEventListener.OnApparatusTaken, (Delegate)(Action)([CompilerGenerated] () =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.ApparatusTaken);
			}));
			gameEventListener.OnCurrentMoonChanged = (Action<SelectableLevel>)(object)Delegate.Combine((Delegate)(object)gameEventListener.OnCurrentMoonChanged, (Delegate)(object)(Action<SelectableLevel>)([CompilerGenerated] (SelectableLevel? l) =>
			{
				CheckScriptEvents(ScriptEvent.GameEventType.CurrentMoonChanged);
			}));
			Logger.LogInfo((object)"Done loading scripts");
		}

		private void CheckScriptEvents(ScriptEvent.GameEventType eventType)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			Enumerator<Script> enumerator = loadedScripts.GetEnumerator();
			try
			{
				List<ScriptEvent> val = default(List<ScriptEvent>);
				while (enumerator.MoveNext())
				{
					Script current = enumerator.Current;
					if (!current.loadedScriptEvents.TryGetValue(eventType, ref val))
					{
						continue;
					}
					Enumerator<ScriptEvent> enumerator2 = val.GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							ScriptEvent current2 = enumerator2.Current;
							if (current2.CheckConditions(current))
							{
								Logger.LogDebug((object)String.Concat((string[])(object)new String[5]
								{
									"Conditions for a script event have been met!\n Script Event Type: ",
									current2.scriptEventType,
									String.Format("\n   Game Event Type: {0}", (object)current2.gameEventType),
									"\n           Comment: ",
									current2.comment
								}));
								current2.Run(current);
							}
						}
					}
					finally
					{
						((IDisposable)enumerator2).Dispose();
					}
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		private Script? DeserializeScript(string name)
		{
			//IL_005c: Expected O, but got Unknown
			string filePath = CustomManager.GetFilePath(String.Concat("Scripts/", name, ".json"), String.Concat("DefaultScripts/", name, ".json"));
			if (!File.Exists(filePath))
			{
				Logger.LogError((object)String.Concat("Script \"", name, "\" does not exist! Make sure you spelt it right the config, and make sure its file extension is \".json\""));
				return null;
			}
			string text = File.ReadAllText(filePath);
			try
			{
				return JsonConvert.DeserializeObject<Script>(text);
			}
			catch (Exception val)
			{
				Exception val2 = val;
				Logger.LogError((object)String.Concat("Failed to deserialize script \"", name, "\":\n", val2.Message));
				return null;
			}
		}

		public void UpdateAllScriptTimers(float deltaTime)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<Script> enumerator = loadedScripts.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					enumerator.Current.UpdateTimers(deltaTime);
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}

		public void ClearAllScriptTimers()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Enumerator<Script> enumerator = loadedScripts.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					enumerator.Current.ClearTimers();
				}
			}
			finally
			{
				((IDisposable)enumerator).Dispose();
			}
		}
	}
}
namespace PizzaTowerEscapeMusic.Scripting.ScriptEvents
{
	public class ScriptEventConverter : JsonConverter<ScriptEvent>
	{
		public override bool CanWrite => false;

		public override ScriptEvent ReadJson(JsonReader reader, Type objectType, ScriptEvent? existingValue, bool hasExistingValue, JsonSerializer serializer)
		{
			//IL_001b: 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)
			JObject val = JObject.Load(reader);
			JToken val2 = default(JToken);
			if (!val.TryGetValue("scriptEventType", ref val2))
			{
				throw new Exception("scriptEventType type is null!");
			}
			string text = Extensions.Value<string>((IEnumerable<JToken>)(object)val2);
			ScriptEvent scriptEvent;
			if (!(text == "PlayMusic"))
			{
				if (!(text == "StopMusic"))
				{
					if (!(text == "ResetTimers"))
					{
						if (!(text == "SetVolumeGroupMasterVolume"))
						{
							throw new Exception(String.Format("Condition type \"{0}\" does not exist", (object)val2));
						}
						scriptEvent = new ScriptEvent_SetVolumeGroupMasterVolume();
					}
					else
					{
						scriptEvent = new ScriptEvent_ResetTimers();
					}
				}
				else
				{
					scriptEvent = new ScriptEvent_StopMusic();
				}
			}
			else
			{
				scriptEvent = new ScriptEvent_PlayMusic();
			}
			ScriptEvent scriptEvent2 = scriptEvent;
			serializer.Populate(((JToken)val).CreateReader(), (object)scriptEvent2);
			return scriptEvent2;
		}

		public override void WriteJson(JsonWriter writer, ScriptEvent? value, JsonSerializer serializer)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			throw new NotImplementedException();
		}
	}
	[JsonConverter(/*Could not decode attribute arguments.*/)]
	public abstract class ScriptEvent : Object
	{
		public enum GameEventType : Enum
		{
			FrameUpdated,
			ShipLanded,
			ShipTakeOff,
			ShipLeavingAlertCalled,
			PlayerDamaged,
			PlayerDied,
			PlayerEnteredFacility,
			PlayerExitedFacility,
			PlayerEnteredShip,
			PlayerExitedShip,
			ApparatusTaken,
			CurrentMoonChanged
		}

		[CompilerGenerated]
		private sealed class <>c__DisplayClass5_0 : Object
		{
			public Script script;

			internal bool <CheckConditions>b__0(Condition c)
			{
				return !c.Check(script);
			}
		}

		public string comment = String.Empty;

		[JsonRequired]
		public string scriptEventType = String.Empty;

		[JsonRequired]
		public GameEventType gameEventType;

		public Condition[] conditions = Array.Empty<Condition>();

		public bool CheckConditions(Script script)
		{
			<>c__DisplayClass5_0 CS$<>8__locals0 = new <>c__DisplayClass5_0();
			CS$<>8__locals0.script = script;
			return !Enumerable.Any<Condition>((IEnumerable<Condition>)(object)conditions, (Func<Condition, bool>)((Condition c) => !c.Check(CS$<>8__locals0.script)));
		}

		public abstract void Run(Script script);
	}
	public class ScriptEvent_PlayMusic : ScriptEvent
	{
		public enum OverlapHandling : Enum
		{
			IgnoreAll,
			IgnoreTag,
			OverrideAll,
			OverrideTag,
			OverrideFadeAll,
			OverrideFadeTag,
			Overlap
		}

		public bool loop;

		public bool silenceGameMusic = true;

		[JsonRequired]
		public OverlapHandling overlapHandling;

		public string? tag;

		[JsonRequired]
		public string[] musicNames = Array.Empty<string>();

		public override void Run(Script script)
		{
			if (musicNames.Length != 0)
			{
				PizzaTowerEscapeMusicManager.MusicManager.PlayMusic(script, this);
			}
		}
	}
	public class ScriptEvent_StopMusic : ScriptEvent
	{
		public string[]? targetTags;

		public bool instant;

		public override void Run(Script script)
		{
			if (targetTags != null)
			{
				string[] array = targetTags;
				foreach (string targetTag in array)
				{
					if (instant)
					{
						PizzaTowerEscapeMusicManager.MusicManager.StopMusic(targetTag);
					}
					else
					{
						PizzaTowerEscapeMusicManager.MusicManager.FadeStopMusic(targetTag);
					}
				}
			}
			else if (instant)
			{
				PizzaTowerEscapeMusicManager.MusicManager.StopMusic();
			}
			else
			{
				PizzaTowerEscapeMusicManager.MusicManager.FadeStopMusic();
			}
		}
	}
	public class ScriptEvent_ResetTimers : ScriptEvent
	{
		public string[]? targetTimerNames;

		public override void Run(Script script)
		{
			if (targetTimerNames == null)
			{
				script.ClearTimers();
				return;
			}
			string[] array = targetTimerNames;
			foreach (string timerName in array)
			{
				script.ClearTimer(timerName);
			}
		}
	}
	public class ScriptEvent_SetVolumeGroupMasterVolume : ScriptEvent
	{
		public string[] targetTags = Array.Empty<string>();

		[JsonRequired]
		public float masterVolume;

		public override void Run(Script script)
		{
			if (targetTags.Length == 0)
			{
				Script.DefaultVolumeGroup.masterVolume = masterVolume;
				return;
			}
			string[] array = targetTags;
			Script.VolumeGroup volumeGroup = default(Script.VolumeGroup);
			foreach (string text in array)
			{
				if (!script.loadedScriptVolumeGroups.TryGetValue(text, ref volumeGroup))
				{
					PizzaTowerEscapeMusicManager.ScriptManager.Logger.LogError((object)String.Concat("Script Event SetVolumeGroupMasterVolume was called for volume group with tag \"", text, "\", but there is no volume group of that tag"));
				}
				else
				{
					volumeGroup.masterVolume = masterVolume;
				}
			}
		}
	}
}
namespace PizzaTowerEscapeMusic.Scripting.Conditions
{
	public class ConditionConverter : JsonConverter<Condition>
	{
		public override bool CanWrite => false;

		public override Condition ReadJson(JsonReader reader, Type objectType, Condition? existingValue, bool hasExistingValue, JsonSerializer serializer)
		{
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_037a: Unknown result type (might be due to invalid IL or missing references)
			JObject val = JObject.Load(reader);
			JToken val2 = default(JToken);
			if (!val.TryGetValue("conditionType", ref val2))
			{
				throw new Exception("Condition type is null!");
			}
			string text = Extensions.Value<string>((IEnumerable<JToken>)(object)val2);
			Condition condition;
			switch (<PrivateImplementationDetails>.ComputeStringHash(text))
			{
			case 1907748166u:
				if (!(text == "And"))
				{
					goto default;
				}
				condition = new Condition_And();
				break;
			case 1558476708u:
				if (!(text == "Or"))
				{
					goto default;
				}
				condition = new Condition_Or();
				break;
			case 2352858922u:
				if (!(text == "Not"))
				{
					goto default;
				}
				condition = new Condition_Not();
				break;
			case 1726658099u:
				if (!(text == "Weather"))
				{
					goto default;
				}
				condition = new Condition_Weather();
				break;
			case 1942965639u:
				if (!(text == "PlayerLocation"))
				{
					goto default;
				}
				condition = new Condition_PlayerLocation();
				break;
			case 3247184081u:
				if (!(text == "PlayerAlive"))
				{
					goto default;
				}
				condition = new Condition_PlayerAlive();
				break;
			case 3722301318u:
				if (!(text == "PlayerHealth"))
				{
					goto default;
				}
				condition = new Condition_PlayerHealth();
				break;
			case 1781886746u:
				if (!(text == "PlayerCrouching"))
				{
					goto default;
				}
				condition = new Condition_PlayerCrouching();
				break;
			case 2841340677u:
				if (!(text == "PlayerInsanity"))
				{
					goto default;
				}
				condition = new Condition_PlayerInsanity();
				break;
			case 2094408611u:
				if (!(text == "ShipLanded"))
				{
					goto default;
				}
				condition = new Condition_ShipLanded();
				break;
			case 2572448556u:
				if (!(text == "ShipLeavingAlertCalled"))
				{
					goto default;
				}
				condition = new Condition_ShipLeavingAlertCalled();
				break;
			case 178210114u:
				if (!(text == "MusicWithTagPlaying"))
				{
					goto default;
				}
				condition = new Condition_MusicWithTagPlaying();
				break;
			case 1546530407u:
				if (!(text == "CurrentMoon"))
				{
					goto default;
				}
				condition = new Condition_CurrentMoon();
				break;
			case 3948127682u:
				if (!(text == "Timer"))
				{
					goto default;
				}
				condition = new Condition_Timer();
				break;
			case 1091948930u:
				if (!(text == "Random"))
				{
					goto default;
				}
				condition = new Condition_Random();
				break;
			case 2203947620u:
				if (!(text == "ApparatusDocked"))
				{
					goto default;
				}
				condition = new Condition_ApparatusDocked();
				break;
			case 1151347181u:
				if (!(text == "TimeOfDay"))
				{
					goto default;
				}
				condition = new Condition_TimeOfDay();
				break;
			default:
				throw new Exception(String.Format("Condition type \"{0}\" does not exist", (object)val2));
			}
			Condition condition2 = condition;
			serializer.Populate(((JToken)val).CreateReader(), (object)condition2);
			return condition2;
		}

		public override void WriteJson(JsonWriter writer, Condition? value, JsonSerializer serializer)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			throw new NotImplementedException();
		}
	}
	[JsonConverter(/*Could not decode attribute arguments.*/)]
	public abstract class Condition : Object
	{
		[JsonRequired]
		public string conditionType = String.Empty;

		public abstract bool Check(Script script);
	}
	public abstract class ConditionComparableNumber : Condition
	{
		public enum ComparisonType : Enum
		{
			Equals,
			NotEquals,
			GreaterThan,
			LessThan,
			GreaterThanOrEquals,
			LessThanOrEquals
		}

		[JsonRequired]
		public ComparisonType comparisonType;
	}
	public class Condition_And : Condition
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass1_0 : Object
		{
			public Script script;

			internal bool <Check>b__0(Condition c)
			{
				return !c.Check(script);
			}
		}

		[JsonRequired]
		public Condition[] conditions = Array.Empty<Condition>();

		public override bool Check(Script script)
		{
			<>c__DisplayClass1_0 CS$<>8__locals0 = new <>c__DisplayClass1_0();
			CS$<>8__locals0.script = script;
			return !Enumerable.Any<Condition>((IEnumerable<Condition>)(object)conditions, (Func<Condition, bool>)((Condition c) => !c.Check(CS$<>8__locals0.script)));
		}
	}
	public class Condition_Or : Condition
	{
		[CompilerGenerated]
		private sealed class <>c__DisplayClass1_0 : Object
		{
			public Script script;

			internal bool <Check>b__0(Condition c)
			{
				return c.Check(script);
			}
		}

		[JsonRequired]
		public Condition[] conditions = Array.Empty<Condition>();

		public override bool Check(Script script)
		{
			<>c__DisplayClass1_0 CS$<>8__locals0 = new <>c__DisplayClass1_0();
			CS$<>8__locals0.script = script;
			return Enumerable.Any<Condition>((IEnumerable<Condition>)(object)conditions, (Func<Condition, bool>)((Condition c) => c.Check(CS$<>8__locals0.script)));
		}
	}
	public class Condition_Not : Condition
	{
		[JsonRequired]
		public Condition? condition;

		public override bool Check(Script script)
		{
			if (condition == null)
			{
				return true;
			}
			return !condition.Check(script);
		}
	}
	public class Condition_Weather : Condition
	{
		[JsonRequired]
		public object weather;

		private static Type _weatherConfigHelperType;

		private static MethodInfo _resolveWeatherMethod;

		private static PropertyInfo _vanillaWeatherTypeProp;

		public override bool Check(Script script)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: 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_00a1: 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)
			if ((Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return false;
			}
			LevelWeatherType currentLevelWeather = TimeOfDay.Instance.currentLevelWeather;
			if (weather is LevelWeatherType val)
			{
				return currentLevelWeather == val;
			}
			object obj = weather;
			string text = (string)((obj is String) ? obj : null);
			if (text == null || _weatherConfigHelperType == (Type)null || _resolveWeatherMethod == (MethodInfo)null || _vanillaWeatherTypeProp == (PropertyInfo)null)
			{
				return false;
			}
			try
			{
				object obj2 = ((MethodBase)_resolveWeatherMethod).Invoke((object)null, (object[])(object)new Object[1] { (Object)text });
				if (obj2 == null)
				{
					return false;
				}
				LevelWeatherType val2 = (LevelWeatherType)_vanillaWeatherTypeProp.GetValue(obj2);
				return currentLevelWeather == val2;
			}
			catch (Exception)
			{
				return false;
			}
		}

		static Condition_Weather()
		{
			try
			{
				_weatherConfigHelperType = Type.GetType("WeatherRegistry.ConfigHelper, WeatherRegistry");
				if (_weatherConfigHelperType != (Type)null)
				{
					_resolveWeatherMethod = _weatherConfigHelperType.GetMethod("ResolveStringToWeather", (Type[])(object)new Type[1] { typeof(String) });
					Type type = Type.GetType("WeatherRegistry.Weather, WeatherRegistry");
					if (type != (Type)null)
					{
						_vanillaWeatherTypeProp = type.GetProperty("VanillaWeatherType");
					}
				}
			}
			catch (Exception)
			{
				_weatherConfigHelperType = null;
				_resolveWeatherMethod = null;
				_vanillaWeatherTypeProp = null;
			}
		}
	}
	public class Condition_PlayerLocation : Condition
	{
		public enum Location : Enum
		{
			Ship,
			Facility
		}

		[JsonRequired]
		public Location location;

		public override bool Check(Script script)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return false;
			}
			return location switch
			{
				Location.Ship => GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom, 
				Location.Facility => GameNetworkManager.Instance.localPlayerController.isInsideFactory, 
				_ => false, 
			};
		}
	}
	public class Condition_PlayerAlive : Condition
	{
		public override bool Check(Script script)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return false;
			}
			return !GameNetworkManager.Instance.localPlayerController.isPlayerDead;
		}
	}
	public class Condition_PlayerHealth : ConditionComparableNumber
	{
		[JsonRequired]
		public int value;

		public override bool Check(Script script)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return false;
			}
			int health = GameNetworkManager.Instance.localPlayerController.health;
			return comparisonType switch
			{
				ComparisonType.Equals => health == value, 
				ComparisonType.NotEquals => health != value, 
				ComparisonType.GreaterThan => health > value, 
				ComparisonType.LessThan => health < value, 
				ComparisonType.GreaterThanOrEquals => health >= value, 
				ComparisonType.LessThanOrEquals => health <= value, 
				_ => false, 
			};
		}
	}
	public class Condition_PlayerCrouching : Condition
	{
		public override bool Check(Script script)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return false;
			}
			return GameNetworkManager.Instance.localPlayerController.isCrouching;
		}
	}
	public class Condition_PlayerInsanity : ConditionComparableNumber
	{
		[JsonRequired]
		public float level;

		public override bool Check(Script script)
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)GameNetworkManager.Instance.localPlayerController == (Object)null)
			{
				return false;
			}
			float num = GameNetworkManager.Instance.localPlayerController.insanityLevel / GameNetworkManager.Instance.localPlayerController.maxInsanityLevel;
			return comparisonType switch
			{
				ComparisonType.Equals => level == num, 
				ComparisonType.NotEquals => level != num, 
				ComparisonType.GreaterThan => level > num, 
				ComparisonType.LessThan => level < num, 
				ComparisonType.GreaterThanOrEquals => level >= num, 
				ComparisonType.LessThanOrEquals => level <= num, 
				_ => false, 
			};
		}
	}
	public class Condition_ShipLanded : Condition
	{
		public override bool Check(Script script)
		{
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return false;
			}
			return StartOfRound.Instance.shipHasLanded;
		}
	}
	public class Condition_ShipLeavingAlertCalled : Condition
	{
		public override bool Check(Script script)
		{
			if ((Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return false;
			}
			return TimeOfDay.Instance.shipLeavingAlertCalled;
		}
	}
	public class Condition_MusicWithTagPlaying : Condition
	{
		[JsonRequired]
		public string tag = String.Empty;

		public override bool Check(Script script)
		{
			return PizzaTowerEscapeMusicManager.MusicManager.GetIsMusicPlaying(tag);
		}
	}
	public class Condition_CurrentMoon : Condition
	{
		private static readonly Dictionary<string, int> moonNameToId = new Dictionary<string, int>();

		[JsonRequired]
		public string moonName = String.Empty;

		private bool isDisabled;

		public override bool Check(Script script)
		{
			if ((Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return false;
			}
			if ((Object)(object)StartOfRound.Instance == (Object)null)
			{
				return false;
			}
			if (isDisabled)
			{
				return false;
			}
			int num = default(int);
			if (!moonNameToId.TryGetValue(moonName, ref num))
			{
				SelectableLevel[] levels = StartOfRound.Instance.levels;
				foreach (SelectableLevel val in levels)
				{
					moonNameToId.TryAdd(val.PlanetName, val.levelID);
				}
				if (!moonNameToId.TryGetValue(moonName, ref num))
				{
					PizzaTowerEscapeMusicManager.ScriptManager.Logger.LogError((object)String.Concat("From CurrentMoon condition: Found no existing level with the name \"", moonName, "\""));
					isDisabled = true;
					return false;
				}
			}
			return TimeOfDay.Instance.currentLevel.levelID == num;
		}
	}
	public class Condition_Timer : Condition
	{
		[JsonRequired]
		public string timerName = String.Empty;

		[JsonRequired]
		public float timeGoal;

		public bool resetsTimer = true;

		public override bool Check(Script script)
		{
			Script.Timer timer = default(Script.Timer);
			if (!script.activeTimers.TryGetValue(timerName, ref timer))
			{
				timer = new Script.Timer(timerName);
				script.activeTimers.Add(timerName, timer);
			}
			if (timer.time >= timeGoal)
			{
				if (resetsTimer)
				{
					timer.time = 0f;
				}
				return true;
			}
			return false;
		}
	}
	public class Condition_Random : Condition
	{
		[JsonRequired]
		public float chance;

		public override bool Check(Script script)
		{
			return Random.Range(0f, 1f) <= chance;
		}
	}
	public class Condition_ApparatusDocked : Condition
	{
		public override bool Check(Script script)
		{
			return GameEventListener.IsApparatusDocked();
		}
	}
	public class Condition_TimeOfDay : ConditionComparableNumber
	{
		[JsonRequired]
		public float time;

		public override bool Check(Script script)
		{
			if ((Object)(object)TimeOfDay.Instance == (Object)null)
			{
				return false;
			}
			float num = TimeOfDay.Instance.currentDayTime / TimeOfDay.Instance.totalTime;
			return comparisonType switch
			{
				ComparisonType.Equals => num == time, 
				ComparisonType.NotEquals => num != time, 
				ComparisonType.GreaterThan => num > time, 
				ComparisonType.LessThan => num < time, 
				ComparisonType.GreaterThanOrEquals => num >= time, 
				ComparisonType.LessThanOrEquals => num <= time, 
				_ => false, 
			};
		}
	}
}