using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using Steamworks.Data;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("AdjustMaxPlayers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AdjustMaxPlayers")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("332fb87a-6417-4a3c-b614-543d93450b34")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MorePlayers;
[BepInPlugin("zelofi.MorePlayers", "MorePlayers", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
[HarmonyPatch(typeof(NetworkConnect), "TryJoiningRoom")]
public class TryJoiningRoomPatch
{
private static bool Prefix(ref string ___RoomName)
{
//IL_0059: Unknown result type (might be due to invalid IL or missing references)
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Expected O, but got Unknown
if (string.IsNullOrEmpty(___RoomName))
{
mls.LogError((object)"RoomName is null or empty, using previous method!");
return true;
}
if (configMaxPlayers.Value == 0)
{
mls.LogError((object)"The MaxPlayers config is null or empty, using previous method!");
return true;
}
if ((Object)(object)NetworkConnect.instance != (Object)null)
{
PhotonNetwork.JoinOrCreateRoom(___RoomName, new RoomOptions
{
MaxPlayers = configMaxPlayers.Value
}, TypedLobby.Default, (string[])null);
return false;
}
mls.LogError((object)"NetworkConnect instance is null, using previous method!");
return true;
}
}
[HarmonyPatch(typeof(SteamManager), "HostLobby")]
public class HostLobbyPatch
{
private static bool Prefix()
{
HostLobbyAsync();
return false;
}
private static async void HostLobbyAsync()
{
Debug.Log((object)"Steam: Hosting lobby...");
Lobby? lobby = await SteamMatchmaking.CreateLobbyAsync(configMaxPlayers.Value);
if (!lobby.HasValue)
{
Debug.LogError((object)"Lobby created but not correctly instantiated.");
return;
}
Lobby value = lobby.Value;
((Lobby)(ref value)).SetPublic();
value = lobby.Value;
((Lobby)(ref value)).SetJoinable(false);
}
}
public const string modGUID = "zelofi.MorePlayers";
public const string modName = "MorePlayers";
public const string modVersion = "1.0.1";
private readonly Harmony harmony = new Harmony("zelofi.MorePlayers");
public static ConfigEntry<int> configMaxPlayers;
public static ManualLogSource mls;
private void Awake()
{
mls = Logger.CreateLogSource("zelofi.MorePlayers");
mls.LogInfo((object)"zelofi.MorePlayers is now awake!");
configMaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 10, "The max amount of players allowed in a server");
harmony.PatchAll(typeof(TryJoiningRoomPatch));
harmony.PatchAll(typeof(HostLobbyPatch));
}
}