Decompiled source of AutoSoil v0.1.0

Mods/AutoSoil.dll

Decompiled 2 months ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using AutoWater;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(AutoWaterMod), "AutoSoil", "0.1.0", "Michiyo", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("AutoSoil")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+ac0c751f90ac060ff0e83fc7055d7dbd39fefa45")]
[assembly: AssemblyProduct("AutoSoil")]
[assembly: AssemblyTitle("AutoSoil")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace AutoWater
{
	public class AutoWaterMod : MelonMod
	{
		private MelonPreferences_Category _category;

		private MelonPreferences_Entry<double> _checkInterval;

		private float _lastCheckTime = 0f;

		public override void OnInitializeMelon()
		{
			_category = MelonPreferences.CreateCategory("AutoSoil", "AutoSoil Settings");
			_checkInterval = _category.CreateEntry<double>("CheckInterval", 60.0, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
			((MelonPreferences_Entry)_checkInterval).Comment = "Time (in seconds) between soil checks";
			MelonLogger.Msg($"[AutoSoil] Config loaded: Interval={_checkInterval.Value}");
		}

		public override void OnUpdate()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			Scene activeScene = SceneManager.GetActiveScene();
			string name = ((Scene)(ref activeScene)).name;
			if (!(name != "Main"))
			{
				float realtimeSinceStartup = Time.realtimeSinceStartup;
				float num = realtimeSinceStartup - _lastCheckTime;
				if ((double)num >= _checkInterval.Value)
				{
					_lastCheckTime = realtimeSinceStartup;
					MelonCoroutines.Start(ProcessAllSoilPourers());
				}
			}
		}

		private IEnumerator ProcessAllSoilPourers()
		{
			MonoBehaviour[] allObjects = Object.FindObjectsOfType<MonoBehaviour>();
			int pourerCount = 0;
			int activatedCount = 0;
			MonoBehaviour[] array = allObjects;
			foreach (MonoBehaviour obj in array)
			{
				if ((Object)(object)obj == (Object)null || ((object)obj).GetType().FullName != "ScheduleOne.ObjectScripts.SoilPourer")
				{
					continue;
				}
				pourerCount++;
				Type type = ((object)obj).GetType();
				MethodInfo pourMethod = type.GetMethod("SendPourSoil", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				MethodInfo getPotsMethod = type.GetMethod("GetPots", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (pourMethod == null || getPotsMethod == null)
				{
					continue;
				}
				object potList = getPotsMethod.Invoke(obj, null);
				if (potList == null)
				{
					continue;
				}
				foreach (object pot in (IEnumerable)potList)
				{
					if (pot != null)
					{
						Type potType = pot.GetType();
						PropertyInfo isFilledProp = potType.GetProperty("IsFilledWithSoil", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
						if (!(isFilledProp == null) && !(bool)isFilledProp.GetValue(pot))
						{
							pourMethod.Invoke(obj, null);
							activatedCount++;
							break;
						}
					}
				}
			}
			yield return null;
		}
	}
}