Decompiled source of BetaEnergyCrystals v1.6.0

BetaEnergyCrystals/BetaEnergyCrystals.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("BetaRevive")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("BetaRevive")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e18e20df-9b8c-4dd3-8bab-7ccaaca633f0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("Xero.betaenergycrystals", "Beta Energy Crystals", "1.6.0")]
public class Plugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <PeriodicChargeReset>d__9 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public Plugin <>4__this;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <PeriodicChargeReset>d__9(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			int num = <>1__state;
			Plugin plugin = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				break;
			case 1:
			{
				<>1__state = -1;
				plugin.forceMaxCharge = true;
				ChargingStation[] array = Object.FindObjectsOfType<ChargingStation>();
				foreach (ChargingStation fullCharge in array)
				{
					plugin.SetFullCharge(fullCharge);
				}
				plugin.forceMaxCharge = false;
				break;
			}
			}
			if (plugin.pluginEnabled.Value)
			{
				<>2__current = (object)new WaitForSeconds(plugin.resetIntervalSeconds.Value);
				<>1__state = 1;
				return true;
			}
			return false;
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private readonly Harmony harmony = new Harmony("Xero.betaenergycrystals");

	internal ConfigEntry<bool> pluginEnabled;

	internal ConfigEntry<float> resetIntervalSeconds;

	private bool forceMaxCharge = true;

	public static Plugin Instance { get; private set; }

	public void Awake()
	{
		Instance = this;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Beta Energy Crystals loaded.");
		pluginEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Settings", "EnablePlugin", true, "Activa o desactiva el plugin.");
		resetIntervalSeconds = ((BaseUnityPlugin)this).Config.Bind<float>("Settings", "ResetIntervalSeconds", 60f, "Tiempo en segundos para reiniciar la carga.");
		harmony.PatchAll(typeof(ChargingStationPatches));
		harmony.PatchAll(typeof(ChargingStationUpdatePatch));
		harmony.PatchAll(typeof(PreventShutdownPatch));
		harmony.PatchAll(typeof(PreventCrystalDestructionPatch));
		if (pluginEnabled.Value)
		{
			((MonoBehaviour)this).StartCoroutine(PeriodicChargeReset());
		}
	}

	[IteratorStateMachine(typeof(<PeriodicChargeReset>d__9))]
	private IEnumerator PeriodicChargeReset()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <PeriodicChargeReset>d__9(0)
		{
			<>4__this = this
		};
	}

	public void SetFullCharge(ChargingStation station)
	{
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeInt");
		FieldInfo fieldInfo2 = AccessTools.Field(typeof(ChargingStation), "chargeTotal");
		FieldInfo fieldInfo3 = AccessTools.Field(typeof(ChargingStation), "chargeFloat");
		FieldInfo fieldInfo4 = AccessTools.Field(typeof(ChargingStation), "chargeBar");
		FieldInfo fieldInfo5 = AccessTools.Field(typeof(ChargingStation), "chargeSegmentCurrent");
		FieldInfo fieldInfo6 = AccessTools.Field(typeof(ChargingStation), "chargeSegments");
		List<Transform> list = (List<Transform>)AccessTools.Field(typeof(ChargingStation), "crystals").GetValue(station);
		fieldInfo.SetValue(station, list.Count);
		if (fieldInfo2.FieldType == typeof(float))
		{
			fieldInfo2.SetValue(station, 100f);
		}
		else
		{
			fieldInfo2.SetValue(station, 100);
		}
		fieldInfo3.SetValue(station, 1f);
		int num = (int)fieldInfo6.GetValue(station);
		fieldInfo5.SetValue(station, num);
		Transform val = (Transform)fieldInfo4.GetValue(station);
		if ((Object)(object)val != (Object)null)
		{
			val.localScale = new Vector3(1f, 1f, 1f);
		}
	}

	public bool ShouldForceMaxCharge()
	{
		if (pluginEnabled.Value)
		{
			return forceMaxCharge;
		}
		return false;
	}
}
[HarmonyPatch(typeof(ChargingStation))]
internal class ChargingStationPatches
{
	[HarmonyPostfix]
	[HarmonyPatch("Start")]
	private static void PostfixStart(ChargingStation __instance)
	{
		if (Plugin.Instance.pluginEnabled.Value)
		{
			Plugin.Instance.SetFullCharge(__instance);
		}
	}
}
[HarmonyPatch(typeof(ChargingStation))]
internal class ChargingStationUpdatePatch
{
	[HarmonyPrefix]
	[HarmonyPatch("Update")]
	private static bool PrefixUpdate(ChargingStation __instance)
	{
		if (Plugin.Instance.ShouldForceMaxCharge())
		{
			FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeInt");
			FieldInfo fieldInfo2 = AccessTools.Field(typeof(ChargingStation), "chargeTotal");
			FieldInfo fieldInfo3 = AccessTools.Field(typeof(ChargingStation), "chargeFloat");
			FieldInfo fieldInfo4 = AccessTools.Field(typeof(ChargingStation), "chargeSegmentCurrent");
			FieldInfo fieldInfo5 = AccessTools.Field(typeof(ChargingStation), "chargeSegments");
			List<Transform> list = (List<Transform>)AccessTools.Field(typeof(ChargingStation), "crystals").GetValue(__instance);
			fieldInfo.SetValue(__instance, list.Count);
			if (fieldInfo2.FieldType == typeof(float))
			{
				fieldInfo2.SetValue(__instance, 100f);
			}
			else
			{
				fieldInfo2.SetValue(__instance, 100);
			}
			fieldInfo3.SetValue(__instance, 1f);
			int num = (int)fieldInfo5.GetValue(__instance);
			fieldInfo4.SetValue(__instance, num);
			return false;
		}
		return true;
	}
}
[HarmonyPatch(typeof(ChargingStation))]
internal class PreventShutdownPatch
{
	[HarmonyPrefix]
	[HarmonyPatch("OutOfCrystalsShutdown")]
	private static bool PrefixOutOfCrystalsShutdown()
	{
		return !Plugin.Instance.pluginEnabled.Value;
	}
}
[HarmonyPatch(typeof(ChargingStation))]
internal class PreventCrystalDestructionPatch
{
	[HarmonyPrefix]
	[HarmonyPatch("UpdateChargeBarRPC")]
	private static bool PrefixUpdateChargeBarRPC(ChargingStation __instance, int segmentPassed)
	{
		if (!Plugin.Instance.pluginEnabled.Value)
		{
			return true;
		}
		FieldInfo fieldInfo = AccessTools.Field(typeof(ChargingStation), "chargeSegmentPrevious");
		FieldInfo fieldInfo2 = AccessTools.Field(typeof(ChargingStation), "chargeSegmentCurrent");
		FieldInfo fieldInfo3 = AccessTools.Field(typeof(ChargingStation), "chargeCurveTime");
		fieldInfo.SetValue(__instance, fieldInfo2.GetValue(__instance));
		fieldInfo2.SetValue(__instance, segmentPassed);
		fieldInfo3.SetValue(__instance, 0f);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch("DestroyCrystal")]
	private static bool PrefixDestroyCrystal()
	{
		return !Plugin.Instance.pluginEnabled.Value;
	}
}