Decompiled source of StationChargeBoost v0.0.2

StationChargeBoost.dll

Decompiled 2 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.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("StationChargeBoost")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Increases the maximum charge power for interstellar stations beyond the default limit.")]
[assembly: AssemblyFileVersion("0.0.2.0")]
[assembly: AssemblyInformationalVersion("0.0.2+eae07488cd657e90ea7fbaf4577eb0e465c5fbe9")]
[assembly: AssemblyProduct("StationChargeBoost")]
[assembly: AssemblyTitle("StationChargeBoost")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.2.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 StationChargeBoost
{
	[BepInPlugin("lxb007981.dsp.StationChargeBoost", "StationChargeBoost", "0.0.2")]
	public class StationChargeBoost : BaseUnityPlugin
	{
		public static class Configs
		{
			public static int ConfigMaxChargePower = 1000;
		}

		public const string __NAME__ = "StationChargeBoost";

		public const string __GUID__ = "lxb007981.dsp.StationChargeBoost";

		public const string __VERSION__ = "0.0.2";

		private Harmony harmony;

		public static readonly ManualLogSource Logger = Logger.CreateLogSource("StationChargeBoost");

		public void Awake()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Expected O, but got Unknown
			harmony = new Harmony("lxb007981.dsp.StationChargeBoost");
			Configs.ConfigMaxChargePower = ((BaseUnityPlugin)this).Config.Bind<int>("General", "MaxChargePower", 1000, "The maximum charge power (mw) for interstellar stations.").Value;
			Logger.LogInfo((object)"Plugin lxb007981.dsp.StationChargeBoost is loaded!");
			harmony.PatchAll(typeof(StationChargeBoost));
		}

		public void OnDestroy()
		{
			harmony.UnpatchSelf();
		}

		public static bool IsValidStellarStation(StationComponent sc)
		{
			return sc != null && sc.entityId > 0 && !sc.isVeinCollector && !sc.isCollector && sc.isStellar;
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIStationWindow), "OnMaxChargePowerSliderValueChange")]
		public static void UIStationWindow_OnMaxChargePowerSliderValueChange_Prefix(ref UIStationWindow __instance, ref float value)
		{
			StationComponent sc = __instance.transport.stationPool[__instance.stationId];
			if (IsValidStellarStation(sc))
			{
				value = 10f + (value - 10f) * (float)(Configs.ConfigMaxChargePower - 30) / 270f;
			}
		}

		[HarmonyPrefix]
		[HarmonyPatch(typeof(UIControlPanelStationInspector), "OnMaxChargePowerSliderValueChange")]
		public static void UIControlPanelStationInspector_OnMaxChargePowerSliderValueChange_Prefix(ref UIControlPanelStationInspector __instance, ref float value)
		{
			StationComponent sc = __instance.transport.stationPool[__instance.stationId];
			if (IsValidStellarStation(sc))
			{
				value = 10f + (value - 10f) * (float)(Configs.ConfigMaxChargePower - 30) / 270f;
			}
		}

		private static float ComputeSliderValue(long workEnergyPerTick)
		{
			return (float)(((double)workEnergyPerTick / 50000.0 - 10.0) * 270.0 / (double)(Configs.ConfigMaxChargePower - 30) + 10.0);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIStationWindow), "OnStationIdChange")]
		public static void UIStationWindow_OnStationIdChange_Postfix(ref UIStationWindow __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && __instance.factory != null && __instance.stationId != 0)
			{
				StationComponent val = __instance.transport.stationPool[__instance.stationId];
				if (IsValidStellarStation(val))
				{
					long workEnergyPerTick = __instance.powerSystem.consumerPool[val.pcId].workEnergyPerTick;
					__instance.maxChargePowerSlider.Set(ComputeSliderValue(workEnergyPerTick), false);
				}
			}
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(UIControlPanelStationInspector), "OnStationIdChange")]
		public static void UIControlPanelStationInspector_OnStationIdChange_Postfix(ref UIControlPanelStationInspector __instance)
		{
			StationComponent val = __instance.transport.stationPool[__instance.stationId];
			if (IsValidStellarStation(val))
			{
				long workEnergyPerTick = __instance.powerSystem.consumerPool[val.pcId].workEnergyPerTick;
				__instance.maxChargePowerSlider.Set(ComputeSliderValue(workEnergyPerTick), false);
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "StationChargeBoost";

		public const string PLUGIN_NAME = "StationChargeBoost";

		public const string PLUGIN_VERSION = "0.0.2";
	}
}