using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Mirror;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("GambleMaxPlayers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.1.0")]
[assembly: AssemblyInformationalVersion("1.0.1+efa243a6cb2485fc08631e5c324ba8cfbedd81f6")]
[assembly: AssemblyProduct("GambleMaxPlayers")]
[assembly: AssemblyTitle("GambleMaxPlayers")]
[assembly: AssemblyVersion("1.0.1.0")]
namespace GambleMaxPlayers;
[HarmonyPatch(typeof(NetworkServer), "Listen")]
internal static class NetworkServerListenPatch
{
private static void Prefix(ref int maxConns)
{
maxConns = Plugin.MaxPlayers.Value;
Plugin.Log.LogInfo((object)$"NetworkServer.Listen patch fired — set maxConns to {maxConns}");
}
}
[HarmonyPatch(typeof(SpawnBoxPlayerRagdollTrigger), "AssignPlayer")]
internal static class SpawnWakeFixPatch
{
[CompilerGenerated]
private sealed class <FinalWakeRoutine>d__1 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PlayerController pc;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <FinalWakeRoutine>d__1(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0034: Unknown result type (might be due to invalid IL or missing references)
//IL_003e: Expected O, but got Unknown
//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Expected O, but got Unknown
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 1;
return true;
case 1:
<>1__state = -1;
if ((Object)(object)pc == (Object)null)
{
return false;
}
SafeInvoke(pc, "ServerLock", false);
pc.LocalLock(false);
SafeInvoke(pc, "ServerWakeUp");
<>2__current = (object)new WaitForSeconds(0.5f);
<>1__state = 2;
return true;
case 2:
<>1__state = -1;
SafeInvoke(pc, "ServerLock", false);
pc.LocalLock(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();
}
}
[HarmonyPostfix]
private static void AssignPlayerPatch(PlayerController player)
{
if (!((Object)(object)player == (Object)null) && NetworkServer.active)
{
((MonoBehaviour)player).StartCoroutine(FinalWakeRoutine(player));
}
}
[IteratorStateMachine(typeof(<FinalWakeRoutine>d__1))]
private static IEnumerator FinalWakeRoutine(PlayerController pc)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <FinalWakeRoutine>d__1(0)
{
pc = pc
};
}
private static void SafeInvoke(object obj, string methodName, params object[] args)
{
obj.GetType().GetMethod(methodName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(obj, args);
}
}
[BepInPlugin("com.gamblewithfriends.maxplayers", "GambleMaxPlayers", "1.0.1")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.gamblewithfriends.maxplayers";
public const string PluginName = "GambleMaxPlayers";
public const string PluginVersion = "1.0.1";
internal static ConfigEntry<int> MaxPlayers;
internal static ManualLogSource Log;
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_00a2: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
MaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 10, new ConfigDescription("Maximum number of players allowed in a lobby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 100), Array.Empty<object>()));
LobbySettings val = Resources.Load<LobbySettings>("LobbySettings");
if ((Object)(object)val != (Object)null)
{
val.maxPlayers = MaxPlayers.Value;
((BaseUnityPlugin)this).Logger.LogInfo((object)$"Set LobbySettings.maxPlayers to {val.maxPlayers}");
}
else
{
((BaseUnityPlugin)this).Logger.LogWarning((object)"LobbySettings resource not found — lobby size NOT changed.");
}
new Harmony("com.gamblewithfriends.maxplayers").PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)string.Format("{0} loaded — max players: {1}", "GambleMaxPlayers", MaxPlayers.Value));
}
}