Decompiled source of V1LevelSpeak v1.3.2

UK_V1LevelSpeak.dll

Decompiled 5 days ago
using System;
using System.Collections;
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;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ccobaltdev.v1levelspeak")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.3.2.0")]
[assembly: AssemblyInformationalVersion("1.3.2+7cfd378c28c96c2765a44efa6a4dd91714e44ad7")]
[assembly: AssemblyProduct("V1LevelSpeak")]
[assembly: AssemblyTitle("ccobaltdev.v1levelspeak")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 V1LevelSpeak
{
	[BepInPlugin("ccobaltdev.v1levelspeak", "V1LevelSpeak", "1.3.2")]
	public class Main : BaseUnityPlugin
	{
		[HarmonyPatch]
		public static class LevelNamePopup_Patch
		{
			private static readonly FieldRef<LevelNamePopup, string> layerStringField = AccessTools.FieldRefAccess<LevelNamePopup, string>("layerString");

			[HarmonyPrefix]
			[HarmonyPatch(typeof(LevelNamePopup), "ShowLayerText")]
			public static void patch_ShowLayerText(LevelNamePopup __instance)
			{
				string levelID = GetLevelID(layerStringField.Invoke(__instance));
				if (levelID != null)
				{
					string key = levelID + "-1";
					if (clips.ContainsKey(key))
					{
						AudioSource val = ((Component)Camera.main).gameObject.AddComponent<AudioSource>();
						val.clip = clips[key];
						val.volume = 1f;
						val.Play();
						Object.Destroy((Object)(object)val, 10f);
						((MonoBehaviour)__instance).StartCoroutine(RunInABit(levelID, val.clip.length));
					}
				}
			}

			private static IEnumerator RunInABit(string baseKey, float delay)
			{
				yield return (object)new WaitForSeconds(delay);
				string key = baseKey + "-2";
				if (clips.ContainsKey(key))
				{
					AudioSource obj = ((Component)Camera.main).gameObject.AddComponent<AudioSource>();
					obj.clip = clips[key];
					obj.volume = 1f;
					obj.Play();
					Object.Destroy((Object)(object)obj, 10f);
				}
			}
		}

		private static ManualLogSource log;

		private static AssetBundle assets;

		private static Dictionary<string, AudioClip> clips = new Dictionary<string, AudioClip>();

		private static readonly Dictionary<string, string> layerToNumber = new Dictionary<string, string>
		{
			{ "PRELUDE", "0" },
			{ "LIMBO", "1" },
			{ "LUST", "2" },
			{ "GLUTTONY", "3" },
			{ "GREED", "4" },
			{ "WRATH", "5" },
			{ "HERESY", "6" },
			{ "VIOLENCE", "7" },
			{ "FRAUD", "8" },
			{ "TREACHERY", "9" }
		};

		private static readonly Dictionary<string, string> levelToNumber = new Dictionary<string, string>
		{
			{ "FIRST", "1" },
			{ "SECOND", "2" },
			{ "THIRD", "3" },
			{ "FOURTH", "4" },
			{ "FIFTH", "5" },
			{ "CLIMAX", "4" },
			{ "ENCORE", "E" },
			{ "ACT I CRESCENDO", "1" },
			{ "ACT I CLIMAX", "2" },
			{ "ACT II CRESCENDO", "1" },
			{ "ACT II CLIMAX", "2" },
			{ "ACT III CRESCENDO", "1" },
			{ "ACT III CLIMAX", "2" }
		};

		private void Awake()
		{
			Harmony.CreateAndPatchAll(typeof(LevelNamePopup_Patch), (string)null);
			assets = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "leveltitles"));
			AudioClip[] array = assets.LoadAllAssets<AudioClip>();
			foreach (AudioClip val in array)
			{
				clips.Add(((Object)val).name, val);
			}
			log = ((BaseUnityPlugin)this).Logger;
		}

		public static string GetLevelID(string layerName)
		{
			string[] array = layerName.Split(' ');
			string key = string.Join(" ", array.Skip(2));
			if (!levelToNumber.ContainsKey(key))
			{
				return null;
			}
			string text = levelToNumber[key];
			if (array[0] == "PRELUDE" && array[2] == "CLIMAX")
			{
				text = "5";
			}
			if (!layerToNumber.ContainsKey(array[0]))
			{
				return null;
			}
			return layerToNumber[array[0]] + "-" + text;
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "ccobaltdev.v1levelspeak";

		public const string PLUGIN_NAME = "V1LevelSpeak";

		public const string PLUGIN_VERSION = "1.3.2";
	}
}