Some mods target the Mono version of the game, which is available by opting into the Steam beta branch "alternate"
Decompiled source of BotanistUseSprinkler v1.0.3
BotanistUseSprinkler_Mono.dll
Decompiled 14 hours agousing 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+81a75662dd3900a22ae5ac75fcd42a96d280273a")] [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 { private static MethodInfo GetPots = typeof(Sprinkler).GetMethod("GetPots", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); private static MethodInfo StopPerformAction = typeof(PotActionBehaviour).GetMethod("StopPerformAction", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); private static MethodInfo CompleteAction = typeof(PotActionBehaviour).GetMethod("CompleteAction", BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic); [HarmonyPostfix] private static void Postfix(PotActionBehaviour __instance) { //IL_007d: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_0097: Unknown result type (might be due to invalid IL or missing references) //IL_009c: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00be: Invalid comparison between Unknown and I4 //IL_00ea: Unknown result type (might be due to invalid IL or missing references) //IL_00ef: Unknown result type (might be due to invalid IL or missing references) //IL_00f5: Expected O, but got Unknown if (!_config.Enabled) { return; } if ((object)GetPots == null) { Log("(PotActionBehaviourPerformActionPatch/Postfix) GetPots method is null, cannot execute", LogLevel.Warn); return; } if ((object)StopPerformAction == null) { Log("(PotActionBehaviourPerformActionPatch/Postfix) StopPerformAction method is null, cannot execute", LogLevel.Warn); return; } if ((object)CompleteAction == null) { Log("(PotActionBehaviourPerformActionPatch/Postfix) CompleteAction method is null, cannot execute", LogLevel.Warn); 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; } Sprinkler potSprinkler = GetPotSprinkler(__instance.AssignedPot); if (potSprinkler != null) { Coordinate val = new Coordinate(((GridItem)potSprinkler).OriginCoordinate); Log($"(PotActionBehaviourPeformActionPatch/Postfix) Sprinkler at x: {val.x}, y: {val.y} with IsSprinkling: {potSprinkler.IsSprinkling}", LogLevel.Debug); if (!potSprinkler.IsSprinkling) { potSprinkler.Interacted(); } StopPerformAction.Invoke(__instance, null); CompleteAction.Invoke(__instance, null); ((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 Sprinkler? GetPotSprinkler(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_0281: Unknown result type (might be due to invalid IL or missing references) //IL_0286: Unknown result type (might be due to invalid IL or missing references) //IL_028d: Expected O, but got Unknown //IL_03b3: Unknown result type (might be due to invalid IL or missing references) //IL_03b8: Unknown result type (might be due to invalid IL or missing references) //IL_03bf: 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); } } Sprinkler result = null; if (list.Count <= 0) { return result; } 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); object obj = GetPots.Invoke(list[k], null); if (obj == null) { Log($"(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Pots for sprinkler at x: {val6.x}, y: {val6.y} is null", LogLevel.Debug); continue; } if (!(obj is List<Pot> list2)) { Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Returned value for GetPots is not List<Pot>", LogLevel.Debug); continue; } if (list2 == null) { Log($"(PotActionBehaviourPeformActionPatch/GetPotSprinklers) Sprinkler at x: {val6.x}, y: {val6.y} returned pots is null", LogLevel.Debug); continue; } if (list2.Count <= 0) { Log($"(PotActionBehaviourPeformActionPatch/GetPotSprinklers) Sprinkler at x: {val6.x}, y: {val6.y} has not pots", LogLevel.Debug); continue; } foreach (Pot item in list2) { if (item == null) { Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Sprinkler pot is pull", LogLevel.Debug); continue; } Coordinate val7 = new Coordinate(((GridItem)item).OriginCoordinate); Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Checking if pot matches assigned pot", LogLevel.Debug); if (val7.x == val.x && val7.y == val.y) { Log("(PotActionBehaviourPerformActionPatch/GetPotSprinklers) Pot matched, returning sprinkler", LogLevel.Debug); result = list[k]; } } } return result; } 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; } } }
BotanistUseSprinkler.dll
Decompiled 14 hours agousing 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+81a75662dd3900a22ae5ac75fcd42a96d280273a")] [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_003d: Unknown result type (might be due to invalid IL or missing references) //IL_0043: Invalid comparison between Unknown and I4 //IL_0059: Unknown result type (might be due to invalid IL or missing references) //IL_005f: Invalid comparison between Unknown and I4 //IL_00ed: Unknown result type (might be due to invalid IL or missing references) //IL_00f2: Unknown result type (might be due to invalid IL or missing references) //IL_00f9: Expected O, but got Unknown //IL_019f: Unknown result type (might be due to invalid IL or missing references) //IL_01a4: Unknown result type (might be due to invalid IL or missing references) //IL_01aa: 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; } Sprinkler potSprinkler = GetPotSprinkler(__instance2.AssignedPot); if (potSprinkler == null) { Log("(PotActionBehaviourActiveMinPassPatch/Postfix) Pot has no sprinklers, adding to active hand watered pots", LogLevel.Debug); ActiveHandWateredPots.Add(__instance2.AssignedPot); return; } Coordinate val2 = new Coordinate(((GridItem)potSprinkler).OriginCoordinate); Log($"(PotActionBehaviourActiveMinPassPatch/Postfix) Sprinkler at x: {val2.x}, y: {val2.y} with IsSprinkling: {potSprinkler.IsSprinkling}", LogLevel.Debug); if (!potSprinkler.IsSprinkling) { potSprinkler.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 Sprinkler? GetPotSprinkler(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_03a4: Unknown result type (might be due to invalid IL or missing references) //IL_03a9: Unknown result type (might be due to invalid IL or missing references) //IL_03b0: Expected O, but got Unknown //IL_0467: Unknown result type (might be due to invalid IL or missing references) //IL_046c: Unknown result type (might be due to invalid IL or missing references) //IL_0473: 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); } } } Sprinkler result = null; if (list.Count <= 0) { return result; } 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); List<Pot> pots = list[k].GetPots(); if (pots.Count <= 0) { Log($"(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Sprinkler at x: {val6.x}, y: {val6.y} contains no pots", LogLevel.Debug); break; } Enumerator<Pot> enumerator = pots.GetEnumerator(); while (enumerator.MoveNext()) { Pot current = enumerator.Current; if (current == null) { Log("(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Sprinkler Pot is null", LogLevel.Debug); continue; } Coordinate val7 = new Coordinate(((GridItem)current).OriginCoordinate); Log("(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Checking if pot matches assigned pot", LogLevel.Debug); if (val7.x == val.x && val7.y == val.y) { Log("(PotActionBehaviourActiveMinPassPatch/GetPotSprinklers) Pot matched, returning sprinkler", LogLevel.Debug); result = list[k]; } } } return result; } 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; } } }