Decompiled source of KD Custom Music Pack v1.0.3

plugins/KDTeam.MixtapeFix.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[CompilerGenerated]
	[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 MixtapeFix
{
	[BepInPlugin("KDTeam.MixtapeFix", "MixtapeFix", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class MixtapeFixPlugin : BaseUnityPlugin
	{
		private const string TracksDirName = "SpookboxMixtape";

		private static MethodInfo? getTracksFromDir;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			MethodInfo methodInfo = AccessTools.Method("Spookbox.Mixtape:GetAllTracks", (Type[])null, (Type[])null);
			getTracksFromDir = AccessTools.Method("Spookbox.Mixtape:GetTracksFromDir", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method("Spookbox.Mixtape:Load", (Type[])null, (Type[])null);
			if (methodInfo == null || getTracksFromDir == null || methodInfo2 == null)
			{
				Logger.LogWarning((object)"Spöökbox not found, nothing to fix");
				return;
			}
			List<string> first = (List<string>)methodInfo.Invoke(null, null);
			new Harmony("KDTeam.MixtapeFix").Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(MixtapeFixPlugin), "AllTracks", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			List<string> second = (List<string>)methodInfo.Invoke(null, null);
			if (!first.SequenceEqual<string>(second, StringComparer.OrdinalIgnoreCase))
			{
				methodInfo2.Invoke(null, null);
			}
		}

		private static void AllTracks(ref List<string> __result)
		{
			IEnumerable<string> second = Directory.GetDirectories(Paths.PluginPath, "SpookboxMixtape", SearchOption.AllDirectories).SelectMany((string dir) => (IEnumerable<string>)getTracksFromDir.Invoke(null, new object[1] { dir }));
			List<string> list = new List<string>();
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			foreach (string item in __result.Concat(second))
			{
				if (hashSet.Add(Path.GetFileName(item)))
				{
					list.Add(item);
				}
			}
			if (list.Count != __result.Count)
			{
				Logger.LogInfo((object)$"Track list: {__result.Count} found by Spöökbox -> {list.Count} after adding nested folders and removing duplicates");
			}
			__result = list.OrderBy<string, string>(Path.GetFileName, StringComparer.InvariantCultureIgnoreCase).ToList();
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}