Decompiled source of BurstActionBuffer v1.1.0

BurstActionBuffer.dll

Decompiled 2 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using GTFO.API.Utilities;
using Gear;
using HarmonyLib;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("BurstActionBuffer")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("BurstActionBuffer")]
[assembly: AssemblyTitle("BurstActionBuffer")]
[assembly: AssemblyVersion("1.0.0.0")]
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 BurstActionBuffer
{
	[HarmonyPatch]
	internal static class BurstPatches
	{
		private enum BufferAction
		{
			None,
			Reload,
			Swap,
			Push
		}

		[CompilerGenerated]
		private sealed class <SwapBuffer>d__7 : IEnumerator<object>, IEnumerator, IDisposable
		{
			private int <>1__state;

			private object <>2__current;

			public PlayerAgent owner;

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

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

			[DebuggerHidden]
			public <SwapBuffer>d__7(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_0064: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
				switch (<>1__state)
				{
				default:
					return false;
				case 0:
					<>1__state = -1;
					break;
				case 1:
					<>1__state = -1;
					break;
				}
				if ((Object)(object)owner != (Object)null)
				{
					if (InputMapper.GetButtonDown.Invoke((InputAction)11, owner.InputFilter))
					{
						_bufferAction = BufferAction.Reload;
						_bufferTime = Clock.Time;
					}
					foreach (KeyValuePair<InputAction, InventorySlot> swapAction in SwapActions)
					{
						if (InputMapper.GetButtonDown.Invoke(swapAction.Key, owner.InputFilter))
						{
							_bufferSwapSlot = swapAction.Value;
							_bufferAction = BufferAction.Swap;
							_bufferTime = Clock.Time;
						}
					}
					if (InputMapper.GetButtonDown.Invoke((InputAction)12, owner.InputFilter))
					{
						_bufferAction = BufferAction.Push;
						_bufferTime = Clock.Time;
					}
					<>2__current = null;
					<>1__state = 1;
					return true;
				}
				ClearBuffer();
				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 static Coroutine? _bufferRoutine;

		private static InventorySlot _bufferSwapSlot;

		private static BufferAction _bufferAction;

		private static float _bufferTime;

		private static readonly Dictionary<InputAction, InventorySlot> SwapActions = new Dictionary<InputAction, InventorySlot>
		{
			{
				(InputAction)23,
				(InventorySlot)1
			},
			{
				(InputAction)24,
				(InventorySlot)2
			},
			{
				(InputAction)25,
				(InventorySlot)3
			},
			{
				(InputAction)26,
				(InventorySlot)10
			},
			{
				(InputAction)28,
				(InventorySlot)5
			},
			{
				(InputAction)29,
				(InventorySlot)11
			},
			{
				(InputAction)27,
				(InventorySlot)4
			}
		};

		[HarmonyPatch(typeof(BWA_Burst), "OnStartFiring")]
		[HarmonyPostfix]
		private static void Post_StartBurstFire(BWA_Burst __instance)
		{
			_bufferRoutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(SwapBuffer(((BulletWeaponArchetype)__instance).m_owner)), (Action)null);
		}

		[IteratorStateMachine(typeof(<SwapBuffer>d__7))]
		private static IEnumerator SwapBuffer(PlayerAgent? owner)
		{
			//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
			return new <SwapBuffer>d__7(0)
			{
				owner = owner
			};
		}

		[HarmonyPatch(typeof(BWA_Burst), "OnStopFiring")]
		[HarmonyPostfix]
		private static void Post_EndBurstFire(BWA_Burst __instance)
		{
			TryBufferedAction(__instance);
			ClearBuffer();
		}

		private static void TryBufferedAction(BWA_Burst __instance)
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Invalid comparison between Unknown and I4
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			if (Clock.Time - _bufferTime > Configuration.BufferTime)
			{
				return;
			}
			PlayerAgent owner = ((BulletWeaponArchetype)__instance).m_owner;
			if ((Object)(object)owner == (Object)null)
			{
				return;
			}
			FirstPersonItemHolder fPItemHolder = owner.FPItemHolder;
			if ((Object)(object)fPItemHolder.WieldedItem != (Object)(object)((BulletWeaponArchetype)__instance).m_weapon)
			{
				return;
			}
			PlayerInventoryBase inventory = owner.Inventory;
			switch (_bufferAction)
			{
			case BufferAction.Reload:
				if (!fPItemHolder.ItemIsBusy && inventory.CanReloadCurrent())
				{
					inventory.TriggerReload();
				}
				break;
			case BufferAction.Swap:
				if ((int)inventory.WieldedSlot != 8 && inventory.WieldedSlot != _bufferSwapSlot)
				{
					owner.Sync.WantsToWieldSlot(_bufferSwapSlot, false);
				}
				break;
			case BufferAction.Push:
				fPItemHolder.MeleeAttackShortcut();
				break;
			}
		}

		private static void ClearBuffer()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			_bufferAction = BufferAction.None;
			_bufferSwapSlot = (InventorySlot)0;
			_bufferTime = 0f;
			if (_bufferRoutine != null)
			{
				CoroutineManager.StopCoroutine(_bufferRoutine);
			}
			_bufferRoutine = null;
		}
	}
	internal static class Configuration
	{
		private static ConfigEntry<float> _bufferTime;

		public static float BufferTime => _bufferTime.Value;

		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Expected O, but got Unknown
			ConfigFile config = new ConfigFile(Path.Combine(Paths.ConfigPath, "BurstActionBuffer.cfg"), true);
			_bufferTime = config.Bind<float>("Base Settings", "Buffer Time", 0.5f, "Maximum allowed time between buffering an action and finishing the burst.");
			LiveEdit.CreateListener(Paths.ConfigPath, "BurstActionBuffer.cfg", false).FileChanged += (LiveEditEventHandler)delegate
			{
				config.Reload();
			};
		}
	}
	internal static class DinoLogger
	{
		private static ManualLogSource logger = Logger.CreateLogSource("BurstActionBuffer");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	[BepInPlugin("Dinorush.BurstActionBuffer", "BurstActionBuffer", "1.0.0")]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "BurstActionBuffer";

		public override void Load()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			Configuration.Init();
			new Harmony("BurstActionBuffer").PatchAll();
			((BasePlugin)this).Log.LogMessage((object)"Loaded BurstActionBuffer");
		}
	}
}