Decompiled source of HarpoonReelIn v1.0.0

plugins\HarpoonReelIn.dll

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

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace HarpoonReelIn;

[BepInPlugin("com.kaden.harpoonreelin", "HarpoonReelIn", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	public const string PluginGUID = "com.kaden.harpoonreelin";

	public const string PluginName = "HarpoonReelIn";

	public const string PluginVersion = "1.0.0";

	public static ConfigEntry<KeyboardShortcut> ReelKey;

	public static ConfigEntry<float> ReelSpeed;

	public static ConfigEntry<float> StaminaDrainPerSecond;

	public static ConfigEntry<float> MinDistance;

	private Harmony _harmony;

	private void Awake()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Expected O, but got Unknown
		//IL_009c: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Expected O, but got Unknown
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e4: Expected O, but got Unknown
		ReelKey = ((BaseUnityPlugin)this).Config.Bind<KeyboardShortcut>("Reel In", "ReelKey", new KeyboardShortcut((KeyCode)304, (KeyCode[])(object)new KeyCode[0]), "Key to hold to reel in a harpooned target.");
		ReelSpeed = ((BaseUnityPlugin)this).Config.Bind<float>("Reel In", "ReelSpeed", 4f, new ConfigDescription("How fast the tether shortens (meters per second).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 20f), new object[0]));
		StaminaDrainPerSecond = ((BaseUnityPlugin)this).Config.Bind<float>("Reel In", "StaminaDrainPerSecond", 5f, new ConfigDescription("Extra stamina drained per second while reeling.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 50f), new object[0]));
		MinDistance = ((BaseUnityPlugin)this).Config.Bind<float>("Reel In", "MinDistance", 3f, new ConfigDescription("Minimum tether distance — target won't be pulled closer than this.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 15f), new object[0]));
		_harmony = Harmony.CreateAndPatchAll(typeof(ReelInPatch), "com.kaden.harpoonreelin");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"HarpoonReelIn v1.0.0 loaded.");
	}

	private void OnDestroy()
	{
		if (_harmony != null)
		{
			_harmony.UnpatchSelf();
		}
	}
}
[HarmonyPatch(typeof(SE_Harpooned), "UpdateStatusEffect")]
public static class ReelInPatch
{
	private static void Postfix(SE_Harpooned __instance, float dt, Character ___m_attacker, ref float ___m_baseDistance, bool ___m_broken)
	{
		if (___m_broken || (Object)(object)___m_attacker == (Object)null || (Object)(object)Player.m_localPlayer == (Object)null || (Object)(object)___m_attacker != (Object)(object)Player.m_localPlayer || !IsReelKeyHeld())
		{
			return;
		}
		Player localPlayer = Player.m_localPlayer;
		float num = Plugin.StaminaDrainPerSecond.Value * dt;
		if (!(num > 0f) || ((Character)localPlayer).HaveStamina(num))
		{
			if (num > 0f)
			{
				((Character)localPlayer).UseStamina(num);
			}
			float num2 = Plugin.ReelSpeed.Value * dt;
			float value = Plugin.MinDistance.Value;
			___m_baseDistance = Mathf.Max(___m_baseDistance - num2, value);
		}
	}

	private static bool IsReelKeyHeld()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		KeyboardShortcut value = Plugin.ReelKey.Value;
		if (((KeyboardShortcut)(ref value)).IsPressed())
		{
			return true;
		}
		return false;
	}
}