using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Pigeon.Movement;
using UnityEngine;
using UnityEngine.InputSystem;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("ToggleAim")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.0.0.0")]
[assembly: AssemblyInformationalVersion("0.0.0-alpha.0")]
[assembly: AssemblyProduct("ToggleAim")]
[assembly: AssemblyTitle("ToggleAim")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.Embedded]
internal sealed class EmbeddedAttribute : Attribute
{
}
}
namespace System.Runtime.CompilerServices
{
[CompilerGenerated]
[Microsoft.CodeAnalysis.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;
}
}
}
[BepInPlugin("com.yourname.mycopunk.toggleaim", "ToggleAim", "1.0.0")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class AimTogglePlugin : BaseUnityPlugin
{
internal static ConfigEntry<bool> enableToggle;
internal static bool isAimToggled;
internal static InputAction aimAction;
private void Awake()
{
//IL_0128: Unknown result type (might be due to invalid IL or missing references)
//IL_012e: Expected O, but got Unknown
//IL_017c: Unknown result type (might be due to invalid IL or missing references)
//IL_0189: Expected O, but got Unknown
//IL_01bc: Unknown result type (might be due to invalid IL or missing references)
//IL_01ca: Expected O, but got Unknown
//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
//IL_020b: Expected O, but got Unknown
//IL_0241: Unknown result type (might be due to invalid IL or missing references)
//IL_024f: Expected O, but got Unknown
//IL_0286: Unknown result type (might be due to invalid IL or missing references)
//IL_0293: Expected O, but got Unknown
//IL_02ca: Unknown result type (might be due to invalid IL or missing references)
//IL_02d7: Expected O, but got Unknown
enableToggle = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "EnableAimToggle", true, "If true, aim becomes a toggle (press to enter/exit) instead of hold.");
AimPatches.isAimInputHeldField = AccessTools.Field(typeof(Gun), "isAimInputHeld");
_ = AimPatches.isAimInputHeldField == null;
AimPatches.lastPressedAimTimeField = AccessTools.Field(typeof(Gun), "lastPressedAimTime");
_ = AimPatches.lastPressedAimTimeField == null;
AimPatches.lastPressedFireTimeField = AccessTools.Field(typeof(Gun), "lastPressedFireTime");
_ = AimPatches.lastPressedFireTimeField == null;
AimPatches.playerField = AccessTools.Field(typeof(Gun), "player");
_ = AimPatches.playerField == null;
AimPatches.isAimingGetter = AccessTools.PropertyGetter(typeof(Gun), "IsAiming");
_ = AimPatches.isAimingGetter == null;
AimPatches.wantsToFireGetter = AccessTools.PropertyGetter(typeof(Gun), "WantsToFire");
_ = AimPatches.wantsToFireGetter == null;
AimPatches.lastFireTimeGetter = AccessTools.PropertyGetter(typeof(Gun), "LastFireTime");
_ = AimPatches.lastFireTimeGetter == null;
Harmony val = new Harmony("com.yourname.mycopunk.toggleaim");
((BaseUnityPlugin)this).Logger.LogInfo((object)(val.Id + " loaded!"));
MethodInfo methodInfo = AccessTools.Method(typeof(PlayerInput), "Initialize", (Type[])null, (Type[])null);
if (methodInfo != null)
{
val.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(AimPatches), "PlayerInputInitializePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo2 = AccessTools.Method(typeof(Gun), "OnAimInputPerformed", (Type[])null, (Type[])null);
if (methodInfo2 != null)
{
val.Patch((MethodBase)methodInfo2, new HarmonyMethod(typeof(AimPatches), "SkipPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo3 = AccessTools.Method(typeof(Gun), "OnAimInputCancelled", (Type[])null, (Type[])null);
if (methodInfo3 != null)
{
val.Patch((MethodBase)methodInfo3, new HarmonyMethod(typeof(AimPatches), "SkipPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo4 = AccessTools.Method(typeof(Gun), "HandleAim", (Type[])null, (Type[])null);
if (methodInfo4 != null)
{
val.Patch((MethodBase)methodInfo4, new HarmonyMethod(typeof(AimPatches), "HandleAimPrefix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo5 = AccessTools.Method(typeof(Gun), "Update", (Type[])null, (Type[])null);
if (methodInfo5 != null)
{
val.Patch((MethodBase)methodInfo5, (HarmonyMethod)null, new HarmonyMethod(typeof(AimPatches), "UpdatePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
MethodInfo methodInfo6 = AccessTools.Method(typeof(Player), "Resurrect_ClientRpc", (Type[])null, (Type[])null);
if (methodInfo6 != null)
{
val.Patch((MethodBase)methodInfo6, (HarmonyMethod)null, new HarmonyMethod(typeof(AimPatches), "ResetTogglePostfix", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
}
}
private void OnDestroy()
{
if (aimAction != null)
{
aimAction.started -= OnAimStarted;
}
}
internal static void OnAimStarted(CallbackContext context)
{
if (enableToggle.Value)
{
isAimToggled = !isAimToggled;
}
}
}
internal class AimPatches
{
internal static FieldInfo isAimInputHeldField;
internal static FieldInfo lastPressedAimTimeField;
internal static FieldInfo lastPressedFireTimeField;
internal static FieldInfo playerField;
internal static MethodInfo isAimingGetter;
internal static MethodInfo wantsToFireGetter;
internal static MethodInfo lastFireTimeGetter;
public static void PlayerInputInitializePostfix()
{
//IL_000c: Unknown result type (might be due to invalid IL or missing references)
//IL_0011: Unknown result type (might be due to invalid IL or missing references)
PlayerControls controls = PlayerInput.Controls;
object aimAction;
if (controls == null)
{
aimAction = null;
}
else
{
PlayerActions player = controls.Player;
aimAction = ((PlayerActions)(ref player)).Aim;
}
AimTogglePlugin.aimAction = (InputAction)aimAction;
if (AimTogglePlugin.aimAction != null && AimTogglePlugin.enableToggle.Value)
{
AimTogglePlugin.aimAction.started += AimTogglePlugin.OnAimStarted;
}
}
public static bool SkipPrefix()
{
return !AimTogglePlugin.enableToggle.Value;
}
public static void HandleAimPrefix(Gun __instance)
{
if (AimTogglePlugin.enableToggle.Value && isAimInputHeldField != null)
{
_ = (bool)isAimInputHeldField.GetValue(__instance);
isAimInputHeldField.SetValue(__instance, AimTogglePlugin.isAimToggled);
if (AimTogglePlugin.isAimToggled && lastPressedAimTimeField != null)
{
lastPressedAimTimeField.SetValue(__instance, Time.time);
}
}
}
public static void UpdatePostfix(Gun __instance)
{
//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
//IL_00b8: Expected O, but got Unknown
if (AimTogglePlugin.enableToggle.Value && isAimingGetter != null && wantsToFireGetter != null && lastFireTimeGetter != null && lastPressedFireTimeField != null && playerField != null)
{
bool flag = (bool)isAimingGetter.Invoke(__instance, null);
bool flag2 = (bool)wantsToFireGetter.Invoke(__instance, null);
float num = (float)lastFireTimeGetter.Invoke(__instance, null);
float num2 = (float)lastPressedFireTimeField.GetValue(__instance);
Player val = (Player)playerField.GetValue(__instance);
if ((Object)(object)val != (Object)null && !flag && !flag2 && Time.time - Mathf.Max(num, num2) > 0.5f)
{
val.ResumeSprint();
}
}
}
public static void ResetTogglePostfix()
{
AimTogglePlugin.isAimToggled = false;
}
}
namespace ToggleAim
{
public static class MyPluginInfo
{
public const string PLUGIN_GUID = "ToggleAim";
public const string PLUGIN_NAME = "ToggleAim";
public const string PLUGIN_VERSION = "0.0.0";
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}