Decompiled source of AutoIgnite v1.0.5

AutoIgnite.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem.Collections.Generic;
using SSSGame;
using SSSGame.AI;
using SSSGame.Weather;
using SandSailorStudio.Inventory;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("blacks7ar")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.5")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("AutoIgnite")]
[assembly: AssemblyTitle("AutoIgnite")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.5.0")]
[module: UnverifiableCode]
namespace AutoIgnite;

public static class Helper
{
	public static bool IsCooking(this CookingStation station)
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Expected O, but got Unknown
		if ((Object)(object)station == (Object)null)
		{
			return false;
		}
		List<CookingOutlet> cookingInteractions = station._cookingInteractions;
		if (cookingInteractions != null && cookingInteractions.Count != 0)
		{
			Enumerator<CookingOutlet> enumerator = cookingInteractions.GetEnumerator();
			bool flag = default(bool);
			while (enumerator.MoveNext())
			{
				CookingOutlet current = enumerator.Current;
				if (((current != null) ? current.cooker.activeRecipeContainer.container._inventory : null) == null)
				{
					ManualLogSource sTLogger = Plugin.STLogger;
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(44, 1, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CookingHouse: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(((Object)station).name);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" no cooking ingredients found.");
					}
					sTLogger.LogDebug(val);
				}
				else
				{
					Dictionary<ItemInfo, List<Item>> items = current.cooker.activeRecipeContainer.container._inventory._items;
					if (items != null && items.Count != 0)
					{
						return true;
					}
				}
			}
			List<CookingProject> cookingProjects = station.cookingProjects;
			if (cookingProjects != null && cookingProjects.Count != 0)
			{
				Enumerator<CookingProject> enumerator2 = cookingProjects.GetEnumerator();
				while (enumerator2.MoveNext())
				{
					CookingProject current2 = enumerator2.Current;
					if (current2 != null && current2.taskData != null)
					{
						return true;
					}
				}
				return false;
			}
			return false;
		}
		return false;
	}

	public static List<Structure> GetAllAddOns(Structure parent)
	{
		List<Structure> list = new List<Structure>();
		if ((Object)(object)parent == (Object)null)
		{
			return list;
		}
		Il2CppArrayBase<Structure> componentsInChildren = ((Component)parent).GetComponentsInChildren<Structure>(true);
		list.AddRange(((IEnumerable<Structure>)componentsInChildren).Where((Structure child) => (Object)(object)child != (Object)null && (Object)(object)child != (Object)(object)parent));
		return list;
	}

	public static bool IsWinter()
	{
		WeatherSystem instance = WeatherSystem.Instance;
		if ((Object)(object)instance == (Object)null || instance.CurrentSeason == null)
		{
			return false;
		}
		SeasonConfig config = instance.CurrentSeason.config;
		if ((Object)(object)config == (Object)null)
		{
			return false;
		}
		return ((Object)config).name.ToLower().Contains("winter");
	}
}
[BepInPlugin("blacks7ar.AutoIgnite", "AutoIgnite", "1.0.5")]
public class Plugin : BasePlugin
{
	[HarmonyPatch]
	private static class Patch
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Structure), "Spawned")]
		private static void Spawned_Postfix(Structure __instance)
		{
			//IL_0243: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Expected O, but got Unknown
			try
			{
				if (((Object)((Component)__instance).gameObject).name.Contains("FlimsyTorch") || ((Object)((Component)__instance).gameObject).name.Contains("StoneLantern"))
				{
					FireStructure componentInChildren = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren));
				}
				if (_enableHealingHouses.Value && ((Object)((Component)__instance).gameObject).name.Contains("HealingHouse"))
				{
					FireStructure componentInChildren2 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren2 == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren2));
				}
				if ((_enableCampfires.Value && ((Object)((Component)__instance).gameObject).name.Contains("ImprovedFire")) || ((Object)((Component)__instance).gameObject).name.Contains("SimpleFire"))
				{
					FireStructure componentInChildren3 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren3 == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren3));
				}
				if (_enableCookingHouses.Value && ((Object)((Component)__instance).gameObject).name.Contains("CookingHouse"))
				{
					FireStructure componentInChildren4 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren4 == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren4));
				}
				if (_enableRuneStones.Value && ((Object)((Component)__instance).gameObject).name.Contains("Runestone"))
				{
					FireStructure componentInChildren5 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren5 == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren5));
				}
				if (_enableFurnitureHeart.Value && ((Object)((Component)__instance).gameObject).name.Contains("FurnitureHearth"))
				{
					FireStructure componentInChildren6 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if ((Object)(object)componentInChildren6 == (Object)null)
					{
						return;
					}
					MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren6));
				}
				if (_enableFurnitureFireplace.Value && ((Object)((Component)__instance).gameObject).name.Contains("SmallFireplace"))
				{
					FireStructure componentInChildren7 = ((Component)__instance).gameObject.GetComponentInChildren<FireStructure>(true);
					if (!((Object)(object)componentInChildren7 == (Object)null))
					{
						MonoBehaviourExtensions.StartCoroutine((MonoBehaviour)(object)__instance, CheckTimeAndFuel(componentInChildren7));
					}
				}
			}
			catch (Exception ex)
			{
				ManualLogSource sTLogger = STLogger;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(27, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Spawned_Postfix exception: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				sTLogger.LogError(val);
			}
		}

		private static IEnumerator CheckTimeAndFuel(FireStructure fireStructure)
		{
			bool flag6 = default(bool);
			while (true)
			{
				yield return (object)new WaitForSeconds(5f);
				try
				{
					float currentFuelVolume = fireStructure.CurrentFuelVolume;
					WeatherSystem instance = WeatherSystem.Instance;
					if (!((Object)(object)instance != (Object)null))
					{
						continue;
					}
					float timeOfDay = instance.TimeOfDay;
					float value = _igniteTime.Value;
					float value2 = _extinguishTime.Value;
					if (currentFuelVolume > 0f && timeOfDay >= value && (int)fireStructure.CurrentFireState == 1)
					{
						fireStructure.Rpc_ChangeFireState((FireState)8);
					}
					if (!(timeOfDay >= value2) || !(timeOfDay < value) || (int)fireStructure.CurrentFireState == 1)
					{
						continue;
					}
					Structure componentInParent = ((Component)fireStructure).gameObject.GetComponentInParent<Structure>();
					bool flag = false;
					bool flag2 = false;
					bool flag3 = false;
					bool flag4 = false;
					bool flag5 = false;
					if ((Object)(object)componentInParent != (Object)null)
					{
						foreach (Structure item in from addOn in Helper.GetAllAddOns(componentInParent)
							where (Object)(object)addOn != (Object)null && ((Object)((Component)addOn).gameObject).name.Contains("Barbecue")
							select addOn)
						{
							_ = item;
							flag = true;
						}
						HealingStation component = ((Component)componentInParent).gameObject.GetComponent<HealingStation>();
						if ((Object)(object)component != (Object)null)
						{
							List<ITaskAgent> taskAgents = ((Workstation)component)._taskAgents;
							if (taskAgents != null && taskAgents.Count > 0)
							{
								Il2CppArrayBase<ITaskAgent> items = taskAgents._items;
								if (items != null && items.Count > 0)
								{
									flag3 = true;
								}
							}
						}
						CookingStation component2 = ((Component)componentInParent).gameObject.GetComponent<CookingStation>();
						if ((Object)(object)component2 != (Object)null && component2.IsCooking())
						{
							flag4 = true;
						}
						if ((Object)(object)component2 != (Object)null)
						{
							List<ITaskAgent> taskAgents = ((Workstation)component2)._taskAgents;
							if (taskAgents != null && taskAgents.Count > 0)
							{
								Il2CppArrayBase<ITaskAgent> items = taskAgents._items;
								if (items != null && items.Count > 0)
								{
									flag5 = true;
								}
							}
						}
					}
					if (Helper.IsWinter() && (Object)(object)componentInParent != (Object)null && (((Object)((Component)componentInParent).gameObject).name.Contains("House") || ((Object)((Component)componentInParent).gameObject).name.Contains("Fire") || ((Object)((Component)componentInParent).gameObject).name.Contains("Heart") || ((Object)((Component)componentInParent).gameObject).name.Contains("Fireplace")))
					{
						flag2 = true;
					}
					if (!(flag2 || flag || flag3 || flag4 || flag5))
					{
						fireStructure.Rpc_ChangeFireState((FireState)1);
					}
				}
				catch (Exception ex)
				{
					ManualLogSource sTLogger = STLogger;
					BepInExDebugLogInterpolatedStringHandler val = new BepInExDebugLogInterpolatedStringHandler(28, 1, ref flag6);
					if (flag6)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("CheckTimeAndFuel exception: ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
					}
					sTLogger.LogDebug(val);
				}
			}
		}
	}

	private const string modGUID = "blacks7ar.AutoIgnite";

	public const string modName = "AutoIgnite";

	public const string modAuthor = "blacks7ar";

	public const string modVersion = "1.0.5";

	public static ManualLogSource STLogger;

	private static ConfigEntry<float> _igniteTime;

	private static ConfigEntry<float> _extinguishTime;

	private static ConfigEntry<bool> _enableCookingHouses;

	private static ConfigEntry<bool> _enableHealingHouses;

	private static ConfigEntry<bool> _enableCampfires;

	private static ConfigEntry<bool> _enableRuneStones;

	private static ConfigEntry<bool> _enableFurnitureHeart;

	private static ConfigEntry<bool> _enableFurnitureFireplace;

	public override void Load()
	{
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		STLogger = ((BasePlugin)this).Log;
		_igniteTime = ((BasePlugin)this).Config.Bind<float>("General", "Ignite Time", 21f, "Scheduled time to ignite the torch.");
		_extinguishTime = ((BasePlugin)this).Config.Bind<float>("General", "Extinguish Time", 7f, "Scheduled time to extinguish the torch.");
		_enableCookingHouses = ((BasePlugin)this).Config.Bind<bool>("General", "Enable Cooking House", true, "If true, cooking houses fire will be auto ignite.");
		_enableHealingHouses = ((BasePlugin)this).Config.Bind<bool>("General", "Enable Healing House", true, "If true, healing houses fire will be auto ignite.");
		_enableCampfires = ((BasePlugin)this).Config.Bind<bool>("General", "Enable Campfire", true, "If true, campfires fire will be auto ignite.");
		_enableRuneStones = ((BasePlugin)this).Config.Bind<bool>("General", "Runestones", true, "If true, runestones fire will be auto ignite.");
		_enableFurnitureHeart = ((BasePlugin)this).Config.Bind<bool>("General", "Heart", true, "If true, furniture hearts fire will be auto ignite.");
		_enableFurnitureFireplace = ((BasePlugin)this).Config.Bind<bool>("General", "Fireplace", true, "If true, furniture fireplace fire will be auto ignite.");
		STLogger.LogInfo((object)"Mod loaded.");
		new Harmony("blacks7ar.AutoIgnite").PatchAll();
	}
}