Decompiled source of CharacterAnnouncer v2.1.0

plugins/CharacterAnnouncer.dll

Decompiled a year 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;
using UnityEngine;
using UnityEngine.Audio;
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(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("CharacterAnnouncer")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Adds a SmashBros-like announcer to the character select screen")]
[assembly: AssemblyFileVersion("2.1.0.0")]
[assembly: AssemblyInformationalVersion("2.1.0")]
[assembly: AssemblyProduct("CharacterAnnouncer")]
[assembly: AssemblyTitle("CharacterAnnouncer")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("2.1.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.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]
	[Microsoft.CodeAnalysis.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]
	[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 CharacterAnnouncer
{
	[BepInPlugin("com.guardie.characterannouncer", "CharacterAnnouncer", "2.1.0")]
	[HarmonyPatch]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(CharSelectController_new))]
		private class LoadSounds
		{
			[HarmonyPatch("Awake")]
			private static void Postfix(CharSelectController_new __instance)
			{
				Log.LogInfo((object)"Scene loaded. Getting AudioClips...");
				GetClips("Characters", char_sounds);
				GetClips("Colors", tromb_sounds);
				GetClips("Soundfonts", sfx_sounds);
				GetClips("User Interface", ui_sounds);
				countdown = 3;
			}
		}

		[HarmonyPatch(typeof(CharSelectController_new))]
		private class PatchCharacters
		{
			[HarmonyPatch("chooseChar")]
			private static void Postfix(int puppet_choice, CharSelectController_new __instance)
			{
				puppet_choice = Mathf.Min(puppet_choice, char_sounds.Count() - 1);
				puppet_choice = Mathf.Max(puppet_choice, 0);
				Log.LogDebug((object)("Selected character: " + char_sounds[puppet_choice]));
				PlaySound(char_sounds[puppet_choice], __instance);
			}
		}

		[HarmonyPatch(typeof(CharSelectController_new))]
		private class PatchTrombones
		{
			[HarmonyPatch("chooseTromb")]
			private static void Postfix(int tromb_choice, CharSelectController_new __instance)
			{
				tromb_choice = Mathf.Min(tromb_choice, tromb_sounds.Count() - 1);
				tromb_choice = Mathf.Max(tromb_choice, 0);
				Log.LogDebug((object)("Selected Color: " + tromb_sounds[tromb_choice]));
				PlaySound(tromb_sounds[tromb_choice], __instance);
			}
		}

		[HarmonyPatch(typeof(CharSelectController_new))]
		private class PatchSoundpacks
		{
			[HarmonyPatch("chooseSoundPack")]
			private static void Postfix(int sfx_choice, CharSelectController_new __instance)
			{
				sfx_choice = Mathf.Min(sfx_choice, sfx_sounds.Count() - 1);
				sfx_choice = Mathf.Max(sfx_choice, 0);
				Log.LogDebug((object)("Selected Soundfont: " + sfx_sounds[sfx_choice]));
				PlaySound(sfx_sounds[sfx_choice], __instance);
			}
		}

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

		private static AudioSource newsource = null;

		private static List<string> char_sounds = new List<string> { "appaloosa", "beezerly", "kaizyle", "trixiebell", "meldor", "jermajesty", "hornlord", "soda", "polygon_char", "servant" };

		private static List<string> tromb_sounds = new List<string> { "brass", "silver", "red", "blue", "green", "pink", "polygon", "champ" };

		private static List<string> sfx_sounds = new List<string> { "trombone", "bass_trombone", "muted", "8-bit", "in_the_club", "gassy" };

		private static List<string> ui_sounds = new List<string> { "choose" };

		private static int countdown = 3;

		private static string folderPath;

		internal static ManualLogSource Log;

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			folderPath = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "AnnouncerLines");
			Log = ((BaseUnityPlugin)this).Logger;
			new Harmony("com.guardie.characterannouncer").PatchAll();
		}

		private static void GetClips(string subfolder, List<string> files)
		{
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			foreach (string file in files)
			{
				string text = Path.Combine(folderPath, subfolder, file + ".ogg");
				string text2 = "";
				UnityWebRequest audioClip = UnityWebRequestMultimedia.GetAudioClip(text, (AudioType)14);
				try
				{
					List<string> list = text.Split(new char[1] { Path.DirectorySeparatorChar }).ToList();
					string text3 = "";
					int num = 0;
					foreach (string item in list)
					{
						if (item == "plugins" && text3 == "BepInEx")
						{
							text2 = "./" + string.Join("/", list.GetRange(num - 1, list.Count() - (num - 1)));
						}
						num++;
						text3 = item;
					}
					audioClip.SendWebRequest();
					while (!audioClip.isDone)
					{
					}
					if (audioClip.isHttpError || audioClip.isNetworkError)
					{
						Log.LogWarning((object)("Failed to load " + file + " from " + text2));
						Debug.Log((object)audioClip.error);
						continue;
					}
					((DownloadHandlerAudioClip)audioClip.downloadHandler).streamAudio = true;
					if (audioClip.isNetworkError)
					{
						Log.LogWarning((object)("Failed to stream " + file + " from " + text2));
						Debug.Log((object)audioClip.error);
					}
					else
					{
						AudioClip audioClip2 = ((DownloadHandlerAudioClip)audioClip.downloadHandler).audioClip;
						clips[file] = audioClip2;
					}
				}
				finally
				{
					((IDisposable)audioClip)?.Dispose();
				}
			}
		}

		private static void PlaySound(string name, CharSelectController_new __instance)
		{
			if ((Object)(object)newsource == (Object)null)
			{
				AudioSource val = __instance.all_sfx[0];
				AudioMixerGroup outputAudioMixerGroup = val.outputAudioMixerGroup;
				Component obj = ((Component)val).gameObject.AddComponent(typeof(AudioSource));
				newsource = (AudioSource)(object)((obj is AudioSource) ? obj : null);
				newsource.outputAudioMixerGroup = outputAudioMixerGroup;
			}
			AudioClip value;
			if (countdown == 3)
			{
				countdown += -1;
				clips.TryGetValue("choose", out value);
				newsource.PlayOneShot(value);
			}
			else if (countdown > 0)
			{
				countdown += -1;
			}
			else
			{
				clips.TryGetValue(name, out value);
				newsource.PlayOneShot(value);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "com.guardie.characterannouncer";

		public const string PLUGIN_NAME = "CharacterAnnouncer";

		public const string PLUGIN_VERSION = "2.1.0";
	}
}