Decompiled source of MyBetterLadders v1.2.2

BetterLadders.dll

Decompiled 10 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("BetterLadders")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Alter ladder speed and allow usage with two-handed items")]
[assembly: AssemblyFileVersion("1.2.2.0")]
[assembly: AssemblyInformationalVersion("1.2.2+4e336194702dafb39ba0bcd49e40783f8d68645b")]
[assembly: AssemblyProduct("BetterLadders")]
[assembly: AssemblyTitle("BetterLadders")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.2.2.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace BetterLadders
{
	[BepInPlugin("e3s1.BetterLadders", "BetterLadders", "1.2.2")]
	public class BetterLadders : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlayerControllerB))]
		internal class PlayerControllerBPatch
		{
			[HarmonyPatch("Update")]
			[HarmonyPostfix]
			private static void LadderClimbSpeedPatch(ref bool ___isSprinting, ref float ___climbSpeed, ref bool ___isClimbingLadder, ref PlayerControllerB __instance)
			{
				if (___isClimbingLadder)
				{
					float num = ((!___isSprinting) ? (4f * Instance.configClimbSpeedMultiplier.Value) : (4f * Instance.configClimbSpeedMultiplier.Value * Instance.configClimbSprintSpeedMultiplier.Value));
					float num2 = num / 4f;
					___climbSpeed = num;
					if (Instance.configScaleAnimationSpeed.Value && __instance.playerBodyAnimator.GetFloat("animationSpeed") != 0f)
					{
						__instance.playerBodyAnimator.SetFloat("animationSpeed", num2);
					}
				}
			}

			[HarmonyPatch("Interact_performed")]
			[HarmonyPrefix]
			private static void LadderTwoHandedAccessPatch(ref InteractTrigger ___hoveringOverTrigger, ref bool ___twoHanded)
			{
				if ((Instance.configAllowTwoHanded.Value && (Object)(object)___hoveringOverTrigger != (Object)null && ___hoveringOverTrigger.isLadder) & ___twoHanded)
				{
					___hoveringOverTrigger.twoHandedItemAllowed = true;
					___hoveringOverTrigger.specialCharacterAnimation = false;
					___hoveringOverTrigger.hidePlayerItem = true;
				}
			}

			[HarmonyPatch("SetHoverTipAndCurrentInteractTrigger")]
			[HarmonyPostfix]
			private static void LadderHandsFullTipPatch(ref PlayerControllerB __instance, ref InteractTrigger ___hoveringOverTrigger, ref bool ___isHoldingInteract, ref bool ___twoHanded)
			{
				if (((Instance.configAllowTwoHanded.Value && (Object)(object)___hoveringOverTrigger != (Object)null) & ___isHoldingInteract & ___twoHanded) && ___hoveringOverTrigger.isLadder)
				{
					((TMP_Text)__instance.cursorTip).text = ___hoveringOverTrigger.hoverTip.Replace("[LMB]", "[E]");
				}
			}

			[HarmonyPatch("SwitchToItemSlot")]
			[HarmonyPostfix]
			private static void LadderHeldItemVisibilityPatch(ref PlayerControllerB __instance)
			{
				LadderItemVisibility.Set(ref __instance.isClimbingLadder);
			}
		}

		[HarmonyPatch(typeof(InteractTrigger))]
		internal class InteractTriggerPatch
		{
			[HarmonyPatch("SetUsingLadderOnLocalClient")]
			[HarmonyPostfix]
			private static void LadderHeldItemVisibilityPatch(ref bool ___usingLadder)
			{
				LadderItemVisibility.Set(ref ___usingLadder);
			}
		}

		internal static class LadderItemVisibility
		{
			public static void Set(ref bool ___usingLadder)
			{
				PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
				if (localPlayerController.isHoldingObject && ((Instance.configAllowTwoHanded.Value && Instance.configHideTwoHanded.Value && localPlayerController.twoHanded) || (Instance.configHideOneHanded.Value && !localPlayerController.twoHanded)))
				{
					localPlayerController.currentlyHeldObjectServer.EnableItemMeshes(!___usingLadder);
					((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"Held item mesh set to {!___usingLadder}");
				}
			}
		}

		private readonly Harmony harmony = new Harmony("e3s1.BetterLadders");

		public static BetterLadders Instance;

		public const string GUID = "e3s1.BetterLadders";

		public const string NAME = "BetterLadders";

		public const string VERSION = "1.2.2";

		private ConfigEntry<float> configClimbSpeedMultiplier;

		private ConfigEntry<float> configClimbSprintSpeedMultiplier;

		private ConfigEntry<bool> configAllowTwoHanded;

		private ConfigEntry<bool> configScaleAnimationSpeed;

		private ConfigEntry<bool> configHideOneHanded;

		private ConfigEntry<bool> configHideTwoHanded;

		private void Awake()
		{
			Instance = this;
			configClimbSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "climbSpeedMultipler", 1f, "Ladder climb speed multiplier");
			configClimbSprintSpeedMultiplier = ((BaseUnityPlugin)this).Config.Bind<float>("General", "sprintingClimbSpeedMultiplier", 1.25f, "Ladder climb speed multiplier while sprinting, stacks with climbSpeedMultiplier");
			configAllowTwoHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "allowTwoHanded", true, "Whether to allow using ladders while carrying a two-handed object");
			configScaleAnimationSpeed = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "scaleAnimationSpeed", true, "Whether to scale the speed of the climbing animation to the climbing speed");
			configHideOneHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "hideOneHanded", true, "Whether to hide one-handed items while climbing a ladder - false in vanilla");
			configHideTwoHanded = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "hideTwoHanded", true, "Whether to hide two-handed items while climbing a ladder");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"BetterLadders loaded!");
			harmony.PatchAll(typeof(BetterLadders));
			harmony.PatchAll(typeof(PlayerControllerBPatch));
			harmony.PatchAll(typeof(InteractTriggerPatch));
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "BetterLadders";

		public const string PLUGIN_NAME = "BetterLadders";

		public const string PLUGIN_VERSION = "1.2.2";
	}
}