using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;
[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.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("LobbyTalkMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+93265485c02a478503823bb2a7d45edf64f8c452")]
[assembly: AssemblyProduct("LobbyTalkMod")]
[assembly: AssemblyTitle("LobbyTalkMod")]
[assembly: AssemblyVersion("1.0.0.0")]
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;
}
}
}
namespace LobbyTalkMod
{
[BepInPlugin("com.yourname.unmuteonmenu", "Unmute On Main Menu", "1.1.0")]
public class UnmuteOnMenu : BaseUnityPlugin
{
private Harmony _harmony;
private void Awake()
{
//IL_0007: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Expected O, but got Unknown
_harmony = new Harmony("com.yourname.unmuteonmenu");
TryPatchMainMenuAwake();
TryPatchLobbyEntered();
TryPatchStartGame();
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
private void TryPatchMainMenuAwake()
{
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Expected O, but got Unknown
Type type = AccessTools.TypeByName("MainMenuManager");
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager type not found; cannot patch Awake yet.");
return;
}
MethodInfo methodInfo = AccessTools.Method(type, "Awake", Type.EmptyTypes, (Type[])null);
if (methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager.Awake() not found.");
return;
}
MethodInfo methodInfo2 = AccessTools.Method(typeof(UnmuteOnMenu), "LobbyTalkEnable", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched MainMenuManager.Awake() postfix.");
}
private void TryPatchLobbyEntered()
{
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: Expected O, but got Unknown
Type type = AccessTools.TypeByName("MainMenuManager");
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager type not found; cannot patch LobbyEntered yet.");
return;
}
MethodInfo methodInfo = AccessTools.Method(type, "LobbyEntered", new Type[3]
{
typeof(string),
typeof(bool),
typeof(ulong)
}, (Type[])null);
if (methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager.LobbyEntered(string[], string[]) not found.");
return;
}
MethodInfo methodInfo2 = AccessTools.Method(typeof(UnmuteOnMenu), "LobbyTalkEnable", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched MainMenuManager.LobbyEntered() postfix.");
}
private void TryPatchStartGame()
{
//IL_007a: Unknown result type (might be due to invalid IL or missing references)
//IL_0087: Expected O, but got Unknown
Type type = AccessTools.TypeByName("MainMenuManager");
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager type not found; cannot patch ActuallyStartGameActually yet.");
return;
}
MethodInfo methodInfo = AccessTools.Method(type, "ActuallyStartGameActually", (Type[])null, (Type[])null);
if (methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"MainMenuManager.ActuallyStartGameActually() not found.");
return;
}
MethodInfo methodInfo2 = AccessTools.Method(typeof(UnmuteOnMenu), "LobbyTalkDisable", (Type[])null, (Type[])null);
_harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"Patched MainMenuManager.LobbyEntered() postfix.");
}
private static void LobbyTalkEnable()
{
TryForceUnmute("Dissonance.DissonanceComms", "DissonanceSetup", "DissonanceComms");
TryForceUnmute("Dissonance.VoiceBroadcastTrigger", "DissonanceSetup", "VoiceBroadcastTrigger");
SetVoiceDistance(5000f);
}
private static void LobbyTalkDisable()
{
TryForceUnmute("Dissonance.DissonanceComms", "DissonanceSetup", "DissonanceComms");
TryForceUnmute("Dissonance.VoiceBroadcastTrigger", "DissonanceSetup", "VoiceBroadcastTrigger");
SetVoiceDistance(150f);
}
private static void SetVoiceDistance(float distance, bool setMixerGroup = false)
{
GameObject[] source = Resources.FindObjectsOfTypeAll<GameObject>();
GameObject[] array = source.Where((GameObject go) => (Object)(object)go != (Object)null && (SafeCompareTag(go, "playbackprefab") || ((Object)go).name == "pbpf")).ToArray();
if (array.Length == 0)
{
Debug.LogWarning((object)"[UnmuteOnMenu] No hidden/inactive playback prefab found by tag 'playbackprefab' or name 'pbpf'.");
return;
}
GameObject[] array2 = array;
foreach (GameObject val in array2)
{
AudioSource componentInChildren = val.GetComponentInChildren<AudioSource>(true);
if ((Object)(object)componentInChildren == (Object)null)
{
Debug.LogWarning((object)("[UnmuteOnMenu] '" + ((Object)val).name + "' found but has no AudioSource (self or children)."));
continue;
}
componentInChildren.maxDistance = distance;
RaycastAudioDamper val2 = val.GetComponentInParent<RaycastAudioDamper>(true) ?? val.GetComponentInChildren<RaycastAudioDamper>(true);
if ((Object)(object)val2 != (Object)null && (Object)(object)val2.globalloud != (Object)null)
{
if ((Object)(object)val2.ps != (Object)null)
{
val2.ps.outputAudioMixerGroup = val2.globalloud;
Debug.Log((object)"[UnmuteOnMenu] Mixer group set.");
continue;
}
if (setMixerGroup)
{
componentInChildren.outputAudioMixerGroup = val2.globalloud;
}
Debug.LogWarning((object)("[UnmuteOnMenu] RaycastAudioDamper.ps was null on '" + ((Object)val).name + "', applied globalloud to found AudioSource instead."));
}
else
{
Debug.LogWarning((object)("[UnmuteOnMenu] Could not find RaycastAudioDamper/globalloud near '" + ((Object)val).name + "'. No fallback applied."));
}
}
Debug.Log((object)$"[UnmuteOnMenu] Set AudioSource.maxDistance to {distance}. Mixer group set.");
}
private static bool SafeCompareTag(GameObject go, string tag)
{
try
{
return go.CompareTag(tag);
}
catch
{
return go.tag == tag;
}
}
private static void TryForceUnmute(string componentTypeName, string goName, string label)
{
GameObject val = GameObject.Find(goName);
if (!Object.op_Implicit((Object)(object)val))
{
return;
}
Component component = val.GetComponent(componentTypeName);
if ((Object)(object)component == (Object)null)
{
return;
}
PropertyInfo property = ((object)component).GetType().GetProperty("IsMuted", BindingFlags.Instance | BindingFlags.Public);
if (!(property == null) && property.CanRead && property.CanWrite)
{
object value = property.GetValue(component, null);
bool flag = default(bool);
int num;
if (value is bool)
{
flag = (bool)value;
num = 1;
}
else
{
num = 0;
}
if (((uint)num & (flag ? 1u : 0u)) != 0)
{
property.SetValue(component, false, null);
Debug.Log((object)("[UnmuteOnMenu] " + label + ".IsMuted forced to false."));
}
}
}
}
}