Decompiled source of StereoLoveBoomBox v1.0.0

StereoLoveBoomBox.dll

Decompiled a day 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;

[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("StereoLoveBoomBox")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("StereoLoveBoomBox")]
[assembly: AssemblyTitle("StereoLoveBoomBox")]
[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("DgDarel.StereoLoveBoomBox", "StereoLoveBoomBox", "2.1.0")]
public class StereoLoveBoomBox : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <LoadAudio>d__3 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public StereoLoveBoomBox <>4__this;

		private string <folder>5__1;

		private string <path>5__2;

		private byte[] <bytes>5__3;

		private WAV <wav>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<folder>5__1 = null;
			<path>5__2 = null;
			<bytes>5__3 = null;
			<wav>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(1f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<folder>5__1 = Path.GetDirectoryName(((BaseUnityPlugin)<>4__this).Info.Location);
				<path>5__2 = Path.Combine(<folder>5__1, "StereoLoveBoomBox.wav");
				if (!File.Exists(<path>5__2))
				{
					((BaseUnityPlugin)<>4__this).Logger.LogError((object)"WAV not found");
					return false;
				}
				<bytes>5__3 = File.ReadAllBytes(<path>5__2);
				<wav>5__4 = new WAV(<bytes>5__3);
				<>4__this.customClip = AudioClip.Create("StereoLoveBoomBox", <wav>5__4.SampleCount, <wav>5__4.ChannelCount, <wav>5__4.Frequency, false);
				<>4__this.customClip.SetData(<wav>5__4.Samples, 0);
				((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"WAV loaded correctly");
				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 <MonitorAudio>d__4 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public StereoLoveBoomBox <>4__this;

		private AudioSource[] <all>5__1;

		private AudioSource[] <>s__2;

		private int <>s__3;

		private AudioSource <src>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<all>5__1 = null;
			<>s__2 = null;
			<src>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if ((Object)(object)<>4__this.customClip != (Object)null)
			{
				<all>5__1 = Object.FindObjectsOfType<AudioSource>(true);
				<>s__2 = <all>5__1;
				for (<>s__3 = 0; <>s__3 < <>s__2.Length; <>s__3++)
				{
					<src>5__4 = <>s__2[<>s__3];
					if (!((Object)(object)<src>5__4 == (Object)null) && !<>4__this.hooked.Contains(<src>5__4))
					{
						<>4__this.hooked.Add(<src>5__4);
						((MonoBehaviour)<>4__this).StartCoroutine(<>4__this.WatchSource(<src>5__4));
						<src>5__4 = null;
					}
				}
				<>s__2 = null;
				<all>5__1 = null;
			}
			<>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();
		}
	}

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

		private object <>2__current;

		public AudioSource src;

		public StereoLoveBoomBox <>4__this;

		private bool <replaced>5__1;

		private Transform <t>5__2;

		private bool <isBoombox>5__3;

		private string <n>5__4;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<t>5__2 = null;
			<n>5__4 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<replaced>5__1 = false;
				break;
			case 1:
				<>1__state = -1;
				break;
			}
			if ((Object)(object)src != (Object)null)
			{
				if (src.isPlaying)
				{
					if (!<replaced>5__1)
					{
						<replaced>5__1 = true;
						<t>5__2 = ((Component)src).transform;
						<isBoombox>5__3 = false;
						while ((Object)(object)<t>5__2 != (Object)null)
						{
							<n>5__4 = ((Object)<t>5__2).name.ToLower();
							if (<n>5__4.Contains("boombox") || <n>5__4.Contains("boom") || <n>5__4.Contains("stereo"))
							{
								<isBoombox>5__3 = true;
								break;
							}
							<t>5__2 = <t>5__2.parent;
							<n>5__4 = null;
						}
						if (<isBoombox>5__3)
						{
							src.Stop();
							src.clip = <>4__this.customClip;
							src.loop = true;
							src.spatialBlend = 1f;
							src.rolloffMode = (AudioRolloffMode)1;
							src.minDistance = 4f;
							src.maxDistance = 18f;
							src.volume = 1f;
							src.pitch = 1f;
							src.Play();
							((BaseUnityPlugin)<>4__this).Logger.LogInfo((object)"Custom boombox music playing");
						}
						<t>5__2 = null;
					}
				}
				else
				{
					<replaced>5__1 = false;
				}
				<>2__current = null;
				<>1__state = 1;
				return true;
			}
			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 AudioClip customClip;

	private readonly HashSet<AudioSource> hooked = new HashSet<AudioSource>();

	private void Start()
	{
		((MonoBehaviour)this).StartCoroutine(LoadAudio());
		((MonoBehaviour)this).StartCoroutine(MonitorAudio());
	}

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

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

	[IteratorStateMachine(typeof(<WatchSource>d__5))]
	private IEnumerator WatchSource(AudioSource src)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <WatchSource>d__5(0)
		{
			<>4__this = this,
			src = src
		};
	}
}
public class WAV
{
	public float[] Samples;

	public int ChannelCount;

	public int SampleCount;

	public int Frequency;

	public WAV(byte[] wav)
	{
		ChannelCount = wav[22];
		Frequency = wav[24] | (wav[25] << 8) | (wav[26] << 16) | (wav[27] << 24);
		int num = 12;
		while (wav[num] != 100 || wav[num + 1] != 97 || wav[num + 2] != 116 || wav[num + 3] != 97)
		{
			num += 4;
			int num2 = wav[num] | (wav[num + 1] << 8) | (wav[num + 2] << 16) | (wav[num + 3] << 24);
			num += 4 + num2;
		}
		num += 8;
		int num3 = 2;
		SampleCount = (wav.Length - num) / num3;
		Samples = new float[SampleCount];
		int num4 = 0;
		while (num < wav.Length)
		{
			Samples[num4] = BytesToFloat(wav[num], wav[num + 1]);
			num += 2;
			num4++;
		}
		SampleCount /= ChannelCount;
	}

	private float BytesToFloat(byte first, byte second)
	{
		short num = (short)((second << 8) | first);
		return (float)num / 32768f;
	}
}