Decompiled source of L4D Meltdown And Escape Music Pack v1.4.2

LethalCompanyL4D.dll

Decompiled 4 days ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using LethalConfig.ConfigItems.Options;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.Networking;

[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("LethalCompanyL4D")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LethalCompanyL4D")]
[assembly: AssemblyTitle("LethalCompanyL4D")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
		}
	}
}
namespace LethalCompanyL4D
{
	[BepInPlugin("Krysa.L4D_Meltdown_And_Escape_Music_Pack", "L4D Meltdown and Escape Music Pack", "1.4.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(HUDManager), "Update")]
		public class SafetyCheckPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				//IL_008a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0091: Expected O, but got Unknown
				if (MeltdownActive)
				{
					return;
				}
				GameObject val = GameObject.Find("MeltdownHandler") ?? GameObject.Find("FacilityMeltdownLogic") ?? GameObject.Find("MeltdownHandler(Clone)");
				if (!((Object)(object)val != (Object)null))
				{
					return;
				}
				AudioClip selectedClip = GetSelectedClip();
				if (!((Object)(object)selectedClip == (Object)null))
				{
					MeltdownActive = true;
					Log.LogInfo((object)"Disaster object mapping verified! Starting global sound pipeline.");
					if ((Object)(object)customAudioSource == (Object)null)
					{
						GameObject val2 = new GameObject("L4DCustomAudio");
						customAudioSource = val2.AddComponent<AudioSource>();
						Object.DontDestroyOnLoad((Object)(object)val2);
					}
					customAudioSource.Stop();
					customAudioSource.clip = selectedClip;
					customAudioSource.volume = MusicVolume.Value;
					customAudioSource.loop = LoopMusic.Value;
					customAudioSource.spatialBlend = 0f;
					customAudioSource.Play();
					Log.LogInfo((object)"Left 4 Dead music successfully started!");
				}
			}
		}

		[HarmonyPatch(typeof(HUDManager), "FillEndGameStats")]
		public class ScoreScreenPatch
		{
			[HarmonyPostfix]
			private static void Postfix()
			{
				MeltdownActive = false;
				if ((Object)(object)customAudioSource != (Object)null)
				{
					customAudioSource.Stop();
					Log.LogInfo((object)"Custom Left 4 Dead channels silenced.");
				}
			}
		}

		private const string ModGUID = "Krysa.L4D_Meltdown_And_Escape_Music_Pack";

		private const string ModName = "L4D Meltdown and Escape Music Pack";

		private const string ModVersion = "1.4.2";

		public static ManualLogSource Log;

		private static AudioClip l4d1Music;

		private static AudioClip l4d2Music;

		public static ConfigEntry<float> MusicVolume;

		public static ConfigEntry<bool> LoopMusic;

		public static ConfigEntry<string> GameVersion;

		public static bool MeltdownActive;

		private static AudioSource customAudioSource;

		private void Awake()
		{
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Log.LogInfo((object)"==================================================");
			Log.LogInfo((object)"L4D Meltdown and Escape Music Pack v1.4.2 is bootstrapping...");
			Log.LogInfo((object)"==================================================");
			try
			{
				MusicVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Volume", 0.8f, "Volume of the music tracks (0.0 - 1.0)");
				LoopMusic = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Loop Meltdown Music", true, "Should the music loop during the escape?");
				GameVersion = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Meltdown Version", "Left 4 Dead 2", new ConfigDescription("Select version.", (AcceptableValueBase)(object)new AcceptableValueList<string>(new string[2] { "Left 4 Dead 1", "Left 4 Dead 2" }), Array.Empty<object>()));
				Log.LogInfo((object)"Configuration entries bound successfully.");
			}
			catch (Exception ex)
			{
				Log.LogError((object)("CRITICAL: Failed to bind configuration items: " + ex.Message));
			}
			if (AppDomain.CurrentDomain.ToString().Contains("LethalConfig"))
			{
				SetupLethalConfig();
			}
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			Log.LogInfo((object)("Target folder: " + directoryName));
			l4d1Music = LoadWavDirectly(directoryName, "skin_on_our_teeth_l4d1.wav", "L4D1 Meltdown Theme");
			l4d2Music = LoadWavDirectly(directoryName, "skin_on_our_teeth_l4d2.wav", "L4D2 Meltdown Theme");
			Harmony val = new Harmony("Krysa.L4D_Meltdown_And_Escape_Music_Pack");
			val.PatchAll();
			Log.LogInfo((object)"All patches injected successfully.");
		}

		private void SetupLethalConfig()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Expected O, but got Unknown
			//IL_0028: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			ConfigEntry<float> musicVolume = MusicVolume;
			FloatSliderOptions val = new FloatSliderOptions();
			((BaseRangeOptions<float>)val).Min = 0f;
			((BaseRangeOptions<float>)val).Max = 1f;
			FloatSliderConfigItem val2 = new FloatSliderConfigItem(musicVolume, val);
			BoolCheckBoxConfigItem val3 = new BoolCheckBoxConfigItem(LoopMusic, new BoolCheckBoxOptions());
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val2);
			LethalConfigManager.AddConfigItem((BaseConfigItem)(object)val3);
		}

		private AudioClip LoadWavDirectly(string folder, string filename, string displayName)
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Invalid comparison between Unknown and I4
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Invalid comparison between Unknown and I4
			string text = Path.Combine(folder, filename);
			if (!File.Exists(text))
			{
				Log.LogError((object)("File missing: " + filename));
				return null;
			}
			try
			{
				string text2 = "file://" + text.Replace("\\", "/");
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text2, (AudioType)20);
				try
				{
					((DownloadHandlerAudioClip)audioClip.downloadHandler).streamAudio = true;
					audioClip.SendWebRequest();
					while (!audioClip.isDone)
					{
					}
					if ((int)audioClip.result == 1)
					{
						AudioClip content = DownloadHandlerAudioClip.GetContent(audioClip);
						if ((Object)(object)content != (Object)null && (int)content.loadState == 2)
						{
							Log.LogInfo((object)("SUCCESS: " + displayName + " loaded."));
							return content;
						}
					}
				}
				finally
				{
					((IDisposable)audioClip)?.Dispose();
				}
			}
			catch (Exception ex)
			{
				Log.LogError((object)("Error loading " + filename + ": " + ex.Message));
			}
			return null;
		}

		public static AudioClip GetSelectedClip()
		{
			if (GameVersion.Value == "Left 4 Dead 1" && (Object)(object)l4d1Music != (Object)null)
			{
				return l4d1Music;
			}
			return l4d2Music;
		}
	}
}