using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CG.Ship.Repair;
using Gameplay.MissionDifficulty;
using Gameplay.Quests;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using ToolClasses;
using UI;
using UI.Settings;
using UnityEngine;
using UnityEngine.UIElements;
using VoidManager;
using VoidManager.Chat.Router;
using VoidManager.CustomGUI;
using VoidManager.MPModChecks;
using VoidManager.Utilities;
using WebSocketSharp;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("MaxPlayers")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Increase the maximum player count")]
[assembly: AssemblyFileVersion("1.1.1.0")]
[assembly: AssemblyInformationalVersion("1.1.1+53720b6467c09260a0d423ca8a78f908cd692145")]
[assembly: AssemblyProduct("MaxPlayers")]
[assembly: AssemblyTitle("Increases the player limit to 8, customizable up to 255.")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.1.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 MaxPlayers
{
[BepInPlugin("VoidCrewModdingTeam.MaxPlayers", "Max Players", "1.1.1")]
[BepInProcess("Void Crew.exe")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class BepinPlugin : BaseUnityPlugin
{
internal static readonly Harmony Harmony = new Harmony("VoidCrewModdingTeam.MaxPlayers");
internal static ManualLogSource Log;
private void Awake()
{
Log = ((BaseUnityPlugin)this).Logger;
Settings.DefaultPlayerLimit = ((BaseUnityPlugin)this).Config.Bind<byte>("Settings", "DefaultPlayerLimit", (byte)8, "The player limit you'll default to.");
Settings.SliderLimit = ((BaseUnityPlugin)this).Config.Bind<byte>("Settings", "SliderLimit", (byte)24, "How high the slider can slide.");
Settings.ChairStartEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "ChairStartEnabled", true, "While enabled, players can start a session solely by sitting down. Disable if you want the host to maintain control.");
Harmony.PatchAll();
((BaseUnityPlugin)this).Logger.LogInfo((object)"Plugin VoidCrewModdingTeam.MaxPlayers is loaded!");
}
}
internal class CountCommand : ChatCommand
{
public override string[] CommandAliases()
{
return new string[2] { "playercount", "pc" };
}
public override string Description()
{
return "Count of players.";
}
public override void Execute(string arguments)
{
if (PhotonNetwork.InRoom)
{
Messaging.Echo($"Players: {PhotonNetwork.CurrentRoom.PlayerCount} / {PhotonNetwork.CurrentRoom.MaxPlayers}", true);
}
}
}
internal class IncreaseCommand : ChatCommand
{
public override string[] CommandAliases()
{
return new string[2] { "setplayerlimit", "spl" };
}
public override string Description()
{
return "Player Limit";
}
public override void Execute(string arguments)
{
string[] array = arguments.Split(' ');
if (array.Length >= 1 && PhotonNetwork.IsMasterClient)
{
if (int.TryParse(array[0], out var result))
{
Limits.PlayerLimit = result;
}
Messaging.Echo($"Player limit: {Limits.PlayerLimit}", true);
}
}
}
internal class StartQuest : ChatCommand
{
private static List<Argument> arguments = new List<Argument>
{
new Argument(new string[1] { "now" })
};
public static bool ToldToStart { get; set; } = false;
public override string[] CommandAliases()
{
return new string[2] { "startquest", "sq" };
}
public override string Description()
{
return "Starts the session hub count down. Use \"now\" argument to begin immediately";
}
public override List<Argument> Arguments()
{
return arguments;
}
internal static void ExecuteStartQuest()
{
if (!PhotonNetwork.InRoom || !PhotonNetwork.IsMasterClient)
{
Messaging.Notification("Must be host to use this command.", 10000L, false);
return;
}
if (HubQuestManager.Instance.SelectedQuest == null || HubQuestManager.Instance.CurrentShipSelected == null)
{
Messaging.Notification("Must have a quest and ship selected.", 10000L, false);
return;
}
ToldToStart = !ToldToStart;
if (ToldToStart)
{
Messaging.Notification("Starting Countdown at 30 seconds", false);
HubQuestManager.Instance.QuestStartProcess.StartProcess();
}
else
{
Messaging.Notification("Stopping Countdown", false);
}
}
public override void Execute(string arguments)
{
if (arguments.StartsWith("now", StringComparison.OrdinalIgnoreCase))
{
Messaging.Echo("Starting Quest Now.", false);
HubQuestManager.Instance.StartQuest(HubQuestManager.Instance.SelectedQuest);
}
else
{
ExecuteStartQuest();
}
}
}
internal class GUI : ModSettingsMenu
{
private string PlayerlimitStr;
private string ErrorText;
public override string Name()
{
return "Max Players";
}
public override void Draw()
{
if (!Ext.IsNullOrEmpty(ErrorText))
{
GUILayout.Label(ErrorText, Array.Empty<GUILayoutOption>());
}
GUITools.DrawTextField<byte>("Slider Limit", ref Settings.SliderLimit, 80f);
if (GUITools.DrawTextField("Player Limit", ref PlayerlimitStr, Limits.DefaultPlayerLimit.ToString(), 80f) && int.TryParse(PlayerlimitStr, out var result))
{
if (!PhotonNetwork.InRoom)
{
ErrorText = "<color=red>Error: Cannot change Player Limit while not in room</color>";
}
else if (result <= 0 || result >= 256)
{
ErrorText = "<color=red>Error: Player Limit must be between 1 and 255</color>";
}
else
{
Limits.PlayerLimit = result;
ErrorText = null;
}
}
GUITools.DrawTextField<byte>("Default Player Limit", ref Settings.DefaultPlayerLimit, 80f);
GUITools.DrawCheckbox("Enable chair starting from hub", ref Settings.ChairStartEnabled);
if (PhotonNetwork.InRoom && PhotonNetwork.IsMasterClient && GameSessionManager.InHub && GUILayout.Button("Start Quest", Array.Empty<GUILayoutOption>()))
{
StartQuest.ExecuteStartQuest();
}
}
public override void OnOpen()
{
PlayerlimitStr = Limits.PlayerLimit.ToString();
}
}
internal class Limits
{
public static int DefaultPlayerLimit
{
get
{
return Settings.DefaultPlayerLimit.Value;
}
set
{
if (value >= 256 || value <= -1)
{
BepinPlugin.Log.LogWarning((object)("Cannont assign DefaultPlayerLimit to value not between 0 and 255. Attempted setting as " + value));
}
else
{
Settings.DefaultPlayerLimit.Value = (byte)value;
}
}
}
public static int PlayerLimit
{
get
{
if (!PhotonNetwork.InRoom)
{
return 0;
}
return PunSingleton<PhotonService>.Instance.GetCurrentPlayerLimit();
}
set
{
if (value >= 256 || value <= -1)
{
BepinPlugin.Log.LogWarning((object)("Cannont assign PlayerLimit to value not between 0 and 255. Attempted setting as " + value));
}
else
{
PunSingleton<PhotonService>.Instance.SetCurrentRoomPlayerLimit(value);
}
}
}
public static int SliderLimit
{
get
{
return Settings.SliderLimit.Value;
}
set
{
if (value >= 256 || value <= -1)
{
BepinPlugin.Log.LogWarning((object)("Cannont assign SliderLimit to value not between 0 and 255. Attempted setting as " + value));
}
else
{
Settings.SliderLimit.Value = (byte)value;
}
}
}
}
public class MyPluginInfo
{
public const string PLUGIN_GUID = "VoidCrewModdingTeam.MaxPlayers";
public const string PLUGIN_NAME = "MaxPlayers";
public const string USERS_PLUGIN_NAME = "Max Players";
public const string PLUGIN_VERSION = "1.1.1";
public const string PLUGIN_DESCRIPTION = "Increases the player limit to 8, customizable up to 255.";
public const string PLUGIN_ORIGINAL_AUTHOR = "VoidCrewModdingTeam";
public const string PLUGIN_AUTHORS = "Dragon, Mest";
public const string PLUGIN_THUNDERSTORE_ID = "VoidCrewModdingTeam/Max_Players";
}
internal class Settings
{
internal static ConfigEntry<byte> DefaultPlayerLimit;
internal const byte defaultplayerlimit = 8;
internal static ConfigEntry<byte> SliderLimit;
internal const byte defaultsliderlimit = 24;
internal static ConfigEntry<bool> ChairStartEnabled;
}
internal class VoidManagerPlugin : VoidPlugin
{
public override MultiplayerType MPType => (MultiplayerType)30;
public override string Author => "Dragon, Mest";
public override string Description => "Increases the player limit to 8, customizable up to 255.";
public override string ThunderstoreID => "VoidCrewModdingTeam/Max_Players";
}
}
namespace MaxPlayers.Patches
{
[HarmonyPatch(typeof(GameSessionManager), "LoadGameSessionNetworkedAssets")]
internal class DefaultSessionMaxPlayers
{
private static FieldInfo activeGameSessioninfo = AccessTools.Field(typeof(GameSessionManager), "activeGameSession");
[HarmonyTranspiler]
public static IEnumerable<CodeInstruction> Replacement(IEnumerable<CodeInstruction> instructions)
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_0016: Expected O, but got Unknown
//IL_001e: Unknown result type (might be due to invalid IL or missing references)
//IL_0024: Expected O, but got Unknown
//IL_002c: Unknown result type (might be due to invalid IL or missing references)
//IL_0032: Expected O, but got Unknown
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
//IL_0048: Unknown result type (might be due to invalid IL or missing references)
//IL_004e: Expected O, but got Unknown
//IL_0056: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_0064: Unknown result type (might be due to invalid IL or missing references)
//IL_006a: Expected O, but got Unknown
//IL_0072: Unknown result type (might be due to invalid IL or missing references)
//IL_0078: Expected O, but got Unknown
//IL_0080: Unknown result type (might be due to invalid IL or missing references)
//IL_0086: Expected O, but got Unknown
//IL_008f: Unknown result type (might be due to invalid IL or missing references)
//IL_0095: Expected O, but got Unknown
//IL_009e: Unknown result type (might be due to invalid IL or missing references)
//IL_00a4: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b3: Expected O, but got Unknown
//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
//IL_00c2: Expected O, but got Unknown
//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
//IL_00d1: Expected O, but got Unknown
CodeInstruction[] array = (CodeInstruction[])(object)new CodeInstruction[14]
{
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)null),
new CodeInstruction(OpCodes.Brtrue, (object)null),
new CodeInstruction(OpCodes.Call, (object)null),
new CodeInstruction(OpCodes.Ldarg_0, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)null),
new CodeInstruction(OpCodes.Ldfld, (object)null),
new CodeInstruction(OpCodes.Call, (object)null),
new CodeInstruction(OpCodes.Callvirt, (object)null),
new CodeInstruction(OpCodes.Call, (object)null),
new CodeInstruction(OpCodes.Conv_U1, (object)null),
new CodeInstruction(OpCodes.Callvirt, (object)null)
};
CodeInstruction[] array2 = (CodeInstruction[])(object)new CodeInstruction[0];
return HarmonyHelpers.PatchBySequence(instructions, (IEnumerable<CodeInstruction>)array, (IEnumerable<CodeInstruction>)array2, (PatchMode)2, (CheckMode)2, false);
}
}
[HarmonyPatch(typeof(DifficultyPlayerCountTable), "GetConfig")]
internal class DifficultyPlayerCountTablePatch
{
[HarmonyPrefix]
private static void GetConfigPrefix(ref int playerCount)
{
int num = 4;
foreach (DifficultySetup setup in DataTable<DifficultyPlayerCountTable>.Instance.setups)
{
if (setup.playerCount > num)
{
num = setup.playerCount;
}
}
if (playerCount > num)
{
playerCount = num;
}
}
}
[HarmonyPatch(/*Could not decode attribute arguments.*/)]
internal class HullDamageControlerPatch
{
private static bool Prefix(HullDamageController __instance, ref HullDamageConfig __result)
{
int num = GameSessionManager.ActiveSession.PlayerCount;
if (num > __instance.damageConfigs.Length)
{
num = __instance.damageConfigs.Length - 1;
}
__result = __instance.damageConfigs[num];
return false;
}
}
[HarmonyPatch(typeof(QuestStartProcess), "UpdateQuestProcess")]
internal class FourPlayersStartSession
{
[HarmonyPrefix]
public static bool Replacement(QuestStartProcess __instance, int playersInZoneCount, ref float ____timeLeft, ref bool ____allPlayersWereInZone)
{
if (!PhotonNetwork.InRoom)
{
return false;
}
float num = 30f;
int num2 = Math.Min(PhotonNetwork.CurrentRoom.Players.Count, 4);
float num3;
if (!StartQuest.ToldToStart && (!__instance.HasEnoughPlayersToBeginCountdown(num2, playersInZoneCount) || !Settings.ChairStartEnabled.Value))
{
num3 = 30f;
}
else
{
if (Settings.ChairStartEnabled.Value)
{
if (num2 == playersInZoneCount)
{
____allPlayersWereInZone = true;
num = 6f;
}
else if (____allPlayersWereInZone)
{
____allPlayersWereInZone = false;
____timeLeft = 30f;
num = 30f;
}
}
num3 = 0f - Time.deltaTime;
}
____timeLeft = Mathf.Clamp(____timeLeft + num3, 0f, num);
int num4 = (int)____timeLeft;
if (num4 == __instance.SecondsLeft)
{
return false;
}
__instance.SetSecondsLeft(num4);
return false;
}
}
[HarmonyPatch(typeof(QuestGenerator), "Create")]
internal class IncreaseMaximumAllowedPlayers
{
[HarmonyPostfix]
public static void Patch(ref Quest __result)
{
if (__result.Asset.scenarioSetup.MaximumPlayers >= 4)
{
__result.Asset.scenarioSetup.MaximumPlayers = int.MaxValue;
}
}
}
[HarmonyPatch(typeof(HubQuestManager), "StartQuest")]
internal class ResetForceStart
{
[HarmonyPostfix]
public static void Patch()
{
StartQuest.ToldToStart = false;
}
}
[HarmonyPatch(typeof(SliderIntSettingEntryVE), "Init")]
internal class SliderIntSettingEntryVEOverride
{
private static void Postfix(SliderIntSettingEntryVE __instance)
{
if (((SettingEntryVE)__instance).DisplayName.Contains("player_limit") && __instance.setting != null)
{
((ClampedSetting<int>)(object)__instance.setting).max = Limits.SliderLimit;
__instance.HighValue = ((ClampedSetting<int>)(object)__instance.setting).max;
((BaseSlider<int>)(object)__instance.slider).highValue = ((ClampedSetting<int>)(object)__instance.setting).max;
((BaseField<int>)(object)__instance.slider).value = Limits.DefaultPlayerLimit;
VisualElement val = UQueryExtensions.Q(((VisualElement)__instance.slider).parent, "StepContainer", (string)null);
if (val != null)
{
UItoolkitExtensionMethods.RemoveChildren(val);
((SettingEntryVE)__instance).SetupContainers();
}
}
}
}
}