Decompiled source of Toggle Mute v1.0.0

Computery.ToggleMute.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CurvedUI;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PushToMute.Patches;
using ToggleMute;
using ToggleMute.Utilities;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Settings;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("Computery.ToggleMute")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-dev.2+688eea2ce0db3a782e01d1efec47f08500d2446d")]
[assembly: AssemblyProduct("ToggleMute")]
[assembly: AssemblyTitle("Computery.ToggleMute")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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 PushToMute.Patches
{
	[HarmonyPatch(typeof(GameAPI))]
	internal static class GameAPIPatches
	{
		internal static string MUTE_UI_ASSET_BUNDLE_PATH = "MuteUI";

		[HarmonyPostfix]
		[HarmonyPatch("Awake")]
		private static void AwakePatch(ref GameAPI __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).buildIndex != 0)
			{
				if ((Object)(object)global::ToggleMute.ToggleMute.MuteUIAssetBundle == (Object)null)
				{
					global::ToggleMute.ToggleMute.DebugLogger.LogError((object)"Asset bundle is null");
				}
				else
				{
					Object.Instantiate<GameObject>(global::ToggleMute.ToggleMute.MuteUIAssetBundle.LoadAsset<GameObject>(MUTE_UI_ASSET_BUNDLE_PATH), ((Component)__instance).transform);
				}
			}
		}
	}
	[HarmonyPatch(typeof(VoiceChatModeSetting))]
	internal static class VoiceChatModeSettingPatches
	{
		internal static int PushToMuteIndex;

		internal static int ToggleMuteIndex;

		internal static bool canTalk = true;

		internal static bool showMutedImage = false;

		private static bool wasPressingButton = false;

		[HarmonyPostfix]
		[HarmonyPatch("GetChoices")]
		private static void GetChoicesPatch(ref List<string> __result)
		{
			__result.Add("Push to Mute");
			PushToMuteIndex = __result.Count - 1;
			__result.Add("Toggle Mute");
			ToggleMuteIndex = __result.Count - 1;
		}

		[HarmonyPostfix]
		[HarmonyPatch("CanTalk")]
		private static void CanTalkPatch(ref bool __result, ref VoiceChatModeSetting __instance)
		{
			bool key = GlobalInputHandler.PushToTalkKey.GetKey();
			if (((IntSetting)__instance).Value == PushToMuteIndex)
			{
				__result = !key;
			}
			else if (((IntSetting)__instance).Value == ToggleMuteIndex)
			{
				canTalk = ((!wasPressingButton && key) ? (!canTalk) : canTalk);
				__result = canTalk;
			}
			wasPressingButton = key;
			showMutedImage = !__result;
		}
	}
}
namespace ToggleMute
{
	public class MuteImageHandler : MonoBehaviour
	{
		public Image image;

		public Sprite mutedSprite;

		public Sprite unmutedSprite;

		public void LateUpdate()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			image.sprite = (VoiceChatModeSettingPatches.showMutedImage ? mutedSprite : unmutedSprite);
			float microphoneValue = Player.localPlayer.data.microphoneValue;
			microphoneValue *= 0.5f;
			microphoneValue = CurvedUIExtensionMethods.Clamp(microphoneValue, 0.1f, 1f);
			((Graphic)image).color = new Color(((Graphic)image).color.r, ((Graphic)image).color.g, ((Graphic)image).color.b, microphoneValue);
		}
	}
	public class UIAspectRatioUpdater : MonoBehaviour
	{
		private (int, int) m_currentResolution;

		public AspectRatioUISetter[] AspectRatioUISetters;

		private void LateUpdate()
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			(int, int) tuple = (Screen.width, Screen.height);
			(int, int) currentResolution = m_currentResolution;
			(int, int) tuple2 = tuple;
			if (currentResolution.Item1 != tuple2.Item1 || currentResolution.Item2 != tuple2.Item2)
			{
				AspectRatio aspectRatio = AspectRatioUtility.GetAspectRatio((float)Screen.width / (float)Screen.height);
				LoadAspectRatio(aspectRatio);
				m_currentResolution = tuple;
			}
		}

		public void LoadAspectRatio(AspectRatio aspectRatio)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0002: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if ((int)aspectRatio == 3)
			{
				aspectRatio = (AspectRatio)1;
			}
			AspectRatioUISetter[] aspectRatioUISetters = AspectRatioUISetters;
			foreach (AspectRatioUISetter val in aspectRatioUISetters)
			{
				val.LoadAspectPosition(aspectRatio);
			}
		}
	}
	[ContentWarningPlugin("Computery.ToggleMute", "1.0.0", true)]
	[BepInPlugin("Computery.ToggleMute", "ToggleMute", "1.0.0")]
	public class ToggleMute : BaseUnityPlugin
	{
		internal static string MUTE_UI_ASSET_BUNDLE_PATH = "ToggleMute.Resources.MuteUI.AssetBundle";

		internal static AssetBundle MuteUIAssetBundle = null;

		internal static Assembly ToggleMuteAssembly => Assembly.GetExecutingAssembly();

		internal static ManualLogSource DebugLogger { get; private set; } = null;


		internal static Harmony Harmony { get; set; } = null;


		private void Awake()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			DebugLogger = ((BaseUnityPlugin)this).Logger;
			DebugLogger.LogInfo((object)"Logging set.");
			MuteUIAssetBundle = EmbeddedResources.LoadAssetBundleFromResources(MUTE_UI_ASSET_BUNDLE_PATH);
			if ((Object)(object)MuteUIAssetBundle == (Object)null)
			{
				DebugLogger.LogError((object)("Failed to load asset bundle from " + MUTE_UI_ASSET_BUNDLE_PATH));
			}
			else
			{
				DebugLogger.LogInfo((object)("Loaded asset bundle from " + MUTE_UI_ASSET_BUNDLE_PATH));
			}
			Harmony = Harmony.CreateAndPatchAll(ToggleMuteAssembly, (string)null);
			DebugLogger.LogInfo((object)$"Patched {Harmony.GetPatchedMethods().Count()} methods.");
			((EnumSetting)new VoiceChatModeSetting()).GetChoices();
			DebugLogger.LogInfo((object)"Propigated the possible choices for the VoiceChatModeSetting.");
			DebugLogger.LogInfo((object)"Computery.ToggleMute v1.0.0 has loaded.");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Computery.ToggleMute";

		public const string PLUGIN_NAME = "ToggleMute";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace ToggleMute.Utilities
{
	internal static class EmbeddedResources
	{
		internal static AssetBundle? LoadAssetBundleFromResources(string assetBundlePath)
		{
			if (!ToggleMute.ToggleMuteAssembly.GetManifestResourceNames().Contains(assetBundlePath))
			{
				return null;
			}
			using Stream stream = ToggleMute.ToggleMuteAssembly.GetManifestResourceStream(assetBundlePath);
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			return AssetBundle.LoadFromMemory(memoryStream.ToArray());
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}