Decompiled source of SpeechAction v0.0.2

SpeechAction.dll

Decompiled 8 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.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Windows.Speech;

[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 = "")]
[assembly: AssemblyCompany("SpeechAction")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod that turns speech into action")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: AssemblyInformationalVersion("0.0.1")]
[assembly: AssemblyProduct("SpeechAction")]
[assembly: AssemblyTitle("SpeechAction")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
[module: UnverifiableCode]
namespace SpeechAction
{
	[BepInPlugin("Navinate.SpeechAction", "SpeechAction", "0.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		private const string modGUID = "Navinate.SpeechAction";

		private const string modName = "SpeechAction";

		private const string modVersion = "0.0.2";

		private readonly Harmony harmony = new Harmony("Navinate.SpeechAction");

		private static Plugin Instance;

		internal static ManualLogSource Log;

		private KeywordRecognizer keywordRecognizer;

		private Dictionary<string, Action> actions = new Dictionary<string, Action>();

		internal static PlayerControllerB player;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			Log = ((BaseUnityPlugin)this).Logger;
			harmony.PatchAll();
			Log.LogInfo((object)"Plugin SpeechAction is loaded!");
		}

		private void Start()
		{
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			actions.Add("dance", StartDanceEmote);
			actions.Add("party", StartDanceEmote);
			actions.Add("point", StartPointEmote);
			actions.Add("there", StartPointEmote);
			keywordRecognizer = new KeywordRecognizer(actions.Keys.ToArray());
			((PhraseRecognizer)keywordRecognizer).OnPhraseRecognized += new PhraseRecognizedDelegate(HandleRecognizedSpeech);
			((PhraseRecognizer)keywordRecognizer).Start();
		}

		private void HandleRecognizedSpeech(PhraseRecognizedEventArgs speech)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo((object)speech.text);
			actions[speech.text]();
		}

		private void StartDanceEmote()
		{
			if (((((NetworkBehaviour)player).IsOwner && player.isPlayerControlled && (!((NetworkBehaviour)player).IsServer || player.isHostPlayerObject)) || player.isTestingPlayer) && !(player.timeSinceStartingEmote < 0.5f))
			{
				player.timeSinceStartingEmote = 0f;
				player.performingEmote = true;
				player.playerBodyAnimator.SetInteger("emoteNumber", 1);
				player.StartPerformingEmoteServerRpc();
			}
		}

		private void StartPointEmote()
		{
			if (((((NetworkBehaviour)player).IsOwner && player.isPlayerControlled && (!((NetworkBehaviour)player).IsServer || player.isHostPlayerObject)) || player.isTestingPlayer) && !(player.timeSinceStartingEmote < 0.5f))
			{
				player.timeSinceStartingEmote = 0f;
				player.performingEmote = true;
				player.playerBodyAnimator.SetInteger("emoteNumber", 2);
				player.StartPerformingEmoteServerRpc();
			}
		}
	}
}
namespace SpeechAction.patches
{
	[HarmonyPatch(typeof(StartOfRound))]
	internal class StartOfRoundPatch
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void storePlayerScript(ref PlayerControllerB ___localPlayerController)
		{
			Plugin.player = ___localPlayerController;
		}
	}
}