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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PEAKLib.UI;
using Photon.Voice.Unity;
using Unity.Mathematics;
using UnityEngine;
using Zorro.Settings;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("io.senftresearch")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.7.0")]
[assembly: AssemblyInformationalVersion("0.1.7+e0f315b551a9387769f6da2cae2cae6448372795")]
[assembly: AssemblyProduct("io.senftresearch")]
[assembly: AssemblyTitle("SoundGate")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.7.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.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;
}
}
[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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace SoundGate
{
internal class BepInExFloat : FloatSetting, IBepInExProperty, IExposedSetting
{
[CompilerGenerated]
private string <displayName>P;
[CompilerGenerated]
private float <defaultValue>P;
[CompilerGenerated]
private string <categoryName>P;
[CompilerGenerated]
private float <minValue>P;
[CompilerGenerated]
private float <maxValue>P;
[CompilerGenerated]
private float <currentValue>P;
[CompilerGenerated]
private Action<float>? <saveCallback>P;
[CompilerGenerated]
private Action<BepInExFloat>? <onApply>P;
public BepInExFloat(string displayName, float defaultValue = 0f, string categoryName = "Mods", float minValue = 0f, float maxValue = 1f, float currentValue = 0f, Action<float>? saveCallback = null, Action<BepInExFloat>? onApply = null)
{
<displayName>P = displayName;
<defaultValue>P = defaultValue;
<categoryName>P = categoryName;
<minValue>P = minValue;
<maxValue>P = maxValue;
<currentValue>P = currentValue;
<saveCallback>P = saveCallback;
<onApply>P = onApply;
((FloatSetting)this)..ctor();
}
public override void Load(ISettingsSaveLoad loader)
{
//IL_000d: Unknown result type (might be due to invalid IL or missing references)
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_0014: Unknown result type (might be due to invalid IL or missing references)
//IL_0020: Unknown result type (might be due to invalid IL or missing references)
((FloatSetting)this).Value = <currentValue>P;
float2 minMaxValue = ((FloatSetting)this).GetMinMaxValue();
((FloatSetting)this).MinValue = minMaxValue.x;
((FloatSetting)this).MaxValue = minMaxValue.y;
}
public override void Save(ISettingsSaveLoad saver)
{
<saveCallback>P?.Invoke(((FloatSetting)this).Value);
}
public override void ApplyValue()
{
<onApply>P?.Invoke(this);
}
public string GetDisplayName()
{
return <displayName>P;
}
public string GetCategory()
{
return <categoryName>P;
}
protected override float GetDefaultValue()
{
return <defaultValue>P;
}
protected override float2 GetMinMaxValue()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
return new float2(<minValue>P, <maxValue>P);
}
}
internal interface IBepInExProperty
{
}
internal static class NoiseGate
{
public static BepInExFloat Sensitivity { get; private set; }
public static void InitSettings()
{
Sensitivity = new BepInExFloat("input_sensitivity", 0.5f, "Audio", 0f, 1f, 0f, delegate(float v)
{
ApplyThresholdTo(Plugin.LocalRecorder, v);
}, delegate(BepInExFloat s)
{
ApplyThresholdTo(Plugin.LocalRecorder, ((FloatSetting)s).Value);
});
SettingsHandler.Instance.AddSetting((Setting)(object)Sensitivity);
}
public static void ApplyToLocalRecorder()
{
Recorder localRecorder = Plugin.LocalRecorder;
BepInExFloat sensitivity = Sensitivity;
ApplyThresholdTo(localRecorder, (sensitivity != null) ? ((FloatSetting)sensitivity).Value : 0.5f);
}
private static void ApplyThresholdTo(Recorder recorder, float value01)
{
if (!((Object)(object)recorder == (Object)null))
{
recorder.VoiceDetectionThreshold = Mathf.Clamp01(value01);
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogInfo((object)$"VAD threshold set -> {recorder.VoiceDetectionThreshold:0.###}");
}
}
}
}
[BepInPlugin("io.senftresearch", "SoundGate", "0.1.7")]
public class Plugin : BaseUnityPlugin
{
internal static Recorder LocalRecorder;
private GameObject _pageGO;
public const string Id = "io.senftresearch";
internal static ManualLogSource Log { get; private set; }
public static string Name => "SoundGate";
public static string Version => "0.1.7";
private void Start()
{
NoiseGate.InitSettings();
}
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("io.senftresearch.soundgate").PatchAll();
Log.LogInfo((object)"Noise Gate mod loaded");
}
}
}
namespace SoundGate.patches
{
[HarmonyPatch(typeof(AnimatedMouth))]
internal static class AnimatedMouthPatch
{
[HarmonyPostfix]
[HarmonyPatch("ProcessMicData")]
private static void ProcessMicData_Postfix(AnimatedMouth __instance)
{
if ((Object)(object)__instance == (Object)null)
{
return;
}
Character character = __instance.character;
if ((Object)(object)character == (Object)null || !character.IsLocal || __instance.isGhost || IsRecorderTransmitting())
{
return;
}
__instance.isSpeaking = false;
if (!((Object)(object)__instance.mouthRenderer == (Object)null))
{
__instance.mouthRenderer.material.SetInt("_UseTalkSprites", 0);
if (__instance.mouthTextures != null && __instance.mouthTextures.Length != 0)
{
__instance.amplitudeIndex = 0;
__instance.mouthRenderer.material.SetTexture("_TalkSprite", (Texture)(object)__instance.mouthTextures[0]);
}
}
}
private static bool IsRecorderTransmitting()
{
Recorder localRecorder = Plugin.LocalRecorder;
if ((Object)(object)localRecorder == (Object)null)
{
return true;
}
try
{
return localRecorder.IsCurrentlyTransmitting || (localRecorder.VoiceDetection && localRecorder.VoiceDetector != null && localRecorder.VoiceDetector.Detected);
}
catch
{
return true;
}
}
}
[HarmonyPatch(typeof(MainMenu))]
internal static class MenuPatch
{
[HarmonyPrefix]
[HarmonyPatch("Start")]
private static void Start_Prefix(MainMenu __instance)
{
Plugin.Log.LogInfo((object)"Did the sensitivity stuff");
MenuAPI.CreateLocalization("input_sensitivity").AddLocalization("Input Sensitivity", (Language)0);
}
}
[HarmonyPatch(typeof(VoiceClientHandler))]
internal static class VoiceClientHandlerPatch
{
[HarmonyPostfix]
[HarmonyPatch("LocalPlayerAssigned")]
private static void LocalPlayerAssigned_Postfix(Recorder r)
{
if (!((Object)(object)r == (Object)null))
{
Plugin.LocalRecorder = r;
r.VoiceDetection = true;
r.VoiceDetectionDelayMs = 200;
WebRtcAudioDsp val = ((Component)r).GetComponent<WebRtcAudioDsp>() ?? ((Component)r).gameObject.AddComponent<WebRtcAudioDsp>();
val.NoiseSuppression = true;
val.HighPass = true;
val.AEC = false;
NoiseGate.ApplyToLocalRecorder();
ManualLogSource log = Plugin.Log;
if (log != null)
{
log.LogInfo((object)"Configured Recorder VAD + WebRTC DSP");
}
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}