Decompiled source of AirframeAPI v1.0.0

Mods/AirframeAPI.dll

Decompiled 17 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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 System.Text.RegularExpressions;
using AirframeAPI;
using AirframeAPI.Extensions;
using AirframeAPI.Features;
using AirframeAPI.Interfaces;
using AirframeAPI.Registration;
using HarmonyLib;
using Il2Cpp;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppMenu;
using Il2CppPhoton.Client;
using Il2CppPhoton.Realtime;
using Il2CppSystem;
using Il2CppSystem.Collections;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Semver;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonPriority(-1000)]
[assembly: MelonInfo(typeof(AirframeAPI_Core), "AirframeAPI", "1.0.0", "blankochan", "https://thunderstore.io/c/airframe-ultra/p/blankochan/AirframeAPI/")]
[assembly: MelonGame("Videocult", "Airframe")]
[assembly: MelonColor(255, 176, 11, 19)]
[assembly: MelonAuthorColor(255, 255, 170, 238)]
[assembly: AirframeModTags(typeof(AirframeAPI_Core), ModTags.IsLocalClientOnly, VersionPreference.Same)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("AirframeAPI")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+13292ea2f29d2a5cc4cbbc8369a4fb9bc7d75822")]
[assembly: AssemblyProduct("AirframeAPI")]
[assembly: AssemblyTitle("AirframeAPI")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class IsUnmanagedAttribute : Attribute
	{
	}
	[CompilerGenerated]
	[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]
	[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 AirframeAPI
{
	internal class AirframeAPI_Core : MelonMod
	{
		internal static AirframeAPI_Core Instance;

		private string _configPath = Path.Combine(MelonEnvironment.UserDataDirectory, "AirframeAPI.toml");

		private static MelonPreferences_Category _apiPrefs = MelonPreferences.CreateCategory("AirframeAPI");

		internal static Instance Logger => ((MelonBase)Instance).LoggerInstance;

		public override void OnEarlyInitializeMelon()
		{
			Instance = this;
			_apiPrefs.SetFilePath(_configPath, true, false);
			if (File.Exists(_configPath))
			{
				_apiPrefs.LoadFromFile(false);
			}
			else
			{
				_apiPrefs.SaveToFile(true);
			}
		}

		public override void OnLateInitializeMelon()
		{
			RegistrationAPI.RegisterAttributeBasedMelons();
		}

		public override void OnSceneWasLoaded(int buildIndex, string sceneName)
		{
			if (sceneName == "MainMenu")
			{
				PhotonHandler.OnMainMenuLoaded();
			}
		}
	}
	internal class BuildInfo
	{
		internal const string Name = "AirframeAPI";

		internal const string Version = "1.0.0";

		internal const string Author = "blankochan";

		internal const string DownloadUrl = "https://thunderstore.io/c/airframe-ultra/p/blankochan/AirframeAPI/";
	}
	internal static class PhotonHandler
	{
		public static RealtimeClient networkingClient;

		public static PhotonController controller;

		public static int? LastRoomCode;

		public static RoomRegistrationInfo? LastRoomInfo;

		public static Dictionary<IDisableable, bool> originalDisablableStates = new Dictionary<IDisableable, bool>(RegistrationAPI.DisableableMods.Count);

		public static Instance Logger => AirframeAPI_Core.Logger;

		public static void OnEvent(EventData eventData)
		{
			if (eventData.Code == 4)
			{
				UpdateLastRoomRegistrationInfo(networkingClient.CurrentRoom);
			}
			if (eventData.Code == EventCode.GameList)
			{
				ParseRooms(((Il2CppObjectBase)eventData[ParameterCode.GameList]).Cast<PhotonHashtable>());
			}
			if (eventData.Code == EventCode.GameListUpdate)
			{
				ParseRooms(((Il2CppObjectBase)eventData[ParameterCode.GameList]).Cast<PhotonHashtable>());
			}
		}

		public static void HandleLastRoomInfo()
		{
			if ((!LastRoomCode.HasValue || LastRoomInfo == null) && ((Dictionary<Object, Object>)(object)((RoomInfo)networkingClient.CurrentRoom).CustomProperties).ContainsKey(Object.op_Implicit("AirframeAPI")))
			{
				UpdateLastRoomRegistrationInfo(networkingClient.CurrentRoom);
			}
			if (LastRoomCode.HasValue || LastRoomInfo != null)
			{
				AddAirframeAPI_ToRoom(networkingClient.CurrentRoom);
			}
		}

		public static void ClearLastRoomRegistrationInfo()
		{
			LastRoomCode = null;
			LastRoomInfo = null;
		}

		public static void UpdateLastRoomRegistrationInfo(Room room)
		{
			Object val = default(Object);
			if (((Dictionary<Object, Object>)(object)((RoomInfo)room).CustomProperties).TryGetValue(Object.op_Implicit("AirframeAPI"), ref val))
			{
				PhotonHashtable val2 = ((Il2CppObjectBase)val).TryCast<PhotonHashtable>();
				if (val2 != null && RoomRegistrationInfo.TryParseFromHashtable(val2, out RoomRegistrationInfo roomRegistrationInfo))
				{
					LastRoomInfo = roomRegistrationInfo;
					LastRoomCode = PhotonHashtableExtensions.GetIntOrZero(((RoomInfo)room).CustomProperties, Object.op_Implicit("ROOM_CODE_INT"));
				}
			}
		}

		public static void RestoreOriginalDisabledState()
		{
			throw new NotImplementedException("see message in PhotonHandler.HandleDisableableMods");
		}

		public static void OnMainMenuLoaded()
		{
			ClearLastRoomRegistrationInfo();
			Utilities.Events.InvokeMainMenuLoaded();
		}

		public static void AddAirframeAPI_ToRoom(Room room)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Expected O, but got Unknown
			if (((Dictionary<Object, Object>)(object)((RoomInfo)room).CustomProperties).ContainsKey(Object.op_Implicit("AirframeAPI")) || !networkingClient.LocalPlayer.IsMasterClient)
			{
				return;
			}
			if (PhotonHashtableExtensions.GetIntOrZero(((RoomInfo)room).CustomProperties, Object.op_Implicit("ROOM_CODE_INT")) == LastRoomCode)
			{
				if (LastRoomInfo != null)
				{
					Logger.Msg("Installing AirframeAPI to " + room.Name);
					PhotonHashtable val = new PhotonHashtable(1)
					{
						[Object.op_Implicit("AirframeAPI")] = (Object)(object)LastRoomInfo.ToHashtable(),
						[Object.op_Implicit("IS_PRIVATE_GAME")] = Object.op_Implicit(LastRoomInfo.RequiredMods.Count() > 0)
					};
					room.SetPropertiesListedInLobby(((IEnumerable<Object>)room.PropertiesListedInLobby).Append(Object.op_Implicit("AirframeAPI")).ToIl2CppReferenceArray<Object>());
					room.SetCustomProperties(val, (PhotonHashtable)null);
				}
			}
			else
			{
				ClearLastRoomRegistrationInfo();
			}
		}

		private static void saveOriginalDisablableStates()
		{
			foreach (RegistrationInfo disableableMod in RegistrationAPI.DisableableMods)
			{
				if (disableableMod.Melon is IDisableable disableable)
				{
					originalDisablableStates.Add(disableable, disableable.Enabled);
				}
			}
		}

		public static void HandleDisableableMods(PhotonHashtable roomProps)
		{
			throw new NotImplementedException("Partially implemented");
		}

		public static void ParseRooms(PhotonHashtable rooms)
		{
			DictionaryEntryEnumerator enumerator = rooms.GetEnumerator();
			Object val2 = default(Object);
			while (enumerator.MoveNext())
			{
				DictionaryEntry current = enumerator.Current;
				string roomName = current.Key.ToString();
				PhotonHashtable val = ((Il2CppObjectBase)current.Value).Cast<PhotonHashtable>();
				if (!findRoomByPredicate((PhotonControllerRoomData room) => room.name == roomName, out var roomData, out var roomIndex))
				{
					continue;
				}
				if (RegistrationAPI.RegisteredMods.Any((RegistrationInfo modInfo) => !modInfo.Tags.HasTag(ModTags.CanJoinVanilla)) && !((Dictionary<Object, Object>)(object)val).ContainsKey(Object.op_Implicit("AirframeAPI")))
				{
					HideRoom(roomData, roomIndex);
				}
				else
				{
					if (!((Dictionary<Object, Object>)(object)val).TryGetValue(Object.op_Implicit("AirframeAPI"), ref val2))
					{
						continue;
					}
					PhotonHashtable val3 = ((Il2CppObjectBase)val2).TryCast<PhotonHashtable>();
					if (val3 == null || !RoomRegistrationInfo.TryParseFromHashtable(val3, out RoomRegistrationInfo roomRegistrationInfo))
					{
						continue;
					}
					bool flag = true;
					if (roomRegistrationInfo.IsActuallyPrivate)
					{
						flag = false;
					}
					foreach (RegistrationInfo remoteMod in roomRegistrationInfo.RequiredMods)
					{
						RegistrationInfo registrationInfo = RegistrationAPI.RegisteredMods.FirstOrDefault((RegistrationInfo localMod) => localMod.Name == remoteMod.Name, null);
						if (registrationInfo != null)
						{
							if (!registrationInfo.CheckCompatibility(remoteMod))
							{
								flag = false;
								HideRoom(roomData, roomIndex, "Incompatible mod versions");
							}
						}
						else
						{
							flag = false;
							HideRoom(roomData, roomIndex, "Mod not installed");
						}
					}
					if (flag)
					{
						ShowRoom(roomData, roomIndex);
					}
					else
					{
						HideRoom(roomData, roomIndex);
					}
				}
			}
			static void HideRoom(PhotonControllerRoomData val4, int num, string Reason = "Unspecified")
			{
				val4.isPrivate = true;
				controller.availableRooms[num] = val4;
			}
			static void ShowRoom(PhotonControllerRoomData val4, int num, string Reason = "Unspecified")
			{
				val4.isPrivate = false;
				controller.availableRooms[num] = val4;
			}
			static bool findRoomByPredicate(Predicate<PhotonControllerRoomData> predicate, out PhotonControllerRoomData reference, out int reference2)
			{
				for (int i = 0; i < controller.availableRooms.Count; i++)
				{
					reference = controller.availableRooms[i];
					if (predicate(reference))
					{
						reference2 = i;
						return true;
					}
				}
				reference = null;
				reference2 = -1;
				return false;
			}
		}
	}
}
namespace AirframeAPI.Registration
{
	[AttributeUsage(AttributeTargets.Assembly)]
	public class AirframeModTagsAttribute : Attribute
	{
		public ModTags Tags { get; init; }

		public Type MelonType { get; init; }

		public VersionPreference VersionPreference { get; init; }

		public AirframeModTagsAttribute(Type melonType, ModTags tags, VersionPreference versionPreference = VersionPreference.Same)
		{
			Tags = tags;
			MelonType = melonType;
			VersionPreference = versionPreference;
		}
	}
	[Flags]
	public enum ModTags : uint
	{
		Unspecified = 0u,
		IsRequiredToJoin = 1u,
		CanJoinVanilla = 2u,
		IsLocalClientOnly = 6u,
		CanBeDisabled = 8u,
		DesiresFailSafe = 0x11u,
		Reserved = 0xFFFFFFC0u
	}
	public record PhotonPlayerRegistrationInfo
	{
		public const byte SpecVersion = 1;

		public const string API_Version = "1.0.0";

		public IEnumerable<RegistrationInfo> Mods;

		public PhotonPlayerRegistrationInfo(IEnumerable<RegistrationInfo> mods)
		{
			Mods = mods;
		}

		public PhotonHashtable ToHashtable()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Expected O, but got Unknown
			return new PhotonHashtable(3)
			{
				[Object.op_Implicit("SpecVersion")] = Object.op_Implicit((byte)1),
				[Object.op_Implicit("API_Version")] = Object.op_Implicit("1.0.0"),
				[Object.op_Implicit("Mods")] = ((Il2CppObjectBase)Mods.Select((RegistrationInfo info) => info.ToHashtable()).ToIl2CppReferenceArray<PhotonHashtable>()).Cast<Object>()
			};
		}

		[CompilerGenerated]
		protected PhotonPlayerRegistrationInfo(PhotonPlayerRegistrationInfo original)
		{
			Mods = original.Mods;
		}
	}
	public static class RegistrationAPI
	{
		private static Dictionary<string, ModTags> _manualMelonTags = new Dictionary<string, ModTags> { ["UnityExplorer"] = ModTags.IsLocalClientOnly };

		private static HashSet<string> _registeredMelonHashes = new HashSet<string>(MelonTypeBase<MelonMod>.RegisteredMelons.Count);

		private static List<RegistrationInfo> _registeredMods = new List<RegistrationInfo>(MelonTypeBase<MelonMod>.RegisteredMelons.Count);

		private static List<RegistrationInfo> _disabableMods = new List<RegistrationInfo>(MelonTypeBase<MelonMod>.RegisteredMelons.Count);

		private static Dictionary<string, MelonBase> _hashToMelon = new Dictionary<string, MelonBase>(MelonTypeBase<MelonMod>.RegisteredMelons.Count);

		public const string AlphanumericRegex = "^[a-zA-Z0-9_]*$";

		public static IReadOnlyList<RegistrationInfo> RegisteredMods => _registeredMods;

		public static IReadOnlyList<RegistrationInfo> DisableableMods => _disabableMods;

		public static bool FailsafeActive { get; private set; } = false;

		public static void EngageFailsafe(string reason = "Unspecified")
		{
			AirframeAPI_Core.Logger.BigError("Entering Fail safe because '" + reason + "'");
			FailsafeActive = true;
		}

		public static List<RegistrationInfo> GetRequiredToJoinMods(bool enabledOnly = true)
		{
			List<RegistrationInfo> list = new List<RegistrationInfo>(_registeredMods.Count);
			foreach (RegistrationInfo registeredMod in RegisteredMods)
			{
				if (registeredMod.Tags.HasTag(ModTags.IsRequiredToJoin) && (!enabledOnly || !registeredMod.Tags.HasTag(ModTags.CanBeDisabled) || !(registeredMod.Melon is IDisableable { Enabled: false })))
				{
					list.Add(registeredMod);
				}
			}
			return list;
		}

		internal static RoomRegistrationInfo BuildRoomRegistration(bool isPrivate = false)
		{
			return new RoomRegistrationInfo(GetRequiredToJoinMods(), isPrivate);
		}

		internal static PhotonPlayerRegistrationInfo BuildLocalPlayerRegistration()
		{
			return new PhotonPlayerRegistrationInfo(RegisteredMods);
		}

		public static void Register(MelonBase melon, ModTags tags, VersionPreference versionPreference = VersionPreference.Same)
		{
			MelonInfoAttribute info = melon.Info;
			if (_registeredMelonHashes.Contains(melon.MelonAssembly.Hash))
			{
				return;
			}
			if (melon.MelonTypeName != "Mod")
			{
				AirframeAPI_Core.Logger.Warning($"'{melon.Info.Name}' Is a Melon{melon.MelonTypeName} instead of a 'MelonMod'");
			}
			RegistrationInfo registrationInfo = RegistrationInfo.FromMelon(melon, tags, versionPreference);
			if (!registrationInfo.CheckValidity(out string RejectionReason))
			{
				EngageFailsafe(info.Name + " could not be validated '" + RejectionReason + "' ");
			}
			if (registrationInfo.Tags == ModTags.Unspecified)
			{
				EngageFailsafe(info.Name + " does not specify its ModTags");
			}
			if (registrationInfo.Tags.HasTag(ModTags.DesiresFailSafe))
			{
				EngageFailsafe(info.Name + " has DesiresFailSafe");
			}
			if (registrationInfo.Tags.HasTag(ModTags.Reserved))
			{
				EngageFailsafe(info.Name + " has a reserved tag");
			}
			if (registrationInfo.Tags.HasTag(ModTags.IsLocalClientOnly) && registrationInfo.Tags.HasTag(ModTags.IsRequiredToJoin))
			{
				EngageFailsafe(info.Name + " is tagged with LocalClientOnly, but also has IsRequiredToJoin");
			}
			if (registrationInfo.Tags.HasTag(ModTags.CanBeDisabled))
			{
				if (!(melon is IDisableable))
				{
					EngageFailsafe(info.Name + " is tagged with CanBeDisabled but does not implement AirframeAPI.Interfaces.IDisableable");
				}
				else
				{
					_disabableMods.Add(registrationInfo);
				}
			}
			_registeredMelonHashes.Add(melon.MelonAssembly.Hash);
			_hashToMelon.Add(melon.MelonAssembly.Hash, melon);
			_registeredMods.Add(registrationInfo);
		}

		internal static void RegisterAttributeBasedMelons()
		{
			foreach (MelonBase melon in MelonBase.RegisteredMelons)
			{
				if (!(melon.MelonTypeName != "Mod") && !_registeredMelonHashes.Contains(melon.MelonAssembly.Hash))
				{
					IEnumerable<AirframeModTagsAttribute> source = melon.MelonAssembly.Assembly.GetCustomAttributes(inherit: false).OfType<AirframeModTagsAttribute>();
					ModTags tags = ModTags.Unspecified;
					VersionPreference versionPreference = VersionPreference.Same;
					AirframeModTagsAttribute airframeModTagsAttribute = source.FirstOrDefault((AirframeModTagsAttribute attr) => attr.MelonType == ((object)melon).GetType(), null);
					if (airframeModTagsAttribute != null)
					{
						tags = airframeModTagsAttribute.Tags;
						versionPreference = airframeModTagsAttribute.VersionPreference;
					}
					if (_manualMelonTags.TryGetValue(melon.Info.Name, out var value))
					{
						tags = value;
					}
					Register(melon, tags, versionPreference);
				}
			}
		}
	}
	public record RegistrationInfo
	{
		public bool IsValid
		{
			get
			{
				string RejectionReason;
				return CheckValidity(out RejectionReason);
			}
		}

		public MelonBase? Melon { get; private set; }

		public string Name;

		public string Author;

		public string Version;

		public string Hash;

		public string? DownloadLink;

		public ModTags Tags;

		public VersionPreference VersionPreference;

		public bool IsLocal = true;

		public RegistrationInfo()
		{
			Name = "Unknown";
			Author = "Unknown";
			Version = "0.0.0";
			Hash = "Unknown";
		}

		public bool CheckCompatibility(RegistrationInfo remoteMod)
		{
			return VersionPreference switch
			{
				VersionPreference.Any => true, 
				VersionPreference.Same => Version == remoteMod.Version, 
				VersionPreference.SameOrNewer => SemVersion.Parse(Version, false) >= SemVersion.Parse(remoteMod.Version, false), 
				VersionPreference.SameOrOlder => SemVersion.Parse(Version, false) <= SemVersion.Parse(remoteMod.Version, false), 
				VersionPreference.ExactHash => Hash == remoteMod.Hash, 
				_ => false, 
			};
		}

		public bool CheckValidity(out string RejectionReason)
		{
			if (Name.Length > 128)
			{
				RejectionReason = "Name over 128 characters";
				return false;
			}
			if (Author.Length > 128)
			{
				RejectionReason = "Author over 128 characters";
				return false;
			}
			if (Version.Length > 32)
			{
				RejectionReason = "Version string over 32 characters";
				return false;
			}
			if (DownloadLink != null && DownloadLink.Length > 512)
			{
				RejectionReason = "DownloadLink over 512 characters";
				return false;
			}
			if (Hash.Length != 64)
			{
				RejectionReason = "Invalid Hash";
				return false;
			}
			if (!Regex.IsMatch(Name, "^[a-zA-Z0-9_]*$"))
			{
				RejectionReason = "Name does not match '^[a-zA-Z0-9_]*$'";
				return false;
			}
			SemVersion val = default(SemVersion);
			if (!SemVersion.TryParse(Version, ref val, false))
			{
				RejectionReason = "Version string is not valid semvar";
				return false;
			}
			if (!Enum.IsDefined(VersionPreference))
			{
				RejectionReason = "Invalid VersionPreference";
				return false;
			}
			RejectionReason = null;
			return true;
		}

		internal static RegistrationInfo FromMelon(MelonBase melon, ModTags tags, VersionPreference versionPref = VersionPreference.Same)
		{
			MelonInfoAttribute info = melon.Info;
			return new RegistrationInfo
			{
				Name = info.Name,
				Author = info.Author,
				Version = info.Version,
				Hash = melon.MelonAssembly.Hash,
				DownloadLink = info.DownloadLink,
				Tags = tags,
				VersionPreference = versionPref,
				IsLocal = true,
				Melon = melon
			};
		}

		public PhotonHashtable ToHashtable()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			PhotonHashtable val = new PhotonHashtable(6)
			{
				[Object.op_Implicit("Name")] = Object.op_Implicit(Name),
				[Object.op_Implicit("Author")] = Object.op_Implicit(Author),
				[Object.op_Implicit("Version")] = Object.op_Implicit(Version),
				[Object.op_Implicit("Hash")] = Object.op_Implicit(Hash),
				[Object.op_Implicit("Tags")] = Object.op_Implicit((int)Tags),
				[Object.op_Implicit("VersionPreference")] = Object.op_Implicit((int)VersionPreference)
			};
			if (DownloadLink != null)
			{
				val[Object.op_Implicit("DownloadLink")] = Object.op_Implicit(DownloadLink);
			}
			return val;
		}

		public static RegistrationInfo? FromHashtable(PhotonHashtable table)
		{
			TryFromHashtable(table, out RegistrationInfo registrationInfo);
			return registrationInfo;
		}

		public static bool TryFromHashtable(PhotonHashtable table, out RegistrationInfo registrationInfo)
		{
			registrationInfo = null;
			Object val = default(Object);
			if (((Dictionary<Object, Object>)(object)table).TryGetValue(Object.op_Implicit("Name"), ref val))
			{
				string name = val.ToString();
				Object val2 = default(Object);
				if (((Dictionary<Object, Object>)(object)table).TryGetValue(Object.op_Implicit("Author"), ref val2))
				{
					string author = val2.ToString();
					Object val3 = default(Object);
					if (((Dictionary<Object, Object>)(object)table).TryGetValue(Object.op_Implicit("Version"), ref val3))
					{
						string version = val3.ToString();
						Object val4 = default(Object);
						if (((Dictionary<Object, Object>)(object)table).TryGetValue(Object.op_Implicit("Hash"), ref val4))
						{
							string hash = val4.ToString();
							Object val5 = default(Object);
							string downloadLink = ((!((Dictionary<Object, Object>)(object)table).TryGetValue(Object.op_Implicit("DownloadLink"), ref val5)) ? null : val5.ToString());
							int num = default(int);
							if (PhotonHashtableExtensions.TryGetInt(table, Object.op_Implicit("Tags"), ref num))
							{
								ModTags tags = (ModTags)num;
								int num2 = default(int);
								if (PhotonHashtableExtensions.TryGetInt(table, Object.op_Implicit("VersionPreference"), ref num2))
								{
									VersionPreference versionPreference = (VersionPreference)num2;
									registrationInfo = new RegistrationInfo
									{
										Name = name,
										Author = author,
										Version = version,
										Hash = hash,
										DownloadLink = downloadLink,
										Tags = tags,
										VersionPreference = versionPreference,
										IsLocal = false
									};
									return true;
								}
								return false;
							}
							return false;
						}
						return false;
					}
					return false;
				}
				return false;
			}
			return false;
		}

		[CompilerGenerated]
		protected virtual bool PrintMembers(StringBuilder builder)
		{
			RuntimeHelpers.EnsureSufficientExecutionStack();
			builder.Append("Name = ");
			builder.Append((object?)Name);
			builder.Append(", Author = ");
			builder.Append((object?)Author);
			builder.Append(", Version = ");
			builder.Append((object?)Version);
			builder.Append(", Hash = ");
			builder.Append((object?)Hash);
			builder.Append(", DownloadLink = ");
			builder.Append((object?)DownloadLink);
			builder.Append(", Tags = ");
			builder.Append(Tags.ToString());
			builder.Append(", VersionPreference = ");
			builder.Append(VersionPreference.ToString());
			builder.Append(", IsLocal = ");
			builder.Append(IsLocal.ToString());
			builder.Append(", IsValid = ");
			builder.Append(IsValid.ToString());
			builder.Append(", Melon = ");
			builder.Append(Melon);
			return true;
		}

		[CompilerGenerated]
		public override int GetHashCode()
		{
			return ((((((((EqualityComparer<Type>.Default.GetHashCode(EqualityContract) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Name)) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Author)) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Version)) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(Hash)) * -1521134295 + EqualityComparer<string>.Default.GetHashCode(DownloadLink)) * -1521134295 + EqualityComparer<ModTags>.Default.GetHashCode(Tags)) * -1521134295 + EqualityComparer<VersionPreference>.Default.GetHashCode(VersionPreference)) * -1521134295 + EqualityComparer<bool>.Default.GetHashCode(IsLocal)) * -1521134295 + EqualityComparer<MelonBase>.Default.GetHashCode(Melon);
		}

		[CompilerGenerated]
		public virtual bool Equals(RegistrationInfo? other)
		{
			if ((object)this != other)
			{
				if ((object)other != null && EqualityContract == other.EqualityContract && EqualityComparer<string>.Default.Equals(Name, other.Name) && EqualityComparer<string>.Default.Equals(Author, other.Author) && EqualityComparer<string>.Default.Equals(Version, other.Version) && EqualityComparer<string>.Default.Equals(Hash, other.Hash) && EqualityComparer<string>.Default.Equals(DownloadLink, other.DownloadLink) && EqualityComparer<ModTags>.Default.Equals(Tags, other.Tags) && EqualityComparer<VersionPreference>.Default.Equals(VersionPreference, other.VersionPreference) && EqualityComparer<bool>.Default.Equals(IsLocal, other.IsLocal))
				{
					return EqualityComparer<MelonBase>.Default.Equals(Melon, other.Melon);
				}
				return false;
			}
			return true;
		}

		[CompilerGenerated]
		protected RegistrationInfo(RegistrationInfo original)
		{
			Name = original.Name;
			Author = original.Author;
			Version = original.Version;
			Hash = original.Hash;
			DownloadLink = original.DownloadLink;
			Tags = original.Tags;
			VersionPreference = original.VersionPreference;
			IsLocal = original.IsLocal;
			Melon = original.Melon;
		}
	}
	public record RoomRegistrationInfo
	{
		public const int SpecVersion = 1;

		public bool IsActuallyPrivate;

		public IEnumerable<RegistrationInfo> RequiredMods;

		public List<RegistrationInfo> GetMutualMods()
		{
			List<RegistrationInfo> list = new List<RegistrationInfo>();
			foreach (RegistrationInfo remoteMod in RequiredMods)
			{
				RegistrationInfo registrationInfo = RegistrationAPI.RegisteredMods.FirstOrDefault((RegistrationInfo info) => info.Name == remoteMod.Name, null);
				if (registrationInfo != null)
				{
					list.Add(registrationInfo);
				}
			}
			return list;
		}

		public PhotonHashtable ToHashtable()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			return new PhotonHashtable(4)
			{
				[Object.op_Implicit("SpecVersion")] = Object.op_Implicit(1),
				[Object.op_Implicit("IsActuallyPrivate")] = Object.op_Implicit(IsActuallyPrivate),
				[Object.op_Implicit("RequiredMods")] = ((Il2CppObjectBase)RequiredMods.Select((RegistrationInfo info) => info.ToHashtable()).ToIl2CppReferenceArray<PhotonHashtable>()).Cast<Object>()
			};
		}

		public RoomRegistrationInfo(IEnumerable<RegistrationInfo> requiredToConnectMods, bool isActuallyPrivate)
		{
			RequiredMods = requiredToConnectMods;
			IsActuallyPrivate = isActuallyPrivate;
		}

		public static RoomRegistrationInfo? ParseFromHashtable(PhotonHashtable sourceTable)
		{
			TryParseFromHashtable(sourceTable, out RoomRegistrationInfo roomRegistrationInfo);
			return roomRegistrationInfo;
		}

		public static bool TryParseFromHashtable(PhotonHashtable sourceTable, out RoomRegistrationInfo roomRegistrationInfo)
		{
			roomRegistrationInfo = null;
			List<RegistrationInfo> list = new List<RegistrationInfo>();
			int num = default(int);
			if (PhotonHashtableExtensions.TryGetInt(sourceTable, Object.op_Implicit("SpecVersion"), ref num))
			{
				if (num != 1)
				{
					return false;
				}
				bool flag = default(bool);
				if (PhotonHashtableExtensions.TryGetBool(sourceTable, Object.op_Implicit("IsActuallyPrivate"), ref flag))
				{
					bool isActuallyPrivate = flag;
					Object val = default(Object);
					if (((Dictionary<Object, Object>)(object)sourceTable).TryGetValue(Object.op_Implicit("RequiredMods"), ref val))
					{
						Il2CppReferenceArray<PhotonHashtable> val2 = ((Il2CppObjectBase)val).TryCast<Il2CppReferenceArray<PhotonHashtable>>();
						if (val2 != null)
						{
							list.EnsureCapacity(((Il2CppArrayBase<PhotonHashtable>)(object)val2).Length);
							foreach (PhotonHashtable item in (Il2CppArrayBase<PhotonHashtable>)(object)val2)
							{
								if (RegistrationInfo.TryFromHashtable(item, out RegistrationInfo registrationInfo) && registrationInfo.IsValid)
								{
									list.Add(registrationInfo);
								}
							}
							roomRegistrationInfo = new RoomRegistrationInfo(list, isActuallyPrivate);
							return true;
						}
						return false;
					}
					return false;
				}
				return false;
			}
			return false;
		}

		[CompilerGenerated]
		protected RoomRegistrationInfo(RoomRegistrationInfo original)
		{
			IsActuallyPrivate = original.IsActuallyPrivate;
			RequiredMods = original.RequiredMods;
		}
	}
	public enum VersionPreference
	{
		Same,
		SameOrNewer,
		SameOrOlder,
		ExactHash,
		Any
	}
}
namespace AirframeAPI.Patches
{
	[HarmonyPatch(typeof(PhotonController))]
	internal static class PhotonController__patches
	{
		[HarmonyPostfix]
		[HarmonyPatch("Connect")]
		public static void Connect_postfix(PhotonController __instance)
		{
			PhotonHandler.controller = __instance;
			PhotonHandler.networkingClient = __instance.client;
			((Dictionary<Object, Object>)(object)__instance.client.LocalPlayer.CustomProperties).TryAdd(Object.op_Implicit("AirframeAPI"), (Object)(object)RegistrationAPI.BuildLocalPlayerRegistration().ToHashtable());
		}

		[HarmonyPostfix]
		[HarmonyPatch("OnPhotonEventReceived")]
		public static void OnPhotonEventReceived__postfix(PhotonController __instance, EventData __0)
		{
			PhotonHandler.OnEvent(__0);
		}
	}
	[HarmonyPatch(typeof(RealtimeClient))]
	public static class RealtimeClient__patches
	{
		[HarmonyPrefix]
		[HarmonyPatch("OpCreateRoom")]
		public static void OpCreateRoom__prefix(RealtimeClient __instance, EnterRoomArgs enterRoomArgs)
		{
			bool boolOrFalse = PhotonHashtableExtensions.GetBoolOrFalse(enterRoomArgs.RoomOptions.CustomRoomProperties, Object.op_Implicit("IS_PRIVATE_GAME"));
			RoomRegistrationInfo roomRegistrationInfo = RegistrationAPI.BuildRoomRegistration(boolOrFalse);
			if (roomRegistrationInfo.RequiredMods.Count() > 0)
			{
				enterRoomArgs.RoomOptions.CustomRoomPropertiesForLobby = CollectionExtensions.AddItem<Object>((IEnumerable<Object>)enterRoomArgs.RoomOptions.CustomRoomPropertiesForLobby, Object.op_Implicit("AirframeAPI")).ToIl2CppReferenceArray<Object>();
				((Dictionary<Object, Object>)(object)enterRoomArgs.RoomOptions.CustomRoomProperties).TryAdd(Object.op_Implicit("AirframeAPI"), (Object)(object)roomRegistrationInfo.ToHashtable());
				if (!boolOrFalse)
				{
					enterRoomArgs.RoomOptions.CustomRoomProperties[Object.op_Implicit("IS_PRIVATE_GAME")] = Object.op_Implicit(roomRegistrationInfo.RequiredMods.Count() > 0);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch("GameEnteredOnGameServer")]
		public static void GameEnteredOnGameServer__postfix(RealtimeClient __instance, OperationResponse operationResponse)
		{
			__instance.Service();
			PhotonHandler.HandleLastRoomInfo();
			Utilities.Events.InvokeOnEnteredRoom(__instance.CurrentRoom);
		}

		[HarmonyPrefix]
		[HarmonyPatch("OpJoinLobby")]
		public static void OpJoinLobby__prefix(RealtimeClient __instance, ref TypedLobby lobby)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (RegistrationAPI.FailsafeActive && lobby == null)
			{
				lobby = new TypedLobby("AirframeAPI Fail-safe lobby (github.com/blankochan/AirframeAPI)", (LobbyType)0);
				AirframeAPI_Core.Logger.BigError("Failsafe active, this client will be seperated from the vannilla game pool, and you will likely experience instablity");
			}
		}
	}
}
namespace AirframeAPI.Interfaces
{
	public interface IDisableable
	{
		bool Enabled { get; }

		bool Disable();

		bool Enable();
	}
}
namespace AirframeAPI.Features
{
	public static class Utilities
	{
		public static class Events
		{
			public static event Action<Room>? OnEnteredRoom;

			public static event Action? MainMenuLoaded;

			internal static void InvokeOnEnteredRoom(Room room)
			{
				Events.OnEnteredRoom?.Invoke(room);
			}

			internal static void InvokeMainMenuLoaded()
			{
				Events.MainMenuLoaded?.Invoke();
			}
		}

		public static string GameVersion = Page_MainPage.versionString.Split(' ').Last();

		public static string APIVersion = "1.0.0";
	}
}
namespace AirframeAPI.Extensions
{
	public static class EnumExtensions
	{
		public static bool HasTag(this ModTags sourceTags, ModTags tag)
		{
			return (sourceTags & tag) == tag;
		}

		public static bool DoesNotHaveTag(this ModTags sourceTags, ModTags tag)
		{
			return !sourceTags.HasTag(tag);
		}
	}
	public static class Il2CppEnumerableExtensions
	{
		public static Il2CppStringArray ToIl2CppStringArray(this IEnumerable<string> strings)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Expected O, but got Unknown
			Il2CppStringArray val = new Il2CppStringArray((long)strings.Count());
			int num = 0;
			foreach (string @string in strings)
			{
				((Il2CppArrayBase<string>)(object)val)[num] = @string;
				num++;
			}
			return val;
		}

		public static Il2CppStructArray<T> ToIl2CppStructArray<T>(this IEnumerable<T> enumerable) where T : unmanaged
		{
			Il2CppStructArray<T> val = new Il2CppStructArray<T>((long)enumerable.Count());
			int num = 0;
			foreach (T item in enumerable)
			{
				((Il2CppArrayBase<T>)(object)val)[num] = item;
				num++;
			}
			return val;
		}

		public static Il2CppReferenceArray<T> ToIl2CppReferenceArray<T>(this IEnumerable<T> enumerable) where T : Il2CppObjectBase
		{
			Il2CppReferenceArray<T> val = new Il2CppReferenceArray<T>((long)enumerable.Count());
			int num = 0;
			foreach (T item in enumerable)
			{
				((Il2CppArrayBase<T>)(object)val)[num] = item;
				num++;
			}
			return val;
		}

		public static List<T> ToIl2CppList<T>(this IEnumerable<T> items)
		{
			List<T> val = new List<T>(items.Count());
			foreach (T item in items)
			{
				val.Add(item);
			}
			return val;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}