Decompiled source of PEAKMatchmaking v1.1.0

BepInEx/plugins/PEAKMatchmaking.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using BepInEx.Bootstrap;
using ExitGames.Client.Photon;
using HarmonyLib;
using Newtonsoft.Json;
using PEAKMatchmaking.Settings;
using Photon.Pun;
using Photon.Realtime;
using Steamworks;
using TMPro;
using Unity.Collections;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Localization;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using Zorro.Core;
using Zorro.Core.Serizalization;
using Zorro.Settings;
using Zorro.UI.Modal;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("PEAKMatchmaking")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PEAKMatchmaking")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fa597764-03ba-4e73-8e60-0f44f312d648")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace PEAKMatchmaking
{
	[Serializable]
	public class LobbyInfo
	{
		public string region;

		public string roomName;

		public string steamRoomId;

		public string creatorName;

		public int currentPlayers;

		public int maxPlayers;

		public List<string> modList;

		public string regionJoinable;

		public long timestamp;
	}
	public static class FirebaseLobbyClient
	{
		[Serializable]
		private class PushResponse
		{
			public string name;
		}

		[CompilerGenerated]
		private sealed class <DeleteLobby>d__7 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string key;

			public Action<bool> onComplete;

			private int <attempt>5__2;

			private float <delay>5__3;

			private UnityWebRequest <req>5__4;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<req>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Invalid comparison between Unknown and I4
				//IL_0130: Unknown result type (might be due to invalid IL or missing references)
				//IL_013a: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						<attempt>5__2 = 0;
						<delay>5__3 = 1f;
						goto IL_0039;
					case 1:
						<>1__state = -3;
						if ((int)<req>5__4.result == 1)
						{
							onComplete?.Invoke(obj: true);
							result = false;
						}
						else
						{
							Debug.LogWarning((object)$"[Firebase] DELETE attempt {<attempt>5__2 + 1} failed: {<req>5__4.error}");
							if (++<attempt>5__2 < 3)
							{
								<>m__Finally1();
								<req>5__4 = null;
								<>2__current = (object)new WaitForSecondsRealtime(<delay>5__3);
								<>1__state = 2;
								result = true;
								break;
							}
							onComplete?.Invoke(obj: false);
							result = false;
						}
						<>m__Finally1();
						break;
					case 2:
						{
							<>1__state = -1;
							<delay>5__3 *= 2f;
							goto IL_0039;
						}
						IL_0039:
						<req>5__4 = UnityWebRequest.Delete("https://peakmatchmaking-default-rtdb.firebaseio.com/lobbies/" + key + ".json");
						<>1__state = -3;
						<req>5__4.SetRequestHeader("Accept-Encoding", "gzip");
						<>2__current = <req>5__4.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__4 != null)
				{
					((IDisposable)<req>5__4).Dispose();
				}
			}

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

		[CompilerGenerated]
		private sealed class <FetchLobbies>d__6 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public string region;

			public Action<string> onComplete;

			private string <url>5__2;

			private int <attempt>5__3;

			private float <delay>5__4;

			private UnityWebRequest <req>5__5;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<url>5__2 = null;
				<req>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Invalid comparison between Unknown and I4
				//IL_015c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0166: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
					{
						<>1__state = -1;
						string text = region + "_true";
						<url>5__2 = "https://peakmatchmaking-default-rtdb.firebaseio.com/lobbies.json?orderBy=%22regionJoinable%22&equalTo=%22" + UnityWebRequest.EscapeURL(text) + "%22&limitToFirst=10";
						<attempt>5__3 = 0;
						<delay>5__4 = 1f;
						goto IL_0065;
					}
					case 1:
						<>1__state = -3;
						if ((int)<req>5__5.result == 1)
						{
							onComplete?.Invoke(<req>5__5.downloadHandler.text);
							result = false;
						}
						else
						{
							Debug.LogWarning((object)$"[Firebase] GET attempt {<attempt>5__3 + 1} failed: {<req>5__5.error}");
							if (++<attempt>5__3 < 3)
							{
								<>m__Finally1();
								<req>5__5 = null;
								<>2__current = (object)new WaitForSecondsRealtime(<delay>5__4);
								<>1__state = 2;
								result = true;
								break;
							}
							onComplete?.Invoke(null);
							result = false;
						}
						<>m__Finally1();
						break;
					case 2:
						{
							<>1__state = -1;
							<delay>5__4 *= 2f;
							goto IL_0065;
						}
						IL_0065:
						<req>5__5 = UnityWebRequest.Get(<url>5__2);
						<>1__state = -3;
						<req>5__5.SetRequestHeader("Accept-Encoding", "gzip");
						<>2__current = <req>5__5.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__5 != null)
				{
					((IDisposable)<req>5__5).Dispose();
				}
			}

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

		[CompilerGenerated]
		private sealed class <PostLobby>d__3 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Action<bool, string> onComplete;

			public LobbyInfo info;

			private byte[] <body>5__2;

			private int <attempt>5__3;

			private float <delay>5__4;

			private UnityWebRequest <req>5__5;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<body>5__2 = null;
				<req>5__5 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Invalid comparison between Unknown and I4
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Expected O, but got Unknown
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Expected O, but got Unknown
				//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
				//IL_01f0: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
					{
						<>1__state = -1;
						if (!string.IsNullOrEmpty(LastLobbyKey))
						{
							Debug.Log((object)("[Firebase] Skiping POST – lobby already registered under key " + LastLobbyKey));
							onComplete?.Invoke(arg1: true, LastLobbyKey);
							result = false;
							break;
						}
						string s = JsonUtility.ToJson((object)info);
						<body>5__2 = Encoding.UTF8.GetBytes(s);
						<attempt>5__3 = 0;
						<delay>5__4 = 1f;
						goto IL_0094;
					}
					case 1:
						<>1__state = -3;
						if ((int)<req>5__5.result == 1)
						{
							PushResponse pushResponse = JsonUtility.FromJson<PushResponse>(<req>5__5.downloadHandler.text);
							LastLobbyKey = pushResponse.name;
							onComplete?.Invoke(arg1: true, pushResponse.name);
							result = false;
						}
						else
						{
							Debug.LogWarning((object)$"[Firebase] POST attempt {<attempt>5__3 + 1} failed: {<req>5__5.error}");
							if (++<attempt>5__3 < 3)
							{
								<>m__Finally1();
								<req>5__5 = null;
								<>2__current = (object)new WaitForSecondsRealtime(<delay>5__4);
								<>1__state = 2;
								result = true;
								break;
							}
							onComplete?.Invoke(arg1: false, null);
							result = false;
						}
						<>m__Finally1();
						break;
					case 2:
						{
							<>1__state = -1;
							<delay>5__4 *= 2f;
							goto IL_0094;
						}
						IL_0094:
						<req>5__5 = new UnityWebRequest("https://peakmatchmaking-default-rtdb.firebaseio.com/lobbies.json", "POST");
						<>1__state = -3;
						<req>5__5.uploadHandler = (UploadHandler)new UploadHandlerRaw(<body>5__2);
						<req>5__5.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
						<req>5__5.SetRequestHeader("Content-Type", "application/json");
						<req>5__5.SetRequestHeader("Accept-Encoding", "gzip");
						<>2__current = <req>5__5.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__5 != null)
				{
					((IDisposable)<req>5__5).Dispose();
				}
			}

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

		[CompilerGenerated]
		private sealed class <SetJoinable>d__4 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Action<bool> cb;

			public bool value;

			private string <url>5__2;

			private byte[] <body>5__3;

			private int <attempt>5__4;

			private float <delay>5__5;

			private UnityWebRequest <req>5__6;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<url>5__2 = null;
				<body>5__3 = null;
				<req>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0177: Invalid comparison between Unknown and I4
				//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ec: Expected O, but got Unknown
				//IL_0100: Unknown result type (might be due to invalid IL or missing references)
				//IL_010a: Expected O, but got Unknown
				//IL_0110: Unknown result type (might be due to invalid IL or missing references)
				//IL_011a: Expected O, but got Unknown
				//IL_0234: Unknown result type (might be due to invalid IL or missing references)
				//IL_023e: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
					{
						<>1__state = -1;
						if (string.IsNullOrEmpty(LastLobbyKey))
						{
							Debug.LogWarning((object)"[Firebase] SetJoinable called but LastLobbyKey is null");
							cb?.Invoke(obj: false);
							result = false;
							break;
						}
						<url>5__2 = "https://peakmatchmaking-default-rtdb.firebaseio.com/lobbies/" + LastLobbyKey + "/regionJoinable.json";
						string text = (value ? "true" : "false");
						<body>5__3 = Encoding.UTF8.GetBytes("\"" + PhotonNetwork.CloudRegion + "_" + text + "\"");
						<attempt>5__4 = 0;
						<delay>5__5 = 1f;
						goto IL_00d6;
					}
					case 1:
						<>1__state = -3;
						if ((int)<req>5__6.result == 1)
						{
							Debug.Log((object)$"[Firebase] joinable updated to {value} (key {LastLobbyKey})");
							cb?.Invoke(obj: true);
							result = false;
						}
						else
						{
							Debug.LogWarning((object)$"[Firebase] joinable PUT attempt {<attempt>5__4 + 1} failed: {<req>5__6.error}");
							if (++<attempt>5__4 < 3)
							{
								<>m__Finally1();
								<req>5__6 = null;
								<>2__current = (object)new WaitForSecondsRealtime(<delay>5__5);
								<>1__state = 2;
								result = true;
								break;
							}
							Debug.LogError((object)$"[Firebase] failed to update joinable after {3} attempts");
							cb?.Invoke(obj: false);
							result = false;
						}
						<>m__Finally1();
						break;
					case 2:
						{
							<>1__state = -1;
							<delay>5__5 *= 2f;
							goto IL_00d6;
						}
						IL_00d6:
						<req>5__6 = new UnityWebRequest(<url>5__2, "PUT");
						<>1__state = -3;
						<req>5__6.uploadHandler = (UploadHandler)new UploadHandlerRaw(<body>5__3);
						<req>5__6.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
						<req>5__6.SetRequestHeader("Content-Type", "application/json");
						<req>5__6.SetRequestHeader("Accept-Encoding", "gzip");
						<>2__current = <req>5__6.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__6 != null)
				{
					((IDisposable)<req>5__6).Dispose();
				}
			}

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

		[CompilerGenerated]
		private sealed class <UpdatePlayerCount>d__5 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Action<bool> cb;

			public int count;

			private string <url>5__2;

			private byte[] <body>5__3;

			private int <attempt>5__4;

			private float <delay>5__5;

			private UnityWebRequest <req>5__6;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<url>5__2 = null;
				<body>5__3 = null;
				<req>5__6 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_012e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0134: Invalid comparison between Unknown and I4
				//IL_009f: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a9: Expected O, but got Unknown
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c7: Expected O, but got Unknown
				//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d7: Expected O, but got Unknown
				//IL_0194: Unknown result type (might be due to invalid IL or missing references)
				//IL_019e: Expected O, but got Unknown
				bool result;
				try
				{
					switch (<>1__state)
					{
					default:
						result = false;
						break;
					case 0:
						<>1__state = -1;
						if (string.IsNullOrEmpty(LastLobbyKey))
						{
							cb?.Invoke(obj: false);
							result = false;
							break;
						}
						<url>5__2 = "https://peakmatchmaking-default-rtdb.firebaseio.com/lobbies/" + LastLobbyKey + "/currentPlayers.json";
						<body>5__3 = Encoding.UTF8.GetBytes(count.ToString());
						<attempt>5__4 = 0;
						<delay>5__5 = 1f;
						goto IL_0093;
					case 1:
						<>1__state = -3;
						if ((int)<req>5__6.result == 1)
						{
							cb?.Invoke(obj: true);
							result = false;
						}
						else
						{
							if (++<attempt>5__4 < 3)
							{
								<>m__Finally1();
								<req>5__6 = null;
								<>2__current = (object)new WaitForSecondsRealtime(<delay>5__5);
								<>1__state = 2;
								result = true;
								break;
							}
							cb?.Invoke(obj: false);
							result = false;
						}
						<>m__Finally1();
						break;
					case 2:
						{
							<>1__state = -1;
							<delay>5__5 *= 2f;
							goto IL_0093;
						}
						IL_0093:
						<req>5__6 = new UnityWebRequest(<url>5__2, "PUT");
						<>1__state = -3;
						<req>5__6.uploadHandler = (UploadHandler)new UploadHandlerRaw(<body>5__3);
						<req>5__6.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
						<req>5__6.SetRequestHeader("Content-Type", "application/json");
						<req>5__6.SetRequestHeader("Accept-Encoding", "gzip");
						<>2__current = <req>5__6.SendWebRequest();
						<>1__state = 1;
						result = true;
						break;
					}
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
				return result;
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				if (<req>5__6 != null)
				{
					((IDisposable)<req>5__6).Dispose();
				}
			}

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

		private const string DatabaseUrl = "https://peakmatchmaking-default-rtdb.firebaseio.com/";

		public static string LastLobbyKey;

		[IteratorStateMachine(typeof(<PostLobby>d__3))]
		public static IEnumerator PostLobby(LobbyInfo info, Action<bool, string> onComplete)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <PostLobby>d__3(0)
			{
				info = info,
				onComplete = onComplete
			};
		}

		[IteratorStateMachine(typeof(<SetJoinable>d__4))]
		public static IEnumerator SetJoinable(bool value, Action<bool> cb = null)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SetJoinable>d__4(0)
			{
				value = value,
				cb = cb
			};
		}

		[IteratorStateMachine(typeof(<UpdatePlayerCount>d__5))]
		public static IEnumerator UpdatePlayerCount(int count, Action<bool> cb = null)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <UpdatePlayerCount>d__5(0)
			{
				count = count,
				cb = cb
			};
		}

		[IteratorStateMachine(typeof(<FetchLobbies>d__6))]
		public static IEnumerator FetchLobbies(string region, Action<string> onComplete)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FetchLobbies>d__6(0)
			{
				region = region,
				onComplete = onComplete
			};
		}

		[IteratorStateMachine(typeof(<DeleteLobby>d__7))]
		public static IEnumerator DeleteLobby(string key, Action<bool> onComplete)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <DeleteLobby>d__7(0)
			{
				key = key,
				onComplete = onComplete
			};
		}
	}
	public class PlayerCountSync : MonoBehaviour, IInRoomCallbacks
	{
		private void OnEnable()
		{
			PhotonNetwork.AddCallbackTarget((object)this);
		}

		private void OnDisable()
		{
			PhotonNetwork.RemoveCallbackTarget((object)this);
		}

		public void OnPlayerEnteredRoom(Player newPlayer)
		{
			PushCount();
		}

		public void OnPlayerLeftRoom(Player otherPlayer)
		{
			PushCount();
		}

		public void OnRoomPropertiesUpdate(Hashtable propertiesThatChanged)
		{
		}

		public void OnPlayerPropertiesUpdate(Player targetPlayer, Hashtable changedProps)
		{
		}

		public void OnMasterClientSwitched(Player newMasterClient)
		{
		}

		private void PushCount()
		{
			if (PhotonNetwork.IsMasterClient && FirebaseLobbyClient.LastLobbyKey != null)
			{
				int playerCount = PhotonNetwork.CurrentRoom.PlayerCount;
				Debug.Log((object)$"[Firebase] Host updating player count → {playerCount}");
				((MonoBehaviour)this).StartCoroutine(FirebaseLobbyClient.UpdatePlayerCount(playerCount));
			}
		}
	}
	[BepInPlugin("synqnilumn.peak.matchmaking", "PEAK Matchmaking", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private sealed class <WaitAndAddSetting>d__22 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public SettingsHandler handler;

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

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

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

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

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (!PhotonNetwork.IsConnectedAndReady || string.IsNullOrEmpty(PhotonNetwork.CloudRegion))
				{
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				handler.AddSetting((Setting)(object)new ConnectedRegionSetting());
				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();
			}
		}

		[CompilerGenerated]
		private sealed class <WaitForModalOpen>d__23 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public Plugin <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fe: 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_0158: Unknown result type (might be due to invalid IL or missing references)
				//IL_0184: Unknown result type (might be due to invalid IL or missing references)
				//IL_018e: Expected O, but got Unknown
				int num = <>1__state;
				Plugin plugin = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
				{
					<>1__state = -1;
					GameObject obj = GameObject.Find("Modal(Clone)/Canvas/Background/InputFields/ButtonsInputField(Clone)");
					Transform val = ((obj != null) ? obj.transform : null);
					if ((Object)(object)val == (Object)null)
					{
						Debug.LogError((object)"modal parent not found");
						return false;
					}
					GameObject val2 = GameObject.Find("Modal(Clone)/Canvas/Background/InputFields/ButtonsInputField(Clone)/Button");
					if ((Object)(object)val2 == (Object)null)
					{
						Debug.LogError((object)"placeholder button not found");
						return false;
					}
					val2.SetActive(false);
					plugin.loadingicon = Object.Instantiate<GameObject>(plugin.buttonicon);
					plugin.loadingicon.transform.SetParent(val, false);
					plugin.loadingicon.GetComponent<RectTransform>().anchoredPosition = new Vector2(505f, -30f);
					((Graphic)plugin.loadingicon.GetComponent<Image>()).color = new Color(0.4717f, 0.3949f, 0.3182f, 1f);
					plugin.loadingicon.transform.localScale = Vector3.one * 1.3f;
					((Object)plugin.loadingicon).name = "LoadingIcon";
					plugin.loadingicon.SetActive(true);
					plugin.startloading = true;
					GameObject obj2 = Object.Instantiate<GameObject>(val2);
					obj2.transform.SetParent(val, false);
					obj2.GetComponent<RectTransform>().anchoredPosition = new Vector2(505f, -240f);
					((UnityEventBase)obj2.GetComponent<Button>().onClick).RemoveAllListeners();
					((UnityEvent)obj2.GetComponent<Button>().onClick).AddListener(new UnityAction(plugin.QuitMatchmaking));
					((TMP_Text)((Component)obj2.transform.GetChild(0)).GetComponent<TextMeshProUGUI>()).text = "Cancel";
					((Object)obj2).name = "CancelButton";
					obj2.SetActive(true);
					((Behaviour)((Component)val).GetComponent<HorizontalLayoutGroup>()).enabled = false;
					((MonoBehaviour)plugin).StartCoroutine(FirebaseLobbyClient.FetchLobbies(PhotonNetwork.CloudRegion, plugin.LobbiesFetched));
					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();
			}
		}

		private string iconb64 = "iVBORw0KGgoAAAANSUhEUgAAACQAAAAkCAYAAADhAJiYAAAAAXNSR0IArs4c6QAAApVJREFUWEfNmE1OAzEMhW2JA8AOVtAbgMQSCXoS4BCsKTfgBpQdtwB27OgNgBXs6AGQQt/IGXk8+XEqVWqkkUDjcb7YL45Tpi0bvGU8NAAKIdwS0cXqeWHmuxxsCOGIiC7lPf7Gg/Epzxczz9dZbA8kMDPl5No6VcCArg3AYcxLi7NONNCzRCfaIEpT/JOArcHY94DDAl9qHxaB4ISIHgxozWfp/awWrRLQGxHtK32UJora8aQSKcRCk6MEVFypvHzVaRCxR5GfrwR+lXGShWoFcmvBob1k+lqAsI0fMZFHnDEyErWcDqfWlwZ6J6Jjp2Kr4rR+Qgh2F3d1i5kn2lYDfYuInUw0Wl3pQ4nUR8JmUO800C8R7XppVumbMHMsfq7PQggQOdKnR1/vOjmoXJ8REcK64/A+cOKw700SqRukzZ5lgDolokVhEjhoioz2lan6ffotUFdDWnZRS3SkFKB4IhN69JtEp0wbNtWbFqiMuPtCqYEgNl1Z19ZJDTCho36uUmEc1YjaRN73CSBXhFCRN9JRStqgI2h2II9Sg4YFNxU/b4RE3MkNlBN19N18RJgtrttby4vWBll40i80ED62pX1tYWfOrlQQ/4johpnvB5Vawpg6AEe9tSc1qwIYPHZis2TmvRRQ6qyB6KAld3UuHKQ5xh9mPhgBFaLUnLrGi8GCmU9yQKnSDtt1IxXvcLl2Fr7HhdFxAEYo9z3L1JuSpMpAkjrcYvXFUTvE/QrtLKp5f9cSANjFW23uewvnAoqh9jhtuQbBdmna5TpQXEKjOGs7vZvYdbiWPFVuDjWIkfZch6vHq/TE0IfnhprdBIneetygeYBUGqEvQB3KiW1/jsEZ5fk5Z/TTz0bai5bFWdutA/oHSIpJNEbalEMAAAAASUVORK5CYII=";

		private Sprite icon;

		private GameObject buttonicon;

		private GameObject loadingicon;

		private bool startloading;

		public List<string> nojoincache = new List<string>();

		public List<string> cantjoincache = new List<string>();

		public string lastjoinid;

		public int curlobbytype;

		public int curjoinwind;

		public string[] loadingdescriptions = new string[3] { "Searching for open lobbies.", "Looking for open lobbies.", "Sniffing out open lobbies." };

		public bool joined;

		public static Plugin Instance { get; private set; }

		private void Awake()
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			new Harmony("synq.peak.matchmaking").PatchAll(Assembly.GetExecutingAssembly());
			SceneManager.sceneLoaded += OnSceneLoaded;
			Application.wantsToQuit += OnWantsToQuit;
			geticon();
		}

		private static bool OnWantsToQuit()
		{
			//IL_0020: 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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			CSteamID val = (CSteamID)typeof(SteamLobbyHandler).GetField("m_currentLobby", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GameHandler.GetService<SteamLobbyHandler>());
			if (SteamMatchmaking.GetLobbyData(val, "MMMOD") == "true" && SteamMatchmaking.GetNumLobbyMembers(val) <= 1)
			{
				string key = FirebaseLobbyClient.LastLobbyKey;
				if (!string.IsNullOrEmpty(key))
				{
					((MonoBehaviour)Instance).StartCoroutine(FirebaseLobbyClient.DeleteLobby(key, delegate(bool success)
					{
						if (success)
						{
							Debug.Log((object)("[Firebase] Deleted lobby " + key));
						}
						else
						{
							Debug.LogError((object)("[Firebase] Failed to delete lobby " + key));
						}
					}));
				}
			}
			return true;
		}

		private void Update()
		{
			if (startloading && (Object)(object)loadingicon != (Object)null)
			{
				loadingicon.transform.Rotate(0f, 0f, 60f * Time.deltaTime);
			}
		}

		private async void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			Debug.Log((object)("scene loaded: " + ((Scene)(ref scene)).name));
			await Task.Delay(800);
			if (((Scene)(ref scene)).name == "Title")
			{
				GameObject.Find("MainMenu/Canvas/MainPage/Menu/Panel (3)").transform.localScale = new Vector3(1f, 1.3f, 1f);
				GameObject.Find("MainMenu/Canvas/MainPage/Menu/Panel (2)").transform.localScale = new Vector3(1f, 1.3f, 1f);
				GameObject val = Object.Instantiate<GameObject>(GameObject.Find("MainMenu/Canvas/MainPage/Menu/Buttons/Button_PlaySolo"));
				val.transform.SetParent(GameObject.Find("MainMenu/Canvas/MainPage/Menu/Buttons").transform, false);
				((Object)val).name = "Button_Matchmake";
				val.transform.localPosition = new Vector3(53.7f, 169.8668f, 0f);
				val.transform.rotation = Quaternion.Euler(0f, 0f, 3.6109f);
				((TMP_Text)((Component)val.transform.GetChild(0).GetChild(3)).GetComponent<TextMeshProUGUI>()).text = "MATCHMAKE";
				((Component)val.transform.GetChild(0).GetChild(4).GetChild(0)).GetComponent<Image>().sprite = icon;
				buttonicon = ((Component)val.transform.GetChild(0).GetChild(4).GetChild(0)).gameObject;
				((UnityEvent)val.GetComponent<Button>().onClick).AddListener(new UnityAction(OnMatchmakeClicked));
			}
			if (curlobbytype == 2 && curjoinwind == 1 && FirebaseLobbyClient.LastLobbyKey != null)
			{
				if (((Scene)(ref scene)).name.StartsWith("Level"))
				{
					Debug.Log((object)"[MM] Host left Airport => setting joinable = false");
					((MonoBehaviour)this).StartCoroutine(FirebaseLobbyClient.SetJoinable(value: false));
				}
				else if (((Scene)(ref scene)).name == "Airport")
				{
					Debug.Log((object)"[MM] Host returned to Airport => setting joinable = true");
					((MonoBehaviour)this).StartCoroutine(FirebaseLobbyClient.SetJoinable(value: true));
				}
			}
			if (((Scene)(ref scene)).name != "Pretitle")
			{
				SharedSettingsMenu val2;
				while ((Object)(object)(val2 = Object.FindObjectOfType<SharedSettingsMenu>()) == (Object)null)
				{
					await Task.Delay(100);
				}
				GameObject gameObject = ((Component)val2).gameObject;
				if (gameObject.transform.GetChild(1).GetChild(1).childCount == 4)
				{
					GameObject obj = Object.Instantiate<GameObject>(((Component)gameObject.transform.GetChild(1).GetChild(1).GetChild(2)).gameObject);
					((TMP_Text)((Component)obj.transform.GetChild(2)).GetComponent<TextMeshProUGUI>()).text = "Matchmaking";
					Object.Destroy((Object)(object)obj.GetComponent<LocalizedText>());
					Object.Destroy((Object)(object)((Component)obj.transform.GetChild(2)).GetComponent<LocalizedText>());
					((Object)obj).name = "Matchmaking";
					obj.transform.SetParent(gameObject.transform.GetChild(1).GetChild(1), false);
					obj.SetActive(true);
				}
			}
		}

		private void OnMatchmakeClicked()
		{
			//IL_001a: 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)
			//IL_0030: Expected O, but got Unknown
			//IL_0030: Expected O, but got Unknown
			Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption("PEAK Matchmaking", loadingdescriptions[Random.Range(0, loadingdescriptions.Length)]), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[0]), (Action)null);
			((MonoBehaviour)this).StartCoroutine(WaitForModalOpen());
		}

		public void StartWait()
		{
			((MonoBehaviour)this).StartCoroutine(WaitForModalOpen());
		}

		public void WaitForConnection(SettingsHandler handler)
		{
			((MonoBehaviour)this).StartCoroutine(WaitAndAddSetting(handler));
		}

		[IteratorStateMachine(typeof(<WaitAndAddSetting>d__22))]
		private IEnumerator WaitAndAddSetting(SettingsHandler handler)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitAndAddSetting>d__22(0)
			{
				handler = handler
			};
		}

		[IteratorStateMachine(typeof(<WaitForModalOpen>d__23))]
		private IEnumerator WaitForModalOpen()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <WaitForModalOpen>d__23(0)
			{
				<>4__this = this
			};
		}

		public void FetchLobbiesI()
		{
			((MonoBehaviour)this).StartCoroutine(FirebaseLobbyClient.FetchLobbies(PhotonNetwork.CloudRegion, LobbiesFetched));
		}

		public void LobbiesFetched(string output)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Expected O, but got Unknown
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Expected O, but got Unknown
			//IL_0062: Expected O, but got Unknown
			//IL_0183: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			//IL_01af: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b5: Expected O, but got Unknown
			//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Expected O, but got Unknown
			//IL_01c0: Expected O, but got Unknown
			//IL_0125: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrWhiteSpace(output) || output == "null")
			{
				QuitMatchmaking();
				Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption("PEAK Matchmaking", "Sorry!, Seems like we couldn't find a lobby for you. Would you like to retry?"), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[2]
				{
					new Option("No thanks", (Action)null),
					new Option("Retry", (Action)delegate
					{
						Modal.CloseModal();
						((MonoBehaviour)this).StartCoroutine(WaitForModalOpen());
					})
				}), (Action)null);
				return;
			}
			try
			{
				Dictionary<string, LobbyInfo> dictionary = JsonConvert.DeserializeObject<Dictionary<string, LobbyInfo>>(output);
				foreach (LobbyInfo value in dictionary.Values)
				{
					if (value.currentPlayers < value.maxPlayers && (nojoincache == null || !nojoincache.Contains(value.steamRoomId)) && (cantjoincache == null || !cantjoincache.Contains(value.steamRoomId)))
					{
						((TMP_Text)GameObject.Find("Modal(Clone)/Canvas/Background/TitleFields/SubheaderModalField(Clone)/Text (TMP)").GetComponent<TextMeshProUGUI>()).text = "Joining " + value.creatorName + "'s lobby.";
						typeof(SteamLobbyHandler).GetMethod("JoinLobby", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(GameHandler.GetService<SteamLobbyHandler>(), new object[1] { (object)new CSteamID(ulong.Parse(value.steamRoomId)) });
						lastjoinid = value.steamRoomId;
						break;
					}
				}
				if (dictionary.Values.All((LobbyInfo lobby) => (nojoincache != null && nojoincache.Contains(lobby.steamRoomId)) || (cantjoincache != null && cantjoincache.Contains(lobby.steamRoomId))))
				{
					Modal.OpenModal((HeaderModalOption)new DefaultHeaderModalOption("PEAK Matchmaking", "Sorry!, Seems like we couldn't find a lobby for you. Would you like to retry?"), (ModalContentOption)new ModalButtonsOption((Option[])(object)new Option[2]
					{
						new Option("No thanks", (Action)null),
						new Option("Retry", (Action)delegate
						{
							Modal.CloseModal();
							((MonoBehaviour)this).StartCoroutine(WaitForModalOpen());
						})
					}), (Action)null);
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("failed to parse data: " + ex.Message));
			}
		}

		private void QuitMatchmaking()
		{
			startloading = false;
			Modal.CloseModal();
			((Behaviour)GameObject.Find("Modal(Clone)/Canvas/Background/InputFields/ButtonsInputField(Clone)").GetComponent<HorizontalLayoutGroup>()).enabled = true;
		}

		private void geticon()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Expected O, but got Unknown
			//IL_0036: 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)
			byte[] array = Convert.FromBase64String(iconb64);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			icon = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
		}
	}
}
namespace PEAKMatchmaking.Settings
{
	public class ConnectedRegionSetting : EnumSetting<ConnectedRegionSetting.RegionType>, IExposedSetting
	{
		public enum RegionType
		{
			us,
			usw,
			ussc,
			asia,
			au,
			eu,
			hk,
			jp
		}

		public override void ApplyValue()
		{
			if (PhotonNetwork.IsConnected)
			{
				PhotonNetwork.Disconnect();
			}
			Debug.Log((object)("region to set: " + GetRegionFromType(base.Value)));
			PhotonNetwork.ConnectToRegion(GetRegionFromType(base.Value));
		}

		public override void Load(ISettingsSaveLoad loader)
		{
			base.Load(loader);
			if (!PlayerPrefs.HasKey("DEFAULT_CHANGE_REGION_TYPE"))
			{
				base.Value = ((EnumSetting<RegionType>)this).GetDefaultValue();
			}
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			base.Save(saver);
			PlayerPrefs.SetInt("DEFAULT_CHANGE_REGION_TYPE", 1);
		}

		public static string GetRegionFromType(RegionType t)
		{
			return t.ToString();
		}

		public static RegionType GetRegionFromString(string r)
		{
			if (string.IsNullOrEmpty(r))
			{
				return RegionType.us;
			}
			r = r.ToLowerInvariant();
			foreach (RegionType value in Enum.GetValues(typeof(RegionType)))
			{
				if (r.StartsWith(value.ToString().ToLowerInvariant()))
				{
					return value;
				}
			}
			Debug.LogWarning((object)"failed to find region, defaulting to us");
			return RegionType.us;
		}

		protected override RegionType GetDefaultValue()
		{
			return RegionType.us;
		}

		public override List<LocalizedString> GetLocalizedChoices()
		{
			return null;
		}

		public override List<string> GetUnlocalizedChoices()
		{
			return new List<string> { "us", "usw", "ussc", "asia", "au", "eu", "hk", "jp" };
		}

		public string GetDisplayName()
		{
			return "Connected Region";
		}

		public string GetCategory()
		{
			return "Matchmaking";
		}
	}
	public class JoinWindowSetting : EnumSetting<JoinWindowSetting.JoinType>, IExposedSetting
	{
		public enum JoinType
		{
			Anytime,
			AirportOnly
		}

		public override void ApplyValue()
		{
			Plugin.Instance.curjoinwind = ((EnumSetting<JoinType>)this).GetValue();
		}

		public override void Load(ISettingsSaveLoad loader)
		{
			base.Load(loader);
			if (!PlayerPrefs.HasKey("DEFAULT_CHANGE_JOIN_TYPE"))
			{
				base.Value = ((EnumSetting<JoinType>)this).GetDefaultValue();
			}
		}

		public override void Save(ISettingsSaveLoad saver)
		{
			base.Save(saver);
			PlayerPrefs.SetInt("DEFAULT_CHANGE_JOIN_TYPE", 1);
		}

		protected override JoinType GetDefaultValue()
		{
			return JoinType.Anytime;
		}

		public override List<LocalizedString> GetLocalizedChoices()
		{
			return null;
		}

		public override List<string> GetUnlocalizedChoices()
		{
			return new List<string> { "Anytime", "Airport Only" };
		}

		public string GetDisplayName()
		{
			return "Join Window";
		}

		public string GetCategory()
		{
			return "Matchmaking";
		}
	}
}
namespace PEAKMatchmaking.Patches
{
	[HarmonyPatch(typeof(LobbyTypeSetting), "GetUnlocalizedChoices")]
	public class ChoicesPatch
	{
		private static void Postfix(ref List<string> __result)
		{
			if (!__result.Contains("Public"))
			{
				__result.Add("Public");
			}
		}
	}
	[HarmonyPatch(typeof(LobbyTypeSetting), "GetCategory")]
	public class CategoryPatch
	{
		private static bool Prefix(ref string __result)
		{
			__result = "Matchmaking";
			return false;
		}
	}
	[HarmonyPatch(typeof(LobbyTypeSetting), "ApplyValue")]
	public class ApplyPatch
	{
		private static void Prefix(LobbyTypeSetting __instance)
		{
			Plugin.Instance.curlobbytype = ((EnumSetting<LobbyType>)(object)__instance).GetValue();
		}
	}
	[HarmonyPatch(typeof(SettingsHandler))]
	[HarmonyPatch(/*Could not decode attribute arguments.*/)]
	public class HandlerPatch
	{
		private static void Postfix(SettingsHandler __instance)
		{
			__instance.AddSetting((Setting)(object)new JoinWindowSetting());
			Plugin.Instance.WaitForConnection(__instance);
		}
	}
	[HarmonyPatch(typeof(SharedSettingsMenu), "ShowSettings")]
	public class ShowPatch
	{
		[CompilerGenerated]
		private sealed class <FadeInCells>d__3 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			private int <i>5__2;

			private List<SettingsUICell>.Enumerator <>7__wrap2;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				int num = <>1__state;
				if (num == -3 || num == 1)
				{
					try
					{
					}
					finally
					{
						<>m__Finally1();
					}
				}
				<>7__wrap2 = default(List<SettingsUICell>.Enumerator);
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0053: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Expected O, but got Unknown
				try
				{
					switch (<>1__state)
					{
					default:
						return false;
					case 0:
						<>1__state = -1;
						<i>5__2 = 0;
						<>7__wrap2 = m_spawnedCells.GetEnumerator();
						<>1__state = -3;
						break;
					case 1:
						<>1__state = -3;
						<i>5__2++;
						break;
					}
					if (<>7__wrap2.MoveNext())
					{
						<>7__wrap2.Current.FadeIn();
						<>2__current = (object)new WaitForSecondsRealtime(0.05f);
						<>1__state = 1;
						return true;
					}
					<>m__Finally1();
					<>7__wrap2 = default(List<SettingsUICell>.Enumerator);
					m_fadeInCoroutine = null;
					return false;
				}
				catch
				{
					//try-fault
					((IDisposable)this).Dispose();
					throw;
				}
			}

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

			private void <>m__Finally1()
			{
				<>1__state = -1;
				((IDisposable)<>7__wrap2).Dispose();
			}

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

		public static List<SettingsUICell> m_spawnedCells = new List<SettingsUICell>();

		public static Coroutine m_fadeInCoroutine;

		private static bool Prefix(SharedSettingsMenu __instance, SettingsCategory category)
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Invalid comparison between Unknown and I4
			if (m_fadeInCoroutine != null)
			{
				((MonoBehaviour)__instance).StopCoroutine(m_fadeInCoroutine);
				m_fadeInCoroutine = null;
			}
			FieldInfo field = typeof(SharedSettingsMenu).GetField("m_spawnedCells", BindingFlags.Instance | BindingFlags.NonPublic);
			FieldInfo field2 = typeof(SharedSettingsMenu).GetField("settings", BindingFlags.Instance | BindingFlags.NonPublic);
			foreach (SettingsUICell spawnedCell in m_spawnedCells)
			{
				if ((Object)(object)spawnedCell != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)spawnedCell).gameObject);
				}
			}
			m_spawnedCells = (List<SettingsUICell>)field.GetValue(__instance);
			m_spawnedCells.Clear();
			typeof(SharedSettingsMenu).GetMethod("RefreshSettings", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(__instance, null);
			List<IExposedSetting> obj = (List<IExposedSetting>)field2.GetValue(__instance);
			string text = (((int)category != 3) ? ((object)(SettingsCategory)(ref category)).ToString() : "Matchmaking");
			foreach (IExposedSetting item in obj)
			{
				if (!(item.GetCategory() != text))
				{
					IConditionalSetting val = (IConditionalSetting)(object)((item is IConditionalSetting) ? item : null);
					if (val == null || val.ShouldShow())
					{
						SettingsUICell component = Object.Instantiate<GameObject>(__instance.m_settingsCellPrefab, __instance.m_settingsContentParent).GetComponent<SettingsUICell>();
						m_spawnedCells.Add(component);
						component.Setup<Setting>((Setting)(object)((item is Setting) ? item : null));
					}
				}
			}
			m_fadeInCoroutine = ((MonoBehaviour)__instance).StartCoroutine(FadeInCells(__instance));
			return false;
		}

		[IteratorStateMachine(typeof(<FadeInCells>d__3))]
		private static IEnumerator FadeInCells(SharedSettingsMenu whatemenuhuh)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <FadeInCells>d__3(0);
		}
	}
	[HarmonyPatch(typeof(SettingsTABS), "OnSelected")]
	public class SelectPatch
	{
		private static bool Prefix(SettingsTABS __instance, SettingsTABSButton button)
		{
			if (((Object)((Component)button.SelectedGraphic.transform.parent).gameObject).name == "Matchmaking")
			{
				__instance.SettingsMenu.ShowSettings((SettingsCategory)3);
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(LocalizedText), "GetText", new Type[]
	{
		typeof(string),
		typeof(bool)
	})]
	public class LocalizePatch
	{
		private static bool Prefix(LocalizedText __instance, ref string __result, string id, bool printDebug = true)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected I4, but got Unknown
			List<string> list = null;
			id = id.ToUpperInvariant();
			string text;
			try
			{
				if (LocalizedText.mainTable.TryGetValue(id, out var value))
				{
					list = value;
				}
				if (list != null)
				{
					string s = list[(int)LocalizedText.CURRENT_LANGUAGE];
					s = FailsafeParsing(s);
					if (string.IsNullOrEmpty(s))
					{
						s = list[0];
						s = FailsafeParsing(s);
					}
					text = s;
				}
				else if (printDebug)
				{
					text = id;
				}
				else
				{
					Debug.LogError((object)("Failed to load text: " + id));
					text = "";
				}
			}
			catch (Exception ex)
			{
				string text2 = "Failed to load text: ";
				string text3 = id;
				string text4 = "\n";
				Debug.LogError((object)(text2 + text3 + text4 + ex));
				text = "";
			}
			__result = text;
			return false;
		}

		private static string FailsafeParsing(string s)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			s = s.Replace("\"\"", "\"");
			_ = LocalizedText.CURRENT_LANGUAGE;
			return s;
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyCreated")]
	public class CreatePatch
	{
		private static void Prefix(LobbyCreated_t param)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Instance.curlobbytype == 2 && !SteamMatchmaking.SetLobbyData(new CSteamID(param.m_ulSteamIDLobby), "MMMOD", "true"))
			{
				Debug.LogError((object)"Failed to assign custom matchmaking variable to lobbydata");
			}
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "LeaveLobby")]
	public class LeavePatch
	{
		private static void Prefix()
		{
			//IL_0020: 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)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			CSteamID val = (CSteamID)typeof(SteamLobbyHandler).GetField("m_currentLobby", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GameHandler.GetService<SteamLobbyHandler>());
			if (!(val != CSteamID.Nil) || !(SteamMatchmaking.GetLobbyData(val, "MMMOD") == "true") || SteamMatchmaking.GetNumLobbyMembers(val) > 1)
			{
				return;
			}
			string key = FirebaseLobbyClient.LastLobbyKey;
			if (string.IsNullOrEmpty(key))
			{
				return;
			}
			((MonoBehaviour)Plugin.Instance).StartCoroutine(FirebaseLobbyClient.DeleteLobby(key, delegate(bool success)
			{
				if (success)
				{
					Debug.Log((object)("[Firebase] Deleted lobby " + key));
				}
				else
				{
					Debug.LogError((object)("[Firebase] Failed to delete lobby " + key));
				}
			}));
			FirebaseLobbyClient.LastLobbyKey = null;
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "OnLobbyEnter")]
	public class LobbyEnterPatch
	{
		private static void Prefix(LobbyEnter_t param)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			if (param.m_EChatRoomEnterResponse == 2)
			{
				Debug.Log((object)"cant join this lobby");
				((TMP_Text)GameObject.Find("Modal(Clone)/Canvas/Background/TitleFields/SubheaderModalField(Clone)/Text (TMP)").GetComponent<TextMeshProUGUI>()).text = Plugin.Instance.loadingdescriptions[Random.Range(0, Plugin.Instance.loadingdescriptions.Length)];
				Plugin.Instance.nojoincache.Add(Plugin.Instance.lastjoinid);
				Plugin.Instance.FetchLobbiesI();
			}
		}
	}
	[HarmonyPatch(typeof(LoadingScreenHandler), "Load")]
	public class LoadingScreenPatch
	{
		private static void Postfix()
		{
			if (Modal.IsOpen)
			{
				Modal.CloseModal();
			}
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "HandleMessage")]
	public class HandleMessagePatch
	{
		private static bool Prefix(SteamLobbyHandler __instance, MessageType messageType, BinaryDeserializer deserializer, CSteamID lobbyID)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Invalid comparison between Unknown and I4
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Invalid comparison between Unknown and I4
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			_ = (CSteamID)typeof(SteamLobbyHandler).GetField("m_currentLobby", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GameHandler.GetService<SteamLobbyHandler>());
			if ((int)messageType == 1)
			{
				if (PhotonNetwork.IsMasterClient && PhotonNetwork.InRoom)
				{
					_ = (MethodInfo)typeof(SteamLobbyHandler).GetMethod("SendRoomID", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(GameHandler.GetService<SteamLobbyHandler>(), null);
					return false;
				}
			}
			else if ((int)messageType == 2)
			{
				FieldInfo field = typeof(SteamLobbyHandler).GetField("m_currentlyRequestingRoomID", BindingFlags.Instance | BindingFlags.NonPublic);
				Optionable<CSteamID> val = (Optionable<CSteamID>)field.GetValue(__instance);
				if (val.IsNone)
				{
					Debug.LogError((object)"Not requesting room id, ignoring...");
					return false;
				}
				if (val.IsSome && val.Value != lobbyID)
				{
					Debug.LogError((object)"Got room id for wrong lobby");
					return false;
				}
				FieldInfo field2 = typeof(SteamLobbyHandler).GetField("m_currentlyWaitingForRoomID", BindingFlags.Instance | BindingFlags.NonPublic);
				Optionable<(CSteamID, string, string)> val2 = (Optionable<(CSteamID, string, string)>)field2.GetValue(__instance);
				string text = deserializer.ReadString(Encoding.ASCII);
				if (text == "NOJOIN")
				{
					Debug.Log((object)"cant join this lobby");
					((TMP_Text)GameObject.Find("Modal(Clone)/Canvas/Background/TitleFields/SubheaderModalField(Clone)/Text (TMP)").GetComponent<TextMeshProUGUI>()).text = Plugin.Instance.loadingdescriptions[Random.Range(0, Plugin.Instance.loadingdescriptions.Length)];
					Plugin.Instance.cantjoincache.Add(((object)(CSteamID)(ref lobbyID)).ToString());
					Plugin.Instance.FetchLobbiesI();
					return false;
				}
				(CSteamID, string, string) value = val2.Value;
				string text2 = value.Item2;
				string item = value.Item3;
				field.SetValue(__instance, Optionable<CSteamID>.None);
				field2.SetValue(__instance, Optionable<(CSteamID, string, string)>.None);
				if (string.IsNullOrEmpty(text2))
				{
					text2 = "Airport";
					Debug.LogError((object)"Failed to get scene to load, defaulting to airport");
				}
				JoinSpecificRoomState obj = ((StateMachine<ConnectionState>)(object)GameHandler.GetService<ConnectionService>().StateMachine).SwitchState<JoinSpecificRoomState>(false);
				obj.RoomName = text;
				obj.RegionToJoin = item;
				Debug.Log((object)("Joining photon room: " + text));
				IEnumerator enumerator = (IEnumerator)typeof(LoadingScreenHandler).GetMethod("LoadSceneProcess", BindingFlags.Instance | BindingFlags.NonPublic).Invoke(RetrievableResourceSingleton<LoadingScreenHandler>.Instance, new object[4] { text2, false, true, 3f });
				RetrievableResourceSingleton<LoadingScreenHandler>.Instance.Load((LoadingScreenType)0, (Action)null, new IEnumerator[1] { enumerator });
				Plugin.Instance.cantjoincache.Clear();
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(SteamLobbyHandler), "SendRoomID")]
	public class SendRoomPatch
	{
		private static bool Prefix(SteamLobbyHandler __instance)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: 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_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			if (Plugin.Instance.curjoinwind == 1)
			{
				Scene activeScene = SceneManager.GetActiveScene();
				if (((Scene)(ref activeScene)).name.StartsWith("Level"))
				{
					FieldInfo field = typeof(SteamLobbyHandler).GetField("m_currentLobby", BindingFlags.Instance | BindingFlags.NonPublic);
					CSteamID val = (CSteamID)field.GetValue(GameHandler.GetService<SteamLobbyHandler>());
					if (val == CSteamID.Nil)
					{
						return false;
					}
					BinarySerializer val2 = new BinarySerializer(256, (Allocator)2);
					val2.WriteByte((byte)2);
					val2.WriteString("NOJOIN", Encoding.ASCII);
					byte[] array = NativeArrayExtensions.ToByteArray(val2.buffer);
					val2.Dispose();
					if (!SteamMatchmaking.SendLobbyChatMsg(val, array, array.Length))
					{
						typeof(SteamLobbyHandler).GetField("m_currentlyWaitingForRoomID", BindingFlags.Instance | BindingFlags.NonPublic);
						field.SetValue(__instance, Optionable<CSteamID>.None);
						Debug.LogError((object)"Failed to send Room ID...");
						return false;
					}
					((MonoBehaviour)Plugin.Instance).StartCoroutine(FirebaseLobbyClient.SetJoinable(value: false));
					return false;
				}
				activeScene = SceneManager.GetActiveScene();
				_ = ((Scene)(ref activeScene)).name == "Airport";
				return true;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(NetworkConnector), "HandleConnectionState")]
	public class ConnectionPatch
	{
		public static string the()
		{
			Random rand = new Random();
			return new string((from s in Enumerable.Repeat("ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", 5)
				select s[rand.Next(s.Length)]).ToArray());
		}

		private static bool Prefix(ConnectionState state, NetworkConnector __instance)
		{
			//IL_0041: 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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_00ed: Expected O, but got Unknown
			if (Plugin.Instance.curlobbytype == 2)
			{
				if (state is HostState)
				{
					CSteamID val = (CSteamID)typeof(SteamLobbyHandler).GetField("m_currentLobby", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(GameHandler.GetService<SteamLobbyHandler>());
					RoomOptions val2 = NetworkConnector.HostRoomOptions();
					val2.IsVisible = true;
					val2.IsOpen = true;
					string text = $"{the()}-MMMOD-{val}";
					List<string> list = new List<string>();
					foreach (PluginInfo value in Chainloader.PluginInfos.Values)
					{
						list.Add(value.Metadata.Name);
					}
					PhotonNetwork.CreateRoom(text, val2, (TypedLobby)null, (string[])null);
					if ((Object)(object)Object.FindObjectOfType<PlayerCountSync>() == (Object)null)
					{
						GameObject val3 = new GameObject("PlayerCountSync");
						val3.AddComponent<PlayerCountSync>();
						Object.DontDestroyOnLoad((Object)val3);
					}
					LobbyInfo info = new LobbyInfo
					{
						region = PhotonNetwork.CloudRegion,
						roomName = text,
						steamRoomId = ((object)(CSteamID)(ref val)).ToString(),
						creatorName = SteamFriends.GetPersonaName(),
						currentPlayers = 1,
						maxPlayers = val2.MaxPlayers,
						modList = list,
						regionJoinable = PhotonNetwork.CloudRegion + "_true",
						timestamp = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
					};
					((MonoBehaviour)__instance).StartCoroutine(FirebaseLobbyClient.PostLobby(info, delegate(bool success, string key)
					{
						if (success)
						{
							Debug.Log((object)("[Firebase] Lobby posted under key: " + key));
						}
						else
						{
							Debug.LogError((object)"[Firebase] Failed to post lobby");
						}
					}));
				}
				JoinSpecificRoomState joinState = (JoinSpecificRoomState)(object)((state is JoinSpecificRoomState) ? state : null);
				if (joinState != null)
				{
					Debug.Log((object)("$Connecting to specific region: " + joinState.RegionToJoin + " with app ID " + PhotonNetwork.PhotonServerSettings.AppSettings.AppIdRealtime + ". Is currently connected to: " + PhotonNetwork.CloudRegion));
					if (PhotonNetwork.CloudRegion != joinState.RegionToJoin && !string.IsNullOrEmpty(joinState.RegionToJoin))
					{
						Debug.Log((object)("Disconnecting and reconnecting to specfic region: " + joinState.RegionToJoin));
						PhotonNetwork.Disconnect();
						MethodInfo? method = ((object)__instance).GetType().GetMethod("PrepareSteamAuthTicket", BindingFlags.Static | BindingFlags.NonPublic);
						Action action = delegate
						{
							PhotonNetwork.ConnectToRegion(joinState.RegionToJoin);
						};
						method.Invoke(null, new object[1] { action });
						return false;
					}
					Debug.Log((object)("Joining specific room: " + joinState.RoomName));
					PhotonNetwork.JoinRoom(joinState.RoomName, (string[])null);
				}
				return false;
			}
			return true;
		}
	}
	public class PunCallbacks : MonoBehaviourPunCallbacks
	{
		public override void OnConnectedToMaster()
		{
			((MonoBehaviourPunCallbacks)this).OnConnectedToMaster();
		}
	}
}