Decompiled source of PeakBugleMeowsynth v1.0.1

PeakBugleMeowsynth.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
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("PeakBugleMeowsynth")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PeakBugleMeowsynth")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9d4b12a9-ca97-4e94-9769-cd802d936ba6")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PeakBugleMeowsynth;

[BepInPlugin("murka124.PeakBugleMeowsynth", "PeakBugleMeowsynth", "1.0.1.0")]
[BepInProcess("PEAK.exe")]
public class PeakBugleMeowsynth : BaseUnityPlugin
{
	[HarmonyPatch(typeof(BugleSFX))]
	[HarmonyPatch("Start")]
	private static class BuglePatch
	{
		private static void Postfix(BugleSFX __instance)
		{
			if (!((Object)(object)customClips[0] == (Object)null))
			{
				for (int i = 0; i < 4 && i < __instance.bugle.Length && (Object)(object)customClips[i] != (Object)null && ((Object)__instance.bugle[i]).name == ((Object)customClips[i]).name; i++)
				{
					__instance.bugle[i] = customClips[i];
				}
			}
		}
	}

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

		private object <>2__current;

		public PeakBugleMeowsynth <>4__this;

		private Assembly <assembly>5__1;

		private string <resourceName>5__2;

		private Stream <stream>5__3;

		private byte[] <bundleData>5__4;

		private AssetBundleCreateRequest <bundleLoadRequest>5__5;

		private string[] <clipNames>5__6;

		private int <i>5__7;

		private AssetBundleRequest <clipRequest>5__8;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || (uint)(num - 1) <= 1u)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<assembly>5__1 = null;
			<resourceName>5__2 = null;
			<stream>5__3 = null;
			<bundleData>5__4 = null;
			<bundleLoadRequest>5__5 = null;
			<clipNames>5__6 = null;
			<clipRequest>5__8 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			bool result;
			try
			{
				switch (<>1__state)
				{
				default:
					result = false;
					goto end_IL_0000;
				case 0:
					<>1__state = -1;
					<assembly>5__1 = Assembly.GetExecutingAssembly();
					<resourceName>5__2 = "PeakBugleMeowsynth.meowsounds.bundle";
					<stream>5__3 = <assembly>5__1.GetManifestResourceStream(<resourceName>5__2);
					<>1__state = -3;
					if (<stream>5__3 == null)
					{
						((BaseUnityPlugin)<>4__this).Logger.LogError((object)("Embedded resource not found: " + <resourceName>5__2));
						result = false;
						break;
					}
					<bundleData>5__4 = new byte[<stream>5__3.Length];
					<stream>5__3.Read(<bundleData>5__4, 0, (int)<stream>5__3.Length);
					<bundleLoadRequest>5__5 = AssetBundle.LoadFromMemoryAsync(<bundleData>5__4);
					<>2__current = <bundleLoadRequest>5__5;
					<>1__state = 1;
					result = true;
					goto end_IL_0000;
				case 1:
					<>1__state = -3;
					customSoundBundle = <bundleLoadRequest>5__5.assetBundle;
					if ((Object)(object)customSoundBundle == (Object)null)
					{
						((BaseUnityPlugin)<>4__this).Logger.LogError((object)"Failed to load embedded AssetBundle!");
						result = false;
						break;
					}
					<clipNames>5__6 = new string[4] { "Au_Bugle2", "Au_Bugle1", "Au_Bugle3", "Au_Bugle4" };
					<i>5__7 = 0;
					goto IL_0264;
				case 2:
					{
						<>1__state = -3;
						ref AudioClip reference = ref customClips[<i>5__7];
						Object asset = <clipRequest>5__8.asset;
						reference = (AudioClip)(object)((asset is AudioClip) ? asset : null);
						if ((Object)(object)customClips[<i>5__7] != (Object)null)
						{
							((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)("Loaded embedded sound: " + <clipNames>5__6[<i>5__7]));
						}
						else
						{
							((BaseUnityPlugin)<>4__this).Logger.LogError((object)("Failed to load embedded sound: " + <clipNames>5__6[<i>5__7]));
						}
						<clipRequest>5__8 = null;
						<i>5__7++;
						goto IL_0264;
					}
					IL_0264:
					if (<i>5__7 < 4)
					{
						<clipRequest>5__8 = customSoundBundle.LoadAssetAsync<AudioClip>(<clipNames>5__6[<i>5__7]);
						<>2__current = <clipRequest>5__8;
						<>1__state = 2;
						result = true;
					}
					else
					{
						<bundleData>5__4 = null;
						<bundleLoadRequest>5__5 = null;
						<clipNames>5__6 = null;
						<>m__Finally1();
						<stream>5__3 = null;
						result = false;
					}
					goto end_IL_0000;
				}
				<>m__Finally1();
				end_IL_0000:;
			}
			catch
			{
				//try-fault
				((IDisposable)this).Dispose();
				throw;
			}
			return result;
		}

		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 (<stream>5__3 != null)
			{
				((IDisposable)<stream>5__3).Dispose();
			}
		}

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

	public const string pluginGuid = "murka124.PeakBugleMeowsynth";

	public const string pluginName = "PeakBugleMeowsynth";

	public const string pluginVersion = "1.0.1.0";

	private static ManualLogSource logger;

	private static AssetBundle customSoundBundle;

	private static readonly AudioClip[] customClips = (AudioClip[])(object)new AudioClip[4];

	private void Awake()
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"PeakBugleMeowsynth initialized!");
		LogEmbeddedResources();
		((MonoBehaviour)this).StartCoroutine(LoadEmbeddedSounds());
		Harmony val = new Harmony("murka124.PeakBugleMeowsynth");
		val.PatchAll();
	}

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

	private void LogEmbeddedResources()
	{
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
		string[] array = manifestResourceNames;
		foreach (string text in array)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("List of embedded resources: " + text));
		}
	}
}