Decompiled source of PushToMute v1.1.0

BepInEx/plugins/PushToMute.dll

Decompiled 10 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using PushToMute.Patches;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PushToMute")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PushToMute")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("faaa231e-a5f3-481d-a1d9-f1f5799855fc")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PushToMute
{
	[BepInPlugin("Baba.PushToMute", "PushToMute", "1.0.0")]
	public class PTMModBase : BaseUnityPlugin
	{
		private const string modGUID = "Baba.PushToMute";

		private const string modName = "PushToMute";

		private const string modVersion = "1.0.0";

		private readonly Harmony harmony = new Harmony("Baba.PushToMute");

		private static PTMModBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Baba.PushToMute");
			harmony.PatchAll(typeof(PTMModBase));
			harmony.PatchAll(typeof(UpdatePatch));
			harmony.PatchAll(typeof(InGamePlayerSettingsPatch));
			mls.LogInfo((object)"Push To Mute successfully loaded!");
		}
	}
}
namespace PushToMute.Patches
{
	[HarmonyPatch(typeof(StartOfRound), "Update")]
	internal class UpdatePatch
	{
		private static void Postfix(StartOfRound __instance)
		{
			if ((Object)(object)__instance.voiceChatModule != (Object)null && !IngamePlayerSettings.Instance.settings.pushToTalk)
			{
				__instance.voiceChatModule.IsMuted = IngamePlayerSettings.Instance.playerInput.actions.FindAction("VoiceButton", false).IsPressed();
			}
		}
	}
	[HarmonyPatch(typeof(IngamePlayerSettings))]
	internal class InGamePlayerSettingsPatch
	{
		[HarmonyPatch("SetMicPushToTalk")]
		[HarmonyPostfix]
		private static void SetMicPushToTalkPatch(IngamePlayerSettings __instance)
		{
			if (!__instance.unsavedSettings.pushToTalk)
			{
				__instance.SetSettingsOptionsText((SettingsOptionType)3, "MODE: Push to mute");
			}
		}

		[HarmonyPatch("UpdateMicPushToTalkButton")]
		[HarmonyPostfix]
		private static void UpdateMicPushToTalkButtonPatch(IngamePlayerSettings __instance)
		{
			if (!__instance.settings.pushToTalk)
			{
				__instance.SetSettingsOptionsText((SettingsOptionType)3, "MODE: Push to mute");
			}
		}
	}
}