Decompiled source of PhotonServerSettings REPO v1.0.2

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

Decompiled 4 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;

[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: AssemblyCompany("uk.1a3.photonserversettings")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2+4c7779480b5c107a80cd7b18fcb8522c1af4582f")]
[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]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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.2")]
	internal class PluginLoader : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("uk.1a3.photonserversettings");

		private static bool initialized;

		internal static ConfigEntry<string> PhotonAppIdRealtime;

		internal static ConfigEntry<string> PhotonAppIdVoice;

		internal static ConfigEntry<string> PhotonServerAddress;

		internal static ConfigEntry<int> PhotonServerPort;

		internal static ConfigEntry<int> PhotonServerVersion;

		internal static ConfigEntry<string> PhotonConnectionProtocol;

		internal static ManualLogSource StaticLogger { get; private set; }

		internal static ConfigFile StaticConfig { get; private set; }

		private void Awake()
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			if (!initialized)
			{
				initialized = true;
				StaticLogger = ((BaseUnityPlugin)this).Logger;
				StaticConfig = ((BaseUnityPlugin)this).Config;
				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>()));
				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>()));
				harmony.PatchAll(typeof(GeneralPatches));
				StaticLogger.LogInfo((object)"Patches Loaded");
			}
		}
	}
	[HarmonyPatch]
	internal static class GeneralPatches
	{
		[HarmonyPatch(typeof(DataDirector), "PhotonSetAppId")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void DataDirector_PhotonSetAppId_Postfix()
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f1: 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;
			if (!string.IsNullOrEmpty(PluginLoader.PhotonServerAddress.Value))
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.Server = PluginLoader.PhotonServerAddress.Value;
				PluginLoader.StaticLogger.LogInfo((object)"Photon: Changed Server Address");
				if (PluginLoader.PhotonServerVersion.Value == 4)
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.UseNameServer = false;
					PhotonNetwork.NetworkingClient.SerializationProtocol = (SerializationProtocol)0;
				}
				if (PluginLoader.PhotonServerPort.Value > 0)
				{
					PhotonNetwork.PhotonServerSettings.AppSettings.Port = PluginLoader.PhotonServerPort.Value;
					PluginLoader.StaticLogger.LogInfo((object)"Photon: Changed Server Port");
				}
			}
			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 (!string.IsNullOrEmpty(PluginLoader.PhotonAppIdRealtime.Value))
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = PluginLoader.PhotonAppIdRealtime.Value;
				PluginLoader.StaticLogger.LogInfo((object)"Photon: Changed AppIdRealtime");
			}
			if (!string.IsNullOrEmpty(PluginLoader.PhotonAppIdVoice.Value))
			{
				PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = PluginLoader.PhotonAppIdVoice.Value;
				PluginLoader.StaticLogger.LogInfo((object)"Photon: Changed 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: Cleared Region");
			}
		}

		[HarmonyPatch(typeof(SteamManager), "SendSteamAuthTicket")]
		[HarmonyPostfix]
		[HarmonyWrapSafe]
		public static void SteamManager_SendSteamAuthTicket_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: Cleared Auth Type");
			}
		}
	}
	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.2";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}