Decompiled source of MoreEfficientChargingStation v1.0.1

plugins/yazirushi-MoreEfficientChargingStation/MoreEfficientChargingStation.dll

Decompiled 2 months ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
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("MoreEfficientChargingStation")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreEfficientChargingStation")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("fb73a4de-ee3c-435a-9712-e558bfdb6cae")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace MoreEfficientChargingStation;

[BepInPlugin("yazirushi.MoreEfficientChargingStation", "More Efficient ChargingStation", "1.0.1")]
public class MoreEfficientChargingStation : BaseUnityPlugin
{
	private readonly Harmony harmony = new Harmony("yazirushi.MoreEfficientChargingStation");

	internal static ManualLogSource mls;

	public static ConfigEntry<float> Multiplier;

	public static ConfigEntry<bool> EnableEnergyCrystalPriceAdjustment;

	public static ConfigEntry<bool> EnableLogging;

	private void Awake()
	{
		Multiplier = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "Multiplier", 2f, "長持ちする倍率。値が大きいほど長持ちします");
		EnableEnergyCrystalPriceAdjustment = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "EnableEnergyCrystalPriceAdjustment", true, "エナジークリスタルの価格調整の有効化");
		EnableLogging = ((BaseUnityPlugin)this).Config.Bind<bool>("ConsoleLog", "EnableLogging", false, "ログの有効化");
		mls = ((BaseUnityPlugin)this).Logger;
		mls.LogInfo((object)"MoreEfficientChargingStationが起動しました!");
		mls.LogInfo((object)$"MoreEfficientChargingStation:Multiplier = {Multiplier.Value:F2}");
		mls.LogInfo((object)$"MoreEfficientChargingStation:EnableEnergyCrystalPriceAdjustment = {EnableEnergyCrystalPriceAdjustment.Value}");
		mls.LogInfo((object)$"MoreEfficientChargingStation:EnableLogging = {EnableLogging.Value}");
		harmony.PatchAll();
	}
}
[HarmonyPatch(typeof(ChargingStation), "Start")]
public class Patch_ChargingStation
{
	private static void Postfix(ChargingStation __instance)
	{
		FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeRate");
		float value = MoreEfficientChargingStation.Multiplier.Value;
		value = Mathf.Max(value, 0.01f);
		float num = (float)fieldInfo.GetValue(__instance);
		float num2 = num / value;
		fieldInfo.SetValue(__instance, num2);
		if (MoreEfficientChargingStation.EnableLogging.Value)
		{
			MoreEfficientChargingStation.mls.LogInfo((object)$"MoreEfficientChargingStation config Multiplier:{value:F2}");
			MoreEfficientChargingStation.mls.LogInfo((object)$"MoreEfficientChargingStation chargeRate Original:{num},Result:{num2}");
		}
	}
}
[HarmonyPatch(typeof(ShopManager), "CrystalValueGet")]
public class CrystalValuePatch
{
	private static void Postfix(ref float __result)
	{
		if (MoreEfficientChargingStation.EnableEnergyCrystalPriceAdjustment.Value)
		{
			float value = MoreEfficientChargingStation.Multiplier.Value;
			float num = __result;
			value = Mathf.Max(value, 0.01f);
			__result *= value;
			__result = Mathf.Ceil(__result);
			__result = Mathf.Max(__result, 1f);
			if (MoreEfficientChargingStation.EnableLogging.Value)
			{
				MoreEfficientChargingStation.mls.LogInfo((object)$"MoreEfficientChargingStation config Multiplier:{value:F2}");
				MoreEfficientChargingStation.mls.LogInfo((object)$"MoreEfficientChargingStation price Original:{num},Result:{__result}");
			}
		}
		else if (MoreEfficientChargingStation.EnableLogging.Value)
		{
			MoreEfficientChargingStation.mls.LogInfo((object)"MoreEfficientChargingStation CrystalValuePatch skip");
		}
	}
}