Decompiled source of WaitWhat v1.1.0

WaitWhat.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[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("WaitWhat")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+65cfc5668852add0acf73ba872d9924353e5b46c")]
[assembly: AssemblyProduct("WaitWhat")]
[assembly: AssemblyTitle("WaitWhat")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.0")]
namespace WaitWhat;

internal sealed class IngredientBiomeFile
{
	public readonly List<string> Biomes = new List<string>();

	private readonly Dictionary<string, string> _biomeByPrefab = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);

	public string GetBiome(string prefabName)
	{
		if (!_biomeByPrefab.TryGetValue(prefabName, out var value))
		{
			return null;
		}
		return value;
	}

	public static IngredientBiomeFile Load(string path, ManualLogSource logger)
	{
		IngredientBiomeFile ingredientBiomeFile = new IngredientBiomeFile();
		if (!File.Exists(path))
		{
			logger.LogWarning((object)("Ingredient biome file not found: " + path + ". Biome groups are unavailable."));
			return ingredientBiomeFile;
		}
		string[] array;
		try
		{
			array = File.ReadAllLines(path);
		}
		catch (Exception ex) when (ex is IOException || ex is UnauthorizedAccessException)
		{
			logger.LogWarning((object)("Ingredient biome file could not be read: " + path + " (" + ex.Message + "). Biome groups are unavailable."));
			return ingredientBiomeFile;
		}
		string text = null;
		string[] array2 = array;
		for (int i = 0; i < array2.Length; i++)
		{
			string text2 = array2[i].Trim();
			if (text2.Length == 0 || text2.StartsWith("#"))
			{
				continue;
			}
			if (text2.StartsWith("[") && text2.EndsWith("]"))
			{
				text = text2.Substring(1, text2.Length - 2).Trim();
				if (text.Length == 0)
				{
					text = null;
				}
				else if (!ingredientBiomeFile.Biomes.Contains(text))
				{
					ingredientBiomeFile.Biomes.Add(text);
				}
			}
			else if (text != null && !ingredientBiomeFile._biomeByPrefab.ContainsKey(text2))
			{
				ingredientBiomeFile._biomeByPrefab.Add(text2, text);
			}
		}
		return ingredientBiomeFile;
	}
}
internal static class InputBlockPatches
{
	[HarmonyPatch(typeof(Menu), "IsVisible")]
	private static class MenuIsVisible
	{
		private static void Postfix(ref bool __result)
		{
			if (Blocking)
			{
				__result = true;
			}
		}
	}

	[HarmonyPatch(typeof(TextInput), "IsVisible")]
	private static class TextInputIsVisible
	{
		private static void Postfix(ref bool __result)
		{
			if (Blocking)
			{
				__result = true;
			}
		}
	}

	private static int _blockUntilFrame = -1;

	private static bool _open;

	public static Func<bool> ShortcutActive = () => false;

	private static bool _bypass;

	private static bool Blocking
	{
		get
		{
			if (!_bypass)
			{
				if (!_open && Time.frameCount > _blockUntilFrame)
				{
					return ShortcutActive();
				}
				return true;
			}
			return false;
		}
	}

	public static void SetOpen(bool open)
	{
		_open = open;
		if (!open)
		{
			_blockUntilFrame = Time.frameCount;
		}
	}

	public static bool Unblocked(Func<bool> check)
	{
		_bypass = true;
		try
		{
			return check();
		}
		finally
		{
			_bypass = false;
		}
	}
}
internal abstract class KnownEntry
{
	public string Key;

	public string PrefabName;

	public string DisplayName;

	public string Biome;

	public string SearchText;

	public Sprite Icon;

	public bool HasKnownUses;

	public bool Matches(string lowerQuery)
	{
		if (lowerQuery.Length != 0)
		{
			return SearchText.Contains(lowerQuery);
		}
		return true;
	}
}
internal sealed class KnownIngredient : KnownEntry
{
	public bool SharesKnowledge;
}
internal sealed class KnownStation : KnownEntry
{
}
internal sealed class LostRecipe
{
	public string Key;

	public string DisplayName;

	public Sprite Icon;

	public HashSet<string> IngredientKeys;

	public HashSet<string> StationKeys;
}
internal static class Knowledge
{
	private sealed class Unlock
	{
		public string Key;

		public Sprite Icon;

		public Requirement[] Resources;

		public CraftingStation Station;

		public Recipe Recipe;

		public Piece Piece;
	}

	public static List<KnownIngredient> CollectIngredients(Player player, IngredientBiomeFile biomes)
	{
		List<Unlock> list = AllUnlocks();
		Dictionary<string, bool> dictionary = new Dictionary<string, bool>();
		foreach (Unlock item in list)
		{
			if (!IsDiscoverable(player, item))
			{
				continue;
			}
			bool flag = player.m_knownRecipes.Contains(item.Key);
			Requirement[] resources = item.Resources;
			foreach (Requirement val in resources)
			{
				if (IsIngredient(val))
				{
					string name = val.m_resItem.m_itemData.m_shared.m_name;
					if (player.m_knownMaterial.Contains(name))
					{
						dictionary.TryGetValue(name, out var value);
						dictionary[name] = value || flag;
					}
				}
			}
		}
		Dictionary<string, KnownIngredient> dictionary2 = new Dictionary<string, KnownIngredient>(StringComparer.OrdinalIgnoreCase);
		foreach (Unlock item2 in list)
		{
			Requirement[] resources = item2.Resources;
			foreach (Requirement val2 in resources)
			{
				if (!IsIngredient(val2))
				{
					continue;
				}
				string name2 = val2.m_resItem.m_itemData.m_shared.m_name;
				if (dictionary.TryGetValue(name2, out var value2))
				{
					string name3 = ((Object)val2.m_resItem).name;
					if (!dictionary2.ContainsKey(name3))
					{
						string text = Localization.instance.Localize(name2);
						dictionary2.Add(name3, new KnownIngredient
						{
							Key = name2,
							PrefabName = name3,
							DisplayName = text,
							Biome = biomes.GetBiome(name3),
							SearchText = (text + "\n" + name2 + "\n" + name3).ToLowerInvariant(),
							Icon = val2.m_resItem.m_itemData.GetIcon(),
							HasKnownUses = value2
						});
					}
				}
			}
		}
		foreach (IGrouping<string, KnownIngredient> item3 in from knownIngredient in dictionary2.Values
			group knownIngredient by knownIngredient.Key into g
			where g.Count() > 1
			select g)
		{
			foreach (KnownIngredient item4 in item3)
			{
				item4.SharesKnowledge = true;
				item4.DisplayName = item4.DisplayName + " (" + item4.PrefabName + ")";
			}
		}
		return (from knownIngredient in dictionary2.Values
			orderby knownIngredient.DisplayName, knownIngredient.PrefabName
			select knownIngredient).ToList();
	}

	public static List<KnownStation> CollectStations(Player player, IngredientBiomeFile biomes)
	{
		Dictionary<string, KnownStation> dictionary = new Dictionary<string, KnownStation>();
		foreach (Unlock item in AllUnlocks())
		{
			if (Object.op_Implicit((Object)(object)item.Station) && IsDiscoverable(player, item))
			{
				string name = item.Station.m_name;
				bool flag = player.m_knownRecipes.Contains(item.Key);
				if (dictionary.TryGetValue(name, out var value))
				{
					value.HasKnownUses |= flag;
					continue;
				}
				string name2 = ((Object)item.Station).name;
				string text = Localization.instance.Localize(name);
				dictionary.Add(name, new KnownStation
				{
					Key = name,
					PrefabName = name2,
					DisplayName = text,
					Biome = biomes.GetBiome(name2),
					SearchText = (text + "\n" + name + "\n" + name2).ToLowerInvariant(),
					Icon = item.Station.m_icon,
					HasKnownUses = flag
				});
			}
		}
		return (from s in dictionary.Values
			orderby s.DisplayName, s.PrefabName
			select s).ToList();
	}

	public static List<LostRecipe> RecipesLostWithout(Player player, ICollection<string> ingredientKeys)
	{
		return RecipesLostWithout(player, ingredientKeys, new string[0]);
	}

	public static List<LostRecipe> RecipesLostWithout(Player player, ICollection<string> ingredientKeys, ICollection<string> stationKeys)
	{
		List<LostRecipe> list = new List<LostRecipe>();
		if (ingredientKeys.Count == 0 && stationKeys.Count == 0)
		{
			return list;
		}
		Dictionary<string, List<Unlock>> dictionary = new Dictionary<string, List<Unlock>>();
		foreach (Unlock item in AllUnlocks())
		{
			if (player.m_knownRecipes.Contains(item.Key))
			{
				if (!dictionary.TryGetValue(item.Key, out var value))
				{
					dictionary.Add(item.Key, value = new List<Unlock>());
				}
				value.Add(item);
			}
		}
		List<string> list2 = ingredientKeys.Distinct().Where(player.m_knownMaterial.Contains).ToList();
		Dictionary<string, int> dictionary2 = new Dictionary<string, int>();
		foreach (string item2 in stationKeys.Distinct())
		{
			if (player.m_knownStations.TryGetValue(item2, out var value2))
			{
				dictionary2.Add(item2, value2);
			}
		}
		Dictionary<Unlock, bool> discoverableBefore = new Dictionary<Unlock, bool>();
		foreach (List<Unlock> value3 in dictionary.Values)
		{
			foreach (Unlock item3 in value3)
			{
				discoverableBefore[item3] = IsDiscoverable(player, item3);
			}
		}
		foreach (string item4 in list2)
		{
			player.m_knownMaterial.Remove(item4);
		}
		foreach (string key in dictionary2.Keys)
		{
			player.m_knownStations.Remove(key);
		}
		try
		{
			foreach (KeyValuePair<string, List<Unlock>> item5 in dictionary)
			{
				HashSet<string> hashSet = new HashSet<string>((from q in item5.Value.SelectMany((Unlock u) => u.Resources).Where(IsIngredient)
					select q.m_resItem.m_itemData.m_shared.m_name).Where(ingredientKeys.Contains));
				HashSet<string> hashSet2 = new HashSet<string>((from u in item5.Value
					where Object.op_Implicit((Object)(object)u.Station)
					select u.Station.m_name).Where(stationKeys.Contains));
				if (hashSet.Count != 0 || hashSet2.Count != 0)
				{
					bool num = item5.Value.Any((Unlock u) => discoverableBefore[u]);
					bool flag = item5.Value.Any((Unlock u) => IsDiscoverable(player, u));
					if (num && !flag)
					{
						list.Add(new LostRecipe
						{
							Key = item5.Key,
							DisplayName = Localization.instance.Localize(item5.Key),
							Icon = item5.Value[0].Icon,
							IngredientKeys = hashSet,
							StationKeys = hashSet2
						});
					}
				}
			}
			return list;
		}
		finally
		{
			foreach (string item6 in list2)
			{
				player.m_knownMaterial.Add(item6);
			}
			foreach (KeyValuePair<string, int> item7 in dictionary2)
			{
				player.m_knownStations[item7.Key] = item7.Value;
			}
		}
	}

	public static void Forget(Player player, ICollection<string> ingredientKeys)
	{
		Forget(player, ingredientKeys, new string[0]);
	}

	public static void Forget(Player player, ICollection<string> ingredientKeys, ICollection<string> stationKeys)
	{
		List<LostRecipe> list = RecipesLostWithout(player, ingredientKeys, stationKeys);
		foreach (string item in ingredientKeys.Distinct())
		{
			player.m_knownMaterial.Remove(item);
		}
		foreach (string item2 in stationKeys.Distinct())
		{
			player.m_knownStations.Remove(item2);
		}
		foreach (LostRecipe item3 in list)
		{
			player.m_knownRecipes.Remove(item3.Key);
		}
		player.UpdateAvailablePiecesList();
		player.UpdateEvents();
	}

	public static HashSet<string> CarriedItemKeys(Player player)
	{
		return new HashSet<string>(from i in ((Humanoid)player).GetInventory().GetAllItems()
			select i.m_shared.m_name);
	}

	private static List<Unlock> AllUnlocks()
	{
		List<Unlock> list = new List<Unlock>();
		foreach (Recipe recipe in ObjectDB.instance.m_recipes)
		{
			if (Object.op_Implicit((Object)(object)recipe) && Object.op_Implicit((Object)(object)recipe.m_item) && recipe.m_resources != null)
			{
				ItemData itemData = recipe.m_item.m_itemData;
				list.Add(new Unlock
				{
					Key = itemData.m_shared.m_name,
					Icon = itemData.GetIcon(),
					Resources = recipe.m_resources,
					Station = recipe.m_craftingStation,
					Recipe = recipe
				});
			}
		}
		HashSet<Piece> hashSet = new HashSet<Piece>();
		foreach (GameObject item in ObjectDB.instance.m_items)
		{
			ItemDrop val = (Object.op_Implicit((Object)(object)item) ? item.GetComponent<ItemDrop>() : null);
			PieceTable val2 = (Object.op_Implicit((Object)(object)val) ? val.m_itemData.m_shared.m_buildPieces : null);
			if (!Object.op_Implicit((Object)(object)val2))
			{
				continue;
			}
			foreach (GameObject piece in val2.m_pieces)
			{
				Piece val3 = (Object.op_Implicit((Object)(object)piece) ? piece.GetComponent<Piece>() : null);
				if (Object.op_Implicit((Object)(object)val3) && val3.m_resources != null && hashSet.Add(val3))
				{
					list.Add(new Unlock
					{
						Key = val3.m_name,
						Icon = val3.m_icon,
						Resources = val3.m_resources,
						Station = val3.m_craftingStation,
						Piece = val3
					});
				}
			}
		}
		return list;
	}

	private static bool IsIngredient(Requirement requirement)
	{
		if (Object.op_Implicit((Object)(object)requirement.m_resItem) && requirement.m_amount > 0)
		{
			return !requirement.m_upgraderResource;
		}
		return false;
	}

	private static bool IsDiscoverable(Player player, Unlock unlock)
	{
		if (!Object.op_Implicit((Object)(object)unlock.Recipe))
		{
			return player.HaveRequirements(unlock.Piece, (RequirementMode)1);
		}
		return player.HaveRequirements(unlock.Recipe, true, 0, 1);
	}
}
internal sealed class RecipeWindow
{
	private sealed class PreviewRow
	{
		public KnownEntry Entry;

		public string Header;

		public List<LostRecipe> Recipes;
	}

	private const int WindowId = 358935;

	private const float ReferenceHeight = 1080f;

	private const float Width = 620f;

	private const float Height = 700f;

	private const float TitleGap = 18f;

	private const float IconSize = 24f;

	private const float IngredientGap = 18f;

	private readonly string _ingredientFile;

	private readonly ManualLogSource _logger;

	private IngredientBiomeFile _biomes;

	private List<KnownIngredient> _ingredients = new List<KnownIngredient>();

	private List<KnownStation> _stations = new List<KnownStation>();

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

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

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

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

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

	private bool _selectAll;

	private string _search = "";

	private Vector2 _scroll;

	private bool _confirming;

	private List<KnownIngredient> _affected = new List<KnownIngredient>();

	private List<KnownStation> _affectedStations = new List<KnownStation>();

	private List<LostRecipe> _lost = new List<LostRecipe>();

	private Vector2 _confirmScroll;

	private List<PreviewRow> _preview = new List<PreviewRow>();

	private string _carriedSummary;

	private string _inRangeSummary;

	private GUIStyle _window;

	private GUIStyle _label;

	private GUIStyle _header;

	private GUIStyle _toggle;

	private GUIStyle _headerToggle;

	private GUIStyle _button;

	private GUIStyle _textField;

	private GUIStyle _placeholder;

	private Texture2D _background;

	public bool IsOpen { get; private set; }

	public RecipeWindow(string ingredientFile, ManualLogSource logger)
	{
		_ingredientFile = ingredientFile;
		_logger = logger;
	}

	public void Open()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		_biomes = IngredientBiomeFile.Load(_ingredientFile, _logger);
		ClearSelection();
		_search = "";
		_scroll = Vector2.zero;
		_confirming = false;
		Refresh();
		IsOpen = true;
		InputBlockPatches.SetOpen(open: true);
	}

	public void Close()
	{
		IsOpen = false;
		_confirming = false;
		InputBlockPatches.SetOpen(open: false);
	}

	private void ClearSelection()
	{
		_selectedKeys.Clear();
		_selectedStationKeys.Clear();
		_selectedBiomes.Clear();
		_selectAll = false;
	}

	private void Refresh()
	{
		_ingredients = Knowledge.CollectIngredients(Player.m_localPlayer, _biomes);
		_stations = Knowledge.CollectStations(Player.m_localPlayer, _biomes);
		UpdateSelection();
	}

	private void UpdateSelection()
	{
		_biomeSelectedKeys.Clear();
		foreach (KnownIngredient ingredient in _ingredients)
		{
			if (ingredient.HasKnownUses && IsBiomeSelected(ingredient.Biome))
			{
				_biomeSelectedKeys.Add(ingredient.Key);
			}
		}
		_biomeSelectedStationKeys.Clear();
		foreach (KnownStation station in _stations)
		{
			if (station.HasKnownUses && IsBiomeSelected(station.Biome))
			{
				_biomeSelectedStationKeys.Add(station.Key);
			}
		}
		_affected = _ingredients.Where(IsSelected).ToList();
		_affectedStations = _stations.Where(IsSelected).ToList();
		_lost = Knowledge.RecipesLostWithout(Player.m_localPlayer, IngredientKeys(), StationKeys());
	}

	private List<string> IngredientKeys()
	{
		return _affected.Select((KnownIngredient i) => i.Key).Distinct().ToList();
	}

	private List<string> StationKeys()
	{
		return _affectedStations.Select((KnownStation s) => s.Key).ToList();
	}

	private bool IsSelected(KnownEntry entry)
	{
		if (entry.HasKnownUses)
		{
			if (!IsSelectedByBiome(entry))
			{
				return ManualSelection(entry).Contains(entry.Key);
			}
			return true;
		}
		return false;
	}

	private bool IsSelectedByBiome(KnownEntry entry)
	{
		if (!_selectAll)
		{
			return ((entry is KnownStation) ? _biomeSelectedStationKeys : _biomeSelectedKeys).Contains(entry.Key);
		}
		return true;
	}

	private HashSet<string> ManualSelection(KnownEntry entry)
	{
		if (!(entry is KnownStation))
		{
			return _selectedKeys;
		}
		return _selectedStationKeys;
	}

	private bool IsBiomeSelected(string biome)
	{
		if (!_selectAll)
		{
			if (biome != null)
			{
				return _selectedBiomes.Contains(biome);
			}
			return false;
		}
		return true;
	}

	public void Draw()
	{
		//IL_0014: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Invalid comparison between Unknown and I4
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Expected O, but got Unknown
		//IL_00d9: 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_0028: Invalid comparison between Unknown and I4
		if (!IsOpen)
		{
			return;
		}
		EnsureStyles();
		if ((int)Event.current.type == 4 && (int)Event.current.keyCode == 27)
		{
			Event.current.Use();
			if (!_confirming)
			{
				Close();
				return;
			}
			_confirming = false;
		}
		float num = Mathf.Max(0.5f, (float)Screen.height / 1080f);
		Matrix4x4 matrix = GUI.matrix;
		GUI.matrix = Matrix4x4.Scale(new Vector3(num, num, 1f));
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(((float)Screen.width / num - 620f) / 2f, ((float)Screen.height / num - 700f) / 2f, 620f, 700f);
		GUILayout.Window(358935, val, new WindowFunction(DrawWindow), "Wait what?", _window, Array.Empty<GUILayoutOption>());
		GUI.matrix = matrix;
	}

	private void DrawWindow(int id)
	{
		//IL_010c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ef: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f4: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(18f);
		if (_confirming)
		{
			DrawConfirm();
			return;
		}
		if (GUILayout.Toggle(_selectAll, " " + Texts.ForgetAll, _headerToggle, Array.Empty<GUILayoutOption>()) != _selectAll)
		{
			_selectAll = !_selectAll;
			UpdateSelection();
		}
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Intro, _label, Array.Empty<GUILayoutOption>());
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Biomes, _header, Array.Empty<GUILayoutOption>());
		DrawBiomes();
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Stations, _header, Array.Empty<GUILayoutOption>());
		DrawStations();
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Ingredients, _header, Array.Empty<GUILayoutOption>());
		_search = GUILayout.TextField(_search, _textField, Array.Empty<GUILayoutOption>());
		if (_search.Length == 0)
		{
			GUI.Label(GUILayoutUtility.GetLastRect(), Texts.SearchPlaceholder, _placeholder);
		}
		if (_ingredients.Any((KnownIngredient i) => i.SharesKnowledge))
		{
			GUILayout.Label(Texts.SharedIngredientKnowledge, _label, Array.Empty<GUILayoutOption>());
		}
		DrawIngredientList();
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Selection(_affected.Count, _affectedStations.Count, _lost.Count), _label, Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		GUI.enabled = _affected.Count + _affectedStations.Count > 0;
		if (GUILayout.Button(Texts.PreviewSelection, _button, Array.Empty<GUILayoutOption>()))
		{
			BuildPreview();
			_confirmScroll = Vector2.zero;
			_confirming = true;
		}
		GUI.enabled = true;
		GUILayout.FlexibleSpace();
		if (GUILayout.Button(Texts.Close, _button, Array.Empty<GUILayoutOption>()))
		{
			Close();
		}
		GUILayout.EndHorizontal();
	}

	private void DrawBiomes()
	{
		Dictionary<string, int> dictionary = (from e in _ingredients.Cast<KnownEntry>().Concat(_stations)
			where e.Biome != null && e.HasKnownUses
			group e by e.Biome).ToDictionary((IGrouping<string, KnownEntry> g) => g.Key, (IGrouping<string, KnownEntry> g) => g.Count());
		List<string> list = _biomes.Biomes.Where(dictionary.ContainsKey).ToList();
		if (list.Count == 0)
		{
			GUILayout.Label(Texts.NoBiomeIngredients, _label, Array.Empty<GUILayoutOption>());
			return;
		}
		for (int num = 0; num < list.Count; num += 3)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (string item in list.Skip(num).Take(3))
			{
				bool flag = IsBiomeSelected(item);
				GUI.enabled = !_selectAll;
				bool num2 = GUILayout.Toggle(flag, $" {Texts.Biome(item)} ({dictionary[item]})", _toggle, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(193.33333f) }) != flag;
				GUI.enabled = true;
				if (num2 && !_selectAll)
				{
					if (flag)
					{
						_selectedBiomes.Remove(item);
					}
					else
					{
						_selectedBiomes.Add(item);
					}
					UpdateSelection();
				}
			}
			GUILayout.EndHorizontal();
		}
	}

	private void DrawStations()
	{
		if (_stations.Count == 0)
		{
			GUILayout.Label(Texts.NoStations, _label, Array.Empty<GUILayoutOption>());
			return;
		}
		for (int i = 0; i < _stations.Count; i += 2)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			foreach (KnownStation item in _stations.Skip(i).Take(2))
			{
				DrawEntryToggle(item, GUILayout.Width(290f));
			}
			GUILayout.EndHorizontal();
		}
	}

	private void DrawEntryToggle(KnownEntry entry, params GUILayoutOption[] options)
	{
		bool flag = IsSelected(entry);
		bool flag2 = IsSelectedByBiome(entry) || !entry.HasKnownUses;
		GUI.enabled = !flag2;
		if (GUILayout.Toggle(flag, " " + entry.DisplayName, _toggle, options) != flag && !flag2)
		{
			if (flag)
			{
				ManualSelection(entry).Remove(entry.Key);
			}
			else
			{
				ManualSelection(entry).Add(entry.Key);
			}
			UpdateSelection();
		}
		GUI.enabled = true;
	}

	private void DrawIngredientList()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		string lowerQuery = _search.Trim().ToLowerInvariant();
		_scroll = GUILayout.BeginScrollView(_scroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
		int num = 0;
		foreach (KnownIngredient ingredient in _ingredients)
		{
			if (ingredient.Matches(lowerQuery))
			{
				num++;
				DrawEntryToggle(ingredient);
			}
		}
		if (num == 0)
		{
			GUILayout.Label((_ingredients.Count == 0) ? Texts.NoIngredients : Texts.NoMatches, _label, Array.Empty<GUILayoutOption>());
		}
		GUILayout.EndScrollView();
	}

	private void BuildPreview()
	{
		HashSet<string> carried = Knowledge.CarriedItemKeys(Player.m_localPlayer);
		HashSet<string> inRange = StationKeysInDiscoverRange(Player.m_localPlayer);
		List<KnownStation> list = _affectedStations.Where((KnownStation s) => inRange.Contains(s.Key)).ToList();
		List<KnownIngredient> list2 = _affected.Where((KnownIngredient i) => carried.Contains(i.Key)).ToList();
		_preview = list.Select((KnownStation s) => PreviewRowFor(s, relearned: true, Texts.InRange, (LostRecipe r) => r.StationKeys)).Concat(list2.Select((KnownIngredient i) => PreviewRowFor(i, relearned: true, Texts.InInventory, (LostRecipe r) => r.IngredientKeys))).Concat(from s in _affectedStations.Except(list)
			select PreviewRowFor(s, relearned: false, null, (LostRecipe r) => r.StationKeys))
			.Concat(from i in _affected.Except(list2)
				select PreviewRowFor(i, relearned: false, null, (LostRecipe r) => r.IngredientKeys))
			.ToList();
		_inRangeSummary = RelearnSummary(Texts.InRangeSummary, list);
		_carriedSummary = RelearnSummary(Texts.CarriedSummary, list2);
	}

	private PreviewRow PreviewRowFor(KnownEntry entry, bool relearned, string marker, Func<LostRecipe, HashSet<string>> keys)
	{
		string text = ((!_selectAll && entry.Biome != null && _selectedBiomes.Contains(entry.Biome)) ? (entry.DisplayName + " " + Texts.ViaBiome(Texts.Biome(entry.Biome))) : entry.DisplayName);
		return new PreviewRow
		{
			Entry = entry,
			Header = (relearned ? ("<color=#ff5a4a>" + text + "</color> " + marker) : text) + ":",
			Recipes = (from r in _lost
				where keys(r).Contains(entry.Key)
				orderby r.DisplayName
				select r).ToList()
		};
	}

	private static string RelearnSummary(string text, IEnumerable<KnownEntry> entries)
	{
		List<string> list = entries.Select((KnownEntry e) => e.DisplayName).ToList();
		if (list.Count <= 0)
		{
			return null;
		}
		return "<color=#ff5a4a>" + text + ": " + string.Join(", ", list) + "</color>";
	}

	private static HashSet<string> StationKeysInDiscoverRange(Player player)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		Vector3 position = ((Component)player).transform.position;
		return new HashSet<string>(from s in CraftingStation.m_allStations
			where Object.op_Implicit((Object)(object)s) && Vector3.Distance(((Component)s).transform.position, position) < s.m_discoverRange
			select s.m_name);
	}

	private void DrawConfirm()
	{
		//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d8: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: 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)
		GUILayout.Label(Texts.ConfirmQuestion(_affected.Count, _affectedStations.Count, _lost.Count), _header, Array.Empty<GUILayoutOption>());
		if (_affected.Any((KnownIngredient i) => i.SharesKnowledge))
		{
			GUILayout.Label(Texts.SharedIngredientKnowledge, _label, Array.Empty<GUILayoutOption>());
		}
		if (_inRangeSummary != null)
		{
			GUILayout.Label(_inRangeSummary, _header, Array.Empty<GUILayoutOption>());
		}
		if (_carriedSummary != null)
		{
			GUILayout.Label(_carriedSummary, _header, Array.Empty<GUILayoutOption>());
		}
		GUILayout.Space(8f);
		_confirmScroll = GUILayout.BeginScrollView(_confirmScroll, (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandHeight(true) });
		foreach (PreviewRow item in _preview)
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			DrawSprite(GUILayoutUtility.GetRect(24f, 24f, (GUILayoutOption[])(object)new GUILayoutOption[2]
			{
				GUILayout.Width(24f),
				GUILayout.Height(24f)
			}), item.Entry.Icon);
			GUILayout.Label(item.Header, _header, Array.Empty<GUILayoutOption>());
			GUILayout.EndHorizontal();
			if (item.Recipes.Count == 0)
			{
				GUILayout.Label(Texts.NoKnownRecipes, _label, Array.Empty<GUILayoutOption>());
			}
			foreach (LostRecipe recipe in item.Recipes)
			{
				GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
				DrawSprite(GUILayoutUtility.GetRect(24f, 24f, (GUILayoutOption[])(object)new GUILayoutOption[2]
				{
					GUILayout.Width(24f),
					GUILayout.Height(24f)
				}), recipe.Icon);
				GUILayout.Label(recipe.DisplayName, _label, Array.Empty<GUILayoutOption>());
				GUILayout.EndHorizontal();
			}
			GUILayout.Space(18f);
		}
		GUILayout.EndScrollView();
		GUILayout.Space(8f);
		GUILayout.Label(Texts.Relearn, _label, Array.Empty<GUILayoutOption>());
		GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
		if (GUILayout.Button(Texts.ForgetRecipes(_lost.Count), _button, Array.Empty<GUILayoutOption>()))
		{
			Knowledge.Forget(Player.m_localPlayer, IngredientKeys(), StationKeys());
			ClearSelection();
			_confirming = false;
			Refresh();
		}
		GUILayout.FlexibleSpace();
		if (GUILayout.Button(Texts.Back, _button, Array.Empty<GUILayoutOption>()))
		{
			_confirming = false;
		}
		GUILayout.EndHorizontal();
	}

	private static void DrawSprite(Rect rect, Sprite sprite)
	{
		//IL_001e: 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_0067: 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)
		if (Object.op_Implicit((Object)(object)sprite) && Object.op_Implicit((Object)(object)sprite.texture))
		{
			Texture2D texture = sprite.texture;
			Rect textureRect = sprite.textureRect;
			Rect val = default(Rect);
			((Rect)(ref val))..ctor(((Rect)(ref textureRect)).x / (float)((Texture)texture).width, ((Rect)(ref textureRect)).y / (float)((Texture)texture).height, ((Rect)(ref textureRect)).width / (float)((Texture)texture).width, ((Rect)(ref textureRect)).height / (float)((Texture)texture).height);
			GUI.DrawTextureWithTexCoords(rect, (Texture)(object)texture, val);
		}
	}

	private void EnsureStyles()
	{
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0084: Expected O, but got Unknown
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: 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_00e7: Expected O, but got Unknown
		//IL_00ec: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0134: Unknown result type (might be due to invalid IL or missing references)
		//IL_0146: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: 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_016d: Expected O, but got Unknown
		//IL_0178: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		//IL_018e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: 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_01a9: Expected O, but got Unknown
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ca: Unknown result type (might be due to invalid IL or missing references)
		//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Expected O, but got Unknown
		//IL_020a: Unknown result type (might be due to invalid IL or missing references)
		//IL_020b: Unknown result type (might be due to invalid IL or missing references)
		//IL_020c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: Unknown result type (might be due to invalid IL or missing references)
		//IL_0215: Unknown result type (might be due to invalid IL or missing references)
		//IL_0216: Unknown result type (might be due to invalid IL or missing references)
		//IL_021d: Unknown result type (might be due to invalid IL or missing references)
		//IL_021f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0220: Unknown result type (might be due to invalid IL or missing references)
		//IL_0227: Unknown result type (might be due to invalid IL or missing references)
		//IL_0235: Unknown result type (might be due to invalid IL or missing references)
		//IL_023a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0250: Expected O, but got Unknown
		//IL_027c: Unknown result type (might be due to invalid IL or missing references)
		//IL_027d: Unknown result type (might be due to invalid IL or missing references)
		//IL_027e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_0288: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0292: Unknown result type (might be due to invalid IL or missing references)
		//IL_0299: 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)
		//IL_02b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
		//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Expected O, but got Unknown
		//IL_02d5: Expected O, but got Unknown
		//IL_02e0: Unknown result type (might be due to invalid IL or missing references)
		//IL_02e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_02f9: Expected O, but got Unknown
		//IL_0300: Unknown result type (might be due to invalid IL or missing references)
		//IL_030a: Expected O, but got Unknown
		//IL_0326: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0332: Unknown result type (might be due to invalid IL or missing references)
		//IL_033d: Unknown result type (might be due to invalid IL or missing references)
		if (_window == null)
		{
			Color val = default(Color);
			((Color)(ref val))..ctor(0.93f, 0.87f, 0.75f);
			Color val2 = default(Color);
			((Color)(ref val2))..ctor(1f, 0.78f, 0.38f);
			Font val3 = ((IEnumerable<Font>)Resources.FindObjectsOfTypeAll<Font>()).FirstOrDefault((Func<Font, bool>)((Font f) => ((Object)f).name == "AveriaSerifLibre-Bold"));
			if (!Object.op_Implicit((Object)(object)val3))
			{
				_logger.LogInfo((object)"Valheim font AveriaSerifLibre-Bold not found, using the default font.");
			}
			_background = new Texture2D(1, 1);
			_background.SetPixel(0, 0, new Color(0.11f, 0.08f, 0.06f, 0.95f));
			_background.Apply();
			_window = new GUIStyle(GUI.skin.window)
			{
				font = val3,
				fontSize = 22,
				padding = new RectOffset(16, 16, 40, 16)
			};
			GUIStyleState normal = _window.normal;
			Texture2D background = (_window.onNormal.background = _background);
			normal.background = background;
			GUIStyleState normal2 = _window.normal;
			Color textColor = (_window.onNormal.textColor = val2);
			normal2.textColor = textColor;
			_header = new GUIStyle(GUI.skin.label)
			{
				font = val3,
				fontSize = 18,
				wordWrap = true,
				richText = true
			};
			_header.normal.textColor = val2;
			_label = new GUIStyle(GUI.skin.label)
			{
				font = val3,
				fontSize = 16,
				wordWrap = true
			};
			_label.normal.textColor = val;
			_toggle = new GUIStyle(GUI.skin.toggle)
			{
				font = val3,
				fontSize = 16
			};
			GUIStyleState normal3 = _toggle.normal;
			GUIStyleState onNormal = _toggle.onNormal;
			GUIStyleState hover = _toggle.hover;
			Color val5 = (_toggle.onHover.textColor = val);
			Color val7 = (hover.textColor = val5);
			textColor = (onNormal.textColor = val7);
			normal3.textColor = textColor;
			_headerToggle = new GUIStyle(_toggle)
			{
				fontSize = _header.fontSize
			};
			GUIStyleState normal4 = _headerToggle.normal;
			GUIStyleState onNormal2 = _headerToggle.onNormal;
			GUIStyleState hover2 = _headerToggle.hover;
			val5 = (_headerToggle.onHover.textColor = val2);
			val7 = (hover2.textColor = val5);
			textColor = (onNormal2.textColor = val7);
			normal4.textColor = textColor;
			_button = new GUIStyle(GUI.skin.button)
			{
				font = val3,
				fontSize = 16,
				padding = new RectOffset(14, 14, 6, 6)
			};
			_textField = new GUIStyle(GUI.skin.textField)
			{
				font = val3,
				fontSize = 16
			};
			_placeholder = new GUIStyle(_textField);
			_placeholder.normal.background = null;
			_placeholder.normal.textColor = new Color(val.r, val.g, val.b, 0.45f);
		}
	}
}
internal static class Texts
{
	private static bool German => Localization.instance.GetSelectedLanguage() == "German";

	public static string Intro => T("Check biomes below to forget all recipes with crafting ingredients or crafting stations from this biome, or pick single crafting stations and ingredients to forget their recipes.", "Biome unten ankreuzen, um alle Rezepte mit Zutaten oder Handwerksstationen aus diesem Biom zu vergessen, oder einzelne Handwerksstationen und Zutaten wählen, um deren Rezepte zu vergessen.");

	public static string ForgetAll => T("Forget all known recipes", "Alle bekannten Rezepte vergessen");

	public static string CarriedSummary => T("In inventory, would be instantly relearned", "Im Inventar, würde sofort neu gelernt");

	public static string InRangeSummary => T("Crafting station nearby, would be instantly relearned", "Handwerksstation in der Nähe, würde sofort neu gelernt");

	public static string Biomes => T("Forget all from biome", "Alles aus Biom vergessen");

	public static string Stations => T("Forget all with crafting station", "Alles mit Handwerksstation vergessen");

	public static string Ingredients => T("Forget all with ingredient", "Alles mit Zutat vergessen");

	public static string SearchPlaceholder => T("Search ingredients", "Zutaten suchen");

	public static string NoBiomeIngredients => T("No known ingredients assigned to a biome.", "Keine bekannten Zutaten einem Biom zugeordnet.");

	public static string NoStations => T("No known crafting stations used by discoverable recipes.", "Keine bekannten Handwerksstationen mit entdeckbaren Rezepten.");

	public static string NoIngredients => T("This character knows no ingredients.", "Dieser Charakter kennt keine Zutaten.");

	public static string NoMatches => T("No matching ingredients.", "Keine passenden Zutaten.");

	public static string PreviewSelection => T("Preview selection", "Auswahl ansehen");

	public static string Close => T("Close", "Schließen");

	public static string Back => T("Back", "Zurück");

	public static string Relearn => T("Picking up a forgotten ingredient or coming near a forgotten crafting station again discovers its recipes the normal way.", "Wird eine vergessene Zutat wieder aufgehoben oder eine vergessene Handwerksstation wieder aufgesucht, werden ihre Rezepte auf normalem Weg neu entdeckt.");

	public static string InInventory => T("(in inventory)", "(im Inventar)");

	public static string InRange => T("(nearby)", "(in der Nähe)");

	public static string NoKnownRecipes => T("(no known recipes)", "(keine bekannten Rezepte)");

	public static string SharedIngredientKnowledge => T("Items marked with their prefab names share knowledge: selecting or forgetting one also affects the others with the same game name.", "Einträge mit Prefab-Namen teilen ihr Wissen: Auswahl und Vergessen betreffen auch die anderen Einträge mit dem gleichen Spielnamen.");

	private static string T(string en, string de)
	{
		if (!German)
		{
			return en;
		}
		return de;
	}

	public static string ViaBiome(string biome)
	{
		return T("(via " + biome + ")", "(über " + biome + ")");
	}

	public static string Selection(int ingredients, int stations, int recipes)
	{
		if (stations > 0)
		{
			if (!German)
			{
				return "Selected " + Count(ingredients, "ingredient", "ingredients") + " and " + Count(stations, "crafting station", "crafting stations") + " -> forget " + Count(recipes, "known recipe", "known recipes");
			}
			return Count(ingredients, "Zutat", "Zutaten") + " und " + Count(stations, "Handwerksstation", "Handwerksstationen") + " ausgewählt -> " + Count(recipes, "bekanntes Rezept", "bekannte Rezepte") + " vergessen";
		}
		if (!German)
		{
			return "Selected " + Count(ingredients, "ingredient", "ingredients") + " -> forget " + Count(recipes, "known recipe", "known recipes") + " " + ((ingredients == 1) ? "with this ingredient" : "with these ingredients");
		}
		return Count(ingredients, "Zutat", "Zutaten") + " ausgewählt -> " + Count(recipes, "bekanntes Rezept", "bekannte Rezepte") + " " + ((ingredients == 1) ? "mit dieser Zutat vergessen" : "mit diesen Zutaten vergessen");
	}

	public static string ForgetRecipes(int recipes)
	{
		if (!German)
		{
			return "Forget " + Count(recipes, "recipe", "recipes");
		}
		return Count(recipes, "Rezept", "Rezepte") + " vergessen";
	}

	public static string ConfirmQuestion(int ingredients, int stations, int recipes)
	{
		if (stations > 0)
		{
			if (!German)
			{
				return "Forget " + Count(ingredients, "ingredient", "ingredients") + ", " + Count(stations, "crafting station", "crafting stations") + " and " + Count(recipes, "recipe", "recipes") + "?";
			}
			return Count(ingredients, "Zutat", "Zutaten") + ", " + Count(stations, "Handwerksstation", "Handwerksstationen") + " und " + Count(recipes, "Rezept", "Rezepte") + " vergessen?";
		}
		if (!German)
		{
			return "Forget " + Count(ingredients, "ingredient", "ingredients") + " and " + Count(recipes, "recipe", "recipes") + "?";
		}
		return Count(ingredients, "Zutat", "Zutaten") + " und " + Count(recipes, "Rezept", "Rezepte") + " vergessen?";
	}

	public static string Biome(string fileName)
	{
		string text = "$biome_" + fileName.Replace(" ", "").ToLowerInvariant();
		string text2 = Localization.instance.Localize(text);
		if (!text2.StartsWith("[") && !(text2 == text))
		{
			return text2;
		}
		return fileName;
	}

	private static string Count(int count, string singular, string plural)
	{
		return $"{count} {((count == 1) ? singular : plural)}";
	}
}
[BepInPlugin("de.evabs.valheim.waitwhat", "Wait What?", "1.1.0")]
public class WaitWhatPlugin : BaseUnityPlugin
{
	public const string PluginGuid = "de.evabs.valheim.waitwhat";

	public const string PluginName = "Wait What?";

	public const string PluginVersion = "1.1.0";

	private const string IngredientFileName = "WaitWhat.ingredients.txt";

	private ConfigEntry<KeyboardShortcut> _toggleKey;

	private Harmony _harmony;

	private RecipeWindow _window;

	private void Awake()
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		//IL_008b: Expected O, but got Unknown
		_toggleKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("General", "ToggleKey", new KeyboardShortcut((KeyCode)102, (KeyCode[])(object)new KeyCode[2]
		{
			(KeyCode)306,
			(KeyCode)308
		}), "Opens and closes the Wait What? window.");
		string ingredientFile = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "WaitWhat.ingredients.txt");
		_window = new RecipeWindow(ingredientFile, ((BaseUnityPlugin)this).Logger);
		InputBlockPatches.ShortcutActive = delegate
		{
			//IL_0006: 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)
			KeyboardShortcut value = _toggleKey.Value;
			return ((KeyboardShortcut)(ref value)).IsDown() || ((KeyboardShortcut)(ref value)).IsPressed() || ((KeyboardShortcut)(ref value)).IsUp();
		};
		_harmony = new Harmony("de.evabs.valheim.waitwhat");
		_harmony.PatchAll(typeof(WaitWhatPlugin).Assembly);
	}

	private void OnDestroy()
	{
		Harmony harmony = _harmony;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
	}

	private void Update()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		if (_window.IsOpen && !CanStayOpen())
		{
			_window.Close();
			return;
		}
		KeyboardShortcut value = _toggleKey.Value;
		if (((KeyboardShortcut)(ref value)).IsDown())
		{
			if (_window.IsOpen)
			{
				_window.Close();
			}
			else if (CanOpen())
			{
				_window.Open();
			}
		}
	}

	private void LateUpdate()
	{
		if (_window.IsOpen)
		{
			ZCursor.LockState = (CursorLockMode)0;
			ZCursor.Show();
		}
	}

	private void OnGUI()
	{
		_window.Draw();
	}

	private static bool CanStayOpen()
	{
		if (Object.op_Implicit((Object)(object)Player.m_localPlayer))
		{
			return !((Character)Player.m_localPlayer).IsDead();
		}
		return false;
	}

	private bool CanOpen()
	{
		if (!CanStayOpen() || !Object.op_Implicit((Object)(object)ObjectDB.instance))
		{
			return false;
		}
		if (InputBlockPatches.Unblocked(() => Menu.IsVisible() || Console.IsVisible() || TextInput.IsVisible() || Minimap.InTextInput()))
		{
			return false;
		}
		if (Object.op_Implicit((Object)(object)Chat.instance) && Chat.instance.HasFocus())
		{
			return false;
		}
		if (InventoryGui.IsVisible())
		{
			InventoryGui.instance.Hide();
		}
		if (StoreGui.IsVisible())
		{
			StoreGui.instance.Hide();
		}
		if (Object.op_Implicit((Object)(object)TextViewer.instance) && TextViewer.instance.IsVisible())
		{
			TextViewer.instance.Hide();
		}
		if (Hud.IsPieceSelectionVisible())
		{
			Hud.HidePieceSelection();
		}
		if (Minimap.IsOpen())
		{
			Minimap.instance.SetMapMode((MapMode)1);
		}
		return true;
	}
}