Decompiled source of ContinuousDynamic v1.1.0

Mods/ContinuousDynamicMod.dll

Decompiled a week ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BoneLib.BoneMenu;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using MelonLoader;
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(ContinuousDynamicMod), "Continuous Dynamic", "2.0.0", "YourName", null)]
[assembly: MelonGame("Stress Level Zero", "BONELAB")]
[assembly: AssemblyTitle("ContinuousDynamicMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ContinuousDynamicMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("844838bb-e953-4634-bc53-df739c70080f")]
[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")]
public class ContinuousDynamicMod : MelonMod
{
	private static bool modEnabled = false;

	private static int defaultSolverIterations;

	private static int defaultSolverVelocityIterations;

	private static float defaultMaxDepenetrationVelocity;

	private static List<Rigidbody> trackedBodies = new List<Rigidbody>();

	private static float scanTimer = 0f;

	private static float scanInterval = 4f;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("Continuous Dynamic Loaded (Optimized)");
		defaultSolverIterations = Physics.defaultSolverIterations;
		defaultSolverVelocityIterations = Physics.defaultSolverVelocityIterations;
		defaultMaxDepenetrationVelocity = Physics.defaultMaxDepenetrationVelocity;
		SetupMenu();
	}

	private void SetupMenu()
	{
		//IL_000b: 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)
		Page val = Page.Root.CreatePage("Continuous Dynamic", Color.cyan, 0, true);
		val.CreateBool("Enable Anti-Clipping", Color.white, false, (Action<bool>)delegate(bool value)
		{
			modEnabled = value;
			if (modEnabled)
			{
				EnablePhysics();
			}
			else
			{
				DisablePhysics();
			}
		});
	}

	public override void OnUpdate()
	{
		if (modEnabled)
		{
			scanTimer += Time.deltaTime;
			if (scanTimer >= scanInterval)
			{
				ScanRigidbodies();
				scanTimer = 0f;
			}
			ApplyToTracked();
		}
	}

	private static void EnablePhysics()
	{
		Physics.defaultSolverIterations = 16;
		Physics.defaultSolverVelocityIterations = 16;
		Physics.defaultMaxDepenetrationVelocity = 15f;
		MelonLogger.Msg("Anti-Clipping ENABLED");
	}

	private static void DisablePhysics()
	{
		Physics.defaultSolverIterations = defaultSolverIterations;
		Physics.defaultSolverVelocityIterations = defaultSolverVelocityIterations;
		Physics.defaultMaxDepenetrationVelocity = defaultMaxDepenetrationVelocity;
		foreach (Rigidbody trackedBody in trackedBodies)
		{
			if (!((Object)(object)trackedBody == (Object)null))
			{
				trackedBody.collisionDetectionMode = (CollisionDetectionMode)0;
			}
		}
		trackedBodies.Clear();
		MelonLogger.Msg("Anti-Clipping DISABLED");
	}

	private static void ScanRigidbodies()
	{
		Il2CppArrayBase<Rigidbody> val = Object.FindObjectsOfType<Rigidbody>();
		trackedBodies.Clear();
		foreach (Rigidbody item in val)
		{
			if (!((Object)(object)item == (Object)null))
			{
				string text = ((Object)((Component)item).gameObject).name.ToLower();
				if (!text.Contains("player") && !text.Contains("ragdoll"))
				{
					trackedBodies.Add(item);
				}
			}
		}
		MelonLogger.Msg($"Tracked {trackedBodies.Count} rigidbodies");
	}

	private static void ApplyToTracked()
	{
		//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_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_0099: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007a: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
		foreach (Rigidbody trackedBody in trackedBodies)
		{
			if (!((Object)(object)trackedBody == (Object)null))
			{
				Vector3 velocity = trackedBody.velocity;
				if (((Vector3)(ref velocity)).magnitude > 2f)
				{
					trackedBody.collisionDetectionMode = (CollisionDetectionMode)2;
				}
				else
				{
					trackedBody.collisionDetectionMode = (CollisionDetectionMode)1;
				}
				velocity = trackedBody.velocity;
				if (((Vector3)(ref velocity)).magnitude > 25f)
				{
					velocity = trackedBody.velocity;
					trackedBody.velocity = ((Vector3)(ref velocity)).normalized * 25f;
				}
				velocity = trackedBody.velocity;
				if (((Vector3)(ref velocity)).magnitude < 0.02f && !trackedBody.IsSleeping())
				{
					trackedBody.AddForce(Vector3.up * 0.5f, (ForceMode)5);
				}
			}
		}
	}
}