Decompiled source of MorePlayers v1.1.0

MorePlayers.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using Steamworks.Data;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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]
	[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
{
	[BepInPlugin("ozoka.moreplayers", "MorePlayers", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		internal static ManualLogSource Log;

		internal static ConfigEntry<int> MaxPlayers;

		internal static ConfigEntry<bool> PublicLobbySupport;

		private readonly Harmony _harmony = new Harmony("ozoka.moreplayers");

		private void Awake()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			MaxPlayers = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Max Players", 10, new ConfigDescription("Maximum number of players allowed in a lobby.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(2, 20), Array.Empty<object>()));
			PublicLobbySupport = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Public Lobby Support", true, "If enabled, public lobbies will be visible in the server list.");
			Log.LogInfo((object)"MorePlayers geladen!");
			_harmony.PatchAll();
		}
	}
	[HarmonyPatch(typeof(GameManager))]
	internal class GameManagerPatch
	{
		private static readonly FieldInfo _maxPlayersPhotonField = typeof(GameManager).GetField("maxPlayersPhoton", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		internal static void AwakePatch(GameManager __instance)
		{
			_maxPlayersPhotonField?.SetValue(__instance, Plugin.MaxPlayers.Value);
			__instance.SetMaxPlayers(Plugin.MaxPlayers.Value);
			Plugin.Log.LogInfo((object)("[MorePlayers] MaxPlayers gesetzt: " + Plugin.MaxPlayers.Value));
		}
	}
	[HarmonyPatch(typeof(NetworkConnect))]
	internal class NetworkConnectPatch
	{
		private static readonly FieldInfo _networkPasswordField = typeof(DataDirector).GetField("networkPassword", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo _networkServerNameField = typeof(DataDirector).GetField("networkServerName", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo _connectRandomField = typeof(GameManager).GetField("connectRandom", BindingFlags.Instance | BindingFlags.NonPublic);

		[HarmonyPatch("TryJoiningRoom")]
		[HarmonyPrefix]
		internal static bool TryJoiningRoomPatch(ref string ___RoomName)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			if (string.IsNullOrEmpty(___RoomName))
			{
				Plugin.Log.LogError((object)"RoomName ist leer, nutze originale Methode!");
				return true;
			}
			if (Plugin.MaxPlayers.Value == 0)
			{
				Plugin.Log.LogError((object)"MaxPlayers ist 0, nutze originale Methode!");
				return true;
			}
			string value = (_networkPasswordField?.GetValue(DataDirector.instance) as string) ?? "";
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)(object)val).Add((object)"PASSWORD", (object)value);
			PhotonNetwork.LocalPlayer.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			RoomOptions val2 = new RoomOptions
			{
				MaxPlayers = Plugin.MaxPlayers.Value,
				IsVisible = false
			};
			Hashtable val3 = new Hashtable();
			((Dictionary<object, object>)(object)val3).Add((object)"PASSWORD", (object)value);
			val2.CustomRoomProperties = val3;
			PhotonNetwork.JoinOrCreateRoom(___RoomName, val2, TypedLobby.Default, (string[])null);
			return false;
		}

		[HarmonyPatch("OnConnectedToMaster")]
		[HarmonyPrefix]
		internal static bool OnConnectedToMasterPatch()
		{
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Expected O, but got Unknown
			if (!Plugin.PublicLobbySupport.Value)
			{
				return true;
			}
			bool flag = (bool)(_connectRandomField?.GetValue(GameManager.instance) ?? ((object)false));
			string text = (_networkServerNameField?.GetValue(DataDirector.instance) as string) ?? "";
			if (!flag)
			{
				return true;
			}
			if (string.IsNullOrEmpty(text))
			{
				return true;
			}
			if (Plugin.MaxPlayers.Value == 0)
			{
				return true;
			}
			Plugin.Log.LogInfo((object)("[MorePlayers] Erstelle öffentliche Lobby: " + text));
			RoomOptions val = new RoomOptions();
			val.CustomRoomPropertiesForLobby = new string[1] { "server_name" };
			Hashtable val2 = new Hashtable();
			((Dictionary<object, object>)(object)val2).Add((object)"server_name", (object)("[Modded] " + text));
			val.CustomRoomProperties = val2;
			val.MaxPlayers = Plugin.MaxPlayers.Value;
			val.IsVisible = true;
			PhotonNetwork.CreateRoom((string)null, val, DataDirector.instance.customLobby, (string[])null);
			return false;
		}
	}
	[HarmonyPatch(typeof(SteamManager))]
	internal class SteamManagerPatch
	{
		[HarmonyPatch("HostLobby")]
		[HarmonyPrefix]
		internal static bool HostLobbyPatch()
		{
			HostLobbyAsync();
			return false;
		}

		private static async void HostLobbyAsync()
		{
			Plugin.Log.LogInfo((object)"[MorePlayers] Steam Lobby wird erstellt...");
			Lobby? lobby = await SteamMatchmaking.CreateLobbyAsync(Plugin.MaxPlayers.Value);
			if (!lobby.HasValue)
			{
				Plugin.Log.LogError((object)"[MorePlayers] Steam Lobby konnte nicht erstellt werden!");
				return;
			}
			Lobby value = lobby.Value;
			((Lobby)(ref value)).SetPublic();
			((Lobby)(ref value)).SetJoinable(false);
			Plugin.Log.LogInfo((object)"[MorePlayers] Steam Lobby erstellt!");
		}
	}
}