Decompiled source of Man Your Machine v1.0.0

Man_Your_Machine.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 JetBrains.Annotations;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("Man_Your_Machine")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Norger")]
[assembly: AssemblyProduct("Man_Your_Machine")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4358610B-F3F4-4843-B7AF-98B7BC60DCDE")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.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 Man_Your_Machine
{
	[BepInPlugin("Norger.Man_Your_Machine", "Man_Your_Machine", "1.0.0")]
	public class Man_Your_MachinePlugin : BaseUnityPlugin
	{
		public enum Toggle
		{
			On = 1,
			Off = 0
		}

		private class ConfigurationManagerAttributes
		{
			[UsedImplicitly]
			public int? Order;

			[UsedImplicitly]
			public bool? Browsable;

			[UsedImplicitly]
			public string? Category;

			[UsedImplicitly]
			public Action<ConfigEntryBase>? CustomDrawer;
		}

		private class AcceptableShortcuts : AcceptableValueBase
		{
			public AcceptableShortcuts()
				: base(typeof(KeyboardShortcut))
			{
			}

			public override object Clamp(object value)
			{
				return value;
			}

			public override bool IsValid(object value)
			{
				return true;
			}

			public override string ToDescriptionString()
			{
				return "# Acceptable values: " + string.Join(", ", UnityInput.Current.SupportedKeyCodes);
			}
		}

		[HarmonyPatch(typeof(BioFuelLab))]
		[HarmonyPatch("Awake")]
		public static class BioFuelLab_Awake_Patch
		{
			private static void Postfix(BioFuelLab __instance)
			{
				__instance.IngredientCapacity = IngredientCapacity.Value;
				__instance.woodCapacity = WoodCapacity.Value;
			}
		}

		[HarmonyPatch(typeof(BioFuelLab))]
		[HarmonyPatch("Spawned")]
		public static class BioFuelLab_Spawned_Patch
		{
			public static void Postfix(BioFuelLab __instance)
			{
				__instance.fuelCapacity = fuelCapacity.Value;
			}
		}

		[HarmonyPatch(typeof(BioFuelLab))]
		[HarmonyPatch("CalculateFuelProduction")]
		public static class BioFuelLab_Patch
		{
			private static void Postfix(ref BioFuelLab __instance)
			{
				__instance.productionTimeInterval = productionTimeInterval.Value;
			}
		}

		[HarmonyPatch(typeof(BioFuelLab))]
		[HarmonyPatch("CalculateWoodConsumption")]
		public static class BioFuelLab_Patch1
		{
			private static void Postfix(ref BioFuelLab __instance)
			{
				__instance.woodBurnDuration = woodBurnDuration.Value;
			}
		}

		[HarmonyPatch(typeof(SteelFurnace))]
		[HarmonyPatch("Awake")]
		public static class SteelFurnace_Awake_Patch
		{
			private static void Postfix(SteelFurnace __instance)
			{
				__instance.IronIngotRequest = IronIngotRequest.Value;
			}
		}

		[HarmonyPatch(typeof(WaterBucket))]
		[HarmonyPatch("Awake")]
		public static class WaterBucket_Patch
		{
			private static void Postfix(WaterBucket __instance)
			{
				__instance.MaxFreshWater = MaxFreshWater.Value;
			}
		}

		internal const string ModName = "Man_Your_Machine";

		internal const string ModVersion = "1.0.0";

		internal const string Author = "Norger";

		private const string ModGUID = "Norger.Man_Your_Machine";

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

		private static string ConfigFileFullPath;

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

		public static readonly ManualLogSource Man_Your_MachineLogger;

		public static ConfigEntry<bool> ModEnabled;

		public static ConfigEntry<float> fuelCapacity;

		public static ConfigEntry<float> woodBurnDuration;

		public static ConfigEntry<float> productionTimeInterval;

		public static ConfigEntry<int> IngredientCapacity;

		public static ConfigEntry<int> WoodCapacity;

		public static ConfigEntry<float> ItemProcessingDuration;

		public static ConfigEntry<int> IronIngotRequest;

		public static ConfigEntry<int> MaxFreshWater;

		private static ConfigEntry<Toggle> exampleConfig;

		public void Awake()
		{
			ModEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("1 - General", "ModEnabled", true, "Enable or disable the mod.");
			productionTimeInterval = ((BaseUnityPlugin)this).Config.Bind<float>("2 - BioFuelLab", "productionTimeInterval", 0.5f, "Adjust the Production Time Interval per second.");
			woodBurnDuration = ((BaseUnityPlugin)this).Config.Bind<float>("2 - BioFuelLab", "woodBurnDuration", 2f, "woodBurnDuration - how long wood will burn for in seconds.");
			fuelCapacity = ((BaseUnityPlugin)this).Config.Bind<float>("2 - BioFuelLab", "fuelCapacity", 20f, "Hold more or less fuel.");
			IngredientCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("2 - BioFuelLab", "IngredientCapacity", 10, "Set the maximum ingredient capacity.");
			WoodCapacity = ((BaseUnityPlugin)this).Config.Bind<int>("2 - BioFuelLab", "WoodCapacity", 10, "Set the maximum wood capacity.");
			ItemProcessingDuration = ((BaseUnityPlugin)this).Config.Bind<float>("3 - Furnace", "ItemProcessingDuration", 2f, "Item processing duration in seconds.");
			IronIngotRequest = ((BaseUnityPlugin)this).Config.Bind<int>("4 - Iron Ingot", "IronIngotRequest", 10, "Set the Iron Ingot request value.");
			MaxFreshWater = ((BaseUnityPlugin)this).Config.Bind<int>("4 - WaterAmount", "WaterAmount", 10, "Set the WaterAmount value.");
			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
			{
				Man_Your_MachineLogger.LogDebug((object)"ReadConfigValues called");
				((BaseUnityPlugin)this).Config.Reload();
			}
			catch
			{
				Man_Your_MachineLogger.LogError((object)("There was an issue loading your " + ConfigFileName));
				Man_Your_MachineLogger.LogError((object)"Please check your config entries for spelling and format!");
			}
		}

		static Man_Your_MachinePlugin()
		{
			string configPath = Paths.ConfigPath;
			char directorySeparatorChar = Path.DirectorySeparatorChar;
			ConfigFileFullPath = configPath + directorySeparatorChar + ConfigFileName;
			Man_Your_MachineLogger = Logger.CreateLogSource("Man_Your_Machine");
			exampleConfig = null;
		}
	}
}