Decompiled source of FullAutoIrrigation v1.0.0

BepInEx/plugins/FullAutoIrrigation.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
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.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("FullAutoIrrigation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("FullAutoIrrigation")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4AE49755-A977-4B8C-99C6-33C8C6B76881")]
[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")]
[BepInPlugin("com.lan.FullAutoIrrigation", "全自动灌溉", "1.0.0")]
public class FullAutoIrrigation : BaseUnityPlugin
{
	private static readonly FieldInfo _isWatered = AccessTools.Field(typeof(BlockDirt), "isWatered");

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

	private static int dirtNum = 0;

	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.lan.FullAutoIrrigation");
		val.PatchAll(typeof(FullAutoIrrigation));
		Debug.LogWarning((object)"全自动灌溉 --作者:她说缝上都不给我");
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(BlockTree))]
	[HarmonyPatch("CheckRainServer")]
	public static void Postfix(BlockTree __instance)
	{
		//IL_005f: 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)
		if (!((NetworkBehaviour)__instance).IsServer)
		{
			return;
		}
		NetworkVariable<bool> val = (NetworkVariable<bool>)_isWateredTree.GetValue(__instance);
		if (!val.Value)
		{
			val.Value = true;
			if ((double)GameManager.Instance.GetTimelineValue() > 6.03)
			{
				string localizedString = LocalizationSettings.StringDatabase.GetLocalizedString(TableReference.op_Implicit("Translations"), TableEntryReference.op_Implicit(((ItemSO)((Block)__instance).blockSO).itemName), (Locale)null, (FallbackBehavior)0, Array.Empty<object>());
				GameManager.Instance.IncrementCoinsServer(-10, (TransactionType)6, "成功灌溉了(AutoIrrigation)" + localizedString);
			}
			else
			{
				dirtNum++;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(BlockDirt))]
	[HarmonyPatch("CheckRainServer")]
	public static void Postfix(BlockDirt __instance)
	{
		if (!((NetworkBehaviour)__instance).IsServer)
		{
			return;
		}
		NetworkVariable<bool> val = (NetworkVariable<bool>)_isWatered.GetValue(__instance);
		if (!val.Value)
		{
			val.Value = true;
			if ((double)GameManager.Instance.GetTimelineValue() > 6.03)
			{
				GameManager.Instance.IncrementCoinsServer(-10, (TransactionType)6, "成功灌溉一块土地(AutoIrrigation Dirt)");
			}
			else
			{
				dirtNum++;
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameManager))]
	[HarmonyPatch("OnTimelineChanged")]
	public static void Postfix(GameManager __instance, float current)
	{
		if ((double)current > 6.03 && dirtNum > 0 && (double)current < 6.05)
		{
			__instance.IncrementCoinsServer(-10 * dirtNum, (TransactionType)6, "成功灌溉了所有土块和树(Successfully irrigated all dirt blocks and tree)");
			dirtNum = 0;
		}
	}
}