Decompiled source of PhotonServerSettings REPO v1.0.5

BepInEx/plugins/PhotonServerSettings/uk.1a3.photonserversettings.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Platforms;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("uk.1a3.photonserversettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5.0")]
[assembly: AssemblyInformationalVersion("1.0.5-dev.4+17464e549071b0c4301cb36a3418afd8aec652bd")]
[assembly: AssemblyProduct("PhotonServerSettings")]
[assembly: AssemblyTitle("uk.1a3.photonserversettings")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PhotonServerSettings
{
	[BepInPlugin("uk.1a3.photonserversettings", "PhotonServerSettings", "1.0.5")]
	internal class PluginLoader : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("uk.1a3.photonserversettings");

		private static bool initialized;

		internal static ConfigEntry<bool> PhotonAppIdEnabled;

		internal static ConfigEntry<string> PhotonAppIdRealtime;

		internal static ConfigEntry<string> PhotonAppIdVoice;

		internal static ConfigEntry<bool> PhotonServerEnabled;

		internal static ConfigEntry<string> PhotonServerAddress;

		internal static ConfigEntry<int> PhotonServerPort;

		internal static ConfigEntry<int> PhotonServerVersion;

		internal static ConfigEntry<string> PhotonConnectionProtocol;

		internal static ConfigEntry<bool> PhotonAlternativeUdpPorts;

		internal static ConfigEntry<int> PhotonObjectsInOneUpdate;

		internal static ConfigEntry<int> PhotonSendRate;

		internal static int DefaultPhotonObjectsInOneUpdate = 10;

		internal static int DefaultPhotonSendRate = 25;

		internal static ManualLogSource StaticLogger { get; private set; }

		internal static ConfigFile StaticConfig { get; private set; }

		private void Awake()
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Expected O, but got Unknown
			//IL_012d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Expected O, but got Unknown
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Expected O, but got Unknown
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01aa: Expected O, but got Unknown
			//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d5: Expected O, but got Unknown
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Expected O, but got Unknown
			//IL_0258: Unknown result type (might be due to invalid IL or missing references)
			//IL_0262: Expected O, but got Unknown
			if (initialized)
			{
				return;
			}
			initialized = true;
			StaticLogger = ((BaseUnityPlugin)this).Logger;
			StaticConfig = ((BaseUnityPlugin)this).Config;
			PhotonAppIdEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Photon", "AppId Override", true, new ConfigDescription("Photon App ID Override", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonAppIdRealtime = ((BaseUnityPlugin)this).Config.Bind<string>("Photon", "AppId Realtime", "", new ConfigDescription("Photon Realtime App ID", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonAppIdVoice = ((BaseUnityPlugin)this).Config.Bind<string>("Photon", "AppId Voice", "", new ConfigDescription("Photon Voice App ID", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonServerEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Photon", "Server Override", true, new ConfigDescription("Photon Server Override", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonServerAddress = ((BaseUnityPlugin)this).Config.Bind<string>("Photon", "Server", "", new ConfigDescription("Photon Server Address", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonServerPort = ((BaseUnityPlugin)this).Config.Bind<int>("Photon", "Server Port", 0, new ConfigDescription("Photon Server Port", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 65535), Array.Empty<object>()));
			PhotonServerVersion = ((BaseUnityPlugin)this).Config.Bind<int>("Photon", "Server Version", 5, new ConfigDescription("Photon Server Version", (AcceptableValueBase)(object)new AcceptableValueRange<int>(4, 5), Array.Empty<object>()));
			PhotonConnectionProtocol = ((BaseUnityPlugin)this).Config.Bind<string>("Photon", "Protocol", "Udp", new ConfigDescription("Photon Protocol", (AcceptableValueBase)(object)new AcceptableValueList<string>(Enum.GetNames(typeof(ConnectionProtocol))), Array.Empty<object>()));
			PhotonAlternativeUdpPorts = ((BaseUnityPlugin)this).Config.Bind<bool>("Photon", "Alternative Udp Ports", true, new ConfigDescription("Photon Alternative Ports (Udp)", (AcceptableValueBase)null, Array.Empty<object>()));
			PhotonObjectsInOneUpdate = ((BaseUnityPlugin)this).Config.Bind<int>("Photon Networking", "Objects In One Update", 0, new ConfigDescription("Do not change this unless you know what you are doing. 0 = Vanilla", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			PhotonObjectsInOneUpdate.SettingChanged += delegate
			{
				if (PhotonObjectsInOneUpdate.Value > 0)
				{
					PhotonNetwork.ObjectsInOneUpdate = PhotonObjectsInOneUpdate.Value;
					StaticLogger.LogInfo((object)$"[Photon] Changed ObjectsInOneUpdate: {PhotonNetwork.ObjectsInOneUpdate}");
				}
				else
				{
					PhotonNetwork.ObjectsInOneUpdate = DefaultPhotonObjectsInOneUpdate;
					StaticLogger.LogInfo((object)$"[Photon] Reset ObjectsInOneUpdate: {PhotonNetwork.ObjectsInOneUpdate}");
				}
			};
			PhotonSendRate = ((BaseUnityPlugin)this).Config.Bind<int>("Photon Networking", "Send Rate", 0, new ConfigDescription("Do not change this unless you know what you are doing. 0 = Vanilla", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
			PhotonSendRate.SettingChanged += delegate
			{
				if (Object.op_Implicit((Object)(object)NetworkManager.instance))
				{
					if (PhotonSendRate.Value > 0)
					{
						PhotonNetwork.SendRate = PhotonSendRate.Value;
						PhotonNetwork.SerializationRate = PhotonSendRate.Value;
						StaticLogger.LogInfo((object)$"[Photon] Changed SendRate and SerializationRate: {PhotonNetwork.SendRate}");
					}
					else
					{
						PhotonNetwork.SendRate = DefaultPhotonSendRate;
						PhotonNetwork.SerializationRate = DefaultPhotonSendRate;
						StaticLogger.LogInfo((object)$"[Photon] Reset SendRate and SerializationRate: {PhotonNetwork.SendRate}");
					}
				}
			};
			harmony.PatchAll(typeof(GeneralPatches));
			StaticLogger.LogInfo((object)"Patches Loaded");
		}
	}
	[HarmonyPatch]
	internal static class GeneralPatches
	{
		[HarmonyPatch(typeof(NetworkManager), "Start")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void NetworkManager_Start()
		{
			PluginLoader.DefaultPhotonSendRate = PhotonNetwork.SendRate;
			if (PluginLoader.PhotonSendRate.Value > 0)
			{
				PhotonNetwork.SendRate = PluginLoader.PhotonSendRate.Value;
				PhotonNetwork.SerializationRate = PluginLoader.PhotonSendRate.Value;
				PluginLoader.StaticLogger.LogInfo((object)$"[Photon] Changed SendRate and SerializationRate: {PhotonNetwork.SendRate}");
			}
		}

		[HarmonyPatch(typeof(DataDirector), "PhotonSetAppId")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void DataDirector_PhotonSetAppId_Postfix()
		{
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_01be: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
			PhotonNetwork.PhotonServerSettings.AppSettings.Port = 0;
			PhotonNetwork.PhotonServerSettings.AppSettings.UseNameServer = true;
			PhotonNetwork.NetworkingClient.SerializationProtocol = (SerializationProtocol)1;
			PluginLoader.DefaultPhotonObjectsInOneUpdate = PhotonNetwork.ObjectsInOneUpdate;
			if (PluginLoader.PhotonObjectsInOneUpdate.Value > 0)
			{
				PhotonNetwork.ObjectsInOneUpdate = PluginLoader.PhotonObjectsInOneUpdate.Value;
				PluginLoader.StaticLogger.LogInfo((object)$"[Photon] Changed ObjectsInOneUpdate: {PhotonNetwork.ObjectsInOneUpdate}");
			}
			if (PluginLoader.PhotonServerEnabled.Value && !string.IsNullOrEmpty(PluginLoader.PhotonServerAddress.Value))
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.Server = PluginLoader.PhotonServerAddress.Value;
				PluginLoader.StaticLogger.LogInfo((object)("[Photon] Changed Server Address: " + PhotonNetwork.PhotonServerSettings.AppSettings.Server));
				if (PluginLoader.PhotonServerPort.Value > 0)
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.Port = PluginLoader.PhotonServerPort.Value;
					PluginLoader.StaticLogger.LogInfo((object)$"[Photon] Changed Server Port: {PhotonNetwork.PhotonServerSettings.AppSettings.Port}");
				}
				if (PluginLoader.PhotonServerVersion.Value == 4)
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.UseNameServer = false;
					PhotonNetwork.NetworkingClient.SerializationProtocol = (SerializationProtocol)0;
				}
			}
			if (Enum.TryParse<ConnectionProtocol>(PluginLoader.PhotonConnectionProtocol.Value, out ConnectionProtocol result))
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.Protocol = result;
				PluginLoader.StaticLogger.LogInfo((object)$"[Photon] Changed Protocol: {result}");
			}
			else
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.Protocol = (ConnectionProtocol)0;
			}
			if (PluginLoader.PhotonAlternativeUdpPorts.Value && (int)PhotonNetwork.PhotonServerSettings.AppSettings.Protocol == 0)
			{
				PhotonNetwork.ServerPortOverrides = PhotonPortDefinition.AlternativeUdpPorts;
			}
			else
			{
				PhotonNetwork.ServerPortOverrides = default(PhotonPortDefinition);
			}
			if (PluginLoader.PhotonAppIdEnabled.Value)
			{
				if (!string.IsNullOrEmpty(PluginLoader.PhotonAppIdRealtime.Value))
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = PluginLoader.PhotonAppIdRealtime.Value;
					PluginLoader.StaticLogger.LogInfo((object)("[Photon] Changed AppIdRealtime: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime));
				}
				if (!string.IsNullOrEmpty(PluginLoader.PhotonAppIdVoice.Value))
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = PluginLoader.PhotonAppIdVoice.Value;
					PluginLoader.StaticLogger.LogInfo((object)("[Photon] Changed AppIdVoice: " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice));
				}
			}
		}

		[HarmonyPatch(typeof(DataDirector), "PhotonSetRegion")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void DataDirector_PhotonSetRegion_Postfix()
		{
			if (!string.IsNullOrEmpty(PluginLoader.PhotonServerAddress.Value) && PluginLoader.PhotonServerVersion.Value == 4)
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
				PluginLoader.StaticLogger.LogInfo((object)"[Photon] Changed Region: Empty");
			}
		}

		[HarmonyPatch(typeof(PlatformManager), "SetPhotonAuthTicket")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void PlatformManager_SetPhotonAuthTicket_Postfix()
		{
			if (!string.IsNullOrEmpty(PluginLoader.PhotonServerAddress.Value) || !string.IsNullOrEmpty(PluginLoader.PhotonAppIdRealtime.Value) || !string.IsNullOrEmpty(PluginLoader.PhotonAppIdVoice.Value))
			{
				PhotonNetwork.AuthValues.AuthType = (CustomAuthenticationType)255;
				PluginLoader.StaticLogger.LogInfo((object)"[Photon] Changed AuthType: None");
			}
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "uk.1a3.photonserversettings";

		public const string PLUGIN_NAME = "PhotonServerSettings";

		public const string PLUGIN_VERSION = "1.0.5";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}