Decompiled source of NoiseSuppression v1.0.2

NoiseSuppression.dll

Decompiled 9 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 Dissonance.Config;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using NoiseSuppression.Patches;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("NoiseSuppression")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Enables the built-in noise suppression (rnnoise) so people don't have to listen to your keyboard!")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+cc5c1e6fa040f4299a2ee79edc2902ccbb9d7452")]
[assembly: AssemblyProduct("NoiseSuppression")]
[assembly: AssemblyTitle("NoiseSuppression")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 NoiseSuppression
{
	[BepInPlugin("NoiseSuppression", "NoiseSuppression", "1.0.2")]
	public class Plugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private void Awake()
		{
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011f: Expected O, but got Unknown
			ConfigEntry<bool> val = ((BaseUnityPlugin)this).Config.Bind<bool>("Suppression", "HasSetDefaultState", false, (ConfigDescription)null);
			if (val.Value)
			{
				PlayerControllerInputPatch.SetSuppressionState(state: true);
				val.Value = true;
				((BaseUnityPlugin)this).Config.Save();
			}
			ConfigEntry<string> val2 = ((BaseUnityPlugin)this).Config.Bind<string>("Suppression", "ToggleKey", "Alpha0", "Toggle noise suppression");
			ConfigEntry<string> val3 = ((BaseUnityPlugin)this).Config.Bind<string>("Suppression", "EnableKey", "PageUp", "Enable noise suppression");
			ConfigEntry<string> val4 = ((BaseUnityPlugin)this).Config.Bind<string>("Suppression", "DisableKey", "PageDown", "Disable noise suppression");
			ConfigEntry<string> val5 = ((BaseUnityPlugin)this).Config.Bind<string>("Suppression", "DecreaseKey", "Alpha8", "Decrease noise suppression");
			ConfigEntry<string> obj = ((BaseUnityPlugin)this).Config.Bind<string>("Suppression", "IncreaseKey", "Alpha9", "Increase noise suppression");
			PlayerControllerInputPatch.ToggleSuppressionKey = val2.Value;
			PlayerControllerInputPatch.EnableSuppressionKey = val3.Value;
			PlayerControllerInputPatch.DisableSuppressionKey = val4.Value;
			PlayerControllerInputPatch.DecreaseSuppressionKey = val5.Value;
			PlayerControllerInputPatch.IncreaseSuppressionKey = obj.Value;
			_harmony = new Harmony("NoiseSuppression");
			_harmony.PatchAll(typeof(PlayerControllerInputPatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "NoiseSuppression";

		public const string PLUGIN_NAME = "NoiseSuppression";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}
namespace NoiseSuppression.Patches
{
	public class PlayerControllerInputPatch
	{
		private const float SuppressionStepPercentage = 0.1f;

		public static string ToggleSuppressionKey;

		public static string EnableSuppressionKey;

		public static string DisableSuppressionKey;

		public static string DecreaseSuppressionKey;

		public static string IncreaseSuppressionKey;

		private static bool _isEnabled;

		private static float _wetAudioMix;

		[HarmonyPatch(typeof(PlayerControllerB), "Update")]
		[HarmonyPostfix]
		private static void UpdateHandleKeyPresses(PlayerControllerB __instance)
		{
			if (__instance.isPlayerControlled && ((NetworkBehaviour)__instance).IsOwner)
			{
				if (UnityInput.Current.GetKeyDown(ToggleSuppressionKey))
				{
					SetSuppressionState(!_isEnabled);
				}
				else if (UnityInput.Current.GetKeyDown(EnableSuppressionKey))
				{
					SetSuppressionState(state: true);
				}
				else if (UnityInput.Current.GetKeyDown(DisableSuppressionKey))
				{
					SetSuppressionState(state: false);
				}
				else if (UnityInput.Current.GetKeyDown(IncreaseSuppressionKey))
				{
					AdjustWetMix(0.1f);
				}
				else if (UnityInput.Current.GetKeyDown(DecreaseSuppressionKey))
				{
					AdjustWetMix(-0.1f);
				}
			}
		}

		internal static void SetSuppressionState(bool state)
		{
			_isEnabled = state;
			VoiceSettings.Instance.BackgroundSoundRemovalEnabled = _isEnabled;
		}

		private static void AdjustWetMix(float delta)
		{
			_wetAudioMix = Mathf.Clamp(_wetAudioMix + delta, 0f, 1f);
		}
	}
}