Decompiled source of ApparatusMeltdownMusic v1.0.0

BepInEx/plugins/ApparatusMeltdownMusic.dll

Decompiled 5 days ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Microsoft.CodeAnalysis;
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: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ApparatusMeltdownMusic")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ApparatusMeltdownMusic")]
[assembly: AssemblyTitle("ApparatusMeltdownMusic")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
[BepInPlugin("thatkidhector.apparatusmeltdownmusic", "ApparatusMeltdownMusic", "1.0.0")]
public class ApparatusMeltdownMusic : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <PlayRandomMusic>d__5 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public ApparatusMeltdownMusic <>4__this;

		private string <selectedMusic>5__1;

		private string <filePath>5__2;

		private UnityWebRequest <uwr>5__3;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if (num == -3 || (uint)(num - 2) <= 1u)
			{
				try
				{
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<selectedMusic>5__1 = null;
			<filePath>5__2 = null;
			<uwr>5__3 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Invalid comparison between Unknown and I4
			bool result;
			try
			{
				switch (<>1__state)
				{
				default:
					result = false;
					goto end_IL_0000;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSeconds(2f);
					<>1__state = 1;
					result = true;
					goto end_IL_0000;
				case 1:
					<>1__state = -1;
					if (<>4__this.musicFiles.Length == 0)
					{
						result = false;
					}
					else
					{
						<selectedMusic>5__1 = <>4__this.musicFiles[Random.Range(0, <>4__this.musicFiles.Length)];
						<filePath>5__2 = "file:///" + <selectedMusic>5__1.Replace("\\", "/");
						<uwr>5__3 = UnityWebRequestMultimedia.GetAudioClip(<filePath>5__2, (AudioType)14);
						<>1__state = -3;
						<>2__current = <uwr>5__3.SendWebRequest();
						<>1__state = 2;
						result = true;
					}
					goto end_IL_0000;
				case 2:
					<>1__state = -3;
					if ((int)<uwr>5__3.result == 1)
					{
						<>4__this.audioSource.clip = DownloadHandlerAudioClip.GetContent(<uwr>5__3);
						<>4__this.audioSource.Play();
						<>4__this.isPlaying = true;
						break;
					}
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)("No se pudo cargar el audio: " + <uwr>5__3.error));
					result = false;
					<>m__Finally1();
					goto end_IL_0000;
				case 3:
					<>1__state = -3;
					break;
				}
				if (<>4__this.audioSource.isPlaying)
				{
					<>2__current = null;
					<>1__state = 3;
					result = true;
				}
				else
				{
					<>4__this.isPlaying = false;
					<>m__Finally1();
					<uwr>5__3 = null;
					result = false;
				}
				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 (<uwr>5__3 != null)
			{
				((IDisposable)<uwr>5__3).Dispose();
			}
		}

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

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

		private object <>2__current;

		public ApparatusMeltdownMusic <>4__this;

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

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

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

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

		private bool MoveNext()
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if (<>4__this.CheckEndCondition() && <>4__this.isPlaying)
			{
				<>4__this.audioSource.Stop();
				<>4__this.isPlaying = false;
			}
			<>2__current = (object)new WaitForSeconds(0.5f);
			<>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();
		}
	}

	private AudioSource audioSource;

	private string[] musicFiles = new string[0];

	private bool isPlaying = false;

	private void Awake()
	{
		audioSource = ((Component)this).gameObject.AddComponent<AudioSource>();
		audioSource.loop = false;
		string path = Path.Combine(Paths.PluginPath, "ApparatusMeltdownMusic", "Music");
		if (Directory.Exists(path))
		{
			musicFiles = Directory.GetFiles(path, "*.ogg");
			if (musicFiles.Length == 0)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"No se encontraron archivos .ogg en la carpeta Music.");
			}
		}
		else
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"No se encontró la carpeta Music. Crea 'BepInEx/plugins/ApparatusMeltdownMusic/Music' y añade tus .ogg.");
		}
		((MonoBehaviour)this).StartCoroutine(WatchForApparatusPickup());
	}

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

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

	public void StopMusic()
	{
		if (audioSource.isPlaying)
		{
			audioSource.Stop();
			isPlaying = false;
		}
	}

	private bool CheckEndCondition()
	{
		return false;
	}
}