Decompiled source of VerticalGoodsHUD v1.0.0

VerticalGoodsHUD.dll

Decompiled 19 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using Eremite;
using Eremite.Model;
using Eremite.View.HUD;
using Eremite.View.Popups.Recipes;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("VerticalGoodsHUD")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Example Mod for Against The Storm")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+d6ada77561ccfe85ca4c2c807fd24c8c3fc0d51c")]
[assembly: AssemblyProduct("VerticalGoodsHUD")]
[assembly: AssemblyTitle("VerticalGoodsHUD")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace VerticalGoodsHUD
{
	internal static class GoodsHUDCategoryState
	{
		internal static GoodsCategoryHUDSlot RawFoodSlot;

		internal static GoodsCategoryHUDSlot ComplexFoodSlot;

		internal static GoodsCategoryHUDSlot RawCraftSlot;

		internal static GoodsCategoryHUDSlot ComplexCraftSlot;
	}
	[HarmonyPatch(typeof(GoodsHUD), "SetUpCategories")]
	internal static class GoodsHUD_SetUpCategories_Patch
	{
		private static readonly MethodInfo GetOrCreateMethod = typeof(GameMB).GetMethod("GetOrCreate", BindingFlags.Instance | BindingFlags.NonPublic).MakeGenericMethod(typeof(GoodsCategoryHUDSlot));

		private static bool Prefix(GoodsHUD __instance, List<GoodsCategoryHUDSlot> ___categoriesSlots)
		{
			//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c1: Expected O, but got Unknown
			GoodCategoryModel[] goodsCategories = MB.Settings.GoodsCategories;
			if (goodsCategories == null || goodsCategories.Length == 0)
			{
				return true;
			}
			List<GoodCategoryModel> list = new List<GoodCategoryModel>();
			GoodCategoryModel val = null;
			GoodCategoryModel val2 = null;
			GoodCategoryModel[] array = goodsCategories;
			foreach (GoodCategoryModel val3 in array)
			{
				if (!((Object)(object)val3 == (Object)null) && val3.showOnHUD)
				{
					string text = (((Object)(object)val3.icon != (Object)null) ? ((Object)val3.icon).name : string.Empty);
					if (text == "Icon_UI_CategoryFood" && (Object)(object)val == (Object)null)
					{
						val = val3;
						list.Add(val3);
						list.Add(val3);
					}
					else if (text == "Icon_UI_CategoryCrafting" && (Object)(object)val2 == (Object)null)
					{
						val2 = val3;
						list.Add(val3);
						list.Add(val3);
					}
					else
					{
						list.Add(val3);
					}
				}
			}
			for (int j = 1; j < ___categoriesSlots.Count; j++)
			{
				if ((Object)(object)___categoriesSlots[j] != (Object)null)
				{
					((Component)___categoriesSlots[j]).gameObject.SetActive(false);
				}
			}
			int num = 1;
			GoodsHUDCategoryState.RawFoodSlot = null;
			GoodsHUDCategoryState.ComplexFoodSlot = null;
			GoodsHUDCategoryState.RawCraftSlot = null;
			GoodsHUDCategoryState.ComplexCraftSlot = null;
			int num2 = 0;
			int num3 = 0;
			foreach (GoodCategoryModel item in list)
			{
				GoodsCategoryHUDSlot val4 = (GoodsCategoryHUDSlot)GetOrCreateMethod.Invoke(__instance, new object[2]
				{
					___categoriesSlots,
					num++
				});
				val4.SetUp(item, (Action<GoodsCategoryHUDSlot>)__instance.OnCategoryClicked, (Action)__instance.RebuildLayout);
				((Component)val4).gameObject.SetActive(true);
				string text2 = (((Object)(object)item.icon != (Object)null) ? ((Object)item.icon).name : string.Empty);
				if (text2 == "Icon_UI_CategoryFood")
				{
					switch (num2)
					{
					case 0:
						GoodsHUDCategoryState.RawFoodSlot = val4;
						break;
					case 1:
						GoodsHUDCategoryState.ComplexFoodSlot = val4;
						break;
					}
					num2++;
				}
				else if (text2 == "Icon_UI_CategoryCrafting")
				{
					switch (num3)
					{
					case 0:
						GoodsHUDCategoryState.RawCraftSlot = val4;
						break;
					case 1:
						GoodsHUDCategoryState.ComplexCraftSlot = val4;
						break;
					}
					num3++;
				}
			}
			__instance.RebuildLayout();
			return false;
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "SetUp")]
	internal static class GoodsHUD_SetUp_Patch
	{
		private static void Postfix(GoodsHUD __instance)
		{
			GoodsHUDVerticalController.Init(__instance);
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "OnCategoryClicked")]
	internal static class GoodsHUD_OnCategoryClicked_Patch
	{
		private static bool Prefix(GoodsHUD __instance, GoodsCategoryHUDSlot slot)
		{
			GoodsHUDVerticalController.ToggleCategory(slot);
			return false;
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "ShowGoods")]
	internal static class GoodsHUD_ShowGoods_Patch
	{
		private static bool Prefix(GoodsHUD __instance, List<string> goods)
		{
			GoodsHUDVerticalController.RebuildAllColumns();
			return false;
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "OnGoodDiscovered")]
	internal static class GoodsHUD_OnGoodDiscovered_Patch
	{
		private static void Postfix()
		{
			GoodsHUDVerticalController.OnGoodDiscovered();
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "OnTrackingChanged")]
	internal static class GoodsHUD_OnTrackingChanged_Patch
	{
		private static void Postfix()
		{
			GoodsHUDVerticalController.OnTrackingChanged();
		}
	}
	internal static class GoodsHUDVerticalBuilder
	{
		private static readonly HashSet<string> RawFoodIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Berries", "Eggs", "Fish", "Insects", "Meat", "Mushrooms", "Roots", "Vegetables" };

		private static readonly HashSet<string> RawCraftIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Algae", "Clay", "CopperOre", "Herbs", "Grain", "Leather", "PlantFibre", "Stone" };

		public static bool IsRawFood(GoodModel good)
		{
			return RawFoodIds.Contains(good.consoleId);
		}

		public static bool IsComplexFood(GoodModel good)
		{
			return !IsRawFood(good);
		}

		public static bool IsRawCraft(GoodModel good)
		{
			return RawCraftIds.Contains(good.consoleId);
		}

		public static bool IsComplexCraft(GoodModel good)
		{
			return !IsRawCraft(good);
		}

		private static RectTransform CreateColumn(string name, GameObject parent, RectTransform iconRT, float columnXShift, float iconToColumnGap, float verticalSpacing)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0165: Unknown result type (might be due to invalid IL or missing references)
			//IL_016a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject(name, new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent.transform, false);
			RectTransform component = val.GetComponent<RectTransform>();
			Rect rect = iconRT.rect;
			float num = ((Rect)(ref rect)).width * (iconRT.pivot.x - 0.5f);
			rect = iconRT.rect;
			Vector3 val2 = ((Transform)iconRT).TransformPoint(new Vector3(num, ((Rect)(ref rect)).height * (iconRT.pivot.y - 0.5f), 0f));
			Vector3 val3 = parent.transform.InverseTransformPoint(val2);
			component.anchorMin = new Vector2(0.5f, 1f);
			component.anchorMax = new Vector2(0.5f, 1f);
			component.pivot = new Vector2(0.5f, 1f);
			float num2 = val3.x + columnXShift;
			float y = val3.y;
			rect = iconRT.rect;
			component.anchoredPosition = new Vector2(num2, y - ((Rect)(ref rect)).height - iconToColumnGap);
			rect = iconRT.rect;
			component.SetSizeWithCurrentAnchors((Axis)0, ((Rect)(ref rect)).width);
			VerticalLayoutGroup val4 = val.AddComponent<VerticalLayoutGroup>();
			((LayoutGroup)val4).childAlignment = (TextAnchor)1;
			((HorizontalOrVerticalLayoutGroup)val4).spacing = verticalSpacing;
			((HorizontalOrVerticalLayoutGroup)val4).childControlHeight = false;
			((HorizontalOrVerticalLayoutGroup)val4).childControlWidth = false;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandHeight = false;
			((HorizontalOrVerticalLayoutGroup)val4).childForceExpandWidth = false;
			LayoutElement val5 = val.AddComponent<LayoutElement>();
			rect = iconRT.rect;
			val5.preferredWidth = ((Rect)(ref rect)).width;
			return component;
		}

		public static void BuildColumns(GameObject goodsParent, List<GoodsCategoryHUDSlot> categorySlots, Dictionary<object, RectTransform> columns, Dictionary<object, bool> columnVisible, Dictionary<object, int> slotIndices, FieldInfo iconField, float columnXShift, float iconToColumnGap, float verticalSpacing)
		{
			columns.Clear();
			columnVisible.Clear();
			slotIndices.Clear();
			for (int i = 0; i < categorySlots.Count; i++)
			{
				GoodsCategoryHUDSlot val = categorySlots[i];
				if (!(val is TrackedGoodsHUDSlot))
				{
					object? value = iconField.GetValue(val);
					Image val2 = (Image)((value is Image) ? value : null);
					if (!((Object)(object)val2 == (Object)null))
					{
						RectTransform value2 = CreateColumn($"GoodsColumn_{((Object)val).name}_{i}", goodsParent, ((Graphic)val2).rectTransform, columnXShift, iconToColumnGap, verticalSpacing);
						columns[val] = value2;
						columnVisible[val] = true;
						slotIndices[val] = i;
						GoodsHUDVerticalLayoutRuntime.RegisterSlot(val, i);
						AddRawComplexLabel(val, ((Graphic)val2).rectTransform, i);
					}
				}
			}
		}

		private static void AddRawComplexLabel(GoodsCategoryHUDSlot slot, RectTransform iconRT, int index)
		{
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Expected O, but got Unknown
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: 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_00ca: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_010b: Unknown result type (might be due to invalid IL or missing references)
			string text = null;
			if (index == 1 || index == 5)
			{
				text = "Raw";
			}
			else if (index == 2 || index == 6)
			{
				text = "Com";
			}
			if (text != null)
			{
				GameObject val = new GameObject("RC_Label", new Type[1] { typeof(RectTransform) });
				val.transform.SetParent(((Component)slot).transform, false);
				val.transform.SetSiblingIndex(((Component)iconRT).transform.GetSiblingIndex() + 1);
				RectTransform component = val.GetComponent<RectTransform>();
				Rect rect = iconRT.rect;
				Vector3 val2 = ((Transform)iconRT).TransformPoint(new Vector3(0f, ((Rect)(ref rect)).height * 0.35f, 0f));
				Vector3 localPosition = ((Component)slot).transform.InverseTransformPoint(val2);
				((Transform)component).localPosition = localPosition;
				component.sizeDelta = new Vector2(40f, 40f);
				TextMeshProUGUI val3 = val.AddComponent<TextMeshProUGUI>();
				((TMP_Text)val3).text = text;
				((TMP_Text)val3).fontSize = 14f;
				((Graphic)val3).color = Color.white;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val3).enableWordWrapping = false;
			}
		}

		public static void BuildTrackedColumn(GameObject goodsParent, List<GoodsCategoryHUDSlot> categorySlots, GoodsCategoryHUDSlot trackedSlotKey, Dictionary<object, RectTransform> columns, Dictionary<object, bool> columnVisible, FieldInfo iconField, float columnXShift, float iconToColumnGap, float verticalSpacing, out RectTransform trackedColumn)
		{
			trackedColumn = null;
			if (!((Object)(object)trackedSlotKey == (Object)null))
			{
				GoodsCategoryHUDSlot obj = categorySlots[1];
				object? value = iconField.GetValue(obj);
				Image val = (Image)((value is Image) ? value : null);
				if (!((Object)(object)val == (Object)null))
				{
					float columnXShift2 = 115f;
					trackedColumn = CreateColumn("GoodsColumn_Tracked", goodsParent, ((Graphic)val).rectTransform, columnXShift2, iconToColumnGap, verticalSpacing);
					columns[trackedSlotKey] = trackedColumn;
					columnVisible[trackedSlotKey] = true;
				}
			}
		}

		public static void BuildTrackedGoods(RectTransform trackedColumn, GoodsCategoryHUDSlot trackedSlotKey, GoodsHUDSlot templateSlot, Sprite counterSprite, float counterShiftX, float counterShiftY, float counterSize, float textShiftX)
		{
			if ((Object)(object)trackedColumn == (Object)null)
			{
				return;
			}
			foreach (string trackedGood in MB.MetaStateService.Gameplay.trackedGoods)
			{
				if (GameMB.StorageService.WasDiscovered(trackedGood))
				{
					GoodModel good = MB.Settings.GetGood(trackedGood);
					if (!((Object)(object)good == (Object)null))
					{
						GoodsHUDVerticalLayout.CreateSlot(trackedColumn, templateSlot, good, counterSprite, counterShiftX, counterShiftY, counterSize, textShiftX);
						GameObject gameObject = ((Component)((Transform)trackedColumn).GetChild(((Transform)trackedColumn).childCount - 1)).gameObject;
						AddIngredientClickHandler(gameObject, good);
					}
				}
			}
		}

		public static void BuildCategoryGoods(Dictionary<object, RectTransform> columns, Dictionary<object, bool> columnVisible, Dictionary<object, int> slotIndices, GoodsCategoryHUDSlot trackedSlotKey, GoodsHUDSlot templateSlot, Sprite counterSprite, float counterShiftX, float counterShiftY, float counterSize, float textShiftX)
		{
			foreach (KeyValuePair<object, RectTransform> column in columns)
			{
				if (column.Key == trackedSlotKey || !columnVisible[column.Key])
				{
					continue;
				}
				object key = column.Key;
				GoodsCategoryHUDSlot val = (GoodsCategoryHUDSlot)((key is GoodsCategoryHUDSlot) ? key : null);
				if ((Object)(object)val == (Object)null || !slotIndices.TryGetValue(val, out var value))
				{
					continue;
				}
				GoodCategoryModel category = val.category;
				if ((Object)(object)category == (Object)null)
				{
					continue;
				}
				List<GoodModel> list = (from g in MB.Settings.Goods
					where (Object)(object)g.category == (Object)(object)category && g.isOnHUD
					orderby (g.displayName != null) ? g.displayName.GetText() : ((SO)g).Name
					select g).ToList();
				foreach (GoodModel item in list)
				{
					if (GameMB.StorageService.WasDiscovered(((SO)item).Name) && (value != 1 || IsRawFood(item)) && (value != 2 || IsComplexFood(item)) && (value != 5 || IsRawCraft(item)) && (value != 6 || IsComplexCraft(item)))
					{
						GoodsHUDVerticalLayout.CreateSlot(column.Value, templateSlot, item, counterSprite, counterShiftX, counterShiftY, counterSize, textShiftX);
						GameObject gameObject = ((Component)((Transform)column.Value).GetChild(((Transform)column.Value).childCount - 1)).gameObject;
						AddIngredientClickHandler(gameObject, item);
					}
				}
			}
		}

		private static void AddIngredientClickHandler(GameObject slotGO, GoodModel good)
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Expected O, but got Unknown
			Image val = slotGO.GetComponent<Image>();
			if ((Object)(object)val == (Object)null)
			{
				val = slotGO.AddComponent<Image>();
			}
			((Graphic)val).color = new Color(0f, 0f, 0f, 0f);
			((Graphic)val).raycastTarget = true;
			Button val2 = slotGO.GetComponent<Button>();
			if ((Object)(object)val2 == (Object)null)
			{
				val2 = slotGO.AddComponent<Button>();
			}
			((UnityEventBase)val2.onClick).RemoveAllListeners();
			((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
			{
				//IL_0044: Unknown result type (might be due to invalid IL or missing references)
				RecipesPopup val3 = Object.FindObjectOfType<RecipesPopup>();
				if (!((Object)(object)val3 == (Object)null))
				{
					RecipesPopupRequest val4 = default(RecipesPopupRequest);
					((RecipesPopupRequest)(ref val4))..ctor(good, true);
					MethodInfo method = typeof(RecipesPopup).GetMethod("Show", BindingFlags.Instance | BindingFlags.NonPublic);
					method.Invoke(val3, new object[1] { val4 });
				}
			});
		}
	}
	internal static class GoodsHUDVerticalController
	{
		private static bool _needsRebuild;

		private static GameObject _goodsParent;

		private static List<GoodsCategoryHUDSlot> _categorySlots;

		private static GoodsHUDSlot _templateSlot;

		private static GoodsCategoryHUDSlot _trackedSlotKey;

		private static RectTransform _trackedColumn;

		private static readonly Dictionary<object, RectTransform> Columns = new Dictionary<object, RectTransform>();

		private static readonly Dictionary<object, bool> ColumnVisible = new Dictionary<object, bool>();

		private static readonly Dictionary<object, int> SlotIndices = new Dictionary<object, int>();

		private static readonly FieldInfo GoodsParentField = AccessTools.Field(typeof(GoodsHUD), "goodsParent");

		private static readonly FieldInfo GoodsSlotsField = AccessTools.Field(typeof(GoodsHUD), "goodsSlots");

		private static readonly FieldInfo CategoriesSlotsField = AccessTools.Field(typeof(GoodsHUD), "categoriesSlots");

		private static readonly FieldInfo IconField = AccessTools.Field(typeof(GoodsCategoryHUDSlot), "icon");

		private const float ColumnXShift = 165f;

		private const float IconToColumnGap = 3f;

		private const float VerticalSpacing = -12f;

		private const float CounterShiftX = 1f;

		private const float CounterShiftY = -8f;

		private const float CounterSize = 12f;

		private const float TextShiftX = 1f;

		private static Sprite BetterCounterSprite;

		private static bool NotReady => (Object)(object)_goodsParent == (Object)null || _categorySlots == null || (Object)(object)_templateSlot == (Object)null || Columns.Count == 0;

		public static void Init(GoodsHUD hud)
		{
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			_goodsParent = (GameObject)GoodsParentField.GetValue(hud);
			List<GoodsHUDSlot> list = (List<GoodsHUDSlot>)GoodsSlotsField.GetValue(hud);
			_categorySlots = (List<GoodsCategoryHUDSlot>)CategoriesSlotsField.GetValue(hud);
			if ((Object)(object)_goodsParent == (Object)null || list == null || _categorySlots == null)
			{
				return;
			}
			if (BetterCounterSprite == null)
			{
				BetterCounterSprite = ((IEnumerable<Sprite>)Resources.FindObjectsOfTypeAll<Sprite>()).FirstOrDefault((Func<Sprite, bool>)((Sprite s) => ((Object)s).name == "Popup_Gradient"));
			}
			_templateSlot = list.FirstOrDefault();
			if ((Object)(object)_templateSlot != (Object)null)
			{
				((Component)_templateSlot).gameObject.SetActive(false);
			}
			Columns.Clear();
			ColumnVisible.Clear();
			SlotIndices.Clear();
			GoodsHUDVerticalBuilder.BuildColumns(_goodsParent, _categorySlots, Columns, ColumnVisible, SlotIndices, IconField, 165f, 3f, -12f);
			_trackedSlotKey = _categorySlots[0];
			GoodsHUDVerticalBuilder.BuildTrackedColumn(_goodsParent, _categorySlots, _trackedSlotKey, Columns, ColumnVisible, IconField, 165f, 3f, -12f, out _trackedColumn);
			RebuildAllColumns();
		}

		public static void ToggleCategory(GoodsCategoryHUDSlot slot)
		{
			if (!NotReady)
			{
				object key = (((Object)(object)slot == (Object)(object)_trackedSlotKey) ? _trackedSlotKey : slot);
				if (Columns.TryGetValue(key, out var value))
				{
					bool flag = !ColumnVisible[key];
					ColumnVisible[key] = flag;
					((Component)value).gameObject.SetActive(flag);
					UpdateGoodsParentActive();
				}
			}
		}

		public static void ToggleAll()
		{
			if (NotReady)
			{
				return;
			}
			bool flag = !ColumnVisible.Values.Any((bool v) => v);
			foreach (KeyValuePair<object, RectTransform> column in Columns)
			{
				ColumnVisible[column.Key] = flag;
				((Component)column.Value).gameObject.SetActive(flag);
			}
			UpdateGoodsParentActive();
			if (flag && _needsRebuild)
			{
				_needsRebuild = false;
				RebuildAllColumns();
			}
		}

		private static void UpdateGoodsParentActive()
		{
			if (!((Object)(object)_goodsParent == (Object)null))
			{
				bool active = ColumnVisible.Values.Any((bool v) => v);
				_goodsParent.SetActive(active);
			}
		}

		public static void RebuildAllColumns()
		{
			if (NotReady)
			{
				return;
			}
			foreach (RectTransform value in Columns.Values)
			{
				for (int num = ((Transform)value).childCount - 1; num >= 0; num--)
				{
					Object.Destroy((Object)(object)((Component)((Transform)value).GetChild(num)).gameObject);
				}
			}
			GoodsHUDVerticalBuilder.BuildTrackedGoods(_trackedColumn, _trackedSlotKey, _templateSlot, BetterCounterSprite, 1f, -8f, 12f, 1f);
			GoodsHUDVerticalBuilder.BuildCategoryGoods(Columns, ColumnVisible, SlotIndices, _trackedSlotKey, _templateSlot, BetterCounterSprite, 1f, -8f, 12f, 1f);
			UpdateGoodsParentActive();
		}

		public static void OnGoodDiscovered()
		{
			if (!NotReady)
			{
				RebuildAllColumns();
			}
		}

		public static void OnTrackingChanged()
		{
			if ((Object)(object)_goodsParent != (Object)null && !_goodsParent.activeSelf)
			{
				_needsRebuild = true;
			}
			else
			{
				RebuildAllColumns();
			}
		}
	}
	internal static class GoodsHUDVerticalLayout
	{
		public static void CreateSlot(RectTransform parent, GoodsHUDSlot template, GoodModel good, Sprite counterSprite, float counterShiftX, float counterShiftY, float counterSize, float textShiftX)
		{
			//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)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0123: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0269: Unknown result type (might be due to invalid IL or missing references)
			//IL_0280: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_02f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_0305: Unknown result type (might be due to invalid IL or missing references)
			//IL_030a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0387: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = Object.Instantiate<GameObject>(((Component)template).gameObject, (Transform)(object)parent);
			val.SetActive(true);
			RectTransform component = val.GetComponent<RectTransform>();
			if ((Object)(object)component != (Object)null)
			{
				component.sizeDelta = new Vector2(component.sizeDelta.x, 44f);
				component.anchorMin = new Vector2(0.5f, 0.5f);
				component.anchorMax = new Vector2(0.5f, 0.5f);
				component.pivot = new Vector2(0.5f, 0.5f);
				component.anchoredPosition = Vector2.zero;
			}
			LayoutElement val2 = val.GetComponent<LayoutElement>() ?? val.AddComponent<LayoutElement>();
			val2.preferredHeight = 44f;
			Image val3 = ((IEnumerable<Image>)val.GetComponentsInChildren<Image>()).FirstOrDefault((Func<Image, bool>)((Image img) => ((Object)((Component)img).gameObject).name == "Icon" || (Object)(object)img.sprite != (Object)null));
			if ((Object)(object)val3 != (Object)null)
			{
				RectTransform rectTransform = ((Graphic)val3).rectTransform;
				rectTransform.anchorMin = new Vector2(0.5f, 0.5f);
				rectTransform.anchorMax = new Vector2(0.5f, 0.5f);
				rectTransform.pivot = new Vector2(0.5f, 0.5f);
				rectTransform.anchoredPosition = Vector2.zero;
				rectTransform.SetSizeWithCurrentAnchors((Axis)0, 30f);
				rectTransform.SetSizeWithCurrentAnchors((Axis)1, 30f);
				val3.preserveAspect = true;
			}
			Transform val4 = val.transform.Find("TrendMarker");
			if ((Object)(object)val4 != (Object)null)
			{
				RectTransform component2 = ((Component)val4).GetComponent<RectTransform>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.anchorMin = new Vector2(0.5f, 0.5f);
					component2.anchorMax = new Vector2(0.5f, 0.5f);
					component2.pivot = new Vector2(0.5f, 0.5f);
					component2.anchoredPosition = Vector2.zero;
				}
			}
			Transform counter = val.transform.Find("Counter");
			if ((Object)(object)counter != (Object)null)
			{
				RectTransform component3 = ((Component)counter).GetComponent<RectTransform>();
				Image component4 = ((Component)counter).GetComponent<Image>();
				if ((Object)(object)component3 != (Object)null)
				{
					component3.anchorMin = new Vector2(0.5f, 0.5f);
					component3.anchorMax = new Vector2(0.5f, 0.5f);
					component3.pivot = new Vector2(0.5f, 0.5f);
					component3.anchoredPosition = new Vector2(counterShiftX, counterShiftY);
					component3.SetSizeWithCurrentAnchors((Axis)0, counterSize);
					component3.SetSizeWithCurrentAnchors((Axis)1, counterSize);
					RectTransform val5 = ((IEnumerable<RectTransform>)((Component)counter).GetComponentsInChildren<RectTransform>()).FirstOrDefault((Func<RectTransform, bool>)((RectTransform rt) => (Object)(object)((Component)rt).gameObject != (Object)(object)((Component)counter).gameObject));
					if ((Object)(object)val5 != (Object)null)
					{
						val5.anchoredPosition += new Vector2(textShiftX, 0f);
						TextMeshProUGUI component5 = ((Component)val5).GetComponent<TextMeshProUGUI>();
						if ((Object)(object)component5 != (Object)null)
						{
							((TMP_Text)component5).alignment = (TextAlignmentOptions)4100;
						}
					}
				}
				if ((Object)(object)component4 != (Object)null && (Object)(object)counterSprite != (Object)null)
				{
					component4.sprite = counterSprite;
					component4.type = (Type)1;
					component4.preserveAspect = false;
					((Graphic)component4).color = new Color(0f, 0f, 0f, 1f);
				}
			}
			GoodsHUDSlot component6 = val.GetComponent<GoodsHUDSlot>();
			component6.SetUp(good);
			Object.Destroy((Object)(object)component6);
		}
	}
	[BepInPlugin("VerticalGoodsHUD", "Vertical Goods HUD", "1.0.0")]
	public class VerticalGoodsHUDPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		private void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			_harmony = new Harmony("VerticalGoodsHUD.Harmony");
			_harmony.PatchAll();
		}

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

		private void Update()
		{
			if (Keyboard.current != null && ((ButtonControl)Keyboard.current.semicolonKey).wasPressedThisFrame)
			{
				GoodsHUDVerticalController.ToggleAll();
			}
		}
	}
	[HarmonyPatch(typeof(GoodsCategoryHUDSlot), "SumTrackedGoods")]
	internal static class CategoryTotalsPatch
	{
		private static bool Prefix(GoodsCategoryHUDSlot __instance, ref int __result)
		{
			if (!GoodsHUDVerticalLayoutRuntime.TryGetSlotIndex(__instance, out var index))
			{
				return true;
			}
			IEnumerable<GoodModel> source = from name in __instance.GetGoodsToShow()
				select MB.Settings.GetGood(name) into g
				where (Object)(object)g != (Object)null
				select g;
			switch (index)
			{
			case 1:
				__result = source.Where(GoodsHUDVerticalBuilder.IsRawFood).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 2:
				__result = source.Where(GoodsHUDVerticalBuilder.IsComplexFood).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 5:
				__result = source.Where(GoodsHUDVerticalBuilder.IsRawCraft).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 6:
				__result = source.Where(GoodsHUDVerticalBuilder.IsComplexCraft).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			default:
				return true;
			}
		}
	}
	internal static class GoodsHUDVerticalLayoutRuntime
	{
		private static readonly Dictionary<GoodsCategoryHUDSlot, int> slotIndexMap = new Dictionary<GoodsCategoryHUDSlot, int>();

		public static void RegisterSlot(GoodsCategoryHUDSlot slot, int index)
		{
			slotIndexMap[slot] = index;
		}

		public static bool TryGetSlotIndex(GoodsCategoryHUDSlot slot, out int index)
		{
			return slotIndexMap.TryGetValue(slot, out index);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "VerticalGoodsHUD";

		public const string PLUGIN_NAME = "VerticalGoodsHUD";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}