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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Fusion;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Microsoft.CodeAnalysis;
using Steamworks;
using TMPro;
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(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("ShiftAtMidnightMorePlayers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ShiftAtMidnightMorePlayers")]
[assembly: AssemblyTitle("ShiftAtMidnightMorePlayers")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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 ShiftAtMidnightMorePlayers
{
[BepInPlugin("dev.fuzs.shiftatmidnight.moreplayers", "Shift At Midnight More Players", "1.0.3")]
public sealed class Plugin : BasePlugin
{
public const string PluginGuid = "dev.fuzs.shiftatmidnight.moreplayers";
public const string PluginName = "Shift At Midnight More Players";
public const string PluginVersion = "1.0.3";
internal static ManualLogSource Logger;
internal static readonly int[] AllowedPlayerCounts = new int[6] { 1, 2, 3, 6, 8, 16 };
internal static int DesiredLobbyMax = 3;
public const int HardMaxPlayers = 16;
public override void Load()
{
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005b: Expected O, but got Unknown
Logger = ((BasePlugin)this).Log;
try
{
DesiredLobbyMax = 3;
ApplyHardCap();
Harmony.CreateAndPatchAll(typeof(Plugin).Assembly, "dev.fuzs.shiftatmidnight.moreplayers");
((BasePlugin)this).Log.LogInfo((object)"Shift At Midnight More Players v1.0.3 carregado! Opções: 1, 2, 3, 6, 8 e 16.");
}
catch (Exception ex)
{
ManualLogSource log = ((BasePlugin)this).Log;
bool flag = default(bool);
BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Erro ao carregar o plugin:\n");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
}
log.LogError(val);
}
}
internal static void ApplyHardCap()
{
try
{
PlatformManager.s_MAXPLAYERS = 16;
ManualLogSource logger = Logger;
if (logger != null)
{
logger.LogInfo((object)("PlatformManager.s_MAXPLAYERS=" + 16));
}
}
catch (Exception ex)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
logger2.LogWarning((object)("Não foi possível alterar PlatformManager.s_MAXPLAYERS ainda: " + ex.Message));
}
}
}
internal static bool IsAllowedPlayerCount(int value)
{
for (int i = 0; i < AllowedPlayerCounts.Length; i++)
{
if (AllowedPlayerCounts[i] == value)
{
return true;
}
}
return false;
}
internal static int ResolveLobbyMaxPlayers(int requested)
{
if (IsAllowedPlayerCount(requested))
{
return requested;
}
if (requested <= 1)
{
return 1;
}
if (requested <= 2)
{
return 2;
}
if (requested <= 3)
{
return 3;
}
if (requested <= 6)
{
return 6;
}
if (requested <= 8)
{
return 8;
}
return 16;
}
internal static void SetDesiredLobbyMax(int requested)
{
DesiredLobbyMax = ResolveLobbyMaxPlayers(requested);
}
internal static void ForcePendingLobbyMax(string reason)
{
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
//IL_003c: Expected O, but got Unknown
bool flag = default(bool);
try
{
ApplyHardCap();
int num = (PendingLobbySettings.maxPlayers = (DesiredLobbyMax = ResolveLobbyMaxPlayers(DesiredLobbyMax)));
PlatformManager.s_MAXPLAYERS = 16;
ManualLogSource logger = Logger;
if (logger != null)
{
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ForcePendingLobbyMax=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("(");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(reason);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
logger.LogInfo(val);
}
}
catch (Exception ex)
{
ManualLogSource logger2 = Logger;
if (logger2 != null)
{
BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(32, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("ForcePendingLobbyMax falhou ");
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("(");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(reason);
((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("): ");
((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
}
logger2.LogError(val2);
}
}
}
internal static int GetEffectiveLobbyMax()
{
int num = ResolveLobbyMaxPlayers(DesiredLobbyMax);
try
{
int maxPlayers = PendingLobbySettings.maxPlayers;
if (IsAllowedPlayerCount(maxPlayers) && maxPlayers > num)
{
return maxPlayers;
}
}
catch
{
}
return num;
}
}
}
namespace ShiftAtMidnightMorePlayers.Patches
{
[HarmonyPatch(typeof(CreateLobbySettings))]
internal static class CreateLobbySettingsPatches
{
[HarmonyPostfix]
[HarmonyPatch("OnEnable")]
private static void OnEnablePostfix(CreateLobbySettings __instance)
{
try
{
Plugin.ApplyHardCap();
RebuildMaxPlayersDropdown(__instance);
}
catch (Exception value)
{
Plugin.Logger.LogError((object)("Patch de CreateLobbySettings.OnEnable " + $"falhou: {value}"));
}
}
[HarmonyPostfix]
[HarmonyPatch("UpdateDropdownLanguage")]
private static void UpdateDropdownLanguagePostfix(CreateLobbySettings __instance)
{
try
{
RebuildMaxPlayersDropdown(__instance);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)("Patch de UpdateDropdownLanguage falhou: " + ex));
}
}
[HarmonyPrefix]
[HarmonyPatch("ChangeMaxPlayers")]
private static bool ChangeMaxPlayersPrefix(CreateLobbySettings __instance, int players)
{
//IL_001d: Unknown result type (might be due to invalid IL or missing references)
//IL_0023: Expected O, but got Unknown
try
{
int num = ResolveFromDropdownOrArg(__instance, players);
ApplyLobbyMax(__instance, num);
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("ChangeMaxPlayers: índice/valor=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(players);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("resolvido=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
}
logger.LogInfo(val);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)("Patch de ChangeMaxPlayers falhou: " + ex));
}
return false;
}
[HarmonyPrefix]
[HarmonyPatch("StartLobby")]
private static void StartLobbyPrefix(CreateLobbySettings __instance)
{
//IL_0022: Unknown result type (might be due to invalid IL or missing references)
//IL_0028: Expected O, but got Unknown
try
{
int num = ResolveFromDropdownOrArg(__instance, __instance.maxPlayers);
ApplyLobbyMax(__instance, num);
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 1, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("StartLobby prefix maxPlayers=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
}
logger.LogInfo(val);
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)("StartLobby prefix falhou: " + ex));
}
}
[HarmonyPostfix]
[HarmonyPatch("StartLobby")]
private static void StartLobbyPostfix(CreateLobbySettings __instance)
{
try
{
int maxPlayers = ResolveFromDropdownOrArg(__instance, Plugin.DesiredLobbyMax);
ApplyLobbyMax(__instance, maxPlayers);
Plugin.ForcePendingLobbyMax("CreateLobbySettings.StartLobby postfix");
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)("StartLobby postfix falhou: " + ex));
}
}
private static int ResolveFromDropdownOrArg(CreateLobbySettings instance, int players)
{
TMP_Dropdown maxPlayersDropdown = instance.maxPlayersDropdown;
if ((Object)(object)maxPlayersDropdown != (Object)null && maxPlayersDropdown.options != null && maxPlayersDropdown.options.Count > 0)
{
int value = maxPlayersDropdown.value;
if (value >= 0 && value < maxPlayersDropdown.options.Count)
{
string text = maxPlayersDropdown.options[value].text;
if (int.TryParse(text, out var result) && Plugin.IsAllowedPlayerCount(result))
{
return result;
}
if (value >= 0 && value < Plugin.AllowedPlayerCounts.Length)
{
return Plugin.AllowedPlayerCounts[value];
}
}
}
return Plugin.ResolveLobbyMaxPlayers(players);
}
private static void ApplyLobbyMax(CreateLobbySettings instance, int maxPlayers)
{
Plugin.SetDesiredLobbyMax(maxPlayers);
instance.maxPlayers = Plugin.DesiredLobbyMax;
PendingLobbySettings.maxPlayers = Plugin.DesiredLobbyMax;
PlatformManager.s_MAXPLAYERS = 16;
}
private static void RebuildMaxPlayersDropdown(CreateLobbySettings instance)
{
TMP_Dropdown maxPlayersDropdown = instance.maxPlayersDropdown;
if ((Object)(object)maxPlayersDropdown == (Object)null)
{
return;
}
int num = instance.maxPlayers;
if (!Plugin.IsAllowedPlayerCount(num))
{
num = Plugin.DesiredLobbyMax;
}
if (!Plugin.IsAllowedPlayerCount(num))
{
num = 3;
}
maxPlayersDropdown.ClearOptions();
List<string> val = new List<string>();
for (int i = 0; i < Plugin.AllowedPlayerCounts.Length; i++)
{
val.Add(Plugin.AllowedPlayerCounts[i].ToString());
}
maxPlayersDropdown.AddOptions(val);
int num2 = 2;
for (int j = 0; j < Plugin.AllowedPlayerCounts.Length; j++)
{
if (Plugin.AllowedPlayerCounts[j] == num)
{
num2 = j;
break;
}
}
maxPlayersDropdown.SetValueWithoutNotify(num2);
maxPlayersDropdown.RefreshShownValue();
int num3 = Plugin.AllowedPlayerCounts[num2];
ApplyLobbyMax(instance, num3);
Plugin.Logger.LogInfo((object)("Dropdown reconstruído: 1, 2, 3, 8 e 16. " + $"Selecionado={num3}"));
}
}
[HarmonyPatch(typeof(NetworkRunner))]
internal static class NetworkRunnerPatches
{
[HarmonyPrefix]
[HarmonyPatch("StartGame")]
private static void StartGamePrefix(ref StartGameArgs args)
{
//IL_0004: Unknown result type (might be due to invalid IL or missing references)
//IL_0009: Unknown result type (might be due to invalid IL or missing references)
//IL_000a: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Invalid comparison between Unknown and I4
//IL_0041: Unknown result type (might be due to invalid IL or missing references)
//IL_0048: Expected O, but got Unknown
//IL_0071: Unknown result type (might be due to invalid IL or missing references)
try
{
GameMode gameMode = args.GameMode;
if ((int)gameMode != 5)
{
Plugin.ForcePendingLobbyMax("NetworkRunner.StartGame");
int effectiveLobbyMax = Plugin.GetEffectiveLobbyMax();
args.PlayerCount = new Nullable<int>(effectiveLobbyMax);
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 2, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("NetworkRunner.StartGame PlayerCount=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(effectiveLobbyMax);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (mode=");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<GameMode>(gameMode);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(")");
}
logger.LogInfo(val);
}
}
catch (Exception ex)
{
Plugin.Logger.LogError((object)("NetworkRunner.StartGame patch falhou: " + ex));
}
}
}
[HarmonyPatch(typeof(FusionNetworkManager))]
internal static class FusionNetworkManagerPatches
{
[HarmonyPrefix]
[HarmonyPatch("StartAsHost")]
private static void StartAsHostPrefix()
{
Plugin.ForcePendingLobbyMax("FusionNetworkManager.StartAsHost");
Plugin.Logger.LogInfo((object)("StartAsHost pending maxPlayers=" + Plugin.GetEffectiveLobbyMax()));
}
}
[HarmonyPatch(typeof(PlatformManager))]
internal static class PlatformManagerHostPatches
{
[HarmonyPrefix]
[HarmonyPatch("HostLobby")]
private static void HostLobbyPrefix()
{
Plugin.ForcePendingLobbyMax("PlatformManager.HostLobby");
}
}
[HarmonyPatch(typeof(PlatformManager_Steam))]
internal static class PlatformManagerSteamHostPatches
{
[HarmonyPrefix]
[HarmonyPatch("HostLobby")]
private static void HostLobbyPrefix()
{
Plugin.ForcePendingLobbyMax("PlatformManager_Steam.HostLobby prefix");
}
[HarmonyPostfix]
[HarmonyPatch("HostLobby")]
private static void HostLobbyPostfix()
{
Plugin.ForcePendingLobbyMax("PlatformManager_Steam.HostLobby postfix");
}
}
[HarmonyPatch(typeof(LobbyUIManager))]
internal static class LobbyUIManagerHostPatches
{
[HarmonyPrefix]
[HarmonyPatch("HostLobby")]
private static void HostLobbyPrefix()
{
Plugin.ForcePendingLobbyMax("LobbyUIManager.HostLobby");
}
}
[HarmonyPatch(typeof(SteamMatchmaking))]
internal static class SteamMatchmakingPatches
{
[HarmonyPrefix]
[HarmonyPatch("CreateLobby")]
private static void CreateLobbyPrefix(ref ELobbyType eLobbyType, ref int cMaxMembers)
{
int effectiveLobbyMax = Plugin.GetEffectiveLobbyMax();
Plugin.Logger.LogInfo((object)("SteamMatchmaking.CreateLobby cMaxMembers " + $"{cMaxMembers} -> {effectiveLobbyMax}"));
cMaxMembers = effectiveLobbyMax;
Plugin.ForcePendingLobbyMax("SteamMatchmaking.CreateLobby");
}
[HarmonyPrefix]
[HarmonyPatch("SetLobbyMemberLimit")]
private static void SetLobbyMemberLimitPrefix(CSteamID steamIDLobby, ref int cMaxMembers)
{
int effectiveLobbyMax = Plugin.GetEffectiveLobbyMax();
if (cMaxMembers != effectiveLobbyMax)
{
Plugin.Logger.LogInfo((object)("SteamMatchmaking.SetLobbyMemberLimit " + $"{cMaxMembers} -> {effectiveLobbyMax}"));
cMaxMembers = effectiveLobbyMax;
}
}
[HarmonyPrefix]
[HarmonyPatch("SetLobbyData")]
private static void SetLobbyDataPrefix(CSteamID steamIDLobby, string pchKey, ref string pchValue)
{
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006b: Expected O, but got Unknown
try
{
string maxPlayersKey = PlatformManager_Steam._maxPlayersKey;
if (string.IsNullOrEmpty(maxPlayersKey) || pchKey == null || !string.Equals(pchKey, maxPlayersKey, StringComparison.Ordinal))
{
return;
}
string text = Plugin.GetEffectiveLobbyMax().ToString();
if (!(pchValue == text))
{
ManualLogSource logger = Plugin.Logger;
bool flag = default(bool);
BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 3, ref flag);
if (flag)
{
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Steam SetLobbyData ");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pchKey);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pchValue);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' -> '");
((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'");
}
logger.LogInfo(val);
pchValue = text;
}
}
catch (Exception ex)
{
Plugin.Logger.LogWarning((object)("SetLobbyData patch falhou: " + ex.Message));
}
}
}
[HarmonyPatch(typeof(PlatformManager))]
internal static class PlatformManagerPatches
{
[HarmonyPostfix]
[HarmonyPatch("Awake")]
private static void AwakePostfix()
{
Plugin.ApplyHardCap();
}
[HarmonyPostfix]
[HarmonyPatch("Init")]
private static void InitPostfix()
{
Plugin.ApplyHardCap();
}
}
}