using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterLobby")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1")]
[assembly: AssemblyProduct("BetterLobby")]
[assembly: AssemblyTitle("BetterLobby")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.1.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 BetterLobby
{
[BepInPlugin("BetterLobby", "BetterLobby", "1.0.1")]
public sealed class Plugin : BaseUnityPlugin
{
public static ManualLogSource CurLogger { get; private set; }
private void Awake()
{
CurLogger = ((BaseUnityPlugin)this).Logger;
}
private void OnEnable()
{
SceneManager.sceneLoaded += OnSceneLoaded;
}
private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
{
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
if (!GameUtils.IsOnSurface)
{
return;
}
if ((Object)(object)PlayerHandler.instance != (Object)null)
{
PlayerHandler instance = PlayerHandler.instance;
instance.OnPlayerJoined = (Action<Player>)Delegate.Combine(instance.OnPlayerJoined, (Action<Player>)delegate(Player player)
{
((MonoBehaviour)this).StartCoroutine(OnPlayerJoined(player));
});
}
EscapeMenuUtils.CreateButton("FILL", "FILL LOBBY", new UnityAction(OnFillPress));
}
private IEnumerator OnPlayerJoined(Player player)
{
int num = LobbyUtils.CurPlayers ?? 1;
int num2 = LobbyUtils.MaxPlayers ?? 4;
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Player has joined the lobby! {num} / {num2}");
if (num >= num2 && SurfaceNetworkHandler.HasStarted && LobbyUtils.IsOpen)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Maximum number of players reached, closing lobby...");
LobbyUtils.StopAccepting();
}
yield return (object)new WaitForSeconds(2f);
if (!SurfaceNetworkHandler.HasStarted)
{
yield break;
}
((BaseUnityPlugin)this).Logger.LogInfo((object)"Game has already started, sending RPCA_OpenDoor to the late-joiner...");
SurfaceNetworkHandler instance = SurfaceNetworkHandler.Instance;
if (instance != null)
{
PhotonView photonView = ((MonoBehaviourPun)instance).photonView;
if (photonView != null)
{
photonView.RPC("RPCA_OpenDoor", (RpcTarget)0, new object[0]);
}
}
}
private void OnFillPress()
{
int num = PlayerHandler.instance?.players.Count ?? 1;
int num2 = LobbyUtils.MaxPlayers ?? 4;
if (num >= num2)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"Lobby is already full, will not make it public.");
}
else if (!GameUtils.IsOnSurface)
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"You need to be on surface to fill the lobby!");
}
else
{
LobbyUtils.MakePublic();
}
}
}
internal sealed class GameUtils : MonoBehaviour
{
internal static bool IsOnSurface => Object.FindObjectOfType<DivingBell>()?.onSurface ?? false;
}
internal sealed class EscapeMenuUtils : MonoBehaviour
{
internal static bool CreateButton(string name, string text, UnityAction action)
{
GameObject val = FindButtonList();
if ((Object)(object)val == (Object)null)
{
ManualLogSource curLogger = Plugin.CurLogger;
if (curLogger != null)
{
curLogger.LogError((object)"Failed to find the EscapeMenu control list!");
}
return false;
}
Transform obj = val.transform.Find("RESUME");
GameObject val2 = ((obj != null) ? ((Component)obj).gameObject : null);
if ((Object)(object)val2 == (Object)null)
{
ManualLogSource curLogger2 = Plugin.CurLogger;
if (curLogger2 != null)
{
curLogger2.LogError((object)"Failed to find the 'RESUME' control!");
}
return false;
}
GameObject val3 = Object.Instantiate<GameObject>(val2, val.transform);
((Object)val3).name = name;
Button componentInChildren = val3.GetComponentInChildren<Button>();
if ((Object)(object)componentInChildren == (Object)null)
{
ManualLogSource curLogger3 = Plugin.CurLogger;
if (curLogger3 != null)
{
curLogger3.LogError((object)"Failed to find the Button component!");
}
Object.Destroy((Object)(object)val3);
return false;
}
TextMeshProUGUI componentInChildren2 = val3.GetComponentInChildren<TextMeshProUGUI>();
if ((Object)(object)componentInChildren2 == (Object)null)
{
ManualLogSource curLogger4 = Plugin.CurLogger;
if (curLogger4 != null)
{
curLogger4.LogError((object)"Failed to find the TextMeshProUGUI component!");
}
Object.Destroy((Object)(object)val3);
return false;
}
((UnityEvent)componentInChildren.onClick).AddListener(action);
((TMP_Text)componentInChildren2).SetCharArray(text.ToCharArray());
((Graphic)componentInChildren2).SetAllDirty();
return true;
}
private static GameObject FindButtonList()
{
Transform? obj2 = ((IEnumerable<Transform>)Resources.FindObjectsOfTypeAll<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform obj) => ((Object)obj).name == "EscapeMenu"));
if (obj2 == null)
{
return null;
}
Transform obj3 = obj2.Find("MainPage/LIST");
if (obj3 == null)
{
return null;
}
return ((Component)obj3).gameObject;
}
}
internal static class LobbyUtils
{
internal static bool IsOpen;
private static bool MasterClient
{
get
{
SteamLobbyHandler steamLobbyHandler = MainMenuHandler.SteamLobbyHandler;
if (steamLobbyHandler == null)
{
return false;
}
return steamLobbyHandler.MasterClient;
}
}
private static CSteamID? CurrentID
{
get
{
//IL_0025: Unknown result type (might be due to invalid IL or missing references)
if (MainMenuHandler.SteamLobbyHandler == null)
{
return null;
}
return Traverse.Create((object)MainMenuHandler.SteamLobbyHandler).Field("m_CurrentLobby").GetValue<CSteamID>();
}
}
internal static int? CurPlayers => PlayerHandler.instance?.players.Count;
internal static int? MaxPlayers
{
get
{
if (MainMenuHandler.SteamLobbyHandler == null)
{
return null;
}
return Traverse.Create((object)MainMenuHandler.SteamLobbyHandler).Field("m_MaxPlayers").GetValue<int>();
}
}
internal static bool MakePublic()
{
//IL_0046: 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)
CSteamID? currentID = CurrentID;
if (!currentID.HasValue)
{
ManualLogSource curLogger = Plugin.CurLogger;
if (curLogger != null)
{
curLogger.LogWarning((object)"Cannot make the lobby public because it does not exist.");
}
return false;
}
if (!MasterClient)
{
ManualLogSource curLogger2 = Plugin.CurLogger;
if (curLogger2 != null)
{
curLogger2.LogWarning((object)"Cannot make the lobby public because you are not the master client.");
}
return false;
}
SteamMatchmaking.SetLobbyType(currentID.Value, (ELobbyType)2);
SetJoinable(currentID.Value, value: true);
return true;
}
internal static bool StopAccepting()
{
//IL_001a: Unknown result type (might be due to invalid IL or missing references)
CSteamID? currentID = CurrentID;
if (!currentID.HasValue || !MasterClient)
{
return false;
}
SetJoinable(currentID.Value, value: false);
return true;
}
private static void SetJoinable(CSteamID id, bool value)
{
//IL_0000: Unknown result type (might be due to invalid IL or missing references)
SteamMatchmaking.SetLobbyJoinable(id, value);
if (PhotonNetwork.CurrentRoom != null)
{
PhotonNetwork.CurrentRoom.IsOpen = value;
PhotonNetwork.CurrentRoom.IsVisible = value;
}
}
static LobbyUtils()
{
Room currentRoom = PhotonNetwork.CurrentRoom;
int isOpen;
if (currentRoom != null && currentRoom.IsOpen)
{
Room currentRoom2 = PhotonNetwork.CurrentRoom;
isOpen = ((currentRoom2 != null && currentRoom2.IsVisible) ? 1 : 0);
}
else
{
isOpen = 0;
}
IsOpen = (byte)isOpen != 0;
}
}
public static class PluginInfo
{
public const string PLUGIN_GUID = "BetterLobby";
public const string PLUGIN_NAME = "BetterLobby";
public const string PLUGIN_VERSION = "1.0.1";
}
}