Decompiled source of ChainGang v1.0.0

ChainGang.dll

Decompiled 4 days ago
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using KinematicCharacterController;
using RoR2;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace ChainGang;

public class ChainAnchor : MonoBehaviour
{
	public Vector3 velocity;

	public float slackTime = 1f;

	private Vector3 lastPosition;

	private bool hasLastPosition;

	private void FixedUpdate()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Unknown result type (might be due to invalid IL or missing references)
		//IL_0037: Unknown result type (might be due to invalid IL or missing references)
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: 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_0070: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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)
		Vector3 position = ((Component)this).transform.position;
		float fixedDeltaTime = Time.fixedDeltaTime;
		if (slackTime > 0f)
		{
			slackTime -= fixedDeltaTime;
		}
		if (hasLastPosition)
		{
			Vector3 val = position - lastPosition;
			if (ChainMath.IsTeleport(((Vector3)(ref val)).magnitude, fixedDeltaTime))
			{
				velocity = Vector3.zero;
				slackTime = 1f;
			}
			else
			{
				velocity = Vector3.Lerp(velocity, val / fixedDeltaTime, 0.35f);
			}
		}
		lastPosition = position;
		hasLastPosition = true;
	}
}
[BepInPlugin("ror2.chaingang", "ChainGang", "1.0.0")]
public class ChainGangPlugin : BaseUnityPlugin
{
	private struct ChainMember
	{
		public uint order;

		public CharacterBody body;

		public ChainAnchor anchor;
	}

	public const string PluginGuid = "ror2.chaingang";

	public const string PluginName = "ChainGang";

	public const string PluginVersion = "1.0.0";

	private const string ChainMaterialKey = "RoR2/Base/Gravekeeper/matGravekeeperHookChain.mat";

	private const string RopeMaterialKey = "RoR2/Base/Loader/matLoaderHookRope.mat";

	private const int LinePoints = 20;

	private const float ClotheslineInterval = 0.25f;

	private const float ClotheslineRadius = 0.6f;

	private const int ClotheslineSegments = 5;

	private static readonly Comparison<ChainMember> byOrder = CompareOrder;

	private ConfigEntry<bool> chainEnabled;

	private ConfigEntry<float> chainLength;

	private ConfigEntry<float> pullStrength;

	private ConfigEntry<float> clotheslineDamage;

	private ConfigEntry<float> clotheslineProc;

	private ConfigEntry<float> chainWidth;

	private readonly List<ChainMember> members = new List<ChainMember>();

	private readonly List<LineRenderer> lines = new List<LineRenderer>();

	private readonly Collider[] overlapBuffer = (Collider[])(object)new Collider[128];

	private readonly HashSet<HealthComponent> struck = new HashSet<HealthComponent>();

	private readonly Vector3[] linePositions = (Vector3[])(object)new Vector3[20];

	private Material chainMaterial;

	private bool materialRequested;

	private float clotheslineTimer;

	private int clotheslineTicks;

	private void Awake()
	{
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_005b: Expected O, but got Unknown
		//IL_0090: Unknown result type (might be due to invalid IL or missing references)
		//IL_009a: Expected O, but got Unknown
		//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d9: Expected O, but got Unknown
		//IL_010e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0118: Expected O, but got Unknown
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0157: Expected O, but got Unknown
		chainEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Chain", "Enabled", true, "Chains every living player to the next one.");
		chainLength = ((BaseUnityPlugin)this).Config.Bind<float>("Chain", "Length", 14f, new ConfigDescription("Chain length between two players in meters. Every player should use the same value.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(4f, 60f), new object[0]));
		pullStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Chain", "PullStrength", 1f, new ConfigDescription("Multiplier for how hard a stretched chain pulls.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.25f, 3f), new object[0]));
		clotheslineDamage = ((BaseUnityPlugin)this).Config.Bind<float>("Clothesline", "DamagePerSecond", 1.5f, new ConfigDescription("Damage per second a taut chain deals to enemies touching it, as a multiple of the damage of the player holding it. 0 turns it off. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 20f), new object[0]));
		clotheslineProc = ((BaseUnityPlugin)this).Config.Bind<float>("Clothesline", "ProcCoefficient", 0.2f, new ConfigDescription("Proc coefficient of each chain hit. 0 means the chain never triggers item effects. Host only.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), new object[0]));
		chainWidth = ((BaseUnityPlugin)this).Config.Bind<float>("Visuals", "Width", 0.35f, new ConfigDescription("Width of the drawn chain in meters.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.05f, 2f), new object[0]));
		RoR2Application.onFixedUpdate += FixedTick;
		RoR2Application.onLateUpdate += LateTick;
		Run.onRunStartGlobal += OnRunStart;
		Run.onRunDestroyGlobal += OnRunDestroy;
	}

	private void OnDestroy()
	{
		RoR2Application.onFixedUpdate -= FixedTick;
		RoR2Application.onLateUpdate -= LateTick;
		Run.onRunStartGlobal -= OnRunStart;
		Run.onRunDestroyGlobal -= OnRunDestroy;
	}

	private static int CompareOrder(ChainMember a, ChainMember b)
	{
		return a.order.CompareTo(b.order);
	}

	private void OnRunStart(Run run)
	{
		if (chainEnabled.Value)
		{
			Chat.AddMessage($"<color=#c9ced6>ChainGang:</color> chain length {chainLength.Value:0.#} m");
		}
	}

	private void OnRunDestroy(Run run)
	{
		members.Clear();
		HideLinesFrom(0);
	}

	private void CollectMembers()
	{
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_006e: Unknown result type (might be due to invalid IL or missing references)
		members.Clear();
		ReadOnlyCollection<PlayerCharacterMasterController> instances = PlayerCharacterMasterController.instances;
		ChainMember item = default(ChainMember);
		for (int i = 0; i < instances.Count; i++)
		{
			CharacterMaster master = instances[i].master;
			if (!Object.op_Implicit((Object)(object)master))
			{
				continue;
			}
			CharacterBody body = master.GetBody();
			if (!Object.op_Implicit((Object)(object)body) || Object.op_Implicit((Object)(object)body.currentVehicle))
			{
				continue;
			}
			HealthComponent healthComponent = body.healthComponent;
			if (Object.op_Implicit((Object)(object)healthComponent) && healthComponent.alive)
			{
				NetworkInstanceId netId = ((NetworkBehaviour)master).netId;
				item.order = ((NetworkInstanceId)(ref netId)).Value;
				item.body = body;
				item.anchor = ((Component)body).GetComponent<ChainAnchor>();
				if (!Object.op_Implicit((Object)(object)item.anchor))
				{
					item.anchor = ((Component)body).gameObject.AddComponent<ChainAnchor>();
				}
				members.Add(item);
			}
		}
		members.Sort(byOrder);
	}

	private void FixedTick()
	{
		if (!chainEnabled.Value || !Object.op_Implicit((Object)(object)Run.instance))
		{
			members.Clear();
			return;
		}
		CollectMembers();
		float fixedDeltaTime = Time.fixedDeltaTime;
		for (int i = 0; i < members.Count; i++)
		{
			CharacterBody body = members[i].body;
			if (!body.hasEffectiveAuthority)
			{
				continue;
			}
			CharacterMotor characterMotor = body.characterMotor;
			if (Object.op_Implicit((Object)(object)characterMotor))
			{
				if (i > 0)
				{
					Pull(members[i], characterMotor, members[i - 1], fixedDeltaTime);
				}
				if (i < members.Count - 1)
				{
					Pull(members[i], characterMotor, members[i + 1], fixedDeltaTime);
				}
			}
		}
		if (NetworkServer.active)
		{
			Clothesline(fixedDeltaTime);
		}
	}

	private static Vector3 PointOnChain(Vector3 start, Vector3 end, float sag, float t)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0008: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		Vector3 result = Vector3.Lerp(start, end, t);
		result.y -= ChainMath.SagAt(sag, t);
		return result;
	}

	private void Pull(ChainMember self, CharacterMotor motor, ChainMember other, float deltaTime)
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_003a: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: 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_007b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0080: Unknown result type (might be due to invalid IL or missing references)
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0124: Unknown result type (might be due to invalid IL or missing references)
		//IL_0129: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0131: 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_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Unknown result type (might be due to invalid IL or missing references)
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_014c: 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_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0164: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cb: 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_00dd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		if (self.anchor.slackTime > 0f || other.anchor.slackTime > 0f)
		{
			return;
		}
		Vector3 val = other.body.corePosition - self.body.corePosition;
		float magnitude = ((Vector3)(ref val)).magnitude;
		float num = magnitude - chainLength.Value;
		if (num <= 0f)
		{
			return;
		}
		Vector3 val2 = val / magnitude;
		float value = pullStrength.Value;
		motor.rootMotion += val2 * ChainMath.HardPullStep(num, deltaTime);
		if (motor.isGrounded)
		{
			if (!ChainMath.ShouldLiftOff(num, val2.y))
			{
				Vector3 val3 = default(Vector3);
				((Vector3)(ref val3))..ctor(val2.x, 0f, val2.z);
				motor.rootMotion += val3 * (ChainMath.GroundDragSpeed(num, value) * deltaTime);
				return;
			}
			((BaseCharacterController)motor).Motor.ForceUnground(0.1f);
			motor.velocity.y = Mathf.Max(motor.velocity.y, 6f);
		}
		Vector3 velocity = other.anchor.velocity;
		float separatingSpeed = Vector3.Dot(motor.velocity - velocity, -val2);
		motor.velocity += val2 * (ChainMath.SpringAcceleration(num, separatingSpeed, value) * deltaTime);
	}

	private void Clothesline(float deltaTime)
	{
		//IL_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_009c: 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_00a5: 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_00a9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: 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_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_0104: 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_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0128: Unknown result type (might be due to invalid IL or missing references)
		float value = clotheslineDamage.Value;
		if (value <= 0f)
		{
			return;
		}
		clotheslineTimer -= deltaTime;
		if (clotheslineTimer > 0f)
		{
			return;
		}
		clotheslineTimer = 0.25f;
		clotheslineTicks++;
		float value2 = chainLength.Value;
		int num = LayerMask.op_Implicit(((LayerIndex)(ref LayerIndex.entityPrecise)).mask);
		for (int i = 0; i < members.Count - 1; i++)
		{
			CharacterBody body = members[i].body;
			CharacterBody body2 = members[i + 1].body;
			Vector3 corePosition = body.corePosition;
			Vector3 corePosition2 = body2.corePosition;
			float distance = Vector3.Distance(corePosition, corePosition2);
			if (ChainMath.IsTaut(distance, value2))
			{
				CharacterBody attacker = ((((clotheslineTicks + i) & 1) == 0) ? body : body2);
				float sag = ChainMath.Sag(distance, value2);
				struck.Clear();
				Vector3 val = corePosition;
				for (int j = 1; j <= 5; j++)
				{
					Vector3 val2 = PointOnChain(corePosition, corePosition2, sag, (float)j / 5f);
					int hits = Physics.OverlapCapsuleNonAlloc(val, val2, 0.6f, overlapBuffer, num);
					StrikeHits(attacker, hits, value);
					val = val2;
				}
			}
		}
	}

	private void StrikeHits(CharacterBody attacker, int hits, float coefficient)
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Invalid comparison between Unknown and I4
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		for (int i = 0; i < hits; i++)
		{
			HurtBox component = ((Component)overlapBuffer[i]).GetComponent<HurtBox>();
			if (Object.op_Implicit((Object)(object)component) && (int)component.teamIndex != 1)
			{
				HealthComponent healthComponent = component.healthComponent;
				if (Object.op_Implicit((Object)(object)healthComponent) && healthComponent.alive && struck.Add(healthComponent))
				{
					Strike(attacker, healthComponent, ((Component)component).transform.position, coefficient);
				}
			}
		}
	}

	private void Strike(CharacterBody attacker, HealthComponent victim, Vector3 position, float coefficient)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Expected O, but got Unknown
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0064: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: Unknown result type (might be due to invalid IL or missing references)
		DamageInfo val = new DamageInfo();
		val.damage = attacker.damage * coefficient * 0.25f;
		val.crit = attacker.RollCrit();
		val.attacker = ((Component)attacker).gameObject;
		val.inflictor = ((Component)attacker).gameObject;
		val.position = position;
		val.force = Vector3.zero;
		val.procCoefficient = clotheslineProc.Value;
		val.damageType = DamageTypeCombo.op_Implicit((DamageType)0);
		val.damageColorIndex = (DamageColorIndex)3;
		victim.TakeDamage(val);
		GlobalEventManager instance = GlobalEventManager.instance;
		if (Object.op_Implicit((Object)(object)instance) && val.procCoefficient > 0f)
		{
			instance.OnHitEnemy(val, ((Component)victim).gameObject);
			instance.OnHitAll(val, ((Component)victim).gameObject);
		}
	}

	private void LateTick()
	{
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Unknown result type (might be due to invalid IL or missing references)
		int num = 0;
		float value = chainLength.Value;
		float value2 = chainWidth.Value;
		for (int i = 0; i < members.Count - 1; i++)
		{
			CharacterBody body = members[i].body;
			CharacterBody body2 = members[i + 1].body;
			if (Object.op_Implicit((Object)(object)body) && Object.op_Implicit((Object)(object)body2))
			{
				DrawLink(LineAt(num), body.corePosition, body2.corePosition, value, value2);
				num++;
			}
		}
		HideLinesFrom(num);
	}

	private void DrawLink(LineRenderer line, Vector3 start, Vector3 end, float length, float width)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0053: 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_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: 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)
		float distance = Vector3.Distance(start, end);
		float sag = ChainMath.Sag(distance, length);
		for (int i = 0; i < 20; i++)
		{
			ref Vector3 reference = ref linePositions[i];
			reference = PointOnChain(start, end, sag, (float)i / 19f);
		}
		Color endColor = (line.startColor = Color.Lerp(Color.white, new Color(1f, 0.35f, 0.3f), Mathf.InverseLerp(0.6f, 1f, ChainMath.Tension(distance, length))));
		line.endColor = endColor;
		line.startWidth = width;
		line.endWidth = width;
		line.SetPositions(linePositions);
		((Renderer)line).enabled = true;
	}

	private LineRenderer LineAt(int index)
	{
		while (lines.Count <= index)
		{
			lines.Add(CreateLine());
		}
		return lines[index];
	}

	private LineRenderer CreateLine()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: Expected O, but got Unknown
		GameObject val = new GameObject("ChainGangLink");
		Object.DontDestroyOnLoad((Object)(object)val);
		LineRenderer val2 = val.AddComponent<LineRenderer>();
		val2.useWorldSpace = true;
		val2.positionCount = 20;
		val2.textureMode = (LineTextureMode)1;
		((Renderer)val2).shadowCastingMode = (ShadowCastingMode)0;
		((Renderer)val2).receiveShadows = false;
		((Renderer)val2).sharedMaterial = ChainMaterial();
		((Renderer)val2).enabled = false;
		return val2;
	}

	private void HideLinesFrom(int index)
	{
		for (int i = index; i < lines.Count; i++)
		{
			if (Object.op_Implicit((Object)(object)lines[i]))
			{
				((Renderer)lines[i]).enabled = false;
			}
		}
	}

	private Material ChainMaterial()
	{
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		if (materialRequested)
		{
			return chainMaterial;
		}
		materialRequested = true;
		chainMaterial = LoadMaterial("RoR2/Base/Gravekeeper/matGravekeeperHookChain.mat");
		if (!Object.op_Implicit((Object)(object)chainMaterial))
		{
			chainMaterial = LoadMaterial("RoR2/Base/Loader/matLoaderHookRope.mat");
		}
		if (!Object.op_Implicit((Object)(object)chainMaterial))
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)"No chain material found in the game assets (RoR2/Base/Gravekeeper/matGravekeeperHookChain.mat, RoR2/Base/Loader/matLoaderHookRope.mat). The chain still pulls but is drawn without a texture.");
			Shader val = Shader.Find("Sprites/Default");
			if (Object.op_Implicit((Object)(object)val))
			{
				chainMaterial = new Material(val);
			}
		}
		return chainMaterial;
	}

	private Material LoadMaterial(string key)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			return Addressables.LoadAssetAsync<Material>((object)key).WaitForCompletion();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("Could not load " + key + ": " + ex.Message));
			return null;
		}
	}
}
public static class ChainMath
{
	public const float Stiffness = 18f;

	public const float Damping = 5f;

	public const float RecoilFadeSpeed = 4f;

	public const float MinRecoil = 0.1f;

	public const float MaxAcceleration = 150f;

	public const float MaxApproachSpeed = 70f;

	public const float GroundDragPerMeter = 2.5f;

	public const float MaxGroundDrag = 30f;

	public const float YankExcess = 5f;

	public const float LiftExcess = 2f;

	public const float LiftSlope = 0.6f;

	public const float LiftSpeed = 6f;

	public const float HardStretch = 8f;

	public const float MaxHardSpeed = 45f;

	public const float TeleportSpeed = 200f;

	public const float SlackAfterTeleport = 1f;

	public const float TautFraction = 0.6f;

	public static float SpringAcceleration(float excess, float separatingSpeed, float strength)
	{
		if (excess <= 0f || 0f - separatingSpeed >= 70f)
		{
			return 0f;
		}
		float num = Math.Max(0f, 0f - separatingSpeed);
		float num2 = Math.Max(0.1f, 1f - num / 4f);
		float val = strength * (18f * excess * num2 + 5f * Math.Max(0f, separatingSpeed));
		return Math.Min(val, 150f);
	}

	public static float GroundDragSpeed(float excess, float strength)
	{
		if (excess <= 0f)
		{
			return 0f;
		}
		return Math.Min(strength * 2.5f * excess, 30f);
	}

	public static float HardPullStep(float excess, float deltaTime)
	{
		float num = excess - 8f;
		if (num <= 0f)
		{
			return 0f;
		}
		return Math.Min(num * 0.5f, 45f * deltaTime);
	}

	public static bool IsTeleport(float movedDistance, float deltaTime)
	{
		return movedDistance > 200f * deltaTime;
	}

	public static bool ShouldLiftOff(float excess, float directionY)
	{
		if (!(excess > 5f))
		{
			if (excess > 2f)
			{
				return directionY > 0.6f;
			}
			return false;
		}
		return true;
	}

	public static bool IsTaut(float distance, float length)
	{
		return distance >= length * 0.6f;
	}

	public static float Tension(float distance, float length)
	{
		if (length <= 0f)
		{
			return 1f;
		}
		return Math.Max(0f, Math.Min(1f, distance / length));
	}

	public static float Sag(float distance, float length)
	{
		if (distance >= length)
		{
			return 0f;
		}
		return 0.5f * (float)Math.Sqrt(length * length - distance * distance);
	}

	public static float SagAt(float sag, float t)
	{
		return sag * 4f * t * (1f - t);
	}
}