Decompiled source of AudioPlugin CCM v1.0.5

AudioPlugin_CCM.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Bounce.Singletons;
using HarmonyLib;
using ModdingTales;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AudioPlugin_CCM")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Nth Dimension")]
[assembly: AssemblyProduct("AudioPlugin_CCM")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("AudioPlugin_CCM")]
[assembly: ComVisible(false)]
[assembly: Guid("c303405d-e66c-4316-9cdb-4e3ca15c6360")]
[assembly: AssemblyFileVersion("1.0.6.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.6.0")]
namespace LordAshes;

[BepInPlugin("org.lordashes.plugins.audio.ccm", "Audio Plugin CCM", "1.0.6.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class AudioPlugin : BaseUnityPlugin
{
	public static class Provider
	{
		[CompilerGenerated]
		private sealed class <GetAudioAssets>d__2 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public ReadOnlyDictionary<string, AssetInfo> existingAssets;

			public Func<Dictionary<string, AssetInfo>, string, IEnumerator> callback;

			private byte[] <iconStop>5__1;

			private byte[] <iconVolUp>5__2;

			private byte[] <iconVolDown>5__3;

			private byte[] <iconLoop>5__4;

			private byte[] <imageBytes>5__5;

			private string[] <audioFiles>5__6;

			private Dictionary<string, AssetInfo> <assets>5__7;

			private string[] <>s__8;

			private int <>s__9;

			private string <audioFile>5__10;

			private string <audioSource>5__11;

			private string <prefab>5__12;

			private string <group>5__13;

			private string <header>5__14;

			private string <category>5__15;

			private string <pack>5__16;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<iconStop>5__1 = null;
				<iconVolUp>5__2 = null;
				<iconVolDown>5__3 = null;
				<iconLoop>5__4 = null;
				<imageBytes>5__5 = null;
				<audioFiles>5__6 = null;
				<assets>5__7 = null;
				<>s__8 = null;
				<audioFile>5__10 = null;
				<audioSource>5__11 = null;
				<prefab>5__12 = null;
				<group>5__13 = null;
				<header>5__14 = null;
				<category>5__15 = null;
				<pack>5__16 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//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_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_0190: Unknown result type (might be due to invalid IL or missing references)
				//IL_019c: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: 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_01c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
				//IL_01e9: Expected O, but got Unknown
				//IL_0215: Unknown result type (might be due to invalid IL or missing references)
				//IL_021a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0226: Unknown result type (might be due to invalid IL or missing references)
				//IL_0232: Unknown result type (might be due to invalid IL or missing references)
				//IL_023e: Unknown result type (might be due to invalid IL or missing references)
				//IL_024a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0256: Unknown result type (might be due to invalid IL or missing references)
				//IL_0262: Unknown result type (might be due to invalid IL or missing references)
				//IL_026e: Unknown result type (might be due to invalid IL or missing references)
				//IL_027a: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Expected O, but got Unknown
				//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02bc: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c8: Unknown result type (might be due to invalid IL or missing references)
				//IL_02d4: 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_02ec: Unknown result type (might be due to invalid IL or missing references)
				//IL_02f8: Unknown result type (might be due to invalid IL or missing references)
				//IL_0304: Unknown result type (might be due to invalid IL or missing references)
				//IL_0310: Unknown result type (might be due to invalid IL or missing references)
				//IL_031c: Unknown result type (might be due to invalid IL or missing references)
				//IL_032d: Expected O, but got Unknown
				//IL_0359: Unknown result type (might be due to invalid IL or missing references)
				//IL_035e: Unknown result type (might be due to invalid IL or missing references)
				//IL_036a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0376: Unknown result type (might be due to invalid IL or missing references)
				//IL_0382: Unknown result type (might be due to invalid IL or missing references)
				//IL_038e: Unknown result type (might be due to invalid IL or missing references)
				//IL_039a: Unknown result type (might be due to invalid IL or missing references)
				//IL_03a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b2: Unknown result type (might be due to invalid IL or missing references)
				//IL_03be: Unknown result type (might be due to invalid IL or missing references)
				//IL_03cf: Expected O, but got Unknown
				//IL_0422: Unknown result type (might be due to invalid IL or missing references)
				//IL_0427: Unknown result type (might be due to invalid IL or missing references)
				//IL_0433: 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_044b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0457: Unknown result type (might be due to invalid IL or missing references)
				//IL_0463: Unknown result type (might be due to invalid IL or missing references)
				//IL_046f: Unknown result type (might be due to invalid IL or missing references)
				//IL_047b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0487: Unknown result type (might be due to invalid IL or missing references)
				//IL_0498: Expected O, but got Unknown
				//IL_04c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_04c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_04e1: Unknown result type (might be due to invalid IL or missing references)
				//IL_04ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_04f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0505: Unknown result type (might be due to invalid IL or missing references)
				//IL_0511: Unknown result type (might be due to invalid IL or missing references)
				//IL_051d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0529: Unknown result type (might be due to invalid IL or missing references)
				//IL_053a: Expected O, but got Unknown
				//IL_0566: Unknown result type (might be due to invalid IL or missing references)
				//IL_056b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0577: Unknown result type (might be due to invalid IL or missing references)
				//IL_0583: Unknown result type (might be due to invalid IL or missing references)
				//IL_058f: Unknown result type (might be due to invalid IL or missing references)
				//IL_059b: Unknown result type (might be due to invalid IL or missing references)
				//IL_05a7: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_05bf: Unknown result type (might be due to invalid IL or missing references)
				//IL_05cb: Unknown result type (might be due to invalid IL or missing references)
				//IL_05dc: Expected O, but got Unknown
				//IL_0608: Unknown result type (might be due to invalid IL or missing references)
				//IL_060d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0619: Unknown result type (might be due to invalid IL or missing references)
				//IL_0625: Unknown result type (might be due to invalid IL or missing references)
				//IL_0631: Unknown result type (might be due to invalid IL or missing references)
				//IL_063d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0649: Unknown result type (might be due to invalid IL or missing references)
				//IL_0655: Unknown result type (might be due to invalid IL or missing references)
				//IL_0661: Unknown result type (might be due to invalid IL or missing references)
				//IL_066d: Unknown result type (might be due to invalid IL or missing references)
				//IL_067e: Expected O, but got Unknown
				//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
				//IL_06e3: Expected O, but got Unknown
				//IL_093b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0940: Unknown result type (might be due to invalid IL or missing references)
				//IL_094c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0959: Unknown result type (might be due to invalid IL or missing references)
				//IL_0965: Unknown result type (might be due to invalid IL or missing references)
				//IL_0972: Unknown result type (might be due to invalid IL or missing references)
				//IL_097f: Unknown result type (might be due to invalid IL or missing references)
				//IL_098c: Unknown result type (might be due to invalid IL or missing references)
				//IL_099e: Unknown result type (might be due to invalid IL or missing references)
				//IL_09ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_09ff: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					LoggingPlugin.LogInfo("Loading Icons");
					<iconStop>5__1 = ImageConversion.EncodeToPNG(Image.LoadTexture("org.lordashes.plugins.audio.ccm.Stop.png", (CacheType)999));
					<iconVolUp>5__2 = ImageConversion.EncodeToPNG(Image.LoadTexture("org.lordashes.plugins.audio.ccm.VolumeUp.png", (CacheType)999));
					<iconVolDown>5__3 = ImageConversion.EncodeToPNG(Image.LoadTexture("org.lordashes.plugins.audio.ccm.VolumeDown.png", (CacheType)999));
					<iconLoop>5__4 = ImageConversion.EncodeToPNG(Image.LoadTexture("org.lordashes.plugins.audio.ccm.Loop.png", (CacheType)999));
					<imageBytes>5__5 = ImageConversion.EncodeToPNG(Image.LoadTexture("Kind.Audio.png", (CacheType)999));
					LoggingPlugin.LogInfo("Collecting audio files");
					<audioFiles>5__6 = (from file in File.Catalog(false)
						where "|.MP3|.WAV|.OGG|.WWW|".Contains(file.Substring(file.Length - 4).ToUpper())
						select file).ToArray();
					LoggingPlugin.LogInfo("Found " + <audioFiles>5__6.Length + " Potential Audio Assets. Aware Of " + existingAssets.Count + " Registered Assets.");
					<assets>5__7 = new Dictionary<string, AssetInfo>();
					if (!existingAssets.ContainsKey("[Audio.Ambient.Stop]"))
					{
						<assets>5__7.Add("[Audio.Ambient.Stop]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Ambient",
							groupName = "[Control Ambient]",
							name = "Stop Ambient",
							prefab = ".STOP.Ambient",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..STOP.Ambient.png", <iconStop>5__1, (CacheType)999);
						<assets>5__7.Add("[Audio.Ambient.VolumeUp]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Ambient",
							groupName = "[Control Ambient]",
							name = "Volume Up",
							prefab = ".VOL.Ambient.Up",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..VOL.Ambient.Up.png", <iconVolUp>5__2, (CacheType)999);
						<assets>5__7.Add("[Audio.Ambient.VolumeDown]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Ambient",
							groupName = "[Control Ambient]",
							name = "Volume Down",
							prefab = ".VOL.Ambient.Down",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..VOL.Ambient.Down.png", <iconVolDown>5__3, (CacheType)999);
						<assets>5__7.Add("[Audio.Ambient.Loop]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Ambient",
							groupName = "[Control Ambient]",
							name = "Toggle Loop",
							prefab = ".LOOP.Ambient",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..LOOP.Ambient.png", <iconLoop>5__4, (CacheType)999);
					}
					LoggingPlugin.LogInfo("Building Audio Controls");
					if (!existingAssets.ContainsKey("[Audio.Music.Stop]"))
					{
						<assets>5__7.Add("[Audio.Music.Stop]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Music",
							groupName = "[Control Music]",
							name = "Stop Music",
							prefab = ".STOP.Music",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..STOP.Music.png", <iconStop>5__1, (CacheType)999);
						<assets>5__7.Add("[Audio.Music.VolumeUp]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Music",
							groupName = "[Control Music]",
							name = "Volume Up",
							prefab = ".VOL.Music.Up",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..VOL.Music.Up.png", <iconVolUp>5__2, (CacheType)999);
						<assets>5__7.Add("[Audio.Music.VolumeDown]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Music",
							groupName = "[Control Music]",
							name = "Volume Down",
							prefab = ".VOL.Music.Down",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..VOL.Music.Down.png", <iconVolDown>5__3, (CacheType)999);
						<assets>5__7.Add("[Audio.Music.Loop]", new AssetInfo
						{
							provider = "AUDIO",
							pack = "AudioPlugin",
							kind = "Audio",
							category = "Audio",
							header = "Music",
							groupName = "[Control Music]",
							name = "Toggle Loop",
							prefab = ".LOOP.Music",
							filename = ""
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait..LOOP.Music.png", <iconLoop>5__4, (CacheType)999);
					}
					LoggingPlugin.LogInfo("Building Audio Files Items");
					<>s__8 = <audioFiles>5__6;
					<>s__9 = 0;
					break;
				case 1:
					<>1__state = -1;
					<audioSource>5__11 = File.Find(<audioFile>5__10, (CacheType)999).ElementAt(0);
					<prefab>5__12 = Path.GetFileNameWithoutExtension(<audioFile>5__10);
					<group>5__13 = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(<audioFile>5__10));
					<header>5__14 = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(Path.GetDirectoryName(<audioFile>5__10)));
					<category>5__15 = Path.GetFileNameWithoutExtension(Path.GetDirectoryName(Path.GetDirectoryName(Path.GetDirectoryName(<audioFile>5__10))));
					<pack>5__16 = <audioSource>5__11.Substring(Paths.PluginPath.Length + 1);
					<pack>5__16 = <pack>5__16.Substring(0, <pack>5__16.IndexOf("/", 1));
					if (<header>5__14.ToUpper() == "AUDIO" && (<group>5__13.ToUpper() == "AMBIENT" || <group>5__13.ToUpper() == "MUSIC"))
					{
						<category>5__15 = "Audio";
						<header>5__14 = <group>5__13;
						<group>5__13 = "General";
					}
					LoggingPlugin.LogTrace("Found Asset (Kind: Audio, Category: " + <category>5__15 + ", Header: Audio, Group: " + <group>5__13 + ", Pack: " + <pack>5__16 + ", Name: " + insertSpaces(<prefab>5__12) + ", Prefab: " + <prefab>5__12 + ", File: " + <audioSource>5__11 + ")");
					if (!existingAssets.ContainsKey(<prefab>5__12) && !<assets>5__7.ContainsKey(<prefab>5__12))
					{
						_self.notification = "Registering... [Provider: AUDIO, Pack: " + <group>5__13 + ", Item: " + <prefab>5__12 + "]";
						<assets>5__7.Add(<prefab>5__12.Replace(" ", ""), new AssetInfo
						{
							provider = "AUDIO",
							pack = <pack>5__16,
							kind = "Audio",
							category = <category>5__15,
							header = <header>5__14,
							groupName = <group>5__13,
							name = insertSpaces(<prefab>5__12),
							prefab = <prefab>5__12.Replace(" ", ""),
							filename = (<audioFile>5__10.ToUpper().EndsWith(".WWW") ? File.ReadAllText(<audioFile>5__10, (CacheType)999) : ("File:///" + <audioSource>5__11))
						});
						File.WriteAllBytes(Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/Portrait." + <prefab>5__12.Replace(" ", "") + ".png", <imageBytes>5__5, (CacheType)999);
					}
					<audioSource>5__11 = null;
					<prefab>5__12 = null;
					<group>5__13 = null;
					<header>5__14 = null;
					<category>5__15 = null;
					<pack>5__16 = null;
					<audioFile>5__10 = null;
					<>s__9++;
					break;
				}
				if (<>s__9 < <>s__8.Length)
				{
					<audioFile>5__10 = <>s__8[<>s__9];
					<>2__current = (object)new WaitForEndOfFrame();
					<>1__state = 1;
					return true;
				}
				<>s__8 = null;
				_self.notification = null;
				((MonoBehaviour)_self).StartCoroutine(callback((from kvp in <assets>5__7
					orderby kvp.Value.header, kvp.Value.category, kvp.Value.name
					select kvp).ToDictionary((KeyValuePair<string, AssetInfo> kvp) => kvp.Key, (KeyValuePair<string, AssetInfo> kvp) => kvp.Value), "Audio"));
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

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

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

			private object <>2__current;

			public string audio;

			public string type;

			private GameObject <speaker>5__1;

			private AudioSource <player>5__2;

			private string <bundleName>5__3;

			private string <assetName>5__4;

			private AssetBundle <bundle>5__5;

			private UnityWebRequest <www>5__6;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<speaker>5__1 = null;
				<player>5__2 = null;
				<bundleName>5__3 = null;
				<assetName>5__4 = null;
				<bundle>5__5 = null;
				<www>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b0: Expected O, but got Unknown
				//IL_0391: Unknown result type (might be due to invalid IL or missing references)
				//IL_0397: Invalid comparison between Unknown and I4
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						LoggingPlugin.LogInfo("Audio Plugin: Audio URL = '" + audio + "' For 'AudioSpeaker." + type + "'");
						LoggingPlugin.LogInfo("Audio Plugin: Getting Audio Speaker");
						<speaker>5__1 = GameObject.Find("AudioSpeaker." + type);
						if ((Object)(object)<speaker>5__1 == (Object)null)
						{
							LoggingPlugin.LogInfo("Audio Plugin: Creating Audio Speaker");
							<speaker>5__1 = new GameObject();
							((Object)<speaker>5__1).name = "AudioSpeaker." + type;
							<speaker>5__1.AddComponent<AudioSource>();
						}
						LoggingPlugin.LogInfo("Audio Plugin: Creating Audio Speaker Source");
						<player>5__2 = <speaker>5__1.GetComponent<AudioSource>();
						<player>5__2.volume = ((type.ToUpper() == "AMBIENT") ? _self.volumeAmbient.Value : _self.volumeMusic.Value);
						<player>5__2.loop = ((type.ToUpper() == "AMBIENT") ? _self.loopAmbient.Value : _self.loopMusic.Value);
						if (audio != "" || audio.StartsWith("#STOP."))
						{
							if (audio.ToUpper().StartsWith("ASSETBUNDLE:"))
							{
								<bundleName>5__3 = Path.GetDirectoryName(audio.Substring("ASSETBUNDLE:".Length));
								<assetName>5__4 = Path.GetFileName(audio.Substring("ASSETBUNDLE:".Length));
								<bundle>5__5 = AssetBundle.LoadFromFile(<bundleName>5__3);
								if ((Object)(object)<bundle>5__5 != (Object)null)
								{
									Debug.Log((object)("Audio Plugin: Loading Audio '" + <bundleName>5__3 + "/" + <assetName>5__4 + "'"));
									<player>5__2.clip = <bundle>5__5.LoadAsset<AudioClip>(<assetName>5__4);
									Debug.Log((object)("Audio Plugin: Playing Audio '" + <bundleName>5__3 + "/" + <assetName>5__4 + "'"));
									<player>5__2.Play();
								}
								<bundle>5__5.Unload(false);
								if (type.ToUpper() == "AMBIENT")
								{
									bundleAmbient = <bundle>5__5;
								}
								else
								{
									bundleMusic = <bundle>5__5;
								}
								<bundleName>5__3 = null;
								<assetName>5__4 = null;
								<bundle>5__5 = null;
								break;
							}
							LoggingPlugin.LogInfo("Audio Plugin: Starting Audio '" + audio + "' Request");
							<www>5__6 = UnityWebRequestMultimedia.GetAudioClip(audio, (AudioType)0);
							<>1__state = -3;
							<>2__current = <www>5__6.SendWebRequest();
							<>1__state = 1;
							return true;
						}
						Debug.Log((object)"Audio Plugin: Stopping Audio");
						<player>5__2.Stop();
						if (type.ToUpper() == "AMBIENT")
						{
							if ((Object)(object)bundleAmbient != (Object)null)
							{
								bundleAmbient.Unload(true);
							}
							bundleAmbient = null;
						}
						else
						{
							if ((Object)(object)bundleMusic != (Object)null)
							{
								bundleMusic.Unload(true);
							}
							bundleMusic = null;
						}
						break;
					case 1:
						<>1__state = -3;
						if ((int)<www>5__6.result == 2)
						{
							LoggingPlugin.LogWarning("Audio Plugin: Failure To Request '" + audio + "'");
							LoggingPlugin.LogWarning(<www>5__6.error);
						}
						else
						{
							Debug.Log((object)("Audio Plugin: Loading Audio '" + audio + "'"));
							<player>5__2.clip = DownloadHandlerAudioClip.GetContent(<www>5__6);
							Debug.Log((object)("Audio Plugin: Playing Audio '" + audio + "'"));
							<player>5__2.Play();
						}
						<>m__Finally1();
						<www>5__6 = null;
						break;
					}
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<www>5__6 != null)
				{
					((IDisposable)<www>5__6).Dispose();
				}
			}

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

		private static AssetBundle bundleAmbient;

		private static AssetBundle bundleMusic;

		[IteratorStateMachine(typeof(<GetAudioAssets>d__2))]
		public static IEnumerator GetAudioAssets(ReadOnlyDictionary<string, AssetInfo> existingAssets, Func<Dictionary<string, AssetInfo>, string, IEnumerator> callback)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetAudioAssets>d__2(0)
			{
				existingAssets = existingAssets,
				callback = callback
			};
		}

		public static void AudioRequest(AssetInfo assetInfo)
		{
			//IL_02c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Expected O, but got Unknown
			//IL_031c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0322: Expected O, but got Unknown
			if (Utility.isBoardLoaded())
			{
				LoggingPlugin.LogInfo("Requesting Audio '" + assetInfo.prefab + "'");
				if (assetInfo.prefab.StartsWith(".VOL."))
				{
					if (assetInfo.prefab.EndsWith("Up"))
					{
						if (assetInfo.header.ToUpper() == "AMBIENT")
						{
							LoggingPlugin.LogInfo("Increasing Ambient Volume");
							if (_self.volumeAmbient.Value <= 0.9f)
							{
								ConfigEntry<float> volumeAmbient = _self.volumeAmbient;
								volumeAmbient.Value += 0.1f;
							}
						}
						else
						{
							LoggingPlugin.LogInfo("Increasing Music Volume");
							if (_self.volumeMusic.Value <= 0.9f)
							{
								ConfigEntry<float> volumeMusic = _self.volumeMusic;
								volumeMusic.Value += 0.1f;
							}
						}
					}
					else if (assetInfo.prefab.EndsWith("Down"))
					{
						if (assetInfo.header.ToUpper() == "AMBIENT")
						{
							LoggingPlugin.LogInfo("Decreasing Ambient Volume");
							if (_self.volumeAmbient.Value >= 0.1f)
							{
								ConfigEntry<float> volumeAmbient2 = _self.volumeAmbient;
								volumeAmbient2.Value -= 0.1f;
							}
						}
						else
						{
							LoggingPlugin.LogInfo("Decreasing Music Volume");
							if (_self.volumeMusic.Value >= 0.1f)
							{
								ConfigEntry<float> volumeMusic2 = _self.volumeMusic;
								volumeMusic2.Value -= 0.1f;
							}
						}
					}
					SystemMessage.DisplayInfoText("Ambient Volume: " + Math.Max(0, Math.Min(100, (int)(100.0 * ((double)_self.volumeAmbient.Value + 0.01)))) + "%\r\nMusic Volume: " + Math.Max(0, Math.Min(100, (int)(100.0 * ((double)_self.volumeMusic.Value + 0.01)))) + "%", 2.5f, 0f);
					((BaseUnityPlugin)CommonCustomsMenuPlugin._self).Config.Save();
					GameObject val = GameObject.Find("AudioSpeaker.Ambient");
					if ((Object)(object)val == (Object)null)
					{
						LoggingPlugin.LogInfo("Audio Plugin: Creating Audio Speaker");
						val = new GameObject();
						((Object)val).name = "AudioSpeaker.Ambient";
						val.AddComponent<AudioSource>();
					}
					AudioSource component = val.GetComponent<AudioSource>();
					component.volume = _self.volumeAmbient.Value;
					val = GameObject.Find("AudioSpeaker.Music");
					if ((Object)(object)val == (Object)null)
					{
						LoggingPlugin.LogInfo("Audio Plugin: Creating Audio Speaker");
						val = new GameObject();
						((Object)val).name = "AudioSpeaker.Music";
						val.AddComponent<AudioSource>();
					}
					component = val.GetComponent<AudioSource>();
					component.volume = _self.volumeMusic.Value;
				}
				else if (assetInfo.prefab.StartsWith(".LOOP."))
				{
					if (assetInfo.header.ToUpper() == "AMBIENT")
					{
						_self.loopAmbient.Value = !_self.loopAmbient.Value;
					}
					else
					{
						_self.loopMusic.Value = !_self.loopMusic.Value;
					}
					SystemMessage.DisplayInfoText("Ambient Loop: " + (_self.loopAmbient.Value ? "Yes" : "No") + "\r\nMusic Loop: " + (_self.loopMusic.Value ? "Yes" : "No"), 2.5f, 0f);
					((BaseUnityPlugin)CommonCustomsMenuPlugin._self).Config.Save();
				}
				else if (!SafeCalls.InvokeWithSuccessBool("LordAshes.AssetDataPlugin, AssetDataPlugin", "SetInfo", new object[4] { "SPEAKERS", "org.lordashes.plugins.audio.ccm.audio", assetInfo.prefab, false }, (object)null))
				{
					LoggingPlugin.LogInfo("Distribution Failed. Playing Audio '" + assetInfo.prefab + "' Locally");
					RemoteAudioRequest("Add", "SPEAKERS", "org.lordashes.plugins.audio.ccm.audio", "", assetInfo.prefab);
				}
			}
			else
			{
				SystemMessage.DisplayInfoText("Audio Can Only Be Played\r\nWhen A Board Is Loaded", 2.5f, 0f);
			}
		}

		[IteratorStateMachine(typeof(<PlayAudio>d__4))]
		public static IEnumerator PlayAudio(string audio, string type)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PlayAudio>d__4(0)
			{
				audio = audio,
				type = type
			};
		}

		private static string insertSpaces(string camelCase)
		{
			string text = camelCase.Substring(0, 1);
			for (int i = 1; i < camelCase.Length; i++)
			{
				if (camelCase.Substring(i - 1, 1) == camelCase.Substring(i - 1, 1).ToLower() && camelCase.Substring(i, 1) == camelCase.Substring(i - 1, 1).ToUpper() && camelCase.Substring(i, 1).ToLower() != camelCase.Substring(i - 1, 1).ToUpper())
				{
					text += " ";
				}
				text += camelCase.Substring(i, 1);
			}
			return text;
		}
	}

	public static class Utility
	{
		public static bool isBoardLoaded()
		{
			return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && !BoardSessionManager.IsLoading;
		}

		public static float ParseFloat(string value)
		{
			return float.Parse(value, CultureInfo.InvariantCulture);
		}

		public static GameObject FindInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject FindInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: true, ref results, ref done, partial: true);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllInHierarchy(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static GameObject[] FindAllInHierarchyViaPartialName(GameObject start, string seekName)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, seekName, null, single: false, ref results, ref done, partial: true);
			return results.ToArray();
		}

		public static GameObject FindWithComponentInHierarchy(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: true, ref results, ref done);
			return (results.Count > 0) ? results.ElementAt(0) : null;
		}

		public static GameObject[] FindAllWithComponentInHierarchy<T>(GameObject start, string seekType)
		{
			List<GameObject> results = new List<GameObject>();
			bool done = false;
			Traverse(start.transform, null, seekType, single: false, ref results, ref done);
			return results.ToArray();
		}

		public static void Traverse(Transform root, string seekName, string seekType, bool single, ref List<GameObject> results, ref bool done, bool partial = false)
		{
			try
			{
				if ((seekName == null || seekName == ((Object)((Component)root).gameObject).name || (partial && ((Object)((Component)root).gameObject).name.Contains(seekName))) && (seekType == null || (Object)(object)((Component)root).GetComponent(seekType) != (Object)null))
				{
					LoggingPlugin.LogTrace("Matched '" + ((Object)((Component)root).gameObject).name + "'");
					results.Add(((Component)root).gameObject);
					if (single)
					{
						done = true;
						return;
					}
				}
				foreach (Transform item in ExtensionMethods.Children(root))
				{
					if (!done)
					{
						Traverse(item, seekName, seekType, single, ref results, ref done, partial);
					}
				}
			}
			catch
			{
			}
		}

		public static object LookUp(in Dictionary<string, object> dictionary, string key)
		{
			foreach (KeyValuePair<string, object> item in dictionary)
			{
				if (item.Key.ToUpper() == key.ToUpper())
				{
					return item.Value;
				}
			}
			return null;
		}

		public static void PostOnMainPage(BaseUnityPlugin plugin)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			string text = "Lord Ashes" + ("Lord Ashes".ToUpper().EndsWith("S") ? "'" : "'s");
			ModdingUtils.Initialize(plugin, new ManualLogSource("Audio Plugin CCM"), text, false);
		}
	}

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

		private object <>2__current;

		public AudioPlugin <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			try
			{
				DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
				SystemMessage.DisplayInfoText("Audio Plugin CCM: Using '" + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + "' diagnostics.\r\nUse 'Info' for better performance", 10f, 0f);
				SystemMessage.DisplayInfoText("Audio Plugin CCM: Use 'Debug' or 'Trace' for\r\ntroubleshooting only.", 10f, 0f);
			}
			catch
			{
				goto IL_0072;
			}
			return false;
			IL_0072:
			<>2__current = (object)new WaitForSeconds(1f);
			<>1__state = 1;
			return true;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

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

	public const string Name = "Audio Plugin CCM";

	public const string Guid = "org.lordashes.plugins.audio.ccm";

	public const string Version = "1.0.6.0";

	public const string Author = "Lord Ashes";

	public static AudioPlugin _self;

	private string notification = null;

	private ConfigEntry<float> volumeAmbient;

	private ConfigEntry<float> volumeMusic;

	private ConfigEntry<bool> loopAmbient;

	private ConfigEntry<bool> loopMusic;

	private Rect registrationMessagePos = Rect.zero;

	private GUIStyle registrationMessageStyle = new GUIStyle();

	private void Awake()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0062: Invalid comparison between Unknown and I4
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0211: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Expected O, but got Unknown
		_self = this;
		LoggingPlugin.SetLogLevel(((BaseUnityPlugin)this).Config.Bind<DiagnosticLevel>("Settings", "Diagnostic Level", (DiagnosticLevel)3, (ConfigDescription)null).Value);
		string? assemblyQualifiedName = ((object)this).GetType().AssemblyQualifiedName;
		DiagnosticLevel logLevel = LoggingPlugin.GetLogLevel();
		Debug.Log((object)(assemblyQualifiedName + ": Active. (Diagnostic Mode = " + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + ")"));
		if ((int)LoggingPlugin.GetLogLevel() >= 4)
		{
			((MonoBehaviour)this).StartCoroutine(WarnAboutLogLevel());
		}
		volumeAmbient = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Ambient Volume (0-1)", 1f, (ConfigDescription)null);
		volumeMusic = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Music Volume (0-1)", 1f, (ConfigDescription)null);
		loopAmbient = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Loop Ambient", true, (ConfigDescription)null);
		loopMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "Loop Music", true, (ConfigDescription)null);
		string text = CommonCustomsMenuPlugin.RegisterProviderV2("AUDIO", "Ambient and music audio", Application.version.ToString(), (Func<ReadOnlyDictionary<string, AssetInfo>, Func<Dictionary<string, AssetInfo>, string, IEnumerator>, IEnumerator>)Provider.GetAudioAssets, (Action<AssetInfo>)delegate(AssetInfo selectedAsset)
		{
			Provider.AudioRequest(selectedAsset);
		});
		string[] array = text.Split(new char[1] { ',' });
		registrationMessagePos = new Rect((float)int.Parse(array[0]), (float)int.Parse(array[1]), (float)(Screen.width - int.Parse(array[0])), (float)(Screen.height - int.Parse(array[1])));
		registrationMessageStyle.fontSize = int.Parse(array[2]);
		registrationMessageStyle.fontStyle = (FontStyle)1;
		registrationMessageStyle.active.textColor = Color.white;
		registrationMessageStyle.normal.textColor = Color.white;
		SafeCalls.Invoke("LordAshes.AssetDataPlugin, AssetDataPlugin", "SubscribeViaReflection", new object[3]
		{
			"org.lordashes.plugins.audio.ccm.audio",
			((object)this).GetType().AssemblyQualifiedName,
			"RemoteAudioRequest"
		}, (object)null);
		Harmony val = new Harmony("org.lordashes.plugins.audio.ccm");
		val.PatchAll();
		Utility.PostOnMainPage((BaseUnityPlugin)(object)this);
	}

	private void OnGUI()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		if (notification != null)
		{
			GUI.Label(registrationMessagePos, notification, registrationMessageStyle);
		}
	}

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

	public static void RemoteAudioRequest(object action, object source, object key, object previous, object current)
	{
		LoggingPlugin.LogInfo("Remote Audio Request For '" + current?.ToString() + "'");
		try
		{
			AssetInfo val = (from info in CommonCustomsMenuPlugin.GetAssets()
				where info.prefab == current.ToString()
				select info).FirstOrDefault();
			LoggingPlugin.LogInfo("Remote Audio Request For URL '" + val.filename + "' From '" + val.header + "'");
			((MonoBehaviour)_self).StartCoroutine(Provider.PlayAudio(val.filename, val.header));
		}
		catch
		{
		}
	}
}