Decompiled source of BotanistUseSprinkler v1.0.2

BotanistUseSprinkler.dll

Decompiled 2 weeks 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.Json;
using System.Text.Json.Serialization;
using BotanistUseSprinkler;
using HarmonyLib;
using Il2CppFishNet;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppScheduleOne.Employees;
using Il2CppScheduleOne.EntityFramework;
using Il2CppScheduleOne.NPCs.Behaviour;
using Il2CppScheduleOne.ObjectScripts;
using Il2CppScheduleOne.Tiles;
using Il2CppSystem.Collections.Generic;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(BotanistUseSprinklerMod), "Botanist Use Sprinkler", "1.0.2", "Fortis", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BotanistUseSprinkler")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+30f3c438caeaa6a516525b56680bfc28279cbe1d")]
[assembly: AssemblyProduct("BotanistUseSprinkler")]
[assembly: AssemblyTitle("BotanistUseSprinkler")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BotanistUseSprinkler
{
	public class BotanistUseSprinklerMod : MelonMod
	{
		[HarmonyPatch(typeof(PotActionBehaviour), "ActiveMinPass")]
		public static class PotActionBehaviourActiveMinPassPatch
		{
			public static List<Pot> ActiveHandWateredPots = new List<Pot>();

			[HarmonyPostfix]
			private static void Postfix(PotActionBehaviour __instance)
			{
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0041: Invalid comparison between Unknown and I4
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_005d: Invalid comparison between Unknown and I4
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f7: Expected O, but got Unknown
				//IL_01be: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01ca: Expected O, but got Unknown
				PotActionBehaviour __instance2 = __instance;
				if (!_config.Enabled || !InstanceFinder.IsServer || (int)__instance2.CurrentState != 4 || (int)__instance2.CurrentActionType != 3 || !IsAtPot(__instance2))
				{
					return;
				}
				Log($"(PotActionBehaviourActiveMinPassPatch/Postfix) ActiveHandWateredPots Count: {ActiveHandWateredPots.Count}", LogLevel.Debug);
				if (((IEnumerable<Pot>)ActiveHandWateredPots).FirstOrDefault((Func<Pot, bool>)((Pot x) => ((GridItem)x).OriginCoordinate == ((GridItem)__instance2.AssignedPot).OriginCoordinate)) != null)
				{
					Coordinate val = new Coordinate(((GridItem)__instance2.AssignedPot).OriginCoordinate);
					Log($"(PotActionBehaviourActiveMinPassPatch/Postfix) Pot at x: {val.x}, y: {val.y} is currently being hand watered, skipping", LogLevel.Debug);
					return;
				}
				List<Sprinkler> potSprinklers = GetPotSprinklers(__instance2.AssignedPot);
				if (potSprinklers.Count <= 0)
				{
					Log("(PotActionBehaviourActiveMinPassPatch/Postfix) Pot has no sprinklers, adding to active hand watered pots", LogLevel.Debug);
					ActiveHandWateredPots.Add(__instance2.AssignedPot);
					return;
				}
				foreach (Sprinkler item in potSprinklers)
				{
					Coordinate val2 = new Coordinate(((GridItem)item).OriginCoordinate);
					Log($"(PotActionBehaviourActiveMinPassPatch/Postfix) Sprinkler at x: {val2.x}, y: {val2.y} with IsSprinkling: {item.IsSprinkling}", LogLevel.Debug);
					if (!item.IsSprinkling)
					{
						item.Interacted();
					}
				}
				__instance2.StopPerformAction();
				__instance2.CompleteAction();
				((Behaviour)__instance2).SendEnd();
				((Employee)__instance2.botanist).SetIdle(true);
			}

			private static bool IsAtPot(PotActionBehaviour behaviour)
			{
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				//IL_003b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0075: Unknown result type (might be due to invalid IL or missing references)
				if (behaviour.AssignedPot == null)
				{
					return false;
				}
				for (int i = 0; i < ((Il2CppArrayBase<Transform>)(object)behaviour.AssignedPot.AccessPoints).Length; i++)
				{
					if (Vector3.Distance(((Component)((Behaviour)behaviour).Npc).transform.position, ((Il2CppArrayBase<Transform>)(object)behaviour.AssignedPot.AccessPoints)[i].position) < 0.4f)
					{
						return true;
					}
					if (((Behaviour)behaviour).Npc.Movement.IsAsCloseAsPossible(((Component)((Il2CppArrayBase<Transform>)(object)behaviour.AssignedPot.AccessPoints)[i]).transform.position, 0.4f))
					{
						return true;
					}
				}
				return false;
			}

			private static List<Sprinkler> GetPotSprinklers(Pot pot)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Expected O, but got Unknown
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Expected O, but got Unknown
				//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ac: Expected O, but got Unknown
				//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c2: Expected O, but got Unknown
				//IL_03a8: Unknown result type (might be due to invalid IL or missing references)
				//IL_03ad: Unknown result type (might be due to invalid IL or missing references)
				//IL_03b4: Expected O, but got Unknown
				//IL_0419: Unknown result type (might be due to invalid IL or missing references)
				//IL_041e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0425: Unknown result type (might be due to invalid IL or missing references)
				//IL_043d: Expected O, but got Unknown
				//IL_0442: Expected O, but got Unknown
				//IL_044c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0451: Unknown result type (might be due to invalid IL or missing references)
				//IL_0458: Unknown result type (might be due to invalid IL or missing references)
				//IL_0470: Expected O, but got Unknown
				//IL_0475: Expected O, but got Unknown
				//IL_05a6: Unknown result type (might be due to invalid IL or missing references)
				//IL_05ab: Unknown result type (might be due to invalid IL or missing references)
				//IL_05b2: Expected O, but got Unknown
				Coordinate val = new Coordinate(((GridItem)pot).OriginCoordinate);
				Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Assigned Pot Coords x: {val.x}, y: {val.y}", LogLevel.Debug);
				List<Sprinkler> list = new List<Sprinkler>();
				for (int i = 1; i < 4; i++)
				{
					Coordinate val2 = new Coordinate(val.x + i, val.y);
					Coordinate val3 = new Coordinate(val.x - i, val.y);
					Coordinate val4 = new Coordinate(val.x, val.y + i);
					Coordinate val5 = new Coordinate(val.x, val.y - i);
					Tile tile = ((GridItem)pot).OwnerGrid.GetTile(val2);
					Tile tile2 = ((GridItem)pot).OwnerGrid.GetTile(val3);
					Tile tile3 = ((GridItem)pot).OwnerGrid.GetTile(val4);
					Tile tile4 = ((GridItem)pot).OwnerGrid.GetTile(val5);
					Tile[] array = (Tile[])(object)new Tile[4] { tile, tile2, tile3, tile4 };
					for (int j = 0; j < array.Length; j++)
					{
						if (array[j] == null)
						{
							Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Tile at index {j} is null, skipping", LogLevel.Debug);
							continue;
						}
						Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Checking tile at x: {array[j].x}, y: {array[j].y}", LogLevel.Debug);
						if (!TryGetSprinkler(array[j], out Sprinkler sprinkler))
						{
							Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Tile at x: {array[j].x}, y: {array[j].y} contains no sprinklers", LogLevel.Debug);
						}
						else if (sprinkler == null)
						{
							Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Tile at x: {array[j].x}, y: {array[j].y} contains a sprinkler but sprinkler returned is null", LogLevel.Warn);
						}
						else
						{
							Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Sprinkler found at x: {array[j].x}, y: {array[j].y}", LogLevel.Debug);
							list.Add(sprinkler);
						}
					}
				}
				List<Sprinkler> list2 = new List<Sprinkler>();
				if (list.Count <= 0)
				{
					return list2;
				}
				Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) sprinklersAroundPot Count: {list.Count}", LogLevel.Debug);
				for (int k = 0; k < list.Count; k++)
				{
					Coordinate val6 = new Coordinate(((GridItem)list[k]).OriginCoordinate);
					Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Checking if sprinkler at x: {val6.x}, y: {val6.y} pot is assigned pot", LogLevel.Debug);
					Coordinate val7 = new Coordinate(((GridItem)list[k]).OriginCoordinate) + Coordinate.RotateCoordinates(new Coordinate(0, 1), (float)((GridItem)list[k]).Rotation);
					Coordinate val8 = new Coordinate(((GridItem)list[k]).OriginCoordinate) + Coordinate.RotateCoordinates(new Coordinate(1, 1), (float)((GridItem)list[k]).Rotation);
					Tile tile5 = ((GridItem)list[k]).OwnerGrid.GetTile(val7);
					Tile tile6 = ((GridItem)list[k]).OwnerGrid.GetTile(val8);
					List<Pot> list3 = new List<Pot>();
					if ((Object)(object)tile5 != (Object)null && (Object)(object)tile6 != (Object)null)
					{
						Pot val9 = null;
						Enumerator<GridItem> enumerator = tile5.BuildableOccupants.GetEnumerator();
						while (enumerator.MoveNext())
						{
							GridItem current = enumerator.Current;
							if (current is Pot)
							{
								val9 = (Pot)(object)((current is Pot) ? current : null);
								break;
							}
						}
						if ((Object)(object)val9 != (Object)null && tile6.BuildableOccupants.Contains((GridItem)(object)val9))
						{
							list3.Add(val9);
						}
					}
					if (list3.Count <= 0)
					{
						Log("(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Tile pots count is 0 or less", LogLevel.Debug);
						return list2;
					}
					Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Sprinkler pots count: {list3.Count}", LogLevel.Debug);
					for (int l = 0; l < list3.Count; l++)
					{
						Coordinate val10 = new Coordinate(((GridItem)list3[l]).OriginCoordinate);
						Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Checking sprinkler pot at x: {val10.x}, y: {val10.y} matches assigned pot at x: {val.x}, y {val.y}", LogLevel.Debug);
						if (val10.x == val.x && val10.y == val.y)
						{
							Log("(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Adding Sprinkler", LogLevel.Debug);
							list2.Add(list[k]);
						}
					}
				}
				Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Sprinklers to be activated: {list2.Count}", LogLevel.Debug);
				return list2;
			}

			private static bool TryGetSprinkler(Tile tile, out Sprinkler? sprinkler)
			{
				sprinkler = null;
				Enumerator<GridItem> enumerator = tile.BuildableOccupants.GetEnumerator();
				Sprinkler val = default(Sprinkler);
				while (enumerator.MoveNext())
				{
					GridItem current = enumerator.Current;
					if (current != null)
					{
						Log("(PotActionBehaviourActiveMinPassPatch/TryGetSprinkler) Grid Item: " + ((Object)current).name, LogLevel.Debug);
						if (((Component)current).TryGetComponent<Sprinkler>(ref val))
						{
							sprinkler = val;
							return true;
						}
					}
				}
				return false;
			}
		}

		[HarmonyPatch(typeof(PotActionBehaviour), "CompleteAction")]
		public static class PotActionBehaviourCompleteActionPatch
		{
			[HarmonyPostfix]
			private static void Postfix(PotActionBehaviour __instance)
			{
				//IL_0014: Unknown result type (might be due to invalid IL or missing references)
				//IL_001a: Invalid comparison between Unknown and I4
				PotActionBehaviour __instance2 = __instance;
				if ((int)__instance2.CurrentActionType == 3 && __instance2.AssignedPot != null && ((IEnumerable<Pot>)PotActionBehaviourActiveMinPassPatch.ActiveHandWateredPots).FirstOrDefault((Func<Pot, bool>)((Pot x) => ((GridItem)x).OriginCoordinate == ((GridItem)__instance2.AssignedPot).OriginCoordinate)) != null)
				{
					Log("(PotActionBehaviourCompleteActionPatch/Postfix) Pot finished watering, removing pot from active hand watered", LogLevel.Debug);
					PotActionBehaviourActiveMinPassPatch.ActiveHandWateredPots.Remove(__instance2.AssignedPot);
				}
			}
		}

		private enum LogLevel
		{
			Debug,
			Info,
			Warn,
			Error,
			Fatal
		}

		private Harmony _harmony;

		private static readonly string ConfigDirectoryPath = Path.Combine(MelonEnvironment.UserDataDirectory, "BotanistUseSprinkler") ?? "";

		private static readonly string ConfigFilePath = Path.Combine(ConfigDirectoryPath, "configuration.json") ?? "";

		private static Configuration _config;

		public override void OnInitializeMelon()
		{
			Log("Initializing...", LogLevel.Info);
			LoadConfigFromFile();
			Log($"Enabled: {_config.Enabled}", LogLevel.Info);
			if (_config.Enabled)
			{
				_harmony = Harmony.CreateAndPatchAll(typeof(BotanistUseSprinklerMod), "com.fortis.botanistusesprinkler");
				if (_config.Debug)
				{
					Log("Debug Mode Enabled", LogLevel.Debug);
				}
				Log("Initialized", LogLevel.Info);
			}
		}

		public override void OnDeinitializeMelon()
		{
			if (_harmony != null)
			{
				Log("Unpatching Mod", LogLevel.Info);
				_harmony.UnpatchSelf();
				Log("Unpatched", LogLevel.Info);
			}
		}

		private static void LoadConfigFromFile()
		{
			Configuration configuration = new Configuration();
			configuration.Enabled = true;
			configuration.Debug = false;
			if (!Directory.Exists(ConfigDirectoryPath))
			{
				Directory.CreateDirectory(ConfigDirectoryPath);
			}
			if (!File.Exists(ConfigFilePath))
			{
				CreateConfigFile();
				_config = configuration;
				return;
			}
			string json = File.ReadAllText(ConfigFilePath);
			Configuration configuration2 = JsonSerializer.Deserialize<Configuration>(json);
			if (configuration2 == null)
			{
				_config = configuration;
				return;
			}
			configuration.Enabled = configuration2.Enabled;
			configuration.Debug = configuration2.Debug;
			_config = configuration;
		}

		private static void CreateConfigFile()
		{
			JsonSerializerOptions jsonSerializerOptions = new JsonSerializerOptions();
			jsonSerializerOptions.WriteIndented = true;
			Configuration configuration = new Configuration();
			configuration.Enabled = true;
			configuration.Debug = false;
			string contents = JsonSerializer.Serialize(configuration, jsonSerializerOptions);
			File.WriteAllText(ConfigFilePath, contents);
		}

		private static void Log(string message, LogLevel level)
		{
			string logPrefix = GetLogPrefix(level);
			if (level != 0 || _config.Debug)
			{
				MelonLogger.Msg(logPrefix + " " + message);
			}
		}

		private static string GetLogPrefix(LogLevel level)
		{
			return level switch
			{
				LogLevel.Debug => "[DEBUG]", 
				LogLevel.Info => "[INFO]", 
				LogLevel.Warn => "[WARN]", 
				LogLevel.Error => "[ERROR]", 
				LogLevel.Fatal => "[FATAL]", 
				_ => "[MISC]", 
			};
		}
	}
	public class Configuration
	{
		[JsonPropertyName("enabled")]
		public bool Enabled { get; set; }

		[JsonPropertyName("debug")]
		public bool Debug { get; set; }
	}
}

BotanistUseSprinkler_Mono.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BotanistUseSprinkler;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Utils;
using Microsoft.CodeAnalysis;
using Newtonsoft.Json;
using ScheduleOne.Employees;
using ScheduleOne.EntityFramework;
using ScheduleOne.NPCs;
using ScheduleOne.NPCs.Behaviour;
using ScheduleOne.ObjectScripts;
using ScheduleOne.Tiles;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(BotanistUseSprinklerMod), "Botanist Use Sprinkler", "1.0.2", "Fortis", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BotanistUseSprinkler_Mono")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+30f3c438caeaa6a516525b56680bfc28279cbe1d")]
[assembly: AssemblyProduct("BotanistUseSprinkler_Mono")]
[assembly: AssemblyTitle("BotanistUseSprinkler_Mono")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BotanistUseSprinkler
{
	public class BotanistUseSprinklerMod : MelonMod
	{
		[HarmonyPatch(typeof(PotActionBehaviour), "PerformAction")]
		public static class PotActionBehaviourPerformActionPatch
		{
			[HarmonyPostfix]
			private static void Postfix(PotActionBehaviour __instance)
			{
				//IL_001f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0024: Unknown result type (might be due to invalid IL or missing references)
				//IL_0039: Unknown result type (might be due to invalid IL or missing references)
				//IL_003e: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Invalid comparison between Unknown and I4
				//IL_00aa: 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)
				//IL_00b6: Expected O, but got Unknown
				if (!_config.Enabled)
				{
					return;
				}
				EActionType currentActionType = __instance.CurrentActionType;
				string? text = ((object)(EActionType)(ref currentActionType)).ToString();
				EState currentState = __instance.CurrentState;
				Log("(PotActionBehaviourPeformActionPatch/Postfix) Postfix fired with action type: " + text + " and current state: " + ((object)(EState)(ref currentState)).ToString(), LogLevel.Debug);
				if ((int)__instance.CurrentActionType != 3)
				{
					return;
				}
				List<Sprinkler> potSprinklers = GetPotSprinklers(__instance.AssignedPot);
				if (potSprinklers.Count <= 0)
				{
					return;
				}
				foreach (Sprinkler item in potSprinklers)
				{
					Coordinate val = new Coordinate(((GridItem)item).OriginCoordinate);
					Log($"(PotActionBehaviourPeformActionPatch/Postfix) Sprinkler at x: {val.x}, y: {val.y} with IsSprinkling: {item.IsSprinkling}", LogLevel.Debug);
					if (!item.IsSprinkling)
					{
						item.Interacted();
					}
				}
				MethodInfo method = typeof(PotActionBehaviour).GetMethod("StopPerformAction", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				if ((object)method != null)
				{
					method.Invoke(__instance, null);
				}
				else
				{
					Log("(PotActionBehaviourPeformActionPatch/Postfix) StopPerformAction is null", LogLevel.Debug);
				}
				MethodInfo method2 = typeof(PotActionBehaviour).GetMethod("CompleteAction", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				if ((object)method2 != null)
				{
					method2.Invoke(__instance, null);
				}
				else
				{
					Log("(PotActionBehaviourPeformActionPatch/Postfix) CompleteAction is null", LogLevel.Debug);
				}
				((Behaviour)__instance).SendEnd();
				NPC npc = ((Behaviour)__instance).Npc;
				Botanist val2 = (Botanist)(object)((npc is Botanist) ? npc : null);
				if (val2 != null)
				{
					((Employee)val2).SetIdle(true);
				}
			}

			private static List<Sprinkler> GetPotSprinklers(Pot pot)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0007: Unknown result type (might be due to invalid IL or missing references)
				//IL_000d: Expected O, but got Unknown
				//IL_0050: Unknown result type (might be due to invalid IL or missing references)
				//IL_0057: Expected O, but got Unknown
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Expected O, but got Unknown
				//IL_007a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0081: Expected O, but got Unknown
				//IL_008f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Expected O, but got Unknown
				//IL_0285: Unknown result type (might be due to invalid IL or missing references)
				//IL_028a: Unknown result type (might be due to invalid IL or missing references)
				//IL_0291: Expected O, but got Unknown
				//IL_02c2: Unknown result type (might be due to invalid IL or missing references)
				//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
				//IL_02ce: Unknown result type (might be due to invalid IL or missing references)
				//IL_02e6: Expected O, but got Unknown
				//IL_02eb: Expected O, but got Unknown
				//IL_02f5: Unknown result type (might be due to invalid IL or missing references)
				//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
				//IL_0301: Unknown result type (might be due to invalid IL or missing references)
				//IL_0319: Expected O, but got Unknown
				//IL_031e: Expected O, but got Unknown
				//IL_044c: Unknown result type (might be due to invalid IL or missing references)
				//IL_0451: Unknown result type (might be due to invalid IL or missing references)
				//IL_0458: Expected O, but got Unknown
				Coordinate val = new Coordinate(((GridItem)pot).OriginCoordinate);
				Log($"(PotActionBehaviourPeformActionPatch/GetPotSprinklers) Assigned Pot Coords x: {val.x}, y: {val.y}", LogLevel.Debug);
				List<Sprinkler> list = new List<Sprinkler>();
				for (int i = 1; i < 4; i++)
				{
					Coordinate val2 = new Coordinate(val.x + i, val.y);
					Coordinate val3 = new Coordinate(val.x - i, val.y);
					Coordinate val4 = new Coordinate(val.x, val.y + i);
					Coordinate val5 = new Coordinate(val.x, val.y - i);
					Tile tile = ((GridItem)pot).OwnerGrid.GetTile(val2);
					Tile tile2 = ((GridItem)pot).OwnerGrid.GetTile(val3);
					Tile tile3 = ((GridItem)pot).OwnerGrid.GetTile(val4);
					Tile tile4 = ((GridItem)pot).OwnerGrid.GetTile(val5);
					Tile[] array = (Tile[])(object)new Tile[4] { tile, tile2, tile3, tile4 };
					for (int j = 0; j < array.Length; j++)
					{
						if (array[j] == null)
						{
							Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Tile at index {j} is null, skipping", LogLevel.Debug);
							continue;
						}
						Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Checking tile at x: {array[j].x}, y: {array[j].y}", LogLevel.Debug);
						if (!TryGetSprinkler(array[j], out Sprinkler sprinkler))
						{
							Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Tile at x: {array[j].x}, y: {array[j].y} contains no sprinklers", LogLevel.Debug);
							continue;
						}
						if (sprinkler == null)
						{
							Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Tile at x: {array[j].x}, y: {array[j].y} contains a sprinkler but sprinkler returned is null", LogLevel.Warn);
							continue;
						}
						Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Sprinkler found at x: {array[j].x}, y: {array[j].y}", LogLevel.Debug);
						list.Add(sprinkler);
					}
				}
				List<Sprinkler> list2 = new List<Sprinkler>();
				if (list.Count <= 0)
				{
					return list2;
				}
				Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) sprinklersAroundPot Count: {list.Count}", LogLevel.Debug);
				for (int k = 0; k < list.Count; k++)
				{
					Coordinate val6 = new Coordinate(((GridItem)list[k]).OriginCoordinate);
					Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Checking if sprinkler at x: {val6.x}, y: {val6.y} pot is assigned pot", LogLevel.Debug);
					Coordinate val7 = new Coordinate(((GridItem)list[k]).OriginCoordinate) + Coordinate.RotateCoordinates(new Coordinate(0, 1), (float)((GridItem)list[k]).Rotation);
					Coordinate val8 = new Coordinate(((GridItem)list[k]).OriginCoordinate) + Coordinate.RotateCoordinates(new Coordinate(1, 1), (float)((GridItem)list[k]).Rotation);
					Tile tile5 = ((GridItem)list[k]).OwnerGrid.GetTile(val7);
					Tile tile6 = ((GridItem)list[k]).OwnerGrid.GetTile(val8);
					List<Pot> list3 = new List<Pot>();
					if ((Object)(object)tile5 != (Object)null && (Object)(object)tile6 != (Object)null)
					{
						Pot val9 = null;
						foreach (GridItem buildableOccupant in tile5.BuildableOccupants)
						{
							if (buildableOccupant is Pot)
							{
								val9 = (Pot)(object)((buildableOccupant is Pot) ? buildableOccupant : null);
								break;
							}
						}
						if ((Object)(object)val9 != (Object)null && tile6.BuildableOccupants.Contains((GridItem)(object)val9))
						{
							list3.Add(val9);
						}
					}
					if (list3.Count <= 0)
					{
						Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Tile pots count is 0 or less", LogLevel.Debug);
						return list2;
					}
					Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Sprinkler pots count: {list3.Count}", LogLevel.Debug);
					for (int l = 0; l < list3.Count; l++)
					{
						Coordinate val10 = new Coordinate(((GridItem)list3[l]).OriginCoordinate);
						Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Checking sprinkler pot at x: {val10.x}, y: {val10.y} matches assigned pot at x: {val.x}, y {val.y}", LogLevel.Debug);
						if (val10.x == val.x && val10.y == val.y)
						{
							Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Adding Sprinkler", LogLevel.Debug);
							list2.Add(list[k]);
						}
					}
				}
				Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Sprinklers to be activated: {list2.Count}", LogLevel.Debug);
				return list2;
			}

			private static bool TryGetSprinkler(Tile tile, out Sprinkler? sprinkler)
			{
				//IL_0036: Unknown result type (might be due to invalid IL or missing references)
				//IL_003c: Expected O, but got Unknown
				sprinkler = null;
				foreach (GridItem buildableOccupant in tile.BuildableOccupants)
				{
					if (buildableOccupant == null || !(buildableOccupant is Sprinkler))
					{
						continue;
					}
					sprinkler = (Sprinkler)buildableOccupant;
					break;
				}
				return Object.op_Implicit((Object)(object)sprinkler);
			}
		}

		private enum LogLevel
		{
			Debug,
			Info,
			Warn,
			Error,
			Fatal
		}

		private Harmony _harmony;

		private static readonly string ConfigDirectoryPath = Path.Combine(MelonEnvironment.UserDataDirectory, "BotanistUseSprinkler") ?? "";

		private static readonly string ConfigFilePath = Path.Combine(ConfigDirectoryPath, "configuration.json") ?? "";

		private static Configuration _config;

		public override void OnInitializeMelon()
		{
			Log("Initializing...", LogLevel.Info);
			LoadConfigFromFile();
			Log($"Enabled: {_config.Enabled}", LogLevel.Info);
			if (_config.Enabled)
			{
				_harmony = Harmony.CreateAndPatchAll(typeof(BotanistUseSprinklerMod), "com.fortis.botanistusesprinkler");
				if (_config.Debug)
				{
					Log("Debug Mode Enabled", LogLevel.Debug);
				}
				Log("Initialized", LogLevel.Info);
			}
		}

		public override void OnDeinitializeMelon()
		{
			if (_harmony != null)
			{
				Log("Unpatching Mod", LogLevel.Info);
				_harmony.UnpatchSelf();
				Log("Unpatched", LogLevel.Info);
			}
		}

		private static void LoadConfigFromFile()
		{
			Configuration configuration = new Configuration();
			configuration.Enabled = true;
			configuration.Debug = false;
			if (!Directory.Exists(ConfigDirectoryPath))
			{
				Directory.CreateDirectory(ConfigDirectoryPath);
			}
			if (!File.Exists(ConfigFilePath))
			{
				CreateConfigFile();
				_config = configuration;
				return;
			}
			string text = File.ReadAllText(ConfigFilePath);
			Configuration configuration2 = JsonConvert.DeserializeObject<Configuration>(text);
			if (configuration2 == null)
			{
				_config = configuration;
				return;
			}
			configuration.Enabled = configuration2.Enabled;
			configuration.Debug = configuration2.Debug;
			_config = configuration;
		}

		private static void CreateConfigFile()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			JsonSerializerSettings val = new JsonSerializerSettings();
			val.Formatting = (Formatting)1;
			Configuration configuration = new Configuration();
			configuration.Enabled = true;
			configuration.Debug = false;
			string contents = JsonConvert.SerializeObject((object)configuration, val);
			File.WriteAllText(ConfigFilePath, contents);
		}

		private static void Log(string message, LogLevel level)
		{
			string logPrefix = GetLogPrefix(level);
			if (level != 0 || _config.Debug)
			{
				MelonLogger.Msg(logPrefix + " " + message);
			}
		}

		private static string GetLogPrefix(LogLevel level)
		{
			return level switch
			{
				LogLevel.Debug => "[DEBUG]", 
				LogLevel.Info => "[INFO]", 
				LogLevel.Warn => "[WARN]", 
				LogLevel.Error => "[ERROR]", 
				LogLevel.Fatal => "[FATAL]", 
				_ => "[MISC]", 
			};
		}
	}
	public class Configuration
	{
		[JsonProperty("enabled")]
		public bool Enabled { get; set; }

		[JsonProperty("debug")]
		public bool Debug { get; set; }
	}
}