Decompiled source of RoundStartEnergyReset v1.3.0

RoundStartEnergyReset.dll

Decompiled 21 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.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 RoundStartEnergyReset
{
	[BepInPlugin("SisyphusMods.RoundStartEnergyReset", "RoundStartEnergyReset", "1.2.0")]
	public class RoundStartEnergyReset : BaseUnityPlugin
	{
		internal static RoundStartEnergyReset Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)"================================");
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			Logger.LogInfo((object)"================================");
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
			Logger.LogInfo((object)"[RoundStartEnergyReset] Harmony patches applied");
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}
namespace RoundStartEnergyReset.Patches
{
	[HarmonyPatch(typeof(ChargingStation))]
	internal static class ChargingStationPatch
	{
		[HarmonyPrefix]
		[HarmonyPatch("Start")]
		private static void OnStart(ChargingStation __instance)
		{
			__instance.chargeTotal = 100;
			RoundStartEnergyReset.Logger.LogInfo((object)"[RoundStartEnergyReset] ChargingStation.Start() - chargeTotal set to 100 (full)");
		}
	}
	[HarmonyPatch(typeof(GameDirector))]
	internal static class GameDirectorPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("SetStart")]
		private static void OnRoundStart()
		{
			PlayerController instance = PlayerController.instance;
			if ((Object)(object)instance != (Object)null)
			{
				instance.EnergyCurrent = instance.EnergyStart;
				RoundStartEnergyReset.Logger.LogInfo((object)"[RoundStartEnergyReset] Stamina refilled!");
			}
			else
			{
				RoundStartEnergyReset.Logger.LogWarning((object)"[RoundStartEnergyReset] PlayerController.instance is null at SetStart");
			}
			RefillChargingStation();
		}

		private static void RefillChargingStation()
		{
			ChargingStation instance = ChargingStation.instance;
			if ((Object)(object)instance == (Object)null)
			{
				RoundStartEnergyReset.Logger.LogWarning((object)"[RoundStartEnergyReset] ChargingStation.instance is null");
				return;
			}
			instance.chargeTotal = 100;
			instance.chargeFloat = 1f;
			instance.chargeSegmentCurrent = instance.chargeSegments;
			RoundStartEnergyReset.Logger.LogInfo((object)"[RoundStartEnergyReset] Charging station refilled to max!");
		}
	}
	[HarmonyPatch(typeof(PlayerController))]
	internal static class PlayerControllerPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Start")]
		private static void OnPlayerControllerStart(PlayerController __instance)
		{
			RoundStartEnergyReset.Logger.LogInfo((object)"[RoundStartEnergyReset] PlayerController.Start() triggered");
			__instance.EnergyCurrent = __instance.EnergyStart;
			RoundStartEnergyReset.Logger.LogInfo((object)"[RoundStartEnergyReset] Player stamina set to max on controller start");
		}
	}
}