Decompiled source of VirtualBooth v0.0.2

BepInEx/plugins/VirtualBooth.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameEvent;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.Networking;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
using VirtualBooth;
using VirtualOutfitBooth;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VirtualOutfitBooth
{
	public class VirtualOutfitBooth : MonoBehaviour
	{
		[HarmonyPatch(typeof(OutfitController), "ReceiveEvent")]
		public static class OutfitControllerInputPatch
		{
			public static bool Prefix(OutfitController __instance, InputEvent e)
			{
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_003a: Invalid comparison between Unknown and I4
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005e: Invalid comparison between Unknown and I4
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0094: Invalid comparison between Unknown and I4
				//IL_0097: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Invalid comparison between Unknown and I4
				if ((Object)(object)Instance != (Object)null && Instance.IsBoothActive)
				{
					if (Instance._gracePeriodTimer > 0f)
					{
						return false;
					}
					if ((int)e.Key == 9 && e.Changed)
					{
						e.Consume();
						Instance.DeactivateBoothWithAbort();
						return false;
					}
					if ((int)e.Key == 21 && e.Changed && (Object)(object)__instance == (Object)(object)Instance.ActiveOutfitController)
					{
						e.Consume();
						Instance.DeactivateBooth();
						return false;
					}
					if (((int)e.Key == 22 || (int)e.Key == 19) && e.Changed && (Object)(object)__instance == (Object)(object)Instance.ActiveOutfitController)
					{
						e.Consume();
						Instance.DeactivateBoothWithAbort();
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(OutfitController), "Release")]
		public static class OutfitControllerReleasePatch
		{
			public static void Postfix(OutfitController __instance)
			{
				if ((Object)(object)Instance != (Object)null && Instance.IsBoothActive && (Object)(object)__instance == (Object)(object)Instance.ActiveOutfitController)
				{
					Instance.DeactivateBooth();
				}
			}
		}

		[HarmonyPatch(typeof(ZoomCamera), "GetFrame")]
		public static class ZoomCameraGetFramePatch
		{
			public static bool Prefix(ZoomCamera __instance, ref Bounds __result)
			{
				//IL_0034: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_005f: 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_007b: 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)
				//IL_0093: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00e5: 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_0145: Unknown result type (might be due to invalid IL or missing references)
				//IL_011d: Unknown result type (might be due to invalid IL or missing references)
				//IL_016c: Unknown result type (might be due to invalid IL or missing references)
				//IL_017d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0155: Unknown result type (might be due to invalid IL or missing references)
				//IL_018d: Unknown result type (might be due to invalid IL or missing references)
				if ((Object)(object)Instance != (Object)null && Instance._isBoothActive && (Object)(object)Instance._localCharacter != (Object)null)
				{
					Scene activeScene = SceneManager.GetActiveScene();
					if (((Scene)(ref activeScene)).name == "TreeHouseLobby")
					{
						Vector3 position = ((Component)Instance._localCharacter).transform.position;
						float num = 11f;
						float num2 = num * __instance.useCamera.aspect;
						Vector3 val = default(Vector3);
						((Vector3)(ref val))..ctor(position.x, position.y + 1f, ((Component)__instance).transform.position.z);
						Bounds bounds = __instance.GetBounds();
						Vector3 size = ((Bounds)(ref bounds)).size;
						if (((Vector3)(ref size)).sqrMagnitude > 0f)
						{
							if (val.x - num2 / 2f < ((Bounds)(ref bounds)).min.x)
							{
								val.x = ((Bounds)(ref bounds)).min.x + num2 / 2f;
							}
							if (val.x + num2 / 2f > ((Bounds)(ref bounds)).max.x)
							{
								val.x = ((Bounds)(ref bounds)).max.x - num2 / 2f;
							}
							if (val.y - num / 2f < ((Bounds)(ref bounds)).min.y)
							{
								val.y = ((Bounds)(ref bounds)).min.y + num / 2f;
							}
							if (val.y + num / 2f > ((Bounds)(ref bounds)).max.y)
							{
								val.y = ((Bounds)(ref bounds)).max.y - num / 2f;
							}
						}
						__result = new Bounds(val, new Vector3(num2, num, 0f));
						return false;
					}
				}
				return true;
			}
		}

		[HarmonyPatch(typeof(LobbyPlayer), "ReceiveEvent")]
		public static class LobbyPlayerReceiveEventPatch
		{
			public static bool Prefix(LobbyPlayer __instance, InputEvent e)
			{
				//IL_001a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0021: Invalid comparison between Unknown and I4
				if ((Object)(object)Instance != (Object)null && Instance.IsBoothActive && (int)e.Key == 9 && e.Changed && e.Valueb)
				{
					return false;
				}
				return true;
			}
		}

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

			private object <>2__current;

			public VirtualOutfitBooth <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_002f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Expected O, but got Unknown
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009c: Expected O, but got Unknown
				//IL_0069: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Expected O, but got Unknown
				int num = <>1__state;
				VirtualOutfitBooth virtualOutfitBooth = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForSecondsRealtime(0.6f);
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)virtualOutfitBooth._activeOutfitController != (Object)null && (Object)(object)virtualOutfitBooth._suppressedController != (Object)null)
					{
						InputEvent val2 = new InputEvent(1, (InputKey)2, true, true);
						virtualOutfitBooth._activeOutfitController.ReceiveEvent(val2);
						<>2__current = null;
						<>1__state = 2;
						return true;
					}
					break;
				case 2:
				{
					<>1__state = -1;
					InputEvent val = new InputEvent(1, (InputKey)3, true, true);
					virtualOutfitBooth._activeOutfitController.ReceiveEvent(val);
					break;
				}
				}
				return false;
			}

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

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

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

			private object <>2__current;

			public VirtualOutfitBooth <>4__this;

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

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

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

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

			private bool MoveNext()
			{
				//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
				//IL_0151: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: Expected O, but got Unknown
				int num = <>1__state;
				VirtualOutfitBooth virtualOutfitBooth = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = null;
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					if ((Object)(object)virtualOutfitBooth._localLobbyPlayer != (Object)null && (Object)(object)virtualOutfitBooth._hijackedLevelSelect != (Object)null)
					{
						InventoryBook gameRuleBook = virtualOutfitBooth._hijackedLevelSelect.GameRuleBook;
						if ((Object)(object)virtualOutfitBooth._suppressedController != (Object)null)
						{
							virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)virtualOutfitBooth._hijackedLevelSelect);
						}
						if ((Object)(object)gameRuleBook != (Object)null && (Object)(object)virtualOutfitBooth._suppressedController != (Object)null)
						{
							PickCursor cursor = gameRuleBook.GetCursor(virtualOutfitBooth._localLobbyPlayer.networkNumber);
							if ((Object)(object)cursor == (Object)null)
							{
								cursor = gameRuleBook.AddPlayer(virtualOutfitBooth._localLobbyPlayer.localNumber, virtualOutfitBooth._localLobbyPlayer.networkNumber, virtualOutfitBooth._suppressedController, virtualOutfitBooth._localLobbyPlayer.PickedAnimal);
							}
							else
							{
								virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)cursor);
							}
						}
						if ((Object)(object)virtualOutfitBooth._suppressedController != (Object)null && (Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
						{
							virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)virtualOutfitBooth._localCharacter);
						}
						if ((Object)(object)gameRuleBook != (Object)null)
						{
							gameRuleBook.Show(false);
							gameRuleBook.GotoPage(true, (PageTypes)30, false, false);
						}
						if (LobbyManager.instance.IsInOnlineGame)
						{
							GameEventManager.SendEvent((GameEvent)new PlayerInGameRuleEvent(true, virtualOutfitBooth._localLobbyPlayer.networkNumber, false));
						}
						else
						{
							Plugin.Logger.LogInfo((object)"[VirtualOutfitBooth] Local Deactivation: Manually restored menu.");
							gameRuleBook.ShowCursor(virtualOutfitBooth._localLobbyPlayer.networkNumber);
							((MonoBehaviour)virtualOutfitBooth).StartCoroutine(virtualOutfitBooth.WatchForMenuClose(gameRuleBook));
						}
					}
					else
					{
						Plugin.Logger.LogError((object)"[VirtualOutfitBooth] Cannot restore menu - missing LobbyPlayer or LevelSelect!");
					}
					virtualOutfitBooth._suppressedController = null;
					virtualOutfitBooth._hijackedLevelSelect = null;
					virtualOutfitBooth._frozenCharacter = null;
					return false;
				}
			}

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

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

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

			private object <>2__current;

			public VirtualOutfitBooth <>4__this;

			private InventoryBook <inventoryBook>5__2;

			private float <timeout>5__3;

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

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

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

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

			private bool MoveNext()
			{
				//IL_0259: Unknown result type (might be due to invalid IL or missing references)
				int num = <>1__state;
				VirtualOutfitBooth virtualOutfitBooth = <>4__this;
				if (num != 0)
				{
					if (num != 1)
					{
						return false;
					}
					<>1__state = -1;
				}
				else
				{
					<>1__state = -1;
					<inventoryBook>5__2 = Object.FindObjectOfType<InventoryBook>();
					if (!((Object)(object)<inventoryBook>5__2 != (Object)null) || !<inventoryBook>5__2.Visible)
					{
						goto IL_0104;
					}
					virtualOutfitBooth.InjectInput((InputKey)22);
					<timeout>5__3 = 1f;
				}
				if (<inventoryBook>5__2.Visible && <timeout>5__3 > 0f)
				{
					<timeout>5__3 -= Time.unscaledDeltaTime;
					if ((Object)(object)virtualOutfitBooth._frozenCharacter != (Object)null)
					{
						virtualOutfitBooth._frozenCharacter.Freeze(false, false, false);
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				if (<inventoryBook>5__2.Visible)
				{
					Plugin.Logger.LogWarning((object)"Input close failed, forcing Hide()");
					<inventoryBook>5__2.Hide();
				}
				if ((Object)(object)virtualOutfitBooth._frozenCharacter != (Object)null)
				{
					virtualOutfitBooth._frozenCharacter.Freeze(false, false, false);
				}
				goto IL_0104;
				IL_0104:
				if ((Object)(object)LobbyManager.instance != (Object)null)
				{
					virtualOutfitBooth._hijackedLevelSelect = LobbyManager.instance.CurrentLevelSelectController;
					if (virtualOutfitBooth._localLobbyPlayer.LocalPlayer != null)
					{
						virtualOutfitBooth._suppressedController = virtualOutfitBooth._localLobbyPlayer.LocalPlayer.UseController;
					}
					if ((Object)(object)virtualOutfitBooth._suppressedController != (Object)null)
					{
						if ((Object)(object)virtualOutfitBooth._hijackedLevelSelect != (Object)null)
						{
							virtualOutfitBooth._suppressedController.RemoveReceiver((InputReceiver)(object)virtualOutfitBooth._hijackedLevelSelect);
						}
						if ((Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
						{
							virtualOutfitBooth._suppressedController.RemoveReceiver((InputReceiver)(object)virtualOutfitBooth._localCharacter);
						}
					}
				}
				OutfitChangeProp val = Object.FindObjectOfType<OutfitChangeProp>();
				if ((Object)(object)val != (Object)null)
				{
					if (OutfitChangeProp.OutfitControllers.ContainsKey(virtualOutfitBooth._localCharacter))
					{
						virtualOutfitBooth._activeOutfitController = OutfitChangeProp.OutfitControllers[virtualOutfitBooth._localCharacter];
					}
					else
					{
						virtualOutfitBooth._activeOutfitController = Object.Instantiate<OutfitController>(val.outfitControllerPrefab);
						OutfitChangeProp.OutfitControllers.Add(virtualOutfitBooth._localCharacter, virtualOutfitBooth._activeOutfitController);
						virtualOutfitBooth._activeOutfitController.OutfitManager = val.OutfitManager;
					}
					if ((Object)(object)virtualOutfitBooth._activeOutfitController != (Object)null)
					{
						virtualOutfitBooth._activeOutfitController.outfitChangeProp = val;
						virtualOutfitBooth._activeOutfitController.player = virtualOutfitBooth._localLobbyPlayer;
						virtualOutfitBooth._activeOutfitController.characterUsing = virtualOutfitBooth._localCharacter;
						((Component)virtualOutfitBooth._activeOutfitController).transform.position = ((Component)virtualOutfitBooth._localCharacter).transform.position;
						virtualOutfitBooth._activeOutfitController.UseController = virtualOutfitBooth._suppressedController;
						virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)virtualOutfitBooth._activeOutfitController);
						virtualOutfitBooth._activeOutfitController.Show();
						((MonoBehaviour)virtualOutfitBooth).StartCoroutine(virtualOutfitBooth.RefreshOutfitDisplay());
					}
				}
				return false;
			}

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

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

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

			private object <>2__current;

			public InventoryBook book;

			public VirtualOutfitBooth <>4__this;

			private float <timeout>5__2;

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

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

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

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

			private bool MoveNext()
			{
				int num = <>1__state;
				VirtualOutfitBooth virtualOutfitBooth = <>4__this;
				switch (num)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					Plugin.Logger.LogInfo((object)$"[VirtualOutfitBooth] WatchForMenuClose Started. Book Visible: {book.Visible}");
					<timeout>5__2 = 1f;
					goto IL_0083;
				case 1:
					<>1__state = -1;
					goto IL_0083;
				case 2:
					{
						<>1__state = -1;
						break;
					}
					IL_0083:
					if ((Object)(object)book != (Object)null && !book.Visible && <timeout>5__2 > 0f)
					{
						<timeout>5__2 -= Time.unscaledDeltaTime;
						<>2__current = null;
						<>1__state = 1;
						return true;
					}
					if ((Object)(object)book == (Object)null || !book.Visible)
					{
						Plugin.Logger.LogWarning((object)"[VirtualOutfitBooth] Menu never became visible during open watch.");
						if ((Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
						{
							virtualOutfitBooth._localCharacter.Freeze(false, false, false);
							virtualOutfitBooth._localCharacter.InMenu = false;
						}
						virtualOutfitBooth._frozenCharacter = null;
						return false;
					}
					if ((Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
					{
						virtualOutfitBooth._localCharacter.Freeze(false, false, false);
						virtualOutfitBooth._localCharacter.InMenu = true;
						Plugin.Logger.LogInfo((object)"[VirtualOutfitBooth] Menu Open. Set InMenu=true, Cleared Hard Freeze.");
					}
					break;
				}
				if ((Object)(object)book != (Object)null && book.Visible)
				{
					<>2__current = null;
					<>1__state = 2;
					return true;
				}
				Plugin.Logger.LogInfo((object)"[VirtualOutfitBooth] Menu closed detected via Coroutine.");
				if ((Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
				{
					virtualOutfitBooth._localCharacter.InMenu = false;
				}
				virtualOutfitBooth._frozenCharacter = null;
				return false;
			}

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

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

		private const float GRACE_PERIOD = 0.5f;

		private bool _isBoothActive;

		private float _gracePeriodTimer;

		private OutfitController _activeOutfitController;

		private LevelSelectController _hijackedLevelSelect;

		private Controller _suppressedController;

		private Character _frozenCharacter;

		private LobbyPlayer _localLobbyPlayer;

		private Character _localCharacter;

		private int[] _savedOutfitArray;

		public static VirtualOutfitBooth Instance { get; private set; }

		public bool IsBoothActive => _isBoothActive;

		public OutfitController ActiveOutfitController => _activeOutfitController;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			else
			{
				Object.Destroy((Object)(object)this);
			}
		}

		private void Update()
		{
			if (_gracePeriodTimer > 0f)
			{
				_gracePeriodTimer -= Time.deltaTime;
			}
		}

		public void ActivateBooth()
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			if (_isBoothActive)
			{
				return;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "TreeHouseLobby")
			{
				return;
			}
			_localLobbyPlayer = GetLocalLobbyPlayer();
			if (!((Object)(object)_localLobbyPlayer == (Object)null))
			{
				_localCharacter = _localLobbyPlayer.CharacterInstance;
				if (!((Object)(object)_localCharacter == (Object)null))
				{
					_isBoothActive = true;
					_gracePeriodTimer = 0.5f;
					_frozenCharacter = _localCharacter;
					_frozenCharacter.InMenu = true;
					_frozenCharacter.Freeze(false, false, false);
					_savedOutfitArray = _localCharacter.GetOutfitsAsArray();
					((MonoBehaviour)this).StartCoroutine(SetupBoothRoutine());
				}
			}
		}

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

		public void DeactivateBooth()
		{
			if (!_isBoothActive)
			{
				return;
			}
			_isBoothActive = false;
			if ((Object)(object)_activeOutfitController != (Object)null)
			{
				try
				{
					LobbyPlayer player = _activeOutfitController.player;
					object obj;
					if (player == null)
					{
						obj = null;
					}
					else
					{
						Player localPlayer = player.LocalPlayer;
						obj = ((localPlayer != null) ? localPlayer.AssociatedLobbyPlayer : null);
					}
					if ((Object)obj != (Object)null)
					{
						_activeOutfitController.player.LocalPlayer.AssociatedLobbyPlayer.CallCmdSetOutfitsFromArray(_localCharacter.GetOutfitsAsArray());
					}
				}
				catch
				{
				}
				if ((Object)(object)_suppressedController != (Object)null)
				{
					_suppressedController.RemoveReceiver((InputReceiver)(object)_activeOutfitController);
				}
				_activeOutfitController.Hide();
				_activeOutfitController.UseController = null;
				_activeOutfitController = null;
			}
			((MonoBehaviour)this).StartCoroutine(RestoreMenuRoutine());
		}

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

		private void OnDestroy()
		{
		}

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

		private void InjectInput(InputKey key)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Expected O, but got Unknown
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Expected O, but got Unknown
			LobbyPlayer localLobbyPlayer = _localLobbyPlayer;
			object obj;
			if (localLobbyPlayer == null)
			{
				obj = null;
			}
			else
			{
				Player localPlayer = localLobbyPlayer.LocalPlayer;
				obj = ((localPlayer != null) ? localPlayer.UseController : null);
			}
			if ((Object)obj != (Object)null)
			{
				int num = 1 << _localLobbyPlayer.networkNumber - 1;
				_localLobbyPlayer.LocalPlayer.UseController.Notify(new InputEvent(num, key, true, true));
				_localLobbyPlayer.LocalPlayer.UseController.Notify(new InputEvent(num, key, false, true));
			}
		}

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

		public static void FixInventoryBook(InventoryBook book)
		{
			Camera val = book.UiCamera ?? Camera.main;
			if (book.InventoryPages != null)
			{
				InventoryPage[] inventoryPages = book.InventoryPages;
				foreach (InventoryPage val2 in inventoryPages)
				{
					_ = ((Component)val2).gameObject.activeSelf;
					Renderer[] componentsInChildren = ((Component)val2).GetComponentsInChildren<Renderer>(true);
					for (int j = 0; j < componentsInChildren.Length; j++)
					{
						componentsInChildren[j].enabled = true;
					}
					if ((Object)(object)val2.textCanvas != (Object)null && (Object)(object)val != (Object)null)
					{
						val2.textCanvas.worldCamera = val;
					}
				}
			}
			if (book.cursors == null)
			{
				return;
			}
			foreach (PickCursor cursor in book.cursors)
			{
				if ((Object)(object)cursor != (Object)null)
				{
					((Component)cursor).gameObject.SetActive(true);
					((Cursor)cursor).Enable();
				}
			}
		}

		private LobbyPlayer GetLocalLobbyPlayer()
		{
			if ((Object)(object)LobbyManager.instance == (Object)null)
			{
				return null;
			}
			NetworkLobbyPlayer[] lobbySlots = ((NetworkLobbyManager)LobbyManager.instance).lobbySlots;
			foreach (NetworkLobbyPlayer obj in lobbySlots)
			{
				LobbyPlayer val = (LobbyPlayer)(object)((obj is LobbyPlayer) ? obj : null);
				if ((Object)(object)val != (Object)null && ((NetworkBehaviour)val).isLocalPlayer)
				{
					return val;
				}
			}
			return null;
		}

		public void DeactivateBoothWithAbort()
		{
			if (_isBoothActive)
			{
				if (_savedOutfitArray != null && (Object)(object)_localCharacter != (Object)null)
				{
					_localCharacter.SetOutfitsFromArray(_savedOutfitArray);
					_localCharacter.TellEverybodyAboutOutfits();
				}
				DeactivateBooth();
			}
		}
	}
	public static class VirtualOutfitUI
	{
		public static void Init()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Expected O, but got Unknown
			Harmony val = new Harmony("de.knusbernd.virtualoutfitbooth");
			MethodInfo methodInfo = AccessTools.Method(typeof(InventoryBook), "Show", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(typeof(InventoryBookShowPatch), "Postfix", (Type[])null, (Type[])null);
			if (methodInfo == null)
			{
				Plugin.Logger.LogError((object)"[VirtualOutfitUI] Could not find InventoryBook.Show method!");
			}
			if (methodInfo2 == null)
			{
				Plugin.Logger.LogError((object)"[VirtualOutfitUI] Could not find Postfix method!");
			}
			if (methodInfo != null && methodInfo2 != null)
			{
				val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(methodInfo2), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			}
		}
	}
	[HarmonyPatch(typeof(InventoryBook), "Show")]
	public static class InventoryBookShowPatch
	{
		public static void Postfix(InventoryBook __instance)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: 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_00d7: Expected O, but got Unknown
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0149: Unknown result type (might be due to invalid IL or missing references)
			//IL_015a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0174: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018a: 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_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0202: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0306: Expected O, but got Unknown
			//IL_0405: Unknown result type (might be due to invalid IL or missing references)
			//IL_040a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0472: Unknown result type (might be due to invalid IL or missing references)
			//IL_047d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			if (((Scene)(ref activeScene)).name != "TreeHouseLobby")
			{
				return;
			}
			string text = "TabletHolder(Clone)/TabletScreen/TextCanvas/Anchor/ScreenContentMask/Home Screen Sidebar/SidebarMask/SidebarContainer/Treehouse Home/Game Mode Control/Mode Select Widget/Next Button";
			Transform obj = ((Component)__instance).transform.Find(text);
			TabletButton val = ((obj != null) ? ((Component)obj).GetComponent<TabletButton>() : null);
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[VirtualOutfitUI] Next Button not found via precise path, falling back to name search.");
				val = ((IEnumerable<TabletButton>)((Component)__instance).GetComponentsInChildren<TabletButton>(true)).FirstOrDefault((Func<TabletButton, bool>)((TabletButton b) => ((Object)b).name == "Next Button"));
			}
			if ((Object)(object)val == (Object)null)
			{
				Plugin.Logger.LogWarning((object)"[VirtualOutfitUI] Could not find any suitable button to clone.");
				return;
			}
			Transform parent = ((Component)val).transform.parent;
			string text2 = "VirtualBoothContainer";
			Transform val2 = parent.Find(text2);
			GameObject val3;
			if ((Object)(object)val2 == (Object)null)
			{
				val3 = new GameObject(text2, new Type[1] { typeof(RectTransform) });
				val3.transform.SetParent(parent, false);
			}
			else
			{
				val3 = ((Component)val2).gameObject;
			}
			RectTransform component = val3.GetComponent<RectTransform>();
			((Transform)component).localScale = new Vector3(0.7f, 0.7f, 1f);
			component.sizeDelta = ((RectTransform)((Component)val).transform).sizeDelta;
			component.anchorMin = ((RectTransform)((Component)val).transform).anchorMin;
			component.anchorMax = ((RectTransform)((Component)val).transform).anchorMax;
			component.pivot = ((RectTransform)((Component)val).transform).pivot;
			Rect rect = ((RectTransform)((Component)val).transform).rect;
			float height = ((Rect)(ref rect)).height;
			component.anchoredPosition = ((RectTransform)((Component)val).transform).anchoredPosition + new Vector2(0f, height);
			Transform val4 = val3.transform.Find("VirtualBoothButton");
			GameObject val5;
			if ((Object)(object)val4 == (Object)null)
			{
				val5 = Object.Instantiate<GameObject>(((Component)val).gameObject, val3.transform);
				((Object)val5).name = "VirtualBoothButton";
				val5.transform.localScale = Vector3.one;
				val5.transform.localPosition = Vector3.zero;
				RenameChildren(val5.transform, "_Virtual");
				MonoBehaviour[] components = val5.GetComponents<MonoBehaviour>();
				foreach (MonoBehaviour val6 in components)
				{
					switch (((object)val6).GetType().Name)
					{
					case "TabletButton":
					case "TabletClickable":
					case "TextMeshProUGUI":
					case "Image":
					case "RawImage":
					case "CanvasRenderer":
					case "LayoutElement":
					case "RectTransform":
						continue;
					}
					Object.Destroy((Object)(object)val6);
				}
				Transform val7 = val5.transform.Find("UI.TextLabel_Virtual");
				if ((Object)(object)val7 != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)val7).gameObject);
				}
				TabletButton component2 = val5.GetComponent<TabletButton>();
				component2.OnClick = new TabletButtonEvent();
				((TabletStyledObject)component2).SetDisabled(false);
				((TabletStyledObject)component2).SetInteractable(true);
				((UnityEvent<PickCursor>)(object)component2.OnClick).AddListener((UnityAction<PickCursor>)delegate
				{
					VirtualOutfitBooth.Instance.ActivateBooth();
				});
				Text[] componentsInChildren = val5.GetComponentsInChildren<Text>(true);
				foreach (Text val8 in componentsInChildren)
				{
					if ((Object)(object)((Component)val8).gameObject != (Object)(object)val5)
					{
						val8.text = "";
						((Behaviour)val8).enabled = false;
						((Component)val8).gameObject.SetActive(false);
					}
				}
				TextMeshProUGUI[] componentsInChildren2 = val5.GetComponentsInChildren<TextMeshProUGUI>(true);
				foreach (TextMeshProUGUI val9 in componentsInChildren2)
				{
					if ((Object)(object)((Component)val9).gameObject != (Object)(object)val5)
					{
						((TMP_Text)val9).text = "";
						((Behaviour)val9).enabled = false;
						((Component)val9).gameObject.SetActive(false);
					}
				}
				Sprite val10 = LoadSpriteFromResource("hanger_icon.png");
				if ((Object)(object)val10 != (Object)null)
				{
					GameObject val11 = new GameObject("Icon_Hanger");
					val11.transform.SetParent(val5.transform, false);
					Image obj2 = val11.AddComponent<Image>();
					obj2.sprite = val10;
					obj2.preserveAspect = true;
					((Graphic)obj2).raycastTarget = false;
					RectTransform rectTransform = ((Graphic)obj2).rectTransform;
					rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
					rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
					rectTransform.pivot = new Vector2(0.5f, 0.5f);
					rectTransform.anchoredPosition = Vector2.zero;
					rectTransform.sizeDelta = new Vector2(165f, 86f);
				}
			}
			else
			{
				val5 = ((Component)val4).gameObject;
			}
			val5.transform.localScale = Vector3.one;
			CanvasGroup component3 = val5.GetComponent<CanvasGroup>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.interactable = true;
				component3.blocksRaycasts = true;
			}
			TabletButton component4 = val5.GetComponent<TabletButton>();
			if ((Object)(object)component4.background == (Object)null)
			{
				Image val12 = val5.GetComponent<Image>() ?? val5.GetComponentInChildren<Image>(true);
				if ((Object)(object)val12 != (Object)null)
				{
					component4.background = val12;
					((Graphic)val12).raycastTarget = true;
				}
			}
			else
			{
				((Graphic)component4.background).raycastTarget = true;
			}
			if ((Object)(object)((TabletStyledObject)component4).colorScheme == (Object)null)
			{
				((TabletStyledObject)component4).colorScheme = ((TabletStyledObject)(((Component)val).GetComponent<TabletButton>()?)).colorScheme ?? ((Component)__instance).GetComponentInChildren<TabletColorScheme>(true);
			}
			((TabletStyledObject)component4).ResetStyles();
			val5.SetActive(true);
		}

		private static void RenameChildren(Transform parent, string suffix)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			foreach (Transform item in parent)
			{
				((Object)item).name = ((Object)item).name + suffix;
				RenameChildren(item, suffix);
			}
		}

		private static Sprite LoadSpriteFromResource(string resourceName)
		{
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string r) => r.EndsWith(resourceName));
				if (string.IsNullOrEmpty(text))
				{
					Plugin.Logger.LogError((object)("[VirtualOutfitUI] Resource not found ending with: " + resourceName));
					string[] manifestResourceNames = executingAssembly.GetManifestResourceNames();
					foreach (string text2 in manifestResourceNames)
					{
						Plugin.Logger.LogInfo((object)("  Available Resource: " + text2));
					}
					return null;
				}
				using Stream stream = executingAssembly.GetManifestResourceStream(text);
				if (stream == null)
				{
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, (int)stream.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				ImageConversion.LoadImage(val, array);
				((Texture)val).filterMode = (FilterMode)1;
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f));
			}
			catch (Exception ex)
			{
				Plugin.Logger.LogError((object)("[VirtualOutfitUI] Failed to load sprite: " + ex.Message));
				return null;
			}
		}
	}
}
namespace VirtualBooth
{
	[BepInPlugin("de.knusbernd.virtualoutfitbooth", "VirtualOutfitBooth", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public static Plugin Instance;

		internal static ManualLogSource Logger;

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			new Harmony("de.knusbernd.virtualoutfitbooth").PatchAll(typeof(Plugin).Assembly);
			VirtualOutfitUI.Init();
			((Component)this).gameObject.AddComponent<global::VirtualOutfitBooth.VirtualOutfitBooth>();
			Logger.LogInfo((object)"Plugin de.knusbernd.virtualoutfitbooth is loaded!");
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "de.knusbernd.virtualoutfitbooth";

		public const string PLUGIN_NAME = "VirtualOutfitBooth";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}