Decompiled source of UltraVoice Retaken v1.5.6

UltraVoice Retaken/UltraVoice.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Notiffy.API;
using PluginConfig.API;
using PluginConfig.API.Fields;
using TMPro;
using ULTRAKILL.Cheats;
using UltraVoice.Characters;
using UltraVoice.Utilities;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("UltraVoice")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+91c4efb38f551e7a44d6a600e7da9b4e86849556")]
[assembly: AssemblyProduct("UltraVoice")]
[assembly: AssemblyTitle("UltraVoice")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace UltraVoice
{
	[BepInPlugin("com.achelia.ultravoiceretaken", "UltraVoice Retaken", "2.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class UltraVoicePlugin : BaseUnityPlugin
	{
		public enum SwordsmachineVoiceActor
		{
			Mel,
			Noto,
			Soil
		}

		public enum SentryVoiceActor
		{
			Noto,
			Goober
		}

		public enum GuttertankVoiceActor
		{
			Mel,
			Virchew
		}

		public enum GuttermanVoiceActor
		{
			Mel,
			Lemen
		}

		public enum CerberusVoiceActor
		{
			Mel,
			Soil,
			Rotund
		}

		public enum FerrymanVoiceActor
		{
			Mel,
			Soil,
			Nicky
		}

		public enum V1VoiceActor
		{
			Cyberlord,
			Noto,
			HashCap
		}

		public enum V2VoiceActor
		{
			Ruby,
			Cazsu
		}

		public enum IdolVoiceActor
		{
			Voinvi,
			Virchew
		}

		public enum VirtueVoiceActor
		{
			Noto,
			Virchew
		}

		public enum MirrorReaperVoiceActor
		{
			Noto,
			Rotund
		}

		public enum ShopTerminalVoiceActor
		{
			Bouncy,
			Goober
		}

		public enum EarthmoverVoiceActor
		{
			Rotund,
			Tondar,
			Megaslash
		}

		public enum GeryonVoiceActor
		{
			TheRatmanValinMegaslash,
			Mel
		}

		public enum PowerVoiceActor
		{
			Random,
			Cazsu,
			Goober,
			NotoMasc,
			Vanilla,
			Mel,
			NotoFem
		}

		public const string PluginGuid = "com.achelia.ultravoiceretaken";

		public const string PluginName = "UltraVoice Retaken";

		public const string PluginVersion = "2.0.0";

		public static UltraVoicePlugin Instance;

		public static VoiceManager VoiceManager;

		private Harmony harmony;

		public static VoiceConfig ConfigModule;

		public static BoolField CerberusVoiceEnabled;

		public static BoolField SwordsmachineVoiceEnabled;

		public static BoolField V2VoiceEnabled;

		public static BoolField StreetcleanerVoiceEnabled;

		public static BoolField MindflayerVoiceEnabled;

		public static BoolField VirtueVoiceEnabled;

		public static BoolField FerrymanVoiceEnabled;

		public static BoolField GuttermanVoiceEnabled;

		public static BoolField MannequinVoiceEnabled;

		public static BoolField GuttertankVoiceEnabled;

		public static BoolField ProvidenceVoiceEnabled;

		public static BoolField SentryVoiceEnabled;

		public static BoolField MauriceVoiceEnabled;

		public static BoolField EarthmoverVoiceEnabled;

		public static BoolField MirrorReaperVoiceEnabled;

		public static BoolField GeryonVoiceEnabled;

		public static BoolField LeviathanVoiceEnabled;

		public static BoolField InsurrectionistVoiceEnabled;

		public static BoolField FilthVoiceEnabled;

		public static BoolField StrayVoiceEnabled;

		public static BoolField SchismVoiceEnabled;

		public static BoolField SoldierVoiceEnabled;

		public static BoolField StalkerVoiceEnabled;

		public static BoolField MassVoiceEnabled;

		public static BoolField IdolVoiceEnabled;

		public static BoolField WickedVoiceEnabled;

		public static BoolField V1VoiceEnabled;

		public static BoolField ShopTerminalVoiceEnabled;

		public static BoolField PowerAltVoiceEnabled;

		public static BoolField DeathcatcherVoiceEnabled;

		public static BoolField MasterVoiceEnabled;

		public static BoolField SubtitleColorsEnabled;

		public static FloatSliderField VoiceCooldown;

		public static IntField SubtitleLimit;

		public static EnumField<SwordsmachineVoiceActor> SwordsmachineVoiceActorField;

		public static EnumField<SentryVoiceActor> SentryVoiceActorField;

		public static EnumField<GuttertankVoiceActor> GuttertankVoiceActorField;

		public static EnumField<GuttermanVoiceActor> GuttermanVoiceActorField;

		public static EnumField<CerberusVoiceActor> CerberusVoiceActorField;

		public static EnumField<FerrymanVoiceActor> FerrymanVoiceActorField;

		public static EnumField<IdolVoiceActor> IdolVoiceActorField;

		public static EnumField<VirtueVoiceActor> VirtueVoiceActorField;

		public static EnumField<MirrorReaperVoiceActor> MirrorReaperVoiceActorField;

		public static EnumField<ShopTerminalVoiceActor> ShopTerminalVoiceActorField;

		public static EnumField<GeryonVoiceActor> GeryonVoiceActorField;

		public static EnumField<EarthmoverVoiceActor> EarthmoverVoiceActorField;

		public static EnumField<PowerVoiceActor> PowerVoiceActorField;

		public static ConfigPanel PowerVoicePoolPanel;

		public static Dictionary<string, BoolField> PowerVoiceToggles = new Dictionary<string, BoolField>();

		public static readonly string[] PowerVoiceOrder = new string[6] { "Cazsu", "Goober", "NotoMasc", "Vanilla", "Mel", "NotoFem" };

		public static readonly Dictionary<string, string> PowerVoiceNames = new Dictionary<string, string>
		{
			{ "Cazsu", "Cazsu (Masc)" },
			{ "Goober", "Goober (Masc)" },
			{ "NotoMasc", "Noto (Masc)" },
			{ "Vanilla", "Kennady (Fem)" },
			{ "Mel", "Mel (Fem)" },
			{ "NotoFem", "Noto (Fem)" }
		};

		public static EnumField<V1VoiceActor> V1VoiceActorField;

		public static EnumField<V2VoiceActor> V2VoiceActorField;

		public static ConfigPanel TogglesPanel;

		public static ConfigPanel EnemyTogglesPanel;

		public static ConfigPanel ActorPanel;

		public static ConfigPanel VolumePanel;

		public static ConfigPanel EnemyVolumePanel;

		public static ConfigPanel V1LinesPanel;

		public static ConfigPanel SubtitleColorsPanel;

		public static ConfigPanel CharacterSubtitleColorsPanel;

		public static readonly Dictionary<string, BoolField> SubtitleColorToggles = new Dictionary<string, BoolField>();

		public static Dictionary<string, BoolField> V1LineToggles = new Dictionary<string, BoolField>();

		public static FloatSliderField MasterVolumeField;

		public static FloatSliderField PowerAltVolumeField;

		public static Dictionary<string, FloatSliderField> EnemyVolumeFields = new Dictionary<string, FloatSliderField>();

		public static bool VoicesEnabled
		{
			get
			{
				if (MasterVoiceEnabled != null)
				{
					return MasterVoiceEnabled.value;
				}
				return true;
			}
		}

		public static bool V1LineEnabled(string key)
		{
			if (V1VoiceEnabled == null || !V1VoiceEnabled.value)
			{
				return false;
			}
			if (V1LineToggles.TryGetValue(key, out var value))
			{
				return value.value;
			}
			return true;
		}

		public static bool SubtitleColorAllowed(string voiceName)
		{
			if (SubtitleColorsEnabled != null && !SubtitleColorsEnabled.value)
			{
				return false;
			}
			if (string.IsNullOrEmpty(voiceName))
			{
				return true;
			}
			if (voiceName.StartsWith("Agony") || voiceName.StartsWith("Tundra"))
			{
				voiceName = "Swordsmachine";
			}
			foreach (KeyValuePair<string, BoolField> subtitleColorToggle in SubtitleColorToggles)
			{
				if (voiceName.StartsWith(subtitleColorToggle.Key))
				{
					return subtitleColorToggle.Value.value;
				}
			}
			return true;
		}

		private void Awake()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			Instance = this;
			VoiceManager = new VoiceManager();
			ConfigModule = new VoiceConfig();
			LoadAssets();
			harmony = new Harmony("com.achelia.ultravoiceretaken");
			harmony.PatchAll();
			SceneManager.sceneLoaded += OnSceneLoaded;
			((MonoBehaviour)this).StartCoroutine(UpdateChecker.CheckForUpdates(((BaseUnityPlugin)this).Logger));
			((BaseUnityPlugin)this).Logger.LogInfo((object)"UltraVoice Retaken loaded successfully!");
		}

		private void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			ResetEnemyStates();
			UpdateChecker.OnSceneLoaded();
		}

		private void ResetEnemyStates()
		{
			SwordsmachineCharacter.FirstFightDone = false;
			SwordsmachineCharacter.FirstFightLinePlayed = false;
			V2Character.V2IntroTime = -999f;
			V2Character.V2CutsceneVoicePlayed = false;
			V2Character.V2SecondVoiceRestartPlayed = false;
			V2Character.V2DeathPlayed = false;
			V1Character.V2BossKillPlayed = false;
			V1Character.AlreadyPickedUp.Clear();
			ShopTerminalCharacter.BootUpPlayed = false;
			ShopTerminalCharacter.FlippedPlayed = false;
			if (SceneHelper.CurrentScene != "Endless")
			{
				ShopTerminalCharacter.CybergrindDeath = false;
			}
			else
			{
				((MonoBehaviour)this).StartCoroutine(ShopTerminalCharacter.WaveWatcher());
			}
			EarthmoverCharacter.IntroPlayed = false;
			EarthmoverCharacter.DeathPlayed = false;
			EarthmoverCharacter.lastIdolTime = -999f;
			FerrymanCharacter.FerrymanCoinTossed = false;
			FerrymanCharacter.FerrymanPhaseChangePlayed = false;
			GuttertankCharacter.GuttertankSpawnInMirror = false;
			GeryonCharacter.EnrageLinePlayed = false;
			GeryonCharacter.CanRestartFight = false;
			PowerCharacter.RollVoice();
			PowerCharacter.ResetIntroRolls();
		}

		private void LoadAssets()
		{
			CerberusCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			DeathcatcherCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			EarthmoverCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			FerrymanCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			FilthCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			GeryonCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			GuttermanCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			GuttertankCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			HideousMassCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			IdolCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			InsurrectionistCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			LeviathanCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			MaliciousFaceCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			MannequinCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			MindflayerCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			MirrorReaperCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			PowerCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			ProvidenceCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			SchismCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			SentryCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			ShopTerminalCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			SoldierCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			WickedCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			StalkerCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			StrayCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			StreetcleanerCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			SwordsmachineCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			V1Character.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			V2Character.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
			VirtueCharacter.LoadVoiceLines(((BaseUnityPlugin)this).Logger);
		}

		public static float GetVoiceVolume(string voiceName)
		{
			float num = ((MasterVolumeField != null) ? (MasterVolumeField.value / 100f) : 1f);
			if (string.IsNullOrEmpty(voiceName))
			{
				return num;
			}
			if (voiceName.StartsWith("Agony") || voiceName.StartsWith("Tundra"))
			{
				voiceName = "Swordsmachine";
			}
			float num2 = 1f;
			foreach (KeyValuePair<string, FloatSliderField> enemyVolumeField in EnemyVolumeFields)
			{
				if (voiceName.StartsWith(enemyVolumeField.Key))
				{
					num2 = enemyVolumeField.Value.value / 100f;
					break;
				}
			}
			return num * num2;
		}

		public static AudioClip[] LoadClips(string format, int count)
		{
			AudioClip[] array = (AudioClip[])(object)new AudioClip[count];
			for (int i = 0; i < count; i++)
			{
				array[i] = LoadClip(string.Format(format, i + 1));
			}
			return array;
		}

		public static AudioClip LoadClip(string resourcePath)
		{
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				if (!resourcePath.StartsWith("UltraVoice.Resources."))
				{
					resourcePath = "UltraVoice.Resources." + resourcePath;
				}
				using Stream stream = executingAssembly.GetManifestResourceStream(resourcePath);
				if (stream == null)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)("UltraVoice missing clip: " + resourcePath));
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				AudioClip val = WavUtility.ToAudioClip(array);
				if ((Object)(object)val == (Object)null)
				{
					((BaseUnityPlugin)Instance).Logger.LogWarning((object)("UltraVoice failed to convert clip: " + resourcePath));
					return null;
				}
				return val;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)Instance).Logger.LogError((object)$"UltraVoice error loading clip {resourcePath}: {arg}");
				return null;
			}
		}
	}
}
namespace UltraVoice.Patches
{
	[HarmonyPatch(typeof(SubtitleController), "DisplaySubtitle", new Type[]
	{
		typeof(string),
		typeof(AudioSource),
		typeof(bool)
	})]
	public static class SubtitleLimitPatch
	{
		public static void Prefix(SubtitleController __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				int num = ((UltraVoicePlugin.SubtitleLimit != null) ? UltraVoicePlugin.SubtitleLimit.value : 5);
				Transform container = __instance.container;
				if ((Object)(object)container == (Object)null)
				{
					return;
				}
				int num2 = 0;
				for (int i = 0; i < container.childCount; i++)
				{
					Transform child = container.GetChild(i);
					if ((Object)(object)((Component)child).GetComponent<Subtitle>() != (Object)null && ((Component)child).gameObject.activeInHierarchy)
					{
						num2++;
					}
				}
				while (num2 >= num)
				{
					Subtitle val = null;
					int num3 = int.MaxValue;
					for (int j = 0; j < container.childCount; j++)
					{
						Transform child2 = container.GetChild(j);
						Subtitle component = ((Component)child2).GetComponent<Subtitle>();
						if (!((Object)(object)component == (Object)null) && ((Component)child2).gameObject.activeInHierarchy)
						{
							int siblingIndex = child2.GetSiblingIndex();
							if (siblingIndex < num3)
							{
								num3 = siblingIndex;
								val = component;
							}
						}
					}
					if (!((Object)(object)val == (Object)null))
					{
						ReleaseAndDestroy(val);
						num2--;
						continue;
					}
					break;
				}
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"SubtitleLimitPatch.Prefix error: {arg}");
			}
		}

		public static void Postfix(string caption, AudioSource audioSource, bool ignoreSetting, SubtitleController __instance)
		{
			try
			{
				if ((Object)(object)__instance == (Object)null)
				{
					return;
				}
				Transform container = __instance.container;
				if ((Object)(object)container == (Object)null)
				{
					return;
				}
				Subtitle val = null;
				for (int num = container.childCount - 1; num >= 0; num--)
				{
					Subtitle component = ((Component)container.GetChild(num)).GetComponent<Subtitle>();
					if ((Object)(object)component != (Object)null)
					{
						val = component;
						break;
					}
				}
				if (!((Object)(object)val == (Object)null) && (Object)(object)((Component)val).GetComponent<SubtitleWatcher>() == (Object)null)
				{
					SubtitleWatcher subtitleWatcher = ((Component)val).gameObject.AddComponent<SubtitleWatcher>();
					subtitleWatcher.source = audioSource;
					subtitleWatcher.controller = __instance;
					subtitleWatcher.spawnTime = Time.time;
					subtitleWatcher.StartWatching();
				}
			}
			catch (Exception arg)
			{
				Debug.LogError((object)$"SubtitleLimitPatch.Postfix error: {arg}");
			}
		}

		public static void ReleaseAndDestroy(Subtitle subtitle)
		{
			if (!((Object)(object)subtitle == (Object)null))
			{
				Transform parent = ((Component)subtitle).transform.parent;
				SubtitleController instance = MonoSingleton<SubtitleController>.Instance;
				if (instance != null)
				{
					instance.NotifyHoldEnd(subtitle);
				}
				if ((Object)(object)subtitle.nextInChain != (Object)null)
				{
					subtitle.nextInChain.ContinueChain();
				}
				Object.Destroy((Object)(object)((Component)subtitle).gameObject);
				ForceRebuildContainerLayout(parent);
			}
		}

		public static void ForceRebuildContainerLayout(Transform container)
		{
			if (!((Object)(object)container == (Object)null))
			{
				RectTransform val = (RectTransform)(((object)((container is RectTransform) ? container : null)) ?? ((object)((Component)container).GetComponent<RectTransform>()));
				if ((Object)(object)val != (Object)null)
				{
					LayoutRebuilder.ForceRebuildLayoutImmediate(val);
				}
			}
		}
	}
	public class SubtitleWatcher : MonoBehaviour
	{
		public AudioSource source;

		public SubtitleController controller;

		public float spawnTime;

		private Subtitle subtitle;

		private CanvasGroup group;

		private float fadeOutSpeed;

		private Coroutine monitorCoroutine;

		private bool watching;

		private const float WaitBeforeFadeAfterAudio = 5f;

		private const float LifetimeBeforeAutoFade = 5f;

		private const float FallbackFadeDuration = 0.6f;

		private void Awake()
		{
			subtitle = ((Component)this).GetComponent<Subtitle>();
			if ((Object)(object)subtitle != (Object)null)
			{
				group = subtitle.group ?? ((Component)subtitle).GetComponent<CanvasGroup>();
				fadeOutSpeed = subtitle.fadeOutSpeed;
			}
		}

		public void StartWatching()
		{
			watching = true;
			if (monitorCoroutine == null)
			{
				monitorCoroutine = ((MonoBehaviour)this).StartCoroutine(MonitorLifecycle());
			}
		}

		private void OnEnable()
		{
			if (watching && monitorCoroutine == null)
			{
				monitorCoroutine = ((MonoBehaviour)this).StartCoroutine(MonitorLifecycle());
			}
		}

		private void OnDisable()
		{
			if (monitorCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(monitorCoroutine);
				monitorCoroutine = null;
			}
		}

		private IEnumerator MonitorLifecycle()
		{
			while (true)
			{
				int num = CountActiveSubtitles();
				int max = ((UltraVoicePlugin.SubtitleLimit != null) ? UltraVoicePlugin.SubtitleLimit.value : 5);
				if (num > max)
				{
					SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
					Object.Destroy((Object)(object)this);
					yield break;
				}
				if (Time.time - spawnTime >= 5f)
				{
					break;
				}
				if ((Object)(object)source != (Object)null && source.isPlaying)
				{
					while ((Object)(object)source != (Object)null && source.isPlaying)
					{
						if (CountActiveSubtitles() > max)
						{
							SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
							Object.Destroy((Object)(object)this);
							yield break;
						}
						if (Time.time - spawnTime >= 5f)
						{
							yield return ((MonoBehaviour)this).StartCoroutine(FadeOutAndDestroy());
							yield break;
						}
						yield return null;
					}
					float waited = 0f;
					while (waited < 5f)
					{
						if (CountActiveSubtitles() > max)
						{
							SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
							Object.Destroy((Object)(object)this);
							yield break;
						}
						if ((Object)(object)source != (Object)null && source.isPlaying)
						{
							break;
						}
						if (Time.time - spawnTime >= 5f)
						{
							yield return ((MonoBehaviour)this).StartCoroutine(FadeOutAndDestroy());
							yield break;
						}
						waited += Time.deltaTime;
						yield return null;
					}
				}
				else
				{
					float num2 = 5f - (Time.time - spawnTime);
					if (num2 > 0f)
					{
						float num3 = Mathf.Min(0.2f, num2);
						yield return (object)new WaitForSeconds(num3);
					}
				}
				yield return null;
			}
			yield return ((MonoBehaviour)this).StartCoroutine(FadeOutAndDestroy());
		}

		private int CountActiveSubtitles()
		{
			SubtitleController val = controller ?? MonoSingleton<SubtitleController>.Instance;
			Transform val2 = (((Object)(object)val != (Object)null) ? val.container : null);
			if ((Object)(object)val2 != (Object)null)
			{
				int num = 0;
				for (int i = 0; i < val2.childCount; i++)
				{
					Subtitle component = ((Component)val2.GetChild(i)).GetComponent<Subtitle>();
					if ((Object)(object)component != (Object)null && ((Component)component).gameObject.activeInHierarchy)
					{
						num++;
					}
				}
				return num;
			}
			Subtitle[] array = Object.FindObjectsOfType<Subtitle>();
			int num2 = 0;
			Subtitle[] array2 = array;
			foreach (Subtitle val3 in array2)
			{
				if ((Object)(object)val3 != (Object)null && ((Component)val3).gameObject.activeInHierarchy)
				{
					num2++;
				}
			}
			return num2;
		}

		private IEnumerator FadeOutAndDestroy()
		{
			if ((Object)(object)group == (Object)null)
			{
				SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
				Object.Destroy((Object)(object)this);
				yield break;
			}
			float startAlpha = Mathf.Clamp01(group.alpha);
			float duration = 0.6f;
			if (fadeOutSpeed > 1E-05f)
			{
				duration = Mathf.Max(0.01f, startAlpha / fadeOutSpeed);
			}
			if (duration <= 0.0001f)
			{
				SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
				Object.Destroy((Object)(object)this);
				yield break;
			}
			float t = 0f;
			while (t < duration)
			{
				t += Time.deltaTime;
				group.alpha = Mathf.Lerp(startAlpha, 0f, t / duration);
				yield return null;
			}
			group.alpha = 0f;
			SubtitleLimitPatch.ReleaseAndDestroy(subtitle);
			Object.Destroy((Object)(object)this);
		}
	}
}
namespace UltraVoice.Utilities
{
	[HarmonyPatch(typeof(VirtualAudioManager), "AddAudioSource", new Type[] { typeof(AudioSource) })]
	internal class PowerAudioFix
	{
		public static bool SkipVirtualAudio(AudioSource source)
		{
			if ((Object)(object)source == (Object)null || SceneHelper.CurrentScene != "Level 8-3")
			{
				return false;
			}
			return (Object)(object)((Component)source).GetComponentInParent<Power>() != (Object)null;
		}

		private static bool Prefix(AudioSource source)
		{
			return !SkipVirtualAudio(source);
		}
	}
	[HarmonyPatch(typeof(VirtualAudioManager), "AddAudioSource", new Type[] { typeof(VirtualAudioFilter) })]
	internal class PowerAudioFilterFix
	{
		private static bool Prefix(VirtualAudioFilter filter)
		{
			if ((Object)(object)filter == (Object)null || !PowerAudioFix.SkipVirtualAudio(filter.source))
			{
				return true;
			}
			((Behaviour)filter).enabled = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(VirtualAudioManager), "UpdateSources")]
	internal class AudioFix
	{
		private static void Prefix(VirtualAudioManager __instance)
		{
			List<VirtualAudioFilter> sources = __instance.m_Sources;
			bool flag = false;
			for (int num = sources.Count - 1; num >= 0; num--)
			{
				VirtualAudioFilter val = sources[num];
				if (!((Object)(object)val == (Object)null))
				{
					AudioSource source = val.source;
					if (!((Object)(object)source == (Object)null))
					{
						try
						{
							AudioSourceExtensions.IsPaused(source);
						}
						catch (NullReferenceException)
						{
							val.trackedIndex = -1;
							Object.Destroy((Object)(object)val);
							sources.RemoveAt(num);
							flag = true;
						}
					}
				}
			}
			if (!flag)
			{
				return;
			}
			for (int i = 0; i < sources.Count; i++)
			{
				if ((Object)(object)sources[i] != (Object)null)
				{
					sources[i].trackedIndex = i;
				}
			}
		}
	}
	public class UpdateChecker
	{
		[Serializable]
		private class PackageMetrics
		{
			public int downloads;

			public int rating_score;

			public string latest_version;
		}

		private const string MetricsUrl = "https://thunderstore.io/api/v1/package-metrics/achelia/UltraVoice_Retaken/";

		private const string PageUrl = "https://thunderstore.io/c/ultrakill/p/achelia/UltraVoice_Retaken/";

		private const string ChangelogUrl = "https://thunderstore.io/c/ultrakill/p/achelia/UltraVoice_Retaken/changelog";

		private const string OpenPageAction = "ultravoice_open_page";

		private const string ViewChangelogAction = "ultravoice_view_changelog";

		private const string MainMenuScene = "Main Menu";

		private static uint notificationId;

		private static string pendingVersion;

		private static bool notificationShown;

		public static IEnumerator CheckForUpdates(ManualLogSource logger)
		{
			UnityWebRequest request = UnityWebRequest.Get("https://thunderstore.io/api/v1/package-metrics/achelia/UltraVoice_Retaken/");
			try
			{
				yield return request.SendWebRequest();
				if ((int)request.result != 1)
				{
					logger.LogWarning((object)("UltraVoice update check failed: " + request.error));
					yield break;
				}
				PackageMetrics packageMetrics = null;
				try
				{
					packageMetrics = JsonUtility.FromJson<PackageMetrics>(request.downloadHandler.text);
				}
				catch (Exception ex)
				{
					logger.LogWarning((object)("UltraVoice update check could not parse the response: " + ex.Message));
				}
				if (packageMetrics == null || string.IsNullOrEmpty(packageMetrics.latest_version) || !Version.TryParse(packageMetrics.latest_version, out Version result) || !Version.TryParse("2.0.0", out Version result2) || result <= result2)
				{
					yield break;
				}
				logger.LogInfo((object)("UltraVoice update available: 2.0.0 -> " + packageMetrics.latest_version));
				pendingVersion = packageMetrics.latest_version;
				TryShowNotification();
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}

		public static void OnSceneLoaded()
		{
			TryShowNotification();
		}

		private static void TryShowNotification()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (notificationShown || pendingVersion == null)
			{
				return;
			}
			if (SceneHelper.CurrentScene != "Main Menu")
			{
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name != "Main Menu")
				{
					return;
				}
			}
			notificationShown = true;
			NotificationSystem.ActionInvoked += OnActionInvoked;
			notificationId = NotificationSystem.NotifySend("Update available!", "UltraVoice Retaken has been updated to " + pendingVersion, LoadIcon("UltraVoice.Images.notiffy_icon.png"), "", (Urgency)1, "UltraVoice Retaken", 0u, new Dictionary<string, string>
			{
				{ "ultravoice_open_page", "Thunderstore Page" },
				{ "ultravoice_view_changelog", "View Changelog" }
			}, -1);
		}

		private static void OnActionInvoked(uint id, string action)
		{
			if (id == notificationId)
			{
				if (action == "ultravoice_open_page")
				{
					Application.OpenURL("https://thunderstore.io/c/ultrakill/p/achelia/UltraVoice_Retaken/");
				}
				else if (action == "ultravoice_view_changelog")
				{
					Application.OpenURL("https://thunderstore.io/c/ultrakill/p/achelia/UltraVoice_Retaken/changelog");
				}
			}
		}

		public static Sprite LoadIcon(string resourcePath)
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourcePath);
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					return null;
				}
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch
			{
				return null;
			}
		}
	}
	public class VoiceConfig
	{
		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static PostBoolValueChangeEvent <>9__5_0;

			public static PostBoolValueChangeEvent <>9__5_1;

			public static PostBoolValueChangeEvent <>9__5_2;

			public static PostEnumValueChangeEvent<UltraVoicePlugin.PowerVoiceActor> <>9__5_3;

			public static PostEnumValueChangeEvent<UltraVoicePlugin.V1VoiceActor> <>9__9_0;

			internal void <.ctor>b__5_0(bool _)
			{
				RefreshInteractable();
			}

			internal void <.ctor>b__5_1(bool _)
			{
				RefreshInteractable();
			}

			internal void <.ctor>b__5_2(bool _)
			{
				RefreshInteractable();
			}

			internal void <.ctor>b__5_3(UltraVoicePlugin.PowerVoiceActor _)
			{
				RefreshInteractable();
			}

			internal void <BuildVoiceActors>b__9_0(UltraVoicePlugin.V1VoiceActor _)
			{
				V1Character.ApplyVoiceActor();
			}
		}

		public PluginConfigurator Config { get; }

		private ConfigPanel Root => Config.rootPanel;

		public VoiceConfig()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Expected O, but got Unknown
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Expected O, but got Unknown
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Expected O, but got Unknown
			Config = PluginConfigurator.Create("UltraVoice Retaken", "com.achelia.ultravoiceretaken");
			Config.icon = UpdateChecker.LoadIcon("UltraVoice.Images.notiffy_icon.png");
			UltraVoicePlugin.TogglesPanel = CreatePanel(Root, "toggles", "Enemy Line Toggles");
			UltraVoicePlugin.ActorPanel = CreatePanel(Root, "actors", "Voice Actors");
			UltraVoicePlugin.VolumePanel = CreatePanel(Root, "volumes", "Volume Levels");
			UltraVoicePlugin.SubtitleColorsPanel = CreatePanel(Root, "subtitlecolors", "Subtitle Colors");
			UltraVoicePlugin.VoiceCooldown = CreateSlider(Root, "cooldown", "Voice Cooldown", 0.25f, 0f, 0.5f, 2);
			UltraVoicePlugin.SubtitleLimit = new IntField(Root, "Max Allowed Subtitles", "subtitlelimit", 5, 1, 10);
			BuildToggles();
			BuildSubtitleColors();
			BuildVoiceActors();
			BuildVolumes();
			BoolField masterVoiceEnabled = UltraVoicePlugin.MasterVoiceEnabled;
			object obj = <>c.<>9__5_0;
			if (obj == null)
			{
				PostBoolValueChangeEvent val = delegate
				{
					RefreshInteractable();
				};
				<>c.<>9__5_0 = val;
				obj = (object)val;
			}
			masterVoiceEnabled.postValueChangeEvent += (PostBoolValueChangeEvent)obj;
			BoolField subtitleColorsEnabled = UltraVoicePlugin.SubtitleColorsEnabled;
			object obj2 = <>c.<>9__5_1;
			if (obj2 == null)
			{
				PostBoolValueChangeEvent val2 = delegate
				{
					RefreshInteractable();
				};
				<>c.<>9__5_1 = val2;
				obj2 = (object)val2;
			}
			subtitleColorsEnabled.postValueChangeEvent += (PostBoolValueChangeEvent)obj2;
			BoolField v1VoiceEnabled = UltraVoicePlugin.V1VoiceEnabled;
			object obj3 = <>c.<>9__5_2;
			if (obj3 == null)
			{
				PostBoolValueChangeEvent val3 = delegate
				{
					RefreshInteractable();
				};
				<>c.<>9__5_2 = val3;
				obj3 = (object)val3;
			}
			v1VoiceEnabled.postValueChangeEvent += (PostBoolValueChangeEvent)obj3;
			UltraVoicePlugin.PowerVoiceActorField.postValueChangeEvent += delegate
			{
				RefreshInteractable();
			};
			RefreshInteractable();
		}

		private static void RefreshInteractable()
		{
			bool value = UltraVoicePlugin.MasterVoiceEnabled.value;
			((ConfigField)UltraVoicePlugin.VoiceCooldown).interactable = value;
			((ConfigField)UltraVoicePlugin.SubtitleLimit).interactable = value;
			((ConfigField)UltraVoicePlugin.EnemyTogglesPanel).interactable = value;
			((ConfigField)UltraVoicePlugin.ActorPanel).interactable = value;
			((ConfigField)UltraVoicePlugin.MasterVolumeField).interactable = value;
			((ConfigField)UltraVoicePlugin.EnemyVolumePanel).interactable = value;
			((ConfigField)UltraVoicePlugin.SubtitleColorsEnabled).interactable = value;
			((ConfigField)UltraVoicePlugin.CharacterSubtitleColorsPanel).interactable = value && UltraVoicePlugin.SubtitleColorsEnabled.value;
			((ConfigField)UltraVoicePlugin.V1LinesPanel).interactable = value && UltraVoicePlugin.V1VoiceEnabled.value;
			((ConfigField)UltraVoicePlugin.PowerVoicePoolPanel).interactable = value && UltraVoicePlugin.PowerVoiceActorField.value == UltraVoicePlugin.PowerVoiceActor.Random;
		}

		private void BuildToggles()
		{
			ConfigPanel togglesPanel = UltraVoicePlugin.TogglesPanel;
			UltraVoicePlugin.MasterVoiceEnabled = CreateSetting("mastervoice", "Enable Voice Lines", defaultValue: true, togglesPanel);
			ConfigPanel val = (UltraVoicePlugin.EnemyTogglesPanel = CreatePanel(togglesPanel, "enemytoggles", "Enemy Toggles"));
			UltraVoicePlugin.CerberusVoiceEnabled = CreateEnemyToggle("cerberusvoice", "Cerberus", defaultValue: true, val);
			UltraVoicePlugin.DeathcatcherVoiceEnabled = CreateEnemyToggle("deathcatchervoice", "Deathcatcher", defaultValue: true, val);
			UltraVoicePlugin.EarthmoverVoiceEnabled = CreateEnemyToggle("earthmovervoice", "Earthmover", defaultValue: true, val);
			UltraVoicePlugin.FerrymanVoiceEnabled = CreateEnemyToggle("ferrymanvoice", "Ferryman", defaultValue: true, val);
			UltraVoicePlugin.FilthVoiceEnabled = CreateEnemyToggle("filthvoice", "Filth", defaultValue: true, val);
			UltraVoicePlugin.GeryonVoiceEnabled = CreateEnemyToggle("geryonvoice", "Geryon", defaultValue: true, val);
			UltraVoicePlugin.GuttermanVoiceEnabled = CreateEnemyToggle("guttermanvoice", "Gutterman", defaultValue: true, val);
			UltraVoicePlugin.GuttertankVoiceEnabled = CreateEnemyToggle("guttertankvoice", "Guttertank", defaultValue: true, val);
			UltraVoicePlugin.MassVoiceEnabled = CreateEnemyToggle("massvoice", "Hideous Mass", defaultValue: true, val);
			UltraVoicePlugin.IdolVoiceEnabled = CreateEnemyToggle("idolvoice", "Idol", defaultValue: true, val);
			UltraVoicePlugin.InsurrectionistVoiceEnabled = CreateEnemyToggle("Insurrectionist", "Insurrectionist", defaultValue: true, val);
			UltraVoicePlugin.LeviathanVoiceEnabled = CreateEnemyToggle("levivoice", "Leviathan", defaultValue: true, val);
			UltraVoicePlugin.MauriceVoiceEnabled = CreateEnemyToggle("mauricevoice", "Malicious Face", defaultValue: true, val);
			UltraVoicePlugin.MannequinVoiceEnabled = CreateEnemyToggle("mannequinvoice", "Mannequin", defaultValue: true, val);
			UltraVoicePlugin.MindflayerVoiceEnabled = CreateEnemyToggle("mindflayervoice", "Mindflayer", defaultValue: true, val);
			UltraVoicePlugin.MirrorReaperVoiceEnabled = CreateEnemyToggle("mirrorreapervoice", "Mirror Reaper", defaultValue: true, val);
			UltraVoicePlugin.PowerAltVoiceEnabled = CreateEnemyToggle("poweraltvoice", "Power Alt", defaultValue: true, val);
			UltraVoicePlugin.ProvidenceVoiceEnabled = CreateEnemyToggle("providencevoice", "Providence", defaultValue: true, val);
			UltraVoicePlugin.SchismVoiceEnabled = CreateEnemyToggle("schismvoice", "Schism", defaultValue: true, val);
			UltraVoicePlugin.SentryVoiceEnabled = CreateEnemyToggle("sentryvoice", "Sentry", defaultValue: true, val);
			UltraVoicePlugin.ShopTerminalVoiceEnabled = CreateEnemyToggle("shopterminalvoice", "Shop Terminal", defaultValue: true, val);
			UltraVoicePlugin.SoldierVoiceEnabled = CreateEnemyToggle("soldiervoice", "Soldier", defaultValue: true, val);
			UltraVoicePlugin.StalkerVoiceEnabled = CreateEnemyToggle("stalkervoice", "Stalker", defaultValue: true, val);
			UltraVoicePlugin.StrayVoiceEnabled = CreateEnemyToggle("strayvoice", "Stray", defaultValue: true, val);
			UltraVoicePlugin.StreetcleanerVoiceEnabled = CreateEnemyToggle("streetcleanervoice", "Streetcleaner", defaultValue: true, val);
			UltraVoicePlugin.SwordsmachineVoiceEnabled = CreateEnemyToggle("swordsmachinevoice", "Swordsmachine", defaultValue: true, val);
			UltraVoicePlugin.V1VoiceEnabled = CreateEnemyToggle("v1voice", "V1", defaultValue: true, val);
			ConfigPanel panel = (UltraVoicePlugin.V1LinesPanel = CreatePanel(val, "v1lines", "V1 Line Categories"));
			(string, string)[] array = new(string, string)[21]
			{
				("kill", "Kill Lines"),
				("multikill", "Multikill Lines"),
				("bosskill", "Boss Kill Lines"),
				("headshot", "Headshot Lines"),
				("airshot", "Airshot Lines"),
				("environmental", "Environmental Kill Lines"),
				("crushed", "Crushed Lines"),
				("ricoshot", "Ricoshot Kill Lines"),
				("levelstart", "Level Start Lines"),
				("maxstyle", "Max Style Lines"),
				("rank", "Level Rank Lines"),
				("parry", "Parry Lines"),
				("enrage", "Enrage Lines"),
				("death", "Death Lines"),
				("pickup", "Weapon Pickup Lines"),
				("dualwield", "Dual Wield Lines"),
				("purchase", "Purchase Lines"),
				("skull", "Skull Pickup Lines"),
				("checkpoint", "Checkpoint Lines"),
				("respawn", "Respawn Lines"),
				("secret", "Secret Orb Lines")
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (text, name) = array[i];
				UltraVoicePlugin.V1LineToggles[text] = CreateSetting("v1line_" + text, name, defaultValue: true, panel);
			}
			UltraVoicePlugin.V2VoiceEnabled = CreateEnemyToggle("v2voice", "V2", defaultValue: true, val);
			UltraVoicePlugin.VirtueVoiceEnabled = CreateEnemyToggle("virtuevoice", "Virtue", defaultValue: true, val);
			UltraVoicePlugin.WickedVoiceEnabled = CreateEnemyToggle("wickedvoice", "Wicked", defaultValue: true, val);
		}

		private void BuildSubtitleColors()
		{
			ConfigPanel subtitleColorsPanel = UltraVoicePlugin.SubtitleColorsPanel;
			UltraVoicePlugin.SubtitleColorsEnabled = CreateSetting("subtitlecolorsenabled", "Enable Subtitle Colors", defaultValue: true, subtitleColorsPanel);
			ConfigPanel panel = (UltraVoicePlugin.CharacterSubtitleColorsPanel = CreatePanel(subtitleColorsPanel, "charsubtitlecolors", "Character Subtitle Colors"));
			(string, string)[] array = new(string, string)[24]
			{
				("Cerberus", "Cerberus"),
				("Deathcatcher", "Deathcatcher"),
				("Ferryman", "Ferryman"),
				("Geryon", "Geryon"),
				("Gutterman", "Gutterman"),
				("Guttertank", "Guttertank"),
				("HideousMass", "Hideous Mass"),
				("Idol", "Idol"),
				("Insurrectionist", "Insurrectionist"),
				("MaliciousFace", "Malicious Face"),
				("Mannequin", "Mannequin"),
				("Mindflayer", "Mindflayer"),
				("MirrorReaper", "Mirror Reaper"),
				("Power", "Power"),
				("Providence", "Providence"),
				("Sentry", "Sentry"),
				("Stalker", "Stalker"),
				("ShopTerminal", "Shop Terminal"),
				("Streetcleaner", "Streetcleaner"),
				("Swordsmachine", "Swordsmachine"),
				("V1", "V1"),
				("V2", "V2"),
				("Virtue", "Virtue"),
				("Wicked", "Wicked")
			};
			for (int i = 0; i < array.Length; i++)
			{
				var (text, name) = array[i];
				UltraVoicePlugin.SubtitleColorToggles[text] = CreateSetting("subcolor_" + text.ToLowerInvariant(), name, defaultValue: true, panel);
			}
		}

		private void BuildVoiceActors()
		{
			ConfigPanel actorPanel = UltraVoicePlugin.ActorPanel;
			UltraVoicePlugin.CerberusVoiceActorField = CreateActorSetting("cerbvoiceactor", "Cerberus", UltraVoicePlugin.CerberusVoiceActor.Mel, actorPanel, (UltraVoicePlugin.CerberusVoiceActor.Mel, "Mel"), (UltraVoicePlugin.CerberusVoiceActor.Soil, "Buried Soil"), (UltraVoicePlugin.CerberusVoiceActor.Rotund, "Rotund"));
			UltraVoicePlugin.EarthmoverVoiceActorField = CreateActorSetting("earthmovervoiceactor", "Earthmover", UltraVoicePlugin.EarthmoverVoiceActor.Rotund, actorPanel, (UltraVoicePlugin.EarthmoverVoiceActor.Rotund, "Rotund"), (UltraVoicePlugin.EarthmoverVoiceActor.Tondar, "TondarYZD"), (UltraVoicePlugin.EarthmoverVoiceActor.Megaslash, "Megaslash"));
			UltraVoicePlugin.FerrymanVoiceActorField = CreateActorSetting("ferryvoiceactor", "Ferryman", UltraVoicePlugin.FerrymanVoiceActor.Mel, actorPanel, (UltraVoicePlugin.FerrymanVoiceActor.Mel, "Mel"), (UltraVoicePlugin.FerrymanVoiceActor.Soil, "Buried Soil"), (UltraVoicePlugin.FerrymanVoiceActor.Nicky, "Nicky"));
			UltraVoicePlugin.GeryonVoiceActorField = CreateActorSetting("geryonvoiceactor", "Geryon", UltraVoicePlugin.GeryonVoiceActor.TheRatmanValinMegaslash, actorPanel, (UltraVoicePlugin.GeryonVoiceActor.TheRatmanValinMegaslash, "TheRatman, Valin, Megalash"), (UltraVoicePlugin.GeryonVoiceActor.Mel, "Mel"));
			UltraVoicePlugin.GuttermanVoiceActorField = CreateActorSetting("gmvoiceactor", "Gutterman", UltraVoicePlugin.GuttermanVoiceActor.Mel, actorPanel, (UltraVoicePlugin.GuttermanVoiceActor.Mel, "Mel"), (UltraVoicePlugin.GuttermanVoiceActor.Lemen, "Lemen"));
			UltraVoicePlugin.GuttertankVoiceActorField = CreateActorSetting("gtvoiceactor", "Guttertank", UltraVoicePlugin.GuttertankVoiceActor.Mel, actorPanel, (UltraVoicePlugin.GuttertankVoiceActor.Mel, "Mel"), (UltraVoicePlugin.GuttertankVoiceActor.Virchew, "Virchew"));
			UltraVoicePlugin.IdolVoiceActorField = CreateActorSetting("idolvoiceactor", "Idol", UltraVoicePlugin.IdolVoiceActor.Voinvi, actorPanel, (UltraVoicePlugin.IdolVoiceActor.Voinvi, "Voinvi"), (UltraVoicePlugin.IdolVoiceActor.Virchew, "Virchew"));
			UltraVoicePlugin.MirrorReaperVoiceActorField = CreateActorSetting("mrvoiceactor", "Mirror Reaper", UltraVoicePlugin.MirrorReaperVoiceActor.Noto, actorPanel, (UltraVoicePlugin.MirrorReaperVoiceActor.Noto, "Noto"), (UltraVoicePlugin.MirrorReaperVoiceActor.Rotund, "Rotund"));
			UltraVoicePlugin.PowerVoiceActorField = CreateActorSetting("powervoiceactor", "Power", UltraVoicePlugin.PowerVoiceActor.Random, actorPanel, (UltraVoicePlugin.PowerVoiceActor.Random, "Random"), (UltraVoicePlugin.PowerVoiceActor.Cazsu, "Cazsu (Masc)"), (UltraVoicePlugin.PowerVoiceActor.Goober, "Goober (Masc)"), (UltraVoicePlugin.PowerVoiceActor.NotoMasc, "Noto (Masc)"), (UltraVoicePlugin.PowerVoiceActor.Vanilla, "Kennady (Fem)"), (UltraVoicePlugin.PowerVoiceActor.Mel, "Mel (Fem)"), (UltraVoicePlugin.PowerVoiceActor.NotoFem, "Noto (Fem)"));
			ConfigPanel panel = (UltraVoicePlugin.PowerVoicePoolPanel = CreatePanel(actorPanel, "powervoicepool", "Power Voice Pool"));
			string[] powerVoiceOrder = UltraVoicePlugin.PowerVoiceOrder;
			foreach (string text in powerVoiceOrder)
			{
				UltraVoicePlugin.PowerVoiceToggles[text] = CreateSetting("powervoice_" + text.ToLowerInvariant(), UltraVoicePlugin.PowerVoiceNames[text], defaultValue: true, panel);
			}
			UltraVoicePlugin.SentryVoiceActorField = CreateActorSetting("svoiceactor", "Sentry", UltraVoicePlugin.SentryVoiceActor.Goober, actorPanel, (UltraVoicePlugin.SentryVoiceActor.Noto, "Noto"), (UltraVoicePlugin.SentryVoiceActor.Goober, "Goober"));
			UltraVoicePlugin.ShopTerminalVoiceActorField = CreateActorSetting("shopterminalvoiceactor", "Shop Terminal", UltraVoicePlugin.ShopTerminalVoiceActor.Bouncy, actorPanel, (UltraVoicePlugin.ShopTerminalVoiceActor.Bouncy, "Bouncy"), (UltraVoicePlugin.ShopTerminalVoiceActor.Goober, "Goober"));
			UltraVoicePlugin.SwordsmachineVoiceActorField = CreateActorSetting("smvoiceactor", "Swordsmachine", UltraVoicePlugin.SwordsmachineVoiceActor.Mel, actorPanel, (UltraVoicePlugin.SwordsmachineVoiceActor.Mel, "Mel"), (UltraVoicePlugin.SwordsmachineVoiceActor.Noto, "Noto"), (UltraVoicePlugin.SwordsmachineVoiceActor.Soil, "Buried Soil"));
			UltraVoicePlugin.V1VoiceActorField = CreateActorSetting("v1voiceactor", "V1", UltraVoicePlugin.V1VoiceActor.HashCap, actorPanel, (UltraVoicePlugin.V1VoiceActor.Cyberlord, "Cyberlord (Masc)"), (UltraVoicePlugin.V1VoiceActor.Noto, "Noto (Fem)"), (UltraVoicePlugin.V1VoiceActor.HashCap, "HashCap (Masc)"));
			UltraVoicePlugin.V1VoiceActorField.postValueChangeEvent += delegate
			{
				V1Character.ApplyVoiceActor();
			};
			UltraVoicePlugin.V2VoiceActorField = CreateActorSetting("v2voiceactor", "V2", UltraVoicePlugin.V2VoiceActor.Ruby, actorPanel, (UltraVoicePlugin.V2VoiceActor.Ruby, "Ruby (Fem)"), (UltraVoicePlugin.V2VoiceActor.Cazsu, "Cazsu (Masc)"));
			UltraVoicePlugin.VirtueVoiceActorField = CreateActorSetting("virtuevoiceactor", "Virtue", UltraVoicePlugin.VirtueVoiceActor.Noto, actorPanel, (UltraVoicePlugin.VirtueVoiceActor.Noto, "Noto"), (UltraVoicePlugin.VirtueVoiceActor.Virchew, "Virchew"));
		}

		private void BuildVolumes()
		{
			//IL_03f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0401: Expected O, but got Unknown
			ConfigPanel volumePanel = UltraVoicePlugin.VolumePanel;
			UltraVoicePlugin.MasterVolumeField = CreateSlider(volumePanel, "mastervolume", "Master Voice Volume", 100f, 0f, 200f, 0);
			ConfigPanel panel = (UltraVoicePlugin.EnemyVolumePanel = CreatePanel(volumePanel, "enemyvolumes", "Enemy Volumes"));
			(string, string, BoolField)[] array = new(string, string, BoolField)[29]
			{
				("Cerberus", "Cerberus", UltraVoicePlugin.CerberusVoiceEnabled),
				("Earthmover", "Earthmover", UltraVoicePlugin.EarthmoverVoiceEnabled),
				("Ferryman", "Ferryman", UltraVoicePlugin.FerrymanVoiceEnabled),
				("Filth", "Filth", UltraVoicePlugin.FilthVoiceEnabled),
				("Geryon", "Geryon", UltraVoicePlugin.GeryonVoiceEnabled),
				("Gutterman", "Gutterman", UltraVoicePlugin.GuttermanVoiceEnabled),
				("Guttertank", "Guttertank", UltraVoicePlugin.GuttertankVoiceEnabled),
				("HideousMass", "Hideous Mass", UltraVoicePlugin.MassVoiceEnabled),
				("Idol", "Idol", UltraVoicePlugin.IdolVoiceEnabled),
				("Insurrectionist", "Insurrectionist", UltraVoicePlugin.InsurrectionistVoiceEnabled),
				("Leviathan", "Leviathan", UltraVoicePlugin.LeviathanVoiceEnabled),
				("MaliciousFace", "Malicious Face", UltraVoicePlugin.MauriceVoiceEnabled),
				("Mannequin", "Mannequin", UltraVoicePlugin.MannequinVoiceEnabled),
				("Mindflayer", "Mindflayer", UltraVoicePlugin.MindflayerVoiceEnabled),
				("MirrorReaper", "Mirror Reaper", UltraVoicePlugin.MirrorReaperVoiceEnabled),
				("PowerAlt", "Power Alt", UltraVoicePlugin.PowerAltVoiceEnabled),
				("Providence", "Providence", UltraVoicePlugin.ProvidenceVoiceEnabled),
				("Schism", "Schism", UltraVoicePlugin.SchismVoiceEnabled),
				("Sentry", "Sentry", UltraVoicePlugin.SentryVoiceEnabled),
				("ShopTerminal", "Shop Terminal", UltraVoicePlugin.ShopTerminalVoiceEnabled),
				("Soldier", "Soldier", UltraVoicePlugin.SoldierVoiceEnabled),
				("Stalker", "Stalker", UltraVoicePlugin.StalkerVoiceEnabled),
				("Stray", "Stray", UltraVoicePlugin.StrayVoiceEnabled),
				("Streetcleaner", "Streetcleaner", UltraVoicePlugin.StreetcleanerVoiceEnabled),
				("Swordsmachine", "Swordsmachine", UltraVoicePlugin.SwordsmachineVoiceEnabled),
				("V1", "V1", UltraVoicePlugin.V1VoiceEnabled),
				("V2", "V2", UltraVoicePlugin.V2VoiceEnabled),
				("Virtue", "Virtue", UltraVoicePlugin.VirtueVoiceEnabled),
				("Wicked", "Wicked", UltraVoicePlugin.WickedVoiceEnabled)
			};
			for (int i = 0; i < array.Length; i++)
			{
				(string, string, BoolField) tuple = array[i];
				string item = tuple.Item1;
				string item2 = tuple.Item2;
				BoolField item3 = tuple.Item3;
				FloatSliderField slider = CreateSlider(panel, "volume_" + item.ToLowerInvariant(), item2, 100f, 0f, 200f, 0);
				UltraVoicePlugin.EnemyVolumeFields[item] = slider;
				((ConfigField)slider).hidden = !item3.value;
				item3.postValueChangeEvent += (PostBoolValueChangeEvent)delegate(bool enabled)
				{
					((ConfigField)slider).hidden = !enabled;
				};
			}
			UltraVoicePlugin.PowerAltVolumeField = UltraVoicePlugin.EnemyVolumeFields["PowerAlt"];
		}

		private static ConfigPanel CreatePanel(ConfigPanel parent, string guid, string name)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Expected O, but got Unknown
			return new ConfigPanel(parent, name, guid);
		}

		private static BoolField CreateSetting(string guid, string name, bool defaultValue, ConfigPanel panel)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			return new BoolField(panel, name, guid, defaultValue);
		}

		private static BoolField CreateEnemyToggle(string guid, string name, bool defaultValue, ConfigPanel panel)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			return new BoolField(panel, name, guid, defaultValue);
		}

		private static FloatSliderField CreateSlider(ConfigPanel panel, string guid, string name, float defaultValue, float min, float max, int decimals)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			return new FloatSliderField(panel, name, guid, new Tuple<float, float>(min, max), defaultValue, decimals);
		}

		private static EnumField<T> CreateActorSetting<T>(string guid, string name, T defaultValue, ConfigPanel panel, params (T actor, string label)[] options) where T : struct, Enum
		{
			EnumField<T> val = new EnumField<T>(panel, name, guid, defaultValue);
			for (int i = 0; i < options.Length; i++)
			{
				var (val2, text) = options[i];
				val.SetEnumDisplayName(val2, text);
			}
			return val;
		}
	}
	public class VoiceManager
	{
		private static float lastVoiceTime = -999f;

		private static Dictionary<int, float> enemyVoiceCooldown = new Dictionary<int, float>();

		private static Dictionary<string, float> eventCooldown = new Dictionary<string, float>();

		public static Dictionary<Component, float> spawnVoiceEndTimes = new Dictionary<Component, float>();

		public static Dictionary<Component, float> enemySpawnTimes = new Dictionary<Component, float>();

		public static Color GetEnemyTypeColor(EnemyType enemyType)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected I4, but got Unknown
			//IL_00fd: 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_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_0246: Unknown result type (might be due to invalid IL or missing references)
			//IL_024b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: 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_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_022f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_025d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Invalid comparison between Unknown and I4
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected I4, but got Unknown
			//IL_0199: Unknown result type (might be due to invalid IL or missing references)
			//IL_019e: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_0274: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_021d: Unknown result type (might be due to invalid IL or missing references)
			switch ((int)enemyType)
			{
			default:
				if ((int)enemyType != 26)
				{
					switch (enemyType - 31)
					{
					case 2:
						return new Color(0.91f, 0.73f, 0.51f);
					case 3:
						return new Color(0.81f, 0.12f, 0.12f);
					case 0:
						return new Color(0.91f, 0.91f, 0.91f);
					case 7:
						return new Color(0.9f, 0.79f, 0.86f);
					case 10:
						return new Color(0.9f, 0.85f, 0.76f);
					case 8:
						return new Color(1f, 0f, 0f);
					}
					break;
				}
				return new Color(0f, 0.66f, 0.77f);
			case 8:
				return new Color(0.8f, 0.07f, 0.07f);
			case 7:
				return new Color(0.91f, 0.6f, 0.05f);
			case 6:
				return new Color(0.82f, 0.3f, 0.09f);
			case 0:
				return new Color(0.65f, 0.65f, 0.65f);
			case 5:
				return new Color(0.26f, 0.89f, 0.74f);
			case 9:
				return new Color(0.4f, 0.75f, 0.94f);
			case 12:
				return new Color(0.67f, 0.61f, 0.47f);
			case 20:
				return new Color(0.51f, 0.68f, 0.1f);
			case 4:
				return new Color(0.76f, 0.66f, 0.56f);
			case 19:
				return new Color(0.79f, 0.58f, 0.49f);
			case 2:
				return new Color(0.67f, 0.57f, 0.57f);
			case 21:
				return new Color(0.62f, 0.87f, 0.92f);
			case 1:
			case 3:
			case 10:
			case 11:
			case 13:
			case 14:
			case 15:
			case 16:
			case 17:
			case 18:
				break;
			}
			return Color.white;
		}

		public static Color? GetSubtitleColor(Component enemy, Color? colorOverride)
		{
			//IL_000b: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			if (colorOverride.HasValue)
			{
				return colorOverride.Value;
			}
			EnemyIdentifier val = default(EnemyIdentifier);
			if (enemy.TryGetComponent<EnemyIdentifier>(ref val))
			{
				return GetEnemyTypeColor(val.enemyType);
			}
			return null;
		}

		public static bool CheckCooldown(Component enemy, float cooldown)
		{
			int instanceID = ((Object)enemy).GetInstanceID();
			if (enemyVoiceCooldown.TryGetValue(instanceID, out var value) && Time.time - value < cooldown)
			{
				return false;
			}
			enemyVoiceCooldown[instanceID] = Time.time;
			return true;
		}

		public static bool CheckEventCooldown(string key, float cooldown)
		{
			if (eventCooldown.TryGetValue(key, out var value) && Time.time - value < cooldown)
			{
				return false;
			}
			eventCooldown[key] = Time.time;
			return true;
		}

		public static bool CheckGlobalCooldown()
		{
			if (Time.time - lastVoiceTime < UltraVoicePlugin.VoiceCooldown.value)
			{
				return false;
			}
			lastVoiceTime = Time.time;
			return true;
		}

		public static bool IsSpawnVoicePlaying(Component enemy)
		{
			if (!spawnVoiceEndTimes.TryGetValue(enemy, out var value))
			{
				return false;
			}
			return Time.time < value;
		}

		public static bool IsEnemyVoicePlaying(Component enemy)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in enemy.transform)
			{
				if (((Object)item).name.StartsWith("UltraVoice_"))
				{
					return true;
				}
			}
			return false;
		}

		public static bool TooSoonAfterSpawn(Component enemy, float delay)
		{
			if (!enemySpawnTimes.TryGetValue(enemy, out var value))
			{
				return false;
			}
			return Time.time - value < delay;
		}

		public static AudioClip ToMono(AudioClip clip)
		{
			if ((Object)(object)clip == (Object)null || clip.channels == 1)
			{
				return clip;
			}
			int channels = clip.channels;
			float[] array = new float[clip.samples * channels];
			clip.GetData(array, 0);
			float[] array2 = new float[clip.samples];
			for (int i = 0; i < array2.Length; i++)
			{
				float num = 0f;
				for (int j = 0; j < channels; j++)
				{
					num += array[i * channels + j];
				}
				array2[i] = num / (float)channels;
			}
			AudioClip obj = AudioClip.Create(((Object)clip).name, clip.samples, 1, clip.frequency, false);
			obj.SetData(array2, 0);
			return obj;
		}

		public static AudioClip AmplifyClip(AudioClip clip, float gain)
		{
			float[] array = new float[clip.samples * clip.channels];
			clip.GetData(array, 0);
			for (int i = 0; i < array.Length; i++)
			{
				array[i] = Mathf.Clamp(array[i] * gain, -1f, 1f);
			}
			AudioClip obj = AudioClip.Create(((Object)clip).name + "_amp", clip.samples, clip.channels, clip.frequency, false);
			obj.SetData(array, 0);
			return obj;
		}

		public static void ApplyVolume(AudioSource src, float gain)
		{
			if (gain > 1f && (Object)(object)src.clip != (Object)null)
			{
				src.clip = AmplifyClip(src.clip, gain);
				src.volume = 1f;
				Object.Destroy((Object)(object)src.clip, src.clip.length + 2f);
			}
			else
			{
				src.volume = gain;
			}
		}

		public static AudioSource CreateVoiceSource(Component enemy, string name, AudioClip clip, string subtitle = null, bool shouldInterrupt = false, Color? subtitleColor = null, bool randomPitch = false, float spatialBlend = 1f, float volumeMult = 1f, bool parentToEnemy = true, float maxDistance = 200f, bool ignoreTimeFreeze = false)
		{
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Expected O, but got Unknown
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			if (!UltraVoicePlugin.VoicesEnabled)
			{
				return null;
			}
			if ((Object)(object)enemy == (Object)null || (Object)(object)clip == (Object)null)
			{
				return null;
			}
			string name2 = ((Object)enemy.gameObject).name;
			if (name2.Contains("Johnator") || name2.Contains("Johninator"))
			{
				return null;
			}
			EnemyIdentifier val = default(EnemyIdentifier);
			if (enemy.gameObject.TryGetComponent<EnemyIdentifier>(ref val) && val.puppet)
			{
				return null;
			}
			bool flag = name == "V1" || name == "ShopTerminal";
			if (!shouldInterrupt)
			{
				if (!flag && !CheckGlobalCooldown())
				{
					return null;
				}
				if (IsEnemyVoicePlaying(enemy))
				{
					return null;
				}
			}
			else
			{
				InterruptVoices(enemy);
			}
			if (!flag)
			{
				lastVoiceTime = Time.time;
			}
			GameObject val2 = new GameObject("UltraVoice_" + name);
			if (parentToEnemy)
			{
				val2.transform.SetParent(enemy.transform);
				val2.transform.localPosition = Vector3.zero;
			}
			else
			{
				val2.transform.position = enemy.transform.position;
			}
			AudioSource val3 = val2.AddComponent<AudioSource>();
			val3.clip = clip;
			AudioSourceExtensions.SetSpatialBlend(val3, spatialBlend);
			bool flag2 = name == "ShopTerminal";
			ApplyVolume(val3, Mathf.Min(volumeMult, 1f) * UltraVoicePlugin.GetVoiceVolume(name));
			val3.minDistance = (flag2 ? 8f : 50f);
			val3.maxDistance = (flag2 ? 35f : maxDistance);
			val3.dopplerLevel = 0.25f;
			if (randomPitch)
			{
				AudioSourceExtensions.SetPitch(val3, Random.Range(0.95f, 1.05f));
			}
			AudioMixerController instance = MonoSingleton<AudioMixerController>.Instance;
			if ((Object)(object)instance != (Object)null)
			{
				val3.outputAudioMixerGroup = (ignoreTimeFreeze ? instance.unfreezeableGroup : instance.allGroup);
			}
			AudioSourceExtensions.Play(val3, true);
			Color? subtitleColor2 = GetSubtitleColor(enemy, subtitleColor);
			if (!string.IsNullOrEmpty(subtitle))
			{
				ShowSubtitle(subtitle, val3, subtitleColor2, ignoreTimeFreeze);
			}
			val2.AddComponent<RemoveOnTime>().useAudioLength = true;
			return val3;
		}

		public static void PlayRandomVoice(Component enemy, string enemyName, AudioClip[] clips, string[] subtitles, bool interrupt = false, bool randomPitch = false, float volumeMult = 1f, Color? colorOverride = null, float spatialBlend = 1f, bool ignoreTimeFreeze = false)
		{
			if (clips != null && clips.Length != 0)
			{
				int num = Random.Range(0, clips.Length);
				string subtitle = null;
				if (subtitles != null && num < subtitles.Length)
				{
					subtitle = subtitles[num];
				}
				CreateVoiceSource(enemy, enemyName, clips[num], subtitle, interrupt, colorOverride, randomPitch, spatialBlend, volumeMult, parentToEnemy: true, 200f, ignoreTimeFreeze);
			}
		}

		public static void PlayRandomVoiceDelayed(float delay, Component enemy, string enemyName, AudioClip[] clips, string[] subtitles, bool interrupt = false, bool randomPitch = false, float volumeMult = 1f, Color? colorOverride = null, float spatialBlend = 1f)
		{
			((MonoBehaviour)UltraVoicePlugin.Instance).StartCoroutine(Routine());
			IEnumerator Routine()
			{
				yield return (object)new WaitForSeconds(delay);
				if (!((Object)(object)enemy == (Object)null))
				{
					PlayRandomVoice(enemy, enemyName, clips, subtitles, interrupt, randomPitch, volumeMult, colorOverride, spatialBlend);
				}
			}
		}

		public static void ShowSubtitle(string text, AudioSource src, Color? color = null, bool ignoreTimeFreeze = false)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(text))
			{
				return;
			}
			if (color.HasValue && (Object)(object)src != (Object)null && ((Object)((Component)src).gameObject).name.StartsWith("UltraVoice_") && !UltraVoicePlugin.SubtitleColorAllowed(((Object)((Component)src).gameObject).name.Substring(11)))
			{
				color = null;
			}
			if (color.HasValue)
			{
				text = "<color=#" + ColorUtility.ToHtmlStringRGB(color.Value) + ">" + text + "</color>";
			}
			SubtitleController instance = MonoSingleton<SubtitleController>.Instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			Subtitle previousSubtitle = instance.previousSubtitle;
			instance.DisplaySubtitle(text, src, false);
			if (ignoreTimeFreeze)
			{
				Subtitle previousSubtitle2 = instance.previousSubtitle;
				if (!((Object)(object)previousSubtitle2 == (Object)null) && !((Object)(object)previousSubtitle2 == (Object)(object)previousSubtitle))
				{
					((MonoBehaviour)UltraVoicePlugin.Instance).StartCoroutine(UnfreezeSubtitle(previousSubtitle2, src));
				}
			}
		}

		private static IEnumerator UnfreezeSubtitle(Subtitle subtitle, AudioSource src)
		{
			yield return null;
			if ((Object)(object)subtitle == (Object)null)
			{
				yield break;
			}
			float preferredSize = LayoutUtility.GetPreferredSize(subtitle.uiText.rectTransform, 0);
			subtitle.uiText.rectTransform.SetSizeWithCurrentAnchors((Axis)0, preferredSize);
			subtitle.rectTransform.SetSizeWithCurrentAnchors((Axis)0, preferredSize + subtitle.paddingHorizontal * 2f);
			while ((Object)(object)subtitle != (Object)null && subtitle.isFadingIn)
			{
				subtitle.currentAlpha += subtitle.fadeInSpeed * Time.unscaledDeltaTime;
				yield return null;
			}
			yield return (object)new WaitForSecondsRealtime(((Object)(object)subtitle == (Object)null) ? 0f : subtitle.holdFor);
			if (!((Object)(object)subtitle == (Object)null))
			{
				subtitle.chainContinue = true;
				subtitle.holdingSince = TimeSince.op_Implicit(subtitle.holdFor + 1f);
				while ((Object)(object)subtitle != (Object)null && !subtitle.isFadingOut)
				{
					yield return null;
				}
				while ((Object)(object)subtitle != (Object)null)
				{
					subtitle.currentAlpha -= subtitle.fadeOutSpeed * Time.unscaledDeltaTime;
					yield return null;
				}
			}
		}

		public static void InterruptVoices(Component enemy)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			foreach (Transform item in enemy.transform)
			{
				Transform val = item;
				if (((Object)val).name.StartsWith("UltraVoice_"))
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
		}
	}
	public static class WavUtility
	{
		public static AudioClip ToAudioClip(byte[] fileBytes, string name = "AudioClip")
		{
			using (MemoryStream memoryStream = new MemoryStream(fileBytes))
			{
				using BinaryReader binaryReader = new BinaryReader(memoryStream);
				if (new string(binaryReader.ReadChars(4)) != "RIFF")
				{
					return null;
				}
				binaryReader.ReadInt32();
				if (new string(binaryReader.ReadChars(4)) != "WAVE")
				{
					return null;
				}
				int num = 0;
				int num2 = 0;
				int num3 = 0;
				while (memoryStream.Position < memoryStream.Length)
				{
					string text = new string(binaryReader.ReadChars(4));
					int num4 = binaryReader.ReadInt32();
					if (text == "fmt ")
					{
						binaryReader.ReadInt16();
						num = binaryReader.ReadInt16();
						num2 = binaryReader.ReadInt32();
						binaryReader.ReadInt32();
						binaryReader.ReadInt16();
						num3 = binaryReader.ReadInt16() / 8;
						if (num4 > 16)
						{
							binaryReader.ReadBytes(num4 - 16);
						}
						continue;
					}
					if (text == "data")
					{
						int num5 = num4 / num3 / num;
						float[] array = new float[num5 * num];
						for (int i = 0; i < num5 * num; i++)
						{
							switch (num3)
							{
							case 2:
							{
								short num6 = binaryReader.ReadInt16();
								array[i] = (float)num6 / 32768f;
								break;
							}
							case 1:
							{
								byte b = binaryReader.ReadByte();
								array[i] = (float)(b - 128) / 128f;
								break;
							}
							}
						}
						AudioClip obj = AudioClip.Create(name, num5, num, num2, false);
						obj.SetData(array, 0);
						return obj;
					}
					binaryReader.ReadBytes(num4);
				}
			}
			return null;
		}
	}
}
namespace UltraVoice.Characters
{
	public class CerberusCharacter
	{
		public static AudioClip PreludeClip;

		public static AudioClip[] AwakenClips;

		public static AudioClip[] EnrageClips;

		public static AudioClip[] ThrowClips;

		public static AudioClip[] StompClips;

		public static AudioClip[] TackleClips;

		public static AudioClip[] DeathClips;

		public static AudioClip PreludeClipSoil;

		public static AudioClip[] AwakenClipsSoil;

		public static AudioClip[] EnrageClipsSoil;

		public static AudioClip[] ThrowClipsSoil;

		public static AudioClip[] StompClipsSoil;

		public static AudioClip[] TackleClipsSoil;

		public static AudioClip[] DeathClipsSoil;

		public static AudioClip PreludeClipRotund;

		public static AudioClip[] AwakenClipsRotund;

		public static AudioClip[] EnrageClipsRotund;

		public static AudioClip[] ThrowClipsRotund;

		public static AudioClip[] StompClipsRotund;

		public static AudioClip[] TackleClipsRotund;

		public static AudioClip[] DeathClipsRotund;

		public static readonly string[] AwakenSubs = new string[6] { "Who dares awaken me?", "You will go no further", "Your story ends here", "Your defiance shall be punished", "Be gone, or be destroyed", "You stand condemned" };

		public static readonly string[] EnrageSubs = new string[4] { "You will regret crossing me!", "Your arrogance will cost you!", "I will avenge my brother!", "This shall not go unpunished!" };

		public static readonly string[] ThrowSubs = new string[2] { "Perish", "Die" };

		public static readonly string[] StompSubs = new string[2] { "Tremble", "Fall" };

		public static readonly string[] TackleSubs = new string[2] { "Face me", "You cannot run" };

		public static Color CerberusColor => VoiceManager.GetEnemyTypeColor((EnemyType)0);

		public static AudioClip UseCerberusClip(AudioClip melClip, AudioClip soilClip, AudioClip rotundClip)
		{
			if (UltraVoicePlugin.CerberusVoiceActorField == null)
			{
				return melClip;
			}
			return (AudioClip)(UltraVoicePlugin.CerberusVoiceActorField.value switch
			{
				UltraVoicePlugin.CerberusVoiceActor.Soil => soilClip, 
				UltraVoicePlugin.CerberusVoiceActor.Rotund => rotundClip, 
				_ => melClip, 
			});
		}

		public static AudioClip[] UseCerberusClips(AudioClip[] melClips, AudioClip[] soilClips, AudioClip[] rotundClips)
		{
			if (UltraVoicePlugin.CerberusVoiceActorField == null)
			{
				return melClips;
			}
			return UltraVoicePlugin.CerberusVoiceActorField.value switch
			{
				UltraVoicePlugin.CerberusVoiceActor.Soil => soilClips, 
				UltraVoicePlugin.CerberusVoiceActor.Rotund => rotundClips, 
				_ => melClips, 
			};
		}

		public static void LoadVoiceLines(ManualLogSource logger)
		{
			PreludeClip = UltraVoicePlugin.LoadClip("Cerberus.Mel.cerb_WakeUpSpecial.wav");
			AwakenClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_WakeUp{0}.wav", 6);
			EnrageClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_Enrage{0}.wav", 4);
			ThrowClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_Orb{0}.wav", 2);
			StompClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_Stomp{0}.wav", 2);
			TackleClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_Tackle{0}.wav", 2);
			DeathClips = UltraVoicePlugin.LoadClips("Cerberus.Mel.cerb_Death{0}.wav", 3);
			PreludeClipSoil = UltraVoicePlugin.LoadClip("Cerberus.Soil.cerb_WakeUpSpecial.wav");
			AwakenClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_WakeUp{0}.wav", 6);
			EnrageClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_Enrage{0}.wav", 4);
			ThrowClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_Orb{0}.wav", 2);
			StompClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_Stomp{0}.wav", 2);
			TackleClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_Tackle{0}.wav", 2);
			DeathClipsSoil = UltraVoicePlugin.LoadClips("Cerberus.Soil.cerb_Death{0}.wav", 3);
			PreludeClipRotund = UltraVoicePlugin.LoadClip("Cerberus.Rotund.cerb_WakeUpSpecial.wav");
			AwakenClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_WakeUp{0}.wav", 6);
			EnrageClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_Enrage{0}.wav", 4);
			ThrowClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_Orb{0}.wav", 2);
			StompClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_Stomp{0}.wav", 2);
			TackleClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_Tackle{0}.wav", 2);
			DeathClipsRotund = UltraVoicePlugin.LoadClips("Cerberus.Rotund.cerb_Death{0}.wav", 3);
			logger.LogInfo((object)"Cerberus voice lines loaded successfully!");
		}
	}
	[HarmonyPatch(typeof(StatueFake), "SlowStart")]
	internal class CerberusIntroPatch
	{
		private static void Postfix(StatueFake __instance)
		{
			if (!__instance.quickSpawn && UltraVoicePlugin.CerberusVoiceEnabled.value)
			{
				((MonoBehaviour)UltraVoicePlugin.Instance).StartCoroutine(PlayIntro(__instance));
			}
		}

		private static IEnumerator PlayIntro(StatueFake cerb)
		{
			yield return (object)new WaitForSeconds(3.5f);
			if ((Object)(object)cerb == (Object)null)
			{
				yield break;
			}
			AudioSource src = VoiceManager.CreateVoiceSource((Component)(object)cerb, "CerberusIntro", CerberusCharacter.UseCerberusClip(CerberusCharacter.PreludeClip, CerberusCharacter.PreludeClipSoil, CerberusCharacter.PreludeClipRotund), "You tread forbidden ground, machine", shouldInterrupt: true, CerberusCharacter.CerberusColor, randomPitch: false, 1f, 1f, parentToEnemy: false, 500f);
			if (!((Object)(object)src == (Object)null))
			{
				yield return (object)new WaitForSeconds(3.75f);
				if (!((Object)(object)src == (Object)null))
				{
					VoiceManager.ShowSubtitle("BEGONE", src, CerberusCharacter.CerberusColor);
				}
			}
		}
	}
	[HarmonyPatch(typeof(StatueFake), "Activate")]
	internal class CerberusWakePatch
	{
		private static void Postfix(StatueFake __instance)
		{
			if (__instance.quickSpawn && UltraVoicePlugin.CerberusVoiceEnabled.value && VoiceManager.CheckCooldown((Component)(object)__instance, 3f))
			{
				VoiceManager.enemySpawnTimes[(Component)(object)__instance] = Time.time;
				((MonoBehaviour)UltraVoicePlugin.Instance).StartCoroutine(PlayAwaken(__instance));
			}
		}

		private static IEnumerator PlayAwaken(StatueFake cerb)
		{
			yield return (object)new WaitForSeconds(Random.Range(0f, 1f));
			if (!((Object)(object)cerb == (Object)null))
			{
				AudioClip[] array = CerberusCharacter.UseCerberusClips(CerberusCharacter.AwakenClips, CerberusCharacter.AwakenClipsSoil, CerberusCharacter.AwakenClipsRotund);
				int num = Random.Range(0, array.Length);
				VoiceManager.CreateVoiceSource((Component)(object)cerb, "CerberusAwaken", array[num], CerberusCharacter.AwakenSubs[num], shouldInterrupt: true, CerberusCharacter.CerberusColor, randomPitch: false, 1f, 1f, parentToEnemy: false, 500f);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "Start")]
	internal class CerberusSpawnTracker
	{
		private static void Postfix(StatueBoss __instance)
		{
			VoiceManager.enemySpawnTimes[(Component)(object)__instance] = Time.time;
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "Enrage")]
	internal class CerberusEnragePatch
	{
		private static void Postfix(StatueBoss __instance)
		{
			if (UltraVoicePlugin.CerberusVoiceEnabled.value)
			{
				VoiceManager.PlayRandomVoiceDelayed(Random.Range(0f, 0.4f), (Component)(object)__instance, "Cerberus", CerberusCharacter.UseCerberusClips(CerberusCharacter.EnrageClips, CerberusCharacter.EnrageClipsSoil, CerberusCharacter.EnrageClipsRotund), CerberusCharacter.EnrageSubs, interrupt: true, randomPitch: true);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "Throw")]
	internal class CerberusThrowPatch
	{
		private static void Postfix(StatueBoss __instance)
		{
			if (UltraVoicePlugin.CerberusVoiceEnabled.value && !VoiceManager.IsSpawnVoicePlaying((Component)(object)__instance) && VoiceManager.CheckCooldown((Component)(object)__instance, 3f))
			{
				VoiceManager.PlayRandomVoiceDelayed(0.2f, (Component)(object)__instance, "Cerberus", CerberusCharacter.UseCerberusClips(CerberusCharacter.ThrowClips, CerberusCharacter.ThrowClipsSoil, CerberusCharacter.ThrowClipsRotund), CerberusCharacter.ThrowSubs, interrupt: false, randomPitch: true);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "Stomp")]
	internal class CerberusStompPatch
	{
		private static void Postfix(StatueBoss __instance)
		{
			if (UltraVoicePlugin.CerberusVoiceEnabled.value && !VoiceManager.IsSpawnVoicePlaying((Component)(object)__instance) && VoiceManager.CheckCooldown((Component)(object)__instance, 3f))
			{
				VoiceManager.PlayRandomVoiceDelayed(0.2f, (Component)(object)__instance, "Cerberus", CerberusCharacter.UseCerberusClips(CerberusCharacter.StompClips, CerberusCharacter.StompClipsSoil, CerberusCharacter.StompClipsRotund), CerberusCharacter.StompSubs, interrupt: false, randomPitch: true);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "Tackle")]
	internal class CerberusTacklePatch
	{
		private static void Postfix(StatueBoss __instance)
		{
			if (UltraVoicePlugin.CerberusVoiceEnabled.value && !VoiceManager.IsSpawnVoicePlaying((Component)(object)__instance) && VoiceManager.CheckCooldown((Component)(object)__instance, 3f))
			{
				VoiceManager.PlayRandomVoiceDelayed(0.2f, (Component)(object)__instance, "Cerberus", CerberusCharacter.UseCerberusClips(CerberusCharacter.TackleClips, CerberusCharacter.TackleClipsSoil, CerberusCharacter.TackleClipsRotund), CerberusCharacter.TackleSubs, interrupt: false, randomPitch: true);
			}
		}
	}
	[HarmonyPatch(typeof(StatueBoss), "OnGoLimp")]
	internal class CerberusDeathPatch
	{
		private static void Postfix(StatueBoss __instance)
		{
			if (UltraVoicePlugin.CerberusVoiceEnabled.value)
			{
				VoiceManager.PlayRandomVoice((Component)(object)__instance, "Cerberus", CerberusCharacter.UseCerberusClips(CerberusCharacter.DeathClips, CerberusCharacter.DeathClipsSoil, CerberusCharacter.DeathClipsRotund), null, interrupt: true, randomPitch: true);
			}
		}
	}
	public class DeathcatcherCharacter
	{
		public static AudioClip[] ReviveClips;

		public static readonly string[] ReviveSubs = new string[6] { "No, no, no...", "I promised...", "I'm sorry...", "The pieces...", "Protected... see?", "Stay with me..." };

		public static void LoadVoiceLines(ManualLogSource logger)
		{
			ReviveClips = UltraVoicePlugin.LoadClips("Deathcatcher.Test.dc_Revive{0}.wav", 6);
			logger.LogInfo((object)"Deathcatcher voice lines loaded successfully!");
		}
	}
	[HarmonyPatch(typeof(Deathcatcher), "RespawnPuppets")]
	internal class DeathcatcherRevivePatch
	{
		private static void Postfix(Deathcatcher __instance)
		{
			if (UltraVoicePlugin.DeathcatcherVoiceEnabled.value && __instance.chargeAud.isPlaying)
			{
				VoiceManager.PlayRandomVoice((Component)(object)__instance, "Deathcatcher", DeathcatcherCharacter.ReviveClips, DeathcatcherCharacter.ReviveSubs, interrupt: false, randomPitch: true);
			}
		}
	}
	public class EarthmoverCharacter
	{
		public static AudioClip IntroClip;

		public static AudioClip ShootClip;

		public static AudioClip DeathClip;

		public static AudioClip IdolClip;

		public static AudioClip BloodVentClip;

		public static AudioClip DefenseSystemClip;

		public static AudioClip BloodFloodClip;

		public static AudioClip BrainBattleClip;

		public static AudioClip BrainKilledClip;

		public static AudioClip IntroClipTondar;

		public static AudioClip ShootClipTondar;

		public static AudioClip DeathClipTondar;

		public static AudioClip IdolClipTondar;

		public static AudioClip BloodVentClipTondar;

		public static AudioClip DefenseSystemClipTondar;

		public static AudioClip BloodFloodClipTondar;

		public static AudioClip BrainBattleClipTondar;

		public static AudioClip BrainKilledClipTondar;

		public static AudioClip IntroClipMegaslash;

		public static AudioClip ShootClipMegaslash;

		public static AudioClip DeathClipMegaslash;

		public static AudioClip IdolClipMegaslash;

		public static AudioClip BloodVentClipMegaslash;

		public static AudioClip DefenseSystemClipMegaslash;

		public static AudioClip BloodFloodClipMegaslash;

		public static AudioClip BrainBattleClipMegaslash;

		public static AudioClip BrainKilledClipMegaslash;

		public const string EarthmoverSceneName = "6e981b1865c649749a610aafc471e198";

		public static float lastBloodFloodTime;

		public static float lastBrainBattleTime;

		public static float lastSelfDestructTime;

		public static bool IntroPlayed = false;

		public static bool DeathPlayed = false;

		public static float lastIdolTime = -999f;

		public static UltraVoicePlugin.EarthmoverVoiceActor CurrentActor
		{
			get
			{
				if (UltraVoicePlugin.EarthmoverVoiceActorField == null)
				{
					return UltraVoicePlugin.EarthmoverVoiceActor.Rotund;
				}
				return UltraVoicePlugin.EarthmoverVoiceActorField.value;
			}
		}

		public static AudioClip UseEarthmoverClip(AudioClip rotundClip, AudioClip tondarClip, AudioClip megaslashClip)
		{
			return (AudioClip)(CurrentActor switch
			{
				UltraVoicePlugin.EarthmoverVoiceActor.Tondar => tondarClip, 
				UltraVoicePlugin.EarthmoverVoiceActor.Megaslash => megaslashClip, 
				_ => rotundClip, 
			});
		}

		public static float UseEarthmoverDelay(float rotundDelay, float tondarDelay, float megaslashDelay)
		{
			return CurrentActor switch
			{
				UltraVoicePlugin.EarthmoverVoiceActor.Tondar => tondarDelay, 
				UltraVoicePlugin.EarthmoverVoiceActor.Megaslash => megaslashDelay, 
				_ => rotundDelay, 
			};
		}

		public static void TryIntro(string bossName)
		{
			if (!IntroPlayed && !string.IsNullOrEmpty(bossName) && bossName.Contains("EARTHMOVER") && UltraVoicePlugin.EarthmoverVoiceEnabled.value)
			{
				IntroPlayed = true;
				PlayAnnouncement(3f, "Earthmover_Intro", UseEarthmoverClip(IntroClip, IntroClipTondar, IntroClipMegaslash), "HIGH-PRIORITY TARGET DETECTED", (2.15f, 2.55f, 2.9f, "READYING WEAPONS"));
			}
		}

		public static bool InEarthmoverLevel()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			return ((Scene)(ref activeScene)).name == "6e981b1865c649749a610aafc471e198";
		}

		public static void LoadVoiceLines(ManualLogSource logger)
		{
			IntroClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_Intro.wav");
			ShootClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_Shoot.wav");
			DeathClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_Death.wav");
			IdolClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_Idol.wav");
			BloodVentClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_BloodVent.wav");
			DefenseSystemClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_DefenseSystem.wav");
			BloodFloodClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_BloodFlood.wav");
			BrainBattleClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_BrainBattle.wav");
			BrainKilledClip = UltraVoicePlugin.LoadClip("Earthmover.Rotund.em_BrainKilled.wav");
			IntroClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_Intro.wav");
			ShootClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_Shoot.wav");
			DeathClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_Death.wav");
			IdolClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_Idol.wav");
			BloodVentClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_BloodVent.wav");
			DefenseSystemClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_DefenseSystem.wav");
			BloodFloodClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_BloodFlood.wav");
			BrainBattleClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_BrainBattle.wav");
			BrainKilledClipTondar = UltraVoicePlugin.LoadClip("Earthmover.Tondar.em_BrainKilled.wav");
			IntroClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_Intro.wav");
			ShootClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_Shoot.wav");
			DeathClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_Death.wav");
			IdolClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_Idol.wav");
			BloodVentClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_BloodVent.wav");
			DefenseSystemClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_DefenseSystem.wav");
			BloodFloodClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_BloodFlood.wav");
			BrainBattleClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_BrainBattle.wav");
			BrainKilledClipMegaslash = UltraVoicePlugin.LoadClip("Earthmover.Megaslash.em_BrainKilled.wav");
			logger.LogInfo((object)"Earthmover voice lines loaded successfully!");
		}

		public static void PlayShootAnnouncement()
		{
			if (VoiceManager.CheckEventCooldown("Earthmover_Shoot", 5f))
			{
				PlayAnnouncement(3f, "Earthmover_Shoot", UseEarthmoverClip(ShootClip, ShootClipTondar, ShootClipMegaslash), "FIRING SEQUENCE INTERRUPTED", (2.1f, 2.05f, 2.55f, "EXTERIOR HULL INTEGRITY:"), (1.5f, 1.6f, 2.4f, "60%"));
			}
		}

		public static void PlayAnnouncement(float startDelay, string sourceName, AudioClip clip, string firstSub, params (float rotundDelay, float tondarDelay, float megaslashDelay, string text)[] followUps)
		{
			((MonoBehaviour)UltraVoicePlugin.Instance).StartCoroutine(Routine());
			IEnumerator Routine()
			{
				yield return (object)new WaitForSeconds(startDelay);
				AudioSource src = VoiceManager.CreateVoiceSource((Component)(object)MonoSingleton<NewMovement>.Instance, sourceName, clip, firstSub, shouldInterrupt: true, null, randomPitch: false, 0f);
				if (!((Object)(object)src == (Object)null))
				{
					(float rotundDelay, float tondarDelay, float megaslashDelay, string text)[] array = followUps;
					for (int i = 0; i < array.Length; i++)
					{
						var (rotundDelay, tondarDelay, megaslashDelay, text) = array[i];
						yield return (object)new WaitForSeconds(UseEarthmoverDelay(rotundDelay, tondarDelay, megaslashDelay));
						if ((Object)(object)src == (Object)null)
						{
							break;
						}
						VoiceManager.ShowSubtitle(text, src);
					}
				}
			}
		}
	}
	[HarmonyPatch(typeof(EnemyIdentifier), "Bless")]
	internal class EarthmoverIdolPatch
	{
		private static void Prefix(EnemyIdentifier __instance, out bool __state)
		{
			__state = (Object)(object)__instance != (Object)null && __instance.blessed;
		}

		private static void Postfix(EnemyIdentifier __instance, bool ignorePrevious, bool __state)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Invalid comparison between Unknown and I4
			if (!((Object)(object)__instance == (Object)null) && (int)__instance.enemyType == 35 && !(__state || ignorePrevious) && __instance.blessed && EarthmoverCharacter.InEarthmoverLevel() && UltraVoicePlugin.EarthmoverVoiceEnabled.value && !(Time.time - EarthmoverCharacter.lastIdolTime < 5f))
			{
				EarthmoverCharacter.lastIdolTime = Time.time;
				EarthmoverCharacter.PlayAnnouncement(0f, "Earthmover_Idol", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.IdolClip, EarthmoverCharacter.IdolClipTondar, EarthmoverCharacter.IdolClipMegaslash), "ENGAGING SHIELD.");
			}
		}
	}
	[HarmonyPatch(typeof(Countdown), "Update")]
	internal class EarthmoverDeathPatch
	{
		private static void Postfix(Countdown __instance)
		{
			if (!EarthmoverCharacter.DeathPlayed && UltraVoicePlugin.EarthmoverVoiceEnabled.value && EarthmoverCharacter.InEarthmoverLevel() && !(((Object)__instance).name != "Countdown") && !__instance.paused && !(__instance.time > 2.7f))
			{
				EarthmoverCharacter.DeathPlayed = true;
				EarthmoverCharacter.PlayAnnouncement(0f, "Earthmover_Death", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.DeathClip, EarthmoverCharacter.DeathClipTondar, EarthmoverCharacter.DeathClipMegaslash), "WELL-FOUGHT.");
			}
		}
	}
	[HarmonyPatch(typeof(AudioSource))]
	internal class EarthmoverShootPatch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return from method in AccessTools.GetDeclaredMethods(typeof(AudioSource))
				where !method.IsStatic && !method.IsSpecialName && method.Name.StartsWith("Play")
				select method;
		}

		private static void Postfix(AudioSource __instance)
		{
			if (UltraVoicePlugin.EarthmoverVoiceEnabled.value && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.clip == (Object)null) && EarthmoverCharacter.InEarthmoverLevel() && !(((Object)__instance.clip).name != "Centaur A-1"))
			{
				EarthmoverCharacter.PlayShootAnnouncement();
			}
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	internal class EarthmoverShootPollPatch
	{
		private static readonly Dictionary<int, bool> lastState = new Dictionary<int, bool>();

		private static void Postfix(AudioSource __instance, bool __result)
		{
			if (UltraVoicePlugin.EarthmoverVoiceEnabled.value && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.clip == (Object)null) && !(((Object)__instance.clip).name != "Centaur A-1") && EarthmoverCharacter.InEarthmoverLevel())
			{
				int instanceID = ((Object)__instance).GetInstanceID();
				bool value;
				bool flag = lastState.TryGetValue(instanceID, out value) && value;
				lastState[instanceID] = __result;
				if (!(!__result || flag))
				{
					EarthmoverCharacter.PlayShootAnnouncement();
				}
			}
		}
	}
	[HarmonyPatch(typeof(BossHealthBar), "OnEnable")]
	internal class EarthmoverIntroPatch
	{
		private static void Postfix(BossHealthBar __instance)
		{
			EarthmoverCharacter.TryIntro(__instance.bossName);
		}
	}
	[HarmonyPatch(typeof(CombinedBossBar), "OnEnable")]
	internal class EarthmoverIntroCombinedPatch
	{
		private static void Postfix(CombinedBossBar __instance)
		{
			EarthmoverCharacter.TryIntro(__instance.fullName);
		}
	}
	[HarmonyPatch(typeof(Crossfade), "StartFade")]
	internal class EarthmoverBloodVentPatch
	{
		private static void Postfix(Crossfade __instance)
		{
			if (UltraVoicePlugin.EarthmoverVoiceEnabled.value && EarthmoverCharacter.InEarthmoverLevel() && !((Object)(object)__instance == (Object)null) && !((Object)(object)__instance.to == (Object)null) && !((Object)(object)__instance.to.clip == (Object)null) && !(((Object)__instance.to.clip).name != "Centaur A-2") && VoiceManager.CheckEventCooldown("Earthmover_BloodVent", 1f))
			{
				EarthmoverCharacter.PlayAnnouncement(0.5f, "Earthmover_BloodVent", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.BloodVentClip, EarthmoverCharacter.BloodVentClipTondar, EarthmoverCharacter.BloodVentClipMegaslash), "CONTAMINATED BLOOD DETECTED IN FUEL TANK B.", (3.1f, 3.2f, 4.2f, "OPENING VENTS..."));
			}
		}
	}
	[HarmonyPatch(typeof(CombinedBossBar), "OnEnable")]
	internal class EarthmoverDefenseSystemPatch
	{
		private static void Postfix(CombinedBossBar __instance)
		{
			if (UltraVoicePlugin.EarthmoverVoiceEnabled.value && EarthmoverCharacter.InEarthmoverLevel() && !(((Object)__instance).name != "SecuritySystem") && VoiceManager.CheckCooldown((Component)(object)__instance, 0.1f))
			{
				EarthmoverCharacter.PlayAnnouncement(0.1f, "Earthmover_DefenseSystem", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.DefenseSystemClip, EarthmoverCharacter.DefenseSystemClipTondar, EarthmoverCharacter.DefenseSystemClipMegaslash), "UNAUTHORIZED PERSONNEL DETECTED AT INTERIOR ENTRANCE.", (3.1f, 3.55f, 4.9f, "ENGAGING DEFENSE SYSTEM..."));
			}
		}
	}
	[HarmonyPatch(typeof(GameObject), "SetActive")]
	internal class EarthmoverBloodFloodPatch
	{
		private static void Postfix(GameObject __instance)
		{
			if (!UltraVoicePlugin.EarthmoverVoiceEnabled.value || (Object)(object)__instance == (Object)null || !EarthmoverCharacter.InEarthmoverLevel() || ((Object)__instance).name != "SecondBeats" || Time.time - EarthmoverCharacter.lastBloodFloodTime < 0.1f)
			{
				return;
			}
			Transform val = __instance.transform.Find("Alarm");
			if (!((Object)(object)val == (Object)null))
			{
				AudioSource component = ((Component)val).GetComponent<AudioSource>();
				if (!((Object)(object)component == (Object)null) && component.isPlaying)
				{
					EarthmoverCharacter.lastBloodFloodTime = Time.time;
					EarthmoverCharacter.PlayAnnouncement(0f, "Earthmover_BloodFlood", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.BloodFloodClip, EarthmoverCharacter.BloodFloodClipTondar, EarthmoverCharacter.BloodFloodClipMegaslash), "UNAUTHORIZED PERSONNEL HAS BREACHED INTERIOR ENTRANCE.", (2.85f, 3.45f, 4.4f, "FLUSHING INTERIOR..."));
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameObject), "SetActive")]
	internal class EarthmoverBrainBattlePatch
	{
		private static void Postfix(GameObject __instance)
		{
			if (UltraVoicePlugin.EarthmoverVoiceEnabled.value && !((Object)(object)__instance == (Object)null) && __instance.activeSelf && EarthmoverCharacter.InEarthmoverLevel() && !(((Object)__instance).name != "Beams"))
			{
				Transform val = (((Object)(object)__instance.transform.parent != (Object)null) ? __instance.transform.parent.parent : null);
				if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "LaserRing") && !(Time.time - EarthmoverCharacter.lastBrainBattleTime < 0.1f))
				{
					EarthmoverCharacter.lastBrainBattleTime = Time.time;
					EarthmoverCharacter.PlayAnnouncement(0f, "Earthmover_BrainBattle", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.BrainBattleClip, EarthmoverCharacter.BrainBattleClipTondar, EarthmoverCharacter.BrainBattleClipMegaslash), "UNAUTHORIZED PERSONNEL HAS BREACHED CENTRAL CONTROL TOWER.", (3f, 3.7f, 5.2f, "ENGAGING DEFENSE PROTOCOLS..."));
				}
			}
		}
	}
	[HarmonyPatch(typeof(GameObject), "SetActive")]
	internal class EarthmoverSelfDestructPatch
	{
		private static void Postfix(GameObject __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && __instance.activeSelf && UltraVoicePlugin.EarthmoverVoiceEnabled.value && EarthmoverCharacter.InEarthmoverLevel() && !(((Object)__instance).name != "Countdown") && !(Time.time - EarthmoverCharacter.lastSelfDestructTime < 0.1f))
			{
				EarthmoverCharacter.lastSelfDestructTime = Time.time;
				EarthmoverCharacter.PlayAnnouncement(0.25f, "Earthmover_SelfDestruct", EarthmoverCharacter.UseEarthmoverClip(EarthmoverCharacter.BrainKilledClip, EarthmoverCharacter.BrainKilledClipTondar, EarthmoverCharacter.BrainKilledClipMegaslash), "CRITICAL DAMAGE DETECTED IN CENTRAL CONTROL TOWER!", (3.3f, 3.65f, 4.4f, "SELF-DESTRUCT SEQUENCE INITIATED,"), (2.05f, 2.6f, 3.55f, "ALL PERSONNEL EVACUATE IMMEDIATELY!"));
			}
		}
	}
	public class FerrymanCharacter
	{
		public static AudioClip BossIntroClip;

		public static AudioClip CoinSkipClip;

		public static AudioClip CoinFightClip;

		public static AudioClip PhaseChangeClip;

		public static AudioClip ApproachClip;

		public static AudioClip AgonisIntroClip;

		public static AudioClip RudrakshaIntroClip;

		public static AudioClip AgonisDownedClip;

		public static AudioClip RudrakshaDownedClip;

		public static AudioClip[] SpawnClips;

		public static AudioClip[] ChatterClips;

		public static AudioClip[] DeathClips;

		public static AudioClip BossIntroClipSoil;

		public static AudioClip BossIntroClipNicky;

		public static AudioClip CoinSkipClipSoil;

		public static AudioClip CoinSkipClipNicky;

		public static AudioClip CoinFightClipSoil;

		public static AudioClip CoinFightClipNicky;

		public static AudioClip PhaseChangeClipSoil;

		public static AudioClip PhaseChangeClipNicky;

		public static AudioClip ApproachClipSoil;

		public static AudioClip ApproachClipNicky;

		public static AudioClip AgonisIntroClipSoil;

		public static AudioClip AgonisIntroClipNicky;

		public static AudioClip RudrakshaIntroClipSoil;

		public static AudioClip RudrakshaIntroClipNicky;

		public static AudioClip AgonisDownedClipSoil;

		public static AudioClip AgonisDownedClipNicky;

		public static AudioClip RudrakshaDownedClipSoil;

		public static AudioClip RudrakshaDownedClipNicky;

		public static AudioClip[] SpawnClipsSoil;

		public static AudioClip[] SpawnClipsNicky;

		public static AudioClip[] ChatterClipsSoil;

		public static AudioClip[] ChatterClipsNicky;

		public static AudioClip[] DeathClipsSoil;

		public static AudioClip[] DeathClipsNicky;

		public static readonly string[] ChatterSubs = new string[4] { "Have at you!", "Come on!", "Come at me!", "Try me!" };

		public static readonly string[] SpawnSubs = new string[5] { "Another soul to face my wrath.", "If you seek death, you have found it.", "You are not the first. You will not be the last.", "I have no mercy left to give.", "I grow weary of your kind." };

		public const string FerrymanBossSceneName = "e964cf0ffaa9e0e4e940b5c738983796";

		public static bool FerrymanCoinTossed = false;

		public static bool FerrymanPhaseChangePlayed = false;

		public static Color FerrymanColor => VoiceManager.GetEnemyTypeColor((EnemyType)26);

		public static UltraVoicePlugin.FerrymanVoiceActor CurrentActor
		{
			get
			{
				if (UltraVoicePlugin.FerrymanVoiceActorField == null)
				{
					return UltraVoicePlugin.FerrymanVoiceActor.Mel;
				}
				return UltraVoicePlugin.FerrymanVoiceActorField.value;
			}
		}

		public static bool IsAgonisOrRudraksha(Ferryman ferryman)
		{
			Transform val = ((Component)ferryman).transform;
			while ((Object)(object)val != (Object)null)
			{
				if (((Object)val).name.Contains("10S - Secret Arena"))
				{
					return true;
				}
				val = val.parent;
			}
			return false;
		}

		public static bool IsAgonis(Ferryman ferryman)
		{
			if (!IsAgonisOrRudraksha(ferryman))
			{
				return false;
			}
			return ((Component)ferryman).GetComponent<EnemyIdentifier>().mirrorOnly;
		}

		public static bool IsRudraksha(Ferryman ferryman)
		{
			if (!IsAgonisOrRudraksha(ferryman))
			{
				return false;
			}
			return !((Component)ferryman).GetComponent<EnemyIdentifier>().mirrorOnly;
		}

		public static AudioClip UseFerrymanClip(AudioClip melClip, AudioClip soilClip, AudioClip nickyClip)
		{
			return (AudioClip)(CurrentActor switch
			{
				UltraVoicePlugin.FerrymanVoiceActor.Soil => soilClip, 
				UltraVoicePlugin.FerrymanVoiceActor.Nicky => nickyClip, 
				_ => melClip, 
			});
		}

		public static AudioClip[] UseFerrymanClips(AudioClip[] melClips, AudioClip[] soilClips, AudioClip[] nickyClips)
		{
			return CurrentActor switch
			{
				UltraVoicePlugin.FerrymanVoiceActor.Soil => soilClips, 
				UltraVoicePlugin.FerrymanVoiceActor.Nicky => nickyClips, 
				_ => melClips, 
			};
		}

		public static float UseFerrymanDelay(float melDelay, float soilDelay, float nickyDelay)
		{
			return CurrentActor switch
			{
				UltraVoicePlugin.FerrymanVoiceActor.Soil => soilDelay, 
				UltraVoicePlugin.FerrymanVoiceActor.Nicky => nickyDelay, 
				_ => melDelay, 
			};
		}

		public static void LoadVoiceLines(ManualLogSource logger)
		{
			BossIntroClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_FightStarted.wav");
			CoinSkipClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.Ferry_CoinSkip.wav");
			CoinFightClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_CoinFight.wav");
			PhaseChangeClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_PhaseChange.wav");
			ApproachClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_Approach.wav");
			AgonisIntroClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_SpawnSpecialAgonis.wav");
			RudrakshaIntroClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_SpawnSpecialRudraksha.wav");
			AgonisDownedClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_DownedAgonis.wav");
			RudrakshaDownedClip = UltraVoicePlugin.LoadClip("Ferryman.Mel.ferry_DownedRudraksha.wav");
			SpawnClips = UltraVoicePlugin.LoadClips("Ferryman.Mel.ferry_Spawn{0}.wav", 5);
			ChatterClips = UltraVoicePlugin.LoadClips("Ferryman.Mel.Ferry_Chatter{0}.wav", 4);
			DeathClips = UltraVoicePlugin.LoadClips("Ferryman.Mel.ferry_Death{0}.wav", 3);
			BossIntroClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_FightStarted.wav");
			BossIntroClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_FightStarted.wav");
			CoinSkipClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.Ferry_CoinSkip.wav");
			CoinSkipClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.Ferry_CoinSkip.wav");
			CoinFightClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_CoinFight.wav");
			CoinFightClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_CoinFight.wav");
			PhaseChangeClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_PhaseChange.wav");
			PhaseChangeClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_PhaseChange.wav");
			ApproachClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_Approach.wav");
			ApproachClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_Approach.wav");
			AgonisIntroClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_SpawnSpecialAgonis.wav");
			AgonisIntroClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_SpawnSpecialAgonis.wav");
			RudrakshaIntroClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_SpawnSpecialRudraksha.wav");
			RudrakshaIntroClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_SpawnSpecialRudraksha.wav");
			AgonisDownedClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_DownedAgonis.wav");
			AgonisDownedClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_DownedAgonis.wav");
			RudrakshaDownedClipSoil = UltraVoicePlugin.LoadClip("Ferryman.Soil.ferry_DownedRudraksha.wav");
			RudrakshaDownedClipNicky = UltraVoicePlugin.LoadClip("Ferryman.Nicky.ferry_DownedRudraksha.wav");
			SpawnClipsSoil = UltraVoicePlugin.LoadClips("Ferryman.Soil.ferry_Spawn{0}.wav", 5);
			SpawnClipsNicky = UltraVoicePlugin.LoadClips("Ferryman.Nicky.ferry_Spawn{0}.wav", 5);
			ChatterClipsSoil = UltraVoicePlugin.LoadClips("Ferryman.Soil.Ferry_Chatter{0}.wav", 4);
			ChatterClipsNicky = UltraVoicePlugin.LoadClips("Ferryman.Nicky.Ferry_Chatter{0}.wav", 4);
			DeathClipsSoil = UltraVoicePlugin.LoadClips("Ferryman.Soil.ferry_Death{0}.wav", 3);
			DeathClip