Decompiled source of DissonanceVoiceSettings v1.0.1

DissonanceVoiceSettings.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
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 Dissonance;
using Dissonance.Audio.Capture;
using Dissonance.Config;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("DissonanceVoiceSettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Change Dissonance VOIP (voice chat) settings")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("DissonanceVoiceSettings")]
[assembly: AssemblyTitle("DissonanceVoiceSettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace DissonanceVoiceSettings;

[BepInPlugin("DissonanceVoiceSettings", "DissonanceVoiceSettings", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static bool defaultBackgroundSoundRemovalEnabled = false;

	internal static int defaultBackgroundSoundRemovalAmount = 65;

	internal static NoiseSuppressionLevels defaultDenoiseAmount = (NoiseSuppressionLevels)1;

	internal static bool defaultForwardErrorCorrection = true;

	internal static FrameSize defaultFrameSize = (FrameSize)0;

	internal static AudioQuality defaultQuality = (AudioQuality)1;

	internal static int defaultVoiceDuckLevel = 100;

	internal static VadSensitivityLevels defaultVadSensitivity = (VadSensitivityLevels)1;

	private ConfigEntry<bool> configBackgroundSoundRemovalEnabled;

	private ConfigEntry<int> configBackgroundSoundRemovalAmount;

	private ConfigEntry<NoiseSuppressionLevels> configDenoiseAmount;

	private ConfigEntry<bool> configForwardErrorCorrection;

	private ConfigEntry<FrameSize> configFrameSize;

	private ConfigEntry<int> configVoiceDuckLevel;

	private ConfigEntry<VadSensitivityLevels> configVadSensitivity;

	private ConfigEntry<AudioQuality> configQuality;

	private void Awake()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Expected O, but got Unknown
		//IL_019f: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0225: Unknown result type (might be due to invalid IL or missing references)
		//IL_022f: Expected O, but got Unknown
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_026a: Unknown result type (might be due to invalid IL or missing references)
		//IL_02cb: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Unknown result type (might be due to invalid IL or missing references)
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"Plugin DissonanceVoiceSettings is loaded!");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.BackgroundSoundRemovalEnabled = {VoiceSettings.Instance.BackgroundSoundRemovalEnabled}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.BackgroundSoundRemovalAmount = {VoiceSettings.Instance.BackgroundSoundRemovalAmount}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.DenoiseAmount = {VoiceSettings.Instance.DenoiseAmount}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.ForwardErrorCorrection = {VoiceSettings.Instance.ForwardErrorCorrection}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.FrameSize = {VoiceSettings.Instance.FrameSize}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.Quality = {VoiceSettings.Instance.Quality}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.VoiceDuckLevel = {VoiceSettings.Instance.VoiceDuckLevel}");
		Log.LogInfo((object)$"Pre-patch VoiceSettings.Instance.VadSensitivity = {VoiceSettings.Instance.VadSensitivity}");
		configBackgroundSoundRemovalEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Noise Suppression", "BackgroundSoundRemovalEnabled", defaultBackgroundSoundRemovalEnabled, "Enables RNNoise, an ML based background sound removal system. When there is a lot of background sound (e.g. people talking, dogs barking, keyboard clatter, fan noise, loud breathing) this system will remove it, but will distort speech much more than the basic Noise Suppression system. Dissonance can run both noise removal systems at once, which reduces the amount of distortion present even in very noisy environments. It is recommended to enable this system if you are building an application where there is likely to be a lot of environmental noise (e.g. a mobile app, where the user is expected to be on-the-move while talking) or an intense VR game (where the user may be breathing heavily while talking).");
		configBackgroundSoundRemovalAmount = ((BaseUnityPlugin)this).Config.Bind<int>("Noise Suppression", "BackgroundSoundRemovalAmount", defaultBackgroundSoundRemovalAmount, new ConfigDescription("The intensity slider limits the amount of background sound that can be removed and also limits the maximum amount of distortion even in the worst case. Set it higher to cancel more noise.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		configDenoiseAmount = ((BaseUnityPlugin)this).Config.Bind<NoiseSuppressionLevels>("Noise Suppression", "DenoiseAmount", defaultDenoiseAmount, "Controls how much the audio pre-processor removes noise from the signal. Higher values will remove more noise but may also make speech quieter. Sounds such as people talking in the background are not noise and will not be removed by the noise suppressor. This system removes non-voice sounds such as fans hum, keyboard clatter, or fuzz from a poor quality microphone.");
		configForwardErrorCorrection = ((BaseUnityPlugin)this).Config.Bind<bool>("Codec", "ForwardErrorCorrection", defaultForwardErrorCorrection, "Controls if the codec is using Forward Error Correction which improves audio quality when packets are lost. When network conditions are good this makes no difference to network data used. When network conditions are bad this slightly increases the total data used (by about 10%) and massively improves audio quality (it can almost completely mask ~5% packet loss). WARNING: It is very highly recommended to keep FEC enabled. It is a huge quality increase for a very small increase in network data usage.");
		configFrameSize = ((BaseUnityPlugin)this).Config.Bind<FrameSize>("Codec", "FrameSize", defaultFrameSize, "Controls how much audio is packed into a single network packet. Smaller frames reduce recording latency but send more packets over the network per second, which consumes more network data and slightly more CPU power. The exact frame size at each setting is: Tiny = 10ms (100 packets/s), Small = 20ms (50 packets/s), Medium = 40ms (25 packets/s), Large = 60ms (16.6 packets/second). WARNING: The smallest option (Tiny) is not suitable for use over the internet or over a wireless network. This option should only be used in very special cases where all clients will be connected to the same wired local area network.");
		configVoiceDuckLevel = ((BaseUnityPlugin)this).Config.Bind<int>("Codec", "VoiceDuckLevel", defaultVoiceDuckLevel, new ConfigDescription("Controls how much received Dissonance audio will be attenuated by when any VoiceBroadcastTrigger is activated (i.e. speech is being transmitted). This can help prevent feedback of recorded audio into the microphone. The AEC system is not perfect - even if you have AEC setup and working it is still worth using audio ducking. The default value configured in Dissonance is a very mild (almost imperceptible) level of audio ducking. Much smaller values can reasonably be used, particularly on mobile platforms or VR headsets where feedback (due to speakers and microphones in close proximity) is a much more common problem.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		configVadSensitivity = ((BaseUnityPlugin)this).Config.Bind<VadSensitivityLevels>("Codec", "VadSensitivity", defaultVadSensitivity, "The voice detector detects speech and activates Voice Broadcast Trigger components configured with Activation Mode: Voice Activation. This settings controls a tradeoff between accuracy (not activating when no one is speaking) and sensitivity (always activating when someone is speaking). A low sensitivity voice detector will not activate when there is non-speech audio (e.g. keyboard clatter), but it sometimes may not activate when there is speech (e.g. quiet speech). A high sensitivity voice detector will activate when there is speech, but it may also activate when there is non-speech audio.");
		configQuality = ((BaseUnityPlugin)this).Config.Bind<AudioQuality>("Codec", "Quality", defaultQuality, "Controls how many bits-per-second (on average) the audio codec will use to encode audio. Higher bitrates sound better but use more network data and slightly more CPU power. The data rate used by each quality setting is: Low = 1.25 KB/s, Medium = 2.125 KB/s, High = 3 KB/s");
		Application.quitting += Quit;
		VoiceSettings.Instance.BackgroundSoundRemovalEnabled = configBackgroundSoundRemovalEnabled.Value;
		VoiceSettings.Instance.BackgroundSoundRemovalAmount = (float)configBackgroundSoundRemovalAmount.Value / 100f;
		VoiceSettings.Instance.DenoiseAmount = configDenoiseAmount.Value;
		VoiceSettings.Instance.ForwardErrorCorrection = configForwardErrorCorrection.Value;
		VoiceSettings.Instance.FrameSize = configFrameSize.Value;
		VoiceSettings.Instance.Quality = configQuality.Value;
		VoiceSettings.Instance.VoiceDuckLevel = (float)configVoiceDuckLevel.Value / 100f;
		VoiceSettings.Instance.VadSensitivity = configVadSensitivity.Value;
	}

	private static void Quit()
	{
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Unknown result type (might be due to invalid IL or missing references)
		Log.LogInfo((object)"Restoring default voice settings.");
		VoiceSettings.Instance.BackgroundSoundRemovalEnabled = defaultBackgroundSoundRemovalEnabled;
		VoiceSettings.Instance.BackgroundSoundRemovalAmount = (float)defaultBackgroundSoundRemovalAmount / 100f;
		VoiceSettings.Instance.DenoiseAmount = defaultDenoiseAmount;
		VoiceSettings.Instance.ForwardErrorCorrection = defaultForwardErrorCorrection;
		VoiceSettings.Instance.FrameSize = defaultFrameSize;
		VoiceSettings.Instance.Quality = defaultQuality;
		VoiceSettings.Instance.VoiceDuckLevel = (float)defaultVoiceDuckLevel / 100f;
		VoiceSettings.Instance.VadSensitivity = defaultVadSensitivity;
	}
}
public static class PluginInfo
{
	public const string PLUGIN_GUID = "DissonanceVoiceSettings";

	public const string PLUGIN_NAME = "DissonanceVoiceSettings";

	public const string PLUGIN_VERSION = "1.0.0";
}