Decompiled source of FullAutoIrrigation v1.2.0

BepInEx/plugins/FullAutoIrrigation.dll

Decompiled a month ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Unity.Netcode;
using UnityEngine;

[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.2.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(BlockDirt))]
	[HarmonyPatch("OnNetworkSpawn")]
	private static void Prefix(BlockDirt __instance)
	{
		if (((NetworkBehaviour)__instance).IsServer && !((double)GameManager.Instance.GetTimelineValue() <= 6.05))
		{
			NetworkVariable<bool> val = (NetworkVariable<bool>)_isWatered.GetValue(__instance);
			if (!val.Value)
			{
				val.Value = true;
				GameManager.Instance.IncrementCoinsServer(-1, (TransactionType)6, "成功灌溉一块土地(Successfully irrigated a dirt block)");
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(BlockTree))]
	[HarmonyPatch("OnNetworkSpawn")]
	private static void PrefixTree(BlockTree __instance)
	{
		if (((NetworkBehaviour)__instance).IsServer && !((double)GameManager.Instance.GetTimelineValue() <= 6.05))
		{
			NetworkVariable<bool> val = (NetworkVariable<bool>)_isWateredTree.GetValue(__instance);
			if (!val.Value)
			{
				val.Value = true;
				GameManager.Instance.IncrementCoinsServer(-1, (TransactionType)6, "成功灌溉一棵树(Successfully irrigated a tree block)");
			}
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameManager))]
	[HarmonyPatch("OnTimelineChanged")]
	public static void Postfix(GameManager __instance, float current)
	{
		if ((double)current > 6.02 && (double)current < 6.05)
		{
			List<BlockDirt> list = Object.FindObjectsOfType<BlockDirt>().ToList();
			List<BlockTree> list2 = Object.FindObjectsOfType<BlockTree>().ToList();
			foreach (BlockDirt item in list)
			{
				NetworkVariable<bool> val = (NetworkVariable<bool>)_isWatered.GetValue(item);
				if (!val.Value)
				{
					val.Value = true;
					dirtNum++;
				}
			}
			foreach (BlockTree item2 in list2)
			{
				NetworkVariable<bool> val2 = (NetworkVariable<bool>)_isWateredTree.GetValue(item2);
				if (!val2.Value)
				{
					val2.Value = true;
					dirtNum++;
				}
			}
		}
		if ((double)current > 6.05 && dirtNum > 0 && (double)current < 6.1)
		{
			__instance.IncrementCoinsServer(-1 * dirtNum, (TransactionType)6, "成功灌溉了所有土块和树(Successfully irrigated all dirt blocks and tree)");
			dirtNum = 0;
		}
	}
}