Decompiled source of GtfoSkipDrop v4.0.0

GTFO.SkipDrop.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using HarmonyLib;
using Microsoft.CodeAnalysis;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("GTFO.SkipDrop")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+e39315c62aa1652bcbaf8e3df803121fea88b941")]
[assembly: AssemblyProduct("GTFO.SkipDrop")]
[assembly: AssemblyTitle("GTFO.SkipDrop")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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;
		}
	}
	[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 GTFO.SkipDrop
{
	[BepInPlugin("MindAttic.GTFO.SkipDrop", "GTFO.SkipDrop", "4.0.0")]
	[BepInProcess("GTFO.exe")]
	public class Plugin : BasePlugin
	{
		public const string GUID = "MindAttic.GTFO.SkipDrop";

		public const string NAME = "GTFO.SkipDrop";

		public const string VERSION = "4.0.0";

		private static readonly (string Field, float Value)[] RideTimings = new(string, float)[3]
		{
			("m_startDelay", 0f),
			("m_engineStartDelay", 0f),
			("m_endDur", 0.1f)
		};

		private static ManualLogSource _log = null;

		private static MethodInfo _skipPreRelease = null;

		private static PropertyInfo _fastElevator = null;

		private static PropertyInfo _minTimeLooping = null;

		private static PropertyInfo _current = null;

		private static readonly List<PropertyInfo> _rideTimings = new List<PropertyInfo>();

		private static object? _savedFastElevator;

		private static readonly Stopwatch _dropTimer = new Stopwatch();

		private static double _phaseStart;

		private static string? _phase;

		public override void Load()
		{
			//IL_0153: Unknown result type (might be due to invalid IL or missing references)
			//IL_0158: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0178: Expected O, but got Unknown
			//IL_0179: Unknown result type (might be due to invalid IL or missing references)
			//IL_018b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0199: Expected O, but got Unknown
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ba: Expected O, but got Unknown
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Expected O, but got Unknown
			//IL_01e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Expected O, but got Unknown
			_log = ((BasePlugin)this).Log;
			Type type = AccessTools.TypeByName("ElevatorRide");
			MethodInfo methodInfo = AccessTools.Method(type, "StartPreReleaseSequence", (Type[])null, (Type[])null);
			MethodInfo methodInfo2 = AccessTools.Method(type, "StartElevatorRide", (Type[])null, (Type[])null);
			MethodInfo methodInfo3 = AccessTools.Method(type, "StopElevatorRide", (Type[])null, (Type[])null);
			MethodInfo methodInfo4 = AccessTools.Method(type, "ChangeState", (Type[])null, (Type[])null);
			_skipPreRelease = AccessTools.Method(type, "SkipPreReleaseSequence", (Type[])null, (Type[])null);
			_minTimeLooping = AccessTools.Property(type, "MinTimeLooping");
			_current = AccessTools.Property(type, "Current");
			_fastElevator = AccessTools.Property(AccessTools.TypeByName("Globals.Global"), "FastElevator");
			(string, float)[] rideTimings = RideTimings;
			for (int i = 0; i < rideTimings.Length; i++)
			{
				string item = rideTimings[i].Item1;
				_rideTimings.Add(AccessTools.Property(type, item));
			}
			if (new object[8] { methodInfo, methodInfo2, methodInfo3, methodInfo4, _skipPreRelease, _minTimeLooping, _fastElevator, _current }.Concat(_rideTimings).Any((object m) => m == null))
			{
				((BasePlugin)this).Log.LogError((object)"Elevator members not found - game update? Drop will not be skipped.");
				return;
			}
			Harmony val = new Harmony("MindAttic.GTFO.SkipDrop");
			val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "SkipPreRelease", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(Plugin), "SpeedUpDrop", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)methodInfo3, (HarmonyMethod)null, new HarmonyMethod(typeof(Plugin), "RestoreAfterDrop", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			val.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(Plugin), "LogPhase", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
			ManualLogSource log = ((BasePlugin)this).Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(10, 2, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("GTFO.SkipDrop");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" v");
				((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<string>("4.0.0");
				((BepInExLogInterpolatedStringHandler)val2).AppendLiteral(" loaded.");
			}
			log.LogInfo(val2);
		}

		private static void SkipPreRelease()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			try
			{
				_skipPreRelease.Invoke(null, null);
			}
			catch (Exception ex)
			{
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(37, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't skip the opening animation: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void SpeedUpDrop()
		{
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e6: Expected O, but got Unknown
			_dropTimer.Restart();
			_phaseStart = 0.0;
			_phase = null;
			try
			{
				if (_savedFastElevator == null)
				{
					_savedFastElevator = _fastElevator.GetValue(null);
				}
				_fastElevator.SetValue(null, true);
				_minTimeLooping.SetValue(null, Convert.ChangeType(0, _minTimeLooping.PropertyType));
				object value = _current.GetValue(null);
				if (value == null)
				{
					_log.LogWarning((object)"ElevatorRide.Current is null - ride delays not cut.");
					return;
				}
				for (int i = 0; i < RideTimings.Length; i++)
				{
					_rideTimings[i].SetValue(value, Convert.ChangeType(RideTimings[i].Value, _rideTimings[i].PropertyType));
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = _log;
				bool flag = default(bool);
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(48, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't speed up the drop, leaving it vanilla: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
		}

		private static void LogPhase(object __0)
		{
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Expected O, but got Unknown
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Expected O, but got Unknown
			if (!_dropTimer.IsRunning)
			{
				return;
			}
			bool flag = default(bool);
			try
			{
				double totalSeconds = _dropTimer.Elapsed.TotalSeconds;
				if (_phase != null)
				{
					ManualLogSource log = _log;
					BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(14, 2, ref flag);
					if (flag)
					{
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Drop phase ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>(_phase);
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral(": ");
						((BepInExLogInterpolatedStringHandler)val).AppendFormatted<double>(totalSeconds - _phaseStart, "0.0");
						((BepInExLogInterpolatedStringHandler)val).AppendLiteral("s");
					}
					log.LogInfo(val);
				}
				_phase = __0?.ToString();
				_phaseStart = totalSeconds;
			}
			catch (Exception ex)
			{
				ManualLogSource log2 = _log;
				BepInExErrorLogInterpolatedStringHandler val2 = new BepInExErrorLogInterpolatedStringHandler(25, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Couldn't log drop phase: ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<Exception>(ex);
				}
				log2.LogError(val2);
			}
		}

		private static void RestoreAfterDrop()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Expected O, but got Unknown
			bool flag = default(bool);
			try
			{
				if (_savedFastElevator != null)
				{
					_fastElevator.SetValue(null, _savedFastElevator);
				}
			}
			catch (Exception ex)
			{
				ManualLogSource log = _log;
				BepInExErrorLogInterpolatedStringHandler val = new BepInExErrorLogInterpolatedStringHandler(31, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Couldn't restore FastElevator: ");
					((BepInExLogInterpolatedStringHandler)val).AppendFormatted<Exception>(ex);
				}
				log.LogError(val);
			}
			_savedFastElevator = null;
			if (_dropTimer.IsRunning)
			{
				ManualLogSource log2 = _log;
				BepInExInfoLogInterpolatedStringHandler val2 = new BepInExInfoLogInterpolatedStringHandler(12, 1, ref flag);
				if (flag)
				{
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("Drop took ");
					((BepInExLogInterpolatedStringHandler)val2).AppendFormatted<double>(_dropTimer.Elapsed.TotalSeconds, "0.0");
					((BepInExLogInterpolatedStringHandler)val2).AppendLiteral("s.");
				}
				log2.LogInfo(val2);
			}
			_dropTimer.Reset();
		}
	}
}