Decompiled source of FamBook v3.2.1

FamBook.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using FamBook.Services;
using FamBook.Utilities;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Microsoft.CodeAnalysis;
using ProjectM;
using ProjectM.Hybrid;
using ProjectM.Network;
using ProjectM.Physics;
using ProjectM.Scripting;
using ProjectM.UI;
using TMPro;
using Unity.Collections;
using Unity.Entities;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("FamBook")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("3.2.1.0")]
[assembly: AssemblyInformationalVersion("3.2.1+9bdcad0524e6d04bf05014dbd64ef20643edeb45")]
[assembly: AssemblyProduct("FamBook")]
[assembly: AssemblyTitle("FamBook")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("3.2.1.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.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 FamBook
{
	internal static class Core
	{
		private static World? _client;

		private static SystemService? _systemService;

		private static Entity _localCharacter = Entity.Null;

		private static Entity _localUser = Entity.Null;

		private static MonoBehaviour? _monoBehaviour;

		private static bool _initialized;

		public static Entity LocalCharacter => _localCharacter.Exists() ? _localCharacter : (ConsoleShared.TryGetLocalCharacterInCurrentWorld(ref _localCharacter, _client) ? _localCharacter : Entity.Null);

		public static Entity LocalUser => _localUser.Exists() ? _localUser : (ConsoleShared.TryGetLocalUserInCurrentWorld(ref _localUser, _client) ? _localUser : Entity.Null);

		public static EntityManager EntityManager => _client.EntityManager;

		public static SystemService SystemService => _systemService ?? (_systemService = new SystemService(_client));

		public static ClientGameManager ClientGameManager => SystemService.ClientScriptMapper._ClientGameManager;

		public static CanvasService? CanvasService { get; set; }

		public static ServerTime ServerTime => ClientGameManager.ServerTime;

		public static ManualLogSource Log => Plugin.LogInstance;

		public static bool HasInitialized => _initialized;

		public static void Initialize(GameDataManager gameDataManager)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			if (!_initialized)
			{
				_client = ((ComponentSystemBase)gameDataManager).World;
				_initialized = true;
				ManualLogSource log = Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(27, 0, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Core initialized.");
				}
				log.LogInfo(val);
			}
		}

		public static void Reset()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			_client = null;
			_systemService = null;
			CanvasService = null;
			_initialized = false;
			_localCharacter = Entity.Null;
			_localUser = Entity.Null;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(21, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Core reset.");
			}
			log.LogInfo(val);
		}

		public static void SetCanvas(UICanvasBase canvas)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			CanvasService = new CanvasService(canvas);
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(37, 0, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Canvas service initialized.");
			}
			log.LogInfo(val);
		}

		public static Coroutine StartCoroutine(IEnumerator routine)
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			if ((Object)(object)_monoBehaviour == (Object)null)
			{
				GameObject val = new GameObject("FamBook");
				_monoBehaviour = (MonoBehaviour?)(object)val.AddComponent<IgnorePhysicsDebugSystem>();
				Object.DontDestroyOnLoad((Object)(object)val);
			}
			return _monoBehaviour.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(routine));
		}

		public static void StopCoroutine(Coroutine routine)
		{
			if (!((Object)(object)_monoBehaviour == (Object)null))
			{
				_monoBehaviour.StopCoroutine(routine);
			}
		}
	}
	[BepInPlugin("com.fambook.vrising", "FamBook", "3.2.1")]
	internal class Plugin : BasePlugin
	{
		private Harmony _harmony = null;

		private static ConfigEntry<bool> _familiarsPanel;

		private static ConfigEntry<bool> _showActiveIndicator;

		private static ConfigEntry<bool> _eclipsed;

		internal static Plugin Instance { get; private set; }

		public static ManualLogSource LogInstance => ((BasePlugin)Instance).Log;

		public static bool FamiliarsPanel => _familiarsPanel.Value;

		public static bool ShowActiveIndicator => _showActiveIndicator.Value;

		public static bool Eclipsed => _eclipsed.Value;

		public override void Load()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Expected O, but got Unknown
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			Instance = this;
			bool flag = default(bool);
			if (!Application.productName.Equals("VRising", StringComparison.OrdinalIgnoreCase))
			{
				ManualLogSource log = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(43, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("FamBook");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("3.2.1");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] is a client mod – skipping on server (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(Application.productName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogInfo(val);
			}
			else
			{
				_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), (string)null);
				InitConfig();
				ManualLogSource log2 = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(20, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("FamBook");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("3.2.1");
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("] loaded on client!");
				}
				log2.LogInfo(val);
			}
		}

		private static void InitConfig()
		{
			_familiarsPanel = InitConfigEntry("UIOptions", "FamiliarsPanel", defaultValue: true, "Enable/Disable the familiars panel that lists all unlocked familiars.");
			_showActiveIndicator = InitConfigEntry("UIOptions", "ShowActiveIndicator", defaultValue: true, "Highlight the currently active familiar in the panel.");
			_eclipsed = InitConfigEntry("UIOptions", "Eclipsed", defaultValue: true, "Set to false for slower update intervals (0.1s -> 1s) if performance is negatively impacted.");
		}

		private static ConfigEntry<T> InitConfigEntry<T>(string section, string key, T defaultValue, string description)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected O, but got Unknown
			ConfigEntry<T> val = ((BasePlugin)Instance).Config.Bind<T>(section, key, defaultValue, description);
			ConfigFile val2 = new ConfigFile(Path.Combine(Paths.ConfigPath, "com.fambook.vrising.cfg"), true);
			ConfigEntry<T> val3 = default(ConfigEntry<T>);
			if (val2.TryGetEntry<T>(section, key, ref val3))
			{
				val.Value = val3.Value;
			}
			return val;
		}

		public override bool Unload()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			return true;
		}
	}
	internal static class VExtensions
	{
		private static EntityManager EntityManager => Core.EntityManager;

		public static bool Has<T>(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = EntityManager;
			return ((EntityManager)(ref entityManager)).HasComponent<T>(entity);
		}

		public static bool Exists(this Entity entity)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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)
			int result;
			if (entity != Entity.Null)
			{
				EntityManager entityManager = EntityManager;
				result = (((EntityManager)(ref entityManager)).Exists(entity) ? 1 : 0);
			}
			else
			{
				result = 0;
			}
			return (byte)result != 0;
		}

		public static T Read<T>(this Entity entity) where T : struct
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = EntityManager;
			T val = default(T);
			return ((EntityManager)(ref entityManager)).TryGetComponentData<T>(entity, ref val) ? val : default(T);
		}

		public static void Write<T>(this Entity entity, T componentData) where T : struct
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			if (entity.Has<T>())
			{
				EntityManager entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<T>(entity, componentData);
			}
		}

		public static NetworkId GetNetworkId(this Entity entity)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: 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_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			EntityManager entityManager = EntityManager;
			NetworkId result = default(NetworkId);
			if (((EntityManager)(ref entityManager)).TryGetComponentData<NetworkId>(entity, ref result))
			{
				return result;
			}
			return NetworkId.Empty;
		}

		public static Coroutine Run(this IEnumerator routine)
		{
			return Core.StartCoroutine(routine);
		}

		public static void Stop(this Coroutine routine)
		{
			if (routine != null)
			{
				Core.StopCoroutine(routine);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.fambook.vrising";

		public const string PLUGIN_NAME = "FamBook";

		public const string PLUGIN_VERSION = "3.2.1";
	}
}
namespace FamBook.Utilities
{
	internal static class CommandSender
	{
		private static FromCharacter? _fromCharacter;

		private static readonly ComponentType[] _componentTypes = (ComponentType[])(object)new ComponentType[4]
		{
			ComponentType.ReadOnly(Il2CppType.Of<FromCharacter>()),
			ComponentType.ReadOnly(Il2CppType.Of<NetworkEventType>()),
			ComponentType.ReadOnly(Il2CppType.Of<SendNetworkEventTag>()),
			ComponentType.ReadOnly(Il2CppType.Of<ChatMessageEvent>())
		};

		private static readonly NetworkEventType _networkEventType = new NetworkEventType
		{
			IsAdminEvent = false,
			EventId = NetworkEvents.EventId_ChatMessageEvent,
			IsDebugEvent = false
		};

		private static EntityManager EntityManager => Core.EntityManager;

		private static Entity LocalCharacter => Core.LocalCharacter;

		private static Entity LocalUser => Core.LocalUser;

		private static FromCharacter FromCharacter
		{
			get
			{
				//IL_0005: Unknown result type (might be due to invalid IL or missing references)
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: 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_0021: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_002d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0032: 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_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				FromCharacter valueOrDefault = _fromCharacter.GetValueOrDefault();
				FromCharacter result;
				if (!_fromCharacter.HasValue)
				{
					FromCharacter val = default(FromCharacter);
					val.Character = LocalCharacter;
					val.User = LocalUser;
					valueOrDefault = val;
					_fromCharacter = valueOrDefault;
					result = valueOrDefault;
				}
				else
				{
					result = valueOrDefault;
				}
				return result;
			}
		}

		public static void Send(string command)
		{
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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_0098: 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_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Expected O, but got Unknown
			if (Core.HasInitialized && !(LocalCharacter == Entity.Null) && !(LocalUser == Entity.Null))
			{
				ChatMessageEvent val = default(ChatMessageEvent);
				val.MessageText = new FixedString512Bytes(command);
				val.MessageType = (ChatMessageType)4;
				val.ReceiverEntity = LocalUser.GetNetworkId();
				ChatMessageEvent val2 = val;
				EntityManager entityManager = EntityManager;
				Entity val3 = ((EntityManager)(ref entityManager)).CreateEntity(_componentTypes);
				entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<FromCharacter>(val3, FromCharacter);
				entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<NetworkEventType>(val3, _networkEventType);
				entityManager = EntityManager;
				((EntityManager)(ref entityManager)).SetComponentData<ChatMessageEvent>(val3, val2);
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val4 = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[FamBook] Sent command: ");
					((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(command);
				}
				log.LogInfo(val4);
			}
		}

		public static void RequestBoxData(int boxIndex)
		{
			Send($".fam cb box{boxIndex + 1}");
			Send(".fam l");
			DataService.BeginAwaitingResponse();
		}

		public static void Reset()
		{
			_fromCharacter = null;
		}
	}
	internal static class GameObjects
	{
		public static Transform? FindChildRecursive(Transform parent, string name)
		{
			if (((Object)parent).name == name)
			{
				return parent;
			}
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform val = FindChildRecursive(parent.GetChild(i), name);
				if ((Object)(object)val != (Object)null)
				{
					return val;
				}
			}
			return null;
		}

		public static GameObject? FindTargetObject(Transform parent, string name)
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Expected O, but got Unknown
			Transform val = FindChildRecursive(parent, name);
			if ((Object)(object)val == (Object)null)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(42, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[FamBook] Could not find child '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("' under '");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(((Object)parent).name);
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("'");
				}
				log.LogWarning(val2);
			}
			return (val != null) ? ((Component)val).gameObject : null;
		}

		public static void DeactivateChildrenExcept(Transform parent, string keepName)
		{
			for (int i = 0; i < parent.childCount; i++)
			{
				Transform child = parent.GetChild(i);
				if (!((Object)child).name.Equals(keepName, StringComparison.Ordinal))
				{
					((Component)child).gameObject.SetActive(false);
				}
			}
		}
	}
}
namespace FamBook.Services
{
	internal class CanvasService
	{
		[CompilerGenerated]
		private sealed class <UpdateLoop>d__29 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			private Exception <ex>5__1;

			private ManualLogSource <>s__2;

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

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

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

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

			private bool MoveNext()
			{
				//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c1: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if (_killSwitch)
				{
					return false;
				}
				if (_ready)
				{
					DataService.FinalizeIfExpired();
					DataService.FinalizeListIfExpired();
					if (_showingBoxList && _currentListedBoxIndex == -1 && DataService.LastListedBoxNames.Count > 0)
					{
						_currentListedBoxIndex = 0;
					}
					if (_bookOpen && DataService.IsDirty)
					{
						try
						{
							RefreshBookPage();
							DataService.IsDirty = false;
						}
						catch (Exception ex)
						{
							<ex>5__1 = ex;
							<>s__2 = Core.Log;
							bool flag = default(bool);
							BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Update error: ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(<ex>5__1);
							}
							<>s__2.LogError(val);
							<>s__2 = null;
						}
					}
				}
				<>2__current = WaitForSeconds;
				<>1__state = 1;
				return true;
			}

			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 <VBloodScanPage>d__41 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public int pageIndex;

			private List<List<string>> <pages>5__1;

			private List<string> <page>5__2;

			private int <i>5__3;

			private string <vb>5__4;

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

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

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

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<pages>5__1 = null;
				<page>5__2 = null;
				<vb>5__4 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					if (_vbloodScanning)
					{
						return false;
					}
					_vbloodScanning = true;
					<pages>5__1 = DataService.VbloodPages;
					if (<pages>5__1 == null || <pages>5__1.Count == 0 || pageIndex < 0 || pageIndex >= <pages>5__1.Count)
					{
						_vbloodScanning = false;
						return false;
					}
					_vbloodPage = pageIndex;
					RefreshBookPage();
					<page>5__2 = <pages>5__1[pageIndex];
					<i>5__3 = 0;
					goto IL_01d3;
				case 1:
					<>1__state = -1;
					goto IL_0173;
				case 2:
					{
						<>1__state = -1;
						<vb>5__4 = null;
						goto IL_01c1;
					}
					IL_01c1:
					<i>5__3++;
					goto IL_01d3;
					IL_01d3:
					if (<i>5__3 >= <page>5__2.Count || !_bookOpen || !_showingVBloodList)
					{
						break;
					}
					<vb>5__4 = <page>5__2[<i>5__3];
					if (DataService.VbloodResults.ContainsKey(<vb>5__4))
					{
						goto IL_01c1;
					}
					CommandSender.Send(".fam s \"" + <vb>5__4 + "\"");
					DataService.BeginAwaitingSearch(<vb>5__4);
					goto IL_0173;
					IL_0173:
					if (DataService.AwaitingSearch && _bookOpen && _showingVBloodList)
					{
						<>2__current = WaitForSeconds;
						<>1__state = 1;
						return true;
					}
					if (!_bookOpen || !_showingVBloodList)
					{
						break;
					}
					RefreshBookPage();
					<>2__current = WaitForSeconds;
					<>1__state = 2;
					return true;
				}
				_vbloodScanning = false;
				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 BOOK_W = 310f;

		private const float BOOK_H = 380f;

		private const float HEADER_H = 30f;

		private const float SEP_H = 2f;

		private const float NAV_H = 66f;

		private const float CARD_H = 26f;

		private const float CARD_GAP = 2f;

		private const int MAX_CARDS = 10;

		private static readonly WaitForSeconds _fastWait = new WaitForSeconds(0.1f);

		private static readonly WaitForSeconds _slowWait = new WaitForSeconds(1f);

		private static bool _ready;

		private static bool _bookOpen;

		private static bool _killSwitch;

		private static Canvas? _bottomBarCanvas;

		private static int _layer;

		private static GameObject? _iconButton;

		private static GameObject? _bookPanel;

		private static GameObject? _cardsContainer;

		private static TextMeshProUGUI? _pageLabel;

		private static readonly List<FamiliarCard> _cards = new List<FamiliarCard>();

		private static bool _showingVBloodList = false;

		private static int _vbloodPage = 0;

		private static bool _vbloodScanning = false;

		private static bool _showingBoxList = false;

		private static int _boxListPage = 0;

		private static int _currentListedBoxIndex = -1;

		private static WaitForSeconds WaitForSeconds => Plugin.Eclipsed ? _fastWait : _slowWait;

		internal CanvasService(UICanvasBase canvas)
		{
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			_killSwitch = false;
			_ready = false;
			_bookOpen = false;
			_cards.Clear();
			_bottomBarCanvas = ((Component)canvas.BottomBarParent).gameObject.GetComponent<Canvas>();
			_layer = ((Component)_bottomBarCanvas).gameObject.layer;
			if (!Plugin.FamiliarsPanel)
			{
				return;
			}
			try
			{
				BuildIconButton();
				BuildBookPanel();
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Failed to build HUD: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_bookOpen = false;
			GameObject? bookPanel = _bookPanel;
			if (bookPanel != null)
			{
				bookPanel.SetActive(false);
			}
			if ((Object)(object)_iconButton != (Object)null)
			{
				_ready = true;
				Core.StartCoroutine(UpdateLoop());
			}
		}

		[IteratorStateMachine(typeof(<UpdateLoop>d__29))]
		private static IEnumerator UpdateLoop()
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <UpdateLoop>d__29(0);
		}

		private static void BuildIconButton()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Expected O, but got Unknown
			//IL_012a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			_iconButton = new GameObject("FamBook_Icon");
			AttachToCanvas(_iconButton);
			RectTransform val = _iconButton.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0f, 0f);
			val.anchorMax = new Vector2(0f, 0f);
			val.pivot = new Vector2(0f, 0f);
			val.anchoredPosition = new Vector2(20f, 60f);
			val.sizeDelta = new Vector2(76f, 28f);
			Image val2 = _iconButton.AddComponent<Image>();
			((Graphic)val2).color = new Color(0.06f, 0.06f, 0.12f, 0.85f);
			GameObject val3 = new GameObject("IconLabel");
			val3.layer = _layer;
			val3.transform.SetParent(_iconButton.transform, false);
			TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val4).text = "FamBook";
			((TMP_Text)val4).fontSize = 11f;
			((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val4).enableWordWrapping = false;
			RectTransform component = val3.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
			((UnityEvent)_iconButton.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)OnIconClicked));
			_iconButton.SetActive(true);
		}

		private static void BuildBookPanel()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: 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_00a8: 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_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
			_bookPanel = new GameObject("FamBook_Book");
			AttachToCanvas(_bookPanel);
			RectTransform val = _bookPanel.AddComponent<RectTransform>();
			val.anchorMin = new Vector2(0.5f, 0.5f);
			val.anchorMax = new Vector2(0.5f, 0.5f);
			val.pivot = new Vector2(0.5f, 0.5f);
			val.anchoredPosition = Vector2.zero;
			val.sizeDelta = new Vector2(310f, 380f);
			((Graphic)_bookPanel.AddComponent<Image>()).color = new Color(0.05f, 0.04f, 0.07f, 0.92f);
			BuildHeader();
			GameObject val2 = MakeChild("Sep1", _bookPanel.transform);
			((Graphic)val2.AddComponent<Image>()).color = new Color(0.5f, 0.4f, 0.2f, 0.7f);
			Stretch(val2, 0f, 0f, 348f, 30f);
			_cardsContainer = MakeChild("FamBook_Cards", _bookPanel.transform);
			((Graphic)_cardsContainer.AddComponent<Image>()).color = Color.clear;
			Stretch(_cardsContainer, 4f, 4f, 68f, 32f);
			for (int i = 0; i < 10; i++)
			{
				_cards.Add(new FamiliarCard(_cardsContainer.transform, _layer, i, 26f, 2f));
			}
			GameObject val3 = MakeChild("Sep2", _bookPanel.transform);
			((Graphic)val3.AddComponent<Image>()).color = new Color(0.5f, 0.4f, 0.2f, 0.7f);
			Stretch(val3, 0f, 0f, 66f, 312f);
			BuildNav();
		}

		private static void BuildHeader()
		{
			//IL_0030: 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)
			//IL_01b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0293: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = MakeChild("BookHeader", _bookPanel.transform);
			((Graphic)val.AddComponent<Image>()).color = new Color(0.08f, 0.07f, 0.1f, 0.85f);
			Stretch(val, 0f, 0f, 350f, 0f);
			GameObject val2 = MakeChild("Title", val.transform);
			TextMeshProUGUI val3 = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val3).text = "FamBook";
			((TMP_Text)val3).fontSize = 12f;
			((TMP_Text)val3).alignment = (TextAlignmentOptions)513;
			((TMP_Text)val3).enableWordWrapping = false;
			Frac(val2, 0.05f, 0.1f, 0.6f, 0.9f, 8f, 0f, 3f, 3f);
			GameObject val4 = MakeChild("BoxesBtn", val.transform);
			((Graphic)val4.AddComponent<Image>()).color = Color.clear;
			Frac(val4, 0.6f, 0f, 0.75f, 1f, 0f, 4f, 2f, 2f);
			TextMeshProUGUI val5 = MakeChild("BoxesTxt", val4.transform).AddComponent<TextMeshProUGUI>();
			((TMP_Text)val5).text = "Boxes";
			((TMP_Text)val5).fontSize = 12f;
			((TMP_Text)val5).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val5).enableWordWrapping = false;
			FillParent(((Component)val5).gameObject);
			((UnityEvent)val4.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)OnBoxesClicked));
			GameObject val6 = MakeChild("VBloodBtn", val.transform);
			((Graphic)val6.AddComponent<Image>()).color = Color.clear;
			Frac(val6, 0.75f, 0f, 0.88f, 1f, 0f, 4f, 2f, 2f);
			TextMeshProUGUI val7 = MakeChild("VBloodTxt", val6.transform).AddComponent<TextMeshProUGUI>();
			((TMP_Text)val7).text = "VBlood";
			((TMP_Text)val7).fontSize = 12f;
			((TMP_Text)val7).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val7).enableWordWrapping = false;
			FillParent(((Component)val7).gameObject);
			((UnityEvent)val6.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)OnVBloodClicked));
			GameObject val8 = MakeChild("CloseBtn", val.transform);
			((Graphic)val8.AddComponent<Image>()).color = Color.clear;
			Frac(val8, 0.88f, 0f, 1f, 1f, 0f, 4f, 2f, 2f);
			TextMeshProUGUI val9 = MakeChild("CloseTxt", val8.transform).AddComponent<TextMeshProUGUI>();
			((TMP_Text)val9).text = "<color=#FF6666>x</color>";
			((TMP_Text)val9).fontSize = 13f;
			((TMP_Text)val9).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val9).enableWordWrapping = false;
			FillParent(((Component)val9).gameObject);
			((UnityEvent)val8.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)CloseBook));
		}

		private static void BuildNav()
		{
			//IL_0030: 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_01f2: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = MakeChild("NavBar", _bookPanel.transform);
			((Graphic)val.AddComponent<Image>()).color = new Color(0.07f, 0.06f, 0.09f, 0.85f);
			Stretch(val, 0f, 0f, 0f, 314f);
			GameObject val2 = MakeChild("PrevBtn", val.transform);
			((Graphic)val2.AddComponent<Image>()).color = new Color(0.25f, 0.18f, 0.08f, 0.9f);
			Frac(val2, 0.02f, 0.18f, 0.3f, 0.82f);
			GameObject val3 = MakeChild("PrevLbl", val2.transform);
			TextMeshProUGUI val4 = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val4).text = "< Prev";
			((TMP_Text)val4).fontSize = 11f;
			((TMP_Text)val4).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val4).enableWordWrapping = false;
			FillParent(val3);
			((UnityEvent)val2.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				OnPrevPage();
			}));
			GameObject val5 = MakeChild("PageNum", val.transform);
			_pageLabel = val5.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_pageLabel).text = "";
			((TMP_Text)_pageLabel).fontSize = 10f;
			((TMP_Text)_pageLabel).alignment = (TextAlignmentOptions)514;
			((TMP_Text)_pageLabel).enableWordWrapping = false;
			Frac(val5, 0.32f, 0.1f, 0.68f, 0.9f);
			GameObject val6 = MakeChild("NextBtn", val.transform);
			((Graphic)val6.AddComponent<Image>()).color = new Color(0.25f, 0.18f, 0.08f, 0.9f);
			Frac(val6, 0.7f, 0.18f, 0.98f, 0.82f);
			GameObject val7 = MakeChild("NextLbl", val6.transform);
			TextMeshProUGUI val8 = val7.AddComponent<TextMeshProUGUI>();
			((TMP_Text)val8).text = "Next >";
			((TMP_Text)val8).fontSize = 11f;
			((TMP_Text)val8).alignment = (TextAlignmentOptions)514;
			((TMP_Text)val8).enableWordWrapping = false;
			FillParent(val7);
			((UnityEvent)val6.AddComponent<Button>().onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				OnNextPage();
			}));
		}

		private static void AttachToCanvas(GameObject go)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			go.layer = _layer;
			Object.DontDestroyOnLoad((Object)(object)go);
			SceneManager.MoveGameObjectToScene(go, SceneManager.GetSceneByName("VRisingWorld"));
			go.transform.SetParent(((Component)_bottomBarCanvas).transform, false);
		}

		private static GameObject MakeChild(string name, Transform parent)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Expected O, but got Unknown
			GameObject val = new GameObject(name);
			val.layer = _layer;
			val.transform.SetParent(parent, false);
			return val;
		}

		private static void Stretch(GameObject go, float left, float right, float bottom, float top)
		{
			//IL_0009: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = go.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = new Vector2(left, bottom);
			component.offsetMax = new Vector2(0f - right, 0f - top);
		}

		private static void Frac(GameObject go, float x0, float y0, float x1, float y1, float pl = 0f, float pr = 0f, float pb = 0f, float pt = 0f)
		{
			//IL_000b: 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_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = go.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(x0, y0);
			component.anchorMax = new Vector2(x1, y1);
			component.offsetMin = new Vector2(pl, pb);
			component.offsetMax = new Vector2(0f - pr, 0f - pt);
		}

		private static void FillParent(GameObject go)
		{
			//IL_0009: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = go.GetComponent<RectTransform>();
			component.anchorMin = Vector2.zero;
			component.anchorMax = Vector2.one;
			component.offsetMin = Vector2.zero;
			component.offsetMax = Vector2.zero;
		}

		private static void OnBoxesClicked()
		{
			OpenBook();
			_showingVBloodList = false;
			_showingBoxList = true;
			_boxListPage = 0;
			CommandSender.Send(".fam listboxes");
			DataService.BeginAwaitingBoxList();
		}

		private static void OnVBloodClicked()
		{
			_bookOpen = true;
			GameObject? bookPanel = _bookPanel;
			if (bookPanel != null)
			{
				bookPanel.SetActive(true);
			}
			_showingBoxList = false;
			_showingVBloodList = true;
			_boxListPage = 0;
			_vbloodPage = 0;
			DataService.LoadVbloodPages();
			RefreshBookPage();
			_vbloodScanning = false;
			Core.StartCoroutine(VBloodScanPage(_vbloodPage));
		}

		[IteratorStateMachine(typeof(<VBloodScanPage>d__41))]
		private static IEnumerator VBloodScanPage(int pageIndex)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <VBloodScanPage>d__41(0)
			{
				pageIndex = pageIndex
			};
		}

		private static void OnIconClicked()
		{
			if (_bookOpen)
			{
				CloseBook();
			}
			else
			{
				OpenBook();
			}
		}

		private static void OpenBook()
		{
			_bookOpen = true;
			GameObject? bookPanel = _bookPanel;
			if (bookPanel != null)
			{
				bookPanel.SetActive(true);
			}
			_showingVBloodList = false;
			_showingBoxList = true;
			_boxListPage = 0;
			CommandSender.Send(".fam listboxes");
			DataService.BeginAwaitingBoxList();
		}

		private static void CloseBook()
		{
			_bookOpen = false;
			GameObject? bookPanel = _bookPanel;
			if (bookPanel != null)
			{
				bookPanel.SetActive(false);
			}
			_showingVBloodList = false;
			_vbloodScanning = false;
		}

		private static void OnPrevPage()
		{
			if (_showingBoxList)
			{
				int count = DataService.LastListedBoxNames.Count;
				int num = Math.Max(0, (count - 1) / 10);
				if (_boxListPage > 0)
				{
					_boxListPage--;
					RefreshBookPage();
				}
				return;
			}
			if (_showingVBloodList)
			{
				int num2 = DataService.VbloodPages?.Count ?? 0;
				if (_vbloodPage > 0)
				{
					_vbloodPage--;
					RefreshBookPage();
					Core.StartCoroutine(VBloodScanPage(_vbloodPage));
				}
				return;
			}
			List<string> lastListedBoxNames = DataService.LastListedBoxNames;
			if (lastListedBoxNames != null && lastListedBoxNames.Count > 0)
			{
				int num3 = ((_currentListedBoxIndex >= 0) ? _currentListedBoxIndex : lastListedBoxNames.FindIndex((string n) => n == DataService.CurrentBoxName));
				if (num3 > 0)
				{
					_currentListedBoxIndex = num3 - 1;
					OpenBoxByIndex(_currentListedBoxIndex);
				}
			}
			else if (DataService.CurrentBoxIndex > 0)
			{
				DataService.CurrentBoxIndex--;
				RequestCurrentBox();
			}
		}

		private static void OnNextPage()
		{
			if (_showingBoxList)
			{
				int count = DataService.LastListedBoxNames.Count;
				int num = Math.Max(0, (count - 1) / 10);
				if (_boxListPage < num)
				{
					_boxListPage++;
					RefreshBookPage();
				}
				return;
			}
			if (_showingVBloodList)
			{
				int num2 = DataService.VbloodPages?.Count ?? 0;
				if (_vbloodPage < num2 - 1)
				{
					_vbloodPage++;
					RefreshBookPage();
					Core.StartCoroutine(VBloodScanPage(_vbloodPage));
				}
				return;
			}
			List<string> lastListedBoxNames = DataService.LastListedBoxNames;
			if (lastListedBoxNames != null && lastListedBoxNames.Count > 0)
			{
				int num3 = ((_currentListedBoxIndex >= 0) ? _currentListedBoxIndex : lastListedBoxNames.FindIndex((string n) => n == DataService.CurrentBoxName));
				if (num3 < 0)
				{
					num3 = DataService.CurrentBoxIndex;
				}
				if (num3 < lastListedBoxNames.Count - 1)
				{
					_currentListedBoxIndex = num3 + 1;
					OpenBoxByIndex(_currentListedBoxIndex);
					return;
				}
			}
			DataService.CurrentBoxIndex++;
			RequestCurrentBox();
		}

		private static void RequestCurrentBox()
		{
			CommandSender.RequestBoxData(DataService.CurrentBoxIndex);
		}

		private static void OpenBoxByIndex(int idx)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Expected O, but got Unknown
			if (idx < 0)
			{
				return;
			}
			List<string> lastListedBoxNames = DataService.LastListedBoxNames;
			if (lastListedBoxNames != null && idx < lastListedBoxNames.Count)
			{
				string text = lastListedBoxNames[idx];
				_showingBoxList = false;
				_boxListPage = 0;
				_currentListedBoxIndex = idx;
				CommandSender.Send(".fam cb " + text);
				CommandSender.Send(".fam l");
				DataService.BeginAwaitingResponse();
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(55, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Requested familiars for box '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' via Next/Prev.");
				}
				log.LogInfo(val);
			}
		}

		private static void RefreshBookPage()
		{
			//IL_0184: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Expected O, but got Unknown
			//IL_05b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_05bf: Expected O, but got Unknown
			//IL_0436: Unknown result type (might be due to invalid IL or missing references)
			//IL_043d: Expected O, but got Unknown
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val;
			if (_showingBoxList && DataService.LastListedBoxNames.Count > 0)
			{
				int count = DataService.LastListedBoxNames.Count;
				int num = _boxListPage * 10;
				int num2 = Math.Min(10, Math.Max(0, count - num));
				if ((Object)(object)_pageLabel != (Object)null)
				{
					((TMP_Text)_pageLabel).SetText($"<color=#CCBBAA>Boxes {num + 1}-{num + num2} of {count}</color>", true);
				}
				for (int i = 0; i < _cards.Count; i++)
				{
					int num3 = num + i;
					if (num3 < count)
					{
						string boxName = DataService.LastListedBoxNames[num3];
						_cards[i].UpdateBox(boxName, num3 + 1, OnBoxClicked);
						_cards[i].SetVisible(v: true);
					}
					else
					{
						_cards[i].SetVisible(v: false);
					}
				}
				ManualLogSource log = Core.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(54, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Boxes refreshed: showing ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" of ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" boxes (page ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(_boxListPage + 1);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
				}
				log.LogInfo(val);
				return;
			}
			if (_showingVBloodList)
			{
				List<List<string>> vbloodPages = DataService.VbloodPages;
				if (vbloodPages == null || vbloodPages.Count == 0)
				{
					if ((Object)(object)_pageLabel != (Object)null)
					{
						((TMP_Text)_pageLabel).SetText("<color=#CCBBAA>No VBlood pages loaded</color>", true);
					}
					for (int j = 0; j < _cards.Count; j++)
					{
						_cards[j].SetVisible(v: false);
					}
					return;
				}
				int num4 = Math.Max(0, Math.Min(_vbloodPage, vbloodPages.Count - 1));
				List<string> list = vbloodPages[num4];
				if ((Object)(object)_pageLabel != (Object)null)
				{
					((TMP_Text)_pageLabel).SetText($"<color=#CCBBAA>VBloods page {num4 + 1} of {vbloodPages.Count}</color>", true);
				}
				for (int k = 0; k < _cards.Count; k++)
				{
					if (k < list.Count)
					{
						string text = list[k];
						if (!DataService.TryGetVbloodResult(text, out string value))
						{
							value = "...";
						}
						string rightText = ((value == "...") ? value : (string.Equals(value, "not owned", StringComparison.OrdinalIgnoreCase) ? "<color=#AAAAAA>not owned</color>" : ((!string.Equals(value, "unknown", StringComparison.OrdinalIgnoreCase)) ? ("Box: " + value) : "<color=#FFCC00>unknown</color>")));
						_cards[k].UpdateVBlood(text, rightText, OnVBloodCardClicked);
						_cards[k].SetVisible(v: true);
					}
					else
					{
						_cards[k].SetVisible(v: false);
					}
				}
				ManualLogSource log2 = Core.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(34, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] VBlood page refreshed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num4 + 1);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("/");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(vbloodPages.Count);
				}
				log2.LogInfo(val);
				return;
			}
			int currentBoxIndex = DataService.CurrentBoxIndex;
			List<FamiliarEntry> list2 = new List<FamiliarEntry>();
			string text2 = DataService.CurrentBoxName;
			if (string.IsNullOrEmpty(text2))
			{
				text2 = $"Box {currentBoxIndex + 1}";
			}
			if (DataService.Boxes.TryGetValue(currentBoxIndex, out BoxData value2))
			{
				list2 = value2.Familiars;
			}
			if ((Object)(object)_pageLabel != (Object)null)
			{
				((TMP_Text)_pageLabel).SetText("<color=#CCBBAA>" + text2 + "</color>", true);
			}
			for (int l = 0; l < _cards.Count; l++)
			{
				if (l < list2.Count)
				{
					_cards[l].Update(list2[l], l + 1, OnFamiliarClicked);
					_cards[l].SetVisible(v: true);
				}
				else
				{
					_cards[l].SetVisible(v: false);
				}
			}
			ManualLogSource log3 = Core.Log;
			val = new BepInExInfoLogInterpolatedStringHandler(46, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Book refreshed: ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(list2.Count);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" cards shown for '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'.");
			}
			log3.LogInfo(val);
		}

		private static void OnFamiliarClicked(int famNumber, string familiarName)
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			if (famNumber > 0)
			{
				DataService.BeginAwaitingBindAttempt(famNumber);
				CommandSender.Send($".fam b {famNumber}");
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(42, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Clicked familiar #");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(famNumber);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(familiarName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(") -> .fam b ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(famNumber);
				}
				log.LogInfo(val);
			}
		}

		private static void OnBoxClicked(int boxNumber, string boxName)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Expected O, but got Unknown
			if (!string.IsNullOrWhiteSpace(boxName))
			{
				_showingBoxList = false;
				_boxListPage = 0;
				_currentListedBoxIndex = Math.Max(0, boxNumber - 1);
				CommandSender.Send(".fam cb " + boxName);
				CommandSender.Send(".fam l");
				DataService.BeginAwaitingResponse();
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(52, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Requested familiars for box '");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(boxName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("' via button.");
				}
				log.LogInfo(val);
			}
		}

		private static void OnVBloodCardClicked(int unused, string vbloodName)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			if (!string.IsNullOrWhiteSpace(vbloodName))
			{
				CommandSender.Send(".fam sb \"" + vbloodName + "\"");
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Sent .fam sb \"");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(vbloodName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("\" via VBlood card click.");
				}
				log.LogInfo(val);
			}
		}

		public static void ResetState()
		{
			_killSwitch = true;
			_ready = false;
			_bookOpen = false;
			Destroy(_iconButton);
			_iconButton = null;
			Destroy(_bookPanel);
			_bookPanel = null;
			_cardsContainer = null;
			_cards.Clear();
			_showingBoxList = false;
			_showingVBloodList = false;
			_boxListPage = 0;
			_vbloodPage = 0;
			_vbloodScanning = false;
			_currentListedBoxIndex = -1;
			DataService.Reset();
			CommandSender.Reset();
			Core.Log.LogInfo((object)"[FamBook] State reset.");
		}

		private static void Destroy(GameObject? go)
		{
			if ((Object)(object)go != (Object)null)
			{
				Object.Destroy((Object)(object)go);
			}
		}
	}
	internal sealed class FamiliarCard
	{
		private readonly GameObject _root;

		private readonly TextMeshProUGUI _nameText;

		private readonly TextMeshProUGUI _infoText;

		private readonly Button _button;

		private static readonly Color NormalBg = new Color(0.1f, 0.09f, 0.12f, 0.55f);

		public FamiliarCard(Transform parent, int layer, int index, float cardH, float gap)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Expected O, but got Unknown
			//IL_0066: 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_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Expected O, but got Unknown
			//IL_0247: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_027e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ac: Unknown result type (might be due to invalid IL or missing references)
			_root = new GameObject($"FamCard_{index}");
			_root.layer = layer;
			_root.transform.SetParent(parent, false);
			Image val = _root.AddComponent<Image>();
			((Graphic)val).color = NormalBg;
			_button = _root.AddComponent<Button>();
			RectTransform component = _root.GetComponent<RectTransform>();
			component.anchorMin = new Vector2(0f, 1f);
			component.anchorMax = new Vector2(1f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			component.anchoredPosition = new Vector2(0f, 0f - ((float)index * (cardH + gap) + 3f));
			component.sizeDelta = new Vector2(0f, cardH);
			GameObject val2 = new GameObject("NameTxt");
			val2.layer = layer;
			val2.transform.SetParent(_root.transform, false);
			_nameText = val2.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_nameText).fontSize = 12f;
			((TMP_Text)_nameText).alignment = (TextAlignmentOptions)513;
			((TMP_Text)_nameText).enableWordWrapping = false;
			RectTransform component2 = val2.GetComponent<RectTransform>();
			component2.anchorMin = new Vector2(0f, 0f);
			component2.anchorMax = new Vector2(0.68f, 1f);
			component2.offsetMin = new Vector2(8f, 2f);
			component2.offsetMax = new Vector2(0f, -2f);
			GameObject val3 = new GameObject("InfoTxt");
			val3.layer = layer;
			val3.transform.SetParent(_root.transform, false);
			_infoText = val3.AddComponent<TextMeshProUGUI>();
			((TMP_Text)_infoText).fontSize = 11f;
			((TMP_Text)_infoText).alignment = (TextAlignmentOptions)516;
			((TMP_Text)_infoText).enableWordWrapping = false;
			((Graphic)_infoText).color = new Color(0.85f, 0.85f, 0.85f);
			RectTransform component3 = val3.GetComponent<RectTransform>();
			component3.anchorMin = new Vector2(0.68f, 0f);
			component3.anchorMax = new Vector2(1f, 1f);
			component3.offsetMin = new Vector2(0f, 2f);
			component3.offsetMax = new Vector2(-8f, -2f);
			_root.SetActive(false);
		}

		public void Update(FamiliarEntry f, int famNumber, Action<int, string> onClick)
		{
			Action<int, string> onClick2 = onClick;
			FamiliarEntry f2 = f;
			string text = (f2.IsShiny ? (f2.ShinyColorTag + "*</color>") : string.Empty);
			((TMP_Text)_nameText).SetText("<color=#90EE90>" + f2.Name + "</color>" + text, true);
			string value = ((f2.Prestige > 0) ? $"[<color=#90EE90>P{f2.Prestige}</color>] " : string.Empty);
			((TMP_Text)_infoText).SetText($"{value}Lv <color=white>{f2.Level}</color>", true);
			((UnityEventBase)_button.onClick).RemoveAllListeners();
			((UnityEvent)_button.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				onClick2(famNumber, f2.Name);
			}));
		}

		public void UpdateBox(string boxName, int boxNumber, Action<int, string> onClick)
		{
			Action<int, string> onClick2 = onClick;
			string boxName2 = boxName;
			((TMP_Text)_nameText).SetText("<color=#90EE90>" + boxName2 + "</color>", true);
			((TMP_Text)_infoText).SetText($"# {boxNumber}", true);
			((UnityEventBase)_button.onClick).RemoveAllListeners();
			((UnityEvent)_button.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				onClick2(boxNumber, boxName2);
			}));
		}

		public void UpdateVBlood(string vbloodName, string rightText, Action<int, string> onClick)
		{
			Action<int, string> onClick2 = onClick;
			string vbloodName2 = vbloodName;
			((TMP_Text)_nameText).SetText("<color=#90EE90>" + vbloodName2 + "</color>", true);
			((TMP_Text)_infoText).SetText(rightText, true);
			((UnityEventBase)_button.onClick).RemoveAllListeners();
			((UnityEvent)_button.onClick).AddListener(UnityAction.op_Implicit((Action)delegate
			{
				onClick2(0, vbloodName2);
			}));
		}

		public void SetVisible(bool v)
		{
			_root.SetActive(v);
		}
	}
	internal static class DataService
	{
		public static readonly Dictionary<int, BoxData> Boxes = new Dictionary<int, BoxData>();

		private static float _responseDeadline;

		private static readonly List<FamiliarEntry> _pendingEntries = new List<FamiliarEntry>();

		private static string _pendingBoxName = string.Empty;

		private static readonly List<string> _pendingBoxNames = new List<string>();

		public static readonly List<string> LastListedBoxNames = new List<string>();

		private static string _pendingSearchName = string.Empty;

		public static readonly Dictionary<string, string> VbloodResults = new Dictionary<string, string>();

		public static readonly List<List<string>> VbloodPages = new List<List<string>>();

		private const float BASE_WINDOW = 3f;

		private const float EXTEND_EACH = 1.5f;

		private static readonly Regex _boxHeaderRx = new Regex("^<color=white>(.+)</color>:$", RegexOptions.Compiled);

		private static readonly Regex _boxSelectedRx = new Regex("^Box Selected - <color=white>(.+)</color>$", RegexOptions.IgnoreCase | RegexOptions.Compiled);

		private static readonly Regex _famLineRx = new Regex("^<color=yellow>\\d+</color>\\| <color=green>(.+?)</color>(?:(<color=[^>]+>)\\*</color>)? \\[<color=white>(\\d+)</color>\\](?:\\[<color=#90EE90>(\\d+)</color>\\])?$", RegexOptions.Compiled);

		public static int CurrentBoxIndex { get; set; } = 0;


		public static string CurrentBoxName { get; private set; } = string.Empty;


		public static bool IsDirty { get; set; } = false;


		public static bool AwaitingResponse { get; private set; } = false;


		public static bool AwaitingListBoxes { get; private set; } = false;


		public static bool AwaitingBindAttempt { get; private set; } = false;


		public static bool AwaitingSearch { get; private set; } = false;


		public static int PendingBindFamiliarNumber { get; private set; } = 0;


		private static string NormalizeVbloodKey(string s)
		{
			if (s == null)
			{
				return string.Empty;
			}
			string text = Regex.Replace(s, "\\s+", " ").Trim();
			return text.ToLowerInvariant();
		}

		public static bool TryGetVbloodResult(string vbName, out string value)
		{
			value = string.Empty;
			if (string.IsNullOrWhiteSpace(vbName))
			{
				return false;
			}
			if (VbloodResults.TryGetValue(NormalizeVbloodKey(vbName), out string value2))
			{
				value = value2 ?? string.Empty;
				return true;
			}
			return false;
		}

		public static void BeginAwaitingResponse()
		{
			_pendingEntries.Clear();
			_pendingBoxName = string.Empty;
			_responseDeadline = Time.realtimeSinceStartup + 3f;
			AwaitingResponse = true;
			Core.Log.LogInfo((object)"[FamBook] Awaiting .fam l response...");
		}

		public static void BeginAwaitingBindAttempt(int familiarNumber)
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			PendingBindFamiliarNumber = familiarNumber;
			AwaitingBindAttempt = true;
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(58, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Awaiting bind attempt response for familiar #");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(familiarNumber);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("...");
			}
			log.LogInfo(val);
		}

		public static void RetryBindWithUnbind()
		{
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			if (PendingBindFamiliarNumber > 0)
			{
				AwaitingBindAttempt = false;
				int pendingBindFamiliarNumber = PendingBindFamiliarNumber;
				CommandSender.Send(".fam ub");
				CommandSender.Send($".fam b {pendingBindFamiliarNumber}");
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(67, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Bind conflict detected; retrying familiar #");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(pendingBindFamiliarNumber);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" after unbind.");
				}
				log.LogInfo(val);
			}
		}

		public static void ClearBindAttempt()
		{
			AwaitingBindAttempt = false;
			PendingBindFamiliarNumber = 0;
		}

		public static void BeginAwaitingSearch(string name)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			_pendingSearchName = name;
			AwaitingSearch = true;
			_responseDeadline = Time.realtimeSinceStartup + 3f;
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(44, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Awaiting .fam s response for '");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(name);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("'...");
			}
			log.LogInfo(val);
		}

		public static void LoadVbloodPages()
		{
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0311: Expected O, but got Unknown
			//IL_04d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dd: Expected O, but got Unknown
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Expected O, but got Unknown
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0464: Expected O, but got Unknown
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028b: Expected O, but got Unknown
			VbloodPages.Clear();
			VbloodResults.Clear();
			string text = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? AppDomain.CurrentDomain.BaseDirectory;
			string baseDirectory = AppDomain.CurrentDomain.BaseDirectory;
			string currentDirectory = Directory.GetCurrentDirectory();
			string[] array = new string[6]
			{
				Path.Combine(text, "vbloods.json"),
				Path.Combine(text, "Services", "vbloods.json"),
				Path.Combine(baseDirectory, "vbloods.json"),
				Path.Combine(baseDirectory, "Services", "vbloods.json"),
				Path.Combine(currentDirectory, "vbloods.json"),
				Path.Combine(currentDirectory, "Services", "vbloods.json")
			};
			ManualLogSource log = Core.Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(73, 3, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Searching vbloods.json candidates: assemblyDir=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", baseDir=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(baseDirectory);
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(", cwd=");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(currentDirectory);
			}
			log.LogInfo(val);
			string text2 = null;
			string[] array2 = array;
			foreach (string text3 in array2)
			{
				if (File.Exists(text3))
				{
					text2 = text3;
					break;
				}
			}
			if (text2 == null)
			{
				Assembly executingAssembly = Assembly.GetExecutingAssembly();
				string text4 = "FamBook.Services.vbloods.json";
				using Stream stream = executingAssembly.GetManifestResourceStream(text4);
				if (stream != null)
				{
					try
					{
						using StreamReader streamReader = new StreamReader(stream);
						string json = streamReader.ReadToEnd();
						using JsonDocument jsonDocument = JsonDocument.Parse(json);
						foreach (JsonProperty item in jsonDocument.RootElement.EnumerateObject())
						{
							if (item.Value.ValueKind == JsonValueKind.Array)
							{
								List<string> list = new List<string>();
								foreach (JsonElement item2 in item.Value.EnumerateArray())
								{
									list.Add(item2.GetString() ?? string.Empty);
								}
								VbloodPages.Add(list);
							}
						}
						ManualLogSource log2 = Core.Log;
						val = new BepInExInfoLogInterpolatedStringHandler(57, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Loaded ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(VbloodPages.Count);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" VBlood pages from embedded resource (");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text4);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(").");
						}
						log2.LogInfo(val);
						return;
					}
					catch (Exception ex)
					{
						ManualLogSource log3 = Core.Log;
						BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(48, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[FamBook] Failed to load embedded vbloods.json: ");
							((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex.Message);
						}
						log3.LogWarning(val2);
						return;
					}
				}
				Core.Log.LogWarning((object)"[FamBook] vbloods.json not found; VBlood pages empty.");
				return;
			}
			try
			{
				string json2 = File.ReadAllText(text2);
				using JsonDocument jsonDocument2 = JsonDocument.Parse(json2);
				foreach (JsonProperty item3 in jsonDocument2.RootElement.EnumerateObject())
				{
					if (item3.Value.ValueKind != JsonValueKind.Array)
					{
						continue;
					}
					List<string> list2 = new List<string>();
					foreach (JsonElement item4 in item3.Value.EnumerateArray())
					{
						list2.Add(item4.GetString() ?? string.Empty);
					}
					VbloodPages.Add(list2);
				}
				ManualLogSource log4 = Core.Log;
				val = new BepInExInfoLogInterpolatedStringHandler(37, 2, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Loaded ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(VbloodPages.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" VBlood pages from ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(".");
				}
				log4.LogInfo(val);
			}
			catch (Exception ex2)
			{
				ManualLogSource log5 = Core.Log;
				BepInExWarningLogInterpolatedStringHandler val2 = new BepInExWarningLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("[FamBook] Failed to load vbloods.json: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>(ex2.Message);
				}
				log5.LogWarning(val2);
			}
		}

		public static bool TryParseBloodcraftLine(string raw)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			//IL_033a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0341: Expected O, but got Unknown
			//IL_041a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Expected O, but got Unknown
			//IL_0992: Unknown result type (might be due to invalid IL or missing references)
			//IL_0999: Expected O, but got Unknown
			//IL_058f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0596: Expected O, but got Unknown
			//IL_0547: Unknown result type (might be due to invalid IL or missing references)
			//IL_054e: Expected O, but got Unknown
			//IL_073e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0745: Expected O, but got Unknown
			//IL_08cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d4: Expected O, but got Unknown
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_0278: Expected O, but got Unknown
			//IL_061c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0623: Expected O, but got Unknown
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01dd: Expected O, but got Unknown
			if (string.IsNullOrWhiteSpace(raw))
			{
				return false;
			}
			bool flag = default(bool);
			if (AwaitingBindAttempt)
			{
				if (raw.Contains("you already have an active familiar") || raw.Contains("Unbind that one first"))
				{
					ManualLogSource log = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(34, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Detected bind conflict: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(raw);
					}
					log.LogInfo(val);
					RetryBindWithUnbind();
					return true;
				}
				ClearBindAttempt();
				return false;
			}
			if (AwaitingListBoxes)
			{
				if (Time.realtimeSinceStartup > _responseDeadline)
				{
					return false;
				}
				string text = StripTags(raw);
				if (string.IsNullOrWhiteSpace(text))
				{
					return false;
				}
				if (text.StartsWith("Familiar Boxes", StringComparison.OrdinalIgnoreCase))
				{
					_responseDeadline = Time.realtimeSinceStartup + 1.5f;
					return true;
				}
				if (_boxSelectedRx.IsMatch(raw))
				{
					return true;
				}
				if (text.Contains("|") || text.EndsWith(":"))
				{
					_responseDeadline = Time.realtimeSinceStartup + 1.5f;
					return true;
				}
				if (text.Contains(","))
				{
					string[] array = text.Split(',');
					string[] array2 = array;
					foreach (string s2 in array2)
					{
						string text2 = CleanBoxToken(s2);
						if (!string.IsNullOrWhiteSpace(text2) && !_pendingBoxNames.Contains(text2))
						{
							_pendingBoxNames.Add(text2);
							ManualLogSource log2 = Core.Log;
							BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
							if (flag)
							{
								((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Parsed box token: ");
								((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text2);
							}
							log2.LogInfo(val);
						}
					}
					_responseDeadline = Time.realtimeSinceStartup + 1.5f;
					return true;
				}
				string text3 = CleanBoxToken(text);
				if (!string.IsNullOrWhiteSpace(text3) && !_pendingBoxNames.Contains(text3))
				{
					_pendingBoxNames.Add(text3);
					ManualLogSource log3 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(28, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Parsed box token: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text3);
					}
					log3.LogInfo(val);
				}
				_responseDeadline = Time.realtimeSinceStartup + 1.5f;
				return true;
			}
			if (AwaitingSearch)
			{
				string text4 = StripTags(raw);
				if (text4.IndexOf("Matching familiar", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					string[] array3 = text4.Split(':');
					if (array3.Length >= 2)
					{
						string text5 = array3[1].Trim();
						string pendingSearchName = _pendingSearchName;
						VbloodResults[NormalizeVbloodKey(pendingSearchName)] = text5;
						ManualLogSource log4 = Core.Log;
						BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 2, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Search result: ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pendingSearchName);
							((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
							((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text5);
						}
						log4.LogInfo(val);
					}
					else
					{
						string pendingSearchName2 = _pendingSearchName;
						VbloodResults[NormalizeVbloodKey(pendingSearchName2)] = "unknown";
					}
					_pendingSearchName = string.Empty;
					AwaitingSearch = false;
					IsDirty = true;
					return true;
				}
				if (text4.IndexOf("couldn't find", StringComparison.OrdinalIgnoreCase) >= 0 || text4.IndexOf("no matching", StringComparison.OrdinalIgnoreCase) >= 0)
				{
					string pendingSearchName3 = _pendingSearchName;
					VbloodResults[NormalizeVbloodKey(pendingSearchName3)] = "not owned";
					ManualLogSource log5 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Search result: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pendingSearchName3);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> not owned");
					}
					log5.LogInfo(val);
					_pendingSearchName = string.Empty;
					AwaitingSearch = false;
					IsDirty = true;
					return true;
				}
			}
			if (!AwaitingResponse)
			{
				return false;
			}
			if (Time.realtimeSinceStartup > _responseDeadline)
			{
				return false;
			}
			Match match = _boxSelectedRx.Match(raw);
			if (match.Success)
			{
				string text6 = match.Groups[1].Value.Trim();
				int result = 0;
				Match match2 = Regex.Match(text6, "box(\\d+)$", RegexOptions.IgnoreCase);
				if (!match2.Success)
				{
					int.TryParse(text6, NumberStyles.Integer, CultureInfo.InvariantCulture, out result);
				}
				else
				{
					result = ParseInt(match2.Groups[1].Value);
				}
				if (result > 0)
				{
					CurrentBoxIndex = result - 1;
					ManualLogSource log6 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Box selected: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(CurrentBoxIndex + 1);
					}
					log6.LogInfo(val);
				}
				else
				{
					_pendingBoxName = text6;
					ManualLogSource log7 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(24, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Box selected: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text6);
					}
					log7.LogInfo(val);
				}
				if (AwaitingSearch && _pendingSearchName.Length > 0)
				{
					string pendingSearchName4 = _pendingSearchName;
					VbloodResults[NormalizeVbloodKey(pendingSearchName4)] = text6;
					_pendingSearchName = string.Empty;
					AwaitingSearch = false;
					IsDirty = true;
					ManualLogSource log8 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(29, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Search result: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(pendingSearchName4);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" -> ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text6);
					}
					log8.LogInfo(val);
				}
				return true;
			}
			Match match3 = _famLineRx.Match(raw);
			if (match3.Success)
			{
				string value = match3.Groups[1].Value;
				string text7 = (match3.Groups[2].Success ? match3.Groups[2].Value : string.Empty);
				int num = ParseInt(match3.Groups[3].Value);
				int num2 = (match3.Groups[4].Success ? ParseInt(match3.Groups[4].Value) : 0);
				_pendingEntries.Add(new FamiliarEntry(value, num, num2, text7));
				_responseDeadline = Time.realtimeSinceStartup + 1.5f;
				ManualLogSource log9 = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(39, 4, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Parsed familiar: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(value);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Lv");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" P");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num2);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" shiny=");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(text7.Length > 0);
				}
				log9.LogInfo(val);
				return true;
			}
			if (raw.Contains("|"))
			{
				string input = StripTags(raw);
				Match match4 = Regex.Match(input, "^\\s*\\d+\\|\\s*(.+?)\\s*(\\*)?\\s*\\[(\\d+)\\](?:\\[(\\d+)\\])?\\s*$");
				if (match4.Success)
				{
					string text8 = match4.Groups[1].Value.Trim();
					bool flag2 = match4.Groups[2].Success && match4.Groups[2].Value == "*";
					int num3 = ParseInt(match4.Groups[3].Value);
					int num4 = (match4.Groups[4].Success ? ParseInt(match4.Groups[4].Value) : 0);
					string empty = string.Empty;
					_pendingEntries.Add(new FamiliarEntry(text8, num3, num4, empty));
					_responseDeadline = Time.realtimeSinceStartup + 1.5f;
					ManualLogSource log10 = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(50, 4, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Parsed familiar (fallback): ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(text8);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" Lv");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num3);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" P");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(num4);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" shiny=");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<bool>(flag2);
					}
					log10.LogInfo(val);
					return true;
				}
			}
			Match match5 = _boxHeaderRx.Match(raw);
			if (match5.Success)
			{
				_pendingBoxName = match5.Groups[1].Value;
				_responseDeadline = Time.realtimeSinceStartup + 1.5f;
				ManualLogSource log11 = Core.Log;
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(22, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Box header: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_pendingBoxName);
				}
				log11.LogInfo(val);
				return true;
			}
			return false;
			static string CleanBoxToken(string s)
			{
				string text9 = s.Trim();
				if (text9.EndsWith(":"))
				{
					text9 = text9.Substring(0, text9.Length - 1).Trim();
				}
				return Regex.Replace(text9, "[\n\r\t\\\"']", string.Empty).Trim();
			}
		}

		private static string StripTags(string s)
		{
			return Regex.Replace(s, "<.*?>", string.Empty).Trim();
		}

		public static void BeginAwaitingBoxList()
		{
			_pendingBoxNames.Clear();
			_responseDeadline = Time.realtimeSinceStartup + 3f;
			AwaitingListBoxes = true;
			Core.Log.LogInfo((object)"[FamBook] Awaiting .fam listboxes response...");
		}

		public static void FinalizeListIfExpired()
		{
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			if (AwaitingListBoxes && !(Time.realtimeSinceStartup < _responseDeadline))
			{
				LastListedBoxNames.Clear();
				LastListedBoxNames.AddRange(_pendingBoxNames);
				_pendingBoxNames.Clear();
				AwaitingListBoxes = false;
				IsDirty = true;
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(38, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Finalised listboxes: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(LastListedBoxNames.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" boxes.");
				}
				log.LogInfo(val);
			}
		}

		public static void FinalizeIfExpired()
		{
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			if (AwaitingResponse && !(Time.realtimeSinceStartup < _responseDeadline))
			{
				int currentBoxIndex = CurrentBoxIndex;
				Boxes[currentBoxIndex] = new BoxData(currentBoxIndex, _pendingBoxName, new List<FamiliarEntry>(_pendingEntries));
				CurrentBoxName = _pendingBoxName;
				_pendingEntries.Clear();
				_pendingBoxName = string.Empty;
				AwaitingResponse = false;
				IsDirty = true;
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(40, 3, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Finalised box ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(currentBoxIndex + 1);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" (");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(CurrentBoxName);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("): ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<int>(Boxes[currentBoxIndex].Familiars.Count);
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" familiars.");
				}
				log.LogInfo(val);
			}
		}

		private static int ParseInt(string s)
		{
			int result;
			return int.TryParse(s, NumberStyles.Integer, CultureInfo.InvariantCulture, out result) ? result : 0;
		}

		public static void Reset()
		{
			Boxes.Clear();
			CurrentBoxName = string.Empty;
			CurrentBoxIndex = 0;
			IsDirty = false;
			AwaitingResponse = false;
			AwaitingBindAttempt = false;
			PendingBindFamiliarNumber = 0;
			_pendingEntries.Clear();
			_pendingBoxName = string.Empty;
			AwaitingListBoxes = false;
			_pendingBoxNames.Clear();
			LastListedBoxNames.Clear();
		}
	}
	internal sealed class BoxData
	{
		public int BoxIndex { get; }

		public string BoxName { get; }

		public List<FamiliarEntry> Familiars { get; }

		public string Title => string.IsNullOrEmpty(BoxName) ? $"Box {BoxIndex + 1}" : BoxName;

		public BoxData(int boxIndex, string boxName, List<FamiliarEntry> familiars)
		{
			BoxIndex = boxIndex;
			BoxName = boxName;
			Familiars = familiars;
			base..ctor();
		}
	}
	internal sealed class FamiliarEntry
	{
		public string Name { get; }

		public int Level { get; }

		public int Prestige { get; }

		public string ShinyColorTag { get; }

		public bool IsShiny => ShinyColorTag.Length > 0;

		public string PrestigeLabel => (Prestige > 0) ? ToRoman(Prestige) : string.Empty;

		public FamiliarEntry(string name, int level, int prestige, string shinyColorTag)
		{
			Name = name;
			Level = level;
			Prestige = prestige;
			ShinyColorTag = shinyColorTag;
			base..ctor();
		}

		private static string ToRoman(int num)
		{
			(int, string)[] array = new(int, string)[13]
			{
				(1000, "M"),
				(900, "CM"),
				(500, "D"),
				(400, "CD"),
				(100, "C"),
				(90, "XC"),
				(50, "L"),
				(40, "XL"),
				(10, "X"),
				(9, "IX"),
				(5, "V"),
				(4, "IV"),
				(1, "I")
			};
			StringBuilder stringBuilder = new StringBuilder();
			(int, string)[] array2 = array;
			for (int i = 0; i < array2.Length; i++)
			{
				var (num2, value) = array2[i];
				while (num >= num2)
				{
					stringBuilder.Append(value);
					num -= num2;
				}
			}
			return stringBuilder.ToString();
		}
	}
	internal class SystemService
	{
		private readonly World _world = world ?? throw new ArgumentNullException("world");

		private ClientScriptMapper? _clientScriptMapper;

		private PrefabCollectionSystem? _prefabCollectionSystem;

		private GameDataSystem? _gameDataSystem;

		private ManagedDataSystem? _managedDataSystem;

		private UIDataSystem? _uiDataSystem;

		private HybridModelSystem? _hybridModelSystem;

		public ClientScriptMapper ClientScriptMapper => _clientScriptMapper ?? (_clientScriptMapper = GetSystem<ClientScriptMapper>());

		public PrefabCollectionSystem PrefabCollectionSystem => _prefabCollectionSystem ?? (_prefabCollectionSystem = GetSystem<PrefabCollectionSystem>());

		public GameDataSystem GameDataSystem => _gameDataSystem ?? (_gameDataSystem = GetSystem<GameDataSystem>());

		public ManagedDataSystem ManagedDataSystem => _managedDataSystem ?? (_managedDataSystem = GetSystem<ManagedDataSystem>());

		public UIDataSystem UIDataSystem => _uiDataSystem ?? (_uiDataSystem = GetSystem<UIDataSystem>());

		public HybridModelSystem HybridModelSystem => _hybridModelSystem ?? (_hybridModelSystem = GetSystem<HybridModelSystem>());

		public SystemService(World world)
		{
		}

		private T GetSystem<T>() where T : ComponentSystemBase
		{
			return _world.GetExistingSystemManaged<T>() ?? throw new InvalidOperationException("Failed to get " + Il2CppType.Of<T>().FullName + " from the world.");
		}
	}
}
namespace FamBook.Patches
{
	[HarmonyPatch]
	internal static class ClientChatSystemPatch
	{
		private static EntityManager EntityManager => Core.EntityManager;

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ClientChatSystem), "OnUpdate")]
		private static void OnUpdate_Prefix(ClientChatSystem __instance)
		{
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_003c: 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_0045: 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_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: 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_0059: 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_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_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			//IL_0114: 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_011d: Unknown result type (might be due to invalid IL or missing references)
			if (!Core.HasInitialized || (!DataService.AwaitingResponse && !DataService.AwaitingBindAttempt && !DataService.AwaitingListBoxes && !DataService.AwaitingSearch))
			{
				return;
			}
			EntityQuery receiveChatMessagesQuery = __instance._ReceiveChatMessagesQuery;
			NativeArray<Entity> val = ((EntityQuery)(ref receiveChatMessagesQuery)).ToEntityArray(AllocatorHandle.op_Implicit((Allocator)2));
			try
			{
				Enumerator<Entity> enumerator = val.GetEnumerator();
				bool flag = default(bool);
				while (enumerator.MoveNext())
				{
					Entity current = enumerator.Current;
					if (!current.Has<ChatMessageServerEvent>())
					{
						continue;
					}
					ChatMessageServerEvent val2 = current.Read<ChatMessageServerEvent>();
					if (!((object)(ServerChatMessageType)(ref val2.MessageType)).Equals((object)(ServerChatMessageType)6))
					{
						continue;
					}
					string value = ((FixedString512Bytes)(ref val2.MessageText)).Value;
					if (string.IsNullOrEmpty(value))
					{
						continue;
					}
					ManualLogSource log = Core.Log;
					BepInExInfoLogInterpolatedStringHandler val3 = new BepInExInfoLogInterpolatedStringHandler(21, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val3).AppendLiteral("[FamBook][intercept] ");
						((BepInExLogInterpolatedStringHandler)val3).AppendFormatted<string>(value);
					}
					log.LogInfo(val3);
					try
					{
						if (DataService.TryParseBloodcraftLine(value))
						{
							EntityManager entityManager = EntityManager;
							((EntityManager)(ref entityManager)).DestroyEntity(current);
						}
					}
					catch (Exception ex)
					{
						ManualLogSource log2 = Core.Log;
						BepInExWarningLogInterpolatedStringHandler val4 = new BepInExWarningLogInterpolatedStringHandler(33, 1, ref flag);
						if (flag)
						{
							((BepInExLogInterpolatedStringHandler)val4).AppendLiteral("[FamBook] Error parsing message: ");
							((BepInExLogInterpolatedStringHandler)val4).AppendFormatted<string>(ex.Message);
						}
						log2.LogWarning(val4);
					}
				}
			}
			finally
			{
				val.Dispose();
			}
		}
	}
	[HarmonyPatch]
	internal static class InitializationPatches
	{
		private static bool _setCanvas;

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameDataManager), "OnUpdate")]
		private static void GameDataManager_OnUpdate_Postfix(GameDataManager __instance)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Expected O, but got Unknown
			if (Core.HasInitialized || !__instance.GameDataInitialized || !((ComponentSystemBase)__instance).World.IsCreated)
			{
				return;
			}
			try
			{
				Core.Initialize(__instance);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(39, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] GameDataManager init failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UICanvasSystem), "UpdateHideIfDisabled")]
		private static void UICanvasSystem_UpdateHideIfDisabled_Postfix(UICanvasBase canvas)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			if (_setCanvas || !Core.HasInitialized || Core.CanvasService != null)
			{
				return;
			}
			try
			{
				_setCanvas = true;
				Core.SetCanvas(canvas);
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(40, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Canvas initialization failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(ClientBootstrapSystem), "OnDestroy")]
		private static void ClientBootstrapSystem_OnDestroy_Prefix()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			try
			{
				_setCanvas = false;
				CanvasService.ResetState();
				Core.Reset();
			}
			catch (Exception ex)
			{
				ManualLogSource log = Core.Log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(24, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("[FamBook] Reset failed: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}
	}
}