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 HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Voice.Unity;
using UnityEngine;
[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 = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VoiceThreshold")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Voice Threshold")]
[assembly: AssemblyTitle("VoiceThreshold")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 VoiceThreshold
{
[BepInPlugin("VoiceThreshold", "Voice Threshold", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch]
public class Patches
{
[HarmonyPatch(typeof(PlayerVoiceChat), "Awake")]
[HarmonyPostfix]
private static void PlayerVoiceChatAwakePatch(PlayerVoiceChat __instance)
{
PhotonView component = ((Component)__instance).GetComponent<PhotonView>();
Recorder component2 = ((Component)__instance).GetComponent<Recorder>();
if ((Object)(object)component != (Object)null && component.IsMine && (Object)(object)component2 != (Object)null)
{
recorder = component2;
component2.VoiceDetection = configUseThreshold.Value;
component2.VoiceDetectionThreshold = configThresholdValue.Value;
}
}
}
internal static ManualLogSource Logger;
public static ConfigEntry<float> configThresholdValue;
public static ConfigEntry<bool> configUseThreshold;
public static Recorder recorder;
private readonly Harmony _harmony = new Harmony("VoiceThreshold");
public Plugin()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_0010: Expected O, but got Unknown
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
configThresholdValue = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ThresholdValue", 0.01f, new ConfigDescription("The threshold value for the voice", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
configUseThreshold = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "UseThreshold", true, "Whether to use the threshold value");
configThresholdValue.SettingChanged += ThresholdChanged;
configUseThreshold.SettingChanged += UseThresholdChanged;
}
private void Awake()
{
Logger = ((BaseUnityPlugin)this).Logger;
Logger.LogInfo((object)"Plugin VoiceThreshold is loaded!");
_harmony.PatchAll();
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
Logger.LogInfo((object)"Cleaning up my shit!");
}
private void ThresholdChanged(object sender, EventArgs e)
{
if (e is SettingChangedEventArgs && (Object)(object)recorder != (Object)null)
{
SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
float voiceDetectionThreshold = (float)val.ChangedSetting.BoxedValue;
recorder.VoiceDetectionThreshold = voiceDetectionThreshold;
}
}
private void UseThresholdChanged(object sender, EventArgs e)
{
if (e is SettingChangedEventArgs && (Object)(object)recorder != (Object)null)
{
SettingChangedEventArgs val = (SettingChangedEventArgs)(object)((e is SettingChangedEventArgs) ? e : null);
bool voiceDetection = (bool)val.ChangedSetting.BoxedValue;
recorder.VoiceDetection = voiceDetection;
}
}
}
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "VoiceThreshold";
public const string PLUGIN_NAME = "Voice Threshold";
public const string PLUGIN_VERSION = "1.0.0";
}
}