Decompiled source of PeakLobbyJoinFix v1.0.0

PeakLobbyFixMod.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Steamworks;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PeakLobbyFixMod")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes Steam lobby join timing issues for PEAK")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakLobbyFixMod")]
[assembly: AssemblyTitle("PeakLobbyFixMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 PeakLobbyFixMod
{
	[BepInPlugin("com.icemods.peaklobbyfix", "Peak Lobby Fix", "1.0.0")]
	[BepInProcess("PEAK.exe")]
	public class PeakLobbyFixMod : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		private static bool hasLobbyJoinRequest = false;

		private static CSteamID pendingLobbyID = CSteamID.Nil;

		private static bool isProcessingLobbyJoin = false;

		public static PeakLobbyFixMod Instance { get; private set; }

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				new Harmony("com.icemods.peaklobbyfix").PatchAll();
				Log.LogInfo((object)"Peak Lobby Fix Mod loaded - Simple approach!");
			}
			catch (Exception arg)
			{
				Log.LogError((object)$"Failed to apply patches: {arg}");
			}
		}

		private void Update()
		{
			if (hasLobbyJoinRequest && !isProcessingLobbyJoin && IsPhotonReady())
			{
				Log.LogInfo((object)"Photon is ready! Processing delayed lobby join...");
				isProcessingLobbyJoin = true;
				((MonoBehaviour)this).StartCoroutine(ProcessDelayedLobbyJoin());
			}
		}

		private bool IsPhotonReady()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			if (PhotonNetwork.IsConnected && (int)PhotonNetwork.NetworkClientState == 15)
			{
				return PhotonNetwork.AuthValues != null;
			}
			return false;
		}

		private IEnumerator ProcessDelayedLobbyJoin()
		{
			yield return (object)new WaitForSeconds(1f);
			Log.LogInfo((object)$"Executing delayed lobby join for: {pendingLobbyID}");
			SteamLobbyHandler service = GameHandler.GetService<SteamLobbyHandler>();
			if (service != null)
			{
				service.TryJoinLobby(pendingLobbyID);
				Log.LogInfo((object)"Successfully initiated delayed lobby join!");
			}
			else
			{
				Log.LogError((object)"SteamLobbyHandler not found!");
			}
			hasLobbyJoinRequest = false;
			pendingLobbyID = CSteamID.Nil;
			isProcessingLobbyJoin = false;
		}

		public static void DelayLobbyJoin(CSteamID lobbyID)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			Log.LogInfo((object)$"Delaying lobby join for: {lobbyID}");
			hasLobbyJoinRequest = true;
			pendingLobbyID = lobbyID;
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "TryJoinLobby")]
	public class SteamLobbyHandlerPatch
	{
		private static bool Prefix(CSteamID lobbyID)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsConnected || (int)PhotonNetwork.NetworkClientState != 15 || PhotonNetwork.AuthValues == null)
			{
				PeakLobbyFixMod.Log.LogInfo((object)$"Photon not ready, delaying lobby join for: {lobbyID}");
				PeakLobbyFixMod.DelayLobbyJoin(lobbyID);
				return false;
			}
			PeakLobbyFixMod.Log.LogInfo((object)$"Photon ready, allowing immediate lobby join for: {lobbyID}");
			return true;
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyJoinRequested")]
	public class OnLobbyJoinRequestedPatch
	{
		private static bool Prefix(GameLobbyJoinRequested_t param)
		{
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Invalid comparison between Unknown and I4
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			if (!PhotonNetwork.IsConnected || (int)PhotonNetwork.NetworkClientState != 15 || PhotonNetwork.AuthValues == null)
			{
				PeakLobbyFixMod.Log.LogInfo((object)$"Photon not ready, delaying lobby join request for: {param.m_steamIDLobby}");
				PeakLobbyFixMod.DelayLobbyJoin(param.m_steamIDLobby);
				return false;
			}
			PeakLobbyFixMod.Log.LogInfo((object)$"Photon ready, allowing immediate lobby join request for: {param.m_steamIDLobby}");
			return true;
		}
	}
	[HarmonyPatch(typeof(NetworkConnector), "OnConnectedToMaster")]
	public class NetworkConnectorPatch
	{
		private static void Postfix()
		{
			PeakLobbyFixMod.Log.LogInfo((object)"Photon connected to master server!");
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "PeakLobbyFixMod";

		public const string PLUGIN_NAME = "PeakLobbyFixMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}