Decompiled source of SteamJunction v1.0.2

SteamJunction.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("SteamJunction")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("FluxTeam")]
[assembly: AssemblyProduct("SteamJunction")]
[assembly: AssemblyCopyright("Copyright © FluxTeam 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("32b83c68-bdd6-409d-8a93-2c25e072e2a2")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.2.0")]
namespace SteamJunction;

[BepInPlugin("FluxTeam.SteamJunction", "Steam Junction", "1.0.2")]
public class SteamJunction : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <HandleJoinBasedOnGameState>d__45 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string roomCode;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <HandleJoinBasedOnGameState>d__45(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0031: 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_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Expected O, but got Unknown
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
			{
				<>1__state = -1;
				logger.LogInfo((object)"HandleJoinBasedOnGameState coroutine started");
				Scene activeScene = SceneManager.GetActiveScene();
				string name = ((Scene)(ref activeScene)).name;
				logger.LogInfo((object)("Current scene: " + name + ", RoomCode: " + roomCode));
				if (name == "Game")
				{
					logger.LogInfo((object)"Already in Game scene, joining room directly");
					if (PhotonNetwork.InRoom)
					{
						logger.LogInfo((object)"Already in a room, leaving first...");
						PhotonNetwork.LeaveRoom(true);
						<>2__current = (object)new WaitUntil((Func<bool>)(() => !PhotonNetwork.InRoom));
						<>1__state = 1;
						return true;
					}
					goto IL_00f5;
				}
				logger.LogInfo((object)"Not in Game scene, attempting to use MainMenuController flow");
				MainMenuController instance = MainMenuController.instance;
				if ((Object)(object)instance != (Object)null)
				{
					logger.LogInfo((object)"MainMenuController found, using reflection to set room code");
					FieldInfo field = typeof(MainMenuController).GetField("roomCode", BindingFlags.Instance | BindingFlags.NonPublic);
					FieldInfo field2 = typeof(MainMenuController).GetField("action", BindingFlags.Instance | BindingFlags.Public);
					logger.LogInfo((object)("roomCodeField: " + ((field == null) ? "NULL" : "FOUND") + ", actionField: " + ((field2 == null) ? "NULL" : "FOUND")));
					if (field != null && field2 != null)
					{
						field.SetValue(instance, roomCode);
						field2.SetValue(instance, (object)(ActionTypes)3);
						logger.LogInfo((object)"Fields set via reflection, calling GoToGameScene()");
						instance.GoToGameScene();
						break;
					}
					logger.LogWarning((object)"Reflection failed, trying public JoinPublicAction method...");
					MethodInfo method = typeof(MainMenuController).GetMethod("JoinPublicAction", BindingFlags.Instance | BindingFlags.Public);
					if (method != null)
					{
						logger.LogInfo((object)"Found JoinPublicAction method, calling it...");
						method.Invoke(instance, new object[1] { roomCode });
					}
					else
					{
						logger.LogError((object)"JoinPublicAction method not found either");
					}
				}
				else
				{
					logger.LogError((object)"MainMenuController not found - cannot join room");
					TerminalManager instance2 = TerminalManager.instance;
					if (instance2 != null)
					{
						instance2.QueueTextLine("Cannot join - main menu not available", new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
					}
				}
				break;
			}
			case 1:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 2;
				return true;
			case 2:
				{
					<>1__state = -1;
					goto IL_00f5;
				}
				IL_00f5:
				if ((Object)(object)NetworkManager.instance != (Object)null)
				{
					logger.LogInfo((object)("Calling NetworkManager.instance.Join(" + roomCode + ")"));
					NetworkManager.instance.Join(roomCode);
				}
				else
				{
					logger.LogError((object)"NetworkManager.instance is null!");
				}
				break;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <InitializeSteamCallbacksCoroutine>d__35 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		private int <waitCount>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <InitializeSteamCallbacksCoroutine>d__35(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				logger.LogInfo((object)"=== INITIALIZE STEAM CALLBACKS COROUTINE STARTED ===");
				<waitCount>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				if (<waitCount>5__2 > 20)
				{
					logger.LogError((object)"SteamManager initialization timeout!");
					isInitializing = false;
					return false;
				}
				break;
			}
			if (!IsSteamInitialized())
			{
				<waitCount>5__2++;
				logger.LogInfo((object)$"Waiting for SteamManager to initialize... attempt {<waitCount>5__2}");
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 1;
				return true;
			}
			logger.LogInfo((object)"SteamManager initialized, registering callbacks");
			try
			{
				logger.LogInfo((object)"Creating LobbyCreated callback...");
				lobbyCreatedCallback = Callback<LobbyCreated_t>.Create((DispatchDelegate<LobbyCreated_t>)OnLobbyCreated);
				logger.LogInfo((object)"Creating LobbyEnter callback...");
				lobbyEnterCallback = Callback<LobbyEnter_t>.Create((DispatchDelegate<LobbyEnter_t>)OnLobbyEntered);
				logger.LogInfo((object)"Creating GameLobbyJoinRequested callback...");
				joinRequestCallback = Callback<GameLobbyJoinRequested_t>.Create((DispatchDelegate<GameLobbyJoinRequested_t>)OnJoinRequested);
				logger.LogInfo((object)"Creating LobbyDataUpdate callback...");
				lobbyDataUpdateCallback = Callback<LobbyDataUpdate_t>.Create((DispatchDelegate<LobbyDataUpdate_t>)OnLobbyDataUpdate);
				isInitialized = true;
				isInitializing = false;
				logger.LogInfo((object)"=== ALL STEAM CALLBACKS REGISTERED SUCCESSFULLY ===");
				CheckForSteamLaunchParameters();
			}
			catch (Exception arg)
			{
				logger.LogError((object)$"ERROR registering Steam callbacks: {arg}");
				isInitializing = false;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <JoinTimeoutCoroutine>d__43 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <JoinTimeoutCoroutine>d__43(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				logger.LogInfo((object)"=== JOIN TIMEOUT COROUTINE STARTED ===");
				<>2__current = (object)new WaitForSeconds(10f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if (isJoiningRoom)
				{
					logger.LogError((object)"Join request timed out");
					ResetJoinState();
					TerminalManager instance = TerminalManager.instance;
					if (instance != null)
					{
						instance.QueueTextLine("Failed to join game - timeout", new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
					}
				}
				else
				{
					logger.LogInfo((object)"Join completed before timeout");
				}
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <ProcessDelayedJoinRequest>d__42 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CSteamID lobbyId;

		private int <waitCount>5__2;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ProcessDelayedJoinRequest>d__42(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Expected O, but got Unknown
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				logger.LogInfo((object)"=== PROCESS DELAYED JOIN REQUEST COROUTINE STARTED ===");
				<waitCount>5__2 = 0;
				break;
			case 1:
				<>1__state = -1;
				if (<waitCount>5__2 > 20)
				{
					logger.LogError((object)"Steam initialization timeout in delayed join!");
					return false;
				}
				break;
			}
			if (!isInitialized)
			{
				<waitCount>5__2++;
				logger.LogInfo((object)$"Waiting for Steam initialization... attempt {<waitCount>5__2}");
				<>2__current = (object)new WaitForSeconds(0.5f);
				<>1__state = 1;
				return true;
			}
			logger.LogInfo((object)"Processing delayed join request now that Steam is initialized");
			pendingJoinLobby = lobbyId;
			isJoiningRoom = true;
			bool flag = SteamMatchmaking.RequestLobbyData(lobbyId);
			logger.LogInfo((object)$"Delayed join lobby data request result: {flag}");
			SafeStartCoroutine(JoinTimeoutCoroutine());
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	[CompilerGenerated]
	private sealed class <ProcessLobbyJoin>d__44 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public CSteamID lobbyId;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ProcessLobbyJoin>d__44(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_020e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0213: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_026a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				logger.LogInfo((object)$"ProcessLobbyJoin coroutine started - LobbyID: {lobbyId}");
				<>2__current = null;
				<>1__state = 1;
				return true;
			case 1:
			{
				<>1__state = -1;
				string lobbyData = SteamMatchmaking.GetLobbyData(lobbyId, "RoomCode");
				string lobbyData2 = SteamMatchmaking.GetLobbyData(lobbyId, "InProgress");
				string lobbyData3 = SteamMatchmaking.GetLobbyData(lobbyId, "Version");
				string lobbyData4 = SteamMatchmaking.GetLobbyData(lobbyId, "CrewName");
				logger.LogInfo((object)("Lobby Data - RoomCode: '" + lobbyData + "', InProgress: '" + lobbyData2 + "', Version: '" + lobbyData3 + "', CrewName: '" + lobbyData4 + "'"));
				if (!string.IsNullOrEmpty(lobbyData3) && lobbyData3 != Application.version)
				{
					logger.LogError((object)("Version mismatch: Host=" + lobbyData3 + ", Client=" + Application.version));
					TerminalManager instance = TerminalManager.instance;
					if (instance != null)
					{
						instance.QueueTextLine("Version mismatch: Host=" + lobbyData3 + ", Client=" + Application.version, new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
					}
					ResetJoinState();
					return false;
				}
				if (lobbyData2 == "true" && !IsAllowLateJoinEnabled())
				{
					logger.LogWarning((object)("Cannot join Room " + lobbyData + " - Game is already in progress and Allow Late Join is disabled"));
					SteamMatchmaking.LeaveLobby(lobbyId);
					TerminalManager instance2 = TerminalManager.instance;
					if (instance2 != null)
					{
						instance2.QueueTextLine("Cannot join - Game is already in progress", new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
					}
					ResetJoinState();
					return false;
				}
				if (!string.IsNullOrEmpty(lobbyData))
				{
					logger.LogInfo((object)("Attempting to join Photon room: " + lobbyData));
					pendingRoomCode = lobbyData;
					pendingJoinFromSteam = true;
					logger.LogInfo((object)"Joining Steam lobby...");
					SteamMatchmaking.JoinLobby(lobbyId);
					<>2__current = coroutineHelper.StartCoroutine(HandleJoinBasedOnGameState(lobbyData));
					<>1__state = 2;
					return true;
				}
				logger.LogError((object)"No Room Code found in Lobby Data");
				TerminalManager instance3 = TerminalManager.instance;
				if (instance3 != null)
				{
					instance3.QueueTextLine("Invalid lobby - no room code", new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
				}
				break;
			}
			case 2:
				<>1__state = -1;
				break;
			}
			ResetJoinState();
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private const string GUID = "FluxTeam.SteamJunction";

	private const string NAME = "Steam Junction";

	private const string VERSION = "1.0.2";

	internal static ManualLogSource logger;

	internal static CSteamID currentLobbyId = CSteamID.Nil;

	private static Callback<LobbyCreated_t> lobbyCreatedCallback;

	private static Callback<LobbyEnter_t> lobbyEnterCallback;

	private static Callback<GameLobbyJoinRequested_t> joinRequestCallback;

	private static Callback<LobbyDataUpdate_t> lobbyDataUpdateCallback;

	private static SteamJunction instance;

	private static bool isJoiningRoom = false;

	private static CSteamID pendingJoinLobby = CSteamID.Nil;

	internal static string pendingRoomCode = null;

	internal static bool pendingJoinFromSteam = false;

	internal static MonoBehaviour coroutineHelper;

	private static bool isInitializing = false;

	private static bool isInitialized = false;

	private static PropertyInfo _steamManagerInstanceProperty;

	private static FieldInfo _steamManagerInitializedField;

	private const string CREW_LATE_JOIN_GUID = "com.fluxteam.crewlatejoin";

	private static bool _crewLateJoinPresent = false;

	private static Type _crewLateJoinType = null;

	private static FieldInfo _allowLateJoinField = null;

	public static ConfigEntry<bool> EnableSteamJunction;

	private void Awake()
	{
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Expected O, but got Unknown
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Expected O, but got Unknown
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0145: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: Expected O, but got Unknown
		//IL_014c: 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)
		//IL_018a: Expected O, but got Unknown
		//IL_018a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Expected O, but got Unknown
		//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0206: Expected O, but got Unknown
		//IL_0206: Unknown result type (might be due to invalid IL or missing references)
		//IL_023d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0244: Expected O, but got Unknown
		logger = ((BaseUnityPlugin)this).Logger;
		instance = this;
		EnableSteamJunction = ((BaseUnityPlugin)this).Config.Bind<bool>("Network.Steam", "EnableSteamJunction", true, "Enable Steam Junction");
		logger.LogInfo((object)"Steam Junction v1.0.2 loaded!");
		logger.LogInfo((object)$"Config - Steam Junction Enabled: {EnableSteamJunction.Value}");
		CacheSteamManagerReflection();
		DetectCrewLateJoin();
		if (EnableSteamJunction.Value)
		{
			logger.LogInfo((object)"SteamJunction enabled in config, initializing...");
			InitializeSteamIntegration();
		}
		else
		{
			logger.LogInfo((object)"SteamJunction disabled in config, skipping initialization");
		}
		try
		{
			Harmony val = new Harmony("FluxTeam.SteamJunction");
			MethodInfo methodInfo = AccessTools.Method(typeof(NetworkManager), "OnCreatedRoom", (Type[])null, (Type[])null);
			HarmonyMethod val2 = new HarmonyMethod(typeof(NetworkManagerPatches), "OnCreatedRoom_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, val2, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(NetworkManager), "OnJoinedRoom", (Type[])null, (Type[])null);
			HarmonyMethod val3 = new HarmonyMethod(typeof(NetworkManagerPatches), "OnJoinedRoom_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo2, (HarmonyMethod)null, val3, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo3 = AccessTools.Method(typeof(NetworkManager), "OnDisconnected", (Type[])null, (Type[])null);
			HarmonyMethod val4 = new HarmonyMethod(typeof(NetworkManagerPatches), "OnDisconnected_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, val4, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo4 = AccessTools.Method(typeof(MainMenuController), "Start", (Type[])null, (Type[])null);
			HarmonyMethod val5 = new HarmonyMethod(typeof(MainMenuControllerPatches), "Start_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo4, (HarmonyMethod)null, val5, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo5 = AccessTools.Method(typeof(GameController), "StartNewMapRPC", (Type[])null, (Type[])null);
			HarmonyMethod val6 = new HarmonyMethod(typeof(GameControllerPatches), "StartNewMapRPC_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, val6, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo6 = AccessTools.Method(typeof(GameController), "GoToCheckpointRPC", (Type[])null, (Type[])null);
			HarmonyMethod val7 = new HarmonyMethod(typeof(GameControllerPatches), "GoToCheckpointRPC_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, val7, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo7 = AccessTools.Method(typeof(GameController), "ResetGameRPC", (Type[])null, (Type[])null);
			HarmonyMethod val8 = new HarmonyMethod(typeof(GameControllerPatches), "ResetGameRPC_Postfix", (Type[])null);
			val.Patch((MethodBase)methodInfo7, (HarmonyMethod)null, val8, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			logger.LogInfo((object)"Harmony patches applied successfully");
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Failed to apply Harmony patches: {arg}");
		}
	}

	private static void CacheSteamManagerReflection()
	{
		try
		{
			logger.LogInfo((object)"Caching SteamManager reflection...");
			Type typeFromHandle = typeof(SteamManager);
			_steamManagerInstanceProperty = typeFromHandle.GetProperty("Instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
			_steamManagerInitializedField = typeFromHandle.GetField("m_bInitialized", BindingFlags.Instance | BindingFlags.NonPublic);
			if (_steamManagerInstanceProperty == null)
			{
				logger.LogWarning((object)"Could not find SteamManager.Instance property");
			}
			if (_steamManagerInitializedField == null)
			{
				logger.LogWarning((object)"Could not find SteamManager.m_bInitialized field");
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error caching SteamManager reflection: {arg}");
		}
	}

	public static bool IsSteamInitialized()
	{
		try
		{
			SteamManager steamManagerInstance = GetSteamManagerInstance();
			if ((Object)(object)steamManagerInstance == (Object)null)
			{
				return false;
			}
			return GetSteamManagerInitialized(steamManagerInstance);
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error checking Steam initialization: {arg}");
			return false;
		}
	}

	private static SteamManager GetSteamManagerInstance()
	{
		if (_steamManagerInstanceProperty == null)
		{
			return null;
		}
		object? value = _steamManagerInstanceProperty.GetValue(null);
		return (SteamManager)((value is SteamManager) ? value : null);
	}

	private static bool GetSteamManagerInitialized(SteamManager instance)
	{
		if (_steamManagerInitializedField == null)
		{
			return false;
		}
		if ((Object)(object)instance == (Object)null)
		{
			return false;
		}
		try
		{
			return (bool)_steamManagerInitializedField.GetValue(instance);
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error getting initialized state: {arg}");
			return false;
		}
	}

	private static bool IsModLoaded(string guid)
	{
		return Chainloader.PluginInfos.ContainsKey(guid);
	}

	private static void DetectCrewLateJoin()
	{
		try
		{
			logger.LogInfo((object)"Checking for CrewLateJoin mod using BepInEx Chainloader...");
			if (IsModLoaded("com.fluxteam.crewlatejoin"))
			{
				logger.LogInfo((object)"✓ CrewLateJoin plugin detected via Chainloader (GUID: com.fluxteam.crewlatejoin)");
				SetupCrewLateJoinIntegration("com.fluxteam.crewlatejoin");
				return;
			}
			foreach (PluginInfo value in Chainloader.PluginInfos.Values)
			{
				if (value.Metadata.Name.Contains("Crew Late Join") || value.Metadata.Name.Contains("CrewLateJoin") || ((object)value.Instance).GetType().Name.Contains("CrewLateJoin"))
				{
					logger.LogInfo((object)("✓ CrewLateJoin plugin detected by name: " + value.Metadata.Name));
					SetupCrewLateJoinIntegration(value.Metadata.GUID);
					return;
				}
			}
			logger.LogInfo((object)"CrewLateJoin not detected - running in standalone mode");
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error detecting CrewLateJoin: {arg}");
			_crewLateJoinPresent = false;
		}
	}

	private static void SetupCrewLateJoinIntegration(string guid)
	{
		try
		{
			_crewLateJoinType = ((object)Chainloader.PluginInfos[guid].Instance).GetType();
			_allowLateJoinField = _crewLateJoinType.GetField("AllowLateJoin", BindingFlags.Static | BindingFlags.Public);
			if (_allowLateJoinField != null)
			{
				_crewLateJoinPresent = true;
				logger.LogInfo((object)"✓ CrewLateJoin AllowLateJoin field found - integration successful!");
			}
			else
			{
				logger.LogWarning((object)"⚠ CrewLateJoin found but missing AllowLateJoin field");
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error setting up CrewLateJoin integration: {arg}");
			_crewLateJoinPresent = false;
		}
	}

	public static bool IsAllowLateJoinEnabled()
	{
		if (!_crewLateJoinPresent)
		{
			return false;
		}
		try
		{
			object value = _allowLateJoinField.GetValue(null);
			if (value != null)
			{
				PropertyInfo property = value.GetType().GetProperty("Value");
				if (property != null)
				{
					return (bool)property.GetValue(value);
				}
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error checking AllowLateJoin state: {arg}");
		}
		return false;
	}

	private static void CheckForSteamLaunchParameters()
	{
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			logger.LogInfo((object)"Checking for Steam launch parameters...");
			string[] commandLineArgs = Environment.GetCommandLineArgs();
			for (int i = 0; i < commandLineArgs.Length; i++)
			{
				if (commandLineArgs[i] == "+connect_lobby" && i + 1 < commandLineArgs.Length)
				{
					string text = commandLineArgs[i + 1];
					logger.LogInfo((object)("Found Steam launch parameter +connect_lobby: " + text));
					if (ulong.TryParse(text, out var result))
					{
						logger.LogInfo((object)$"Parsed lobby ID: {result}, processing join...");
						CSteamID val = (pendingJoinLobby = new CSteamID(result));
						pendingJoinFromSteam = true;
						isJoiningRoom = true;
						SteamMatchmaking.RequestLobbyData(val);
					}
					break;
				}
			}
		}
		catch (Exception arg)
		{
			logger.LogError((object)$"Error checking Steam launch parameters: {arg}");
		}
	}

	private static void InitializeSteamIntegration()
	{
		logger.LogInfo((object)"=== INITIALIZE STEAM INTEGRATION CALLED ===");
		logger.LogInfo((object)$"isInitializing: {isInitializing}, isInitialized: {isInitialized}");
		if (isInitializing || isInitialized)
		{
			logger.LogInfo((object)"Already initializing or initialized, skipping");
			return;
		}
		isInitializing = true;
		EnsureCoroutineHelper();
		if ((Object)(object)coroutineHelper == (Object)null)
		{
			logger.LogError((object)"CRITICAL: coroutineHelper is still null after EnsureCoroutineHelper!");
			isInitializing = false;
		}
		else
		{
			logger.LogInfo((object)"Starting InitializeSteamCallbacks coroutine...");
			coroutineHelper.StartCoroutine(InitializeSteamCallbacksCoroutine());
		}
	}

	[IteratorStateMachine(typeof(<InitializeSteamCallbacksCoroutine>d__35))]
	private static IEnumerator InitializeSteamCallbacksCoroutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <InitializeSteamCallbacksCoroutine>d__35(0);
	}

	private static void EnsureCoroutineHelper()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		logger.LogInfo((object)("EnsureCoroutineHelper called - coroutineHelper = " + (((Object)(object)coroutineHelper == (Object)null) ? "NULL" : "NOT NULL")));
		if ((Object)(object)coroutineHelper == (Object)null)
		{
			logger.LogInfo((object)"Creating new coroutine helper GameObject...");
			GameObject val = new GameObject("SteamJunction_CoroutineHelper");
			coroutineHelper = (MonoBehaviour)(object)val.AddComponent<EmptyMonoBehaviour>();
			Object.DontDestroyOnLoad((Object)val);
			logger.LogInfo((object)"Created coroutine helper");
		}
		else
		{
			logger.LogInfo((object)"Coroutine helper already exists");
		}
	}

	private static void SafeStartCoroutine(IEnumerator coroutine)
	{
		logger.LogInfo((object)("SafeStartCoroutine called - coroutineHelper = " + (((Object)(object)coroutineHelper == (Object)null) ? "NULL" : "NOT NULL")));
		if ((Object)(object)coroutineHelper == (Object)null)
		{
			logger.LogInfo((object)"coroutineHelper is null, calling EnsureCoroutineHelper...");
			EnsureCoroutineHelper();
		}
		if ((Object)(object)coroutineHelper != (Object)null)
		{
			logger.LogInfo((object)"Starting coroutine...");
			coroutineHelper.StartCoroutine(coroutine);
		}
		else
		{
			logger.LogError((object)"CRITICAL: Cannot start coroutine - coroutineHelper is null!");
		}
	}

	private static void OnLobbyCreated(LobbyCreated_t callback)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Invalid comparison between Unknown and I4
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0098: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_0039: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)$"OnLobbyCreated - Result: {callback.m_eResult}, LobbyID: {callback.m_ulSteamIDLobby}");
		if ((int)callback.m_eResult == 1)
		{
			currentLobbyId = new CSteamID(callback.m_ulSteamIDLobby);
			logger.LogInfo((object)$"Steam lobby created: {currentLobbyId}");
			if (PhotonNetwork.InRoom)
			{
				logger.LogInfo((object)"Photon is in room, updating lobby data...");
				UpdateLobbyData();
			}
			else
			{
				logger.LogWarning((object)"Photon is NOT in room, cannot update lobby data");
			}
		}
		else
		{
			logger.LogError((object)$"Failed to create lobby: {callback.m_eResult}");
		}
	}

	private static void OnLobbyEntered(LobbyEnter_t callback)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: 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_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)$"OnLobbyEntered - LobbyID: {callback.m_ulSteamIDLobby}, ChatRoomEnterResponse: {callback.m_EChatRoomEnterResponse}");
		currentLobbyId = new CSteamID(callback.m_ulSteamIDLobby);
		logger.LogInfo((object)$"Entered Steam lobby: {currentLobbyId}");
	}

	private static void OnLobbyDataUpdate(LobbyDataUpdate_t callback)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0052: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)$"OnLobbyDataUpdate - LobbyID: {callback.m_ulSteamIDLobby}, Success: {callback.m_bSuccess}");
		logger.LogInfo((object)$"pendingJoinLobby: {pendingJoinLobby}, isJoiningRoom: {isJoiningRoom}");
		if (callback.m_ulSteamIDLobby == pendingJoinLobby.m_SteamID && isJoiningRoom)
		{
			logger.LogInfo((object)$"Processing lobby data update for pending join: {pendingJoinLobby}");
			SafeStartCoroutine(ProcessLobbyJoin(pendingJoinLobby));
		}
		else
		{
			logger.LogInfo((object)"Ignoring lobby data update - not for pending join or not in joining state");
		}
	}

	private static void OnJoinRequested(GameLobbyJoinRequested_t callback)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)"=== ON JOIN REQUESTED CALLBACK ===");
		logger.LogInfo((object)$"LobbyID: {callback.m_steamIDLobby}, FriendID: {callback.m_steamIDFriend}");
		logger.LogInfo((object)$"isJoiningRoom: {isJoiningRoom}, isInitialized: {isInitialized}, isInitializing: {isInitializing}");
		logger.LogInfo((object)("coroutineHelper: " + (((Object)(object)coroutineHelper == (Object)null) ? "NULL" : "NOT NULL")));
		if (isJoiningRoom)
		{
			logger.LogWarning((object)"Already processing a join request, ignoring new one");
			return;
		}
		if (!isInitialized)
		{
			logger.LogWarning((object)"Steam not fully initialized yet, queuing join request");
			SafeStartCoroutine(ProcessDelayedJoinRequest(callback.m_steamIDLobby));
			return;
		}
		pendingJoinLobby = callback.m_steamIDLobby;
		isJoiningRoom = true;
		logger.LogInfo((object)"Requesting lobby data...");
		bool flag = SteamMatchmaking.RequestLobbyData(callback.m_steamIDLobby);
		logger.LogInfo((object)$"Lobby data request result: {flag}");
		SafeStartCoroutine(JoinTimeoutCoroutine());
	}

	[IteratorStateMachine(typeof(<ProcessDelayedJoinRequest>d__42))]
	private static IEnumerator ProcessDelayedJoinRequest(CSteamID lobbyId)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ProcessDelayedJoinRequest>d__42(0)
		{
			lobbyId = lobbyId
		};
	}

	[IteratorStateMachine(typeof(<JoinTimeoutCoroutine>d__43))]
	private static IEnumerator JoinTimeoutCoroutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <JoinTimeoutCoroutine>d__43(0);
	}

	[IteratorStateMachine(typeof(<ProcessLobbyJoin>d__44))]
	private static IEnumerator ProcessLobbyJoin(CSteamID lobbyId)
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ProcessLobbyJoin>d__44(0)
		{
			lobbyId = lobbyId
		};
	}

	[IteratorStateMachine(typeof(<HandleJoinBasedOnGameState>d__45))]
	private static IEnumerator HandleJoinBasedOnGameState(string roomCode)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <HandleJoinBasedOnGameState>d__45(0)
		{
			roomCode = roomCode
		};
	}

	private static void ResetJoinState()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)"Resetting join state");
		isJoiningRoom = false;
		pendingJoinLobby = CSteamID.Nil;
		pendingRoomCode = null;
		pendingJoinFromSteam = false;
	}

	public static void UpdateLobbyData()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		logger.LogInfo((object)$"UpdateLobbyData called - currentLobbyId: {currentLobbyId}, EnableSteamJunction: {EnableSteamJunction.Value}");
		if (currentLobbyId == CSteamID.Nil || !EnableSteamJunction.Value)
		{
			logger.LogInfo((object)"Cannot update lobby data - no active lobby or disabled");
		}
		else if (PhotonNetwork.InRoom)
		{
			string name = PhotonNetwork.CurrentRoom.Name;
			logger.LogInfo((object)("Updating lobby data for room: " + name));
			bool flag = SteamMatchmaking.SetLobbyData(currentLobbyId, "RoomCode", name);
			bool flag2 = SteamMatchmaking.SetLobbyData(currentLobbyId, "Version", Application.version);
			logger.LogInfo((object)$"Lobby data set - RoomCode: {flag}, Version: {flag2}");
			if (((Dictionary<object, object>)(object)((RoomInfo)PhotonNetwork.CurrentRoom).CustomProperties).TryGetValue((object)"CREW", out object value))
			{
				bool flag3 = SteamMatchmaking.SetLobbyData(currentLobbyId, "CrewName", value.ToString());
				logger.LogInfo((object)$"CrewName set: {flag3}, Value: {value}");
			}
			else
			{
				logger.LogInfo((object)"No CREW property found in room custom properties");
			}
			logger.LogInfo((object)("Lobby data updated for room: " + name));
		}
		else
		{
			logger.LogInfo((object)"Cannot update lobby data - not in a Photon room");
		}
	}

	public static void SetLobbyInProgress(bool inProgress)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		if (currentLobbyId == CSteamID.Nil)
		{
			logger.LogWarning((object)"Cannot set Lobby State - No active Lobby");
		}
		else if (EnableSteamJunction.Value)
		{
			string text = (inProgress ? "true" : "false");
			SteamMatchmaking.SetLobbyData(currentLobbyId, "InProgress", text);
			if (!IsAllowLateJoinEnabled())
			{
				bool flag = !inProgress;
				SteamMatchmaking.SetLobbyJoinable(currentLobbyId, flag);
				logger.LogInfo((object)string.Format("Steam lobby set to {0} (Joinable: {1})", inProgress ? "IN PROGRESS" : "WAITING", flag));
			}
			else
			{
				SteamMatchmaking.SetLobbyJoinable(currentLobbyId, true);
				logger.LogInfo((object)("Steam lobby state set to " + (inProgress ? "IN PROGRESS" : "WAITING") + " (Still joinable due to AllowLateJoin)"));
			}
		}
	}

	public static void LockLobby()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (!(currentLobbyId == CSteamID.Nil) && EnableSteamJunction.Value)
		{
			SteamMatchmaking.SetLobbyJoinable(currentLobbyId, false);
			logger.LogInfo((object)"Lobby manually locked");
		}
	}

	public static void UnlockLobby()
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		if (!(currentLobbyId == CSteamID.Nil) && EnableSteamJunction.Value)
		{
			SteamMatchmaking.SetLobbyJoinable(currentLobbyId, true);
			logger.LogInfo((object)"Lobby manually unlocked");
		}
	}

	public static void OpenInviteOverlay()
	{
		//IL_001c: 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)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		if (!EnableSteamJunction.Value)
		{
			logger.LogWarning((object)"Steam Junction is Disabled in config");
		}
		else if (currentLobbyId != CSteamID.Nil && IsSteamInitialized())
		{
			if (SteamMatchmaking.GetLobbyData(currentLobbyId, "InProgress") == "true" && !IsAllowLateJoinEnabled())
			{
				logger.LogWarning((object)"Cannot Invite - Game is already in progress and Allow Late Join is Disabled");
				TerminalManager obj = TerminalManager.instance;
				if (obj != null)
				{
					obj.QueueTextLine("Cannot Invite - Game is already in progress", new Vector2(1f, 0f), 0.075f, (AudioClip)null, 0f);
				}
			}
			else
			{
				SteamFriends.ActivateGameOverlayInviteDialog(currentLobbyId);
				logger.LogInfo((object)"Opened Steam invite overlay");
			}
		}
		else
		{
			logger.LogWarning((object)"Cannot open Invite Overlay - No active Lobby");
		}
	}
}
public static class NetworkManagerPatches
{
	public static void OnCreatedRoom_Postfix()
	{
		//IL_004b: Unknown result type (might be due to invalid IL or missing references)
		if (SteamJunction.EnableSteamJunction.Value && PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient)
		{
			SteamJunction.logger.LogInfo((object)("Creating Steam lobby for room: " + PhotonNetwork.CurrentRoom.Name));
			SteamMatchmaking.CreateLobby((ELobbyType)((!PhotonNetwork.CurrentRoom.IsVisible) ? 1 : 2), 6);
		}
	}

	public static void OnJoinedRoom_Postfix()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		if (SteamJunction.EnableSteamJunction.Value && SteamJunction.currentLobbyId != CSteamID.Nil)
		{
			SteamJunction.UpdateLobbyData();
		}
	}

	public static void OnDisconnected_Postfix(DisconnectCause cause)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_0028: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		if (SteamJunction.EnableSteamJunction.Value && SteamJunction.currentLobbyId != CSteamID.Nil)
		{
			SteamJunction.logger.LogInfo((object)$"Leaving Steam lobby on disconnect (cause: {cause})");
			SteamMatchmaking.LeaveLobby(SteamJunction.currentLobbyId);
			SteamJunction.currentLobbyId = CSteamID.Nil;
		}
	}
}
public static class MainMenuControllerPatches
{
	public static void Start_Postfix(MainMenuController __instance)
	{
		if (SteamJunction.EnableSteamJunction.Value && SteamJunction.pendingJoinFromSteam && !string.IsNullOrEmpty(SteamJunction.pendingRoomCode))
		{
			SteamJunction.logger.LogInfo((object)("Main menu loaded with pending Steam join for room: " + SteamJunction.pendingRoomCode));
			FieldInfo field = typeof(MainMenuController).GetField("roomCode", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(MainMenuController).GetField("action", BindingFlags.Instance | BindingFlags.Public);
			if (field != null && field2 != null)
			{
				field.SetValue(__instance, SteamJunction.pendingRoomCode);
				field2.SetValue(__instance, (object)(ActionTypes)3);
				__instance.GoToGameScene();
				SteamJunction.pendingJoinFromSteam = false;
				SteamJunction.pendingRoomCode = null;
			}
		}
	}
}
public static class GameControllerPatches
{
	public static void StartNewMapRPC_Postfix()
	{
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		if (PhotonNetwork.IsMasterClient && SteamJunction.EnableSteamJunction.Value)
		{
			SteamJunction.logger.LogInfo((object)"Game started (StartNewMapRPC) - Marking Steam Lobby as In Progress");
			if (SteamJunction.IsAllowLateJoinEnabled())
			{
				SteamJunction.SetLobbyInProgress(inProgress: true);
				SteamMatchmaking.SetLobbyJoinable(SteamJunction.currentLobbyId, true);
				SteamJunction.logger.LogInfo((object)"AllowLateJoin Enabled - Steam Lobby will remain Joinable");
			}
			else
			{
				SteamJunction.SetLobbyInProgress(inProgress: true);
			}
		}
	}

	public static void GoToCheckpointRPC_Postfix()
	{
		if (PhotonNetwork.IsMasterClient && SteamJunction.EnableSteamJunction.Value)
		{
			SteamJunction.logger.LogInfo((object)"Returned to Checkpoint - Marking Steam Lobby as Waiting");
			SteamJunction.SetLobbyInProgress(inProgress: false);
		}
	}

	public static void ResetGameRPC_Postfix()
	{
		if (PhotonNetwork.IsMasterClient && SteamJunction.EnableSteamJunction.Value)
		{
			SteamJunction.logger.LogInfo((object)"Game Reset - Marking Steam Lobby as Waiting");
			SteamJunction.SetLobbyInProgress(inProgress: false);
		}
	}
}
public class EmptyMonoBehaviour : MonoBehaviour
{
	private void Awake()
	{
		SteamJunction.logger.LogInfo((object)"EmptyMonoBehaviour Awake called");
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
	}

	private void OnDestroy()
	{
		SteamJunction.logger.LogInfo((object)"EmptyMonoBehaviour OnDestroy called");
	}
}