Decompiled source of BetterEnergyExchanger v1.0.0

BetterEnergyExchanger.dll

Decompiled 3 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("BetterEnergyExchanger")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+2079608356d554c25c4f80f74f819ef4235886b0")]
[assembly: AssemblyProduct("BetterEnergyExchanger")]
[assembly: AssemblyTitle("BetterEnergyExchanger")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterEnergyExchanger
{
	[BepInPlugin("kelso4321.plugin.BetterEnergyExchanger", "BetterEnergyExchanger", "1.0.0")]
	public class BetterEnergyExchanger : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PowerExchangerComponent), "CalculateActualEnergyPerTick")]
		public static class EnergyExchangerPatch
		{
			private static void Postfix(bool isOutput, ref long __result)
			{
				if (!((Object)(object)Instance == (Object)null))
				{
					int value = ChargeMultiplier.Value;
					int value2 = DischargeMultiplier.Value;
					__result *= (isOutput ? value2 : value);
				}
			}
		}

		public const string GUID = "kelso4321.plugin.BetterEnergyExchanger";

		public const string NAME = "BetterEnergyExchanger";

		public const string VERSION = "1.0.0";

		internal static BetterEnergyExchanger Instance;

		internal static ManualLogSource Logger;

		internal static Harmony harmony;

		private static ConfigEntry<int> ChargeMultiplier;

		private static ConfigEntry<int> DischargeMultiplier;

		private void Awake()
		{
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: Expected O, but got Unknown
			Instance = this;
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"BetterEnergyExchanger v1.0.0 loaded!");
			InitConfig();
			harmony = new Harmony("kelso4321.plugin.BetterEnergyExchanger");
			harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private static void InitConfig()
		{
			Logger.LogInfo((object)("Initializing config from " + ((BaseUnityPlugin)Instance).Config.ConfigFilePath + "..."));
			ChargeMultiplier = CreateConfigEntry("ChargeMultiplier", "Charge multiplier", "Multiplier for energy exchanger charge rate");
			DischargeMultiplier = CreateConfigEntry("DischargeMultiplier", "Discharge multiplier", "Multiplier for energy exchanger discharge rate");
			Logger.LogInfo((object)$"Config initialized with ChargeMultiplier: {ChargeMultiplier.Value}, DischargeMultiplier: {DischargeMultiplier.Value}");
		}

		private static ConfigEntry<int> CreateConfigEntry(string key, string name, string description, int defaultValue = 2, int min = 1, int max = 10)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			return ((BaseUnityPlugin)Instance).Config.Bind<int>("General", key, defaultValue, new ConfigDescription(description, (AcceptableValueBase)(object)new AcceptableValueRange<int>(min, max), Array.Empty<object>()));
		}
	}
}