using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
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", "2.0.1", "github.com/NeoMimicry", 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+1f1d1459f4e3477615fa4d30d6cbe818c56e8bea")]
[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.neomimicry.moreplayers").PatchAll(typeof(MorePlayersMod).Assembly);
}
}
[HarmonyPatch]
public class IVroom_CanEnterChannel_Transpiler
{
private static IEnumerable<MethodBase> TargetMethods()
{
List<MethodBase> list = new List<MethodBase>();
MethodBase iVroomCanEnterChannel = ServerNetworkAPI.GetIVroomCanEnterChannel();
if (iVroomCanEnterChannel != null)
{
list.Add(iVroomCanEnterChannel);
}
return list;
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0052: Unknown result type (might be due to invalid IL or missing references)
//IL_005c: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: 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.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "C_MaxPlayerCount")
{
list[i] = new CodeInstruction(OpCodes.Pop, (object)null);
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_I4, (object)999));
break;
}
}
return list;
}
}
[HarmonyPatch]
public class GetMaximumClients_Patch
{
private static MethodBase TargetMethod()
{
return (ServerNetworkAPI.GetGameAssembly()?.GetType("FishySteamworks.Server.ServerSocket"))?.GetMethod("GetMaximumClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
private static bool Prefix(ref int __result)
{
__result = 999;
return false;
}
}
[HarmonyPatch]
public class SetMaximumClients_Patch
{
private static MethodBase TargetMethod()
{
return (ServerNetworkAPI.GetGameAssembly()?.GetType("FishySteamworks.Server.ServerSocket"))?.GetMethod("SetMaximumClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
private static bool Prefix(ref int value)
{
if (value < 999)
{
value = 999;
}
return true;
}
}
[HarmonyPatch]
public class ServerSocket_Constructor_Patch
{
private static MethodBase TargetMethod()
{
return (ServerNetworkAPI.GetGameAssembly()?.GetType("FishySteamworks.Server.ServerSocket"))?.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault();
}
private static void Postfix(object __instance)
{
try
{
__instance.GetType().GetMethod("SetMaximumClients", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)?.Invoke(__instance, new object[1] { 999 });
}
catch
{
}
}
}
[HarmonyPatch]
public class GetMemberCount_Smart_Patch
{
private static IEnumerable<MethodBase> TargetMethods()
{
List<MethodBase> list = new List<MethodBase>();
MethodInfo methodInfo = ServerNetworkAPI.GetIVroomType()?.GetMethod("GetMemberCount", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo != null)
{
list.Add(methodInfo);
}
return list;
}
private static bool Prefix(ref int __result, object __instance)
{
try
{
int roomPlayerCount = ServerNetworkAPI.GetRoomPlayerCount(__instance);
StackTrace stackTrace = new StackTrace();
bool flag = false;
bool flag2 = false;
for (int i = 0; i < Math.Min(stackTrace.FrameCount, 10); i++)
{
MethodBase methodBase = stackTrace.GetFrame(i)?.GetMethod();
if (methodBase != null)
{
string name = methodBase.Name;
if (name.Contains("EnterWaitingRoom") || name.Contains("EnterMaintenenceRoom") || name.Contains("CanEnter"))
{
flag = true;
break;
}
if (name.Contains("GetSessionCount") || name.Contains("GetRoomMemberCount"))
{
flag2 = true;
break;
}
}
}
if (flag)
{
__result = 0;
return false;
}
__result = roomPlayerCount;
return false;
}
catch
{
return true;
}
}
}
[HarmonyPatch]
public class AllRooms_CanEnterChannel_Patch
{
private static IEnumerable<MethodBase> TargetMethods()
{
Assembly gameAssembly = ServerNetworkAPI.GetGameAssembly();
List<MethodBase> list = new List<MethodBase>();
MethodInfo methodInfo = (gameAssembly?.GetType("VWaitingRoom"))?.GetMethod("CanEnterChannel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo != null)
{
list.Add(methodInfo);
}
MethodInfo methodInfo2 = (gameAssembly?.GetType("MaintenanceRoom"))?.GetMethod("CanEnterChannel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo2 != null)
{
list.Add(methodInfo2);
}
MethodInfo methodInfo3 = (gameAssembly?.GetType("IVroom"))?.GetMethod("CanEnterChannel", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
if (methodInfo3 != null)
{
list.Add(methodInfo3);
}
return list;
}
private static bool Prefix(ref object __result, object __instance, long playerUID)
{
try
{
Type type = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault((Assembly a) => a.GetName().Name.Contains("FishySteamworks") || a.GetName().Name == "Assembly-CSharp")?.GetTypes().FirstOrDefault((Type t) => t.Name == "MsgErrorCode");
if (type == null || !type.IsEnum)
{
return true;
}
if (__instance.GetType().GetField("_vPlayerDict", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is IDictionary dictionary)
{
foreach (object value2 in dictionary.Values)
{
PropertyInfo property = value2.GetType().GetProperty("UID", BindingFlags.Instance | BindingFlags.Public);
if (property != null)
{
object value = property.GetValue(value2);
if (value != null && value.Equals(playerUID))
{
__result = Enum.Parse(type, "DuplicatePlayer");
return false;
}
}
}
if (dictionary.Count >= 999)
{
__result = Enum.Parse(type, "PlayerCountExceeded");
return false;
}
}
__result = Enum.Parse(type, "Success");
return false;
}
catch
{
return true;
}
}
}
[HarmonyPatch]
public class VRoomManager_EnterWaitingRoom_Patch
{
private static MethodBase TargetMethod()
{
return (ServerNetworkAPI.GetGameAssembly()?.GetType("VRoomManager"))?.GetMethod("EnterWaitingRoom", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
private static void Prefix(object __instance, object context)
{
try
{
if (!(__instance.GetType().GetField("_vrooms", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is IDictionary dictionary))
{
return;
}
foreach (object value in dictionary.Values)
{
if (value.GetType().Name == "VWaitingRoom")
{
FieldInfo fieldInfo = value.GetType().BaseType?.GetField("_maxPlayers", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo != null)
{
fieldInfo.SetValue(value, 999);
}
break;
}
}
}
catch
{
}
}
}
[HarmonyPatch]
public class VRoomManager_EnterMaintenenceRoom_Patch
{
private static MethodBase TargetMethod()
{
return (ServerNetworkAPI.GetGameAssembly()?.GetType("VRoomManager"))?.GetMethod("EnterMaintenenceRoom", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
}
private static void Prefix(object __instance, object context)
{
try
{
if (!(__instance.GetType().GetField("_vrooms", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(__instance) is IDictionary dictionary))
{
return;
}
foreach (object value in dictionary.Values)
{
if (value.GetType().Name == "MaintenanceRoom")
{
FieldInfo fieldInfo = value.GetType().BaseType?.GetField("_maxPlayers", BindingFlags.Instance | BindingFlags.NonPublic);
if (fieldInfo != null)
{
fieldInfo.SetValue(value, 999);
}
break;
}
}
}
catch
{
}
}
}
[HarmonyPatch]
public class GameSessionInfo_AddPlayerSteamID_Patch
{
private static MethodBase TargetMethod()
{
return ServerNetworkAPI.GetGameSessionInfoAddPlayerSteamID();
}
private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
{
//IL_0039: Unknown result type (might be due to invalid IL or missing references)
//IL_0043: Expected O, but got Unknown
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009a: Expected O, but got Unknown
//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
//IL_00b7: Expected O, but got Unknown
List<CodeInstruction> list = new List<CodeInstruction>(instructions);
int num = 0;
for (int i = 0; i < list.Count; i++)
{
if (list[i].opcode == OpCodes.Ldc_I4_4)
{
list[i] = new CodeInstruction(OpCodes.Ldc_I4, (object)999);
num++;
}
else if (list[i].opcode == OpCodes.Ldfld && list[i].operand is FieldInfo fieldInfo && fieldInfo.Name == "C_MaxPlayerCount")
{
list[i] = new CodeInstruction(OpCodes.Pop, (object)null);
list.Insert(i + 1, new CodeInstruction(OpCodes.Ldc_I4, (object)999));
num++;
i++;
}
}
return list;
}
}
[HarmonyPatch(typeof(SteamInviteDispatcher), "CreateLobby")]
public class SteamLobbyCreation_Patch
{
private static bool Prefix(bool isOpenForRandomMatch)
{
try
{
Type type = Type.GetType("Steamworks.SteamMatchmaking, com.rlabrecque.steamworks.net");
Type type2 = Type.GetType("Steamworks.ELobbyType, com.rlabrecque.steamworks.net");
Type type3 = Type.GetType("UnityEngine.PlayerPrefs, UnityEngine.CoreModule");
if (type == null || type2 == null || type3 == null)
{
return true;
}
MethodInfo method = type.GetMethod("CreateLobby", BindingFlags.Static | BindingFlags.Public);
MethodInfo method2 = type3.GetMethod("SetInt", BindingFlags.Static | BindingFlags.Public);
if (method == null || method2 == null)
{
return true;
}
object obj = Enum.ToObject(type2, 2);
method.Invoke(null, new object[2] { obj, 999 });
method2.Invoke(null, new object[2]
{
"TempLobbyIsOpen",
isOpenForRandomMatch ? 1 : 0
});
return false;
}
catch
{
return true;
}
}
}
}