Decompiled source of TwoHandedLadders v1.0.1

TwoHandedLadders.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 TwoHandedLadders
{
	[BepInPlugin("com.khameli0n.twohandedladders", "TwoHandedLadders", "1.0.1")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.khameli0n.twohandedladders";

		public const string PLUGIN_NAME = "TwoHandedLadders";

		public const string PLUGIN_VERSION = "1.0.1";

		public const string PLUGIN_AUTHOR = "Khameli0n";

		private Harmony harmony;

		public static Plugin Instance { get; private set; }

		public static ManualLogSource Log { get; private set; }

		private void Awake()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			Instance = this;
			Log = ((BaseUnityPlugin)this).Logger;
			try
			{
				harmony = new Harmony("com.khameli0n.twohandedladders");
				harmony.PatchAll();
				Log.LogInfo((object)"TwoHandedLadders v1.0.1 by Khameli0n loaded successfully! 2-handed ladder climbing enabled.");
			}
			catch (Exception arg)
			{
				Log.LogError((object)string.Format("Failed to patch {0}: {1}", "TwoHandedLadders", arg));
			}
		}

		private void OnDestroy()
		{
			Harmony obj = harmony;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
		}
	}
}
namespace TwoHandedLadders.Patches
{
	public static class LadderManager
	{
		public static readonly HashSet<InteractTrigger> RegisteredLadders = new HashSet<InteractTrigger>();

		public static void Register(InteractTrigger trigger)
		{
			if ((Object)(object)trigger != (Object)null && trigger.isLadder)
			{
				trigger.twoHandedItemAllowed = true;
				trigger.oneHandedItemAllowed = true;
				RegisteredLadders.Add(trigger);
			}
		}

		public static void Unregister(InteractTrigger trigger)
		{
			if ((Object)(object)trigger != (Object)null)
			{
				RegisteredLadders.Remove(trigger);
			}
		}

		public static InteractTrigger GetNearestLadder(Vector3 playerPos, float maxDistance = 1.6f)
		{
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			InteractTrigger result = null;
			float num = maxDistance * maxDistance;
			foreach (InteractTrigger registeredLadder in RegisteredLadders)
			{
				if ((Object)(object)registeredLadder == (Object)null || !((Component)registeredLadder).gameObject.activeInHierarchy || !registeredLadder.isLadder)
				{
					continue;
				}
				Vector3 val = (((Object)(object)registeredLadder.bottomOfLadderPosition != (Object)null) ? registeredLadder.bottomOfLadderPosition.position : ((Component)registeredLadder).transform.position);
				Vector3 val2 = (((Object)(object)registeredLadder.topOfLadderPosition != (Object)null) ? registeredLadder.topOfLadderPosition.position : (val + Vector3.up * 4f));
				float num2 = Mathf.Min(val.y, val2.y) - 0.75f;
				float num3 = Mathf.Max(val.y, val2.y) + 1.25f;
				if (!(playerPos.y < num2) && !(playerPos.y > num3))
				{
					float num4 = playerPos.x - val.x;
					float num5 = playerPos.z - val.z;
					float num6 = num4 * num4 + num5 * num5;
					if (num6 < num)
					{
						num = num6;
						result = registeredLadder;
					}
				}
			}
			return result;
		}
	}
	[HarmonyPatch(typeof(InteractTrigger))]
	public static class InteractTriggerPatches
	{
		[HarmonyPatch("Start")]
		[HarmonyPostfix]
		public static void Start_Postfix(InteractTrigger __instance)
		{
			if ((Object)(object)__instance != (Object)null && __instance.isLadder)
			{
				LadderManager.Register(__instance);
			}
		}

		[HarmonyPatch("OnEnable")]
		[HarmonyPostfix]
		public static void OnEnable_Postfix(InteractTrigger __instance)
		{
			if ((Object)(object)__instance != (Object)null && __instance.isLadder)
			{
				LadderManager.Register(__instance);
			}
		}

		[HarmonyPatch("OnDisable")]
		[HarmonyPostfix]
		public static void OnDisable_Postfix(InteractTrigger __instance)
		{
			LadderManager.Unregister(__instance);
		}

		[HarmonyPatch("OnDestroy")]
		[HarmonyPostfix]
		public static void OnDestroy_Postfix(InteractTrigger __instance)
		{
			LadderManager.Unregister(__instance);
		}

		[HarmonyPatch("Interact")]
		[HarmonyPrefix]
		public static void Interact_Prefix(InteractTrigger __instance)
		{
			if ((Object)(object)__instance != (Object)null && __instance.isLadder)
			{
				__instance.twoHandedItemAllowed = true;
				__instance.oneHandedItemAllowed = true;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	public static class PlayerControllerLadderPatches
	{
		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		public static void Update_Postfix(PlayerControllerB __instance)
		{
			//IL_01a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_0157: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0175: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_017f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0187: Unknown result type (might be due to invalid IL or missing references)
			//IL_018e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_01db: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ee: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0057: Unknown result type (might be due to invalid IL or missing references)
			//IL_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0225: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ba: Unknown result type (might be due to invalid IL or missing references)
			//IL_02bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_0282: Unknown result type (might be due to invalid IL or missing references)
			//IL_023b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_024a: Unknown result type (might be due to invalid IL or missing references)
			//IL_024f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0259: Unknown result type (might be due to invalid IL or missing references)
			//IL_025e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0272: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_0102: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Unknown result type (might be due to invalid IL or missing references)
			//IL_011a: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance == (Object)null || ((Object)(object)GameNetworkManager.Instance != (Object)null && (Object)(object)__instance != (Object)(object)GameNetworkManager.Instance.localPlayerController) || __instance.isPlayerDead || __instance.inSpecialMenu || __instance.inTerminalMenu || __instance.isClimbingLadder)
			{
				return;
			}
			Vector3 position = ((Component)__instance).transform.position;
			InteractTrigger nearestLadder = LadderManager.GetNearestLadder(position, 1.55f);
			if (!((Object)(object)nearestLadder != (Object)null))
			{
				return;
			}
			nearestLadder.twoHandedItemAllowed = true;
			nearestLadder.oneHandedItemAllowed = true;
			Vector3 val = (((Object)(object)nearestLadder.bottomOfLadderPosition != (Object)null) ? nearestLadder.bottomOfLadderPosition.position : ((Component)nearestLadder).transform.position);
			Vector3 val2 = (((Object)(object)nearestLadder.topOfLadderPosition != (Object)null) ? nearestLadder.topOfLadderPosition.position : (val + Vector3.up * 4f));
			float num = Mathf.Max(val.y, val2.y);
			float num2 = Mathf.Min(val.y, val2.y);
			Vector2 moveInputVector = __instance.moveInputVector;
			bool flag = false;
			try
			{
				int num3;
				if (__instance.playerActions != null)
				{
					MovementActions movement = __instance.playerActions.Movement;
					if (((MovementActions)(ref movement)).Jump.triggered)
					{
						num3 = 1;
						goto IL_0146;
					}
				}
				num3 = ((Keyboard.current != null && ((ButtonControl)Keyboard.current.spaceKey).wasPressedThisFrame) ? 1 : 0);
				goto IL_0146;
				IL_0146:
				flag = (byte)num3 != 0;
			}
			catch
			{
			}
			if (flag)
			{
				Vector3 val3 = -((Component)__instance).transform.forward * 4f + Vector3.up * 3f;
				__instance.thisController.Move(val3 * Time.deltaTime);
				__instance.fallValue = -2.5f;
			}
			else if (Mathf.Abs(moveInputVector.y) > 0.1f)
			{
				float num4 = (((Object)(object)__instance.gameplayCamera != (Object)null) ? ((Component)__instance.gameplayCamera).transform.forward.y : 0f);
				float num5 = 0f;
				num5 = ((!(moveInputVector.y > 0f)) ? (-1f) : ((num4 >= -0.28f) ? 1f : (-1f)));
				if (num5 > 0f && position.y >= num - 0.35f)
				{
					Vector3 val4 = (((Component)__instance).transform.forward + Vector3.up * 0.35f) * 3.5f;
					__instance.thisController.Move(val4 * Time.deltaTime);
				}
				else if (!(num5 < 0f) || !(position.y <= num2 + 0.15f))
				{
					float num6 = 4.5f;
					Vector3 val5 = Vector3.up * (num5 * num6);
					__instance.thisController.Move(val5 * Time.deltaTime);
					__instance.fallValue = 0f;
					__instance.fallValueUncapped = 0f;
					__instance.isFallingFromJump = false;
					__instance.isFallingNoJump = false;
				}
			}
			else if (position.y > num2 + 0.3f && position.y < num + 0.5f)
			{
				__instance.fallValue = 0f;
				__instance.fallValueUncapped = 0f;
			}
		}

		[HarmonyPatch("SetHoverTipAndCurrentInteractTrigger")]
		[HarmonyPostfix]
		public static void SetHoverTip_Postfix(PlayerControllerB __instance)
		{
			if ((Object)(object)__instance == (Object)null || (Object)(object)__instance.hoveringOverTrigger == (Object)null || !__instance.hoveringOverTrigger.isLadder)
			{
				return;
			}
			__instance.hoveringOverTrigger.twoHandedItemAllowed = true;
			__instance.hoveringOverTrigger.oneHandedItemAllowed = true;
			if ((Object)(object)__instance.cursorTip != (Object)null)
			{
				string text = ((TMP_Text)__instance.cursorTip).text;
				if (string.IsNullOrEmpty(text) || text.Contains("Hands full") || text.Contains("full"))
				{
					((TMP_Text)__instance.cursorTip).text = "Climb : [E]";
				}
			}
			if ((Object)(object)__instance.cursorIcon != (Object)null && !((Behaviour)__instance.cursorIcon).enabled)
			{
				((Behaviour)__instance.cursorIcon).enabled = true;
				if ((Object)(object)__instance.hoveringOverTrigger.hoverIcon != (Object)null)
				{
					__instance.cursorIcon.sprite = __instance.hoveringOverTrigger.hoverIcon;
				}
			}
		}

		[HarmonyPatch("Interact_performed")]
		[HarmonyPrefix]
		public static void Interact_performed_Prefix(PlayerControllerB __instance, ref bool __state)
		{
			__state = false;
			if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.hoveringOverTrigger != (Object)null && __instance.hoveringOverTrigger.isLadder)
			{
				__instance.hoveringOverTrigger.twoHandedItemAllowed = true;
				__instance.hoveringOverTrigger.oneHandedItemAllowed = true;
				__instance.hoveringOverTrigger.specialCharacterAnimation = false;
				if (__instance.twoHanded)
				{
					__state = true;
					__instance.twoHanded = false;
				}
			}
		}

		[HarmonyPatch("Interact_performed")]
		[HarmonyPostfix]
		public static void Interact_performed_Postfix(PlayerControllerB __instance, bool __state)
		{
			if ((Object)(object)__instance != (Object)null)
			{
				if ((Object)(object)__instance.hoveringOverTrigger != (Object)null && __instance.hoveringOverTrigger.isLadder)
				{
					__instance.hoveringOverTrigger.specialCharacterAnimation = true;
				}
				if (__state)
				{
					__instance.twoHanded = true;
				}
			}
		}

		[HarmonyPatch("ClickHoldInteraction")]
		[HarmonyPrefix]
		public static void ClickHoldInteraction_Prefix(PlayerControllerB __instance)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)__instance.hoveringOverTrigger != (Object)null && __instance.hoveringOverTrigger.isLadder)
			{
				__instance.hoveringOverTrigger.twoHandedItemAllowed = true;
				__instance.hoveringOverTrigger.oneHandedItemAllowed = true;
			}
		}
	}
}