Decompiled source of BoomBoxMoreCustomMusic v1.1.0

BoomBoxMoreCustomMusic.dll

Decompiled 2 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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("BoomBoxMoreCustomMusic")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BoomBoxMoreCustomMusic")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("874615ec-0ae6-41d0-9134-16ebf5d9cd01")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.bublensky.BoomBoxMoreCustom", "BoomBox Custom More Music", "1.0.1")]
public class BoomBoxMoreCustomMusic : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <LoadTracks>d__5 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public BoomBoxMoreCustomMusic <>4__this;

		private List<string> <files>5__1;

		private string[] <>s__2;

		private int <>s__3;

		private string <ext>5__4;

		private List<string>.Enumerator <>s__5;

		private string <file>5__6;

		private string <url>5__7;

		private AudioType <type>5__8;

		private UnityWebRequest <www>5__9;

		private AudioClip <clip>5__10;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			int num = <>1__state;
			if ((uint)(num - -4) <= 1u || num == 1)
			{
				try
				{
					if (num == -4 || num == 1)
					{
						try
						{
						}
						finally
						{
							<>m__Finally2();
						}
					}
				}
				finally
				{
					<>m__Finally1();
				}
			}
			<files>5__1 = null;
			<>s__2 = null;
			<ext>5__4 = null;
			<>s__5 = default(List<string>.Enumerator);
			<file>5__6 = null;
			<url>5__7 = null;
			<www>5__9 = null;
			<clip>5__10 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Invalid comparison between Unknown and I4
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_0192: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (!Directory.Exists(modPath))
					{
						return false;
					}
					<files>5__1 = new List<string>();
					<>s__2 = audioExtensions;
					for (<>s__3 = 0; <>s__3 < <>s__2.Length; <>s__3++)
					{
						<ext>5__4 = <>s__2[<>s__3];
						<files>5__1.AddRange(Directory.GetFiles(modPath, <ext>5__4));
						<ext>5__4 = null;
					}
					<>s__2 = null;
					<files>5__1.Sort();
					<>s__5 = <files>5__1.GetEnumerator();
					<>1__state = -3;
					break;
				case 1:
					<>1__state = -4;
					if ((int)<www>5__9.result == 1)
					{
						<clip>5__10 = DownloadHandlerAudioClip.GetContent(<www>5__9);
						((Object)<clip>5__10).name = Path.GetFileNameWithoutExtension(<file>5__6);
						CustomClips.Add(<clip>5__10);
						Debug.Log((object)("[BoomboxCustomMusic] Loaded: " + ((Object)<clip>5__10).name));
						<clip>5__10 = null;
					}
					else
					{
						Debug.Log((object)("[BoomboxCustomMusic] Failed to load: " + <file>5__6 + " (" + <www>5__9.error + ")"));
					}
					<>m__Finally2();
					<www>5__9 = null;
					<url>5__7 = null;
					<file>5__6 = null;
					break;
				}
				if (<>s__5.MoveNext())
				{
					<file>5__6 = <>s__5.Current;
					<url>5__7 = "file://" + Path.GetFullPath(<file>5__6);
					<type>5__8 = (AudioType)0;
					if (<file>5__6.EndsWith(".mp3"))
					{
						<type>5__8 = (AudioType)13;
					}
					else if (<file>5__6.EndsWith(".wav"))
					{
						<type>5__8 = (AudioType)20;
					}
					else if (<file>5__6.EndsWith(".ogg"))
					{
						<type>5__8 = (AudioType)14;
					}
					else if (<file>5__6.EndsWith(".aiff"))
					{
						<type>5__8 = (AudioType)2;
					}
					else if (<file>5__6.EndsWith(".flac"))
					{
						<type>5__8 = (AudioType)0;
					}
					<www>5__9 = UnityWebRequestMultimedia.GetAudioClip(<url>5__7, <type>5__8);
					<>1__state = -4;
					<>2__current = <www>5__9.SendWebRequest();
					<>1__state = 1;
					return true;
				}
				<>m__Finally1();
				<>s__5 = default(List<string>.Enumerator);
				Debug.Log((object)$"[BoomboxCustomMusic] Total tracks loaded: {CustomClips.Count}");
				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__5).Dispose();
		}

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

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

	public static List<AudioClip> CustomClips = new List<AudioClip>();

	public static int CurrentTrackIndex = 0;

	public static string modPath;

	private static readonly string[] audioExtensions = new string[5] { "*.mp3", "*.wav", "*.ogg", "*.aiff", "*.flac" };

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		modPath = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location);
		Harmony val = new Harmony("com.bublensky.BoomBoxCustom");
		((MonoBehaviour)this).StartCoroutine(LoadTracks());
		val.PatchAll();
	}

	[IteratorStateMachine(typeof(<LoadTracks>d__5))]
	private IEnumerator LoadTracks()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <LoadTracks>d__5(0)
		{
			<>4__this = this
		};
	}
}
[HarmonyPatch(typeof(ValuableBoombox), "Update")]
internal class BoomboxUpdatePatch
{
	private static void Postfix(ValuableBoombox __instance)
	{
		//IL_0065: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_026c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		if (BoomBoxMoreCustomMusic.CustomClips.Count == 0)
		{
			return;
		}
		PhysGrabObject value = Traverse.Create((object)__instance).Field("physGrabObject").GetValue<PhysGrabObject>();
		if (!((Object)(object)value != (Object)null) || !value.grabbed)
		{
			if ((Object)(object)__instance.speaker1 != (Object)null)
			{
				__instance.speaker1.localScale = Vector3.one;
			}
			if ((Object)(object)__instance.speaker2 != (Object)null)
			{
				__instance.speaker2.localScale = Vector3.one;
			}
			return;
		}
		AudioSource val = null;
		if (__instance.soundBoomboxMusic != null)
		{
			val = Traverse.Create((object)__instance.soundBoomboxMusic).Field("source").GetValue<AudioSource>();
		}
		if ((Object)(object)val == (Object)null)
		{
			val = ((Component)__instance).GetComponentInChildren<AudioSource>();
		}
		if (!((Object)(object)val == (Object)null))
		{
			if (!BoomBoxMoreCustomMusic.CustomClips.Contains(val.clip))
			{
				BoomBoxMoreCustomMusic.CurrentTrackIndex %= BoomBoxMoreCustomMusic.CustomClips.Count;
				val.clip = BoomBoxMoreCustomMusic.CustomClips[BoomBoxMoreCustomMusic.CurrentTrackIndex];
				val.time = 0f;
				Debug.Log((object)("[BoomboxCustomMusic] Replacing clip with: " + ((Object)val.clip).name));
			}
			if ((Object)(object)val.clip != (Object)null && val.isPlaying && val.time >= val.clip.length - 0.2f)
			{
				BoomBoxMoreCustomMusic.CurrentTrackIndex = (BoomBoxMoreCustomMusic.CurrentTrackIndex + 1) % BoomBoxMoreCustomMusic.CustomClips.Count;
				val.clip = BoomBoxMoreCustomMusic.CustomClips[BoomBoxMoreCustomMusic.CurrentTrackIndex];
				val.time = 0f;
				val.Play();
				Debug.Log((object)("[BoomboxCustomMusic] Next track: " + ((Object)val.clip).name));
			}
			if (!val.isPlaying && (Object)(object)val.clip != (Object)null)
			{
				val.Play();
				Debug.Log((object)"[BoomboxCustomMusic] Audio restarted");
			}
			val.volume = 1f;
			val.mute = false;
			float num = 1f + Mathf.Sin(Time.time * 60f) * 0.012f;
			if ((Object)(object)__instance.speaker1 != (Object)null)
			{
				__instance.speaker1.localScale = new Vector3(num, num, num);
			}
			if ((Object)(object)__instance.speaker2 != (Object)null)
			{
				__instance.speaker2.localScale = new Vector3(num, num, num);
			}
		}
	}
}