Decompiled source of CustomPhotonServer v1.0.5

CustomPhotonServer.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using MenuLib;
using MenuLib.MonoBehaviors;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
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("RepoCustomPhotonServer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RepoCustomPhotonServer")]
[assembly: AssemblyTitle("RepoCustomPhotonServer")]
[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 RepoCustomPhotonServer
{
	[BepInPlugin("RepoCustomPhotonServer", "Custom Photon Server", "1.0.2")]
	internal sealed class RepoCustomPhotonServer : BaseUnityPlugin
	{
		[HarmonyPatch]
		private static class FixRepoConfig
		{
			[Serializable]
			[CompilerGenerated]
			private sealed class <>c
			{
				public static readonly <>c <>9 = new <>c();

				public static Func<ConfigEntryBase, string> <>9__1_0;

				public static Func<ConfigEntryBase, bool> <>9__1_1;

				public static Func<ConfigEntryBase, bool> <>9__1_2;

				public static Func<Assembly, IEnumerable<Type>> <>9__1_3;

				public static Func<Type, bool> <>9__1_4;

				public static ScrollViewBuilderDelegate <>9__1_5;

				public static Action <>9__1_11;

				internal string <Prefix>b__1_0(ConfigEntryBase entry)
				{
					return entry.Definition.Section;
				}

				internal bool <Prefix>b__1_1(ConfigEntryBase entry)
				{
					return entry.Definition.Section == "Photon AppIDs";
				}

				internal bool <Prefix>b__1_2(ConfigEntryBase entry)
				{
					return entry.Definition.Section != "Photon AppIDs";
				}

				internal IEnumerable<Type> <Prefix>b__1_3(Assembly a)
				{
					return a.GetTypes();
				}

				internal bool <Prefix>b__1_4(Type t)
				{
					return t.FullName == "REPOConfig.ConfigMenu";
				}

				internal RectTransform <Prefix>b__1_5(Transform scrollView)
				{
					//IL_0008: Unknown result type (might be due to invalid IL or missing references)
					//IL_000e: Unknown result type (might be due to invalid IL or missing references)
					REPOLabel obj = MenuAPI.CreateREPOLabel("Photon AppIDs", scrollView, default(Vector2));
					((TMP_Text)obj.labelTMP).fontStyle = (FontStyles)1;
					return ((REPOElement)obj).rectTransform;
				}

				internal void <Prefix>b__1_11()
				{
				}
			}

			private static MethodBase TargetMethod()
			{
				return AccessTools.Method(AccessTools.TypeByName("REPOConfig.ConfigMenu"), "CreateModEntries", new Type[2]
				{
					typeof(REPOPopupPage),
					typeof(ConfigEntryBase[])
				}, (Type[])null);
			}

			[HarmonyPrefix]
			private static bool Prefix(REPOPopupPage modPage, ConfigEntryBase[] configEntryBases)
			{
				//IL_0178: Unknown result type (might be due to invalid IL or missing references)
				//IL_018c: Expected O, but got Unknown
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a8: Expected O, but got Unknown
				//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c4: Expected O, but got Unknown
				//IL_011e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0123: Unknown result type (might be due to invalid IL or missing references)
				//IL_0129: Expected O, but got Unknown
				_ = from entry in configEntryBases
					group entry by entry.Definition.Section;
				if (!configEntryBases.Any((ConfigEntryBase entry) => entry.Definition.Section == "Photon AppIDs"))
				{
					return true;
				}
				ConfigEntryBase[] array = configEntryBases.Where((ConfigEntryBase entry) => entry.Definition.Section != "Photon AppIDs").ToArray();
				Type type = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.FullName == "REPOConfig.ConfigMenu");
				if (type != null)
				{
					MethodInfo method = type.GetMethod("CreateModEntries", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					if (method != null)
					{
						method.Invoke(null, new object[2] { modPage, array });
					}
				}
				object obj = <>c.<>9__1_5;
				if (obj == null)
				{
					ScrollViewBuilderDelegate val = delegate(Transform scrollView)
					{
						//IL_0008: Unknown result type (might be due to invalid IL or missing references)
						//IL_000e: Unknown result type (might be due to invalid IL or missing references)
						REPOLabel obj5 = MenuAPI.CreateREPOLabel("Photon AppIDs", scrollView, default(Vector2));
						((TMP_Text)obj5.labelTMP).fontStyle = (FontStyles)1;
						return ((REPOElement)obj5).rectTransform;
					};
					<>c.<>9__1_5 = val;
					obj = (object)val;
				}
				modPage.AddElementToScrollView((ScrollViewBuilderDelegate)obj, 0f, 0f);
				string AppIdRealtime = Instance.AppIdRealtime.Value;
				string AppIdVoice = Instance.AppIdVoice.Value;
				REPOInputField appIdRealtimeField = null;
				REPOInputField appIdVoiceField = null;
				modPage.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform scrollView)
				{
					//IL_0038: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					Action<string> obj4 = delegate(string s)
					{
						string text2 = (string.IsNullOrEmpty(s) ? null : s.ToLower().Trim());
						AppIdRealtime = text2;
					};
					string value2 = Instance.AppIdRealtime.Value;
					appIdRealtimeField = MenuAPI.CreateREPOInputField("AppId Realtime", obj4, scrollView, default(Vector2), false, "", value2);
					return ((REPOElement)appIdRealtimeField).rectTransform;
				}, 0f, 0f);
				modPage.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform scrollView)
				{
					//IL_0038: Unknown result type (might be due to invalid IL or missing references)
					//IL_003e: Unknown result type (might be due to invalid IL or missing references)
					Action<string> obj3 = delegate(string s)
					{
						string text = (string.IsNullOrEmpty(s) ? null : s.ToLower().Trim());
						AppIdVoice = text;
					};
					string value = Instance.AppIdVoice.Value;
					appIdVoiceField = MenuAPI.CreateREPOInputField("AppId Voice", obj3, scrollView, default(Vector2), false, "", value);
					return ((REPOElement)appIdVoiceField).rectTransform;
				}, 0f, 0f);
				modPage.AddElementToScrollView((ScrollViewBuilderDelegate)delegate(Transform scrollView)
				{
					//IL_0027: Unknown result type (might be due to invalid IL or missing references)
					//IL_002d: Unknown result type (might be due to invalid IL or missing references)
					//IL_007c: Unknown result type (might be due to invalid IL or missing references)
					//IL_0086: Expected O, but got Unknown
					//IL_00de: Unknown result type (might be due to invalid IL or missing references)
					//IL_00e4: Unknown result type (might be due to invalid IL or missing references)
					//IL_0117: Unknown result type (might be due to invalid IL or missing references)
					//IL_011d: Unknown result type (might be due to invalid IL or missing references)
					REPOButton val2 = MenuAPI.CreateREPOButton("", (Action)delegate
					{
					}, scrollView, default(Vector2));
					((Behaviour)val2).enabled = false;
					val2.menuButton.doButtonEffect = false;
					((Behaviour)val2.menuButton).enabled = false;
					_ = ((REPOElement)val2).rectTransform;
					HorizontalLayoutGroup obj2 = ((Component)val2).gameObject.AddComponent<HorizontalLayoutGroup>();
					((LayoutGroup)obj2).childAlignment = (TextAnchor)5;
					((HorizontalOrVerticalLayoutGroup)obj2).spacing = 6f;
					((LayoutGroup)obj2).padding = new RectOffset(0, 0, 0, 0);
					((HorizontalOrVerticalLayoutGroup)obj2).childControlWidth = false;
					((HorizontalOrVerticalLayoutGroup)obj2).childControlHeight = false;
					((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandWidth = false;
					((HorizontalOrVerticalLayoutGroup)obj2).childForceExpandHeight = false;
					((Component)val2).gameObject.AddComponent<ContentSizeFitter>().horizontalFit = (FitMode)0;
					MenuAPI.CreateREPOButton("Save", (Action)delegate
					{
						if (checkAppID(AppIdRealtime, appID: true))
						{
							Instance.AppIdRealtime.Value = AppIdRealtime;
						}
						if (checkAppID(AppIdVoice, appID: false))
						{
							Instance.AppIdVoice.Value = AppIdVoice;
						}
					}, ((Component)val2).transform, default(Vector2));
					MenuAPI.CreateREPOButton("Import from clipboard", (Action)delegate
					{
						//IL_0046: Unknown result type (might be due to invalid IL or missing references)
						//IL_0050: Expected O, but got Unknown
						//IL_0051: Unknown result type (might be due to invalid IL or missing references)
						//IL_005b: Expected O, but got Unknown
						//IL_0068: Unknown result type (might be due to invalid IL or missing references)
						//IL_0072: Expected O, but got Unknown
						//IL_007f: Unknown result type (might be due to invalid IL or missing references)
						//IL_0089: Expected O, but got Unknown
						//IL_0094: Unknown result type (might be due to invalid IL or missing references)
						string clipboardText = GUIUtility.systemCopyBuffer;
						if (Guid.TryParseExact(clipboardText ?? "", "D", out var _))
						{
							MenuButtonPopUp val3 = ((Component)MenuManager.instance).gameObject.AddComponent<MenuButtonPopUp>();
							val3.option1Event = new UnityEvent();
							val3.option2Event = new UnityEvent();
							val3.option1Event.AddListener((UnityAction)delegate
							{
								appIdRealtimeField.inputStringSystem.SetValue(clipboardText, true);
								if (checkAppID(clipboardText, appID: true))
								{
									Instance.AppIdRealtime.Value = clipboardText;
								}
							});
							val3.option2Event.AddListener((UnityAction)delegate
							{
								appIdVoiceField.inputStringSystem.SetValue(clipboardText, true);
								if (checkAppID(clipboardText, appID: false))
								{
									Instance.AppIdVoice.Value = clipboardText;
								}
							});
							MenuManager.instance.PagePopUpTwoOptions(val3, "Select the appid type", Color.yellow, "Please select the AppID type", "Realtime", "Voice", false);
						}
					}, ((Component)val2).transform, default(Vector2));
					return ((REPOElement)val2).rectTransform;
				}, 0f, 0f);
				return false;
			}
		}

		[HarmonyPatch(typeof(NetworkConnect))]
		public static class NetworkConnectPatch
		{
			[HarmonyPatch("Start")]
			[HarmonyPrefix]
			public static void Start_Prefix()
			{
				if (Instance.isActive.Value)
				{
					logger.LogInfo((object)"Updating Photon Settings");
					UpdatePhotonSettings();
				}
			}
		}

		[HarmonyPatch(typeof(DataDirector))]
		public static class DataDirectorPatch
		{
			[HarmonyPatch("PhotonSetAppId")]
			[HarmonyPrefix]
			public static void Start_Prefix()
			{
				if (Instance.isActive.Value)
				{
					logger.LogInfo((object)"Updating Photon Settings");
					UpdatePhotonSettings();
				}
			}
		}

		[HarmonyPatch(typeof(SteamManager))]
		public static class SteamManagerPatch
		{
			[HarmonyPatch("Awake")]
			[HarmonyPrefix]
			public static void Awake_Prefix()
			{
				if (Instance.isChangeSteamAppId.Value)
				{
					logger.LogInfo((object)$"Change appid to {480u}");
					SteamClient.Init(480u, true);
				}
			}

			[HarmonyPatch("Start")]
			[HarmonyPrefix]
			public static void Start_Prefix()
			{
				if (Instance.isChangeSteamAppId.Value)
				{
					logger.LogInfo((object)"Doing something in Start");
					UpdateAuthMethod();
				}
			}

			[HarmonyPatch("SendSteamAuthTicket")]
			[HarmonyPrefix]
			public static bool SendSteamAuthTicket_Prefix()
			{
				if (Instance.isActive.Value)
				{
					logger.LogInfo((object)"Updating Auth Method");
					UpdateAuthMethod();
					return false;
				}
				return true;
			}
		}

		internal static readonly ManualLogSource logger = Logger.CreateLogSource("Photon fixer");

		public ConfigEntry<bool> isActive;

		public ConfigEntry<bool> isChangeSteamAppId;

		public ConfigEntry<string> AppIdRealtime;

		public ConfigEntry<string> AppIdVoice;

		internal static AuthTicket steamAuthTicket;

		public static RepoCustomPhotonServer Instance { get; private set; }

		private void Awake()
		{
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Expected O, but got Unknown
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			logger.LogInfo((object)"RepoCustomPhotonServer Loaded!");
			isActive = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable", false, (ConfigDescription)null);
			isChangeSteamAppId = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Change SteamAppId", false, (ConfigDescription)null);
			AppIdRealtime = ((BaseUnityPlugin)this).Config.Bind<string>("Photon AppIDs", "AppIdRealtime", "", new ConfigDescription("Photon Realtime App ID", (AcceptableValueBase)null, Array.Empty<object>()));
			AppIdVoice = ((BaseUnityPlugin)this).Config.Bind<string>("Photon AppIDs", "AppIdVoice", "", new ConfigDescription("Photon Voice App ID", (AcceptableValueBase)null, Array.Empty<object>()));
			new Harmony("RepoCustomPhotonServer").PatchAll();
		}

		private static bool checkAppID(string input, bool appID)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			if (!Guid.TryParseExact(input ?? "", "D", out var _))
			{
				if (appID)
				{
					MenuManager.instance.PagePopUp("Invalid AppID", Color.red, "Invalid AppIdVoice format. It must be in the format of a Guid (e.g., h26742gw-96e2-4c18-93c4-978176705b0c).", "OK.", false);
				}
				else
				{
					MenuManager.instance.PagePopUp("Invalid AppID", Color.red, "Invalid AppIdRealtime format. It must be in the format of a Guid (e.g., h26742gw-96e2-4c18-93c4-978176705b0c).", "OK.", false);
				}
				return false;
			}
			return true;
		}

		private static string GetSteamAuthTicket(out AuthTicket ticket)
		{
			logger.LogInfo((object)"Getting Steam Auth Ticket...");
			ticket = SteamUser.GetAuthSessionTicket();
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < ticket.Data.Length; i++)
			{
				stringBuilder.AppendFormat("{0:x2}", ticket.Data[i]);
			}
			return stringBuilder.ToString();
		}

		private static void UpdatePhotonSettings()
		{
			ServerSettings val = Object.FindObjectOfType<ServerSettings>() ?? Resources.Load<ServerSettings>("PhotonServerSettings");
			if ((Object)(object)val != (Object)null)
			{
				val.AppSettings.AppIdRealtime = Instance.AppIdRealtime.Value;
				val.AppSettings.AppIdVoice = Instance.AppIdVoice.Value;
				logger.LogDebug((object)("AppIdRealtime: " + val.AppSettings.AppIdRealtime));
				logger.LogDebug((object)("AppIdVoice: " + val.AppSettings.AppIdVoice));
				PhotonNetwork.ConnectUsingSettings();
			}
		}

		private static void UpdateAuthMethod()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Expected O, but got Unknown
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			PhotonNetwork.AuthValues = new AuthenticationValues();
			AuthenticationValues authValues = PhotonNetwork.AuthValues;
			SteamId steamId = SteamClient.SteamId;
			authValues.UserId = ((object)(SteamId)(ref steamId)).ToString();
			PhotonNetwork.AuthValues.AuthType = (CustomAuthenticationType)255;
			string text = GetSteamAuthTicket(out steamAuthTicket);
			logger.LogDebug((object)("SteamAuthTicket: " + text));
			PhotonNetwork.AuthValues.AddAuthParameter("ticket", text);
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}