Decompiled source of For Watt Its Worth v1.0.2

For_Watt_Its_Worth.dll

Decompiled a year ago
using System;
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 Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("For_Watt_Its_Worth")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Norger")]
[assembly: AssemblyProduct("For_Watt_Its_Worth")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.2")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.0")]
[module: UnverifiableCode]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace ForWattItsWorth
{
	[BepInPlugin("Norger.For_Watt_Its_Worth", "For_Watt_Its_Worth", "1.0.2")]
	public class ForWattItsWorthPlugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(ElectricGenerator))]
		[HarmonyPatch("Spawned")]
		public static class ElectricGenerator_Spawned_Patch
		{
			public static void Postfix(ElectricGenerator __instance)
			{
				__instance.MaxSupply = MaxSupply.Value;
				__instance.fuelCapacity = fuelCapacity.Value;
			}
		}

		[HarmonyPatch(typeof(ElectricGenerator))]
		[HarmonyPatch("Update")]
		public class ElectricGenerator_Patch
		{
			private static void Postfix(ref ElectricGenerator __instance)
			{
				__instance.ConsumptionOfFuel = ConsumptionOfFuel.Value;
			}
		}

		[HarmonyPatch(typeof(HeadLight))]
		[HarmonyPatch("Update")]
		public class HeadLight_Patch
		{
			private static void Postfix(ref HeadLight __instance)
			{
				__instance.batteryPowerConsumptionPerSecond = batteryPowerConsumptionPerSecond.Value;
			}
		}

		[HarmonyPatch(typeof(HandheldSwimmer))]
		[HarmonyPatch("Update")]
		public class HandheldSwimmer_Patch
		{
			private static void Postfix(ref HandheldSwimmer __instance)
			{
				__instance.PowerConsumingRate = PowerConsumingRate.Value;
			}
		}

		internal const string ModName = "For_Watt_Its_Worth";

		internal const string ModVersion = "1.0.2";

		internal const string Author = "Norger";

		private const string ModGUID = "Norger.For_Watt_Its_Worth";

		private static string ConfigFileName = "Norger.For_Watt_Its_Worth.cfg";

		private static string ConfigFileFullPath;

		private readonly Harmony _harmony = new Harmony("Norger.For_Watt_Its_Worth");

		public static readonly ManualLogSource ForWattItsWorthLogger;

		public static ConfigEntry<bool> ModEnabled;

		public static ConfigEntry<float> ConsumptionOfFuel;

		public static ConfigEntry<float> MaxSupply;

		public static ConfigEntry<float> fuelCapacity;

		public static ConfigEntry<float> batteryPowerConsumptionPerSecond;

		public static ConfigEntry<float> PowerConsumingRate;

		public void Awake()
		{
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ModEnabled", true, "Enable or disable the mod.");
			ConsumptionOfFuel = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Generator", "ConsumeFuelAmount", 0.0001f, "Adjust the fuel consumption rate per second.0.00001 = 1E-05 which is roughly 0.1 loss every 3.5 minutes");
			MaxSupply = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Generator", "MaxSupply", 1000f, "Maxsupport is the needed power requirements + the value entered so you will always have enough power.");
			fuelCapacity = ((BaseUnityPlugin)this).Config.Bind<float>("2 - Generator", "fuelCapacity", 1000f, "Hold more or less fuel.");
			batteryPowerConsumptionPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("3 - HeadLight", "batteryPowerConsumptionPerSecond", 0.0001f, "Adjust the battrypowerconsumption rate per second.");
			PowerConsumingRate = ((BaseUnityPlugin)this).Config.Bind<float>("4 - HandheldSwimmer", "batteryPowerConsumptionPerSecond", 0.0001f, "Adjust the battrypowerconsumption rate per second.");
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			_harmony.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
			{
				ForWattItsWorthLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				ForWattItsWorthLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				ForWattItsWorthLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		static ForWattItsWorthPlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			ForWattItsWorthLogger = Logger.CreateLogSource("For_Watt_Its_Worth");
		}
	}
}