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("LethalCompanyTemplate")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Mod for Repo")]
[assembly: AssemblyFileVersion("0.0.5.0")]
[assembly: AssemblyInformationalVersion("0.0.5+bc0d5c229d6182a2e42fa3d13552014142ecefca")]
[assembly: AssemblyProduct("LethalCompanyTemplate")]
[assembly: AssemblyTitle("LethalCompanyTemplate")]
[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;
}
}
}
[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; }
private void Awake()
{
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
//IL_0098: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
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)");
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;
}
public 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), "Awake")]
internal class PushToMuteInitPatch
{
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;
}
}
}
[HarmonyPatch(typeof(PlayerVoiceChat), "OnDestroy")]
internal class PushToMuteCleanupPatch
{
private static void Prefix(PlayerVoiceChat __instance)
{
PushToMutePatch.playerRecorders.Remove(__instance);
}
}
[HarmonyPatch(typeof(PlayerVoiceChat), "Update")]
internal class PushToMutePatch
{
public static Dictionary<PlayerVoiceChat, Recorder> playerRecorders = new Dictionary<PlayerVoiceChat, Recorder>();
public static bool isMuted = false;
private static GameObject muteIcon;
private static Image muteIconImage;
private static Color muteIconColor;
private static AssetBundle muteIconBundle;
private static AudioSource audioSource;
private static AudioClip muteSound;
private static AudioClip unmuteSound;
private static Sprite unmutedIcon;
public static PlayerVoiceChat instance;
public static void UpdateUI(bool Animation)
{
if ((Object)(object)muteIcon == (Object)null)
{
InitMuteIcon();
}
isMuted = Animation;
((MonoBehaviour)PushToMuteMod.Instance).StartCoroutine(AnimateMuteIcon(Animation, force: true));
}
private static void Postfix(PlayerVoiceChat __instance)
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
//IL_002a: Unknown result type (might be due to invalid IL or missing references)
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
instance = __instance;
if (playerRecorders.TryGetValue(__instance, out var value))
{
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) && Input.GetKeyDown(value2))
{
isMuted = !isMuted;
value.TransmitEnabled = !isMuted;
value.RecordingEnabled = !isMuted;
((MonoBehaviour)__instance).StartCoroutine(AnimateMuteIcon(isMuted, force: false));
}
}
}
private static void InitMuteIcon()
{
//IL_001c: Unknown result type (might be due to invalid IL or missing references)
//IL_0026: Expected O, but got Unknown
//IL_0062: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_0165: Unknown result type (might be due to invalid IL or missing references)
//IL_016a: Unknown result type (might be due to invalid IL or missing references)
//IL_0183: Unknown result type (might be due to invalid IL or missing references)
GameObject hudCanvas = PushToMuteMod.GetHudCanvas();
if ((Object)(object)hudCanvas == (Object)null)
{
return;
}
muteIcon = new GameObject("MuteIcon");
muteIcon.transform.SetParent(hudCanvas.transform, false);
RectTransform val = muteIcon.AddComponent<RectTransform>();
((Component)val).gameObject.transform.position = new Vector3(680f, 30f, 0f);
val.sizeDelta = new Vector2(50f, 50f);
muteIconImage = muteIcon.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 val2 = muteIconBundle.LoadAsset<Sprite>("assets/muteicon.png");
unmutedIcon = muteIconBundle.LoadAsset<Sprite>("assets/unmutedicon.png");
muteSound = muteIconBundle.LoadAsset<AudioClip>("assets/on.ogg");
unmuteSound = muteIconBundle.LoadAsset<AudioClip>("assets/off.ogg");
if ((Object)(object)val2 != (Object)null && (Object)(object)unmutedIcon != (Object)null)
{
muteIconImage.sprite = val2;
}
}
muteIconColor = ((Graphic)muteIconImage).color;
muteIconColor.a = 0f;
((Graphic)muteIconImage).color = muteIconColor;
muteIcon.SetActive(false);
if ((Object)(object)audioSource == (Object)null)
{
audioSource = muteIcon.AddComponent<AudioSource>();
}
}
public static IEnumerator AnimateMuteIcon(bool show, bool force)
{
Sprite muteSprite = muteIconBundle.LoadAsset<Sprite>("assets/muteicon.png");
if ((Object)(object)muteIcon == (Object)null || (Object)(object)muteIconImage == (Object)null || (Object)(object)muteIconBundle == (Object)null)
{
Debug.LogError((object)"Mute icon or bundle is not initialized");
yield break;
}
muteIcon.SetActive(true);
if (force)
{
float endAlpha = (show ? 1 : 0);
if (!show)
{
_ = Vector3.one;
}
else
{
_ = Vector3.zero;
}
Vector3 endScale = (show ? Vector3.one : Vector3.zero);
muteIconColor.a = endAlpha;
((Graphic)muteIconImage).color = muteIconColor;
muteIcon.transform.localScale = endScale;
muteIconImage.sprite = (show ? muteSprite : unmutedIcon);
yield break;
}
AudioClip sound = (show ? muteSound : unmuteSound);
if ((Object)(object)sound != (Object)null)
{
audioSource.PlayOneShot(sound, PushToMuteMod.SoundVolume.Value);
}
float duration = 0.3f;
float elapsed = 0f;
float startAlpha = ((!show) ? 1 : 0);
float endAlpha2 = (show ? 1 : 0);
Vector3 startScale = (show ? Vector3.zero : Vector3.one);
Vector3 endScale2 = (show ? Vector3.one : Vector3.zero);
while (elapsed < duration)
{
elapsed += Time.deltaTime;
float t2 = elapsed / duration;
t2 = Mathf.Sin(t2 * MathF.PI * 0.5f);
muteIconColor.a = Mathf.Lerp(startAlpha, endAlpha2, t2);
((Graphic)muteIconImage).color = muteIconColor;
muteIcon.transform.localScale = Vector3.Lerp(startScale, endScale2, t2);
yield return null;
}
muteIconColor.a = endAlpha2;
((Graphic)muteIconImage).color = muteIconColor;
muteIcon.transform.localScale = endScale2;
muteIconImage.sprite = (show ? muteSprite : unmutedIcon);
}
}
namespace LethalCompanyTemplate
{
public static class PluginInfo
{
public const string PLUGIN_GUID = "LethalCompanyTemplate";
public const string PLUGIN_NAME = "LethalCompanyTemplate";
public const string PLUGIN_VERSION = "0.0.5";
}
}