using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using BepInEx; using BepInEx.Logging; using HarmonyLib; using TMPro; using Unity.Netcode; using UnityEngine; using UnityEngine.Localization; using UnityEngine.Localization.Settings; using UnityEngine.Localization.Tables; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: AssemblyTitle("OldMarket.FarmingSupport")] [assembly: AssemblyDescription("")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("")] [assembly: AssemblyProduct("OldMarket.FarmingSupport")] [assembly: AssemblyCopyright("Copyright © 2025")] [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("cd64c961-d01e-412c-8668-c4beaef94969")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyVersion("1.0.0.0")] namespace OldMarket.FarmingSupport; [HarmonyPatch(typeof(PlayerInteraction), "InteractionRay")] internal static class SeedPickupLayoutPatch { private static readonly FieldInfo LastOutlineField = AccessTools.Field(typeof(PlayerInteraction), "lastOutline"); [HarmonyPostfix] [HarmonyPriority(0)] private static void Postfix(PlayerInteraction __instance) { //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.interactionUI == (Object)null || !__instance.interactionUI.activeSelf || LastOutlineField == null) { return; } object? value = LastOutlineField.GetValue(__instance); Outline val = (Outline)((value is Outline) ? value : null); if ((Object)(object)val == (Object)null) { return; } Interactable componentInParent = ((Component)val).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return; } Item val2 = (Item)(object)((componentInParent is Item) ? componentInParent : null); if ((Object)(object)val2 == (Object)null) { return; } ItemSO itemSO = val2.itemSO; SeedSO val3 = (SeedSO)(object)((itemSO is SeedSO) ? itemSO : null); if ((Object)(object)val3 == (Object)null) { return; } try { if ((Object)(object)__instance.textPrimaryInteraction != (Object)null) { ((TMP_Text)__instance.textPrimaryInteraction).text = componentInParent.GetDescription(); } } catch { } int num = val3.daysToFullGrowth; if (num < 0) { num = 0; } string text; try { text = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("days"), (Locale)null, (FallbackBehavior)0, Array.Empty()); } catch { text = "DAYS"; } string text2 = null; try { Locale selectedLocale = LocalizationSettings.SelectedLocale; if ((Object)(object)selectedLocale != (Object)null) { LocaleIdentifier identifier = selectedLocale.Identifier; text2 = ((LocaleIdentifier)(ref identifier)).Code; } } catch { } string text3 = ((string.IsNullOrEmpty(text2) || !text2.StartsWith("ja", StringComparison.OrdinalIgnoreCase)) ? $"{num} {text.ToUpperInvariant()}" : $"{text} {num}"); string text4 = string.Empty; if ((Object)(object)val3.productSO != (Object)null && (Object)(object)val3.productSO.season != (Object)null) { text4 = val3.productSO.season.GetLocalizedName() ?? string.Empty; } if ((Object)(object)__instance.textSubtitle != (Object)null) { if (!string.IsNullOrEmpty(text4)) { ((TMP_Text)__instance.textSubtitle).text = text3 + " | " + text4; } else { ((TMP_Text)__instance.textSubtitle).text = text3; } } } } [BepInPlugin("oldmarket.farminfo", "Old Market Farm Info", "1.1.1")] public class FarmInfoPlugin : BaseUnityPlugin { public const string PluginGuid = "oldmarket.farminfo"; public const string PluginName = "Old Market Farm Info"; public const string PluginVersion = "1.1.1"; internal static ManualLogSource Log; private void Awake() { //IL_0010: Unknown result type (might be due to invalid IL or missing references) Log = ((BaseUnityPlugin)this).Logger; new Harmony("oldmarket.farminfo").PatchAll(); } internal static string FormatRemainingDays(int remainingDays) { //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (remainingDays <= 0) { return string.Empty; } string text = null; try { text = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("days_left"), (Locale)null, (FallbackBehavior)0, Array.Empty()); } catch (Exception ex) { if (Log != null) { Log.LogWarning((object)("Failed to get localized 'days_left': " + ex)); } } if (!string.IsNullOrEmpty(text)) { try { if (text.IndexOf("{0", StringComparison.Ordinal) >= 0) { return string.Format(text, remainingDays); } return remainingDays + " " + text; } catch (FormatException) { return remainingDays + " " + text; } } if (remainingDays == 1) { return "1 day left"; } return remainingDays + " days left"; } internal static string AppendDaysSuffix(string baseText, int remainingDays) { string text = FormatRemainingDays(remainingDays); if (string.IsNullOrEmpty(text)) { return baseText ?? string.Empty; } if (string.IsNullOrEmpty(baseText)) { return text; } text = text.Replace("\r", "").Replace("\n", " "); return baseText + "\n" + text; } } [HarmonyPatch(typeof(BlockDirt))] public static class BlockDirt_GetDescription_Patch { [HarmonyPostfix] [HarmonyPatch("GetDescription")] public static void Postfix(BlockDirt __instance, ref string __result) { if (string.IsNullOrEmpty(__result) || (Object)(object)GameManager.Instance == (Object)null) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(BlockDirt), "currentSeed"); if (fieldInfo == null || !(fieldInfo.GetValue(__instance) is NetworkVariable val) || val.Value == -1) { return; } ItemSO itemById = GameManager.Instance.GetItemById(val.Value); SeedSO val2 = (SeedSO)(object)((itemById is SeedSO) ? itemById : null); if ((Object)(object)val2 == (Object)null) { return; } int value = Traverse.Create((object)__instance).Field("dayCounter").GetValue>() .Value; int daysToFullGrowth = val2.daysToFullGrowth; if (daysToFullGrowth > 0 && value < daysToFullGrowth) { int remainingDays = daysToFullGrowth - value; __result = FarmInfoPlugin.AppendDaysSuffix(__result, remainingDays); } if ((Object)(object)val2.productSO != (Object)null && (Object)(object)val2.productSO.season != (Object)null) { string text = val2.productSO.season.GetLocalizedName() ?? string.Empty; if (!string.IsNullOrEmpty(text) && __result.IndexOf(text, StringComparison.Ordinal) < 0) { __result = __result + "\n" + text; } } } } [HarmonyPatch(typeof(BlockTree))] public static class BlockTree_GetDescription_Patch { [HarmonyPostfix] [HarmonyPatch("GetDescription")] public static void Postfix(BlockTree __instance, ref string __result) { if (string.IsNullOrEmpty(__result)) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(BlockTree), "treeSO"); TreeSO val = (TreeSO)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null) { return; } int value = Traverse.Create((object)__instance).Field("dayCounter").GetValue>() .Value; if (value < val.daysToHarvestAfterGrowth) { int num = ((value >= val.daysToFullGrowth) ? (val.daysToHarvestAfterGrowth - value) : (val.daysToFullGrowth - value)); if (num > 0) { __result = FarmInfoPlugin.AppendDaysSuffix(__result, num); } } if ((Object)(object)val.productSO != (Object)null && (Object)(object)val.productSO.season != (Object)null) { string text = val.productSO.season.GetLocalizedName() ?? string.Empty; if (!string.IsNullOrEmpty(text) && __result.IndexOf(text, StringComparison.Ordinal) < 0) { __result = __result + "\n" + text; } } } } [HarmonyPatch(typeof(BlockAnimal))] public static class BlockAnimal_GetDescription_Patch { [HarmonyPostfix] [HarmonyPatch("GetDescription")] public static void Postfix(BlockAnimal __instance, ref string __result) { if (string.IsNullOrEmpty(__result)) { return; } FieldInfo fieldInfo = AccessTools.Field(typeof(BlockAnimal), "animalSO"); AnimalSO val = (AnimalSO)((fieldInfo != null) ? /*isinst with value type is only supported in some contexts*/: null); if ((Object)(object)val == (Object)null) { return; } int value = Traverse.Create((object)__instance).Field("dayCounter").GetValue>() .Value; if (value >= val.daysToHarvestAfterGrowth) { return; } int num = ((value >= val.daysToGrowth) ? (val.daysToHarvestAfterGrowth - value) : (val.daysToGrowth - value)); if (num > 0) { string text = FarmInfoPlugin.FormatRemainingDays(num); if (!string.IsNullOrEmpty(text)) { __result = __result + " (" + text + ")"; } } } } [HarmonyPatch(typeof(PlayerInteraction))] public static class PlayerInteraction_SeedInfoPatch { [HarmonyPostfix] [HarmonyPatch("InteractionRay")] public static void Postfix(PlayerInteraction __instance) { //IL_008e: 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_0095: 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) //IL_00a4: Unknown result type (might be due to invalid IL or missing references) //IL_00ac: Unknown result type (might be due to invalid IL or missing references) try { if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.interactionUI == (Object)null || !__instance.interactionUI.activeSelf) { return; } TextMeshProUGUI textPrimaryInteraction = __instance.textPrimaryInteraction; if ((Object)(object)textPrimaryInteraction == (Object)null || string.IsNullOrEmpty(((TMP_Text)textPrimaryInteraction).text)) { return; } Traverse obj = Traverse.Create((object)__instance); Camera value = obj.Field("mainCamera").GetValue(); if (!obj.Field("isInteractionEnabled").GetValue() || (Object)(object)value == (Object)null) { return; } float interactionDistance = __instance.interactionDistance; LayerMask layerMask = __instance.layerMask; RaycastHit val = default(RaycastHit); if (!Physics.Raycast(value.ViewportPointToRay(Vector3.one / 2f), ref val, interactionDistance, LayerMask.op_Implicit(layerMask), (QueryTriggerInteraction)1)) { return; } Interactable componentInParent = ((Component)((RaycastHit)(ref val)).collider).GetComponentInParent(); if ((Object)(object)componentInParent == (Object)null) { return; } Item val2 = (Item)(object)((componentInParent is Item) ? componentInParent : null); if ((Object)(object)val2 == (Object)null) { return; } ItemSO itemSO = val2.itemSO; SeedSO val3 = (SeedSO)(object)((itemSO is SeedSO) ? itemSO : null); if ((Object)(object)val3 == (Object)null) { return; } int num = Mathf.Max(val3.daysToFullGrowth, 0); if (num > 0 && ((TMP_Text)textPrimaryInteraction).text.IndexOf("Harvest in", StringComparison.Ordinal) < 0) { string text = ((num == 1) ? "Harvest in 1 day" : ("Harvest in " + num + " days")); ((TMP_Text)textPrimaryInteraction).text = ((TMP_Text)textPrimaryInteraction).text + "\n" + text; } TextMeshProUGUI textSubtitle = __instance.textSubtitle; if ((Object)(object)textSubtitle != (Object)null && (Object)(object)val3.productSO != (Object)null && (Object)(object)val3.productSO.season != (Object)null) { string text2 = val3.productSO.season.GetLocalizedName() ?? string.Empty; if (!string.IsNullOrEmpty(text2)) { ((TMP_Text)textSubtitle).text = text2; } } } catch (Exception ex) { FarmInfoPlugin.Log.LogError((object)("Seed info patch error: " + ex)); } } } [HarmonyPatch(typeof(BlockBeeHive), "GetDescription")] public static class BlockBeeHive_GetDescription_Patch { private static readonly FieldInfo HasBeeField = AccessTools.Field(typeof(BlockBeeHive), "hasBee"); private static void Postfix(BlockBeeHive __instance, ref string __result) { //IL_00cd: Unknown result type (might be due to invalid IL or missing references) //IL_0073: Unknown result type (might be due to invalid IL or missing references) //IL_007d: Unknown result type (might be due to invalid IL or missing references) if ((Object)(object)__instance == (Object)null) { return; } bool flag = false; if (HasBeeField != null && HasBeeField.GetValue(__instance) is NetworkVariable val) { flag = val.Value; } if (!flag) { return; } int value = Traverse.Create((object)__instance).Field("dayCounter").GetValue>() .Value; int num = __instance.requiredDays - value; if (num < 0) { num = 0; } if (num > 0) { string localizedString = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit("days_left"), (Locale)null, (FallbackBehavior)0, Array.Empty()); if (!string.IsNullOrEmpty(localizedString)) { __result = $"{__result} ({localizedString}: {num})"; } else { __result = $"{__result} ({num} days left)"; } } int num2 = 0; Collider[] array = Physics.OverlapSphere(((Component)__instance).transform.position, (float)__instance.treeDetectionRadius); if (array != null) { foreach (Collider val2 in array) { if ((Object)(object)val2 != (Object)null && !val2.isTrigger && (Object)(object)((Component)val2).GetComponent() != (Object)null) { num2++; } } } int num3 = ((num2 < 3) ? 1 : ((num2 >= 6) ? 3 : 2)); __result = $"{__result} [Trees: {num2}, Honey: {num3}]"; } }