using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Realtime;
using Photon.Voice.PUN;
using Photon.Voice.Unity;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[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 RejoinVoiceFix
{
[BepInPlugin("patchnote.rejoinvoicefix", "Rejoin Voice Fix", "1.0.0")]
public sealed class RejoinVoiceFixPlugin : BaseUnityPlugin
{
internal const string PluginGuid = "patchnote.rejoinvoicefix";
internal const string PluginName = "Rejoin Voice Fix";
internal const string PluginVersion = "1.0.0";
private Harmony? _harmony;
internal static RejoinVoiceFixPlugin? Instance { get; private set; }
private void Awake()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
Instance = this;
_harmony = new Harmony("patchnote.rejoinvoicefix");
PatchMethod("Player", "LeaveCurrentGame", "PlayerLeaveCurrentGamePrefix");
((BaseUnityPlugin)this).Logger.LogInfo((object)"Loaded voice reset fix.");
}
private void OnDestroy()
{
Harmony? harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
if (Instance == this)
{
Instance = null;
}
}
private void ResetVoice(string source)
{
//IL_0085: Unknown result type (might be due to invalid IL or missing references)
PunVoiceClient instance = PunVoiceClient.Instance;
if (((instance != null) ? ((VoiceConnection)instance).Client : null) != null)
{
string arg = ((((LoadBalancingClient)((VoiceConnection)instance).Client).InRoom && ((LoadBalancingClient)((VoiceConnection)instance).Client).CurrentRoom != null) ? (((LoadBalancingClient)((VoiceConnection)instance).Client).CurrentRoom.Name ?? "<unknown>") : "<none>");
try
{
((LoadBalancingClient)((VoiceConnection)instance).Client).Disconnect();
}
catch (Exception arg2)
{
((BaseUnityPlugin)this).Logger.LogError((object)$"Voice disconnect threw while handling {source}: {arg2}");
return;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Voice disconnect requested. source={source} room={arg} state={((VoiceConnection)instance).ClientState}");
}
}
private void PatchMethod(string typeName, string methodName, string prefixName)
{
//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
//IL_00b2: Expected O, but got Unknown
if (_harmony == null)
{
return;
}
Type type = AccessTools.TypeByName(typeName);
if (type == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not find type '" + typeName + "' to patch " + methodName + "."));
return;
}
MethodInfo methodInfo = AccessTools.Method(type, methodName, (Type[])null, (Type[])null);
if (methodInfo == null)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not find method '" + typeName + "." + methodName + "' to patch."));
}
else
{
HarmonyMethod val = new HarmonyMethod(AccessTools.Method(typeof(RejoinVoiceFixPlugin), prefixName, (Type[])null, (Type[])null));
_harmony.Patch((MethodBase)methodInfo, val, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private static void PlayerLeaveCurrentGamePrefix()
{
Instance?.ResetVoice("Player.LeaveCurrentGame");
}
}
}