Decompiled source of ToggleAim v1.0.2

BepInEx/plugins/ToggleAim.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
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+0ed067ba7ab2652c4f8177cb2e1a2a8a71790816")]
[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("sparroh.toggleaim", "ToggleAim", "1.0.2")]
[MycoMod(/*Could not decode attribute arguments.*/)]
public class AimTogglePlugin : BaseUnityPlugin
{
	public const string PluginGUID = "sparroh.toggleaim";

	public const string PluginName = "ToggleAim";

	public const string PluginVersion = "1.0.2";

	internal static ConfigEntry<bool> enableToggle;

	internal static bool isAimToggled;

	internal static InputAction aimAction;

	private void Awake()
	{
		//IL_00d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_0100: Unknown result type (might be due to invalid IL or missing references)
		//IL_0113: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Expected O, but got Unknown
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0182: Unknown result type (might be due to invalid IL or missing references)
		//IL_0190: Expected O, but got Unknown
		//IL_01a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_01ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c8: Expected O, but got Unknown
		//IL_01e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_01f5: Unknown result type (might be due to invalid IL or missing references)
		//IL_0202: Expected O, but got Unknown
		//IL_022e: Unknown result type (might be due to invalid IL or missing references)
		//IL_023b: 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.lastPressedAimTimeField = AccessTools.Field(typeof(Gun), "lastPressedAimTime");
		AimPatches.lastPressedFireTimeField = AccessTools.Field(typeof(Gun), "lastPressedFireTime");
		AimPatches.playerField = AccessTools.Field(typeof(Gun), "player");
		AimPatches.isAimingGetter = AccessTools.PropertyGetter(typeof(Gun), "IsAiming");
		AimPatches.wantsToFireGetter = AccessTools.PropertyGetter(typeof(Gun), "WantsToFire");
		AimPatches.lastFireTimeGetter = AccessTools.PropertyGetter(typeof(Gun), "LastFireTime");
		Harmony val = new Harmony("sparroh.toggleaim");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ToggleAim loaded successfully.");
		MethodInfo methodInfo = AccessTools.Method(typeof(PlayerInput), "Initialize", (Type[])null, (Type[])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);
		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);
		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);
		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);
		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);
		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)
		{
			_ = (bool)isAimInputHeldField.GetValue(__instance);
			isAimInputHeldField.SetValue(__instance, AimTogglePlugin.isAimToggled);
			if (AimTogglePlugin.isAimToggled)
			{
				lastPressedAimTimeField.SetValue(__instance, Time.time);
			}
		}
	}

	public static void UpdatePostfix(Gun __instance)
	{
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		if (AimTogglePlugin.enableToggle.Value)
		{
			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;
	}
}
[CompilerGenerated]
[ExcludeFromCodeCoverage]
internal static class GitVersionInformation
{
	public const string AssemblySemFileVer = "0.0.1.0";

	public const string AssemblySemVer = "0.0.1.0";

	public const string BranchName = "master";

	public const string BuildMetaData = "";

	public const string CommitDate = "2025-10-17";

	public const string CommitsSinceVersionSource = "1";

	public const string EscapedBranchName = "master";

	public const string FullBuildMetaData = "Branch.master.Sha.0ed067ba7ab2652c4f8177cb2e1a2a8a71790816";

	public const string FullSemVer = "0.0.1-1";

	public const string InformationalVersion = "0.0.1-1+Branch.master.Sha.0ed067ba7ab2652c4f8177cb2e1a2a8a71790816";

	public const string Major = "0";

	public const string MajorMinorPatch = "0.0.1";

	public const string Minor = "0";

	public const string Patch = "1";

	public const string PreReleaseLabel = "";

	public const string PreReleaseLabelWithDash = "";

	public const string PreReleaseNumber = "1";

	public const string PreReleaseTag = "1";

	public const string PreReleaseTagWithDash = "-1";

	public const string SemVer = "0.0.1-1";

	public const string Sha = "0ed067ba7ab2652c4f8177cb2e1a2a8a71790816";

	public const string ShortSha = "0ed067b";

	public const string UncommittedChanges = "12";

	public const string VersionSourceSha = "";

	public const string WeightedPreReleaseNumber = "55001";
}
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)
		{
		}
	}
}