Decompiled source of BetterMarketPlus v1.3.3

BepInEx/plugins/BetterMarketPlus.dll

Decompiled 2 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.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BetterMarketPlus.Compatibility;
using BetterMarketPlus.Configuration;
using BetterMarketPlus.Localization;
using BetterMarketPlus.Utils;
using HarmonyLib;
using Newtonsoft.Json;
using TMPro;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.InputSystem;
using UnityEngine.Localization;
using UnityEngine.Localization.Settings;
using UnityEngine.Localization.SmartFormat.Extensions;
using UnityEngine.Localization.SmartFormat.PersistentVariables;
using UnityEngine.Localization.Tables;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetterMarketPlus")]
[assembly: AssemblyDescription("Better Market Plus mod for Old Market Simulator by Ice Box Studio")]
[assembly: AssemblyCompany("Ice Box Studio")]
[assembly: AssemblyProduct("BetterMarketPlus")]
[assembly: AssemblyCopyright("Copyright © 2025 Ice Box Studio All rights reserved.")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("EAAD3296-E8E3-4C52-BF86-6907CB4F80E6")]
[assembly: AssemblyFileVersion("1.3.3.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.3.3.0")]
namespace BetterMarketPlus
{
	[BepInPlugin("IceBoxStudio.BetterMarketPlus", "BetterMarketPlus", "1.3.3")]
	[BepInIncompatibility("ViViKo.BetterMarket")]
	public class BetterMarketPlus : BaseUnityPlugin
	{
		public static BetterMarketPlus _Instance;

		private Harmony _harmony;

		private bool patchesApplied;

		public static BetterMarketPlus Instance => _Instance;

		internal static ManualLogSource Logger { get; private set; }

		private void Awake()
		{
			_Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			try
			{
				Logger.LogInfo((object)"=============================================");
				Logger.LogInfo((object)("BetterMarketPlus " + LocalizationManager.Instance.GetLocalizedText("plugin.initializing")));
				Logger.LogInfo((object)(LocalizationManager.Instance.GetLocalizedText("plugin.author_prefix") + "Ice Box Studio(https://steamcommunity.com/id/ibox666/)"));
				ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
				ApplyPatches();
				Logger.LogInfo((object)("BetterMarketPlus " + LocalizationManager.Instance.GetLocalizedText("plugin.initialized")));
				Logger.LogInfo((object)"=============================================");
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("BetterMarketPlus 初始化错误: " + ex.Message + "\n" + ex.StackTrace));
			}
		}

		private void ApplyPatches()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!patchesApplied)
			{
				try
				{
					_harmony = new Harmony("IceBoxStudio.BetterMarketPlus");
					_harmony.PatchAll();
					patchesApplied = true;
					return;
				}
				catch (Exception ex)
				{
					Logger.LogError((object)("BetterMarketPlus 应用补丁错误: " + ex.Message + "\n" + ex.StackTrace));
					return;
				}
			}
			Logger.LogInfo((object)LocalizationManager.Instance.GetLocalizedText("plugin.patches_skipped"));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IceBoxStudio.BetterMarketPlus";

		public const string PLUGIN_NAME = "BetterMarketPlus";

		public const string PLUGIN_VERSION = "1.3.3";

		public const string PLUGIN_AUTHOR = "Ice Box Studio";

		public const string PLUGIN_DESCRIPTION = "调整和增强原有游戏体验,增加更多新内容和功能。";
	}
}
namespace BetterMarketPlus.Utils
{
	public static class SaveSlotManager
	{
		public static void Initialize()
		{
		}
	}
	[HarmonyPatch(typeof(SaveManager), "LoadWorldData")]
	public static class SaveManagerLoadWorldDataPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			UnacceptedTaskManager.Instance.ReloadForNewSaveSlot();
		}
	}
	[HarmonyPatch(typeof(GameManager), "Awake")]
	public static class GameManagerAwakePatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			UnacceptedTaskManager.Instance.LoadMarkedExpansions();
		}
	}
	[HarmonyPatch(typeof(SaveManager), "SetCurrentSlot")]
	public static class SaveManagerSetCurrentSlotPatch
	{
		[HarmonyPostfix]
		public static void Postfix()
		{
			UnacceptedTaskManager.Instance.ReloadForNewSaveSlot();
		}
	}
	public class UnacceptedTaskManager
	{
		private static UnacceptedTaskManager _instance;

		private readonly HashSet<long> markedAdvancedExpansions = new HashSet<long>();

		private readonly Dictionary<long, ulong> markedByUsers = new Dictionary<long, ulong>();

		private readonly Dictionary<long, string> markedByUsernames = new Dictionary<long, string>();

		public static UnacceptedTaskManager Instance
		{
			get
			{
				if (_instance == null)
				{
					_instance = new UnacceptedTaskManager();
				}
				return _instance;
			}
		}

		private static string CurrentSlot
		{
			get
			{
				if ((Object)(object)SaveManager.Instance != (Object)null)
				{
					string text = AccessTools.Field(typeof(SaveManager), "currentSlot")?.GetValue(SaveManager.Instance) as string;
					if (!string.IsNullOrEmpty(text))
					{
						return text;
					}
				}
				return "slot1";
			}
		}

		private static string MarkedExpansionsFilePath => Path.Combine(Paths.ConfigPath, "BetterMarketPlus", "marked_expansions_" + CurrentSlot + ".json");

		public event Action OnMarkedExpansionsChanged;

		public event Action<long> OnToggleRequested;

		public event Action<long> OnRemoveRequested;

		public void DeleteMarkedExpansionsFileForSlot(string slot)
		{
			if (string.IsNullOrEmpty(slot))
			{
				return;
			}
			string path = Path.Combine(Paths.ConfigPath, "BetterMarketPlus", "marked_expansions_" + slot + ".json");
			if (!File.Exists(path))
			{
				return;
			}
			try
			{
				File.Delete(path);
			}
			catch
			{
			}
		}

		public void DeleteMarkedExpansionsFileForCurrentSlot()
		{
			DeleteMarkedExpansionsFileForSlot(CurrentSlot);
		}

		public bool ToggleAdvancedExpansion(long expansionId)
		{
			bool result = !markedAdvancedExpansions.Contains(expansionId);
			Action<long> onToggleRequested = this.OnToggleRequested;
			if (onToggleRequested != null)
			{
				onToggleRequested(expansionId);
				return result;
			}
			return result;
		}

		public bool IsAdvancedExpansionMarked(long expansionId)
		{
			return markedAdvancedExpansions.Contains(expansionId);
		}

		public List<long> GetMarkedAdvancedExpansionIds()
		{
			return new List<long>(markedAdvancedExpansions);
		}

		public List<AdvancedExpansionSO> GetMarkedUnlockedAdvancedExpansions()
		{
			List<AdvancedExpansionSO> list = new List<AdvancedExpansionSO>();
			if (GameManager.Instance?.expansionDatabase == null)
			{
				return list;
			}
			foreach (ExpansionSO item in GameManager.Instance.expansionDatabase)
			{
				AdvancedExpansionSO val = (AdvancedExpansionSO)(object)((item is AdvancedExpansionSO) ? item : null);
				if (val != null && markedAdvancedExpansions.Contains(item.id) && !GameManager.Instance.IsExpansionUnlocked(item.id))
				{
					list.Add(val);
				}
			}
			return list;
		}

		public bool RemoveUnlockedExpansion(long expansionId)
		{
			this.OnRemoveRequested?.Invoke(expansionId);
			return true;
		}

		public void SaveMarkedExpansions()
		{
			string directoryName = Path.GetDirectoryName(MarkedExpansionsFilePath);
			if (!Directory.Exists(directoryName))
			{
				Directory.CreateDirectory(directoryName);
			}
			string contents = JsonConvert.SerializeObject((object)new MarkedExpansionsSaveData
			{
				MarkedExpansionIds = new List<long>(markedAdvancedExpansions),
				MarkedByUsers = new Dictionary<long, ulong>(markedByUsers),
				MarkedByUsernames = new Dictionary<long, string>(markedByUsernames)
			}, (Formatting)1);
			File.WriteAllText(MarkedExpansionsFilePath, contents);
		}

		public void LoadMarkedExpansions()
		{
			if (!File.Exists(MarkedExpansionsFilePath))
			{
				return;
			}
			MarkedExpansionsSaveData markedExpansionsSaveData = JsonConvert.DeserializeObject<MarkedExpansionsSaveData>(File.ReadAllText(MarkedExpansionsFilePath));
			if (markedExpansionsSaveData?.MarkedExpansionIds == null)
			{
				return;
			}
			markedAdvancedExpansions.Clear();
			markedByUsers.Clear();
			markedByUsernames.Clear();
			foreach (long markedExpansionId in markedExpansionsSaveData.MarkedExpansionIds)
			{
				markedAdvancedExpansions.Add(markedExpansionId);
				if (markedExpansionsSaveData.MarkedByUsers != null && markedExpansionsSaveData.MarkedByUsers.TryGetValue(markedExpansionId, out var value))
				{
					markedByUsers[markedExpansionId] = value;
				}
				if (markedExpansionsSaveData.MarkedByUsernames != null && markedExpansionsSaveData.MarkedByUsernames.TryGetValue(markedExpansionId, out var value2))
				{
					markedByUsernames[markedExpansionId] = value2;
				}
			}
		}

		public void ReloadForNewSaveSlot()
		{
			markedAdvancedExpansions.Clear();
			LoadMarkedExpansions();
		}

		public void SyncFromNetwork(List<long> markedExpansionIds, List<ulong> markerUserIds, List<string> markerUsernames)
		{
			markedAdvancedExpansions.Clear();
			markedByUsers.Clear();
			markedByUsernames.Clear();
			for (int i = 0; i < markedExpansionIds.Count; i++)
			{
				long num = markedExpansionIds[i];
				markedAdvancedExpansions.Add(num);
				if (markerUserIds != null && i < markerUserIds.Count)
				{
					markedByUsers[num] = markerUserIds[i];
				}
				if (markerUsernames != null && i < markerUsernames.Count && !string.IsNullOrEmpty(markerUsernames[i]))
				{
					markedByUsernames[num] = markerUsernames[i];
				}
			}
			this.OnMarkedExpansionsChanged?.Invoke();
		}

		internal void InternalAdd(long expansionId, ulong markerUserId)
		{
			if (markedAdvancedExpansions.Contains(expansionId))
			{
				return;
			}
			markedAdvancedExpansions.Add(expansionId);
			markedByUsers[expansionId] = markerUserId;
			try
			{
				if (AccessTools.Field(typeof(GameManager), "clientIdMap")?.GetValue(GameManager.Instance) is Dictionary<ulong, ulong> dictionary)
				{
					foreach (KeyValuePair<ulong, ulong> item in dictionary)
					{
						if (item.Value == markerUserId)
						{
							string clientNickname = GameManager.Instance.GetClientNickname(item.Key);
							if (!string.IsNullOrEmpty(clientNickname))
							{
								markedByUsernames[expansionId] = clientNickname;
							}
							break;
						}
					}
				}
			}
			catch
			{
			}
			SaveMarkedExpansions();
			this.OnMarkedExpansionsChanged?.Invoke();
		}

		internal void InternalRemove(long expansionId)
		{
			if (markedAdvancedExpansions.Remove(expansionId))
			{
				markedByUsers.Remove(expansionId);
				markedByUsernames.Remove(expansionId);
				SaveMarkedExpansions();
				this.OnMarkedExpansionsChanged?.Invoke();
			}
		}

		public ulong? GetMarkerUserId(long expansionId)
		{
			if (markedByUsers.TryGetValue(expansionId, out var value))
			{
				return value;
			}
			return null;
		}

		public string GetMarkerName(long expansionId)
		{
			if (markedByUsernames.TryGetValue(expansionId, out var value))
			{
				return value;
			}
			ulong? markerUserId = GetMarkerUserId(expansionId);
			if (markerUserId.HasValue && (Object)(object)GameManager.Instance != (Object)null)
			{
				try
				{
					if (AccessTools.Field(typeof(GameManager), "clientIdMap")?.GetValue(GameManager.Instance) is Dictionary<ulong, ulong> dictionary)
					{
						foreach (KeyValuePair<ulong, ulong> item in dictionary)
						{
							if (item.Value == markerUserId.Value)
							{
								return GameManager.Instance.GetClientNickname(item.Key);
							}
						}
					}
				}
				catch
				{
				}
			}
			return null;
		}

		public void TriggerMarkedExpansionsChanged()
		{
			this.OnMarkedExpansionsChanged?.Invoke();
		}
	}
	public class MarkedExpansionsSaveData
	{
		public List<long> MarkedExpansionIds { get; set; } = new List<long>();


		public Dictionary<long, ulong> MarkedByUsers { get; set; } = new Dictionary<long, ulong>();


		public Dictionary<long, string> MarkedByUsernames { get; set; } = new Dictionary<long, string>();

	}
}
namespace BetterMarketPlus.Patches
{
	[HarmonyPatch(typeof(BlockAlcoholMachine))]
	public class BlockAlcoholMachinePatch
	{
		private static readonly FieldInfo currentOutputField = AccessTools.Field(typeof(BlockAlcoholMachine), "currentOutput");

		private static readonly FieldInfo remainingDaysField = AccessTools.Field(typeof(BlockAlcoholMachine), "remainingDays");

		private static long GetCurrentOutput(BlockAlcoholMachine instance)
		{
			object value = currentOutputField.GetValue(instance);
			return (long)value.GetType().GetProperty("Value").GetValue(value);
		}

		private static int GetRemainingDays(BlockAlcoholMachine instance)
		{
			object value = remainingDaysField.GetValue(instance);
			return (int)value.GetType().GetProperty("Value").GetValue(value);
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void Postfix(BlockAlcoholMachine __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockAlcoholMachine"))
			{
				return;
			}
			long currentOutput = GetCurrentOutput(__instance);
			int remainingDays = GetRemainingDays(__instance);
			if (currentOutput != -1)
			{
				ItemSO itemById = GameManager.Instance.GetItemById(currentOutput);
				__result = itemById.GetLocalizedName();
				if (remainingDays > 0)
				{
					string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", remainingDays);
					__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(BlockAnimal))]
	public class BlockAnimalPatch
	{
		private static readonly FieldInfo animalSOField = AccessTools.Field(typeof(BlockAnimal), "animalSO");

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void Postfix(BlockAnimal __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockAnimal"))
			{
				object? value = animalSOField.GetValue(__instance);
				AnimalSO val = (AnimalSO)((value is AnimalSO) ? value : null);
				if (__instance.dayCounter.Value < val.daysToHarvestAfterGrowth)
				{
					int days = val.daysToHarvestAfterGrowth - __instance.dayCounter.Value;
					string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", days);
					__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(BlockBeeHive))]
	public class BlockBeeHivePatch
	{
		private static readonly FieldInfo dayCounterField = AccessTools.Field(typeof(BlockBeeHive), "dayCounter");

		private static readonly FieldInfo hasBeeField = AccessTools.Field(typeof(BlockBeeHive), "hasBee");

		private static readonly FieldInfo blockBlueprintField = AccessTools.Field(typeof(PlayerInventory), "blockBlueprint");

		private static readonly Dictionary<int, RadiusVisualizer> visualizers = new Dictionary<int, RadiusVisualizer>();

		private static HashSet<int> targetedThisFrame = new HashSet<int>();

		private static HashSet<int> targetedLastFrame = new HashSet<int>();

		private static int lastUpdateFrame;

		private static readonly Dictionary<GameObject, RadiusVisualizer> ghostVisualizers = new Dictionary<GameObject, RadiusVisualizer>();

		private static int GetDayCounter(BlockBeeHive instance)
		{
			object value = dayCounterField.GetValue(instance);
			return (int)value.GetType().GetProperty("Value").GetValue(value);
		}

		private static bool GetHasBee(BlockBeeHive instance)
		{
			object value = hasBeeField.GetValue(instance);
			return (bool)value.GetType().GetProperty("Value").GetValue(value);
		}

		private static GameObject GetBlockBlueprint(PlayerInventory instance)
		{
			object? value = blockBlueprintField.GetValue(instance);
			return (GameObject)((value is GameObject) ? value : null);
		}

		private static int CountTreesAround(BlockBeeHive instance)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			int num = 0;
			Collider[] array = Physics.OverlapSphere(((Component)instance).transform.position, (float)instance.treeDetectionRadius);
			foreach (Collider val in array)
			{
				if (!val.isTrigger && (Object)(object)((Component)val).GetComponent<BlockTree>() != (Object)null)
				{
					num++;
				}
			}
			return num;
		}

		private static int CalculateHoneyOutput(int treeCount)
		{
			if (treeCount < 3)
			{
				return 1;
			}
			if (treeCount < 6)
			{
				return 2;
			}
			return 3;
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void GetDescriptionPatch(BlockBeeHive __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockBeeHiveRadius"))
			{
				int instanceID = ((Object)__instance).GetInstanceID();
				targetedThisFrame.Add(instanceID);
				if (visualizers.TryGetValue(instanceID, out var value))
				{
					value.SetTargeted(targeted: true);
				}
			}
			ConfigManager instance2 = ConfigManager.Instance;
			if (instance2 == null || instance2.IsPatchEnabled("BlockBeeHive"))
			{
				int dayCounter = GetDayCounter(__instance);
				if (GetHasBee(__instance) && dayCounter < __instance.requiredDays)
				{
					int days = __instance.requiredDays - dayCounter;
					int num = CountTreesAround(__instance);
					int num2 = CalculateHoneyOutput(num);
					string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", days);
					string localizedText = LocalizationManager.Instance.GetLocalizedText("beehive.trees", num);
					string localizedText2 = LocalizationManager.Instance.GetLocalizedText("beehive.output", num2);
					string text = localizedDaysWithPrefix + "," + localizedText + "," + localizedText2;
					__result = ((ItemSO)((Block)__instance).blockSO).GetLocalizedName() + " <i><color=yellow>[" + text + "]</color></i>";
				}
			}
		}

		[HarmonyPatch("OnNetworkSpawn")]
		[HarmonyPostfix]
		private static void OnNetworkSpawnPatch(BlockBeeHive __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockBeeHiveRadius"))
			{
				GameObject val = new GameObject($"BeeHiveRadius_{((Object)__instance).GetInstanceID()}");
				val.transform.SetParent(((Component)__instance).transform);
				val.transform.localPosition = Vector3.zero;
				RadiusVisualizer radiusVisualizer = val.AddComponent<RadiusVisualizer>();
				radiusVisualizer.Initialize(__instance.treeDetectionRadius);
				visualizers[((Object)__instance).GetInstanceID()] = radiusVisualizer;
			}
		}

		[HarmonyPatch("OnNetworkDespawn")]
		[HarmonyPostfix]
		private static void OnNetworkDespawnPatch(BlockBeeHive __instance)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			visualizers.Remove(instanceID);
			targetedThisFrame.Remove(instanceID);
			targetedLastFrame.Remove(instanceID);
		}

		[HarmonyPatch(typeof(PlayerInventory), "Update")]
		[HarmonyPostfix]
		private static void PlayerInventoryUpdatePatch()
		{
			ConfigManager instance = ConfigManager.Instance;
			if ((instance != null && !instance.IsPatchEnabled("BlockBeeHiveRadius")) || Time.frameCount == lastUpdateFrame)
			{
				return;
			}
			lastUpdateFrame = Time.frameCount;
			foreach (int item in targetedLastFrame)
			{
				if (!targetedThisFrame.Contains(item) && visualizers.TryGetValue(item, out var value))
				{
					value.SetTargeted(targeted: false);
				}
			}
			HashSet<int> hashSet = targetedLastFrame;
			HashSet<int> hashSet2 = targetedThisFrame;
			targetedThisFrame = hashSet;
			targetedLastFrame = hashSet2;
			targetedThisFrame.Clear();
		}

		[HarmonyPatch(typeof(PlayerInventory), "HandleNewBlockPlacement")]
		[HarmonyPostfix]
		private static void HandleNewBlockPlacementPatch(PlayerInventory __instance)
		{
			//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_0031: 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_00f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010d: Unknown result type (might be due to invalid IL or missing references)
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockBeeHiveRadius"))
			{
				return;
			}
			GameObject blockBlueprint = GetBlockBlueprint(__instance);
			if ((Object)(object)blockBlueprint == (Object)null)
			{
				return;
			}
			InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
			if (currentInventorySlot.itemId == -1)
			{
				return;
			}
			ItemSO itemById = GameManager.Instance.GetItemById(currentInventorySlot.itemId);
			if ((Object)(object)itemById == (Object)null)
			{
				return;
			}
			BlockSO val = (BlockSO)(object)((itemById is BlockSO) ? itemById : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)((ItemSO)val).prefab.GetComponent<BlockBeeHive>() != (Object)null) || ghostVisualizers.ContainsKey(blockBlueprint))
			{
				return;
			}
			int radius = 3;
			BlockBeeHive component = blockBlueprint.GetComponent<BlockBeeHive>();
			if ((Object)(object)component != (Object)null)
			{
				radius = component.treeDetectionRadius;
			}
			else if ((Object)(object)((ItemSO)val).prefab != (Object)null)
			{
				BlockBeeHive component2 = ((ItemSO)val).prefab.GetComponent<BlockBeeHive>();
				if ((Object)(object)component2 != (Object)null)
				{
					radius = component2.treeDetectionRadius;
				}
			}
			GameObject val2 = new GameObject($"GhostBeeHiveRadius_{((Object)blockBlueprint).GetInstanceID()}");
			val2.transform.SetParent(blockBlueprint.transform);
			val2.transform.localPosition = Vector3.zero;
			RadiusVisualizer radiusVisualizer = val2.AddComponent<RadiusVisualizer>();
			radiusVisualizer.Initialize(radius);
			radiusVisualizer.SetTargeted(targeted: true);
			ghostVisualizers[blockBlueprint] = radiusVisualizer;
		}

		[HarmonyPatch(typeof(PlayerInventory), "DestroyBlockBlueprint")]
		[HarmonyPrefix]
		private static void DestroyBlockBlueprintPatch(PlayerInventory __instance)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockBeeHiveRadius"))
			{
				GameObject blockBlueprint = GetBlockBlueprint(__instance);
				if ((Object)(object)blockBlueprint != (Object)null && ghostVisualizers.ContainsKey(blockBlueprint))
				{
					ghostVisualizers.Remove(blockBlueprint);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "OnCurrentSlotChanged")]
		[HarmonyPrefix]
		private static void OnCurrentSlotChangedPatch(PlayerInventory __instance)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockBeeHiveRadius"))
			{
				GameObject blockBlueprint = GetBlockBlueprint(__instance);
				if ((Object)(object)blockBlueprint != (Object)null && ghostVisualizers.ContainsKey(blockBlueprint))
				{
					ghostVisualizers.Remove(blockBlueprint);
				}
			}
		}
	}
	public class RadiusVisualizer : MonoBehaviour
	{
		private int radius;

		private readonly float pulseSpeed = 0.5f;

		private LineRenderer circleRenderer;

		private readonly Dictionary<int, LineRenderer> treeConnections = new Dictionary<int, LineRenderer>();

		private bool isTargeted;

		private bool isVisible;

		private readonly float fadeSpeed = 3f;

		private float currentAlpha;

		private float targetAlpha;

		private readonly float hideDelay = 1f;

		private float hideDelayTimer;

		public void Initialize(int radius)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004c: 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)
			this.radius = radius;
			circleRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>();
			((Renderer)circleRenderer).material = new Material(Shader.Find("Sprites/Default"));
			circleRenderer.startColor = new Color(1f, 0.5f, 0f, 0f);
			circleRenderer.endColor = new Color(1f, 0.5f, 0f, 0f);
			circleRenderer.startWidth = 0.05f;
			circleRenderer.endWidth = 0.05f;
			circleRenderer.positionCount = 51;
			circleRenderer.useWorldSpace = true;
			DrawCircle();
		}

		private void DrawCircle()
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0055: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = (float)Math.PI / 25f;
			for (int i = 0; i <= 50; i++)
			{
				float num3 = Mathf.Sin(num) * (float)radius;
				float num4 = Mathf.Cos(num) * (float)radius;
				Vector3 val = ((Component)this).transform.position + new Vector3(num3, 0.1f, num4);
				circleRenderer.SetPosition(i, val);
				num += num2;
			}
		}

		public void SetTargeted(bool targeted)
		{
			if (isTargeted != targeted)
			{
				isTargeted = targeted;
				if (targeted)
				{
					targetAlpha = 1f;
					hideDelayTimer = 0f;
				}
				else
				{
					hideDelayTimer = hideDelay;
				}
			}
		}

		private void Update()
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			if (!isTargeted && hideDelayTimer > 0f)
			{
				hideDelayTimer -= Time.deltaTime;
				if (hideDelayTimer <= 0f)
				{
					targetAlpha = 0f;
				}
			}
			if (Mathf.Abs(currentAlpha - targetAlpha) > 0.01f)
			{
				currentAlpha = Mathf.MoveTowards(currentAlpha, targetAlpha, fadeSpeed * Time.deltaTime);
				UpdateVisibility();
			}
			if (currentAlpha <= 0.01f)
			{
				if (isVisible)
				{
					SetVisibility(visible: false);
				}
				return;
			}
			if (!isVisible)
			{
				SetVisibility(visible: true);
			}
			DrawCircle();
			float num = 0.7f + Mathf.PingPong(Time.time * pulseSpeed, 0.3f);
			float num2 = currentAlpha * num;
			Color val = default(Color);
			((Color)(ref val))..ctor(1f, 0.5f, 0f, num2 * 0.3f);
			circleRenderer.startColor = val;
			circleRenderer.endColor = val;
			UpdateTreeConnections(num2);
		}

		private void UpdateTreeConnections(float alphaWithPulse)
		{
			//IL_0006: 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)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			Collider[] array = Physics.OverlapSphere(((Component)this).transform.position, (float)radius);
			HashSet<int> hashSet = new HashSet<int>();
			Collider[] array2 = array;
			Color val2 = default(Color);
			foreach (Collider val in array2)
			{
				if (!val.isTrigger && (Object)(object)((Component)val).GetComponent<BlockTree>() != (Object)null)
				{
					int instanceID = ((Object)val).GetInstanceID();
					hashSet.Add(instanceID);
					if (!treeConnections.ContainsKey(instanceID))
					{
						CreateTreeConnection(instanceID, ((Component)val).transform);
					}
					else
					{
						UpdateTreeConnection(instanceID, ((Component)val).transform);
					}
					if (treeConnections.TryGetValue(instanceID, out var value))
					{
						((Color)(ref val2))..ctor(0f, 1f, 0f, alphaWithPulse * 0.8f);
						value.startColor = val2;
						value.endColor = val2;
					}
				}
			}
			List<int> list = new List<int>();
			foreach (int key in treeConnections.Keys)
			{
				if (!hashSet.Contains(key))
				{
					list.Add(key);
				}
			}
			foreach (int item in list)
			{
				if ((Object)(object)treeConnections[item] != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)treeConnections[item]).gameObject);
				}
				treeConnections.Remove(item);
			}
		}

		private void UpdateVisibility()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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_007e: 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)
			Color startColor = circleRenderer.startColor;
			startColor.a = currentAlpha * 0.3f;
			circleRenderer.startColor = startColor;
			circleRenderer.endColor = startColor;
			Color val = default(Color);
			((Color)(ref val))..ctor(0f, 1f, 0f, currentAlpha * 0.8f);
			foreach (LineRenderer value in treeConnections.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					value.startColor = val;
					value.endColor = val;
				}
			}
		}

		private void SetVisibility(bool visible)
		{
			isVisible = visible;
			((Renderer)circleRenderer).enabled = visible;
			foreach (LineRenderer value in treeConnections.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					((Renderer)value).enabled = visible;
				}
			}
		}

		private void CreateTreeConnection(int treeId, Transform treeTransform)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: 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_0041: Expected O, but got Unknown
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject($"TreeConnection_{treeId}");
			val.transform.SetParent(((Component)this).transform);
			LineRenderer val2 = val.AddComponent<LineRenderer>();
			((Renderer)val2).material = new Material(Shader.Find("Sprites/Default"));
			val2.startColor = new Color(0f, 1f, 0f, currentAlpha * 0.8f);
			val2.endColor = new Color(0f, 1f, 0f, currentAlpha * 0.8f);
			val2.startWidth = 0.04f;
			val2.endWidth = 0.04f;
			val2.positionCount = 2;
			val2.useWorldSpace = true;
			((Renderer)val2).enabled = isVisible;
			val2.SetPosition(0, ((Component)this).transform.position + new Vector3(0f, 0.1f, 0f));
			val2.SetPosition(1, treeTransform.position + new Vector3(0f, 0.1f, 0f));
			treeConnections[treeId] = val2;
		}

		private void UpdateTreeConnection(int treeId, Transform treeTransform)
		{
			//IL_0036: 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_004f: 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_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			if (treeConnections.ContainsKey(treeId) && (Object)(object)treeConnections[treeId] != (Object)null)
			{
				LineRenderer obj = treeConnections[treeId];
				obj.SetPosition(0, ((Component)this).transform.position + new Vector3(0f, 0.1f, 0f));
				obj.SetPosition(1, treeTransform.position + new Vector3(0f, 0.1f, 0f));
			}
		}

		private void OnDestroy()
		{
			foreach (LineRenderer value in treeConnections.Values)
			{
				if ((Object)(object)value != (Object)null)
				{
					Object.Destroy((Object)(object)((Component)value).gameObject);
				}
			}
			treeConnections.Clear();
		}
	}
	[HarmonyPatch(typeof(BlockCheeseMachine))]
	public class BlockCheeseMachinePatch
	{
		private static readonly FieldInfo currentOutputField = AccessTools.Field(typeof(BlockCheeseMachine), "currentOutput");

		private static readonly FieldInfo remainingDaysField = AccessTools.Field(typeof(BlockCheeseMachine), "remainingDays");

		private static long GetCurrentOutput(BlockCheeseMachine instance)
		{
			object value = currentOutputField.GetValue(instance);
			return (long)value.GetType().GetProperty("Value").GetValue(value);
		}

		private static int GetRemainingDays(BlockCheeseMachine instance)
		{
			object value = remainingDaysField.GetValue(instance);
			return (int)value.GetType().GetProperty("Value").GetValue(value);
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void GetDescriptionPatch(BlockCheeseMachine __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockCheeseMachine"))
			{
				return;
			}
			long currentOutput = GetCurrentOutput(__instance);
			int remainingDays = GetRemainingDays(__instance);
			if (currentOutput == -1)
			{
				return;
			}
			ItemSO itemById = GameManager.Instance.GetItemById(currentOutput);
			if ((Object)(object)itemById != (Object)null)
			{
				__result = itemById.GetLocalizedName();
				if (remainingDays > 0)
				{
					string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", remainingDays);
					__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
				}
			}
			else
			{
				string localizedText = LocalizationManager.Instance.GetLocalizedText("common.unknown_item");
				string localizedDaysWithPrefix2 = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", remainingDays);
				__result = localizedText + " <i><color=yellow>[" + localizedDaysWithPrefix2 + "]</color></i>";
			}
		}
	}
	[HarmonyPatch(typeof(BlockOilMachine))]
	public class BlockOilMachinePatch
	{
		private static readonly FieldInfo currentOutputField = AccessTools.Field(typeof(BlockOilMachine), "currentOutput");

		private static readonly FieldInfo remainingDaysField = AccessTools.Field(typeof(BlockOilMachine), "remainingDays");

		private static long GetCurrentOutput(BlockOilMachine instance)
		{
			object value = currentOutputField.GetValue(instance);
			return (long)value.GetType().GetProperty("Value").GetValue(value);
		}

		private static int GetRemainingDays(BlockOilMachine instance)
		{
			object value = remainingDaysField.GetValue(instance);
			return (int)value.GetType().GetProperty("Value").GetValue(value);
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void Postfix(BlockOilMachine __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockOilMachine"))
			{
				return;
			}
			long currentOutput = GetCurrentOutput(__instance);
			int remainingDays = GetRemainingDays(__instance);
			if (currentOutput != -1)
			{
				ItemSO itemById = GameManager.Instance.GetItemById(currentOutput);
				__result = itemById.GetLocalizedName();
				if (remainingDays > 0)
				{
					string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", remainingDays);
					__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(BlockDirt))]
	public class BlockDirtPatch
	{
		private static readonly FieldInfo currentSeedField = AccessTools.Field(typeof(BlockDirt), "currentSeed");

		private static string GetSeasonText(SeedSO seedSO)
		{
			if ((Object)(object)seedSO == (Object)null)
			{
				return null;
			}
			SeasonSO val = seedSO.productSO?.season;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return val.GetLocalizedName();
		}

		private static string GetSeasonColor(SeasonSO season)
		{
			List<SeasonSO> list = GameManager.Instance?.seasons;
			if ((Object)(object)season == (Object)null || list == null)
			{
				return "#FFFF00";
			}
			return list.IndexOf(season) switch
			{
				1 => "#32CD32", 
				2 => "#FFA500", 
				3 => "#D2691E", 
				0 => "#1E90FF", 
				_ => "#FFFF00", 
			};
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void Postfix(BlockDirt __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockDirt"))
			{
				return;
			}
			object value = currentSeedField.GetValue(__instance);
			long num = (long)value.GetType().GetProperty("Value").GetValue(value);
			if (num == -1)
			{
				return;
			}
			ItemSO itemById = GameManager.Instance.GetItemById(num);
			SeedSO val = (SeedSO)(object)((itemById is SeedSO) ? itemById : null);
			if (__instance.dayCounter.Value < val.daysToFullGrowth)
			{
				int days = val.daysToFullGrowth - __instance.dayCounter.Value;
				string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", days);
				__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
			}
			string seasonText = GetSeasonText(val);
			if (!string.IsNullOrEmpty(seasonText))
			{
				ConfigManager instance2 = ConfigManager.Instance;
				if (instance2 == null || instance2.IsPatchEnabled("BlockDirtSeason"))
				{
					string seasonColor = GetSeasonColor(val.productSO?.season);
					__result = __result + "\n<color=" + seasonColor + ">" + seasonText + "</color>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(BlockSprinkler))]
	public class BlockSprinklerPatch
	{
		private static readonly FieldInfo radiusField = AccessTools.Field(typeof(BlockSprinkler), "radius");

		private static readonly FieldInfo blockBlueprintField = AccessTools.Field(typeof(PlayerInventory), "blockBlueprint");

		private static readonly Dictionary<int, SprinklerRadiusVisualizer> visualizers = new Dictionary<int, SprinklerRadiusVisualizer>();

		private static HashSet<int> targetedThisFrame = new HashSet<int>();

		private static HashSet<int> targetedLastFrame = new HashSet<int>();

		private static int lastUpdateFrame;

		private static readonly Dictionary<GameObject, SprinklerRadiusVisualizer> ghostVisualizers = new Dictionary<GameObject, SprinklerRadiusVisualizer>();

		private static GameObject GetBlockBlueprint(PlayerInventory instance)
		{
			object? value = blockBlueprintField.GetValue(instance);
			return (GameObject)((value is GameObject) ? value : null);
		}

		private static float GetRadius(BlockSprinkler instance)
		{
			return (float)radiusField.GetValue(instance);
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void GetDescriptionPatch(BlockSprinkler __instance)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockSprinkler"))
			{
				int instanceID = ((Object)__instance).GetInstanceID();
				targetedThisFrame.Add(instanceID);
				if (visualizers.TryGetValue(instanceID, out var value))
				{
					value.SetTargeted(targeted: true);
				}
			}
		}

		[HarmonyPatch("OnNetworkSpawn")]
		[HarmonyPostfix]
		private static void OnNetworkSpawnPatch(BlockSprinkler __instance)
		{
			//IL_002e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: 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)
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockSprinkler"))
			{
				GameObject val = new GameObject($"SprinklerRadius_{((Object)__instance).GetInstanceID()}");
				val.transform.SetParent(((Component)__instance).transform);
				val.transform.localPosition = Vector3.zero;
				SprinklerRadiusVisualizer sprinklerRadiusVisualizer = val.AddComponent<SprinklerRadiusVisualizer>();
				sprinklerRadiusVisualizer.Initialize(GetRadius(__instance));
				visualizers[((Object)__instance).GetInstanceID()] = sprinklerRadiusVisualizer;
			}
		}

		[HarmonyPatch("OnNetworkDespawn")]
		[HarmonyPostfix]
		private static void OnNetworkDespawnPatch(BlockSprinkler __instance)
		{
			int instanceID = ((Object)__instance).GetInstanceID();
			visualizers.Remove(instanceID);
			targetedThisFrame.Remove(instanceID);
			targetedLastFrame.Remove(instanceID);
		}

		[HarmonyPatch(typeof(PlayerInventory), "Update")]
		[HarmonyPostfix]
		private static void PlayerInventoryUpdatePatch()
		{
			ConfigManager instance = ConfigManager.Instance;
			if ((instance != null && !instance.IsPatchEnabled("BlockSprinkler")) || Time.frameCount == lastUpdateFrame)
			{
				return;
			}
			lastUpdateFrame = Time.frameCount;
			foreach (int item in targetedLastFrame)
			{
				if (!targetedThisFrame.Contains(item) && visualizers.TryGetValue(item, out var value))
				{
					value.SetTargeted(targeted: false);
				}
			}
			HashSet<int> hashSet = targetedLastFrame;
			HashSet<int> hashSet2 = targetedThisFrame;
			targetedThisFrame = hashSet;
			targetedLastFrame = hashSet2;
			targetedThisFrame.Clear();
		}

		[HarmonyPatch(typeof(PlayerInventory), "HandleNewBlockPlacement")]
		[HarmonyPostfix]
		private static void HandleNewBlockPlacementPatch(PlayerInventory __instance)
		{
			//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_0031: 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_00f5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_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)
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockSprinkler"))
			{
				return;
			}
			GameObject blockBlueprint = GetBlockBlueprint(__instance);
			if ((Object)(object)blockBlueprint == (Object)null)
			{
				return;
			}
			InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
			if (currentInventorySlot.itemId == -1)
			{
				return;
			}
			ItemSO itemById = GameManager.Instance.GetItemById(currentInventorySlot.itemId);
			if ((Object)(object)itemById == (Object)null)
			{
				return;
			}
			BlockSO val = (BlockSO)(object)((itemById is BlockSO) ? itemById : null);
			if (!((Object)(object)val != (Object)null) || !((Object)(object)((ItemSO)val).prefab.GetComponent<BlockSprinkler>() != (Object)null) || ghostVisualizers.ContainsKey(blockBlueprint))
			{
				return;
			}
			float radius = 2f;
			BlockSprinkler component = blockBlueprint.GetComponent<BlockSprinkler>();
			if ((Object)(object)component != (Object)null)
			{
				radius = GetRadius(component);
			}
			else if ((Object)(object)((ItemSO)val).prefab != (Object)null)
			{
				BlockSprinkler component2 = ((ItemSO)val).prefab.GetComponent<BlockSprinkler>();
				if ((Object)(object)component2 != (Object)null)
				{
					radius = GetRadius(component2);
				}
			}
			GameObject val2 = new GameObject($"GhostSprinklerRadius_{((Object)blockBlueprint).GetInstanceID()}");
			val2.transform.SetParent(blockBlueprint.transform);
			val2.transform.localPosition = Vector3.zero;
			SprinklerRadiusVisualizer sprinklerRadiusVisualizer = val2.AddComponent<SprinklerRadiusVisualizer>();
			sprinklerRadiusVisualizer.Initialize(radius);
			sprinklerRadiusVisualizer.SetTargeted(targeted: true);
			ghostVisualizers[blockBlueprint] = sprinklerRadiusVisualizer;
		}

		[HarmonyPatch(typeof(PlayerInventory), "DestroyBlockBlueprint")]
		[HarmonyPrefix]
		private static void DestroyBlockBlueprintPatch(PlayerInventory __instance)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockSprinkler"))
			{
				GameObject blockBlueprint = GetBlockBlueprint(__instance);
				if ((Object)(object)blockBlueprint != (Object)null && ghostVisualizers.ContainsKey(blockBlueprint))
				{
					ghostVisualizers.Remove(blockBlueprint);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "OnCurrentSlotChanged")]
		[HarmonyPrefix]
		private static void OnCurrentSlotChangedPatch(PlayerInventory __instance)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance == null || instance.IsPatchEnabled("BlockSprinkler"))
			{
				GameObject blockBlueprint = GetBlockBlueprint(__instance);
				if ((Object)(object)blockBlueprint != (Object)null && ghostVisualizers.ContainsKey(blockBlueprint))
				{
					ghostVisualizers.Remove(blockBlueprint);
				}
			}
		}
	}
	public class SprinklerRadiusVisualizer : MonoBehaviour
	{
		private float radius;

		private readonly float pulseSpeed = 0.5f;

		private LineRenderer circleRenderer;

		private bool isTargeted;

		private bool isVisible;

		private readonly float fadeSpeed = 3f;

		private float currentAlpha;

		private float targetAlpha;

		private readonly float hideDelay = 1f;

		private float hideDelayTimer;

		public void Initialize(float radius)
		{
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Expected O, but got Unknown
			//IL_004c: 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)
			this.radius = radius;
			circleRenderer = ((Component)this).gameObject.AddComponent<LineRenderer>();
			((Renderer)circleRenderer).material = new Material(Shader.Find("Sprites/Default"));
			circleRenderer.startColor = new Color(0f, 0.7f, 1f, 0f);
			circleRenderer.endColor = new Color(0f, 0.7f, 1f, 0f);
			circleRenderer.startWidth = 0.05f;
			circleRenderer.endWidth = 0.05f;
			circleRenderer.positionCount = 51;
			circleRenderer.useWorldSpace = true;
			DrawCircle();
		}

		private void DrawCircle()
		{
			//IL_0033: 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_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			float num = 0f;
			float num2 = (float)Math.PI / 25f;
			for (int i = 0; i <= 50; i++)
			{
				float num3 = Mathf.Sin(num) * radius;
				float num4 = Mathf.Cos(num) * radius;
				Vector3 val = ((Component)this).transform.position + new Vector3(num3, 0.1f, num4);
				circleRenderer.SetPosition(i, val);
				num += num2;
			}
		}

		public void SetTargeted(bool targeted)
		{
			if (isTargeted != targeted)
			{
				isTargeted = targeted;
				if (targeted)
				{
					targetAlpha = 1f;
					hideDelayTimer = 0f;
				}
				else
				{
					hideDelayTimer = hideDelay;
				}
			}
		}

		private void Update()
		{
			//IL_00fc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0108: Unknown result type (might be due to invalid IL or missing references)
			if (!isTargeted && hideDelayTimer > 0f)
			{
				hideDelayTimer -= Time.deltaTime;
				if (hideDelayTimer <= 0f)
				{
					targetAlpha = 0f;
				}
			}
			if (Mathf.Abs(currentAlpha - targetAlpha) > 0.01f)
			{
				currentAlpha = Mathf.MoveTowards(currentAlpha, targetAlpha, fadeSpeed * Time.deltaTime);
				UpdateVisibility();
			}
			if (currentAlpha <= 0.01f)
			{
				if (isVisible)
				{
					SetVisibility(visible: false);
				}
				return;
			}
			if (!isVisible)
			{
				SetVisibility(visible: true);
			}
			DrawCircle();
			float num = 0.7f + Mathf.PingPong(Time.time * pulseSpeed, 0.3f);
			float num2 = currentAlpha * num;
			Color val = default(Color);
			((Color)(ref val))..ctor(0f, 0.7f, 1f, num2 * 0.3f);
			circleRenderer.startColor = val;
			circleRenderer.endColor = val;
		}

		private void UpdateVisibility()
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0025: 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)
			Color startColor = circleRenderer.startColor;
			startColor.a = currentAlpha * 0.3f;
			circleRenderer.startColor = startColor;
			circleRenderer.endColor = startColor;
		}

		private void SetVisibility(bool visible)
		{
			isVisible = visible;
			((Renderer)circleRenderer).enabled = visible;
		}
	}
	[HarmonyPatch(typeof(BlockTree))]
	public class BlockTreePatch
	{
		private static readonly FieldInfo treeSOField = AccessTools.Field(typeof(BlockTree), "treeSO");

		private static string GetSeasonText(TreeSO treeSO)
		{
			if ((Object)(object)treeSO == (Object)null)
			{
				return null;
			}
			SeasonSO val = treeSO.productSO?.season;
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			return val.GetLocalizedName();
		}

		private static string GetSeasonColor(SeasonSO season)
		{
			List<SeasonSO> list = GameManager.Instance?.seasons;
			if ((Object)(object)season == (Object)null || list == null)
			{
				return "#FFFF00";
			}
			return list.IndexOf(season) switch
			{
				1 => "#32CD32", 
				2 => "#FFA500", 
				3 => "#D2691E", 
				0 => "#1E90FF", 
				_ => "#FFFF00", 
			};
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void Postfix(BlockTree __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("BlockTree"))
			{
				return;
			}
			object? value = treeSOField.GetValue(__instance);
			TreeSO val = (TreeSO)((value is TreeSO) ? value : null);
			if (__instance.dayCounter.Value < val.daysToHarvestAfterGrowth)
			{
				int days = val.daysToHarvestAfterGrowth - __instance.dayCounter.Value;
				string localizedDaysWithPrefix = LocalizationManager.Instance.GetLocalizedDaysWithPrefix("common.remaining_prefix", days);
				__result = __result + " <i><color=yellow>[" + localizedDaysWithPrefix + "]</color></i>";
			}
			bool flag = ConfigManager.Instance?.IsPatchEnabled("TreeMove") ?? true;
			bool flag2 = ConfigManager.Instance?.IsPatchEnabled("TreeMoveHint") ?? true;
			ConfigManager instance2 = ConfigManager.Instance;
			if ((instance2 == null || instance2.IsPatchEnabled("BlockTreeSeason")) && !(flag && flag2))
			{
				string seasonText = GetSeasonText(val);
				if (!string.IsNullOrEmpty(seasonText))
				{
					string seasonColor = GetSeasonColor(val.productSO?.season);
					__result = __result + "\n<color=" + seasonColor + ">" + seasonText + "</color>";
				}
			}
		}
	}
	[HarmonyPatch(typeof(DockOrderTile))]
	public class DockOrderTilePatch
	{
		[HarmonyPatch("SetData")]
		[HarmonyPostfix]
		private static void SetDataPatch(DockOrderTile __instance, ProductSO productSO)
		{
			ConfigManager instance = ConfigManager.Instance;
			if ((instance == null || instance.IsPatchEnabled("DockOrderTile")) && BetterDockOrderCompatibility.ShouldShowInventoryHint())
			{
				int productAmount = GetProductAmount(productSO);
				TextMeshProUGUI textTitle = __instance.textTitle;
				string localizedText = LocalizationManager.Instance.GetLocalizedText("order.inventory", productAmount);
				((TMP_Text)textTitle).text = ((TMP_Text)textTitle).text + $" <color=yellow>[{localizedText}]</color>";
			}
		}

		public static int GetProductAmount(ProductSO product)
		{
			return (from x in Object.FindObjectsOfType<Item>()
				where x.itemSO is ProductSO && x.itemSO.itemName == ((ItemSO)product).itemName
				select x).Sum((Item item) => item.amount.Value);
		}
	}
	[HarmonyPatch(typeof(GameManager))]
	public class GameManagerPatch
	{
		private const string MESSAGE_TOGGLE = "BetterMarketPlus_ToggleMarked";

		private const string MESSAGE_REMOVE = "BetterMarketPlus_RemoveMarked";

		private const string MESSAGE_SYNC = "BetterMarketPlus_SyncMarked";

		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		private static void AwakePostfix()
		{
			UnacceptedTaskManager.Instance.OnToggleRequested -= OnToggleRequested;
			UnacceptedTaskManager.Instance.OnRemoveRequested -= OnRemoveRequested;
			UnacceptedTaskManager.Instance.OnToggleRequested += OnToggleRequested;
			UnacceptedTaskManager.Instance.OnRemoveRequested += OnRemoveRequested;
		}

		private static string GetNicknameByUserId(ulong userId)
		{
			if (userId == 0L || (Object)(object)GameManager.Instance == (Object)null)
			{
				return "";
			}
			try
			{
				if (AccessTools.Field(typeof(GameManager), "clientIdNicknames")?.GetValue(GameManager.Instance) is Dictionary<ulong, string> dictionary && AccessTools.Field(typeof(GameManager), "clientIdMap")?.GetValue(GameManager.Instance) is Dictionary<ulong, ulong> dictionary2)
				{
					foreach (KeyValuePair<ulong, ulong> item in dictionary2)
					{
						if (item.Value == userId && dictionary.ContainsKey(item.Key))
						{
							return dictionary[item.Key];
						}
					}
				}
			}
			catch
			{
			}
			return "";
		}

		[HarmonyPatch("OnNetworkSpawn")]
		[HarmonyPostfix]
		private static void OnNetworkSpawnPostfix()
		{
			RegisterMessageHandlers();
			if ((Object)(object)NetworkManager.Singleton != (Object)null)
			{
				NetworkManager.Singleton.OnClientConnectedCallback -= OnClientConnected;
				NetworkManager.Singleton.OnClientConnectedCallback += OnClientConnected;
				NetworkManager.Singleton.OnClientDisconnectCallback -= OnClientDisconnected;
				NetworkManager.Singleton.OnClientDisconnectCallback += OnClientDisconnected;
			}
		}

		[HarmonyPatch("OnActiveExpansionsChanged")]
		[HarmonyPostfix]
		private static void OnActiveExpansionsChangedPostfix(NetworkListEvent<long> changeEvent)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			if ((int)changeEvent.Type == 0)
			{
				long value = changeEvent.Value;
				if ((Object)(object)GameManager.Instance != (Object)null && GameManager.Instance.GetExpansionById(value) is AdvancedExpansionSO)
				{
					UnacceptedTaskManager.Instance.RemoveUnlockedExpansion(value);
				}
			}
		}

		private static void OnClientDisconnected(ulong clientId)
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.IsListening && (singleton.IsServer || singleton.IsHost))
			{
				UnacceptedTaskManager.Instance.TriggerMarkedExpansionsChanged();
			}
		}

		private static void OnClientConnected(ulong clientId)
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || (!singleton.IsServer && !singleton.IsHost))
			{
				return;
			}
			List<long> markedAdvancedExpansionIds = UnacceptedTaskManager.Instance.GetMarkedAdvancedExpansionIds();
			int num = 4;
			foreach (long item in markedAdvancedExpansionIds)
			{
				num += 8;
				num += 8;
				ulong? markerUserId = UnacceptedTaskManager.Instance.GetMarkerUserId(item);
				string text = (markerUserId.HasValue ? GetNicknameByUserId(markerUserId.Value) : "");
				num += 4 + (text.Length + 1) * 4;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1);
			try
			{
				int count = markedAdvancedExpansionIds.Count;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
				foreach (long item2 in markedAdvancedExpansionIds)
				{
					long current2 = item2;
					((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref current2, default(ForPrimitives));
					ulong valueOrDefault = UnacceptedTaskManager.Instance.GetMarkerUserId(current2).GetValueOrDefault();
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref valueOrDefault, default(ForPrimitives));
					string nicknameByUserId = GetNicknameByUserId(valueOrDefault);
					((FastBufferWriter)(ref val)).WriteValueSafe(nicknameByUserId, false);
				}
				singleton.CustomMessagingManager.SendNamedMessage("BetterMarketPlus_SyncMarked", clientId, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
			UnacceptedTaskManager.Instance.TriggerMarkedExpansionsChanged();
		}

		private static void RegisterMessageHandlers()
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Expected O, but got Unknown
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Expected O, but got Unknown
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null))
			{
				singleton.CustomMessagingManager.RegisterNamedMessageHandler("BetterMarketPlus_ToggleMarked", new HandleNamedMessageDelegate(OnToggleMessageReceived));
				singleton.CustomMessagingManager.RegisterNamedMessageHandler("BetterMarketPlus_RemoveMarked", new HandleNamedMessageDelegate(OnRemoveMessageReceived));
				singleton.CustomMessagingManager.RegisterNamedMessageHandler("BetterMarketPlus_SyncMarked", new HandleNamedMessageDelegate(OnSyncMessageReceived));
			}
		}

		private static void OnToggleRequested(long expansionId)
		{
			SendToggleMessage(expansionId);
		}

		private static void OnRemoveRequested(long expansionId)
		{
			SendRemoveMessage(expansionId);
		}

		private static void SendToggleMessage(long expansionId)
		{
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: 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)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				HandleToggle(expansionId, 0uL);
				return;
			}
			if (singleton.IsServer || singleton.IsHost)
			{
				ulong clientUserIdServer = GameManager.Instance.GetClientUserIdServer(singleton.LocalClientId);
				HandleToggle(expansionId, clientUserIdServer);
				BroadcastSyncMessage();
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref expansionId, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("BetterMarketPlus_ToggleMarked", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void SendRemoveMessage(long expansionId)
		{
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening)
			{
				HandleRemove(expansionId);
				return;
			}
			if (singleton.IsServer || singleton.IsHost)
			{
				HandleRemove(expansionId);
				BroadcastSyncMessage();
				return;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(8, (Allocator)2, -1);
			try
			{
				((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref expansionId, default(ForPrimitives));
				singleton.CustomMessagingManager.SendNamedMessage("BetterMarketPlus_RemoveMarked", 0uL, val, (NetworkDelivery)3);
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}

		private static void OnToggleMessageReceived(ulong senderId, FastBufferReader reader)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref reader)).TryBeginRead(8))
			{
				long expansionId = default(long);
				((FastBufferReader)(ref reader)).ReadValueSafe<long>(ref expansionId, default(ForPrimitives));
				ulong clientUserIdServer = GameManager.Instance.GetClientUserIdServer(senderId);
				HandleToggle(expansionId, clientUserIdServer);
				BroadcastSyncMessage();
			}
		}

		private static void OnRemoveMessageReceived(ulong senderId, FastBufferReader reader)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			if (((FastBufferReader)(ref reader)).TryBeginRead(8))
			{
				long expansionId = default(long);
				((FastBufferReader)(ref reader)).ReadValueSafe<long>(ref expansionId, default(ForPrimitives));
				HandleRemove(expansionId);
				BroadcastSyncMessage();
			}
		}

		private static void OnSyncMessageReceived(ulong senderId, FastBufferReader reader)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			if (!((FastBufferReader)(ref reader)).TryBeginRead(4))
			{
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			List<long> list = new List<long>();
			List<ulong> list2 = new List<ulong>();
			List<string> list3 = new List<string>();
			long item = default(long);
			ulong item2 = default(ulong);
			string text = default(string);
			for (int i = 0; i < num; i++)
			{
				if (!((FastBufferReader)(ref reader)).TryBeginRead(16))
				{
					return;
				}
				((FastBufferReader)(ref reader)).ReadValueSafe<long>(ref item, default(ForPrimitives));
				list.Add(item);
				((FastBufferReader)(ref reader)).ReadValueSafe<ulong>(ref item2, default(ForPrimitives));
				list2.Add(item2);
				((FastBufferReader)(ref reader)).ReadValueSafe(ref text, false);
				list3.Add(text ?? "");
			}
			UnacceptedTaskManager.Instance.SyncFromNetwork(list, list2, list3);
		}

		private static void HandleToggle(long expansionId, ulong markerUserId)
		{
			UnacceptedTaskManager instance = UnacceptedTaskManager.Instance;
			if (instance.IsAdvancedExpansionMarked(expansionId))
			{
				instance.InternalRemove(expansionId);
			}
			else
			{
				instance.InternalAdd(expansionId, markerUserId);
			}
		}

		private static void HandleRemove(long expansionId)
		{
			UnacceptedTaskManager.Instance.InternalRemove(expansionId);
		}

		private static void BroadcastSyncMessage()
		{
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0112: Unknown result type (might be due to invalid IL or missing references)
			//IL_016f: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton == (Object)null || !singleton.IsListening || (!singleton.IsServer && !singleton.IsHost))
			{
				return;
			}
			List<long> markedAdvancedExpansionIds = UnacceptedTaskManager.Instance.GetMarkedAdvancedExpansionIds();
			int num = 4;
			foreach (long item in markedAdvancedExpansionIds)
			{
				num += 8;
				num += 8;
				ulong? markerUserId = UnacceptedTaskManager.Instance.GetMarkerUserId(item);
				string text = (markerUserId.HasValue ? GetNicknameByUserId(markerUserId.Value) : "");
				num += 4 + (text.Length + 1) * 4;
			}
			FastBufferWriter val = default(FastBufferWriter);
			((FastBufferWriter)(ref val))..ctor(num, (Allocator)2, -1);
			try
			{
				int count = markedAdvancedExpansionIds.Count;
				((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref count, default(ForPrimitives));
				foreach (long item2 in markedAdvancedExpansionIds)
				{
					long current2 = item2;
					((FastBufferWriter)(ref val)).WriteValueSafe<long>(ref current2, default(ForPrimitives));
					ulong valueOrDefault = UnacceptedTaskManager.Instance.GetMarkerUserId(current2).GetValueOrDefault();
					((FastBufferWriter)(ref val)).WriteValueSafe<ulong>(ref valueOrDefault, default(ForPrimitives));
					string nicknameByUserId = GetNicknameByUserId(valueOrDefault);
					((FastBufferWriter)(ref val)).WriteValueSafe(nicknameByUserId, false);
				}
				foreach (NetworkClient connectedClients in singleton.ConnectedClientsList)
				{
					singleton.CustomMessagingManager.SendNamedMessage("BetterMarketPlus_SyncMarked", connectedClients.ClientId, val, (NetworkDelivery)3);
				}
			}
			finally
			{
				((IDisposable)(FastBufferWriter)(ref val)).Dispose();
			}
		}
	}
	[HarmonyPatch]
	public static class HorseCargoTooltipPatch
	{
		[HarmonyPatch(typeof(HorseCargo), "GetDescription")]
		[HarmonyPostfix]
		public static void HorseCargo_GetDescription_Postfix(HorseCargo __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if ((instance != null && !instance.IsPatchEnabled("HorseCargoTooltip")) || string.IsNullOrEmpty(__result))
			{
				return;
			}
			Horse horse = __instance.horse;
			if (!((Object)(object)horse == (Object)null) && horse.slots != null)
			{
				int usedSlotsCount = GetUsedSlotsCount(horse);
				int count = horse.slots.Count;
				string text = LocalizationManager.Instance?.GetLocalizedText("horse.cargo_info", usedSlotsCount, count);
				if (horse.IsFull())
				{
					string text2 = LocalizationManager.Instance?.GetLocalizedText("horse.cargo_full");
					text = text + " " + text2;
				}
				__result = $"{__result}\n{text}";
			}
		}

		[HarmonyPatch(typeof(Horse), "GetDescription")]
		[HarmonyPostfix]
		public static void Horse_GetDescription_Postfix(Horse __instance, ref string __result)
		{
			ConfigManager instance = ConfigManager.Instance;
			if ((instance == null || instance.IsPatchEnabled("HorseCargoTooltip")) && __instance.slots != null)
			{
				int usedSlotsCount = GetUsedSlotsCount(__instance);
				int count = __instance.slots.Count;
				string text = LocalizationManager.Instance?.GetLocalizedText("horse.cargo_info", usedSlotsCount, count);
				if (__instance.IsFull())
				{
					string text2 = LocalizationManager.Instance?.GetLocalizedText("horse.cargo_full");
					text = text + " " + text2;
				}
				if (string.IsNullOrEmpty(__result))
				{
					__result = text;
				}
				else
				{
					__result = $"{__result}\n{text}";
				}
			}
		}

		private static int GetUsedSlotsCount(Horse horse)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (horse?.slots == null)
			{
				return 0;
			}
			int num = 0;
			for (int i = 0; i < horse.slots.Count; i++)
			{
				if (horse.slots[i].itemId != -1)
				{
					num++;
				}
			}
			return num;
		}
	}
	[HarmonyPatch(typeof(Item))]
	public class ItemSeedDetailPatch
	{
		private static string GetSeasonColor(SeasonSO season)
		{
			List<SeasonSO> list = GameManager.Instance?.seasons;
			if ((Object)(object)season == (Object)null || list == null)
			{
				return "#FFFF00";
			}
			return list.IndexOf(season) switch
			{
				1 => "#32CD32", 
				2 => "#FFA500", 
				3 => "#D2691E", 
				0 => "#1E90FF", 
				_ => "#FFFF00", 
			};
		}

		[HarmonyPatch("GetDescription")]
		[HarmonyPostfix]
		private static void GetDescription_Postfix(Item __instance, ref string __result)
		{
			if (!((Interactable)__instance).CanInteract())
			{
				return;
			}
			ItemSO itemSO = __instance.itemSO;
			SeedSO val = (SeedSO)(object)((itemSO is SeedSO) ? itemSO : null);
			if ((Object)(object)val != (Object)null)
			{
				ConfigManager instance = ConfigManager.Instance;
				if (instance == null || instance.IsPatchEnabled("ItemSeedInfo"))
				{
					string localizedDays = LocalizationManager.Instance.GetLocalizedDays(val.daysToFullGrowth);
					SeasonSO val2 = val.productSO?.season;
					if ((Object)(object)val2 != (Object)null)
					{
						string localizedName = val2.GetLocalizedName();
						string seasonColor = GetSeasonColor(val2);
						__result = __result + "\n<color=" + seasonColor + ">" + localizedName + "</color> - " + localizedDays;
					}
					else
					{
						__result = __result + "\n" + localizedDays;
					}
				}
				return;
			}
			ItemSO itemSO2 = __instance.itemSO;
			TreeSO val3 = (TreeSO)(object)((itemSO2 is TreeSO) ? itemSO2 : null);
			if (!((Object)(object)val3 != (Object)null))
			{
				return;
			}
			ConfigManager instance2 = ConfigManager.Instance;
			if (instance2 == null || instance2.IsPatchEnabled("ItemTreeInfo"))
			{
				int daysToHarvestAfterGrowth = val3.daysToHarvestAfterGrowth;
				string localizedDays2 = LocalizationManager.Instance.GetLocalizedDays(daysToHarvestAfterGrowth);
				SeasonSO val4 = val3.productSO?.season;
				if ((Object)(object)val4 != (Object)null)
				{
					string localizedName2 = val4.GetLocalizedName();
					string seasonColor2 = GetSeasonColor(val4);
					__result = __result + "\n<color=" + seasonColor2 + ">" + localizedName2 + "</color> - " + localizedDays2;
				}
				else
				{
					__result = __result + "\n" + localizedDays2;
				}
			}
		}
	}
	[HarmonyPatch(typeof(PlayerInventory))]
	public class PlayerInventoryPatch
	{
		private static readonly HashSet<string> AllowPlacementAnywhere = new HashSet<string>
		{
			"floor_sign", "wall_sign", "big_fence", "chandelier", "lantern", "small_fence", "wall_candle", "paper_lantern_1", "paper_lantern_2", "paper_lantern_3",
			"paper_lantern_4", "golden_candle", "torch", "calendar", "fire_bin"
		};

		private static readonly HashSet<string> AllowWorkshopPlacementAnywhere = new HashSet<string>
		{
			"meat_cutter", "alcohol_machine", "potion_boiler", "sculpting_machine", "melting_machine", "spice_machine", "oven", "cheese_machine", "jam_machine", "anvil",
			"oil_machine"
		};

		private static readonly HashSet<string> AllowLivestockPlacementAnywhere = new HashSet<string> { "brown_horse", "grey_horse", "chicken", "goat", "cow", "brown_cow" };

		private static readonly FieldRef<PlayerInventory, GameObject> blockBlueprint = AccessTools.FieldRefAccess<PlayerInventory, GameObject>("blockBlueprint");

		private static readonly FieldRef<PlayerInventory, GameObject> itemBlueprint = AccessTools.FieldRefAccess<PlayerInventory, GameObject>("itemBlueprint");

		[HarmonyPatch(typeof(PlayerInventory), "HandleItemPlacement")]
		[HarmonyPrefix]
		public static bool PatchItemRotation(PlayerInventory __instance)
		{
			//IL_003c: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("PlayerInventoryRotation"))
			{
				return true;
			}
			GameObject val = itemBlueprint.Invoke(__instance);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			PlayerActions player = InputManager.Instance.inputMaster.Player;
			if (((PlayerActions)(ref player)).Rotate.WasPerformedThisFrame())
			{
				LeanTweenExt.LeanRotateAroundLocal(val, Vector3.up, 45f, 0.1f);
				return false;
			}
			return true;
		}

		[HarmonyPatch("HandleNewBlockPlacement")]
		[HarmonyPrefix]
		public static bool HandleNewBlockPlacementPatch(PlayerInventory __instance)
		{
			//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_003c: 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_0042: 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_0118: 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_0127: 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_0132: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: 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_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_0151: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_03f1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0415: Unknown result type (might be due to invalid IL or missing references)
			//IL_0426: Expected O, but got Unknown
			//IL_0216: Unknown result type (might be due to invalid IL or missing references)
			//IL_021b: Unknown result type (might be due to invalid IL or missing references)
			//IL_046b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0470: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_0284: Unknown result type (might be due to invalid IL or missing references)
			//IL_028e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0505: Unknown result type (might be due to invalid IL or missing references)
			//IL_050a: Unknown result type (might be due to invalid IL or missing references)
			//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_04af: Unknown result type (might be due to invalid IL or missing references)
			//IL_04c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_0572: Unknown result type (might be due to invalid IL or missing references)
			//IL_0579: Expected O, but got Unknown
			//IL_0591: Unknown result type (might be due to invalid IL or missing references)
			//IL_059d: 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_05ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_05b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_05ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_05be: Unknown result type (might be due to invalid IL or missing references)
			//IL_05c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_05cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_05d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0546: Unknown result type (might be due to invalid IL or missing references)
			//IL_0528: Unknown result type (might be due to invalid IL or missing references)
			//IL_068e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0693: Unknown result type (might be due to invalid IL or missing references)
			//IL_06ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_06d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_06db: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				PlayerActions player = InputManager.Instance.inputMaster.Player;
				if (((PlayerActions)(ref player)).Place.IsPressed() || (Object)(object)itemBlueprint.Invoke(__instance) != (Object)null)
				{
					return true;
				}
				InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
				if (currentInventorySlot.itemId == -1)
				{
					return true;
				}
				ItemSO itemById = GameManager.Instance.GetItemById(currentInventorySlot.itemId);
				BlockSO val = (BlockSO)(object)((itemById is BlockSO) ? itemById : null);
				if ((Object)(object)val == (Object)null)
				{
					return true;
				}
				ConfigManager instance = ConfigManager.Instance;
				int num;
				if ((instance != null && !instance.IsPatchEnabled("PlayerInventoryFreePlacement")) || !AllowPlacementAnywhere.Contains(((ItemSO)val).itemName))
				{
					ConfigManager instance2 = ConfigManager.Instance;
					if ((instance2 != null && !instance2.IsPatchEnabled("PlayerInventoryFreePlacementWorkshop")) || !AllowWorkshopPlacementAnywhere.Contains(((ItemSO)val).itemName))
					{
						ConfigManager instance3 = ConfigManager.Instance;
						num = (((instance3 == null || instance3.IsPatchEnabled("PlayerInventoryFreePlacementLivestock")) && AllowLivestockPlacementAnywhere.Contains(((ItemSO)val).itemName)) ? 1 : 0);
						goto IL_00fd;
					}
				}
				num = 1;
				goto IL_00fd;
				IL_00fd:
				bool flag = (byte)num != 0;
				Ray val2 = ((Camera)AccessTools.Field(typeof(PlayerInventory), "playerCamera").GetValue(__instance)).ViewportPointToRay(Vector3.one / 2f);
				LayerMask val3 = LayerMask.op_Implicit(~LayerMask.op_Implicit(__instance.blockIgnoredLayerMask));
				LayerMask.op_Implicit(flag ? (-1) : (-1 & LayerMask.op_Implicit(val3)));
				QueryTriggerInteraction val4 = (QueryTriggerInteraction)1;
				int num2 = 1;
				if (((ItemSO)val).prefab.CompareTag("Boat") || ((ItemSO)val).prefab.CompareTag("Floatable"))
				{
					val4 = (QueryTriggerInteraction)2;
					num2 = 2;
				}
				RaycastHit val5 = default(RaycastHit);
				if (Physics.Raycast(val2, ref val5, __instance.buildDistance * (float)num2, flag ? (-1) : (-1 & LayerMask.op_Implicit(val3)), val4))
				{
					if (!flag && !LayerMaskExtensions.Includes(val.placementLayerMask, ((Component)((RaycastHit)(ref val5)).collider).gameObject.layer))
					{
						AccessTools.Method(typeof(PlayerInventory), "DestroyBlockBlueprint", (Type[])null, (Type[])null).Invoke(__instance, null);
						return false;
					}
					GameObject val6 = blockBlueprint.Invoke(__instance);
					if ((Object)(object)val6 == (Object)null)
					{
						Quaternion rotation = ((RaycastHit)(ref val5)).transform.rotation;
						string text = LayerMask.LayerToName(((Component)((RaycastHit)(ref val5)).collider).gameObject.layer);
						if (GameManager.Instance.mapSO.id == 0 && (text == "Water" || text == "Terrain"))
						{
							((Quaternion)(ref rotation)).eulerAngles = new Vector3(((Quaternion)(ref rotation)).eulerAngles.x, ((Quaternion)(ref rotation)).eulerAngles.y - 28.85f, ((Quaternion)(ref rotation)).eulerAngles.z);
						}
						AccessTools.Field(typeof(PlayerInventory), "blockBlueprint").SetValue(__instance, Object.Instantiate<GameObject>(((ItemSO)val).prefab, ((RaycastHit)(ref val5)).point, rotation));
						AccessTools.Field(typeof(PlayerInventory), "blockBlueprintHit").SetValue(__instance, ((RaycastHit)(ref val5)).transform);
						GameObject val7 = blockBlueprint.Invoke(__instance);
						Collider[] componentsInChildren = val7.GetComponentsInChildren<Collider>();
						for (int i = 0; i < componentsInChildren.Length; i++)
						{
							componentsInChildren[i].enabled = false;
						}
						val7.GetComponent<NetworkObject>().AutoObjectParentSync = false;
						BoxCollider blueprintTrigger = val7.GetComponent<Block>().blueprintTrigger;
						AccessTools.Field(typeof(PlayerInventory), "blueprintTrigger").SetValue(__instance, blueprintTrigger);
						((Component)blueprintTrigger).gameObject.layer = LayerMask.NameToLayer("IgnoreBlockCollision");
						ObstacleColliderVisualizer val8 = default(ObstacleColliderVisualizer);
						if (((Component)blueprintTrigger).TryGetComponent<ObstacleColliderVisualizer>(ref val8))
						{
							((Behaviour)val8).enabled = true;
						}
						if ((Object)(object)blueprintTrigger != (Object)null)
						{
							((Collider)blueprintTrigger).enabled = true;
						}
						AccessTools.Field(typeof(PlayerInventory), "meshRenderersBlockBlueprint").SetValue(__instance, val7.GetComponentsInChildren<MeshRenderer>().ToList());
						AccessTools.Method(typeof(PlayerInventory), "ShowObstacleVisualizers", (Type[])null, (Type[])null).Invoke(__instance, new object[1] { true });
						return false;
					}
					val6.transform.position = ((RaycastHit)(ref val5)).point;
					if ((Object)(Transform)AccessTools.Field(typeof(PlayerInventory), "blockBlueprintHit").GetValue(__instance) != (Object)(object)((RaycastHit)(ref val5)).transform)
					{
						AccessTools.Field(typeof(PlayerInventory), "blockBlueprintHit").SetValue(__instance, ((RaycastHit)(ref val5)).transform);
						string text2 = LayerMask.LayerToName(((Component)((RaycastHit)(ref val5)).collider).gameObject.layer);
						Quaternion rotation2 = ((RaycastHit)(ref val5)).transform.rotation;
						if (GameManager.Instance.mapSO.id == 0 && (text2 == "Water" || text2 == "Terrain"))
						{
							((Quaternion)(ref rotation2)).eulerAngles = new Vector3(((Quaternion)(ref rotation2)).eulerAngles.x, ((Quaternion)(ref rotation2)).eulerAngles.y - 28.85f, ((Quaternion)(ref rotation2)).eulerAngles.z);
						}
						val6.transform.rotation = rotation2;
					}
					bool flag2 = ConfigManager.Instance?.IsPatchEnabled("PlayerInventoryRotation") ?? true;
					player = InputManager.Instance.inputMaster.Player;
					if (((PlayerActions)(ref player)).Rotate.WasPerformedThisFrame() && !val.disableRotation)
					{
						if (flag2)
						{
							LeanTweenExt.LeanRotateAroundLocal(val6, Vector3.up, 45f, 0.1f);
						}
						else
						{
							val6.transform.Rotate(Vector3.up, 90f);
						}
					}
					bool flag3 = true;
					BoxCollider val9 = (BoxCollider)AccessTools.Field(typeof(PlayerInventory), "blueprintTrigger").GetValue(__instance);
					if ((Object)(object)val9 == (Object)null)
					{
						Debug.LogError((object)"Block needs a blueprint collider!");
					}
					else
					{
						Vector3 val10 = Vector3.Scale(val9.size, ((Component)val9).transform.lossyScale) / 2f;
						Bounds bounds = ((Collider)val9).bounds;
						flag3 = Physics.CheckBox(((Bounds)(ref bounds)).center, val10, ((Component)val9).transform.rotation, LayerMask.op_Implicit(val3), (QueryTriggerInteraction)(flag ? 1 : 2));
					}
					List<MeshRenderer> obj = (List<MeshRenderer>)AccessTools.Field(typeof(PlayerInventory), "meshRenderersBlockBlueprint").GetValue(__instance);
					Material val11 = (flag3 ? __instance.materialBlueprintInvalid : __instance.materialBlueprintValid);
					foreach (MeshRenderer item in obj)
					{
						int num3 = ((Renderer)item).sharedMaterials.Length;
						Material[] array = (Material[])(object)new Material[num3];
						for (int j = 0; j < num3; j++)
						{
							array[j] = val11;
						}
						((Renderer)item).materials = array;
					}
					if (flag3)
					{
						return false;
					}
					player = InputManager.Instance.inputMaster.Player;
					if (((PlayerActions)(ref player)).Put.WasPerformedThisFrame())
					{
						__instance.audioSource.PlayOneShot(__instance.placementSound, 0.2f);
						__instance.PlaceBlockServerRpc(((ItemSO)val).id, val6.transform.position, val6.transform.rotation, currentInventorySlot.dayCounter);
						__instance.UseItem();
						AccessTools.Method(typeof(PlayerInventory), "DestroyBlockBlueprint", (Type[])null, (Type[])null).Invoke(__instance, null);
						return false;
					}
				}
				else
				{
					AccessTools.Method(typeof(PlayerInventory), "DestroyBlockBlueprint", (Type[])null, (Type[])null).Invoke(__instance, null);
				}
				return false;
			}
			catch (Exception ex)
			{
				BetterMarketPlus.Logger.LogError((object)("方块放置错误: " + ex.Message + "\n" + ex.StackTrace));
				return true;
			}
		}
	}
	[HarmonyPatch(typeof(SaveManager))]
	public static class SaveManagerPatch
	{
		[HarmonyPatch("DeleteSave")]
		[HarmonyPostfix]
		private static void DeleteSave_Postfix()
		{
			UnacceptedTaskManager.Instance.DeleteMarkedExpansionsFileForCurrentSlot();
		}

		[HarmonyPatch("DeleteSlot")]
		[HarmonyPostfix]
		private static void DeleteSlot_Postfix(string slot)
		{
			UnacceptedTaskManager.Instance.DeleteMarkedExpansionsFileForSlot(slot);
		}
	}
	[HarmonyPatch]
	public class TreeMovePatch
	{
		private struct TreeStateData
		{
			public int dayCounter;

			public int currentTotalHarvestAmount;

			public int harvestCount;

			public bool hasBeeHive;

			public bool isWatered;
		}

		[CompilerGenerated]
		private sealed class <RestoreTreeStateCoroutine>d__23 : IEnumerator<object>, IDisposable, IEnumerator
		{
			private int <>1__state;

			private object <>2__current;

			public int encodedState;

			public int dayCounter;

			public Vector3 position;

			private TreeStateData <treeState>5__2;

			private BlockTree <blockTree>5__3;

			object IEnumerator<object>.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			object IEnumerator.Current
			{
				[DebuggerHidden]
				get
				{
					return <>2__current;
				}
			}

			[DebuggerHidden]
			public <RestoreTreeStateCoroutine>d__23(int <>1__state)
			{
				this.<>1__state = <>1__state;
			}

			[DebuggerHidden]
			void IDisposable.Dispose()
			{
				<blockTree>5__3 = null;
				<>1__state = -2;
			}

			private bool MoveNext()
			{
				//IL_0027: Unknown result type (might be due to invalid IL or missing references)
				//IL_0031: Expected O, but got Unknown
				//IL_0042: Unknown result type (might be due to invalid IL or missing references)
				//IL_004c: Expected O, but got Unknown
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Expected O, but got Unknown
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					<>2__current = (object)new WaitForFixedUpdate();
					<>1__state = 1;
					return true;
				case 1:
					<>1__state = -1;
					<>2__current = (object)new WaitForFixedUpdate();
					<>1__state = 2;
					return true;
				case 2:
				{
					<>1__state = -1;
					<treeState>5__2 = DecodeTreeState(encodedState, dayCounter);
					Collider[] array = Physics.OverlapSphere(position, 1f);
					foreach (Collider val in array)
					{
						<blockTree>5__3 = ((Component)val).GetComponent<BlockTree>();
						if ((Object)(object)<blockTree>5__3 != (Object)null && Vector3.Distance(((Component)<blockTree>5__3).transform.position, position) < 0.5f)
						{
							if (!((NetworkBehaviour)<blockTree>5__3).IsServer)
							{
								break;
							}
							RestoreFullTreeState(<blockTree>5__3, <treeState>5__2);
							<>2__current = (object)new WaitForFixedUpdate();
							<>1__state = 3;
							return true;
						}
						<blockTree>5__3 = null;
					}
					break;
				}
				case 3:
					<>1__state = -1;
					if (<treeState>5__2.currentTotalHarvestAmount > 0)
					{
						<blockTree>5__3.currentTotalHarvestAmount.Value = <treeState>5__2.currentTotalHarvestAmount;
					}
					break;
				}
				return false;
			}

			bool IEnumerator.MoveNext()
			{
				//ILSpy generated this explicit interface implementation from .override directive in MoveNext
				return this.MoveNext();
			}

			[DebuggerHidden]
			void IEnumerator.Reset()
			{
				throw new NotSupportedException();
			}
		}

		private static readonly FieldInfo treSOField = AccessTools.Field(typeof(BlockTree), "treeSO");

		private static readonly FieldInfo itemIdField = AccessTools.Field(typeof(Item), "itemId");

		private static readonly FieldInfo localPlayerInventoryField = AccessTools.Field(typeof(BlockTree), "localPlayerInventory");

		private static readonly FieldInfo beeHiveField = AccessTools.Field(typeof(BlockTree), "beeHive");

		private static readonly FieldInfo isWateredField = AccessTools.Field(typeof(BlockTree), "isWatered");

		private static readonly Dictionary<ulong, int> pendingTreeRestores = new Dictionary<ulong, int>();

		private static readonly FieldInfo itemCostField = AccessTools.Field(typeof(Item), "cost");

		private static readonly Dictionary<long, (int cost, int useCount)> pendingCostFix = new Dictionary<long, (int, int)>();

		private static int EncodeTreeState(TreeStateData state)
		{
			int num = 0;
			num |= state.currentTotalHarvestAmount & 0xFFFF;
			num |= (state.harvestCount & 0x3FFF) << 16;
			if (state.hasBeeHive)
			{
				num |= 0x40000000;
			}
			if (state.isWatered)
			{
				num |= int.MinValue;
			}
			return num;
		}

		private static TreeStateData DecodeTreeState(int encoded, int dayCounter)
		{
			TreeStateData result = default(TreeStateData);
			result.dayCounter = dayCounter;
			result.currentTotalHarvestAmount = encoded & 0xFFFF;
			result.harvestCount = (encoded >> 16) & 0x3FFF;
			result.hasBeeHive = (encoded & 0x40000000) != 0;
			result.isWatered = (encoded & int.MinValue) != 0;
			return result;
		}

		private static TreeStateData ExtractTreeState(BlockTree treeInstance)
		{
			object? value = beeHiveField.GetValue(treeInstance);
			GameObject val = (GameObject)((value is GameObject) ? value : null);
			bool isWatered = (isWateredField.GetValue(treeInstance) as NetworkVariable<bool>)?.Value ?? false;
			TreeStateData result = default(TreeStateData);
			result.dayCounter = treeInstance.dayCounter.Value;
			result.currentTotalHarvestAmount = treeInstance.currentTotalHarvestAmount.Value;
			result.harvestCount = treeInstance.harvestCount.Value;
			result.hasBeeHive = (Object)(object)val != (Object)null;
			result.isWatered = isWatered;
			return result;
		}

		[HarmonyPatch(typeof(BlockTree), "UseTool")]
		[HarmonyPrefix]
		private static bool UseTool_Prefix(BlockTree __instance)
		{
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: 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_009c: Unknown result type (might be due to invalid IL or missing references)
			ConfigManager instance = ConfigManager.Instance;
			if (instance != null && !instance.IsPatchEnabled("TreeMove"))
			{
				return true;
			}
			object? value = localPlayerInventoryField.GetValue(__instance);
			PlayerInventory val = (PlayerInventory)((value is PlayerInventory) ? value : null);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			ItemSO currentItemSO = val.GetCurrentItemSO();
			ToolSO val2 = (ToolSO)(object)((currentItemSO is ToolSO) ? currentItemSO : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return true;
			}
			if (!(AccessTools.Field(typeof(BlockTree), "hoes").GetValue(__instance) is List<ToolSO> list))
			{
				return true;
			}
			if (list.Contains(val2) && IsShiftPressed())
			{
				NetworkObjectReference val3 = NetworkObjectReference.op_Implicit(((NetworkBehaviour)__instance).NetworkObject);
				GameManager.Instance.RemoveBlockServerRpc(val3, default(ServerRpcParams));
				return false;
			}
			return true;
		}

		private static bool IsShiftPressed()
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			if (InputManager.Instance?.inputMaster != null)
			{
				PlayerActions player = InputManager.Instance.inputMaster.Player;
				return ((PlayerActions)(ref player)).Sprint.IsPressed();
			}
			return false;
		}

		[HarmonyPatch(typeof(GameManager), "RemoveBlockServerRpc")]
		[HarmonyPrefix]
		private static bool GameManager_RemoveBlockServerRpc_Prefix(GameManager __instance, NetworkObjectReference target)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			NetworkObject val = NetworkObjectReference.op_Implicit(target);
			if ((Object)(object)val == (Object)null)
			{
				return true;
			}
			Block component = ((Component)val).GetComponent<Block>();
			BlockTree val2 = (BlockTree)(object)((component is BlockTree) ? component : null);
			if ((Object)(object)val2 == (Object)null)
			{
				return true;
			}
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return true;
			}
			if (val2.dayCounter.Value <= 0)
			{
				return true;
			}
			object? value = treSOField.GetValue(val2);
			TreeSO val3 = (TreeSO)((value is TreeSO) ? value : null);
			if ((Object)(object)val3 == (Object)null)
			{
				return true;
			}
			TreeStateData state = ExtractTreeState(val2);
			int num = EncodeTreeState(state);
			Vector3 val4 = ((Component)val2).transform.position + new Vector3(0f, 0.5f, 0f);
			GameManager.Instance.SpawnItemAtPositionServerRpc(((ItemSO)val3).id, val4, true, 1, num, state.dayCounter);
			val.Despawn(true);
			val2.HarvestEffectsClientRpc();
			return false;
		}

		[HarmonyPatch(typeof(BlockTree), "RemoveTreeServerRpc")]
		[HarmonyPrefix]
		private static bool RemoveTreeServerRpc_Prefix()
		{
			return true;
		}

		private static void PerformLosslessTreeMoving(BlockTree treeInstance)
		{
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: 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)
			object? value = treSOField.GetValue(treeInstance);
			TreeSO val = (TreeSO)((value is TreeSO) ? value : null);
			if (!((Object)(object)val == (Object)null))
			{
				TreeStateData state = ExtractTreeState(treeInstance);
				int num = EncodeTreeState(state);
				treeInstance.HarvestEffectsClientRpc();
				Vector3 val2 = ((Component)treeInstance).transform.position + new Vector3(0f, 0.5f, 0f);
				GameManager.Instance.SpawnItemAtPositionServerRpc(((ItemSO)val).id, val2, true, 1, num, state.dayCounter);
				((NetworkBehaviour)treeInstance).NetworkObject.Despawn(true);
			}
		}

		[HarmonyPatch(typeof(Item), "TakeItemServerRpc")]
		[HarmonyPrefix]
		private static void TakeItemServerRpc_Prefix(Item __instance)
		{
			if (__instance.dayCounter.Value > 0 && itemIdField.GetValue(__instance) is NetworkVariable<long> val && GameManager.Instance.GetItemById(val.Value) is TreeSO)
			{
				int value = __instance.sellingPriceForTag.Value;
				if (value != -1 && value != 0)
				{
					long key = val.Value * 1000 + __instance.dayCounter.Value;
					pendingCostFix[key] = (value, 0);
				}
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "GiveItemClientRpc")]
		[HarmonyPrefix]
		private static void GiveItemClientRpc_Prefix(PlayerInventory __instance, long itemId, ref int cost, int dayCounter)
		{
			if (!((NetworkBehaviour)__instance).IsServer || dayCounter <= 0 || !(GameManager.Instance.GetItemById(itemId) is TreeSO))
			{
				return;
			}
			long key = itemId * 1000 + dayCounter;
			if (pendingCostFix.TryGetValue(key, out (int, int) value))
			{
				cost = value.Item1;
				int num = value.Item2 + 1;
				if (num >= 2)
				{
					pendingCostFix.Remove(key);
				}
				else
				{
					pendingCostFix[key] = (value.Item1, num);
				}
			}
		}

		[HarmonyPatch(typeof(Item), "ServerSetupItem")]
		[HarmonyPostfix]
		private static void ServerSetupItem_Postfix(Item __instance, long itemId, int cost, int dayCounter)
		{
			if (((NetworkBehaviour)__instance).IsServer && dayCounter > 0 && cost != 0 && GameManager.Instance.GetItemById(itemId) is TreeSO)
			{
				__instance.sellingPriceForTag.Value = cost;
			}
		}

		[HarmonyPatch(typeof(Item), "OnDayChanged")]
		[HarmonyPrefix]
		private static bool Item_OnDayChanged_Prefix(Item __instance)
		{
			if (!((NetworkBehaviour)__instance).IsServer)
			{
				return true;
			}
			if (itemIdField.GetValue(__instance) is NetworkVariable<long> val && GameManager.Instance.GetItemById(val.Value) is TreeSO)
			{
				return false;
			}
			return true;
		}

		[HarmonyPatch(typeof(PlayerInventory), "PlaceBlockServerRpc")]
		[HarmonyPrefix]
		private static void PlaceBlockServerRpc_Prefix(PlayerInventory __instance, long itemId, int dayCounter)
		{
			//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)
			//IL_002d: 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)
			if (((NetworkBehaviour)__instance).IsServer && dayCounter > 0 && /*isinst with value type is only supported in some contexts*/is TreeSO)
			{
				InventorySlot currentInventorySlot = __instance.GetCurrentInventorySlot();
				if (currentInventorySlot.itemId == itemId)
				{
					pendingTreeRestores[((NetworkBehaviour)__instance).OwnerClientId] = currentInventorySlot.cost;
				}
			}
		}

		[HarmonyPatch(typeof(PlayerInventory), "PlaceBlockServerRpc")]
		[HarmonyPostfix]
		private static void PlaceBlockServerRpc_Postfix(PlayerInventory __instance, Vector3 position, int dayCounter)
		{
			//IL_0034: Unknown result type (might be due to invalid IL or missing references)
			if (((NetworkBehaviour)__instance).IsServer && pendingTreeRestores.TryGetValue(((NetworkBehaviour)__instance).OwnerClientId, out var value))
			{
				pendingTreeRestores.Remove(((NetworkBehaviour)__instance).OwnerClientId);
				((MonoBehaviour)GameManager.Instanc