using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Steamworks;
using TMPro;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ZortModBepInex")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ZortModBepInex")]
[assembly: AssemblyCopyright("Copyright © 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9df868d5-31a0-4d0d-8de2-7370fe2e4989")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ZortMod;
[BepInPlugin("erne.zort.moreplayers", "More Players", "1.0.0")]
public class MorePlayers : BaseUnityPlugin
{
public const string pluginGuid = "erne.zort.moreplayers";
public const string pluginName = "More Players";
public const string pluginVersion = "1.0.0";
private const string LOBBY_DATA_NAME = "name";
private TMP_Dropdown playerCountDropdown;
private TMP_InputField directJoinIPField;
public void Awake()
{
PatchUtils.RegisterCallback(typeof(MainMenuManager), "Host_Btn", SetDropdown);
PatchUtils.RegisterCallback(typeof(MainMenuManager), "OnLobbyCreated", SetLobbyData);
}
public void SetDropdown()
{
playerCountDropdown = GetPrivateVariable<TMP_Dropdown>(StaticInstance<MainMenuManager>.Instance, "hostSettingsPlayerCountDropdown");
for (int i = 5; i <= 16; i++)
{
playerCountDropdown.AddOptions(new List<string> { i.ToString() });
}
}
public void SetLobbyData()
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_001b: Unknown result type (might be due to invalid IL or missing references)
string lobbyData = SteamMatchmaking.GetLobbyData(SteamManager.CurrentLobby.Value, "name");
SteamMatchmaking.SetLobbyData(SteamManager.CurrentLobby.Value, "name", lobbyData + " [ErneDev]");
}
public T GetPrivateVariable<T>(object instance, string name)
{
Type type = instance.GetType();
FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
object value = field.GetValue(instance);
return (value is T) ? ((T)value) : default(T);
}
}
public static class PatchUtils
{
private static Dictionary<string, Action> actions = new Dictionary<string, Action>();
private static object callback;
public static void RegisterCallback(Type classType, string callback, Action action, bool oneTime = false)
{
//IL_003a: Unknown result type (might be due to invalid IL or missing references)
//IL_0040: Expected O, but got Unknown
//IL_006f: Unknown result type (might be due to invalid IL or missing references)
//IL_007c: Expected O, but got Unknown
PatchUtils.callback = callback;
if (!actions.ContainsKey(callback))
{
actions.Add(callback, action);
}
else
{
actions[callback] = action;
}
Harmony val = new Harmony("com.example.patch");
MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
MethodInfo methodInfo2 = AccessTools.Method(typeof(PatchUtils), oneTime ? "DynamicPostfixOnce" : "DynamicPostfix", (Type[])null, (Type[])null);
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
public static void UnRegisterCallback(Type classType, string callback)
{
//IL_0006: Unknown result type (might be due to invalid IL or missing references)
//IL_000c: Expected O, but got Unknown
Harmony val = new Harmony("com.example.patch");
MethodInfo methodInfo = AccessTools.Method(classType, callback, (Type[])null, (Type[])null);
val.Unpatch((MethodBase)methodInfo, (HarmonyPatchType)0, "com.example.patch");
actions.Remove(callback);
}
public static void DynamicPostfix(MethodBase __originalMethod)
{
string name = __originalMethod.Name;
actions[name]?.Invoke();
}
public static void DynamicPostfixOnce(MethodBase __originalMethod)
{
string name = __originalMethod.Name;
actions[name]?.Invoke();
UnRegisterCallback(__originalMethod.DeclaringType, name);
}
}