Decompiled source of LCStudiopolisDiscoMod v1.0.2

LCStudiopolisDiscoMod.dll

Decompiled 6 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using HarmonyLib.Tools;
using Microsoft.CodeAnalysis;
using STSharedAudioLib;
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("LCStudiopolisDiscoMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Replace the Disco Ball music with Studiopolis Zone from Sonic Mania!")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("LCStudiopolisDiscoMod")]
[assembly: AssemblyTitle("LCStudiopolisDiscoMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 LCStudiopolisDiscoMod
{
	[BepInPlugin("LCStudiopolisDiscoMod", "LCStudiopolisDiscoMod", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public static AssetBundle StudiopolisAssetBundle;

		internal static ManualLogSource Logger;

		public static bool UseSongs = true;

		public static AudioClip Act1;

		public static AudioClip Act2;

		public static bool LCSimonTendoPlaylistsModCompatible = false;

		private void Awake()
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin LCStudiopolisDiscoMod is loaded!");
			Harmony val = new Harmony("LCStudiopolisDiscoMod");
			val.PatchAll();
			HarmonyFileLog.Enabled = false;
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			StudiopolisAssetBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "studiopolisassetbundle"));
			if ((Object)(object)StudiopolisAssetBundle == (Object)null)
			{
				Logger.LogError((object)"Failed to load Studiopolis AssetBundle");
				UseSongs = false;
				return;
			}
			Logger.LogInfo((object)"Loaded Studiopolis AssetBundle");
			Act1 = StudiopolisAssetBundle.LoadAsset<AudioClip>("Assets/Studiopolis Zone Act 1.ogg");
			Act2 = StudiopolisAssetBundle.LoadAsset<AudioClip>("Assets/Studiopolis Zone Act 2.ogg");
			LCSimonTendoPlaylistsModCompatible = CheckForPlugin("LCSimonTendoPlaylistsMod");
		}

		public static bool CheckForPlugin(string pluginName, bool printDebug = true)
		{
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (value.Metadata.Name == pluginName)
				{
					if (printDebug)
					{
						Logger.LogDebug((object)("Successfully found " + pluginName));
					}
					return true;
				}
			}
			if (printDebug)
			{
				Logger.LogDebug((object)("Failed to find " + pluginName));
			}
			return false;
		}

		public static void AddSharedAudioToDiscoBall(List<UnlockableItem> array)
		{
			foreach (UnlockableItem item in array)
			{
				if (item.unlockableName == "Disco Ball")
				{
					SharedAudioMethods.AudioClipAddNew(Act1, SharedAudioMethods.AudioListGetByName("LCSimonTendoPlaylistsMod", item.prefabObject, false, true), true, 100, false);
					SharedAudioMethods.AudioClipAddNew(Act2, SharedAudioMethods.AudioListGetByName("LCSimonTendoPlaylistsMod", item.prefabObject, false, true), true, 100, false);
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(StartOfRound), "Start")]
	public class NewStartOfRoundStart
	{
		[HarmonyPrefix]
		public static void StartPrefix(StartOfRound __instance)
		{
			if (Plugin.LCSimonTendoPlaylistsModCompatible && Plugin.UseSongs)
			{
				Plugin.AddSharedAudioToDiscoBall(__instance.unlockablesList.unlockables);
			}
		}
	}
	[HarmonyPatch(typeof(CozyLights), "SetAudio")]
	public class NewCozyLightsSetAudio
	{
		[HarmonyPrefix]
		public static void DiscoBallPrefix(CozyLights __instance, bool ___cozyLightsOn)
		{
			int num;
			if (!Plugin.LCSimonTendoPlaylistsModCompatible)
			{
				Transform parent = ((Component)__instance).gameObject.transform.parent;
				if (((parent != null) ? ((Object)parent).name : null) == "DiscoBallContainer(Clone)")
				{
					num = (Plugin.UseSongs ? 1 : 0);
					goto IL_0038;
				}
			}
			num = 0;
			goto IL_0038;
			IL_0038:
			if (((uint)num & (___cozyLightsOn ? 1u : 0u)) != 0 && !__instance.turnOnAudio.isPlaying)
			{
				if (((Object)__instance.turnOnAudio.clip).name != "Studiopolis Zone Act 1")
				{
					__instance.turnOnAudio.clip = Plugin.Act1;
				}
				else if (((Object)__instance.turnOnAudio.clip).name == "Studiopolis Zone Act 1")
				{
					__instance.turnOnAudio.clip = Plugin.Act2;
				}
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "LCStudiopolisDiscoMod";

		public const string PLUGIN_NAME = "LCStudiopolisDiscoMod";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}