Decompiled source of Fall Velocity Fix v1.0.2

PEAK.FallFix.dll

Decompiled a month ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyCompany("PEAK.FallFix")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PEAK.FallFix")]
[assembly: AssemblyTitle("PEAK.FallFix")]
[assembly: AssemblyVersion("1.0.0.0")]
[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;
		}
	}
}
[BepInPlugin("com.tgudge.peak.fallvelocityfix", "PEAK Fall Velocity Fix", "1.0.0")]
public class FallVelocityFix : BaseUnityPlugin
{
	private const float MaxFallSpeed = -25f;

	private void Awake()
	{
		Harmony.CreateAndPatchAll(typeof(FallVelocityFix), (string)null);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"tgudge's PEAK Fall Velocity Fix Loaded");
	}

	[HarmonyPatch(typeof(CharacterMovement), "FixedUpdate")]
	[HarmonyPostfix]
	private static void CapFallSpeed(CharacterMovement __instance)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0148: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		FieldInfo field = typeof(CharacterMovement).GetField("character", BindingFlags.Instance | BindingFlags.NonPublic);
		Character val = (Character)field.GetValue(__instance);
		Type type = typeof(Object).Assembly.GetType("UnityEngine.Rigidbody");
		if (type == null)
		{
			return;
		}
		foreach (Bodypart part in val.refs.ragdoll.partList)
		{
			object obj = ((object)((object)part).GetType().GetProperty("rigidBody")) ?? ((object)((object)part).GetType().GetField("rigidBody"));
			if (obj == null)
			{
				continue;
			}
			object obj2 = ((obj is PropertyInfo propertyInfo) ? propertyInfo.GetValue(part) : ((FieldInfo)obj).GetValue(part));
			if (obj2 == null)
			{
				continue;
			}
			object obj3 = Convert.ChangeType(obj2, type);
			if (obj3 != null)
			{
				PropertyInfo property = type.GetProperty("velocity");
				Vector3? val2 = property.GetValue(obj3) as Vector3?;
				if (val2.HasValue && val2.Value.y < -25f)
				{
					Vector3 value = val2.Value;
					value.y = -25f;
					property.SetValue(obj3, value);
				}
			}
		}
	}
}