Decompiled source of HoldtoAutoKnifeSlab v1.0.0

HoldtoAutoKnifeSlab.dll

Decompiled a week ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("lethaltestmod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Atlas Playbook v0.4.1")]
[assembly: AssemblyProduct("lethaltestmod")]
[assembly: AssemblyCopyright("Copyright © Atlas Playbook v0.4.1 2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e75e037d-b118-4f16-80e0-ee240e02127b")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HoldtoAutoKnifeSlab
{
	[BepInPlugin("Samnoon.HoldtoAutoKnifeSlab", "HoldtoAutoKnifeSlab", "1.1.0")]
	public class Plugin : BaseUnityPlugin
	{
		private readonly Harmony _harmony = new Harmony("Samnoon.HoldtoAutoKnifeSlab");

		public static ManualLogSource Log { get; private set; }

		public static ConfigEntry<float> AttackInterval { get; private set; }

		public void Awake()
		{
			Log = ((BaseUnityPlugin)this).Logger;
			AttackInterval = ((BaseUnityPlugin)this).Config.Bind<float>("General", "AttackInterval", 0.11f, "Knife auto-attack interval in seconds (e.g. 0.11 = 11 attacks per second).");
			Log.LogInfo((object)"Loading HoldtoAutoKnifeSlab (v1.1.0)");
			_harmony.PatchAll();
			Log.LogInfo((object)"Plugin loaded!");
		}
	}
}
namespace HoldtoAutoKnifeSlab.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatches
	{
		private static float _timeAtLastAttack;

		[HarmonyPostfix]
		[HarmonyPatch("Update")]
		internal static void ItemActivatePostfix(PlayerControllerB __instance)
		{
			GrabbableObject currentlyHeldObjectServer = __instance.currentlyHeldObjectServer;
			if ((Object)(object)currentlyHeldObjectServer != (Object)null && ((object)currentlyHeldObjectServer).GetType() == typeof(KnifeItem) && IngamePlayerSettings.Instance.playerInput.actions.FindAction("ActivateItem", false).IsPressed() && Time.realtimeSinceStartup - _timeAtLastAttack > Plugin.AttackInterval.Value)
			{
				_timeAtLastAttack = Time.realtimeSinceStartup;
				currentlyHeldObjectServer.UseItemOnClient(true);
			}
		}
	}
}