Decompiled source of Run With Knives Mod v1.0.1

ValheimRunWithKnivesMod.dll

Decompiled 2 months 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 HarmonyLib;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ValheimRunWithKnivesMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ValheimRunWithKnivesMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("123504c7-f39f-4f16-b985-1bfd90f7d173")]
[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 ValheimRunWithKnivesMod;

[BepInPlugin("rocks.ghostapps.valheim.runwithknives", "Run With Knives", "1.0.1")]
[BepInProcess("valheim.exe")]
public class ValheimMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "GetRunSpeedFactor")]
	public class PlayerUpdatePatch
	{
		private static void Postfix(Player __instance, ref float __result)
		{
			ItemData rightItem = ((Humanoid)__instance).RightItem;
			if (((Character)__instance).IsRunning() && rightItem != null && rightItem.m_shared.m_name.ToLower().Contains("knife"))
			{
				Log.LogDebug((object)"Running with a knife detected, increasing run speed.");
				__result = KnifeRunSpeedMultiplier.Value;
			}
		}
	}

	private readonly Harmony harmony = new Harmony("rocks.ghostapps.valheim.runwithknives");

	public static ConfigEntry<float> KnifeRunSpeedMultiplier;

	internal static ManualLogSource Log;

	private void Awake()
	{
		KnifeRunSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "KnifeRunSpeedMultiplier", 1.5f, "Run speed multiplier when running with a knife.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Run With Knives Mod loaded!");
		Log = ((BaseUnityPlugin)this).Logger;
		harmony.PatchAll();
	}
}