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.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = "")]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("ToggleMute")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("A mod for Lethal Company that adds a customizable toggle mute hotkey")]
[assembly: AssemblyFileVersion("1.3.0.0")]
[assembly: AssemblyInformationalVersion("1.3.0")]
[assembly: AssemblyProduct("ToggleMute")]
[assembly: AssemblyTitle("ToggleMute")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.3.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 ToggleMute
{
public class Config
{
public static ConfigEntry<bool> allowMuteInTerminal;
public static void Load()
{
allowMuteInTerminal = Plugin.config.Bind<bool>("General", "Allow Mute In Terminal", false, "Will you be able to use the toggle mute hotkey while in the terminal or while typing in chat?");
}
}
[HarmonyPatch(typeof(HUDManager), "Awake")]
internal class HUDPatch
{
private static void Postfix()
{
//IL_0021: Unknown result type (might be due to invalid IL or missing references)
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0054: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
ToggleMuteManager instance = ToggleMuteManager.instance;
instance.micDisabledImagePrefab = Plugin.Bundle.LoadAsset<GameObject>("Assets/ToggleMute/MicDisabled.prefab");
Transform transform = new GameObject("ToggleMuteUI").transform;
transform.SetParent(HUDManager.Instance.HUDContainer.transform.parent, false);
instance.micDisabledImage = Object.Instantiate<GameObject>(instance.micDisabledImagePrefab, Vector3.zero, Quaternion.identity);
instance.micDisabledImage.transform.SetParent(transform, false);
instance.micDisabledImage.transform.localPosition = new Vector3(-420f, -230f, 6.5f);
instance.micDisabledImage.SetActive(false);
}
}
[HarmonyPatch(typeof(IngamePlayerSettings), "Awake")]
internal class PlayerSettingsPatch
{
private static void Postfix(ref IngamePlayerSettings __instance)
{
ToggleMuteManager toggleMuteManager = default(ToggleMuteManager);
if (!((Component)__instance).gameObject.TryGetComponent<ToggleMuteManager>(ref toggleMuteManager))
{
ToggleMuteManager toggleMuteManager2 = ((Component)__instance).gameObject.AddComponent<ToggleMuteManager>();
toggleMuteManager2.playerSettings = __instance;
}
}
}
[BepInPlugin("quackandcheese.togglemute", "ToggleMute", "1.3.1")]
[BepInProcess("Lethal Company.exe")]
public class Plugin : BaseUnityPlugin
{
public const string ModGUID = "quackandcheese.togglemute";
public const string ModName = "ToggleMute";
public const string ModVersion = "1.3.1";
public static AssetBundle Bundle;
public static ConfigFile config;
public static ManualLogSource logger;
private void Awake()
{
//IL_0031: Unknown result type (might be due to invalid IL or missing references)
//IL_0037: Expected O, but got Unknown
Bundle = QuickLoadAssetBundle("togglemute.assets");
logger = ((BaseUnityPlugin)this).Logger;
config = ((BaseUnityPlugin)this).Config;
Config.Load();
Harmony val = new Harmony("quackandcheese.togglemute");
val.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin ToggleMute is loaded!");
}
public static T FindAsset<T>(string name) where T : Object
{
return Resources.FindObjectsOfTypeAll<T>().ToList().Find((T x) => ((Object)x).name == name);
}
public static AssetBundle QuickLoadAssetBundle(string assetBundleName)
{
string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), assetBundleName);
return AssetBundle.LoadFromFile(text);
}
}
[HarmonyPatch(typeof(HUDManager), "UpdateSpectateBoxSpeakerIcons")]
internal class SpectateBoxHUDPatch
{
private static void Postfix(ref HUDManager __instance)
{
KeyValuePair<Animator, PlayerControllerB> keyValuePair = __instance.spectatingPlayerBoxes.FirstOrDefault((KeyValuePair<Animator, PlayerControllerB> x) => (Object)(object)x.Value == (Object)(object)GameNetworkManager.Instance.localPlayerController);
if (StartOfRound.Instance.voiceChatModule.IsMuted && !keyValuePair.Equals(default(KeyValuePair<Animator, PlayerControllerB>)))
{
keyValuePair.Key.SetBool("speaking", false);
}
}
}
public class ToggleMuteInputActions : LcInputActions
{
public static ToggleMuteInputActions Instance = new ToggleMuteInputActions();
[InputAction(/*Could not decode attribute arguments.*/)]
public InputAction ToggleMuteKey { get; set; }
}
public class ToggleMuteManager : MonoBehaviour
{
public IngamePlayerSettings playerSettings;
public GameObject micDisabledImagePrefab;
public GameObject micDisabledImage;
public static ToggleMuteManager instance;
public void Awake()
{
instance = this;
ToggleMuteInputActions.Instance.ToggleMuteKey.performed += OnToggleMuteKeyPressed;
}
public void OnDestroy()
{
ToggleMuteInputActions.Instance.ToggleMuteKey.performed -= OnToggleMuteKeyPressed;
}
private void OnToggleMuteKeyPressed(CallbackContext ctx)
{
if (!((CallbackContext)(ref ctx)).performed || !Object.op_Implicit((Object)(object)playerSettings) || !Object.op_Implicit((Object)(object)StartOfRound.Instance) || !Object.op_Implicit((Object)(object)StartOfRound.Instance.voiceChatModule) || !Application.isFocused)
{
return;
}
if (Object.op_Implicit((Object)(object)GameNetworkManager.Instance))
{
PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
if (Object.op_Implicit((Object)(object)localPlayerController) && !Config.allowMuteInTerminal.Value && (localPlayerController.inTerminalMenu || localPlayerController.isTypingChat))
{
return;
}
}
IngamePlayerSettings.Instance.settings.micEnabled = !IngamePlayerSettings.Instance.settings.micEnabled;
IngamePlayerSettings.Instance.SetMicrophoneEnabled();
SettingsOption val = Object.FindObjectsOfType<SettingsOption>(true).ToList().Find((SettingsOption x) => ((Object)x).name == "SpeakerButton");
val.ToggleEnabledImage(4);
}
public void Update()
{
if ((Object)(object)micDisabledImage != (Object)null && Object.op_Implicit((Object)(object)playerSettings))
{
micDisabledImage.SetActive(!playerSettings.settings.micEnabled);
}
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "ToggleMute";
public const string PLUGIN_NAME = "ToggleMute";
public const string PLUGIN_VERSION = "1.3.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}