using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using LethalSettings.UI;
using LethalSettings.UI.Components;
using Microsoft.CodeAnalysis;
using UnityEngine;
using VoiceRecognitionAPI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ShipVoiceCommands")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ShipVoiceCommands")]
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a7de5cc0-290b-4c88-97fd-d3cb6d0e5b13")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace ShipVoiceCommands
{
[BepInPlugin("me.loaforc.shipvoicecommands", "ShipVoiceCommands", "1.5.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ShipVoiceCommandsBase : BaseUnityPlugin
{
private const string modGUID = "me.loaforc.shipvoicecommands";
private const string modName = "ShipVoiceCommands";
private const string modVersion = "1.5.0";
private readonly Harmony harmony = new Harmony("me.loaforc.shipvoicecommands");
internal static ShipVoiceCommandsBase instance;
internal static ManualLogSource logger;
internal static ConfigEntry<int> CONFIG_VERSION;
internal static ConfigEntry<bool> ARE_COMMANDS_GLOBAL;
internal static ConfigEntry<string> OPEN_DOORS_COMMAND;
internal static ConfigEntry<string> CLOSE_DOORS_COMMAND;
internal static ConfigEntry<string> ACTIVATE_TELEPORT_COMMAND;
internal static ConfigEntry<string> TOGGLE_CAMERA;
internal static ConfigEntry<string> SWITCH_CAMERA;
internal static ConfigEntry<string> TOGGLE_LIGHTS;
internal static ConfigEntry<string> PULL_LEVER;
internal static ConfigEntry<double> CONFIDENCE;
private void Awake()
{
//IL_02eb: Unknown result type (might be due to invalid IL or missing references)
//IL_02f1: Expected O, but got Unknown
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_032b: Unknown result type (might be due to invalid IL or missing references)
//IL_0337: Expected O, but got Unknown
//IL_0339: Unknown result type (might be due to invalid IL or missing references)
//IL_033e: Unknown result type (might be due to invalid IL or missing references)
//IL_0349: Unknown result type (might be due to invalid IL or missing references)
//IL_0360: Unknown result type (might be due to invalid IL or missing references)
//IL_0386: Expected O, but got Unknown
if (!((Object)(object)instance == (Object)null))
{
return;
}
instance = this;
logger = Logger.CreateLogSource("me.loaforc.shipvoicecommands");
logger.LogInfo((object)"Setting up config.");
CONFIG_VERSION = ((BaseUnityPlugin)this).Config.Bind<int>("Config", "ConfigVersion", 1, "Yeah don't touch this lol. You could mess up your settings.");
ARE_COMMANDS_GLOBAL = ((BaseUnityPlugin)this).Config.Bind<bool>("Gameplay", "AreCommandsGlobal", false, "Are the voice commands global? Or do you need to be near the ship? It is recommend to play with this off.");
CONFIDENCE = ((BaseUnityPlugin)this).Config.Bind<double>("Recognition", "Confidence", 0.2, "What amount of confidence is require for it to be classified as recognized. Higher values may help with false positives but may increase times it does not work. Value between 0 and 1.");
OPEN_DOORS_COMMAND = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "OpenShipDoors", "open doors,open ship doors", "What voice phrases should open the ship doors. Each phrase should be seperated with a comma");
CLOSE_DOORS_COMMAND = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "CloseShipDoors", "close doors,close ship doors", "What voice phrases should close the ship doors. Each phrase should be seperated with a comma");
ACTIVATE_TELEPORT_COMMAND = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "ActivateTeleporter", "teleport,teleport player", "What voice phrases should activate the ship teleporter. Each phrase should be seperated with a comma");
TOGGLE_CAMERA = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "ToggleCamera", "camera on,camera off, camera toggle", "What voice phrases should toggle the camera. Each phrase should be seperated with a comma");
SWITCH_CAMERA = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "SwitchCamera", "camera switch,switch camera,camera next", "What voice phrases should switch the camera. Each phrase should be seperated with a comma");
TOGGLE_LIGHTS = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "ToggleLights", "lights on,lights off,toggle lights,night night", "What voice phrases should toggle the ship lights. Each phrase should be seperated with a comma");
PULL_LEVER = ((BaseUnityPlugin)this).Config.Bind<string>("Commands", "PullLever", "launch,take off", "What voice phrases should cause the ship to take off. Each phrase should be seperated with a comma");
logger.LogInfo((object)"Performing any needed config migrations");
if (CONFIG_VERSION.Value == 1)
{
CONFIG_VERSION.Value = 2;
if (CONFIDENCE.Value == 0.2)
{
CONFIDENCE.Value = 0.85;
}
}
logger.LogInfo((object)"Registering voice commands!");
Voice.CustomListenForPhrases(CollectionExtensions.AddRangeToArray<string>(CollectionExtensions.AddRangeToArray<string>(CollectionExtensions.AddRangeToArray<string>(CollectionExtensions.AddRangeToArray<string>(CollectionExtensions.AddRangeToArray<string>(CollectionExtensions.AddRangeToArray<string>(OPEN_DOORS_COMMAND.Value.Split(new char[1] { ',' }), CLOSE_DOORS_COMMAND.Value.Split(new char[1] { ',' })), ACTIVATE_TELEPORT_COMMAND.Value.Split(new char[1] { ',' })), SWITCH_CAMERA.Value.Split(new char[1] { ',' })), TOGGLE_CAMERA.Value.Split(new char[1] { ',' })), TOGGLE_LIGHTS.Value.Split(new char[1] { ',' })), PULL_LEVER.Value.Split(new char[1] { ',' })), (EventHandler<VoiceRecognitionEventArgs>)delegate(object __, VoiceRecognitionEventArgs args)
{
if (!((double)args.Confidence < CONFIDENCE.Value) && IsPlayerWithinShipBounds())
{
if (OPEN_DOORS_COMMAND.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
HangarShipDoor val2 = Object.FindFirstObjectByType<HangarShipDoor>();
if ((Object)(object)val2 != (Object)null)
{
InteractTrigger component = ((Component)((Component)val2).transform.Find("HangarDoorButtonPanel/StartButton/Cube (2)")).GetComponent<InteractTrigger>();
TriggerButton(component);
}
}
if (CLOSE_DOORS_COMMAND.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
HangarShipDoor val3 = Object.FindFirstObjectByType<HangarShipDoor>();
if ((Object)(object)val3 != (Object)null)
{
InteractTrigger component2 = ((Component)((Component)val3).transform.Find("HangarDoorButtonPanel/StopButton/Cube (3)")).GetComponent<InteractTrigger>();
TriggerButton(component2);
}
}
if (ACTIVATE_TELEPORT_COMMAND.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
GameObject val4 = GameObject.Find("Teleporter(Clone)/ButtonContainer/ButtonAnimContainer/RedButton");
if ((Object)(object)val4 != (Object)null)
{
TriggerButton(val4.GetComponent<InteractTrigger>());
}
}
if (SWITCH_CAMERA.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
GameObject val5 = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube.001/CameraMonitorSwitchButton/Cube (2)");
if ((Object)(object)val5 != (Object)null)
{
TriggerButton(val5.GetComponent<InteractTrigger>());
}
}
if (TOGGLE_CAMERA.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
GameObject val6 = GameObject.Find("Environment/HangarShip/ShipModels2b/MonitorWall/Cube.001/CameraMonitorOnButton/Cube (2)");
if ((Object)(object)val6 != (Object)null)
{
TriggerButton(val6.GetComponent<InteractTrigger>());
}
}
if (TOGGLE_LIGHTS.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
GameObject val7 = GameObject.Find("Environment/HangarShip/LightSwitchContainer/LightSwitch");
if ((Object)(object)val7 != (Object)null)
{
TriggerButton(val7.GetComponent<InteractTrigger>());
}
}
if (PULL_LEVER.Value.Split(new char[1] { ',' }).Contains(args.Message))
{
StartMatchLever val8 = Object.FindObjectOfType<StartMatchLever>();
if ((Object)(object)val8 != (Object)null && StartOfRound.Instance.shipHasLanded)
{
val8.triggerScript.animationString = "SA_PushLeverBack";
val8.leverHasBeenPulled = false;
val8.triggerScript.interactable = false;
val8.leverAnimatorObject.SetBool("pullLever", false);
StartOfRound.Instance.shipHasLanded = false;
StartOfRound.Instance.shipIsLeaving = true;
StartOfRound.Instance.shipAnimator.ResetTrigger("ShipLeave");
StartOfRound.Instance.shipAnimator.SetTrigger("ShipLeave");
}
}
}
});
logger.LogInfo((object)"Creating mod settings menu...");
ModSettingsConfig val = new ModSettingsConfig();
val.Name = "ShipVoiceCommands";
val.Id = "me.loaforc.shipvoicecommands";
val.Version = "1.5.0";
val.Description = "Adds simple voice commands to control your ship!";
val.MenuComponents = (MenuComponent[])(object)new MenuComponent[2]
{
(MenuComponent)new LabelComponent
{
Text = "Increase confidence to decrease false positives. Increasing confidence may also make it not register sometimes."
},
(MenuComponent)new SliderComponent
{
Text = "Confidence",
Value = (float)CONFIDENCE.Value * 100f,
OnValueChanged = delegate(SliderComponent self, float value)
{
logger.LogInfo((object)$"Confidence slider set to: {value}, current confidence percent: {CONFIDENCE.Value} setting to -> {value / 100f}");
CONFIDENCE.Value = value / 100f;
}
}
};
ModMenu.RegisterMod(val);
logger.LogInfo((object)"ShipVoiceCommands:1.5.0 has succesfully loaded!");
}
private void TriggerButton(InteractTrigger trigger)
{
trigger.Interact(((Component)GameNetworkManager.Instance.localPlayerController).transform);
}
private bool IsPlayerWithinShipBounds()
{
//IL_0038: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
StartOfRound val = Object.FindFirstObjectByType<StartOfRound>();
if ((Object)(object)val == (Object)null)
{
return false;
}
if (ARE_COMMANDS_GLOBAL.Value)
{
return true;
}
if (GameNetworkManager.Instance.localPlayerController.isPlayerDead)
{
return false;
}
Bounds bounds = val.shipBounds.bounds;
return ((Bounds)(ref bounds)).Contains(((Component)GameNetworkManager.Instance.localPlayerController).transform.position);
}
}
}