Decompiled source of UnlimitedFuel v1.2.1

UnlimitedFuel.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Xml.Linq;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("eff5117c-c508-4bed-97b7-ae18774fc548")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace UnlimitedFuel;

[BepInPlugin("com.Odion30.UnlimitedFuel", "UnlimitedFuel", "1.2.1")]
public class UnlimitedFuel : BaseUnityPlugin
{
	public const string MODNAME = "UnlimitedFuel";

	public const string AUTHOR = "Odion30";

	public const string GUID = "com.Odion30.UnlimitedFuel";

	public const string VERSION = "1.2.1";

	public static Mod_Config Mod_Config;

	private static UnlimitedFuel context;

	public void Awake()
	{
		//IL_001c: Unknown result type (might be due to invalid IL or missing references)
		context = this;
		Mod_Config = new Mod_Config(((BaseUnityPlugin)this).Config);
		new Harmony("com.Odion30.UnlimitedFuel").PatchAll();
		Object.DontDestroyOnLoad((Object)(object)this);
	}

	public static void Dbgl(string str = "", LogLevel logLevel = 32)
	{
		//IL_000b: Unknown result type (might be due to invalid IL or missing references)
		((BaseUnityPlugin)context).Logger.Log(logLevel, (object)(typeof(UnlimitedFuel).Namespace + " " + str));
	}
}
[HarmonyPatch(typeof(Game), "Start")]
public static class Game_Start_Patch
{
	public static void Postfix()
	{
		UnlimitedFuel.Mod_Config.Reload();
	}
}
[HarmonyPatch(typeof(ZNet), "OnNewConnection")]
public static class RegisterAndCheckVersion
{
	private static void Prefix(ZNetPeer peer, ref ZNet __instance)
	{
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Expected O, but got Unknown
		UnlimitedFuel.Dbgl("Registering UnlimitedFuel_ConfigSync", (LogLevel)16);
		peer.m_rpc.Register<ZPackage>("UnlimitedFuel_ConfigSync", (Action<ZRpc, ZPackage>)RPC_Handler.RPC_UnlimitedFuel_ConfigSync);
		if (ZNet.instance.IsServer())
		{
			ZPackage val = new ZPackage();
			val.Write(((object)UnlimitedFuel.Mod_Config.xConfig).ToString());
			peer.m_rpc.Invoke("UnlimitedFuel_ConfigSync", new object[1] { val });
		}
	}
}
public static class RPC_Handler
{
	public static void RPC_UnlimitedFuel_ConfigSync(ZRpc rpc, ZPackage pkg)
	{
		string text = pkg.ReadString();
		if (ZNet.instance.IsServer())
		{
			return;
		}
		try
		{
			XElement val = XElement.Parse(text);
			if (val != null)
			{
				UnlimitedFuel.Mod_Config.xConfig = val;
				UnlimitedFuel.Dbgl("Recived Config Enabled " + UnlimitedFuel.Mod_Config.Enabled, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Torches " + UnlimitedFuel.Mod_Config.Fuel_Torches, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Fireplaces " + UnlimitedFuel.Mod_Config.Fuel_Fireplaces, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Oven " + UnlimitedFuel.Mod_Config.Fuel_Oven, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Smelter " + UnlimitedFuel.Mod_Config.Fuel_Smelter, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Bathtub " + UnlimitedFuel.Mod_Config.Fuel_Bathtub, (LogLevel)16);
				UnlimitedFuel.Dbgl("Recived Config Fuel_Shield " + UnlimitedFuel.Mod_Config.Fuel_Shield, (LogLevel)16);
			}
		}
		catch
		{
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "UpdateFireplace")]
public static class Fireplace_UpdateFireplace_Patch
{
	public static void Prefix(Fireplace __instance, ZNetView ___m_nview)
	{
		if (!UnlimitedFuel.Mod_Config.Enabled)
		{
			return;
		}
		if (__instance.m_name.Contains("torch"))
		{
			if (UnlimitedFuel.Mod_Config.Fuel_Torches)
			{
				___m_nview.GetZDO().Set(ZDOVars.s_fuel, __instance.m_maxFuel);
			}
		}
		else if (UnlimitedFuel.Mod_Config.Fuel_Fireplaces)
		{
			___m_nview.GetZDO().Set(ZDOVars.s_fuel, __instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(Smelter), "UpdateSmelter")]
public static class Smelter_UpdateSmelter_Patch
{
	public static void Prefix(Smelter __instance, ZNetView ___m_nview)
	{
		if (!UnlimitedFuel.Mod_Config.Enabled || !((float)__instance.m_maxFuel > 0f))
		{
			return;
		}
		if ((float)__instance.m_maxOre > 0f)
		{
			if (UnlimitedFuel.Mod_Config.Fuel_Smelter)
			{
				___m_nview.GetZDO().Set(ZDOVars.s_fuel, (float)__instance.m_maxFuel);
			}
		}
		else if (UnlimitedFuel.Mod_Config.Fuel_Bathtub)
		{
			___m_nview.GetZDO().Set(ZDOVars.s_fuel, (float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "UpdateCooking")]
public static class CookingStation_UpdateCooking_Patch
{
	public static void Postfix(CookingStation __instance, ZNetView ___m_nview)
	{
		if (UnlimitedFuel.Mod_Config.Enabled && (float)__instance.m_maxFuel > 0f && UnlimitedFuel.Mod_Config.Fuel_Oven)
		{
			___m_nview.GetZDO().Set(ZDOVars.s_fuel, (float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(ShieldGenerator), "UpdateShield")]
public static class ShieldGenerator_UpdateShield_Patch
{
	public static void Prefix(ShieldGenerator __instance, ZNetView ___m_nview)
	{
		if (UnlimitedFuel.Mod_Config.Enabled && UnlimitedFuel.Mod_Config.Fuel_Shield)
		{
			___m_nview.GetZDO().Set(ZDOVars.s_fuel, (float)__instance.m_maxFuel);
		}
	}
}
public class Mod_Config
{
	private ConfigFile Config;

	public XElement xConfig
	{
		get
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Expected O, but got Unknown
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_005d: Expected O, but got Unknown
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Expected O, but got Unknown
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Expected O, but got Unknown
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f5: Expected O, but got Unknown
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Expected O, but got Unknown
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0121: Expected O, but got Unknown
			return new XElement(XName.op_Implicit("Config"), new object[7]
			{
				(object)new XAttribute(XName.op_Implicit("Enabled"), (object)(Enabled ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Torches"), (object)(Fuel_Torches ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Fireplaces"), (object)(Fuel_Fireplaces ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Oven"), (object)(Fuel_Oven ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Smelter"), (object)(Fuel_Smelter ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Bathtub"), (object)(Fuel_Bathtub ? "true" : "false")),
				(object)new XAttribute(XName.op_Implicit("Fuel_Shield"), (object)(Fuel_Shield ? "true" : "false"))
			});
		}
		set
		{
			Enabled = value.Attribute(XName.op_Implicit("Enabled")).Value == "true";
			Fuel_Torches = value.Attribute(XName.op_Implicit("Fuel_Torches")).Value == "true";
			Fuel_Fireplaces = value.Attribute(XName.op_Implicit("Fuel_Fireplaces")).Value == "true";
			Fuel_Oven = value.Attribute(XName.op_Implicit("Fuel_Oven")).Value == "true";
			Fuel_Smelter = value.Attribute(XName.op_Implicit("Fuel_Smelter")).Value == "true";
			Fuel_Bathtub = value.Attribute(XName.op_Implicit("Fuel_Bathtub")).Value == "true";
			Fuel_Shield = value.Attribute(XName.op_Implicit("Fuel_Shield")).Value == "true";
		}
	}

	public bool Enabled { get; set; }

	public bool Fuel_Torches { get; private set; }

	public bool Fuel_Fireplaces { get; private set; }

	public bool Fuel_Oven { get; private set; }

	public bool Fuel_Smelter { get; private set; }

	public bool Fuel_Bathtub { get; private set; }

	public bool Fuel_Shield { get; private set; }

	public Mod_Config(ConfigFile Config)
	{
		this.Config = Config;
		Reload();
	}

	public void Reload()
	{
		if (Config != null)
		{
			Enabled = Config.Bind<bool>("General", "Enabled", true, "Enable this mod").Value;
			Fuel_Torches = Config.Bind<bool>("General", "Torches", true, "Autofill Torches!").Value;
			Fuel_Fireplaces = Config.Bind<bool>("General", "Fireplaces", true, "Autofill Fireplaces!").Value;
			Fuel_Oven = Config.Bind<bool>("General", "Oven", true, "Autofill Oven!").Value;
			Fuel_Smelter = Config.Bind<bool>("General", "Smelter", true, "Autofill Smelter!").Value;
			Fuel_Bathtub = Config.Bind<bool>("General", "Bathtub", true, "Autofill Bathtub!").Value;
			Fuel_Shield = Config.Bind<bool>("General", "Shield", true, "Autofill Shield!").Value;
		}
	}
}