Decompiled source of Tweaks v1.1.3

Tweaks.dll

Decompiled 2 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("Tweaks")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Tweaks")]
[assembly: AssemblyTitle("Tweaks")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Tweaks;

internal static class ContainerAccessHelper
{
	private static readonly MethodInfo s_containerCheckAccess = BuildCheckAccessMethod();

	private static bool s_loggedCheckAccessFailure;

	private static readonly Collider[] s_overlapBuffer = (Collider[])(object)new Collider[256];

	private static readonly HashSet<Container> s_seen = new HashSet<Container>();

	private static readonly List<Container> s_result = new List<Container>();

	private static MethodInfo BuildCheckAccessMethod()
	{
		try
		{
			return AccessTools.Method(typeof(Container), "CheckAccess", new Type[1] { typeof(long) }, (Type[])null);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:상자접근] Container.CheckAccess 확보 실패: {arg}");
			return null;
		}
	}

	public static List<Container> GetAccessibleContainers(Player player, float radius)
	{
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		s_seen.Clear();
		s_result.Clear();
		int num = Physics.OverlapSphereNonAlloc(((Component)player).transform.position, Mathf.Max(0f, radius), s_overlapBuffer);
		for (int i = 0; i < num; i++)
		{
			Collider val = s_overlapBuffer[i];
			if (!((Object)(object)val == (Object)null))
			{
				Container componentInParent = ((Component)val).GetComponentInParent<Container>();
				if (!((Object)(object)componentInParent == (Object)null) && s_seen.Add(componentInParent) && IsAccessible(componentInParent, player))
				{
					s_result.Add(componentInParent);
				}
			}
		}
		return s_result;
	}

	private static bool IsAccessible(Container container, Player player)
	{
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			ZNetView component = ((Component)container).GetComponent<ZNetView>();
			if ((Object)(object)component == (Object)null || !component.IsValid())
			{
				return false;
			}
			if (container.IsInUse())
			{
				return false;
			}
			if (container.m_checkGuardStone && !PrivateArea.CheckAccess(((Component)container).transform.position, 0f, false, false))
			{
				return false;
			}
			if (s_containerCheckAccess != null)
			{
				long playerID = Game.instance.GetPlayerProfile().GetPlayerID();
				if (s_containerCheckAccess.Invoke(container, new object[1] { playerID }) is bool flag && !flag)
				{
					return false;
				}
			}
			return true;
		}
		catch (Exception arg)
		{
			if (!s_loggedCheckAccessFailure)
			{
				s_loggedCheckAccessFailure = true;
				Plugin.Log.LogError((object)$"[Tweaks:상자접근] 접근 판정 중 오류: {arg}");
			}
			return false;
		}
	}

	public static void ClaimOwnership(Container container)
	{
		try
		{
			if (!container.IsOwner())
			{
				ZNetView component = ((Component)container).GetComponent<ZNetView>();
				if ((Object)(object)component != (Object)null && component.IsValid())
				{
					component.ClaimOwnership();
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:상자접근] 소유권 이전 중 오류: {arg}");
		}
	}

	public static int SumContainerCount(List<Container> containers, string itemName, int quality)
	{
		int num = 0;
		foreach (Container container in containers)
		{
			num += container.GetInventory().CountItems(itemName, quality, true);
		}
		return num;
	}

	public static int ConsumeFromContainers(List<Container> containers, string itemName, int quality, int amount)
	{
		int num = amount;
		foreach (Container container in containers)
		{
			if (num <= 0)
			{
				break;
			}
			Inventory inventory = container.GetInventory();
			int num2 = inventory.CountItems(itemName, quality, true);
			if (num2 > 0)
			{
				int num3 = Mathf.Min(num2, num);
				ClaimOwnership(container);
				inventory.RemoveItem(itemName, num3, quality, true);
				num -= num3;
			}
		}
		return amount - num;
	}
}
[HarmonyPatch(typeof(LightFlicker), "Awake")]
internal static class Feature01_LightFlickerPatch
{
	[HarmonyPostfix]
	private static void Postfix(LightFlicker __instance)
	{
		if (!TweaksConfig.LightEnabled.Value)
		{
			return;
		}
		try
		{
			if ((Object)(object)((Component)__instance).GetComponentInParent<Fireplace>() != (Object)null || TweaksConfig.LightIncludeHandheld.Value)
			{
				Traverse val = Traverse.Create((object)__instance);
				float value = val.Field("m_baseIntensity").GetValue<float>();
				val.Field("m_baseIntensity").SetValue((object)(value * TweaksConfig.LightIntensityMultiplier.Value));
				Light value2 = val.Field("m_light").GetValue<Light>();
				if ((Object)(object)value2 != (Object)null)
				{
					value2.range *= TweaksConfig.LightRangeMultiplier.Value;
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능1-광원] LightFlicker '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "Awake")]
internal static class Feature01_FireplaceLightPatch
{
	[HarmonyPostfix]
	private static void Postfix(Fireplace __instance)
	{
		if (!TweaksConfig.LightEnabled.Value)
		{
			return;
		}
		try
		{
			Light[] componentsInChildren = ((Component)__instance).gameObject.GetComponentsInChildren<Light>(true);
			Light[] array = componentsInChildren;
			foreach (Light val in array)
			{
				if (!((Object)(object)((Component)val).GetComponent<LightFlicker>() != (Object)null))
				{
					val.intensity *= TweaksConfig.LightIntensityMultiplier.Value;
					val.range *= TweaksConfig.LightRangeMultiplier.Value;
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능1-광원] Fireplace '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Location), "IsInsideNoBuildLocation")]
internal static class Feature02_NoBuildZonePatch
{
	[HarmonyPrefix]
	private static bool Prefix(Vector3 point, ref bool __result)
	{
		if (!TweaksConfig.NoBuildZoneEnabled.Value)
		{
			return true;
		}
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(Player), "UpdatePlacementGhost")]
internal static class Feature03_DungeonBuildPatch
{
	private sealed class State
	{
		public Piece Piece;

		public bool GroundPiece;

		public bool GroundOnly;

		public bool CultivatedGroundOnly;

		public bool AllowedInDungeons;
	}

	[HarmonyPrefix]
	private static void Prefix(Player __instance, out State __state)
	{
		__state = null;
		if (!TweaksConfig.DungeonBuildEnabled.Value)
		{
			return;
		}
		try
		{
			if (!((Character)__instance).InInterior())
			{
				return;
			}
			GameObject value = Traverse.Create((object)__instance).Field("m_placementGhost").GetValue<GameObject>();
			if (!((Object)(object)value == (Object)null))
			{
				Piece component = value.GetComponent<Piece>();
				if (!((Object)(object)component == (Object)null))
				{
					__state = new State
					{
						Piece = component,
						GroundPiece = component.m_groundPiece,
						GroundOnly = component.m_groundOnly,
						CultivatedGroundOnly = component.m_cultivatedGroundOnly,
						AllowedInDungeons = component.m_allowedInDungeons
					};
					component.m_groundPiece = false;
					component.m_groundOnly = false;
					component.m_cultivatedGroundOnly = false;
					component.m_allowedInDungeons = true;
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능3-던전건설] 사전 처리 중 오류: {arg}");
			__state = null;
		}
	}

	[HarmonyPostfix]
	private static void Postfix(State __state)
	{
		if (__state == null)
		{
			return;
		}
		try
		{
			__state.Piece.m_groundPiece = __state.GroundPiece;
			__state.Piece.m_groundOnly = __state.GroundOnly;
			__state.Piece.m_cultivatedGroundOnly = __state.CultivatedGroundOnly;
			__state.Piece.m_allowedInDungeons = __state.AllowedInDungeons;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능3-던전건설] 복원 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(StationExtension), "Awake")]
internal static class Feature04_StationExtensionRangePatch
{
	[HarmonyPostfix]
	private static void Postfix(StationExtension __instance)
	{
		if (!TweaksConfig.StationDistanceEnabled.Value)
		{
			return;
		}
		try
		{
			float value = TweaksConfig.StationDistance.Value;
			__instance.m_maxStationDistance = ((value <= 0f) ? 100000f : value);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능4-부속품거리] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(StationExtension), "OtherExtensionInRange")]
internal static class Feature04_StationSpacingPatch
{
	[HarmonyPrefix]
	private static bool Prefix(ref bool __result)
	{
		if (!TweaksConfig.StationSpacingEnabled.Value)
		{
			return true;
		}
		__result = false;
		return false;
	}
}
[HarmonyPatch(typeof(Beehive), "Awake")]
internal static class Feature05_BeehiveCeilingPatch
{
	[HarmonyPostfix]
	private static void Postfix(Beehive __instance)
	{
		if (!TweaksConfig.BeehiveCeilingEnabled.Value)
		{
			return;
		}
		try
		{
			Piece value = Traverse.Create((object)__instance).Field("m_piece").GetValue<Piece>();
			if ((Object)(object)value != (Object)null)
			{
				value.m_groundPiece = false;
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능5-벌집천장] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Beehive), "HaveFreeSpace")]
internal static class Feature05_BeehiveIgnoreCoverPatch
{
	[HarmonyPrefix]
	private static bool Prefix(ref bool __result)
	{
		if (!TweaksConfig.BeehiveIgnoreCoverEnabled.Value)
		{
			return true;
		}
		__result = true;
		return false;
	}
}
[HarmonyPatch(typeof(Plant), "SUpdate")]
internal static class Feature06_RainGrowthPatch
{
	private const float MinIntervalSeconds = 5f;

	private static readonly ConditionalWeakTable<Plant, StrongBox<float>> s_lastApplied = new ConditionalWeakTable<Plant, StrongBox<float>>();

	[HarmonyPostfix]
	private static void Postfix(Plant __instance)
	{
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: 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 (!TweaksConfig.RainGrowthEnabled.Value)
		{
			return;
		}
		try
		{
			if (!EnvMan.IsWet())
			{
				return;
			}
			float value = TweaksConfig.RainGrowthMultiplier.Value;
			if (value <= 1f)
			{
				return;
			}
			ZNetView value2 = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
			if ((Object)(object)value2 == (Object)null || !value2.IsValid() || !value2.IsOwner())
			{
				return;
			}
			StrongBox<float> orCreateValue = s_lastApplied.GetOrCreateValue(__instance);
			float time = Time.time;
			float num = time - orCreateValue.Value;
			if (orCreateValue.Value > 0f && num < 5f)
			{
				return;
			}
			orCreateValue.Value = time;
			if (num <= 0f || num > 300f)
			{
				return;
			}
			Vector3 position = ((Component)__instance).transform.position;
			if (!VanillaSafeAccess.TryGetCoverForPoint(position, 0.5f, out var coverRatio, out var _) || !(coverRatio >= 0.5f))
			{
				ZDO zDO = value2.GetZDO();
				long num2 = zDO.GetLong(ZDOVars.s_plantTime, 0L);
				if (num2 != 0)
				{
					double num3 = (double)num * ((double)value - 1.0);
					long num4 = (long)(num3 * 10000000.0);
					zDO.Set(ZDOVars.s_plantTime, num2 - num4);
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능6-비성장] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Plant), "Grow")]
internal static class Feature07_MarkGrownCropPatch
{
	internal const string IsCropZdoKey = "TweaksIsCrop";

	[HarmonyPostfix]
	private static void Postfix(GameObject __result)
	{
		if ((Object)(object)__result == (Object)null)
		{
			return;
		}
		try
		{
			ZNetView componentInChildren = __result.GetComponentInChildren<ZNetView>();
			if ((Object)(object)componentInChildren != (Object)null && componentInChildren.IsValid())
			{
				componentInChildren.GetZDO().Set("TweaksIsCrop", true);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능7-벌집산출] 작물 표식 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Pickable), "RPC_Pick")]
internal static class Feature07_BeehiveYieldPatch
{
	[HarmonyPostfix]
	private static void Postfix(Pickable __instance)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		if (!TweaksConfig.BeehiveYieldEnabled.Value)
		{
			return;
		}
		try
		{
			Traverse val = Traverse.Create((object)__instance);
			ZNetView value = val.Field("m_nview").GetValue<ZNetView>();
			if (!((Object)(object)value == (Object)null) && value.IsValid() && value.IsOwner() && value.GetZDO().GetBool("TweaksIsCrop", false) && HasNearbyBeehive(((Component)__instance).transform.position, TweaksConfig.BeehiveYieldRadius.Value) && !(Random.value > TweaksConfig.BeehiveYieldChance.Value))
			{
				int value2 = TweaksConfig.BeehiveYieldBonusAmount.Value;
				if (value2 > 0 && !((Object)(object)__instance.m_itemPrefab == (Object)null))
				{
					val.Method("Drop", new object[3] { __instance.m_itemPrefab, 0, value2 }).GetValue();
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능7-벌집산출] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}

	private static bool HasNearbyBeehive(Vector3 position, float radius)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		Collider[] array = Physics.OverlapSphere(position, radius);
		Collider[] array2 = array;
		foreach (Collider val in array2)
		{
			if ((Object)(object)((Component)val).GetComponentInParent<Beehive>() != (Object)null)
			{
				return true;
			}
		}
		return false;
	}
}
[HarmonyPatch(typeof(Player), "UpdateEnvStatusEffects")]
internal static class Feature08_InstantRestedPatch
{
	private static readonly ConditionalWeakTable<Player, StrongBox<float>> s_nearFireAccum = new ConditionalWeakTable<Player, StrongBox<float>>();

	[ThreadStatic]
	private static bool s_bypassActive;

	internal static bool IsBypassActive => s_bypassActive;

	[HarmonyPrefix]
	private static void Prefix(Player __instance, float dt)
	{
		s_bypassActive = false;
		if (!TweaksConfig.InstantRestedEnabled.Value)
		{
			return;
		}
		try
		{
			float value = Traverse.Create((object)__instance).Field("m_nearFireTimer").GetValue<float>();
			bool flag = value < 0.25f;
			StrongBox<float> orCreateValue = s_nearFireAccum.GetOrCreateValue(__instance);
			if (!flag)
			{
				orCreateValue.Value = 0f;
				return;
			}
			orCreateValue.Value += dt;
			if (orCreateValue.Value >= TweaksConfig.InstantRestedWaitSeconds.Value)
			{
				s_bypassActive = true;
				((Character)__instance).GetSEMan().AddStatusEffect(SEMan.s_statusEffectRested, true, 0, 0f, (short)(-1));
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능8-휴식즉시적용] 처리 중 오류: {arg}");
		}
	}

	[HarmonyPostfix]
	private static void Postfix()
	{
		s_bypassActive = false;
	}
}
[HarmonyPatch(typeof(Player), "InShelter")]
internal static class Feature08_ShelterBypassPatch
{
	[HarmonyPostfix]
	private static void Postfix(ref bool __result)
	{
		if (Feature08_InstantRestedPatch.IsBypassActive)
		{
			__result = true;
		}
	}
}
[HarmonyPatch(typeof(Smelter), "Awake")]
internal static class Feature09_SmelterCapacityPatch
{
	[HarmonyPostfix]
	private static void Postfix(Smelter __instance)
	{
		if (!TweaksConfig.SmelterCapacityEnabled.Value)
		{
			return;
		}
		try
		{
			if (__instance.m_maxOre > 0)
			{
				__instance.m_maxOre = Mathf.Max(1, Mathf.RoundToInt((float)__instance.m_maxOre * TweaksConfig.SmelterOreMultiplier.Value));
			}
			if (__instance.m_maxFuel > 0)
			{
				__instance.m_maxFuel = Mathf.Max(1, Mathf.RoundToInt((float)__instance.m_maxFuel * TweaksConfig.SmelterFuelMultiplier.Value));
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능9-제련용량] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
internal static class HoverReflect
{
	public static T CallPrivate<T>(object instance, string methodName, object[] args = null)
	{
		if (args == null)
		{
			args = Array.Empty<object>();
		}
		MethodInfo methodInfo = AccessTools.Method(instance.GetType(), methodName, ArgTypes(args), (Type[])null);
		object obj = methodInfo.Invoke(instance, args);
		return (T)obj;
	}

	public static object InvokeWithRefArgs(object instance, string methodName, object[] args)
	{
		MethodInfo methodInfo = AccessTools.Method(instance.GetType(), methodName, (Type[])null, (Type[])null);
		return methodInfo.Invoke(instance, args);
	}

	private static Type[] ArgTypes(object[] args)
	{
		Type[] array = new Type[args.Length];
		for (int i = 0; i < args.Length; i++)
		{
			array[i] = args[i]?.GetType() ?? typeof(object);
		}
		return array;
	}
}
[HarmonyPatch(typeof(Smelter), "OnHoverAddOre")]
internal static class Feature10_SmelterOreHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Smelter __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoSmelter.Value)
		{
			return;
		}
		try
		{
			int num = HoverReflect.CallPrivate<int>(__instance, "GetQueueSize");
			if (num > 0 && !(__instance.m_secPerProduct <= 0f))
			{
				float num2 = HoverReflect.CallPrivate<float>(__instance, "GetBakeTimer");
				float secPerProduct = __instance.m_secPerProduct;
				float num3 = Mathf.Max(0f, secPerProduct - num2);
				float seconds = num3 + secPerProduct * (float)(num - 1);
				__result += $"\n다음 완성 {TweaksTimeFormat.Format(num3)} · 전체 완료 {TweaksTimeFormat.Format(seconds)} ({num}개)";
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] Smelter 투입칸 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Smelter), "OnHoverAddFuel")]
internal static class Feature10_SmelterFuelHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Smelter __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoSmelter.Value)
		{
			return;
		}
		try
		{
			if (__instance.m_fuelPerProduct > 0)
			{
				float num = HoverReflect.CallPrivate<float>(__instance, "GetFuel");
				int num2 = HoverReflect.CallPrivate<int>(__instance, "GetQueueSize");
				int num3 = Mathf.FloorToInt(num / (float)__instance.m_fuelPerProduct);
				if (num3 >= num2)
				{
					__result += $"\n남은 연료로 {num3}개 처리 가능";
					return;
				}
				int num4 = num2 * __instance.m_fuelPerProduct;
				int num5 = Mathf.CeilToInt((float)num4 - num);
				__result += $"\n남은 연료로 {num3}개 처리 가능 (연료 {num5}개 부족)";
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] Smelter 연료칸 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Fermenter), "GetHoverText")]
internal static class Feature10_FermenterHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Fermenter __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoFermenter.Value)
		{
			return;
		}
		try
		{
			object obj = HoverReflect.CallPrivate<object>(__instance, "GetStatus");
			if (obj != null && !(obj.ToString() != "Fermenting"))
			{
				double num = HoverReflect.CallPrivate<double>(__instance, "GetFermentationTime");
				if (!(num < 0.0))
				{
					float seconds = Mathf.Max(0f, __instance.m_fermentationDuration - (float)num);
					__result = __result + "\n완성까지 " + TweaksTimeFormat.Format(seconds);
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] Fermenter 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "GetHoverText")]
internal static class Feature10_FireplaceHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Fireplace __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoFire.Value)
		{
			return;
		}
		try
		{
			if (!__instance.m_infiniteFuel)
			{
				ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
				if (!((Object)(object)value == (Object)null) && value.IsValid())
				{
					float num = value.GetZDO().GetFloat(ZDOVars.s_fuel, 0f);
					float seconds = num * __instance.m_secPerFuel;
					__result = __result + "\n연료 " + TweaksTimeFormat.Format(seconds) + " 남음";
				}
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] Fireplace 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Beehive), "GetHoverText")]
internal static class Feature10_BeehiveHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Beehive __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoBeehive.Value)
		{
			return;
		}
		try
		{
			int num = HoverReflect.CallPrivate<int>(__instance, "GetHoneyLevel");
			if (num >= __instance.m_maxHoney)
			{
				__result += "\n가득참";
				return;
			}
			ZNetView value = Traverse.Create((object)__instance).Field("m_nview").GetValue<ZNetView>();
			if (!((Object)(object)value == (Object)null) && value.IsValid())
			{
				float num2 = value.GetZDO().GetFloat(ZDOVars.s_product, 0f);
				float seconds = Mathf.Max(0f, __instance.m_secPerUnit - num2);
				__result = __result + "\n다음 꿀까지 " + TweaksTimeFormat.Format(seconds);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] Beehive 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "GetHoverText")]
internal static class Feature10_CookingStationHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(CookingStation __instance, ref string __result)
	{
		if (!TweaksConfig.HoverInfoEnabled.Value || !TweaksConfig.HoverInfoCooking.Value)
		{
			return;
		}
		try
		{
			if (__instance.m_slots == null || __instance.m_slots.Length == 0)
			{
				return;
			}
			StringBuilder stringBuilder = new StringBuilder();
			for (int i = 0; i < __instance.m_slots.Length; i++)
			{
				object[] array = new object[5] { i, "", 0f, 0, false };
				HoverReflect.InvokeWithRefArgs(__instance, "GetSlot", array);
				string text = (string)array[1];
				float num = (float)array[2];
				int num2 = (int)array[3];
				if (string.IsNullOrEmpty(text))
				{
					continue;
				}
				switch (num2)
				{
				case 1:
					stringBuilder.Append("\n" + text + ": 곧 탐! 경고");
					continue;
				case 2:
					continue;
				}
				object obj = HoverReflect.CallPrivate<object>(__instance, "GetItemConversion", new object[1] { text });
				if (obj != null)
				{
					float value = Traverse.Create(obj).Field("m_cookTime").GetValue<float>();
					float seconds = Mathf.Max(0f, value - num);
					stringBuilder.Append("\n" + text + ": 완성까지 " + TweaksTimeFormat.Format(seconds));
				}
			}
			if (stringBuilder.Length > 0)
			{
				__result += stringBuilder.ToString();
			}
			if (__instance.m_useFuel)
			{
				float num3 = HoverReflect.CallPrivate<float>(__instance, "GetFuel");
				__result += $"\n연료 {Mathf.Ceil(num3)}/{__instance.m_maxFuel}";
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능10-조준정보] CookingStation 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Player), "CanEat")]
internal static class Feature11_CanEatPatch
{
	[HarmonyPrefix]
	private static bool Prefix(Player __instance, ItemData item, bool showMessages, ref bool __result)
	{
		if (!TweaksConfig.FoodSlotsEnabled.Value)
		{
			return true;
		}
		try
		{
			int num = Mathf.Max(3, TweaksConfig.FoodSlotsCount.Value);
			List<Food> foods = __instance.GetFoods();
			foreach (Food item2 in foods)
			{
				if (item2.m_item.m_shared.m_name == item.m_shared.m_name)
				{
					if (item2.CanEatAgain())
					{
						__result = true;
						return false;
					}
					if (showMessages)
					{
						((Character)__instance).Message((MessageType)2, Localization.instance.Localize("$msg_nomore", new string[1] { item.m_shared.m_name }), 0, (Sprite)null, false);
					}
					__result = false;
					return false;
				}
			}
			foreach (Food item3 in foods)
			{
				if (item3.CanEatAgain())
				{
					__result = true;
					return false;
				}
			}
			if (foods.Count >= num)
			{
				if (showMessages)
				{
					((Character)__instance).Message((MessageType)2, "$msg_isfull", 0, (Sprite)null, false);
				}
				__result = false;
				return false;
			}
			__result = true;
			return false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능11-음식슬롯] CanEat 처리 중 오류: {arg}");
			return true;
		}
	}
}
[HarmonyPatch(typeof(Player), "EatFood")]
internal static class Feature11_EatFoodPatch
{
	[HarmonyPrefix]
	private static bool Prefix(Player __instance, ItemData item, ref bool __result)
	{
		//IL_0237: Unknown result type (might be due to invalid IL or missing references)
		//IL_023c: Unknown result type (might be due to invalid IL or missing references)
		//IL_024d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0254: Unknown result type (might be due to invalid IL or missing references)
		//IL_0265: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_0287: Unknown result type (might be due to invalid IL or missing references)
		//IL_029a: Expected O, but got Unknown
		if (!TweaksConfig.FoodSlotsEnabled.Value)
		{
			return true;
		}
		try
		{
			if (!__instance.CanEat(item, false))
			{
				__result = false;
				return false;
			}
			int num = Mathf.Max(3, TweaksConfig.FoodSlotsCount.Value);
			string text = "";
			if (item.m_shared.m_food > 0f)
			{
				text = text + " +" + item.m_shared.m_food + " $item_food_health ";
			}
			if (item.m_shared.m_foodStamina > 0f)
			{
				text = text + " +" + item.m_shared.m_foodStamina + " $item_food_stamina ";
			}
			if (item.m_shared.m_foodEitr > 0f)
			{
				text = text + " +" + item.m_shared.m_foodEitr + " $item_food_eitr ";
			}
			((Character)__instance).Message((MessageType)2, text, 0, (Sprite)null, false);
			List<Food> foods = __instance.GetFoods();
			foreach (Food item3 in foods)
			{
				if (item3.m_item.m_shared.m_name == item.m_shared.m_name)
				{
					if (item3.CanEatAgain())
					{
						item3.m_time = item.m_shared.m_foodBurnTime;
						item3.m_health = item.m_shared.m_food;
						item3.m_stamina = item.m_shared.m_foodStamina;
						item3.m_eitr = item.m_shared.m_foodEitr;
						Game.instance.IncrementPlayerStat((PlayerStatType)49, 1f, false);
						Game.instance.GetPlayerProfile().IncrementStatFoodEaten(item.m_shared.m_name, 1f, item.m_cheated);
						InvokeVanillaUpdateFood(__instance);
						__result = true;
						return false;
					}
					__result = false;
					return false;
				}
			}
			if (foods.Count < num)
			{
				Food item2 = new Food
				{
					m_name = ((Object)item.m_dropPrefab).name,
					m_item = item,
					m_time = item.m_shared.m_foodBurnTime,
					m_health = item.m_shared.m_food,
					m_stamina = item.m_shared.m_foodStamina,
					m_eitr = item.m_shared.m_foodEitr
				};
				foods.Add(item2);
				Game.instance.IncrementPlayerStat((PlayerStatType)49, 1f, false);
				Game.instance.GetPlayerProfile().IncrementStatFoodEaten(item.m_shared.m_name, 1f, item.m_cheated);
				InvokeVanillaUpdateFood(__instance);
				__result = true;
				return false;
			}
			Food mostDepletedFood = GetMostDepletedFood(foods);
			if (mostDepletedFood != null)
			{
				mostDepletedFood.m_name = ((Object)item.m_dropPrefab).name;
				mostDepletedFood.m_item = item;
				mostDepletedFood.m_time = item.m_shared.m_foodBurnTime;
				mostDepletedFood.m_health = item.m_shared.m_food;
				mostDepletedFood.m_stamina = item.m_shared.m_foodStamina;
				Game.instance.IncrementPlayerStat((PlayerStatType)49, 1f, false);
				Game.instance.GetPlayerProfile().IncrementStatFoodEaten(item.m_shared.m_name, 1f, item.m_cheated);
				InvokeVanillaUpdateFood(__instance);
				__result = true;
				return false;
			}
			__result = false;
			return false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능11-음식슬롯] EatFood 처리 중 오류: {arg}");
			return true;
		}
	}

	private static Food GetMostDepletedFood(List<Food> foods)
	{
		Food val = null;
		foreach (Food food in foods)
		{
			if (food.CanEatAgain() && (val == null || food.m_time < val.m_time))
			{
				val = food;
			}
		}
		return val;
	}

	private static void InvokeVanillaUpdateFood(Player player)
	{
		AccessTools.Method(typeof(Player), "UpdateFood", (Type[])null, (Type[])null).Invoke(player, new object[2] { 0f, true });
	}
}
[HarmonyPatch(typeof(Hud), "Awake")]
internal static class Feature11_HudFoodSlotsPatch
{
	[HarmonyPostfix]
	private static void Postfix(Hud __instance)
	{
		//IL_01a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b9: Unknown result type (might be due to invalid IL or missing references)
		//IL_01be: Unknown result type (might be due to invalid IL or missing references)
		//IL_01fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0223: Unknown result type (might be due to invalid IL or missing references)
		//IL_0245: Unknown result type (might be due to invalid IL or missing references)
		//IL_0247: Unknown result type (might be due to invalid IL or missing references)
		//IL_0276: Unknown result type (might be due to invalid IL or missing references)
		//IL_027b: Unknown result type (might be due to invalid IL or missing references)
		//IL_027f: 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_033d: Unknown result type (might be due to invalid IL or missing references)
		//IL_033f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0344: Unknown result type (might be due to invalid IL or missing references)
		//IL_0349: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c6: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_03d2: Unknown result type (might be due to invalid IL or missing references)
		if (!TweaksConfig.FoodSlotsEnabled.Value)
		{
			return;
		}
		try
		{
			Image[] foodBars = __instance.m_foodBars;
			int num = ((foodBars != null) ? foodBars.Length : 0);
			int num2 = Mathf.Max(3, TweaksConfig.FoodSlotsCount.Value);
			if (num < 2 || num2 <= num)
			{
				return;
			}
			Image val = __instance.m_foodBars[num - 1];
			Image val2 = __instance.m_foodIcons[num - 1];
			TMP_Text val3 = __instance.m_foodTime[num - 1];
			Transform parent = ((Component)__instance.m_foodIcons[0]).transform.parent;
			Transform parent2 = ((Component)__instance.m_foodIcons[1]).transform.parent;
			Transform parent3 = ((Component)val2).transform.parent;
			if ((Object)(object)parent == (Object)null || (Object)(object)parent2 == (Object)null || (Object)(object)parent3 == (Object)null || (Object)(object)__instance.m_foodTime[0].transform.parent != (Object)(object)parent || (Object)(object)__instance.m_foodTime[1].transform.parent != (Object)(object)parent2 || (Object)(object)val3.transform.parent != (Object)(object)parent3)
			{
				Plugin.Log.LogError((object)"[Tweaks:기능11-음식슬롯] 칸 오브젝트 구조가 예상과 달라 확장을 건너뜀(아이콘·시간이 같은 칸의 자식이 아님).");
				return;
			}
			RectTransform val4 = AsRect(parent);
			RectTransform val5 = AsRect(parent2);
			RectTransform val6 = AsRect(parent3);
			if ((Object)(object)val4 == (Object)null || (Object)(object)val5 == (Object)null || (Object)(object)val6 == (Object)null)
			{
				Plugin.Log.LogError((object)"[Tweaks:기능11-음식슬롯] 칸 오브젝트에 RectTransform이 없어 확장을 건너뜀.");
				return;
			}
			Vector2 delta = GetDelta(((Graphic)__instance.m_foodBars[0]).rectTransform, ((Graphic)__instance.m_foodBars[1]).rectTransform);
			Vector2 val7 = val5.anchoredPosition - val4.anchoredPosition;
			bool flag = HasLayoutGroup(((Component)val).transform.parent);
			bool flag2 = HasLayoutGroup(parent3.parent);
			Plugin.Log.LogInfo((object)("[Tweaks:기능11-음식슬롯][진단] " + $"slotParent={Describe(parent3.parent)} slotDelta={val7} slotLayoutGroup={flag2} " + $"barParent={Describe(((Component)val).transform.parent)} barDelta={delta} barLayoutGroup={flag}"));
			if (!flag2 && val7 == Vector2.zero)
			{
				Plugin.Log.LogError((object)"[Tweaks:기능11-음식슬롯] 칸끼리의 위치 차이가 0이고 레이아웃 그룹도 없어 새 칸의 위치를 계산할 수 없음 — 확장을 건너뜀.");
				return;
			}
			Vector2 anchoredPosition = ((Graphic)val).rectTransform.anchoredPosition;
			Vector2 anchoredPosition2 = val6.anchoredPosition;
			Image[] array = (Image[])(object)new Image[num2];
			Image[] array2 = (Image[])(object)new Image[num2];
			TMP_Text[] array3 = (TMP_Text[])(object)new TMP_Text[num2];
			Array.Copy(__instance.m_foodBars, array, num);
			Array.Copy(__instance.m_foodIcons, array2, num);
			Array.Copy(__instance.m_foodTime, array3, num);
			List<string> list = new List<string>();
			for (int i = num; i < num2; i++)
			{
				int num3 = i - (num - 1);
				Image val8 = Object.Instantiate<Image>(val, ((Component)val).transform.parent);
				((Object)val8).name = $"foodbar_{i}";
				((Component)val8).transform.SetAsLastSibling();
				((Component)val8).gameObject.SetActive(true);
				if (!flag)
				{
					((Graphic)val8).rectTransform.anchoredPosition = anchoredPosition + delta * (float)num3;
				}
				array[i] = val8;
				GameObject val9 = Object.Instantiate<GameObject>(((Component)parent3).gameObject, parent3.parent);
				((Object)val9).name = $"food{i}";
				val9.transform.SetAsLastSibling();
				val9.SetActive(true);
				RectTransform val10 = AsRect(val9.transform);
				if (!flag2 && (Object)(object)val10 != (Object)null)
				{
					val10.anchoredPosition = anchoredPosition2 + val7 * (float)num3;
				}
				Transform val11 = FindCorrespondingChild(val9.transform, parent3, ((Component)val2).transform);
				Transform val12 = FindCorrespondingChild(val9.transform, parent3, val3.transform);
				Image val13 = (((Object)(object)val11 != (Object)null) ? ((Component)val11).GetComponent<Image>() : null);
				TMP_Text val14 = (((Object)(object)val12 != (Object)null) ? ((Component)val12).GetComponent<TMP_Text>() : null);
				if ((Object)(object)val13 == (Object)null || (Object)(object)val14 == (Object)null)
				{
					Plugin.Log.LogError((object)("[Tweaks:기능11-음식슬롯] " + ((Object)val9).name + " 안에서 아이콘·시간 자식을 찾지 못함 — 이 칸은 정상 갱신되지 않을 수 있음."));
				}
				array2[i] = val13;
				array3[i] = val14;
				list.Add(((Object)val9).name);
			}
			__instance.m_foodBars = array;
			__instance.m_foodIcons = array2;
			__instance.m_foodTime = array3;
			ForceLayoutRebuild(((Component)val).transform.parent);
			ForceLayoutRebuild(parent3.parent);
			Plugin.Log.LogInfo((object)("[Tweaks:기능11-음식슬롯][진단] 생성된 칸: " + string.Join(", ", list)));
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능11-음식슬롯] HUD 슬롯 확장 중 오류: {arg}");
		}
	}

	private static Transform FindCorrespondingChild(Transform cloneRoot, Transform originalRoot, Transform originalTarget)
	{
		List<int> list = new List<int>();
		Transform val = originalTarget;
		while ((Object)(object)val != (Object)null && (Object)(object)val != (Object)(object)originalRoot)
		{
			list.Add(val.GetSiblingIndex());
			val = val.parent;
		}
		list.Reverse();
		Transform val2 = cloneRoot;
		foreach (int item in list)
		{
			if ((Object)(object)val2 == (Object)null || item >= val2.childCount)
			{
				return null;
			}
			val2 = val2.GetChild(item);
		}
		return val2;
	}

	private static RectTransform AsRect(Transform t)
	{
		return (RectTransform)(((object)((t is RectTransform) ? t : null)) ?? ((object)((t != null) ? ((Component)t).GetComponent<RectTransform>() : null)));
	}

	private static Vector2 GetDelta(RectTransform a, RectTransform b)
	{
		//IL_0002: 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)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: 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)
		return b.anchoredPosition - a.anchoredPosition;
	}

	private static bool HasLayoutGroup(Transform parent)
	{
		return (Object)(object)parent != (Object)null && (Object)(object)((Component)parent).GetComponent<HorizontalOrVerticalLayoutGroup>() != (Object)null;
	}

	private static void ForceLayoutRebuild(Transform parent)
	{
		if (!((Object)(object)parent == (Object)null))
		{
			RectTransform val = (RectTransform)(((object)((parent is RectTransform) ? parent : null)) ?? ((object)((Component)parent).GetComponent<RectTransform>()));
			if ((Object)(object)val != (Object)null)
			{
				LayoutRebuilder.ForceRebuildLayoutImmediate(val);
			}
		}
	}

	private static string Describe(Transform t)
	{
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)t == (Object)null)
		{
			return "null";
		}
		StringBuilder stringBuilder = new StringBuilder();
		Component[] components = ((Component)t).GetComponents<Component>();
		foreach (Component val in components)
		{
			stringBuilder.Append(((object)val).GetType().Name).Append(',');
		}
		RectTransform val2 = (RectTransform)(object)((t is RectTransform) ? t : null);
		string arg = (((Object)(object)val2 != (Object)null) ? $" sizeDelta={val2.sizeDelta} anchorMin={val2.anchorMin} anchorMax={val2.anchorMax}" : "");
		return $"{((Object)t).name}[{stringBuilder}]{arg}";
	}
}
[HarmonyPatch(typeof(CraftingStation), "Start")]
internal static class Feature12_NoRoofCraftingPatch
{
	[HarmonyPostfix]
	private static void Postfix(CraftingStation __instance)
	{
		if (!TweaksConfig.NoRoofCraftingEnabled.Value)
		{
			return;
		}
		try
		{
			__instance.m_craftRequireRoof = false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능12-지붕요구제거] '{((Object)__instance).name}' 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(SE_Rested), "Setup")]
internal static class Feature13_RestedDurationPatch
{
	[HarmonyPrefix]
	private static void Prefix(SE_Rested __instance)
	{
		if (!TweaksConfig.RestedDurationEnabled.Value)
		{
			return;
		}
		try
		{
			__instance.m_baseTTL = TweaksConfig.RestedBaseDuration.Value;
			__instance.m_TTLPerComfortLevel = TweaksConfig.RestedDurationPerComfort.Value;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능13-휴식지속시간] 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(EnvMan), "Awake")]
internal static class Feature14_DayLengthPatch
{
	[HarmonyPostfix]
	private static void Postfix(EnvMan __instance)
	{
		if (!TweaksConfig.DayLengthEnabled.Value)
		{
			return;
		}
		try
		{
			__instance.m_dayLengthSec = (long)TweaksConfig.DayLengthSeconds.Value;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능14-하루길이] 처리 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Player), "UpdateFood")]
internal static class Feature15_SmoothFoodRegenPatch
{
	private static readonly ConditionalWeakTable<Player, StrongBox<float>> s_accum = new ConditionalWeakTable<Player, StrongBox<float>>();

	[HarmonyPrefix]
	private static void Prefix(Player __instance)
	{
		if (!TweaksConfig.SmoothFoodRegenEnabled.Value)
		{
			return;
		}
		try
		{
			Traverse.Create((object)__instance).Field("m_foodRegenTimer").SetValue((object)0f);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능15-회복분산] 바닐라 회복 타이머 억제 중 오류: {arg}");
		}
	}

	[HarmonyPostfix]
	private static void Postfix(Player __instance, float dt, bool forceUpdate)
	{
		if (!TweaksConfig.SmoothFoodRegenEnabled.Value || forceUpdate)
		{
			return;
		}
		try
		{
			StrongBox<float> orCreateValue = s_accum.GetOrCreateValue(__instance);
			orCreateValue.Value += dt;
			while (orCreateValue.Value >= 1f)
			{
				orCreateValue.Value -= 1f;
				ApplyOneSecondRegen(__instance);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능15-회복분산] 1초 회복 적용 중 오류: {arg}");
		}
	}

	private static void ApplyOneSecondRegen(Player player)
	{
		float num = 0f;
		foreach (Food food in player.GetFoods())
		{
			num += food.m_item.m_shared.m_foodRegen;
		}
		if (!(num <= 0f))
		{
			float num2 = 1f;
			((Character)player).GetSEMan().ModifyHealthRegen(ref num2);
			float num3 = num / 10f * num2;
			if (num3 > 0f)
			{
				((Character)player).Heal(num3, true);
			}
		}
	}
}
internal static class Feature16_ContainerSnapshot
{
	private const float CacheLifetimeSeconds = 2.5f;

	private static Player s_cachedPlayer;

	private static float s_cachedTime = float.NegativeInfinity;

	private static List<Container> s_cachedContainers;

	private static bool s_consumedSinceCache;

	public static List<Container> GetOrScan(Player player)
	{
		float time = Time.time;
		if ((Object)(object)s_cachedPlayer == (Object)(object)player && s_cachedContainers != null && !s_consumedSinceCache && time - s_cachedTime <= 2.5f)
		{
			return s_cachedContainers;
		}
		s_cachedContainers = new List<Container>(ContainerAccessHelper.GetAccessibleContainers(player, TweaksConfig.CraftFromContainersRadius.Value));
		s_cachedPlayer = player;
		s_cachedTime = time;
		s_consumedSinceCache = false;
		return s_cachedContainers;
	}

	public static void MarkConsumed()
	{
		s_consumedSinceCache = true;
	}
}
[HarmonyPatch(typeof(Player), "HaveRequirementItems", new Type[]
{
	typeof(Recipe),
	typeof(bool),
	typeof(int),
	typeof(int)
})]
internal static class Feature16_HaveRequirementItemsPatch
{
	[HarmonyPrefix]
	private static bool Prefix(Player __instance, Recipe piece, bool discover, int qualityLevel, int amount, ref bool __result)
	{
		if (!TweaksConfig.CraftFromContainersEnabled.Value || discover)
		{
			return true;
		}
		try
		{
			CraftingStation currentCraftingStation = __instance.GetCurrentCraftingStation();
			Inventory inventory = ((Humanoid)__instance).GetInventory();
			List<Container> orScan = Feature16_ContainerSnapshot.GetOrScan(__instance);
			bool requireOnlyOneIngredient = piece.m_requireOnlyOneIngredient;
			Requirement[] resources = piece.m_resources;
			foreach (Requirement val in resources)
			{
				if (((Object)(object)currentCraftingStation != (Object)null && currentCraftingStation.m_upgrader != val.m_upgraderResource) || ((Object)(object)currentCraftingStation == (Object)null && val.m_upgraderResource) || !Object.op_Implicit((Object)(object)val.m_resItem))
				{
					continue;
				}
				int num = val.GetAmount(qualityLevel) * amount;
				int num2 = 0;
				int maxQuality = val.m_resItem.m_itemData.m_shared.m_maxQuality;
				for (int j = 1; j < maxQuality + 1; j++)
				{
					string name = val.m_resItem.m_itemData.m_shared.m_name;
					int num3 = inventory.CountItems(name, j, true) + ContainerAccessHelper.SumContainerCount(orScan, name, j);
					if (num3 > num2)
					{
						num2 = num3;
					}
				}
				if (requireOnlyOneIngredient)
				{
					if (num2 >= num)
					{
						__result = true;
						return false;
					}
				}
				else if (num2 < num)
				{
					__result = false;
					return false;
				}
			}
			__result = !requireOnlyOneIngredient;
			return false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능16-상자재료] 재료 보유 판정(Recipe) 중 오류: {arg}");
			return true;
		}
	}
}
[HarmonyPatch(typeof(Player), "HaveRequirements", new Type[]
{
	typeof(Piece),
	typeof(RequirementMode)
})]
internal static class Feature16_HaveRequirementsPiecePatch
{
	[HarmonyPrefix]
	private static bool Prefix(Player __instance, Piece piece, RequirementMode mode, ref bool __result)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Invalid comparison between Unknown and I4
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_00af: Unknown result type (might be due to invalid IL or missing references)
		if (!TweaksConfig.CraftFromContainersEnabled.Value || (int)mode > 0)
		{
			return true;
		}
		try
		{
			if (Object.op_Implicit((Object)(object)piece.m_craftingStation) && !Object.op_Implicit((Object)(object)CraftingStation.HaveBuildStationInRange(piece.m_craftingStation.m_name, ((Component)__instance).transform.position)) && !ZoneSystem.instance.GetGlobalKey((GlobalKeys)27))
			{
				__result = false;
				return false;
			}
			if (piece.m_dlc.Length > 0 && !DLCMan.instance.IsDLCInstalled(piece.m_dlc))
			{
				__result = false;
				return false;
			}
			if (ZoneSystem.instance.GetGlobalKey(piece.FreeBuildKey()))
			{
				__result = true;
				return false;
			}
			Inventory inventory = ((Humanoid)__instance).GetInventory();
			List<Container> orScan = Feature16_ContainerSnapshot.GetOrScan(__instance);
			Requirement[] resources = piece.m_resources;
			foreach (Requirement val in resources)
			{
				if (Object.op_Implicit((Object)(object)val.m_resItem) && val.m_amount > 0)
				{
					string name = val.m_resItem.m_itemData.m_shared.m_name;
					int num = inventory.CountItems(name, -1, true) + ContainerAccessHelper.SumContainerCount(orScan, name, -1);
					if (num < val.m_amount)
					{
						__result = false;
						return false;
					}
				}
			}
			__result = true;
			return false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능16-상자재료] 재료 보유 판정(Piece) 중 오류: {arg}");
			return true;
		}
	}
}
[HarmonyPatch(typeof(Player), "ConsumeResources")]
internal static class Feature16_ConsumeResourcesPatch
{
	private const float ConsumeRadiusMargin = 5f;

	[HarmonyPrefix]
	private static bool Prefix(Player __instance, Requirement[] requirements, int qualityLevel, int itemQuality, int multiplier)
	{
		if (!TweaksConfig.CraftFromContainersEnabled.Value || __instance.NoCostCheat())
		{
			return true;
		}
		try
		{
			CraftingStation currentCraftingStation = __instance.GetCurrentCraftingStation();
			Inventory inventory = ((Humanoid)__instance).GetInventory();
			List<Container> list = new List<Container>(Feature16_ContainerSnapshot.GetOrScan(__instance));
			Feature16_ContainerSnapshot.MarkConsumed();
			bool flag = false;
			List<(Requirement, int, int)> list2 = new List<(Requirement, int, int)>();
			bool flag2 = false;
			foreach (Requirement val in requirements)
			{
				if (((Object)(object)currentCraftingStation != (Object)null && currentCraftingStation.m_upgrader != val.m_upgraderResource) || ((Object)(object)currentCraftingStation == (Object)null && val.m_upgraderResource) || !Object.op_Implicit((Object)(object)val.m_resItem))
				{
					continue;
				}
				int num = val.GetAmount(qualityLevel) * multiplier;
				if (num <= 0)
				{
					continue;
				}
				string name = val.m_resItem.m_itemData.m_shared.m_name;
				int num2 = inventory.CountItems(name, itemQuality, true);
				int num3 = Mathf.Min(num2, num);
				int num4 = ContainerAccessHelper.SumContainerCount(list, name, itemQuality);
				int num5 = num - num3 - Mathf.Min(num4, num - num3);
				if (num5 > 0 && !flag)
				{
					flag = true;
					float radius = TweaksConfig.CraftFromContainersRadius.Value + 5f;
					foreach (Container accessibleContainer in ContainerAccessHelper.GetAccessibleContainers(__instance, radius))
					{
						if (!list.Contains(accessibleContainer))
						{
							list.Add(accessibleContainer);
						}
					}
					num4 = ContainerAccessHelper.SumContainerCount(list, name, itemQuality);
					num5 = num - num3 - Mathf.Min(num4, num - num3);
				}
				if (num5 > 0)
				{
					flag2 = true;
					Plugin.Log.LogError((object)$"[Tweaks:기능16-상자재료] '{name}' {num5}개 부족 — 판정 시점과 소모 시점의 수량이 어긋남(여유 마진 반경으로도 못 채움). 이번 소모는 중단하지 못하고 가능한 만큼만 차감됨에 유의.");
				}
				list2.Add((val, num, num3));
			}
			if (flag2)
			{
				((Character)__instance).Message((MessageType)2, "$msg_missingrequirement", 0, (Sprite)null, false);
			}
			foreach (var item4 in list2)
			{
				Requirement item = item4.Item1;
				int item2 = item4.Item2;
				int item3 = item4.Item3;
				string name2 = item.m_resItem.m_itemData.m_shared.m_name;
				if (item3 > 0)
				{
					inventory.RemoveItem(name2, item3, itemQuality, true);
				}
				int num6 = item2 - item3;
				if (num6 > 0)
				{
					int num7 = ContainerAccessHelper.ConsumeFromContainers(list, name2, itemQuality, num6);
					num6 -= num7;
					if (num6 > 0)
					{
						Plugin.Log.LogWarning((object)$"[Tweaks:기능16-상자재료] '{name2}' {num6}개를 끝내 채우지 못하고 소모를 마침.");
					}
				}
			}
			return false;
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능16-상자재료] 재료 소모 중 오류: {arg}");
			return true;
		}
	}
}
[HarmonyPatch(typeof(InventoryGui), "SetupRequirement")]
internal static class Feature16_SetupRequirementHintPatch
{
	[HarmonyPostfix]
	private static void Postfix(Transform elementRoot, Requirement req, Player player, bool craft, int quality, int craftMultiplier)
	{
		//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		if (!TweaksConfig.CraftFromContainersEnabled.Value || !TweaksConfig.CraftFromContainersShowCombinedCount.Value || (Object)(object)req.m_resItem == (Object)null)
		{
			return;
		}
		try
		{
			string name = req.m_resItem.m_itemData.m_shared.m_name;
			int num = req.GetAmount(quality) * craftMultiplier;
			if (num > 0)
			{
				int num2 = ((Humanoid)player).GetInventory().CountItems(name, -1, true);
				List<Container> orScan = Feature16_ContainerSnapshot.GetOrScan(player);
				int num3 = ContainerAccessHelper.SumContainerCount(orScan, name, -1);
				int num4 = num2 + num3;
				TMP_Text component = ((Component)((Component)elementRoot).transform.Find("res_amount")).GetComponent<TMP_Text>();
				component.text = $"{num}/{num4}";
				((Graphic)component).color = ((num4 >= num) ? Color.white : ((Mathf.Sin(Time.time * 10f) > 0f) ? Color.red : Color.white));
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능16-상자재료] 요구 재료 표시 보정 중 오류: {arg}");
		}
	}
}
internal static class Feature17_HoverState
{
	public static Smelter Smelter;

	public static bool IsOre;

	public static float LastSeenTime = -999f;

	public static void Mark(Smelter smelter, bool isOre)
	{
		Smelter = smelter;
		IsOre = isOre;
		LastSeenTime = Time.unscaledTime;
	}

	public static bool TryGetFresh(out Smelter smelter, out bool isOre)
	{
		smelter = Smelter;
		isOre = IsOre;
		return (Object)(object)smelter != (Object)null && Time.unscaledTime - LastSeenTime < 0.2f;
	}
}
[HarmonyPatch(typeof(Smelter), "OnHoverAddOre")]
internal static class Feature17_SmelterOreHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Smelter __instance, ref string __result)
	{
		if (!TweaksConfig.BulkInsertEnabled.Value)
		{
			return;
		}
		try
		{
			Feature17_HoverState.Mark(__instance, isOre: true);
			Feature17_Core.AppendHint(__instance, isOre: true, ref __result);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능17-일괄투입] 투입물 조준 표시 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Smelter), "OnHoverAddFuel")]
internal static class Feature17_SmelterFuelHoverPatch
{
	[HarmonyPostfix]
	private static void Postfix(Smelter __instance, ref string __result)
	{
		if (!TweaksConfig.BulkInsertEnabled.Value)
		{
			return;
		}
		try
		{
			Feature17_HoverState.Mark(__instance, isOre: false);
			Feature17_Core.AppendHint(__instance, isOre: false, ref __result);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능17-일괄투입] 연료 조준 표시 중 오류: {arg}");
		}
	}
}
[HarmonyPatch(typeof(Player), "Update")]
internal static class Feature17_BulkInsertActionPatch
{
	[HarmonyPostfix]
	private static void Postfix(Player __instance)
	{
		//IL_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		if (!TweaksConfig.BulkInsertEnabled.Value || (Object)(object)__instance != (Object)(object)Player.m_localPlayer)
		{
			return;
		}
		try
		{
			KeyboardShortcut value = TweaksConfig.BulkInsertShortcut.Value;
			if (((KeyboardShortcut)(ref value)).IsDown() && Feature17_HoverState.TryGetFresh(out var smelter, out var isOre))
			{
				Feature17_Core.DoBulkInsert(smelter, isOre, __instance);
			}
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능17-일괄투입] 단축키 처리 중 오류: {arg}");
		}
	}
}
internal static class Feature17_Core
{
	public static void AppendHint(Smelter smelter, bool isOre, ref string result)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		if (!((Object)(object)localPlayer == (Object)null) && HasRemainingCapacity(smelter, isOre) && TryPickItem(localPlayer, smelter, isOre, out var itemName, out var invCount, out var containerCount) && invCount + containerCount > 0)
		{
			string text = ((object)TweaksConfig.BulkInsertShortcut.Value/*cast due to .constrained prefix*/).ToString();
			string text2 = Localization.instance.Localize(itemName);
			result += $"\n[<color=yellow><b>{text}</b></color>] 일괄 투입: {text2} (인벤 {invCount} + 상자 {containerCount})";
		}
	}

	public static bool HasRemainingCapacity(Smelter smelter, bool isOre)
	{
		try
		{
			if (isOre)
			{
				int num = HoverReflect.CallPrivate<int>(smelter, "GetQueueSize");
				return num < smelter.m_maxOre;
			}
			float num2 = HoverReflect.CallPrivate<float>(smelter, "GetFuel");
			return !(num2 > (float)(smelter.m_maxFuel - 1));
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:기능17-일괄투입] 잔여 용량 확인 중 오류: {arg}");
			return false;
		}
	}

	private static bool TryPickItem(Player player, Smelter smelter, bool isOre, out string itemName, out int invCount, out int containerCount)
	{
		itemName = null;
		invCount = 0;
		containerCount = 0;
		List<Container> list = (TweaksConfig.BulkInsertIncludeContainers.Value ? ContainerAccessHelper.GetAccessibleContainers(player, TweaksConfig.CraftFromContainersRadius.Value) : null);
		if (isOre)
		{
			foreach (ItemConversion item in smelter.m_conversion)
			{
				if (!((Object)(object)item.m_from == (Object)null))
				{
					string name = item.m_from.m_itemData.m_shared.m_name;
					int num = ((Humanoid)player).GetInventory().CountItems(name, -1, true);
					int num2 = ((list != null) ? ContainerAccessHelper.SumContainerCount(list, name, -1) : 0);
					if (num + num2 > 0)
					{
						itemName = name;
						invCount = num;
						containerCount = num2;
						return true;
					}
				}
			}
			return false;
		}
		if ((Object)(object)smelter.m_fuelItem == (Object)null)
		{
			return false;
		}
		string name2 = smelter.m_fuelItem.m_itemData.m_shared.m_name;
		invCount = ((Humanoid)player).GetInventory().CountItems(name2, -1, true);
		containerCount = ((list != null) ? ContainerAccessHelper.SumContainerCount(list, name2, -1) : 0);
		itemName = name2;
		return invCount + containerCount > 0;
	}

	public static void DoBulkInsert(Smelter smelter, bool isOre, Player player)
	{
		if ((Object)(object)smelter == (Object)null)
		{
			return;
		}
		Switch val = (isOre ? smelter.m_addOreSwitch : smelter.m_addWoodSwitch);
		if ((Object)(object)val == (Object)null)
		{
			return;
		}
		int num = 0;
		int num2 = 999;
		while (num2-- > 0 && HasRemainingCapacity(smelter, isOre))
		{
			if (val.Interact((Humanoid)(object)player, false, false))
			{
				num++;
			}
			else if (!TweaksConfig.BulkInsertIncludeContainers.Value || !TryPullOneItemFromContainers(player, smelter, isOre))
			{
				break;
			}
		}
		if (num > 0)
		{
			((Character)player).Message((MessageType)2, $"일괄 투입 완료: {num}개", 0, (Sprite)null, false);
		}
	}

	private static bool TryPullOneItemFromContainers(Player player, Smelter smelter, bool isOre)
	{
		List<string> list = new List<string>();
		if (isOre)
		{
			foreach (ItemConversion item2 in smelter.m_conversion)
			{
				if ((Object)(object)item2.m_from != (Object)null)
				{
					list.Add(item2.m_from.m_itemData.m_shared.m_name);
				}
			}
		}
		else if ((Object)(object)smelter.m_fuelItem != (Object)null)
		{
			list.Add(smelter.m_fuelItem.m_itemData.m_shared.m_name);
		}
		if (list.Count == 0)
		{
			return false;
		}
		List<Container> accessibleContainers = ContainerAccessHelper.GetAccessibleContainers(player, TweaksConfig.CraftFromContainersRadius.Value);
		foreach (Container item3 in accessibleContainers)
		{
			Inventory inventory = item3.GetInventory();
			foreach (string item4 in list)
			{
				if (inventory.CountItems(item4, -1, true) <= 0)
				{
					continue;
				}
				ItemData item = inventory.GetItem(item4, -1, false);
				if (item == null)
				{
					continue;
				}
				ItemData val = item.Clone();
				val.m_stack = 1;
				if (!((Humanoid)player).GetInventory().AddItem(val))
				{
					return false;
				}
				ContainerAccessHelper.ClaimOwnership(item3);
				inventory.RemoveOneItem(item);
				return true;
			}
		}
		return false;
	}
}
[BepInPlugin("MM94.Tweaks", "Tweaks", "1.1.3")]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGUID = "MM94.Tweaks";

	public const string PluginName = "Tweaks";

	public const string PluginVersion = "1.1.3";

	internal static ManualLogSource Log;

	private readonly Harmony _harmony = new Harmony("MM94.Tweaks");

	private void Awake()
	{
		Log = ((BaseUnityPlugin)this).Logger;
		LogBuildInfo();
		TweaksConfig.Init(((BaseUnityPlugin)this).Config);
		ApplyHarmonyPatchesIsolated();
		Log.LogInfo((object)"[Tweaks:기능8-조사결과] vanilla에는 불 근처 체류 기반 Rested 자동부여 경로가 없음(SE_Rested는 SetSleeping(false)에서만 Add) — WaitSeconds는 이 모드 자체 타이머.");
		Log.LogInfo((object)"Tweaks v1.1.3 loaded.");
	}

	private void ApplyHarmonyPatchesIsolated()
	{
		int num = 0;
		int num2 = 0;
		List<Type> list = (from t in AccessTools.GetTypesFromAssembly(Assembly.GetExecutingAssembly())
			where t.GetCustomAttributes(typeof(HarmonyPatch), inherit: false).Length != 0
			select t).ToList();
		foreach (Type item in list)
		{
			try
			{
				_harmony.CreateClassProcessor(item).Patch();
				num++;
			}
			catch (Exception arg)
			{
				num2++;
				Log.LogError((object)$"[Tweaks:패치실패] '{item.FullName}' 패치 적용 실패 — 이 기능만 비활성화된 채로 나머지는 계속 진행됨. {arg}");
			}
		}
		Log.LogInfo((object)$"[Tweaks:패치요약] 대상 클래스 {list.Count}개 — 성공 {num}개 / 실패 {num2}개");
	}

	private void LogBuildInfo()
	{
		try
		{
			string location = Assembly.GetExecutingAssembly().Location;
			DateTime lastWriteTime = File.GetLastWriteTime(location);
			Log.LogInfo((object)string.Format("[Tweaks:빌드정보] {0} — DLL 빌드 시각 {1:yyyy-MM-dd HH:mm:ss}", "1.1.3", lastWriteTime));
		}
		catch (Exception ex)
		{
			Log.LogError((object)("[Tweaks] 빌드 정보 로그 오류: " + ex.Message));
		}
	}
}
internal static class TweaksConfig
{
	public static ConfigEntry<bool> FoodSlotsEnabled;

	public static ConfigEntry<int> FoodSlotsCount;

	public static ConfigEntry<bool> NoRoofCraftingEnabled;

	public static ConfigEntry<bool> RestedDurationEnabled;

	public static ConfigEntry<float> RestedBaseDuration;

	public static ConfigEntry<float> RestedDurationPerComfort;

	public static ConfigEntry<bool> DayLengthEnabled;

	public static ConfigEntry<float> DayLengthSeconds;

	public static ConfigEntry<bool> SmoothFoodRegenEnabled;

	public static ConfigEntry<bool> CraftFromContainersEnabled;

	public static ConfigEntry<float> CraftFromContainersRadius;

	public static ConfigEntry<bool> CraftFromContainersShowCombinedCount;

	public static ConfigEntry<bool> BulkInsertEnabled;

	public static ConfigEntry<KeyboardShortcut> BulkInsertShortcut;

	public static ConfigEntry<bool> BulkInsertIncludeContainers;

	public static ConfigEntry<bool> LightEnabled;

	public static ConfigEntry<float> LightIntensityMultiplier;

	public static ConfigEntry<float> LightRangeMultiplier;

	public static ConfigEntry<bool> LightIncludeHandheld;

	public static ConfigEntry<bool> NoBuildZoneEnabled;

	public static ConfigEntry<bool> DungeonBuildEnabled;

	public static ConfigEntry<bool> StationDistanceEnabled;

	public static ConfigEntry<float> StationDistance;

	public static ConfigEntry<bool> StationSpacingEnabled;

	public static ConfigEntry<bool> BeehiveCeilingEnabled;

	public static ConfigEntry<bool> BeehiveIgnoreCoverEnabled;

	public static ConfigEntry<bool> RainGrowthEnabled;

	public static ConfigEntry<float> RainGrowthMultiplier;

	public static ConfigEntry<bool> BeehiveYieldEnabled;

	public static ConfigEntry<float> BeehiveYieldRadius;

	public static ConfigEntry<float> BeehiveYieldChance;

	public static ConfigEntry<int> BeehiveYieldBonusAmount;

	public static ConfigEntry<bool> InstantRestedEnabled;

	public static ConfigEntry<float> InstantRestedWaitSeconds;

	public static ConfigEntry<bool> SmelterCapacityEnabled;

	public static ConfigEntry<float> SmelterOreMultiplier;

	public static ConfigEntry<float> SmelterFuelMultiplier;

	public static ConfigEntry<bool> HoverInfoEnabled;

	public static ConfigEntry<bool> HoverInfoSmelter;

	public static ConfigEntry<bool> HoverInfoFermenter;

	public static ConfigEntry<bool> HoverInfoFire;

	public static ConfigEntry<bool> HoverInfoBeehive;

	public static ConfigEntry<bool> HoverInfoCooking;

	public static void Init(ConfigFile cfg)
	{
		//IL_04a3: Unknown result type (might be due to invalid IL or missing references)
		LightEnabled = cfg.Bind<bool>("01_Light", "Enabled", true, "광원 밝기·범위 조절 기능 사용 여부");
		LightIntensityMultiplier = cfg.Bind<float>("01_Light", "IntensityMultiplier", 1.5f, "횃불·모닥불 등 광원의 밝기 배율");
		LightRangeMultiplier = cfg.Bind<float>("01_Light", "RangeMultiplier", 2f, "횃불·모닥불 등 광원이 비추는 범위 배율");
		LightIncludeHandheld = cfg.Bind<bool>("01_Light", "IncludeHandheld", false, "손에 든 횃불의 광원에도 동일한 배율을 적용할지 여부");
		NoBuildZoneEnabled = cfg.Bind<bool>("02_NoBuildZone", "Enabled", true, "보스 제단·상인 주변 등 건설불가지역에서도 건설을 허용할지 여부 (경계석에 의한 제한은 영향받지 않음)");
		DungeonBuildEnabled = cfg.Bind<bool>("03_DungeonBuild", "Enabled", true, "매장지·동굴 등 던전 내부에서도 조각 설치를 허용할지 여부");
		StationDistanceEnabled = cfg.Bind<bool>("04_StationDistance", "Enabled", true, "제작대 부속품(절단대·가죽걸이 등)의 연결 거리 제한을 완화할지 여부");
		StationDistance = cfg.Bind<float>("04_StationDistance", "Distance", 50f, "제작대 부속품이 제작대와 연결되는 최대 거리(m). 0 이하로 설정하면 사실상 무제한으로 처리됨");
		StationSpacingEnabled = cfg.Bind<bool>("04_StationDistance", "SpacingEnabled", true, "부속품(절단대·가죽걸이 등)을 다른 부속품에 바짝 붙여 설치할 수 있도록 부속품 간 간격 제한을 제거할지 여부");
		BeehiveCeilingEnabled = cfg.Bind<bool>("05_Beehive", "CeilingPlacement", true, "벌집을 구조물 천장(아랫면)에도 설치할 수 있게 허용할지 여부");
		BeehiveIgnoreCoverEnabled = cfg.Bind<bool>("05_Beehive", "IgnoreCoverCheck", true, "벌집이 덮인 곳에 있어도 벌이 불행해지는 공간 검사를 무시할지 여부");
		RainGrowthEnabled = cfg.Bind<bool>("06_RainGrowth", "Enabled", true, "비가 내리는 동안 작물·묘목의 성장을 가속할지 여부 (지붕 등으로 덮여 비를 맞지 않는 개체는 제외)");
		RainGrowthMultiplier = cfg.Bind<float>("06_RainGrowth", "Multiplier", 2f, "비가 내리는 동안 적용되는 성장 속도 배율");
		BeehiveYieldEnabled = cfg.Bind<bool>("07_BeehiveYield", "Enabled", true, "벌집 근처에서 작물을 수확할 때 확률로 추가 산출을 얻을지 여부 (야생 채집물 제외)");
		BeehiveYieldRadius = cfg.Bind<float>("07_BeehiveYield", "Radius", 20f, "벌집 추가 산출이 적용되는 반경(m)");
		BeehiveYieldChance = cfg.Bind<float>("07_BeehiveYield", "Chance", 0.25f, "벌집 추가 산출이 발생할 확률 (0.0~1.0)");
		BeehiveYieldBonusAmount = cfg.Bind<int>("07_BeehiveYield", "BonusAmount", 1, "벌집 추가 산출 발생 시 추가로 얻는 개수");
		InstantRestedEnabled = cfg.Bind<bool>("08_InstantRested", "Enabled", true, "휴식 조건(불 근처 + 지붕 또는 앉기)을 만족하면 대기시간 없이 '충분한 휴식' 버프를 바로 적용할지 여부");
		InstantRestedWaitSeconds = cfg.Bind<float>("08_InstantRested", "WaitSeconds", 0f, "휴식 버프가 적용되기까지 불 근처에서 버텨야 하는 시간(초). 0이면 즉시 적용");
		SmelterCapacityEnabled = cfg.Bind<bool>("09_SmelterCapacity", "Enabled", true, "제련소·용광로·숯가마 등 제련 기기의 투입물·연료 최대 적재량을 늘릴지 여부");
		SmelterOreMultiplier = cfg.Bind<float>("09_SmelterCapacity", "OreMultiplier", 3f, "투입물(광석 등) 최대 적재량 배율");
		SmelterFuelMultiplier = cfg.Bind<float>("09_SmelterCapacity", "FuelMultiplier", 3f, "연료 최대 적재량 배율");
		HoverInfoEnabled = cfg.Bind<bool>("10_HoverInfo", "Enabled", true, "조준 시 생산 시간·연료 정보 표기 기능 전체 사용 여부");
		HoverInfoSmelter = cfg.Bind<bool>("10_HoverInfo", "Smelter", true, "제련소·용광로·숯가마 등 제련 기기 조준 시 정보 표기");
		HoverInfoFermenter = cfg.Bind<bool>("10_HoverInfo", "Fermenter", true, "발효기 조준 시 정보 표기");
		HoverInfoFire = cfg.Bind<bool>("10_HoverInfo", "Fire", true, "모닥불·화덕·횃불 거치대 조준 시 정보 표기");
		HoverInfoBeehive = cfg.Bind<bool>("10_HoverInfo", "Beehive", true, "벌집 조준 시 정보 표기");
		HoverInfoCooking = cfg.Bind<bool>("10_HoverInfo", "Cooking", true, "요리 거치대(돌 오븐 포함) 조준 시 정보 표기");
		FoodSlotsEnabled = cfg.Bind<bool>("11_FoodSlots", "Enabled", true, "동시에 먹을 수 있는 음식 슬롯 갯수를 늘릴지 여부");
		FoodSlotsCount = cfg.Bind<int>("11_FoodSlots", "SlotCount", 4, "동시에 먹을 수 있는 음식 최대 개수 (권장 범위 3~6, 최소 3)");
		NoRoofCraftingEnabled = cfg.Bind<bool>("12_NoRoofCrafting", "Enabled", true, "작업대·대장간 등 제작대의 지붕(비 가림) 요구 조건을 제거할지 여부");
		RestedDurationEnabled = cfg.Bind<bool>("13_RestedDuration", "Enabled", true, "휴식함(Rested) 버프의 지속시간을 조절할지 여부");
		RestedBaseDuration = cfg.Bind<float>("13_RestedDuration", "BaseDuration", 300f, "휴식함 버프의 기본 지속시간(초). 바닐라 기본값 300초");
		RestedDurationPerComfort = cfg.Bind<float>("13_RestedDuration", "DurationPerComfort", 60f, "안락함(Comfort) 레벨 1당 추가되는 지속시간(초). 바닐라 기본값 60초");
		DayLengthEnabled = cfg.Bind<bool>("14_DayLength", "Enabled", true, "하루(낮+밤)의 길이를 조절할지 여부");
		DayLengthSeconds = cfg.Bind<float>("14_DayLength", "DayLengthSeconds", 1200f, "하루의 전체 길이(초). 바닐라 기본값 1200초(20분), 낮/밤 비율은 그대로 유지된 채 전체 길이만 늘어나거나 줄어듦");
		SmoothFoodRegenEnabled = cfg.Bind<bool>("15_SmoothFoodRegen", "Enabled", true, "음식의 체력 회복(foodRegen)을 10초에 한 번 몰아서 받는 대신 1초마다 1/10씩 나눠 받을지 여부 (총 회복량은 동일)");
		CraftFromContainersEnabled = cfg.Bind<bool>("16_CraftFromContainers", "Enabled", true, "제작대 제작·아이템 강화·망치 건설 시 인벤토리에 부족한 재료를 주변 상자에서 자동으로 끌어와 사용할지 여부");
		CraftFromContainersRadius = cfg.Bind<float>("16_CraftFromContainers", "Radius", 20f, "재료를 끌어올 상자를 탐색하는 반경(m). 경계석으로 접근이 막혔거나 다른 사람이 열어 둔 상자는 제외됨");
		CraftFromContainersShowCombinedCount = cfg.Bind<bool>("16_CraftFromContainers", "ShowCombinedCount", true, "제작창·건설창의 재료 수량을 '필요/보유(인벤+상자)' 형식으로 표기할지 여부");
		BulkInsertEnabled = cfg.Bind<bool>("17_BulkInsert", "Enabled", true, "제련소·용광로·숯가마 등 제련 기기의 투입구를 조준한 상태에서 단축키로 일괄 투입할지 여부");
		BulkInsertShortcut = cfg.Bind<KeyboardShortcut>("17_BulkInsert", "Shortcut", new KeyboardShortcut((KeyCode)101, (KeyCode[])(object)new KeyCode[1] { (KeyCode)304 }), "일괄 투입 단축키 (기본 Shift+E)");
		BulkInsertIncludeContainers = cfg.Bind<bool>("17_BulkInsert", "IncludeContainers", true, "일괄 투입 시 인벤토리에 부족한 만큼 주변 상자(기능16과 동일한 반경)에서도 끌어올지 여부");
	}
}
internal static class TweaksTimeFormat
{
	public static string Format(float seconds)
	{
		if (seconds < 0f)
		{
			seconds = 0f;
		}
		int num = (int)seconds;
		if (num < 60)
		{
			return $"{num}초";
		}
		int num2 = num / 60;
		int num3 = num % 60;
		return $"{num2}분 {num3}초";
	}
}
internal static class VanillaSafeAccess
{
	private static readonly MethodInfo s_getCoverForPoint = BuildGetCoverForPoint();

	private static bool s_loggedFailure;

	private static MethodInfo BuildGetCoverForPoint()
	{
		try
		{
			Type type = AccessTools.TypeByName("Cover");
			return (type == null) ? null : AccessTools.Method(type, "GetCoverForPoint", (Type[])null, (Type[])null);
		}
		catch (Exception arg)
		{
			Plugin.Log.LogError((object)$"[Tweaks:VanillaSafeAccess] Cover.GetCoverForPoint 확보 실패: {arg}");
			return null;
		}
	}

	public static bool TryGetCoverForPoint(Vector3 point, float radius, out float coverRatio, out bool underRoof)
	{
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		coverRatio = 0f;
		underRoof = false;
		if (s_getCoverForPoint == null)
		{
			return false;
		}
		try
		{
			object[] array = new object[4] { point, 0f, false, radius };
			s_getCoverForPoint.Invoke(null, array);
			coverRatio = (float)array[1];
			underRoof = (bool)array[2];
			return true;
		}
		catch (Exception arg)
		{
			if (!s_loggedFailure)
			{
				s_loggedFailure = true;
				Plugin.Log.LogError((object)$"[Tweaks:VanillaSafeAccess] Cover.GetCoverForPoint 호출 실패: {arg}");
			}
			return false;
		}
	}
}