Decompiled source of Fling v1.1.0

Mods/Fling.dll

Decompiled 8 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib;
using BoneLib.BoneMenu;
using BoneLib.BoneMenu.Elements;
using Fling;
using MelonLoader;
using MelonLoader.Preferences;
using SLZ.VRMK;
using SLZ.Vehicle;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(Main), "Fling", "1.1.0", "Bailout", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("Fling")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Fling")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("dcbb8334-dc6f-4833-8cd6-ad1cedf2ff30")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Fling;

public static class BuildInfo
{
	public const string Name = "Fling";

	public const string Author = "Bailout";

	public const string Version = "1.1.0";
}
public class Main : MelonMod
{
	private bool SceneLoaded = false;

	private bool RagdollState = false;

	private Vector3 PreviousVelocity;

	private Vector3 CurrentVelocity;

	private Vector3 VehicleVelocity;

	private float StartTime;

	private float EndTime;

	public static float DynRagTime;

	public static float SpeedThreshold = 3f;

	public static float MassMultiplier = 1f;

	public static float RagdollTime = 5f;

	public static float ImmunityTime = 2f;

	public static float DamageMultiplier = 5f;

	public static float DamageThreshold = 20f;

	public static float ForceMultiplier = 1f;

	public override void OnInitializeMelon()
	{
		Hooking.OnLevelInitialized += delegate
		{
			OnSceneAwake();
		};
		Preferences.BonemenuCreator();
	}

	public void OnSceneAwake()
	{
		SceneLoaded = true;
	}

	public override void OnUpdate()
	{
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0029: 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_00b4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0345: Unknown result type (might be due to invalid IL or missing references)
		//IL_034a: Unknown result type (might be due to invalid IL or missing references)
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0322: Unknown result type (might be due to invalid IL or missing references)
		//IL_032c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0336: Unknown result type (might be due to invalid IL or missing references)
		if (!Preferences.IsEnabled || !SceneLoaded)
		{
			return;
		}
		CurrentVelocity = Player.physicsRig.wholeBodyVelocity;
		if (Time.time - StartTime >= (Preferences.SpeedEffectsRagdoll ? DynRagTime : RagdollTime) && RagdollState && Preferences.IsRagdollEnabled)
		{
			RagdollState = false;
			Player.physicsRig.UnRagdollRig();
			EndTime = Time.time;
		}
		RaycastHit val = default(RaycastHit);
		if (Preferences.AirborneOnly && Physics.Raycast(((Component)Player.physicsRig.feet.GetComponent<PhysGrounder>()).transform.position, new Vector3(0f, -1f, 0f), ref val, Player.rigManager.avatar._height / 3f))
		{
			PreviousVelocity = CurrentVelocity;
			return;
		}
		if ((double)Mathf.Abs(((Vector3)(ref CurrentVelocity)).magnitude - ((Vector3)(ref PreviousVelocity)).magnitude) >= (double)SpeedThreshold * (Preferences.AvatarMass ? ((double)(MassMultiplier * Player.rigManager.avatar._massTotal) / 81.48) : 1.0) && Time.time - EndTime >= ImmunityTime)
		{
			if (Preferences.IsRagdollEnabled)
			{
				if (Preferences.IsVehicleEnabled && Object.op_Implicit((Object)(object)Player.rigManager.activeSeat))
				{
					VehicleVelocity = PreviousVelocity;
					Player.rigManager.activeSeat.seatState = (SeatState)2;
				}
				if (Preferences.SpeedEffectsRagdoll)
				{
					DynRagTime = Mathf.Clamp(4f * (Mathf.Abs(((Vector3)(ref CurrentVelocity)).magnitude - ((Vector3)(ref PreviousVelocity)).magnitude) - SpeedThreshold * (Preferences.AvatarMass ? (MassMultiplier * Player.rigManager.avatar._massTotal / 82f) : 1f)), 0f, 2f * RagdollTime);
				}
				Ragdoll();
				StartTime = Time.time;
			}
			if (Preferences.IsDamageEnabled && Mathf.Abs((((Vector3)(ref CurrentVelocity)).magnitude - ((Vector3)(ref PreviousVelocity)).magnitude) * DamageMultiplier) > DamageThreshold)
			{
				Player.rigManager.health.TAKEDAMAGE(Mathf.Abs((((Vector3)(ref CurrentVelocity)).magnitude - ((Vector3)(ref PreviousVelocity)).magnitude) * DamageMultiplier) - DamageThreshold);
			}
		}
		if ((double)(Time.time - StartTime) >= 0.5 && Time.time - StartTime <= 1f && !Player.physicsRig._legsKinematic && Preferences.IsVehicleEnabled)
		{
			Ragdoll();
			if (Preferences.CarryVehicleForces)
			{
				Player.physicsRig.torso.rbChest.velocity = VehicleVelocity * ForceMultiplier / 3f;
			}
		}
		PreviousVelocity = CurrentVelocity;
	}

	public void Ragdoll()
	{
		RagdollState = true;
		Player.physicsRig.RagdollRig();
		if (Preferences.KeepArmControl)
		{
			Player.physicsRig.leftHand.physHand.forceMultiplier = 1f;
			Player.physicsRig.rightHand.physHand.forceMultiplier = 1f;
		}
	}
}
public class Preferences : MelonMod
{
	public static MelonPreferences_Category MelonPrefCategory { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefEnabled { get; private set; }

	public static bool IsEnabled { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefAirborneOnly { get; private set; }

	public static bool AirborneOnly { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefSpeedThreshold { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefAvatarMass { get; private set; }

	public static bool AvatarMass { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefMassMultiplier { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefRagdollEnabled { get; private set; }

	public static bool IsRagdollEnabled { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefSpeedEffects { get; private set; }

	public static bool SpeedEffectsRagdoll { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefRagdollTime { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefImmunityTime { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefArmControl { get; private set; }

	public static bool KeepArmControl { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefDamageEnabled { get; private set; }

	public static bool IsDamageEnabled { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefDamageThreshold { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefDamageMutiplier { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefVehicleEnabled { get; private set; }

	public static bool IsVehicleEnabled { get; private set; }

	public static MelonPreferences_Entry<bool> MelonPrefVehicleForces { get; private set; }

	public static bool CarryVehicleForces { get; private set; }

	public static MelonPreferences_Entry<float> MelonPrefForceMutiplier { get; private set; }

	public static void BonemenuCreator()
	{
		MelonPrefCategory = MelonPreferences.CreateCategory("Fling");
		MelonPrefEnabled = MelonPrefCategory.CreateEntry<bool>("Mod Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsEnabled = MelonPrefEnabled.Value;
		MelonPrefAirborneOnly = MelonPrefCategory.CreateEntry<bool>("Airborne Only", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AirborneOnly = MelonPrefAirborneOnly.Value;
		MelonPrefSpeedThreshold = MelonPrefCategory.CreateEntry<float>("Speed Threshold", 3f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefAvatarMass = MelonPrefCategory.CreateEntry<bool>("Avatar Mass Effects Fling", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		AvatarMass = MelonPrefAvatarMass.Value;
		MelonPrefMassMultiplier = MelonPrefCategory.CreateEntry<float>("Avatar Mass Multiplyer", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefRagdollEnabled = MelonPrefCategory.CreateEntry<bool>("Ragdoll Enabled", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsRagdollEnabled = MelonPrefRagdollEnabled.Value;
		MelonPrefSpeedEffects = MelonPrefCategory.CreateEntry<bool>("Dynamic Ragdoll Time", true, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		SpeedEffectsRagdoll = MelonPrefSpeedEffects.Value;
		MelonPrefRagdollTime = MelonPrefCategory.CreateEntry<float>("Ragdoll Time", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefImmunityTime = MelonPrefCategory.CreateEntry<float>("Immunity Time", 2f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefArmControl = MelonPrefCategory.CreateEntry<bool>("Keep Arm Control", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		KeepArmControl = MelonPrefArmControl.Value;
		MelonPrefDamageEnabled = MelonPrefCategory.CreateEntry<bool>("Damage Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsDamageEnabled = MelonPrefDamageEnabled.Value;
		MelonPrefDamageThreshold = MelonPrefCategory.CreateEntry<float>("Damage Threshold", 20f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefDamageMutiplier = MelonPrefCategory.CreateEntry<float>("Damage Multiplier", 5f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPrefVehicleEnabled = MelonPrefCategory.CreateEntry<bool>("Vehicle Enabled", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		IsVehicleEnabled = MelonPrefVehicleEnabled.Value;
		MelonPrefVehicleForces = MelonPrefCategory.CreateEntry<bool>("Carry Vehicle Forces", false, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		CarryVehicleForces = MelonPrefVehicleForces.Value;
		MelonPrefForceMutiplier = MelonPrefCategory.CreateEntry<float>("Vehicle Force Multiplier", 1f, (string)null, (string)null, false, false, (ValueValidator)null, (string)null);
		MenuCategory val = MenuManager.CreateCategory("Fling", "#6279b8");
		val.CreateBoolElement("Mod Toggle", "#6279b8", IsEnabled, (Action<bool>)OnSetEnabled);
		SubPanelElement val2 = val.CreateSubPanel("Trigger", "#8ea4d2");
		val2.CreateBoolElement("Airborne Only", "#49516f", AirborneOnly, (Action<bool>)OnSetAirborneOnly);
		val2.CreateFloatElement("Speed Threshold", "#49516f", Main.SpeedThreshold, 1f, 1f, 100f, (Action<float>)delegate(float st)
		{
			Main.SpeedThreshold = st;
			MelonPrefSpeedThreshold.Value = st;
			MelonPrefCategory.SaveToFile(true);
		});
		val2.CreateBoolElement("Mass Effects Fling", "#49516f", AvatarMass, (Action<bool>)OnSetAvatarMass);
		val2.CreateFloatElement("Mass Multiplier", "#49516f", Main.SpeedThreshold, 1f, 1f, 100f, (Action<float>)delegate(float mm)
		{
			Main.MassMultiplier = mm;
			MelonPrefMassMultiplier.Value = mm;
			MelonPrefCategory.SaveToFile(true);
		});
		SubPanelElement val3 = val.CreateSubPanel("Ragdoll", "#8ea4d2");
		val3.CreateBoolElement("Ragdoll Toggle", "#49516f", IsRagdollEnabled, (Action<bool>)OnSetRagdollEnabled);
		val3.CreateBoolElement("Dynamic Ragdoll Time", "#49516f", SpeedEffectsRagdoll, (Action<bool>)OnSetSpeedEffects);
		val3.CreateFloatElement("Manual Ragdoll Time", "#49516f", Main.RagdollTime, 1f, 1f, 100f, (Action<float>)delegate(float rt)
		{
			Main.RagdollTime = rt;
			MelonPrefRagdollTime.Value = rt;
			MelonPrefCategory.SaveToFile(true);
		});
		val3.CreateFloatElement("Immunity Time", "#49516f", Main.ImmunityTime, 1f, 1f, 100f, (Action<float>)delegate(float it)
		{
			Main.ImmunityTime = it;
			MelonPrefImmunityTime.Value = it;
			MelonPrefCategory.SaveToFile(true);
		});
		val3.CreateBoolElement("Keep Arm Control", "#49516f", KeepArmControl, (Action<bool>)OnSetArmControl);
		SubPanelElement val4 = val.CreateSubPanel("Damage", "#8ea4d2");
		val4.CreateBoolElement("Damage Toggle", "#49516f", IsDamageEnabled, (Action<bool>)OnSetDamageEnabled);
		val4.CreateFloatElement("Damage Multiplier", "#49516f", Main.DamageMultiplier, 1f, 1f, 100f, (Action<float>)delegate(float dm)
		{
			Main.DamageMultiplier = dm;
			MelonPrefDamageMutiplier.Value = dm;
			MelonPrefCategory.SaveToFile(true);
		});
		val4.CreateFloatElement("Damage Threshold", "#49516f", Main.DamageThreshold, 1f, 1f, 100f, (Action<float>)delegate(float dt)
		{
			Main.DamageThreshold = dt;
			MelonPrefDamageThreshold.Value = dt;
			MelonPrefCategory.SaveToFile(true);
		});
		SubPanelElement val5 = val.CreateSubPanel("Vehicle", "#8ea4d2");
		val5.CreateBoolElement("Vehicle Toggle", "#49516f", IsVehicleEnabled, (Action<bool>)OnSetVehicleEnabled);
		val5.CreateBoolElement("Carry Forces", "#49516f", CarryVehicleForces, (Action<bool>)OnSetVehicleForces);
		val5.CreateFloatElement("Force Multiplier", "#49516f", Main.ForceMultiplier, 1f, 1f, 100f, (Action<float>)delegate(float fm)
		{
			Main.ForceMultiplier = fm;
			MelonPrefForceMutiplier.Value = fm;
			MelonPrefCategory.SaveToFile(true);
		});
	}

	public static void OnSetEnabled(bool value)
	{
		IsEnabled = value;
		MelonPrefEnabled.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetAirborneOnly(bool value)
	{
		AirborneOnly = value;
		MelonPrefAirborneOnly.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetAvatarMass(bool value)
	{
		AvatarMass = value;
		MelonPrefAvatarMass.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetRagdollEnabled(bool value)
	{
		IsRagdollEnabled = value;
		MelonPrefRagdollEnabled.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetSpeedEffects(bool value)
	{
		SpeedEffectsRagdoll = value;
		MelonPrefSpeedEffects.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetArmControl(bool value)
	{
		KeepArmControl = value;
		MelonPrefArmControl.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetDamageEnabled(bool value)
	{
		IsDamageEnabled = value;
		MelonPrefDamageEnabled.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetVehicleEnabled(bool value)
	{
		IsVehicleEnabled = value;
		MelonPrefVehicleEnabled.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}

	public static void OnSetVehicleForces(bool value)
	{
		CarryVehicleForces = value;
		MelonPrefVehicleForces.Value = value;
		MelonPrefCategory.SaveToFile(true);
	}
}