using System;
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 Microsoft.CodeAnalysis;
using MorePlayers.Patches;
using Ox1;
[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("MorePlayers")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1+35dee5b5040d45b60425871720df4c0fa6e384c8")]
[assembly: AssemblyProduct("MorePlayers")]
[assembly: AssemblyTitle("MorePlayers")]
[assembly: AssemblyVersion("0.1.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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 MorePlayers
{
internal sealed class ConfigurationManagerAttributes
{
public string DispName;
public int? Order;
}
[BepInPlugin("com.darkharasho.trashday.moreplayers", "MorePlayers", "0.1.1")]
public class Plugin : BaseUnityPlugin
{
public const string PluginGuid = "com.darkharasho.trashday.moreplayers";
public const string PluginName = "MorePlayers";
public const string PluginVersion = "0.1.1";
internal static ManualLogSource Log;
internal static ConfigEntry<int> MaxPlayers;
private Harmony _harmony;
private void Awake()
{
//IL_0046: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: Expected O, but got Unknown
//IL_0084: Unknown result type (might be due to invalid IL or missing references)
//IL_008e: Expected O, but got Unknown
Log = ((BaseUnityPlugin)this).Logger;
MaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxPlayers", 12, new ConfigDescription("Most players allowed in a lobby you host, including you. The game's default is 6. Only the host needs this mod. Changing it while hosting updates the current lobby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 250), new object[1]
{
new ConfigurationManagerAttributes
{
DispName = "Max players"
}
}));
MaxPlayers.SettingChanged += delegate
{
MaxPlayersCap.ApplyLive();
};
_harmony = new Harmony("com.darkharasho.trashday.moreplayers");
try
{
_harmony.PatchAll();
}
catch (Exception arg)
{
Log.LogError((object)$"Patching failed, likely a game update; the player cap stays at the game's default. {arg}");
_harmony.UnpatchSelf();
return;
}
MaxPlayersCap.Apply();
Log.LogInfo((object)string.Format("{0} {1} loaded (max players {2})", "MorePlayers", "0.1.1", MaxPlayers.Value));
}
private void OnDestroy()
{
Harmony harmony = _harmony;
if (harmony != null)
{
harmony.UnpatchSelf();
}
}
}
}
namespace MorePlayers.Patches
{
internal static class MaxPlayersCap
{
private static readonly MethodInfo Setter = AccessTools.PropertySetter(typeof(OnlineLobbyManager), "MaxConnectedPlayers");
private static readonly MethodInfo SetMaxPlayersCommand = AccessTools.Method(typeof(OnlineLobbyManager), "SetMaxPlayersCommand", new Type[1] { typeof(int) }, (Type[])null);
private static bool _loggedFailure;
internal static void Apply()
{
try
{
ApplyCore();
}
catch (Exception e)
{
LogFailureOnce(e);
}
}
internal static void ApplyLive()
{
try
{
ApplyLiveCore();
}
catch (Exception e)
{
LogFailureOnce(e);
}
}
internal static void ApplyWithLobbyData()
{
try
{
ApplyCore();
SetLobbyMaxPlayers();
}
catch (Exception e)
{
LogFailureOnce(e);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void ApplyCore()
{
int value = Plugin.MaxPlayers.Value;
if (OnlineLobbyManager.MaxConnectedPlayers != value)
{
if (Setter == null)
{
throw new MissingMemberException("OnlineLobbyManager", "MaxConnectedPlayers setter");
}
Setter.Invoke(null, new object[1] { value });
Plugin.Log.LogInfo((object)$"Max players: {value}");
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void ApplyLiveCore()
{
if (!OnlineLobbyManager.IsLobbyOwner)
{
ApplyCore();
return;
}
if (SetMaxPlayersCommand == null)
{
throw new MissingMemberException("OnlineLobbyManager", "SetMaxPlayersCommand");
}
SetMaxPlayersCommand.Invoke(null, new object[1] { Plugin.MaxPlayers.Value });
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void SetLobbyMaxPlayers()
{
OnlineLobbyManager.SetLobbyData("MaxPlayers", OnlineLobbyManager.MaxConnectedPlayers.ToString());
}
private static void LogFailureOnce(Exception e)
{
if (!_loggedFailure)
{
_loggedFailure = true;
Plugin.Log.LogError((object)$"Couldn't set the player cap, likely a game update; it may stay at the game's default. {e}");
}
}
}
[HarmonyPatch(typeof(OnlineLobbyManager), "CreateLobby")]
internal static class ApplyBeforeCreateLobbyPatch
{
private static void Prefix()
{
MaxPlayersCap.Apply();
}
}
[HarmonyPatch(typeof(OnlineLobbyManager), "RequestCreateLobby")]
internal static class ApplyBeforeRequestCreateLobbyPatch
{
private static void Prefix()
{
MaxPlayersCap.ApplyWithLobbyData();
}
}
}