using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Voice.Unity;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[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("ToggleMute")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod for Repo")]
[assembly: AssemblyFileVersion("0.0.5.0")]
[assembly: AssemblyInformationalVersion("0.0.5+d2d866fd73d0e86b799bd7475b8582103b6a59b8")]
[assembly: AssemblyProduct("ToggleMute")]
[assembly: AssemblyTitle("ToggleMute")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.5.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 ToggleMute
{
[HarmonyPatch(typeof(PlayerVoiceChat), "OnDestroy")]
internal class PushToMuteCleanupPatch
{
[HarmonyPrefix]
private static void Prefix(PlayerVoiceChat __instance)
{
if (PushToMutePatch.playerRecorders.ContainsKey(__instance))
{
PushToMutePatch.playerRecorders.Remove(__instance);
PushToMutePatch.AnimateIconCoroutine = null;
}
else
{
Debug.Log((object)("PlayerVoiceChat OnDestroy: No recorder found for " + ((Component)__instance).GetComponent<PhotonView>().Owner.NickName + "."));
}
}
}
[HarmonyPatch(typeof(PlayerVoiceChat), "Awake")]
internal class PushToMuteInitPatch
{
[HarmonyPostfix]
private static void Postfix(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)
{
PushToMutePatch.playerRecorders[__instance] = component2;
}
}
}
[BepInPlugin("com.coddingcat.togglemute", "ToggleMute", "1.0.0")]
public class PushToMuteMod : BaseUnityPlugin
{
private Harmony harmony;
private static GameObject hudCanvas;
public AssetBundle muteIconBundle;
public static PushToMuteMod Instance;
public static ConfigEntry<KeyCode> MuteKey { get; private set; }
public static ConfigEntry<float> SoundVolume { get; private set; }
public static ConfigEntry<int> AnimationTime { get; private set; }
private void Awake()
{
//IL_0032: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
//IL_0058: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
BindCofigs();
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
harmony = new Harmony("com.coddingcat.pushtomute");
harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Push-to-Mute mod loaded! Key: {MuteKey.Value}");
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void BindCofigs()
{
MuteKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "MuteKey", (KeyCode)109, "Key to toggle Push-to-Mute (Change in config file)");
SoundVolume = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SoundVolume", 0.3f, "Volume of mute/unmute sound (0.0 - 1.0)");
AnimationTime = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Animation Duration", 200, "Duration of the mute icon animation in milliseconds.");
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
PushToMutePatch.UpdateUI(PushToMutePatch.isMuted);
}
private void LogAssetNames(AssetBundle bundle)
{
if (!((Object)(object)bundle == (Object)null))
{
string[] allAssetNames = bundle.GetAllAssetNames();
string[] array = allAssetNames;
foreach (string text in array)
{
Debug.Log((object)("Asset in bundle: " + text));
}
}
}
public static GameObject GetHudCanvas()
{
if ((Object)(object)hudCanvas == (Object)null)
{
hudCanvas = GameObject.Find("UI/HUD/HUD Canvas");
if ((Object)(object)hudCanvas == (Object)null)
{
Debug.LogError((object)"HUD Canvas not found");
}
}
return hudCanvas;
}
}
[HarmonyPatch(typeof(PlayerVoiceChat), "Update")]
internal class PushToMutePatch
{
public static Dictionary<PlayerVoiceChat, Recorder> playerRecorders = new Dictionary<PlayerVoiceChat, Recorder>();
private static GameObject muteIcon;
private static GameObject cutLineIcon;
private static Image muteIconImage;
private static Image cutLineImage;
private static Color muteIconColor;
private static Color cutLineColor;
private static AssetBundle muteIconBundle;
private static AudioSource audioSource;
private static AudioClip muteSound;
private static AudioClip unmuteSound;
public static PlayerVoiceChat instance;
public static Coroutine AnimateIconCoroutine;
public static bool isMuted = false;
private static float t = 0f;
public static void UpdateUI(bool Animation)
{
if ((Object)(object)muteIcon == (Object)null)
{
InitMuteIcon();
}
isMuted = Animation;
AnimateIconCoroutine = ((MonoBehaviour)PushToMuteMod.Instance).StartCoroutine(AnimateIcon());
}
[HarmonyPostfix]
private static void Postfix(PlayerVoiceChat __instance)
{
//IL_0027: Unknown result type (might be due to invalid IL or missing references)
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_007f: Unknown result type (might be due to invalid IL or missing references)
instance = __instance;
if (!playerRecorders.TryGetValue(__instance, out var value))
{
return;
}
KeyCode value2 = PushToMuteMod.MuteKey.Value;
if ((Object)(object)muteIcon == (Object)null)
{
InitMuteIcon();
}
if (!(bool)typeof(ChatManager).GetField("chatActive", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(ChatManager.instance))
{
if (Input.GetKeyDown(value2))
{
isMuted = !isMuted;
audioSource.clip = (isMuted ? muteSound : unmuteSound);
audioSource.Play();
value.TransmitEnabled = !isMuted;
value.RecordingEnabled = !isMuted;
}
bool flag = AnimateIconCoroutine != null;
bool flag2 = (t != 1f || !isMuted) && (t != 0f || isMuted);
if (!flag && flag2)
{
AnimateIconCoroutine = ((MonoBehaviour)__instance).StartCoroutine(AnimateIcon());
}
}
}
private static void InitMuteIcon()
{
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Unknown result type (might be due to invalid IL or missing references)
//IL_0081: Unknown result type (might be due to invalid IL or missing references)
//IL_0097: Unknown result type (might be due to invalid IL or missing references)
//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
//IL_00af: Unknown result type (might be due to invalid IL or missing references)
//IL_00b9: Expected O, but got Unknown
//IL_00da: Unknown result type (might be due to invalid IL or missing references)
//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
//IL_0105: Unknown result type (might be due to invalid IL or missing references)
//IL_010f: Expected O, but got Unknown
//IL_0127: Unknown result type (might be due to invalid IL or missing references)
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0141: Unknown result type (might be due to invalid IL or missing references)
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0153: Unknown result type (might be due to invalid IL or missing references)
//IL_0160: Unknown result type (might be due to invalid IL or missing references)
//IL_0261: Unknown result type (might be due to invalid IL or missing references)
//IL_0266: Unknown result type (might be due to invalid IL or missing references)
//IL_0270: Unknown result type (might be due to invalid IL or missing references)
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
GameObject hudCanvas = PushToMuteMod.GetHudCanvas();
if ((Object)(object)hudCanvas == (Object)null)
{
return;
}
GameObject val = new GameObject("MuteIconContainer");
RectTransform val2 = val.AddComponent<RectTransform>();
((Transform)val2).SetParent(hudCanvas.transform, false);
Vector2 sizeDelta = default(Vector2);
((Vector2)(ref sizeDelta))..ctor(40f, 40f);
val2.anchorMin = new Vector2(1f, 0f);
val2.anchorMax = new Vector2(1f, 0f);
val2.pivot = new Vector2(1f, 0f);
val2.anchoredPosition = new Vector2(-10f, 10f);
val2.sizeDelta = sizeDelta;
muteIcon = new GameObject("MuteIcon");
RectTransform val3 = muteIcon.AddComponent<RectTransform>();
((Transform)val3).SetParent((Transform)(object)val2);
val3.pivot = new Vector2(0.5f, 0.5f);
val3.anchoredPosition = Vector2.op_Implicit(Vector3.zero);
val3.sizeDelta = sizeDelta;
cutLineIcon = new GameObject("CutLine");
RectTransform val4 = cutLineIcon.AddComponent<RectTransform>();
((Transform)val4).SetParent((Transform)(object)val2, false);
val4.anchorMin = Vector2.zero;
val4.anchorMax = Vector2.zero;
val4.pivot = Vector2.zero;
val4.anchoredPosition = Vector2.op_Implicit(Vector3.zero);
val4.sizeDelta = sizeDelta;
muteIconImage = muteIcon.AddComponent<Image>();
cutLineImage = cutLineIcon.AddComponent<Image>();
string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
if ((Object)(object)muteIconBundle == (Object)null)
{
muteIconBundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "togglemutebundle"));
}
if ((Object)(object)muteIconBundle != (Object)null)
{
Sprite val5 = muteIconBundle.LoadAsset<Sprite>("assets/unmuted.png");
Sprite val6 = muteIconBundle.LoadAsset<Sprite>("assets/cutLine.png");
muteSound = muteIconBundle.LoadAsset<AudioClip>("assets/on.ogg");
unmuteSound = muteIconBundle.LoadAsset<AudioClip>("assets/off.ogg");
if ((Object)(object)val5 != (Object)null && (Object)(object)val6 != (Object)null)
{
muteIconImage.sprite = val5;
cutLineImage.sprite = val6;
}
}
muteIconColor = ((Graphic)muteIconImage).color;
cutLineColor = ((Graphic)cutLineImage).color;
if ((Object)(object)audioSource == (Object)null)
{
audioSource = muteIcon.AddComponent<AudioSource>();
}
audioSource.volume = PushToMuteMod.SoundVolume.Value;
}
private static IEnumerator AnimateIcon()
{
while (true)
{
if ((Object)(object)muteIcon == (Object)null || (Object)(object)muteIconImage == (Object)null)
{
AnimateIconCoroutine = null;
yield break;
}
if (t == 1f && isMuted)
{
muteIcon.transform.localScale = Vector3.one;
muteIconColor.a = 1f;
((Graphic)muteIconImage).color = muteIconColor;
cutLineIcon.transform.localScale = Vector3.one;
cutLineColor.a = 1f;
((Graphic)cutLineImage).color = cutLineColor;
AnimateIconCoroutine = null;
yield break;
}
if (t == 0f && !isMuted)
{
break;
}
if (PushToMuteMod.AnimationTime.Value == 0)
{
t = (isMuted ? 1f : 0f);
}
else
{
float animationTimeInSeconds = (float)PushToMuteMod.AnimationTime.Value * 0.001f;
t = Mathf.MoveTowards(t, isMuted ? 1f : 0f, Time.deltaTime / animationTimeInSeconds);
}
float easeT = EaseInOut(t);
muteIcon.transform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, easeT);
cutLineIcon.transform.localScale = Vector3.Lerp(Vector3.zero, Vector3.one, easeT);
muteIconColor = ((Graphic)muteIconImage).color;
muteIconColor.a = Mathf.Lerp(0f, 1f, easeT);
cutLineColor = ((Graphic)cutLineImage).color;
cutLineColor.a = Mathf.Lerp(0f, 1f, easeT);
((Graphic)cutLineImage).color = cutLineColor;
((Graphic)muteIconImage).color = muteIconColor;
yield return null;
}
muteIcon.transform.localScale = Vector3.zero;
muteIconColor.a = 0f;
((Graphic)muteIconImage).color = muteIconColor;
cutLineIcon.transform.localScale = Vector3.zero;
cutLineColor.a = 0f;
((Graphic)cutLineImage).color = cutLineColor;
AnimateIconCoroutine = null;
}
private static float EaseInOut(float t)
{
return t * t * (3f - 2f * t);
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ToggleMute";
public const string PLUGIN_NAME = "ToggleMute";
public const string PLUGIN_VERSION = "0.0.5";
}
}