using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
using Microsoft.CodeAnalysis;
using MorePlayers;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::MorePlayers.MorePlayers), "Inside the Backrooms MorePlayers", "1.0.1", "Mr. Monocle", null)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("MorePlayers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MorePlayers")]
[assembly: AssemblyTitle("MorePlayers")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[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]
[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 MorePlayers
{
public class MorePlayers : MelonMod
{
private int playerCount = 8;
private bool isMainMenu = false;
public override void OnInitializeMelon()
{
try
{
string path = "Mods/MaxPlayers.txt";
if (File.Exists(path))
{
string text = File.ReadAllText(path).Trim();
if (!string.IsNullOrEmpty(text) && int.TryParse(text, out var result))
{
playerCount = Mathf.Clamp(result, 1, 32);
}
}
}
catch (Exception value)
{
((MelonBase)this).LoggerInstance.Error($"Failed to read MaxPlayers.txt: {value}");
}
((MelonBase)this).LoggerInstance.Msg($"Max Players Set to: {playerCount}");
}
public override void OnSceneWasInitialized(int buildIndex, string sceneName)
{
if (sceneName == "MainMenu")
{
isMainMenu = true;
((MelonBase)this).LoggerInstance.Msg("MorePlayers: MainMenu detected.");
try
{
GameNetworkManager.MaxPlayersPerRoom = playerCount;
((MelonBase)this).LoggerInstance.Msg($"MorePlayers: MaxPlayersPerRoom set to {playerCount}");
return;
}
catch (Exception value)
{
((MelonBase)this).LoggerInstance.Error($"MorePlayers: Failed to set MaxPlayersPerRoom: {value}");
return;
}
}
isMainMenu = false;
}
public override void OnUpdate()
{
if (isMainMenu && Keyboard.current != null && ((ButtonControl)Keyboard.current.backquoteKey).wasPressedThisFrame)
{
((MelonBase)this).LoggerInstance.Msg("MorePlayers: Backquote key detected.");
TrySetPlayerSelection();
}
}
private void TrySetPlayerSelection()
{
try
{
ButtonsOptionSelect[] array = Il2CppArrayBase<ButtonsOptionSelect>.op_Implicit(Object.FindObjectsOfType<ButtonsOptionSelect>());
((MelonBase)this).LoggerInstance.Msg($"MorePlayers: found {array.Length} ButtonsOptionSelect objects.");
ButtonsOptionSelect[] array2 = array;
foreach (ButtonsOptionSelect val in array2)
{
if (!((Object)(object)val == (Object)null))
{
try
{
((MelonBase)this).LoggerInstance.Msg("MorePlayers: ButtonsOptionSelect = " + ((Object)((Component)val).gameObject).name);
}
catch (Exception value)
{
((MelonBase)this).LoggerInstance.Error($"MorePlayers: Failed reading selector name: {value}");
}
}
}
ButtonsOptionSelect val2 = null;
ButtonsOptionSelect[] array3 = array;
foreach (ButtonsOptionSelect val3 in array3)
{
if (!((Object)(object)val3 == (Object)null))
{
string name = ((Object)((Component)val3).gameObject).name;
if (name.IndexOf("PLAYER", StringComparison.OrdinalIgnoreCase) >= 0)
{
val2 = val3;
break;
}
}
}
if ((Object)(object)val2 == (Object)null)
{
((MelonBase)this).LoggerInstance.Error("MorePlayers: Could not find the player-count selector.");
return;
}
val2.SelectedOption = playerCount;
((MelonBase)this).LoggerInstance.Msg($"MorePlayers: Player selector set to {playerCount}");
try
{
GameNetworkManager.MaxPlayersPerRoom = playerCount;
((MelonBase)this).LoggerInstance.Msg($"MorePlayers: MaxPlayersPerRoom set to {playerCount}");
}
catch (Exception value2)
{
((MelonBase)this).LoggerInstance.Error($"MorePlayers: Failed to update network limit: {value2}");
}
}
catch (Exception value3)
{
((MelonBase)this).LoggerInstance.Error($"MorePlayers failed while setting player count: {value3}");
}
}
}
}