Decompiled source of CraftingBook v1.1.2

plugins/CraftingBook.dll

Decompiled an hour ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
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("CraftingBook")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.2.0")]
[assembly: AssemblyInformationalVersion("1.1.2+36cab87793e4e8c370b63f900ede78b256f102a3")]
[assembly: AssemblyProduct("CraftingBook")]
[assembly: AssemblyTitle("CraftingBook")]
[assembly: AssemblyVersion("1.1.2.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 CraftingBook
{
	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 void Icon(RectTransform rect, Sprite sprite)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			if (Object.op_Implicit((Object)(object)sprite))
			{
				Image obj = Image(rect, Color.white);
				obj.sprite = sprite;
				obj.preserveAspect = true;
			}
		}

		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("CraftingBook.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;

		private readonly Image hitArea;

		private readonly Scrollbar scrollbar;

		public RectTransform Root { get; }

		public RectTransform Content { get; }

		public float Width { get; }

		public BookScroll(RectTransform root, float width, bool showScrollbar, float scrollSensitivity)
		{
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_0177: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_0219: Unknown result type (might be due to invalid IL or missing references)
			//IL_0265: Unknown result type (might be due to invalid IL or missing references)
			//IL_0273: Unknown result type (might be due to invalid IL or missing references)
			Root = root;
			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>();
			hitArea = 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);
				BookUi.Image(val2, new Color(0.1f, 0.065f, 0.038f, 0.78f), null, raycast: true);
				RectTransform val3 = BookUi.Rect("Sliding area", (Transform)(object)val2);
				BookUi.Fill(val3, 1f, 1f, 1f, 1f);
				RectTransform val4 = BookUi.Rect("Thumb", (Transform)(object)val3);
				BookUi.Fill(val4);
				Image targetGraphic = BookUi.Image(val4, new Color(0.72f, 0.49f, 0.27f, 0.9f), null, raycast: true);
				scrollbar = ((Component)val2).gameObject.AddComponent<Scrollbar>();
				scrollbar.handleRect = val4;
				((Selectable)scrollbar).targetGraphic = (Graphic)(object)targetGraphic;
				scrollbar.direction = (Direction)2;
				Scrollbar obj = scrollbar;
				Navigation navigation = default(Navigation);
				((Navigation)(ref navigation)).mode = (Mode)0;
				((Selectable)obj).navigation = navigation;
				scroll.verticalScrollbar = scrollbar;
				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 void EnableInput(bool enabled)
		{
			if (((Graphic)hitArea).raycastTarget != enabled)
			{
				((Graphic)hitArea).raycastTarget = enabled;
				if (Object.op_Implicit((Object)(object)scrollbar))
				{
					((Selectable)scrollbar).interactable = enabled;
				}
				if (!enabled)
				{
					scroll.StopMovement();
				}
			}
		}
	}
	internal sealed class BookView : IDisposable
	{
		private sealed class MaterialCount
		{
			public readonly string ItemName;

			public readonly int Required;

			public readonly TMP_Text Label;

			public int Owned = -1;

			public MaterialCount(string itemName, int required, TMP_Text label)
			{
				ItemName = itemName;
				Required = required;
				Label = label;
			}
		}

		private static readonly Color Gold = new Color(1f, 0.75f, 0.38f);

		private static readonly Color PinCardColor = new Color(0.035f, 0.03f, 0.025f, 0.52f);

		private static readonly Color ColumnColor = new Color(0.15f, 0.09f, 0.055f, 0.81f);

		private static readonly Color RowColor = new Color(0.36f, 0.25f, 0.16f, 0.88f);

		private static readonly Color SelectedColor = new Color(0.67f, 0.4f, 0.16f);

		private static readonly Color EnoughColor = new Color(0.78f, 0.94f, 0.61f);

		private static readonly Color MissingColor = new Color(1f, 0.62f, 0.43f);

		private const float PinWidth = 304f;

		private const float PinMaxHeight = 648f;

		private const float RowHeight = 44f;

		private const float RowGap = 3f;

		private const float DefaultScrollSensitivity = 3000f;

		private readonly Image frameStyle;

		private readonly Image buttonStyle;

		private readonly TMP_Text titleStyle;

		private readonly TMP_Text bodyStyle;

		private readonly float scrollSensitivity;

		private readonly Action<BookRecipe> togglePin;

		private readonly RectTransform[] toolbar;

		private readonly Vector2[] originalPositions;

		private readonly RectTransform bookButton;

		private readonly Texture2D bookTexture;

		private readonly Sprite bookSprite;

		private readonly Canvas canvas;

		private readonly GraphicRaycaster raycaster;

		private readonly RectTransform modal;

		private readonly BookScroll stations;

		private readonly BookScroll recipes;

		private readonly BookScroll details;

		private readonly BookScroll pins;

		private readonly RectTransform pinButton;

		private readonly TMP_Text pinLabel;

		private readonly RectTransform craftingPinButton;

		private readonly TMP_Text craftingPinLabel;

		private readonly List<MaterialCount> detailCounts = new List<MaterialCount>();

		private readonly List<MaterialCount> pinCounts = new List<MaterialCount>();

		private readonly HashSet<string> pinnedIds = new HashSet<string>();

		private BookRecipe selectedRecipe;

		private Recipe craftingSelection;

		private BookRecipe craftingRecipe;

		private Image selectedStationRow;

		private Image selectedRecipeRow;

		private float nextCountUpdate;

		public bool IsOpen => ((Component)modal).gameObject.activeSelf;

		public static BookView Create(InventoryGui gui, Action toggleBook, Action<BookRecipe> togglePin)
		{
			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)val2))
			{
				obj = null;
			}
			else
			{
				Transform obj2 = val2.Find("bkg");
				obj = ((obj2 != null) ? ((Component)obj2).GetComponent<Image>() : null);
			}
			Image val3 = (Image)obj;
			object obj3;
			if (!Object.op_Implicit((Object)(object)val2))
			{
				obj3 = null;
			}
			else
			{
				Transform obj4 = val2.Find("Closebutton");
				obj3 = ((obj4 != null) ? ((Component)obj4).GetComponent<Image>() : null);
			}
			Image val4 = (Image)obj3;
			object obj5;
			if (!Object.op_Implicit((Object)(object)val2))
			{
				obj5 = null;
			}
			else
			{
				Transform obj6 = val2.Find("topic");
				obj5 = ((obj6 != null) ? ((Component)obj6).GetComponent<TMP_Text>() : null);
			}
			TMP_Text val5 = (TMP_Text)obj5;
			if (!Object.op_Implicit((Object)(object)val) || !Object.op_Implicit((Object)(object)gui.m_crafting) || !Object.op_Implicit((Object)(object)val3) || !Object.op_Implicit((Object)(object)val4) || !Object.op_Implicit((Object)(object)val5) || !Object.op_Implicit((Object)(object)gui.m_recipeDecription))
			{
				return null;
			}
			RectTransform[] array = (RectTransform[])(object)new RectTransform[5];
			string[] array2 = new string[5] { "Texts", "Skills", "Trophies", "Achievements", "PVP" };
			for (int i = 0; i < array2.Length; i++)
			{
				ref RectTransform reference = ref array[i];
				Transform obj7 = ((Transform)info).Find(array2[i]);
				reference = (RectTransform)(object)((obj7 is RectTransform) ? obj7 : null);
				if (!Object.op_Implicit((Object)(object)array[i]))
				{
					return null;
				}
			}
			UIGroupHandler component = ((Component)gui.m_skillsDialog).GetComponent<UIGroupHandler>();
			return new BookView(info, array, val3, val4, val5, gui.m_recipeDecription, val, gui, Object.op_Implicit((Object)(object)component) ? component.m_groupPriority : 2, toggleBook, togglePin);
		}

		private BookView(RectTransform bar, RectTransform[] toolbar, Image frame, Image button, TMP_Text title, TMP_Text body, Canvas inventoryCanvas, InventoryGui gui, int groupPriority, Action toggleBook, Action<BookRecipe> togglePin)
		{
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0145: 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_015f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0295: Expected O, but got Unknown
			//IL_030c: Unknown result type (might be due to invalid IL or missing references)
			//IL_03bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0404: Unknown result type (might be due to invalid IL or missing references)
			//IL_040b: Unknown result type (might be due to invalid IL or missing references)
			//IL_040d: Unknown result type (might be due to invalid IL or missing references)
			//IL_040e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0428: Unknown result type (might be due to invalid IL or missing references)
			//IL_043a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0491: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_065a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0661: Unknown result type (might be due to invalid IL or missing references)
			//IL_0678: Unknown result type (might be due to invalid IL or missing references)
			//IL_0692: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_075b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0762: Unknown result type (might be due to invalid IL or missing references)
			//IL_0764: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Unknown result type (might be due to invalid IL or missing references)
			//IL_076c: Unknown result type (might be due to invalid IL or missing references)
			//IL_077f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0795: Unknown result type (might be due to invalid IL or missing references)
			BookView bookView = this;
			this.toolbar = toolbar;
			this.togglePin = togglePin;
			frameStyle = frame;
			buttonStyle = button;
			titleStyle = title;
			bodyStyle = body;
			ScrollRect val = (Object.op_Implicit((Object)(object)gui.m_recipeListRoot) ? ((Component)gui.m_recipeListRoot).GetComponentInParent<ScrollRect>(true) : null);
			scrollSensitivity = (Object.op_Implicit((Object)(object)val) ? val.scrollSensitivity : 3000f);
			originalPositions = (Vector2[])(object)new Vector2[toolbar.Length];
			float y = toolbar[0].anchoredPosition.y;
			for (int i = 0; i < toolbar.Length; i++)
			{
				originalPositions[i] = toolbar[i].anchoredPosition;
				toolbar[i].anchoredPosition = new Vector2((float)(-210 + i * 84), y);
			}
			bookButton = BookUi.Rect("CraftingBook", (Transform)(object)bar);
			RectTransform obj = bookButton;
			RectTransform obj2 = bookButton;
			RectTransform obj3 = bookButton;
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			obj3.pivot = val2;
			Vector2 val3 = (obj.anchorMin = (obj2.anchorMax = val2));
			bookButton.anchoredPosition = new Vector2(210f, y);
			bookButton.sizeDelta = new Vector2(64f, 64f);
			bookTexture = BookUi.LoadBookTexture();
			bookSprite = Sprite.Create(bookTexture, new Rect(0f, 0f, (float)((Texture)bookTexture).width, (float)((Texture)bookTexture).height), new Vector2(0.5f, 0.5f));
			Image val6 = BookUi.Image(bookButton, Color.white);
			val6.sprite = bookSprite;
			val6.preserveAspect = true;
			BookUi.Button(bookButton, val6, toggleBook);
			UITooltip component = ((Component)toolbar[1]).GetComponent<UITooltip>();
			if (Object.op_Implicit((Object)(object)component) && Object.op_Implicit((Object)(object)component.m_tooltipPrefab))
			{
				UITooltip obj4 = ((Component)bookButton).gameObject.AddComponent<UITooltip>();
				obj4.m_tooltipPrefab = component.m_tooltipPrefab;
				obj4.m_text = Text.Label("Crafting book", "Livre de recettes");
			}
			GameObject val7 = new GameObject("CraftingBook Canvas", new Type[3]
			{
				typeof(Canvas),
				typeof(CanvasScaler),
				typeof(GraphicRaycaster)
			});
			canvas = val7.GetComponent<Canvas>();
			canvas.renderMode = (RenderMode)0;
			canvas.sortingLayerID = inventoryCanvas.sortingLayerID;
			canvas.sortingOrder = inventoryCanvas.sortingOrder + 1;
			canvas.targetDisplay = inventoryCanvas.targetDisplay;
			raycaster = val7.GetComponent<GraphicRaycaster>();
			CanvasScaler component2 = val7.GetComponent<CanvasScaler>();
			component2.uiScaleMode = (ScaleMode)1;
			component2.referenceResolution = new Vector2(1920f, 1080f);
			component2.screenMatchMode = (ScreenMatchMode)1;
			modal = BookUi.Rect("Recipe book", ((Component)canvas).transform);
			BookUi.Fill(modal);
			((Component)modal).gameObject.AddComponent<CanvasGroup>();
			((Component)modal).gameObject.AddComponent<UIGroupHandler>().m_groupPriority = groupPriority;
			RectTransform rect = BookUi.Rect("Backdrop", (Transform)(object)modal);
			BookUi.Fill(rect);
			BookUi.Button(rect, BookUi.Image(rect, new Color(0.035f, 0.022f, 0.012f, 0.74f)), Close);
			RectTransform val8 = BookUi.Rect("Book frame", (Transform)(object)modal);
			((Vector2)(ref val2))..ctor(0.5f, 0.5f);
			val8.pivot = val2;
			val3 = (val8.anchorMin = (val8.anchorMax = val2));
			val8.sizeDelta = new Vector2(1120f, 704f);
			BookUi.Image(val8, ((Graphic)frameStyle).color, frameStyle, raycast: true);
			((Graphic)BookUi.Label(BookUi.Place("Title", (Transform)(object)val8, 218f, 13f, 684f, 49f), titleStyle, Text.Label("Crafting book", "Livre de recettes"), 32f, (TextAlignmentOptions)514)).color = Gold;
			RectTransform obj5 = BookUi.Place("Close", (Transform)(object)val8, 957f, 16f, 140f, 40f);
			BookUi.Button(obj5, BookUi.Image(obj5, ((Graphic)buttonStyle).color, buttonStyle), Close);
			BookUi.Label(ChildLabel(obj5, "Close label"), bodyStyle, Text.Label("Close", "Fermer"), 20f, (TextAlignmentOptions)514);
			stations = Column(val8, Text.Label("Stations", "Stations"), 22f, 206f, 581f);
			recipes = Column(val8, Text.Label("Recipes", "Recettes"), 240f, 305f, 581f);
			details = Column(val8, Text.Label("Details", "Détails"), 557f, 541f, 531f);
			pinButton = BookUi.Place("Pin recipe", (Transform)(object)val8, 854f, 630f, 244f, 41f);
			BookUi.Button(pinButton, BookUi.Image(pinButton, ((Graphic)buttonStyle).color, buttonStyle), delegate
			{
				togglePin(bookView.selectedRecipe);
			});
			pinLabel = (TMP_Text)(object)BookUi.Label(ChildLabel(pinButton, "Pin label"), bodyStyle, "", 20f, (TextAlignmentOptions)514);
			craftingPinButton = BookUi.Rect("CraftingBook Pin Recipe", (Transform)(object)gui.m_crafting);
			RectTransform obj6 = craftingPinButton;
			RectTransform obj7 = craftingPinButton;
			((Vector2)(ref val3))..ctor(1f, 1f);
			obj7.anchorMax = val3;
			obj6.anchorMin = val3;
			craftingPinButton.pivot = new Vector2(1f, 0.5f);
			craftingPinButton.anchoredPosition = new Vector2(-12f, -84f);
			craftingPinButton.sizeDelta = new Vector2(210f, 30f);
			BookUi.Button(craftingPinButton, BookUi.Image(craftingPinButton, ((Graphic)buttonStyle).color, buttonStyle), delegate
			{
				togglePin(bookView.craftingRecipe);
			});
			craftingPinLabel = (TMP_Text)(object)BookUi.Label(ChildLabel(craftingPinButton, "Pin label"), bodyStyle, "", 18f, (TextAlignmentOptions)514);
			((Component)craftingPinButton).gameObject.SetActive(false);
			RectTransform val11 = BookUi.Rect("Pinned recipes", ((Component)canvas).transform);
			((Vector2)(ref val2))..ctor(1f, 0.5f);
			val11.pivot = val2;
			val3 = (val11.anchorMin = (val11.anchorMax = val2));
			val11.anchoredPosition = new Vector2(-25f, 0f);
			val11.sizeDelta = new Vector2(304f, 0f);
			pins = new BookScroll(val11, 304f, showScrollbar: true, scrollSensitivity);
			((Component)val11).gameObject.SetActive(false);
			Close();
		}

		public void Open(StationRecipes[] catalog, Inventory inventory)
		{
			if (Object.op_Implicit((Object)(object)EventSystem.current))
			{
				EventSystem.current.SetSelectedGameObject((GameObject)null);
			}
			((Component)modal).gameObject.SetActive(true);
			BookUi.Clear(stations.Content);
			selectedStationRow = null;
			for (int i = 0; i < catalog.Length; i++)
			{
				StationRecipes station = catalog[i];
				Image row = null;
				row = AddRow(stations, i, station.Name, station.Icon, delegate
				{
					SelectStation(station, row);
				});
				if (i == 0)
				{
					SelectStation(station, row);
				}
			}
			stations.SetHeight((float)catalog.Length * 47f);
			if (catalog.Length == 0)
			{
				ClearSelection();
				stations.SetHeight(AddParagraph(stations, 4f, Text.Label("No learned recipes yet.", "Aucune recette apprise."), 18f));
			}
			RefreshCounts(inventory);
		}

		public void Close()
		{
			if (IsOpen)
			{
				((Component)modal).gameObject.SetActive(false);
			}
		}

		public void SetCraftingRecipe(Recipe recipe)
		{
			if (craftingSelection != recipe)
			{
				craftingSelection = recipe;
				craftingRecipe = ((Object.op_Implicit((Object)(object)recipe) && Object.op_Implicit((Object)(object)recipe.m_item)) ? BookRecipe.FromCraftingRecipe(recipe) : null);
				UpdatePinButton(craftingPinButton, craftingPinLabel, craftingRecipe);
			}
		}

		public void SetPins(List<BookRecipe> entries)
		{
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_0131: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			pinnedIds.Clear();
			pinCounts.Clear();
			BookUi.Clear(pins.Content);
			float num = 0f;
			foreach (BookRecipe entry in entries)
			{
				pinnedIds.Add(entry.Id);
				float num2 = (entry.OneIngredient ? 59 : 39) + entry.Ingredients.Length * 29 + 10;
				num2 = Mathf.Max(54f, num2);
				RectTransform val = BookUi.Place("Pinned recipe", (Transform)(object)pins.Content, 0f, num, pins.Width, num2);
				BookUi.Image(val, PinCardColor);
				BookUi.Icon(BookUi.Place("Item icon", (Transform)(object)val, 9f, 7f, 25f, 25f), entry.Item.GetIcon());
				((Graphic)BookUi.Label(BookUi.Place("Recipe name", (Transform)(object)val, 41f, 5f, pins.Width - 50f, 32f), bodyStyle, entry.Name, 17f, (TextAlignmentOptions)513, wrap: true)).color = Gold;
				if (entry.OneIngredient)
				{
					BookUi.Label(BookUi.Place("Alternatives", (Transform)(object)val, 11f, 36f, pins.Width - 22f, 21f), bodyStyle, Text.Label("Any one of these", "Un ingrédient au choix"), 14f, (TextAlignmentOptions)513);
				}
				if (entry.Ingredients.Length == 0)
				{
					BookUi.Label(BookUi.Place("No ingredients", (Transform)(object)val, 11f, 32f, pins.Width - 22f, 19f), bodyStyle, Text.Label("No ingredients", "Aucun ingrédient"), 14f, (TextAlignmentOptions)513);
				}
				for (int i = 0; i < entry.Ingredients.Length; i++)
				{
					float y = (entry.OneIngredient ? 57 : 37) + i * 29;
					AddMaterial(val, y, pins.Width, 28f, entry.Ingredients[i], pinCounts);
				}
				num += num2 + 8f;
			}
			float num3 = ((entries.Count > 0) ? (num - 8f) : 0f);
			pins.Root.sizeDelta = new Vector2(304f, Mathf.Min(648f, num3 + 12f));
			pins.SetHeight(num3);
			nextCountUpdate = 0f;
			UpdatePinButton(pinButton, pinLabel, selectedRecipe);
			UpdatePinButton(craftingPinButton, craftingPinLabel, craftingRecipe);
		}

		public void UpdatePins(bool show, Inventory inventory)
		{
			((Component)pins.Root).gameObject.SetActive(show && pinnedIds.Count != 0);
			((Behaviour)raycaster).enabled = IsOpen;
			pins.EnableInput(IsOpen);
			if (inventory != null && (IsOpen || ((Component)pins.Root).gameObject.activeSelf) && Time.unscaledTime >= nextCountUpdate)
			{
				RefreshCounts(inventory);
			}
		}

		public void Dispose()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < toolbar.Length; i++)
			{
				if (Object.op_Implicit((Object)(object)toolbar[i]))
				{
					toolbar[i].anchoredPosition = originalPositions[i];
				}
			}
			if (Object.op_Implicit((Object)(object)bookButton))
			{
				Object.Destroy((Object)(object)((Component)bookButton).gameObject);
			}
			if (Object.op_Implicit((Object)(object)craftingPinButton))
			{
				Object.Destroy((Object)(object)((Component)craftingPinButton).gameObject);
			}
			if (Object.op_Implicit((Object)(object)canvas))
			{
				Object.Destroy((Object)(object)((Component)canvas).gameObject);
			}
			Object.Destroy((Object)(object)bookSprite);
			Object.Destroy((Object)(object)bookTexture);
		}

		private BookScroll Column(RectTransform panel, string name, float x, float width, float height)
		{
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			((Graphic)BookUi.Label(BookUi.Place(name, (Transform)(object)panel, x + 6f, 62f, width - 12f, 27f), bodyStyle, name, 21f, (TextAlignmentOptions)513)).color = Gold;
			RectTransform obj = BookUi.Place(name + " column", (Transform)(object)panel, x, 90f, width, height);
			BookUi.Image(obj, ColumnColor);
			return new BookScroll(obj, width, showScrollbar: true, scrollSensitivity);
		}

		private Image AddRow(BookScroll column, int index, string name, Sprite icon, Action click)
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			RectTransform val = BookUi.Place("Entry", (Transform)(object)column.Content, 0f, (float)index * 47f, column.Width, 44f);
			Image val2 = BookUi.Image(val, RowColor);
			BookUi.Button(val, val2, click);
			float num = (Object.op_Implicit((Object)(object)icon) ? 43 : 10);
			if (Object.op_Implicit((Object)(object)icon))
			{
				BookUi.Icon(BookUi.Place("Icon", (Transform)(object)val, 6f, 5f, 33f, 33f), icon);
			}
			BookUi.Label(BookUi.Place("Name", (Transform)(object)val, num, 2f, column.Width - num - 8f, 40f), bodyStyle, name, 19f, (TextAlignmentOptions)513, wrap: true);
			return val2;
		}

		private void SelectStation(StationRecipes station, Image row)
		{
			SelectRow(ref selectedStationRow, row);
			BookUi.Clear(recipes.Content);
			selectedRecipeRow = null;
			for (int i = 0; i < station.Recipes.Count; i++)
			{
				BookRecipe recipe = station.Recipes[i];
				Image recipeRow = null;
				recipeRow = AddRow(recipes, i, recipe.Name, recipe.Item.GetIcon(), delegate
				{
					SelectRecipe(recipe, recipeRow);
				});
				if (i == 0)
				{
					SelectRecipe(recipe, recipeRow);
				}
			}
			recipes.SetHeight((float)station.Recipes.Count * 47f);
		}

		private void SelectRecipe(BookRecipe recipe, Image row)
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e6: Unknown result type (might be due to invalid IL or missing references)
			SelectRow(ref selectedRecipeRow, row);
			selectedRecipe = recipe;
			detailCounts.Clear();
			BookUi.Clear(details.Content);
			BookUi.Icon(BookUi.Place("Item icon", (Transform)(object)details.Content, 9f, 9f, 56f, 56f), recipe.Item.GetIcon());
			string text = ((recipe.Amount > 1) ? $"{recipe.Name} x{recipe.Amount}" : recipe.Name);
			((Graphic)BookUi.Label(BookUi.Place("Item name", (Transform)(object)details.Content, 76f, 5f, details.Width - 89f, 62f), bodyStyle, text, 26f, (TextAlignmentOptions)513, wrap: true)).color = Gold;
			float y = 76f;
			if (recipe.StationLevel > 0)
			{
				y = AddParagraph(details, y, Text.Label($"Station level {recipe.StationLevel}", $"Station de niveau {recipe.StationLevel}"), 19f);
			}
			string tooltip = ItemData.GetTooltip(recipe.Item, 1, true, (float)Game.m_worldLevel, recipe.Amount, false);
			y = AddParagraph(details, y, Text.Localize(tooltip), 19f) + 15f;
			string text2 = (recipe.OneIngredient ? Text.Label("Ingredients · choose one", "Ingrédients · un au choix") : Text.Label("Ingredients", "Ingrédients"));
			((Graphic)BookUi.Label(BookUi.Place("Ingredients", (Transform)(object)details.Content, 10f, y, details.Width - 20f, 28f), bodyStyle, text2, 21f, (TextAlignmentOptions)513)).color = Gold;
			y += 32f;
			Ingredient[] ingredients = recipe.Ingredients;
			foreach (Ingredient ingredient in ingredients)
			{
				AddMaterial(details.Content, y, details.Width, 38f, ingredient, detailCounts);
				y += 39f;
			}
			if (recipe.Ingredients.Length == 0)
			{
				y = AddParagraph(details, y, Text.Label("No ingredients", "Aucun ingrédient"), 18f);
			}
			details.SetHeight(y + 6f);
			nextCountUpdate = 0f;
			UpdatePinButton(pinButton, pinLabel, selectedRecipe);
		}

		private void ClearSelection()
		{
			selectedRecipe = null;
			detailCounts.Clear();
			BookUi.Clear(recipes.Content);
			BookUi.Clear(details.Content);
			recipes.SetHeight(0f);
			details.SetHeight(0f);
			UpdatePinButton(pinButton, pinLabel, selectedRecipe);
		}

		private void UpdatePinButton(RectTransform button, TMP_Text label, BookRecipe recipe)
		{
			((Component)button).gameObject.SetActive(recipe != null);
			if (recipe != null)
			{
				label.text = (pinnedIds.Contains(recipe.Id) ? Text.Label("Unpin recipe", "Désépingler la recette") : Text.Label("Pin recipe", "Épingler la recette"));
			}
		}

		private float AddParagraph(BookScroll column, float y, string text, float size)
		{
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			float num = column.Width - 20f;
			RectTransform obj = BookUi.Place("Text", (Transform)(object)column.Content, 10f, y, num, 0f);
			TextMeshProUGUI obj2 = BookUi.Label(obj, bodyStyle, text, size, (TextAlignmentOptions)257, wrap: true);
			((TMP_Text)obj2).overflowMode = (TextOverflowModes)0;
			float num2 = Mathf.Ceil(((TMP_Text)obj2).GetPreferredValues(text, num, 0f).y);
			obj.sizeDelta = new Vector2(num, num2);
			return y + num2 + 6f;
		}

		private void AddMaterial(RectTransform parent, float y, float width, float height, Ingredient ingredient, List<MaterialCount> counts)
		{
			float num = height - 5f;
			BookUi.Icon(BookUi.Place("Ingredient icon", (Transform)(object)parent, 10f, y + 2f, num, num), ingredient.Item.GetIcon());
			float num2 = 16f + num;
			string name = ingredient.Item.m_shared.m_name;
			float size = ((height > 30f) ? 19 : 15);
			BookUi.Label(BookUi.Place("Ingredient name", (Transform)(object)parent, num2, y, width - num2 - 83f, height), bodyStyle, Text.Localize(name), size, (TextAlignmentOptions)513, wrap: true);
			TextMeshProUGUI label = BookUi.Label(BookUi.Place("Owned and required", (Transform)(object)parent, width - 81f, y, 71f, height), bodyStyle, $"…/{ingredient.Amount}", size, (TextAlignmentOptions)516);
			counts.Add(new MaterialCount(name, ingredient.Amount, (TMP_Text)(object)label));
		}

		private void RefreshCounts(Inventory inventory)
		{
			if (IsOpen)
			{
				RefreshCounts(inventory, detailCounts);
			}
			RefreshCounts(inventory, pinCounts);
			nextCountUpdate = Time.unscaledTime + 0.25f;
		}

		private static void RefreshCounts(Inventory inventory, List<MaterialCount> counts)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0065: Unknown result type (might be due to invalid IL or missing references)
			foreach (MaterialCount count in counts)
			{
				int num = inventory.CountItems(count.ItemName, -1, true);
				if (num != count.Owned)
				{
					count.Owned = num;
					count.Label.text = $"{num}/{count.Required}";
					((Graphic)count.Label).color = ((num >= count.Required) ? EnoughColor : MissingColor);
				}
			}
		}

		private static void SelectRow(ref Image selected, Image row)
		{
			//IL_0019: 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)
			if (Object.op_Implicit((Object)(object)selected))
			{
				((Graphic)selected).color = RowColor;
			}
			selected = row;
			((Graphic)row).color = SelectedColor;
		}

		private static RectTransform ChildLabel(RectTransform parent, string name)
		{
			RectTransform obj = BookUi.Rect(name, (Transform)(object)parent);
			BookUi.Fill(obj, 7f, 0f, 7f);
			return obj;
		}
	}
	[BepInPlugin("fr.romaindurand.craftingbook", "CraftingBook", "1.1.2")]
	public sealed class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(InventoryGui), "Hide")]
		private static class InventoryClosed
		{
			private static void Postfix(InventoryGui __instance)
			{
				if (Object.op_Implicit((Object)(object)instance) && (Object)(object)instance.inventoryGui == (Object)(object)__instance && instance.view != null)
				{
					instance.view.Close();
					instance.view.SetCraftingRecipe(null);
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "SetRecipe")]
		private static class CraftingRecipeSelected
		{
			private static void Postfix(InventoryGui __instance)
			{
				if (Object.op_Implicit((Object)(object)instance) && (Object)(object)instance.inventoryGui == (Object)(object)__instance && instance.view != null)
				{
					instance.RefreshCraftingPin();
				}
			}
		}

		[HarmonyPatch(typeof(InventoryGui), "Update")]
		private static class CancelBook
		{
			private static bool Prefix(InventoryGui __instance)
			{
				if (Object.op_Implicit((Object)(object)instance) && !((Object)(object)instance.inventoryGui != (Object)(object)__instance))
				{
					BookView view = instance.view;
					if (view != null && view.IsOpen && InventoryGui.IsVisible() && !Menu.IsVisible() && !Console.IsVisible() && Object.op_Implicit((Object)(object)Player.m_localPlayer) && !((Character)Player.m_localPlayer).IsDead())
					{
						if (!ZInput.GetKeyDown((KeyCode)27, true) && !ZInput.GetButtonDown("JoyButtonB"))
						{
							return true;
						}
						ZInput.ResetButtonStatus("JoyButtonB");
						instance.view.Close();
						return false;
					}
				}
				return true;
			}
		}

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

		private const string Version = "1.1.2";

		private static readonly FieldInfo SelectedRecipeField = AccessTools.Field(typeof(InventoryGui), "m_selectedRecipe");

		private static readonly PropertyInfo SelectedRecipeProperty = ((SelectedRecipeField == null) ? null : AccessTools.Property(SelectedRecipeField.FieldType, "Recipe"));

		private static Plugin instance;

		private Harmony harmony;

		private InventoryGui inventoryGui;

		private ObjectDB database;

		private Player player;

		private long characterId;

		private readonly List<BookRecipe> pinned = new List<BookRecipe>();

		private BookView view;

		private bool triedAttach;

		private void Awake()
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			instance = this;
			harmony = new Harmony("fr.romaindurand.craftingbook");
			harmony.PatchAll(typeof(Plugin).Assembly);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"CraftingBook 1.1.2 loaded (fr.romaindurand.craftingbook).");
		}

		private void LateUpdate()
		{
			InventoryGui val = InventoryGui.instance;
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)database != (Object)(object)ObjectDB.instance)
			{
				database = ObjectDB.instance;
				pinned.Clear();
				view?.Close();
				view?.SetPins(pinned);
			}
			if ((Object)(object)inventoryGui != (Object)(object)val || (!Object.op_Implicit((Object)(object)val) && view != null))
			{
				view?.Dispose();
				view = null;
				inventoryGui = val;
				triedAttach = false;
			}
			if ((Object)(object)localPlayer != (Object)(object)player)
			{
				goto IL_00ca;
			}
			if (!Object.op_Implicit((Object)(object)localPlayer))
			{
				BookView bookView = view;
				if (bookView != null && bookView.IsOpen)
				{
					goto IL_00ca;
				}
			}
			goto IL_0135;
			IL_0135:
			bool flag = Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)database) && Object.op_Implicit((Object)(object)val) && Localization.instance != null && !((Character)player).IsDead() && !((Character)player).InCutscene() && !((Character)player).IsTeleporting();
			if (flag && !triedAttach)
			{
				triedAttach = true;
				view = BookView.Create(val, ToggleBook, TogglePin);
				if (view == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)"CraftingBook could not find the inventory toolbar or Skills panel templates.");
				}
				else
				{
					view.SetPins(pinned);
					RefreshCraftingPin();
				}
			}
			if (view == null)
			{
				return;
			}
			bool flag2 = InventoryGui.IsVisible();
			int num;
			if (flag && !Menu.IsVisible() && !Minimap.IsOpen())
			{
				num = (Console.IsVisible() ? 1 : 0);
				if (num == 0 && flag2)
				{
					goto IL_0229;
				}
			}
			else
			{
				num = 1;
			}
			view.Close();
			goto IL_0229;
			IL_00ca:
			player = localPlayer;
			view?.Close();
			if (Object.op_Implicit((Object)(object)player) && player.GetPlayerID() != characterId)
			{
				characterId = player.GetPlayerID();
				pinned.Clear();
				view?.SetPins(pinned);
			}
			goto IL_0135;
			IL_0229:
			bool flag3 = num == 0 && !Hud.IsUserHidden() && (!flag2 || view.IsOpen);
			view.UpdatePins(flag3, flag3 ? ((Humanoid)player).GetInventory() : null);
		}

		private void ToggleBook()
		{
			if (view.IsOpen)
			{
				view.Close();
			}
			else if (Object.op_Implicit((Object)(object)player) && Object.op_Implicit((Object)(object)database) && InventoryGui.IsVisible())
			{
				view.Open(RecipeCatalog.GetStations(player, database), ((Humanoid)player).GetInventory());
			}
		}

		private void TogglePin(BookRecipe recipe)
		{
			int num = pinned.FindIndex((BookRecipe pin) => pin.Id == recipe.Id);
			if (num < 0)
			{
				pinned.Insert(0, recipe);
			}
			else
			{
				pinned.RemoveAt(num);
			}
			view.SetPins(pinned);
		}

		private void RefreshCraftingPin()
		{
			Recipe craftingRecipe = (Recipe)((Object.op_Implicit((Object)(object)Player.m_localPlayer) && inventoryGui.InCraftTab()) ? /*isinst with value type is only supported in some contexts*/: null);
			view.SetCraftingRecipe(craftingRecipe);
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			view?.Dispose();
			instance = null;
		}
	}
	internal static class RecipeAvailability
	{
		public static bool CanBrowse(bool enabled, bool inSeason, bool upgradeOnly, bool learned, bool unlocked)
		{
			if ((enabled || inSeason) && !upgradeOnly)
			{
				return learned || unlocked;
			}
			return false;
		}
	}
	internal sealed class StationRecipes
	{
		public string Name { get; }

		public Sprite Icon { get; }

		public List<BookRecipe> Recipes { get; } = new List<BookRecipe>();

		public StationRecipes(string name, Sprite icon)
		{
			Name = name;
			Icon = icon;
		}
	}
	internal sealed class BookRecipe
	{
		public string Id { get; }

		public ItemData Item { get; }

		public int Amount { get; }

		public int StationLevel { get; }

		public bool OneIngredient { get; }

		public Ingredient[] Ingredients { get; }

		public string Name => Text.Localize(Item.m_shared.m_name);

		public BookRecipe(string id, ItemData item, int amount, int stationLevel, bool oneIngredient, Ingredient[] ingredients)
		{
			Id = id;
			Item = item;
			Amount = amount;
			StationLevel = stationLevel;
			OneIngredient = oneIngredient;
			Ingredients = ingredients;
		}

		public static BookRecipe FromCraftingRecipe(Recipe recipe)
		{
			Ingredient[] ingredients = (from requirement in recipe.m_resources ?? Array.Empty<Requirement>()
				where requirement != null && Object.op_Implicit((Object)(object)requirement.m_resItem) && !requirement.m_upgraderResource && requirement.GetAmount(1) > 0
				select new Ingredient(requirement.m_resItem.m_itemData, requirement.GetAmount(1))).ToArray();
			return new BookRecipe($"craft/{((Object)recipe).GetInstanceID()}", recipe.m_item.m_itemData, recipe.m_amount, Object.op_Implicit((Object)(object)recipe.m_craftingStation) ? recipe.GetRequiredStationLevel(1) : 0, recipe.m_requireOnlyOneIngredient, ingredients);
		}
	}
	internal readonly struct Ingredient
	{
		public readonly ItemData Item;

		public readonly int Amount;

		public Ingredient(ItemData item, int amount)
		{
			Item = item;
			Amount = amount;
		}
	}
	internal static class RecipeCatalog
	{
		public static StationRecipes[] GetStations(Player player, ObjectDB database)
		{
			Dictionary<string, StationRecipes> dictionary = new Dictionary<string, StationRecipes>();
			SeasonalItemGroup currentSeason = player.CurrentSeason;
			bool unlocked = player.NoCostCheat() || (Object.op_Implicit((Object)(object)ZoneSystem.instance) && ZoneSystem.instance.GetGlobalKey((GlobalKeys)28));
			bool french = Text.French;
			foreach (Recipe recipe in database.m_recipes)
			{
				if (!Object.op_Implicit((Object)(object)recipe) || !Object.op_Implicit((Object)(object)recipe.m_item))
				{
					continue;
				}
				ItemData itemData = recipe.m_item.m_itemData;
				if (RecipeAvailability.CanBrowse(recipe.m_enabled, Object.op_Implicit((Object)(object)currentSeason) && currentSeason.Recipes.Contains(recipe), recipe.m_noCraftOnlyUpgrade, player.IsRecipeKnown(itemData.m_shared.m_name), unlocked))
				{
					string dlc = itemData.m_shared.m_dlc;
					if (string.IsNullOrEmpty(dlc) || (Object.op_Implicit((Object)(object)DLCMan.instance) && DLCMan.instance.IsDLCInstalled(dlc)))
					{
						CraftingStation craftingStation = recipe.m_craftingStation;
						string key = (Object.op_Implicit((Object)(object)craftingStation) ? craftingStation.m_name : "");
						string name = (Object.op_Implicit((Object)(object)craftingStation) ? Text.Localize(craftingStation.m_name) : (french ? "Fabrication à la main" : "Hand crafting"));
						GetStation(dictionary, key, name, Object.op_Implicit((Object)(object)craftingStation) ? craftingStation.m_icon : null).Recipes.Add(BookRecipe.FromCraftingRecipe(recipe));
					}
				}
			}
			AddCookingStations(database, player, unlocked, dictionary);
			foreach (StationRecipes value in dictionary.Values)
			{
				value.Recipes.Sort((BookRecipe a, BookRecipe b) => string.Compare(a.Name, b.Name, StringComparison.CurrentCultureIgnoreCase));
			}
			return dictionary.Values.OrderBy<StationRecipes, string>((StationRecipes station) => station.Name, StringComparer.CurrentCultureIgnoreCase).ToArray();
		}

		private static void AddCookingStations(ObjectDB database, Player player, bool unlocked, Dictionary<string, StationRecipes> stations)
		{
			HashSet<GameObject> hashSet = new HashSet<GameObject>();
			ItemDrop val = default(ItemDrop);
			CookingStation val2 = default(CookingStation);
			Piece val3 = default(Piece);
			foreach (GameObject item in database.m_items)
			{
				if (!Object.op_Implicit((Object)(object)item) || !item.TryGetComponent<ItemDrop>(ref val) || !Object.op_Implicit((Object)(object)val.m_itemData.m_shared.m_buildPieces))
				{
					continue;
				}
				foreach (GameObject piece in val.m_itemData.m_shared.m_buildPieces.m_pieces)
				{
					if (!Object.op_Implicit((Object)(object)piece) || !hashSet.Add(piece) || !piece.TryGetComponent<CookingStation>(ref val2) || !piece.TryGetComponent<Piece>(ref val3) || !val3.m_enabled || (!unlocked && !player.IsRecipeKnown(val3.m_name)))
					{
						continue;
					}
					string text = $"cooking/{((Object)piece).GetInstanceID()}";
					for (int i = 0; i < val2.m_conversion.Count; i++)
					{
						ItemConversion val4 = val2.m_conversion[i];
						if (val4 != null && Object.op_Implicit((Object)(object)val4.m_from) && Object.op_Implicit((Object)(object)val4.m_to) && (unlocked || player.IsKnownMaterial(val4.m_from.m_itemData.m_shared.m_name)))
						{
							GetStation(stations, text, Text.Localize(val3.m_name), val3.m_icon).Recipes.Add(new BookRecipe($"{text}/{i}", val4.m_to.m_itemData, 1, 0, oneIngredient: false, new Ingredient[1]
							{
								new Ingredient(val4.m_from.m_itemData, 1)
							}));
						}
					}
				}
			}
		}

		private static StationRecipes GetStation(Dictionary<string, StationRecipes> stations, string key, string name, Sprite icon)
		{
			if (!stations.TryGetValue(key, out var value))
			{
				value = new StationRecipes(name, icon);
				stations.Add(key, value);
			}
			return value;
		}
	}
	internal static class Text
	{
		public static bool French => Localization.instance.GetSelectedLanguage() == "French";

		public static string Localize(string text)
		{
			return Localization.instance.Localize(text);
		}

		public static string Label(string english, string french)
		{
			if (!French)
			{
				return english;
			}
			return french;
		}
	}
}