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.Configuration;
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 VirtualBooth
{
[BepInPlugin("de.knusbernd.virtualoutfitbooth", "VirtualOutfitBooth", "1.1.1")]
public class Plugin : BaseUnityPlugin
{
public static Plugin Instance;
internal static ManualLogSource Logger;
public static ConfigEntry<bool> ReturnToMenuAfterBooth;
private void Awake()
{
//IL_0036: Unknown result type (might be due to invalid IL or missing references)
Instance = this;
Logger = ((BaseUnityPlugin)this).Logger;
ReturnToMenuAfterBooth = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReturnToMenuAfterBooth", true, "If true, opens the tablet menu after exiting the booth. If false, returns directly to gameplay.");
new Harmony("de.knusbernd.virtualoutfitbooth").PatchAll(typeof(Plugin).Assembly);
((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.1.1";
}
}
namespace VirtualOutfitBooth
{
public class VirtualOutfitBooth : MonoBehaviour
{
[CompilerGenerated]
private sealed class <RefreshOutfitDisplay>d__26 : 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__26(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_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005f: Expected O, but got Unknown
//IL_01a7: 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_022b: 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 (!Plugin.ReturnToMenuAfterBooth.Value)
{
<>2__current = (object)new WaitForSecondsRealtime(0.1f);
<>1__state = 2;
return true;
}
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;
case 2:
<>1__state = -1;
if ((Object)(object)virtualOutfitBooth._suppressedController != (Object)null && (Object)(object)virtualOutfitBooth._hijackedLevelSelect != (Object)null)
{
virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)virtualOutfitBooth._hijackedLevelSelect);
}
if ((Object)(object)virtualOutfitBooth._suppressedController != (Object)null && (Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
{
virtualOutfitBooth._suppressedController.AddReceiver((InputReceiver)(object)virtualOutfitBooth._localCharacter);
}
if ((Object)(object)virtualOutfitBooth._localCharacter != (Object)null)
{
virtualOutfitBooth._localCharacter.Unfreeze();
virtualOutfitBooth._localCharacter.InMenu = false;
}
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__24 : 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__24(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.");
}
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;
internal bool _isBoothActive;
internal float _gracePeriodTimer;
internal OutfitController _activeOutfitController;
private LevelSelectController _hijackedLevelSelect;
private Controller _suppressedController;
private Character _frozenCharacter;
private LobbyPlayer _localLobbyPlayer;
internal 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 (Exception ex)
{
Plugin.Logger.LogError((object)("[VirtualOutfitBooth] Error syncing outfits: " + ex.Message));
}
if ((Object)(object)_activeOutfitController.outfitChangeProp != (Object)null)
{
OutfitChangeProp outfitChangeProp = _activeOutfitController.outfitChangeProp;
if (!string.IsNullOrEmpty(outfitChangeProp.exitAudioString))
{
Type type = AccessTools.TypeByName("AkSoundEngine");
if (type != null)
{
AccessTools.Method(type, "PostEvent", new Type[2]
{
typeof(string),
typeof(GameObject)
}, (Type[])null)?.Invoke(null, new object[2]
{
outfitChangeProp.exitAudioString,
((Component)outfitChangeProp).gameObject
});
}
}
}
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
};
}
[IteratorStateMachine(typeof(<WatchForMenuClose>d__24))]
private IEnumerator WatchForMenuClose(InventoryBook book)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <WatchForMenuClose>d__24(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__26))]
private IEnumerator RefreshOutfitDisplay()
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <RefreshOutfitDisplay>d__26(0)
{
<>4__this = this
};
}
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();
}
}
}
}
namespace VirtualOutfitBooth.Patches
{
[HarmonyPatch(typeof(InventoryBook), "Show")]
public static class InventoryBookPatch
{
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)
Scene activeScene = SceneManager.GetActiveScene();
if (!(((Scene)(ref activeScene)).name != "TreeHouseLobby"))
{
TabletButton val = FindTargetButton(__instance);
if ((Object)(object)val == (Object)null)
{
Plugin.Logger.LogWarning((object)"[InventoryBookPatch] Could not find any suitable button to clone.");
}
else
{
CreateBoothButton(CreateBoothContainer(val), val);
}
}
}
private static TabletButton FindTargetButton(InventoryBook book)
{
string text = "TabletHolder(Clone)/TabletScreen/TextCanvas/Anchor/ScreenContentMask/Home Screen Sidebar/SidebarMask/SidebarContainer/Treehouse Home/Game Mode Control/Mode Select Widget/Next Button";
Transform val = ((Component)book).transform.Find(text);
if ((Object)(object)val != (Object)null)
{
return ((Component)val).GetComponent<TabletButton>();
}
Plugin.Logger.LogWarning((object)"[InventoryBookPatch] Next Button not found via path, falling back to name search.");
return ((IEnumerable<TabletButton>)((Component)book).GetComponentsInChildren<TabletButton>(true)).FirstOrDefault((Func<TabletButton, bool>)((TabletButton b) => ((Object)b).name == "Next Button"));
}
private static GameObject CreateBoothContainer(TabletButton referenceButton)
{
//IL_0037: Unknown result type (might be due to invalid IL or missing references)
//IL_003d: Expected O, but got Unknown
//IL_005f: Unknown result type (might be due to invalid IL or missing references)
//IL_0066: Expected O, but got Unknown
//IL_0076: 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_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
//IL_00b6: 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_00d0: 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)
Transform parent = ((Component)referenceButton).transform.parent;
string text = "VirtualBoothContainer";
Transform val = parent.Find(text);
GameObject val2;
if ((Object)(object)val == (Object)null)
{
val2 = new GameObject(text, new Type[1] { typeof(RectTransform) });
val2.transform.SetParent(parent, false);
}
else
{
val2 = ((Component)val).gameObject;
}
RectTransform component = val2.GetComponent<RectTransform>();
RectTransform val3 = (RectTransform)((Component)referenceButton).transform;
((Transform)component).localScale = new Vector3(0.7f, 0.7f, 1f);
component.sizeDelta = val3.sizeDelta;
component.anchorMin = val3.anchorMin;
component.anchorMax = val3.anchorMax;
component.pivot = val3.pivot;
Vector2 anchoredPosition = val3.anchoredPosition;
Rect rect = val3.rect;
component.anchoredPosition = anchoredPosition + new Vector2(0f, ((Rect)(ref rect)).height);
return val2;
}
private static void CreateBoothButton(GameObject container, TabletButton referenceButton)
{
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_004b: Unknown result type (might be due to invalid IL or missing references)
if (!((Object)(object)container.transform.Find("VirtualBoothButton") != (Object)null))
{
GameObject obj = Object.Instantiate<GameObject>(((Component)referenceButton).gameObject, container.transform);
((Object)obj).name = "VirtualBoothButton";
obj.transform.localScale = Vector3.one;
obj.transform.localPosition = Vector3.zero;
RenameChildren(obj.transform, "_Virtual");
CleanupComponents(obj);
SetupButtonFunctionality(obj);
SetupButtonVisuals(obj);
obj.SetActive(true);
}
}
private static void CleanupComponents(GameObject buttonObj)
{
MonoBehaviour[] components = buttonObj.GetComponents<MonoBehaviour>();
foreach (MonoBehaviour val in components)
{
switch (((object)val).GetType().Name)
{
case "TabletButton":
case "TabletClickable":
case "TextMeshProUGUI":
case "Image":
case "RawImage":
case "CanvasRenderer":
case "LayoutElement":
case "RectTransform":
continue;
}
Object.Destroy((Object)(object)val);
}
Transform val2 = buttonObj.transform.Find("UI.TextLabel_Virtual");
if ((Object)(object)val2 != (Object)null)
{
Object.Destroy((Object)(object)((Component)val2).gameObject);
}
}
private static void SetupButtonFunctionality(GameObject buttonObj)
{
//IL_0012: Unknown result type (might be due to invalid IL or missing references)
//IL_001c: Expected O, but got Unknown
TabletButton component = buttonObj.GetComponent<TabletButton>();
if (!((Object)(object)component == (Object)null))
{
component.OnClick = new TabletButtonEvent();
((TabletStyledObject)component).SetDisabled(false);
((TabletStyledObject)component).SetInteractable(true);
((UnityEvent<PickCursor>)(object)component.OnClick).AddListener((UnityAction<PickCursor>)delegate
{
VirtualOutfitBooth.Instance.ActivateBooth();
});
CanvasGroup component2 = buttonObj.GetComponent<CanvasGroup>();
if ((Object)(object)component2 != (Object)null)
{
component2.interactable = true;
component2.blocksRaycasts = true;
}
}
}
private static void SetupButtonVisuals(GameObject buttonObj)
{
//IL_0095: 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_00df: Unknown result type (might be due to invalid IL or missing references)
//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
//IL_010c: Unknown result type (might be due to invalid IL or missing references)
Text[] componentsInChildren = buttonObj.GetComponentsInChildren<Text>(true);
foreach (Text val in componentsInChildren)
{
if ((Object)(object)((Component)val).gameObject != (Object)(object)buttonObj)
{
((Component)val).gameObject.SetActive(false);
}
}
TextMeshProUGUI[] componentsInChildren2 = buttonObj.GetComponentsInChildren<TextMeshProUGUI>(true);
foreach (TextMeshProUGUI val2 in componentsInChildren2)
{
if ((Object)(object)((Component)val2).gameObject != (Object)(object)buttonObj)
{
((Component)val2).gameObject.SetActive(false);
}
}
((TabletStyledObject)buttonObj.GetComponent<TabletButton>()).ResetStyles();
Sprite val3 = LoadSprite("hanger_icon.png");
if ((Object)(object)val3 != (Object)null)
{
GameObject val4 = new GameObject("Icon_Hanger");
val4.transform.SetParent(buttonObj.transform, false);
Image obj = val4.AddComponent<Image>();
obj.sprite = val3;
obj.preserveAspect = true;
((Graphic)obj).raycastTarget = false;
RectTransform rectTransform = ((Graphic)obj).rectTransform;
Vector2 val5 = default(Vector2);
((Vector2)(ref val5))..ctor(0.5f, 0.5f);
rectTransform.pivot = val5;
Vector2 anchorMin = (rectTransform.anchorMax = val5);
rectTransform.anchorMin = anchorMin;
rectTransform.anchoredPosition = Vector2.zero;
rectTransform.sizeDelta = new Vector2(165f, 86f);
}
}
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 LoadSprite(string resourceName)
{
//IL_008a: Unknown result type (might be due to invalid IL or missing references)
//IL_0091: Expected O, but got Unknown
//IL_00bf: 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)
try
{
Assembly executingAssembly = Assembly.GetExecutingAssembly();
string text = executingAssembly.GetManifestResourceNames().FirstOrDefault((string r) => r.EndsWith(resourceName));
if (string.IsNullOrEmpty(text))
{
Plugin.Logger.LogError((object)("[InventoryBookPatch] Resource mismatched: " + resourceName));
return null;
}
using Stream stream = executingAssembly.GetManifestResourceStream(text);
if (stream == null)
{
return null;
}
byte[] array = new byte[stream.Length];
stream.Read(array, 0, array.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)("[InventoryBookPatch] Failed to load sprite: " + ex.Message));
return null;
}
}
}
[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)VirtualOutfitBooth.Instance != (Object)null && VirtualOutfitBooth.Instance.IsBoothActive && (int)e.Key == 9 && e.Changed && e.Valueb)
{
return false;
}
return true;
}
}
[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)VirtualOutfitBooth.Instance != (Object)null && VirtualOutfitBooth.Instance.IsBoothActive)
{
if (VirtualOutfitBooth.Instance._gracePeriodTimer > 0f)
{
return false;
}
if ((int)e.Key == 9 && e.Changed)
{
e.Consume();
VirtualOutfitBooth.Instance.DeactivateBoothWithAbort();
return false;
}
if ((int)e.Key == 21 && e.Changed && (Object)(object)__instance == (Object)(object)VirtualOutfitBooth.Instance.ActiveOutfitController)
{
e.Consume();
VirtualOutfitBooth.Instance.DeactivateBooth();
return false;
}
if (((int)e.Key == 22 || (int)e.Key == 19) && e.Changed && (Object)(object)__instance == (Object)(object)VirtualOutfitBooth.Instance.ActiveOutfitController)
{
e.Consume();
VirtualOutfitBooth.Instance.DeactivateBoothWithAbort();
return false;
}
}
return true;
}
}
[HarmonyPatch(typeof(OutfitController), "Release")]
public static class OutfitControllerReleasePatch
{
public static void Postfix(OutfitController __instance)
{
if ((Object)(object)VirtualOutfitBooth.Instance != (Object)null && VirtualOutfitBooth.Instance.IsBoothActive && (Object)(object)__instance == (Object)(object)VirtualOutfitBooth.Instance.ActiveOutfitController)
{
VirtualOutfitBooth.Instance.DeactivateBooth();
}
}
}
[HarmonyPatch(typeof(ZoomCamera), "GetFrame")]
public static class ZoomCameraGetFramePatch
{
public static bool Prefix(ZoomCamera __instance, ref Bounds __result)
{
//IL_002e: Unknown result type (might be due to invalid IL or missing references)
//IL_0033: Unknown result type (might be due to invalid IL or missing references)
//IL_0055: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0072: 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_008a: 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_009f: 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_01a0: Unknown result type (might be due to invalid IL or missing references)
//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
//IL_01af: Unknown result type (might be due to invalid IL or missing references)
//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
//IL_00f5: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
//IL_012f: Unknown result type (might be due to invalid IL or missing references)
//IL_0140: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Unknown result type (might be due to invalid IL or missing references)
//IL_0167: Unknown result type (might be due to invalid IL or missing references)
//IL_0178: 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_0188: Unknown result type (might be due to invalid IL or missing references)
VirtualOutfitBooth instance = VirtualOutfitBooth.Instance;
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;
}
}
}