Decompiled source of CoreAudioProxy CCM v1.0.0

CoreAudioProxy_CCM.dll

Decompiled 2 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 Newtonsoft.Json;
using UnityEngine;

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

[BepInPlugin("org.lordashes.plugins.coreaudioproxy.ccm", "Core Audio Proxy Plugin", "1.0.0.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 CoreAssetsProxyPlugin : BaseUnityPlugin
{
	public static class Provider
	{
		public class Index
		{
			public string Name { get; set; }

			public List<MusicItem> Music { get; set; }
		}

		public class MusicItem
		{
			public string Id { get; set; }

			public string Name { get; set; }

			public bool IsDeprecated { get; set; }

			public string GroupTag { get; set; }

			public string[] Tags { get; set; }

			public AssetType Asset { get; set; }
		}

		public class AssetType
		{
			public string BundleId { get; set; }

			public string AssetName { get; set; }
		}

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

			private object <>2__current;

			public string talespireFolder;

			private string <cacheFolder>5__1;

			private Texture2D <portrait>5__2;

			private byte[] <pngData>5__3;

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

			private string[] <>s__5;

			private int <>s__6;

			private string <folderPath>5__7;

			private string <folder>5__8;

			private string <json>5__9;

			private Index <index>5__10;

			private List<MusicItem>.Enumerator <>s__11;

			private MusicItem <item>5__12;

			private AssetInfo <assetInfo>5__13;

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

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

			[DebuggerHidden]
			public <ExtractAudio>d__3(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();
					}
				}
				<cacheFolder>5__1 = null;
				<portrait>5__2 = null;
				<pngData>5__3 = null;
				<assets>5__4 = null;
				<>s__5 = null;
				<folderPath>5__7 = null;
				<folder>5__8 = null;
				<json>5__9 = null;
				<index>5__10 = null;
				<>s__11 = default(List<MusicItem>.Enumerator);
				<item>5__12 = null;
				<assetInfo>5__13 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ce: Expected O, but got Unknown
				//IL_0281: Unknown result type (might be due to invalid IL or missing references)
				//IL_028b: Expected O, but got Unknown
				try
				{
					int num = <>1__state;
					if (num != 0)
					{
						if (num != 1)
						{
							return false;
						}
						<>1__state = -3;
						if (!_existingAssets.ContainsKey(<item>5__12.Asset.AssetName))
						{
							AssetInfo val = new AssetInfo();
							val.provider = "AUDIO";
							val.filename = ("AssetBundle:" + <folderPath>5__7 + "/Assets/" + <item>5__12.Asset.BundleId + ":" + <item>5__12.Asset.AssetName).Replace("\\", "/");
							val.pack = <item>5__12.Asset.BundleId;
							val.prefab = <item>5__12.Asset.AssetName;
							val.name = <item>5__12.Name;
							val.kind = "Audio";
							val.category = "Audio";
							val.header = ((<item>5__12.Asset.BundleId.IndexOf("_amb_") > -1) ? "Ambient" : "Music");
							val.groupName = "Core Talespire";
							val.description = ((<item>5__12.Asset.BundleId.IndexOf("_amb_") > -1) ? "Ambient Audio" : "Music") + " from Core Talespire";
							val.author = "Bouncy Rock";
							val.comment = "Core Talespire audio";
							val.hasAnimations = false;
							val.hasAudio = true;
							val.hasBlendshapes = false;
							val.tags = "Audio,Core";
							<assetInfo>5__13 = val;
							<assets>5__4.Add(<assetInfo>5__13.prefab, <assetInfo>5__13);
							File.WriteAllBytes(<cacheFolder>5__1 + "/Portrait." + <assetInfo>5__13.prefab + ".png", <pngData>5__3, (CacheType)999);
							<assetInfo>5__13 = null;
						}
						<item>5__12 = null;
						goto IL_04c1;
					}
					<>1__state = -1;
					<cacheFolder>5__1 = Paths.PluginPath + "/.cache/org.lordashes.plugins.commoncustomsmenu/";
					<portrait>5__2 = Image.LoadTexture("org.lordashes.plugins.coreaudioproxy.ccm.Default.png", (CacheType)999);
					<pngData>5__3 = ImageConversion.EncodeToPNG(<portrait>5__2);
					<assets>5__4 = new Dictionary<string, AssetInfo>();
					talespireFolder += "/Taleweaver";
					<>s__5 = Directory.GetDirectories(talespireFolder);
					<>s__6 = 0;
					goto IL_0536;
					IL_04c1:
					if (<>s__11.MoveNext())
					{
						<item>5__12 = <>s__11.Current;
						LoggingPlugin.LogTrace(<item>5__12.Name + " (" + ((<item>5__12.Asset.BundleId.IndexOf("_amb_") > -1) ? "Ambient" : "Music") + ") from " + <index>5__10.Name);
						_self.notification = "Registering... [Provider: AUDIO via AUDIOPROXY, Pack: " + <index>5__10.Name + ", Audio: " + <item>5__12.Name + "]";
						<>2__current = (object)new WaitForEndOfFrame();
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>s__11 = default(List<MusicItem>.Enumerator);
					LoggingPlugin.LogTrace(<index>5__10.Name + " from " + <folder>5__8 + ": Processing Completed");
					<json>5__9 = null;
					<index>5__10 = null;
					goto IL_0519;
					IL_0519:
					<folder>5__8 = null;
					<folderPath>5__7 = null;
					<>s__6++;
					goto IL_0536;
					IL_0536:
					if (<>s__6 < <>s__5.Length)
					{
						<folderPath>5__7 = <>s__5[<>s__6];
						<folder>5__8 = Path.GetFileName(<folderPath>5__7);
						if (<folder>5__8.Length > 23 && <folder>5__8.Substring(8, 1) == "-" && <folder>5__8.Substring(13, 1) == "-" && <folder>5__8.Substring(18, 1) == "-" && <folder>5__8.Substring(23, 1) == "-")
						{
							<json>5__9 = File.ReadAllText(<folderPath>5__7 + "/index.json");
							<index>5__10 = JsonConvert.DeserializeObject<Index>(<json>5__9);
							LoggingPlugin.LogDebug(<index>5__10.Name + " from " + <folder>5__8 + ": Processing");
							<>s__11 = <index>5__10.Music.GetEnumerator();
							<>1__state = -3;
							goto IL_04c1;
						}
						goto IL_0519;
					}
					<>s__5 = null;
					_self.notification = null;
					LoggingPlugin.LogDebug("Sending CCM Registration For " + <assets>5__4.Count + " New Core Audio Assets");
					((MonoBehaviour)_self).StartCoroutine(_callback(<assets>5__4, "CoreAudioProxy"));
					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;
				((IDisposable)<>s__11).Dispose();
			}

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

		[CompilerGenerated]
		private sealed class <GetNewAssets>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;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					_existingAssets = existingAssets;
					_callback = callback;
					<>2__current = ((MonoBehaviour)_self).StartCoroutine(ExtractAudio(Paths.GameRootPath));
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					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();
			}
		}

		private static ReadOnlyDictionary<string, AssetInfo> _existingAssets;

		private static Func<Dictionary<string, AssetInfo>, string, IEnumerator> _callback;

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

		[IteratorStateMachine(typeof(<ExtractAudio>d__3))]
		private static IEnumerator ExtractAudio(string talespireFolder)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <ExtractAudio>d__3(0)
			{
				talespireFolder = talespireFolder
			};
		}
	}

	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("Core Audio Proxy Plugin"), text, false);
		}
	}

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

		private object <>2__current;

		public CoreAssetsProxyPlugin <>4__this;

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

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

		[DebuggerHidden]
		public <WarnAboutLogLevel>d__12(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("Core Audio Proxy Plugin: Using '" + ((object)(DiagnosticLevel)(ref logLevel)).ToString() + "' diagnostics.\r\nUse 'Info' for better performance", 10f, 0f);
				SystemMessage.DisplayInfoText("Core Audio Proxy Plugin: 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 = "Core Audio Proxy Plugin";

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

	public const string Version = "1.0.0.0";

	public const string Author = "Lord Ashes";

	public static CoreAssetsProxyPlugin _self;

	private string notification = null;

	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_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0104: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_015b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: 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());
		}
		string text = CommonCustomsMenuPlugin.RegisterProviderV2("AUDIOPROXY", "Core Talespire minis", "1.0.0.0", (Func<ReadOnlyDictionary<string, AssetInfo>, Func<Dictionary<string, AssetInfo>, string, IEnumerator>, IEnumerator>)Provider.GetNewAssets, (Action<AssetInfo>)delegate
		{
			throw new Exception("AUDIOPROXY Is Not Intended To Process Selection.");
		});
		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;
		Harmony val = new Harmony("org.lordashes.plugins.coreaudioproxy.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__12))]
	private IEnumerator WarnAboutLogLevel()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WarnAboutLogLevel>d__12(0)
		{
			<>4__this = this
		};
	}
}