Decompiled source of BetterBoombox v1.1.2

BepInEx/plugins/BetterBoombox.dll

Decompiled a year ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("BetterBoombox")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Less 'human Music' more Kenney Rodgers")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2")]
[assembly: AssemblyProduct("BetterBoombox")]
[assembly: AssemblyTitle("BetterBoombox")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterBoombox
{
	public class AutoNextComponent : MonoBehaviour
	{
		private BoomboxItem _boombox;

		private void Awake()
		{
			_boombox = ((Component)this).GetComponent<BoomboxItem>();
			_boombox.boomboxAudio.loop = false;
		}

		private void Update()
		{
			if (_boombox.isPlayingMusic && !_boombox.boomboxAudio.isPlaying)
			{
				((GrabbableObject)_boombox).ItemActivate(true, true);
			}
		}
	}
	public class MusicUpdater : MonoBehaviour
	{
		private AudioClip[] _clips;

		private int _lastObjectCount = 0;

		private void Awake()
		{
			AssetBundle val = AssetBundle.LoadFromFile(Application.dataPath + "/../BepInEx/bundles/BetterBoombox/betterboombox");
			_clips = val.LoadAllAssets<AudioClip>();
		}

		private void Update()
		{
			BoomboxItem[] array = Object.FindObjectsByType<BoomboxItem>((FindObjectsSortMode)0);
			if (array.Length != _lastObjectCount)
			{
				OverrideMusic(array);
				_lastObjectCount = array.Length;
			}
		}

		private void OverrideMusic(BoomboxItem[] boomboxes)
		{
			AutoNextComponent autoNextComponent = default(AutoNextComponent);
			foreach (BoomboxItem val in boomboxes)
			{
				if (((GrabbableObject)val).itemProperties.requiresBattery)
				{
					val.musicAudios = _clips;
					((GrabbableObject)val).itemProperties.requiresBattery = false;
				}
				if (!((Component)val).TryGetComponent<AutoNextComponent>(ref autoNextComponent))
				{
					((Component)val).gameObject.AddComponent<AutoNextComponent>();
				}
			}
		}
	}
	[BepInPlugin("BetterBoombox", "BetterBoombox", "1.1.2")]
	public class Plugin : BaseUnityPlugin
	{
		private static bool Initialized;

		private void Start()
		{
			Initialize();
		}

		private void OnDestroy()
		{
			Initialize();
		}

		private void Initialize()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Expected O, but got Unknown
			if (!Initialized)
			{
				Initialized = true;
				GameObject val = new GameObject("MusicUpdater");
				Object.DontDestroyOnLoad((Object)(object)val);
				MusicUpdater musicUpdater = val.AddComponent<MusicUpdater>();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin BetterBoombox is loaded!");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterBoombox";

		public const string PLUGIN_NAME = "BetterBoombox";

		public const string PLUGIN_VERSION = "1.1.2";
	}
}