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 Agents;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using GTFO.API.Utilities;
using GameData;
using HarmonyLib;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
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("SprintReloadCancel")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+03abdeaaa296c87fd848075276a3990b9961708e")]
[assembly: AssemblyProduct("SprintReloadCancel")]
[assembly: AssemblyTitle("SprintReloadCancel")]
[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 SprintReloadCancel
{
internal static class Configuration
{
public static bool sprintCancelEnabled = true;
public static bool aimCancelEnabled = false;
public static bool shootCancelEnabled = false;
public static bool swapBuffer = true;
private static ConfigFile configFile;
internal static void Init()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
//IL_001a: Expected O, but got Unknown
//IL_003b: Unknown result type (might be due to invalid IL or missing references)
//IL_0045: Expected O, but got Unknown
configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "SprintReloadCancel.cfg"), true);
BindAll(configFile);
LiveEdit.CreateListener(Paths.ConfigPath, "SprintReloadCancel.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
}
private static void OnFileChanged(LiveEditEventArgs _)
{
configFile.Reload();
sprintCancelEnabled = (bool)configFile["Base Settings", "Sprint to Reload Cancel"].BoxedValue;
aimCancelEnabled = (bool)configFile["Base Settings", "Aim to Reload Cancel"].BoxedValue;
shootCancelEnabled = (bool)configFile["Base Settings", "Shoot to Reload Cancel"].BoxedValue;
swapBuffer = (bool)configFile["Base Settings", "Reload Cancel Swap Buffer"].BoxedValue;
}
private static void BindAll(ConfigFile config)
{
sprintCancelEnabled = config.Bind<bool>("Base Settings", "Sprint to Reload Cancel", sprintCancelEnabled, "Sprinting will cancel reloads.").Value;
aimCancelEnabled = config.Bind<bool>("Base Settings", "Aim to Reload Cancel", aimCancelEnabled, "Aiming will cancel reloads.").Value;
shootCancelEnabled = config.Bind<bool>("Base Settings", "Shoot to Reload Cancel", shootCancelEnabled, "Shooting will cancel reloads.").Value;
swapBuffer = config.Bind<bool>("Base Settings", "Reload Cancel Swap Buffer", swapBuffer, "After a reload cancel, buffers swap inputs until the next possible time.\nThis can mitigate missed inputs when you attempt to swap weapons right after reload canceling.").Value;
}
}
[BepInPlugin("Dinorush.SprintReloadCancel", "SprintReloadCancel", "1.3.3")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
internal sealed class EntryPoint : BasePlugin
{
public const string MODNAME = "SprintReloadCancel";
public override void Load()
{
//IL_0015: Unknown result type (might be due to invalid IL or missing references)
((BasePlugin)this).Log.LogMessage((object)"Loading SprintReloadCancel");
new Harmony("SprintReloadCancel").PatchAll(typeof(ReloadCancelPatches));
Configuration.Init();
((BasePlugin)this).Log.LogMessage((object)"Loaded SprintReloadCancel");
}
}
internal static class ReloadCancelPatches
{
[CompilerGenerated]
private sealed class <SwapBack>d__8 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PlayerAgent owner;
public InventorySlot slot;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SwapBack>d__8(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_0040: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<>2__current = null;
<>1__state = 1;
return true;
case 1:
{
<>1__state = -1;
PlayerAgent obj = owner;
if (obj != null)
{
obj.Sync.WantsToWieldSlot(slot, false);
}
if (Configuration.swapBuffer)
{
CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(SwapBuffer(owner)), (Action)null);
}
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();
}
}
[CompilerGenerated]
private sealed class <SwapBuffer>d__9 : IEnumerator<object>, IEnumerator, IDisposable
{
private int <>1__state;
private object <>2__current;
public PlayerAgent owner;
private float <endTime>5__2;
private InventorySlot <bufferedSlot>5__3;
private bool <bufferedPush>5__4;
object IEnumerator<object>.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
object IEnumerator.Current
{
[DebuggerHidden]
get
{
return <>2__current;
}
}
[DebuggerHidden]
public <SwapBuffer>d__9(int <>1__state)
{
this.<>1__state = <>1__state;
}
[DebuggerHidden]
void IDisposable.Dispose()
{
<>1__state = -2;
}
private bool MoveNext()
{
//IL_002d: Unknown result type (might be due to invalid IL or missing references)
//IL_0111: Unknown result type (might be due to invalid IL or missing references)
//IL_0117: Invalid comparison between Unknown and I4
//IL_0134: Unknown result type (might be due to invalid IL or missing references)
//IL_0147: Unknown result type (might be due to invalid IL or missing references)
//IL_005a: Unknown result type (might be due to invalid IL or missing references)
//IL_0065: Unknown result type (might be due to invalid IL or missing references)
//IL_0074: Unknown result type (might be due to invalid IL or missing references)
//IL_0079: Unknown result type (might be due to invalid IL or missing references)
//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
switch (<>1__state)
{
default:
return false;
case 0:
<>1__state = -1;
<endTime>5__2 = Clock.Time + 0.2f;
<bufferedSlot>5__3 = (InventorySlot)0;
<bufferedPush>5__4 = false;
break;
case 1:
<>1__state = -1;
break;
}
if (Clock.Time < <endTime>5__2 && (Object)(object)owner != (Object)null)
{
foreach (KeyValuePair<InputAction, InventorySlot> swapAction in SwapActions)
{
if (InputMapper.GetButtonDown.Invoke(swapAction.Key, owner.InputFilter))
{
<bufferedSlot>5__3 = swapAction.Value;
<bufferedPush>5__4 = false;
}
}
if (InputMapper.GetButtonDown.Invoke((InputAction)12, owner.InputFilter))
{
<bufferedPush>5__4 = true;
}
<>2__current = null;
<>1__state = 1;
return true;
}
if ((Object)(object)owner != (Object)null && (int)((PlayerInventoryBase)owner.FPItemHolder.m_inventoryLocal).WieldedSlot != 8)
{
if (<bufferedPush>5__4)
{
owner.FPItemHolder.MeleeAttackShortcut();
}
else if ((int)<bufferedSlot>5__3 != 0)
{
owner.Sync.WantsToWieldSlot(<bufferedSlot>5__3, false);
}
}
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 const float SwapTime = 0.2f;
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
}
};
private static float _reloadEndTime = 0f;
private static bool _aimWasDown = false;
[HarmonyPatch(typeof(PLOC_Stand), "Update")]
[HarmonyPatch(typeof(PLOC_Crouch), "Update")]
[HarmonyPatch(typeof(PLOC_Jump), "Update")]
[HarmonyPatch(typeof(PLOC_Fall), "Update")]
[HarmonyWrapSafe]
[HarmonyPrefix]
private static void ReloadCancelStand(PLOC_Stand __instance)
{
AttemptReloadCancel((PLOC_Base)(object)__instance);
}
[HarmonyPatch(typeof(ItemEquippable), "TryTriggerReloadAnimationSequence")]
[HarmonyWrapSafe]
[HarmonyPostfix]
public static void TrackReloadTime(ItemEquippable __instance, bool __result)
{
if (!__result || (Object)(object)((Item)__instance).Owner == (Object)null || !((Agent)((Item)__instance).Owner).IsLocallyOwned)
{
return;
}
GearFrontPartDataBlock frontData = __instance.GearPartHolder.FrontData;
List<WeaponAnimSequenceItem> obj = ((((frontData == null) ? null : frontData.ReloadSequence?.Count).GetValueOrDefault() > 0) ? __instance.GearPartHolder.FrontData.ReloadSequence : __instance.GearPartHolder.StockData.ReloadSequence);
float triggerTime = obj[obj.Count - 1].TriggerTime;
float num = __instance.ReloadTime / triggerTime;
float num2 = 0f;
Enumerator<WeaponAnimSequenceItem> enumerator = obj.GetEnumerator();
while (enumerator.MoveNext())
{
WeaponAnimSequenceItem current = enumerator.Current;
if (current.TriggerTime > num2)
{
num2 = current.TriggerTime;
}
}
_reloadEndTime = Clock.Time + num2 * num;
}
private static void AttemptReloadCancel(PLOC_Base ploc)
{
//IL_0017: Unknown result type (might be due to invalid IL or missing references)
//IL_008b: Unknown result type (might be due to invalid IL or missing references)
//IL_0090: Unknown result type (might be due to invalid IL or missing references)
//IL_009d: Unknown result type (might be due to invalid IL or missing references)
PlayerAgent owner = ploc.m_owner;
if (((Agent)owner).IsLocallyOwned)
{
bool num = InputMapper.GetButton.Invoke((InputAction)7, owner.InputFilter);
bool aimDown = num && !_aimWasDown;
_aimWasDown = num;
FirstPersonItemHolder fPItemHolder = owner.FPItemHolder;
bool? obj;
if (fPItemHolder == null)
{
obj = null;
}
else
{
ItemEquippable wieldedItem = fPItemHolder.WieldedItem;
obj = ((wieldedItem != null) ? new bool?(!wieldedItem.IsReloading) : null);
}
bool? flag = obj;
if (!flag.GetValueOrDefault(true) && ShouldCancel(owner, aimDown))
{
InventorySlot wieldedSlot = ((PlayerInventoryBase)owner.FPItemHolder.m_inventoryLocal).WieldedSlot;
owner.FPItemHolder.MeleeAttackShortcut();
CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(SwapBack(owner, wieldedSlot)), (Action)null);
}
}
}
private static bool ShouldCancel(PlayerAgent owner, bool aimDown)
{
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//IL_0051: Unknown result type (might be due to invalid IL or missing references)
if (!Configuration.sprintCancelEnabled || !InputMapper.GetButtonDown.Invoke((InputAction)9, owner.InputFilter) || !owner.Locomotion.InputIsForwardEnoughForRun())
{
if (_reloadEndTime - 0.2f > Clock.Time)
{
if (!(Configuration.aimCancelEnabled && aimDown))
{
if (Configuration.shootCancelEnabled)
{
return InputMapper.GetButtonDown.Invoke((InputAction)8, owner.InputFilter);
}
return false;
}
return true;
}
return false;
}
return true;
}
[IteratorStateMachine(typeof(<SwapBack>d__8))]
private static IEnumerator SwapBack(PlayerAgent owner, InventorySlot slot)
{
//IL_000e: Unknown result type (might be due to invalid IL or missing references)
//IL_000f: Unknown result type (might be due to invalid IL or missing references)
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SwapBack>d__8(0)
{
owner = owner,
slot = slot
};
}
[IteratorStateMachine(typeof(<SwapBuffer>d__9))]
private static IEnumerator SwapBuffer(PlayerAgent? owner)
{
//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
return new <SwapBuffer>d__9(0)
{
owner = owner
};
}
}
}