Decompiled source of PEAKDeathTunes v1.0.1

PEAKDeathTunes/ryang.peakdeathtunes.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
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.Threading;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

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

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

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

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[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 BepInEx
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Embedded]
	internal sealed class BepInAutoPluginAttribute : Attribute
	{
		public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace BepInEx.Preloader.Core.Patching
{
	[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
	[Conditional("CodeGeneration")]
	[Embedded]
	internal sealed class PatcherAutoPluginAttribute : Attribute
	{
		public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
		{
		}
	}
}
namespace Microsoft.CodeAnalysis
{
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace PEAKDeathTunes
{
	[BepInPlugin("ryang.peakdeathtunes", "PEAKDeathTunes", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Id = "ryang.peakdeathtunes";

		internal static ManualLogSource Log { get; private set; }

		public static string Name => "PEAKDeathTunes";

		public static string Version => "0.1.0";

		private void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)("Plugin " + Name + " is loaded!"));
		}
	}
}
namespace DeathTunes
{
	public static class DeathCustomizationManager
	{
		private class ButtonHoverHandler : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
		{
			public Image Background;

			public TextMeshProUGUI Text;

			public Color NormalBackground;

			public Color HoverBackground;

			public Color NormalText;

			public Color HoverText;

			public void OnPointerEnter(PointerEventData eventData)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Background != (Object)null)
				{
					((Graphic)Background).color = HoverBackground;
				}
				if ((Object)(object)Text != (Object)null)
				{
					((Graphic)Text).color = HoverText;
				}
			}

			public void OnPointerExit(PointerEventData eventData)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Background != (Object)null)
				{
					((Graphic)Background).color = NormalBackground;
				}
				if ((Object)(object)Text != (Object)null)
				{
					((Graphic)Text).color = NormalText;
				}
			}
		}

		[CompilerGenerated]
		private static class <>O
		{
			public static UnityAction <0>__PlaySelectedSound;

			public static UnityAction <1>__SaveSelection;

			public static UnityAction <2>__CloseMenu;

			public static Func<string, bool> <3>__Exists;
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__23_0;

			public static UnityAction <>9__23_1;

			internal void <CreateMenu>b__23_0()
			{
				PreviousSound();
				UpdateMenuDisplay();
			}

			internal void <CreateMenu>b__23_1()
			{
				NextSound();
				UpdateMenuDisplay();
			}
		}

		public static readonly Dictionary<string, AudioClip> Sounds = new Dictionary<string, AudioClip>();

		public static readonly List<string> SoundIDs = new List<string>();

		public static string SelectedSound = "";

		private static int soundIndex;

		private static GameObject menu;

		private static TextMeshProUGUI soundNameText;

		private static TextMeshProUGUI soundCounterText;

		private static Button previousButton;

		private static Button nextButton;

		private static Button previewButton;

		private static Button saveButton;

		private static Button closeButton;

		private static TMP_FontAsset gameFont;

		private static readonly Color WhiteColor = Color32.op_Implicit(new Color32((byte)252, (byte)254, (byte)253, byte.MaxValue));

		private static readonly Color BlueColor = Color32.op_Implicit(new Color32((byte)79, (byte)126, (byte)251, byte.MaxValue));

		public static int CurrentSoundIndex => soundIndex;

		public static bool IsMenuOpen()
		{
			return (Object)(object)menu != (Object)null && menu.activeInHierarchy;
		}

		public static void LoadSounds()
		{
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				return;
			}
			string path = Path.Combine(directoryName, "Sounds");
			List<string> list = new List<string>();
			if (Directory.Exists(path))
			{
				list.AddRange(Directory.GetFiles(path, "*.wav", SearchOption.AllDirectories));
			}
			list.AddRange(Directory.GetFiles(directoryName, "*.wav", SearchOption.TopDirectoryOnly));
			foreach (string item in list.Distinct())
			{
				try
				{
					AudioClip val = DeathTunesPlugin.Instance.LoadWav(item);
					if (!((Object)(object)val == (Object)null))
					{
						string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(item);
						if (!Sounds.ContainsKey(fileNameWithoutExtension))
						{
							Sounds.Add(fileNameWithoutExtension, val);
							SoundIDs.Add(fileNameWithoutExtension);
						}
					}
				}
				catch (Exception arg)
				{
					DeathTunesPlugin.Log.LogError((object)$"Failed loading {item}: {arg}");
				}
			}
			SoundIDs.Sort(StringComparer.OrdinalIgnoreCase);
			if (SoundIDs.Count == 0)
			{
				SelectedSound = "";
				soundIndex = 0;
				return;
			}
			string value = DeathTunesPlugin.SavedDeathSound.Value;
			if (!string.IsNullOrEmpty(value) && Sounds.ContainsKey(value))
			{
				SelectedSound = value;
				soundIndex = SoundIDs.IndexOf(value);
			}
			else
			{
				soundIndex = 0;
				SelectedSound = SoundIDs[0];
			}
		}

		public static void OpenMenu()
		{
			if (IsMainMenu())
			{
				if ((Object)(object)menu == (Object)null)
				{
					CreateMenu();
				}
				menu.SetActive(true);
				UpdateMenuDisplay();
			}
		}

		public static void CloseMenu()
		{
			if ((Object)(object)menu != (Object)null)
			{
				menu.SetActive(false);
			}
		}

		public static bool IsMainMenu()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (!((Scene)(ref activeScene)).IsValid() || !((Scene)(ref activeScene)).isLoaded)
			{
				return false;
			}
			GameObject[] rootGameObjects = ((Scene)(ref activeScene)).GetRootGameObjects();
			GameObject[] array = rootGameObjects;
			foreach (GameObject val in array)
			{
				if ((Object)(object)FindInChildren(val.transform, "MainMenu") != (Object)null)
				{
					return true;
				}
			}
			return false;
		}

		private static Transform FindInChildren(Transform parent, string name)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			if (((Object)parent).name.Equals(name, StringComparison.OrdinalIgnoreCase))
			{
				return parent;
			}
			foreach (Transform item in parent)
			{
				Transform parent2 = item;
				Transform val = FindInChildren(parent2, name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		private static void CreateMenu()
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Expected O, but got Unknown
			//IL_0057: 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_00b9: 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_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Expected O, but got Unknown
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0204: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: 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_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0308: Unknown result type (might be due to invalid IL or missing references)
			//IL_0317: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			//IL_036e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0373: Unknown result type (might be due to invalid IL or missing references)
			//IL_03a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_0345: Unknown result type (might be due to invalid IL or missing references)
			//IL_034a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Expected O, but got Unknown
			//IL_0401: Unknown result type (might be due to invalid IL or missing references)
			//IL_0410: Unknown result type (might be due to invalid IL or missing references)
			//IL_03da: Unknown result type (might be due to invalid IL or missing references)
			//IL_03df: Unknown result type (might be due to invalid IL or missing references)
			//IL_03e5: Expected O, but got Unknown
			//IL_0461: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_043f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0445: Expected O, but got Unknown
			//IL_049a: Unknown result type (might be due to invalid IL or missing references)
			//IL_049f: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Expected O, but got Unknown
			gameFont = FindGameFont();
			menu = new GameObject("DeathTunesMenu");
			Canvas val = menu.AddComponent<Canvas>();
			val.renderMode = (RenderMode)0;
			val.sortingOrder = 5000;
			CanvasScaler val2 = menu.AddComponent<CanvasScaler>();
			val2.uiScaleMode = (ScaleMode)1;
			val2.referenceResolution = new Vector2(1920f, 1080f);
			val2.screenMatchMode = (ScreenMatchMode)0;
			val2.matchWidthOrHeight = 0.5f;
			menu.AddComponent<GraphicRaycaster>();
			GameObject val3 = CreateBoardingPass(menu.transform);
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0.5f, 0.5f);
			component.anchorMax = new Vector2(0.5f, 0.5f);
			component.pivot = new Vector2(0.5f, 0.5f);
			component.sizeDelta = new Vector2(1200f, 400f);
			component.anchoredPosition = Vector2.zero;
			GameObject val4 = new GameObject("Content");
			val4.transform.SetParent(menu.transform, false);
			RectTransform val5 = val4.AddComponent<RectTransform>();
			val5.anchorMin = new Vector2(0.5f, 0.5f);
			val5.anchorMax = new Vector2(0.5f, 0.5f);
			val5.pivot = new Vector2(0.5f, 0.5f);
			val5.sizeDelta = new Vector2(1200f, 300f);
			val5.anchoredPosition = new Vector2(0f, -30f);
			CreateText(val4.transform, "DEATHTUNES", 37, new Vector2(-260f, 103f), BlueColor);
			CreateText(val4.transform, "DEATH SOUND CUSTOMIZATION", 21, new Vector2(-260f, 68f), BlueColor);
			CreateText(val4.transform, "SELECT SOUND", 20, new Vector2(-260f, 38f), BlueColor);
			GameObject val6 = CreatePanel(val4.transform, new Vector2(410f, 52f), new Vector2(-260f, -5f), WhiteColor);
			AddBorder(val6, BlueColor, 2f);
			GameObject val7 = CreateText(val6.transform, "", 25, Vector2.zero, BlueColor);
			soundNameText = val7.GetComponent<TextMeshProUGUI>();
			((TMP_Text)soundNameText).fontStyle = (FontStyles)1;
			previousButton = CreateStyledButton(val4.transform, "‹", new Vector2(-495f, -5f), new Vector2(52f, 52f), arrow: true);
			ButtonClickedEvent onClick = previousButton.onClick;
			object obj = <>c.<>9__23_0;
			if (obj == null)
			{
				UnityAction val8 = delegate
				{
					PreviousSound();
					UpdateMenuDisplay();
				};
				<>c.<>9__23_0 = val8;
				obj = (object)val8;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			nextButton = CreateStyledButton(val4.transform, "›", new Vector2(-25f, -5f), new Vector2(52f, 52f), arrow: true);
			ButtonClickedEvent onClick2 = nextButton.onClick;
			object obj2 = <>c.<>9__23_1;
			if (obj2 == null)
			{
				UnityAction val9 = delegate
				{
					NextSound();
					UpdateMenuDisplay();
				};
				<>c.<>9__23_1 = val9;
				obj2 = (object)val9;
			}
			((UnityEvent)onClick2).AddListener((UnityAction)obj2);
			GameObject val10 = CreateText(val4.transform, "", 16, new Vector2(-260f, -43f), BlueColor);
			soundCounterText = val10.GetComponent<TextMeshProUGUI>();
			previewButton = CreateStyledButton(val4.transform, ">  PREVIEW SOUND", new Vector2(340f, 40f), new Vector2(280f, 46f), arrow: false);
			ButtonClickedEvent onClick3 = previewButton.onClick;
			object obj3 = <>O.<0>__PlaySelectedSound;
			if (obj3 == null)
			{
				UnityAction val11 = PlaySelectedSound;
				<>O.<0>__PlaySelectedSound = val11;
				obj3 = (object)val11;
			}
			((UnityEvent)onClick3).AddListener((UnityAction)obj3);
			saveButton = CreateStyledButton(val4.transform, ">  SAVE", new Vector2(340f, -22f), new Vector2(180f, 46f), arrow: false);
			ButtonClickedEvent onClick4 = saveButton.onClick;
			object obj4 = <>O.<1>__SaveSelection;
			if (obj4 == null)
			{
				UnityAction val12 = SaveSelection;
				<>O.<1>__SaveSelection = val12;
				obj4 = (object)val12;
			}
			((UnityEvent)onClick4).AddListener((UnityAction)obj4);
			closeButton = CreateStyledButton(val4.transform, ">  CLOSE", new Vector2(340f, -84f), new Vector2(180f, 46f), arrow: false);
			ButtonClickedEvent onClick5 = closeButton.onClick;
			object obj5 = <>O.<2>__CloseMenu;
			if (obj5 == null)
			{
				UnityAction val13 = CloseMenu;
				<>O.<2>__CloseMenu = val13;
				obj5 = (object)val13;
			}
			((UnityEvent)onClick5).AddListener((UnityAction)obj5);
			menu.SetActive(false);
		}

		private static GameObject CreateBoardingPass(Transform parent)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("BoardingPass");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = new Vector2(1200f, 400f);
			val2.anchoredPosition = Vector2.zero;
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).color = Color.white;
			((Graphic)val3).raycastTarget = false;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			if (string.IsNullOrEmpty(directoryName))
			{
				return val;
			}
			string[] source = new string[3]
			{
				Path.Combine(directoryName, "Sounds", "Boarding_pass_full.png"),
				Path.Combine(directoryName, "Boarding_pass_full.png"),
				Path.Combine(directoryName, "DeathTunes", "Sounds", "Boarding_pass_full.png")
			};
			string text = source.FirstOrDefault(File.Exists);
			if (string.IsNullOrEmpty(text))
			{
				DeathTunesPlugin.Log.LogError((object)"Could not find Boarding_pass_full.png.");
				return val;
			}
			try
			{
				byte[] array = File.ReadAllBytes(text);
				Texture2D val4 = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val4, array, false))
				{
					Object.Destroy((Object)(object)val4);
					return val;
				}
				((Texture)val4).wrapMode = (TextureWrapMode)1;
				((Texture)val4).filterMode = (FilterMode)1;
				Sprite sprite = Sprite.Create(val4, new Rect(0f, 0f, (float)((Texture)val4).width, (float)((Texture)val4).height), new Vector2(0.5f, 0.5f), 1f);
				val3.sprite = sprite;
				val3.preserveAspect = false;
			}
			catch (Exception arg)
			{
				DeathTunesPlugin.Log.LogError((object)$"Failed to load Boarding_pass_full.png: {arg}");
			}
			return val;
		}

		private static void UpdateMenuDisplay()
		{
			if ((Object)(object)soundNameText == (Object)null)
			{
				return;
			}
			if (SoundIDs.Count == 0)
			{
				((TMP_Text)soundNameText).text = "NO SOUNDS FOUND";
				if ((Object)(object)soundCounterText != (Object)null)
				{
					((TMP_Text)soundCounterText).text = "SOUND 0 / 0";
				}
				return;
			}
			if (soundIndex < 0)
			{
				soundIndex = SoundIDs.Count - 1;
			}
			if (soundIndex >= SoundIDs.Count)
			{
				soundIndex = 0;
			}
			SelectedSound = SoundIDs[soundIndex];
			((TMP_Text)soundNameText).text = FormatSoundName(SelectedSound);
			if ((Object)(object)soundCounterText != (Object)null)
			{
				((TMP_Text)soundCounterText).text = $"SOUND {soundIndex + 1} / {SoundIDs.Count}";
			}
		}

		private static void SaveSelection()
		{
			if (string.IsNullOrEmpty(SelectedSound))
			{
				return;
			}
			DeathTunesPlugin.SavedDeathSound.Value = SelectedSound;
			Character localCharacter = Character.localCharacter;
			if ((Object)(object)localCharacter != (Object)null)
			{
				PhotonView photonView = ((MonoBehaviourPun)localCharacter).photonView;
				if ((Object)(object)photonView != (Object)null)
				{
					DeathSoundNetworking.SendSelection(photonView.ViewID, SelectedSound);
				}
			}
			DeathTunesPlugin.Log.LogInfo((object)("Saved death sound: " + SelectedSound));
		}

		private static void NextSound()
		{
			if (SoundIDs.Count != 0)
			{
				soundIndex++;
				if (soundIndex >= SoundIDs.Count)
				{
					soundIndex = 0;
				}
			}
		}

		private static void PreviousSound()
		{
			if (SoundIDs.Count != 0)
			{
				soundIndex--;
				if (soundIndex < 0)
				{
					soundIndex = SoundIDs.Count - 1;
				}
			}
		}

		private static void PlaySelectedSound()
		{
			if (!string.IsNullOrEmpty(SelectedSound) && Sounds.TryGetValue(SelectedSound, out AudioClip value))
			{
				DeathTunesPlugin.PlayClip(value);
			}
		}

		private static GameObject CreatePanel(Transform parent, Vector2 size, Vector2 position, Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Panel");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = size;
			val2.anchoredPosition = position;
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).color = color;
			return val;
		}

		private static GameObject CreateText(Transform parent, string value, int size, Vector2 position, Color color)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Text");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = new Vector2(600f, 54f);
			val2.anchoredPosition = position;
			TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = value;
			((TMP_Text)val3).fontSize = size;
			((Graphic)val3).color = color;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val3).textWrappingMode = (TextWrappingModes)0;
			((Graphic)val3).raycastTarget = false;
			if ((Object)(object)gameFont != (Object)null)
			{
				((TMP_Text)val3).font = gameFont;
			}
			return val;
		}

		private static Button CreateStyledButton(Transform parent, string value, Vector2 position, Vector2 size, bool arrow)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: 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_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: 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_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("Button");
			val.transform.SetParent(parent, false);
			RectTransform val2 = val.AddComponent<RectTransform>();
			val2.anchorMin = new Vector2(0.5f, 0.5f);
			val2.anchorMax = new Vector2(0.5f, 0.5f);
			val2.pivot = new Vector2(0.5f, 0.5f);
			val2.sizeDelta = size;
			val2.anchoredPosition = position;
			Image val3 = val.AddComponent<Image>();
			((Graphic)val3).color = (arrow ? BlueColor : WhiteColor);
			Button val4 = val.AddComponent<Button>();
			((Selectable)val4).transition = (Transition)0;
			AddBorder(val, BlueColor, 2f);
			GameObject val5 = CreateText(val.transform, value, arrow ? 42 : 18, Vector2.zero, arrow ? WhiteColor : BlueColor);
			TextMeshProUGUI component = val5.GetComponent<TextMeshProUGUI>();
			((TMP_Text)component).fontStyle = (FontStyles)1;
			ButtonHoverHandler buttonHoverHandler = val.AddComponent<ButtonHoverHandler>();
			buttonHoverHandler.Background = val3;
			buttonHoverHandler.Text = component;
			buttonHoverHandler.NormalBackground = (arrow ? BlueColor : WhiteColor);
			buttonHoverHandler.HoverBackground = BlueColor;
			buttonHoverHandler.NormalText = (arrow ? WhiteColor : BlueColor);
			buttonHoverHandler.HoverText = WhiteColor;
			return val4;
		}

		private static void AddBorder(GameObject target, Color color, float thickness)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Outline val = target.AddComponent<Outline>();
			((Shadow)val).effectColor = color;
			((Shadow)val).effectDistance = new Vector2(thickness, thickness);
			((Shadow)val).useGraphicAlpha = true;
		}

		private static TMP_FontAsset FindGameFont()
		{
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			TMP_FontAsset[] array2 = array;
			foreach (TMP_FontAsset val in array2)
			{
				if (!((Object)(object)val == (Object)null) && ((Object)val).name.IndexOf("Darumadrop", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					return val;
				}
			}
			return null;
		}

		private static string FormatSoundName(string id)
		{
			if (string.IsNullOrEmpty(id))
			{
				return "UNKNOWN SOUND";
			}
			return id.Replace("_", " ").Replace("-", " ").ToUpperInvariant();
		}
	}
	[HarmonyPatch(typeof(Character), "RPCA_Die")]
	public static class DeathPatch
	{
		private static void Postfix(Character __instance)
		{
			try
			{
				if (!((Object)(object)__instance == (Object)null) && DeathTunesPlugin.BoundConfig.Enabled.Value)
				{
					PlayerDeathSoundManager.PlayPlayerDeathSound(__instance);
				}
			}
			catch (Exception ex)
			{
				DeathTunesPlugin.Log.LogError((object)("DeathPatch error: " + ex));
			}
		}
	}
	public static class DeathSoundNetworking
	{
		private const byte SoundSelectionEvent = 73;

		private const byte PlayerDeathEvent = 74;

		public static readonly Dictionary<int, string> PlayerSounds = new Dictionary<int, string>();

		public static void Initialize()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonNetwork.AddCallbackTarget((object)DeathTunesPlugin.Instance);
				if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
				{
					DeathTunesPlugin.Log.LogInfo((object)"DeathTunes Photon networking initialized.");
				}
			}
		}

		public static void Shutdown()
		{
			if ((Object)(object)DeathTunesPlugin.Instance != (Object)null)
			{
				PhotonNetwork.RemoveCallbackTarget((object)DeathTunesPlugin.Instance);
			}
			PlayerSounds.Clear();
		}

		public static void SendSelection(int viewID, string sound)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			if (string.IsNullOrEmpty(sound))
			{
				return;
			}
			PlayerSounds[viewID] = sound;
			if (PhotonNetwork.IsConnected && PhotonNetwork.InRoom)
			{
				object[] array = new object[2] { viewID, sound };
				RaiseEventOptions val = new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				};
				SendOptions val2 = default(SendOptions);
				((SendOptions)(ref val2)).Reliability = true;
				PhotonNetwork.RaiseEvent((byte)73, (object)array, val, val2);
				if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
				{
					DeathTunesPlugin.Log.LogInfo((object)$"Sent sound selection: {viewID} -> {sound}");
				}
			}
		}

		public static void SendDeath(int viewID, string sound)
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			if (!string.IsNullOrEmpty(sound) && PhotonNetwork.IsConnected && PhotonNetwork.InRoom)
			{
				object[] array = new object[2] { viewID, sound };
				RaiseEventOptions val = new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				};
				SendOptions val2 = default(SendOptions);
				((SendOptions)(ref val2)).Reliability = true;
				PhotonNetwork.RaiseEvent((byte)74, (object)array, val, val2);
				if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
				{
					DeathTunesPlugin.Log.LogInfo((object)$"Sent death sound: {viewID} -> {sound}");
				}
			}
		}

		public static void OnEvent(EventData photonEvent)
		{
			if (photonEvent != null)
			{
				switch (photonEvent.Code)
				{
				case 73:
					HandleSelectionEvent(photonEvent);
					break;
				case 74:
					HandleDeathEvent(photonEvent);
					break;
				}
			}
		}

		private static void HandleSelectionEvent(EventData photonEvent)
		{
			try
			{
				if (!(photonEvent.CustomData is object[] array) || array.Length < 2)
				{
					return;
				}
				int num = Convert.ToInt32(array[0]);
				string text = array[1] as string;
				if (!string.IsNullOrEmpty(text))
				{
					PlayerSounds[num] = text;
					if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
					{
						DeathTunesPlugin.Log.LogInfo((object)$"Received sound selection: {num} -> {text}");
					}
				}
			}
			catch (Exception ex)
			{
				DeathTunesPlugin.Log.LogError((object)("Failed to process sound selection: " + ex));
			}
		}

		private static void HandleDeathEvent(EventData photonEvent)
		{
			try
			{
				if (!(photonEvent.CustomData is object[] array) || array.Length < 2)
				{
					return;
				}
				int num = Convert.ToInt32(array[0]);
				string text = array[1] as string;
				if (!string.IsNullOrEmpty(text))
				{
					PlayerSounds[num] = text;
					if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
					{
						DeathTunesPlugin.Log.LogInfo((object)$"Received death sound: {num} -> {text}");
					}
					PlayerDeathSoundManager.PlayNetworkDeathSound(num, text);
				}
			}
			catch (Exception ex)
			{
				DeathTunesPlugin.Log.LogError((object)("Failed to process death sound: " + ex));
			}
		}

		public static void ClearPlayer(int viewID)
		{
			PlayerSounds.Remove(viewID);
		}
	}
	[BepInPlugin("ryang.deathtunes", "DeathTunes", "0.1.0")]
	public class DeathTunesPlugin : BaseUnityPlugin, IOnEventCallback
	{
		private class DeathSoundButtonHover : MonoBehaviour, IPointerEnterHandler, IEventSystemHandler, IPointerExitHandler
		{
			public Image Background;

			public TextMeshProUGUI Text;

			public TextMeshProUGUI Arrow;

			private readonly Color normalBackground = Color32.op_Implicit(new Color32((byte)191, (byte)143, (byte)82, byte.MaxValue));

			private readonly Color hoverBackground = Color32.op_Implicit(new Color32((byte)79, (byte)126, (byte)251, byte.MaxValue));

			private readonly Color normalText = Color32.op_Implicit(new Color32((byte)78, (byte)54, (byte)42, byte.MaxValue));

			private readonly Color hoverText = Color32.op_Implicit(new Color32(byte.MaxValue, byte.MaxValue, byte.MaxValue, byte.MaxValue));

			public void OnPointerEnter(PointerEventData eventData)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Background != (Object)null)
				{
					((Graphic)Background).color = hoverBackground;
				}
				if ((Object)(object)Text != (Object)null)
				{
					((Graphic)Text).color = hoverText;
				}
				if ((Object)(object)Arrow != (Object)null)
				{
					((Graphic)Arrow).color = hoverText;
				}
			}

			public void OnPointerExit(PointerEventData eventData)
			{
				//IL_0018: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				//IL_005c: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Background != (Object)null)
				{
					((Graphic)Background).color = normalBackground;
				}
				if ((Object)(object)Text != (Object)null)
				{
					((Graphic)Text).color = normalText;
				}
				if ((Object)(object)Arrow != (Object)null)
				{
					((Graphic)Arrow).color = normalText;
				}
			}
		}

		[HarmonyPatch(typeof(MainMenu), "Start")]
		private static class MainMenuStartPatch
		{
			[HarmonyPostfix]
			private static void Postfix(MainMenu __instance)
			{
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0012: Expected O, but got Unknown
				LockMenuTransition();
				GameObject val = new GameObject("DeathTunesMainMenuRunner");
				((Object)val).hideFlags = (HideFlags)61;
				MainMenuRunner mainMenuRunner = val.AddComponent<MainMenuRunner>();
				mainMenuRunner.Begin();
			}
		}

		private class MainMenuRunner : MonoBehaviour
		{
			public void Begin()
			{
				((MonoBehaviour)this).StartCoroutine(WaitForMainMenu());
			}

			private IEnumerator WaitForMainMenu()
			{
				yield return null;
				yield return (object)new WaitForEndOfFrame();
				yield return (object)new WaitForSecondsRealtime(0.75f);
				if ((Object)(object)FindActiveMainMenu() != (Object)null && !PhotonNetwork.InRoom)
				{
					BeginMainMenuReady();
				}
				Object.Destroy((Object)(object)((Component)this).gameObject);
			}
		}

		[Serializable]
		[CompilerGenerated]
		private sealed class <>c
		{
			public static readonly <>c <>9 = new <>c();

			public static UnityAction <>9__33_0;

			internal void <CreateDeathSoundButton>b__33_0()
			{
				if (menuTransitionLocked || PhotonNetwork.InRoom)
				{
					return;
				}
				if (!DeathCustomizationManager.IsMenuOpen())
				{
					if ((Object)(object)FindActiveMainMenu() != (Object)null)
					{
						DeathCustomizationManager.OpenMenu();
					}
				}
				else
				{
					DeathCustomizationManager.CloseMenu();
				}
			}
		}

		public static ConfigEntry<string> SavedDeathSound;

		private Harmony harmony;

		private bool photonRegistered;

		private Coroutine menuWatcherCoroutine;

		private static GameObject deathTunesButton;

		private static bool menuTransitionLocked;

		private static int mainMenuGeneration;

		public static DeathTunesPlugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		public static AudioSource AudioSource { get; private set; }

		public static ModConfig BoundConfig { get; private set; }

		private void Awake()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			if ((Object)(object)Instance != (Object)null && (Object)(object)Instance != (Object)(object)this)
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
				return;
			}
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
			SavedDeathSound = ((BaseUnityPlugin)this).Config.Bind<string>("DeathTunes", "SelectedDeathSound", "", "The selected death sound.");
			BoundConfig = new ModConfig(((BaseUnityPlugin)this).Config);
			Log.LogInfo((object)"DeathTunes starting...");
			DeathCustomizationManager.LoadSounds();
			CreateAudioObject();
			harmony = new Harmony("ryang.deathtunes");
			harmony.PatchAll();
			((MonoBehaviour)this).StartCoroutine(RegisterPhoton());
			SceneManager.sceneLoaded += OnSceneLoaded;
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			menuWatcherCoroutine = ((MonoBehaviour)this).StartCoroutine(MainMenuWatcher());
			Log.LogInfo((object)"DeathTunes loaded.");
		}

		private IEnumerator RegisterPhoton()
		{
			while (!PhotonNetwork.IsConnected)
			{
				yield return (object)new WaitForSecondsRealtime(1f);
			}
			if (!photonRegistered)
			{
				DeathSoundNetworking.Initialize();
				photonRegistered = true;
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			DeathSoundNetworking.OnEvent(photonEvent);
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			LockMenuTransition();
		}

		private void OnSceneUnloaded(Scene scene)
		{
			LockMenuTransition();
		}

		private void OnDisable()
		{
			SceneManager.sceneLoaded -= OnSceneLoaded;
			SceneManager.sceneUnloaded -= OnSceneUnloaded;
			if (menuWatcherCoroutine != null)
			{
				((MonoBehaviour)this).StopCoroutine(menuWatcherCoroutine);
				menuWatcherCoroutine = null;
			}
			RemoveDeathTunesButton();
			DeathCustomizationManager.CloseMenu();
			if (photonRegistered)
			{
				DeathSoundNetworking.Shutdown();
				photonRegistered = false;
			}
		}

		private static void LockMenuTransition()
		{
			menuTransitionLocked = true;
			RemoveDeathTunesButton();
			DeathCustomizationManager.CloseMenu();
		}

		private static void BeginMainMenuReady()
		{
			mainMenuGeneration++;
			menuTransitionLocked = false;
		}

		private IEnumerator MainMenuWatcher()
		{
			int lastGeneration = -1;
			float readyTime = -1f;
			bool waitingForMenu = true;
			WaitForSecondsRealtime interval = new WaitForSecondsRealtime(0.25f);
			while (true)
			{
				if (PhotonNetwork.InRoom)
				{
					if ((Object)(object)deathTunesButton != (Object)null)
					{
						RemoveDeathTunesButton();
					}
					waitingForMenu = true;
					readyTime = -1f;
					yield return interval;
					continue;
				}
				MainMenu mainMenu = FindActiveMainMenu();
				if ((Object)(object)mainMenu == (Object)null)
				{
					waitingForMenu = true;
					readyTime = -1f;
					if ((Object)(object)deathTunesButton != (Object)null)
					{
						RemoveDeathTunesButton();
					}
					yield return interval;
					continue;
				}
				if (lastGeneration != mainMenuGeneration)
				{
					lastGeneration = mainMenuGeneration;
					waitingForMenu = true;
					readyTime = -1f;
				}
				if (menuTransitionLocked)
				{
					waitingForMenu = true;
					readyTime = -1f;
					if ((Object)(object)deathTunesButton != (Object)null)
					{
						RemoveDeathTunesButton();
					}
					yield return interval;
					continue;
				}
				if (waitingForMenu)
				{
					waitingForMenu = false;
					readyTime = Time.unscaledTime;
				}
				if (Time.unscaledTime - readyTime >= 1f && (Object)(object)deathTunesButton == (Object)null && !menuTransitionLocked && !PhotonNetwork.InRoom && (Object)(object)FindActiveMainMenu() != (Object)null)
				{
					CreateDeathSoundButton();
				}
				yield return interval;
			}
		}

		private static MainMenu FindActiveMainMenu()
		{
			MainMenu[] array = Object.FindObjectsOfType<MainMenu>(true);
			MainMenu[] array2 = array;
			foreach (MainMenu val in array2)
			{
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				GameObject gameObject = ((Component)val).gameObject;
				if (!gameObject.activeInHierarchy || !((Behaviour)val).enabled)
				{
					continue;
				}
				Canvas[] componentsInChildren = ((Component)val).GetComponentsInChildren<Canvas>(true);
				Canvas[] array3 = componentsInChildren;
				foreach (Canvas val2 in array3)
				{
					if (!((Object)(object)val2 == (Object)null) && ((Behaviour)val2).isActiveAndEnabled && ((Component)val2).gameObject.activeInHierarchy)
					{
						return val;
					}
				}
			}
			return null;
		}

		private static void CreateDeathSoundButton()
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0194: Expected O, but got Unknown
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Expected O, but got Unknown
			//IL_0299: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a0: Expected O, but got Unknown
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ed: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_034b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0350: Unknown result type (might be due to invalid IL or missing references)
			if (menuTransitionLocked || PhotonNetwork.InRoom)
			{
				return;
			}
			MainMenu val = FindActiveMainMenu();
			if ((Object)(object)val == (Object)null || (Object)(object)deathTunesButton != (Object)null)
			{
				return;
			}
			Canvas val2 = FindMainMenuCanvas(val);
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			GameObject val3 = (deathTunesButton = new GameObject("DeathTunesMainMenuButton"));
			val3.transform.SetParent(((Component)val2).transform, false);
			RectTransform val4 = val3.AddComponent<RectTransform>();
			val4.anchorMin = new Vector2(1f, 0.5f);
			val4.anchorMax = new Vector2(1f, 0.5f);
			val4.pivot = new Vector2(1f, 0.5f);
			val4.anchoredPosition = new Vector2(-22f, -10f);
			val4.sizeDelta = new Vector2(250f, 72f);
			Image val5 = val3.AddComponent<Image>();
			((Graphic)val5).color = Color32.op_Implicit(new Color32((byte)191, (byte)143, (byte)82, byte.MaxValue));
			Button val6 = val3.AddComponent<Button>();
			((Selectable)val6).targetGraphic = (Graphic)(object)val5;
			((Selectable)val6).transition = (Transition)0;
			ButtonClickedEvent onClick = val6.onClick;
			object obj = <>c.<>9__33_0;
			if (obj == null)
			{
				UnityAction val7 = delegate
				{
					if (!menuTransitionLocked && !PhotonNetwork.InRoom)
					{
						if (!DeathCustomizationManager.IsMenuOpen())
						{
							if ((Object)(object)FindActiveMainMenu() != (Object)null)
							{
								DeathCustomizationManager.OpenMenu();
							}
						}
						else
						{
							DeathCustomizationManager.CloseMenu();
						}
					}
				};
				<>c.<>9__33_0 = val7;
				obj = (object)val7;
			}
			((UnityEvent)onClick).AddListener((UnityAction)obj);
			AddBorder(val3, Color32.op_Implicit(new Color32((byte)78, (byte)54, (byte)42, byte.MaxValue)), 2f);
			GameObject val8 = new GameObject("DeathTunesText");
			val8.transform.SetParent(val3.transform, false);
			RectTransform val9 = val8.AddComponent<RectTransform>();
			val9.anchorMin = new Vector2(0f, 0f);
			val9.anchorMax = new Vector2(0.82f, 1f);
			val9.offsetMin = new Vector2(10f, 0f);
			val9.offsetMax = new Vector2(-5f, 0f);
			TextMeshProUGUI val10 = val8.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val10).text = "DEATHTUNES";
			((TMP_Text)val10).fontSize = 20f;
			((TMP_Text)val10).fontStyle = (FontStyles)1;
			((TMP_Text)val10).alignment = (TextAlignmentOptions)514;
			((Graphic)val10).color = Color32.op_Implicit(new Color32((byte)78, (byte)54, (byte)42, byte.MaxValue));
			((Graphic)val10).raycastTarget = false;
			((TMP_Text)val10).textWrappingMode = (TextWrappingModes)0;
			TMP_FontAsset val11 = FindGameFont();
			if ((Object)(object)val11 != (Object)null)
			{
				((TMP_Text)val10).font = val11;
			}
			GameObject val12 = new GameObject("Arrow");
			val12.transform.SetParent(val3.transform, false);
			RectTransform val13 = val12.AddComponent<RectTransform>();
			val13.anchorMin = new Vector2(0.82f, 0f);
			val13.anchorMax = new Vector2(1f, 1f);
			val13.offsetMin = Vector2.zero;
			val13.offsetMax = Vector2.zero;
			TextMeshProUGUI val14 = val12.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val14).text = "›";
			((TMP_Text)val14).fontSize = 38f;
			((TMP_Text)val14).fontStyle = (FontStyles)1;
			((TMP_Text)val14).alignment = (TextAlignmentOptions)514;
			((Graphic)val14).color = Color32.op_Implicit(new Color32((byte)78, (byte)54, (byte)42, byte.MaxValue));
			((Graphic)val14).raycastTarget = false;
			if ((Object)(object)val11 != (Object)null)
			{
				((TMP_Text)val14).font = val11;
			}
			DeathSoundButtonHover deathSoundButtonHover = val3.AddComponent<DeathSoundButtonHover>();
			deathSoundButtonHover.Background = val5;
			deathSoundButtonHover.Text = val10;
			deathSoundButtonHover.Arrow = val14;
		}

		private static Canvas FindMainMenuCanvas(MainMenu mainMenu)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			if ((Object)(object)mainMenu == (Object)null)
			{
				return null;
			}
			Canvas[] componentsInChildren = ((Component)mainMenu).GetComponentsInChildren<Canvas>(true);
			Canvas[] array = componentsInChildren;
			foreach (Canvas val in array)
			{
				if (!((Object)(object)val == (Object)null) && ((Behaviour)val).isActiveAndEnabled && ((Component)val).gameObject.activeInHierarchy && (int)val.renderMode == 0)
				{
					EnsureEventSystem();
					return val;
				}
			}
			Canvas componentInParent = ((Component)mainMenu).GetComponentInParent<Canvas>();
			if ((Object)(object)componentInParent != (Object)null)
			{
				EnsureEventSystem();
				return componentInParent;
			}
			return null;
		}

		private static void RemoveDeathTunesButton()
		{
			if ((Object)(object)deathTunesButton != (Object)null)
			{
				Object.Destroy((Object)(object)deathTunesButton);
				deathTunesButton = null;
			}
			GameObject val = GameObject.Find("DeathTunesMainMenuButton");
			if ((Object)(object)val != (Object)null)
			{
				Object.Destroy((Object)(object)val);
			}
		}

		private static void EnsureEventSystem()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			EventSystem val = Object.FindObjectOfType<EventSystem>();
			if (!((Object)(object)val != (Object)null))
			{
				GameObject val2 = new GameObject("DeathTunesEventSystem");
				((Object)val2).hideFlags = (HideFlags)61;
				val2.AddComponent<EventSystem>();
				val2.AddComponent<StandaloneInputModule>();
			}
		}

		private static TMP_FontAsset FindGameFont()
		{
			TMP_FontAsset[] array = Resources.FindObjectsOfTypeAll<TMP_FontAsset>();
			TMP_FontAsset[] array2 = array;
			foreach (TMP_FontAsset val in array2)
			{
				if (!((Object)(object)val == (Object)null))
				{
					string text = ((Object)val).name.ToLowerInvariant();
					if (text.Contains("daruma") || text.Contains("drop") || text.Contains("peak"))
					{
						return val;
					}
				}
			}
			return null;
		}

		private static void AddBorder(GameObject target, Color color, float thickness)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			Outline val = target.AddComponent<Outline>();
			((Shadow)val).effectColor = color;
			((Shadow)val).effectDistance = new Vector2(thickness, thickness);
			((Shadow)val).useGraphicAlpha = true;
		}

		public static void CreateAudioObject()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Expected O, but got Unknown
			if (!((Object)(object)AudioSource != (Object)null))
			{
				GameObject val = new GameObject("DeathTunesAudio");
				Object.DontDestroyOnLoad((Object)(object)val);
				AudioSource = val.AddComponent<AudioSource>();
				AudioSource.playOnAwake = false;
				AudioSource.loop = false;
				AudioSource.spatialBlend = 0f;
				AudioSource.volume = 1f;
				AudioSource.ignoreListenerVolume = true;
				AudioSource.priority = 0;
			}
		}

		public AudioClip LoadWav(string path)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Invalid comparison between Unknown and I4
			try
			{
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(new Uri(path).AbsoluteUri, (AudioType)20);
				UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
				while (!((AsyncOperation)val).isDone)
				{
					Thread.Sleep(10);
				}
				if ((int)audioClip.result != 1)
				{
					Log.LogError((object)("Failed loading " + path + ": " + audioClip.error));
					audioClip.Dispose();
					return null;
				}
				AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
				audioClip.Dispose();
				if ((Object)(object)content != (Object)null)
				{
					((Object)content).name = Path.GetFileNameWithoutExtension(path);
				}
				return content;
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Error loading WAV {path}: {arg}");
				return null;
			}
		}

		public static void PlayClip(AudioClip clip)
		{
			if (!((Object)(object)clip == (Object)null))
			{
				if ((Object)(object)AudioSource == (Object)null)
				{
					CreateAudioObject();
				}
				AudioSource.Stop();
				AudioSource.clip = clip;
				AudioSource.volume = BoundConfig.Volume.Value;
				AudioSource.Play();
				if (BoundConfig.DebugLogging.Value)
				{
					Log.LogInfo((object)("Playing death sound: " + ((Object)clip).name));
				}
			}
		}
	}
	public class ModConfig
	{
		public readonly ConfigEntry<float> Volume;

		public readonly ConfigEntry<bool> Enabled;

		public readonly ConfigEntry<bool> DebugLogging;

		public ModConfig(ConfigFile cfg)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			cfg.SaveOnConfigSet = false;
			Volume = cfg.Bind<float>("DeathTunes", "Volume", 1f, new ConfigDescription("Volume of death sounds.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			Enabled = cfg.Bind<bool>("DeathTunes", "Enabled", true, "Enable DeathTunes.");
			DebugLogging = cfg.Bind<bool>("DeathTunes", "DebugLogging", false, "Enable debug logging.");
			ClearOrphanedEntries(cfg);
			cfg.Save();
			cfg.SaveOnConfigSet = true;
		}

		private static void ClearOrphanedEntries(ConfigFile cfg)
		{
			((Dictionary<ConfigDefinition, string>)AccessTools.Property(typeof(ConfigFile), "OrphanedEntries").GetValue(cfg)).Clear();
		}
	}
	public static class PlayerDeathSoundManager
	{
		public static void PlayPlayerDeathSound(Character character)
		{
			if ((Object)(object)character == (Object)null)
			{
				return;
			}
			PhotonView photonView = ((MonoBehaviourPun)character).photonView;
			if ((Object)(object)photonView == (Object)null)
			{
				return;
			}
			int viewID = photonView.ViewID;
			if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
			{
				DeathTunesPlugin.Log.LogInfo((object)$"Processing death for ViewID: {viewID}");
			}
			if (!photonView.IsMine)
			{
				if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
				{
					DeathTunesPlugin.Log.LogInfo((object)$"Ignoring remote death locally for ViewID: {viewID}");
				}
				return;
			}
			string text = null;
			if (DeathSoundNetworking.PlayerSounds.TryGetValue(viewID, out string value))
			{
				text = value;
			}
			if (string.IsNullOrEmpty(text) && (Object)(object)character == (Object)(object)Character.localCharacter)
			{
				string value2 = DeathTunesPlugin.SavedDeathSound.Value;
				if (!string.IsNullOrEmpty(value2))
				{
					text = value2;
				}
			}
			if (string.IsNullOrEmpty(text))
			{
				if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
				{
					DeathTunesPlugin.Log.LogWarning((object)$"No death sound found for local ViewID: {viewID}");
				}
				return;
			}
			if (!DeathCustomizationManager.Sounds.TryGetValue(text, out AudioClip value3))
			{
				DeathTunesPlugin.Log.LogWarning((object)("Could not find local AudioClip for death sound: " + text));
				return;
			}
			DeathSoundNetworking.SendDeath(viewID, text);
			if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
			{
				DeathTunesPlugin.Log.LogInfo((object)$"Playing local death sound: {viewID} -> {text}");
			}
			DeathTunesPlugin.PlayClip(value3);
		}

		public static void PlayNetworkDeathSound(int viewID, string soundID)
		{
			if (string.IsNullOrEmpty(soundID))
			{
				return;
			}
			if (!DeathCustomizationManager.Sounds.TryGetValue(soundID, out AudioClip value))
			{
				DeathTunesPlugin.Log.LogWarning((object)$"Received death sound '{soundID}' for ViewID {viewID}, but the AudioClip was not found locally.");
				return;
			}
			if (DeathTunesPlugin.BoundConfig.DebugLogging.Value)
			{
				DeathTunesPlugin.Log.LogInfo((object)$"Playing network death sound: {viewID} -> {soundID}");
			}
			DeathTunesPlugin.PlayClip(value);
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ConstantExpectedAttribute : Attribute
	{
		public object? Min { get; set; }

		public object? Max { get; set; }
	}
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ExperimentalAttribute : Attribute
	{
		public string DiagnosticId { get; }

		public string? UrlFormat { get; set; }

		public ExperimentalAttribute(string diagnosticId)
		{
			DiagnosticId = diagnosticId;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SetsRequiredMembersAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class StringSyntaxAttribute : Attribute
	{
		public const string CompositeFormat = "CompositeFormat";

		public const string DateOnlyFormat = "DateOnlyFormat";

		public const string DateTimeFormat = "DateTimeFormat";

		public const string EnumFormat = "EnumFormat";

		public const string GuidFormat = "GuidFormat";

		public const string Json = "Json";

		public const string NumericFormat = "NumericFormat";

		public const string Regex = "Regex";

		public const string TimeOnlyFormat = "TimeOnlyFormat";

		public const string TimeSpanFormat = "TimeSpanFormat";

		public const string Uri = "Uri";

		public const string Xml = "Xml";

		public string Syntax { get; }

		public object?[] Arguments { get; }

		public StringSyntaxAttribute(string syntax)
		{
			Syntax = syntax;
			Arguments = new object[0];
		}

		public StringSyntaxAttribute(string syntax, params object?[] arguments)
		{
			Syntax = syntax;
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class UnscopedRefAttribute : Attribute
	{
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresPreviewFeaturesAttribute : Attribute
	{
		public string? Message { get; }

		public string? Url { get; set; }

		public RequiresPreviewFeaturesAttribute()
		{
		}

		public RequiresPreviewFeaturesAttribute(string? message)
		{
			Message = message;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CallerArgumentExpressionAttribute : Attribute
	{
		public string ParameterName { get; }

		public CallerArgumentExpressionAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CollectionBuilderAttribute : Attribute
	{
		public Type BuilderType { get; }

		public string MethodName { get; }

		public CollectionBuilderAttribute(Type builderType, string methodName)
		{
			BuilderType = builderType;
			MethodName = methodName;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CompilerFeatureRequiredAttribute : Attribute
	{
		public const string RefStructs = "RefStructs";

		public const string RequiredMembers = "RequiredMembers";

		public string FeatureName { get; }

		public bool IsOptional { get; set; }

		public CompilerFeatureRequiredAttribute(string featureName)
		{
			FeatureName = featureName;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
	{
		public string[] Arguments { get; }

		public InterpolatedStringHandlerArgumentAttribute(string argument)
		{
			Arguments = new string[1] { argument };
		}

		public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
		{
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerAttribute : Attribute
	{
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal static class IsExternalInit
	{
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ModuleInitializerAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class OverloadResolutionPriorityAttribute : Attribute
	{
		public int Priority { get; }

		public OverloadResolutionPriorityAttribute(int priority)
		{
			Priority = priority;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = true, AllowMultiple = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ParamCollectionAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiredMemberAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresLocationAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SkipLocalsInitAttribute : Attribute
	{
	}
}