Decompiled source of SplitScreenPlus v0.7.0

SplitScreenPlus.dll

Decompiled 3 days 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 BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.InputSystem.LowLevel;
using UnityEngine.InputSystem.Utilities;
using UnityEngine.UI;
using Zorro.ControllerSupport;
using Zorro.Core;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("SplitScreenPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SplitScreenPlus")]
[assembly: AssemblyTitle("SplitScreenPlus")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace SplitScreenPlus
{
	internal static class Guests
	{
		private sealed class Starter : MonoBehaviour
		{
			private void Start()
			{
				try
				{
					PhotonNetwork.AddCallbackTarget((object)_receiver);
					Plugin.Log.LogInfo((object)"Split-screen guests: ready to show friends' split-screen players.");
				}
				catch (Exception ex)
				{
					Plugin.Log.LogError((object)("Split-screen guests: " + ex));
				}
			}
		}

		private sealed class Receiver : IInRoomCallbacks, IMatchmakingCallbacks
		{
			public void OnJoinedRoom()
			{
				Clear();
				Player[] playerList = PhotonNetwork.PlayerList;
				for (int i = 0; i < playerList.Length; i++)
				{
					Sync(playerList[i]);
				}
			}

			public void OnLeftRoom()
			{
				Clear();
			}

			public void OnPlayerEnteredRoom(Player p)
			{
				if (!IsGuestObject(p))
				{
					Sync(p);
				}
			}

			public void OnPlayerLeftRoom(Player p)
			{
				if (IsGuestObject(p))
				{
					return;
				}
				foreach (int item in (from kv in _hostOf
					where kv.Value == p.ActorNumber
					select kv.Key).ToList())
				{
					RemoveGuest(item);
				}
			}

			public unsafe void OnPlayerPropertiesUpdate(Player p, Hashtable changed)
			{
				//IL_0035: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Unknown result type (might be due to invalid IL or missing references)
				if (p == null || IsGuestObject(p) || p.IsLocal)
				{
					return;
				}
				if (((Dictionary<object, object>)(object)changed).ContainsKey((object)"SSPg") || ((Dictionary<object, object>)(object)changed).ContainsKey((object)"SSPn"))
				{
					Sync(p);
				}
				DictionaryEntryEnumerator enumerator = changed.GetEnumerator();
				try
				{
					while (((DictionaryEntryEnumerator)(ref enumerator)).MoveNext())
					{
						DictionaryEntry current = ((DictionaryEntryEnumerator)(ref enumerator)).Current;
						if (current.Key is string text && text.StartsWith("SSPp") && int.TryParse(text.Substring("SSPp".Length), out var result))
						{
							object? value = current.Value;
							Hashtable val = (Hashtable)((value is Hashtable) ? value : null);
							if (val != null)
							{
								ApplyGuestProps(result, val);
							}
						}
					}
				}
				finally
				{
					((IDisposable)(*(DictionaryEntryEnumerator*)(&enumerator))/*cast due to .constrained prefix*/).Dispose();
				}
			}

			public void OnRoomPropertiesUpdate(Hashtable changed)
			{
			}

			public void OnMasterClientSwitched(Player m)
			{
			}

			public void OnFriendListUpdate(List<FriendInfo> l)
			{
			}

			public void OnCreatedRoom()
			{
			}

			public void OnCreateRoomFailed(short c, string m)
			{
			}

			public void OnJoinRoomFailed(short c, string m)
			{
			}

			public void OnJoinRandomFailed(short c, string m)
			{
			}
		}

		internal const string KeyGuests = "SSPg";

		internal const string KeyNames = "SSPn";

		internal const string KeyProps = "SSPp";

		internal const byte ForwardCode = 151;

		private static readonly Dictionary<int, int> _hostOf = new Dictionary<int, int>();

		private static readonly Dictionary<int, Player> _guestPlayers = new Dictionary<int, Player>();

		private static ConstructorInfo _playerCtor;

		private static MethodInfo _setUserId;

		private static MethodInfo _cacheProps;

		private static MethodInfo _removePlayer;

		private static MethodInfo _punOnEvent;

		private static FieldInfo _callbackTargets;

		private static FieldInfo _eventReceived;

		private static Receiver _receiver;

		internal static Action<int, EventData> RunForOwnGuest;

		internal static Func<int, bool> IsOwnGuest = (int _) => false;

		private static readonly FieldRef<CharacterVoiceHandler, Character> VoiceChar = AccessTools.FieldRefAccess<CharacterVoiceHandler, Character>("m_character");

		private static readonly FieldInfo VoiceRec = AccessTools.Field(typeof(CharacterVoiceHandler), "m_Recorder");

		internal static void Patch(Harmony h)
		{
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Expected O, but got Unknown
			//IL_01ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Expected O, but got Unknown
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_018f: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			_playerCtor = AccessTools.Constructor(typeof(Player), new Type[3]
			{
				typeof(string),
				typeof(int),
				typeof(bool)
			}, false);
			_setUserId = AccessTools.PropertySetter(typeof(Player), "UserId");
			_cacheProps = AccessTools.Method(typeof(Player), "InternalCacheProperties", (Type[])null, (Type[])null);
			_removePlayer = AccessTools.Method(typeof(Room), "RemovePlayer", new Type[1] { typeof(Player) }, (Type[])null);
			_punOnEvent = AccessTools.Method(typeof(PhotonNetwork), "OnEvent", (Type[])null, (Type[])null);
			_callbackTargets = AccessTools.Field(typeof(LoadBalancingClient), "InRoomCallbackTargets");
			_eventReceived = AccessTools.Field(typeof(LoadBalancingClient), "EventReceived");
			h.Patch((MethodBase)AccessTools.Method(typeof(LoadBalancingClient), "OpRaiseEvent", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Guests), "OpRaiseEvent_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(typeof(LoadBalancingClient), "OnEvent", (Type[])null, (Type[])null), new HarmonyMethod(typeof(Guests), "OnEvent_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			MethodInfo methodInfo = AccessTools.Method(typeof(CharacterVoiceHandler), "Update", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Guests), "Voice_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			_receiver = new Receiver();
			GameObject val = new GameObject("SplitScreenPlus_Guests");
			Object.DontDestroyOnLoad((Object)val);
			((Object)val).hideFlags = (HideFlags)61;
			val.AddComponent<Starter>();
		}

		internal static bool IsGuestOfOther(int actor)
		{
			return _hostOf.ContainsKey(actor);
		}

		private static bool IsGuestObject(Player p)
		{
			if (p != null)
			{
				if (!_guestPlayers.ContainsKey(p.ActorNumber))
				{
					return IsOwnGuest(p.ActorNumber);
				}
				return true;
			}
			return false;
		}

		private static void Clear()
		{
			_hostOf.Clear();
			_guestPlayers.Clear();
		}

		private static void Sync(Player host)
		{
			if (host == null || host.IsLocal || PhotonNetwork.CurrentRoom == null)
			{
				return;
			}
			try
			{
				object value;
				int[] actors = ((((Dictionary<object, object>)(object)host.CustomProperties).TryGetValue((object)"SSPg", out value) && value is int[] array) ? array : Array.Empty<int>());
				object value2;
				string[] array2 = ((((Dictionary<object, object>)(object)host.CustomProperties).TryGetValue((object)"SSPn", out value2) && value2 is string[] array3) ? array3 : Array.Empty<string>());
				foreach (int item in (from kv in _hostOf
					where kv.Value == host.ActorNumber && !Extensions.Contains(actors, kv.Key)
					select kv.Key).ToList())
				{
					RemoveGuest(item);
				}
				for (int num = 0; num < actors.Length; num++)
				{
					if (!_hostOf.ContainsKey(actors[num]))
					{
						AddGuest(host, actors[num], (num < array2.Length) ? array2[num] : $"{host.NickName} ({num + 2})");
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Split-screen guests: " + ex));
			}
		}

		private static void AddGuest(Player host, int actor, string name)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			Room currentRoom = PhotonNetwork.CurrentRoom;
			if (currentRoom.GetPlayer(actor, false) != null && !_guestPlayers.ContainsKey(actor))
			{
				Plugin.Log.LogWarning((object)$"Split-screen guest {actor} of {host.NickName} clashes with a real player; ignoring it.");
				return;
			}
			Player p = (Player)_playerCtor.Invoke(new object[3] { name, actor, false });
			_setUserId.Invoke(p, new object[1] { $"splitguest-{host.UserId}-{actor}" });
			if (((Dictionary<object, object>)(object)host.CustomProperties).TryGetValue((object)("SSPp" + actor), out object value))
			{
				Hashtable val = (Hashtable)((value is Hashtable) ? value : null);
				if (val != null)
				{
					_cacheProps.Invoke(p, new object[1] { val });
				}
			}
			currentRoom.AddPlayer(p);
			_hostOf[actor] = host.ActorNumber;
			_guestPlayers[actor] = p;
			RefreshViews(actor);
			Each(delegate(IInRoomCallbacks cb)
			{
				cb.OnPlayerEnteredRoom(p);
			});
			Plugin.Log.LogInfo((object)$"Split-screen guest joined: '{name}' (player {actor}, on {host.NickName}'s PC)");
		}

		private static void RemoveGuest(int actor)
		{
			_hostOf.Remove(actor);
			if (!_guestPlayers.TryGetValue(actor, out var p))
			{
				return;
			}
			_guestPlayers.Remove(actor);
			try
			{
				Each(delegate(IInRoomCallbacks cb)
				{
					cb.OnPlayerLeftRoom(p);
				});
			}
			catch
			{
			}
			PhotonView[] array = Object.FindObjectsByType<PhotonView>((FindObjectsSortMode)0);
			foreach (PhotonView val in array)
			{
				if ((Object)(object)val != (Object)null && val.OwnerActorNr == actor && val.isRuntimeInstantiated)
				{
					Object.Destroy((Object)(object)((Component)val).gameObject);
				}
			}
			try
			{
				_removePlayer.Invoke(PhotonNetwork.CurrentRoom, new object[1] { p });
			}
			catch
			{
			}
			Plugin.Log.LogInfo((object)$"Split-screen guest left: '{p.NickName}' (player {actor})");
		}

		private static void RefreshViews(int actor)
		{
			PhotonView[] array = Object.FindObjectsByType<PhotonView>((FindObjectsInactive)1, (FindObjectsSortMode)0);
			foreach (PhotonView val in array)
			{
				if (!((Object)(object)val == (Object)null) && val.OwnerActorNr == actor && val.Owner == null)
				{
					val.OwnerActorNr = 0;
					val.OwnerActorNr = actor;
					val.ControllerActorNr = actor;
				}
			}
		}

		private static void ApplyGuestProps(int actor, Hashtable props)
		{
			if (_guestPlayers.TryGetValue(actor, out var p))
			{
				_cacheProps.Invoke(p, new object[1] { props });
				Each(delegate(IInRoomCallbacks cb)
				{
					cb.OnPlayerPropertiesUpdate(p, props);
				});
			}
		}

		internal static void Each(Action<IInRoomCallbacks> call)
		{
			if (!(_callbackTargets?.GetValue(PhotonNetwork.NetworkingClient) is IEnumerable source))
			{
				return;
			}
			foreach (IInRoomCallbacks item in source.Cast<IInRoomCallbacks>().ToList())
			{
				if ((object)item != _receiver)
				{
					try
					{
						call(item);
					}
					catch (Exception ex)
					{
						Plugin.Log.LogDebug((object)(((object)item).GetType().Name + ": " + ex.Message));
					}
				}
			}
		}

		private static bool OpRaiseEvent_Prefix(LoadBalancingClient __instance, ref bool __result, byte eventCode, object customEventContent, RaiseEventOptions raiseEventOptions, SendOptions sendOptions)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Expected O, but got Unknown
			//IL_0121: Unknown result type (might be due to invalid IL or missing references)
			int[] array = raiseEventOptions?.TargetActors;
			if (array == null || array.Length == 0 || !array.Any((int t) => _hostOf.ContainsKey(t)))
			{
				return true;
			}
			int[] array2 = array.Where((int t) => !_hostOf.ContainsKey(t)).ToArray();
			bool flag = true;
			if (array2.Length != 0)
			{
				flag &= __instance.OpRaiseEvent(eventCode, customEventContent, new RaiseEventOptions
				{
					TargetActors = array2,
					CachingOption = raiseEventOptions.CachingOption,
					InterestGroup = raiseEventOptions.InterestGroup
				}, sendOptions);
			}
			foreach (int item in array.Where((int t) => _hostOf.ContainsKey(t)))
			{
				bool num = flag;
				object[] obj = new object[3] { item, eventCode, customEventContent };
				RaiseEventOptions val = new RaiseEventOptions();
				val.TargetActors = new int[1] { _hostOf[item] };
				flag = num & __instance.OpRaiseEvent((byte)151, (object)obj, val, sendOptions);
			}
			__result = flag;
			return false;
		}

		private static bool OnEvent_Prefix(LoadBalancingClient __instance, EventData photonEvent)
		{
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Expected O, but got Unknown
			if (photonEvent.Code != 151 || __instance != PhotonNetwork.NetworkingClient)
			{
				return true;
			}
			try
			{
				if (!(photonEvent.CustomData is object[] array) || array.Length < 3)
				{
					return false;
				}
				int num = Convert.ToInt32(array[0]);
				EventData val = new EventData
				{
					Code = Convert.ToByte(array[1])
				};
				val.Parameters[val.SenderKey] = photonEvent.Sender;
				val.Parameters[val.CustomDataKey] = array[2];
				if (IsOwnGuest(num) && RunForOwnGuest != null)
				{
					RunForOwnGuest(num, val);
				}
				else
				{
					Plugin.Log.LogDebug((object)$"Message for split-screen guest {num} arrived, but they're not here any more.");
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Message for a split-screen guest failed: " + (ex.InnerException?.Message ?? ex.Message)));
			}
			return false;
		}

		internal static void Dispatch(LoadBalancingClient client, EventData ev)
		{
			if (ev.Code >= 200)
			{
				_punOnEvent.Invoke(null, new object[1] { ev });
			}
			else
			{
				(_eventReceived?.GetValue(client) as Action<EventData>)?.Invoke(ev);
			}
		}

		private static void Voice_Postfix(CharacterVoiceHandler __instance)
		{
			Character val = VoiceChar.Invoke(__instance);
			if ((Object)(object)val == (Object)null || (Object)(object)val.refs?.view == (Object)null || !val.refs.view.IsMine || !IsOwnGuest(val.refs.view.OwnerActorNr))
			{
				return;
			}
			object obj = VoiceRec?.GetValue(__instance);
			if (obj != null)
			{
				Traverse val2 = Traverse.Create(obj);
				if (val2.Property("TransmitEnabled", (object[])null).GetValue<bool>())
				{
					val2.Property("TransmitEnabled", (object[])null).SetValue((object)false);
				}
				if (val2.Property("RecordingEnabled", (object[])null).GetValue<bool>())
				{
					val2.Property("RecordingEnabled", (object[])null).SetValue((object)false);
				}
			}
		}
	}
	internal static class InputPrompts
	{
		private static MethodInfo _ownerOf;

		private static FieldInfo _typeField;

		private static MethodInfo _iconChange;

		private static MethodInfo _inlineChange;

		private static readonly Dictionary<int, int> _applied = new Dictionary<int, int>();

		private static GamepadType _savedType;

		private static bool _swapped;

		private static float _next;

		internal static void Patch(Harmony h)
		{
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Expected O, but got Unknown
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Expected O, but got Unknown
			_ownerOf = AccessTools.Method(AccessTools.TypeByName("PeakSplitScreen.Owners"), "Of", new Type[1] { typeof(Component) }, (Type[])null);
			_typeField = AccessTools.Field(typeof(InputHandler), "_gamepadType");
			_iconChange = AccessTools.Method(typeof(InputIcon), "OnDeviceChange", (Type[])null, (Type[])null);
			_inlineChange = AccessTools.Method(typeof(InLineInputPrompts), "OnDeviceChange", (Type[])null, (Type[])null);
			if (_ownerOf == null || _typeField == null || _iconChange == null || _inlineChange == null)
			{
				Plugin.Log.LogWarning((object)"Per-player button icons: couldn't find what they need, leaving icons alone.");
				return;
			}
			HarmonyMethod val = new HarmonyMethod(typeof(InputPrompts), "Prefix", (Type[])null);
			HarmonyMethod val2 = new HarmonyMethod(typeof(InputPrompts), "Finalizer", (Type[])null);
			h.Patch((MethodBase)_iconChange, val, (HarmonyMethod)null, (HarmonyMethod)null, val2, (HarmonyMethod)null);
			h.Patch((MethodBase)_inlineChange, val, (HarmonyMethod)null, (HarmonyMethod)null, val2, (HarmonyMethod)null);
		}

		private static int SeatOf(Component c)
		{
			try
			{
				return (int)_ownerOf.Invoke(null, new object[1] { c });
			}
			catch
			{
				return 0;
			}
		}

		private static bool For(int seat, out InputScheme scheme, out GamepadType type)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected I4, but got Unknown
			scheme = (InputScheme)1;
			type = (GamepadType)0;
			if (!SplitAccess.Active || seat < 1)
			{
				return false;
			}
			if (seat == 1 && KeyboardMouse.Player1IsKeyboard)
			{
				scheme = (InputScheme)0;
				return true;
			}
			Gamepad[] pads = SplitAccess.Pads;
			Gamepad val = ((pads != null && seat < pads.Length) ? pads[seat] : null);
			if (val == null)
			{
				return false;
			}
			type = (GamepadType)(int)InputHandler.FindGamepadType((InputDevice)(object)val);
			return true;
		}

		private static int Key(int seat, InputScheme s, GamepadType t)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Expected I4, but got Unknown
			return seat * 100 + s * 10 + t;
		}

		private static void Prefix(Component __instance, ref InputScheme scheme)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Expected I4, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Invalid comparison between Unknown and I4
			//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_005e: Unknown result type (might be due to invalid IL or missing references)
			int seat = SeatOf(__instance);
			if (For(seat, out var scheme2, out var type))
			{
				scheme = (InputScheme)(int)scheme2;
				_applied[((Object)__instance).GetInstanceID()] = Key(seat, scheme2, type);
				InputHandler val = InputHandlerInstance();
				if (!((Object)(object)val == (Object)null) && (int)scheme2 == 1)
				{
					_savedType = (GamepadType)_typeField.GetValue(val);
					_typeField.SetValue(val, type);
					_swapped = true;
				}
			}
		}

		private static Exception Finalizer(Exception __exception)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (_swapped)
			{
				_swapped = false;
				InputHandler val = InputHandlerInstance();
				if ((Object)(object)val != (Object)null)
				{
					_typeField.SetValue(val, _savedType);
				}
			}
			return __exception;
		}

		private static InputHandler InputHandlerInstance()
		{
			try
			{
				return RetrievableResourceSingleton<InputHandler>.Instance;
			}
			catch
			{
				return null;
			}
		}

		internal static void Tick()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			if (!(_ownerOf == null) && SplitAccess.Active && !(Time.unscaledTime < _next))
			{
				_next = Time.unscaledTime + 1f;
				InputScheme currentUsedInputScheme = InputHandler.GetCurrentUsedInputScheme();
				Component[] items = (Component[])(object)Object.FindObjectsByType<InputIcon>((FindObjectsSortMode)0);
				Refresh(items, _iconChange, currentUsedInputScheme);
				items = (Component[])(object)Object.FindObjectsByType<InLineInputPrompts>((FindObjectsSortMode)0);
				Refresh(items, _inlineChange, currentUsedInputScheme);
			}
		}

		private static void Refresh(Component[] items, MethodInfo change, InputScheme global)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			foreach (Component val in items)
			{
				if ((Object)(object)val == (Object)null || !val.gameObject.activeInHierarchy)
				{
					continue;
				}
				int seat = SeatOf(val);
				if (For(seat, out var scheme, out var type) && (!_applied.TryGetValue(((Object)val).GetInstanceID(), out var value) || value != Key(seat, scheme, type)))
				{
					try
					{
						change.Invoke(val, new object[1] { global });
					}
					catch (Exception ex)
					{
						Plugin.Log.LogDebug((object)("Icon refresh: " + ex.Message));
					}
				}
			}
		}
	}
	internal static class JoinScreen
	{
		private static Type _setup;

		private static FieldRef<object> _root;

		private static FieldRef<object> _font;

		private static MonoBehaviour _runner;

		private static GameObject _built;

		private static RectTransform _sideRt;

		private static RectTransform _stackedRt;

		private static RectTransform _startRt;

		private static RectTransform _backRt;

		private static GameObject _kbButton;

		private static GameObject _twoButton;

		private static TextMeshProUGUI _kbText;

		private static TextMeshProUGUI _twoText;

		private static readonly TMP_InputField[] _names = (TMP_InputField[])(object)new TMP_InputField[5];

		internal static bool TwoMonitorsChosen;

		private static bool? _navWas;

		internal static bool Open
		{
			get
			{
				if ((Object)(object)_built != (Object)null)
				{
					return _built.activeInHierarchy;
				}
				return false;
			}
		}

		internal static void Patch(Harmony h)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			_setup = AccessTools.TypeByName("PeakSplitScreen.SetupScreen");
			if (!(_setup == null))
			{
				h.Patch((MethodBase)AccessTools.Method(_setup, "Show", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(JoinScreen), "Show_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "Continue", (Type[])null, (Type[])null), new HarmonyMethod(typeof(JoinScreen), "Continue_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "BeginSetup", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(JoinScreen), "BeginSetup_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
				h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "Close", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(JoinScreen), "Close_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static object Static(string f)
		{
			return AccessTools.Field(_setup, f)?.GetValue(null);
		}

		private static RectTransform RibbonRt(string f)
		{
			object obj = Static(f);
			if (obj == null)
			{
				return null;
			}
			return Traverse.Create(obj).Field("rt").GetValue<RectTransform>();
		}

		private static TextMeshProUGUI RibbonText(string f)
		{
			object obj = Static(f);
			if (obj == null)
			{
				return null;
			}
			return Traverse.Create(obj).Field("text").GetValue<TextMeshProUGUI>();
		}

		private static Traverse Runner()
		{
			if ((Object)(object)_runner == (Object)null)
			{
				Object obj = Object.FindAnyObjectByType(SplitAccess.Runner);
				_runner = (MonoBehaviour)(object)((obj is MonoBehaviour) ? obj : null);
			}
			if (!((Object)(object)_runner != (Object)null))
			{
				return null;
			}
			return Traverse.Create((object)_runner);
		}

		private static List<Gamepad> Joined()
		{
			Traverse obj = Runner();
			if (obj == null)
			{
				return null;
			}
			return obj.Field("joined").GetValue<List<Gamepad>>();
		}

		internal static int Step()
		{
			Traverse val = Runner();
			if (val != null)
			{
				return Convert.ToInt32(val.Field("step").GetValue());
			}
			return 0;
		}

		private static void Show_Postfix(int step, IList<Gamepad> joined, bool vertical)
		{
			try
			{
				object obj = Static("root");
				GameObject val = (GameObject)((obj is GameObject) ? obj : null);
				if (!((Object)(object)val == (Object)null))
				{
					if ((Object)(object)_built != (Object)(object)val)
					{
						Build(val);
					}
					Refresh(step, joined, vertical);
					KeepFocus(val);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Join screen: " + ex.Message));
			}
		}

		private static void BeginSetup_Postfix(object __instance)
		{
			try
			{
				BaseInputModule value = Traverse.Create(__instance).Field("menuInput").GetValue<BaseInputModule>();
				if ((Object)(object)value != (Object)null)
				{
					((Behaviour)value).enabled = true;
				}
				EventSystem current = EventSystem.current;
				if ((Object)(object)current != (Object)null)
				{
					bool valueOrDefault = _navWas == true;
					if (!_navWas.HasValue)
					{
						valueOrDefault = current.sendNavigationEvents;
						_navWas = valueOrDefault;
					}
					current.sendNavigationEvents = false;
					current.SetSelectedGameObject((GameObject)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Join screen input: " + ex.Message));
			}
		}

		private static void Close_Postfix()
		{
			EventSystem current = EventSystem.current;
			if ((Object)(object)current != (Object)null && _navWas.HasValue)
			{
				current.sendNavigationEvents = _navWas.Value;
			}
			_navWas = null;
		}

		private static void Build(GameObject root)
		{
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_022c: Unknown result type (might be due to invalid IL or missing references)
			_built = root;
			TwoMonitorsChosen = Plugin.TwoMonitors.Value;
			if ((Object)(object)root.GetComponent<GraphicRaycaster>() == (Object)null)
			{
				root.AddComponent<GraphicRaycaster>();
			}
			Transform obj = root.transform.Find("Dim");
			Image val = ((obj != null) ? ((Component)obj).GetComponent<Image>() : null);
			if ((Object)(object)val != (Object)null)
			{
				((Graphic)val).raycastTarget = true;
			}
			_sideRt = RibbonRt("side");
			_stackedRt = RibbonRt("stacked");
			_startRt = RibbonRt("start");
			_backRt = RibbonRt("back");
			Clickable(_startRt, OnStart);
			Clickable(_backRt, delegate
			{
				Traverse obj3 = Runner();
				if (obj3 != null)
				{
					obj3.Method("Close", Array.Empty<object>()).GetValue();
				}
			});
			Clickable(_sideRt, delegate
			{
				Choose(vertical: true);
			});
			Clickable(_stackedRt, delegate
			{
				Choose(vertical: false);
			});
			_kbButton = CloneRibbon(_backRt, "JoinKeyboard", new Vector2(0f, -255f), new Vector2(640f, 72f), out _kbText);
			Clickable(_kbButton.GetComponent<RectTransform>(), JoinKeyboard);
			_twoButton = CloneRibbon(_sideRt, "TwoMonitors", new Vector2(610f, -255f), new Vector2(380f, 76f), out _twoText);
			Clickable(_twoButton.GetComponent<RectTransform>(), delegate
			{
				if (Step() == 2)
				{
					TwoMonitorsChosen = !TwoMonitorsChosen;
				}
			});
			object obj2 = Static("font");
			TMP_FontAsset font = (TMP_FontAsset)((obj2 is TMP_FontAsset) ? obj2 : null);
			for (int num = 2; num <= 4; num++)
			{
				_names[num] = NameBox(root.transform, num, new Vector2(590f, (float)(185 - (num - 1) * 102)), font);
			}
		}

		private static void Clickable(RectTransform rt, Action onClick)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			if ((Object)(object)rt == (Object)null)
			{
				return;
			}
			Image component = ((Component)rt).GetComponent<Image>();
			if ((Object)(object)component != (Object)null)
			{
				((Graphic)component).raycastTarget = true;
			}
			Button obj = ((Component)rt).GetComponent<Button>() ?? ((Component)rt).gameObject.AddComponent<Button>();
			((Selectable)obj).transition = (Transition)0;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			((UnityEventBase)obj.onClick).RemoveAllListeners();
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				try
				{
					onClick();
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Join screen click: " + ex.Message));
				}
			});
		}

		private static GameObject CloneRibbon(RectTransform src, string name, Vector2 pos, Vector2 size, out TextMeshProUGUI text)
		{
			//IL_0020: 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_002d: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)src).gameObject, ((Transform)src).parent);
			((Object)val).name = name;
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchoredPosition = pos;
			component.sizeDelta = size;
			((Transform)component).localScale = Vector3.one;
			Button component2 = val.GetComponent<Button>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				Object.DestroyImmediate((Object)(object)component2);
			}
			text = val.GetComponentInChildren<TextMeshProUGUI>(true);
			return val;
		}

		private static TMP_InputField NameBox(Transform parent, int seat, Vector2 pos, TMP_FontAsset font)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Expected O, but got Unknown
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: Expected O, but got Unknown
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_011c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0228: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject($"Name{seat}", new Type[2]
			{
				typeof(RectTransform),
				typeof(Image)
			});
			val.SetActive(false);
			val.transform.SetParent(parent, false);
			RectTransform component = val.GetComponent<RectTransform>();
			component.anchoredPosition = pos;
			component.sizeDelta = new Vector2(300f, 64f);
			((Graphic)val.GetComponent<Image>()).color = new Color(0.99f, 0.97f, 0.95f, 0.92f);
			GameObject area = new GameObject("Text Area", new Type[2]
			{
				typeof(RectTransform),
				typeof(RectMask2D)
			});
			area.transform.SetParent(val.transform, false);
			RectTransform component2 = area.GetComponent<RectTransform>();
			component2.anchorMin = Vector2.zero;
			component2.anchorMax = Vector2.one;
			component2.offsetMin = new Vector2(14f, 6f);
			component2.offsetMax = new Vector2(-14f, -6f);
			TextMeshProUGUI textComponent = Make("Text", new Color(0.17f, 0.12f, 0.1f));
			TextMeshProUGUI val2 = Make("Placeholder", new Color(0.17f, 0.12f, 0.1f, 0.45f));
			((TMP_Text)val2).text = $"Player {seat}'s name";
			TMP_InputField obj = val.AddComponent<TMP_InputField>();
			obj.textViewport = component2;
			obj.textComponent = (TMP_Text)(object)textComponent;
			obj.placeholder = (Graphic)(object)val2;
			obj.characterLimit = 20;
			obj.text = Plugin.NameFor(seat);
			((UnityEvent<string>)(object)obj.onEndEdit).AddListener((UnityAction<string>)delegate(string v)
			{
				Plugin.SetName(seat, v);
			});
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			obj.fontAsset = font;
			obj.pointSize = 30f;
			obj.caretColor = new Color(0.17f, 0.12f, 0.1f);
			obj.customCaretColor = true;
			obj.selectionColor = new Color(0.46f, 0.27f, 0.66f, 0.35f);
			((UnityEvent<string>)(object)obj.onSelect).AddListener((UnityAction<string>)delegate
			{
				Plugin.Log.LogInfo((object)$"Editing player {seat}'s name");
			});
			val.SetActive(true);
			return obj;
			TextMeshProUGUI Make(string n, Color c)
			{
				//IL_0014: 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)
				//IL_0048: Unknown result type (might be due to invalid IL or missing references)
				//IL_0052: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				TextMeshProUGUI val3 = new GameObject(n, new Type[1] { typeof(RectTransform) }).AddComponent<TextMeshProUGUI>();
				((TMP_Text)val3).transform.SetParent(area.transform, false);
				RectTransform rectTransform = ((TMP_Text)val3).rectTransform;
				rectTransform.anchorMin = Vector2.zero;
				rectTransform.anchorMax = Vector2.one;
				rectTransform.sizeDelta = Vector2.zero;
				if (Object.op_Implicit((Object)(object)font))
				{
					((TMP_Text)val3).font = font;
				}
				((TMP_Text)val3).fontSize = 30f;
				((Graphic)val3).color = c;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)4097;
				((TMP_Text)val3).enableWordWrapping = false;
				return val3;
			}
		}

		private static void Refresh(int step, IList<Gamepad> joined, bool vertical)
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			bool flag = step == 2;
			bool flag2 = KeyboardMouse.Pad != null && joined.Contains(KeyboardMouse.Pad);
			bool flag3 = flag && joined.Count >= 2 && TwoScreens.MonitorCount() >= 2;
			if (!flag3 && flag)
			{
				TwoMonitorsChosen = false;
			}
			bool flag4 = flag3 && TwoMonitorsChosen;
			_kbButton.SetActive(!flag && Plugin.KeyboardPlayer1.Value);
			if (Object.op_Implicit((Object)(object)_kbText))
			{
				((TMP_Text)_kbText).text = (flag2 ? "KEYBOARD & MOUSE JOINED (PLAYER 1)" : "CLICK HERE / PRESS SPACE: KEYBOARD & MOUSE");
			}
			bool flag5 = flag && (flag4 ? (joined.Count >= 3) : (joined.Count <= 3));
			if (Object.op_Implicit((Object)(object)_sideRt))
			{
				((Component)_sideRt).gameObject.SetActive(flag5);
			}
			if (Object.op_Implicit((Object)(object)_stackedRt))
			{
				((Component)_stackedRt).gameObject.SetActive(flag5);
			}
			if (flag5 && flag4)
			{
				string text = "TOP AND BOTTOM";
				Paint(_stackedRt, vertical ? 0.4f : 1f, vertical ? text : ("‹  " + text + "  ›"));
			}
			_twoButton.SetActive(flag3);
			if (flag3)
			{
				Image component = _twoButton.GetComponent<Image>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Color color = ((Graphic)component).color;
					color.a = (flag4 ? 1f : 0.45f);
					((Graphic)component).color = color;
				}
				_twoButton.transform.localScale = Vector3.one * (flag4 ? 1.06f : 1f);
				if (Object.op_Implicit((Object)(object)_twoText))
				{
					((TMP_Text)_twoText).text = (flag4 ? "TWO MONITORS: ON" : "TWO MONITORS: OFF");
				}
			}
			if (flag2 && Static("pads") is Image[] array)
			{
				int num = joined.IndexOf(KeyboardMouse.Pad);
				if (num >= 0 && num < array.Length && Object.op_Implicit((Object)(object)array[num]))
				{
					((Behaviour)array[num]).enabled = false;
				}
			}
			for (int i = 2; i <= 4; i++)
			{
				if (Object.op_Implicit((Object)(object)_names[i]))
				{
					((Component)_names[i]).gameObject.SetActive(i <= joined.Count);
				}
			}
			object obj = Static("sub");
			TextMeshProUGUI val = (TextMeshProUGUI)((obj is TextMeshProUGUI) ? obj : null);
			object obj2 = Static("hint");
			TextMeshProUGUI val2 = (TextMeshProUGUI)((obj2 is TextMeshProUGUI) ? obj2 : null);
			if (flag)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					((TMP_Text)val).text = "PLAYER 1: CHOOSE HOW TO SPLIT THE SCREEN";
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					((TMP_Text)val2).text = "CLICK YOUR CHOICES, THEN START     ·     ← / →  CHOOSE   SPACE / A  PLAY   ESC / B  BACK";
				}
			}
			else if (Online.InOnlineRoom)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					((TMP_Text)val).text = "ADDING PLAYERS TO THIS ONLINE GAME     ·     PLAYER 1 = YOU     ·     CONTROLLER PLAYERS: PRESS A TO JOIN";
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					((TMP_Text)val2).text = ((joined.Count >= 2) ? "CLICK START WHEN EVERYONE IS IN - THEY JOIN THE GAME AS NEW PLAYERS     ·     ESC / B  BACK" : "PLAYER 1: JOIN FIRST (SPACE FOR KEYBOARD, A FOR CONTROLLER)     ·     TYPE NAMES IN THE BOXES     ·     ESC / B  BACK");
				}
			}
			else
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					((TMP_Text)val).text = "CONTROLLER PLAYERS: PRESS A TO JOIN     ·     KEYBOARD & MOUSE IS ALWAYS PLAYER 1";
				}
				if (Object.op_Implicit((Object)(object)val2))
				{
					((TMP_Text)val2).text = ((joined.Count >= 2) ? "CLICK START (OR ENTER / START BUTTON) WHEN EVERYONE IS IN     ·     ESC / B  BACK" : "2 TO 4 PLAYERS     ·     TYPE NAMES IN THE BOXES     ·     ESC / B  BACK");
				}
			}
		}

		private static void Paint(RectTransform rt, float alpha, string text)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: 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)
			if (!((Object)(object)rt == (Object)null))
			{
				Image component = ((Component)rt).GetComponent<Image>();
				if (Object.op_Implicit((Object)(object)component))
				{
					Color color = ((Graphic)component).color;
					color.a = alpha;
					((Graphic)component).color = color;
				}
				TextMeshProUGUI componentInChildren = ((Component)rt).GetComponentInChildren<TextMeshProUGUI>(true);
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					((TMP_Text)componentInChildren).text = text;
				}
			}
		}

		private static void KeepFocus(GameObject root)
		{
			EventSystem current = EventSystem.current;
			if (!((Object)(object)current == (Object)null))
			{
				GameObject currentSelectedGameObject = current.currentSelectedGameObject;
				if ((Object)(object)currentSelectedGameObject != (Object)null && !currentSelectedGameObject.transform.IsChildOf(root.transform))
				{
					current.SetSelectedGameObject((GameObject)null);
				}
			}
		}

		internal static bool TypingName()
		{
			for (int i = 2; i <= 4; i++)
			{
				if (Object.op_Implicit((Object)(object)_names[i]) && _names[i].isFocused)
				{
					return true;
				}
			}
			return false;
		}

		private static void OnStart()
		{
			List<Gamepad> list = Joined();
			if (list == null)
			{
				return;
			}
			if (Step() == 2)
			{
				Launch();
			}
			else if (list.Count >= 2)
			{
				Traverse obj = Runner();
				if (obj != null)
				{
					obj.Method("Continue", Array.Empty<object>()).GetValue();
				}
			}
		}

		internal static void Launch()
		{
			Traverse obj = Runner();
			if (obj != null)
			{
				obj.Method("Launch", Array.Empty<object>()).GetValue();
			}
		}

		private static void Choose(bool vertical)
		{
			if (Step() == 2)
			{
				Traverse obj = Runner();
				if (obj != null)
				{
					obj.Field("vertical").SetValue((object)vertical);
				}
			}
		}

		internal static bool Continue_Prefix(object __instance)
		{
			Traverse val = Traverse.Create(__instance);
			List<Gamepad> value = val.Field("joined").GetValue<List<Gamepad>>();
			if (value == null || value.Count != 4 || TwoScreens.MonitorCount() < 2)
			{
				return true;
			}
			Traverse obj = val.Field("step");
			obj.SetValue(Enum.ToObject(obj.GetValueType(), 2));
			val.Field("beganFrame").SetValue((object)Time.frameCount);
			return false;
		}

		internal static void JoinKeyboard()
		{
			List<Gamepad> list = Joined();
			if (list != null && Plugin.KeyboardPlayer1.Value && Step() != 2)
			{
				Gamepad val = KeyboardMouse.EnsurePad();
				if (val != null && !list.Contains(val) && list.Count < 4)
				{
					list.Insert(0, val);
					Plugin.Log.LogInfo((object)"Keyboard & Mouse joined as player 1.");
				}
			}
		}
	}
	internal static class KeyboardMouse
	{
		internal static Gamepad Pad;

		private static bool _released;

		internal static bool Player1IsKeyboard
		{
			get
			{
				if (Pad == null || !SplitAccess.Active)
				{
					return false;
				}
				Gamepad[] pads = SplitAccess.Pads;
				if (pads != null && pads.Length > 1)
				{
					return pads[1] == Pad;
				}
				return false;
			}
		}

		internal static void Patch(Harmony h)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Expected O, but got Unknown
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Expected O, but got Unknown
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0125: Expected O, but got Unknown
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "Pairing", (Type[])null, (Type[])null), new HarmonyMethod(typeof(KeyboardMouse), "Pairing_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "Close", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(KeyboardMouse), "Close_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Runner, "Launch", (Type[])null, (Type[])null), new HarmonyMethod(typeof(KeyboardMouse), "Launch_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Split, "PinPlayer1", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(KeyboardMouse), "Pin_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Split, "Player1Pinned", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(KeyboardMouse), "Pinned_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Split, "StartRepair", (Type[])null, (Type[])null), new HarmonyMethod(typeof(KeyboardMouse), "Repair_Prefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		internal static Gamepad EnsurePad()
		{
			if (Pad == null || !((InputDevice)Pad).added)
			{
				Pad = InputSystem.AddDevice<Gamepad>("Keyboard & Mouse");
			}
			return Pad;
		}

		private static void Pairing_Prefix()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
			if (!Plugin.KeyboardPlayer1.Value || Keyboard.current == null)
			{
				return;
			}
			EnsurePad();
			Keyboard current = Keyboard.current;
			GamepadState val = default(GamepadState);
			if (!JoinScreen.TypingName())
			{
				bool num = JoinScreen.Step() == 2;
				if (!num && ((ButtonControl)current.spaceKey).wasPressedThisFrame)
				{
					JoinScreen.JoinKeyboard();
				}
				if (num && ((ButtonControl)current.spaceKey).isPressed)
				{
					val = ((GamepadState)(ref val)).WithButton((GamepadButton)6, true);
				}
				if (((ButtonControl)current.enterKey).isPressed || ((ButtonControl)current.numpadEnterKey).isPressed)
				{
					val = ((GamepadState)(ref val)).WithButton((GamepadButton)12, true);
				}
				if (((ButtonControl)current.leftArrowKey).isPressed || ((ButtonControl)current.aKey).isPressed)
				{
					val = ((GamepadState)(ref val)).WithButton((GamepadButton)2, true);
				}
				if (((ButtonControl)current.rightArrowKey).isPressed || ((ButtonControl)current.dKey).isPressed)
				{
					val = ((GamepadState)(ref val)).WithButton((GamepadButton)3, true);
				}
			}
			InputSystem.QueueStateEvent<GamepadState>((InputDevice)(object)Pad, val, -1.0);
			_released = false;
		}

		private static void Launch_Prefix(object __instance)
		{
			List<Gamepad> value = Traverse.Create(__instance).Field("joined").GetValue<List<Gamepad>>();
			TwoScreens.Want = JoinScreen.TwoMonitorsChosen && value != null && value.Count >= 2 && TwoScreens.MonitorCount() >= 2;
		}

		private static void Close_Postfix(object __instance)
		{
			//IL_000f: 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)
			if (Pad != null)
			{
				InputSystem.QueueStateEvent<GamepadState>((InputDevice)(object)Pad, default(GamepadState), -1.0);
				List<Gamepad> value = Traverse.Create(__instance).Field("joined").GetValue<List<Gamepad>>();
				bool flag = value?.Contains(Pad) ?? false;
				if (!flag && !_released)
				{
					_released = true;
					Gamepad pad = Pad;
					Pad = null;
					InputSystem.RemoveDevice((InputDevice)(object)pad);
				}
				else if (flag)
				{
					Plugin.Log.LogInfo((object)$"Keyboard & Mouse joined as player {value.IndexOf(Pad) + 1}.");
				}
			}
		}

		private static void Pin_Postfix()
		{
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (!Player1IsKeyboard || Keyboard.current == null)
			{
				return;
			}
			List<InputDevice> list = new List<InputDevice> { (InputDevice)(object)Keyboard.current };
			if (Mouse.current != null)
			{
				list.Add((InputDevice)(object)Mouse.current);
			}
			list.Add((InputDevice)(object)Pad);
			PlayerInput playerInput = SplitAccess.PlayerInput;
			if ((Object)(object)playerInput != (Object)null && (Object)(object)playerInput.actions != (Object)null)
			{
				InputControlScheme val = ((IEnumerable<InputControlScheme>)(object)playerInput.actions.controlSchemes).FirstOrDefault((Func<InputControlScheme, bool>)((InputControlScheme s) => ((InputControlScheme)(ref s)).SupportsDevice((InputDevice)(object)Keyboard.current)));
				if (!string.IsNullOrEmpty(((InputControlScheme)(ref val)).name))
				{
					try
					{
						playerInput.SwitchCurrentControlScheme(((InputControlScheme)(ref val)).name, list.Where((InputDevice d) => (object)d != Pad).ToArray());
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("Keyboard scheme switch: " + ex.Message));
					}
				}
			}
			InputSystem.actions.devices = ReadOnlyArray<InputDevice>.op_Implicit(list.ToArray());
			Plugin.Log.LogInfo((object)"Player 1 is on keyboard and mouse.");
		}

		private static void Pinned_Postfix(ref bool __result)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			if (Player1IsKeyboard)
			{
				ReadOnlyArray<InputDevice>? devices = InputSystem.actions.devices;
				__result = devices.HasValue && Keyboard.current != null && ((IEnumerable<InputDevice>)(object)devices.Value).Contains((InputDevice)(object)Keyboard.current);
			}
		}

		private static bool Repair_Prefix(ref int who)
		{
			if (!Player1IsKeyboard)
			{
				return true;
			}
			who &= -3;
			return who != 0;
		}
	}
	internal static class MainOnly
	{
		private const string Wrapper = "SSP_MainMonitor";

		private static readonly List<Canvas> _wrapped = new List<Canvas>();

		private static readonly Dictionary<Transform, Vector2> _shifted = new Dictionary<Transform, Vector2>();

		private static float _next;

		internal static void Tick(bool on, Rect main)
		{
			//IL_00b5: 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)
			if (!on)
			{
				if (_wrapped.Count > 0)
				{
					UnwrapAll();
				}
			}
			else
			{
				if (Time.unscaledTime < _next)
				{
					return;
				}
				_next = Time.unscaledTime + 0.2f;
				HashSet<Canvas> hashSet = new HashSet<Canvas>();
				IEnumerable hudFrames = SplitAccess.HudFrames;
				if (hudFrames != null)
				{
					foreach (object item2 in hudFrames)
					{
						Canvas item = SplitAccess.ReadFrame(item2).canvas;
						if ((Object)(object)item != (Object)null)
						{
							hashSet.Add(item);
						}
					}
				}
				Canvas[] array = Object.FindObjectsByType<Canvas>((FindObjectsInactive)0, (FindObjectsSortMode)0);
				foreach (Canvas val in array)
				{
					if (!((Object)(object)val == (Object)null) && val.isRootCanvas && (int)val.renderMode == 0 && !hashSet.Contains(val) && !((Object)(object)((Component)val).transform.Find("SplitView") != (Object)null))
					{
						Fit(val, main);
					}
				}
				_wrapped.RemoveAll((Canvas c) => (Object)(object)c == (Object)null);
				if (_shifted.Count <= 64)
				{
					return;
				}
				List<Transform> list = new List<Transform>();
				foreach (Transform key in _shifted.Keys)
				{
					if ((Object)(object)key == (Object)null)
					{
						list.Add(key);
					}
				}
				foreach (Transform item3 in list)
				{
					_shifted.Remove(item3);
				}
			}
		}

		private static void Fit(Canvas cv, Rect r)
		{
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d4: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_0146: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f0: Expected O, but got Unknown
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0212: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_0226: Unknown result type (might be due to invalid IL or missing references)
			//IL_022d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0232: Unknown result type (might be due to invalid IL or missing references)
			//IL_0234: Unknown result type (might be due to invalid IL or missing references)
			//IL_0239: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0256: Unknown result type (might be due to invalid IL or missing references)
			Transform obj = ((Component)cv).transform.Find("SSP_MainMonitor");
			RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				val = new GameObject("SSP_MainMonitor", new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
				((Transform)val).SetParent(((Component)cv).transform, false);
				_wrapped.Add(cv);
			}
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor((float)Screen.width, (float)Screen.height);
			Vector2 val3 = default(Vector2);
			((Vector2)(ref val3))..ctor(((Rect)(ref r)).width * val2.x, ((Rect)(ref r)).height * val2.y);
			CanvasScaler component = ((Component)cv).GetComponent<CanvasScaler>();
			float num = ScaleFor(component, val2);
			float num2 = ScaleFor(component, val3);
			Vector2 val4 = val3 / num2;
			List<Transform> list = new List<Transform>();
			foreach (Transform item in ((Component)cv).transform)
			{
				Transform val5 = item;
				if ((Object)(object)val5 != (Object)(object)val)
				{
					list.Add(val5);
				}
			}
			foreach (Transform item2 in list)
			{
				item2.SetParent((Transform)(object)val, false);
				if (!(item2 is RectTransform))
				{
					item2.localPosition += Vector2.op_Implicit(val4 * 0.5f);
					_shifted[item2] = val4 * 0.5f;
				}
			}
			RectTransform obj2 = val;
			RectTransform obj3 = val;
			Vector2 val6 = default(Vector2);
			((Vector2)(ref val6))..ctor(((Rect)(ref r)).x, ((Rect)(ref r)).y);
			obj3.anchorMax = val6;
			obj2.anchorMin = val6;
			val.pivot = Vector2.zero;
			val.anchoredPosition = Vector2.zero;
			((Transform)val).localScale = Vector3.one * (num2 / num);
			val.sizeDelta = val4;
			foreach (Transform item3 in (Transform)val)
			{
				Transform val7 = item3;
				if (!(val7 is RectTransform) && _shifted.TryGetValue(val7, out var value) && value != val4 * 0.5f)
				{
					val7.localPosition += Vector2.op_Implicit(val4 * 0.5f - value);
					_shifted[val7] = val4 * 0.5f;
				}
			}
		}

		private static float ScaleFor(CanvasScaler s, Vector2 size)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Invalid comparison between Unknown and I4
			//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_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Invalid comparison between Unknown and I4
			//IL_0037: 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)
			//IL_0044: 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)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Invalid comparison between Unknown and I4
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)s == (Object)null)
			{
				return 1f;
			}
			if ((int)s.uiScaleMode != 1)
			{
				return s.scaleFactor;
			}
			Vector2 referenceResolution = s.referenceResolution;
			ScreenMatchMode screenMatchMode = s.screenMatchMode;
			if ((int)screenMatchMode != 1)
			{
				if ((int)screenMatchMode == 2)
				{
					return Mathf.Max(size.x / referenceResolution.x, size.y / referenceResolution.y);
				}
				float num = Mathf.Log(size.x / referenceResolution.x, 2f);
				float num2 = Mathf.Log(size.y / referenceResolution.y, 2f);
				return Mathf.Pow(2f, Mathf.Lerp(num, num2, s.matchWidthOrHeight));
			}
			return Mathf.Min(size.x / referenceResolution.x, size.y / referenceResolution.y);
		}

		private static void UnwrapAll()
		{
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			foreach (Canvas item2 in _wrapped)
			{
				if ((Object)(object)item2 == (Object)null)
				{
					continue;
				}
				Transform val = ((Component)item2).transform.Find("SSP_MainMonitor");
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				List<Transform> list = new List<Transform>();
				foreach (Transform item3 in val)
				{
					Transform item = item3;
					list.Add(item);
				}
				foreach (Transform item4 in list)
				{
					item4.SetParent(((Component)item2).transform, false);
					if (_shifted.TryGetValue(item4, out var value))
					{
						item4.localPosition -= Vector2.op_Implicit(value);
					}
				}
				Object.Destroy((Object)(object)((Component)val).gameObject);
			}
			_wrapped.Clear();
			_shifted.Clear();
		}
	}
	internal static class ModCompat
	{
		private static Type _patches;

		private static Type _ctx;

		private static Type _owners;

		private static HarmonyMethod _pre;

		private static HarmonyMethod _fin;

		private static HarmonyMethod _preIter;

		private static HarmonyMethod _gate;

		private static MethodInfo _usesLocal;

		private static MethodInfo _ctxAdd;

		private static MethodInfo _hudTo;

		private static IDictionary _iterSelf;

		private static PropertyInfo _viewsReady;

		private static MethodInfo _ownerOf;

		private static readonly List<Type> _wrappedTypes = new List<Type>();

		private static readonly List<FieldInfo> _uiStatics = new List<FieldInfo>();

		private static readonly List<object[]> _slotValues = new List<object[]>();

		private static readonly HashSet<int> _fitted = new HashSet<int>();

		private static readonly HashSet<Assembly> _modAssemblies = new HashSet<Assembly>();

		private static readonly HashSet<string> Callbacks = new HashSet<string> { "Start", "Update", "LateUpdate", "FixedUpdate", "OnEnable", "OnDisable" };

		internal static void Init(Harmony h)
		{
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Expected O, but got Unknown
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Expected O, but got Unknown
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: Expected O, but got Unknown
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Expected O, but got Unknown
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Expected O, but got Unknown
			//IL_01d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Expected O, but got Unknown
			_patches = AccessTools.TypeByName("PeakSplitScreen.Patches");
			_ctx = AccessTools.TypeByName("PeakSplitScreen.Ctx");
			_owners = AccessTools.TypeByName("PeakSplitScreen.Owners");
			if (_patches == null || _ctx == null || _owners == null)
			{
				Plugin.Log.LogWarning((object)"Mod compat: split-screen internals not found.");
				return;
			}
			_pre = new HarmonyMethod(AccessTools.Method(_patches, "Pre", (Type[])null, (Type[])null));
			_fin = new HarmonyMethod(AccessTools.Method(_patches, "Fin", (Type[])null, (Type[])null));
			_preIter = new HarmonyMethod(AccessTools.Method(_patches, "PreIter", (Type[])null, (Type[])null));
			_gate = new HarmonyMethod(AccessTools.Method(typeof(ModCompat), "Gate", (Type[])null, (Type[])null))
			{
				priority = 800
			};
			_usesLocal = AccessTools.Method(_patches, "UsesLocalPlayer", (Type[])null, (Type[])null);
			_iterSelf = AccessTools.Field(_patches, "iterSelf")?.GetValue(null) as IDictionary;
			_ctxAdd = AccessTools.Method(_ctx, "Add", (Type[])null, (Type[])null);
			_hudTo = AccessTools.Method(SplitAccess.Split, "HudTo", (Type[])null, (Type[])null);
			_viewsReady = AccessTools.Property(SplitAccess.Split, "ViewsReady");
			_ownerOf = AccessTools.Method(_owners, "Of", new Type[1] { typeof(Component) }, (Type[])null);
			h.Patch((MethodBase)AccessTools.Method(_ctx, "Begin", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ModCompat), "Begin_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			h.Patch((MethodBase)AccessTools.Method(SplitAccess.Split, "Views", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ModCompat), "Views_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
		}

		private static bool Excluded(Assembly a)
		{
			string n = a.GetName().Name;
			if (a == typeof(ModCompat).Assembly || a == _patches.Assembly)
			{
				return true;
			}
			if (new string[6] { "BepInEx", "0Harmony", "MonoMod", "Mono.Cecil", "PEAKLib", "com.github.PEAKModding" }.Any((string p) => n.StartsWith(p, StringComparison.OrdinalIgnoreCase)))
			{
				return true;
			}
			return (from s in Plugin.CompatSkip.Value.Split(',')
				select s.Trim() into s
				where s.Length > 0
				select s).Any((string s) => n.IndexOf(s, StringComparison.OrdinalIgnoreCase) >= 0);
		}

		internal static void WrapMods(Harmony h)
		{
			if (_pre == null || _usesLocal == null)
			{
				return;
			}
			List<Assembly> list = (from p in Chainloader.PluginInfos.Values
				where (Object)(object)((p != null) ? p.Instance : null) != (Object)null
				select ((object)p.Instance).GetType().Assembly).Distinct().ToList();
			int num = 0;
			int num2 = 0;
			List<string> list2 = new List<string>();
			foreach (Assembly item in list)
			{
				if (Excluded(item))
				{
					continue;
				}
				_modAssemblies.Add(item);
				Type[] array;
				try
				{
					array = item.GetTypes();
				}
				catch (ReflectionTypeLoadException ex)
				{
					array = ex.Types.Where((Type t) => t != null).ToArray();
				}
				int num3 = num;
				Type[] array2 = array;
				foreach (Type type in array2)
				{
					FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (FieldInfo fieldInfo in fields)
					{
						if (!fieldInfo.IsLiteral && !fieldInfo.IsInitOnly && IsUiType(fieldInfo.FieldType) && !type.IsGenericTypeDefinition)
						{
							_uiStatics.Add(fieldInfo);
						}
					}
					if (!typeof(MonoBehaviour).IsAssignableFrom(type) || type.IsGenericTypeDefinition || type.IsAbstract)
					{
						continue;
					}
					bool flag;
					try
					{
						flag = (bool)_usesLocal.Invoke(null, new object[1] { type });
					}
					catch
					{
						flag = false;
					}
					if (!flag)
					{
						continue;
					}
					num2++;
					_wrappedTypes.Add(type);
					MethodInfo[] methods = type.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					foreach (MethodInfo methodInfo in methods)
					{
						if (!methodInfo.IsAbstract && !methodInfo.ContainsGenericParameters && methodInfo.GetParameters().Length == 0 && Callbacks.Contains(methodInfo.Name))
						{
							try
							{
								h.Patch((MethodBase)methodInfo, _gate, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
								h.Patch((MethodBase)methodInfo, _pre, (HarmonyMethod)null, (HarmonyMethod)null, _fin, (HarmonyMethod)null);
								num++;
							}
							catch
							{
							}
						}
					}
					foreach (Type item2 in Nested(type))
					{
						FieldInfo field = item2.GetField("<>4__this", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						MethodInfo method = item2.GetMethod("MoveNext", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (method == null || !typeof(IEnumerator).IsAssignableFrom(item2) || item2.IsGenericTypeDefinition)
						{
							continue;
						}
						try
						{
							if (_iterSelf != null)
							{
								_iterSelf[item2] = field;
							}
							h.Patch((MethodBase)method, _preIter, (HarmonyMethod)null, (HarmonyMethod)null, _fin, (HarmonyMethod)null);
							num++;
						}
						catch
						{
						}
					}
				}
				if (num > num3)
				{
					list2.Add($"{item.GetName().Name} ({num - num3})");
				}
			}
			Plugin.Log.LogInfo((object)string.Format("Mod compat: {0} methods in {1} components now run per player: {2}. {3} HUD references get a copy per player.", num, num2, string.Join(", ", list2), _uiStatics.Count));
		}

		private static IEnumerable<Type> Nested(Type t)
		{
			Type[] nestedTypes = t.GetNestedTypes(BindingFlags.Public | BindingFlags.NonPublic);
			foreach (Type n in nestedTypes)
			{
				yield return n;
				foreach (Type item in Nested(n))
				{
					yield return item;
				}
			}
		}

		private static bool IsUiType(Type ft)
		{
			if (typeof(RectTransform).IsAssignableFrom(ft) || typeof(Canvas).IsAssignableFrom(ft) || typeof(CanvasGroup).IsAssignableFrom(ft) || typeof(GUIManager).IsAssignableFrom(ft))
			{
				return true;
			}
			string text = ft.Namespace ?? "";
			if (typeof(Component).IsAssignableFrom(ft))
			{
				if (!text.StartsWith("UnityEngine.UI"))
				{
					return text.StartsWith("TMPro");
				}
				return true;
			}
			return false;
		}

		private static bool Gate(Component __instance)
		{
			try
			{
				if (!SplitAccess.Active || _viewsReady == null || (bool)_viewsReady.GetValue(null))
				{
					return true;
				}
				return (int)_ownerOf.Invoke(null, new object[1] { __instance }) <= 1;
			}
			catch
			{
				return true;
			}
		}

		private static void Begin_Postfix()
		{
			_slotValues.Clear();
			if (_ctxAdd == null)
			{
				return;
			}
			foreach (FieldInfo f in _uiStatics)
			{
				object value;
				try
				{
					value = f.GetValue(null);
				}
				catch
				{
					continue;
				}
				object[] array = new object[5] { null, value, null, null, null };
				Func<object> func = () => f.GetValue(null);
				Action<object> action = delegate(object v)
				{
					f.SetValue(null, v);
				};
				try
				{
					_ctxAdd.Invoke(null, new object[6]
					{
						"mod:" + f.DeclaringType.Name + "." + f.Name,
						func,
						action,
						array,
						false,
						false
					});
					_slotValues.Add(array);
				}
				catch (Exception ex)
				{
					Plugin.Log.LogWarning((object)("Mod compat: couldn't split " + f.DeclaringType.Name + "." + f.Name + ": " + ex.Message));
				}
			}
			_fitted.Clear();
			Plugin.Log.LogInfo((object)$"Mod compat: {_slotValues.Count} HUD references split per player.");
		}

		private static void Views_Postfix()
		{
			foreach (object[] slotValue in _slotValues)
			{
				for (int i = 2; i < slotValue.Length; i++)
				{
					slotValue[i] = null;
				}
			}
		}

		internal static void FitModCanvases()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			if (!SplitAccess.Active || _hudTo == null || _viewsReady == null || !(bool)_viewsReady.GetValue(null))
			{
				return;
			}
			Camera[] cams = SplitAccess.Cams;
			Camera val = ((cams != null && cams.Length > 1) ? cams[1] : null);
			Canvas[] array = Object.FindObjectsByType<Canvas>((FindObjectsInactive)0, (FindObjectsSortMode)0);
			foreach (Canvas val2 in array)
			{
				if ((Object)(object)val2 == (Object)null || !val2.isRootCanvas || (int)val2.renderMode != 0)
				{
					continue;
				}
				int instanceID = ((Object)val2).GetInstanceID();
				if (_fitted.Contains(instanceID))
				{
					continue;
				}
				if ((Object)(object)((Component)val2).GetComponentInParent<GUIManager>(true) != (Object)null)
				{
					_fitted.Add(instanceID);
					continue;
				}
				bool num = ((Component)val2).GetComponentsInChildren<MonoBehaviour>(true).Any((MonoBehaviour m) => (Object)(object)m != (Object)null && _modAssemblies.Contains(((object)m).GetType().Assembly));
				_fitted.Add(instanceID);
				if (num && !((Object)(object)((Component)val2).transform.Find("SplitView") != (Object)null))
				{
					try
					{
						_hudTo.Invoke(null, new object[3]
						{
							((Component)val2).gameObject,
							1,
							val
						});
						Plugin.Log.LogInfo((object)("Mod compat: fitted '" + ((Object)val2).name + "' into player 1's screen."));
					}
					catch (Exception ex)
					{
						Plugin.Log.LogWarning((object)("Mod compat: couldn't fit '" + ((Object)val2).name + "': " + ex.Message));
					}
				}
			}
		}
	}
	internal static class Native
	{
		internal struct RECT
		{
			public int Left;

			public int Top;

			public int Right;

			public int Bottom;

			public int W => Right - Left;

			public int H => Bottom - Top;
		}

		[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Auto)]
		private struct MONITORINFO
		{
			public int cbSize;

			public RECT rcMonitor;

			public RECT rcWork;

			public uint dwFlags;
		}

		private delegate bool MonitorEnumProc(IntPtr hMonitor, IntPtr hdc, ref RECT rect, IntPtr data);

		private delegate bool EnumThreadProc(IntPtr hWnd, IntPtr data);

		internal sealed class Monitor
		{
			public RECT Rect;

			public bool Primary;
		}

		private const int GWL_STYLE = -16;

		private const long WS_POPUP = 2147483648L;

		private const long WS_VISIBLE = 268435456L;

		private const uint SWP_FRAMECHANGED = 32u;

		private const uint SWP_SHOWWINDOW = 64u;

		private const uint SWP_NOZORDER = 4u;

		private static readonly IntPtr PerMonitorV2 = new IntPtr(-4);

		internal static bool IsWindows => Environment.OSVersion.Platform == PlatformID.Win32NT;

		[DllImport("user32.dll")]
		private static extern bool EnumDisplayMonitors(IntPtr hdc, IntPtr clip, MonitorEnumProc cb, IntPtr data);

		[DllImport("user32.dll", CharSet = CharSet.Auto)]
		private static extern bool GetMonitorInfo(IntPtr hMonitor, ref MONITORINFO info);

		[DllImport("user32.dll")]
		private static extern IntPtr GetActiveWindow();

		[DllImport("user32.dll", EntryPoint = "GetWindowLongPtrW")]
		private static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int index);

		[DllImport("user32.dll", EntryPoint = "SetWindowLongPtrW")]
		private static extern IntPtr SetWindowLongPtr(IntPtr hWnd, int index, IntPtr value);

		[DllImport("user32.dll")]
		private static extern bool SetWindowPos(IntPtr hWnd, IntPtr after, int x, int y, int cx, int cy, uint flags);

		[DllImport("user32.dll")]
		private static extern bool GetWindowRect(IntPtr hWnd, out RECT rect);

		[DllImport("user32.dll")]
		private static extern IntPtr SetThreadDpiAwarenessContext(IntPtr ctx);

		[DllImport("kernel32.dll")]
		private static extern uint GetCurrentThreadId();

		[DllImport("user32.dll")]
		private static extern bool EnumThreadWindows(uint threadId, EnumThreadProc cb, IntPtr data);

		[DllImport("user32.dll")]
		private static extern bool IsWindowVisible(IntPtr hWnd);

		private static IntPtr WithDpi(Func<IntPtr> f)
		{
			IntPtr intPtr = IntPtr.Zero;
			try
			{
				intPtr = SetThreadDpiAwarenessContext(PerMonitorV2);
			}
			catch
			{
			}
			try
			{
				return f();
			}
			finally
			{
				try
				{
					if (intPtr != IntPtr.Zero)
					{
						SetThreadDpiAwarenessContext(intPtr);
					}
				}
				catch
				{
				}
			}
		}

		internal static List<Monitor> Monitors()
		{
			List<Monitor> list = new List<Monitor>();
			WithDpi(delegate
			{
				EnumDisplayMonitors(IntPtr.Zero, IntPtr.Zero, delegate(IntPtr h, IntPtr dc, ref RECT r, IntPtr d)
				{
					MONITORINFO info = new MONITORINFO
					{
						cbSize = Marshal.SizeOf<MONITORINFO>()
					};
					if (GetMonitorInfo(h, ref info))
					{
						list.Add(new Monitor
						{
							Rect = info.rcMonitor,
							Primary = ((info.dwFlags & 1) != 0)
						});
					}
					return true;
				}, IntPtr.Zero);
				return IntPtr.Zero;
			});
			return list;
		}

		internal static IntPtr GameWindow()
		{
			IntPtr found = GetActiveWindow();
			if (found != IntPtr.Zero)
			{
				return found;
			}
			EnumThreadWindows(GetCurrentThreadId(), delegate(IntPtr h, IntPtr d)
			{
				if (IsWindowVisible(h))
				{
					found = h;
					return false;
				}
				return true;
			}, IntPtr.Zero);
			return found;
		}

		internal static long GetStyle(IntPtr w)
		{
			return GetWindowLongPtr(w, -16).ToInt64();
		}

		internal static RECT GetRect(IntPtr w)
		{
			RECT r = default(RECT);
			WithDpi(delegate
			{
				GetWindowRect(w, out r);
				return IntPtr.Zero;
			});
			return r;
		}

		internal static void Cover(IntPtr w, RECT area)
		{
			SetWindowLongPtr(w, -16, new IntPtr(2415919104L));
			WithDpi(delegate
			{
				SetWindowPos(w, IntPtr.Zero, area.Left, area.Top, area.W, area.H, 100u);
				return IntPtr.Zero;
			});
		}

		internal static void Restore(IntPtr w, long style, RECT rect)
		{
			SetWindowLongPtr(w, -16, new IntPtr(style));
			WithDpi(delegate
			{
				SetWindowPos(w, IntPtr.Zero, rect.Left, rect.Top, rect.W, rect.H, 100u);
				return IntPtr.Zero;
			});
		}
	}
	internal static class Online
	{
		private static Type _split;

		private static Type _ctx;

		private static FieldInfo _requested;

		private static FieldInfo _count;

		private static FieldInfo _pads;

		private static FieldInfo _players;

		private static FieldInfo _actions;

		private static FieldInfo _actor;

		private static FieldInfo _splitActive;

		private static FieldInfo _ctxCur;

		private static MethodInfo _pin;

		private static MethodInfo _findSpawner;

		private static MethodInfo _ctxBegin;

		private static MethodInfo _ctxEnter;

		private static MethodInfo _stop;

		private static MethodInfo _seatOf;

		private static bool _active;

		private static bool _starting;

		private static Player _host;

		private static readonly List<int> _guestActors = new List<int>();

		private static string _error;

		private static float _errorUntil;

		internal static bool Active => _active;

		internal static bool InOnlineRoom
		{
			get
			{
				if (PhotonNetwork.InRoom)
				{
					return !PhotonNetwork.OfflineMode;
				}
				return false;
			}
		}

		internal static string Status
		{
			get
			{
				if (!_starting)
				{
					if (!(Time.unscaledTime < _errorUntil))
					{
						return null;
					}
					return _error;
				}
				return "Adding split-screen players...";
			}
		}

		private static int Cur => (int)_ctxCur.GetValue(null);

		internal static void Patch(Harmony h)
		{
			_split = SplitAccess.Split;
			_ctx = AccessTools.TypeByName("PeakSplitScreen.Ctx");
			_requested = AccessTools.Field(_split, "requested");
			_count = AccessTools.Field(_split, "Count");
			_pads = AccessTools.Field(_split, "pads");
			_players = AccessTools.Field(_split, "players");
			_actions = AccessTools.Field(_split, "actions");
			_actor = AccessTools.Field(_split, "Actor");
			_splitActive = AccessTools.Field(_split, "Active");
			_pin = AccessTools.Method(_split, "PinPlayer1", (Type[])null, (Type[])null);
			_findSpawner = AccessTools.Method(_split, "FindSpawner", (Type[])null, (Type[])null);
			_stop = AccessTools.Method(_split, "Stop", (Type[])null, (Type[])null);
			_seatOf = AccessTools.Method(_split, "SeatOf", (Type[])null, (Type[])null);
			_ctxCur = AccessTools.Field(_ctx, "Cur");
			_ctxBegin = AccessTools.Method(_ctx, "Begin", (Type[])null, (Type[])null);
			_ctxEnter = AccessTools.Method(_ctx, "Enter", (Type[])null, (Type[])null);
			if (new object[14]
			{
				_requested, _count, _pads, _players, _actions, _actor, _splitActive, _pin, _findSpawner, _stop,
				_seatOf, _ctxCur, _ctxBegin, _ctxEnter
			}.Any((object x) => x == null))
			{
				Plugin.Log.LogWarning((object)"Online split screen: couldn't find what it needs in the split mod (different version?) - online is off.");
				_split = null;
				return;
			}
			P(h, AccessTools.Method(_split, "Begin", (Type[])null, (Type[])null), "Begin_Prefix");
			P(h, _stop, "Stop_Prefix", "Stop_Postfix");
			P(h, AccessTools.Method(SplitAccess.Runner, "Launch", (Type[])null, (Type[])null), "Launch_Prefix");
			P(h, AccessTools.Method(typeof(PhotonNetwork), "RPC", new Type[6]
			{
				typeof(PhotonView),
				typeof(string),
				typeof(RpcTarget),
				typeof(Player),
				typeof(bool),
				typeof(object[])
			}, (Type[])null), "Rpc_Prefix", null, first: true);
			P(h, AccessTools.Method(AccessTools.TypeByName("PeakSplitScreen.Net"), "PreMasterClient", (Type[])null, (Type[])null), "PreMasterClient_Prefix");
			P(h, AccessTools.Method(typeof(Player), "AssignUserID", (Type[])null, (Type[])null), "AssignUserID_Prefix", null, first: false, last: true);
			P(h, AccessTools.Method(typeof(Player), "SetCustomProperties", (Type[])null, (Type[])null), "SetProps_Prefix");
			Guests.IsOwnGuest = (int a) => _active && _guestActors.Contains(a);
			Guests.RunForOwnGuest = RunForGuest;
		}

		private static void P(Harmony h, MethodBase m, string pre = null, string post = null, bool first = false, bool last = false)
		{
			if (m == null)
			{
				Plugin.Log.LogWarning((object)("Online split screen: missing hook for " + (pre ?? post)));
			}
			else
			{
				h.Patch(m, Hm(pre), Hm(post), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
			HarmonyMethod Hm(string n)
			{
				//IL_0011: Unknown result type (might be due to invalid IL or missing references)
				//IL_0017: Expected O, but got Unknown
				if (n == null)
				{
					return null;
				}
				HarmonyMethod val = new HarmonyMethod(typeof(Online), n, (Type[])null);
				if (first)
				{
					val.priority = 800;
				}
				if (last)
				{
					val.priority = 0;
				}
				return val;
			}
		}

		private static T S<T>(FieldInfo f)
		{
			return (T)f.GetValue(null);
		}

		private static void Enter(int seat)
		{
			_ctxEnter.Invoke(null, new object[1] { seat });
		}

		private static int SeatOf(int actor)
		{
			return (int)_seatOf.Invoke(null, new object[1] { actor });
		}

		internal static string CantAddReason()
		{
			if (_split == null)
			{
				return "online split screen isn't available with this version of the split mod";
			}
			if (!InOnlineRoom)
			{
				return null;
			}
			if (SplitAccess.Active)
			{
				return "split screen is already on";
			}
			if ((Object)(object)Character.localCharacter == (Object)null)
			{
				return "wait until you've spawned in";
			}
			return null;
		}

		internal static void OpenSetup()
		{
			string text = CantAddReason();
			if (text != null)
			{
				ShowError("Can't add split-screen players: " + text);
				return;
			}
			object value = Traverse.Create(SplitAccess.Runner).Field("I").GetValue();
			if (value != null)
			{
				AccessTools.Method(SplitAccess.Runner, "BeginSetup", (Type[])null, (Type[])null).Invoke(value, new object[1]);
				Plugin.Log.LogInfo((object)"Online: setup screen opened to add players to this game.");
			}
		}

		internal static void ShowError(string msg)
		{
			_error = msg;
			_errorUntil = Time.unscaledTime + 7f;
			Plugin.Log.LogWarning((object)msg);
		}

		private static bool Launch_Prefix(object __instance)
		{
			if (!InOnlineRoom || _split == null)
			{
				return true;
			}
			try
			{
				List<Gamepad> value = Traverse.Create(__instance).Field("joined").GetValue<List<Gamepad>>();
				bool value2 = Traverse.Create(__instance).Field("vertical").GetValue<bool>();
				AccessTools.Method(SplitAccess.Runner, "Close", (Type[])null, (Type[])null).Invoke(__instance, null);
				AccessTools.Method(_split, "Request", (Type[])null, (Type[])null).Invoke(null, new object[2]
				{
					value.ToList(),
					value2
				});
				_requested.SetValue(null, false);
				_starting = true;
				AccessTools.Method(_split, "Begin", (Type[])null, (Type[])null).Invoke(null, null);
			}
			catch (Exception ex)
			{
				ShowError("Online split screen failed to start: " + (ex.InnerException?.Message ?? ex.Message));
			}
			finally
			{
				_starting = false;
			}
			return false;
		}

		private static int GuestActor(int hostActor, int seat)
		{
			return 200 + hostActor * 4 + seat;
		}

		private static bool Begin_Prefix()
		{
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b8: Expected O, but got Unknown
			//IL_02b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cc: Expected O, but got Unknown
			//IL_02cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e2: Expected O, but got Unknown
			//IL_02e9: Expected O, but got Unknown
			if (!InOnlineRoom)
			{
				return true;
			}
			int num = S<int>(_count);
			int[] actor = S<int[]>(_actor);
			Gamepad[] array = S<Gamepad[]>(_pads);
			Player[] array2 = S<Player[]>(_players);
			InputActionAsset[] array3 = S<InputActionAsset[]>(_actions);
			Room currentRoom = PhotonNetwork.CurrentRoom;
			_host = PhotonNetwork.LocalPlayer;
			ConstructorInfo constructorInfo = AccessTools.Constructor(typeof(Player), new Type[3]
			{
				typeof(string),
				typeof(int),
				typeof(bool)
			}, false);
			MethodInfo methodInfo = AccessTools.PropertySetter(typeof(Player), "UserId");
			actor[1] = _host.ActorNumber;
			_guestActors.Clear();
			List<string> names = new List<string>();
			for (int i = 2; i <= num; i++)
			{
				array3[i] = Object.Instantiate<InputActionAsset>(InputSystem.actions);
				array3[i].devices = ReadOnlyArray<InputDevice>.op_Implicit((InputDevice[])(object)new InputDevice[1] { (InputDevice)array[i] });
				array3[i].Enable();
				actor[i] = GuestActor(_host.ActorNumber, i);
				string text = Plugin.NameFor(i);
				if (string.IsNullOrWhiteSpace(text) || text.Trim() == $"Player {i}")
				{
					text = $"{_host.NickName} ({i})";
				}
				array2[i] = (Player)constructorInfo.Invoke(new object[3]
				{
					text,
					actor[i],
					false
				});
				methodInfo.Invoke(array2[i], new object[1] { $"splitguest-{_host.UserId}-{actor[i]}" });
				_guestActors.Add(actor[i]);
				names.Add(text);
			}
			_active = true;
			_pin.Invoke(null, null);
			_ctxBegin.Invoke(null, new object[3] { num, array2, array3 });
			_splitActive.SetValue(null, true);
			_findSpawner.Invoke(null, null);
			for (int j = 2; j <= num; j++)
			{
				currentRoom.AddPlayer(array2[j]);
				Player p = array2[j];
				Guests.Each(delegate(IInRoomCallbacks cb)
				{
					cb.OnPlayerEnteredRoom(p);
				});
			}
			Player host = _host;
			Hashtable val = new Hashtable();
			((Dictionary<object, object>)val).Add((object)"SSPg", (object)_guestActors.ToArray());
			((Dictionary<object, object>)val).Add((object)"SSPn", (object)names.ToArray());
			host.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
			Plugin.Log.LogInfo((object)($"Online split screen started: {num} players on this PC (" + string.Join(", ", from k in Enumerable.Range(1, num)
				select $"player {k} = {((k == 1) ? _host.NickName : names[k - 2])} #{actor[k]}") + "). Friends need Split Screen Plus to see the extra players."));
			return false;
		}

		private static void Stop_Prefix()
		{
			if (!_active)
			{
				return;
			}
			int cur = Cur;
			try
			{
				Enter(1);
				PhotonView[] array = Object.FindObjectsByType<PhotonView>((FindObjectsSortMode)0);
				foreach (PhotonView val in array)
				{
					if ((Object)(object)val != (Object)null && val.IsMine && _guestActors.Contains(val.OwnerActorNr) && val.isRuntimeInstantiated && InOnlineRoom)
					{
						PhotonNetwork.Destroy(((Component)val).gameObject);
					}
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Online: removing guests' objects: " + ex.Message));
			}
			finally
			{
				if (Cur != cur)
				{
					Enter(cur);
				}
			}
		}

		private static void Stop_Postfix()
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			//IL_0047: Expected O, but got Unknown
			if (!_active)
			{
				return;
			}
			_active = false;
			_guestActors.Clear();
			try
			{
				if (InOnlineRoom && _host != null)
				{
					Player host = _host;
					Hashtable val = new Hashtable();
					((Dictionary<object, object>)val).Add((object)"SSPg", (object)Array.Empty<int>());
					host.SetCustomProperties(val, (Hashtable)null, (WebFlags)null);
				}
			}
			catch
			{
			}
			Plugin.Log.LogInfo((object)"Online split screen stopped.");
		}

		private static void RunForGuest(int guest, EventData ev)
		{
			int num = SeatOf(guest);
			if (num < 2)
			{
				return;
			}
			int cur = Cur;
			try
			{
				Enter(num);
				Guests.Dispatch(PhotonNetwork.NetworkingClient, ev);
			}
			finally
			{
				if (Cur != cur)
				{
					Enter(cur);
				}
			}
		}

		private unsafe static bool SetProps_Prefix(Player __instance, Hashtable propertiesToSet, ref bool __result)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Expected O, but got Unknown
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Expected O, but got Unknown
			//IL_00ee: Expected O, but got Unknown
			if (!_active || __instance == null || !_guestActors.Contains(__instance.ActorNumber) || propertiesToSet == null)
			{
				return true;
			}
			try
			{
				AccessTools.Method(typeof(Player), "InternalCacheProperties", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { propertiesToSet });
				Player p = __instance;
				Hashtable changed = propertiesToSet;
				Guests.Each(delegate(IInRoomCallbacks cb)
				{
					cb.OnPlayerPropertiesUpdate(p, changed);
				});
				Hashtable val = new Hashtable();
				DictionaryEntryEnumerator enumerator = __instance.CustomProperties.GetEnumerator();
				try
				{
					while (((DictionaryEntryEnumerator)(ref enumerator)).MoveNext())
					{
						DictionaryEntry current = ((DictionaryEntryEnumerator)(ref enumerator)).Current;
						val[current.Key] = current.Value;
					}
				}
				finally
				{
					((IDisposable)(*(DictionaryEntryEnumerator*)(&enumerator))/*cast due to .constrained prefix*/).Dispose();
				}
				Player host = _host;
				if (host != null)
				{
					Hashtable val2 = new Hashtable();
					((Dictionary<object, object>)val2).Add((object)("SSPp" + __instance.ActorNumber), (object)val);
					host.SetCustomProperties(val2, (Hashtable)null, (WebFlags)null);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Online: guest details: " + ex.Message));
			}
			__result = true;
			return false;
		}

		private static bool PreMasterClient_Prefix(ref bool __result)
		{
			if (!InOnlineRoom)
			{
				return true;
			}
			__result = true;
			return false;
		}

		private static void AssignUserID_Prefix(ref ulong userID)
		{
			if (_active && userID >= 900000002 && userID <= 900000004)
			{
				int num = (int)(userID - 900000000);
				int[] array = S<int[]>(_actor);
				if (num < array.Length)
				{
					userID = (ulong)(900000000000L + array[num]);
				}
			}
		}

		private static void Rpc_Prefix(ref RpcTarget target)
		{
			if (_active && Cur >= 2)
			{
				if ((int)target == 5)
				{
					target = (RpcTarget)0;
				}
				else if ((int)target == 6)
				{
					target = (RpcTarget)3;
				}
			}
		}

		internal static void Tick()
		{
		}

		internal static void OnGUI()
		{
			//IL_0024: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			string status = Status;
			if (status != null)
			{
				int num = Mathf.Max(16, Screen.height / 40);
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					alignment = (TextAnchor)4,
					wordWrap = true,
					fontSize = num
				};
				Rect val2 = new Rect((float)Screen.width * 0.2f, (float)Screen.height * 0.12f, (float)Screen.width * 0.6f, (float)num * 3.4f);
				GUI.color = new Color(0f, 0f, 0f, 0.8f);
				GUI.DrawTexture(val2, (Texture)(object)Texture2D.whiteTexture);
				GUI.color = Color.white;
				GUI.Label(val2, status, val);
			}
		}
	}
	internal static class PauseButton
	{
		private const string Name = "SplitScreenPlus_AddPlayers";

		internal static void Patch(Harmony h)
		{
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			MethodInfo methodInfo = AccessTools.Method(typeof(PauseMenuMainPage), "OnEnable", (Type[])null, (Type[])null);
			if (methodInfo != null)
			{
				h.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(PauseButton), "OnEnable_Postfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}

		private static void OnEnable_Postfix(PauseMenuMainPage __instance)
		{
			try
			{
				Button value = Traverse.Create((object)__instance).Field("m_inviteButton").GetValue<Button>();
				if (!((Object)(object)value == (Object)null))
				{
					Transform val = ((Component)value).transform.parent.Find("SplitScreenPlus_AddPlayers");
					GameObject obj = (Object.op_Implicit((Object)(object)val) ? ((Component)val).gameObject : Build(__instance, value));
					bool active = Online.InOnlineRoom && !SplitAccess.Active && PhotonNetwork.CurrentRoom != null && PhotonNetwork.CurrentRoom.IsOpen;
					obj.SetActive(active);
				}
			}
			catch (Exception ex)
			{
				Plugin.Log.LogWarning((object)("Pause menu button: " + ex.Message));
			}
		}

		private static GameObject Build(PauseMenuMainPage page, Button invite)
		{
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Expected O, but got Unknown
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Expected O, but got Unknown
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)invite).gameObject, ((Component)invite).transform.parent);
			((Object)val).name = "SplitScreenPlus_AddPlayers";
			val.transform.SetSiblingIndex(((Component)invite).transform.GetSiblingIndex() + 1);
			MonoBehaviour[] componentsInChildren = val.GetComponentsInChildren<MonoBehaviour>(true);
			foreach (MonoBehaviour val2 in componentsInChildren)
			{
				if ((Object)(object)val2 != (Object)null && ((object)val2).GetType().Name.StartsWith("Locali"))
				{
					Object.DestroyImmediate((Object)(object)val2);
				}
			}
			TMP_Text[] componentsInChildren2 = val.GetComponentsInChildren<TMP_Text>(true);
			for (int i = 0; i < componentsInChildren2.Length; i++)
			{
				componentsInChildren2[i].text = "ADD SPLIT-SCREEN PLAYERS";
			}
			if ((Object)(object)((Component)((Component)invite).transform.parent).GetComponent<LayoutGroup>() == (Object)null)
			{
				Transform transform = val.transform;
				RectTransform val3 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
				if (val3 != null)
				{
					Transform transform2 = ((Component)invite).transform;
					RectTransform val4 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
					if (val4 != null)
					{
						Vector2 anchoredPosition = val4.anchoredPosition;
						Rect rect = val4.rect;
						val3.anchoredPosition = anchoredPosition - new Vector2(0f, ((Rect)(ref rect)).height * 1.15f);
					}
				}
			}
			Button component = val.GetComponent<Button>();
			component.onClick = new ButtonClickedEvent();
			((UnityEvent)component.onClick).AddListener((UnityAction)delegate
			{
				try
				{
					AccessTools.Method(typeof(PauseMenuMainPage), "OnResumeClicked", (Type[])null, (Type[])null)?.Invoke(page, null);
				}
				catch
				{
				}
				Online.OpenSetup();
			});
			return val;
		}
	}
	[BepInPlugin("com.wolfb.peak.splitscreenplus", "Split Screen Plus", "0.7.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "com.wolfb.peak.splitscreenplus";

		public const string Name = "Split Screen Plus";

		public const string Version = "0.7.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<bool> KeyboardPlayer1;

		internal static ConfigEntry<bool> TwoMonitors;

		internal static ConfigEntry<string> TwoMonitorKey;

		internal static ConfigEntry<string> AddPlayersKey;

		internal static ConfigEntry<bool> CompatOn;

		internal static ConfigEntry<string> CompatSkip;

		internal static Harmony H;

		private static readonly ConfigEntry<string>[] _names = new ConfigEntry<string>[5];

		internal static string NameFor(int seat)
		{
			if (seat < 2 || seat > 4 || _names[seat] == null)
			{
				return "";
			}
			return _names[seat].Value;
		}

		internal static void SetName(int seat, string v)
		{
			if (seat >= 2 && seat <= 4 && _names[seat] != null)
			{
				_names[seat].Value = (v ?? "").Trim();
			}
		}

		private void Awake()
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_013b: Expected O, but got Unknown
			//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d0: Expected O, but got Unknown
			//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			KeyboardPlayer1 = ((BaseUnityPlugin)this).Config.Bind<bool>("Keyboard and Mouse", "Enabled", true, "On the split-screen join screen, press Space to join as player 1 wi