Decompiled source of DadsBetterVal v1.2.10

DadsBetterVal.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("DadsBetterVal")]
[assembly: AssemblyProduct("DadsBetterVal")]
[assembly: AssemblyCompany("Dad_Is_Bored")]
[assembly: AssemblyFileVersion("1.2.7.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.2.7.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[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 DadsBetterVal
{
	[HarmonyPatch(typeof(Player), "Repair")]
	internal static class AreaRepair
	{
		private static readonly FieldInfo AllPieces = AccessTools.Field(typeof(Piece), "s_allPieces");

		private static readonly MethodInfo CanRemove = AccessTools.Method(typeof(Player), "CheckCanRemovePiece", new Type[1] { typeof(Piece) }, (Type[])null);

		private static bool Prefix(Player __instance, ItemData toolItem)
		{
			//IL_0038: 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_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Unknown result type (might be due to invalid IL or missing references)
			//IL_01e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0209: Unknown result type (might be due to invalid IL or missing references)
			if (!DadsBetterValPlugin.AreaRepairEnabled.Value || !__instance.InRepairMode())
			{
				return true;
			}
			Piece hoveringPiece = __instance.GetHoveringPiece();
			Vector3 val = (Object.op_Implicit((Object)(object)hoveringPiece) ? ((Component)hoveringPiece).transform.position : ((Component)__instance).transform.position);
			List<Piece> list = new List<Piece>();
			List<Piece> obj = (List<Piece>)AllPieces.GetValue(null);
			int num = LayerMask.NameToLayer("ghost");
			foreach (Piece item in obj)
			{
				if (Object.op_Implicit((Object)(object)item) && ((Component)item).gameObject.layer != num && Vector3.Distance(val, ((Component)item).transform.position) <= DadsBetterValPlugin.AreaRepairRadius.Value)
				{
					list.Add(item);
				}
			}
			int num2 = 0;
			foreach (Piece item2 in list)
			{
				if (!((Character)__instance).InPlaceMode() || !(bool)CanRemove.Invoke(__instance, new object[1] { item2 }) || !PrivateArea.CheckAccess(((Component)item2).transform.position, 0f, true, false))
				{
					continue;
				}
				if (!((Character)__instance).HaveStamina(toolItem.m_shared.m_attack.m_attackStamina) || (toolItem.m_shared.m_useDurability && toolItem.m_durability <= 0f))
				{
					break;
				}
				WearNTear component = ((Component)item2).GetComponent<WearNTear>();
				if (Object.op_Implicit((Object)(object)component) && component.Repair())
				{
					num2++;
					((Character)__instance).UseStamina(toolItem.m_shared.m_attack.m_attackStamina);
					((Character)__instance).UseEitr(toolItem.m_shared.m_attack.m_attackEitr);
					if (toolItem.m_shared.m_useDurability)
					{
						toolItem.m_durability -= toolItem.m_shared.m_useDurabilityDrain;
					}
					item2.m_placeEffect.Create(((Component)item2).transform.position, ((Component)item2).transform.rotation, (Transform)null, 1f, -1, default(ZDOID));
				}
			}
			((Character)__instance).Message((MessageType)1, $"{num2} pieces repaired", 0, (Sprite)null, false);
			return false;
		}
	}
	[HarmonyPatch(typeof(Smelter))]
	internal static class BetterSmelting
	{
		private sealed class CachedPrefab
		{
			internal string Name = string.Empty;
		}

		private static readonly ConditionalWeakTable<Smelter, CachedPrefab> PrefabNames = new ConditionalWeakTable<Smelter, CachedPrefab>();

		private static string Prefab(Smelter s)
		{
			return PrefabNames.GetValue(s, (Smelter smelter) => new CachedPrefab
			{
				Name = Utils.GetPrefabName(((Component)smelter).gameObject).ToLowerInvariant()
			}).Name;
		}

		private static bool Blast(Smelter s)
		{
			return Prefab(s).Contains("blastfurnace");
		}

		private static bool AlternativeFuelMachine(Smelter s)
		{
			string text = Prefab(s);
			if (!text.Contains("smelter"))
			{
				return text.Contains("blastfurnace");
			}
			return true;
		}

		private static int QueueSize(ZNetView view)
		{
			if (!((Object)(object)view != (Object)null) || !view.IsValid())
			{
				return 0;
			}
			return view.GetZDO().GetInt(ZDOVars.s_queued, 0);
		}

		private static float FuelAmount(ZNetView view)
		{
			if (!((Object)(object)view != (Object)null) || !view.IsValid())
			{
				return 0f;
			}
			return view.GetZDO().GetFloat(ZDOVars.s_fuel, 0f);
		}

		private static ItemData? Cookable(Smelter smelter, Inventory inventory)
		{
			foreach (ItemConversion item2 in smelter.m_conversion)
			{
				if (Object.op_Implicit((Object)(object)item2?.m_from))
				{
					ItemData item = inventory.GetItem(item2.m_from.m_itemData.m_shared.m_name, -1, false);
					if (item != null)
					{
						return item;
					}
				}
			}
			return null;
		}

		private static bool FuelMatches(Smelter s, ItemData? item)
		{
			if (!DadsBetterValPlugin.AlternativeFuel.Value || item == null)
			{
				return false;
			}
			string obj = (Blast(s) ? DadsBetterValPlugin.BlastFuelItems.Value : DadsBetterValPlugin.SmelterFuelItems.Value);
			string value = (Object.op_Implicit((Object)(object)item.m_dropPrefab) ? ((Object)item.m_dropPrefab).name : "");
			string[] array = obj.Split(new char[1] { ',' });
			for (int i = 0; i < array.Length; i++)
			{
				string text = array[i].Trim();
				if (text.Equals(value, StringComparison.OrdinalIgnoreCase) || text.Equals(item.m_shared.m_name, StringComparison.OrdinalIgnoreCase))
				{
					return true;
				}
			}
			return false;
		}

		private static int FuelValue(ItemData item)
		{
			string text = (Object.op_Implicit((Object)(object)item.m_dropPrefab) ? ((Object)item.m_dropPrefab).name : item.m_shared.m_name).ToLowerInvariant();
			if (text.Contains("blackcore") || text.Contains("black_core"))
			{
				return DadsBetterValPlugin.BlackCoreFuel.Value;
			}
			if (text.Contains("surtling"))
			{
				return DadsBetterValPlugin.SurtlingCoreFuel.Value;
			}
			if (text.Contains("finewood") || text.Contains("fine_wood"))
			{
				return DadsBetterValPlugin.FineWoodFuel.Value;
			}
			if (text.Contains("roundlog") || text.Contains("corewood") || text.Contains("core_wood"))
			{
				return DadsBetterValPlugin.CoreWoodFuel.Value;
			}
			if (text.Contains("wood"))
			{
				return DadsBetterValPlugin.WoodFuel.Value;
			}
			return 1;
		}

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostfix(Smelter __instance)
		{
			string text = Prefab(__instance);
			if (text == "charcoal_kiln")
			{
				SetOre(__instance, DadsBetterValPlugin.KilnInput.Value);
			}
			else if (Object.op_Implicit((Object)(object)__instance.m_windmill))
			{
				SetOre(__instance, DadsBetterValPlugin.WindmillInput.Value);
			}
			else if (text == "piece_spinningwheel")
			{
				SetOre(__instance, DadsBetterValPlugin.SpinningInput.Value);
			}
			else if (text == "eitrrefinery")
			{
				SetOre(__instance, DadsBetterValPlugin.EitrInput.Value);
				SetFuel(__instance, DadsBetterValPlugin.EitrFuel.Value);
			}
			else if (Blast(__instance))
			{
				SetOre(__instance, DadsBetterValPlugin.BlastOre.Value);
				SetFuel(__instance, DadsBetterValPlugin.BlastFuel.Value);
				AddNormalConversions(__instance);
			}
			else if (text.Contains("smelter"))
			{
				SetOre(__instance, DadsBetterValPlugin.SmelterOre.Value);
				SetFuel(__instance, DadsBetterValPlugin.SmelterFuel.Value);
			}
		}

		private static void SetOre(Smelter s, int value)
		{
			if (value > 0)
			{
				s.m_maxOre = value;
			}
		}

		private static void SetFuel(Smelter s, int value)
		{
			if (value > 0)
			{
				s.m_maxFuel = value;
			}
		}

		private static void AddNormalConversions(Smelter blast)
		{
			if (!DadsBetterValPlugin.AllOresInBlast.Value)
			{
				return;
			}
			HashSet<string> hashSet = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
			foreach (ItemConversion item in blast.m_conversion)
			{
				if (Object.op_Implicit((Object)(object)item?.m_from))
				{
					hashSet.Add(item.m_from.m_itemData.m_shared.m_name);
				}
			}
			Smelter[] array = Resources.FindObjectsOfTypeAll<Smelter>();
			foreach (Smelter val in array)
			{
				if (!Prefab(val).Contains("smelter") || Blast(val))
				{
					continue;
				}
				{
					foreach (ItemConversion item2 in val.m_conversion)
					{
						if (Object.op_Implicit((Object)(object)item2?.m_from) && hashSet.Add(item2.m_from.m_itemData.m_shared.m_name))
						{
							blast.m_conversion.Add(item2);
						}
					}
					break;
				}
			}
		}

		[HarmonyPatch("GetDeltaTime")]
		[HarmonyPostfix]
		private static void DeltaPostfix(Smelter __instance, ref double __result)
		{
			string text = Prefab(__instance);
			float num = DadsBetterValPlugin.GlobalSpeed.Value;
			if (text == "charcoal_kiln")
			{
				num *= (float)DadsBetterValPlugin.KilnSpeed.Value;
			}
			else if (Object.op_Implicit((Object)(object)__instance.m_windmill))
			{
				num *= (float)DadsBetterValPlugin.WindmillSpeed.Value;
			}
			else if (text == "piece_spinningwheel")
			{
				num *= (float)DadsBetterValPlugin.SpinningSpeed.Value;
			}
			else if (text == "eitrrefinery")
			{
				num *= (float)DadsBetterValPlugin.EitrSpeed.Value;
			}
			else if (Blast(__instance))
			{
				num *= (float)DadsBetterValPlugin.BlastSpeed.Value;
			}
			else if (text.Contains("smelter"))
			{
				num *= (float)DadsBetterValPlugin.SmelterSpeed.Value;
			}
			__result *= num;
		}

		[HarmonyPatch("OnAddOre")]
		[HarmonyPrefix]
		private static bool AddOrePrefix(Smelter __instance, Humanoid user, ZNetView ___m_nview, ref bool __result)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			if (!DadsBetterValPlugin.QuickInsert.Value || !Input.GetKey(DadsBetterValPlugin.QuickInsertKey.Value))
			{
				return true;
			}
			int num = 0;
			Inventory inventory = user.GetInventory();
			int num2 = Math.Max(0, __instance.m_maxOre - QueueSize(___m_nview));
			while (num2-- > 0)
			{
				ItemData val = Cookable(__instance, inventory);
				if (val == null || !inventory.RemoveItem(val, 1))
				{
					break;
				}
				___m_nview.InvokeRPC("RPC_AddOre", new object[2]
				{
					((Object)val.m_dropPrefab).name,
					val.m_cheated
				});
				num++;
			}
			if (num == 0)
			{
				return true;
			}
			((Character)user).Message((MessageType)2, $"Added {num}", 0, (Sprite)null, false);
			__result = true;
			return false;
		}

		[HarmonyPatch("OnAddFuel")]
		[HarmonyPrefix]
		private static bool AddFuelPrefix(Smelter __instance, Humanoid user, ItemData? item, ZNetView ___m_nview, ref bool __result)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			bool flag = DadsBetterValPlugin.QuickInsert.Value && Input.GetKey(DadsBetterValPlugin.QuickInsertKey.Value);
			bool flag2 = DadsBetterValPlugin.AlternativeFuel.Value && AlternativeFuelMachine(__instance);
			if (!flag && !flag2)
			{
				return true;
			}
			Inventory inventory = user.GetInventory();
			int num = 0;
			int num2 = Math.Max(0, __instance.m_maxFuel - Mathf.CeilToInt(FuelAmount(___m_nview)));
			while (num2-- > 0)
			{
				ItemData val = item;
				if (val != null && val.m_shared.m_name != __instance.m_fuelItem.m_itemData.m_shared.m_name && !FuelMatches(__instance, val))
				{
					val = null;
				}
				if (val == null || !inventory.ContainsItem(val))
				{
					val = null;
					foreach (ItemData allItem in inventory.GetAllItems())
					{
						if (allItem.m_shared.m_name == __instance.m_fuelItem.m_itemData.m_shared.m_name || FuelMatches(__instance, allItem))
						{
							val = allItem;
							break;
						}
					}
				}
				if (val == null || (!FuelMatches(__instance, val) && val.m_shared.m_name != __instance.m_fuelItem.m_itemData.m_shared.m_name) || !inventory.RemoveItem(val, 1))
				{
					break;
				}
				int num3 = Math.Min((!FuelMatches(__instance, val)) ? 1 : Math.Max(1, FuelValue(val)), num2 + 1);
				for (int i = 0; i < num3; i++)
				{
					___m_nview.InvokeRPC("RPC_AddFuel", Array.Empty<object>());
				}
				num += num3;
				num2 -= num3 - 1;
				if (!flag)
				{
					break;
				}
				item = null;
			}
			if (num == 0)
			{
				return true;
			}
			((Character)user).Message((MessageType)2, $"Added {num} fuel", 0, (Sprite)null, false);
			__result = true;
			return false;
		}
	}
	[HarmonyPatch(typeof(Beehive), "Awake")]
	internal static class BeehivePatch
	{
		private static void Postfix(Beehive __instance)
		{
			if (DadsBetterValPlugin.HoneyMax.Value > 0)
			{
				__instance.m_maxHoney = DadsBetterValPlugin.HoneyMax.Value;
			}
			__instance.m_secPerUnit /= (float)DadsBetterValPlugin.HoneySpeed.Value;
		}
	}
	[HarmonyPatch(typeof(SapCollector), "Awake")]
	internal static class SapExtractorPatch
	{
		private static void Postfix(SapCollector __instance)
		{
			if (DadsBetterValPlugin.SapExtractorCapacity.Value > 0)
			{
				__instance.m_maxLevel = DadsBetterValPlugin.SapExtractorCapacity.Value;
			}
			__instance.m_secPerUnit /= (float)DadsBetterValPlugin.SapExtractorSpeed.Value;
		}
	}
	[HarmonyPatch(typeof(Fermenter), "Awake")]
	internal static class FermenterPatch
	{
		private static void Postfix(Fermenter __instance)
		{
			__instance.m_fermentationDuration /= (float)DadsBetterValPlugin.FermenterSpeed.Value;
		}
	}
	[HarmonyPatch(typeof(Windmill), "GetPowerOutput")]
	internal static class WindmillPatch
	{
		private static void Postfix(ref float __result)
		{
			if (DadsBetterValPlugin.WindmillIgnoresWind.Value)
			{
				__result = 1f;
			}
		}
	}
	[HarmonyPatch(typeof(CookingStation))]
	internal static class StoneOvenPatch
	{
		private static bool IsStoneOven(CookingStation station)
		{
			return Utils.GetPrefabName(((Component)station).gameObject).Equals("piece_oven", StringComparison.OrdinalIgnoreCase);
		}

		[HarmonyPatch("Awake")]
		[HarmonyPrefix]
		private static void AwakePrefix(CookingStation __instance)
		{
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			if (!IsStoneOven(__instance))
			{
				return;
			}
			Transform[] slots = __instance.m_slots;
			int value = DadsBetterValPlugin.StoneOvenCapacity.Value;
			if (slots != null && slots.Length != 0 && value > slots.Length)
			{
				Transform[] array = (Transform[])(object)new Transform[value];
				Array.Copy(slots, array, slots.Length);
				for (int i = slots.Length; i < array.Length; i++)
				{
					Transform val = slots[i % slots.Length];
					Transform val2 = Object.Instantiate<Transform>(val, val.parent);
					((Object)val2).name = $"DadsBetterVal_OvenSlot_{i}";
					val2.localPosition = val.localPosition + Vector3.back * (0.18f * (float)(i / slots.Length));
					array[i] = val2;
				}
				__instance.m_slots = array;
			}
		}

		[HarmonyPatch("GetDeltaTime")]
		[HarmonyPostfix]
		private static void DeltaPostfix(CookingStation __instance, ref float __result)
		{
			if (IsStoneOven(__instance))
			{
				__result *= DadsBetterValPlugin.StoneOvenSpeed.Value;
			}
		}
	}
	[HarmonyPatch(typeof(Location), "IsInsideNoBuildLocation")]
	internal static class NoBuildZonePatch
	{
		private static void Postfix(ref bool __result)
		{
			if (DadsBetterValPlugin.BuildRestrictionsRemoved.Value)
			{
				__result = false;
			}
		}
	}
	[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
	internal static class PlacementPatch
	{
		private static readonly MethodInfo SetValid = AccessTools.Method(typeof(Player), "SetPlacementGhostValid", new Type[1] { typeof(bool) }, (Type[])null);

		private static void Postfix(Player __instance, GameObject ___m_placementGhost, ref PlacementStatus ___m_placementStatus)
		{
			if (DadsBetterValPlugin.BuildRestrictionsRemoved.Value && Object.op_Implicit((Object)(object)___m_placementGhost))
			{
				___m_placementStatus = (PlacementStatus)0;
				SetValid.Invoke(__instance, new object[1] { true });
			}
		}
	}
	[HarmonyPatch(typeof(CraftingStation), "HaveBuildStationInRange")]
	internal static class StationRangePatch
	{
		private static CraftingStation? _station;

		private static void Postfix(string name, ref CraftingStation __result)
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (DadsBetterValPlugin.BuildRestrictionsRemoved.Value && !Object.op_Implicit((Object)(object)__result))
			{
				if (!Object.op_Implicit((Object)(object)_station))
				{
					_station = new GameObject("DadsBetterVal unrestricted station")
					{
						hideFlags = (HideFlags)61
					}.AddComponent<CraftingStation>();
				}
				_station.m_name = name;
				__result = _station;
			}
		}
	}
	[HarmonyPatch(typeof(Plant), "UpdateHealth")]
	internal static class CropGrowingRestrictionsPatch
	{
		private static void Postfix(Plant __instance, ref Status ___m_status)
		{
			if (DadsBetterValPlugin.BypassCropGrowingRestrictions.Value && __instance.m_needCultivatedGround)
			{
				___m_status = (Status)0;
			}
		}
	}
	[HarmonyPatch(typeof(Hud), "Awake")]
	internal static class ClockHud
	{
		private sealed class ClockDisplay : MonoBehaviour
		{
			private GUIStyle? _style;

			private void OnGUI()
			{
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f2: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Unknown result type (might be due to invalid IL or missing references)
				//IL_0046: Unknown result type (might be due to invalid IL or missing references)
				//IL_004d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0059: Expected O, but got Unknown
				if (DadsBetterValPlugin.ClockEnabled.Value && !((Object)(object)EnvMan.instance == (Object)null) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Hud.IsUserHidden())
				{
					if (_style == null)
					{
						_style = new GUIStyle(GUI.skin.label)
						{
							alignment = (TextAnchor)1,
							fontStyle = (FontStyle)1
						};
					}
					_style.fontSize = DadsBetterValPlugin.ClockFontSize.Value;
					_style.normal.textColor = Color.white;
					float dayFraction = EnvMan.instance.GetDayFraction();
					DateTime dateTime = DateTime.Today.AddHours((double)dayFraction * 24.0);
					string text = DadsBetterValPlugin.ClockFormat.Value.Replace("DAY", EnvMan.instance.GetDay().ToString());
					GUI.Label(new Rect((float)Screen.width * 0.35f, 8f, (float)Screen.width * 0.3f, 60f), dateTime.ToString(text), _style);
				}
			}
		}

		private static void Postfix(Hud __instance)
		{
			if ((Object)(object)((Component)__instance).GetComponent<ClockDisplay>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<ClockDisplay>();
			}
		}
	}
	[BepInPlugin("com.dadisbored.dadsbetterval", "DadsBetterVal", "1.2.10")]
	public sealed class DadsBetterValPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.dadisbored.dadsbetterval";

		public const string Name = "DadsBetterVal";

		public const string Version = "1.2.10";

		internal static DadsBetterValPlugin Instance;

		internal static ConfigEntry<bool> AreaRepairEnabled;

		internal static ConfigEntry<float> AreaRepairRadius;

		internal static ConfigEntry<bool> RecycleEnabled;

		internal static ConfigEntry<KeyCode> RecycleKey;

		internal static ConfigEntry<float> RecycleRate;

		internal static ConfigEntry<bool> ClockEnabled;

		internal static ConfigEntry<string> ClockFormat;

		internal static ConfigEntry<int> ClockFontSize;

		internal static ConfigEntry<bool> BuildRestrictionsRemoved;

		internal static ConfigEntry<bool> BypassCropGrowingRestrictions;

		internal static ConfigEntry<int> SmelterOre;

		internal static ConfigEntry<int> SmelterFuel;

		internal static ConfigEntry<int> BlastOre;

		internal static ConfigEntry<int> BlastFuel;

		internal static ConfigEntry<int> KilnInput;

		internal static ConfigEntry<int> WindmillInput;

		internal static ConfigEntry<int> SpinningInput;

		internal static ConfigEntry<int> EitrInput;

		internal static ConfigEntry<int> EitrFuel;

		internal static ConfigEntry<int> HoneyMax;

		internal static ConfigEntry<int> SapExtractorCapacity;

		internal static ConfigEntry<int> StoneOvenCapacity;

		internal static ConfigEntry<int> GlobalSpeed;

		internal static ConfigEntry<int> SmelterSpeed;

		internal static ConfigEntry<int> BlastSpeed;

		internal static ConfigEntry<int> KilnSpeed;

		internal static ConfigEntry<int> WindmillSpeed;

		internal static ConfigEntry<int> SpinningSpeed;

		internal static ConfigEntry<int> EitrSpeed;

		internal static ConfigEntry<int> FermenterSpeed;

		internal static ConfigEntry<int> HoneySpeed;

		internal static ConfigEntry<int> SapExtractorSpeed;

		internal static ConfigEntry<int> StoneOvenSpeed;

		internal static ConfigEntry<bool> AllOresInBlast;

		internal static ConfigEntry<bool> WindmillIgnoresWind;

		internal static ConfigEntry<bool> QuickInsert;

		internal static ConfigEntry<bool> AlternativeFuel;

		internal static ConfigEntry<KeyCode> QuickInsertKey;

		internal static ConfigEntry<string> SmelterFuelItems;

		internal static ConfigEntry<string> BlastFuelItems;

		internal static ConfigEntry<int> WoodFuel;

		internal static ConfigEntry<int> FineWoodFuel;

		internal static ConfigEntry<int> CoreWoodFuel;

		internal static ConfigEntry<int> SurtlingCoreFuel;

		internal static ConfigEntry<int> BlackCoreFuel;

		private Harmony _harmony;

		private void Awake()
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Expected O, but got Unknown
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: 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_027b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0285: Expected O, but got Unknown
			//IL_049b: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a5: Expected O, but got Unknown
			Instance = this;
			AreaRepairEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Area Repair", "Enabled", true, "Repair every valid placed piece within the configured radius.");
			AreaRepairRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Area Repair", "Radius", 15f, new ConfigDescription("Repair radius in metres.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 100f), Array.Empty<object>()));
			RecycleEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Recycle and Reclaim", "Enabled", true, "Recycle the inventory item under the pointer.");
			RecycleKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Recycle and Reclaim", "Recycle Key", (KeyCode)127, "Recycle the inventory item under the pointer while inventory is open.");
			RecycleRate = ((BaseUnityPlugin)this).Config.Bind<float>("Recycle and Reclaim", "Return Rate", 0.5f, new ConfigDescription("Fraction of recipe materials returned.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			ClockEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Clock", "Enabled", true, "Show the in-game clock.");
			ClockFormat = ((BaseUnityPlugin)this).Config.Bind<string>("Clock", "Format", "hh:mm tt", "Clock format: HH, hh, mm, ss, tt, DAY.");
			ClockFontSize = ((BaseUnityPlugin)this).Config.Bind<int>("Clock", "Font Size", 24, new ConfigDescription("Clock text size.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(10, 72), Array.Empty<object>()));
			BuildRestrictionsRemoved = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Restrictions", "Remove All Restrictions", true, "Make placement valid in restricted locations and conditions.");
			BypassCropGrowingRestrictions = ((BaseUnityPlugin)this).Config.Bind<bool>("Build Restrictions", "Bypass Crop Growing Restrictions", false, "Allow cultivated crops to grow regardless of biome, cultivated ground, roof, spacing, or temperature.");
			SmelterOre = Capacity("Smelter Ore", 10);
			SmelterFuel = Capacity("Smelter Fuel", 20);
			BlastOre = Capacity("Blast Furnace Ore", 10);
			BlastFuel = Capacity("Blast Furnace Fuel", 20);
			KilnInput = Capacity("Charcoal Kiln Input", 0);
			WindmillInput = Capacity("Windmill Input", 0);
			SpinningInput = Capacity("Spinning Wheel Input", 0);
			EitrInput = Capacity("Eitr Refinery Input", 0);
			EitrFuel = Capacity("Eitr Refinery Fuel", 0);
			HoneyMax = Capacity("Beehive Honey", 4);
			SapExtractorCapacity = Capacity("Sap Extractor Capacity", 0);
			StoneOvenCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("Smelting - Capacity", "Stone Oven Capacity", 0, new ConfigDescription("Total stone oven cooking slots. Zero preserves the game value; values below the game value keep the existing slots.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 20), Array.Empty<object>()));
			GlobalSpeed = Speed("Global Multiplier");
			SmelterSpeed = Speed("Smelter Multiplier");
			BlastSpeed = Speed("Blast Furnace Multiplier");
			KilnSpeed = Speed("Charcoal Kiln Multiplier");
			WindmillSpeed = Speed("Windmill Multiplier");
			SpinningSpeed = Speed("Spinning Wheel Multiplier");
			EitrSpeed = Speed("Eitr Refinery Multiplier");
			FermenterSpeed = Speed("Fermenter Multiplier");
			HoneySpeed = Speed("Beehive Multiplier");
			SapExtractorSpeed = Speed("Sap Extractor Multiplier");
			StoneOvenSpeed = Speed("Stone Oven Multiplier");
			AllOresInBlast = ((BaseUnityPlugin)this).Config.Bind<bool>("Smelting", "All Ores In Blast Furnace", true, "Allow normal smelter conversions in the blast furnace.");
			WindmillIgnoresWind = ((BaseUnityPlugin)this).Config.Bind<bool>("Smelting", "Windmill Ignores Wind", false, "Run windmills at full power.");
			QuickInsert = ((BaseUnityPlugin)this).Config.Bind<bool>("Smelting", "Quick Insert", true, "Hold the configured key while using a machine to fill it.");
			QuickInsertKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Smelting", "Quick Insert Key", (KeyCode)304, "Modifier held while using a machine.");
			AlternativeFuel = ((BaseUnityPlugin)this).Config.Bind<bool>("Smelting - Alternative Fuel", "Enabled", true, "Accept configured prefab or localized item names as furnace fuel.");
			SmelterFuelItems = ((BaseUnityPlugin)this).Config.Bind<string>("Smelting - Alternative Fuel", "Smelter Fuel Items", "Coal,Wood,FineWood,RoundLog,SurtlingCore,BlackCore", "Comma-separated acceptable prefab or localized item names.");
			BlastFuelItems = ((BaseUnityPlugin)this).Config.Bind<string>("Smelting - Alternative Fuel", "Blast Furnace Fuel Items", "Coal,Wood,FineWood,RoundLog,SurtlingCore,BlackCore", "Comma-separated acceptable prefab or localized item names.");
			WoodFuel = Int("Smelting - Alternative Fuel", "Wood Fuel Value", 1);
			FineWoodFuel = Int("Smelting - Alternative Fuel", "Fine Wood Fuel Value", 2);
			CoreWoodFuel = Int("Smelting - Alternative Fuel", "Core Wood Fuel Value", 3);
			SurtlingCoreFuel = Int("Smelting - Alternative Fuel", "Surtling Core Fuel Value", 5);
			BlackCoreFuel = Int("Smelting - Alternative Fuel", "Black Core Fuel Value", 10);
			_harmony = new Harmony("com.dadisbored.dadsbetterval");
			_harmony.PatchAll();
		}

		private ConfigEntry<int> Int(string section, string key, int value)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<int>(section, key, value, new ConfigDescription("Zero preserves the game value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 10000), Array.Empty<object>()));
		}

		private ConfigEntry<int> Capacity(string key, int value)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			return ((BaseUnityPlugin)this).Config.Bind<int>("Smelting - Capacity", key, value, new ConfigDescription("Zero preserves the game value.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 1000), Array.Empty<object>()));
		}

		private ConfigEntry<int> Speed(string key)
		{
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Expected O, but got Unknown
			string text = ((key == "Global Multiplier") ? "Whole-number speed multiplier for smelters, blast furnaces, kilns, windmills, spinning wheels, and eitr refineries. Does not affect stone ovens." : ((key == "Stone Oven Multiplier") ? "Whole-number stone oven speed multiplier, independent of Global Multiplier. One is native cooking speed." : "Whole-number processing speed multiplier. Smelters, blast furnaces, kilns, windmills, spinning wheels, and eitr refineries also use Global Multiplier."));
			return ((BaseUnityPlugin)this).Config.Bind<int>("Smelting - Speed", key, 1, new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<int>(1, 100), Array.Empty<object>()));
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Update")]
	internal static class Recycling
	{
		internal static bool ReclaimMode;

		internal static Button? ReclaimButton;

		internal static readonly List<Recipe> TemporaryDeleteRecipes = new List<Recipe>();

		private static readonly MethodInfo UpdateCrafting = AccessTools.Method(typeof(InventoryGui), "UpdateCraftingPanel", new Type[1] { typeof(bool) }, (Type[])null);

		private static readonly MethodInfo AddRecipe = AccessTools.Method(typeof(InventoryGui), "AddRecipeToList", (Type[])null, (Type[])null);

		private static readonly MethodInfo SelectRecipe = AccessTools.Method(typeof(InventoryGui), "SetRecipe", (Type[])null, (Type[])null);

		private static readonly MethodInfo UpdateRecipeMethod = AccessTools.Method(typeof(InventoryGui), "UpdateRecipe", (Type[])null, (Type[])null);

		private static readonly MethodInfo HideRequirementMethod = AccessTools.Method(typeof(InventoryGui), "HideRequirement", new Type[1] { typeof(Transform) }, (Type[])null);

		private static readonly MethodInfo HoveredElement = AccessTools.Method(typeof(InventoryGrid), "GetHoveredElement", (Type[])null, (Type[])null);

		private static readonly MethodInfo ElementPosition = AccessTools.Method(typeof(InventoryGrid), "GetElementPos", (Type[])null, (Type[])null);

		private static readonly MethodInfo SetupDragItem = AccessTools.Method(typeof(InventoryGui), "SetupDragItem", new Type[3]
		{
			typeof(ItemData),
			typeof(Inventory),
			typeof(int)
		}, (Type[])null);

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

		private static readonly FieldInfo AvailableRecipes = AccessTools.Field(typeof(InventoryGui), "m_availableRecipes");

		private static readonly FieldInfo RecipeItemData = AccessTools.Field(SelectedRecipe.FieldType, "<ItemData>k__BackingField");

		private static readonly FieldInfo RecipeInterfaceElement = AccessTools.Field(SelectedRecipe.FieldType, "<InterfaceElement>k__BackingField");

		internal static ItemData? SelectedItem(InventoryGui gui)
		{
			object? value = RecipeItemData.GetValue(SelectedRecipe.GetValue(gui));
			return (ItemData?)((value is ItemData) ? value : null);
		}

		internal static IList RecipeList(InventoryGui gui)
		{
			return (IList)AvailableRecipes.GetValue(gui);
		}

		internal static GameObject? RecipeElement(object pair)
		{
			object? value = RecipeInterfaceElement.GetValue(pair);
			return (GameObject?)((value is GameObject) ? value : null);
		}

		internal static void Refresh(InventoryGui gui, bool focus = true)
		{
			UpdateCrafting.Invoke(gui, new object[1] { focus });
		}

		internal static void AddReclaimRecipe(InventoryGui gui, Player player, Recipe recipe, ItemData item)
		{
			AddRecipe.Invoke(gui, new object[4] { player, recipe, item, true });
		}

		internal static void Select(InventoryGui gui, int index)
		{
			SelectRecipe.Invoke(gui, new object[2] { index, false });
		}

		internal static void DrawRecipe(InventoryGui gui, Player player)
		{
			UpdateRecipeMethod.Invoke(gui, new object[2] { player, 0f });
		}

		internal static void HideRequirement(GameObject requirement)
		{
			HideRequirementMethod.Invoke(null, new object[1] { requirement.transform });
		}

		internal static void ClearDrag(InventoryGui gui)
		{
			SetupDragItem.Invoke(gui, new object[3] { null, null, 1 });
		}

		private static void Postfix(InventoryGui __instance, ItemData? ___m_dragItem)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Expected O, but got Unknown
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			if (!DadsBetterValPlugin.RecycleEnabled.Value || !InventoryGui.IsVisible() || !Input.GetKeyDown(DadsBetterValPlugin.RecycleKey.Value))
			{
				return;
			}
			InventoryGrid playerGrid = __instance.m_playerGrid;
			if ((Object)(object)playerGrid == (Object)null)
			{
				return;
			}
			InventoryElement val = (InventoryElement)HoveredElement.Invoke(playerGrid, Array.Empty<object>());
			if (!((Object)(object)val == (Object)null))
			{
				Vector2i val2 = (Vector2i)ElementPosition.Invoke(playerGrid, new object[1] { val });
				ItemData itemAt = playerGrid.GetInventory().GetItemAt(val2.x, val2.y);
				if (itemAt != null && !itemAt.m_equipped && Recycle(itemAt, playerGrid.GetInventory()) && itemAt == ___m_dragItem)
				{
					ClearDrag(__instance);
				}
			}
		}

		internal static bool Recycle(ItemData source, Inventory inventory)
		{
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Expected O, but got Unknown
			//IL_0133: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_0248: Unknown result type (might be due to invalid IL or missing references)
			//IL_024d: Unknown result type (might be due to invalid IL or missing references)
			ObjectDB instance = ObjectDB.instance;
			Recipe val = ((instance != null) ? instance.GetRecipe(source) : null);
			if ((Object)(object)val == (Object)null || val.m_resources == null || val.m_resources.Length == 0)
			{
				return Delete(source, inventory);
			}
			List<(GameObject, int)> list = new List<(GameObject, int)>();
			Requirement[] resources = val.m_resources;
			foreach (Requirement val2 in resources)
			{
				if (Object.op_Implicit((Object)(object)val2.m_resItem))
				{
					int num = 0;
					for (int j = 1; j <= Math.Max(1, source.m_quality); j++)
					{
						num += val2.GetAmount(j);
					}
					int num2 = Mathf.FloorToInt((float)num * DadsBetterValPlugin.RecycleRate.Value) * source.m_stack;
					if (num2 > 0)
					{
						list.Add((((Component)val2.m_resItem).gameObject, num2));
					}
				}
			}
			if (list.Count == 0)
			{
				return Delete(source, inventory);
			}
			Inventory val3 = new Inventory("DadsBetterVal preflight", (Sprite)null, inventory.GetWidth(), inventory.GetHeight());
			foreach (ItemData allItem in inventory.GetAllItems())
			{
				ItemData val4 = allItem.Clone();
				val4.m_stack = allItem.m_stack;
				if (!val3.AddItem(val4, val4.m_gridPos))
				{
					return false;
				}
			}
			ItemData itemAt = val3.GetItemAt(source.m_gridPos.x, source.m_gridPos.y);
			if (itemAt == null || !val3.RemoveItem(itemAt))
			{
				return false;
			}
			foreach (var item in list)
			{
				if (!val3.AddItem(item.Item1, item.Item2))
				{
					((Character)Player.m_localPlayer).Message((MessageType)2, "$inventory_full", 0, (Sprite)null, false);
					return false;
				}
			}
			if (!inventory.RemoveItem(source))
			{
				return false;
			}
			foreach (var item2 in list)
			{
				if (!inventory.AddItem(item2.Item1, item2.Item2))
				{
					ItemDrop.DropItem(item2.Item1.GetComponent<ItemDrop>().m_itemData, item2.Item2, ((Component)Player.m_localPlayer).transform.position + Vector3.up, Quaternion.identity);
				}
			}
			((Character)Player.m_localPlayer).Message((MessageType)2, "Item reclaimed", 0, (Sprite)null, false);
			return true;
		}

		private static bool Delete(ItemData source, Inventory inventory)
		{
			int stack = source.m_stack;
			if (!inventory.RemoveItem(source))
			{
				return false;
			}
			((Character)Player.m_localPlayer).Message((MessageType)2, (stack > 1) ? $"Deleted {stack} items" : "Item deleted", 0, (Sprite)null, false);
			return true;
		}

		internal static Recipe CreateDeleteRecipe(ItemData item)
		{
			Recipe val = ScriptableObject.CreateInstance<Recipe>();
			((Object)val).hideFlags = (HideFlags)61;
			val.m_item = item.m_dropPrefab.GetComponent<ItemDrop>();
			val.m_amount = item.m_stack;
			val.m_resources = Array.Empty<Requirement>();
			TemporaryDeleteRecipes.Add(val);
			return val;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "Awake")]
	internal static class ReclaimTabSetup
	{
		private static void Postfix(InventoryGui __instance)
		{
			//IL_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Expected O, but got Unknown
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f2: Expected O, but got Unknown
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Expected O, but got Unknown
			if (DadsBetterValPlugin.RecycleEnabled.Value && !Object.op_Implicit((Object)(object)GameObject.Find("DadsBetterVal_ReclaimTab")))
			{
				GameObject val = Object.Instantiate<GameObject>(((Component)__instance.m_tabUpgrade).gameObject, ((Component)__instance.m_tabUpgrade).transform.parent);
				((Object)val).name = "DadsBetterVal_ReclaimTab";
				RectTransform val2 = (RectTransform)val.transform;
				RectTransform val3 = (RectTransform)((Component)__instance.m_tabUpgrade).transform;
				Vector2 anchoredPosition = val3.anchoredPosition;
				Rect rect = val3.rect;
				val2.anchoredPosition = anchoredPosition + new Vector2(((Rect)(ref rect)).width + 8f, 0f);
				TMP_Text componentInChildren = val.GetComponentInChildren<TMP_Text>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.text = "Reclaim";
				}
				Button button = val.GetComponent<Button>();
				Recycling.ReclaimButton = button;
				button.onClick = new ButtonClickedEvent();
				((UnityEvent)button.onClick).AddListener((UnityAction)delegate
				{
					Recycling.ReclaimMode = true;
					((Selectable)button).interactable = false;
					Recycling.Refresh(__instance);
				});
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateCraftingPanel")]
	internal static class ReclaimListPatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			if (!Recycling.ReclaimMode || !DadsBetterValPlugin.RecycleEnabled.Value || (Object)(object)Player.m_localPlayer == (Object)null)
			{
				return;
			}
			IList list = Recycling.RecipeList(__instance);
			foreach (object item in list)
			{
				GameObject val = Recycling.RecipeElement(item);
				if (Object.op_Implicit((Object)(object)val))
				{
					Object.Destroy((Object)(object)val);
				}
			}
			list.Clear();
			foreach (Recipe temporaryDeleteRecipe in Recycling.TemporaryDeleteRecipes)
			{
				if (Object.op_Implicit((Object)(object)temporaryDeleteRecipe))
				{
					Object.Destroy((Object)(object)temporaryDeleteRecipe);
				}
			}
			Recycling.TemporaryDeleteRecipes.Clear();
			foreach (ItemData allItem in ((Humanoid)Player.m_localPlayer).GetInventory().GetAllItems())
			{
				if (!allItem.m_equipped)
				{
					Recipe recipe = ObjectDB.instance.GetRecipe(allItem) ?? Recycling.CreateDeleteRecipe(allItem);
					Recycling.AddReclaimRecipe(__instance, Player.m_localPlayer, recipe, allItem);
				}
			}
			Recycling.Select(__instance, (list.Count <= 0) ? (-1) : 0);
			Recycling.DrawRecipe(__instance, Player.m_localPlayer);
			((Selectable)__instance.m_tabCraft).interactable = true;
			((Selectable)__instance.m_tabUpgrade).interactable = true;
			if (Object.op_Implicit((Object)(object)Recycling.ReclaimButton))
			{
				((Selectable)Recycling.ReclaimButton).interactable = false;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "UpdateRecipe")]
	internal static class ReclaimDetailsPatch
	{
		private static void Postfix(InventoryGui __instance)
		{
			if (!Recycling.ReclaimMode)
			{
				return;
			}
			ItemData val = Recycling.SelectedItem(__instance);
			if (val != null)
			{
				__instance.m_recipeIcon.sprite = val.GetIcon();
				__instance.m_recipeName.text = "Reclaim " + Localization.instance.Localize(val.m_shared.m_name);
				Recipe recipe = ObjectDB.instance.GetRecipe(val);
				string text = (((Object)(object)recipe != (Object)null && recipe.m_resources != null && recipe.m_resources.Length != 0) ? "Returns configured recipe materials and removes the selected stack." : "Deletes the selected stack without material returns.");
				__instance.m_recipeDecription.text = Localization.instance.Localize(ItemData.GetTooltip(val, val.m_quality, false, (float)Game.m_worldLevel, -1, false)) + "\n\n" + text;
				TMP_Text componentInChildren = ((Component)__instance.m_craftButton).GetComponentInChildren<TMP_Text>();
				if (Object.op_Implicit((Object)(object)componentInChildren))
				{
					componentInChildren.text = "Reclaim";
				}
				((Selectable)__instance.m_craftButton).interactable = true;
				GameObject[] recipeRequirementList = __instance.m_recipeRequirementList;
				for (int i = 0; i < recipeRequirementList.Length; i++)
				{
					Recycling.HideRequirement(recipeRequirementList[i]);
				}
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnCraftPressed")]
	internal static class ReclaimActionPatch
	{
		private static bool Prefix(InventoryGui __instance)
		{
			if (!Recycling.ReclaimMode)
			{
				return true;
			}
			ItemData val = Recycling.SelectedItem(__instance);
			if (val != null && Recycling.Recycle(val, ((Humanoid)Player.m_localPlayer).GetInventory()))
			{
				Recycling.Refresh(__instance);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnTabCraftPressed")]
	internal static class ReclaimCraftTabPatch
	{
		private static void Prefix()
		{
			Recycling.ReclaimMode = false;
			if (Object.op_Implicit((Object)(object)Recycling.ReclaimButton))
			{
				((Selectable)Recycling.ReclaimButton).interactable = true;
			}
		}
	}
	[HarmonyPatch(typeof(InventoryGui), "OnTabUpgradePressed")]
	internal static class ReclaimUpgradeTabPatch
	{
		private static void Prefix()
		{
			Recycling.ReclaimMode = false;
			if (Object.op_Implicit((Object)(object)Recycling.ReclaimButton))
			{
				((Selectable)Recycling.ReclaimButton).interactable = true;
			}
		}
	}
}