Decompiled source of MonsterCompendium v1.2.1

plugins/MonsterCompendium.dll

Decompiled 13 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using GUIFramework;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("MonsterCompendium")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.2.1.0")]
[assembly: AssemblyInformationalVersion("1.2.1+54b6bd36ef68ea9f0f4508e668d6c18804540894")]
[assembly: AssemblyProduct("MonsterCompendium")]
[assembly: AssemblyTitle("MonsterCompendium")]
[assembly: AssemblyVersion("1.2.1.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MonsterCompendium
{
	internal static class AttackDamage
	{
		private static readonly DamageType[] Types;

		public static IEnumerable<DamageType> Components(DamageType damage)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return Types.Where((DamageType type) => (damage & type) > 0);
		}

		public static DamageType? Resolve(Attack attack, ItemData weapon, List<ItemData> equipment)
		{
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: 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_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected I4, but got Unknown
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_017b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: 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_01e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029e: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0173: Unknown result type (might be due to invalid IL or missing references)
			HashSet<GameObject> visited = new HashSet<GameObject>();
			DamageType primary = Mask(weapon.GetDamage(weapon.m_quality, 0f));
			AttackType attackType = attack.m_attackType;
			switch ((int)attackType)
			{
			case 0:
			case 1:
				return (DamageType?)(primary | (??)TriggerDamage(attack, weapon, visited) | (??)SpawnDamage((attack.m_spawnOnHitChance > 0f) ? attack.m_spawnOnHit : null, null, visited) | (??)SpawnDamage(weapon.m_shared.m_spawnOnHit, null, visited));
			case 4:
				return (DamageType?)(primary | (??)TriggerDamage(attack, weapon, visited));
			case 2:
			{
				if (string.IsNullOrEmpty(weapon.m_shared.m_ammoType))
				{
					return ProjectileDamage(attack.m_attackProjectile, primary, attack, visited);
				}
				DamageType?[] array = equipment.Where((ItemData item) => item.m_shared.m_ammoType == weapon.m_shared.m_ammoType && ((int)item.m_shared.m_itemType == 9 || (int)item.m_shared.m_itemType == 2)).Select(delegate(ItemData ammo)
				{
					//IL_002f: 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_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)
					GameObject val = ammo.m_shared.m_attack?.m_attackProjectile;
					return ProjectileDamage(Object.op_Implicit((Object)(object)val) ? val : attack.m_attackProjectile, (DamageType)(primary | Mask(ammo.GetDamage(ammo.m_quality, 0f))), attack, visited);
				}).Distinct()
					.Take(2)
					.ToArray();
				if (array.Length != 1)
				{
					return null;
				}
				return array[0];
			}
			case 3:
				return (DamageType?)((??)EffectDamage(attack.m_triggerEffect, visited) | (??)EffectDamage(weapon.m_shared.m_triggerEffect, visited));
			default:
				return null;
			}
		}

		private static DamageType? TriggerDamage(Attack attack, ItemData weapon, HashSet<GameObject> visited)
		{
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: 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_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			return (DamageType?)((??)SpawnDamage(attack.m_spawnOnTrigger, null, visited) | (??)EffectDamage(attack.m_triggerEffect, visited) | (??)EffectDamage(weapon.m_shared.m_triggerEffect, visited));
		}

		private static DamageType? EffectDamage(EffectList effects, HashSet<GameObject> visited)
		{
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			DamageType? val = (DamageType)0;
			if (effects?.m_effectPrefabs != null)
			{
				EffectData[] effectPrefabs = effects.m_effectPrefabs;
				foreach (EffectData val2 in effectPrefabs)
				{
					if (val2 != null && val2.m_enabled)
					{
						val = (DamageType?)((??)val | (??)SpawnDamage(val2.m_prefab, null, visited));
					}
				}
			}
			return val;
		}

		private static DamageType? ProjectileDamage(GameObject prefab, DamageType damage, Attack attack, HashSet<GameObject> visited)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				return null;
			}
			return SpawnDamage(prefab, damage, visited, attack);
		}

		private static DamageType? SpawnDamage(GameObject prefab, DamageType? inherited, HashSet<GameObject> visited, Attack attack = null)
		{
			//IL_0090: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0200: Unknown result type (might be due to invalid IL or missing references)
			//IL_0279: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: 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_01a0: 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_01ac: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)prefab) || !visited.Add(prefab))
			{
				return (DamageType)0;
			}
			DamageType? val = (DamageType)0;
			IProjectile componentInChildren = prefab.GetComponentInChildren<IProjectile>();
			Projectile val2 = (Projectile)(object)((componentInChildren is Projectile) ? componentInChildren : null);
			if (val2 == null)
			{
				Aoe val3 = (Aoe)(object)((componentInChildren is Aoe) ? componentInChildren : null);
				if (val3 == null)
				{
					SpawnAbility val4 = (SpawnAbility)(object)((componentInChildren is SpawnAbility) ? componentInChildren : null);
					if (val4 == null)
					{
						if (!(componentInChildren is TriggerSpawnAbility) && componentInChildren != null)
						{
							val = null;
						}
					}
					else
					{
						val = SpawnDamage(val4.m_aoePrefab, null, visited);
						if (val4.m_spawnPrefab != null)
						{
							GameObject[] spawnPrefab = val4.m_spawnPrefab;
							foreach (GameObject prefab2 in spawnPrefab)
							{
								val = (DamageType?)((??)val | (??)SpawnDamage(prefab2, null, visited));
							}
						}
					}
				}
				else
				{
					val = (DamageType)((val3.m_useAttackSettings && inherited.HasValue) ? inherited.Value : (Mask(val3.m_damage) | Mask(val3.m_damagePerLevel)));
				}
			}
			else
			{
				if (!val2.m_onlySpawnedProjectilesDealDamage)
				{
					val = (DamageType)(((??)inherited) ?? Mask(val2.m_damage));
				}
				bool flag = attack != null && Object.op_Implicit((Object)(object)attack.m_spawnOnHit) && attack.m_spawnOnHitChance > 0f;
				GameObject prefab3 = (flag ? attack.m_spawnOnHit : val2.m_spawnOnHit);
				if (val2.m_spawnCount > 0 && (flag || val2.m_spawnOnHitChance > 0f))
				{
					DamageType? inherited2 = (val2.m_projectilesInheritHitData ? inherited : ((DamageType?)null));
					val = (DamageType?)((??)val | (??)SpawnDamage(prefab3, inherited2, visited));
				}
				if (val2.m_randomSpawnOnHitCount > 0 && val2.m_randomSpawnOnHit != null)
				{
					foreach (GameObject item in val2.m_randomSpawnOnHit)
					{
						val = (DamageType?)((??)val | (??)SpawnDamage(item, null, visited));
					}
				}
			}
			visited.Remove(prefab);
			return val;
		}

		internal static DamageType Mask(DamageTypes damage)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: 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_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			DamageType val = (DamageType)0;
			DamageType[] types = Types;
			foreach (DamageType val2 in types)
			{
				if (Combat.DamageOfType(damage, val2) > 0f)
				{
					val |= val2;
				}
			}
			return val;
		}

		static AttackDamage()
		{
			DamageType[] array = new DamageType[12];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			Types = (DamageType[])(object)array;
		}
	}
	internal static class BookText
	{
		public static string Title => Label("Monster compendium", "Bestiaire");

		public static string Label(string english, string french)
		{
			Localization instance = Localization.instance;
			if (!(((instance != null) ? instance.GetSelectedLanguage() : null) == "French"))
			{
				return english;
			}
			return french;
		}

		public static string Section(FactKind kind)
		{
			return kind switch
			{
				FactKind.Level => Label("Levels seen", "Niveaux observés"), 
				FactKind.Biome => Label("Biomes", "Biomes"), 
				FactKind.Faction => Label("Factions", "Factions"), 
				FactKind.Taming => Label("Taming", "Apprivoisement"), 
				FactKind.Attack => Label("Attacks seen", "Attaques observées"), 
				_ => Label("Damage responses", "Réactions aux dégâts"), 
			};
		}

		public static string Value(FactKind kind, string value)
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			switch (kind)
			{
			case FactKind.Level:
			{
				if (int.TryParse(value, out var result2))
				{
					int num = result2 - 1;
					return num switch
					{
						1 => Label("1 star", "1 étoile"), 
						0 => Label("No stars", "Sans étoile"), 
						_ => num + Label(" stars", " étoiles"), 
					};
				}
				return value;
			}
			case FactKind.Biome:
			{
				if (!Enum.TryParse<Biome>(value, out Biome result))
				{
					return CreatureNames.Words(value);
				}
				return Localization.instance.Localize(BiomeSector.GetBiomeName(result));
			}
			case FactKind.Faction:
				return Faction(value);
			case FactKind.Taming:
				return Label("Tameable", "Apprivoisable");
			default:
				return CreatureNames.Words(value);
			}
		}

		public unsafe static string Attack(string animation, DamageType? damage)
		{
			//IL_0032: 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)
			string text = CreatureNames.Words(animation);
			if (!damage.HasValue)
			{
				return text + " (" + Label("damage type unknown", "type de dégâts inconnu") + ")";
			}
			string text2 = (((int)damage.Value == 0) ? Label("no direct damage", "sans dégâts directs") : string.Join(", ", from type in AttackDamage.Components(damage.Value)
				select DamageType(((object)(*(DamageType*)(&type))/*cast due to .constrained prefix*/).ToString())));
			return text + " (" + text2 + ")";
		}

		public static (string Type, string Response) DamageResponse(string value)
		{
			string[] array = value.Split(new char[1] { ':' });
			if (array.Length != 3)
			{
				return (Type: value, Response: "");
			}
			string text = ((array[2] == "weakspot") ? Label(" (weak spot)", " (point faible)") : "");
			return (Type: DamageType(array[0]), Response: DamageModifier(array[1]) + text);
		}

		private static string Faction(string value)
		{
			return value switch
			{
				"Players" => Label("Players", "Joueurs"), 
				"AnimalsVeg" => Label("Wild animals", "Animaux sauvages"), 
				"ForestMonsters" => Label("Forest monsters", "Monstres de la forêt"), 
				"Undead" => Label("Undead", "Morts-vivants"), 
				"Demon" => Label("Demons", "Démons"), 
				"MountainMonsters" => Label("Mountain monsters", "Monstres de la montagne"), 
				"SeaMonsters" => Label("Sea monsters", "Monstres marins"), 
				"PlainsMonsters" => Label("Plains monsters", "Monstres des plaines"), 
				"Boss" => Label("Bosses", "Boss"), 
				"MistlandsMonsters" => Label("Mistlands monsters", "Monstres des Terres embrumées"), 
				"PlayerSpawned" => Label("Player summons", "Invocations des joueurs"), 
				"DeepNorth" => Label("Deep North", "Grand Nord"), 
				_ => CreatureNames.Words(value), 
			};
		}

		private static string DamageType(string value)
		{
			return value switch
			{
				"Blunt" => Label("Blunt", "Contondant"), 
				"Slash" => Label("Slash", "Tranchant"), 
				"Pierce" => Label("Pierce", "Perforant"), 
				"Chop" => Label("Chop", "Coupe de bois"), 
				"Pickaxe" => Label("Pickaxe", "Pioche"), 
				"Fire" => Label("Fire", "Feu"), 
				"Frost" => Label("Frost", "Gel"), 
				"Lightning" => Label("Lightning", "Foudre"), 
				"Poison" => Label("Poison", "Poison"), 
				"Spirit" => Label("Spirit", "Esprit"), 
				"Damage" => Label("Untyped", "Non typé"), 
				"NonPlayer" => Label("Non-player", "Hors joueurs"), 
				_ => CreatureNames.Words(value), 
			};
		}

		private static string DamageModifier(string value)
		{
			return value switch
			{
				"Normal" => Label("normal", "normal"), 
				"Resistant" => Label("resistant", "résistant"), 
				"VeryResistant" => Label("very resistant", "très résistant"), 
				"SlightlyResistant" => Label("slightly resistant", "légèrement résistant"), 
				"Weak" => Label("weak", "vulnérable"), 
				"VeryWeak" => Label("very weak", "très vulnérable"), 
				"SlightlyWeak" => Label("slightly weak", "légèrement vulnérable"), 
				"Immune" => Label("immune", "immunisé"), 
				_ => CreatureNames.Words(value), 
			};
		}
	}
	internal static class BookUi
	{
		public static RectTransform Rect(string name, Transform parent)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			RectTransform component = new GameObject(name, new Type[1] { typeof(RectTransform) }).GetComponent<RectTransform>();
			((Transform)component).SetParent(parent, false);
			return component;
		}

		public static RectTransform Place(string name, Transform parent, float x, float y, float width, float height)
		{
			//IL_001b: 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_0022: 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_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = Rect(name, parent);
			Vector2 val = default(Vector2);
			((Vector2)(ref val))..ctor(0f, 1f);
			obj.pivot = val;
			Vector2 anchorMin = (obj.anchorMax = val);
			obj.anchorMin = anchorMin;
			obj.anchoredPosition = new Vector2(x, 0f - y);
			obj.sizeDelta = new Vector2(width, height);
			return obj;
		}

		public static void Fill(RectTransform rect, float left = 0f, float top = 0f, float right = 0f, float bottom = 0f)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: 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)
			rect.anchorMin = Vector2.zero;
			rect.anchorMax = Vector2.one;
			rect.offsetMin = new Vector2(left, bottom);
			rect.offsetMax = new Vector2(0f - right, 0f - top);
		}

		public static Image Image(RectTransform rect, Color color, Image template = null, bool raycast = false)
		{
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Image val = ((Component)rect).gameObject.AddComponent<Image>();
			((Graphic)val).color = color;
			((Graphic)val).raycastTarget = raycast;
			if (Object.op_Implicit((Object)(object)template))
			{
				val.sprite = template.sprite;
				val.type = template.type;
				val.pixelsPerUnitMultiplier = template.pixelsPerUnitMultiplier;
			}
			return val;
		}

		public static Button Button(RectTransform rect, Image target, Action click)
		{
			//IL_0029: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: 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_00e4: Expected O, but got Unknown
			Button obj = ((Component)rect).gameObject.AddComponent<Button>();
			((Graphic)target).raycastTarget = true;
			((Selectable)obj).targetGraphic = (Graphic)(object)target;
			Navigation navigation = default(Navigation);
			((Navigation)(ref navigation)).mode = (Mode)0;
			((Selectable)obj).navigation = navigation;
			ColorBlock colors = default(ColorBlock);
			((ColorBlock)(ref colors)).normalColor = Color.white;
			((ColorBlock)(ref colors)).highlightedColor = new Color(1f, 0.84f, 0.57f);
			((ColorBlock)(ref colors)).pressedColor = new Color(0.86f, 0.67f, 0.42f);
			((ColorBlock)(ref colors)).selectedColor = Color.white;
			((ColorBlock)(ref colors)).disabledColor = new Color(0.68f, 0.66f, 0.64f);
			((ColorBlock)(ref colors)).colorMultiplier = 1f;
			((ColorBlock)(ref colors)).fadeDuration = 0.08f;
			((Selectable)obj).colors = colors;
			((UnityEvent)obj.onClick).AddListener((UnityAction)delegate
			{
				click();
			});
			return obj;
		}

		public static TextMeshProUGUI Label(RectTransform rect, TMP_Text template, string text, float size, TextAlignmentOptions alignment = (TextAlignmentOptions)513, bool wrap = false)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			TextMeshProUGUI obj = ((Component)rect).gameObject.AddComponent<TextMeshProUGUI>();
			((TMP_Text)obj).font = template.font;
			((TMP_Text)obj).fontSharedMaterial = template.fontSharedMaterial;
			((TMP_Text)obj).fontStyle = template.fontStyle;
			((Graphic)obj).color = ((Graphic)template).color;
			((TMP_Text)obj).fontSize = size;
			((TMP_Text)obj).alignment = alignment;
			((TMP_Text)obj).textWrappingMode = (TextWrappingModes)(wrap ? 1 : 0);
			((TMP_Text)obj).overflowMode = (TextOverflowModes)1;
			((Graphic)obj).raycastTarget = false;
			((TMP_Text)obj).text = text;
			return obj;
		}

		public static void Clear(RectTransform parent)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			foreach (Transform item in (Transform)parent)
			{
				((Component)item).gameObject.SetActive(false);
				Object.Destroy((Object)(object)((Component)item).gameObject);
			}
		}

		public static Texture2D LoadBookTexture()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Expected O, but got Unknown
			using Stream stream = typeof(BookUi).Assembly.GetManifestResourceStream("MonsterCompendium.assets.book.png");
			byte[] array = new byte[stream.Length];
			using (BinaryReader binaryReader = new BinaryReader(stream))
			{
				array = binaryReader.ReadBytes(array.Length);
			}
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			typeof(ImageConversion).GetMethod("LoadImage", new Type[3]
			{
				typeof(Texture2D),
				typeof(byte[]),
				typeof(bool)
			}).Invoke(null, new object[3] { val, array, true });
			return val;
		}
	}
	internal sealed class BookScroll
	{
		private readonly ScrollRect scroll;

		public RectTransform Content { get; }

		public float Width { get; }

		public BookScroll(RectTransform root, float width, bool showScrollbar, float scrollSensitivity, Scrollbar style = null)
		{
			//IL_004f: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0156: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0260: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_029a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			Width = width - (float)(showScrollbar ? 24 : 12);
			RectTransform val = BookUi.Rect("Viewport", (Transform)(object)root);
			BookUi.Fill(val, 6f, 6f, showScrollbar ? 18 : 6, 6f);
			((Component)val).gameObject.AddComponent<RectMask2D>();
			BookUi.Image(val, Color.clear, null, raycast: true);
			Content = BookUi.Rect("Content", (Transform)(object)val);
			Content.anchorMin = new Vector2(0f, 1f);
			Content.anchorMax = new Vector2(1f, 1f);
			Content.pivot = new Vector2(0f, 1f);
			Content.anchoredPosition = Vector2.zero;
			Content.sizeDelta = Vector2.zero;
			scroll = ((Component)root).gameObject.AddComponent<ScrollRect>();
			scroll.content = Content;
			scroll.viewport = val;
			scroll.horizontal = false;
			scroll.movementType = (MovementType)2;
			scroll.scrollSensitivity = scrollSensitivity;
			if (showScrollbar)
			{
				RectTransform val2 = BookUi.Rect("Scrollbar", (Transform)(object)root);
				val2.anchorMin = new Vector2(1f, 0f);
				val2.anchorMax = Vector2.one;
				val2.offsetMin = new Vector2(-14f, 7f);
				val2.offsetMax = new Vector2(-6f, -7f);
				Image val3 = (Object.op_Implicit((Object)(object)style) ? ((Component)style).GetComponent<Image>() : null);
				BookUi.Image(val2, (Color)(Object.op_Implicit((Object)(object)val3) ? ((Graphic)val3).color : new Color(0.1f, 0.065f, 0.038f, 0.78f)), val3, raycast: true);
				RectTransform val4 = BookUi.Rect("Sliding area", (Transform)(object)val2);
				BookUi.Fill(val4, 1f, 1f, 1f, 1f);
				RectTransform val5 = BookUi.Rect("Thumb", (Transform)(object)val4);
				BookUi.Fill(val5);
				Image val6 = (Image)(Object.op_Implicit((Object)(object)style) ? /*isinst with value type is only supported in some contexts*/: null);
				Image targetGraphic = BookUi.Image(val5, (Color)(Object.op_Implicit((Object)(object)val6) ? ((Graphic)val6).color : new Color(0.72f, 0.49f, 0.27f, 0.9f)), val6, raycast: true);
				Scrollbar val7 = ((Component)val2).gameObject.AddComponent<Scrollbar>();
				val7.handleRect = val5;
				((Selectable)val7).targetGraphic = (Graphic)(object)targetGraphic;
				val7.direction = (Direction)2;
				Navigation navigation = default(Navigation);
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)val7).navigation = navigation;
				scroll.verticalScrollbar = val7;
				scroll.verticalScrollbarVisibility = (ScrollbarVisibility)1;
			}
		}

		public void SetHeight(float height, bool reset = true)
		{
			//IL_000c: 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)
			Content.sizeDelta = new Vector2(0f, height);
			if (reset)
			{
				scroll.StopMovement();
				Content.anchoredPosition = Vector2.zero;
			}
		}

		public bool Shows(float top, float height)
		{
			//IL_0006: 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_002f: Unknown result type (might be due to invalid IL or missing references)
			float y = Content.anchoredPosition.y;
			if (top + 1f >= y)
			{
				float num = top + height;
				Rect rect = scroll.viewport.rect;
				return num <= y + ((Rect)(ref rect)).height + 1f;
			}
			return false;
		}
	}
	internal static class Combat
	{
		[HarmonyPatch(typeof(ZSyncAnimation), "RPC_SetTrigger")]
		private static class AttackTrigger
		{
			private static void Postfix(ZSyncAnimation __instance, string __1)
			{
				Plugin instance = Plugin.Instance;
				if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer))
				{
					return;
				}
				try
				{
					Humanoid componentInParent = ((Component)__instance).GetComponentInParent<Humanoid>();
					if (Object.op_Implicit((Object)(object)componentInParent) && !((Character)componentInParent).IsPlayer())
					{
						instance.QueueAttack(componentInParent, __1);
					}
				}
				catch (Exception error)
				{
					instance.LogObservationError(error);
				}
			}
		}

		[HarmonyPatch(typeof(Humanoid), "OnAttackTrigger")]
		private static class AttackReleased
		{
			private static void Postfix(Humanoid __instance)
			{
				Plugin instance = Plugin.Instance;
				if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)Player.m_localPlayer) || ((Character)__instance).IsPlayer())
				{
					return;
				}
				try
				{
					instance.ReleaseAttack(__instance);
				}
				catch (Exception error)
				{
					instance.LogObservationError(error);
				}
			}
		}

		[HarmonyPatch(typeof(Character), "RPC_Damage")]
		private static class DamageResolution
		{
			private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
			{
				MethodInfo original = AccessTools.Method(typeof(HitData), "ApplyResistance", (Type[])null, (Type[])null);
				MethodInfo replacement = AccessTools.Method(typeof(Combat), "ApplyAndObserve", (Type[])null, (Type[])null);
				foreach (CodeInstruction instruction in instructions)
				{
					if (!CodeInstructionExtensions.Calls(instruction, original))
					{
						yield return instruction;
						continue;
					}
					CodeInstruction val = new CodeInstruction(OpCodes.Ldarg_0, (object)null);
					val.labels.AddRange(instruction.labels);
					val.blocks.AddRange(instruction.blocks);
					yield return val;
					yield return new CodeInstruction(OpCodes.Call, (object)replacement);
				}
			}
		}

		internal const string DamageResultRpc = "fr.romaindurand.monstercompendium.damage.v1";

		private static readonly DamageType[] Types;

		private static void ApplyAndObserve(HitData hit, DamageModifiers modifiers, out DamageModifier result, Character target)
		{
			//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_0008: 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_0033: Unknown result type (might be due to invalid IL or missing references)
			DamageTypes damage = hit.m_damage;
			hit.ApplyResistance(modifiers, ref result);
			Plugin instance = Plugin.Instance;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)target) || target.IsPlayer())
			{
				return;
			}
			try
			{
				ObserveDamage(instance, target, hit, damage, modifiers);
			}
			catch (Exception error)
			{
				instance.LogObservationError(error);
			}
		}

		private static void ObserveDamage(Plugin plugin, Character target, HitData hit, DamageTypes damage, DamageModifiers modifiers)
		{
			//IL_0067: 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_008b: 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_0090: Invalid comparison between Unknown and I4
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0153: Expected O, but got Unknown
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			Character attacker = hit.GetAttacker();
			Player val = (Player)(object)((attacker is Player) ? attacker : null);
			if (val == null || !Object.op_Implicit((Object)(object)val))
			{
				return;
			}
			Creature creature = plugin.Catalog.Find(target);
			if (creature == null)
			{
				return;
			}
			short weakSpot = hit.m_weakSpot;
			bool flag = weakSpot >= 0 && target.m_weakSpots != null && weakSpot < target.m_weakSpots.Length && Object.op_Implicit((Object)(object)target.m_weakSpots[weakSpot]);
			Player localPlayer = Player.m_localPlayer;
			uint num = 0u;
			for (int i = 0; i < Types.Length; i++)
			{
				if (DamageOfType(damage, Types[i]) <= 0f)
				{
					continue;
				}
				DamageModifier modifier = ((DamageModifiers)(ref modifiers)).GetModifier(Types[i]);
				if ((int)modifier != 4 && Enum.IsDefined(typeof(DamageModifier), modifier))
				{
					if ((Object)(object)val == (Object)(object)localPlayer)
					{
						StoreDamage(plugin, creature, Types[i], modifier, flag);
					}
					else
					{
						num |= (uint)(1 << i);
					}
				}
			}
			if (num == 0)
			{
				return;
			}
			ZRoutedRpc instance = ZRoutedRpc.instance;
			ZDOID zDOID = ((Character)val).GetZDOID();
			ZDOMan instance2 = ZDOMan.instance;
			long? obj;
			if (instance2 == null)
			{
				obj = null;
			}
			else
			{
				ZDO zDO = instance2.GetZDO(zDOID);
				obj = ((zDO != null) ? new long?(zDO.GetOwner()) : ((long?)null));
			}
			long? num2 = obj;
			long valueOrDefault = num2.GetValueOrDefault();
			if (instance == null || valueOrDefault == 0L || valueOrDefault == ZNet.GetUID())
			{
				return;
			}
			ZPackage val2 = new ZPackage();
			val2.Write(zDOID);
			val2.Write(target.GetZDOID());
			val2.Write(flag);
			for (int j = 0; j < Types.Length; j++)
			{
				if ((num & (uint)(1 << j)) != 0)
				{
					val2.Write((byte)j);
					val2.Write((byte)((DamageModifiers)(ref modifiers)).GetModifier(Types[j]));
				}
			}
			instance.InvokeRoutedRPC(valueOrDefault, "fr.romaindurand.monstercompendium.damage.v1", new object[1] { val2 });
		}

		internal static void ReceiveDamage(long sender, ZPackage packet)
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Invalid comparison between Unknown and I4
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
			Plugin instance = Plugin.Instance;
			Player localPlayer = Player.m_localPlayer;
			if (!Object.op_Implicit((Object)(object)instance) || !Object.op_Implicit((Object)(object)localPlayer) || packet == null)
			{
				return;
			}
			try
			{
				int num = packet.Size();
				if (num <= 25 || num > 25 + 2 * Types.Length || (num - 25) % 2 != 0 || packet.ReadZDOID() != ((Character)localPlayer).GetZDOID())
				{
					return;
				}
				ZDOMan instance2 = ZDOMan.instance;
				ZDO val = ((instance2 != null) ? instance2.GetZDO(packet.ReadZDOID()) : null);
				if (val == null || val.GetOwner() != sender)
				{
					return;
				}
				Creature creature = instance.Catalog.Find(val);
				if (creature == null)
				{
					return;
				}
				bool weakSpot = packet.ReadBool();
				while (packet.GetPos() < num)
				{
					int num2 = packet.ReadByte();
					DamageModifier val2 = (DamageModifier)packet.ReadByte();
					if (num2 < Types.Length && (int)val2 != 4 && Enum.IsDefined(typeof(DamageModifier), val2))
					{
						StoreDamage(instance, creature, Types[num2], val2, weakSpot);
					}
				}
			}
			catch (Exception error)
			{
				instance.LogObservationError(error);
			}
		}

		private static void StoreDamage(Plugin plugin, Creature creature, DamageType type, DamageModifier modifier, bool weakSpot)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			plugin.Observe(creature, FactKind.Damage, string.Format("{0}:{1}:{2}", type, modifier, weakSpot ? "weakspot" : "body"));
		}

		internal static float DamageOfType(DamageTypes damage, DamageType type)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0003: Invalid comparison between Unknown and I4
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Invalid comparison between Unknown and I4
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Invalid comparison between Unknown and I4
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Invalid comparison between Unknown and I4
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Invalid comparison between Unknown and I4
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002d: Invalid comparison between Unknown and I4
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected I4, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Invalid comparison between Unknown and I4
			//IL_00a3: 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_0054: Invalid comparison between Unknown and I4
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Invalid comparison between Unknown and I4
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Invalid comparison between Unknown and I4
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Invalid comparison between Unknown and I4
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Invalid comparison between Unknown and I4
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			if ((int)type <= 64)
			{
				if ((int)type <= 8)
				{
					switch (type - 1)
					{
					default:
						if ((int)type != 8)
						{
							break;
						}
						return damage.m_chop;
					case 0:
						return damage.m_blunt;
					case 1:
						return damage.m_slash;
					case 3:
						return damage.m_pierce;
					case 2:
						break;
					}
				}
				else
				{
					if ((int)type == 16)
					{
						return damage.m_pickaxe;
					}
					if ((int)type == 32)
					{
						return damage.m_fire;
					}
					if ((int)type == 64)
					{
						return damage.m_frost;
					}
				}
			}
			else if ((int)type <= 256)
			{
				if ((int)type == 128)
				{
					return damage.m_lightning;
				}
				if ((int)type == 256)
				{
					return damage.m_poison;
				}
			}
			else
			{
				if ((int)type == 512)
				{
					return damage.m_spirit;
				}
				if ((int)type == 1024)
				{
					return damage.m_damage;
				}
				if ((int)type == 2048)
				{
					return damage.m_nonPlayer;
				}
			}
			return 0f;
		}

		static Combat()
		{
			DamageType[] array = new DamageType[10];
			RuntimeHelpers.InitializeArray(array, (RuntimeFieldHandle)/*OpCode not supported: LdMemberToken*/);
			Types = (DamageType[])(object)array;
		}
	}
	internal sealed class CompendiumView : IDisposable
	{
		private const float LeftWidth = 310f;

		private const float RowHeight = 32f;

		private const float FactHeight = 29f;

		private const float IconSize = 64f;

		private static readonly string[] ToolbarNames = new string[6] { "Texts", "Skills", "Trophies", "Achievements", "PVP", "CraftingBook" };

		private static readonly Color Gold = Color32.op_Implicit(new Color32(byte.MaxValue, (byte)194, (byte)104, byte.MaxValue));

		private static readonly Color Ink = Color32.op_Implicit(new Color32((byte)16, (byte)14, (byte)13, (byte)224));

		private static readonly Color RowFill = Color32.op_Implicit(new Color32((byte)215, (byte)201, (byte)181, (byte)18));

		private static readonly Color SelectedFill = Color32.op_Implicit(new Color32((byte)193, (byte)129, (byte)47, (byte)143));

		private static readonly Color UnreadFill = Color32.op_Implicit(new Color32((byte)193, (byte)129, (byte)47, (byte)46));

		private static readonly Color Muted = Color32.op_Implicit(new Color32((byte)205, (byte)191, (byte)169, byte.MaxValue));

		private static readonly Color Rule = Color32.op_Implicit(new Color32((byte)173, (byte)116, (byte)53, (byte)125));

		private readonly RectTransform bar;

		private readonly RectTransform icon;

		private readonly RectTransform modal;

		private readonly RectTransform presetOverlay;

		private readonly Canvas canvas;

		private readonly bool embedded;

		private readonly Texture2D texture;

		private readonly Sprite sprite;

		private readonly BookScroll list;

		private readonly BookScroll details;

		private readonly BookScroll menu;

		private readonly GuiInputField search;

		private readonly TMP_Text presetLabel;

		private readonly TMP_Text detailTitle;

		private readonly TMP_Text body;

		private readonly Creatures catalog;

		private readonly Func<Journal> currentJournal;

		private readonly Func<Fact, bool> markRead;

		private readonly List<(Creature Creature, Image Background, TMP_Text Label, Image Marker)> creatureRows = new List<(Creature, Image, TMP_Text, Image)>();

		private readonly List<(Fact Fact, float Top, float Height)> detailRows = new List<(Fact, float, float)>();

		private readonly HashSet<Fact> highlighted = new HashSet<Fact>();

		private readonly List<RectTransform> toolbarButtons = new List<RectTransform>();

		private readonly Dictionary<RectTransform, (Vector3 Original, Vector3 Applied)> toolbarPositions = new Dictionary<RectTransform, (Vector3, Vector3)>();

		private (FactKind Kind, string Value)? preset;

		private Dictionary<string, string> creatureNames;

		private Creature selected;

		private FactKind? menuGroup;

		public bool IsOpen
		{
			get
			{
				if (Object.op_Implicit((Object)(object)modal))
				{
					return ((Component)modal).gameObject.activeInHierarchy;
				}
				return false;
			}
		}

		public bool IsSearchFocused
		{
			get
			{
				if (IsOpen && ((Behaviour)search).isActiveAndEnabled)
				{
					return ((TMP_InputField)search).isFocused;
				}
				return false;
			}
		}

		public static CompendiumView Create(InventoryGui gui, Creatures catalog, Func<Journal> currentJournal, Action toggle, Func<Fact, bool> markRead, RectTransform host = null)
		{
			RectTransform info = gui.m_info;
			Canvas val = (Object.op_Implicit((Object)(object)info) ? ((Component)info).GetComponentInParent<Canvas>(true) : null);
			Transform val2 = (Object.op_Implicit((Object)(object)gui.m_skillsDialog) ? ((Component)gui.m_skillsDialog).transform.Find("SkillsFrame") : null);
			object obj;
			if (!Object.op_Implicit((Object)(object)gui.m_crafting))
			{
				obj = null;
			}
			else
			{
				Transform obj2 = ((Transform)gui.m_crafting).Find("Bkg");
				obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
			}
			Image val3 = (Image)obj;
			if (!Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val2))
			{
				Transform obj3 = val2.Find("bkg");
				val3 = ((obj3 != null) ? ((Component)obj3).GetComponent<Image>() : null);
			}
			object obj4;
			if (!Object.op_Implicit((Object)(object)val2))
			{
				obj4 = null;
			}
			else
			{
				Transform obj5 = val2.Find("Closebutton");
				obj4 = ((obj5 != null) ? ((Component)obj5).GetComponent<Image>() : null);
			}
			Image val4 = (Image)obj4;
			object obj6;
			if (!Object.op_Implicit((Object)(object)val2))
			{
				obj6 = null;
			}
			else
			{
				Transform obj7 = val2.Find("topic");
				obj6 = ((obj7 != null) ? ((Component)obj7).GetComponent<TMP_Text>() : null);
			}
			TMP_Text val5 = (TMP_Text)obj6;
			if (!Object.op_Implicit((Object)(object)val5) || !Object.op_Implicit((Object)(object)gui.m_recipeDecription) || (!Object.op_Implicit((Object)(object)host) && (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4))))
			{
				return null;
			}
			UIGroupHandler component = ((Component)gui.m_skillsDialog).GetComponent<UIGroupHandler>();
			ScrollRect val6 = (Object.op_Implicit((Object)(object)gui.m_recipeListRoot) ? ((Component)gui.m_recipeListRoot).GetComponentInParent<ScrollRect>(true) : null);
			return new CompendiumView(info, val, val3, val4, val5, gui.m_recipeDecription, Object.op_Implicit((Object)(object)component) ? component.m_groupPriority : 2, Object.op_Implicit((Object)(object)val6) ? val6.scrollSensitivity : 3000f, catalog, currentJournal, toggle, markRead, gui, host);
		}

		private CompendiumView(RectTransform bar, Canvas sourceCanvas, Image background, Image buttonStyle, TMP_Text titleStyle, TMP_Text body, int priority, float sensitivity, Creatures catalog, Func<Journal> currentJournal, Action toggle, Func<Fact, bool> markRead, InventoryGui gui, RectTransform host)
		{
			//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Expected O, but got Unknown
			//IL_025a: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_031e: Unknown result type (might be due to invalid IL or missing references)
			//IL_032a: Unknown result type (might be due to invalid IL or missing references)
			//IL_036d: Unknown result type (might be due to invalid IL or missing references)
			//IL_03aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0492: Unknown result type (might be due to invalid IL or missing references)
			//IL_050c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0503: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d8: Unknown result type (might be due to invalid IL or missing references)
			//IL_064a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_072b: Unknown result type (might be due to invalid IL or missing references)
			//IL_075f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0769: Unknown result type (might be due to invalid IL or missing references)
			//IL_076e: Unknown result type (might be due to invalid IL or missing references)
			//IL_076f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0776: Unknown result type (might be due to invalid IL or missing references)
			//IL_0789: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_07bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_07db: Unknown result type (might be due to invalid IL or missing references)
			//IL_07d2: Unknown result type (might be due to invalid IL or missing references)
			this.bar = bar;
			this.body = body;
			this.catalog = catalog;
			this.currentJournal = currentJournal;
			this.markRead = markRead;
			embedded = Object.op_Implicit((Object)(object)host);
			float num = (embedded ? 1120 : 1080);
			RectTransform val;
			if (embedded)
			{
				modal = BookUi.Rect("Monster compendium", (Transform)(object)host);
				val = modal;
			}
			else
			{
				icon = BookUi.Rect("MonsterCompendium", (Transform)(object)bar);
				icon.sizeDelta = Vector2.one * 64f;
				texture = BookUi.LoadBookTexture();
				sprite = Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), Vector2.one * 0.5f);
				Image val2 = BookUi.Image(icon, Color.white);
				val2.sprite = sprite;
				val2.preserveAspect = true;
				BookUi.Button(icon, val2, toggle);
				Transform obj = ((Transform)bar).Find("Skills");
				UITooltip val3 = ((obj != null) ? ((Component)obj).GetComponent<UITooltip>() : null);
				if (Object.op_Implicit((Object)(object)val3) && Object.op_Implicit((Object)(object)val3.m_tooltipPrefab))
				{
					UITooltip obj2 = ((Component)icon).gameObject.AddComponent<UITooltip>();
					obj2.m_tooltipPrefab = val3.m_tooltipPrefab;
					obj2.m_text = BookText.Title;
				}
				GameObject val4 = new GameObject("MonsterCompendium Canvas", new Type[3]
				{
					typeof(Canvas),
					typeof(CanvasScaler),
					typeof(GraphicRaycaster)
				});
				canvas = val4.GetComponent<Canvas>();
				canvas.renderMode = (RenderMode)0;
				canvas.sortingLayerID = sourceCanvas.sortingLayerID;
				canvas.sortingOrder = sourceCanvas.sortingOrder + 1;
				canvas.targetDisplay = sourceCanvas.targetDisplay;
				CanvasScaler component = val4.GetComponent<CanvasScaler>();
				component.uiScaleMode = (ScaleMode)1;
				component.referenceResolution = new Vector2(1920f, 1080f);
				component.screenMatchMode = (ScreenMatchMode)1;
				modal = BookUi.Rect("Monster compendium", ((Component)canvas).transform);
				((Component)modal).gameObject.AddComponent<CanvasGroup>();
				UIGroupHandler obj3 = ((Component)modal).gameObject.AddComponent<UIGroupHandler>();
				obj3.m_groupPriority = priority;
				RectTransform rect = BookUi.Rect("Backdrop", (Transform)(object)modal);
				BookUi.Fill(rect);
				BookUi.Button(rect, BookUi.Image(rect, Color32.op_Implicit(new Color32((byte)13, (byte)9, (byte)6, (byte)184))), Close);
				val = BookUi.Rect("Frame", (Transform)(object)modal);
				val.sizeDelta = new Vector2(num, 704f);
				BookUi.Image(val, ((Graphic)background).color, background, raycast: true);
				((Graphic)BookUi.Label(BookUi.Place("Title", (Transform)(object)val, 170f, 13f, 740f, 44f), titleStyle, BookText.Title, 32f, (TextAlignmentOptions)514)).color = Gold;
				RectTransform val5 = BookUi.Place("Close", (Transform)(object)val, 924f, 16f, 132f, 38f);
				obj3.m_defaultElement = ((Component)val5).gameObject;
				BookUi.Button(val5, BookUi.Image(val5, ((Graphic)buttonStyle).color, buttonStyle), Close);
				Label(val5, BookText.Label("Close", "Fermer"), 19, (TextAlignmentOptions)514);
			}
			BookUi.Fill(modal);
			((Component)modal).gameObject.SetActive(false);
			Image componentInParent = ((Component)body).GetComponentInParent<Image>(true);
			ScrollRect val6 = (Object.op_Implicit((Object)(object)gui.m_recipeListRoot) ? ((Component)gui.m_recipeListRoot).GetComponentInParent<ScrollRect>(true) : null);
			Image val7 = (Object.op_Implicit((Object)(object)val6) ? ((Component)val6).GetComponent<Image>() : null);
			Scrollbar recipeListScroll = gui.m_recipeListScroll;
			RectTransform val8 = BookUi.Place("Creatures", (Transform)(object)val, 24f, 70f, 310f, 610f);
			BookUi.Image(val8, Object.op_Implicit((Object)(object)val7) ? ((Graphic)val7).color : Ink, val7);
			search = AddSearch(val8);
			RectTransform val9 = BookUi.Place("Presets", (Transform)(object)val8, 8f, 47f, 294f, 35f);
			Image val10 = (Object.op_Implicit((Object)(object)gui.m_tabCraft) ? ((Selectable)gui.m_tabCraft).image : null);
			BookUi.Button(val9, BookUi.Image(val9, Object.op_Implicit((Object)(object)val10) ? ((Graphic)val10).color : RowFill, val10), ToggleMenu);
			presetLabel = Label(val9, "", 17, (TextAlignmentOptions)4097, 10f, 38f);
			AddChevron(val9, 273f, 15f);
			UpdatePresetCaption();
			list = new BookScroll(BookUi.Place("Creature list", (Transform)(object)val8, 3f, 88f, 304f, 519f), 304f, showScrollbar: true, sensitivity, recipeListScroll);
			float num2 = num - 348f - 24f;
			RectTransform val11 = BookUi.Place("Creature sheet", (Transform)(object)val, 348f, 70f, num2, 610f);
			BookUi.Image(val11, Object.op_Implicit((Object)(object)componentInParent) ? ((Graphic)componentInParent).color : Ink, componentInParent);
			detailTitle = (TMP_Text)(object)BookUi.Label(BookUi.Place("Creature", (Transform)(object)val11, 20f, 11f, num2 - 40f, 44f), Object.op_Implicit((Object)(object)gui.m_recipeName) ? gui.m_recipeName : titleStyle, "", 31f, (TextAlignmentOptions)4097);
			((Graphic)detailTitle).color = Gold;
			detailTitle.richText = false;
			BookUi.Image(BookUi.Place("Sheet rule", (Transform)(object)val11, 20f, 58f, num2 - 40f, 1f), Rule);
			details = new BookScroll(BookUi.Place("Observations", (Transform)(object)val11, 13f, 65f, num2 - 26f, 536f), num2 - 26f, showScrollbar: true, sensitivity, recipeListScroll);
			presetOverlay = BookUi.Rect("Preset overlay", (Transform)(object)modal);
			BookUi.Fill(presetOverlay);
			RectTransform rect2 = BookUi.Rect("Dismiss presets", (Transform)(object)presetOverlay);
			BookUi.Fill(rect2);
			BookUi.Button(rect2, BookUi.Image(rect2, Color.clear), CloseMenu);
			RectTransform val12 = BookUi.Rect("Preset choices", (Transform)(object)presetOverlay);
			val12.anchorMin = (val12.anchorMax = Vector2.one * 0.5f);
			val12.pivot = new Vector2(0f, 1f);
			val12.anchoredPosition = new Vector2(32f - num / 2f, 198f);
			val12.sizeDelta = new Vector2(294f, 314f);
			BookUi.Image(val12, Object.op_Implicit((Object)(object)val10) ? ((Graphic)val10).color : Ink, val10, raycast: true);
			menu = new BookScroll(val12, 294f, showScrollbar: true, sensitivity, recipeListScroll);
			CloseMenu();
		}

		private static void AddChevron(RectTransform parent, float x, float y)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			RectTransform obj = BookUi.Place("Chevron left", (Transform)(object)parent, x, y, 7f, 1.5f);
			((Transform)obj).localRotation = Quaternion.Euler(0f, 0f, -40f);
			BookUi.Image(obj, Muted);
			RectTransform obj2 = BookUi.Place("Chevron right", (Transform)(object)parent, x + 5f, y + 4.5f, 7f, 1.5f);
			((Transform)obj2).localRotation = Quaternion.Euler(0f, 0f, 40f);
			BookUi.Image(obj2, Muted);
		}

		private GuiInputField AddSearch(RectTransform left)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = BookUi.Place("Name filter", (Transform)(object)left, 8f, 8f, 294f, 33f);
			Image targetGraphic = BookUi.Image(val, Color32.op_Implicit(new Color32((byte)33, (byte)30, (byte)27, byte.MaxValue)), null, raycast: true);
			RectTransform val2 = BookUi.Rect("Text Area", (Transform)(object)val);
			BookUi.Fill(val2, 10f, 0f, 34f);
			((Component)val2).gameObject.AddComponent<RectMask2D>();
			TMP_Text textComponent = Label(val2, "", 19, (TextAlignmentOptions)4097);
			TMP_Text val3 = Label(val2, BookText.Label("Filter by name", "Filtrer par nom"), 19, (TextAlignmentOptions)4097);
			((Graphic)val3).color = Muted;
			GuiInputField field = ((Component)val).gameObject.AddComponent<GuiInputField>();
			((Selectable)field).targetGraphic = (Graphic)(object)targetGraphic;
			((TMP_InputField)field).textViewport = val2;
			((TMP_InputField)field).textComponent = textComponent;
			((TMP_InputField)field).placeholder = (Graphic)(object)val3;
			((TMP_InputField)field).lineType = (LineType)0;
			((TMP_InputField)field).richText = false;
			((UnityEvent<string>)(object)((TMP_InputField)field).onValueChanged).AddListener((UnityAction<string>)delegate
			{
				RefreshList(reset: true);
			});
			RectTransform val4 = BookUi.Place("Clear filter", (Transform)(object)val, 261f, 2f, 31f, 29f);
			BookUi.Button(val4, BookUi.Image(val4, Color.clear), delegate
			{
				((TMP_InputField)field).text = "";
			});
			((Graphic)Label(val4, "×", 25, (TextAlignmentOptions)514)).color = Gold;
			return field;
		}

		public void PositionIcon()
		{
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Unknown result type (might be due to invalid IL or missing references)
			//IL_0161: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c2: 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_019d: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			if (!Object.op_Implicit((Object)(object)icon))
			{
				return;
			}
			toolbarButtons.Clear();
			string[] toolbarNames = ToolbarNames;
			foreach (string text in toolbarNames)
			{
				Transform obj = ((Transform)bar).Find(text);
				RectTransform val = (RectTransform)(object)((obj is RectTransform) ? obj : null);
				if (Object.op_Implicit((Object)(object)val) && ((Component)val).gameObject.activeSelf)
				{
					toolbarButtons.Add(val);
				}
			}
			if (toolbarButtons.Count == 0)
			{
				return;
			}
			float y = ((Transform)toolbarButtons[0]).localPosition.y;
			toolbarButtons.Add(icon);
			Rect rect = bar.rect;
			float num;
			if (!(((Rect)(ref rect)).width > 64f))
			{
				num = 560f;
			}
			else
			{
				rect = bar.rect;
				num = ((Rect)(ref rect)).width;
			}
			float num2 = num;
			float num3 = Mathf.Min(84f, (num2 - 64f - 36f) / (float)(toolbarButtons.Count - 1));
			rect = bar.rect;
			float num4 = ((Rect)(ref rect)).center.x - num3 * (float)(toolbarButtons.Count - 1) / 2f;
			Vector3 val3 = default(Vector3);
			for (int j = 0; j < toolbarButtons.Count; j++)
			{
				RectTransform val2 = toolbarButtons[j];
				Vector3 localPosition = ((Transform)val2).localPosition;
				((Vector3)(ref val3))..ctor(num4 + num3 * (float)j, y, localPosition.z);
				if ((Object)(object)val2 != (Object)(object)icon)
				{
					(Vector3, Vector3) value;
					Vector3 item = ((toolbarPositions.TryGetValue(val2, out value) && localPosition == value.Item2) ? value.Item1 : localPosition);
					toolbarPositions[val2] = (item, val3);
				}
				if (localPosition != val3)
				{
					((Transform)val2).localPosition = val3;
				}
			}
		}

		public void Open()
		{
			ClearFocus();
			UpdateCreatureNames();
			((Component)modal).gameObject.SetActive(true);
			highlighted.Clear();
			RefreshList(!embedded);
			if (embedded)
			{
				DisplaySelected(reset: false);
			}
			else
			{
				Select(null);
			}
		}

		public void Close()
		{
			if (Object.op_Implicit((Object)(object)modal) && ((Component)modal).gameObject.activeSelf)
			{
				ClearFocus();
				CloseMenu();
				((Component)modal).gameObject.SetActive(false);
			}
		}

		public void Reset()
		{
			Close();
			selected = null;
			highlighted.Clear();
			((TMP_InputField)search).SetTextWithoutNotify("");
			preset = null;
			UpdatePresetCaption();
		}

		public bool HandleBack()
		{
			if (!IsOpen)
			{
				return false;
			}
			if (((Component)presetOverlay).gameObject.activeSelf)
			{
				CloseMenu();
			}
			else
			{
				if (!((TMP_InputField)search).isFocused && (!Object.op_Implicit((Object)(object)EventSystem.current) || !((Object)(object)EventSystem.current.currentSelectedGameObject == (Object)(object)((Component)search).gameObject)))
				{
					return false;
				}
				ClearFocus();
			}
			return true;
		}

		private void ClearFocus()
		{
			if (((TMP_InputField)search).isFocused)
			{
				((TMP_InputField)search).DeactivateInputField(false);
			}
			if (Object.op_Implicit((Object)(object)EventSystem.current))
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
		}

		public void Refresh()
		{
			UpdateCreatureNames();
			RefreshList(reset: false);
			DisplaySelected(reset: false);
			if (((Component)presetOverlay).gameObject.activeSelf)
			{
				ShowMenu(menuGroup, reset: false);
			}
		}

		private void RefreshList(bool reset)
		{
			//IL_0140: Unknown result type (might be due to invalid IL or missing references)
			//IL_016e: Unknown result type (might be due to invalid IL or missing references)
			Journal journal = currentJournal();
			if (!IsOpen || journal == null)
			{
				return;
			}
			IOrderedEnumerable<Creature> orderedEnumerable = SeenCreatures(journal).OrderBy<Creature, string>(CreatureName, StringComparer.CurrentCultureIgnoreCase).ThenBy<Creature, string>((Creature creature2) => creature2.Id, StringComparer.Ordinal);
			BookUi.Clear(list.Content);
			creatureRows.Clear();
			float num = 0f;
			foreach (Creature creature in orderedEnumerable)
			{
				string text = CreatureName(creature);
				if (Journal.MatchesName(text, ((TMP_InputField)search).text) && (!preset.HasValue || journal.Has(creature.Id, preset.Value.Kind, preset.Value.Value)))
				{
					RectTransform val = BookUi.Place(creature.Id, (Transform)(object)list.Content, 0f, num, list.Width, 32f);
					Image val2 = BookUi.Image(val, RowFill);
					Image item = BookUi.Image(BookUi.Place("Unread marker", (Transform)(object)val, 0f, 0f, 3f, 32f), Gold);
					BookUi.Button(val, val2, delegate
					{
						Select(creature);
					});
					TMP_Text item2 = Label(val, text, 18, (TextAlignmentOptions)4097, 12f, 8f);
					creatureRows.Add((creature, val2, item2, item));
					num += 35f;
				}
			}
			if (creatureRows.Count == 0)
			{
				Label(BookUi.Place("No matches", (Transform)(object)list.Content, 0f, 0f, list.Width, 32f), (creatureNames.Count == 0) ? BookText.Label("No creatures sighted yet.", "Aucune créature aperçue.") : BookText.Label("No matching creatures.", "Aucune créature correspondante."), 17, (TextAlignmentOptions)4097, 8f);
				num = 32f;
			}
			list.SetHeight(num, reset);
			if (selected != null && !creatureRows.Any(((Creature Creature, Image Background, TMP_Text Label, Image Marker) row) => row.Creature == selected))
			{
				Select(null);
			}
			else
			{
				RefreshMarkers();
			}
		}

		private void RefreshMarkers()
		{
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			Journal journal = currentJournal();
			foreach (var creatureRow in creatureRows)
			{
				bool flag = journal.HasUnread(creatureRow.Creature.Id);
				((Graphic)creatureRow.Background).color = ((creatureRow.Creature == selected) ? SelectedFill : RowFill);
				((Graphic)creatureRow.Label).color = (flag ? Gold : ((Graphic)body).color);
				((Behaviour)creatureRow.Marker).enabled = flag;
			}
		}

		private void Select(Creature creature)
		{
			if (selected != creature)
			{
				selected = creature;
				highlighted.Clear();
			}
			DisplaySelected(reset: true);
			RefreshMarkers();
		}

		private void DisplaySelected(bool reset)
		{
			detailTitle.text = ((selected == null) ? BookText.Label("Select a creature", "Sélectionnez une créature") : CreatureName(selected));
			BookUi.Clear(details.Content);
			detailRows.Clear();
			if (selected == null)
			{
				details.SetHeight(0f, reset);
				return;
			}
			IGrouping<FactKind, Fact>[] array = (from fact in (from fact in currentJournal().For(selected.Id)
					orderby fact.Kind
					select fact).ThenBy<Fact, string>((Fact fact) => fact.Value, StringComparer.OrdinalIgnoreCase)
				group fact by fact.Kind).ToArray();
			float num = 0f;
			IGrouping<FactKind, Fact>[] array2 = array;
			foreach (IGrouping<FactKind, Fact> grouping in array2)
			{
				bool flag = grouping.Key < FactKind.Attack;
				if (!flag)
				{
					num = AddSectionTitle(num, BookText.Section(grouping.Key));
				}
				bool flag2 = true;
				foreach (Fact item in grouping)
				{
					AddObservation(item, num, (flag2 && flag) ? BookText.Section(grouping.Key) : "");
					num += 31f;
					flag2 = false;
				}
			}
			if (array.Length == 0)
			{
				Label(BookUi.Place("No observations", (Transform)(object)details.Content, 0f, 0f, details.Width, 32f), BookText.Label("No observations yet.", "Aucune observation pour le moment."), 18, (TextAlignmentOptions)4097, 8f);
				num = 32f;
			}
			details.SetHeight(num, reset);
		}

		private float AddSectionTitle(float y, string title)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			y += 12f;
			BookUi.Image(BookUi.Place("Section rule", (Transform)(object)details.Content, 7f, y, details.Width - 14f, 1f), Rule);
			((Graphic)Label(BookUi.Place("Section", (Transform)(object)details.Content, 0f, y + 5f, details.Width, 31f), title, 21, (TextAlignmentOptions)4097, 12f)).color = Gold;
			return y + 39f;
		}

		private void AddObservation(Fact fact, float top, string caption)
		{
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0129: Unknown result type (might be due to invalid IL or missing references)
			//IL_019b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
			if (fact.Unread)
			{
				highlighted.Add(fact);
			}
			bool flag = highlighted.Contains(fact);
			RectTransform val = BookUi.Place("Observation", (Transform)(object)details.Content, 0f, top, details.Width, 29f);
			if (flag)
			{
				BookUi.Image(val, UnreadFill);
				BookUi.Image(BookUi.Place("New observation", (Transform)(object)val, 0f, 0f, 2f, 29f), Gold);
			}
			else
			{
				BookUi.Image(BookUi.Place("Row rule", (Transform)(object)val, 8f, 28f, details.Width - 16f, 1f), RowFill);
			}
			if (fact.Kind == FactKind.Attack)
			{
				string text = BookText.Attack(fact.Value, selected.DamageForAttack(fact.Value));
				TMP_Text val2 = Label(val, text, 18, (TextAlignmentOptions)4097, 12f, 12f);
				val2.enableAutoSizing = true;
				val2.fontSizeMin = 15f;
				val2.fontSizeMax = 18f;
				if (flag)
				{
					((Graphic)val2).color = Gold;
				}
			}
			else
			{
				string text2;
				if (fact.Kind == FactKind.Damage)
				{
					(caption, text2) = BookText.DamageResponse(fact.Value);
				}
				else
				{
					text2 = BookText.Value(fact.Kind, fact.Value);
				}
				((Graphic)Label(val, caption, 17, (TextAlignmentOptions)4097, 12f, details.Width - 223f + 10f)).color = Muted;
				TMP_Text val3 = Label(val, text2, 18, (TextAlignmentOptions)4097, 223f, 12f);
				if (flag)
				{
					((Graphic)val3).color = Gold;
				}
			}
			detailRows.Add((fact, top, 29f));
		}

		public void ReadVisibleFacts()
		{
			if (((Component)presetOverlay).gameObject.activeSelf)
			{
				return;
			}
			bool flag = false;
			foreach (var detailRow in detailRows)
			{
				if (detailRow.Fact.Unread && details.Shows(detailRow.Top, detailRow.Height))
				{
					flag |= markRead(detailRow.Fact);
				}
			}
			if (flag)
			{
				RefreshMarkers();
			}
		}

		private void ToggleMenu()
		{
			if (((Component)presetOverlay).gameObject.activeSelf)
			{
				CloseMenu();
				return;
			}
			ClearFocus();
			((Component)presetOverlay).gameObject.SetActive(true);
			ShowMenu(null);
		}

		private void CloseMenu()
		{
			((Component)presetOverlay).gameObject.SetActive(false);
		}

		private void ShowMenu(FactKind? group, bool reset = true)
		{
			menuGroup = group;
			BookUi.Clear(menu.Content);
			float y = 0f;
			if (!group.HasValue)
			{
				AddChoice(ref y, BookText.Label("All sighted creatures", "Toutes les créatures aperçues"), delegate
				{
					SetPreset(null);
				}, !preset.HasValue);
				string text = BookText.Section(FactKind.Biome) + "  >";
				Action onClick = delegate
				{
					ShowMenu(FactKind.Biome);
				};
				ref(FactKind Kind, string Value)? reference = ref preset;
				AddChoice(ref y, text, onClick, reference.HasValue && reference.GetValueOrDefault().Kind == FactKind.Biome);
				string text2 = BookText.Section(FactKind.Faction) + "  >";
				Action onClick2 = delegate
				{
					ShowMenu(FactKind.Faction);
				};
				ref(FactKind Kind, string Value)? reference2 = ref preset;
				AddChoice(ref y, text2, onClick2, reference2.HasValue && reference2.GetValueOrDefault().Kind == FactKind.Faction);
				string text3 = BookText.Value(FactKind.Taming, "true");
				Action onClick3 = delegate
				{
					SetPreset((FactKind.Taming, "true"));
				};
				ref(FactKind Kind, string Value)? reference3 = ref preset;
				AddChoice(ref y, text3, onClick3, reference3.HasValue && reference3.GetValueOrDefault().Kind == FactKind.Taming);
			}
			else
			{
				AddChoice(ref y, BookText.Label("<  Back", "<  Retour"), delegate
				{
					ShowMenu(null);
				});
				Journal journal = currentJournal();
				string[] array = (from fact in SeenCreatures(journal).SelectMany((Creature creature) => journal.For(creature.Id))
					where fact.Kind == @group.Value
					select fact.Value).Distinct().OrderBy<string, string>((string value2) => BookText.Value(group.Value, value2), StringComparer.CurrentCultureIgnoreCase).ToArray();
				string[] array2 = array;
				foreach (string value in array2)
				{
					AddChoice(ref y, BookText.Value(group.Value, value), delegate
					{
						SetPreset((group.Value, value));
					}, preset?.Kind == group.Value && preset?.Value == value);
				}
				if (array.Length == 0)
				{
					Label(BookUi.Place("No presets", (Transform)(object)menu.Content, 0f, y, menu.Width, 32f), BookText.Label("No observations yet.", "Aucune observation pour le moment."), 17, (TextAlignmentOptions)4097, 8f);
					y += 32f;
				}
			}
			menu.SetHeight(y, reset);
		}

		private void AddChoice(ref float y, string text, Action onClick, bool active = false)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = BookUi.Place("Preset choice", (Transform)(object)menu.Content, 0f, y, menu.Width, 32f);
			BookUi.Button(val, BookUi.Image(val, active ? SelectedFill : RowFill), onClick);
			TMP_Text val2 = Label(val, text, 18, (TextAlignmentOptions)4097, 10f, 5f);
			if (active)
			{
				((Graphic)val2).color = Gold;
			}
			y += 35f;
		}

		private void SetPreset((FactKind Kind, string Value)? value)
		{
			preset = value;
			CloseMenu();
			UpdatePresetCaption();
			RefreshList(reset: true);
		}

		private void UpdatePresetCaption()
		{
			//IL_006e: 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)
			presetLabel.text = (preset.HasValue ? BookText.Value(preset.Value.Kind, preset.Value.Value) : BookText.Label("All sighted creatures", "Toutes les créatures aperçues"));
			((Graphic)presetLabel).color = (preset.HasValue ? Gold : ((Graphic)body).color);
		}

		private TMP_Text Label(RectTransform parent, string text, int size, TextAlignmentOptions alignment, float left = 0f, float right = 0f)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			RectTransform rect = BookUi.Rect("Label", (Transform)(object)parent);
			BookUi.Fill(rect, left, 0f, right);
			TextMeshProUGUI obj = BookUi.Label(rect, body, text, size, alignment);
			((TMP_Text)obj).richText = false;
			return (TMP_Text)(object)obj;
		}

		private void UpdateCreatureNames()
		{
			Localization localization = Localization.instance;
			creatureNames = CreatureNames.Build(from creature in SeenCreatures(currentJournal())
				select (Id: creature.Id, localization.Localize(creature.NameKey)), localization.GetSelectedLanguage() == "French");
		}

		private IEnumerable<Creature> SeenCreatures(Journal journal)
		{
			return catalog.Entries.Where((Creature creature) => journal.HasSeen(creature.Id));
		}

		private string CreatureName(Creature creature)
		{
			return creatureNames[creature.Id];
		}

		public void Dispose()
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			Close();
			foreach (KeyValuePair<RectTransform, (Vector3, Vector3)> toolbarPosition in toolbarPositions)
			{
				if (Object.op_Implicit((Object)(object)toolbarPosition.Key) && ((Transform)toolbarPosition.Key).localPosition == toolbarPosition.Value.Item2)
				{
					((Transform)toolbarPosition.Key).localPosition = toolbarPosition.Value.Item1;
				}
			}
			if (Object.op_Implicit((Object)(object)icon))
			{
				Object.Destroy((Object)(object)((Component)icon).gameObject);
			}
			if (embedded)
			{
				if (Object.op_Implicit((Object)(object)modal))
				{
					Object.Destroy((Object)(object)((Component)modal).gameObject);
				}
				return;
			}
			if (Object.op_Implicit((Object)(object)canvas))
			{
				Object.Destroy((Object)(object)((Component)canvas).gameObject);
			}
			Object.Destroy((Object)(object)sprite);
			Object.Destroy((Object)(object)texture);
		}
	}
	internal static class CreatureNames
	{
		private static readonly Regex Markup = new Regex("</?[A-Za-z][A-Za-z0-9-]*(?:[ =][^<>]*)?>|<#[0-9A-Fa-f]{3,8}>");

		private static readonly Regex MissingWord = new Regex("\\[[A-Za-z0-9_]*_[A-Za-z0-9_]+\\]|^\\[\\w+\\]$|\\$\\w+");

		private static readonly Regex WordBoundary = new Regex("(?<=[a-z])(?=[A-Z])");

		public static Dictionary<string, string> Build(IEnumerable<(string Id, string Localized)> creatures, bool french)
		{
			Dictionary<string, string> dictionary = new Dictionary<string, string>(StringComparer.Ordinal);
			foreach (IGrouping<string, (string, string)> item in creatures.GroupBy<(string, string), string>(((string Id, string Localized) creature) => DisplayName(creature.Id, creature.Localized, french), StringComparer.CurrentCultureIgnoreCase))
			{
				(string, string)[] array = item.OrderBy<(string, string), int>(((string Id, string Localized) creature) => creature.Id.Length).ThenBy<(string, string), string>(((string Id, string Localized) creature) => creature.Id, StringComparer.Ordinal).ToArray();
				if (array.Length == 1)
				{
					dictionary.Add(array[0].Item1, item.Key);
					continue;
				}
				HashSet<string> hashSet = new HashSet<string>(StringComparer.CurrentCultureIgnoreCase);
				int num = 2;
				(string, string)[] array2 = array;
				for (int num2 = 0; num2 < array2.Length; num2++)
				{
					(string, string) tuple = array2[num2];
					string text = Variant(tuple.Item1, french);
					string text2 = ((text.Length == 0) ? item.Key : (item.Key + " (" + text + ")"));
					while (!hashSet.Add(text2))
					{
						text2 = item.Key + (french ? " (variante " : " (variant ") + num++ + ")";
					}
					dictionary.Add(tuple.Item1, text2);
				}
			}
			return dictionary;
		}

		private static string DisplayName(string id, string localized, bool french)
		{
			string text = Markup.Replace(localized ?? "", "").Trim();
			if (text.Length > 0 && !MissingWord.IsMatch(text))
			{
				return text;
			}
			switch (id)
			{
			case "Deer_White":
				if (!french)
				{
					return "White deer";
				}
				return "Cerf blanc";
			case "DvergerTest":
				return "Dvergr (test)";
			case "Hive":
				if (!french)
				{
					return "Hive";
				}
				return "Ruche";
			case "TheHive":
				if (!french)
				{
					return "The Hive";
				}
				return "La Ruche";
			case "FrostWisp":
				if (!french)
				{
					return "Frost wisp";
				}
				return "Feu follet de givre";
			case "Bjorn_spiritcaller":
				if (!french)
				{
					return "Summoned bear";
				}
				return "Ours invoqué";
			case "Boar_spiritcaller":
				if (!french)
				{
					return "Summoned boar";
				}
				return "Sanglier invoqué";
			case "Moose_spiritcaller":
				if (!french)
				{
					return "Summoned moose";
				}
				return "Élan invoqué";
			case "Wolf_spiritcaller":
				if (!french)
				{
					return "Summoned wolf";
				}
				return "Loup invoqué";
			default:
				return Words(id);
			}
		}

		private static string Variant(string id, bool french)
		{
			string[] source = Words(id).ToLowerInvariant().Replace("dual wield", "dualwield").Replace("deep north", "deepnorth")
				.Replace("non sleeping", "nonsleeping")
				.Split(new char[1] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
			return string.Join(", ", from word in source
				select VariantWord(word, french) into word
				where word != null
				select word);
		}

		private static string VariantWord(string word, bool french)
		{
			switch (word)
			{
			case "nochest":
				if (!french)
				{
					return "no chest";
				}
				return "sans coffre";
			case "sleeping":
				if (!french)
				{
					return "sleeping";
				}
				return "endormi";
			case "nonsleeping":
				if (!french)
				{
					return "awake";
				}
				return "éveillé";
			case "frozen":
				if (!french)
				{
					return "frozen";
				}
				return "gelé";
			case "ranged":
			case "archer":
				return "archer";
			case "noarcher":
				if (!french)
				{
					return "no bow";
				}
				return "sans arc";
			case "melee":
				if (!french)
				{
					return "melee";
				}
				return "mêlée";
			case "meadows":
				if (!french)
				{
					return "Meadows";
				}
				return "Prairies";
			case "mountains":
				if (!french)
				{
					return "Mountains";
				}
				return "Montagnes";
			case "swamps":
			case "swamp":
				if (!french)
				{
					return "Swamp";
				}
				return "Marais";
			case "deepnorth":
				if (!french)
				{
					return "Deep North";
				}
				return "Grand Nord";
			case "ashlands":
				if (!french)
				{
					return "Ashlands";
				}
				return "Terres calcinées";
			case "cave":
				if (!french)
				{
					return "cave";
				}
				return "grotte";
			case "ice":
				if (!french)
				{
					return "ice";
				}
				return "glace";
			case "fire":
				if (!french)
				{
					return "fire";
				}
				return "feu";
			case "support":
				if (!french)
				{
					return "support";
				}
				return "soutien";
			case "lantern":
				if (!french)
				{
					return "lantern";
				}
				return "lanterne";
			case "dualwield":
				if (!french)
				{
					return "dual wield";
				}
				return "deux armes";
			case "p2":
				return "phase 2";
			case "p3":
				return "phase 3";
			default:
				return null;
			}
		}

		public static string Words(string value)
		{
			string text = WordBoundary.Replace(value, " ").Replace('_', ' ').Trim();
			if (text.Length != 0)
			{
				return char.ToUpper(text[0], CultureInfo.CurrentCulture) + text.Substring(1);
			}
			return value;
		}
	}
	internal sealed class Creature
	{
		private readonly Dictionary<string, string> attackTriggers = new Dictionary<string, string>(StringComparer.Ordinal);

		private readonly Dictionary<string, DamageType?> damageByAttack = new Dictionary<string, DamageType?>(StringComparer.Ordinal);

		public string Id { get; }

		public string NameKey { get; }

		public Creature(Character prefab)
		{
			Id = ((Object)((Component)prefab).gameObject).name;
			NameKey = prefab.m_name;
			Humanoid val = (Humanoid)(object)((prefab is Humanoid) ? prefab : null);
			if (val == null)
			{
				return;
			}
			List<ItemData> list = new List<ItemData>();
			AddItems(list, val.m_defaultItems);
			AddItems(list, val.m_randomWeapon);
			if (val.m_randomSets != null)
			{
				ItemSet[] randomSets = val.m_randomSets;
				foreach (ItemSet val2 in randomSets)
				{
					AddItems(list, val2.m_items);
				}
			}
			if (val.m_randomItems != null)
			{
				RandomItem[] randomItems = val.m_randomItems;
				foreach (RandomItem val3 in randomItems)
				{
					if (Object.op_Implicit((Object)(object)val3.m_prefab))
					{
						AddItem(list, val3.m_prefab.GetComponent<ItemDrop>());
					}
				}
			}
			AddItem(list, val.m_unarmedWeapon);
			ItemData val4 = (Object.op_Implicit((Object)(object)val.m_unarmedWeapon) ? val.m_unarmedWeapon.m_itemData : null);
			bool flag = !Object.op_Implicit((Object)(object)((Component)prefab).GetComponent<MonsterAI>()) || Object.op_Implicit((Object)(object)((Component)prefab).GetComponent<Tameable>());
			foreach (ItemData item in list)
			{
				if (item == val4 || item.IsWeapon())
				{
					AddAttack(item.m_shared.m_attack, item, list);
					if (flag)
					{
						AddAttack(item.m_shared.m_secondaryAttack, item, list);
					}
				}
			}
		}

		public string AttackForTrigger(string trigger)
		{
			if (!attackTriggers.TryGetValue(trigger, out var value))
			{
				return null;
			}
			return value;
		}

		public DamageType? DamageForAttack(string animation)
		{
			if (!damageByAttack.TryGetValue(animation, out var value))
			{
				return null;
			}
			return value;
		}

		private static void AddItems(List<ItemData> equipment, GameObject[] items)
		{
			if (items == null)
			{
				return;
			}
			foreach (GameObject val in items)
			{
				if (Object.op_Implicit((Object)(object)val))
				{
					AddItem(equipment, val.GetComponent<ItemDrop>());
				}
			}
		}

		private static void AddItem(List<ItemData> equipment, ItemDrop item)
		{
			if (Object.op_Implicit((Object)(object)item) && item.m_itemData?.m_shared != null && !equipment.Contains(item.m_itemData))
			{
				equipment.Add(item.m_itemData);
			}
		}

		private void AddAttack(Attack attack, ItemData weapon, List<ItemData> equipment)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			if (string.IsNullOrEmpty(attack?.m_attackAnimation))
			{
				return;
			}
			string attackAnimation = attack.m_attackAnimation;
			DamageType? val = AttackDamage.Resolve(attack, weapon, equipment);
			if (damageByAttack.TryGetValue(attackAnimation, out var value) && value != val)
			{
				val = null;
			}
			damageByAttack[attackAnimation] = val;
			int num = ((attack.m_attackChainLevels > 1) ? attack.m_attackChainLevels : attack.m_attackRandomAnimations);
			if (num < 2)
			{
				attackTriggers[attackAnimation] = attackAnimation;
				return;
			}
			for (int i = 0; i < num; i++)
			{
				attackTriggers[attackAnimation + i] = attackAnimation;
			}
		}
	}
	internal sealed class Creatures
	{
		private readonly Dictionary<string, Creature> entries = new Dictionary<string, Creature>(StringComparer.Ordinal);

		private ZNetScene scene;

		private int prefabCount;

		public IEnumerable<Creature> Entries => entries.Values;

		public bool Refresh()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Invalid comparison between Unknown and I4
			ZNetScene instance = ZNetScene.instance;
			int num = (Object.op_Implicit((Object)(object)instance) ? instance.m_prefabs.Count : 0);
			if (instance == scene && num == prefabCount)
			{
				return false;
			}
			scene = instance;
			prefabCount = num;
			entries.Clear();
			if (Object.op_Implicit((Object)(object)scene))
			{
				foreach (GameObject prefab in scene.m_prefabs)
				{
					Character val = (Object.op_Implicit((Object)(object)prefab) ? prefab.GetComponent<Character>() : null);
					if (Object.op_Implicit((Object)(object)val) && !val.IsPlayer() && Object.op_Implicit((Object)(object)prefab.GetComponent<BaseAI>()) && (int)val.GetFaction() != 12)
					{
						entries[((Object)prefab).name] = new Creature(val);
					}
				}
			}
			return true;
		}

		public Creature Find(Character character)
		{
			if (!Object.op_Implicit((Object)(object)character) || character.IsPlayer())
			{
				return null;
			}
			string prefabName = Utils.GetPrefabName(((Component)character).gameObject);
			if (!entries.TryGetValue(prefabName, out var value))
			{
				return null;
			}
			return value;
		}

		public Creature Find(ZDO zdo)
		{
			GameObject val = ((Object.op_Implicit((Object)(object)scene) && zdo != null) ? scene.GetPrefab(zdo.GetPrefab()) : null);
			if (!Object.op_Implicit((Object)(object)val) || !entries.TryGetValue(((Object)val).name, out var value))
			{
				return null;
			}
			return value;
		}
	}
	internal enum FactKind
	{
		Level,
		Biome,
		Faction,
		Taming,
		Attack,
		Damage
	}
	internal sealed class Fact
	{
		public string Creature { get; }

		public FactKind Kind { get; }

		public string Value { get; }

		public bool Unread { get; set; }

		public Fact(string creature, FactKind kind, string value, bool unread)
		{
			Creature = creature;
			Kind = kind;
			Value = value;
			Unread = unread;
		}
	}
	internal sealed class Journal
	{
		private readonly Dictionary<string, Dictionary<(FactKind, string), Fact>> creatures = new Dictionary<string, Dictionary<(FactKind, string), Fact>>(StringComparer.Ordinal);

		public IEnumerable<Fact> For(string creature)
		{
			if (!creatures.TryGetValue(creature, out var value))
			{
				return Array.Empty<Fact>();
			}
			return value.Values;
		}

		public bool Has(string creature, FactKind kind, string value)
		{
			if (creatures.TryGetValue(creature, out var value2))
			{
				return value2.ContainsKey((kind, value));
			}
			return false;
		}

		public bool HasSeen(string creature)
		{
			foreach (Fact item in For(creature))
			{
				if (item.Kind == FactKind.Level)
				{
					return true;
				}
			}
			return false;
		}

		public bool HasUnread(string creature)
		{
			foreach (Fact item in For(creature))
			{
				if (item.Unread)
				{
					return true;
				}
			}
			return false;
		}

		public bool Observe(string creature, FactKind kind, string value)
		{
			if (!creatures.TryGetValue(creature, out var value2))
			{
				value2 = new Dictionary<(FactKind, string), Fact>();
				creatures.Add(creature, value2);
			}
			(FactKind, string) key = (kind, value);
			if (value2.ContainsKey(key))
			{
				return false;
			}
			value2.Add(key, new Fact(creature, kind, value, unread: true));
			return true;
		}

		public bool Read(Fact fact)
		{
			if (!fact.Unread)
			{
				return false;
			}
			fact.Unread = false;
			return true;
		}

		public string Save()
		{
			StringBuilder stringBuilder = new StringBuilder();
			foreach (Dictionary<(FactKind, string), Fact> value in creatures.Values)
			{
				foreach (Fact value2 in value.Values)
				{
					stringBuilder.Append(Encode(value2.Creature)).Append('\t').Append((int)value2.Kind)
						.Append('\t')
						.Append(Encode(value2.Value))
						.Append('\t')
						.Append(value2.Unread ? '1' : '0')
						.Append('\n');
				}
			}
			return stringBuilder.ToString();
		}

		public static Journal Load(string data)
		{
			Journal journal = new Journal();
			if (string.IsNullOrEmpty(data))
			{
				return journal;
			}
			string[] array = data.Split(new char[1] { '\n' });
			for (int i = 0; i < array.Length; i++)
			{
				string[] array2 = array[i].Split(new char[1] { '\t' });
				if (array2.Length != 4 || !int.TryParse(array2[1], out var result) || !Enum.IsDefined(typeof(FactKind), result) || (array2[3] != "0" && array2[3] != "1"))
				{
					continue;
				}
				try
				{
					string text = Decode(array2[0]);
					string text2 = Decode(array2[2]);
					if (text.Length != 0 && text2.Length != 0 && journal.Observe(text, (FactKind)result, text2))
					{
						journal.creatures[text][((FactKind)result, text2)].Unread = array2[3] == "1";
					}
				}
				catch (FormatException)
				{
				}
			}
			return journal;
		}

		public static bool MatchesName(string name, string query)
		{
			if (!string.IsNullOrWhiteSpace(query))
			{
				return CultureInfo.InvariantCulture.CompareInfo.IndexOf(name, query.Trim(), CompareOptions.IgnoreCase | CompareOptions.IgnoreNonSpace) >= 0;
			}
			return true;
		}

		private static string Encode(string value)
		{
			return Convert.ToBase64String(Encoding.UTF8.GetBytes(value));
		}

		private static string Decode(string value)
		{
			return Encoding.UTF8.GetString(Convert.FromBase64String(value));
		}
	}
	[BepInPlugin("fr.romaindurand.monstercompendium", "MonsterCompendium", "1.2.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(Player), "Save")]
		private static class SavingCharacter
		{
			private static void Prefix(Player __instance)
			{
				Plugin instance = Instance;
				if (Object.op_Implicit((Object)(object)instance) && instance.player == __instance)
				{
					instance.SaveJournal();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Hide")]
		private static class InventoryClosed
		{
			private static void Postfix(InventoryGui __instance)
			{
				Plugin instance = Instance;
				if (Object.op_Implicit((Object)(object)instance) && !instance.sharedBook && (Object)(object)instance.inventory == (Object)(object)__instance)
				{
					instance.view?.Close();
				}
			}
		}

		[HarmonyPatch(typeof(PlayerController), "TakeInput")]
		private static class PlayerControls
		{
			private static bool Prefix(ref bool __result)
			{
				if (!IsSearchFocused)
				{
					return true;
				}
				__result = false;
				return false;
			}
		}

		[HarmonyPatch(typeof(ZInput), "GetButtonDown", new Type[] { typeof(string) })]
		private static class InventoryShortcuts
		{
			private static void Postfix(string __0, ref bool __result)
			{
				if (__result && (__0 == "Use" || __0 == "Inventory") && IsSearchFocused)
				{
					__result = false;
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private static class CancelBook
		{
			private static bool Prefix(InventoryGui __instance)
			{
				Plugin instance = Instance;
				if (Object.op_Implicit((Object)(object)instance) && !instance.sharedBook && !((Object)(object)instance.inventory != (Object)(object)__instance))
				{
					CompendiumView view = instance.view;
					if (view != null && view.IsOpen && instance.CanUseBook())
					{
						if (!ZInput.GetKeyDown((KeyCode)27, true) && !ZInput.GetButtonDown("JoyButtonB"))
						{
							return true;
						}
						ZInput.ResetButtonStatus("JoyButtonB");
						if (!instance.view.HandleBack())
						{
							instance.view.Close();
						}
						return false;
					}
				}
				return true;
			}
		}

		internal const string Guid = "fr.romaindurand.monstercompendium";

		private const string CraftingBookGuid = "fr.romaindurand.craftingbook";

		private const string Version = "1.2.1";

		private const string SaveKey = "fr.romaindurand.monstercompendium.journal.v1";

		private static readonly Func<Tameable, int> Tameness = AccessTools.MethodDelegate<Func<Tameable, int>>(AccessTools.Method(typeof(Tameable), "GetTameness", (Type[])null, (Type[])null), (object)null, true);

		internal readonly Creatures Catalog = new Creatures();

		private readonly List<Renderer> renderers = new List<Renderer>();

		private readonly Dictionary<Humanoid, (Creature Creature, string Name, float Started, bool Released)> attacks = new Dictionary<Humanoid, (Creature, string, float, bool)>();

		private readonly List<Humanoid> finishedAttacks = new List<Humanoid>();

		private Harmony harmony;

		private InventoryGui inventory;

		private CompendiumView view;

		private Player player;

		private Journal journal;

		private ZRoutedRpc rpc;

		private int occluders;

		private float nextLook;

		private bool dirty;

		private bool viewDirty;

		private bool triedAttach;

		private bool sharedBook;

		private bool observationErrorLogged;

		internal static Plugin Instance { get; private set; }

		private static bool IsSearchFocused
		{
			get
			{
				if (Object.op_Implicit((Object)(object)Instance))
				{
					return Instance.view?.IsSearchFocused ?? false;
				}
				return false;
			}
		}

		private void Awake()
		{
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Expected O, but got Unknown
			Instance = this;
			occluders = LayerMask.GetMask(new string[7] { "Default", "Default_small", "static_solid", "piece", "terrain", "viewblock", "vehicle" });
			harmony = new Harmony("fr.romaindurand.monstercompendium");
			harmony.PatchAll(typeof(Plugin).Assembly);
			sharedBook = RegisterBookTab();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"MonsterCompendium 1.2.1 loaded (fr.romaindurand.monstercompendium).");
		}

		private void LateUpdate()
		{
			RegisterNetwork();
			if (Catalog.Refresh())
			{
				viewDirty = true;
			}
			if (EnsurePlayer())
			{
				CheckAttacks();
				LookForCreatures();
			}
			if (!sharedBook)
			{
				UpdateStandaloneBook();
			}
			if (view != null)
			{
				if (!CanUseBook() || !InventoryGui.IsVisible())
				{
					if (!sharedBook)
					{
						view.Close();
					}
				}
				else
				{
					if (!sharedBook)
					{
						view.PositionIcon();
					}
					if (view.IsOpen)
					{
						if (viewDirty)
						{
							view.Refresh();
						}
						view.ReadVisibleFacts();
					}
				}
			}
			viewDirty = false;
			SaveJournal();
		}

		private bool RegisterBookTab()
		{
			if (!Chainloader.PluginInfos.TryGetValue("fr.romaindurand.craftingbook", out var value) || !Object.op_Implicit((Object)(object)value.Instance))
			{
				return false;
			}
			Func<InventoryGui, RectTransform, (Action<bool>, Func<bool>, Action)> func = CreateBookTab;
			MethodInfo method = ((object)value.Instance).GetType().GetMethod("RegisterMonsterCompendium", new Type[1] { func.GetType() });
			if (method == null)
			{
				return false;
			}
			try
			{
				object obj = method.Invoke(value.Instance, new object[1] { func });
				return obj is bool && (bool)obj;
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)$"Could not register the CraftingBook tab: {arg}");
				return false;
			}
		}

		private (Action<bool> SetVisible, Func<bool> HandleBack, Action Dispose) CreateBookTab(InventoryGui gui, RectTransform host)
		{
			if (!Object.op_Implicit((Object)(object)host))
			{
				sharedBook = false;
				return default((Action<bool>, Func<bool>, Action));
			}
			CompendiumView page;
			try
			{
				page = CompendiumView.Create(gui, Catalog, () => journal, null, MarkRead, host);
			}
			catch (Exception arg)
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)$"Could not create the CraftingBook tab: {arg}");
				page = null;
			}
			if (page == null)
			{
				sharedBook = false;
				return default((Action<bool>, Func<bool>, Action));
			}
			view?.Dispose();
			view = page;
			sharedBook = true;
			return (SetVisible: delegate(bool visible)
			{
				if (Object.op_Implicit((Object)(object)this) && view == page)
				{
					if (visible && EnsurePlayer())
					{
						page.Open();
					}
					else
					{
						page.Close();
					}
				}
			}, HandleBack: page.HandleBack, Dispose: delegate
			{
				if (view == page)
				{
					view = null;
					page.Dispose();
				}
			});
		}

		private void UpdateStandaloneBook()
		{
			InventoryGui instance = InventoryGui.instance;
			if (instance != inventory)
			{
				view?.Dispose();
				view = null;
				inventory = instance;
				triedAttach = false;
			}
			if (CanUseBook() && Object.op_Implicit((Object)(object)inventory) && !triedAttach && Localization.instance != null)
			{
				triedAttach = true;
				view = CompendiumView.Create(inventory, Catalog, () => journal, ToggleBook, MarkRead);
				if (view == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"MonsterCompendium could not find the inventory toolbar or Skills panel templates.");
				}
			}
		}

		private bool EnsurePlayer()
		{
			Player localPlayer = Player.m_localPlayer;
			if (player != localPlayer)
			{
				SaveJournal();
				player = localPlayer;
				journal = null;
				attacks.Clear();
				view?.Reset();
			}
			if (!Object.op_Implicit((Object)(object)player))
			{
				return false;
			}
			if (journal == null)
			{
				player.m_customData.TryGetValue("fr.romaindurand.monstercompendium.journal.v1", out var value);
				journal = Journal.Load(value);
				nextLook = 0f;
			}
			return true;
		}

		private bool CanUseBook()
		{
			if (Object.op_Implicit((Object)(object)player) && !((Character)player).IsDead() && !((Character)player).InCutscene() && !((Character)player).IsTeleporting() && !Menu.IsVisible() && !Minimap.I