Decompiled source of TebFireTweaks v0.1.1

TebFireTweaks.dll

Decompiled a year ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
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("TebFireTweaks")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TebFireTweaks")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("193d7a7c-5d30-43ab-a2c3-13840f581179")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace TebFireTweaks;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.tebbeh.mod.TebFireTweaks", "TebFireTweaks", "0.1.0")]
public class TebFireTweaks : BaseUnityPlugin
{
	private const string ModName = "TebFireTweaks";

	private const string ModVersion = "0.1.0";

	private const string Author = "com.tebbeh.mod";

	private const string ModGUID = "com.tebbeh.mod.TebFireTweaks";

	private static string ConfigFileName = "com.tebbeh.mod.TebFireTweaks.cfg";

	private static string ConfigFileFullPath;

	private readonly Harmony HarmonyInstance = new Harmony("com.tebbeh.mod.TebFireTweaks");

	public static readonly ManualLogSource TebLogger;

	internal static ConfigEntry<bool> AdminBypass;

	internal static ConfigEntry<bool> FireplaceInfinite;

	internal static ConfigEntry<bool> FireplaceWeatherBlock;

	internal static ConfigEntry<bool> CookingStationInfinite;

	internal static ConfigEntry<float> CookingCookingSpeedInfinite;

	internal static ConfigEntry<bool> SmelterInfinite;

	private readonly ConfigurationManagerAttributes AdminConfig = new ConfigurationManagerAttributes
	{
		IsAdminOnly = true
	};

	private readonly ConfigurationManagerAttributes ClientConfig = new ConfigurationManagerAttributes
	{
		IsAdminOnly = false
	};

	public static bool GetAdminBypass()
	{
		return AdminBypass.Value;
	}

	public static bool GetFireplaceInfinite()
	{
		return FireplaceInfinite.Value;
	}

	public static bool GetFireplaceWeatherBlock()
	{
		return FireplaceWeatherBlock.Value;
	}

	public static bool GetCookingStationInfinite()
	{
		return CookingStationInfinite.Value;
	}

	public static float GetCookingCookingSpeedInfinite()
	{
		return CookingCookingSpeedInfinite.Value;
	}

	public static bool GetSmelterInfinite()
	{
		return SmelterInfinite.Value;
	}

	private void AddConfig<T>(string key, string section, string description, bool synced, T value, ref ConfigEntry<T> configEntry)
	{
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		string extendedDescription = GetExtendedDescription(description, synced);
		configEntry = ((BaseUnityPlugin)this).Config.Bind<T>(section, key, value, new ConfigDescription(extendedDescription, (AcceptableValueBase)null, new object[1] { synced ? AdminConfig : ClientConfig }));
	}

	public string GetExtendedDescription(string description, bool synchronizedSetting)
	{
		return description + (synchronizedSetting ? " [Synced with Server]" : " [Not Synced with Server]");
	}

	private void Awake()
	{
		AddConfig("AdminBypass", "General", "True to allow admins to bypass some setting restrictions (boolean).", synced: true, value: true, ref AdminBypass);
		AddConfig("FireplaceInfinite", "Misc", "Apply infinite fuel to all types of fireplaces (boolean).", synced: true, value: true, ref FireplaceInfinite);
		AddConfig("FireplaceWeatherBlock", "Misc", "Apply weather block to all types of fireplaces (boolean).", synced: true, value: true, ref FireplaceWeatherBlock);
		AddConfig("CookingStationInfinite", "Misc", "Apply infinite fuel to all types of cooking stations (boolean).", synced: true, value: true, ref CookingStationInfinite);
		AddConfig("CookingStationCookingSpeed", "Misc", "Change cooking speed of cooking stations. -50 will reduce time with 50%. Max is -100, less could cause bugs. (float).", synced: true, 0f, ref CookingCookingSpeedInfinite);
		AddConfig("SmelterInfinite", "Misc", "Apply infinite fuel to all types of smelters (boolean).", synced: true, value: true, ref SmelterInfinite);
		Assembly executingAssembly = Assembly.GetExecutingAssembly();
		HarmonyInstance.PatchAll(executingAssembly);
		SetupWatcher();
	}

	private void OnDestroy()
	{
		((BaseUnityPlugin)this).Config.Save();
	}

	private void SetupWatcher()
	{
		FileSystemWatcher fileSystemWatcher = new FileSystemWatcher(Paths.ConfigPath, ConfigFileName);
		fileSystemWatcher.Changed += ReadConfigValues;
		fileSystemWatcher.Created += ReadConfigValues;
		fileSystemWatcher.Renamed += ReadConfigValues;
		fileSystemWatcher.IncludeSubdirectories = true;
		fileSystemWatcher.SynchronizingObject = ThreadingHelper.SynchronizingObject;
		fileSystemWatcher.EnableRaisingEvents = true;
	}

	private void ReadConfigValues(object sender, FileSystemEventArgs e)
	{
		if (!File.Exists(ConfigFileFullPath))
		{
			return;
		}
		try
		{
			TebLogger.LogDebug((object)"Attempting to reload configuration...");
			((BaseUnityPlugin)this).Config.Reload();
		}
		catch
		{
			TebLogger.LogError((object)("There was an issue loading " + ConfigFileName));
		}
	}

	static TebFireTweaks()
	{
		string configPath = Paths.ConfigPath;
		char directorySeparatorChar = Path.DirectorySeparatorChar;
		ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
		TebLogger = Logger.CreateLogSource("TebFireTweaks");
		AdminBypass = null;
		FireplaceInfinite = null;
		FireplaceWeatherBlock = null;
		CookingStationInfinite = null;
		CookingCookingSpeedInfinite = null;
		SmelterInfinite = null;
	}
}
[HarmonyPatch(typeof(Smelter), "Awake")]
internal static class SmelterInfiniteAwake
{
	[HarmonyPostfix]
	private static void SmelterInfiniteAwakeState(Smelter __instance)
	{
		if (TebFireTweaks.GetSmelterInfinite())
		{
			__instance.SetFuel((float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(Smelter), "UpdateState")]
internal static class SmelterInfiniteUpdateState
{
	[HarmonyPostfix]
	private static void SmelterInfiniteClass(Smelter __instance)
	{
		if (TebFireTweaks.GetSmelterInfinite() && !__instance.IsActive())
		{
			__instance.IsActive();
			__instance.SetFuel((float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "Awake")]
internal static class CookingStationInfiniteAwake
{
	[HarmonyPostfix]
	private static void CookingStationInfiniteAwakeState(CookingStation __instance)
	{
		if (TebFireTweaks.GetCookingCookingSpeedInfinite() != 0f)
		{
			float cookingCookingSpeedInfinite = TebFireTweaks.GetCookingCookingSpeedInfinite();
			float num = 1f + cookingCookingSpeedInfinite / 100f;
			TebFireTweaks.TebLogger.LogDebug((object)cookingCookingSpeedInfinite);
			TebFireTweaks.TebLogger.LogDebug((object)num);
			for (int i = 0; i < __instance.m_conversion.Count; i++)
			{
				ItemConversion obj = __instance.m_conversion[i];
				obj.m_cookTime *= num;
			}
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "UpdateFuel")]
internal static class CookingStationInfiniteSetFuel
{
	[HarmonyPrefix]
	private static void CookingStationSetFuel(CookingStation __instance)
	{
		if (TebFireTweaks.GetCookingStationInfinite() && __instance.GetFuel() <= 1f)
		{
			__instance.SetFuel((float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(CookingStation), "UpdateCooking")]
internal static class CookingStationUpdateCooking
{
	private static Vector3 userPoint;

	[HarmonyPrefix]
	private static void CookingStationUpdateCookingTweak(CookingStation __instance, ZNetView ___m_nview)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: Invalid comparison between Unknown and I4
		//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
		string text = default(string);
		float num = default(float);
		Status val = default(Status);
		for (int i = 0; i < __instance.m_slots.Length; i++)
		{
			string @string = ___m_nview.GetZDO().GetString("slot" + i, "");
			float @float = ___m_nview.GetZDO().GetFloat("slot" + i, 0f);
			int @int = ___m_nview.GetZDO().GetInt("slotstatus" + i, 0);
			__instance.GetSlot(i, ref text, ref num, ref val);
			float cookTime = __instance.m_conversion[i].m_cookTime;
			if (text != "" && (int)val == 1)
			{
				__instance.RPC_RemoveDoneItem((long)i, userPoint);
			}
		}
		if (TebFireTweaks.GetCookingStationInfinite() && __instance.GetFuel() <= 0f)
		{
			__instance.SetFuel((float)__instance.m_maxFuel);
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "Awake")]
internal static class FireplaceInfinite
{
	[HarmonyPostfix]
	private static void FireplaceInfiniteClass(Fireplace __instance)
	{
		if (TebFireTweaks.GetFireplaceInfinite())
		{
			__instance.m_infiniteFuel = true;
		}
	}
}
[HarmonyPatch(typeof(Fireplace), "CheckWet")]
internal static class FireplaceWeatherBlock
{
	[HarmonyPrefix]
	private static bool FireplaceWeatherBlockClass(Fireplace __instance)
	{
		if (TebFireTweaks.GetFireplaceWeatherBlock())
		{
			__instance.m_wet = false;
			return false;
		}
		return true;
	}
}