Decompiled source of LethalVoice v1.0.4

com.github.zehsteam.LethalVoice.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
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.Configuration;
using BepInEx.Logging;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoiceRecognitionAPI;
using com.github.zehsteam.MonsterHotkeys;
using com.github.zehsteam.MonsterHotkeys.MonoBehaviours;

[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("com.github.zehsteam.LethalVoice")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Spawn Monsters and Monster Plushies when you say specific words/phrases using the MonsterHotkeys mod. Highly Configurable.")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4+05e1d324f905d0e70c71aefac460bf7c457fafc2")]
[assembly: AssemblyProduct("LethalVoice")]
[assembly: AssemblyTitle("com.github.zehsteam.LethalVoice")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.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 com.github.zehsteam.LethalVoice
{
	internal class ConfigManager
	{
		private ConfigEntry<bool> VoiceRecognitionEnabledCfg;

		private ConfigEntry<float> VoiceConfidenceCfg;

		private ConfigEntry<bool> DisableHotkeysCfg;

		private ConfigEntry<bool> ShowRecognizedPlushiePhraseMessagesCfg;

		private ConfigEntry<string> SpawnRandomMonsterWordsCfg;

		private ConfigEntry<string> SpawnRandomPlushieWordsCfg;

		internal bool VoiceRecognitionEnabled
		{
			get
			{
				return VoiceRecognitionEnabledCfg.Value;
			}
			set
			{
				VoiceRecognitionEnabledCfg.Value = value;
			}
		}

		internal float VoiceConfidence
		{
			get
			{
				return VoiceConfidenceCfg.Value;
			}
			set
			{
				VoiceConfidenceCfg.Value = value;
			}
		}

		internal bool DisableHotkeys
		{
			get
			{
				return DisableHotkeysCfg.Value;
			}
			set
			{
				DisableHotkeysCfg.Value = value;
			}
		}

		internal bool ShowRecognizedPlushiePhraseMessages
		{
			get
			{
				return ShowRecognizedPlushiePhraseMessagesCfg.Value;
			}
			set
			{
				ShowRecognizedPlushiePhraseMessagesCfg.Value = value;
			}
		}

		internal string[] SpawnRandomMonsterWords
		{
			get
			{
				return (from _ in SpawnRandomMonsterWordsCfg.Value.Split(",")
					select _.Trim().ToLower()).ToArray();
			}
			set
			{
				SpawnRandomMonsterWordsCfg.Value = string.Join(", ", value);
			}
		}

		internal string[] SpawnRandomPlushieWords
		{
			get
			{
				return (from _ in SpawnRandomPlushieWordsCfg.Value.Split(",")
					select _.Trim().ToLower()).ToArray();
			}
			set
			{
				SpawnRandomPlushieWordsCfg.Value = string.Join(", ", value);
			}
		}

		public ConfigManager()
		{
			BindConfigs();
			SetupChangedEvents();
			ClearUnusedEntries();
		}

		private void BindConfigs()
		{
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Expected O, but got Unknown
			ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
			VoiceRecognitionEnabledCfg = config.Bind<bool>("General Settings", "VoiceRecognitionEnabled", true, "If enabled, speech recognition will be active.");
			VoiceConfidenceCfg = config.Bind<float>("General Settings", "VoiceConfidence", 0.7f, new ConfigDescription("How difficult it will be for the speech recognition to recognize your word/phrase.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			DisableHotkeysCfg = config.Bind<bool>("General Settings", "DisableHotkeys", true, "If enabled, the hotkeys from the MonsterHotkeys mod will be disabled.");
			SpawnRandomMonsterWordsCfg = config.Bind<string>("Monster Settings", "SpawnRandomMonsterWords", "alright, fuck, garbage, god, hell, kill, mate, nuts, piece, shit, wait, what, why", "The list of words/phrases you want to trigger a random monster spawn. Each word/phrase should be separated by a comma.");
			SpawnRandomPlushieWordsCfg = config.Bind<string>("Plushie Settings", "SpawnRandomPlushieWords", "ban, hate, like, messed, no, ok, rizz, stop, thank, this", "The list of words/phrases you want to trigger a random plushie spawn. Each word/phrase should be separated by a comma.");
			ShowRecognizedPlushiePhraseMessagesCfg = config.Bind<bool>("General Settings", "ShowRecognizedPlushiePhraseMessages", true, "If enabled, will show a message when a phrase is recognized for spawning plushies. See additional message setting in the MonsterHotkeys config file.");
		}

		private void SetupChangedEvents()
		{
			DisableHotkeysCfg.SettingChanged += Plugin.Instance.OnDisableHotkeysChanged;
			SpawnRandomMonsterWordsCfg.SettingChanged += Plugin.Instance.OnSpawnRandomMonsterWordsChanged;
			SpawnRandomPlushieWordsCfg.SettingChanged += Plugin.Instance.OnSpawnRandomPlushieWordsChanged;
		}

		private void ClearUnusedEntries()
		{
			ConfigFile config = ((BaseUnityPlugin)Plugin.Instance).Config;
			PropertyInfo property = ((object)config).GetType().GetProperty("OrphanedEntries", BindingFlags.Instance | BindingFlags.NonPublic);
			Dictionary<ConfigDefinition, string> dictionary = (Dictionary<ConfigDefinition, string>)property.GetValue(config, null);
			dictionary.Clear();
			config.Save();
		}
	}
	[BepInPlugin("com.github.zehsteam.LethalVoice", "LethalVoice", "1.0.4")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance;

		internal static ManualLogSource logger;

		internal static ConfigManager ConfigManager;

		private string[] activePhrases = Array.Empty<string>();

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			logger = Logger.CreateLogSource("com.github.zehsteam.LethalVoice");
			logger.LogInfo((object)"LethalVoice has awoken!");
			ConfigManager = new ConfigManager();
			UpdateDisableHotkeys();
			RegisterVoiceListener();
		}

		private void RegisterVoiceListener()
		{
			string[] spawnRandomMonsterWords = ConfigManager.SpawnRandomMonsterWords;
			string[] spawnRandomPlushieWords = ConfigManager.SpawnRandomPlushieWords;
			int num = 0;
			string[] array = new string[spawnRandomMonsterWords.Length + spawnRandomPlushieWords.Length];
			ReadOnlySpan<string> readOnlySpan = new ReadOnlySpan<string>(spawnRandomMonsterWords);
			readOnlySpan.CopyTo(new Span<string>(array).Slice(num, readOnlySpan.Length));
			num += readOnlySpan.Length;
			ReadOnlySpan<string> readOnlySpan2 = new ReadOnlySpan<string>(spawnRandomPlushieWords);
			readOnlySpan2.CopyTo(new Span<string>(array).Slice(num, readOnlySpan2.Length));
			num += readOnlySpan2.Length;
			activePhrases = array;
			Voice.RegisterPhrases(activePhrases);
			Voice.RegisterCustomHandler((EventHandler<VoiceRecognitionEventArgs>)delegate(object obj, VoiceRecognitionEventArgs recognized)
			{
				if (ConfigManager.VoiceRecognitionEnabled && !(recognized.Confidence < ConfigManager.VoiceConfidence))
				{
					string message = recognized.Message;
					if (ConfigManager.SpawnRandomMonsterWords.Contains(message))
					{
						logger.LogInfo((object)$"Recognized phrase \"{message}\" with a confidence of {recognized.Confidence}");
						SpawnRandomEnemy(message);
					}
					if (ConfigManager.SpawnRandomPlushieWords.Contains(message))
					{
						logger.LogInfo((object)$"Recognized phrase \"{message}\" with a confidence of {recognized.Confidence}");
						SpawnRandomPlushies(message);
					}
				}
			});
		}

		private void SpawnRandomEnemy(string phrase)
		{
			try
			{
				EnemyHelper.SpawnRandomEnemy(phrase);
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Failed to spawn random enemy.\n\n{arg}");
			}
		}

		private void SpawnRandomPlushies(string phrase)
		{
			try
			{
				PlushieManager instance = PlushieManager.Instance;
				if (instance != null)
				{
					instance.SpawnRandomPlushies();
				}
				ShowPlushiePhraseRecognizedMessage(phrase);
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Failed to spawn random plushies.\n\n{arg}");
			}
		}

		public void OnSpawnRandomMonsterWordsChanged(object sender, EventArgs e)
		{
			string[] array = ConfigManager.SpawnRandomMonsterWords.Where((string _) => !activePhrases.Contains(_)).ToArray();
			if (array.Length != 0)
			{
				Voice.RegisterPhrases(array);
			}
		}

		public void OnSpawnRandomPlushieWordsChanged(object sender, EventArgs e)
		{
			string[] array = ConfigManager.SpawnRandomPlushieWords.Where((string _) => !activePhrases.Contains(_)).ToArray();
			if (array.Length != 0)
			{
				Voice.RegisterPhrases(array);
			}
		}

		private void ShowPlushiePhraseRecognizedMessage(string phrase)
		{
			if (!ConfigManager.ShowRecognizedPlushiePhraseMessages)
			{
				return;
			}
			try
			{
				if (!((Object)(object)PlushieManager.Instance == (Object)null) && !((Object)(object)MessageCanvas.Instance == (Object)null) && PlushieManager.Instance.CanSpawnPlushies(false))
				{
					MessageCanvas.Instance.ShowMessageOnLocalClient("Recognized phrase \"" + phrase + "\"");
				}
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"Failed to show plushie phrase recognized message on local client.\n\n{arg}");
			}
		}

		private void UpdateDisableHotkeys()
		{
			bool disableHotkeys = ConfigManager.DisableHotkeys;
			try
			{
				HotkeyListener.DisableHotkeys = disableHotkeys;
				logger.LogInfo((object)((disableHotkeys ? "Disabled" : "Enabled") + " MonsterHotkeys hotkeys."));
			}
			catch (Exception arg)
			{
				logger.LogError((object)string.Format("Failed to {0} MonsterHotkeys hotkeys.\n\n{1}", disableHotkeys ? "disable" : "enable", arg));
			}
		}

		public void OnDisableHotkeysChanged(object sender, EventArgs e)
		{
			UpdateDisableHotkeys();
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.github.zehsteam.LethalVoice";

		public const string PLUGIN_NAME = "LethalVoice";

		public const string PLUGIN_VERSION = "1.0.4";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}