Decompiled source of MorePlayers v1.2.1

Mods/MorePlayers.dll

Decompiled 2 hours ago
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 FishySteamworks.Server;
using HarmonyLib;
using MelonLoader;
using Microsoft.CodeAnalysis;
using MimicAPI.GameAPI;
using MorePlayers;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(MorePlayersMod), "MorePlayers", "1.2.1", "github.com/Rxflex", null)]
[assembly: MelonGame("ReLUGames", "MIMESIS")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MorePlayers")]
[assembly: AssemblyConfiguration("Release")]
[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]
	[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 MorePlayers
{
	public class MorePlayersMod : MelonMod
	{
		public const int MAX_PLAYERS = 999;

		public override void OnInitializeMelon()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.moreplayers.mod").PatchAll(typeof(MorePlayersMod).Assembly);
		}
	}
	[HarmonyPatch(typeof(ServerSocket), "GetMaximumClients")]
	public class GetMaximumClients_Patch
	{
		private static bool Prefix(ref int __result)
		{
			__result = 999;
			return false;
		}
	}
	[HarmonyPatch(typeof(ServerSocket), "SetMaximumClients")]
	public class SetMaximumClients_Patch
	{
		private static bool Prefix(ServerSocket __instance, ref int value)
		{
			if (value < 999)
			{
				ServerNetworkAPI.SetMaximumClients((object)__instance, 999);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class ServerSocket_Constructor_Patch
	{
		private static void Postfix(ServerSocket __instance)
		{
			ServerNetworkAPI.SetMaximumClients((object)__instance, 999);
		}
	}
	[HarmonyPatch]
	public class MaximumClients_Transpiler_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			return ServerNetworkAPI.GetAllServerSocketMethods();
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions, MethodBase original)
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			FieldInfo maximumClientsField = ServerNetworkAPI.GetMaximumClientsField();
			if (maximumClientsField == null)
			{
				return list;
			}
			for (int i = 0; i < list.Count; i++)
			{
				if (CodeInstructionExtensions.LoadsField(list[i], maximumClientsField, false))
				{
					list.InsertRange(i + 1, (IEnumerable<CodeInstruction>)(object)new CodeInstruction[2]
					{
						new CodeInstruction(OpCodes.Pop, (object)null),
						new CodeInstruction(OpCodes.Ldc_I4, (object)999)
					});
					i += 2;
				}
			}
			return list;
		}
	}
	[HarmonyPatch]
	public class EnterWaitingRoom_SetMaxPlayers_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo vRoomManagerMethod = ServerNetworkAPI.GetVRoomManagerMethod("EnterWaitingRoom");
			if (!(vRoomManagerMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { vRoomManagerMethod };
		}

		private static void Prefix(object __instance)
		{
			try
			{
				object waitingRoom = ServerNetworkAPI.GetWaitingRoom();
				if (waitingRoom != null)
				{
					RoomAPI.SetRoomMaxPlayers(waitingRoom, 999);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch]
	public class CanEnterChannel_AllRooms_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			List<MethodBase> list = new List<MethodBase>();
			MethodInfo roomMethod = ServerNetworkAPI.GetRoomMethod("VWaitingRoom", "CanEnterChannel");
			if (roomMethod != null)
			{
				list.Add(roomMethod);
			}
			MethodInfo roomMethod2 = ServerNetworkAPI.GetRoomMethod("MaintenanceRoom", "CanEnterChannel");
			if (roomMethod2 != null)
			{
				list.Add(roomMethod2);
			}
			return list;
		}

		private static bool Prefix(ref object __result, object __instance, long playerUID)
		{
			try
			{
				int roomMemberCount = ServerNetworkAPI.GetRoomMemberCount(__instance);
				Type msgErrorCodeType = ServerNetworkAPI.GetMsgErrorCodeType();
				if (msgErrorCodeType != null && msgErrorCodeType.IsEnum)
				{
					if (roomMemberCount >= 999)
					{
						__result = Enum.Parse(msgErrorCodeType, "PlayerCountExceeded");
					}
					else
					{
						__result = Enum.Parse(msgErrorCodeType, "Success");
					}
				}
				return false;
			}
			catch
			{
				return true;
			}
		}
	}
	[HarmonyPatch]
	public class EnterMaintenenceRoom_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo vRoomManagerMethod = ServerNetworkAPI.GetVRoomManagerMethod("EnterMaintenenceRoom");
			if (!(vRoomManagerMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { vRoomManagerMethod };
		}

		private static void Prefix(object __instance)
		{
			try
			{
				object maintenanceRoom = ServerNetworkAPI.GetMaintenanceRoom();
				if (maintenanceRoom != null)
				{
					RoomAPI.SetRoomMaxPlayers(maintenanceRoom, 999);
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch]
	public class SteamLobbyCreation_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo steamInviteMethod = ServerNetworkAPI.GetSteamInviteMethod("CreateLobby");
			if (!(steamInviteMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { steamInviteMethod };
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Expected O, but got Unknown
			List<CodeInstruction> list = new List<CodeInstruction>(instructions);
			for (int i = 0; i < list.Count; i++)
			{
				if (list[i].opcode == OpCodes.Ldc_I4_4 || (list[i].opcode == OpCodes.Ldc_I4_S && list[i].operand is sbyte && (sbyte)list[i].operand == 4) || (list[i].opcode == OpCodes.Ldc_I4 && list[i].operand is int && (int)list[i].operand == 4))
				{
					list[i] = new CodeInstruction(OpCodes.Ldc_I4, (object)999);
				}
			}
			return list;
		}
	}
	[HarmonyPatch]
	public class GetMemberCount_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo roomMethod = ServerNetworkAPI.GetRoomMethod("VWaitingRoom", "GetMemberCount");
			if (!(roomMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { roomMethod };
		}

		private static bool Prefix(ref int __result, object __instance)
		{
			__result = 0;
			return false;
		}
	}
	[HarmonyPatch]
	public class InGameMenu_SetPingImage_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo uIMethod = ServerNetworkAPI.GetUIMethod("UIPrefab_InGameMenu", "SetPingImage");
			if (!(uIMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { uIMethod };
		}

		private static Exception Finalizer(Exception __exception)
		{
			if (__exception != null && __exception is ArgumentOutOfRangeException)
			{
				return null;
			}
			return __exception;
		}
	}
	[HarmonyPatch]
	public class InGameMenu_InitPlayerUI_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo uIMethod = ServerNetworkAPI.GetUIMethod("UIPrefab_InGameMenu", "InitializePlayerUI");
			if (!(uIMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { uIMethod };
		}

		private static Exception Finalizer(Exception __exception)
		{
			if (__exception != null && __exception is ArgumentOutOfRangeException)
			{
				return null;
			}
			return __exception;
		}
	}
	[HarmonyPatch]
	public class SurvivalResult_PatchParameter_Patch
	{
		private static IEnumerable<MethodBase> TargetMethods()
		{
			MethodInfo uIMethod = ServerNetworkAPI.GetUIMethod("UIPrefab_SurvivalResult", "PatchParameter");
			if (!(uIMethod != null))
			{
				return new MethodBase[0];
			}
			return new MethodInfo[1] { uIMethod };
		}

		private static Exception Finalizer(Exception __exception)
		{
			if (__exception != null && __exception is ArgumentOutOfRangeException)
			{
				return null;
			}
			return __exception;
		}
	}
}