Decompiled source of TicketBoothPlus v1.0.0

plugins/TicketBoothPlus.dll

Decompiled 2 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text.Json;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using CayplayAI;
using I2.Loc;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using Il2CppSystem.Reflection;
using Microsoft.CodeAnalysis;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("TicketBoothPlus")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TicketBoothPlus")]
[assembly: AssemblyTitle("TicketBoothPlus")]
[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 ParkEditor
{
	internal static class Items
	{
		private static List<ItemSpawner> _spawners = new List<ItemSpawner>();

		private static float _next;

		private static List<ItemSpawner> Spawners()
		{
			if (Time.unscaledTime < _next)
			{
				return _spawners;
			}
			_next = Time.unscaledTime + 2f;
			_spawners = new List<ItemSpawner>();
			foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsByType(Il2CppType.Of<ItemSpawner>(), (FindObjectsSortMode)0))
			{
				ItemSpawner val = ((Il2CppObjectBase)item).TryCast<ItemSpawner>();
				if ((Object)(object)val != (Object)null)
				{
					_spawners.Add(val);
				}
			}
			return _spawners;
		}

		public static List<BaseItem> ItemsOf(ItemSpawner sp)
		{
			List<BaseItem> list = new List<BaseItem>();
			BaseItem item = sp.Item;
			if ((Object)(object)item != (Object)null)
			{
				list.Add(item);
			}
			List<BaseItem> linkedItems = sp.LinkedItems;
			if (linkedItems != null)
			{
				for (int i = 0; i < linkedItems.Count; i++)
				{
					BaseItem l = linkedItems[i];
					if ((Object)(object)l != (Object)null && !list.Any((BaseItem x) => ((Il2CppObjectBase)x).Pointer == ((Il2CppObjectBase)l).Pointer))
					{
						list.Add(l);
					}
				}
			}
			return list;
		}

		public static ItemSpawner SpawnerOf(Transform t, out BaseItem item)
		{
			//IL_0093: 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)
			item = ((Component)t).GetComponentInParent<BaseItem>();
			if ((Object)(object)item == (Object)null || item.inInventory)
			{
				return null;
			}
			ItemSpawner result = null;
			float num = 0.2f;
			foreach (ItemSpawner item2 in Spawners())
			{
				if ((Object)(object)item2 == (Object)null)
				{
					continue;
				}
				foreach (BaseItem item3 in ItemsOf(item2))
				{
					if (((Il2CppObjectBase)item3).Pointer == ((Il2CppObjectBase)item).Pointer)
					{
						return item2;
					}
				}
				float num2 = Vector3.Distance(((Component)item2).transform.position, ((Component)item).transform.position);
				if (num2 < num)
				{
					num = num2;
					result = item2;
				}
			}
			return result;
		}

		public static List<Transform> Resting(ItemSpawner sp, Vector3 around, float radius = 0.5f)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			List<Transform> list = new List<Transform>();
			foreach (BaseItem item in ItemsOf(sp))
			{
				if (!item.inInventory && Vector3.Distance(((Component)item).transform.position, around) <= radius)
				{
					list.Add(((Component)item).transform);
				}
			}
			return list;
		}
	}
	internal static class Layout
	{
		public static readonly Dictionary<string, IntPtr> Applied = new Dictionary<string, IntPtr>();

		public static readonly HashSet<IntPtr> ItemsPlaced = new HashSet<IntPtr>();

		public static void Apply(Func<Transform, bool> refuse = null)
		{
			//IL_00ed: 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_0111: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			bool flag = false;
			bool flag2 = default(bool);
			foreach (Move item in Store.Moves.ToList())
			{
				if (item.Pos == null)
				{
					continue;
				}
				Transform val = Store.Find(item.Path);
				if ((Object)(object)val == (Object)null || (Applied.TryGetValue(item.Path, out var value) && value == ((Il2CppObjectBase)val).Pointer))
				{
					continue;
				}
				if (refuse != null && refuse(val))
				{
					val.SetPositionAndRotation(Store.V(item.OrigPos), Store.Q(item.OrigRot));
					Store.Moves.Remove(item);
					Applied.Remove(item.Path);
					flag = true;
					ManualLogSource l = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(30, 1, ref flag2);
					if (flag2)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Dropped saved move, put back: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(item.Path);
					}
					l.LogWarning(val2);
				}
				else
				{
					val.SetPositionAndRotation(Store.V(item.Pos), Store.Q(item.Rot));
					if (item.Scale != null)
					{
						val.localScale = Store.V(item.Scale);
					}
					Applied[item.Path] = ((Il2CppObjectBase)val).Pointer;
				}
			}
			if (flag)
			{
				Store.Save();
			}
			PlaceSpawnedItems();
		}

		private static void PlaceSpawnedItems()
		{
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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_0093: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: 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_00c8: 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_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: 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_010b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0110: 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_0119: Unknown result type (might be due to invalid IL or missing references)
			//IL_011e: Unknown result type (might be due to invalid IL or missing references)
			if (!SecondWindow.IsHost)
			{
				return;
			}
			foreach (Move move in Store.Moves)
			{
				if (move.Pos == null || !Applied.ContainsKey(move.Path))
				{
					continue;
				}
				Transform val = Store.Find(move.Path);
				ItemSpawner val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<ItemSpawner>() : null);
				if ((Object)(object)val2 == (Object)null)
				{
					continue;
				}
				Vector3 val3 = Store.V(move.OrigPos);
				Quaternion val4 = Store.Q(move.Rot) * Quaternion.Inverse(Store.Q(move.OrigRot));
				Vector3 val5 = Store.V(move.Pos);
				foreach (Transform item in Items.Resting(val2, val3, 0.3f))
				{
					if (!(Vector3.Distance(item.position, val3) >= Vector3.Distance(item.position, val5)) && ItemsPlaced.Add(((Il2CppObjectBase)item).Pointer))
					{
						item.SetPositionAndRotation(val5 + val4 * (item.position - val3), val4 * item.rotation);
					}
				}
			}
		}
	}
	public sealed class RuntimeBehaviour : MonoBehaviour
	{
		private float _nextApply;

		private bool _layoutFailed;

		private bool _windowFailed;

		public RuntimeBehaviour(IntPtr ptr)
			: base(ptr)
		{
		}

		public void Update()
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			bool flag = default(bool);
			if (Time.unscaledTime >= _nextApply)
			{
				_nextApply = Time.unscaledTime + 1f;
				try
				{
					Layout.Apply(Refuse);
					_layoutFailed = false;
				}
				catch (Exception ex)
				{
					if (!_layoutFailed)
					{
						ManualLogSource l = Plugin.L;
						BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(14, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Booth layout: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
						}
						l.LogError(val);
					}
					_layoutFailed = true;
				}
			}
			try
			{
				SecondWindow.Tick();
				_windowFailed = false;
			}
			catch (Exception ex2)
			{
				if (!_windowFailed)
				{
					ManualLogSource l2 = Plugin.L;
					BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(15, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Second window: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex2);
					}
					l2.LogError(val);
				}
				_windowFailed = true;
			}
		}

		private static bool Refuse(Transform t)
		{
			return false;
		}
	}
	[BepInPlugin("chistix.ticketboothplus", "TicketBoothPlus", "1.0.0")]
	public sealed class Plugin : BasePlugin
	{
		public const string Id = "chistix.ticketboothplus";

		public const string Name = "TicketBoothPlus";

		public const string Title = "Ticket Booth Plus";

		public const string Version = "1.0.0";

		internal static ManualLogSource L;

		internal static string DataDir => Path.Combine(Paths.ConfigPath, "ParkEditor");

		public override void Load()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			L = ((BasePlugin)this).Log;
			Store.Load();
			SecondWindow.Init();
			ClassInjector.RegisterTypeInIl2Cpp<RuntimeBehaviour>();
			((BasePlugin)this).AddComponent<RuntimeBehaviour>();
			ManualLogSource l = L;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(8, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Ticket Booth Plus");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("1.0.0");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" loaded");
			}
			l.LogInfo(val);
		}

		internal static string ReadData(string file)
		{
			using Stream stream = typeof(Plugin).Assembly.GetManifestResourceStream("layout/" + file);
			if (stream == null)
			{
				return null;
			}
			using StreamReader streamReader = new StreamReader(stream);
			return streamReader.ReadToEnd();
		}
	}
	public sealed class WindowHandler : Object
	{
		internal uint Kind;

		public WindowHandler(IntPtr ptr)
			: base(ptr)
		{
		}

		public WindowHandler()
			: base(ClassInjector.DerivedConstructorPointer<WindowHandler>())
		{
			ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
		}

		public NetworkObject Instantiate(ulong ownerClientId, Vector3 position, Quaternion rotation)
		{
			//IL_0006: 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_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			try
			{
				return SecondWindow.CreateForNetwork(Kind, position, rotation);
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(28, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Second window instantiate ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<uint>(Kind, "X");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				l.LogError(val);
				return null;
			}
		}

		public void Destroy(NetworkObject networkObject)
		{
			if ((Object)(object)networkObject != (Object)null)
			{
				Object.Destroy((Object)(object)((Component)networkObject).gameObject);
			}
		}
	}
	public sealed class WindowPlacement
	{
		public string Scene { get; set; }

		public float[] Pos { get; set; }

		public float Yaw { get; set; }

		public float[] Pc { get; set; }

		public float[] Printer { get; set; }

		public float[] Switch { get; set; }

		public bool Closed { get; set; }
	}
	internal static class SecondWindow
	{
		public const uint Hash = 1589670343u;

		public const uint PcHash = 1589670344u;

		public const uint PrinterHash = 1589670345u;

		public const uint SwitchHash = 1589670346u;

		private const string CloneName = "TicketStation (ParkEditor window 2)";

		public const string PcName = "ParkEditor TicketPC 2";

		public const string PrinterName = "ParkEditor TicketPrinter 2";

		public const string SwitchName = "ParkEditor Window2 Switch";

		private const float SwitchModelScale = 0.35f;

		private const string SwitchTerm = "ParkEditor/Window2Switch";

		private static readonly uint[] PieceKinds = new uint[3] { 1589670344u, 1589670345u, 1589670346u };

		private static readonly Dictionary<uint, WindowHandler> _handlers = new Dictionary<uint, WindowHandler>();

		private static NetworkManager _registeredOn;

		private static NetworkObject _spawned;

		private static readonly Dictionary<uint, NetworkObject> _pieces = new Dictionary<uint, NetworkObject>();

		private static List<WindowPlacement> _placements;

		private static float _respawnAt = -1f;

		private static float _respawnPiecesAt = -1f;

		private static bool _piecesFailed;

		private static GameObject _holder;

		private static readonly Dictionary<uint, GameObject> _pending = new Dictionary<uint, GameObject>();

		public static Action<string> Notify;

		private static readonly List<TMP_Text> _switchTexts = new List<TMP_Text>();

		private static readonly List<Collider> _switchColliders = new List<Collider>();

		private static readonly Dictionary<string, string[]> Texts = new Dictionary<string, string[]>(StringComparer.OrdinalIgnoreCase)
		{
			["en"] = new string[4] { "WINDOW 2", "OPEN", "CLOSED", "Window 2: open / close" },
			["ru"] = new string[4] { "ОКНО 2", "ОТКРЫТО", "ЗАКРЫТО", "Окно 2: открыть / закрыть" },
			["uk"] = new string[4] { "ВІКНО 2", "ВІДЧИНЕНО", "ЗАЧИНЕНО", "Вікно 2: відчинити / зачинити" },
			["de"] = new string[4] { "SCHALTER 2", "OFFEN", "GESCHLOSSEN", "Schalter 2: öffnen / schließen" },
			["fr"] = new string[4] { "GUICHET 2", "OUVERT", "FERMÉ", "Guichet 2 : ouvrir / fermer" },
			["es"] = new string[4] { "TAQUILLA 2", "ABIERTA", "CERRADA", "Taquilla 2: abrir / cerrar" },
			["pt"] = new string[4] { "BILHETERIA 2", "ABERTA", "FECHADA", "Bilheteria 2: abrir / fechar" },
			["it"] = new string[4] { "SPORTELLO 2", "APERTO", "CHIUSO", "Sportello 2: apri / chiudi" },
			["pl"] = new string[4] { "OKIENKO 2", "OTWARTE", "ZAMKNIĘTE", "Okienko 2: otwórz / zamknij" },
			["cs"] = new string[4] { "OKÉNKO 2", "OTEVŘENO", "ZAVŘENO", "Okénko 2: otevřít / zavřít" },
			["tr"] = new string[4] { "GİŞE 2", "AÇIK", "KAPALI", "Gişe 2: aç / kapat" },
			["nl"] = new string[4] { "LOKET 2", "OPEN", "GESLOTEN", "Loket 2: openen / sluiten" },
			["hu"] = new string[4] { "2. PÉNZTÁR", "NYITVA", "ZÁRVA", "2. pénztár: nyitás / zárás" },
			["sv"] = new string[4] { "LUCKA 2", "ÖPPEN", "STÄNGD", "Lucka 2: öppna / stäng" },
			["zh-TW"] = new string[4] { "2號窗口", "營業中", "已關閉", "2號窗口:開啟 / 關閉" },
			["zh"] = new string[4] { "2号窗口", "营业中", "已关闭", "2号窗口:开启 / 关闭" },
			["ja"] = new string[4] { "窓口2", "営業中", "休止中", "窓口2:開ける / 閉める" },
			["ko"] = new string[4] { "2번 창구", "운영 중", "닫힘", "2번 창구: 열기 / 닫기" }
		};

		private static string _shownLanguage;

		private static float _nextLangCheck;

		private static readonly Color OpenColor = new Color(0.2f, 0.95f, 0.3f);

		private static readonly Color ClosedColor = new Color(1f, 0.2f, 0.15f);

		private static Renderer _switchDome;

		private static TicketStation _a;

		private static TicketStation _b;

		private static string FilePath => Path.Combine(Plugin.DataDir, "window2.json");

		public static WindowPlacement Current
		{
			get
			{
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000c: Unknown result type (might be due to invalid IL or missing references)
				Scene activeScene = SceneManager.GetActiveScene();
				string scene = ((Scene)(ref activeScene)).name;
				return _placements.FirstOrDefault((WindowPlacement p) => p.Scene == scene);
			}
		}

		public static NetworkObject Spawned
		{
			get
			{
				if (!((Object)(object)_spawned != (Object)null) || !_spawned.IsSpawned)
				{
					return null;
				}
				return _spawned;
			}
		}

		public static bool IsHost
		{
			get
			{
				if ((Object)(object)NetworkManager.Singleton != (Object)null)
				{
					return NetworkManager.Singleton.IsServer;
				}
				return false;
			}
		}

		private static string NameOf(uint kind)
		{
			return kind switch
			{
				1589670344u => "ParkEditor TicketPC 2", 
				1589670345u => "ParkEditor TicketPrinter 2", 
				_ => "ParkEditor Window2 Switch", 
			};
		}

		private static uint KindOf(string name)
		{
			if (!(name == "ParkEditor TicketPC 2"))
			{
				if (!(name == "ParkEditor TicketPrinter 2"))
				{
					return 1589670346u;
				}
				return 1589670345u;
			}
			return 1589670344u;
		}

		private static string Russian(uint kind)
		{
			return kind switch
			{
				1589670344u => "компьютер 2", 
				1589670345u => "принтер 2", 
				_ => "кнопка окна 2", 
			};
		}

		public static void Init()
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Expected O, but got Unknown
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			RegisterTypeOptions val = new RegisterTypeOptions();
			val.set_Interfaces(Il2CppInterfaceCollection.op_Implicit(new Type[1] { typeof(INetworkPrefabInstanceHandler) }));
			ClassInjector.RegisterTypeInIl2Cpp<WindowHandler>(val);
			try
			{
				string text = Plugin.ReadData("window2.json");
				_placements = ((text != null) ? JsonSerializer.Deserialize<List<WindowPlacement>>(text) : null);
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(14, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("window2.json: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				l.LogError(val2);
			}
			if (_placements == null)
			{
				_placements = new List<WindowPlacement>();
			}
		}

		private static void SavePlacements()
		{
		}

		private static bool Alive(NetworkObject no)
		{
			if ((Object)(object)no != (Object)null)
			{
				return no.IsSpawned;
			}
			return false;
		}

		private static float[] PoseOf(WindowPlacement p, uint kind)
		{
			return kind switch
			{
				1589670344u => p.Pc, 
				1589670345u => p.Printer, 
				_ => p.Switch, 
			};
		}

		private static void SetPose(WindowPlacement p, uint kind, float[] v)
		{
			switch (kind)
			{
			case 1589670344u:
				p.Pc = v;
				break;
			case 1589670345u:
				p.Printer = v;
				break;
			default:
				p.Switch = v;
				break;
			}
		}

		public static TicketStation Template()
		{
			foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsByType(Il2CppType.Of<TicketStation>(), (FindObjectsSortMode)0))
			{
				TicketStation val = ((Il2CppObjectBase)item).TryCast<TicketStation>();
				if (!((Object)(object)val == (Object)null) && !(((Object)((Component)val).gameObject).name != "TicketStation") && !((Object)(object)((Component)val).GetComponent<Building>() != (Object)null))
				{
					return val;
				}
			}
			return null;
		}

		private static bool DeskTemplates(out Transform printer, out Transform pc, out Transform openPark)
		{
			printer = (pc = (openPark = null));
			foreach (Object item in (Il2CppArrayBase<Object>)(object)Object.FindObjectsByType(Il2CppType.Of<TicketPrinterInteractable>(), (FindObjectsSortMode)0))
			{
				TicketPrinterInteractable val = ((Il2CppObjectBase)item).TryCast<TicketPrinterInteractable>();
				if (!((Object)(object)val == (Object)null) && !((Object)(object)PieceRoot(((Component)val).transform) != (Object)null))
				{
					Transform val2 = ((Component)val).transform;
					while ((Object)(object)val2.parent != (Object)null && (Object)(object)Child(val2.parent, "TicketComputer") == (Object)null)
					{
						val2 = val2.parent;
					}
					if (!((Object)(object)val2.parent == (Object)null))
					{
						printer = val2;
						pc = Child(val2.parent, "TicketComputer");
						openPark = Child(val2.parent, "OpenParkButton");
						return true;
					}
				}
			}
			return false;
		}

		private static Transform TemplateOf(uint kind)
		{
			if (!DeskTemplates(out var printer, out var pc, out var openPark))
			{
				return null;
			}
			return (Transform)(kind switch
			{
				1589670344u => pc, 
				1589670345u => printer, 
				_ => openPark, 
			});
		}

		public static Transform Child(Transform root, string name)
		{
			for (int i = 0; i < root.childCount; i++)
			{
				if (((Object)root.GetChild(i)).name == name)
				{
					return root.GetChild(i);
				}
			}
			return null;
		}

		public static Transform PieceRoot(Transform t)
		{
			Transform val = t;
			while ((Object)(object)val != (Object)null)
			{
				if (((Object)val).name == "ParkEditor TicketPC 2" || ((Object)val).name == "ParkEditor TicketPrinter 2" || ((Object)val).name == "ParkEditor Window2 Switch")
				{
					return val;
				}
				val = val.parent;
			}
			return null;
		}

		public static string PieceTitle(Transform piece)
		{
			return Russian(KindOf(((Object)piece).name));
		}

		public static NetworkObject CreateForNetwork(uint kind, Vector3 position, Quaternion rotation)
		{
			//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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			switch (kind)
			{
			case 1589670343u:
				return CreateClone(position, rotation);
			case 1589670344u:
			case 1589670345u:
			case 1589670346u:
				return CreatePiece(kind, position, rotation);
			default:
				return null;
			}
		}

		public static NetworkObject CreateClone(Vector3 position, Quaternion rotation)
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			TicketStation val = Template();
			if ((Object)(object)val == (Object)null)
			{
				Plugin.L.LogError((object)"Second window: no TicketStation in this scene");
				return null;
			}
			GameObject obj = Object.Instantiate<GameObject>(((Component)val).gameObject, position, rotation);
			((Object)obj).name = "TicketStation (ParkEditor window 2)";
			NetworkObject component = obj.GetComponent<NetworkObject>();
			component.GlobalObjectIdHash = 1589670343u;
			TicketStation component2 = obj.GetComponent<TicketStation>();
			if ((Object)(object)component2 != (Object)null)
			{
				if ((Object)(object)((AttractionInteraction)val).Queue != (Object)null)
				{
					((AttractionInteraction)component2).Queue = ((AttractionInteraction)val).Queue;
				}
				((SimpleInteraction)component2).CanBeUsedByStaff = false;
			}
			Transform val2 = Child(obj.transform, "Queue");
			if ((Object)(object)val2 != (Object)null)
			{
				((Component)val2).gameObject.SetActive(false);
			}
			return component;
		}

		private static NetworkObject CreatePiece(uint kind, Vector3 position, Quaternion rotation)
		{
			//IL_00cc: 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)
			if (!_pending.Remove(kind, out var value) || (Object)(object)value == (Object)null)
			{
				foreach (GameObject value2 in _pending.Values)
				{
					if ((Object)(object)value2 != (Object)null)
					{
						Object.Destroy((Object)(object)value2);
					}
				}
				_pending.Clear();
				Dictionary<uint, GameObject> dictionary = BuildSet();
				if (dictionary == null || !dictionary.TryGetValue(kind, out value))
				{
					return null;
				}
				foreach (KeyValuePair<uint, GameObject> item in dictionary)
				{
					if (item.Key != kind)
					{
						_pending[item.Key] = item.Value;
					}
				}
			}
			return Activate(value, position, rotation, null);
		}

		private static Dictionary<uint, GameObject> BuildSet()
		{
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: 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_0041: Expected O, but got Unknown
			if (!DeskTemplates(out var printer, out var pc, out var openPark))
			{
				Plugin.L.LogError((object)"Second desk: no ticket printer/computer in this scene");
				return null;
			}
			Transform parent = printer.parent;
			if ((Object)(object)_holder == (Object)null)
			{
				_holder = new GameObject("ParkEditor (inactive copies)");
				_holder.SetActive(false);
			}
			GameObject val = Object.Instantiate<GameObject>(((Component)parent).gameObject, _holder.transform);
			val.transform.SetPositionAndRotation(parent.position, parent.rotation);
			Dictionary<uint, Transform> dictionary = new Dictionary<uint, Transform>
			{
				[1589670344u] = val.transform.GetChild(pc.GetSiblingIndex()),
				[1589670345u] = val.transform.GetChild(printer.GetSiblingIndex())
			};
			if ((Object)(object)openPark != (Object)null)
			{
				dictionary[1589670346u] = val.transform.GetChild(openPark.GetSiblingIndex());
			}
			Dictionary<uint, GameObject> dictionary2 = new Dictionary<uint, GameObject>();
			foreach (KeyValuePair<uint, Transform> item in dictionary)
			{
				dictionary2[item.Key] = Wrap(item.Value, NameOf(item.Key), item.Key);
			}
			Object.Destroy((Object)(object)val);
			if (dictionary2.TryGetValue(1589670346u, out var value))
			{
				try
				{
					SetupSwitch(value);
				}
				catch (Exception ex)
				{
					ManualLogSource l = Plugin.L;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Window 2 switch: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					l.LogError(val2);
					Object.Destroy((Object)(object)value);
					dictionary2.Remove(1589670346u);
				}
			}
			return dictionary2;
		}

		private static GameObject Wrap(Transform part, string name, uint hash)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name);
			val.transform.SetParent(_holder.transform, false);
			val.transform.SetPositionAndRotation(part.position, part.rotation);
			part.SetParent(val.transform, true);
			foreach (Paintable componentsInChild in ((Component)part).GetComponentsInChildren<Paintable>(true))
			{
				Object.DestroyImmediate((Object)(object)componentsInChild);
			}
			foreach (UniqueID componentsInChild2 in ((Component)part).GetComponentsInChildren<UniqueID>(true))
			{
				Object.DestroyImmediate((Object)(object)componentsInChild2);
			}
			val.AddComponent<NetworkObject>().GlobalObjectIdHash = hash;
			return val;
		}

		private static NetworkObject Activate(GameObject go, Vector3 position, Quaternion rotation, float? scale)
		{
			//IL_0013: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			go.transform.SetParent((Transform)null, false);
			go.transform.SetPositionAndRotation(position, rotation);
			if (scale.HasValue)
			{
				go.transform.localScale = Vector3.one * scale.Value;
			}
			return go.GetComponent<NetworkObject>();
		}

		private static void SetupSwitch(GameObject root)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: 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_0051: Expected O, but got Unknown
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Expected O, but got Unknown
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019c: Expected O, but got Unknown
			Transform child = root.transform.GetChild(0);
			child.localScale *= 0.35f;
			OpenParkButtonInteractable component = ((Component)child).GetComponent<OpenParkButtonInteractable>();
			string text = null;
			bool flag = default(bool);
			if ((Object)(object)component != (Object)null)
			{
				try
				{
					text = JsonUtility.ToJson((Object)(object)component);
				}
				catch (Exception ex)
				{
					ManualLogSource l = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(23, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Switch: copy settings: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex.Message);
					}
					l.LogWarning(val);
				}
				Object.DestroyImmediate((Object)(object)component);
			}
			InteractableBase val2 = ((Component)child).gameObject.AddComponent<InteractableBase>();
			if (text != null)
			{
				try
				{
					JsonUtility.FromJsonOverwrite(text, (Object)(object)val2);
				}
				catch (Exception ex2)
				{
					ManualLogSource l2 = Plugin.L;
					BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(24, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Switch: apply settings: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex2.Message);
					}
					l2.LogWarning(val);
				}
			}
			val2.OutlineController = ((Component)child).GetComponent<OutlineController>();
			val2.LockBehindGameState = false;
			val2.EnableOutlineOnGameStage = false;
			val2.CreateTaskOnEnable = false;
			val2.CreateTaskOnGameStage = false;
			val2.HighlightOnEnable = false;
			val2.SingleUseInteraction = false;
			val2.InteractionResetOnNewDay = false;
			val2.InteractedToday = false;
			val2.DestroyOnInteraction = false;
			val2.NeedItemForInteraction = false;
			val2.IsHeldInteraction = false;
			val2.HasProgress = false;
			val2.InteractionPrice = 0f;
			val2.OnlyAllowHostInteract = true;
			try
			{
				val2.LocalizedInteractionName = SwitchPrompt();
			}
			catch (Exception ex3)
			{
				ManualLogSource l3 = Plugin.L;
				BepInExWarningLogInterpolatedStringHandler val = new BepInExWarningLogInterpolatedStringHandler(16, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Switch: prompt: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(ex3.Message);
				}
				l3.LogWarning(val);
			}
			UnityEvent val3 = val2.OnInteraction;
			if (val3 == null)
			{
				val3 = (val2.OnInteraction = new UnityEvent());
			}
			for (int i = 0; i < ((UnityEventBase)val3).GetPersistentEventCount(); i++)
			{
				((UnityEventBase)val3).SetPersistentListenerState(i, (UnityEventCallState)0);
			}
			val3.AddListener(UnityAction.op_Implicit((Action)OnToggle));
			_switchColliders.Clear();
			foreach (Collider componentsInChild in ((Component)child).GetComponentsInChildren<Collider>(true))
			{
				componentsInChild.enabled = true;
				_switchColliders.Add(componentsInChild);
			}
			_switchTexts.Clear();
			foreach (TMP_Text componentsInChild2 in ((Component)child).GetComponentsInChildren<TMP_Text>(true))
			{
				foreach (Component component2 in ((Component)componentsInChild2).GetComponents<Component>())
				{
					if ((Object)(object)component2 != (Object)null && ((MemberInfo)((Object)component2).GetIl2CppType()).Name == "Localize")
					{
						Object.DestroyImmediate((Object)(object)component2);
					}
				}
				_switchTexts.Add(componentsInChild2);
			}
			_switchTexts.Sort((TMP_Text a, TMP_Text b) => string.CompareOrdinal(((Object)a).name, ((Object)b).name));
			_switchDome = null;
			foreach (Renderer componentsInChild3 in ((Component)child).GetComponentsInChildren<Renderer>(true))
			{
				if (((Object)componentsInChild3).name == "DayShiftButton")
				{
					_switchDome = componentsInChild3;
				}
			}
			UpdateLabel();
		}

		private static string[] TextsFor(string code)
		{
			if (code == null)
			{
				code = "en";
			}
			if (Texts.TryGetValue(code, out var value))
			{
				return value;
			}
			if (code.StartsWith("zh", StringComparison.OrdinalIgnoreCase))
			{
				return Texts[(code.Contains("TW", StringComparison.OrdinalIgnoreCase) || code.Contains("Hant", StringComparison.OrdinalIgnoreCase) || code.Contains("HK", StringComparison.OrdinalIgnoreCase)) ? "zh-TW" : "zh"];
			}
			int num = code.IndexOf('-');
			if (num > 0 && Texts.TryGetValue(code.Substring(0, num), out value))
			{
				return value;
			}
			return Texts["en"];
		}

		private static string LanguageCode()
		{
			try
			{
				return LocalizationManager.CurrentLanguageCode;
			}
			catch
			{
				return "en";
			}
		}

		private static LocalizedString SwitchPrompt()
		{
			List<LanguageSourceData> sources = LocalizationManager.Sources;
			if (sources != null && sources.Count > 0)
			{
				LanguageSourceData val = sources[0];
				TermData val2 = val.GetTermData("ParkEditor/Window2Switch", false) ?? val.AddTerm("ParkEditor/Window2Switch");
				int num = ((val.mLanguages != null) ? val.mLanguages.Count : 0);
				for (int i = 0; i < num; i++)
				{
					LanguageData obj = val.mLanguages[i];
					string code = ((obj != null) ? obj.Code : null);
					val2.SetTranslation(i, TextsFor(code)[3], (string)null);
				}
			}
			return LocalizedString.op_Implicit("ParkEditor/Window2Switch");
		}

		private static void OnToggle()
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			try
			{
				if (!IsHost)
				{
					Notify?.Invoke("Открыть/закрыть второе окно может хост");
					return;
				}
				WindowPlacement current = Current;
				if (current != null)
				{
					current.Closed = !current.Closed;
					SavePlacements();
					ApplyOpen();
					UpdateLabel();
					Notify?.Invoke(current.Closed ? "Второе окно кассы закрыто" : "Второе окно кассы открыто");
				}
			}
			catch (Exception ex)
			{
				ManualLogSource l = Plugin.L;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(17, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Window 2 toggle: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				l.LogError(val);
			}
		}

		private static void UpdateLabel()
		{
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
			_switchTexts.RemoveAll((TMP_Text t) => (Object)(object)t == (Object)null);
			WindowPlacement current = Current;
			bool flag = IsHost && current != null;
			bool flag2 = flag && current.Closed;
			string[] array = TextsFor(_shownLanguage = LanguageCode());
			if (_switchTexts.Count > 0)
			{
				_switchTexts[0].text = array[0];
				for (int num = 1; num < _switchTexts.Count; num++)
				{
					_switchTexts[num].text = ((!flag) ? "" : (flag2 ? array[2] : array[1]));
					if (flag)
					{
						((Graphic)_switchTexts[num]).color = (flag2 ? ClosedColor : OpenColor);
					}
				}
			}
			if ((Object)(object)_switchDome != (Object)null && flag)
			{
				Tint(_switchDome, flag2 ? ClosedColor : OpenColor);
			}
		}

		private static void Tint(Renderer r, Color c)
		{
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: 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_00ac: Unknown result type (might be due to invalid IL or missing references)
			foreach (Material item in (Il2CppArrayBase<Material>)(object)r.materials)
			{
				if (!((Object)(object)item == (Object)null))
				{
					if (item.HasProperty("_BaseMap"))
					{
						item.SetTexture("_BaseMap", (Texture)null);
					}
					if (item.HasProperty("_MainTex"))
					{
						item.SetTexture("_MainTex", (Texture)null);
					}
					if (item.HasProperty("_BaseColor"))
					{
						item.SetColor("_BaseColor", c);
					}
					if (item.HasProperty("_Color"))
					{
						item.SetColor("_Color", c);
					}
					if (item.HasProperty("_EmissionColor"))
					{
						item.EnableKeyword("_EMISSION");
						item.SetColor("_EmissionColor", c * 1.5f);
					}
				}
			}
		}

		private static void ApplyOpen()
		{
			if (!((Object)(object)_b == (Object)null))
			{
				WindowPlacement current = Current;
				((SimpleInteraction)_b).CanBeUsedByVisitor = current == null || !current.Closed;
				((SimpleInteraction)_b).CanBeUsedByStaff = false;
			}
		}

		public static void Tick()
		{
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0283: Expected O, but got Unknown
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Expected O, but got Unknown
			//IL_01e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null)
			{
				return;
			}
			if ((Object)(object)_registeredOn == (Object)null || ((Il2CppObjectBase)_registeredOn).Pointer != ((Il2CppObjectBase)singleton).Pointer)
			{
				uint[] array = new uint[4] { 1589670343u, 1589670344u, 1589670345u, 1589670346u };
				foreach (uint num in array)
				{
					if (!_handlers.TryGetValue(num, out var value))
					{
						Dictionary<uint, WindowHandler> handlers = _handlers;
						WindowHandler obj = new WindowHandler
						{
							Kind = num
						};
						value = obj;
						handlers[num] = obj;
					}
					if (!singleton.PrefabHandler.ContainsHandler(num))
					{
						singleton.PrefabHandler.AddHandler(num, new INetworkPrefabInstanceHandler(((Il2CppObjectBase)value).Pointer));
					}
				}
				_registeredOn = singleton;
				_piecesFailed = false;
				Plugin.L.LogInfo((object)"Second window: prefab handlers registered");
			}
			foreach (Collider switchCollider in _switchColliders)
			{
				if ((Object)(object)switchCollider != (Object)null && !switchCollider.enabled)
				{
					switchCollider.enabled = true;
				}
			}
			if (_switchTexts.Count > 0 && Time.unscaledTime >= _nextLangCheck)
			{
				_nextLangCheck = Time.unscaledTime + 1f;
				if (LanguageCode() != _shownLanguage)
				{
					UpdateLabel();
				}
			}
			if (!singleton.IsListening || !singleton.IsServer)
			{
				return;
			}
			if (_respawnAt > 0f && Time.unscaledTime >= _respawnAt)
			{
				_respawnAt = -1f;
				Despawn();
			}
			if (_respawnPiecesAt > 0f && Time.unscaledTime >= _respawnPiecesAt)
			{
				_respawnPiecesAt = -1f;
				DespawnPieces();
			}
			WindowPlacement current2 = Current;
			if (current2 == null)
			{
				return;
			}
			if ((Object)(object)Spawned == (Object)null)
			{
				if ((Object)(object)Template() == (Object)null)
				{
					return;
				}
				NetworkObject val = CreateClone(Store.V(current2.Pos), Quaternion.Euler(0f, current2.Yaw, 0f));
				if ((Object)(object)val == (Object)null)
				{
					return;
				}
				val.Spawn(true);
				_spawned = val;
				_b = null;
				Plugin.L.LogInfo((object)"Second window spawned");
			}
			if (!_piecesFailed && !PieceKinds.All((uint k) => _pieces.TryGetValue(k, out var value2) && Alive(value2)))
			{
				try
				{
					SpawnPieces(current2);
				}
				catch (Exception ex)
				{
					_piecesFailed = true;
					ManualLogSource l = Plugin.L;
					bool flag = default(bool);
					BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(13, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Second desk: ");
						((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
					}
					l.LogError(val2);
				}
			}
			Dispatch();
		}

		private static void SpawnPieces(WindowPlacement p)
		{
			//IL_005b: 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_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: 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)
			//IL_0099: 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_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_0173: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Expected O, but got Unknown
			//IL_0127: 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)
			DespawnPieces();
			TicketStation val = Template();
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			bool flag = false;
			uint[] pieceKinds = PieceKinds;
			foreach (uint kind in pieceKinds)
			{
				if (PoseOf(p, kind) == null)
				{
					Transform val2 = TemplateOf(kind);
					if (!((Object)(object)val2 == (Object)null))
					{
						Quaternion val3 = Quaternion.Euler(0f, p.Yaw, 0f) * Quaternion.Inverse(((Component)val).transform.rotation);
						SetPose(p, kind, Pose(Store.V(p.Pos) + val3 * (val2.position - ((Component)val).transform.position), val3 * val2.rotation, 1f));
						flag = true;
					}
				}
			}
			if (flag)
			{
				SavePlacements();
			}
			Dictionary<uint, GameObject> dictionary = BuildSet();
			if (dictionary == null)
			{
				_piecesFailed = true;
				return;
			}
			pieceKinds = PieceKinds;
			foreach (uint num in pieceKinds)
			{
				if (dictionary.TryGetValue(num, out var value))
				{
					float[] array = PoseOf(p, num);
					if (array == null)
					{
						Object.Destroy((Object)(object)value);
						continue;
					}
					NetworkObject val4 = Activate(value, PosOf(array), RotOf(array), ScaleOf(array));
					val4.Spawn(true);
					_pieces[num] = val4;
				}
			}
			ManualLogSource l = Plugin.L;
			bool flag2 = default(bool);
			BepInExInfoLogInterpolatedStringHandler val5 = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag2);
			if (flag2)
			{
				((BepInExLogInterpolatedStringHandler)val5).AppendLiteral("Second desk spawned: ");
				((BepInExLogInterpolatedStringHandler)val5).AppendFormatted<string>(string.Join(", ", _pieces.Keys.Select(Russian)));
			}
			l.LogInfo(val5);
		}

		private static float[] Pose(Vector3 pos, Quaternion rot, float scale)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0035: 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)
			return new float[8] { pos.x, pos.y, pos.z, rot.x, rot.y, rot.z, rot.w, scale };
		}

		private static Vector3 PosOf(float[] a)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(a[0], a[1], a[2]);
		}

		private static Quaternion RotOf(float[] a)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(a[3], a[4], a[5], a[6]);
		}

		private static float ScaleOf(float[] a)
		{
			if (a.Length <= 7 || !(a[7] > 0f))
			{
				return 1f;
			}
			return a[7];
		}

		private static void Dispatch()
		{
			if ((Object)(object)_a == (Object)null)
			{
				_a = Template();
			}
			if ((Object)(object)_b == (Object)null || ((Il2CppObjectBase)_b).Pointer == IntPtr.Zero)
			{
				_b = ((Component)_spawned).GetComponent<TicketStation>();
				ApplyOpen();
			}
			if ((Object)(object)_a == (Object)null || (Object)(object)_b == (Object)null)
			{
				return;
			}
			VisitorQueue queue = ((AttractionInteraction)_a).Queue;
			if ((Object)(object)queue == (Object)null || queue.Queue == null || queue.Queue.Count == 0)
			{
				return;
			}
			WindowPlacement current = Current;
			if (current != null && current.Closed)
			{
				for (int i = 0; i < queue.Queue.Count; i++)
				{
					AIBrain val = queue.Queue[i];
					if ((Object)(object)val != (Object)null && (Object)(object)val.TargetInteraction != (Object)null && ((Il2CppObjectBase)val.TargetInteraction).Pointer == ((Il2CppObjectBase)_b).Pointer)
					{
						val.TargetInteraction = (SimpleInteraction)(object)_a;
					}
				}
				return;
			}
			AIBrain val2 = queue.Queue[0];
			if ((Object)(object)val2 == (Object)null)
			{
				return;
			}
			SimpleInteraction targetInteraction = val2.TargetInteraction;
			if (!((Object)(object)targetInteraction == (Object)null))
			{
				bool areInteractionSlotsFree = ((AttractionInteraction)_a).AreInteractionSlotsFree;
				bool areInteractionSlotsFree2 = ((AttractionInteraction)_b).AreInteractionSlotsFree;
				TicketStation val3 = null;
				if (((Il2CppObjectBase)targetInteraction).Pointer == ((Il2CppObjectBase)_a).Pointer && !areInteractionSlotsFree && areInteractionSlotsFree2)
				{
					val3 = _b;
				}
				else if (((Il2CppObjectBase)targetInteraction).Pointer == ((Il2CppObjectBase)_b).Pointer && !areInteractionSlotsFree2 && areInteractionSlotsFree)
				{
					val3 = _a;
				}
				if (!((Object)(object)val3 == (Object)null))
				{
					val2.TargetInteraction = (SimpleInteraction)(object)val3;
				}
			}
		}

		private static void Despawn()
		{
			_b = null;
			if ((Object)(object)Spawned != (Object)null)
			{
				_spawned.Despawn(true);
			}
			_spawned = null;
			DespawnPieces();
		}

		private static void DespawnPieces()
		{
			foreach (NetworkObject value in _pieces.Values)
			{
				if (Alive(value))
				{
					value.Despawn(true);
				}
			}
			_pieces.Clear();
			_switchTexts.Clear();
		}

		public static string Place(Vector3 standPoint)
		{
			//IL_004e: 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_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: 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_0082: 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_0092: 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)
			if (!IsHost)
			{
				return "Второе окно ставит только хост";
			}
			TicketStation val = Template();
			if ((Object)(object)val == (Object)null)
			{
				return "На этой карте нет кассы";
			}
			Transform transform = ((Component)val).transform;
			Transform val2 = Child(transform, "Interaction Position");
			if ((Object)(object)val2 == (Object)null)
			{
				return "У кассы нет точки для гостя";
			}
			float num = Current?.Yaw ?? transform.eulerAngles.y;
			Quaternion val3 = Quaternion.Euler(0f, num - transform.eulerAngles.y, 0f);
			Save(standPoint + val3 * (transform.position - val2.position), num);
			return "Второе окно кассы поставлено";
		}

		public static string Nudge(Vector3 delta, float dyaw)
		{
			//IL_003a: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: 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_006c: 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_007c: 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_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: 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_00a8: 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_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ba: 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_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_00d5: 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_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			WindowPlacement current = Current;
			if (current == null || !IsHost)
			{
				return null;
			}
			TicketStation val = Template();
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Transform val2 = Child(((Component)val).transform, "Interaction Position");
			Vector3 val3 = Store.V(current.Pos);
			Quaternion val4 = Quaternion.Euler(0f, current.Yaw, 0f);
			Vector3 val5 = val3 + val4 * Quaternion.Inverse(((Component)val).transform.rotation) * (val2.position - ((Component)val).transform.position);
			float num = current.Yaw + dyaw;
			Quaternion val6 = Quaternion.Euler(0f, num, 0f);
			Save(val5 - val6 * Quaternion.Inverse(((Component)val).transform.rotation) * (val2.position - ((Component)val).transform.position) + delta, num);
			return null;
		}

		public static string Remove()
		{
			if (!IsHost)
			{
				return "Убрать второе окно может только хост";
			}
			WindowPlacement current = Current;
			if (current == null)
			{
				return "Второго окна нет";
			}
			_placements.Remove(current);
			SavePlacements();
			Despawn();
			return "Второе окно кассы убрано";
		}

		private static void Save(Vector3 rootPos, float yaw)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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)
			Scene activeScene = SceneManager.GetActiveScene();
			string scene = ((Scene)(ref activeScene)).name;
			WindowPlacement windowPlacement = _placements.FirstOrDefault((WindowPlacement x) => x.Scene == scene);
			_placements.RemoveAll((WindowPlacement x) => x.Scene == scene);
			_placements.Add(new WindowPlacement
			{
				Scene = scene,
				Pos = Store.V(rootPos),
				Yaw = yaw,
				Pc = windowPlacement?.Pc,
				Printer = windowPlacement?.Printer,
				Switch = windowPlacement?.Switch,
				Closed = (windowPlacement?.Closed ?? false)
			});
			SavePlacements();
			_respawnAt = Time.unscaledTime + 0.4f;
		}

		public static bool CopyPlacement(string fromScene, Func<Vector3, Vector3> map, Quaternion turn)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			if (!IsHost)
			{
				return false;
			}
			WindowPlacement windowPlacement = _placements.FirstOrDefault((WindowPlacement x) => x.Scene == fromScene);
			if (windowPlacement == null)
			{
				return false;
			}
			Scene activeScene = SceneManager.GetActiveScene();
			string scene = ((Scene)(ref activeScene)).name;
			try
			{
				if (File.Exists(FilePath))
				{
					File.Copy(FilePath, Path.Combine(Plugin.DataDir, "window2.before-copy.json"), overwrite: true);
				}
			}
			catch
			{
			}
			_placements.RemoveAll((WindowPlacement x) => x.Scene == scene);
			_placements.Add(new WindowPlacement
			{
				Scene = scene,
				Pos = Store.V(map(Store.V(windowPlacement.Pos))),
				Yaw = (windowPlacement.Yaw + ((Quaternion)(ref turn)).eulerAngles.y) % 360f,
				Pc = Piece(windowPlacement.Pc),
				Printer = Piece(windowPlacement.Printer),
				Switch = Piece(windowPlacement.Switch),
				Closed = windowPlacement.Closed
			});
			SavePlacements();
			_respawnAt = Time.unscaledTime + 0.2f;
			return true;
			float[] Piece(float[] a)
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//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)
				//IL_001b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				if (a != null)
				{
					return Pose(map(PosOf(a)), turn * RotOf(a), ScaleOf(a));
				}
				return null;
			}
		}

		public static string SetPiecePose(Transform piece, Vector3 pos, Quaternion rot, float scale)
		{
			//IL_0024: 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)
			if (!IsHost)
			{
				return "Второе окно и его вещи двигает только хост";
			}
			WindowPlacement current = Current;
			if (current == null)
			{
				return null;
			}
			SetPose(current, KindOf(((Object)piece).name), Pose(pos, rot, scale));
			SavePlacements();
			_respawnPiecesAt = Time.unscaledTime + 0.4f;
			return null;
		}

		public static string ResetPiece(Transform piece)
		{
			if (!IsHost)
			{
				return "Второе окно и его вещи двигает только хост";
			}
			WindowPlacement current = Current;
			if (current == null)
			{
				return null;
			}
			uint kind = KindOf(((Object)piece).name);
			SetPose(current, kind, null);
			SavePlacements();
			_respawnPiecesAt = Time.unscaledTime + 0.1f;
			return "Вернул на место у окна 2: " + Russian(kind);
		}

		public static List<(Vector3 pos, string label)> PreviewPoints()
		{
			//IL_003a: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			List<(Vector3, string)> list = new List<(Vector3, string)>();
			NetworkObject spawned = Spawned;
			if ((Object)(object)spawned == (Object)null)
			{
				return list;
			}
			Transform transform = ((Component)spawned).transform;
			Transform val = Child(transform, "Interaction Position");
			WindowPlacement current = Current;
			if ((Object)(object)val != (Object)null)
			{
				list.Add((val.position, (current != null && current.Closed) ? "ГОСТЬ (окно 2 закрыто)" : "ГОСТЬ (окно 2)"));
			}
			Transform val2 = Child(transform, "Staff Spot");
			if ((Object)(object)val2 != (Object)null)
			{
				list.Add((val2.position, "КАССИР 2 (только игрок)"));
			}
			Transform val3 = Child(transform, "Exit Point");
			if ((Object)(object)val3 != (Object)null)
			{
				list.Add((val3.position, "выход 2"));
			}
			return list;
		}
	}
	public sealed class Move
	{
		public string Path { get; set; }

		public float[] OrigPos { get; set; }

		public float[] OrigRot { get; set; }

		public float[] Pos { get; set; }

		public float[] Rot { get; set; }

		public float[] OrigScale { get; set; }

		public float[] Scale { get; set; }

		public List<string> Attached { get; set; }
	}
	internal static class Store
	{
		private static readonly JsonSerializerOptions Json = new JsonSerializerOptions
		{
			WriteIndented = true
		};

		public static List<Move> Moves = new List<Move>();

		private static string FilePath => Path.Combine(Plugin.DataDir, "moves.json");

		public static void Load()
		{
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				string text = Plugin.ReadData("moves.json");
				Moves = ((text != null) ? (JsonSerializer.Deserialize<List<Move>>(text) ?? new List<Move>()) : new List<Move>());
				Moves.RemoveAll((Move m) => m.Path.Contains("Blocker") || m.Path.Contains("UnlockingAreas") || m.Path.Contains("/Blueprint[") || m.Path.Contains("(Clone)"));
				ManualLogSource l = Plugin.L;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Booth layout: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Moves.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" objects");
				}
				l.LogInfo(val);
			}
			catch (Exception ex)
			{
				ManualLogSource l2 = Plugin.L;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(12, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("moves.json: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
				}
				l2.LogError(val2);
				Moves = new List<Move>();
			}
		}

		public static void Save()
		{
		}

		public static void Backup(string tag)
		{
		}

		public static Move Get(string path)
		{
			return Moves.FirstOrDefault((Move m) => m.Path == path);
		}

		public static float[] V(Vector3 v)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			return new float[3] { v.x, v.y, v.z };
		}

		public static float[] Q(Quaternion q)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			return new float[4] { q.x, q.y, q.z, q.w };
		}

		public static Vector3 V(float[] a)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			return new Vector3(a[0], a[1], a[2]);
		}

		public static Quaternion Q(float[] a)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			return new Quaternion(a[0], a[1], a[2], a[3]);
		}

		public static string PathOf(Transform t)
		{
			//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_0075: 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)
			List<string> list = new List<string>();
			Transform val = t;
			Scene scene;
			while ((Object)(object)val != (Object)null)
			{
				int num = 0;
				Transform parent = val.parent;
				if ((Object)(object)parent != (Object)null)
				{
					for (int i = 0; i < parent.childCount; i++)
					{
						Transform child = parent.GetChild(i);
						if (((Il2CppObjectBase)child).Pointer == ((Il2CppObjectBase)val).Pointer)
						{
							break;
						}
						if (((Object)child).name == ((Object)val).name)
						{
							num++;
						}
					}
				}
				else
				{
					scene = ((Component)val).gameObject.scene;
					foreach (GameObject item in (Il2CppArrayBase<GameObject>)(object)((Scene)(ref scene)).GetRootGameObjects())
					{
						if (((Il2CppObjectBase)item.transform).Pointer == ((Il2CppObjectBase)val).Pointer)
						{
							break;
						}
						if (((Object)item).name == ((Object)val).name)
						{
							num++;
						}
					}
				}
				list.Add($"{((Object)val).name}[{num}]");
				val = val.parent;
			}
			list.Reverse();
			scene = ((Component)t).gameObject.scene;
			return ((Scene)(ref scene)).name + ":" + string.Join("/", list);
		}

		public static Transform Find(string path)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			int num = path.IndexOf(':');
			if (num < 0)
			{
				return null;
			}
			Scene sceneByName = SceneManager.GetSceneByName(path.Substring(0, num));
			if (!((Scene)(ref sceneByName)).IsValid() || !((Scene)(ref sceneByName)).isLoaded)
			{
				return null;
			}
			string[] array = path.Substring(num + 1).Split('/');
			if (!Parse(array[0], out var name, out var idx))
			{
				return null;
			}
			Transform val = null;
			int num2 = 0;
			foreach (GameObject item in (Il2CppArrayBase<GameObject>)(object)((Scene)(ref sceneByName)).GetRootGameObjects())
			{
				if (((Object)item).name == name && num2++ == idx)
				{
					val = item.transform;
					break;
				}
			}
			int num3 = 1;
			while ((Object)(object)val != (Object)null && num3 < array.Length)
			{
				if (!Parse(array[num3], out name, out idx))
				{
					return null;
				}
				Transform val2 = null;
				num2 = 0;
				for (int i = 0; i < val.childCount; i++)
				{
					Transform child = val.GetChild(i);
					if (((Object)child).name == name && num2++ == idx)
					{
						val2 = child;
						break;
					}
				}
				val = val2;
				num3++;
			}
			return val;
		}

		private static bool Parse(string part, out string name, out int idx)
		{
			name = part;
			idx = 0;
			int num = part.LastIndexOf('[');
			if (num < 0 || !part.EndsWith("]"))
			{
				return false;
			}
			name = part.Substring(0, num);
			int num2 = num + 1;
			return int.TryParse(part.Substring(num2, part.Length - 1 - num2), out idx);
		}
	}
}