Decompiled source of MorePlayersSimple v1.1.4

plugins/MorePlayersSimple.dll

Decompiled 6 days ago
using System;
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;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MorePlayersSimple")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MorePlayersSimple")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e414bffa-f261-43ba-b6c5-3c2f5941d3af")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MorePlayersSimple;

[BepInPlugin("dyxc666.MorePlayersSimple", "More Players Simple", "1.1.1")]
public class MorePlayersSimplePlugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	public static ConfigEntry<int> MaxPlayersPublic;

	public static ConfigEntry<int> MaxPlayersPrivate;

	internal static string SelfCreatedRoomName = string.Empty;

	private readonly Harmony harmony = new Harmony("dyxc666.MorePlayersSimple");

	private void Awake()
	{
		//IL_0030: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_006c: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		MaxPlayersPublic = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayersPublic", 20, new ConfigDescription("公开房间最大玩家数(1-20)。修改后需重新开房生效。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
		MaxPlayersPrivate = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayersPrivate", 6, new ConfigDescription("私人房间最大玩家数(1-20)。Photon 免费套餐对私人房间有 6 人硬性限制,超过可能无效。", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 20), Array.Empty<object>()));
		harmony.PatchAll();
		Log.LogInfo((object)$"More Players Simple loaded! Public={MaxPlayersPublic.Value}, Private={MaxPlayersPrivate.Value}");
	}
}
[HarmonyPatch(typeof(LoadBalancingClient), "OpCreateRoom")]
public static class OpCreateRoomPatch
{
	[HarmonyPrefix]
	public static bool Prefix(EnterRoomParams enterRoomParams)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		if (enterRoomParams.RoomOptions == null)
		{
			enterRoomParams.RoomOptions = new RoomOptions();
		}
		bool isVisible = enterRoomParams.RoomOptions.IsVisible;
		byte b = (byte)(isVisible ? MorePlayersSimplePlugin.MaxPlayersPublic.Value : MorePlayersSimplePlugin.MaxPlayersPrivate.Value);
		enterRoomParams.RoomOptions.MaxPlayers = b;
		enterRoomParams.RoomOptions.PlayerTtl = 0;
		enterRoomParams.RoomOptions.EmptyRoomTtl = 0;
		if (!string.IsNullOrEmpty(enterRoomParams.RoomName))
		{
			MorePlayersSimplePlugin.SelfCreatedRoomName = enterRoomParams.RoomName;
		}
		MorePlayersSimplePlugin.Log.LogInfo((object)string.Format("OpCreateRoom [{0}]: MaxPlayers = {1}", isVisible ? "PUBLIC" : "PRIVATE", b));
		return true;
	}
}
[HarmonyPatch(typeof(LoadBalancingClient), "OpJoinOrCreateRoom")]
public static class OpJoinOrCreateRoomPatch
{
	[HarmonyPrefix]
	public static bool Prefix(EnterRoomParams enterRoomParams)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		if (enterRoomParams.RoomOptions == null)
		{
			enterRoomParams.RoomOptions = new RoomOptions();
		}
		bool isVisible = enterRoomParams.RoomOptions.IsVisible;
		byte b = (byte)(isVisible ? MorePlayersSimplePlugin.MaxPlayersPublic.Value : MorePlayersSimplePlugin.MaxPlayersPrivate.Value);
		enterRoomParams.RoomOptions.MaxPlayers = b;
		enterRoomParams.RoomOptions.PlayerTtl = 0;
		enterRoomParams.RoomOptions.EmptyRoomTtl = 0;
		if (!string.IsNullOrEmpty(enterRoomParams.RoomName))
		{
			MorePlayersSimplePlugin.SelfCreatedRoomName = enterRoomParams.RoomName;
		}
		MorePlayersSimplePlugin.Log.LogInfo((object)string.Format("[JoinOrCreate] [{0}]: MaxPlayers = {1}", isVisible ? "PUBLIC" : "PRIVATE", b));
		return true;
	}
}
[HarmonyPatch(typeof(SteamManager), "HostLobby")]
public static class HostLobbyPatch
{
	[HarmonyPostfix]
	public static void Postfix(SteamManager __instance)
	{
		try
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(SteamManager), "currentLobby");
			if (fieldInfo == null)
			{
				return;
			}
			object value = fieldInfo.GetValue(__instance);
			if (value == null)
			{
				return;
			}
			int num = ((PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null && !PhotonNetwork.CurrentRoom.IsVisible) ? MorePlayersSimplePlugin.MaxPlayersPrivate.Value : MorePlayersSimplePlugin.MaxPlayersPublic.Value);
			Type type = value.GetType();
			MethodInfo method = type.GetMethod("SetLobbyMemberLimit");
			if (method != null)
			{
				method.Invoke(value, new object[1] { num });
				MorePlayersSimplePlugin.Log.LogInfo((object)$"Steam Lobby member limit set to {num}");
				return;
			}
			FieldInfo fieldInfo2 = type.GetField("MaxMembers") ?? type.GetField("maxMembers");
			if (fieldInfo2 != null)
			{
				fieldInfo2.SetValue(value, num);
				MorePlayersSimplePlugin.Log.LogInfo((object)$"Steam Lobby MaxMembers field set to {num}");
			}
		}
		catch
		{
			MorePlayersSimplePlugin.Log.LogWarning((object)"Failed to set Steam lobby member limit.");
		}
	}
}
[HarmonyPatch(typeof(MenuPageServerList), "CreateServerElement")]
public static class CreateServerElementPatch
{
	[HarmonyPrefix]
	public static bool Prefix(object _room)
	{
		if (_room == null)
		{
			return true;
		}
		FieldInfo field = _room.GetType().GetField("roomName", BindingFlags.Instance | BindingFlags.Public);
		if (field == null)
		{
			return true;
		}
		string text = field.GetValue(_room) as string;
		if (string.IsNullOrEmpty(text))
		{
			return true;
		}
		bool flag = text == MorePlayersSimplePlugin.SelfCreatedRoomName;
		if (!flag && PhotonNetwork.InRoom && PhotonNetwork.CurrentRoom != null)
		{
			flag = text == PhotonNetwork.CurrentRoom.Name;
		}
		if (flag)
		{
			_room.GetType().GetField("maxPlayers", BindingFlags.Instance | BindingFlags.Public)?.SetValue(_room, MorePlayersSimplePlugin.MaxPlayersPublic.Value);
		}
		return true;
	}
}