Decompiled source of VerticalGoodsHUD v1.0.4

VerticalGoodsHUD.dll

Decompiled a month 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 BepInEx.Configuration;
using Eremite;
using Eremite.Buildings.UI;
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;
		}
	}
	internal static class GoodsHUDClassification
	{
		private static readonly HashSet<string> RawFoodIds = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Mushrooms", "Roots", "Vegetables", "Fish", "Meat", "Eggs", "Insects", "Berries" };

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

		private static readonly List<string> CustomOrder = new List<string>
		{
			"Mushrooms", "Roots", "Vegetables", "Fish", "Meat", "Eggs", "Insects", "Berries", "Jerky", "Porridge",
			"Paste", "Skewers", "Biscuits", "Pie", "PickledGoods", "Planks", "Fabric", "Bricks", "Pipe", "Parts",
			"HearthParts", "Fertilizer", "Boots", "Coats", "Ale", "TrainingGear", "Incense", "Scrolls", "TutorialScrolls", "Wine",
			"Tea", "Clay", "Stone", "PlantFibre", "Reeds", "Algae", "Scales", "Leather", "Grain", "Herbs",
			"Resin", "Salt", "CopperOre", "Sparkdew", "Flour", "Pottery", "Barrels", "Waterskin", "Pigment", "CopperBar",
			"CrystalizedDew", "Amber", "PackofProvisions", "PackofBuildingMaterials", "PackofCrops", "PackofLuxuryGoods", "PackofTradeGoods", "AncientTablet", "Fuel Core", "_MetaArtifacts",
			"_MetaFoodStockpiles", "_MetaMachinery", "Wood", "Oil", "Sea Marrow", "Coal", "SimpleTools", "BlightFuel", "Fuel Rod"
		};

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

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

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

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

		public static IEnumerable<GoodModel> OrderGoods(IEnumerable<GoodModel> goods)
		{
			return goods.OrderBy(delegate(GoodModel g)
			{
				int num = CustomOrder.IndexOf(g.consoleId);
				return (num >= 0) ? num : int.MaxValue;
			}).ThenBy((GoodModel g) => (g.displayName != null) ? g.displayName.GetText() : ((SO)g).Name);
		}
	}
	internal static class GoodsHUDColumnFactory
	{
		public 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 AddRawComplexLabel(GoodsCategoryHUDSlot slot, RectTransform iconRT, int index)
		{
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Expected O, but got Unknown
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			if (1 == 0)
			{
			}
			string text;
			switch (index)
			{
			case 1:
			case 5:
				text = "Raw";
				break;
			case 2:
			case 6:
				text = "Com";
				break;
			default:
				text = null;
				break;
			}
			if (1 == 0)
			{
			}
			string text2 = text;
			if (text2 != 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 = text2;
				((TMP_Text)val3).fontSize = 14f;
				((Graphic)val3).color = Color.white;
				((TMP_Text)val3).alignment = (TextAlignmentOptions)514;
				((TMP_Text)val3).enableWordWrapping = 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
	{
		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 = GoodsHUDColumnFactory.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);
						GoodsHUDColumnFactory.AddRawComplexLabel(val, ((Graphic)val2).rectTransform, i);
					}
				}
			}
		}

		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 = GoodsHUDColumnFactory.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;
				}
				IEnumerable<GoodModel> goods = MB.Settings.Goods.Where((GoodModel g) => (Object)(object)g.category == (Object)(object)category && g.isOnHUD);
				goods = GoodsHUDClassification.OrderGoods(goods);
				foreach (GoodModel item in goods)
				{
					if (GameMB.StorageService.WasDiscovered(((SO)item).Name) && (value != 1 || GoodsHUDClassification.IsRawFood(item)) && (value != 2 || GoodsHUDClassification.IsComplexFood(item)) && (value != 5 || GoodsHUDClassification.IsRawCraft(item)) && (value != 6 || GoodsHUDClassification.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_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Expected O, but got Unknown
			Image val = slotGO.GetComponent<Image>() ?? slotGO.AddComponent<Image>();
			((Graphic)val).color = new Color(0f, 0f, 0f, 0f);
			((Graphic)val).raycastTarget = true;
			Button val2 = slotGO.GetComponent<Button>() ?? slotGO.AddComponent<Button>();
			((UnityEventBase)val2.onClick).RemoveAllListeners();
			((UnityEvent)val2.onClick).AddListener((UnityAction)delegate
			{
				//IL_0043: 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;

		public 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);
			VerticalGoodsHUDPlugin.RegisterGoodsHUDRoot(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);
		}
	}
	public class HUDScaler : MonoBehaviour
	{
		private const float Step = 0.05f;

		private bool showIndicator = false;

		private bool isScaling = false;

		private float currentScale = 1f;

		private static BuildingWorkersOverlay cachedOverlay;

		private static Camera cachedUICamera;

		private float MinScale => VerticalGoodsHUDPlugin.MinScaleCfg.Value;

		private float MaxScale => VerticalGoodsHUDPlugin.MaxScaleCfg.Value;

		private void Update()
		{
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: 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)
			if (Mouse.current == null)
			{
				return;
			}
			if (!Mouse.current.middleButton.isPressed)
			{
				isScaling = false;
				showIndicator = false;
			}
			else
			{
				if ((Object)(object)VerticalGoodsHUDPlugin.GoodsHUDRoot == (Object)null || (Object)(object)VerticalGoodsHUDPlugin.LeftPanel == (Object)null)
				{
					return;
				}
				if ((Object)(object)cachedOverlay == (Object)null)
				{
					cachedOverlay = Object.FindObjectOfType<BuildingWorkersOverlay>();
				}
				if (!((Object)(object)cachedOverlay != (Object)null) || !((Component)cachedOverlay).gameObject.activeInHierarchy)
				{
					if ((Object)(object)cachedUICamera == (Object)null)
					{
						Canvas componentInParent = ((Component)VerticalGoodsHUDPlugin.GoodsHUDRoot).GetComponentInParent<Canvas>();
						cachedUICamera = (((Object)(object)componentInParent != (Object)null) ? componentInParent.worldCamera : null);
					}
					Vector2 val = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).position).ReadValue();
					if (RectTransformUtility.RectangleContainsScreenPoint(VerticalGoodsHUDPlugin.LeftPanel, val, cachedUICamera))
					{
						isScaling = true;
					}
					else if (!isScaling)
					{
						showIndicator = false;
						return;
					}
					showIndicator = true;
					float x = ((InputControl<Vector2>)(object)((Pointer)Mouse.current).delta).ReadValue().x;
					float value = VerticalGoodsHUDPlugin.GoodsHUDScale.Value;
					if (!(Mathf.Abs(x) < 0.01f))
					{
						value += ((x > 0f) ? 0.05f : (-0.05f));
						value = Mathf.Clamp(value, MinScale, MaxScale);
						VerticalGoodsHUDPlugin.GoodsHUDScale.Value = value;
						currentScale = value;
						VerticalGoodsHUDPlugin.ApplyHUDScale(value);
					}
				}
			}
		}

		private void OnGUI()
		{
			//IL_001d: 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_002b: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			if (showIndicator)
			{
				GUIStyle val = new GUIStyle(GUI.skin.label)
				{
					fontSize = 18
				};
				val.normal.textColor = Color.white;
				val.alignment = (TextAnchor)4;
				GUIStyle val2 = val;
				Vector2 mousePosition = Event.current.mousePosition;
				GUI.Label(new Rect(mousePosition.x + 20f, mousePosition.y - 20f, 150f, 30f), $"Scale {currentScale:0.00}x", val2);
			}
		}
	}
	[BepInPlugin("VerticalGoodsHUD", "Vertical Goods HUD", "1.0.3")]
	public class VerticalGoodsHUDPlugin : BaseUnityPlugin
	{
		private Harmony _harmony;

		public static ConfigEntry<float> GoodsHUDScale;

		public static ConfigEntry<float> MinScaleCfg;

		public static ConfigEntry<float> MaxScaleCfg;

		public static RectTransform GoodsHUDRoot;

		public static RectTransform LeftPanel;

		private void Awake()
		{
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Expected O, but got Unknown
			GoodsHUDScale = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "VerticalGoodsHUD Scale", 1f, "Scale of the Vertical Goods HUD.");
			GoodsHUDScale.SettingChanged += delegate
			{
				if ((Object)(object)GoodsHUDRoot != (Object)null)
				{
					ApplyHUDScale(GoodsHUDScale.Value);
				}
			};
			MinScaleCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "MinScale", 0.5f, "Minimum allowed scale.");
			MaxScaleCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Scaling", "MaxScale", 2f, "Maximum allowed scale.");
			_harmony = new Harmony("VerticalGoodsHUD.Harmony");
			_harmony.PatchAll();
			((Component)this).gameObject.AddComponent<HUDScaler>();
		}

		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();
			}
		}

		public static void RegisterGoodsHUDRoot(GoodsHUD hud)
		{
			GoodsHUDRoot = ((Component)hud).GetComponent<RectTransform>();
			Transform obj = ((Transform)GoodsHUDRoot).Find("Left Panel");
			LeftPanel = ((obj != null) ? ((Component)obj).GetComponent<RectTransform>() : null);
			ApplyHUDScale(GoodsHUDScale.Value);
		}

		public static void ApplyHUDScale(float scale)
		{
			//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_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)GoodsHUDRoot == (Object)null) && !((Object)(object)LeftPanel == (Object)null))
			{
				Vector3[] array = (Vector3[])(object)new Vector3[4];
				LeftPanel.GetWorldCorners(array);
				Vector3 val = array[2];
				((Transform)GoodsHUDRoot).localScale = new Vector3(scale, scale, 1f);
				LeftPanel.GetWorldCorners(array);
				Vector3 val2 = array[2];
				RectTransform goodsHUDRoot = GoodsHUDRoot;
				((Transform)goodsHUDRoot).position = ((Transform)goodsHUDRoot).position + (val - val2);
			}
		}
	}
	[HarmonyPatch(typeof(GoodsHUD), "SetUp")]
	internal static class GoodsHUD_SetUp_RegisterRoot
	{
		private static void Postfix(GoodsHUD __instance)
		{
			VerticalGoodsHUDPlugin.RegisterGoodsHUDRoot(__instance);
		}
	}
	[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(GoodsHUDClassification.IsRawFood).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 2:
				__result = source.Where(GoodsHUDClassification.IsComplexFood).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 5:
				__result = source.Where(GoodsHUDClassification.IsRawCraft).Sum((GoodModel g) => GameMB.StorageService.GetAmount(((SO)g).Name));
				return false;
			case 6:
				__result = source.Where(GoodsHUDClassification.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)
		{
		}
	}
}