Decompiled source of QuickPunches v1.1.0

QuickPunches.dll

Decompiled 2 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Reflection.Emit;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Configgy;
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: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("QuickPunches")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QuickPunches")]
[assembly: AssemblyTitle("QuickPunches")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace QuickPunches;

[BepInPlugin("quickpunches.ultranoob.ultrakill", "QuickPunches", "1.1.0")]
public class QuickPunches : BaseUnityPlugin
{
	private Harmony harmony;

	public static ConfigBuilder ConfigMenu;

	[Configgable("Settings", "Enable Mod", 0, "Enable or disable the mod.")]
	public static bool modEnabled = true;

	[Configgable("Settings", "No Stamina Cost", 1, "Disable stamina consumption when punching.")]
	public static bool noStaminaCost = false;

	[Configgable("Settings", "Punch Animation Speed", 2, "Punch animation speed: 1 to 10 (10x faster).")]
	[Range(1f, 10f)]
	public static int punchAnimationSpeed = 1;

	[Configgable("Settings", "Stamina Regen Speed", 3, "Stamina regeneration speed: 1 to 10 (10x faster).")]
	[Range(1f, 10f)]
	public static int staminaRegenSpeed = 1;

	public static float GetCooldownFactor()
	{
		return modEnabled ? (1f / (float)staminaRegenSpeed) : 1f;
	}

	public static float GetStaminaCostFactor()
	{
		if (!modEnabled)
		{
			return 0.5f;
		}
		if (noStaminaCost)
		{
			return 0f;
		}
		return 0.5f * GetCooldownFactor();
	}

	public static float GetAnimationFactor()
	{
		return modEnabled ? ((float)punchAnimationSpeed) : 1f;
	}

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Expected O, but got Unknown
		harmony = new Harmony("quickpunches.ultranoob.ultrakill");
		harmony.PatchAll();
		ConfigMenu = new ConfigBuilder("quickpunches.ultranoob.ultrakill", "QuickPunches");
		ConfigMenu.BuildType(typeof(QuickPunches));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"QuickPunches mod loaded!");
	}
}
[HarmonyPatch(typeof(Punch), "PunchStart")]
public static class Punch_PunchStart_Patch
{
	private static float storedStamina;

	private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
	{
		MethodInfo getCooldownFactorMethod = AccessTools.Method(typeof(QuickPunches), "GetCooldownFactor", (Type[])null, (Type[])null);
		MethodInfo getStaminaCostFactorMethod = AccessTools.Method(typeof(QuickPunches), "GetStaminaCostFactor", (Type[])null, (Type[])null);
		float f = default(float);
		foreach (CodeInstruction instruction in instructions)
		{
			int num;
			if (instruction.opcode == OpCodes.Ldc_R4)
			{
				object operand = instruction.operand;
				if (operand is float)
				{
					f = (float)operand;
					num = 1;
				}
				else
				{
					num = 0;
				}
			}
			else
			{
				num = 0;
			}
			if (num != 0)
			{
				if (Mathf.Approximately(f, 0.25f))
				{
					yield return new CodeInstruction(OpCodes.Call, (object)getCooldownFactorMethod);
					yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.25f);
					yield return new CodeInstruction(OpCodes.Mul, (object)null);
					continue;
				}
				if (Mathf.Approximately(f, 0.5f))
				{
					yield return new CodeInstruction(OpCodes.Call, (object)getStaminaCostFactorMethod);
					yield return new CodeInstruction(OpCodes.Ldc_R4, (object)0.5f);
					yield return new CodeInstruction(OpCodes.Mul, (object)null);
					continue;
				}
			}
			yield return instruction;
		}
	}

	private static void Prefix(Punch __instance)
	{
		if (QuickPunches.modEnabled && QuickPunches.noStaminaCost)
		{
			storedStamina = MonoSingleton<WeaponCharges>.Instance.punchStamina;
		}
	}

	private static void Postfix(Punch __instance)
	{
		if (QuickPunches.modEnabled && QuickPunches.noStaminaCost)
		{
			MonoSingleton<WeaponCharges>.Instance.punchStamina = storedStamina;
		}
		float animationFactor = QuickPunches.GetAnimationFactor();
		if ((Object)(object)__instance.anim != (Object)null)
		{
			__instance.anim.speed = animationFactor;
		}
	}
}
[HarmonyPatch(typeof(WeaponCharges), "Update")]
public static class WeaponCharges_Update_Patch
{
	private static void Postfix(WeaponCharges __instance)
	{
		if (QuickPunches.modEnabled)
		{
			__instance.punchStamina = Mathf.MoveTowards(__instance.punchStamina, 2f, Time.deltaTime * (float)QuickPunches.staminaRegenSpeed);
		}
	}
}