Decompiled source of CopyrightFreeBoombox v1.0.1

CopyrightFreeBoombox.dll

Decompiled 5 months ago
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("CopyrightFreeBoombox")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CopyrightFreeBoombox")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d9e8e1a6-78c8-4062-9dc1-7f9424408f06")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace CopyrightFreeBoombox
{
	[BepInPlugin("stormytuna.CopyrightFreeBoombox", "CopyrightFreeBoombox", "1.0.0")]
	public class CopyrightFreeBoomboxBase : BaseUnityPlugin
	{
		public const string ModGUID = "stormytuna.CopyrightFreeBoombox";

		public const string ModName = "CopyrightFreeBoombox";

		public const string ModVersion = "1.0.0";

		public static ManualLogSource Log = Logger.CreateLogSource("stormytuna.CopyrightFreeBoombox");

		public static CopyrightFreeBoomboxBase Instance;

		private readonly Harmony harmony = new Harmony("stormytuna.CopyrightFreeBoombox");

		private void Awake()
		{
			if (Instance == null)
			{
				Instance = this;
			}
			Log.LogInfo((object)"Copyright Free Boombox has awoken!");
			harmony.PatchAll();
		}
	}
}
namespace CopyrightFreeBoombox.Patches
{
	[HarmonyPatch(typeof(BoomboxItem))]
	public class BoomboxItemPatch
	{
		private static bool IsNotCopyrighted(AudioClip audioClip)
		{
			return ((Object)audioClip).name switch
			{
				"BoomboxMusic1" => true, 
				"BoomboxMusic2" => true, 
				"BoomboxMusic3" => true, 
				"BoomboxMusic4" => true, 
				_ => false, 
			};
		}

		[HarmonyPrefix]
		[HarmonyPatch("StartMusic")]
		public static void RemoveCopyrightedMusic(ref AudioClip[] ___musicAudios)
		{
			if (___musicAudios == null)
			{
				CopyrightFreeBoomboxBase.Log.LogError((object)"Failed to patch out copyrighted music!!");
				return;
			}
			CopyrightFreeBoomboxBase.Log.LogInfo((object)"BEFORE");
			AudioClip[] array = ___musicAudios;
			foreach (AudioClip val in array)
			{
				CopyrightFreeBoomboxBase.Log.LogInfo((object)((Object)val).name);
			}
			___musicAudios = ___musicAudios.Where(IsNotCopyrighted).ToArray();
			CopyrightFreeBoomboxBase.Log.LogInfo((object)"AFTER");
			AudioClip[] array2 = ___musicAudios;
			foreach (AudioClip val2 in array2)
			{
				CopyrightFreeBoomboxBase.Log.LogInfo((object)((Object)val2).name);
			}
		}
	}
}