Decompiled source of MusicChanger v1.0.0

music.dll

Decompiled 2 months 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 BepInEx.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;

[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("WormtownTestMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("My first plugin")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("WormtownTestMod")]
[assembly: AssemblyTitle("WormtownTestMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 WormtownTestMod
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "WormtownTestMod";

		public const string PLUGIN_NAME = "WormtownTestMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace CustomMusicMod
{
	[BepInPlugin("pseudopulse.CustomizableMusic", "Customizable Music", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public class VolUpdater : MonoBehaviour
		{
			public AudioSource player;

			public void Start()
			{
				player = ((Component)this).GetComponent<AudioSource>();
			}

			public void LateUpdate()
			{
				//IL_002a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: Invalid comparison between Unknown and I4
				if (Object.op_Implicit((Object)(object)GameManager.Singleton))
				{
					bool enabled = ((Behaviour)player).enabled;
					((Behaviour)player).enabled = (int)GameManager.Singleton.gameState == 1;
					if (((Behaviour)player).enabled != enabled)
					{
						if (((Behaviour)player).enabled)
						{
							player.Play();
							Debug.Log((object)"Playing music track.");
						}
						else
						{
							player.Stop();
							Debug.Log((object)"Stopping music track.");
						}
					}
				}
				else
				{
					((Behaviour)player).enabled = false;
				}
				if (Object.op_Implicit((Object)(object)AudioManager.Singleton))
				{
					player.volume = AudioManager.Singleton.musicVolume;
				}
			}
		}

		public AudioSource instance;

		public static ManualLogSource logger;

		public static ConfigEntry<string> content;

		public static ConfigEntry<AudioType> audioType;

		public static string scene;

		private void Awake()
		{
			content = ((BaseUnityPlugin)this).Config.Bind<string>("Configuration", "Source Link", "N/A", "A direct link to a valid audio file. A youtube link is NOT a valid audio file! Must end in a file extension.");
			audioType = ((BaseUnityPlugin)this).Config.Bind<AudioType>("Configuration", "Audio Type", (AudioType)14, "The file type of the audio.");
			content.SettingChanged += UpdateURL;
			logger = ((BaseUnityPlugin)this).Logger;
			SceneManager.activeSceneChanged += delegate
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_0029: Unknown result type (might be due to invalid IL or missing references)
				//IL_002f: Expected O, but got Unknown
				Scene activeScene = SceneManager.GetActiveScene();
				scene = ((Scene)(ref activeScene)).name;
				if (!Object.op_Implicit((Object)(object)instance))
				{
					GameObject val = new GameObject("Audio Player");
					AudioSource val2 = val.AddComponent<AudioSource>();
					val2.loop = true;
					((Component)val2).gameObject.AddComponent<VolUpdater>();
					instance = val2;
					((Behaviour)instance).enabled = false;
					UpdateURL(null, null);
					Object.DontDestroyOnLoad((Object)(object)val);
				}
			};
		}

		private void UpdateURL(object sender, EventArgs e)
		{
			if (Object.op_Implicit((Object)(object)instance))
			{
				GetNewURL();
			}
		}

		private void GetNewURL()
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			string value = content.Value;
			Debug.Log((object)("Loading: " + value));
			UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(value, audioType.Value);
			UnityWebRequestAsyncOperation val = audioClip.SendWebRequest();
			while (!((AsyncOperation)val).isDone)
			{
			}
			AudioClip val2 = DownloadHandlerAudioClip.GetContent(audioClip);
			Debug.Log((object)val2);
			instance.clip = val2;
			Debug.Log((object)"Clip Loaded");
		}
	}
}