Decompiled source of Kingdom Hearts Menu v1.0.0

BepInEx/plugins/Omniscye-Empress_KH2_Menu/EmpressKH2Menu.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Networking;
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: AssemblyCompany("Empress")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("EmpressKH2Menu")]
[assembly: AssemblyTitle("EmpressKH2Menu")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Empress.REPO.KH2Menu
{
	internal static class EmpressKH2Access
	{
		private static readonly FieldRef<MenuManager, List<MenuPage>> AllPagesRef = AccessTools.FieldRefAccess<MenuManager, List<MenuPage>>("allPages");

		private static readonly FieldRef<MenuPage, PageState> PageStateRef = AccessTools.FieldRefAccess<MenuPage, PageState>("currentPageState");

		private static readonly FieldRef<MenuManager, Sound> SoundHoverRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundHover");

		private static readonly FieldRef<MenuManager, Sound> SoundTickRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundTick");

		private static readonly FieldRef<MenuManager, Sound> SoundMoveRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundMove");

		private static readonly FieldRef<MenuManager, Sound> SoundConfirmRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundConfirm");

		private static readonly FieldRef<MenuManager, Sound> SoundActionRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundAction");

		private static readonly FieldRef<MenuManager, Sound> SoundPageIntroRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundPageIntro");

		private static readonly FieldRef<MenuManager, Sound> SoundWindowPopUpRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundWindowPopUp");

		private static readonly FieldRef<MenuManager, Sound> SoundDenyRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundDeny");

		private static readonly FieldRef<MenuManager, Sound> SoundDudRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundDud");

		private static readonly FieldRef<MenuManager, Sound> SoundPageOutroRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundPageOutro");

		private static readonly FieldRef<MenuManager, Sound> SoundWindowPopUpCloseRef = AccessTools.FieldRefAccess<MenuManager, Sound>("soundWindowPopUpClose");

		private static readonly FieldRef<Sound, AudioClip[]> SoundClipsRef = AccessTools.FieldRefAccess<Sound, AudioClip[]>("Sounds");

		private static readonly FieldRef<Sound, float> SoundSpatialBlendRef = AccessTools.FieldRefAccess<Sound, float>("SpatialBlend");

		private static readonly FieldRef<Sound, float> SoundPitchRef = AccessTools.FieldRefAccess<Sound, float>("Pitch");

		private static readonly FieldRef<Sound, float> SoundPitchDefaultRef = AccessTools.FieldRefAccess<Sound, float>("PitchDefault");

		private static readonly FieldRef<Sound, float> SoundPitchRandomRef = AccessTools.FieldRefAccess<Sound, float>("PitchRandom");

		private static readonly FieldRef<Sound, float> SoundVolumeRandomRef = AccessTools.FieldRefAccess<Sound, float>("VolumeRandom");

		private static readonly FieldRef<MenuSelectionBox, RawImage> SelectionRawImageRef = AccessTools.FieldRefAccess<MenuSelectionBox, RawImage>("rawImage");

		private static readonly FieldRef<MenuSelectionBox, Vector3> SelectionCurrentScaleRef = AccessTools.FieldRefAccess<MenuSelectionBox, Vector3>("currentScale");

		private static readonly FieldRef<MenuSelectionBox, Vector3> SelectionTargetScaleRef = AccessTools.FieldRefAccess<MenuSelectionBox, Vector3>("targetScale");

		private static readonly FieldRef<MenuSelectionBox, RectTransform> SelectionRectRef = AccessTools.FieldRefAccess<MenuSelectionBox, RectTransform>("rectTransform");

		public static bool AnyMenuPageOpen()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Invalid comparison between Unknown and I4
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Invalid comparison between Unknown and I4
			MenuManager instance = MenuManager.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			List<MenuPage> list = AllPagesRef.Invoke(instance);
			if (list == null)
			{
				return false;
			}
			for (int i = 0; i < list.Count; i++)
			{
				MenuPage val = list[i];
				if (!((Object)(object)val == (Object)null))
				{
					PageState val2 = PageStateRef.Invoke(val);
					if ((int)val2 == 0 || (int)val2 == 1 || (int)val2 == 2)
					{
						return true;
					}
				}
			}
			return false;
		}

		public static void SwapMenuSounds(MenuManager manager, AudioClip move, AudioClip select, AudioClip cancel)
		{
			if (!((Object)(object)manager == (Object)null))
			{
				Swap(SoundHoverRef.Invoke(manager), move);
				Swap(SoundTickRef.Invoke(manager), move);
				Swap(SoundMoveRef.Invoke(manager), move);
				Swap(SoundConfirmRef.Invoke(manager), select);
				Swap(SoundActionRef.Invoke(manager), select);
				Swap(SoundPageIntroRef.Invoke(manager), select);
				Swap(SoundWindowPopUpRef.Invoke(manager), select);
				Swap(SoundDenyRef.Invoke(manager), cancel);
				Swap(SoundDudRef.Invoke(manager), cancel);
				Swap(SoundPageOutroRef.Invoke(manager), cancel);
				Swap(SoundWindowPopUpCloseRef.Invoke(manager), cancel);
			}
		}

		public static void HideSelectionBox(MenuSelectionBox selectionBox)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)selectionBox == (Object)null))
			{
				RawImage val = SelectionRawImageRef.Invoke(selectionBox);
				if ((Object)(object)val != (Object)null)
				{
					((Graphic)val).color = new Color(0f, 0f, 0f, 0f);
				}
				SelectionCurrentScaleRef.Invoke(selectionBox) = Vector3.zero;
				SelectionTargetScaleRef.Invoke(selectionBox) = Vector3.zero;
				RectTransform val2 = SelectionRectRef.Invoke(selectionBox);
				if ((Object)(object)val2 != (Object)null)
				{
					((Transform)val2).localScale = Vector3.zero;
				}
			}
		}

		private static void Swap(Sound sound, AudioClip clip)
		{
			if (sound != null && !((Object)(object)clip == (Object)null))
			{
				SoundClipsRef.Invoke(sound) = (AudioClip[])(object)new AudioClip[1] { clip };
				SoundSpatialBlendRef.Invoke(sound) = 0f;
				SoundPitchRef.Invoke(sound) = 1f;
				SoundPitchDefaultRef.Invoke(sound) = 1f;
				SoundPitchRandomRef.Invoke(sound) = 0f;
				SoundVolumeRandomRef.Invoke(sound) = 0f;
			}
		}
	}
	[BepInPlugin("com.empress.repo.kh2menu", "Empress KH2 Menu", "1.0.0")]
	public sealed class EmpressKH2MenuPlugin : BaseUnityPlugin
	{
		public const string PluginGuid = "com.empress.repo.kh2menu";

		public const string PluginName = "Empress KH2 Menu";

		public const string PluginVersion = "1.0.0";

		private Harmony _harmony;

		internal static EmpressKH2MenuPlugin Instance { get; private set; }

		internal static ManualLogSource Log { get; private set; }

		internal static KH2MenuSettings Settings { get; private set; }

		internal static string PluginDirectory { get; private set; }

		private void Awake()
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			PluginDirectory = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
			Settings = new KH2MenuSettings(((BaseUnityPlugin)this).Config);
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			KH2MenuRuntime.EnsureHost();
			KH2MenuAssets.Initialize(PluginDirectory, (MonoBehaviour)(object)KH2MenuRuntime.Instance, ((BaseUnityPlugin)this).Logger);
			_harmony = new Harmony("com.empress.repo.kh2menu");
			_harmony.PatchAll(typeof(EmpressKH2MenuPlugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Empress KH2 Menu v1.0.0 loaded.");
		}

		internal static void DebugLog(string message)
		{
			if (Settings != null && Settings.DebugLogs.Value)
			{
				Log.LogInfo((object)message);
			}
		}
	}
	internal sealed class KH2MenuSettings
	{
		public readonly ConfigEntry<bool> DebugLogs;

		public readonly ConfigEntry<bool> EnableStyle;

		public readonly ConfigEntry<bool> EnableSounds;

		public readonly ConfigEntry<bool> EnableMusic;

		public readonly ConfigEntry<float> MusicVolume;

		public readonly ConfigEntry<float> BackdropOpacity;

		public KH2MenuSettings(ConfigFile config)
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Expected O, but got Unknown
			DebugLogs = config.Bind<bool>("Debug", "DebugLogs", false, "Logs verbose Empress KH2 Menu diagnostics.");
			EnableStyle = config.Bind<bool>("Menu", "EnableStyle", true, "Restyles every REPO menu page with the Kingdom Hearts 2 look.");
			EnableSounds = config.Bind<bool>("Menu", "EnableSounds", true, "Swaps menu hover, confirm, deny and tick sounds with the kh2 ogg files beside the DLL.");
			EnableMusic = config.Bind<bool>("Menu", "EnableMusic", true, "Plays kh2_music.ogg on the main menu instead of the vanilla menu music.");
			MusicVolume = config.Bind<float>("Menu", "MusicVolume", 0.4f, new ConfigDescription("Volume of the menu music.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			BackdropOpacity = config.Bind<float>("Menu", "BackdropOpacity", 1f, new ConfigDescription("Opacity of the dark KH2 backdrop behind menu pages.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 1f), Array.Empty<object>()));
		}
	}
	internal static class KH2MenuAssets
	{
		private static readonly Dictionary<string, Sprite> Sprites = new Dictionary<string, Sprite>();

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

		private static bool _started;

		public static bool Ready { get; private set; }

		public static void Initialize(string directory, MonoBehaviour runner, ManualLogSource log)
		{
			if (!_started && !((Object)(object)runner == (Object)null) && !string.IsNullOrEmpty(directory))
			{
				_started = true;
				LoadSprite(directory, "kh2_bar");
				LoadSprite(directory, "kh2_backdrop");
				LoadSprite(directory, "kh2_menu_backdrop");
				LoadSprite(directory, "kh2_pointer");
				LoadSprite(directory, "kh2_title");
				LoadSprite(directory, "kh2_window");
				runner.StartCoroutine(LoadClips(directory, log));
			}
		}

		public static Sprite GetSprite(string key)
		{
			Sprites.TryGetValue(key, out var value);
			return value;
		}

		public static AudioClip GetClip(string key)
		{
			Clips.TryGetValue(key, out var value);
			return value;
		}

		private static void LoadSprite(string directory, string name)
		{
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: 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_006f: Expected O, but got Unknown
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			string path = Path.Combine(directory, name + ".png");
			if (!File.Exists(path))
			{
				path = Path.Combine(directory, name + ".jpg");
			}
			if (!File.Exists(path))
			{
				path = Path.Combine(directory, name + ".jpeg");
			}
			if (File.Exists(path))
			{
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false)
				{
					wrapMode = (TextureWrapMode)1,
					filterMode = (FilterMode)1,
					anisoLevel = 16
				};
				if (ImageConversion.LoadImage(val, File.ReadAllBytes(path)))
				{
					Sprite value = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
					Sprites[name] = value;
				}
			}
		}

		private static IEnumerator LoadClips(string directory, ManualLogSource log)
		{
			string[] files = Directory.GetFiles(directory, "*.ogg", SearchOption.TopDirectoryOnly);
			for (int i = 0; i < files.Length; i++)
			{
				yield return LoadClip(files[i], log);
			}
			Ready = true;
			if (log != null)
			{
				log.LogInfo((object)("Empress KH2 Menu loaded " + Clips.Count + " sound(s)."));
			}
		}

		private static IEnumerator LoadClip(string path, ManualLogSource log)
		{
			string text = "file:///" + path.Replace("\\", "/");
			UnityWebRequest request = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14);
			try
			{
				yield return request.SendWebRequest();
				if (!string.IsNullOrEmpty(request.error))
				{
					if (log != null)
					{
						log.LogWarning((object)("Empress KH2 Menu could not load " + Path.GetFileName(path) + ": " + request.error));
					}
					yield break;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(request);
				if ((Object)(object)content == (Object)null)
				{
					yield break;
				}
				((Object)content).name = Path.GetFileNameWithoutExtension(path);
				Clips[((Object)content).name.ToLowerInvariant().TrimEnd('.')] = content;
			}
			finally
			{
				((IDisposable)request)?.Dispose();
			}
		}
	}
	[HarmonyPatch(typeof(MenuManager), "Start")]
	internal static class KH2MenuPatchMenuManagerStart
	{
		private static void Postfix(MenuManager __instance)
		{
			KH2MenuStyler.ResetTracking();
			KH2MenuSounds.Apply(__instance);
		}
	}
	[HarmonyPatch(typeof(MenuPage), "Start")]
	internal static class KH2MenuPatchMenuPageStart
	{
		private static void Postfix(MenuPage __instance)
		{
			KH2MenuStyler.StylePage(__instance);
		}
	}
	[HarmonyPatch(typeof(MenuPage), "OnEnable")]
	internal static class KH2MenuPatchMenuPageOnEnable
	{
		private static void Postfix(MenuPage __instance)
		{
			KH2MenuStyler.StylePage(__instance);
		}
	}
	[HarmonyPatch(typeof(MenuManager), "PageOpen")]
	internal static class KH2MenuPatchMenuManagerPageOpen
	{
		private static void Postfix(MenuPage __result)
		{
			KH2MenuStyler.StylePage(__result);
		}
	}
	[HarmonyPatch(typeof(MenuManager), "MenuEffectHover")]
	internal static class KH2MenuPatchMenuEffectHover
	{
		private static void Prefix(ref float pitch)
		{
			if (EmpressKH2MenuPlugin.Settings != null && EmpressKH2MenuPlugin.Settings.EnableSounds.Value && KH2MenuRuntime.MenuOpen())
			{
				pitch = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(MenuSelectionBox), "Update")]
	internal static class KH2MenuPatchMenuSelectionBoxUpdate
	{
		private static bool Prefix(MenuSelectionBox __instance)
		{
			if (EmpressKH2MenuPlugin.Settings == null || !EmpressKH2MenuPlugin.Settings.EnableStyle.Value || !KH2MenuRuntime.MenuOpen())
			{
				return true;
			}
			EmpressKH2Access.HideSelectionBox(__instance);
			return false;
		}
	}
	[HarmonyPatch(typeof(LevelMusic), "Update")]
	internal static class KH2MenuPatchLevelMusic
	{
		private static bool Prefix()
		{
			return !SuppressMenuMusic();
		}

		internal static bool SuppressMenuMusic()
		{
			if (EmpressKH2MenuPlugin.Settings == null || !EmpressKH2MenuPlugin.Settings.EnableMusic.Value)
			{
				return false;
			}
			return KH2MenuRuntime.OnMenu();
		}
	}
	[HarmonyPatch(typeof(ConstantMusic), "Update")]
	internal static class KH2MenuPatchConstantMusic
	{
		private static bool Prefix()
		{
			return !KH2MenuPatchLevelMusic.SuppressMenuMusic();
		}
	}
	internal sealed class KH2MenuRuntime : MonoBehaviour
	{
		private Canvas _backdropCanvas;

		private RectTransform _backdropRect;

		private Image _backdropImage;

		private Canvas _menuBackdropCanvas;

		private RectTransform _menuBackdrop;

		private Image _menuBackdropImage;

		private AudioSource _music;

		private float _soundApplyTimer;

		private bool _musicRouted;

		public static KH2MenuRuntime Instance { get; private set; }

		public bool MusicActive
		{
			get
			{
				if ((Object)(object)_music != (Object)null)
				{
					return _music.isPlaying;
				}
				return false;
			}
		}

		public static KH2MenuRuntime EnsureHost()
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			if ((Object)(object)Instance != (Object)null)
			{
				return Instance;
			}
			GameObject val = new GameObject("Empress KH2 Menu Runtime");
			val.transform.parent = null;
			((Object)val).hideFlags = (HideFlags)61;
			Object.DontDestroyOnLoad((Object)val);
			Instance = val.AddComponent<KH2MenuRuntime>();
			return Instance;
		}

		private void Awake()
		{
			Instance = this;
		}

		private void EnsureBackdrop()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_backdropCanvas != (Object)null))
			{
				_backdropCanvas = new GameObject("Empress KH2 Menu Backdrop").AddComponent<Canvas>();
				((Component)_backdropCanvas).transform.SetParent(((Component)this).transform, false);
				_backdropCanvas.renderMode = (RenderMode)0;
				_backdropCanvas.sortingOrder = -30000;
				CanvasScaler obj = ((Component)_backdropCanvas).gameObject.AddComponent<CanvasScaler>();
				obj.uiScaleMode = (ScaleMode)1;
				obj.referenceResolution = new Vector2(1920f, 1080f);
				obj.matchWidthOrHeight = 0.5f;
				_backdropRect = ((Component)_backdropCanvas).GetComponent<RectTransform>();
				GameObject val = new GameObject("Empress KH2 Title Backdrop");
				RectTransform obj2 = val.AddComponent<RectTransform>();
				((Transform)obj2).SetParent((Transform)(object)_backdropRect, false);
				obj2.anchorMin = Vector2.zero;
				obj2.anchorMax = Vector2.one;
				obj2.offsetMin = Vector2.zero;
				obj2.offsetMax = Vector2.zero;
				_backdropImage = val.AddComponent<Image>();
				_backdropImage.sprite = KH2MenuAssets.GetSprite("kh2_menu_backdrop") ?? KH2MenuAssets.GetSprite("kh2_title") ?? KH2MenuAssets.GetSprite("kh2_backdrop");
				((Graphic)_backdropImage).raycastTarget = false;
				_backdropImage.preserveAspect = false;
				((Graphic)_backdropImage).color = Color.white;
			}
		}

		private void EnsureMusic()
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			if (!((Object)(object)_music != (Object)null))
			{
				GameObject val = new GameObject("Empress KH2 Menu Music");
				val.transform.SetParent(((Component)this).transform, false);
				_music = val.AddComponent<AudioSource>();
				_music.playOnAwake = false;
				_music.loop = true;
				_music.spatialBlend = 0f;
				_music.priority = 0;
			}
		}

		public static bool OnMenu()
		{
			try
			{
				return SemiFunc.MenuLevel() && (Object)(object)MenuManager.instance != (Object)null;
			}
			catch
			{
				return false;
			}
		}

		public static bool MenuOpen()
		{
			try
			{
				return EmpressKH2Access.AnyMenuPageOpen();
			}
			catch
			{
				return false;
			}
		}

		private void Update()
		{
			bool flag = OnMenu();
			bool onMenu = MenuOpen();
			TickBackdrop(flag);
			KH2MenuSuppression.SetActive(flag && EmpressKH2MenuPlugin.Settings != null && EmpressKH2MenuPlugin.Settings.EnableStyle.Value, _music);
			TickMusic(flag);
			TickSounds(onMenu);
		}

		private void TickSounds(bool onMenu)
		{
			if (onMenu && KH2MenuAssets.Ready && !((Object)(object)MenuManager.instance == (Object)null))
			{
				_soundApplyTimer -= Time.unscaledDeltaTime;
				if (!(_soundApplyTimer > 0f))
				{
					_soundApplyTimer = 1f;
					KH2MenuSounds.Apply(MenuManager.instance);
				}
			}
		}

		private void TickBackdrop(bool onMenu)
		{
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			if (!onMenu || EmpressKH2MenuPlugin.Settings == null || !EmpressKH2MenuPlugin.Settings.EnableStyle.Value)
			{
				if ((Object)(object)_backdropCanvas != (Object)null)
				{
					((Component)_backdropCanvas).gameObject.SetActive(false);
				}
				if ((Object)(object)_menuBackdrop != (Object)null)
				{
					((Component)_menuBackdrop).gameObject.SetActive(false);
				}
				return;
			}
			EnsureBackdrop();
			((Component)_backdropCanvas).gameObject.SetActive(true);
			if (!((Object)(object)_backdropImage == (Object)null))
			{
				float num = Mathf.Max(0.98f, EmpressKH2MenuPlugin.Settings.BackdropOpacity.Value);
				((Graphic)_backdropImage).color = new Color(1f, 1f, 1f, num);
				if ((Object)(object)_menuBackdropImage != (Object)null)
				{
					((Graphic)_menuBackdropImage).color = new Color(1f, 1f, 1f, num);
				}
				if ((Object)(object)_menuBackdrop != (Object)null)
				{
					((Component)_menuBackdrop).gameObject.SetActive(true);
					((Transform)_menuBackdrop).SetAsFirstSibling();
				}
			}
		}

		public void AttachBackdrop(MenuPage page)
		{
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)page == (Object)null)
			{
				return;
			}
			Canvas componentInParent = ((Component)page).GetComponentInParent<Canvas>(true);
			if ((Object)(object)componentInParent == (Object)null)
			{
				return;
			}
			if ((Object)(object)_menuBackdrop != (Object)null && (Object)(object)_menuBackdropCanvas == (Object)(object)componentInParent)
			{
				((Transform)_menuBackdrop).SetAsFirstSibling();
				((Component)_menuBackdrop).gameObject.SetActive(true);
				return;
			}
			if ((Object)(object)_menuBackdrop != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)_menuBackdrop).gameObject);
			}
			_menuBackdropCanvas = componentInParent;
			GameObject val = new GameObject("Empress KH2 Menu Real Backdrop");
			_menuBackdrop = val.AddComponent<RectTransform>();
			((Transform)_menuBackdrop).SetParent(((Component)componentInParent).transform, false);
			_menuBackdrop.anchorMin = Vector2.zero;
			_menuBackdrop.anchorMax = Vector2.one;
			_menuBackdrop.offsetMin = Vector2.zero;
			_menuBackdrop.offsetMax = Vector2.zero;
			((Transform)_menuBackdrop).SetAsFirstSibling();
			_menuBackdropImage = val.AddComponent<Image>();
			_menuBackdropImage.sprite = KH2MenuAssets.GetSprite("kh2_menu_backdrop") ?? KH2MenuAssets.GetSprite("kh2_title") ?? KH2MenuAssets.GetSprite("kh2_backdrop");
			((Graphic)_menuBackdropImage).raycastTarget = false;
			_menuBackdropImage.preserveAspect = false;
			((Graphic)_menuBackdropImage).color = Color.white;
		}

		private void TickMusic(bool onMenu)
		{
			if (EmpressKH2MenuPlugin.Settings == null || !EmpressKH2MenuPlugin.Settings.EnableMusic.Value)
			{
				if ((Object)(object)_music != (Object)null && _music.isPlaying)
				{
					_music.Stop();
				}
				return;
			}
			AudioClip clip = KH2MenuAssets.GetClip("kh2_music");
			if ((Object)(object)clip == (Object)null)
			{
				return;
			}
			if (!onMenu)
			{
				if ((Object)(object)_music != (Object)null && _music.isPlaying)
				{
					_music.Stop();
				}
				return;
			}
			EnsureMusic();
			if ((Object)(object)_music.clip != (Object)(object)clip)
			{
				_music.clip = clip;
			}
			_music.volume = EmpressKH2MenuPlugin.Settings.MusicVolume.Value;
			RouteMusic();
			if (!_music.isPlaying)
			{
				_music.Play();
			}
		}

		private void RouteMusic()
		{
			if (!_musicRouted && !((Object)(object)_music == (Object)null) && !((Object)(object)AudioManager.instance == (Object)null) && !((Object)(object)AudioManager.instance.MusicMasterGroup == (Object)null))
			{
				_music.outputAudioMixerGroup = AudioManager.instance.MusicMasterGroup;
				_musicRouted = true;
			}
		}
	}
	internal static class KH2MenuSounds
	{
		public static void Apply(MenuManager manager)
		{
			if (!((Object)(object)manager == (Object)null) && EmpressKH2MenuPlugin.Settings != null && EmpressKH2MenuPlugin.Settings.EnableSounds.Value)
			{
				AudioClip clip = KH2MenuAssets.GetClip("kh2_move");
				AudioClip clip2 = KH2MenuAssets.GetClip("kh2_select");
				AudioClip clip3 = KH2MenuAssets.GetClip("kh2_cancel");
				EmpressKH2Access.SwapMenuSounds(manager, clip, clip2, clip3);
			}
		}
	}
	internal static class KH2MenuStyler
	{
		internal static readonly Color PanelColor = new Color(0.03f, 0.06f, 0.16f, 0.86f);

		internal static readonly Color PanelEdge = new Color(0.32f, 0.55f, 1f, 0.9f);

		internal static readonly Color TextColor = new Color(0.96f, 0.97f, 1f, 1f);

		internal static readonly Color HeaderColor = new Color(1f, 0.86f, 0.42f, 1f);

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

		internal static readonly Color BarColor = new Color(0.16f, 0.4f, 1f, 0f);

		internal static readonly Color BarHoverColor = new Color(0.35f, 0.68f, 1f, 0.62f);

		private static readonly HashSet<int> Styled = new HashSet<int>();

		public static void ResetTracking()
		{
			Styled.Clear();
		}

		public static void StylePage(MenuPage page)
		{
			if (!((Object)(object)page == (Object)null) && EmpressKH2MenuPlugin.Settings != null && EmpressKH2MenuPlugin.Settings.EnableStyle.Value)
			{
				if (KH2MenuRuntime.OnMenu())
				{
					KH2MenuRuntime.Instance?.AttachBackdrop(page);
				}
				if ((Object)(object)page.menuHeader != (Object)null)
				{
					StyleHeader(page.menuHeader);
				}
				TextMeshProUGUI[] componentsInChildren = ((Component)page).GetComponentsInChildren<TextMeshProUGUI>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					StyleText(componentsInChildren[i]);
				}
				Image[] componentsInChildren2 = ((Component)page).GetComponentsInChildren<Image>(true);
				for (int j = 0; j < componentsInChildren2.Length; j++)
				{
					StylePanel(componentsInChildren2[j]);
				}
				MenuButton[] componentsInChildren3 = ((Component)page).GetComponentsInChildren<MenuButton>(true);
				for (int k = 0; k < componentsInChildren3.Length; k++)
				{
					StyleButton(componentsInChildren3[k]);
				}
			}
		}

		private static void StyleHeader(TextMeshProUGUI header)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (Styled.Add(((Object)header).GetInstanceID()))
			{
				((Graphic)header).color = HeaderColor;
				((TMP_Text)header).fontStyle = (FontStyles)(((TMP_Text)header).fontStyle | 1);
				ApplyOutline(header, 0.22f);
			}
		}

		private static void StyleText(TextMeshProUGUI text)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)text == (Object)null) && Styled.Add(((Object)text).GetInstanceID()) && !(((Graphic)text).color.a < 0.05f))
			{
				float num = ((Graphic)text).color.r * 0.3f + ((Graphic)text).color.g * 0.59f + ((Graphic)text).color.b * 0.11f;
				((Graphic)text).color = ((num > 0.75f) ? HeaderColor : TextColor);
				ApplyOutline(text, 0.16f);
			}
		}

		private static void ApplyOutline(TextMeshProUGUI text, float width)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			Material fontMaterial = ((TMP_Text)text).fontMaterial;
			if (!((Object)(object)fontMaterial == (Object)null))
			{
				fontMaterial.EnableKeyword("OUTLINE_ON");
				fontMaterial.SetColor("_OutlineColor", TextOutline);
				fontMaterial.SetFloat("_OutlineWidth", width);
			}
		}

		private static void StylePanel(Image image)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)image == (Object)null || !Styled.Add(((Object)image).GetInstanceID()) || (Object)(object)((Component)image).GetComponentInParent<MenuButton>() != (Object)null)
			{
				return;
			}
			Color color = ((Graphic)image).color;
			if (color.a < 0.12f)
			{
				return;
			}
			RectTransform rectTransform = ((Graphic)image).rectTransform;
			if ((Object)(object)rectTransform == (Object)null)
			{
				return;
			}
			Rect rect = rectTransform.rect;
			Vector2 size = ((Rect)(ref rect)).size;
			if (!(size.x < 90f) && !(size.y < 40f) && (!(color.r * 0.3f + color.g * 0.59f + color.b * 0.11f > 0.55f) || !(color.a > 0.85f)))
			{
				Sprite sprite = KH2MenuAssets.GetSprite("kh2_window");
				if ((Object)(object)sprite != (Object)null)
				{
					image.sprite = sprite;
					image.type = (Type)1;
				}
				((Graphic)image).color = new Color(PanelColor.r, PanelColor.g, PanelColor.b, Mathf.Clamp01(color.a * PanelColor.a + 0.12f));
			}
		}

		private static void StyleButton(MenuButton button)
		{
			if (!((Object)(object)button == (Object)null) && Styled.Add(((Object)button).GetInstanceID()))
			{
				KH2ButtonStyle kH2ButtonStyle = ((Component)button).gameObject.GetComponent<KH2ButtonStyle>();
				if ((Object)(object)kH2ButtonStyle == (Object)null)
				{
					kH2ButtonStyle = ((Component)button).gameObject.AddComponent<KH2ButtonStyle>();
				}
				kH2ButtonStyle.Setup(button);
			}
		}
	}
	internal sealed class KH2ButtonStyle : MonoBehaviour
	{
		public static readonly List<KH2ButtonStyle> Active = new List<KH2ButtonStyle>();

		private static readonly FieldRef<MenuButton, bool> HoveringRef = AccessTools.FieldRefAccess<MenuButton, bool>("hovering");

		private MenuButton _button;

		private Image _bar;

		private Image _pointer;

		private RectTransform _rect;

		private TextMeshProUGUI _label;

		private float _blend;

		public bool Hovering { get; private set; }

		public RectTransform Rect => _rect;

		private void OnEnable()
		{
			if (!Active.Contains(this))
			{
				Active.Add(this);
			}
		}

		private void OnDisable()
		{
			Active.Remove(this);
		}

		public void Setup(MenuButton button)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Expected O, but got Unknown
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0176: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_0227: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			_button = button;
			_rect = ((Component)button).GetComponent<RectTransform>();
			if (!((Object)(object)_rect == (Object)null))
			{
				_label = ((Component)button).GetComponentInChildren<TextMeshProUGUI>(true);
				GameObject val = new GameObject("Empress KH2 Bar");
				RectTransform obj = val.AddComponent<RectTransform>();
				((Transform)obj).SetParent((Transform)(object)_rect, false);
				obj.anchorMin = new Vector2(0f, 0.5f);
				obj.anchorMax = new Vector2(0f, 0.5f);
				obj.pivot = new Vector2(0f, 0.5f);
				obj.sizeDelta = new Vector2(GetBarWidth(), 42f);
				obj.anchoredPosition = GetBarPosition(0f);
				((Transform)obj).SetAsFirstSibling();
				_bar = val.AddComponent<Image>();
				_bar.sprite = KH2MenuAssets.GetSprite("kh2_bar");
				_bar.type = (Type)1;
				((Graphic)_bar).color = KH2MenuStyler.BarColor;
				((Graphic)_bar).raycastTarget = false;
				if ((Object)(object)_bar.sprite == (Object)null)
				{
					((Graphic)_bar).color = new Color(0.12f, 0.3f, 0.8f, 0.4f);
				}
				GameObject val2 = new GameObject("Empress KH2 Pointer");
				RectTransform obj2 = val2.AddComponent<RectTransform>();
				((Transform)obj2).SetParent((Transform)(object)_rect, false);
				obj2.anchorMin = new Vector2(0f, 0.5f);
				obj2.anchorMax = new Vector2(0f, 0.5f);
				obj2.pivot = new Vector2(0f, 0.5f);
				obj2.sizeDelta = new Vector2(52f, 52f);
				((Transform)obj2).localScale = new Vector3(-1f, 1f, 1f);
				obj2.anchoredPosition = GetPointerPosition(0f);
				_pointer = val2.AddComponent<Image>();
				_pointer.sprite = KH2MenuAssets.GetSprite("kh2_pointer");
				((Graphic)_pointer).raycastTarget = false;
				_pointer.preserveAspect = true;
				((Graphic)_pointer).color = new Color(1f, 1f, 1f, 0f);
				if ((Object)(object)_pointer.sprite == (Object)null)
				{
					((Graphic)_pointer).color = new Color(1f, 0.85f, 0.3f, 0f);
				}
			}
		}

		private void Update()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_015d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)_button == (Object)null) && !((Object)(object)_bar == (Object)null))
			{
				bool flag = false;
				try
				{
					flag = HoveringRef.Invoke(_button);
				}
				catch
				{
					flag = false;
				}
				Hovering = flag;
				_blend = Mathf.MoveTowards(_blend, flag ? 1f : 0f, Time.unscaledDeltaTime * 7f);
				((Graphic)_bar).color = Color.Lerp(KH2MenuStyler.BarColor, KH2MenuStyler.BarHoverColor, _blend);
				((Behaviour)_bar).enabled = _blend > 0.015f;
				float num = Mathf.Lerp(0f, 12f, _blend);
				RectTransform rectTransform = ((Graphic)_bar).rectTransform;
				rectTransform.sizeDelta = new Vector2(GetBarWidth(), 42f);
				rectTransform.anchoredPosition = GetBarPosition(num);
				if ((Object)(object)_pointer != (Object)null)
				{
					((Behaviour)_pointer).enabled = _blend > 0.015f;
					((Graphic)_pointer).color = new Color(1f, 1f, 1f, _blend);
					float num2 = Mathf.Sin(Time.unscaledTime * 6f) * 5f;
					((Graphic)_pointer).rectTransform.anchoredPosition = GetPointerPosition(num + num2 * _blend);
				}
			}
		}

		private float GetBarWidth()
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			float num = 220f;
			if ((Object)(object)_label != (Object)null)
			{
				float preferredWidth = ((TMP_Text)_label).preferredWidth;
				if (preferredWidth > 1f)
				{
					num = preferredWidth + 58f;
				}
			}
			else if ((Object)(object)_rect != (Object)null)
			{
				Rect rect = _rect.rect;
				num = ((Rect)(ref rect)).width + 20f;
			}
			return Mathf.Clamp(num, 190f, 330f);
		}

		private Vector2 GetBarPosition(float extend)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(-22f + extend, 0f);
		}

		private Vector2 GetPointerPosition(float offset)
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			return new Vector2(-22f + GetBarWidth() + 66f + offset, 0f);
		}
	}
	internal static class KH2MenuSuppression
	{
		private sealed class AudioState
		{
			private readonly bool _mute;

			private readonly bool _wasPlaying;

			private readonly float _volume;

			public AudioState(AudioSource source)
			{
				_mute = source.mute;
				_wasPlaying = source.isPlaying;
				_volume = source.volume;
			}

			public void Restore(AudioSource source)
			{
				source.mute = _mute;
				source.volume = _volume;
				if (_wasPlaying && !source.isPlaying)
				{
					source.UnPause();
				}
			}
		}

		private static readonly List<Behaviour> Behaviours = new List<Behaviour>();

		private static readonly List<Renderer> Renderers = new List<Renderer>();

		private static readonly List<ParticleSystem> Particles = new List<ParticleSystem>();

		private static readonly Dictionary<AudioSource, AudioState> AudioStates = new Dictionary<AudioSource, AudioState>();

		private static bool _active;

		public static void SetActive(bool active, AudioSource ownMusic)
		{
			if (!active)
			{
				Restore();
				return;
			}
			_active = true;
			SuppressTruckBehaviours();
			SuppressRenderers();
			SuppressParticles();
			SuppressAudio(ownMusic);
		}

		private static void Restore()
		{
			if (!_active)
			{
				return;
			}
			for (int i = 0; i < Behaviours.Count; i++)
			{
				if ((Object)(object)Behaviours[i] != (Object)null)
				{
					Behaviours[i].enabled = true;
				}
			}
			for (int j = 0; j < Renderers.Count; j++)
			{
				if ((Object)(object)Renderers[j] != (Object)null)
				{
					Renderers[j].enabled = true;
				}
			}
			for (int k = 0; k < Particles.Count; k++)
			{
				if ((Object)(object)Particles[k] != (Object)null)
				{
					Particles[k].Play(true);
				}
			}
			foreach (KeyValuePair<AudioSource, AudioState> audioState in AudioStates)
			{
				if ((Object)(object)audioState.Key != (Object)null)
				{
					audioState.Value.Restore(audioState.Key);
				}
			}
			Behaviours.Clear();
			Renderers.Clear();
			Particles.Clear();
			AudioStates.Clear();
			_active = false;
		}

		private static void SuppressTruckBehaviours()
		{
			TruckMenuAnimated[] array = Object.FindObjectsOfType<TruckMenuAnimated>(true);
			foreach (TruckMenuAnimated val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Behaviour)val).enabled && !Behaviours.Contains((Behaviour)(object)val))
				{
					Behaviours.Add((Behaviour)(object)val);
					((Behaviour)val).enabled = false;
				}
			}
		}

		private static void SuppressRenderers()
		{
			Renderer[] array = Object.FindObjectsOfType<Renderer>(true);
			foreach (Renderer val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.enabled && !Renderers.Contains(val) && ShouldSuppressVisual(((Component)val).transform))
				{
					Renderers.Add(val);
					val.enabled = false;
				}
			}
		}

		private static void SuppressParticles()
		{
			ParticleSystem[] array = Object.FindObjectsOfType<ParticleSystem>(true);
			foreach (ParticleSystem val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.isPlaying && !Particles.Contains(val) && ShouldSuppressVisual(((Component)val).transform))
				{
					Particles.Add(val);
					val.Stop(true, (ParticleSystemStopBehavior)0);
				}
			}
		}

		private static void SuppressAudio(AudioSource ownMusic)
		{
			AudioSource[] array = Object.FindObjectsOfType<AudioSource>(true);
			foreach (AudioSource val in array)
			{
				if (!((Object)(object)val == (Object)null) && !((Object)(object)val == (Object)(object)ownMusic) && ShouldSuppressAudio(val))
				{
					if (!AudioStates.ContainsKey(val))
					{
						AudioStates[val] = new AudioState(val);
					}
					val.Pause();
					val.mute = true;
				}
			}
		}

		private static bool ShouldSuppressVisual(Transform candidate)
		{
			if ((Object)(object)candidate == (Object)null)
			{
				return false;
			}
			if ((Object)(object)KH2MenuRuntime.Instance != (Object)null && candidate.IsChildOf(((Component)KH2MenuRuntime.Instance).transform))
			{
				return false;
			}
			if ((Object)(object)((Component)candidate).GetComponentInParent<Canvas>(true) != (Object)null || (Object)(object)((Component)candidate).GetComponentInParent<MenuPage>(true) != (Object)null || (Object)(object)((Component)candidate).GetComponentInParent<MenuButton>(true) != (Object)null)
			{
				return false;
			}
			return true;
		}

		private static bool ShouldSuppressAudio(AudioSource source)
		{
			if ((Object)(object)source == (Object)null)
			{
				return false;
			}
			if ((Object)(object)KH2MenuRuntime.Instance != (Object)null && ((Component)source).transform.IsChildOf(((Component)KH2MenuRuntime.Instance).transform))
			{
				return false;
			}
			if ((Object)(object)((Component)source).GetComponentInParent<MenuPage>(true) != (Object)null || (Object)(object)((Component)source).GetComponentInParent<MenuButton>(true) != (Object)null)
			{
				return false;
			}
			if (source.loop)
			{
				return true;
			}
			string text = TransformPath(((Component)source).transform).ToLowerInvariant();
			if (!text.Contains("music") && !text.Contains("ambience") && !text.Contains("ambient") && !text.Contains("truck") && !text.Contains("mainmenu"))
			{
				return text.Contains("main menu");
			}
			return true;
		}

		private static string TransformPath(Transform transformNode)
		{
			List<string> list = new List<string>();
			while ((Object)(object)transformNode != (Object)null)
			{
				list.Add(((Object)transformNode).name);
				transformNode = transformNode.parent;
			}
			list.Reverse();
			return string.Join("/", list.ToArray());
		}
	}
}