Decompiled source of HexInfiniteFuel v1.0.0

plugins/HexInfiniteFuel.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("HexInfiniteFuel")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HexInfiniteFuel")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("56e2c00c-2961-46ce-80df-7e699c3921de")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HexInfiniteFuel;

[BepInPlugin("hex.infinitefuel", "Infinite Fuel", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	private const string PluginGuid = "hex.infinitefuel";

	private const string PluginName = "Infinite Fuel";

	private const string PluginVersion = "1.0.0";

	private ConfigEntry<bool> _pluginEnabled;

	public static ManualLogSource logger = Logger.CreateLogSource("Infinite Fuel");

	internal static Plugin Instance { get; private set; }

	internal static Harmony HarmonyInstance { get; private set; }

	public static ConfigEntry<bool> EnableAdvancedDebugLogging { get; private set; }

	public bool IsPluginEnabled => _pluginEnabled.Value;

	public void Awake()
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		Instance = this;
		_pluginEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enable Infinite Fuel", true, "Enable or disable " + "Infinite Fuel".ToLower() + ".");
		EnableAdvancedDebugLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "EnableAdvancedDebugLogging", false, "Enable or disable advanced debug logging.");
		_pluginEnabled.SettingChanged += OnPluginEnabledChanged;
		HarmonyInstance = new Harmony("hex.infinitefuel");
		HarmonyInstance.PatchAll();
		logger.LogInfo((object)"Infinite Fuel v1.0.0 is loaded!");
	}

	public void OnDestroy()
	{
		if (_pluginEnabled != null)
		{
			_pluginEnabled.SettingChanged -= OnPluginEnabledChanged;
		}
		Harmony harmonyInstance = HarmonyInstance;
		if (harmonyInstance != null)
		{
			harmonyInstance.UnpatchSelf();
		}
		HarmonyInstance = null;
		Instance = null;
		logger.LogInfo((object)"Infinite Fuel v1.0.0 is unloaded!");
	}

	private void OnPluginEnabledChanged(object sender, EventArgs e)
	{
		ApplyInfiniteFuelToAllFireplaces();
	}

	private void ApplyInfiniteFuelToAllFireplaces()
	{
		Fireplace[] array = Object.FindObjectsByType<Fireplace>((FindObjectsSortMode)0);
		Fireplace[] array2 = array;
		foreach (Fireplace val in array2)
		{
			if (!((Object)(object)val == (Object)null))
			{
				val.m_infiniteFuel = IsPluginEnabled;
			}
		}
		if (EnableAdvancedDebugLogging.Value)
		{
			logger.LogInfo((object)$"Applied Infinite Fuel = {IsPluginEnabled} to {array.Length} fireplaces.");
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "Awake")]
public static class PatchFireplace
{
	private static void Postfix(Fireplace __instance)
	{
		if (!((Object)(object)__instance == (Object)null) && !((Object)(object)Plugin.Instance == (Object)null))
		{
			__instance.m_infiniteFuel = Plugin.Instance.IsPluginEnabled;
			if (Plugin.EnableAdvancedDebugLogging.Value)
			{
				Plugin.logger.LogInfo((object)$"[PatchFireplace] Set m_infiniteFuel to {__instance.m_infiniteFuel}");
			}
		}
	}
}