Decompiled source of Self Hosted Photon v0.1.0

plugins/Self_Hosted_Photon.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.IO;
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 Steamworks.Data;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("zyxterus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Copyright © 2025 zyxterus")]
[assembly: AssemblyDescription("Allows you to connect to a self-hosted Photon server via an IP address or a hostname.")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+1790697de71b2100bb1778eec0eac116caf202fb")]
[assembly: AssemblyProduct("Self_Hosted_Photon")]
[assembly: AssemblyTitle("Self_Hosted_Photon")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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.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;
		}
	}
	[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 Self_Hosted_Photon
{
	internal static class ConfigManager
	{
		public static ConfigFile ConfigFile { get; private set; }

		public static ConfigEntry<bool> Enabled { get; private set; }

		public static ConfigEntry<string> ServerAddress { get; private set; }

		public static ConfigEntry<string> ServerPort { get; private set; }

		public static void Initialize(ConfigFile configFile)
		{
			ConfigFile = configFile;
			BindConfigs();
		}

		private static void BindConfigs()
		{
			Enabled = ConfigFile.Bind<bool>("General", "Enabled", true, "Enable or disable the plugin.");
			ServerAddress = ConfigFile.Bind<string>("Server", "Address", "127.0.0.1", "The IP address or hostname of the Photon server.");
			ServerPort = ConfigFile.Bind<string>("Server", "Port", "5055", "The port number of the Photon server.");
		}
	}
	internal static class Logger
	{
		public static ManualLogSource ManualLogSource { get; private set; }

		public static void Initialize(ManualLogSource manualLogSource)
		{
			ManualLogSource = manualLogSource;
		}

		public static void LogDebug(object data)
		{
			Log((LogLevel)32, data);
		}

		public static void LogInfo(object data)
		{
			Log((LogLevel)16, data);
		}

		public static void LogMessage(object data)
		{
			Log((LogLevel)8, data);
		}

		public static void LogWarning(object data)
		{
			Log((LogLevel)4, data);
		}

		public static void LogError(object data)
		{
			Log((LogLevel)2, data);
		}

		public static void LogFatal(object data)
		{
			Log((LogLevel)1, data);
		}

		public static void Log(LogLevel logLevel, object data)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			ManualLogSource manualLogSource = ManualLogSource;
			if (manualLogSource != null)
			{
				manualLogSource.Log(logLevel, data);
			}
		}
	}
	[BepInPlugin("Self_Hosted_Photon", "Self_Hosted_Photon", "0.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		internal static Plugin Instance { get; private set; }

		internal static string PluginFolder => Path.GetDirectoryName(((BaseUnityPlugin)Instance).Info.Location);

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			Logger.Initialize(Logger.CreateLogSource("Self_Hosted_Photon"));
			Logger.LogDebug("Self_Hosted_Photon has awoken!");
			ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
			Logger.LogDebug("ConfigManager initialized.");
			HarmonyPatch();
			Logger.LogDebug("Harmony patches applied.");
			Logger.LogInfo($"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
		}

		internal void HarmonyPatch()
		{
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0025: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void HarmonyUnpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Self_Hosted_Photon";

		public const string PLUGIN_NAME = "Self_Hosted_Photon";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace Self_Hosted_Photon.Patches
{
	[HarmonyPatch(typeof(DataDirector))]
	internal static class DataDirectorPatch
	{
		[HarmonyPatch("PhotonSetAppId")]
		[HarmonyPrefix]
		private static bool PhotonSetAppIdPrefix()
		{
			if (!ConfigManager.Enabled.Value)
			{
				return true;
			}
			PhotonNetwork.NetworkingClient.SerializationProtocol = (SerializationProtocol)0;
			PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime = string.Empty;
			PhotonNetwork.PhotonServerSettings.AppSettings.AppIdVoice = string.Empty;
			string value = ConfigManager.ServerAddress.Value;
			ushort port = ushort.Parse(ConfigManager.ServerPort.Value);
			PhotonNetwork.PhotonServerSettings.AppSettings.Server = value;
			PhotonNetwork.PhotonServerSettings.AppSettings.Port = port;
			PhotonNetwork.PhotonServerSettings.AppSettings.UseNameServer = false;
			return false;
		}
	}
	[HarmonyPatch(typeof(Lobby))]
	internal static class LobbyPatch
	{
		[HarmonyPatch("SetData")]
		[HarmonyPrefix]
		private static void SetDataPrefix(string key, ref string value)
		{
			if (ConfigManager.Enabled.Value && key == "Region" && string.IsNullOrWhiteSpace(value))
			{
				value = "eu";
				Logger.LogDebug("Overriding Region to eu in SetData");
			}
		}
	}
	[HarmonyPatch(typeof(MenuPageRegions))]
	internal static class MenuPageRegionsPatch
	{
		[CompilerGenerated]
		private sealed class <GetRegions>d__1 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public MenuPageRegions __instance;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <GetRegions>d__1(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
				//IL_0107: Unknown result type (might be due to invalid IL or missing references)
				//IL_0108: Unknown result type (might be due to invalid IL or missing references)
				//IL_013e: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0054: Invalid comparison between Unknown and I4
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
				//IL_00db: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					PhotonNetwork.Disconnect();
					goto IL_0048;
				case 1:
					<>1__state = -1;
					goto IL_0048;
				case 2:
					<>1__state = -1;
					goto IL_00ae;
				case 3:
				{
					<>1__state = -1;
					Vector3 position = __instance.transformStartPosition.position;
					MenuElementRegion component = Object.Instantiate<GameObject>(__instance.regionPrefab, position, Quaternion.identity, __instance.transformStartPosition.parent).GetComponent<MenuElementRegion>();
					((TMP_Text)component.textName).text = "Custom Host";
					((Graphic)component.textName).color = Color.white;
					((TMP_Text)component.textPing).text = "";
					component.parentPage = __instance;
					component.regionCode = "custom";
					PhotonNetwork.Disconnect();
					((Behaviour)__instance.menuScrollBox).enabled = true;
					break;
				}
				case 4:
					{
						<>1__state = -1;
						break;
					}
					IL_0048:
					if ((int)PhotonNetwork.NetworkingClient.State != 14 && (int)PhotonNetwork.NetworkingClient.State != 0)
					{
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					DataDirector.instance.PhotonSetAppId();
					SteamManager.instance.SendSteamAuthTicket();
					PhotonNetwork.PhotonServerSettings.AppSettings.FixedRegion = "";
					ServerSettings.ResetBestRegionCodeInPreferences();
					PhotonNetwork.ConnectUsingSettings();
					goto IL_00ae;
					IL_00ae:
					if (!__instance.connectedToMaster)
					{
						<>2__current = null;
						<>1__state = 2;
						return true;
					}
					__instance.loadingGraphics.SetDone();
					<>2__current = (object)new WaitForSecondsRealtime(0.3f);
					<>1__state = 3;
					return true;
				}
				if (__instance.scrollCanvasGroup.alpha < 0.99f)
				{
					CanvasGroup scrollCanvasGroup = __instance.scrollCanvasGroup;
					scrollCanvasGroup.alpha += Time.deltaTime * 5f;
					<>2__current = null;
					<>1__state = 4;
					return true;
				}
				__instance.scrollCanvasGroup.alpha = 1f;
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		[HarmonyPatch("Start")]
		[HarmonyPrefix]
		private static bool StartPrefix(MenuPageRegions __instance)
		{
			if (!ConfigManager.Enabled.Value)
			{
				return true;
			}
			((MonoBehaviour)__instance).StartCoroutine(GetRegions(__instance));
			return false;
		}

		[IteratorStateMachine(typeof(<GetRegions>d__1))]
		private static IEnumerator GetRegions(MenuPageRegions __instance)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <GetRegions>d__1(0)
			{
				__instance = __instance
			};
		}
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
	internal sealed class SetsRequiredMembersAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
	internal sealed class RequiredMemberAttribute : Attribute
	{
	}
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	internal sealed class CompilerFeatureRequiredAttribute : Attribute
	{
		public const string RefStructs = "RefStructs";

		public const string RequiredMembers = "RequiredMembers";

		public string FeatureName { get; }

		public bool IsOptional { get; set; }

		public CompilerFeatureRequiredAttribute(string featureName)
		{
			FeatureName = featureName;
		}
	}
	[ExcludeFromCodeCoverage]
	[DebuggerNonUserCode]
	internal static class IsExternalInit
	{
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}