Decompiled source of PillarSkip v1.1.0

PillarSkip.dll

Decompiled 9 hours ago
using System;
using System.Collections;
using System.Diagnostics;
using System.IO;
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 EntityStates;
using EntityStates.Missions.Moon;
using EntityStates.MoonElevator;
using Microsoft.CodeAnalysis;
using RoR2;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PillarSkip")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PillarSkip")]
[assembly: AssemblyTitle("PillarSkip")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 PillarSkip
{
	[BepInPlugin("com.you.pillarskip", "PillarSkip", "1.1.0")]
	public class PillarSkipPlugin : BaseUnityPlugin
	{
		public const string Guid = "com.you.pillarskip";

		public const string Name = "PillarSkip";

		public const string Version = "1.1.0";

		private static readonly FieldInfo ElevatorsField = typeof(MoonBatteryMissionController).GetField("elevatorStateMachines", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo BatteriesField = typeof(MoonBatteryMissionController).GetField("batteryStateMachines", BindingFlags.Instance | BindingFlags.NonPublic);

		private ConfigEntry<bool> enabledConfig;

		private ConfigEntry<bool> disablePillarsConfig;

		private void Awake()
		{
			enabledConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Open the moon elevators at the start of Commencement without charging the pillars.");
			disablePillarsConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisablePillars", true, "Also switch the pillars off so they can't be started.");
			Stage.onStageStartGlobal += OnStageStart;
		}

		private void OnDestroy()
		{
			Stage.onStageStartGlobal -= OnStageStart;
		}

		private void OnStageStart(Stage stage)
		{
			if (enabledConfig.Value && NetworkServer.active)
			{
				SceneDef sceneDefForCurrentScene = SceneCatalog.GetSceneDefForCurrentScene();
				string text = ((sceneDefForCurrentScene != null) ? sceneDefForCurrentScene.baseSceneName : null);
				if (!(text != "moon2") || !(text != "moon"))
				{
					((MonoBehaviour)this).StartCoroutine(ReadyElevators());
				}
			}
		}

		private IEnumerator ReadyElevators()
		{
			float timeout = 10f;
			while (!Object.op_Implicit((Object)(object)MoonBatteryMissionController.instance) && timeout > 0f)
			{
				timeout -= Time.deltaTime;
				yield return null;
			}
			MoonBatteryMissionController controller = MoonBatteryMissionController.instance;
			if (!Object.op_Implicit((Object)(object)controller))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"MoonBatteryMissionController not found; nothing to do.");
				yield break;
			}
			yield return (object)new WaitForSeconds(0.5f);
			if (!NetworkServer.active || !Object.op_Implicit((Object)(object)controller))
			{
				yield break;
			}
			EntityStateMachine[] elevators = (EntityStateMachine[])ElevatorsField?.GetValue(controller);
			if (elevators == null)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Could not read elevatorStateMachines; game version may have changed.");
				yield break;
			}
			EntityStateMachine[] array = elevators;
			foreach (EntityStateMachine esm in array)
			{
				if (Object.op_Implicit((Object)(object)esm))
				{
					esm.SetNextState((EntityState)new InactiveToReady());
				}
			}
			if (disablePillarsConfig.Value)
			{
				EntityStateMachine[] batteries = (EntityStateMachine[])BatteriesField?.GetValue(controller);
				if (batteries != null)
				{
					EntityStateMachine[] array2 = batteries;
					foreach (EntityStateMachine esm2 in array2)
					{
						if (Object.op_Implicit((Object)(object)esm2) && !(esm2.state is MoonBatteryComplete))
						{
							esm2.SetNextState((EntityState)new MoonBatteryDisabled());
						}
					}
				}
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Moon elevators readied.");
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
}