using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Discord;
using Gatekeeper.MainMenuScripts.MainMenu.CharacterSelectPanel;
using Gatekeeper.MainMenuScripts.MainMenu.LobbyBrowser;
using HarmonyLib;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Discord.SDK")]
[assembly: IgnoresAccessChecksTo("Gatekeeper")]
[assembly: IgnoresAccessChecksTo("Unity.TextMeshPro")]
[assembly: IgnoresAccessChecksTo("UnityEngine.CoreModule")]
[assembly: IgnoresAccessChecksTo("UnityEngine.UI")]
[assembly: AssemblyCompany("ExtendedPlayerCount")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+5a307bb30b28601d5c91f4317fb4f3729fd492aa")]
[assembly: AssemblyProduct("ExtendedPlayerCount")]
[assembly: AssemblyTitle("ExtendedPlayerCount")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
internal sealed class NullableAttribute : Attribute
{
public readonly byte[] NullableFlags;
public NullableAttribute(byte P_0)
{
NullableFlags = new byte[1] { P_0 };
}
public NullableAttribute(byte[] P_0)
{
NullableFlags = P_0;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
internal sealed class NullableContextAttribute : Attribute
{
public readonly byte Flag;
public NullableContextAttribute(byte P_0)
{
Flag = P_0;
}
}
}
namespace ExtendedPlayerCount
{
public static class LobbyPatches
{
private static CharactersMenuController? _patchedInstance;
private static int _patchedMaxPlayers;
public static void ApplyAll(Harmony harmony)
{
harmony.PatchAll(typeof(LobbyPatches));
Plugin.Log.LogInfo((object)"[ExtendedPlayerCount] All patches applied.");
}
[HarmonyPatch(typeof(LobbyTransaction), "SetCapacity")]
[HarmonyPrefix]
private static void SetCapacity_Prefix(ref uint capacity)
{
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
//IL_0017: Expected O, but got Unknown
capacity = (uint)PlayerCountConfig.MaxPlayers;
ManualLogSource log = Plugin.Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(36, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ExtendedPlayerCount] SetCapacity → ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(capacity);
}
log.LogInfo(val);
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
[HarmonyPostfix]
private static void MaxMembers_Postfix(ref int __result)
{
if (__result < PlayerCountConfig.MaxPlayers)
{
__result = PlayerCountConfig.MaxPlayers;
}
}
[HarmonyPatch(typeof(LobbyBrowserLine), "Setup")]
[HarmonyPostfix]
private static void LobbyBrowserLine_Setup_Postfix(LobbyBrowserLine __instance)
{
//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
//IL_00c6: Expected O, but got Unknown
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Expected O, but got Unknown
bool flag = default(bool);
try
{
string text = __instance.playersText.text;
if (!text.Contains("/"))
{
return;
}
string[] array = text.Split('/');
if (array.Length == 2)
{
string text2 = $"{array[0]}/{PlayerCountConfig.MaxPlayers}";
__instance.playersText.text = text2;
ManualLogSource log = Plugin.Log;
BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(43, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ExtendedPlayerCount] LobbyBrowserLine: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" → ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
}
log.LogDebug(val);
}
}
catch (Exception ex)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(54, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[ExtendedPlayerCount] LobbyBrowserLine_Setup_Postfix: ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
}
log2.LogWarning(val2);
}
}
[HarmonyPatch(typeof(CharactersMenuController), "SetupMenu")]
[HarmonyPostfix]
private static void SetupMenu_Postfix(CharactersMenuController __instance)
{
//IL_0275: Unknown result type (might be due to invalid IL or missing references)
//IL_027c: Expected O, but got Unknown
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
//IL_0047: Expected O, but got Unknown
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
//IL_0176: Unknown result type (might be due to invalid IL or missing references)
//IL_017d: Unknown result type (might be due to invalid IL or missing references)
//IL_0187: Unknown result type (might be due to invalid IL or missing references)
//IL_0203: Unknown result type (might be due to invalid IL or missing references)
//IL_020a: Expected O, but got Unknown
//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
//IL_01b3: Expected O, but got Unknown
bool flag = default(bool);
try
{
if (__instance == _patchedInstance && _patchedMaxPlayers == PlayerCountConfig.MaxPlayers)
{
Plugin.Log.LogInfo((object)"[ExtendedPlayerCount] SetupMenu: slots already added, skipping.");
return;
}
List<LobbyPlayerPanel> playerPanels = __instance.PlayerPanels;
int count = playerPanels.Count;
ManualLogSource log = Plugin.Log;
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(56, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ExtendedPlayerCount] PlayerPanels count: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(count);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", MaxPlayers: ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(PlayerCountConfig.MaxPlayers);
}
log.LogInfo(val);
if (count >= PlayerCountConfig.MaxPlayers)
{
_patchedInstance = __instance;
_patchedMaxPlayers = PlayerCountConfig.MaxPlayers;
return;
}
int num = Math.Min(count, 4);
GameObject gameObject = ((Component)playerPanels[num - 1]).gameObject;
RectTransform component = gameObject.GetComponent<RectTransform>();
Vector2 val2 = (((Object)(object)component != (Object)null) ? component.anchoredPosition : Vector2.zero);
float num2 = (((Object)(object)component != (Object)null && component.sizeDelta.y > 0f) ? component.sizeDelta.y : 80f);
Transform parent = gameObject.transform.parent;
for (int i = count; i < PlayerCountConfig.MaxPlayers; i++)
{
GameObject obj = Object.Instantiate<GameObject>(gameObject, parent);
((Object)obj).name = $"LobbyPlayerPanel_{i}";
RectTransform component2 = obj.GetComponent<RectTransform>();
if ((Object)(object)component2 != (Object)null)
{
float num3 = (float)(i - num + 1) * (0f - (num2 + 5f));
component2.anchoredPosition = new Vector2(val2.x, val2.y + num3);
}
LobbyPlayerPanel component3 = obj.GetComponent<LobbyPlayerPanel>();
if ((Object)(object)component3 == (Object)null)
{
ManualLogSource log2 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(51, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[ExtendedPlayerCount] No LobbyPlayerPanel on slot ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<int>(i);
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral(".");
}
log2.LogWarning(val3);
continue;
}
component3.index = i;
component3.SetPlayerMissing();
playerPanels.Add(component3);
ManualLogSource log3 = Plugin.Log;
val = new BepInExInfoLogInterpolatedStringHandler(49, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ExtendedPlayerCount] Created extra player slot ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(i);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
}
log3.LogInfo(val);
}
_patchedInstance = __instance;
_patchedMaxPlayers = PlayerCountConfig.MaxPlayers;
Plugin.Log.LogInfo((object)"[ExtendedPlayerCount] SetupMenu_Postfix complete.");
}
catch (Exception ex)
{
ManualLogSource log4 = Plugin.Log;
BepInExWarningLogInterpolatedStringHandler val3 = new BepInExWarningLogInterpolatedStringHandler(41, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[ExtendedPlayerCount] SetupMenu_Postfix: ");
((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(ex.Message);
}
log4.LogWarning(val3);
}
}
}
internal static class MyPluginInfo
{
public const string PLUGIN_GUID = "com.yourname.extendedplayercount";
public const string PLUGIN_NAME = "ExtendedPlayerCount";
public const string PLUGIN_VERSION = "1.0.0";
}
public static class PlayerCountConfig
{
public static int MaxPlayers { get; internal set; } = 6;
}
[BepInPlugin("com.yourname.extendedplayercount", "ExtendedPlayerCount", "1.0.0")]
[BepInProcess("Gatekeeper.exe")]
public class Plugin : BasePlugin
{
private ConfigEntry<int> _maxPlayers;
internal static ManualLogSource Log { get; private set; }
public override void Load()
{
//IL_0050: Unknown result type (might be due to invalid IL or missing references)
//IL_0056: Expected O, but got Unknown
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
//IL_0080: Expected O, but got Unknown
Log = ((BasePlugin)this).Log;
_maxPlayers = ((BasePlugin)this).Config.Bind<int>("General", "MaxPlayers", 8, "Maximum number of players allowed in a co-op lobby (vanilla = 4). Valid range: 1-16. Requires all players to have the mod installed.");
int num2 = (PlayerCountConfig.MaxPlayers = Math.Clamp(_maxPlayers.Value, 1, 16));
ManualLogSource log = Log;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[ExtendedPlayerCount] Loaded - MaxPlayers = ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
}
log.LogInfo(val);
LobbyPatches.ApplyAll(new Harmony("com.yourname.extendedplayercount"));
Log.LogInfo((object)"[ExtendedPlayerCount] Harmony patches applied.");
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}