Decompiled source of Wayfarer v1.0.6

Wayfarer.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn.Managers;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Wayfarer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.4.0")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("Wayfarer")]
[assembly: AssemblyTitle("Wayfarer")]
[assembly: AssemblyVersion("1.0.4.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace Wayfarer
{
	internal sealed class ConfigPanel : IDisposable
	{
		private readonly Plugin plugin;

		private GameObject root;

		private Text rowValue;

		private Text weightValue;

		private Text rangeValue;

		private Text clockFontValue;

		private Text clockIntervalValue;

		private Text conflictLine;

		private Text warning;

		private Button fogButton;

		private Button grassButton;

		private Button damageButton;

		private readonly Button[] toggles = (Button[])(object)new Button[14];

		private Button fewerRows;

		private Button moreRows;

		private static readonly string[] SectionNames = new string[4] { "HUD", "Jogabilidade", "Inventário", "Visual" };

		private const float PanelWidth = 730f;

		private const float PanelHeight = 620f;

		private const float ContentTop = 110f;

		private readonly GameObject[] sectionRoots = (GameObject[])(object)new GameObject[4];

		private readonly Button[] navButtons = (Button[])(object)new Button[4];

		private int section;

		private bool blocked;

		private bool closePending;

		private static readonly Dictionary<int, Sprite> cardSprites = new Dictionary<int, Sprite>();

		internal bool IsOpen
		{
			get
			{
				if ((Object)(object)root != (Object)null)
				{
					return root.activeSelf;
				}
				return false;
			}
		}

		private ConfigEntry<bool>[] Entries => new ConfigEntry<bool>[14]
		{
			plugin.Settings.InstantLoot,
			plugin.Settings.AutoRepair,
			plugin.Settings.ExpandInventory,
			plugin.Settings.IncreaseWeight,
			plugin.Settings.ExtraSlots,
			plugin.Settings.OrganizeInventory,
			plugin.Settings.ClockEnabled,
			plugin.Settings.ShowLocalTime,
			plugin.Settings.Clock24h,
			plugin.Settings.QuickStore,
			plugin.Settings.ShowTimers,
			plugin.Settings.MiningWide,
			plugin.Settings.MiningDurability,
			plugin.Settings.CustomHud
		};

		internal ConfigPanel(Plugin plugin)
		{
			this.plugin = plugin;
		}

		internal static bool Busy()
		{
			if (!InventoryGui.IsVisible())
			{
				return BusyExceptInventory();
			}
			return true;
		}

		internal static bool BusyExceptInventory()
		{
			if (!Minimap.IsOpen() && !Console.IsVisible() && !Menu.IsVisible() && !TextInput.IsVisible() && !StoreGui.IsVisible())
			{
				if ((Object)(object)Chat.instance != (Object)null)
				{
					return Chat.instance.HasFocus();
				}
				return false;
			}
			return true;
		}

		private static string FogLabel(FogMode mode)
		{
			return mode switch
			{
				FogMode.Reduzida => "Suave", 
				FogMode.Desativada => "Limpo", 
				_ => "Original", 
			};
		}

		private static string GrassLabel(GrassMode mode)
		{
			return mode switch
			{
				GrassMode.Reduzida => "Suave", 
				GrassMode.Desativada => "Limpo", 
				_ => "Original", 
			};
		}

		private bool Conflict(int index)
		{
			switch (index)
			{
			case 2:
			case 4:
			case 5:
			case 9:
				return plugin.InventoryConflict;
			default:
				return false;
			case 0:
				return plugin.LootConflict;
			}
		}

		private void Ensure()
		{
			//IL_002c: 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_0036: 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_00c6: Expected O, but got Unknown
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0154: Expected O, but got Unknown
			//IL_021a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0224: Expected O, but got Unknown
			if ((Object)(object)root != (Object)null || (Object)(object)GUIManager.CustomGUIFront == (Object)null)
			{
				return;
			}
			root = GUIManager.Instance.CreateWoodpanel(GUIManager.CustomGUIFront.transform, Widgets.Center, Widgets.Center, Vector2.zero, 730f, 620f, false);
			((Object)root).name = "Wayfarer.Config";
			Widgets.Text(root.transform, "WAYFARER", 0f, 17f, 730f, 40f, 30).alignment = (TextAnchor)4;
			Widgets.Button(root.transform, "×", 661f, 21f, 40f, 34f, (UnityAction)delegate
			{
				closePending = true;
			});
			conflictLine = Widgets.Text(root.transform, "", 30f, 44f, 640f, 18f, 13);
			for (int num = 0; num < SectionNames.Length; num++)
			{
				int index = num;
				navButtons[num] = Widgets.Button(root.transform, SectionNames[num], 24 + num * 173, 66f, 164f, 32f, (UnityAction)delegate
				{
					SelectSection(index);
				});
			}
			BuildHud(BeginSection(0));
			BuildGameplay(BeginSection(1));
			BuildInventory(BeginSection(2));
			BuildVisual(BeginSection(3));
			Widgets.Text(root.transform, "F7 / Esc: fechar · Guardar: K · Comidas: Z/X/C · Poções: Num 1–3 · Munições: Num 4–6", 30f, 544f, 670f, 20f, 14);
			Widgets.Text(root.transform, "✓ Alterações salvas automaticamente", 30f, 570f, 440f, 35f, 12);
			Widgets.Button(root.transform, "Fechar", 541f, 570f, 160f, 35f, (UnityAction)delegate
			{
				closePending = true;
			});
			root.SetActive(false);
		}

		private Transform BeginSection(int index)
		{
			RectTransform val = Widgets.Rect("Section" + SectionNames[index], root.transform, 0f, 0f, 730f, 620f);
			sectionRoots[index] = ((Component)val).gameObject;
			((Component)val).gameObject.SetActive(index == section);
			return (Transform)(object)val;
		}

		private void SelectSection(int index)
		{
			section = index;
			for (int i = 0; i < sectionRoots.Length; i++)
			{
				if ((Object)(object)sectionRoots[i] != (Object)null)
				{
					sectionRoots[i].SetActive(i == section);
				}
			}
			RefreshNav();
		}

		private void RefreshNav()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: 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)
			for (int i = 0; i < navButtons.Length; i++)
			{
				if (!((Object)(object)navButtons[i] == (Object)null))
				{
					Widgets.Label(navButtons[i], SectionNames[i]);
					Color color = ((i == section) ? GUIManager.Instance.ValheimOrange : GUIManager.Instance.ValheimBeige);
					Text componentInChildren = ((Component)navButtons[i]).GetComponentInChildren<Text>();
					if ((Object)(object)componentInChildren != (Object)null)
					{
						((Graphic)componentInChildren).color = color;
					}
					TMP_Text componentInChildren2 = ((Component)navButtons[i]).GetComponentInChildren<TMP_Text>();
					if ((Object)(object)componentInChildren2 != (Object)null)
					{
						((Graphic)componentInChildren2).color = color;
					}
				}
			}
		}

		private void BuildHud(Transform parent)
		{
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Expected O, but got Unknown
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0118: Expected O, but got Unknown
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Expected O, but got Unknown
			//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			float num = 110f;
			float num2 = num;
			num = Section(parent, num, "HUD");
			num = BoolRow(parent, 6, "Relógio", "Dia atual e horário do jogo abaixo do minimapa.", num);
			num = BoolRow(parent, 7, "Hora local", "Horário do computador abaixo do jogo.", num);
			num = BoolRow(parent, 8, "Formato 24h", "Desativado usa 12h com AM/PM.", num);
			num = BoolRow(parent, 10, "Temporizadores", "Tempo restante ao olhar para processos.", num);
			num = BoolRow(parent, 13, "HUD Personalizada", "Reorganiza vida, vigor, comidas, buffs, hotbar e notificações.", num);
			Widgets.Text(parent, "Fonte", 50f, num, 120f, 30f, 17);
			Widgets.Button(parent, "−", 175f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeClockFont(-1);
			});
			clockFontValue = Widgets.Text(parent, "", 211f, num, 150f, 30f, 16);
			clockFontValue.alignment = (TextAnchor)4;
			Widgets.Button(parent, "+", 365f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeClockFont(1);
			});
			num += 32f;
			Widgets.Text(parent, "Atualização", 50f, num, 120f, 30f, 17);
			Widgets.Button(parent, "−", 175f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeClockInterval(-0.25f);
			});
			clockIntervalValue = Widgets.Text(parent, "", 211f, num, 150f, 30f, 16);
			clockIntervalValue.alignment = (TextAnchor)4;
			Widgets.Button(parent, "+", 365f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeClockInterval(0.25f);
			});
			num += 32f;
			Card(parent, num2 - 6f, num + 8f);
		}

		private void BuildGameplay(Transform parent)
		{
			float num = 110f;
			float num2 = num;
			num = Section(parent, num, "JOGABILIDADE");
			num = BoolRow(parent, 0, "Loot instantâneo", "Loot liberado na morte, sem esperar o corpo.", num);
			num = BoolRow(parent, 1, "Reparo automático", "Repara tudo ao abrir a bancada.", num);
			num = BoolRow(parent, 11, "Mineração Ampliada", "Picareta atinge as demais partes da mesma formação.", num);
			damageButton = TriRow(parent, num, "Dano ampliado", "Fração do dano nas demais partes.", MiningDamageLabel(plugin.Settings.MiningDamage.Value), delegate
			{
				CycleMiningDamage();
			});
			num += 48f;
			num = BoolRow(parent, 12, "Gastar durabilidade", "Partes extras também gastam durabilidade.", num);
			Card(parent, num2 - 6f, num + 8f);
		}

		private void BuildInventory(Transform parent)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Expected O, but got Unknown
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cc: Expected O, but got Unknown
			//IL_0128: Unknown result type (might be due to invalid IL or missing references)
			//IL_0132: Expected O, but got Unknown
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0189: Expected O, but got Unknown
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Expected O, but got Unknown
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Expected O, but got Unknown
			float num = 110f;
			float num2 = num;
			num = Section(parent, num, "INVENTÁRIO");
			num = BoolRow(parent, 2, "Expandir inventário", "Mais linhas de 8 espaços.", num);
			Widgets.Text(parent, "Linhas", 50f, num, 120f, 30f, 17);
			fewerRows = Widgets.Button(parent, "−", 175f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeRows(-1);
			});
			rowValue = Widgets.Text(parent, "", 211f, num, 150f, 30f, 16);
			rowValue.alignment = (TextAnchor)4;
			moreRows = Widgets.Button(parent, "+", 365f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeRows(1);
			});
			num += 32f;
			num = BoolRow(parent, 3, "Aumentar peso máximo", "Peso base ajustável; bônus continuam.", num);
			Widgets.Text(parent, "Peso base", 50f, num, 120f, 30f, 17);
			Widgets.Button(parent, "−", 175f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeWeight(-50f);
			});
			weightValue = Widgets.Text(parent, "", 211f, num, 150f, 30f, 16);
			weightValue.alignment = (TextAnchor)4;
			Widgets.Button(parent, "+", 365f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeWeight(50f);
			});
			num += 32f;
			num = BoolRow(parent, 4, "Slots extras", "6 equipamentos + 3 comidas + 3 poções + 3 munições.", num);
			warning = Widgets.Text(parent, "", 30f, num + 2f, 660f, 34f, 12);
			num += 38f;
			num = BoolRow(parent, 5, "Organizar inventário", "Botão Organizar abaixo do peso.", num);
			num = BoolRow(parent, 9, "Guardar rápido", "Guarda itens iguais nos baús próximos (tecla).", num);
			Widgets.Text(parent, "Alcance", 50f, num, 120f, 30f, 17);
			Widgets.Button(parent, "−", 175f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeRange(-5f);
			});
			rangeValue = Widgets.Text(parent, "", 211f, num, 150f, 30f, 16);
			rangeValue.alignment = (TextAnchor)4;
			Widgets.Button(parent, "+", 365f, num, 32f, 30f, (UnityAction)delegate
			{
				ChangeRange(5f);
			});
			num += 32f;
			Card(parent, num2 - 6f, num + 8f);
		}

		private void BuildVisual(Transform parent)
		{
			float num = 110f;
			float num2 = num;
			num = Section(parent, num, "VISUAL");
			fogButton = TriRow(parent, num, "Névoa", "Densidade da névoa do ambiente.", FogLabel(plugin.Settings.Fog.Value), delegate
			{
				CycleFog();
			});
			num += 48f;
			grassButton = TriRow(parent, num, "Grama", "Quantidade de grama no ambiente.", GrassLabel(plugin.Settings.Grass.Value), delegate
			{
				CycleGrass();
			});
			num += 48f;
			Card(parent, num2 - 6f, num + 8f);
		}

		private static float RoundedAlpha(float x, float y, float w, float h, float r)
		{
			float num = Mathf.Max(Mathf.Abs(x - (w - 1f) / 2f) - ((w - 1f) / 2f - r), 0f);
			float num2 = Mathf.Max(Mathf.Abs(y - (h - 1f) / 2f) - ((h - 1f) / 2f - r), 0f);
			return Mathf.Clamp01(r - Mathf.Sqrt(num * num + num2 * num2) + 0.5f);
		}

		private void Card(Transform parent, float top, float bottom)
		{
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			//IL_01e5: 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)
			//IL_007d: 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_0110: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: 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_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0162: Unknown result type (might be due to invalid IL or missing references)
			//IL_016c: Unknown result type (might be due to invalid IL or missing references)
			int num = Mathf.RoundToInt(bottom - top);
			if (!cardSprites.TryGetValue(num, out var value))
			{
				Texture2D val = new Texture2D(702, num, (TextureFormat)5, false);
				((Texture)val).wrapMode = (TextureWrapMode)1;
				((Texture)val).filterMode = (FilterMode)1;
				Color val2 = default(Color);
				((Color)(ref val2))..ctor(0.82f, 0.75f, 0.6f, 0.13f);
				Color val3 = default(Color);
				((Color)(ref val3))..ctor(0.055f, 0.045f, 0.035f, 0.55f);
				for (int i = 0; i < 702; i++)
				{
					for (int j = 0; j < num; j++)
					{
						float num2 = val2.a * RoundedAlpha(i, j, 702f, num, 8f) * (1f - RoundedAlpha((float)i - 1f, (float)j - 1f, 700f, (float)num - 2f, 7f));
						float num3 = val3.a * RoundedAlpha((float)i - 1f, (float)j - 1f, 700f, (float)num - 2f, 7f);
						float num4 = num3 + num2 * (1f - num3);
						Color clear = Color.clear;
						if (num4 > 0.001f)
						{
							((Color)(ref clear))..ctor((val3.r * num3 + val2.r * num2 * (1f - num3)) / num4, (val3.g * num3 + val2.g * num2 * (1f - num3)) / num4, (val3.b * num3 + val2.b * num2 * (1f - num3)) / num4);
						}
						val.SetPixel(i, j, new Color(clear.r, clear.g, clear.b, num4));
					}
				}
				val.Apply();
				value = Sprite.Create(val, new Rect(0f, 0f, 702f, (float)num), new Vector2(0.5f, 0.5f), 1f, 0u, (SpriteMeshType)0);
				((Object)value).name = "Wayfarer.Card" + num;
				cardSprites[num] = value;
			}
			RectTransform obj = Widgets.Rect("Card", parent, 14f, top, 702f, num);
			Image obj2 = ((Component)obj).gameObject.AddComponent<Image>();
			obj2.sprite = value;
			obj2.type = (Type)0;
			((Graphic)obj2).raycastTarget = false;
			((Transform)obj).SetAsFirstSibling();
		}

		private float Section(Transform parent, float y, string title)
		{
			Widgets.Text(parent, title, 14f, y, 702f, 26f, 20).alignment = (TextAnchor)4;
			return y + 32f;
		}

		private float BoolRow(Transform parent, int index, string title, string desc, float y)
		{
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Expected O, but got Unknown
			Widgets.Text(parent, title, 30f, y, 510f, 24f);
			Widgets.Text(parent, desc, 30f, y + 23f, 522f, 22f, 14);
			toggles[index] = Widgets.Button(parent, "", 565f, y + 4f, 136f, 34f, (UnityAction)delegate
			{
				Toggle(index);
			});
			return y + 48f;
		}

		private Button TriRow(Transform parent, float y, string title, string desc, string value, Action onCycle)
		{
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			Widgets.Text(parent, title, 30f, y, 510f, 24f);
			Widgets.Text(parent, desc, 30f, y + 23f, 522f, 22f, 14);
			return Widgets.Button(parent, "‹ " + value + " ›", 565f, y + 4f, 136f, 34f, (UnityAction)delegate
			{
				onCycle();
			});
		}

		internal void Tick()
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			if (!Application.isFocused || ((Object)(object)Player.m_localPlayer != (Object)null && ((Character)Player.m_localPlayer).IsDead()))
			{
				if (IsOpen || blocked)
				{
					closePending = true;
				}
				return;
			}
			KeyboardShortcut value = plugin.Settings.MenuKey.Value;
			if (((KeyboardShortcut)(ref value)).IsDown())
			{
				if (IsOpen)
				{
					closePending = true;
				}
				else
				{
					Open();
				}
			}
			if (IsOpen && Input.GetKeyDown((KeyCode)27))
			{
				closePending = true;
			}
			if (IsOpen)
			{
				if ((Object)(object)GUIManager.CustomGUIFront == (Object)null)
				{
					closePending = true;
				}
				else
				{
					Fit();
				}
			}
		}

		private void Open()
		{
			if (Console.IsVisible() || Menu.IsVisible() || TextInput.IsVisible() || ((Object)(object)Chat.instance != (Object)null && Chat.instance.HasFocus()))
			{
				return;
			}
			if (InventoryGui.IsVisible())
			{
				if (InventoryFeatures.DragItem() != null)
				{
					Player localPlayer = Player.m_localPlayer;
					if (localPlayer != null)
					{
						((Character)localPlayer).Message((MessageType)2, "Solte o item do cursor antes de abrir o menu.", 0, (Sprite)null, false);
					}
					return;
				}
				InventoryGui.instance.Hide();
			}
			if (Minimap.IsOpen() || StoreGui.IsVisible())
			{
				return;
			}
			Ensure();
			if (!((Object)(object)root == (Object)null))
			{
				SelectSection(0);
				root.SetActive(true);
				root.transform.SetAsLastSibling();
				Fit();
				Refresh();
				if (!blocked)
				{
					GUIManager.BlockInput(true);
					blocked = true;
				}
			}
		}

		private void Fit()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			Transform parent = root.transform.parent;
			RectTransform val = (RectTransform)(object)((parent is RectTransform) ? parent : null);
			float num2;
			if (!((Object)(object)val == (Object)null))
			{
				Rect rect = val.rect;
				float num = ((Rect)(ref rect)).width / 770f;
				rect = val.rect;
				num2 = Mathf.Min(num, ((Rect)(ref rect)).height / 660f);
			}
			else
			{
				num2 = 1f;
			}
			float num3 = num2;
			root.transform.localScale = Vector3.one * Mathf.Min(plugin.Settings.PanelScale.Value, num3);
		}

		private void Refresh(string message = null)
		{
			if (!((Object)(object)root == (Object)null))
			{
				RefreshNav();
				ConfigEntry<bool>[] entries = Entries;
				for (int i = 0; i < 14; i++)
				{
					((Selectable)toggles[i]).interactable = !Conflict(i);
					bool flag = i == 4 && !Conflict(i) && (Object)(object)InventoryFeatures.Owner == (Object)(object)Player.m_localPlayer && (Object)(object)Player.m_localPlayer != (Object)null && InventoryFeatures.Extra && !entries[i].Value;
					Widgets.Label(toggles[i], Conflict(i) ? "Outro mod" : (flag ? "Em uso" : (entries[i].Value ? "Ativado" : "Desativado")));
				}
				Widgets.Label(fogButton, "‹ " + FogLabel(plugin.Settings.Fog.Value) + " ›");
				Widgets.Label(grassButton, "‹ " + GrassLabel(plugin.Settings.Grass.Value) + " ›");
				Widgets.Label(damageButton, "‹ " + MiningDamageLabel(plugin.Settings.MiningDamage.Value) + " ›");
				Button obj = fewerRows;
				bool interactable = (((Selectable)moreRows).interactable = !plugin.InventoryConflict);
				((Selectable)obj).interactable = interactable;
				rowValue.text = plugin.Settings.Rows.Value + " linhas · " + plugin.Settings.Rows.Value * 8 + " slots";
				weightValue.text = plugin.Settings.CarryWeight.Value.ToString("0") + " kg";
				rangeValue.text = plugin.Settings.QuickStoreRange.Value.ToString("0") + " m";
				clockFontValue.text = plugin.Settings.ClockFontSize.Value + " px";
				clockIntervalValue.text = plugin.Settings.ClockInterval.Value.ToString("0.00") + " s";
				warning.text = message ?? ((InventoryFeatures.Notice.Length > 0) ? InventoryFeatures.Notice : "Os itens precisam caber no inventário ao reduzir ou desativar slots.");
				((Component)conflictLine).gameObject.SetActive(plugin.Conflicts.Length > 0);
				if (plugin.Conflicts.Length > 0)
				{
					conflictLine.text = "Outro mod controla: " + plugin.Conflicts + ". Desative o correspondente no r2modman e reinicie para usar esta função aqui.";
				}
			}
		}

		private void Toggle(int index)
		{
			if (Conflict(index))
			{
				return;
			}
			ConfigEntry<bool> val = Entries[index];
			bool flag = !val.Value;
			if (index == 2 || index == 4)
			{
				Settings settings = plugin.Settings;
				bool num = ((index == 2) ? flag : settings.ExpandInventory.Value);
				if (!InventoryFeatures.TryResize(extra: (index == 4) ? flag : settings.ExtraSlots.Value, rows: num ? Math.Max(settings.Rows.Value, InventoryFeatures.NativeRows(Player.m_localPlayer)) : InventoryFeatures.NativeRows(Player.m_localPlayer), reason: out var reason))
				{
					Refresh(reason);
					return;
				}
			}
			val.Value = flag;
			((BaseUnityPlugin)plugin).Config.Save();
			Refresh();
		}

		private static string MiningDamageLabel(float value)
		{
			if (!(value >= 1f))
			{
				if (!(value >= 0.5f))
				{
					return "25%";
				}
				return "50%";
			}
			return "100%";
		}

		private void CycleMiningDamage()
		{
			ConfigEntry<float> miningDamage = plugin.Settings.MiningDamage;
			float[] array = new float[3] { 1f, 0.5f, 0.25f };
			miningDamage.Value = array[(Array.IndexOf(array, miningDamage.Value) + 1) % array.Length];
			((BaseUnityPlugin)plugin).Config.Save();
			Refresh();
		}

		private void CycleFog()
		{
			ConfigEntry<FogMode> fog = plugin.Settings.Fog;
			fog.Value = (FogMode)((int)(fog.Value + 1) % 3);
			((BaseUnityPlugin)plugin).Config.Save();
			VisualFeatures.ApplyFog();
			Refresh();
		}

		private void CycleGrass()
		{
			ConfigEntry<GrassMode> grass = plugin.Settings.Grass;
			grass.Value = (GrassMode)((int)(grass.Value + 1) % 3);
			((BaseUnityPlugin)plugin).Config.Save();
			VisualFeatures.ApplyGrass();
			Refresh();
		}

		private void ChangeRows(int delta)
		{
			if (!plugin.InventoryConflict)
			{
				int num = Mathf.Clamp(plugin.Settings.Rows.Value + delta, 4, 9);
				if (plugin.Settings.ExpandInventory.Value && !InventoryFeatures.TryResize(Math.Max(num, InventoryFeatures.NativeRows(Player.m_localPlayer)), plugin.Settings.ExtraSlots.Value, out var reason))
				{
					Refresh(reason);
					return;
				}
				plugin.Settings.Rows.Value = num;
				((BaseUnityPlugin)plugin).Config.Save();
				Refresh();
			}
		}

		private void ChangeWeight(float delta)
		{
			plugin.Settings.CarryWeight.Value = Mathf.Clamp(plugin.Settings.CarryWeight.Value + delta, 300f, 3000f);
			((BaseUnityPlugin)plugin).Config.Save();
			Refresh();
		}

		private void ChangeRange(float delta)
		{
			if (!plugin.InventoryConflict)
			{
				plugin.Settings.QuickStoreRange.Value = Mathf.Clamp(plugin.Settings.QuickStoreRange.Value + delta, 5f, 50f);
				((BaseUnityPlugin)plugin).Config.Save();
				Refresh();
			}
		}

		private void ChangeClockFont(int delta)
		{
			plugin.Settings.ClockFontSize.Value = Mathf.Clamp(plugin.Settings.ClockFontSize.Value + delta, 10, 32);
			((BaseUnityPlugin)plugin).Config.Save();
			Refresh();
		}

		private void ChangeClockInterval(float delta)
		{
			plugin.Settings.ClockInterval.Value = Mathf.Clamp(plugin.Settings.ClockInterval.Value + delta, 0.25f, 5f);
			((BaseUnityPlugin)plugin).Config.Save();
			Refresh();
		}

		internal void LateTick()
		{
			if (closePending || (!((Object)(object)root != (Object)null) && blocked))
			{
				closePending = false;
				Close();
			}
		}

		private void Close()
		{
			if ((Object)(object)root != (Object)null)
			{
				if ((Object)(object)EventSystem.current != (Object)null && (Object)(object)EventSystem.current.currentSelectedGameObject != (Object)null && EventSystem.current.currentSelectedGameObject.transform.IsChildOf(root.transform))
				{
					EventSystem.current.SetSelectedGameObject((GameObject)null);
				}
				root.SetActive(false);
			}
			if (blocked)
			{
				GUIManager.BlockInput(false);
				blocked = false;
			}
		}

		public void Dispose()
		{
			Close();
			if ((Object)(object)root != (Object)null)
			{
				Object.Destroy((Object)(object)root);
			}
			foreach (Sprite value in cardSprites.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					if ((Object)(object)value.texture != (Object)null)
					{
						Object.Destroy((Object)(object)value.texture);
					}
					Object.Destroy((Object)(object)value);
				}
			}
			cardSprites.Clear();
		}
	}
	internal sealed class CustomHud : IDisposable
	{
		private sealed class Snap
		{
			internal Vector2 Min;

			internal Vector2 Max;

			internal Vector2 Pivot;

			internal Vector2 Pos;

			internal Vector2 Size;

			internal Vector2 OffMin;

			internal Vector2 OffMax;

			internal Vector3 Scale;

			internal Vector3 Euler;
		}

		private sealed class Member
		{
			internal RectTransform Rect;

			internal Transform Parent;

			internal int Sibling;

			internal Snap Snap;
		}

		private sealed class RotSnap
		{
			internal RectTransform Rect;

			internal Vector3 Euler;

			internal Vector3 Scale;
		}

		private sealed class FeedRow
		{
			internal GameObject Go;

			internal Image Icon;

			internal Text Text;

			internal RectTransform TextRect;

			internal float Expire;

			internal string Base;

			internal Sprite IconSprite;

			internal int Total;
		}

		private readonly Plugin plugin;

		private Hud hud;

		private HotkeyBar hotbar;

		private bool applied;

		private const float HotbarMargin = 28f;

		private const float BlockGap = 12f;

		private const float BarGap = 8f;

		private const float PadBottom = 6f;

		private const float PadTop = 10f;

		private const float FoodSlotGap = 5f;

		private const float FoodStripGap = 6f;

		private const float BuffGap = 16f;

		private const float BuffRowGap = 10f;

		private const float BuffScale = 0.55f;

		private const float BuffGapAboveBlock = 18f;

		private const int BuffPerRow = 10;

		private const float LiftWhenBuilding = 190f;

		private const float FeedDuration = 4f;

		private const int FeedMaxRows = 6;

		private const int FeedRowH = 32;

		private const int FeedGap = 6;

		private const int FeedIcon = 28;

		private const int FeedFont = 20;

		private GameObject block;

		private readonly List<Member> members = new List<Member>();

		private readonly List<RotSnap> rotNodes = new List<RotSnap>();

		private Member health;

		private Member stamina;

		private Member eitr;

		private Member adrenaline;

		private Member foodStrip;

		private Member fork;

		private Member fork2;

		private Member foodText;

		private Member heart;

		private Member darken;

		private readonly List<Member> foodSlots = new List<Member>();

		private Snap statusSnap;

		private Snap hotbarSnap;

		private GameObject feedRoot;

		private readonly List<FeedRow> feedRows = new List<FeedRow>();

		private static Snap Take(RectTransform r)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			return new Snap
			{
				Min = r.anchorMin,
				Max = r.anchorMax,
				Pivot = r.pivot,
				Pos = r.anchoredPosition,
				Size = r.sizeDelta,
				OffMin = r.offsetMin,
				OffMax = r.offsetMax,
				Scale = ((Transform)r).localScale,
				Euler = ((Transform)r).localEulerAngles
			};
		}

		private static void Put(RectTransform r, Snap s)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			r.anchorMin = s.Min;
			r.anchorMax = s.Max;
			r.pivot = s.Pivot;
			r.offsetMin = s.OffMin;
			r.offsetMax = s.OffMax;
			r.anchoredPosition = s.Pos;
			r.sizeDelta = s.Size;
			((Transform)r).localScale = s.Scale;
			((Transform)r).localEulerAngles = s.Euler;
		}

		internal CustomHud(Plugin plugin)
		{
			this.plugin = plugin;
		}

		internal void Tick()
		{
			try
			{
				TickCore();
			}
			catch (Exception ex)
			{
				try
				{
					if (applied)
					{
						Restore();
					}
					else
					{
						ClearPartial();
					}
				}
				catch
				{
				}
				try
				{
					plugin.LogError("[Wayfarer] HUD Personalizada falhou: " + ex.Message);
				}
				catch
				{
				}
			}
		}

		private void TickCore()
		{
			bool num = plugin.Settings?.CustomHud.Value ?? false;
			Hud instance = Hud.instance;
			if ((Object)(object)instance != (Object)(object)hud)
			{
				applied = false;
				hud = instance;
				hotbar = null;
				block = null;
				feedRoot = null;
				feedRows.Clear();
				members.Clear();
				foodSlots.Clear();
				rotNodes.Clear();
				health = (stamina = (eitr = (adrenaline = (foodStrip = (fork = (fork2 = (foodText = (heart = (darken = null)))))))));
				statusSnap = (hotbarSnap = null);
			}
			if (!num)
			{
				if (applied)
				{
					Restore();
				}
			}
			else
			{
				if ((Object)(object)hud == (Object)null)
				{
					return;
				}
				if (!applied)
				{
					if (!Capture())
					{
						return;
					}
					applied = true;
				}
				ApplyDynamic();
			}
		}

		private Member Track(RectTransform rect)
		{
			if ((Object)(object)rect == (Object)null)
			{
				return null;
			}
			foreach (Member member2 in members)
			{
				if ((Object)(object)member2.Rect == (Object)(object)rect)
				{
					return member2;
				}
			}
			Member member = new Member
			{
				Rect = rect,
				Parent = ((Transform)rect).parent,
				Sibling = ((Transform)rect).GetSiblingIndex(),
				Snap = Take(rect)
			};
			members.Add(member);
			return member;
		}

		private void ResetSubtree(RectTransform root)
		{
			//IL_00b1: 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_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)root == (Object)null)
			{
				return;
			}
			Transform[] componentsInChildren;
			try
			{
				componentsInChildren = ((Component)root).GetComponentsInChildren<Transform>(true);
			}
			catch
			{
				return;
			}
			Transform[] array = componentsInChildren;
			foreach (Transform obj2 in array)
			{
				RectTransform val = (RectTransform)(object)((obj2 is RectTransform) ? obj2 : null);
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				bool flag = false;
				foreach (RotSnap rotNode in rotNodes)
				{
					if ((Object)(object)rotNode.Rect == (Object)(object)val)
					{
						flag = true;
						break;
					}
				}
				if (!flag)
				{
					rotNodes.Add(new RotSnap
					{
						Rect = val,
						Euler = ((Transform)val).localEulerAngles,
						Scale = ((Transform)val).localScale
					});
				}
				((Transform)val).localEulerAngles = Vector3.zero;
				((Transform)val).localScale = Vector3.one;
			}
		}

		private static RectTransform Child(Transform parent, string name)
		{
			if ((Object)(object)parent == (Object)null)
			{
				return null;
			}
			try
			{
				Transform obj = parent.Find(name);
				return (RectTransform)(object)((obj is RectTransform) ? obj : null);
			}
			catch
			{
				return null;
			}
		}

		private bool Capture()
		{
			//IL_0754: Unknown result type (might be due to invalid IL or missing references)
			//IL_075b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0777: Unknown result type (might be due to invalid IL or missing references)
			//IL_078c: Unknown result type (might be due to invalid IL or missing references)
			//IL_07a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_07e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_07f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_07ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0462: Unknown result type (might be due to invalid IL or missing references)
			//IL_0473: Unknown result type (might be due to invalid IL or missing references)
			//IL_0484: Unknown result type (might be due to invalid IL or missing references)
			//IL_0495: 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_01cf: Expected O, but got Unknown
			//IL_0206: Unknown result type (might be due to invalid IL or missing references)
			//IL_020d: 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_022c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0662: Unknown result type (might be due to invalid IL or missing references)
			//IL_0667: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0672: Unknown result type (might be due to invalid IL or missing references)
			//IL_067c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0683: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ce: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_06e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ea: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)hud).transform;
			Transform val;
			try
			{
				val = transform.Find("hudroot");
			}
			catch
			{
				val = null;
			}
			if ((Object)(object)val == (Object)null)
			{
				return false;
			}
			Transform val2 = (Transform)(((Object)(object)hud.m_healthPanel != (Object)null) ? ((object)((Component)hud.m_healthPanel).transform) : ((object)Child(val, "healthpanel")));
			if ((Object)(object)val2 == (Object)null)
			{
				return false;
			}
			RectTransform val3 = hud.m_healthBarRoot;
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = Child(val2, "Health");
			}
			if ((Object)(object)val3 == (Object)null)
			{
				val3 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
			}
			RectTransform val4 = hud.m_staminaBar2Root;
			if ((Object)(object)val4 == (Object)null)
			{
				val4 = Child(val, "staminapanel");
			}
			HotkeyBar val5 = FindHotbar(transform, val);
			if ((Object)(object)val3 == (Object)null || (Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null)
			{
				return false;
			}
			if ((Object)(object)hud.m_statusEffectListRoot == (Object)null)
			{
				return false;
			}
			hotbar = val5;
			RectTransform val6 = hud.m_foodBarRoot;
			if ((Object)(object)val6 == (Object)null)
			{
				val6 = Child(val2, "Food");
			}
			RectTransform val7 = (RectTransform)(((Object)(object)hud.m_foodIcon != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val7 == (Object)null)
			{
				val7 = Child(val2, "foodicon");
			}
			RectTransform val8 = (RectTransform)(((Object)(object)hud.m_foodText != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
			if ((Object)(object)val8 == (Object)null)
			{
				val8 = Child(val2, "FoodText");
			}
			block = new GameObject("Wayfarer.HudBlock", new Type[1] { typeof(RectTransform) });
			block.layer = 5;
			RectTransform component = block.GetComponent<RectTransform>();
			((Transform)component).SetParent(val, false);
			Vector2 val9 = default(Vector2);
			((Vector2)(ref val9))..ctor(0.5f, 0f);
			component.anchorMax = val9;
			component.anchorMin = val9;
			component.pivot = new Vector2(0.5f, 0f);
			((Transform)component).localScale = Vector3.one;
			health = Track(val3);
			stamina = Track(val4);
			eitr = Track(hud.m_eitrBarRoot ?? Child(val, "eitrpanel"));
			adrenaline = Track(hud.m_adrenalineBarRoot ?? Child(val, "adrenalinepanel"));
			foodStrip = Track(val6);
			fork = Track(val7);
			fork2 = Track(Child(val2, "foodicon (1)"));
			foodText = Track(val8);
			heart = Track(Child(val2, "healthicon"));
			darken = Track(Child(val2, "darken"));
			for (int i = 0; i < 3; i++)
			{
				RectTransform val10 = Child(val2, "food" + i);
				if ((Object)(object)val10 == (Object)null && hud.m_foodBars != null && i < hud.m_foodBars.Length && (Object)(object)hud.m_foodBars[i] != (Object)null)
				{
					Transform val11 = ((Component)hud.m_foodBars[i]).transform;
					while ((Object)(object)val11.parent != (Object)null && (Object)(object)val11.parent != (Object)(object)val2 && (Object)(object)val11.parent != (Object)(object)val && (Object)(object)val11.parent != (Object)(object)transform)
					{
						val11 = val11.parent;
					}
					val10 = (RectTransform)(object)((val11 is RectTransform) ? val11 : null);
				}
				Member member = Track(val10);
				if (member != null && !foodSlots.Contains(member))
				{
					foodSlots.Add(member);
				}
			}
			foreach (Member member2 in members)
			{
				if ((Object)(object)member2?.Rect == (Object)null)
				{
					continue;
				}
				((Transform)member2.Rect).SetParent((Transform)(object)component, false);
				if (member2 == darken)
				{
					member2.Rect.anchorMin = Vector2.zero;
					member2.Rect.anchorMax = Vector2.one;
					member2.Rect.offsetMin = Vector2.zero;
					member2.Rect.offsetMax = Vector2.zero;
					try
					{
						((Transform)member2.Rect).SetAsFirstSibling();
					}
					catch
					{
					}
				}
				else
				{
					val9 = (member2.Rect.anchorMin = (member2.Rect.anchorMax = new Vector2(0.5f, 0f)));
					((Transform)member2.Rect).localScale = Vector3.one;
				}
			}
			foreach (Member member3 in members)
			{
				if (member3 != null && (Object)(object)member3.Rect != (Object)null)
				{
					ResetSubtree(member3.Rect);
				}
			}
			try
			{
				float num = HeightOf(health?.Rect, 32f);
				var array = new[]
				{
					new
					{
						M = stamina,
						T = hud.m_staminaText
					},
					new
					{
						M = eitr,
						T = hud.m_eitrText
					},
					new
					{
						M = adrenaline,
						T = hud.m_adrenalineText
					}
				};
				foreach (var anon in array)
				{
					RectTransform val14 = (((Object)(object)anon.M?.Rect != (Object)null) ? Child((Transform)(object)anon.M.Rect, "Stamina") : null);
					float num2 = HeightOf(val14, 0f);
					if (!((Object)(object)val14 == (Object)null) && !(num2 <= 1f) && !(num <= 1f))
					{
						float num3 = Mathf.Clamp(0.8f * num / num2, 0.5f, 3f);
						Vector3 localScale = ((Transform)val14).localScale;
						((Transform)val14).localScale = new Vector3(localScale.x, localScale.y * num3, localScale.z);
						RectTransform val15 = (RectTransform)(((Object)(object)anon.T != (Object)null) ? /*isinst with value type is only supported in some contexts*/: null);
						if ((Object)(object)val15 != (Object)null && ((Transform)val15).IsChildOf((Transform)(object)val14))
						{
							Vector3 localScale2 = ((Transform)val15).localScale;
							((Transform)val15).localScale = new Vector3(localScale2.x, localScale2.y / num3, localScale2.z);
						}
					}
				}
			}
			catch
			{
			}
			try
			{
				((Transform)component).SetAsFirstSibling();
			}
			catch
			{
			}
			statusSnap = Take(hud.m_statusEffectListRoot);
			RectTransform statusEffectListRoot = hud.m_statusEffectListRoot;
			RectTransform statusEffectListRoot2 = hud.m_statusEffectListRoot;
			((Vector2)(ref val9))..ctor(0.5f, 0f);
			statusEffectListRoot2.anchorMax = val9;
			statusEffectListRoot.anchorMin = val9;
			hud.m_statusEffectListRoot.pivot = new Vector2(0.5f, 0.5f);
			((Transform)hud.m_statusEffectListRoot).localScale = Vector3.one;
			((Transform)hud.m_statusEffectListRoot).localEulerAngles = Vector3.zero;
			Transform transform2 = ((Component)hotbar).transform;
			RectTransform val16 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
			if (val16 != null)
			{
				hotbarSnap = Take(val16);
				((Vector2)(ref val9))..ctor(0.5f, 0f);
				val16.anchorMax = val9;
				val16.anchorMin = val9;
				((Transform)val16).localScale = Vector3.one;
				((Transform)val16).localEulerAngles = Vector3.zero;
			}
			ApplyDynamic();
			return true;
		}

		private static HotkeyBar FindHotbar(Transform hudT, Transform hudRoot)
		{
			try
			{
				Transform val = (((Object)(object)hudRoot != (Object)null) ? hudRoot.Find("HotKeyBar") : null);
				if ((Object)(object)val != (Object)null)
				{
					HotkeyBar component = ((Component)val).GetComponent<HotkeyBar>();
					if ((Object)(object)component != (Object)null)
					{
						return component;
					}
				}
			}
			catch
			{
			}
			try
			{
				HotkeyBar[] componentsInChildren = ((Component)hudT).GetComponentsInChildren<HotkeyBar>(true);
				foreach (HotkeyBar val2 in componentsInChildren)
				{
					if ((Object)(object)val2 != (Object)null && ((Object)val2).name == "HotKeyBar")
					{
						return val2;
					}
				}
			}
			catch
			{
			}
			return null;
		}

		private static float HeightOf(RectTransform r, float fallback)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)r != (Object)null)
				{
					Rect rect = r.rect;
					if (((Rect)(ref rect)).height > 1f)
					{
						rect = r.rect;
						return ((Rect)(ref rect)).height;
					}
				}
			}
			catch
			{
			}
			return fallback;
		}

		private static float WidthOf(RectTransform r, float fallback)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if ((Object)(object)r != (Object)null)
				{
					Rect rect = r.rect;
					if (((Rect)(ref rect)).width > 1f)
					{
						rect = r.rect;
						return ((Rect)(ref rect)).width;
					}
				}
			}
			catch
			{
			}
			return fallback;
		}

		private void ApplyDynamic()
		{
			//IL_0739: Unknown result type (might be due to invalid IL or missing references)
			//IL_0743: Unknown result type (might be due to invalid IL or missing references)
			//IL_0765: Unknown result type (might be due to invalid IL or missing references)
			//IL_0956: Unknown result type (might be due to invalid IL or missing references)
			//IL_033b: Unknown result type (might be due to invalid IL or missing references)
			//IL_034d: Unknown result type (might be due to invalid IL or missing references)
			//IL_036c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_0801: Unknown result type (might be due to invalid IL or missing references)
			//IL_080d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0819: Unknown result type (might be due to invalid IL or missing references)
			//IL_0823: Unknown result type (might be due to invalid IL or missing references)
			//IL_0267: Unknown result type (might be due to invalid IL or missing references)
			//IL_026c: 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_0283: Unknown result type (might be due to invalid IL or missing references)
			//IL_03be: Unknown result type (might be due to invalid IL or missing references)
			//IL_08b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f4: Unknown result type (might be due to invalid IL or missing references)
			//IL_08d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_08de: Unknown result type (might be due to invalid IL or missing references)
			//IL_08e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_047c: Unknown result type (might be due to invalid IL or missing references)
			//IL_04d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0201: Unknown result type (might be due to invalid IL or missing references)
			//IL_0563: 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_0218: Unknown result type (might be due to invalid IL or missing references)
			//IL_05a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_05e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0654: Unknown result type (might be due to invalid IL or missing references)
			//IL_0659: Unknown result type (might be due to invalid IL or missing references)
			//IL_0697: Unknown result type (might be due to invalid IL or missing references)
			//IL_069c: Unknown result type (might be due to invalid IL or missing references)
			//IL_066b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0670: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_06b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0685: Unknown result type (might be due to invalid IL or missing references)
			//IL_068a: Unknown result type (might be due to invalid IL or missing references)
			//IL_06c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_06cd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)block == (Object)null || (Object)(object)health?.Rect == (Object)null || (Object)(object)stamina?.Rect == (Object)null || (Object)(object)hotbar == (Object)null)
			{
				return;
			}
			RectTransform component = block.GetComponent<RectTransform>();
			if ((Object)(object)component == (Object)null)
			{
				return;
			}
			float num = ((((Object)(object)hud.m_buildHud != (Object)null && hud.m_buildHud.activeSelf) || ((Object)(object)hud.m_shipHudRoot != (Object)null && hud.m_shipHudRoot.activeSelf)) ? 190f : 0f);
			float num2 = WidthOf(health.Rect, 160f);
			float num3 = HeightOf(health.Rect, 32f);
			float num4 = (((Object)(object)foodStrip?.Rect != (Object)null) ? WidthOf(foodStrip.Rect, 160f) : 0f);
			float num5 = 0f;
			float num6 = 0f;
			foreach (Member foodSlot in foodSlots)
			{
				if (!((Object)(object)foodSlot.Rect == (Object)null))
				{
					float num7 = WidthOf(foodSlot.Rect, 0f);
					float num8 = HeightOf(foodSlot.Rect, 0f);
					if (num7 > num5)
					{
						num5 = num7;
					}
					if (num8 > num6)
					{
						num6 = num8;
					}
				}
			}
			bool flag = foodSlots.Count > 0 || num4 > 0f;
			float num9 = HeightOf(stamina.Rect, 32f);
			float num10 = 64f;
			Transform transform = ((Component)hotbar).transform;
			RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
			Rect rect;
			if (val != null)
			{
				try
				{
					rect = val.rect;
					if (((Rect)(ref rect)).height > 1f)
					{
						rect = val.rect;
						num10 = ((Rect)(ref rect)).height;
					}
				}
				catch
				{
				}
			}
			float num11 = 0f;
			try
			{
				for (int i = 0; i < ((Component)hotbar).transform.childCount; i++)
				{
					Transform child = ((Component)hotbar).transform.GetChild(i);
					RectTransform val2 = (RectTransform)(object)((child is RectTransform) ? child : null);
					if ((Object)(object)val2 != (Object)null && ((Component)val2).gameObject.activeSelf)
					{
						rect = val2.rect;
						if (((Rect)(ref rect)).height > 1f)
						{
							rect = val2.rect;
							num11 = ((Rect)(ref rect)).height;
							break;
						}
					}
				}
			}
			catch
			{
			}
			if (num11 <= 1f)
			{
				num11 = num10;
			}
			float num12 = 10f;
			float num13 = num12 + 4f + 6f + num6 / 2f;
			float num14 = (flag ? (num13 + num6 / 2f) : 6f) + 8f;
			float num15 = num14 + num9 + 8f + num3 / 2f;
			float num16 = num15 + num3 / 2f + 10f;
			float num17 = 28f + num10 + 12f + num;
			component.sizeDelta = new Vector2(480f, num16);
			component.anchoredPosition = new Vector2(0f, num17);
			health.Rect.anchoredPosition = new Vector2((0f - num2) / 2f, num15);
			stamina.Rect.anchoredPosition = new Vector2(0f, num14);
			if ((Object)(object)eitr?.Rect != (Object)null)
			{
				eitr.Rect.anchoredPosition = new Vector2(0f, num14);
			}
			if ((Object)(object)adrenaline?.Rect != (Object)null)
			{
				adrenaline.Rect.anchoredPosition = new Vector2(0f, num14);
			}
			if ((Object)(object)heart?.Rect != (Object)null)
			{
				heart.Rect.anchoredPosition = new Vector2((0f - num2) / 2f - 5f - 16f, num15);
			}
			if ((Object)(object)foodStrip?.Rect != (Object)null && num4 > 0f)
			{
				foodStrip.Rect.anchoredPosition = new Vector2((0f - num4) / 2f, num12);
			}
			float num18 = num5 + 5f;
			for (int j = 0; j < foodSlots.Count; j++)
			{
				Member member = foodSlots[j];
				if (!((Object)(object)member.Rect == (Object)null))
				{
					member.Rect.anchoredPosition = new Vector2(((float)j - (float)(foodSlots.Count - 1) / 2f) * num18, num13);
				}
			}
			float num19 = ((foodSlots.Count > 0) ? ((float)(foodSlots.Count - 1) / 2f * num18 + num5 / 2f) : 40f);
			if ((Object)(object)fork?.Rect != (Object)null)
			{
				fork.Rect.anchoredPosition = new Vector2(0f - num19 - 5f - 16f, num13);
			}
			if ((Object)(object)fork2?.Rect != (Object)null)
			{
				fork2.Rect.anchoredPosition = new Vector2(num19 + 5f + 16f, num13);
			}
			if ((Object)(object)foodText?.Rect != (Object)null)
			{
				foodText.Rect.anchoredPosition = new Vector2(num19 + 5f + 44f, num13);
			}
			if ((Object)(object)hud.m_statusEffectListRoot != (Object)null)
			{
				RectTransform statusEffectListRoot = hud.m_statusEffectListRoot;
				float num20 = 46f;
				float num21 = 53f;
				try
				{
					for (int k = 0; k < ((Transform)statusEffectListRoot).childCount; k++)
					{
						Transform child2 = ((Transform)statusEffectListRoot).GetChild(k);
						RectTransform val3 = (RectTransform)(object)((child2 is RectTransform) ? child2 : null);
						if ((Object)(object)val3 == (Object)null || !((Component)val3).gameObject.activeSelf)
						{
							continue;
						}
						rect = val3.rect;
						if (((Rect)(ref rect)).width > 1f)
						{
							rect = val3.rect;
							if (((Rect)(ref rect)).width < num20 + 20f)
							{
								rect = val3.rect;
								num20 = ((Rect)(ref rect)).width;
							}
						}
						rect = val3.rect;
						if (((Rect)(ref rect)).height > 1f)
						{
							rect = val3.rect;
							if (((Rect)(ref rect)).height < num21 + 20f)
							{
								rect = val3.rect;
								num21 = ((Rect)(ref rect)).height;
							}
						}
					}
				}
				catch
				{
				}
				float num22 = num20 * 0.55f;
				float num23 = num21 * 0.55f;
				float num24 = num22 + 16f;
				int num25 = ActiveChildren(statusEffectListRoot);
				float num26 = (float)Math.Min(10, Math.Max(num25, 1)) * num24 + 8f;
				statusEffectListRoot.sizeDelta = new Vector2(num26, statusEffectListRoot.sizeDelta.y);
				statusEffectListRoot.anchoredPosition = new Vector2(0f, num17 + num16 + 18f + 27.5f);
				int num27 = 0;
				for (int l = 0; l < ((Transform)statusEffectListRoot).childCount; l++)
				{
					Transform child3 = ((Transform)statusEffectListRoot).GetChild(l);
					RectTransform val4 = (RectTransform)(object)((child3 is RectTransform) ? child3 : null);
					if (!((Object)(object)val4 == (Object)null) && ((Component)val4).gameObject.activeSelf)
					{
						int num28 = num27 / 10;
						int num29 = num27 % 10;
						int num30 = Math.Min(10, num25 - num28 * 10);
						float num31 = (0f - num26) / 2f + (float)(num30 - 1) * num24 / 2f + num22 / 2f;
						val4.anchoredPosition = new Vector2(num31 - (float)num29 * num24, (float)num28 * (num23 + 10f));
						((Transform)val4).localEulerAngles = Vector3.zero;
						((Transform)val4).localScale = Vector3.one * 0.55f;
						num27++;
					}
				}
			}
			Transform transform2 = ((Component)hotbar).transform;
			RectTransform val5 = (RectTransform)(object)((transform2 is RectTransform) ? transform2 : null);
			if (val5 != null)
			{
				float num32 = 0f;
				float num33 = 0f;
				float num34 = 0f;
				int num35 = 0;
				try
				{
					for (int m = 0; m < ((Component)hotbar).transform.childCount; m++)
					{
						Transform child4 = ((Component)hotbar).transform.GetChild(m);
						RectTransform val6 = (RectTransform)(object)((child4 is RectTransform) ? child4 : null);
						if ((Object)(object)val6 == (Object)null || !((Component)val6).gameObject.activeSelf)
						{
							continue;
						}
						float x = ((Transform)val6).localPosition.x;
						if (num35 == 0)
						{
							num32 = (num33 = x);
							float num36 = 0.5f - val6.pivot.x;
							rect = val6.rect;
							num34 = num36 * ((Rect)(ref rect)).width;
						}
						else
						{
							if (x < num32)
							{
								num32 = x;
							}
							if (x > num33)
							{
								num33 = x;
							}
						}
						num35++;
					}
				}
				catch
				{
				}
				float num37 = ((num35 > 0) ? (0f - ((num32 + num33) / 2f + num34)) : 0f);
				val5.anchoredPosition = new Vector2(num37, 28f + num11);
			}
			HideVanillaFeed();
			UpdateFeed();
		}

		private static int ActiveChildren(RectTransform root)
		{
			int num = 0;
			for (int i = 0; i < ((Transform)root).childCount; i++)
			{
				Transform child = ((Transform)root).GetChild(i);
				if ((Object)(object)child != (Object)null && ((Component)child).gameObject.activeSelf)
				{
					num++;
				}
			}
			return num;
		}

		private void HideVanillaFeed()
		{
			MessageHud instance = MessageHud.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			try
			{
				if ((Object)(object)instance.m_messageText != (Object)null)
				{
					instance.m_messageText.alpha = 0f;
				}
				if ((Object)(object)instance.m_messageIcon != (Object)null)
				{
					((Graphic)instance.m_messageIcon).canvasRenderer.SetAlpha(0f);
				}
			}
			catch
			{
			}
		}

		private void ClearPartial()
		{
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				foreach (Member member in members)
				{
					if (!((Object)(object)member?.Rect == (Object)null) && !((Object)(object)member.Parent == (Object)null) && member.Snap != null)
					{
						try
						{
							((Transform)member.Rect).SetParent(member.Parent, false);
						}
						catch
						{
						}
						try
						{
							Put(member.Rect, member.Snap);
						}
						catch
						{
						}
					}
				}
				foreach (RotSnap rotNode in rotNodes)
				{
					if (!((Object)(object)rotNode?.Rect == (Object)null))
					{
						try
						{
							((Transform)rotNode.Rect).localEulerAngles = rotNode.Euler;
							((Transform)rotNode.Rect).localScale = rotNode.Scale;
						}
						catch
						{
						}
					}
				}
				if ((Object)(object)hotbar != (Object)null && hotbarSnap != null)
				{
					Transform transform = ((Component)hotbar).transform;
					RectTransform val = (RectTransform)(object)((transform is RectTransform) ? transform : null);
					if (val != null)
					{
						try
						{
							Put(val, hotbarSnap);
						}
						catch
						{
						}
					}
				}
				if ((Object)(object)hud != (Object)null && (Object)(object)hud.m_statusEffectListRoot != (Object)null && statusSnap != null)
				{
					try
					{
						Put(hud.m_statusEffectListRoot, statusSnap);
					}
					catch
					{
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)block != (Object)null)
			{
				Object.Destroy((Object)(object)block);
			}
			block = null;
			members.Clear();
			foodSlots.Clear();
			rotNodes.Clear();
			health = (stamina = (eitr = (adrenaline = (foodStrip = (fork = (fork2 = (foodText = (heart = (darken = null)))))))));
			statusSnap = (hotbarSnap = null);
			hotbar = null;
			applied = false;
		}

		private void Restore()
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ff: Unknown result type (might be due to invalid IL or missing references)
			applied = false;
			try
			{
				foreach (Member member in members)
				{
					if ((Object)(object)member?.Rect == (Object)null || (Object)(object)member.Parent == (Object)null || member.Snap == null)
					{
						continue;
					}
					try
					{
						((Transform)member.Rect).SetParent(member.Parent, false);
						try
						{
							((Transform)member.Rect).SetSiblingIndex(member.Sibling);
						}
						catch
						{
						}
						Put(member.Rect, member.Snap);
					}
					catch
					{
					}
				}
				foreach (RotSnap rotNode in rotNodes)
				{
					if (!((Object)(object)rotNode?.Rect == (Object)null))
					{
						try
						{
							((Transform)rotNode.Rect).localEulerAngles = rotNode.Euler;
							((Transform)rotNode.Rect).localScale = rotNode.Scale;
						}
						catch
						{
						}
					}
				}
				if ((Object)(object)hud != (Object)null && (Object)(object)hud.m_statusEffectListRoot != (Object)null)
				{
					if (statusSnap != null)
					{
						try
						{
							Put(hud.m_statusEffectListRoot, statusSnap);
						}
						catch
						{
						}
					}
					float statusEffectSpacing = hud.m_statusEffectSpacing;
					int num = Math.Max(1, hud.m_effectsPerRow);
					int num2 = 0;
					for (int i = 0; i < ((Transform)hud.m_statusEffectListRoot).childCount; i++)
					{
						Transform child = ((Transform)hud.m_statusEffectListRoot).GetChild(i);
						RectTransform val = (RectTransform)(object)((child is RectTransform) ? child : null);
						if (!((Object)(object)val == (Object)null) && ((Component)val).gameObject.activeSelf)
						{
							int num3 = num2 / num;
							int num4 = num2 - num3 * num;
							try
							{
								val.anchoredPosition = Vector2.op_Implicit(new Vector3(-4f - (float)num4 * statusEffectSpacing, (float)(-num3) * statusEffectSpacing, 0f));
								((Transform)val).localEulerAngles = Vector3.zero;
								((Transform)val).localScale = Vector3.one;
							}
							catch
							{
							}
							num2++;
						}
					}
				}
				if ((Object)(object)hotbar != (Object)null && hotbarSnap != null)
				{
					Transform transform = ((Component)hotbar).transform;
					RectTransform val2 = (RectTransform)(object)((transform is RectTransform) ? transform : null);
					if (val2 != null)
					{
						try
						{
							Put(val2, hotbarSnap);
						}
						catch
						{
						}
					}
				}
			}
			catch
			{
			}
			if ((Object)(object)block != (Object)null)
			{
				Object.Destroy((Object)(object)block);
			}
			block = null;
			members.Clear();
			foodSlots.Clear();
			rotNodes.Clear();
			health = (stamina = (eitr = (adrenaline = (foodStrip = (fork = (fork2 = (foodText = (heart = (darken = null)))))))));
			statusSnap = (hotbarSnap = null);
			ClearFeed();
			hotbar = null;
		}

		internal void Enqueue(Sprite icon, string text, int amount)
		{
			try
			{
				string text2 = text ?? "";
				try
				{
					text2 = ((Localization.instance != null) ? Localization.instance.Localize(text2) : text2);
				}
				catch
				{
				}
				if (text2.Length == 0 && (Object)(object)icon == (Object)null)
				{
					return;
				}
				EnsureFeed();
				if ((Object)(object)feedRoot == (Object)null)
				{
					return;
				}
				for (int i = 0; i < feedRows.Count; i++)
				{
					FeedRow feedRow = feedRows[i];
					if (feedRow != null && !(feedRow.Base != text2) && !((Object)(object)feedRow.IconSprite != (Object)(object)icon))
					{
						if (amount > 0)
						{
							feedRow.Total += amount;
						}
						string text3 = feedRow.Base;
						if (feedRow.Total > 1)
						{
							text3 = text3 + " x" + feedRow.Total;
						}
						ApplyRowContent(feedRow, icon, text3);
						feedRow.Expire = Time.unscaledTime + 4f;
						return;
					}
				}
				int num = ((amount > 0) ? amount : 0);
				string text4 = text2;
				if (num > 1)
				{
					text4 = text4 + " x" + num;
				}
				while (feedRows.Count >= 6)
				{
					RemoveRow(feedRows.Count - 1);
				}
				FeedRow feedRow2 = CreateRow(icon, text4);
				feedRow2.Base = text2;
				feedRow2.IconSprite = icon;
				feedRow2.Total = num;
				feedRows.Insert(0, feedRow2);
				StackFeed();
			}
			catch
			{
			}
		}

		private void EnsureFeed()
		{
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b9: Unknown result type (might be due to invalid IL or missing references)
			MessageHud instance = MessageHud.instance;
			if (!((Object)(object)instance == (Object)null) && !((Object)(object)feedRoot != (Object)null))
			{
				feedRoot = new GameObject("Wayfarer.Feed", new Type[1] { typeof(RectTransform) });
				feedRoot.layer = 5;
				RectTransform component = feedRoot.GetComponent<RectTransform>();
				((Transform)component).SetParent(((Component)instance).transform, false);
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0f, 0.5f);
				component.anchorMax = val;
				component.anchorMin = val;
				component.pivot = new Vector2(0f, 0.5f);
				component.anchoredPosition = new Vector2(24f, 0f);
				component.sizeDelta = new Vector2(440f, 228f);
			}
		}

		private FeedRow CreateRow(Sprite icon, string value)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Expected O, but got Unknown
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: 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_0063: 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_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: 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_00ce: 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_00e7: 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)
			//IL_0123: Expected O, but got Unknown
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: 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_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f6: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject("FeedRow", new Type[1] { typeof(RectTransform) });
			val.layer = 5;
			RectTransform component = val.GetComponent<RectTransform>();
			((Transform)component).SetParent(feedRoot.transform, false);
			Vector2 val2 = default(Vector2);
			((Vector2)(ref val2))..ctor(0f, 1f);
			component.pivot = val2;
			Vector2 anchorMin = (component.anchorMax = val2);
			component.anchorMin = anchorMin;
			component.sizeDelta = new Vector2(430f, 32f);
			GameObject val4 = new GameObject("Icon", new Type[1] { typeof(RectTransform) })
			{
				layer = 5
			};
			RectTransform component2 = val4.GetComponent<RectTransform>();
			((Transform)component2).SetParent((Transform)(object)component, false);
			((Vector2)(ref val2))..ctor(0f, 0.5f);
			component2.pivot = val2;
			anchorMin = (component2.anchorMax = val2);
			component2.anchorMin = anchorMin;
			component2.sizeDelta = new Vector2(28f, 28f);
			Image val6 = val4.AddComponent<Image>();
			val6.preserveAspect = true;
			((Graphic)val6).raycastTarget = false;
			GameObject val7 = new GameObject("Text", new Type[1] { typeof(RectTransform) });
			val7.layer = 5;
			RectTransform component3 = val7.GetComponent<RectTransform>();
			((Transform)component3).SetParent((Transform)(object)component, false);
			((Vector2)(ref val2))..ctor(0f, 0.5f);
			component3.pivot = val2;
			anchorMin = (component3.anchorMax = val2);
			component3.anchorMin = anchorMin;
			Text val9 = val7.AddComponent<Text>();
			((Graphic)val9).raycastTarget = false;
			try
			{
				GUIManager.Instance.ApplyTextStyle(val9, GUIManager.Instance.AveriaSerif, Color.white, 20, true);
			}
			catch
			{
				((Graphic)val9).color = Color.white;
				val9.fontSize = 20;
				try
				{
					val9.font = Resources.GetBuiltinResource<Font>("Arial.ttf");
				}
				catch
				{
				}
				try
				{
					Outline obj3 = val7.AddComponent<Outline>();
					((Shadow)obj3).effectColor = new Color(0f, 0f, 0f, 0.85f);
					((Shadow)obj3).effectDistance = new Vector2(1f, -1f);
				}
				catch
				{
				}
			}
			val9.alignment = (TextAnchor)3;
			val9.horizontalOverflow = (HorizontalWrapMode)1;
			val9.verticalOverflow = (VerticalWrapMode)1;
			FeedRow obj5 = new FeedRow
			{
				Go = val,
				Icon = val6,
				Text = val9,
				TextRect = component3,
				Expire = Time.unscaledTime + 4f
			};
			ApplyRowContent(obj5, icon, value);
			return obj5;
		}

		private static void ApplyRowContent(FeedRow row, Sprite icon, string value)
		{
			//IL_004e: 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)
			row.Text.text = value;
			bool flag = (Object)(object)icon != (Object)null;
			((Component)row.Icon).gameObject.SetActive(flag);
			if (flag)
			{
				row.Icon.sprite = icon;
			}
			row.TextRect.anchoredPosition = new Vector2(flag ? 34f : 0f, 0f);
			row.TextRect.sizeDelta = new Vector2(flag ? 396f : 430f, 32f);
		}

		private void StackFeed()
		{
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			for (int i = 0; i < feedRows.Count; i++)
			{
				RectTransform component = feedRows[i].Go.GetComponent<RectTransform>();
				if ((Object)(object)component != (Object)null)
				{
					component.anchoredPosition = new Vector2(0f, (float)(-i * 38));
				}
			}
		}

		private void RemoveRow(int index)
		{
			if (index >= 0 && index < feedRows.Count)
			{
				FeedRow feedRow = feedRows[index];
				feedRows.RemoveAt(index);
				if ((Object)(object)feedRow.Go != (Object)null)
				{
					Object.Destroy((Object)(object)feedRow.Go);
				}
			}
		}

		private void UpdateFeed()
		{
			if ((Object)(object)feedRoot == (Object)null)
			{
				EnsureFeed();
			}
			if ((Object)(object)feedRoot == (Object)null)
			{
				return;
			}
			bool flag = false;
			for (int num = feedRows.Count - 1; num >= 0; num--)
			{
				if (Time.unscaledTime >= feedRows[num].Expire)
				{
					RemoveRow(num);
					flag = true;
				}
			}
			if (flag)
			{
				StackFeed();
			}
			bool flag2 = feedRows.Count > 0 && !Hud.IsUserHidden();
			if (feedRoot.activeSelf != flag2)
			{
				feedRoot.SetActive(flag2);
			}
		}

		private void ClearFeed()
		{
			for (int num = feedRows.Count - 1; num >= 0; num--)
			{
				RemoveRow(num);
			}
			if ((Object)(object)feedRoot != (Object)null)
			{
				feedRoot.SetActive(false);
			}
		}

		public void Dispose()
		{
			if (applied)
			{
				Restore();
			}
			else
			{
				ClearFeed();
			}
			if ((Object)(object)block != (Object)null)
			{
				Object.Destroy((Object)(object)block);
			}
			block = null;
			if ((Object)(object)feedRoot != (Object)null)
			{
				Object.Destroy((Object)(object)feedRoot);
			}
			feedRoot = null;
			feedRows.Clear();
			members.Clear();
			foodSlots.Clear();
			rotNodes.Clear();
			hud = null;
			hotbar = null;
		}
	}
	[HarmonyPatch(typeof(MessageHud), "ShowMessage")]
	internal static class CustomHudFeedPatch
	{
		private static void Postfix(MessageType type, string text, int amount, Sprite icon)
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Invalid comparison between Unknown and I4
			Plugin instance = Plugin.Instance;
			if ((Object)(object)instance == (Object)null || instance.Settings == null || instance.CustomHud == null || !instance.Settings.CustomHud.Value || (int)type != 1)
			{
				return;
			}
			try
			{
				instance.CustomHud.Enqueue(icon, text, amount);
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(Ragdoll), "Setup")]
	internal static class InstantLootPatch
	{
		private static readonly MethodInfo Spawn = AccessTools.Method(typeof(Ragdoll), "SpawnLoot", (Type[])null, (Type[])null);

		private static void Postfix(Ragdoll __instance, CharacterDrop characterDrop)
		{
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			Plugin instance = Plugin.Instance;
			if (instance.Settings.InstantLoot.Value && !instance.LootConflict && Object.op_Implicit((Object)(object)characterDrop) && __instance.m_dropItems)
			{
				ZNetView component = ((Component)__instance).GetComponent<ZNetView>();
				if (Object.op_Implicit((Object)(object)component) && component.IsValid() && component.IsOwner() && component.GetZDO().GetInt(ZDOVars.s_drops, 0) > 0)
				{
					Spawn.Invoke(__instance, new object[1] { ((Component)__instance).transform.position });
					component.GetZDO().Set(ZDOVars.s_drops, 0, false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Show")]
	internal static class AutoRepairPatch
	{
		private static readonly MethodInfo CanRepair = AccessTools.Method(typeof(InventoryGui), "CanRepair", (Type[])null, (Type[])null);

		private static void Postfix(InventoryGui __instance)
		{
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: 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)
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			Plugin instance = Plugin.Instance;
			Player localPlayer = Player.m_localPlayer;
			if (!instance.Settings.AutoRepair.Value || !Object.op_Implicit((Object)(object)localPlayer))
			{
				return;
			}
			CraftingStation currentCraftingStation = localPlayer.GetCurrentCraftingStation();
			if (!Object.op_Implicit((Object)(object)currentCraftingStation) || !currentCraftingStation.m_canRepair || !currentCraftingStation.CheckUsable(localPlayer, false))
			{
				return;
			}
			int num = 0;
			foreach (ItemData allItem in ((Humanoid)localPlayer).GetInventory().GetAllItems())
			{
				if (allItem.m_shared.m_useDurability && !(allItem.m_durability >= allItem.GetMaxDurability()) && (bool)CanRepair.Invoke(__instance, new object[1] { allItem }))
				{
					((Character)localPlayer).RaiseSkill((SkillType)107, 1f - allItem.m_durability / allItem.GetMaxDurability());
					allItem.m_durability = allItem.GetMaxDurability();
					num++;
				}
			}
			if (num != 0)
			{
				currentCraftingStation.m_repairItemDoneEffects.Create(((Component)currentCraftingStation).transform.position, Quaternion.identity, (Transform)null, 1f, -1, default(ZDOID));
				((Character)localPlayer).Message((MessageType)2, $"{num} item(ns) reparado(s)", 0, (Sprite)null, false);
			}
		}
	}
	internal static class MiningFeatures
	{
		private static readonly FieldRef<MineRock, ZNetView> RockView = AccessTools.FieldRefAccess<MineRock, ZNetView>("m_nview");

		private static readonly FieldRef<MineRock, Collider[]> RockAreas = AccessTools.FieldRefAccess<MineRock, Collider[]>("m_hitAreas");

		private static readonly MethodInfo RockAreaIndex = AccessTools.Method(typeof(MineRock), "GetAreaIndex", (Type[])null, (Type[])null);

		private static readonly FieldRef<MineRock5, ZNetView> Rock5View = AccessTools.FieldRefAccess<MineRock5, ZNetView>("m_nview");

		private static readonly MethodInfo Rock5AreaIndex = AccessTools.Method(typeof(MineRock5), "GetAreaIndex", (Type[])null, (Type[])null);

		private static readonly FieldInfo Rock5Areas = AccessTools.Field(typeof(MineRock5), "m_hitAreas");

		private static readonly Type Rock5HitAreaType = typeof(MineRock5).GetNestedType("HitArea", BindingFlags.NonPublic);

		private static readonly FieldInfo Rock5ColliderField = ((Rock5HitAreaType != null) ? Rock5HitAreaType.GetField("m_collider") : null);

		private static int splashFrame = -1;

		private static int splashRock;

		private static ZDOID splashAttacker = ZDOID.None;

		private const float ExtraDurabilityFactor = 0.25f;

		private static bool Active(HitData hit)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			Plugin instance = Plugin.Instance;
			if ((Object)(object)instance == (Object)null || !instance.Settings.MiningWide.Value)
			{
				return false;
			}
			if (hit == null || (int)hit.m_skill != 12)
			{
				return false;
			}
			Player localPlayer = Player.m_localPlayer;
			if ((Object)(object)localPlayer == (Object)null)
			{
				return false;
			}
			try
			{
				if ((Object)(object)hit.GetAttacker() != (Object)(object)localPlayer)
				{
					return false;
				}
			}
			catch
			{
				return false;
			}
			return true;
		}

		private static bool Claim(GameObject rock, ZDOID attacker)
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: 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)
			int num = (((Object)(object)rock != (Object)null) ? ((Object)rock).GetInstanceID() : 0);
			if (num == 0)
			{
				return false;
			}
			if (splashFrame == Time.frameCount && splashRock == num && ((ZDOID)(ref splashAttacker)).Equals(attacker))
			{
				return false;
			}
			splashFrame = Time.frameCount;
			splashRock = num;
			splashAttacker = attacker;
			return true;
		}

		private static void Splash(int count, int struck, Func<int, bool> alive, Action<int, HitData> send, HitData hit)
		{
			Plugin instance = Plugin.Instance;
			float num = Mathf.Clamp(instance.Settings.MiningDamage.Value, 0f, 1f);
			if (num <= 0f)
			{
				return;
			}
			int num2 = 0;
			for (int i = 0; i < count; i++)
			{
				if (i != struck && alive(i))
				{
					HitData val = hit.Clone();
					((DamageTypes)(ref val.m_damage)).Modify(num);
					try
					{
						send(i, val);
					}
					catch
					{
						continue;
					}
					num2++;
				}
			}
			if (num2 > 0 && instance.Settings.MiningDurability.Value)
			{
				DrainWeapon(num2);
			}
		}

		private static void DrainWeapon(int extra)
		{
			Player localPlayer = Player.m_localPlayer;
			if (!((Object)(object)localPlayer == (Object)null))
			{
				ItemData currentWeapon = ((Humanoid)localPlayer).GetCurrentWeapon();
				if (currentWeapon != null && currentWeapon.m_shared != null && currentWeapon.m_shared.m_useDurability)
				{
					currentWeapon.m_durability -= (float)extra * currentWeapon.m_shared.m_useDurabilityDrain * Game.m_durabilityRate * 0.25f;
				}
			}
		}

		internal static void SplashRock(MineRock rock, HitData hit)
		{
			//IL_00ce: 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)
			if ((Object)(object)rock == (Object)null || !Active(hit))
			{
				return;
			}
			ZNetView view;
			Collider[] areas;
			try
			{
				view = RockView.Invoke(rock);
				areas = RockAreas.Invoke(rock);
			}
			catch
			{
				return;
			}
			if ((Object)(object)view == (Object)null || !view.IsValid() || view.GetZDO() == null || areas == null || areas.Length < 2)
			{
				return;
			}
			int num = -1;
			try
			{
				if ((Object)(object)hit.m_hitCollider != (Object)null)
				{
					num = (int)RockAreaIndex.Invoke(rock, new object[1] { hit.m_hitCollider });
				}
			}
			catch
			{
				num = -1;
			}
			if (num < 0 || num >= areas.Length)
			{
				num = NearestRockArea(areas, hit.m_point);
			}
			if (Claim(((Component)rock).gameObject, hit.m_attacker))
			{
				ZDO zdo = view.GetZDO();
				float baseHealth = rock.m_health;
				Splash(areas.Length, num, (int i) => i < areas.Length && (Object)(object)areas[i] != (Object)null && zdo.GetFloat("Health" + i, baseHealth) > 0f, delegate(int i, HitData clone)
				{
					view.InvokeRPC("Hit", new object[2] { clone, i });
				}, hit);
			}
		}

		internal static void SplashRock5(MineRock5 rock, HitData hit)
		{
			//IL_00cd: 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)
			if ((Object)(object)rock == (Object)null || !Active(hit))
			{
				return;
			}
			ZNetView view;
			try
			{
				view = Rock5View.Invoke(rock);
			}
			catch
			{
				return;
			}
			if ((Object)(object)view == (Object)null || !view.IsValid() || view.GetZDO() == null)
			{
				return;
			}
			float[] healths = Rock5Healths(view);
			int num = ((healths != null) ? healths.Length : Rock5ListCount(rock));
			if (num < 2)
			{
				return;
			}
			int num2 = -1;
			try
			{
				if ((Object)(object)hit.m_hitCollider != (Object)null)
				{
					num2 = (int)Rock5AreaIndex.Invoke(rock, new object[1] { hit.m_hitCollider });
				}
			}
			catch
			{
				num2 = -1;
			}
			if (num2 < 0 || num2 >= num)
			{
				num2 = NearestRock5Area(rock, num, hit.m_point);
			}
			if (!Claim(((Component)rock).gameObject, hit.m_attacker))
			{
				return;
			}
			float fallback = rock.m_health;
			Splash(num, num2, delegate(int i)
			{
				if (healths == null)
				{
					return fallback > 0f;
				}
				return i < healths.Length && healths[i] > 0f;
			}, delegate(int i, HitData clone)
			{
				view.InvokeRPC("RPC_Damage", new object[2] { clone, i });
			}, hit);
		}

		private static int NearestRockArea(Collider[] areas, Vector3 point)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			int result = -1;
			float num = float.MaxValue;
			for (int i = 0; i < areas.Length; i++)
			{
				Collider val = areas[i];
				if ((Object)(object)val == (Object)null)
				{
					continue;
				}
				try
				{
					Vector3 val2;
					try
					{
						Bounds bounds = val.bounds;
						val2 = ((Bounds)(ref bounds)).center;
					}
					catch
					{
						val2 = ((Component)val).transform.position;
					}
					Vector3 val3 = val2 - point;
					float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
					if (sqrMagnitude < num)
					{
						num = sqrMagnitude;
						result = i;
					}
				}
				catch
				{
				}
			}
			return result;
		}

		private static Collider Rock5ColliderAt(object hitArea)
		{
			try
			{
				return (Collider)((Rock5ColliderField != null) ? /*isinst with value type is only supported in some contexts*/: null);
			}
			catch
			{
				return null;
			}
		}

		private static int NearestRock5Area(MineRock5 rock, int count, Vector3 point)
		{
			//IL_006c: 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_0075: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: 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_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0060: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				if (!(Rock5Areas.GetValue(rock) is IList list))
				{
					return -1;
				}
				int num = Mathf.Min(count, list.Count);
				int result = -1;
				float num2 = float.MaxValue;
				for (int i = 0; i < num; i++)
				{
					Collider val = Rock5ColliderAt(list[i]);
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					try
					{
						Vector3 val2;
						try
						{
							Bounds bounds = val.bounds;
							val2 = ((Bounds)(ref bounds)).center;
						}
						catch
						{
							val2 = ((Component)val).transform.position;
						}
						Vector3 val3 = val2 - point;
						float sqrMagnitude = ((Vector3)(ref val3)).sqrMagnitude;
						if (sqrMagnitude < num2)
						{
							num2 = sqrMagnitude;
							result = i;
						}
					}
					catch
					{
					}
				}
				return result;
			}
			catch
			{
				return -1;
			}
		}

		private static float[] Rock5Healths(ZNetView view)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Expected O, but got Unknown
			try
			{
				string text = view.GetZDO().GetString(ZDOVars.s_health, "");
				if (text.Length == 0)
				{
					return null;
				}
				ZPackage val = new ZPackage(Convert.FromBase64String(text));
				int num = val.ReadInt();
				float[] array = new float[num];
				for (int i = 0; i < num; i++)
				{
					array[i] = val.ReadSingle();
				}
				return array;
			}
			catch
			{
				return null;
			}
		}

		private static int Rock5ListCount(MineRock5 rock)
		{
			try
			{
				return (Rock5Areas.GetValue(rock) is IList list) ? list.Count : 0;
			}
			catch
			{
				return 0;
			}
		}
	}
	[HarmonyPatch(typeof(MineRock), "Damage")]
	internal static class MineRockWidePatch
	{
		private static void Postfix(MineRock __instance, HitData hit)
		{
			MiningFeatures.SplashRock(__instance, hit);
		}
	}
	[HarmonyPatch(typeof(MineRock5), "Damage")]
	internal static class MineRock5WidePatch
	{
		private static void Postfix(MineRock5 __instance, HitData hit)
		{
			MiningFeatures.SplashRock5(__instance, hit);
		}
	}
	[HarmonyPatch(typeof(Player), "GetMaxCarryWeight")]
	internal static class WeightPatch
	{
		private static readonly FieldRef<Player, float> BaseWeight = AccessTools.FieldRefAccess<Player, float>("m_maxCarryWeight");

		private static void Prefix(Player __instance, out float __state)
		{
			__state = BaseWeight.Invoke(__instance);
			if ((Object)(object)__instance == (Object)(object)Player.m_localPlayer && Plugin.Instance.Settings.IncreaseWeight.Value)
			{
				BaseWeight.Invoke(__instance) = Mathf.Max(__state, Plugin.Instance.Settings.CarryWeight.Value);
			}
		}

		private static void Finalizer(Player __instance, float __state)
		{
			BaseWeight.Invoke(__instance) = __state;
		}
	}
	internal static class VisualFeatures
	{
		private const float ReducedScale = 0.35f;

		private static float BaseAmountScale = -1f;

		private static readonly FieldRef<ClutterSystem, GameObject> GrassRoot = AccessTools.FieldRefAccess<ClutterSystem, GameObject>("m_grassRoot");

		private static readonly FieldRef<EnvMan, GameObject[]> CurrentPSystems = AccessTools.FieldRefAccess<EnvMan, GameObject[]>("m_currentPSystems");

		internal const float FogReducedScale = 0.35f;

		private static bool GrassOff()
		{
			return Plugin.Instance.Settings.Grass.Value == GrassMode.Desativada;
		}

		private static bool FogOff()
		{
			return Plugin.Instance.Settings.Fog.Value == FogMode.Desativada;
		}

		private static bool InMistlands()
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Invalid comparison between Unknown and I4
			EnvMan instance = EnvMan.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return false;
			}
			try
			{
				return (int)instance.GetCurrentBiome() == 512;
			}
			catch
			{
				return false;
			}
		}

		private static bool IsFogSystem(GameObject go)
		{
			if ((Object)(object)go == (Object)null)
			{
				return false;
			}
			string name = ((Object)go).name;
			if (name.IndexOf("fog", StringComparison.OrdinalIgnoreCase) < 0)
			{
				return name.IndexOf("mist", StringComparison.OrdinalIgnoreCase) >= 0;
			}
			return true;
		}

		private static void SetFogParticles(bool enabled, bool clear)
		{
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			EnvMan instance = EnvMan.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			GameObject[] array;
			try
			{
				array = CurrentPSystems.Invoke(instance);
			}
			catch
			{
				return;
			}
			if (array == null)
			{
				return;
			}
			GameObject[] array2 = array;
			foreach (GameObject val in array2)
			{
				if ((Object)(object)val == (Object)null || !IsFogSystem(val))
				{
					continue;
				}
				ParticleSystem[] componentsInChildren = val.GetComponentsInChildren<ParticleSystem>(true);
				if (componentsInChildren != null)
				{
					ParticleSystem[] array3 = componentsInChildren;
					foreach (ParticleSystem val2 in array3)
					{
						if ((Object)(object)val2 == (Object)null)
						{
							continue;
						}
						EmissionModule emission = val2.emission;
						((EmissionModule)(ref emission)).enabled = enabled;
						if (clear && !enabled)
						{
							try
							{
								val2.Clear();
							}
							catch
							{
							}
						}
					}
				}
				MistEmitter[] componentsInChildren2 = val.GetComponentsInChildren<MistEmitter>(true);
				if (componentsInChildren2 == null)
				{
					continue;
				}
				MistEmitter[] array4 = componentsInChildren2;
				foreach (MistEmitter val3 in array4)
				{
					if (!((Object)(object)val3 == (Object)null))
					{
						try
						{
							((Behaviour)val3).enabled = enabled;
						}
						catch
						{
						}
					}
				}
			}
		}

		internal static void ApplyFog()
		{
			RenderSettings.fog = !FogOff();
			if (FogOff())
			{
				RenderSettings.fogDensity = 0f;
				if (!InMistlands())
				{
					SetFogParticles(enabled: false, clear: true);
				}
			}
			else if (!InMistlands())
			{
				SetFogParticles(enabled: true, clear: false);
			}
		}

		internal static void ApplyFogFrame()
		{
			switch (Plugin.Instance.Settings.Fog.Value)
			{
			case FogMode.Desativada:
				RenderSettings.fog = false;
				RenderSettings.fogDensity = 0f;
				if (!InMistlands())
				{
					SetFogParticles(enabled: false, clear: false);
				}
				break;
			case FogMode.Reduzida:
				RenderSettings.fogDensity *= 0.35f;
				break;
			}
		}

		internal static void ApplyGrass()
		{
			ClutterSystem instance = ClutterSystem.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				if (BaseAmountScale < 0f)
				{
					BaseAmountScale = instance.m_amountScale;
				}
				ApplyTo(instance);
			}
		}

		internal static void OnClutterAwake(ClutterSystem clutter)
		{
			BaseAmountScale = clutter.m_amountScale;
			ApplyTo(clutter);
		}

		private static void ApplyTo(ClutterSystem clutter)
		{
			GrassMode value = Plugin.Instance.Settings.Grass.Value;
			if (value == GrassMode.Desativada)
			{
				clutter.ClearAll();
				GameObject val = GrassRoot.Invoke(clutter);
				if ((Object)(object)val != (Object)null)
				{
					val.SetActive(false);
				}
				return;
			}
			clutter.m_amountScale = ((value == GrassMode.Reduzida) ? (BaseAmountScale * 0.35f) : BaseAmountScale);
			GameObject val2 = GrassRoot.Invoke(clutter);
			if ((Object)(object)val2 != (Object)null)
			{
				val2.SetActive(true);
			}
			clutter.ClearAll();
		}

		internal static void Tick()
		{
			if (FogOff())
			{
				if (RenderSettings.fog)
				{
					RenderSettings.fog = false;
				}
				if (RenderSettings.fogDensity != 0f)
				{
					RenderSettings.fogDensity = 0f;
				}
				if (!InMistlands())
				{
					SetFogParticles(enabled: false, clear: true);
				}
			}
			if (!GrassOff())
			{
				return;
			}
			ClutterSystem instance = ClutterSystem.instance;
			if (!((Object)(object)instance == (Object)null))
			{
				GameObject val = GrassRoot.Invoke(instance);
				if ((Object)(object)val != (Object)null && val.activeSelf)
				{
					instance.ClearAll();
					val.SetActive(false);
				}
			}
		}
	}
	[HarmonyPatch(typeof(EnvMan), "SetEnv")]
	internal static class FogPatch
	{
		private static void Postfix()
		{
			VisualFeatures.ApplyFogFrame();
		}
	}
	[HarmonyPatch(typeof(MenuScene), "Update")]
	internal static class MenuFogPatch
	{
		private static void Postfix()
		{
			VisualFeatures.ApplyFogFrame();
		}
	}
	[HarmonyPatch(typeof(ClutterSystem), "UpdateGrass")]
	internal static class GrassPatch
	{
		private static bool Prefix()
		{
			return Plugin.Instance.Settings.Grass.Value != GrassMode.Desativada;
		}
	}
	[HarmonyPatch(typeof(ClutterSystem), "Awake")]
	internal static class GrassAwakePatch
	{
		private static void Postfix(ClutterSystem __instance)
		{
			VisualFeatures.OnClutterAwake(__instance);
		}
	}
	internal sealed class HudClock : IDisposable
	{
		private readonly Plugin plugin;

		private GameObject panel;

		private Text text;

		private Transform parent;

		private float nextUpdate;

		private string shown = "";

		private int shownFont;

		private bool shownLocal;

		internal HudClock(Plugin plugin)
		{
			this.plugin = plugin;
		}

		private void Ensure(Transform root)
		{
			//IL_0159: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Expected O, but got Unknown
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)panel != (Object)null) || !((Object)(object)parent == (Object)(object)root))
			{
				Dispose();
				parent = root;
				panel = new GameObject("Wayfarer.Clock", new Type[1] { typeof(RectTransform) });
				panel.layer = 5;
				RectTransform component = panel.GetComponent<RectTransform>();
				((Transform)component).SetParent(root, false);
				Vector2 val = default(Vector2);
				((Vector2)(ref val))..ctor(0.5f, 0f);
				component.anchorMax = val;
				component.anchorMin = val;
				component.pivot = new Vector2(0.5f, 1f);
				component.anchoredPosition = new Vector2(0f, -10f);
				component.sizeDelta = new Vector2(220f, 40f);
				text = panel.AddComponent<Text>();
				text.alignment = (TextAnchor)1;
				text.horizontalOverflow = (HorizontalWrapMode)1;
				text.verticalOverflow = (VerticalWrapMode)1;
				text.supportRichText = false;
				((Graphic)text).raycastTarget = false;
				try
				{
					GUIManager.Instance.ApplyTextStyle(text, GUIManager.Instance.AveriaSerif, GUIManager.Instance.ValheimBeige, plugin.Settings.ClockFontSize.Value, true);
				}
				catch
				{
					((Graphic)text).color = Color.white;
					text.fontSize = plugin.Settings.ClockFontSize.Value;
				}
				shown = "";
			}
		}

		internal void Tick()
		{
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b2: Expected O, but got Unknown
			//IL_02c6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02e8: Unknown result type (might be due to invalid IL or missing references)
			Settings settings = plugin.Settings;
			Minimap instance = Minimap.instance;
			if (!settings.ClockEnabled.Value || (Object)(object)instance == (Object)null || (Object)(object)instance.m_smallRoot == (Object)null || !instance.m_smallRoot.activeSelf || (Object)(object)EnvMan.instance == (Object)null || (Object)(object)ZNet.instance == (Object)null || Hud.IsUserHidden())
			{
				if ((Object)(object)panel != (Object)null)
				{
					panel.SetActive(false);
				}
				return;
			}
			Ensure(instance.m_smallRoot.transform);
			if ((Object)(object)panel == (Object)null || (Object)(object)this.text == (Object)null)
			{
				return;
			}
			if (!panel.activeSelf)
			{
				panel.SetActive(true);
			}
			bool value = settings.ShowLocalTime.Value;
			int num = Mathf.Clamp(settings.ClockFontSize.Value, 10, 32);
			float num2 = Mathf.Clamp(settings.ClockInterval.Value, 0.25f, 5f);
			if (Time.unscaledTime < nextUpdate && shown.Length > 0 && shownFont == num && shownLocal == value)
			{
				return;
			}
			nextUpdate = Time.unscaledTime + num2;
			double timeSeconds = ZNet.instance.GetTimeSeconds();
			long num3 = EnvMan.instance.m_dayLengthSec;
			if (num3 <= 0)
			{
				num3 = 1800L;
			}
			int day = EnvMan.instance.GetDay(timeSeconds);
			float num4 = (float)(timeSeconds % (double)num3) / (float)num3;
			if (num4 < 0f)
			{
				num4 += 1f;
			}
			int num5 = Mathf.FloorToInt(num4 * 24f);
			num5 = Mathf.Clamp(num5, 0, 23);
			int num6 = Mathf.Clamp(Mathf.FloorToInt((num4 * 24f - (float)num5) * 60f), 0, 59);
			string text;
			if (settings.Clock24h.Value)
			{
				text = num5.ToString("D2") + ":" + num6.ToString("D2");
			}
			else
			{
				int num7 = num5 % 12;
				if (num7