Decompiled source of ScuttleFix v1.0.0

ScuttleFix.dll

Decompiled a month ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;

[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ScuttleFix;

public static class PluginInfo
{
	public const string PLUGIN_GUID = "com.scuttlefix.noregrabpenalty";

	public const string PLUGIN_NAME = "ScuttleFix";

	public const string PLUGIN_VERSION = "1.0.0";
}
[BepInPlugin("com.scuttlefix.noregrabpenalty", "ScuttleFix", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log;

	internal static ConfigEntry<bool> RemoveHigherRegrabCost;

	internal static bool SuppressNextStartClimbStamina;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		RemoveHigherRegrabCost = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RemoveHigherRegrabCost", true, "Remove the extra stamina hit when you let go and re-grab higher (missed scuttle). Does not change normal climb drain.");
		try
		{
			_harmony = new Harmony("com.scuttlefix.noregrabpenalty");
			_harmony.PatchAll(typeof(Plugin).Assembly);
			Log.LogInfo((object)"ScuttleFix v1.0.0 loaded.");
		}
		catch (Exception ex)
		{
			Log.LogError((object)("Failed to load: " + ex));
		}
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch]
public static class StartClimbRpc_Patch
{
	private static MethodBase TargetMethod()
	{
		Type type = AccessTools.TypeByName("CharacterClimbing");
		return (!(type == null)) ? AccessTools.Method(type, "StartClimbRpc", (Type[])null, (Type[])null) : null;
	}

	private static void Prefix()
	{
		Plugin.SuppressNextStartClimbStamina = Plugin.RemoveHigherRegrabCost != null && Plugin.RemoveHigherRegrabCost.Value;
	}

	private static void Postfix()
	{
		Plugin.SuppressNextStartClimbStamina = false;
	}
}
[HarmonyPatch]
public static class UseStamina_Patch
{
	private static MethodBase TargetMethod()
	{
		Type type = AccessTools.TypeByName("Character");
		if (type == null)
		{
			return null;
		}
		return AccessTools.Method(type, "UseStamina", (Type[])null, (Type[])null);
	}

	private static void Prefix(ref float __0)
	{
		if (Plugin.SuppressNextStartClimbStamina)
		{
			__0 = 0f;
		}
	}
}