Decompiled source of RopeSwingingMod v0.6.3

Rope Swing Mod.dll

Decompiled 3 weeks ago
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Rope Swing Mod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Rope Swing Mod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("2ed9ebbe-f95c-429b-9ed7-975d295ad4f9")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("com.lamia.ropeswing", "RopeSwing", "0.6.3")]
public class RopeSwing : BaseUnityPlugin
{
	internal static ConfigEntry<float> BaseSwingForce;

	internal static ConfigEntry<float> JointAngularZLimit;

	internal static ConfigEntry<float> RopeMass;

	internal static ConfigEntry<float> SegmentYouAreOnRopeMass;

	internal static ConfigEntry<float> RopeLengthSpeedMultiplierPerSegment;

	internal static ConfigEntry<KeyCode> SwingForward;

	internal static ConfigEntry<KeyCode> SwingBackwards;

	internal static ConfigEntry<KeyCode> SwingLeft;

	internal static ConfigEntry<KeyCode> SwingRight;

	internal static ManualLogSource Log;

	private void Awake()
	{
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0027: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		Log.LogInfo((object)"RopeSwing loaded.");
		Harmony val = new Harmony("com.lamia.ropeswing");
		val.PatchAll();
		SwingForward = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("RopeSwing", "FlyKey", (KeyCode)304, "Key to activate swinging forward.");
		SwingBackwards = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("RopeSwing", "SwingBackwards", (KeyCode)306, "Key to activate swinging backwards.");
		SwingLeft = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("RopeSwing", "SwingLeft", (KeyCode)97, "Key to activate swinging left.");
		SwingRight = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("RopeSwing", "SwingRight", (KeyCode)100, "Key to activate swinging right.");
		BaseSwingForce = ((BaseUnityPlugin)this).Config.Bind<float>("RopeSwing", "BaseForce", 7.5f, "Base force applied when swinging forward/backward/sideways.");
		JointAngularZLimit = ((BaseUnityPlugin)this).Config.Bind<float>("RopeSwing", "JointAngularZLimit", 25f, "The Joint restrictions on ropes.");
		RopeMass = ((BaseUnityPlugin)this).Config.Bind<float>("RopeSwing", "RopeMass", 0.15f, "The mass of every rope segment.");
		SegmentYouAreOnRopeMass = ((BaseUnityPlugin)this).Config.Bind<float>("RopeSwing", "SegmentYouAreOnRopeMass", 0.35f, "The mass of the rope segment you are currently touching. This should be higher than the normal ropes mass.");
		RopeLengthSpeedMultiplierPerSegment = ((BaseUnityPlugin)this).Config.Bind<float>("RopeSwing", "RopeLengthSpeedMultiplierPerSegment", 0.35f, "How much will the speed multiplier increase with each segment of the rope.");
	}
}
[HarmonyPatch(typeof(Character), "Awake")]
public static class RopeSwingMod
{
	[HarmonyPostfix]
	public static void AwakePatch(Character __instance)
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		if (__instance.IsLocal && (Object)((Component)__instance).GetComponent<RopeSwingPatch>() == (Object)null)
		{
			((Component)__instance).gameObject.AddComponent<RopeSwingPatch>();
			RopeSwing.Log.LogInfo((object)("RopeSwingPatch added to: " + ((Object)__instance).name));
		}
	}
}
[HarmonyPatch(typeof(CharacterRopeHandling), "Update")]
internal class Patch_CharacterRopeHandling_Update_SetMaxAngle
{
	private static void Prefix(CharacterRopeHandling __instance)
	{
		__instance.maxRopeAngle = 150f;
	}
}
public class RopeSwingPatch : MonoBehaviourPun
{
	private Character character;

	private CharacterMovement charMovement;

	private bool jumpedOff = false;

	private void Start()
	{
		character = ((Component)this).GetComponent<Character>();
		charMovement = ((Component)this).GetComponent<CharacterMovement>();
	}

	private void Update()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0094: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: 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_00e8: 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_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_0106: 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)
		//IL_0121: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_013a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0152: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_0155: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: 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_0253: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0275: Unknown result type (might be due to invalid IL or missing references)
		//IL_027a: Unknown result type (might be due to invalid IL or missing references)
		//IL_028c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0291: Unknown result type (might be due to invalid IL or missing references)
		//IL_0367: Unknown result type (might be due to invalid IL or missing references)
		//IL_036d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0396: Unknown result type (might be due to invalid IL or missing references)
		if (!character.IsLocal || !character.data.isRopeClimbing)
		{
			return;
		}
		jumpedOff = true;
		if (!Input.GetKey(RopeSwing.SwingForward.Value) && !Input.GetKey(RopeSwing.SwingBackwards.Value) && !Input.GetKey(RopeSwing.SwingLeft.Value) && !Input.GetKey(RopeSwing.SwingRight.Value))
		{
			return;
		}
		Vector3 val = character.data.lookDirection_Flat;
		if (Input.GetKey(RopeSwing.SwingForward.Value))
		{
			val *= RopeSwing.BaseSwingForce.Value;
		}
		else if (Input.GetKey(RopeSwing.SwingBackwards.Value))
		{
			val *= 0f - RopeSwing.BaseSwingForce.Value;
		}
		Vector3 val2 = Vector3.Cross(Vector3.up, character.data.lookDirection_Flat);
		Vector3 val3 = ((Vector3)(ref val2)).normalized * RopeSwing.BaseSwingForce.Value;
		if (Input.GetKey(RopeSwing.SwingRight.Value))
		{
			val += val3;
		}
		if (Input.GetKey(RopeSwing.SwingLeft.Value))
		{
			val -= val3;
		}
		List<Transform> ropeSegments = character.data.heldRope.GetRopeSegments();
		Rigidbody component = ((Component)((Component)character.data.heldRope).gameObject.GetComponent<RopeClimbingAPI>().GetSegmentFromPercent(character.data.ropePercent)).GetComponent<Rigidbody>();
		bool flag = false;
		foreach (Transform item in ropeSegments)
		{
			float num = 1f;
			Rigidbody component2 = ((Component)item).GetComponent<Rigidbody>();
			if ((Object)(object)component2 != (Object)null)
			{
				component2.isKinematic = false;
				component2.useGravity = true;
				component2.maxAngularVelocity = 0.1f;
				component2.maxLinearVelocity = 55f;
				component2.mass = RopeSwing.RopeMass.Value;
				ConfigurableJoint component3 = ((Component)item).GetComponent<ConfigurableJoint>();
				component3.angularZMotion = (ConfigurableJointMotion)1;
				SoftJointLimit angularZLimit = default(SoftJointLimit);
				((SoftJointLimit)(ref angularZLimit)).limit = RopeSwing.JointAngularZLimit.Value;
				component3.angularZLimit = angularZLimit;
				if (!flag)
				{
					component2.AddForce(val / 4f * num + Vector3.down * (RopeSwing.BaseSwingForce.Value * num), (ForceMode)0);
				}
				component2.interpolation = (RigidbodyInterpolation)1;
				component2.solverIterations = 20;
				component2.solverVelocityIterations = 20;
				if (((object)component2).Equals((object?)component))
				{
					flag = true;
				}
				num += RopeSwing.RopeLengthSpeedMultiplierPerSegment.Value;
			}
			else
			{
				RopeSwing.Log.LogInfo((object)("[RopeMod] Segment " + ((object)component2)?.ToString() + " has no Rigidbody. Cannot apply physics effects."));
			}
		}
		if (!((Object)(object)component != (Object)null))
		{
			return;
		}
		foreach (Bodypart part in character.refs.ragdoll.partList)
		{
			part.AddForce(val * 0.5f, (ForceMode)0);
		}
		component.AddForce(val, (ForceMode)0);
		component.mass = RopeSwing.SegmentYouAreOnRopeMass.Value;
		RopeSwing.Log.LogInfo((object)("[RopeMod] Segment " + (object)component));
	}
}